#include <bits/stdc++.h> n using namespace std; n bool isPrime(int x) { n   if (x == 1) return false; n   for (long long i = 2; i <= sqrt(x); i += 1) n     if (x % i == 0) return false; n   return true; n } n void print(int a[], int n) { n   for (long long i = 0; i < n; i += 1) cout << a[i] <<    ; n } n void iarr(int *a, int n) { n   for (long long i = 0; i < n; i += 1) cin >> a[i]; n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = ((res % 1000000007) * (a % 1000000007)) % 1000000007; n     a = ((a % 1000000007) * (a % 1000000007)) % 1000000007; n     b >>= 1; n   } n   return res; n } n long long numFactors(long long x) { n   long long cnt = 0; n   for (long long i = 1; i <= sqrt(x); i += 1) { n     if (x % i == 0) { n       if (x / i == i) n         cnt += 1; n       else n         cnt += 2; n     } n   } n   return cnt; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout << fixed; n   cout.precision(10); n   ; n   int n; n   cin >> n; n   int a[n]; n   iarr(a, n); n   long long cnt = 0; n   while (true) { n     int ind = -1, mx = a[0]; n     for (long long i = 1; i < n; i += 1) { n       if (a[i] >= mx) { n         ind = i; n         mx = a[i]; n       } n     } n     if (ind != -1) { n       a[ind]--; n       a[0]++; n       cnt++; n     } else if (ind == -1) { n       break; n     } n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long int power(unsigned long long int a, unsigned long long int b, n                              unsigned long long int p) { n   unsigned long long int res = 1; n   a = a % p; n   while (b > 0) { n     if (b & 1) { n       res = (res * a) % p; n       b--; n     } n     a = (a * a) % p; n     b >>= 1; n   } n   return res; n } n unsigned long long int gcd(unsigned long long int a, unsigned long long int b) { n   return (b == 0) ? a : gcd(b, a % b); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   unsigned long long int n, p, k; n   cin >> n >> p >> k; n   vector<unsigned long long int> v(n); n   for (auto &i : v) cin >> i; n   map<unsigned long long int, unsigned long long int> cnt; n   for (unsigned long long int i = 0; i < n; i++) { n     unsigned long long int cur = (power(v[i], 4, p) - (k * v[i]) % p + p) % p; n     cnt[cur]++; n   } n   unsigned long long int ans = 0; n   for (auto i : cnt) ans += (i.second * (i.second - 1)) / 2; n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const unsigned gen_seed = n     std::chrono::system_clock::now().time_since_epoch().count(); n std::mt19937_64 gen(gen_seed); n const int A = 500; n long long d[A + 1][A + 1]; n long long fac[A + 1]; n long long ifac[A + 1]; n long long cfac[A + 1][A + 1]; n long long cfac2[A + 1][A + 1]; n long long gcd(long long a, long long b, long long& x, long long& y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long d = gcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n long long invmod(long long a, long long modulo) { n   long long x, y; n   gcd(a, modulo, x, y); n   return (x % modulo + modulo) % modulo; n } n int main() { n   fac[0] = 1; n   for (long long i = 1; i <= A; i++) fac[i] = (fac[i - 1] * i) % mod; n   for (int i = 0; i < A + 1; i++) ifac[i] = invmod(fac[i], mod); n   d[0][0] = 1; n   for (int i = 0; i < A + 1; i++) n     for (int j = 0; j < i + 1; j++) cfac[i][j] = fac[i] * ifac[i - j] % mod; n   for (int i = 0; i < A + 1; i++) n     for (int j = 0; j < i + 1; j++) cfac2[i][j] = cfac[i][j] * (j + 1) % mod; n   for (int b = 0; b < A + 1; b++) n     for (int a = 0; a < A + 1; a++) { n       if (a == 0) { n         if (b > 0) d[0][b] = (d[0][b - 1] * b) % mod; n         continue; n       } n       for (int tb = 0; tb < b + 1; tb++) { n         d[a][b] += d[a - 1][b - tb] * cfac[b][tb] % mod; n       } n       if (a > 1) { n         long long cand = 0; n         for (int tb = 0; tb < b + 1; tb++) { n           cand += d[a - 2][b - tb] * cfac2[b][tb] % mod; n         } n         d[a][b] += cand * (a - 1); n       } n       d[a][b] %= mod; n     } n   int n; n   scanf( %d , &n); n   int a = 0; n   int b = 0; n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     if (x == 1) n       a++; n     else n       b++; n   } n   cout << d[a][b]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, k, ans = 0, t; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     ans = 0; n     while (n > 0) { n       if (n % k == 0) { n         n /= k; n         ans++; n       } else { n         ans += n % k; n         n -= n % k; n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n long long p(long long n, long long k) { n   long long d = 1; n   while (n) { n     if (n & 1) d = (d * k) % 1000000007; n     k = (k * k) % 1000000007; n     n >>= 1; n   } n   return d; n } n int main() { n   long long n, l; n   scanf( %I64d , &n); n   l = p(n, 2); n   printf( %I64d , ((l + l * l) / 2) % 1000000007); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n using VV = vector<vector<T>>; n template <class T> n inline bool SMIN(T &l, const T &r) { n   return l < r ? l = r, 1 : 0; n } n template <class T> n inline bool SMAX(T &l, const T &r) { n   return l > r ? l = r, 1 : 0; n } n const string yes =  YES , no =  NO ; n int X, Y, Z, T1, T2, T3; n string solve() { n   long long s = abs(X - Y) * T1; n   long long e = abs(Z - X) * T2 + abs(X - Y) * T2 + 3LL * T3; n   return !(s < e) ? yes : no; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> X >> Y >> Z >> T1 >> T2 >> T3; n   cout << solve() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, i, j, mas[50077], fix[50077], dom, a[50077]; n int main() { n   cin >> n; n   for (k = 1; k <= n; k++) cin >> a[k]; n   for (k = 1; k <= n; k++) { n     dom = a[k]; n     for (j = 1; j <= n; j++) mas[a[j]] = 0; n     for (i = k; i <= n; i++) { n       mas[a[i]]++; n       if (mas[a[i]] > mas[dom]) n         dom = a[i]; n       else if (a[i] < dom && mas[a[i]] == mas[dom]) n         dom = a[i]; n       fix[dom]++; n     } n   } n   for (k = 1; k <= n; k++) cout << fix[k] <<    ; n } n


#include <bits/stdc++.h> n const double pi = (double)(2.0 * acos(0.0)); n const int inf = 1 << 30; n const double eps = 1E-9; n const double e = exp(1.0); n const int sz = 100000 + 5; n const int mod = 1000000000 + 7; n using namespace std; n int main() { n   double x, y, z, res, v; n   string st =   ; n   scanf( %lf %lf %lf , &x, &y, &z); n   if (x < 1.0 + eps && y < 1.0 + eps && z < 1.0 + eps) { n     res = 1e18; n     v = z * log(y) + log(log(1.0 / x)); n     if (res > v + eps) res = v, st =  x^y^z ; n     v = y * log(z) + log(log(1.0 / x)); n     if (res > v + eps) res = v, st =  x^z^y ; n     v = log(y) + log(z) + log(log(1.0 / x)); n     if (res > v + eps) res = v, st =  (x^y)^z ; n     v = z * log(x) + log(log(1.0 / y)); n     if (res > v + eps) res = v, st =  y^x^z ; n     v = x * log(z) + log(log(1.0 / y)); n     if (res > v + eps) res = v, st =  y^z^x ; n     v = log(x) + log(z) + log(log(1.0 / y)); n     if (res > v + eps) res = v, st =  (y^x)^z ; n     v = y * log(x) + log(log(1.0 / z)); n     if (res > v + eps) res = v, st =  z^x^y ; n     v = x * log(y) + log(log(1.0 / z)); n     if (res > v + eps) res = v, st =  z^y^x ; n     v = log(x) + log(y) + log(log(1.0 / z)); n     if (res > v + eps) res = v, st =  (z^x)^y ; n     cout << st << endl; n   } else { n     res = -1e18; n     if (x > 1.0 + eps) { n       v = z * log(y) + log(log(x)); n       if (res + eps < v) res = v, st =  x^y^z ; n       v = y * log(z) + log(log(x)); n       if (res + eps < v) res = v, st =  x^z^y ; n       v = log(y) + log(z) + log(log(x)); n       if (res + eps < v) res = v, st =  (x^y)^z ; n     } n     if (y > 1.0 + eps) { n       v = z * log(x) + log(log(y)); n       if (res + eps < v) res = v, st =  y^x^z ; n       v = x * log(z) + log(log(y)); n       if (res + eps < v) res = v, st =  y^z^x ; n       v = log(x) + log(z) + log(log(y)); n       if (res + eps < v) res = v, st =  (y^x)^z ; n     } n     if (z > 1.0 + eps) { n       v = y * log(x) + log(log(z)); n       if (res + eps < v) res = v, st =  z^x^y ; n       v = x * log(y) + log(log(z)); n       if (res + eps < v) res = v, st =  z^y^x ; n       v = log(x) + log(y) + log(log(z)); n       if (res + eps < v) res = v, st =  (z^x)^y ; n     } n     cout << st << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ans = 0; n   string s; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  1 ) n       ans += 10; n     else if (s[i] ==  A ) n       ans += 1; n     else n       ans += s[i] -  0 ; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100005], b[100005], difs, f, s; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b, b + n); n   for (int i = 0; i < n; i++) n     if (a[i] != b[i]) difs++; n   if (difs > 2) { n     cout <<  NO ; n     return 0; n   } else { n     cout <<  YES ; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n using namespace std; n const int maxn = 3e5 + 5; n const int maaxn = 1e7 + 2; n const int minn = 22; n const long long mod = 1e9 + 7; n const long double pi = 3.141592653589793238462643383279; n long long binpow(long long a, long long p) { n   if (p == 0) return 0; n   if (p % 2 == 1) return (a + binpow(a, p - 1)) % mod; n   long long b = binpow(a, p / 2); n   return (b + b) % mod; n } n int a[maxn]; n vector<int> dv[maxn]; n vector<int> hop[maaxn]; n int cnt[maaxn]; n bool sh(int &c, int &b) { return a[c] < a[b]; } n void solve() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     for (int j = 2; j * j <= a[i]; j++) { n       if (a[i] % j == 0) { n         dv[i].push_back(j); n         cnt[j]++; n         hop[j].push_back(i); n         if (j * j != a[i]) n           dv[i].push_back(a[i] / j), cnt[a[i] / j]++, n               hop[a[i] / j].push_back(i); n       } n     } n   } n   for (int i = 2; i < maaxn; i++) { n     if (cnt[i] >= k) { n       for (int j = 0; j < k; j++) { n         cout << (hop[i][j] + 1) <<    ; n       } n       cout << endl; n       return; n     } n   } n   int ma = 0; n   int p = 0; n   for (int i = 2; i < maaxn; i++) { n     if (hop[i].size() > ma) { n       ma = hop[i].size(); n       p = i; n     } n   } n   vector<int> answ; n   unordered_set<int> tv; n   for (int i = 0; i < hop[p].size(); i++) tv.insert(hop[p][i]); n   for (int i = 0; i < n; i++) { n     if (tv.count(i) == 0) answ.push_back(i); n   } n   sort(answ.begin(), answ.end(), sh); n   for (int i = 0; i < k; i++) cout << answ[i] + 1 <<    ; n   return; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   cin >> t; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int p = 1e9 + 7; n struct Matrix { n   int n, m; n   long long a[105][105]; n   Matrix(int x, int y) { n     n = x, m = y; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) a[i][j] = 0; n     } n   } n   void init() { n     for (int i = 1; i <= min(n, m); i++) a[i][i] = 1; n   } n   void print() { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) cout << a[i][j] <<    ; n       cout << endl; n     } n     cout << endl; n   } n }; n Matrix operator*(Matrix a, Matrix b) { n   Matrix c = Matrix(a.n, b.m); n   for (int i = 1; i <= a.n; i++) { n     for (int j = 1; j <= b.m; j++) { n       for (int k = 1; k <= a.m; k++) { n         c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j] % p) % p; n       } n     } n   } n   return c; n } n Matrix qpow(Matrix a, long long b) { n   Matrix res = Matrix(a.n, a.m); n   res.init(); n   while (b) { n     if (b & 1) res = res * a; n     a = a * a; n     b >>= 1; n   } n   return res; n } n long long n, m, k; n int main() { n   cin >> n >> m >> k; n   Matrix f = Matrix(m, m); n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= m; j++) f.a[i][j] = 1; n   } n   string s; n   int x, y, z; n   while (k--) { n     cin >> s; n     if (s[0] <=  Z  && s[0] >=  A ) n       x = s[0] -  A  + 27; n     else n       x = s[0] -  a  + 1; n     if (s[1] <=  Z  && s[1] >=  A ) n       y = s[1] -  A  + 27; n     else n       y = s[1] -  a  + 1; n     f.a[x][y] &= 0; n   } n   Matrix ans = Matrix(1, m); n   for (int i = 1; i <= m; i++) ans.a[1][i] = 1; n   f = qpow(f, n - 1); n   ans = ans * f; n   long long res = 0; n   for (int i = 1; i <= m; i++) res += ans.a[1][i], res %= p; n   cout << res << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n #define pb push_back n using namespace std; n typedef long long ll; n  n void solve() n { n     int n; n     cin >> n; n     int adad[n]; n     map<int, int> cnt; n     for (int i = 0; i < n; i++) n     { n         cin >> adad[i]; n         cnt[adad[i]]++; n     } n     int mini; n     mini = *min_element(adad, adad + n); n     cout << n - cnt[mini] << endl; n } n  n int main() n { n     ios::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n     int t; n     cin >> t; n     while (t--) n     { n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n inline void writeln2() { cout <<   n ; } n inline void writeln() { cout <<   n ; } n inline void readln() {} n template <typename T> n inline void read(T&); n template <typename T> n inline void priws(T); n template <typename T> n inline void print(T); n void err(vector<string>::iterator it) { ++it; } n template <typename Head, typename... Tail> n inline void readln(Head& head, Tail&... tail) { n   read(head); n   readln(tail...); n } n template <typename Head, typename... Tail> n inline void writeln2(Head head, Tail... tail) { n   print(head); n   writeln2(tail...); n } n template <typename Head, typename... Tail> n inline void writeln(Head head, Tail... tail) { n   priws(head); n   writeln2(tail...); n } n template <typename T> n inline void writeln_range(T f, T s) { n   if (f != s) n     for (auto i = f; i != s; ++i) writeln(*i); n } n template <typename Head, typename... Tail> n inline void err(vector<string>::iterator it, Head head, Tail... tail) { n   writeln((*it).substr((*it)[0] ==    ),  = , head); n   err(++it, tail...); n } n vector<string> split(const string& s, char c) { n   vector<string> v; n   stringstream ss(s); n   string x; n   while (getline(ss, x, c)) v.push_back(x); n   return move(v); n } n void printAnsAndExit(long long ans) { n   writeln(ans); n   exit(0); n } n vector<vector<int>> g; n vector<bool> used; n int cc = 0; n int dfs(int u) { n   used[u] = true; n   int ok = 0; n   for (int i = 0; i < (int)(g[u].size()); ++i) n     if (!used[g[u][i]]) ok += dfs(g[u][i]); n   if (ok >= 3) n     cc += 2, ok = 0; n   else { n     if (ok == 2) n       cc += 2, ok = 0; n     else { n       if (ok == 1) cc++; n       ok = 1; n     } n   } n   return ok; n } n void run() { n   int n, x, y; n   readln(n, x, y); n   vector<pair<int, int>> a(n - 1); n   readln(a); n   vector<int> deg(n + 1, 0); n   g.resize(n); n   used.resize(n); n   for (int i = 0; i < (int)(n - 1); ++i) n     deg[a[i].first - 1]++, deg[a[i].second - 1]++, n         g[a[i].first - 1].push_back(a[i].second - 1), n         g[a[i].second - 1].push_back(a[i].first - 1); n   if (x > y) { n     for (int i = 0; i < (int)(deg.size()); ++i) n       if (deg[i] == n - 1) printAnsAndExit(x + (n - 2) * 1ll * y); n     printAnsAndExit((n - 1) * 1ll * y); n   } n   dfs(0); n   writeln(cc * 1ll * x + (n - cc - 1) * 1ll * y); n } n int main() { n   ios_base::sync_with_stdio(false); n   run(); n   return 0; n } n template <typename T> n inline ostream& operator<<(ostream& os, vector<T>& _a); n template <typename T1, typename T2> n inline istream& operator>>(istream& is, pair<T1, T2>& _a) { n   return is >> _a.first >> _a.second; n } n template <typename T1, typename T2> n inline ostream& operator<<(ostream& os, pair<T1, T2>& _a) { n   return os << _a.first <<     << _a.second; n } n template <typename T> n inline ostream& operator<<(ostream& os, vector<T>& _a) { n   if (_a.size()) n     os << _a[0]; n   else n     os <<   n ; n   for (int i = 1; i < _a.size(); ++i) n     os <<   n  [is_fundamental<T>::value] << _a[i]; n   return os; n } n template <typename T> n inline istream& operator>>(istream& is, vector<T>& _a) { n   if (_a.size() == 0) { n     int _n; n     is >> _n; n     _a.resize(_n); n   } n   for (int i = 0; i < _a.size(); ++i) is >> _a[i]; n   return is; n } n template <typename T> n inline void print(T _a) { n   cout <<     << _a; n } n template <typename T> n inline void priws(T _a) { n   cout << _a; n } n template <typename T> n inline void read(T& _a) { n   cin >> _a; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> marc[100010]; n int input(void) { n   int x; n   scanf( %d , &x); n   return x; n } n int main() { n   int n = input(); n   for (int i = 0; i < (n); i++) { n     int x = input(), k = input(); n     if (x == 0) { n       marc[k].insert(0); n     } else { n       if (marc[k].find(x - 1) != marc[k].end()) { n         marc[k].insert(x); n       } else { n         cout <<  NO n ; n         return 0; n       } n     } n   } n   cout <<  YES n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Time { n   long long deno, num; n   inline long long gcd(long long a, long long b) { n     return !b ? a : gcd(b, a % b); n   } n   inline void simplify() { n     long long g = gcd(abs(deno), abs(num)); n     deno /= g; n     num /= g; n     if (deno < 0) { n       deno *= -1; n       num *= -1; n     } n   } n   Time() {} n   Time(long long n, long long d) : num(n), deno(d) { simplify(); } n   inline bool operator<(const Time &t) const { n     return num * t.deno < t.num * deno; n   } n   inline bool operator!=(const Time &t) const { n     return num * t.deno != t.num * deno; n   } n }; n pair<Time, Time> s[100010]; n pair<Time, int> ds[100010]; n int d[100010]; n struct BIT { n   int f[100010]; n   BIT() { fill(f, f + 100010, 0); } n   inline int lowbit(int x) { return (x & -x); } n   inline void add(int p, int v) { n     for (++p; p < 100010; p += lowbit(p)) f[p] += v; n   } n   inline int sum(int p) { n     int ret = 0; n     for (++p; p; p -= lowbit(p)) ret += f[p]; n     return ret; n   } n   inline int sum(int l, int r) { return sum(r) - sum(l - 1); } n } bit; n int n, w; n long long v, x; n int main() { n   cin >> n >> w; n   for (int i = 0; i < n; i++) { n     cin >> x >> v; n     s[i] = make_pair(Time(-x, v - w), Time(-x, v + w)); n   } n   for (int i = 0; i < n; i++) s[i].second.num *= -1; n   sort(s, s + n); n   for (int i = 0; i < n; i++) s[i].second.num *= -1; n   for (int i = 0; i < n; i++) ds[i] = make_pair(s[i].second, i); n   sort(ds, ds + n); n   for (int i = 0, rk = -1; i < n; i++) { n     if (!i || ds[i].first != ds[i - 1].first) rk++; n     d[ds[i].second] = rk; n   } n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     ans += bit.sum(d[i], 100010 - 1); n     bit.add(d[i], 1); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int par1[10008]; n int par2[10008]; n vector<pair<int, int>> result; n int find1(int r) { n   if (par1[r] == r) n     return r; n   else n     return par1[r] = find1(par1[r]); n } n int find2(int r) { n   if (par2[r] == r) n     return r; n   else n     return par2[r] = find2(par2[r]); n } n int main() { n   int i, j, t, n, m1, m2, p, q, res = 0, uu, vv, uu2, vv2; n   cin >> n >> m1 >> m2; n   for (i = 1; i <= n; i++) { n     par1[i] = i; n     par2[i] = i; n   } n   for (i = 0; i < m1; i++) { n     cin >> p >> q; n     uu = find1(p); n     vv = find1(q); n     par1[uu] = vv; n   } n   for (i = 0; i < m2; i++) { n     cin >> p >> q; n     uu2 = find2(p); n     vv2 = find2(q); n     par2[uu2] = vv2; n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       uu = find1(i); n       vv = find1(j); n       uu2 = find2(i); n       vv2 = find2(j); n       if ((uu != vv) && (uu2 != vv2)) { n         res++; n         par1[uu] = vv; n         par2[uu2] = vv2; n         result.push_back({i, j}); n       } n     } n   } n   cout << res << endl; n   for (i = 0; i < result.size(); i++) { n     cout << result[i].first <<     << result[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e17 + 10; n const int N = 1e4 + 10; n const long long mod = 998244353; n map<string, int> ml; n int c[N], vis[N], a[N], t, n, m, x, y, k, dp[N][105]; n char s[N]; n int ex, ey, cnt; n long long dist[N]; n vector<pair<int, int> > v; n map<int, int> mp; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     mp[a[i]]++; n   } n   for (auto p : mp) v.push_back(p); n   if (v.size() == 2) return cout << n << endl, 0; n   dp[0][0] = 1; n   for (auto p : v) { n     int cost = p.first; n     int k = p.second; n     for (int i = N; i >= 0; i--) n       for (int j = 1; j <= n; j++) n         for (int t = 1; t <= k && t <= j && t * cost <= i; t++) n           dp[i][j] += dp[i - t * cost][j - t]; n   } n   int ans = 1; n   for (auto p : v) { n     int cost = p.first; n     int k = p.second; n     for (int i = 1; i <= k; i++) { n       if (dp[i * cost][i] == 1) ans = max(ans, i); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   vector<pair<int, int> > a; n   vector<int> b; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int t; n     scanf( %d , &t); n     if (t & 1) { n       int spd = 0; n       if (t != 5) scanf( %d , &spd); n       a.push_back({t, spd}); n     } else { n       b.push_back(t); n     } n   } n   int res = 0; n   int spd = 0; n   vector<int> lim; n   lim.push_back(1e9); n   for (pair<int, int> p : a) { n     if (p.first == 1) { n       spd = p.second; n       while (spd > lim.back()) { n         lim.pop_back(); n         res++; n       } n     } n     if (p.first == 3) { n       if (spd <= p.second) n         lim.push_back(p.second); n       else n         res++; n     } n     if (p.first == 5) lim.push_back(1e9); n   } n   vector<bool> allowed; n   allowed.push_back(1); n   for (int p : b) { n     if (p == 2) { n       while (!allowed.back()) { n         allowed.pop_back(); n         res++; n       } n     } n     if (p == 4) allowed.push_back(1); n     if (p == 6) allowed.push_back(0); n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, j, k, t, l, r, n, m, p, a, b, c, d, flag; n   cin >> t; n   while (t--) { n     cin >> n; n     for (i = 0; i < n; i++) { n       cout << (i + 1) <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 0; n   char ch = getchar(); n   while (!isdigit(ch)) f |= ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); n   return f ? -x : x; n } n int main() { n   int n = read(), ans = 0; n   for (int i = 1; i <= n; ++i) ans += read() * i; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, t, i, k, tam; n int main() { n   while (scanf( %I64d , &n) > 0) { n     t = 0; n     tam = 0; n     for (i = 0; i < n; i++) { n       scanf( %I64d , &k); n       if (k % 2 != 0) { n         tam = k; n       } n       t += k; n     } n     if (t % 2 != 0) { n       printf( First n ); n     } else { n       if ((t - tam) % 2 != 0) n         printf( First n ); n       else n         printf( Second n ); n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:336777216 ) n using namespace std; n int IT_MAX = 1 << 17; n int MOD = 1000000007; n const int INF = 0x3f3f3f3f; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1); n const double ERR = 1e-10; n long long dp[1050][10050]; n long long C[10050]; n long long cost[10050]; n int main() { n   int N, W, B, X, i, j, k; n   scanf( %d %d %d %d , &N, &W, &B, &X); n   for (i = 1; i <= N; i++) scanf( %lld , &C[i]); n   for (i = 1; i <= N; i++) scanf( %lld , &cost[i]); n   for (i = 0; i <= N; i++) n     for (j = 0; j <= 10000; j++) dp[i][j] = -LL_INF; n   dp[0][0] = W; n   for (i = 1; i <= N; i++) { n     for (j = 0; j <= 10000; j++) { n       long long v = dp[i - 1][j]; n       if (v < 0) continue; n       long long mx = C[i]; n       if (cost[i]) mx = min(mx, v / cost[i]); n       for (k = 0; k <= mx; k++) n         dp[i][j + k] = max(dp[i][j + k], dp[i - 1][j] - cost[i] * k); n     } n     for (j = 0; j <= 10000; j++) n       if (dp[i][j] >= 0) dp[i][j] = min(dp[i][j] + X, (long long)B * j + W); n   } n   int ans = 0; n   for (i = 1; i <= 10000; i++) n     if (dp[N][i] >= 0) ans = max(ans, i); n   return !printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename flow_t, typename cost_t> n struct min_cost_flow { n   const cost_t COST_INF = numeric_limits<cost_t>::max() / 2; n   struct edge { n     int node, rev; n     flow_t capacity; n     cost_t cost; n     edge() {} n     edge(int _node, int _rev, flow_t _capacity, cost_t _cost) n         : node(_node), rev(_rev), capacity(_capacity), cost(_cost) {} n   }; n   int V = -1, E = 0; n   vector<vector<edge>> adj; n   vector<cost_t> dist; n   vector<int> prev; n   vector<edge *> prev_edge; n   bool too_many_bellman_ford_iterations = false; n   min_cost_flow(int vertices = -1) { n     if (vertices >= 0) init(vertices); n   } n   void init(int vertices) { n     V = vertices; n     E = 0; n     adj.assign(V, {}); n     dist.resize(V); n     prev.resize(V); n     prev_edge.resize(V); n     too_many_bellman_ford_iterations = false; n   } n   void add_directional_edge(int u, int v, flow_t capacity, cost_t cost) { n     assert(0 <= u && u < V && 0 <= v && v < V); n     edge uv_edge(v, adj[v].size() + (u == v ? 1 : 0), capacity, cost); n     edge vu_edge(u, adj[u].size(), 0, -cost); n     adj[u].push_back(uv_edge); n     adj[v].push_back(vu_edge); n     E++; n   } n   edge &reverse_edge(const edge &e) { return adj[e.node][e.rev]; } n   bool bellman_ford(int source, int sink) { n     for (int i = 0; i < V; i++) { n       dist[i] = COST_INF; n       prev[i] = -1; n       prev_edge[i] = nullptr; n     } n     long long work = 0; n     vector<int> last_seen(V, -1); n     vector<int> nodes = {source}, next_nodes; n     dist[source] = 0; n     for (int iteration = 0; iteration < V; iteration++) { n       next_nodes.clear(); n       for (int node : nodes) { n         for (edge &e : adj[node]) n           if (e.capacity > 0 && dist[node] + e.cost < dist[e.node]) { n             dist[e.node] = dist[node] + e.cost; n             prev[e.node] = node; n             prev_edge[e.node] = &e; n             if (last_seen[e.node] != iteration) { n               last_seen[e.node] = iteration; n               next_nodes.push_back(e.node); n             } n           } n         work += adj[node].size(); n       } n       swap(nodes, next_nodes); n     } n     if (work > 1.75 * E * (32 - __builtin_clz(V)) + 100) n       too_many_bellman_ford_iterations = true; n     return prev[sink] != -1; n   } n   struct dijkstra_state { n     cost_t dist; n     int node; n     dijkstra_state() {} n     dijkstra_state(cost_t _dist, int _node) : dist(_dist), node(_node) {} n     bool operator<(const dijkstra_state &other) const { n       return dist > other.dist; n     } n   }; n   void dijkstra_check(int node, cost_t potential_dist, int previous, n                       edge *previous_edge, priority_queue<dijkstra_state> &pq) { n     if (potential_dist < dist[node]) { n       dist[node] = potential_dist; n       prev[node] = previous; n       prev_edge[node] = previous_edge; n       pq.emplace(dist[node], node); n     } n   } n   bool dijkstra(int source, int sink) { n     dist.assign(V, COST_INF); n     prev.assign(V, -1); n     prev_edge.assign(V, nullptr); n     priority_queue<dijkstra_state> pq; n     dijkstra_check(source, 0, -1, nullptr, pq); n     while (!pq.empty()) { n       dijkstra_state top = pq.top(); n       pq.pop(); n       if (top.dist > dist[top.node]) continue; n       for (edge &e : adj[top.node]) n         if (e.capacity > 0) n           dijkstra_check(e.node, top.dist + e.cost, top.node, &e, pq); n     } n     return prev[sink] != -1; n   } n   void reduce_cost() { n     for (int i = 0; i < V; i++) n       for (edge &e : adj[i]) n         if (dist[i] < COST_INF && dist[e.node] < COST_INF) n           e.cost += dist[i] - dist[e.node]; n   } n   vector<pair<flow_t, cost_t>> options; n   pair<flow_t, cost_t> solve_min_cost_flow( n       int source, int sink, flow_t flow_goal = numeric_limits<flow_t>::max()) { n     assert(V >= 0); n     flow_t total_flow = 0; n     cost_t total_cost = 0; n     while (total_flow < flow_goal && bellman_ford(source, sink)) { n       if (too_many_bellman_ford_iterations) break; n       flow_t path_cap = flow_goal - total_flow; n       cost_t cost_sum = 0; n       for (int node = sink; prev[node] != -1; node = prev[node]) n         path_cap = min(path_cap, prev_edge[node]->capacity); n       for (int node = sink; prev[node] != -1; node = prev[node]) { n         edge *e = prev_edge[node]; n         e->capacity -= path_cap; n         reverse_edge(*e).capacity += path_cap; n         cost_sum += e->cost; n       } n       total_flow += path_cap; n       total_cost += cost_sum * path_cap; n       options.emplace_back(total_flow, total_cost); n     } n     if (too_many_bellman_ford_iterations) { n       cost_t reduce_sum = 0; n       do { n         reduce_cost(); n         reduce_sum += dist[sink]; n         flow_t path_cap = flow_goal - total_flow; n         for (int node = sink; prev[node] != -1; node = prev[node]) n           path_cap = min(path_cap, prev_edge[node]->capacity); n         for (int node = sink; prev[node] != -1; node = prev[node]) { n           edge *e = prev_edge[node]; n           assert(e->cost == 0); n           e->capacity -= path_cap; n           reverse_edge(*e).capacity += path_cap; n         } n         total_flow += path_cap; n         total_cost += reduce_sum * path_cap; n         options.emplace_back(total_flow, total_cost); n       } while (total_flow < flow_goal && dijkstra(source, sink)); n     } n     return make_pair(total_flow, total_cost); n   } n }; n int main() { n   int N, M; n   scanf( %d %d , &N, &M); n   min_cost_flow<int, long long> graph(N); n   for (int i = 0; i < M; i++) { n     int u, v, weight; n     scanf( %d %d %d , &u, &v, &weight); n     u--; n     v--; n     graph.add_directional_edge(u, v, 1, weight); n   } n   graph.solve_min_cost_flow(0, N - 1); n   int Q; n   scanf( %d , &Q); n   for (int q = 0; q < Q; q++) { n     int x; n     scanf( %d , &x); n     double answer = 1e100; n     for (auto &option : graph.options) n       answer = min(answer, (double)(option.second + x) / option.first); n     printf( %.7lg n , answer); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int row[1010]; n int main() { n   int n, m, k; n   scanf( %d %d %d , &n, &m, &k); n   memset(row, 0x3f3f3f3f, sizeof row); n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     int r, c; n     scanf( %d %d , &r, &c); n     row[r] = min(c, row[r]); n   } n   for (int i = 1; i <= m; ++i) ans += ((row[i] == 0x3f3f3f3f) ? 0 : row[i]); n   cout << min(ans, (long long)k) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, sol[1000005]; n struct ell { n   int dr, cnt, poz; n   bool operator<(const ell &A) const { return dr < A.dr; } n }; n multiset<ell> Q; n struct el { n   int x, y, flag, cnt, poz; n   bool operator<(const el &A) const { n     if (x == A.x) { n       if (y == A.y) return flag > A.flag; n       return y > A.y; n     } n     return x < A.x; n   } n }; n el a[1000005], b[1000005]; n int main() { n   int i, j, cn; n   ell w; n   cin.sync_with_stdio(0); n   cin >> n; n   cn = n; n   for (i = 1; i <= n; ++i) { n     cin >> a[i].x >> a[i].y; n     a[i].poz = i; n     b[i] = a[i]; n   } n   cin >> m; n   for (i = 1; i <= m; ++i) { n     cin >> a[n + i].x >> a[n + i].y >> a[n + i].cnt; n     a[n + i].flag = 1; n     a[n + i].poz = i; n     b[n + i] = a[n + i]; n   } n   n += m; n   sort(a + 1, a + n + 1); n   for (i = 1; i <= n; ++i) { n     if (a[i].flag) { n       w.dr = a[i].y; n       w.cnt = a[i].cnt; n       w.poz = a[i].poz; n       Q.insert(w); n     } else { n       ell w; n       w.dr = a[i].y; n       multiset<ell>::iterator it = Q.lower_bound(w); n       if (it == Q.end()) { n         printf( NO n ); n         return 0; n       } n       sol[a[i].poz] = it->poz; n       --b[it->poz + cn].cnt; n       if (!b[it->poz + cn].cnt) Q.erase(it); n     } n   } n   cout <<  YES n ; n   for (i = 1; i <= n - m; ++i) cout << sol[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e9 + 1; n int a[201][201]; n int cnt[10][10]; n int calc(int x, int y) { n   if (x * 2 > y) n     return 500; n   else if (x * 4 > y) n     return 1000; n   else if (x * 8 > y) n     return 1500; n   else if (x * 16 > y) n     return 2000; n   else if (x * 32 > y) n     return 2500; n   else n     return 3000; n } n int use[10]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 5; j++) { n       cin >> a[i][j]; n     } n   } n   for (int k = 0; k < 5; k++) { n     if (a[0][k] == -1) n       use[k] = 0; n     else if (a[1][k] == -1 || (a[1][k] != -1 && a[1][k] > a[0][k])) n       use[k] = -1; n     else n       use[k] = 1; n   } n   for (int t = 0; t < 50000; t++) { n     int sc1 = 0, sc0 = 0; n     for (int i = 0; i < 5; i++) { n       long long x = 0, y = 0; n       for (int j = 0; j < n; j++) { n         if (a[j][i] != -1) x++; n       } n       if (use[i] == 1) x += t; n       y = n + t; n       if (a[0][i] != -1) { n         sc0 += calc(x, y) * (250 - a[0][i]); n       } n       if (a[1][i] != -1) { n         sc1 += calc(x, y) * (250 - a[1][i]); n       } n     } n     if (sc0 > sc1) { n       cout << t << endl; n       return 0; n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   if (b > a) swap(a, b); n   if (a % b == 0) n     return b; n   else n     return gcd(b, a % b); n } n long long int a, b, k, k1, k2; n int main() { n   cin >> a >> b; n   k = (a * b) / gcd(a, b); n   k1 = k / a; n   k2 = k / b; n   if (abs(k1 - k2) == 1) n     cout <<  Equal ; n   else if (k1 > k2) n     cout <<  Dasha ; n   else n     cout <<  Masha ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXH = 1000000; n const int MAXW = 1000000; n const int MAXN = 100000; n const int MOD = 1000000007; n typedef struct R { n   int x1, y1, x2, y2; n } R; n int h, w, n; n int shead[MAXH], snxt[MAXN]; n int thead[MAXH], tnxt[MAXN]; n R r[MAXN]; n int cur[MAXN], ncur; n int sval[4 * MAXW]; n int slazy[4 * MAXW]; n inline void inc(int &a, int b) { n   if ((a += b) >= MOD) a -= MOD; n } n void spush(int x) { n   if (sval[x] != -1) { n     sval[2 * x + 1] = sval[2 * x + 2] = sval[x]; n     slazy[2 * x + 1] = slazy[2 * x + 2] = 0; n     sval[x] = -1; n   } n   if (slazy[x] != 0) { n     inc(slazy[2 * x + 1], slazy[x]), inc(slazy[2 * x + 2], slazy[x]); n     slazy[x] = 0; n   } n } n void sset(int x, int l, int h, int L, int H, int VAL) { n   if (h < L || l > H) return; n   if (L <= l && h <= H) { n     sval[x] = VAL, slazy[x] = 0; n     return; n   } n   spush(x); n   int m = l + (h - l) / 2; n   sset(2 * x + 1, l, m, L, H, VAL); n   sset(2 * x + 2, m + 1, h, L, H, VAL); n } n void sinc(int x, int l, int h, int L, int H, int BY) { n   if (h < L || l > H) return; n   if (L <= l && h <= H) { n     inc(slazy[x], BY); n     return; n   } n   spush(x); n   int m = l + (h - l) / 2; n   sinc(2 * x + 1, l, m, L, H, BY); n   sinc(2 * x + 2, m + 1, h, L, H, BY); n } n int sget(int x, int l, int h, int IDX) { n   if (sval[x] != -1) return sval[x] + slazy[x]; n   spush(x); n   int m = l + (h - l) / 2; n   return IDX <= m ? sget(2 * x + 1, l, m, IDX) : sget(2 * x + 2, m + 1, h, IDX); n } n void run() { n   scanf( %d%d%d , &h, &w, &n); n   for (int x = (0); x < (h); ++x) shead[x] = thead[x] = -1; n   for (int i = (0); i < (n); ++i) { n     scanf( %d%d%d%d , &r[i].x1, &r[i].y1, &r[i].x2, &r[i].y2); n     --r[i].x1, --r[i].y1, --r[i].x2, --r[i].y2; n     snxt[i] = shead[r[i].x1], shead[r[i].x1] = i; n     tnxt[i] = thead[r[i].x2], thead[r[i].x2] = i; n   } n   multiset<int> have; n   have.insert(w); n   sval[0] = slazy[0] = 0; n   sset(0, 0, w - 1, 0, 0, 1); n   for (int x = (0); x < (h); ++x) { n     for (int z = shead[x]; z != -1; z = snxt[z]) n       sset(0, 0, w - 1, r[z].y1, r[z].y2, 0), have.insert(r[z].y1); n     ncur = 0; n     if (x == 0) n       cur[ncur++] = 0; n     else n       for (int z = thead[x - 1]; z != -1; z = tnxt[z]) { n         if (r[z].y1 != 0) cur[ncur++] = r[z].y1 - 1; n         multiset<int>::iterator it = have.lower_bound(r[z].y1); n         have.erase(it); n       } n     sort(cur, cur + ncur); n     ncur = unique(cur, cur + ncur) - cur; n     for (int i = ncur - 1; i >= 0; --i) { n       int y = cur[i]; n       int val = sget(0, 0, w - 1, y); n       if (val == 0) continue; n       multiset<int>::iterator it = have.lower_bound(y); n       int ny = *it - 1; n       if (y + 1 <= ny) sinc(0, 0, w - 1, y + 1, ny, val); n     } n   } n   int ret = sget(0, 0, w - 1, w - 1); n   printf( %d n , ret); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n template <typename T, typename TT> n inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { n   return os << t.first <<     << t.second; n } n template <typename T> n inline ostream &operator<<(ostream &os, const vector<T> &t) { n   for (auto i : t) os << i <<    ; n   return os; n } n template <typename T> n inline istream &operator>>(istream &is, vector<T> &v) { n   for (T &t : v) is >> t; n   return is; n } n template <typename T1, typename T2> n inline istream &operator>>(istream &is, pair<T1, T2> &t) { n   is >> t.first >> t.second; n   return is; n } n const long long mod = 1e9 + 7; n void solve() { n   int n; n   cin >> n; n   vector<int> val(3 * n), vis(3 * n + 1); n   cin >> val; n   vector<int> loc(3 * n + 1); n   vector<vector<long long> > v(n, vector<long long>(3)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 3; j++) { n       cin >> v[i][j]; n       loc[v[i][j]] = i; n     } n   } n   int k, j = 0; n   cin >> k; n   vector<int> ans, up; n   for (int i = 0; i < loc[k]; i++) { n     for (auto x : v[i]) vis[x] = 1, up.push_back(x); n   } n   while (vis[val[j]]) j++; n   ; n   if (k != val[j]) { n     for (int i = 1; i <= 3 * n; i++) n       if (i != k) cout << i <<    ; n     return; n   } n   for (auto x : v[loc[k]]) n     if (x != k) ans.push_back(x); n   for (int i = loc[k] + 1; i < n; i++) { n     for (auto x : v[i]) ans.push_back(x); n   } n   sort(ans.begin(), ans.begin() + 2); n   sort(ans.begin() + 2, ans.end()); n   sort(up.begin(), up.end()); n   ; n   j = 0; n   for (auto x : ans) { n     while (j < up.size() and up[j] < x) cout << up[j++] <<    ; n     cout << x <<    ; n   } n   cout << vector<long long>(up.begin() + j, up.end()) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   ; n   int T = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


/* n    Author: ChinmayKarnik n    Time: 21:14:26 n    Date: 16-04-2021 n */ n  n #include<bits/stdc++.h> n  n using namespace std; n  n //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n  n typedef enum {BLACK,WHITE,GRAY} color; n  n #define int long long  n #define TESTCASES true n #define FASTIO true n const int maxN = 200009; n const int inf  = (int)1e18 + 1; n int N,K; n int a[maxN]; n  n int p[64]; n  n  n void solve() n { n     int i,j,k; n     vector<int> ans; n  n     cin >> N >> K;  n     int one = 1; n  n     if(N<64) n     { n        if((one<<(N-1))<K) n        { n            cout <<  -1 n ; n            return; n        } n     } n  n     while(N>=64) n     { n         ans.push_back(1); n         N--; n     } n  n     while(N) n     { n         int curr = 1; n         int sub = 0; n         while((curr<=N) && p[N-curr]<K) n         { n             K-=p[N-curr]; n             curr++; n         } n        // curr--; n         N-=curr; n         ans.push_back(curr); n         //K-=(curr-1)*(p[]) n     } n  n     int p = 1; n     vector<int> fin; n  n     for(int x:ans) n     { n         for(i=p+x-1;i>=p;i--) n         { n             fin.push_back(i); n         } n         p=p+x; n     } n      n     for(int x:fin) n     { n         cout << x <<    ; n     } n     cout <<   n ; n      n      n } n  n  n signed main() n { n     if(FASTIO) n     { n         ios_base::sync_with_stdio(false); n         cin.tie(NULL); n     } n     int T = 1; n  n     if(TESTCASES) n     { n         cin >> T; n     } n     int i,j,k; n      n     p[0]=1; n     p[1]=1; n     for(i=2;i<64;i++) n     { n         p[i]=0; n         for(j=0;j<i;j++) n         { n             p[i]+=p[j]; n         } n          n        // cout << p[i] <<    ; n     } n  n     while(T--) n     { n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> v; n   int k, n, fl = 0; n   cin >> n >> k; n   v.resize(n); n   for (int i = 0; i < n; ++i) { n     cin >> v[i]; n     if (v[i] == k) fl = 1; n   } n   int ct = 0; n   if (!fl) { n     v.push_back(k); n     ct++; n     ++n; n   } n   sort(v.begin(), v.end()); n   int p, d = 1e9; n   for (int i = 0; i < v.size(); ++i) { n     if (k == v[i] && abs((n + 1) / 2 - (i + 1)) < d) { n       p = i + 1; n       d = abs((n + 1) / 2 - (i + 1)); n     } n   } n   while (p < (n + 1) / 2) { n     ++ct; n     ++p; n     ++n; n   } n   while (p > (n + 1) / 2) { n     ++ct; n     ++n; n   } n   cout << ct; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long bananaz(long long x, long long y) { n   return (x + 1) * (y + 1) * (x + y) / 2; n } n int main() { n   ios_base::sync_with_stdio(false); n   long long m, b, x = 0, y, max = -1; n   cin >> m >> b; n   y = b; n   while (y >= 0) { n     if (bananaz(x, y) > max) max = bananaz(x, y); n     x++; n     while (y > -1.0 * x / m + b) y--; n   } n   cout << max << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int goal, n, stations; n   scanf( %i%i%i , &goal, &n, &stations); n   vector<pair<int, int> > points; n   points.push_back(make_pair(n, -1)); n   points.push_back(make_pair(goal, 2000000000)); n   for (auto e = 0; e < stations; e++) { n     int a, b; n     scanf( %i%i , &a, &b); n     points.push_back(make_pair(a, b)); n     points.push_back(make_pair(a + n, -b - 1)); n   } n   stable_sort(points.begin(), points.end()); n   multiset<int> sw; n   auto prev = make_pair(0, 0); n   sw.insert(0); n   auto acc = 0LL; n   for (auto e : points) { n     if (sw.empty()) { n       if (e.first != prev.first) { n         acc = -1; n         break; n       } n     } else { n       acc += ((long long)e.first - prev.first) * (*sw.begin()); n     } n     if (e.first == goal) { n       break; n     } n     if (e.second < 0) { n       sw.erase(sw.find(-e.second - 1)); n     } else { n       sw.insert(e.second); n     } n     prev = e; n   } n   printf( %I64d n , acc); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (int)555; n const int mod = (int)1e9 + 7; n const int P = (int)1e6 + 7; n const double pi = acos(-1.0); n int a[maxn][maxn], b[maxn][maxn], n; n vector<vector<int> > base{{1, 2, 4}, {5, 3, 8}, {9, 6, 7}}; n void rec(int n) { n   if (n == 3) { n     for (int i = (0); i <= (n - 1); ++i) n       for (int j = (0); j <= (n - 1); ++j) a[i][j] = base[i][j]; n     return; n   } n   rec(n - 1); n   if (!(n & 1)) { n     int cur = 1; n     for (int i = (n - 1); i >= (1); --i) b[i][n - 1] = cur++; n     for (int i = (n - 1); i >= (0); --i) b[0][i] = cur++; n     for (int i = (1); i <= (n - 1); ++i) n       for (int j = (0); j <= (n - 2); ++j) b[i][j] = cur + a[i - 1][j] - 1; n   } else { n     int cur = 1; n     for (int i = (0); i <= (n - 1); ++i) b[0][i] = cur++; n     for (int i = (1); i <= (n - 1); ++i) b[i][n - 1] = cur++; n     for (int i = (1); i <= (n - 1); ++i) n       for (int j = (0); j <= (n - 2); ++j) b[i][j] = cur + a[i - 1][j] - 1; n   } n   for (int i = (0); i <= (n - 1); ++i) n     for (int j = (0); j <= (n - 1); ++j) a[i][j] = b[i][j]; n } n void solve() { n   scanf( %d , &n); n   if (n <= 2) { n     puts( -1 ); n     return; n   } n   rec(n); n   for (int i = (0); i <= (n - 1); ++i) { n     for (int j = (0); j <= (n - 1); ++j) printf( %d  , a[i][j]); n     puts(  ); n   } n } n int main() { n   int t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n int gcd(int a, int b) { n   if (a == 0) n     return b; n   else n     return (b % a, a); n } n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int a[n]; n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   sort(a, a + n); n   long long tot = 0; n   for (int i = n - 1; i >= 0; i--) { n     tot += a[i]; n     if (tot > sum - tot) { n       cout << n - i << endl; n       return 0; n     } n   } n   return 0; n } n


//#pragma GCC optimize( Ofast ) n #include <bits/stdc++.h> n using namespace std; n typedef long long int ll; n typedef unsigned long long ull; n   n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n ll myRand(ll B) { n  return (ull)rng() % B; n } n  n int main(){ n     cin.tie(nullptr); n     ios::sync_with_stdio(false); n     int n,k; cin >> n >> k; n     vector<int> l(n); n     for(int i=0;i<n;i++){ n         cin >> l[i]; n     } n     sort(l.rbegin(), l.rend()); n     const int N=5e5; n     vector<int> a(N); n     a[0]=1,a[1]=-1; n     int ans=1e9; n     int sum=0; n     for(int i=0,j=0;i<N-1;i++){ n         sum+=a[i]; n         a[i+1]+=a[i]; n         if(sum+a[i+1]>=k){ n             ans=i+1; break; n         } n         while(a[i]>0 and j<n){ n             int u=(l[j]-1)/2; n             int v=l[j]-1-u; n             a[i+2]++; n             a[i+2+u]--; n             a[i+2]++; n             a[i+2+v]--; n             a[i]--; n             sum--; n             j++; n         } n     } n     if(ans==1e9){ n         ans=-1; n     } n     cout << ans << endl; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n const int M = 1e5 + 10; n const int INF = 2147483647; n const int MOD = 1e9 + 7; n int T, n, m; n int sum; n int a[N]; n pair<int, int> b[N]; n long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } n long long qpow(long long base, long long x) { n   long long res = 1; n   while (x) { n     if (x & 1) res *= base; n     base *= base; n     base %= MOD; n     res %= MOD; n     x >>= 1; n   } n   return res; n } n long long qmul(long long a, long long b, long long mod) { n   long long res = 0; n   while (b) { n     if (b & 1) res = (res + a) % mod; n     a = (a + a) % mod; n     b >>= 1; n   } n   return res; n } n void 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; n   } n   exgcd(b, a % b, y, x); n   y -= (a / b) * x; n } n long long getinv(long long x, long long mod) { n   long long x_0, y_0; n   exgcd(x, mod, x_0, y_0); n   return x_0; n } n bool check(int x) { n   if (sum > x) return false; n   vector<int> day(n + 1, 0); n   for (int i = 1; i <= m; i++) { n     int d = b[i].first, item = b[i].second; n     if (d <= x) { n       day[item] = max(day[item], d); n     } n   } n   vector<vector<int>> tmp(200005); n   for (int i = 1; i <= n; i++) { n     if (day[i]) { n       tmp[day[i]].emplace_back(i); n     } n   } n   vector<int> use(n + 1, 0); n   for (int i = 1; i <= n; i++) use[i] = a[i]; n   int cur = 0; n   for (int i = 1; i <= x; i++) { n     ++cur; n     if (i > 200000) continue; n     for (auto &t : tmp[i]) { n       if (cur >= a[t]) { n         cur -= a[t]; n         use[t] = 0; n       } else { n         use[t] -= cur; n         cur = 0; n         break; n       } n     } n   } n   int ss = 0; n   for (int i = 1; i <= n; i++) ss += use[i]; n   return cur >= ss * 2; n } n void solve() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; n   for (int i = 1; i <= m; i++) cin >> b[i].first >> b[i].second; n   int l = 1, r = 1e9; n   while (l < r) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   cout << l << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(nullptr); n   T = 1; n   while (T--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10, P = 998244353; n const double Pi = acos(-1); n inline int read() { n   int x = 0, f = 1, ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar(); n   return x * f; n } n inline int Add(int a, int b) { return a + b >= P ? a + b - P : a + b; } n inline int Sub(int a, int b) { return a - b < 0 ? a - b + P : a - b; } n inline int Mul(int a, int b) { n   long long res = 1ll * a * b; n   return res >= P ? res % P : res; n } n inline int qpow(int a, int b) { n   int res = 1; n   while (b) { n     if (b & 1) res = Mul(res, a); n     a = Mul(a, a); n     b >>= 1; n   } n   return res; n } n int n; n int dp[3][N]; n int cnt, head[N]; n struct Edge { n   int to, nxt; n } edge[N << 1]; n inline void AddEdge(int u, int v) { n   edge[++cnt] = (Edge){v, head[u]}; n   head[u] = cnt; n   return; n } n void solve(int u, int fa) { n   dp[0][u] = dp[2][u] = 1; n   for (int i = head[u], v; i; i = edge[i].nxt) { n     v = edge[i].to; n     if (v == fa) continue; n     solve(v, u); n     dp[0][u] = Mul(dp[0][u], Add(dp[0][v], dp[1][v])); n     dp[1][u] = Add(dp[1][u], n                    Mul(dp[2][v], qpow(Add(dp[0][v], Mul(2, dp[1][v])), P - 2))); n     dp[2][u] = Mul(dp[2][u], Add(dp[0][v], Mul(2, dp[1][v]))); n   } n   dp[1][u] = Mul(dp[1][u], dp[2][u]); n } n signed main() { n   n = read(); n   for (register int i = 2; i <= n; ++i) { n     int a = read(), b = read(); n     AddEdge(a, b), AddEdge(b, a); n   } n   solve(1, 0); n   printf( %d n , Add(dp[0][1], dp[1][1])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 22; n bool visit[2][N]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < N; i++) { n     visit[0][i] = 1; n   } n   for (int i = 0; i < m; i++) { n     int x; n     cin >> x; n     visit[0][x] = 0; n   } n   int ans = 0; n   for (int i = 0; i < (1 << n); i++) { n     if (visit[0][i]) continue; n     visit[0][i] = 1; n     ans++; n     if (!visit[1][i]) { n       visit[1][i] = 1; n       queue<int> q; n       q.push(i); n       while (q.size()) { n         int v = q.front(); n         q.pop(); n         if (visit[0][(1 << n) - v - 1] == 0) { n           visit[0][(1 << n) - v - 1] = 1; n           visit[1][(1 << n) - v - 1] = 1; n           q.push((1 << n) - v - 1); n         } n         for (int j = 0; j < n; j++) { n           if ((v & (1 << j)) == 0 && !visit[1][v | (1 << j)]) { n             q.push(v | (1 << j)); n             visit[1][v | (1 << j)] = 1; n           } n         } n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 2000000000LL; n const long double EPS = 1e-9; n vector<pair<int, int> > clear(vector<pair<int, int> > v) { n   vector<pair<int, int> > ret; n   int tox = v[1].first; n   int x = v[0].first, y = v[0].second; n   while (x <= tox) { n     ret.push_back({x, y}); n     ++x; n   } n   int tx = v[1].first, ty = v[1].second; n   while (ty != y) { n     ret.push_back({tx, ty}); n     (ty > y) ? --ty : ++ty; n   } n   tox = v[2].first; n   int toy = v[2].second; n   int p = v[0].second, q = v[1].second; n   if (p > q) swap(p, q); n   if (v[2].second >= p and v[2].second <= q) { n     while (x <= tox) { n       ret.push_back({x, toy}); n       ++x; n     } n   } else if (v[2].second < p) { n     while (x <= tox) { n       ret.push_back({x, p}); n       ++x; n     } n     while (toy != p) { n       ret.push_back({tox, toy}); n       (toy > p) ? --toy : ++toy; n     } n   } else { n     while (x <= tox) { n       ret.push_back({x, q}); n       ++x; n     } n     while (toy != q) { n       ret.push_back({tox, toy}); n       (toy > q) ? --toy : ++toy; n     } n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   vector<pair<int, int> > v(3); n   for (int i = 0; i < 3; ++i) cin >> v[i].first >> v[i].second; n   sort((v).begin(), (v).end()); n   auto res = clear(v); n   sort((res).begin(), (res).end()); n   res.erase(unique((res).begin(), (res).end()), res.end()); n   cout << res.size() <<   n ; n   for (auto x : res) cout << x.first <<     << x.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n const int inf = 0x3f3f3f3f; n const int mod = 1e9 + 7; n vector<int> ans; n char s1[maxn], s2[maxn]; n int n; n void op(int x) { n   for (int i = 1; i <= x; ++i) { n     s1[i] = s1[i] ==  0  ?  1  :  0 ; n   } n   reverse(s1 + 1, s1 + 1 + x); n   ans.push_back(x); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     cin >> n; n     cin >> s1 + 1 >> s2 + 1; n     ans.clear(); n     for (int i = n; i >= 1; --i) { n       if (s1[i] == s2[i]) continue; n       if (i == 1) n         op(1); n       else { n         if (s1[1] == s2[i]) op(1); n         op(i); n       } n     } n     cout << ((int)ans.size()); n     for (auto &v : ans) cout <<     << v; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e17 + 10; n const int N = 1e6 + 10; n const long long mod = 998244353; n map<string, int> ml; n long long b[N], vis[N], po[N], num[N], t, n, m, x, y, k, a[N]; n long long ex, ey, cnt, ans, sum, flag; n long long dist[N]; n long long dp[N]; n vector<int> v[N]; n map<int, int> mp; n priority_queue<pair<int, int> > q; n priority_queue<pair<int, int> > tq; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; s[i]; i++) { n     a[i] = cnt; n     if (s[i] ==  ( ) n       cnt++; n     else n       cnt--; n     if (a[i - 1] < 0) a[i] = -1; n   } n   cnt = 0; n   for (int i = n - 1; i >= 0; i--) { n     b[i] = cnt; n     if (s[i] ==  ) ) n       cnt++; n     else n       cnt--; n     if (b[i + 1] < 0) b[i] = -1; n   } n   for (int i = 0; s[i]; i++) { n     if (a[i] < 0 && b[i] < 0) return cout << 0 << endl, 0; n     num[i] = a[i] - b[i]; n     if (s[i] ==  (  && num[i] == 1 && a[i] >= 0 && b[i] >= 0) ans++; n     if (s[i] ==  )  && num[i] == -1 && a[i] >= 0 && b[i] >= 0) ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 2e5 + 7; n long long n, k, a, b, q; n long long arr[MAXN]; n void read() { cin >> n >> k >> a >> b >> q; } n long long acnt[MAXN << 2], asum[MAXN << 2], bcnt[MAXN << 2], bsum[MAXN << 2]; n long long getacnt(long long v, long long tl, long long tr, long long l, n                   long long r) { n   if (tr < l || r < tl) return 0; n   if (l <= tl && tr <= r) return acnt[v]; n   long long tm = (tl + tr) >> 1; n   return getacnt(v * 2 + 1, tl, tm, l, r) + n          getacnt(v * 2 + 2, tm + 1, tr, l, r); n } n long long getbcnt(long long v, long long tl, long long tr, long long l, n                   long long r) { n   if (tr < l || r < tl) return 0; n   if (l <= tl && tr <= r) return bcnt[v]; n   long long tm = (tl + tr) >> 1; n   return getbcnt(v * 2 + 1, tl, tm, l, r) + n          getbcnt(v * 2 + 2, tm + 1, tr, l, r); n } n long long getasum(long long v, long long tl, long long tr, long long l, n                   long long r) { n   if (tr < l || r < tl) return 0; n   if (l <= tl && tr <= r) return asum[v]; n   long long tm = (tl + tr) >> 1; n   return getasum(v * 2 + 1, tl, tm, l, r) + n          getasum(v * 2 + 2, tm + 1, tr, l, r); n } n long long getbsum(long long v, long long tl, long long tr, long long l, n                   long long r) { n   if (tr < l || r < tl) return 0; n   if (l <= tl && tr <= r) return bsum[v]; n   long long tm = (tl + tr) >> 1; n   return getbsum(v * 2 + 1, tl, tm, l, r) + n          getbsum(v * 2 + 2, tm + 1, tr, l, r); n } n void updacnt(long long v, long long tl, long long tr, long long p, n              long long x) { n   if (tl == tr) { n     acnt[v] = (arr[p] + x >= a); n     return; n   } n   long long tm = (tl + tr) >> 1; n   if (p <= tm) n     updacnt(v * 2 + 1, tl, tm, p, x); n   else n     updacnt(v * 2 + 2, tm + 1, tr, p, x); n   acnt[v] = acnt[v * 2 + 1] + acnt[v * 2 + 2]; n } n void updbcnt(long long v, long long tl, long long tr, long long p, n              long long x) { n   if (tl == tr) { n     bcnt[v] = (arr[p] + x >= b); n     return; n   } n   long long tm = (tl + tr) >> 1; n   if (p <= tm) n     updbcnt(v * 2 + 1, tl, tm, p, x); n   else n     updbcnt(v * 2 + 2, tm + 1, tr, p, x); n   bcnt[v] = bcnt[v * 2 + 1] + bcnt[v * 2 + 2]; n } n void updasum(long long v, long long tl, long long tr, long long p, n              long long x) { n   if (tl == tr) { n     asum[v] = (arr[p] + x) * (arr[p] + x < a); n     return; n   } n   long long tm = (tl + tr) >> 1; n   if (p <= tm) n     updasum(v * 2 + 1, tl, tm, p, x); n   else n     updasum(v * 2 + 2, tm + 1, tr, p, x); n   asum[v] = asum[v * 2 + 1] + asum[v * 2 + 2]; n } n void updbsum(long long v, long long tl, long long tr, long long p, n              long long x) { n   if (tl == tr) { n     bsum[v] = (arr[p] + x) * (arr[p] + x < b); n     return; n   } n   long long tm = (tl + tr) >> 1; n   if (p <= tm) n     updbsum(v * 2 + 1, tl, tm, p, x); n   else n     updbsum(v * 2 + 2, tm + 1, tr, p, x); n   bsum[v] = bsum[v * 2 + 1] + bsum[v * 2 + 2]; n } n void print() { n   for (long long i = 0; i < q; ++i) { n     long long t; n     cin >> t; n     if (t == 1) { n       long long p, x; n       cin >> p >> x; n       --p; n       updacnt(0, 0, MAXN, p, x); n       updbcnt(0, 0, MAXN, p, x); n       updasum(0, 0, MAXN, p, x); n       updbsum(0, 0, MAXN, p, x); n       arr[p] += x; n     } else { n       long long p; n       cin >> p; n       --p; n       long long sum1 = n           getbcnt(0, 0, MAXN, 0, p - 1) * b + getbsum(0, 0, MAXN, 0, p - 1); n       long long sum2 = getacnt(0, 0, MAXN, p + k, MAXN) * a + n                        getasum(0, 0, MAXN, p + k, MAXN); n       cout << sum1 + sum2 <<   n ; n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   read(); n   print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[1111], b[1111]; n const int inf = 1e9; n map<int, int> mp, mp1; n int nsd(int x, int y) { n   while (x > 0 && y > 0) n     if (x > y) n       x %= y; n     else n       y %= x; n   return x + y; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) cin >> b[i]; n   mp[a[1]] = b[1]; n   for (int i = 2; i <= n; i++) { n     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) { n       int heh = it->first; n       int kok = it->second; n       if (!mp1[heh] || mp1[heh] > kok) mp1[heh] = kok; n       int kek = nsd(a[i], heh); n       if (!mp1[kek] || mp1[kek] > kok + b[i]) mp1[kek] = kok + b[i]; n     } n     mp = mp1; n     mp1.clear(); n     if (!mp[a[i]] || mp[a[i]] > b[i]) mp[a[i]] = b[i]; n   } n   if (mp[1] == 0) n     cout << -1; n   else n     cout << mp[1]; n } n


#include <bits/stdc++.h> n using namespace std; n char s[10], a1[] = { vaporeon }, a2[] = { jolteon }, a3[] = { flareon }, n             a4[] = { espeon }, a5[] = { umbreon }, a6[] = { leafeon }, n             a7[] = { glaceon }, a8[] = { sylveon }; n int n, i; n int main() { n   cin >> n; n   cin >> s; n   if (n == 6) { n     cout << a4; n     return 0; n   } n   if (n == 8) { n     cout << a1; n     return 0; n   } n   for (i = 0; i < n; i++) { n     if (s[i] !=  . ) n       if (s[i] != a2[i]) break; n   } n   if (i == n) { n     cout << a2; n     return 0; n   } n   for (i = 0; i < n; i++) { n     if (s[i] !=  . ) n       if (s[i] != a3[i]) break; n   } n   if (i == n) { n     cout << a3; n     return 0; n   } n   for (i = 0; i < n; i++) { n     if (s[i] !=  . ) n       if (s[i] != a5[i]) break; n   } n   if (i == n) { n     cout << a5; n     return 0; n   } n   for (i = 0; i < n; i++) { n     if (s[i] !=  . ) n       if (s[i] != a6[i]) break; n   } n   if (i == n) { n     cout << a6; n     return 0; n   } n   for (i = 0; i < n; i++) { n     if (s[i] !=  . ) n       if (s[i] != a7[i]) break; n   } n   if (i == n) { n     cout << a7; n     return 0; n   } n   for (i = 0; i < n; i++) { n     if (s[i] !=  . ) n       if (s[i] != a8[i]) break; n   } n   if (i == n) { n     cout << a8; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[600000]; n int main() { n   int n = 6 * 1e5; n   a[0] = 0; n   for (int i = 1; i < n; ++i) { n     int cur = i; n     int t = 0; n     while (cur % 5 == 0) { n       cur /= 5; n       t++; n     } n     a[i] = a[i - 1] + t; n   } n   int m; n   cin >> m; n   vector<int> res; n   for (int i = 1; i < n; ++i) { n     if (a[i] == m) { n       res.push_back(i); n     } n   } n   cout << res.size() << endl; n   for (int i = 0; i < res.size(); ++i) { n     cout << res[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int break_point() { n   char c; n   while ((c = getchar()) !=   n ) n     ; n   return 0; n } n template <typename T> n void read_integer(T &r) { n   bool sign = 0; n   r = 0; n   char c; n   while (1) { n     c = getchar(); n     if (c ==  - ) { n       sign = 1; n       break; n     } n     if (c !=     && c !=   n ) { n       r = c -  0 ; n       break; n     } n   } n   while (1) { n     c = getchar(); n     if (c ==     || c ==   n ) break; n     r = r * 10 + (c -  0 ); n   } n   if (sign) r = -r; n } n long long binpow(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = ret * a; n     a *= a; n     b >>= 1; n   } n   return ret; n } n long long binpow(long long a, long long b, int mod) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = (ret * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return ret; n } n inline int getbit(int x, int b) { return (x >> b) & 1; } n inline int setbit(int x, int b) { return x | (1 << b); } n inline void _setbit(int &x, int b) { x = setbit(x, b); } n inline long long setbit(long long x, int b) { return x | (1ll << b); } n inline void _setbit(long long &x, int b) { x = setbit(x, b); } n inline int unsetbit(int x, int b) { return x & (INT_MAX - (1 << b)); } n inline void _unsetbit(int &x, int b) { x = unsetbit(x, b); } n inline int countbit(int x) { n   x = x - ((x >> 1) & 0x55555555); n   x = (x & 0x33333333) + ((x >> 2) & 0x33333333); n   return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; n } n inline long long countbit(long long x) { n   return countbit(int(x & INT_MAX)) + countbit(int(x >> 31) & INT_MAX); n } n inline void printbit(int x, int len) { n   for (int i = len - 1; i >= 0; i--) printf( %d , getbit(x, i)); n } n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n template <typename A, typename B> n ostream &operator<<(ostream &stream, const pair<A, B> &p) { n   stream <<  {  << p.first <<  ,  << p.second <<  } ; n   return stream; n } n template <typename A> n ostream &operator<<(ostream &stream, const vector<A> &v) { n   stream <<  [ ; n   for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ; n   stream <<  ] ; n   return stream; n } n template <typename A, typename B> n ostream &operator<<(ostream &stream, const map<A, B> &v) { n   stream <<  [ ; n   for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ; n   stream <<  ] ; n   return stream; n } n template <typename A> n ostream &operator<<(ostream &stream, const set<A> &v) { n   stream <<  [ ; n   for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ; n   stream <<  ] ; n   return stream; n } n template <typename A> n ostream &operator<<(ostream &stream, const stack<A> &v) { n   stack<A> st = v; n   stream <<  [ ; n   while (!st.empty()) { n     stream << st.top() <<    ; n     st.pop(); n   } n   stream <<  ] ; n   return stream; n } n template <typename A> n ostream &operator<<(ostream &stream, const priority_queue<A> &v) { n   priority_queue<A> q = v; n   stream <<  [ ; n   while (!q.empty()) { n     stream << q.top() <<    ; n     q.pop(); n   } n   stream <<  ] ; n   return stream; n } n template <typename A> n ostream &operator<<(ostream &stream, const queue<A> &v) { n   queue<A> q = v; n   stream <<  [ ; n   while (!q.empty()) { n     stream << q.front() <<    ; n     q.pop(); n   } n   stream <<  ] ; n   return stream; n } n template <typename A> n ostream &operator<<(ostream &stream, const deque<A> &v) { n   deque<A> q = v; n   stream <<  [ ; n   while (!q.empty()) { n     stream << q.front() <<    ; n     q.pop_front(); n   } n   stream <<  ] ; n   return stream; n } n void run(); n int main() { n   srand(time(NULL)); n   run(); n   return 0; n } n const int mod = 1e9 + 7; n const int N = 1e5 + 7; n struct SegmentTree { n   vector<long long> tr; n   int n; n   SegmentTree(int _n) : n(_n) { tr.resize(n * 4); } n   long long get(int v, int l, int r, int L, int R) { n     if (R < L) return 0; n     if (l == L && r == R) return tr[v]; n     int mid = (l + r) >> 1; n     return max(get(v + v, l, mid, L, min(mid, R)), n                get(v + v + 1, mid + 1, r, max(mid + 1, L), R)); n   } n   long long get(int l, int r) { return get(1, 0, n - 1, l, r); } n   void set(int v, int l, int r, int pos, long long val) { n     if (l == r) n       tr[v] = max((tr[v]), (val)); n     else { n       int mid = (l + r) >> 1; n       if (pos <= mid) n         set(v + v, l, mid, pos, val); n       else n         set(v + v + 1, mid + 1, r, pos, val); n       tr[v] = max(tr[v + v], tr[v + v + 1]); n     } n   } n   void set(int pos, long long val) { set(1, 0, n - 1, pos, val); } n }; n struct tower { n   int a, b, h; n   bool operator<(const tower &other) const { n     if (b == other.b) return a > other.a; n     return b > other.b; n   } n }; n tower tw[N]; n void run() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d%d%d , &tw[i].a, &tw[i].b, &tw[i].h); n   vector<int> p; n   for (int i = 0; i < n; ++i) { n     p.push_back(tw[i].a); n     p.push_back(tw[i].b); n   } n   sort(p.begin(), p.end()); n   int cnt = unique(p.begin(), p.end()) - p.begin(); n   for (int i = 0; i < n; ++i) { n     tw[i].a = upper_bound(p.begin(), p.begin() + cnt, tw[i].a) - p.begin(); n     tw[i].b = upper_bound(p.begin(), p.begin() + cnt, tw[i].b) - p.begin(); n   } n   sort(tw, tw + n); n   SegmentTree tree(cnt + 5); n   for (int i = 0; i < n; ++i) { n     long long H = tree.get(0, tw[i].b - 1) + tw[i].h; n     tree.set(tw[i].a, H); n   } n   printf( %lld , tree.get(0, cnt + 2)); n   putchar(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, k, t; n   cin >> n >> m >> k; n   if (k > n + m - 2) n     cout <<  -1 n ; n   else { n     if (k < max(n, m)) n       cout << max(n * (m / (k + 1)), m * (n / (k + 1))) << endl; n     else n       cout << max(m / (k - n + 2), n / (k - m + 2)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static inline void canhazfast() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n template <typename T> n T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <typename T> n T extgcd(T a, T b, T &x, T &y) { n   T x0 = 1, y0 = 0, x1 = 0, y1 = 1; n   while (b) { n     T q = a / b; n     a %= b; n     swap(a, b); n     x0 -= q * x1; n     swap(x0, x1); n     y0 -= q * y1; n     swap(y0, y1); n   } n   x = x0; n   y = y0; n   return a; n } n static inline int ctz(unsigned x) { return __builtin_ctz(x); } n static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); } n static inline int clz(unsigned x) { return __builtin_clz(x); } n static inline int clzll(unsigned long long x) { return __builtin_clzll(x); } n static inline int popcnt(unsigned x) { return __builtin_popcount(x); } n static inline int popcntll(unsigned long long x) { n   return __builtin_popcountll(x); n } n static inline int bsr(unsigned x) { return 31 ^ clz(x); } n static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); } n int main() { n   canhazfast(); n   int n, m, k; n   int x2, y2, x3, y3; n   long long p, r; n   cin >> n >> m >> k; n   p = 2LL * n * m; n   r = p % k; n   if (r) return cout <<  NO , 0; n   p /= k; n   x2 = n; n   y3 = (p - 1) / n + 1; n   x3 = (long long)x2 * y3 - p; n   y2 = 1; n   cout <<  YES n0 0 n  << x2 <<     << y2 <<   n  << x3 <<     << y3; n   return 0; n } n


#include <bits/stdc++.h> n //#include <ext/pb_ds/assoc_container.hpp> n //#include <ext/pb_ds/tree_policy.hpp>  n using namespace std; n //using namespace __gnu_pbds; n #define rep(i,a,b) for(i=(a);i<=(b);i++) n #define ll long long n #define pll pair<ll, ll> n #define pii pair<int,int> n #define pb push_back n #define F first n #define S second n #define mod 1000000007 n #define maxn 100005 n #define inf 1e18 n #define boost ios::sync_with_stdio(false);cin.tie(0) n #define fr freopen( source.txt , r ,stdin),freopen( output.txt , w ,stdout) n #define SET(a,b) memset(a,b,sizeof(a)) n #define deb(x) cout << #x <<  =  << x << endl n #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl n #define all(x) x.begin(), x.end() n #define ps(x,y) fixed<<setprecision(y)<<x n //template<typename T> n //using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; n template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { n     return out <<   (  << a.F <<  ,   << a.S <<  ) ; n } n   n template<class A> ostream& operator << (ostream& out, const vector<A> &a) { n     out <<  [ ; n     for (auto it = a.begin(); it != a.end(); ++it) { n         if (it != a.begin()) n             out <<  ,  ; n         out << *it; n     } n     return out <<  ] ; n } n void solve(){ n     ll n,i,j,x,t,y; n     cin>>n; n     string s[n]; n     for(i=0;i<n;i++) cin>>s[i]; n     map<ll,ll>mp; n     for(i=0;i<n;i++){ n         for(j=0;j<n;j++){ n             if(s[i][j]!= . ) mp[(i+j)%3]++; n         } n     } n     y=min({mp[0],mp[1],mp[2]}); n     if(mp[0]==y) x=0; n     else if(mp[1]==y) x=1; n     else x=2; n     for(i=0;i<n;i++){ n         for(j=0;j<n;j++){ n             if(s[i][j]!= . &&(i+j)%3==x) s[i][j]= O ; n         } n     } n     for(i=0;i<n;i++) cout<<s[i]<<  n ; n } n int main() n { n     boost; n     ll n,i,j,x,t,y; n     cin>>t; n     while(t--) solve(); n }


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n int vis[10005]; n int main() { n   int n; n   scanf( %d , &n); n   int maxn = -1; n   for (int i = 1; i <= n; i++) { n     int tmp; n     scanf( %d , &tmp); n     vis[tmp]++; n     maxn = max(maxn, tmp); n   } n   long long ans1 = -1, ans2 = -1; n   for (int i = 1; i <= maxn; i++) { n     if (vis[i] != 0) { n       if (i > ans1) { n         ans1 = i; n       } n     } n   } n   for (int i = 1; i <= maxn; i++) { n     if (vis[i] == 2 || (ans1 % i != 0 && vis[i] == 1)) { n       if (i > ans2) { n         ans2 = i; n       } n     } n   } n   printf( %lld %lld n , ans1, ans2); n } n


#include <bits/stdc++.h> n using namespace std; n int ord[100100]; n int inv_ord[100100]; n int dep[100100]; n int fa[100100][17]; n vector<int> g[100100]; n set<int> ss; n int ts; n void dfs(int p, int f) { n   ord[p] = ++ts; n   inv_ord[ord[p]] = p; n   dep[p] = dep[f] + 1; n   fa[p][0] = f; n   for (int i = 0; i < 16; i++) fa[p][i + 1] = fa[fa[p][i]][i]; n   for (int i = 0; i < g[p].size(); i++) n     if (g[p][i] != f) dfs(g[p][i], p); n } n inline int bit(int x, int i) { return (x >> i) & 1; } n int lca(int a, int b) { n   if (dep[a] > dep[b]) swap(a, b); n   for (int i = 0; i < 17; i++) n     if (bit(dep[a] - dep[b], i)) b = fa[b][i]; n   if (a == b) return a; n   for (int i = 16; i >= 0; i--) n     if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i]; n   return fa[a][0]; n } n int calc(int p) { n   if (ss.empty()) return 1; n   set<int>::iterator it = ss.lower_bound(ord[p]); n   int a = inv_ord[it == ss.end() ? *ss.begin() : *it]; n   int b = inv_ord[it == ss.begin() ? *ss.rbegin() : *--it]; n   return dep[p] - dep[lca(a, p)] - dep[lca(b, p)] + dep[lca(a, b)]; n } n int main() { n   int n, k, a, b; n   while (cin >> n >> k) { n     for (int i = 1; i < n; i++) { n       cin >> a >> b; n       g[a].push_back(b); n       g[b].push_back(a); n     } n     ts = 0; n     dfs(1, 0); n     int v = 0; n     int sol = 1; n     for (int i = 1, j = 0; i <= n; i++) { n       while (v <= k) { n         sol = max(sol, j - i + 1); n         if (j == n) break; n         j++; n         v += calc(j); n         ss.insert(ord[j]); n       } n       ss.erase(ord[i]); n       v -= calc(i); n     } n     cout << sol << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool inrange(int y) { return ((y >= 1) && (y <= 9)); } n int main() { n   int r1, r2, c1, c2, d1, d2; n   bool taken[9] = {false}; n   cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; n   int x = (r1 + r2); n   int y = (c1 + c2); n   int z = (d1 + d2); n   int w; n   if (x == y && y == z) { n     if ((r1 + c2 - d1) % 2) { n       cout <<  -1 n ; n       return 0; n     } n     y = (r1 + c2 - d1) / 2; n     if (!inrange(y)) { n       cout <<  -1 n ; n       return 0; n     } n     if (taken[y - 1]) { n       cout <<  -1 n ; n       return 0; n     } else n       taken[y - 1] = true; n     x = r1 - y; n     if (!inrange(x)) { n       cout <<  -1 n ; n       return 0; n     } n     if (taken[x - 1]) { n       cout <<  -1 n ; n       return 0; n     } else { n       taken[x - 1] = true; n     } n     w = d2 - y; n     if (!inrange(w)) { n       cout <<  -1 n ; n       return 0; n     } n     if (taken[w - 1]) { n       cout <<  -1 n ; n       return 0; n     } else { n       taken[w - 1] = true; n     } n     z = c2 - y; n     if (!inrange(z)) { n       cout <<  -1 n ; n       return 0; n     } n     if (taken[z - 1]) { n       cout <<  -1 n ; n       return 0; n     } else { n       taken[z - 1] = true; n     } n     cout << x <<     << y <<   n ; n     cout << w <<     << z <<   n ; n   } else n     cout <<  -1 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n int n; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   int _; n   cin >> _; n   while (_--) { n     cin >> n; n     for (int i = 1; i <= n; i++) { n       cout << i + 1 <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, m; n   cin >> n; n   vector<string> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   cin >> m; n   vector<vector<string>> b(m); n   bool new_problem = 1; n   for (int i = 0; i < m; i++) { n     int k; n     cin >> k; n     b[i].resize(k); n     for (int j = 0; j < k; j++) cin >> b[i][j]; n     int cnt = 0; n     for (int j = 0; j < n; j++) { n       for (int p = 0; p < k; p++) { n         if (a[j] == b[i][p]) { n           cnt++; n           break; n         } n       } n     } n     new_problem &= cnt != n; n   } n   if (new_problem) { n     cout <<  Brand new problem! n ; n     return 0; n   } n   vector<int> p(n); n   iota(p.begin(), p.end(), 0); n   const int INF = 1e9; n   pair<int, int> best = {INF, INF}; n   do { n     int cost = 0; n     for (int i = 1; i < n; i++) { n       for (int j = i - 1; j >= 0; j--) cost += p[i] < p[j]; n     } n     int take = -1; n     for (int i = 0; i < m; i++) { n       int ptr = 0; n       for (int j = 0; j < (int)b[i].size(); j++) { n         if (a[p[ptr]] == b[i][j]) ptr++; n         if (ptr == n) { n           break; n         } n       } n       if (ptr == n) { n         take = i; n         break; n       } n     } n     if (take != -1) { n       if (cost < best.first || (cost == best.first && take < best.second)) n         best = {cost, take}; n     } n   } while (next_permutation(p.begin(), p.end())); n   int x = (n * (n - 1) / 2 - best.first + 1); n   cout << best.second + 1 <<   n ; n   cout <<  [: ; n   while (x) { n     cout <<  | ; n     x--; n   } n   cout <<  :] n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e3 + 3; n long long n, mod = 1e9 + 7, dp[N][N][2]; n long long f(long long idx, long long diff, long long stat) { n   long long &ret = dp[idx][diff][stat]; n   if (ret != -1) return ret; n   if (idx == n) { n     ret = 0; n     return ret; n   } n   ret = 0; n   if (stat == 0) { n     if (n - idx - 1 >= diff + 1) { n       ret = n           (f(idx + 1, diff + 1, 0) + (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) % n           mod; n       ret = max(ret, (f(idx + 1, diff + 1, 1) + 1 + n                       (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) % n                          mod); n       ret = max(ret, (f(idx + 1, diff + 1, 0) + n                       (diff > 0 ? 1 + f(idx + 1, diff - 1, 1) : 0)) % n                          mod); n     } else { n       if (diff > 0) n         ret = max(f(idx + 1, diff - 1, 0), 1 + f(idx + 1, diff - 1, 1)); n       else n         ret = 0; n     } n   } else { n     if (n - idx - 1 >= diff + 1) { n       ret = n           (f(idx + 1, diff + 1, 0) + (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) % n           mod; n     } else { n       if (diff > 0) n         ret = f(idx + 1, diff - 1, 0); n       else n         ret = 0; n     } n   } n   return ret; n } n int main() { n   cin >> n; n   n *= 2; n   for (long long i = 0; i <= n; i++) n     for (long long ii = 0; ii <= n; ii++) n       for (long long iii = 0; iii < 2; iii++) dp[i][ii][iii] = -1; n   cout << f(0, 0, 0) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const long long inf64 = 1e18; n void solve() { n   int n, m; n   cin >> n >> m; n   vector<vector<int>> a(n, vector<int>(m)), b; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) cin >> a[i][j]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int c = 0; n       if (i > 0) c++; n       if (j > 0) c++; n       if (i + 1 < n) c++; n       if (j + 1 < m) c++; n       if (a[i][j] > c) { n         cout <<  NO n ; n         return; n       } n       a[i][j] = c; n     } n   } n   cout <<  YES n ; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << a[i][j] <<    ; n     } n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int tt; n   cin >> tt; n   while (tt--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   ios_base::sync_with_stdio(false); n   int n, x[10], y[10], nx[10], ny[10]; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> nx[i] >> ny[i]; n   int mnx = 1000000, mny = 1000000, mxx = 0, mxy = 0; n   for (int i = 0; i < n; i++) { n     mnx = min(mnx, x[i]); n     mny = min(mny, y[i]); n     mxx = max(mxx, nx[i]); n     mxy = max(mxy, ny[i]); n   } n   long long area = (mxx - mnx) * (mxy - mny); n   long long realarea = 0; n   for (int i = 0; i < n; i++) { n     realarea += (nx[i] - x[i]) * (ny[i] - y[i]); n   } n   if (mxx - mnx == mxy - mny && area == realarea) n     printf( YES ); n   else n     printf( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n int A[1000005], B[1000005], cnt[1000005], num[1000005]; n long long dp[2][1000005]; n int main() { n   int n, k; n   long long l, ans = 0; n   cin >> n >> l >> k; n   if (l <= n) { n     cout << l << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) scanf( %d , &A[i]); n   for (int i = 0; i < n; i++) B[i] = A[i]; n   sort(B, B + n); n   int m = 0, a = 0; n   long long S = l / n; n   for (int i = 0; i < n; i++) { n     a++; n     if (B[i] != B[i + 1] || i == n - 1) { n       B[m] = B[i]; n       cnt[m++] = a; n       a = 0; n     } n   } n   sort(A, A + l % n); n   for (int i = 0; i < m; i++) { n     int t = lower_bound(A, A + l % n, B[i]) - A; n     num[i] = l % n - t; n   } n   dp[0][0] = 1; n   for (int i = 1; i <= min(S, 1LL * k); i++) { n     int cur = i & 1; n     long long sum = 0; n     for (int j = 0; j < n; j++) { n       sum = (sum + dp[!cur][j]) % 1000000007; n       dp[cur][j] = (sum * cnt[j]) % 1000000007; n       ans = (ans + dp[cur][j] * (S % 1000000007 + 1000000007 - i + 1)) % n             1000000007; n       if (i < k) ans = (ans + dp[cur][j] * num[j]) % 1000000007; n     } n   } n   ans = (ans + l % n) % 1000000007; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int n, q[20]; n long long A, B, C, a, b, c, m, m1, ans, v, p[20]; n void dfs1(register int s, long long now) { n   if (now > m) return; n   if (s > n) { n     if (now < a) return; n     b = now; n     c = v / a / b; n     if (a * b + a * c + b * c < ans) n       ans = a * b + a * c + b * c, A = a, B = b, C = c; n     return; n   } n   if (q[s]) q[s]--, dfs1(s, now * p[s]), q[s]++; n   dfs1(s + 1, now); n } n void dfs2(register int s, long long now) { n   if (now > m1) return; n   if (s > n) { n     if (a = now, v / a + 2 * a * sqrt(v / a) < ans) n       m = sqrt(v / a) + 1e-8, dfs1(1, 1); n     return; n   } n   if (q[s]) q[s]--, dfs2(s, now * p[s]), q[s]++; n   dfs2(s + 1, now); n } n int main() { n   for (register int T, x = scanf( %d , &T); T--;) { n     scanf( %d , &n); n     for (register int i = v = 1; i <= n; i++) { n       scanf( %lld%d , &p[i], &q[i]); n       for (register int j = 1; j <= q[i]; j++) v *= p[i]; n     } n     ans = 5e18; n     A = 0; n     m1 = pow(v, 1. / 3) + 1e-8; n     dfs2(1, 1); n     printf( %lld %lld %lld %lld n , ans * 2, A, B, C); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } n long long power(long long x, long long p) { n   if (p == 0) return 1; n   if (p == 1) return x; n   if (p % 2) return x * power(x, p - 1); n   long long y = power(x, p / 2); n   return y * y; n } n void solve() { n   long long n; n   cin >> n; n   long long arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   pair<long long, long long> modd, meven; n   long long odd = 0, even = 0, l = -1, r = -1, res = 0; n   for (int i = 0; i < n; i++) { n     if (i % 2) n       odd += arr[i]; n     else n       even += arr[i]; n     long long cur = odd - even; n     pair<long long, long long> p; n     if (i % 2) n       p = meven; n     else n       p = modd; n     long long val = cur - p.first; n     if (val > res) { n       l = p.second; n       r = i; n       res = val; n     } n     long long x = odd - even + arr[i] * (i % 2 ? -1 : 1); n     if (i % 2 == 0) { n       if (x < meven.first) meven = make_pair(x, i); n     } else { n       if (x < modd.first) modd = make_pair(x, i); n     } n   } n   if (l != -1) { n     for (int i = 0; i < (r - l + 1) / 2; i++) { n       swap(arr[l + i], arr[r - i]); n     } n   } n   odd = 0; n   even = 0; n   for (int i = 0; i < n; i++) { n     if (i % 2) n       odd += arr[i]; n     else n       even += arr[i]; n   } n   cout << max(odd, even) << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5001, M = 1e9 + 7; n int n, F, vis[maxn], T = 1, mid, a[maxn], b[maxn], w[maxn][maxn], ans = 1; n vector<int> g[maxn]; n bool C[maxn]; n bool dfs(int v) { n   vis[v] = T; n   for (int i = 0; i < g[v].size(); i++) n     if (vis[g[v][i]] != T) { n       C[g[v][i]] = !C[v]; n       if (!dfs(g[v][i])) return false; n     } else if (C[g[v][i]] == C[v]) n       return false; n   return true; n } n inline bool check(int x) { n   for (int i = 1; i <= n; i++) g[i].resize(0); n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) n       if (w[i][j] > x) g[i].push_back(j), g[j].push_back(i); n   T++; n   for (int i = 1; i <= n; i++) n     if (vis[i] != T) n       if (!dfs(i)) return false; n   return true; n } n inline void bs(int f, int l) { n   while (f != l) { n     mid = (f + l) / 2; n     if (check(mid)) n       l = mid; n     else n       f = mid + 1; n   } n   check(f); n   F = f; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i); n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) n       w[i][j] = abs(a[i] - a[j]) + abs(b[i] - b[j]); n   bs(0, 7500); n   T++; n   ans = 1; n   for (int i = 1; i <= n; i++) n     if (vis[i] != T) dfs(i), ans = (ans << 1) % M; n   printf( %d n%d n , F, ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[200005]; n long long eff[200005]; n long long dp[200005][2]; n long long dfs(int src, int polarity) { n   long long &ret = dp[src][polarity]; n   if (ret != -1) return ret; n   if (adj[src].size() == 0) return ret = eff[src] * polarity; n   long long sumE = 0; n   vector<long long> even(adj[src].size()), diff(adj[src].size()); n   for (int i = 0; i < adj[src].size(); i++) { n     even[i] = dfs(adj[src][i], 0); n     sumE += even[i]; n     diff[i] = dfs(adj[src][i], 1) - even[i]; n   } n   sort(diff.begin(), diff.end()); n   vector<long long> temp = diff; n   long long bestEvenFromChildren = sumE, bestOddFromChildren = sumE; n   while (temp.size() >= 2 && temp.back() + temp[temp.size() - 2] > 0) { n     bestEvenFromChildren += temp.back(); n     temp.pop_back(); n     bestEvenFromChildren += temp.back(); n     temp.pop_back(); n   } n   temp = diff; n   bestOddFromChildren += temp.back(); n   temp.pop_back(); n   while (temp.size() >= 2 && temp.back() + temp[temp.size() - 2] > 0) { n     bestOddFromChildren += temp.back(); n     temp.pop_back(); n     bestOddFromChildren += temp.back(); n     temp.pop_back(); n   } n   if (polarity == 0) n     return ret = bestEvenFromChildren; n   else n     return ret = max(bestEvenFromChildren + eff[src], bestOddFromChildren); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   memset(dp, -1, sizeof dp); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int p, e; n     cin >> p >> eff[i]; n     if (p != -1) adj[p].push_back(i); n   } n   cout << max(dfs(1, 0), dfs(1, 1)) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, i, d[100005], x, y, a, b, c, r; n int main() { n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     cin >> x >> y; n     d[x]++; n     d[y]++; n   } n   for (i = 1; i <= n; i++) { n     if (d[i] == 1) a++; n     if (d[i] == 2) b++; n     if (d[i] == n - 1) n       c++; n     else n       r++; n   } n   if (a == 2 && b == n - 2) { n     cout <<  bus topology ; n     return 0; n   } n   if (a == n - 1 && c == 1) { n     cout <<  star topology ; n     return 0; n   } n   if (b == n) { n     cout <<  ring topology ; n     return 0; n   } n   cout <<  unknown topology ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mult(int a, int b) { return ((long long)a * b) % 1000000007; } n int binaryPow(int n, int p) { n   int acc = 1; n   while (p) { n     if (p & 1) acc = mult(acc, n); n     n = mult(n, n); n     p >>= 1; n   } n   return acc; n } n int modularInv(int n) { return binaryPow(n, 1000000007 - 2); } n int main() { n   int k, a, b; n   cin >> k >> a >> b; n   int pa = mult(a, modularInv(a + b)); n   int pb = mult(b, modularInv(a + b)); n   int modPB = modularInv(pb); n   int dp[k + 1][k + 1]; n   for (int i = k; i >= 1; i--) { n     for (int j = k; j >= 0; j--) { n       if (i + j < k) { n         dp[i][j] = n             (mult(pa, dp[i + 1][j]) + mult(pb, dp[i][i + j])) % 1000000007; n       } else { n         dp[i][j] = (i + j + mult(pa, modPB)) % 1000000007; n       } n     } n   } n   cout << dp[1][0] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int MOD; n struct Modint { n   int val; n   Modint(int nval = 0) { val = nval % MOD; } n   Modint& operator+=(Modint r) { n     val = (val + r.val) % MOD; n     return *this; n   } n   Modint operator+(Modint r) { return Modint(*this) += r; } n   Modint& operator-=(Modint r) { n     val = (val + MOD - r.val) % MOD; n     return *this; n   } n   Modint operator-(Modint r) { return Modint(*this) -= r; } n   Modint& operator*=(Modint r) { n     val = 1LL * val * r.val % MOD; n     return *this; n   } n   Modint operator*(Modint r) { return Modint(*this) *= r; } n }; n int main() { n   int n, k; n   cin >> n >> k >> MOD; n   static Modint dp[1001][100]; n   static Modint from_end[1001]; n   from_end[0] = 1; n   from_end[1] = 9; n   for (int i = 2; i <= n; i++) { n     from_end[i] = from_end[i - 1] * 10; n   } n   Modint result = 0; n   for (int i = 1; i < 10; i++) { n     dp[1][i % k] += 1; n   } n   int tpow = 10 % k; n   for (int i = 1; i < n; i++) { n     for (int s = 1; s < k; s++) { n       for (int m = 0; m < 10; m++) { n         dp[i + 1][(s + tpow * m) % k] += dp[i][s]; n       } n     } n     for (int m = 1; m < 10; m++) { n       dp[i + 1][tpow * m % k] += 1; n     } n     tpow = (tpow * 10) % k; n   } n   for (int i = 1; i <= n; i++) { n     result += dp[i][0] * from_end[n - i]; n   } n   cout << result.val <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long powmod(long long a, long long b, long long p) { n   long long res = 1; n   a %= p; n   while (b) { n     if (b & 1) res = res * a % p; n     a = a * a % p; n     b >>= 1; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n void solve() { n   int n, m; n   cin >> n >> m; n   vector<string> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   string ans = v[0]; n   for (int j = 0; j < m; j++) { n     char save = ans[j]; n     for (char d =  a ; d <=  z ; d++) { n       ans[j] = d; n       bool flag = true; n       for (int z = 0; z < n; z++) { n         int cntErrors = 0; n         for (int c = 0; c < m; c++) { n           if (v[z][c] != ans[c]) { n             cntErrors++; n           } n         } n         if (cntErrors > 1) { n           flag = false; n           break; n         } n       } n       if (flag) { n         cout << ans << endl; n         return; n       } n     } n     ans[j] = save; n   } n   cout <<  -1  << 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 const int N = 200020, P = 1000000000; n int add(int a, int b) { return a + b >= P ? a + b - P : a + b; } n struct mat { n   int r, c, a[2][2]; n   void construct(int r_, int c_) { n     r = r_, c = c_; n     for (int i = 0; i < r; ++i) n       for (int j = 0; j < c; ++j) a[i][j] = 0; n   } n   mat operator*(const mat& rhs) const { n     mat res; n     res.construct(r, rhs.c); n     for (int i = 0; i < res.r; ++i) n       for (int j = 0; j < res.c; ++j) n         for (int k = 0; k < c; ++k) n           res.a[i][j] = add(res.a[i][j], (long long)a[i][k] * rhs.a[k][j] % P); n     return res; n   } n } trans_sum[N]; n mat qpow(mat t, int k) { n   mat res = t; n   --k; n   for (; k; k >>= 1) { n     if (k & 1) res = res * t; n     t = t * t; n   } n   return res; n } n mat trans; n struct node { n   mat v; n   int sz; n   int tag; n } t[N << 2]; n int n, m, a[N], fibo[N], sfibo[N]; n node merge(node x, node y) { n   node res; n   res.sz = x.sz + y.sz; n   mat nxt = y.v * trans_sum[x.sz]; n   res.v.construct(1, 2); n   res.v.a[0][0] = add(x.v.a[0][0], nxt.a[0][0]); n   res.v.a[0][1] = add(x.v.a[0][1], nxt.a[0][1]); n   res.tag = 0; n   return res; n } n void build(int p, int l, int r) { n   t[p].tag = 0; n   if (l == r) { n     t[p].v.construct(1, 2); n     t[p].v.a[0][0] = t[p].v.a[0][1] = a[l]; n     t[p].sz = 1; n     return; n   } n   int mid = (l + r) >> 1; n   build(p << 1, l, mid); n   build(p << 1 | 1, mid + 1, r); n   t[p] = merge(t[p << 1], t[p << 1 | 1]); n } n void ontag(int p, int l, int r, int v) { n   t[p].tag = add(t[p].tag, v); n   t[p].v.a[0][0] = add(t[p].v.a[0][0], (long long)v * sfibo[r - l] % P); n   t[p].v.a[0][1] = n       add(t[p].v.a[0][1], (long long)v * (sfibo[r - l + 1] - 1 + P) % P); n } n void pushdown(int p, int l, int r) { n   if (t[p].tag) { n     int mid = (l + r) >> 1; n     ontag(p << 1, l, mid, t[p].tag); n     ontag(p << 1 | 1, mid + 1, r, t[p].tag); n     t[p].tag = 0; n   } n } n void add(int p, int l, int r, int L, int R, int v) { n   if (L <= l && r <= R) { n     ontag(p, l, r, v); n     return; n   } n   pushdown(p, l, r); n   int mid = (l + r) >> 1; n   if (L <= mid) add(p << 1, l, mid, L, R, v); n   if (R > mid) add(p << 1 | 1, mid + 1, r, L, R, v); n   t[p] = merge(t[p << 1], t[p << 1 | 1]); n } n void change(int p, int l, int r, int v, int x) { n   if (l == r) { n     a[l] = x; n     t[p].v.construct(1, 2); n     t[p].v.a[0][0] = t[p].v.a[0][1] = a[l]; n     t[p].sz = 1; n     return; n   } n   pushdown(p, l, r); n   int mid = (l + r) >> 1; n   if (v <= mid) n     change(p << 1, l, mid, v, x); n   else n     change(p << 1 | 1, mid + 1, r, v, x); n   t[p] = merge(t[p << 1], t[p << 1 | 1]); n } n node qry(int p, int l, int r, int L, int R) { n   if (L <= l && r <= R) return t[p]; n   pushdown(p, l, r); n   int mid = (l + r) >> 1; n   if (R <= mid) n     return qry(p << 1, l, mid, L, R); n   else if (L > mid) n     return qry(p << 1 | 1, mid + 1, r, L, R); n   else n     return merge(qry(p << 1, l, mid, L, R), qry(p << 1 | 1, mid + 1, r, L, R)); n } n int main() { n   cout << fixed; n   trans.construct(2, 2); n   trans.a[0][1] = trans.a[1][0] = trans.a[1][1] = 1; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   fibo[0] = fibo[1] = sfibo[0] = 1; n   sfibo[1] = 2; n   for (int i = 2; i <= n; ++i) { n     fibo[i] = add(fibo[i - 1], fibo[i - 2]); n     sfibo[i] = add(sfibo[i - 1], fibo[i]); n   } n   trans_sum[1] = trans; n   for (int i = 2; i <= n; ++i) trans_sum[i] = trans_sum[i - 1] * trans; n   build(1, 1, n); n   while (m--) { n     int op, x, v, l, r, d; n     scanf( %d , &op); n     if (op == 1) { n       scanf( %d%d , &x, &v); n       change(1, 1, n, x, v); n     } else if (op == 2) { n       scanf( %d%d , &l, &r); n       node ans = qry(1, 1, n, l, r); n       printf( %d n , ans.v.a[0][0]); n     } else if (op == 3) { n       scanf( %d%d%d , &l, &r, &d); n       add(1, 1, n, l, r, d); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n using std::vector; n int main() { n   long long n; n   cin >> n; n   int t = 0; n   while (n > 0) { n     if (n % 2 != 0) t++; n     n = n / 2; n   } n   cout << t; n   int h; n   cin >> h; n   return 0; n } n