#include <bits/stdc++.h> n using namespace std; n #ifdef tabr n #include  library/debug.cpp  n #else n #define debug(...) n #endif n  n template <long long mod> n struct modular { n     long long value; n     modular(long long x = 0) { n         value = x % mod; n         if (value < 0) value += mod; n     } n     modular& operator+=(const modular& other) { n         if ((value += other.value) >= mod) value -= mod; n         return *this; n     } n     modular& operator-=(const modular& other) { n         if ((value -= other.value) < 0) value += mod; n         return *this; n     } n     modular& operator*=(const modular& other) { n         value = value * other.value % mod; n         return *this; n     } n     modular& operator/=(const modular& other) { n         long long a = 0, b = 1, c = other.value, m = mod; n         while (c != 0) { n             long long t = m / c; n             m -= t * c; n             swap(c, m); n             a -= t * b; n             swap(a, b); n         } n         a %= mod; n         if (a < 0) a += mod; n         value = value * a % mod; n         return *this; n     } n     modular operator+(const modular& rhs) const { return modular(*this) += rhs; } n     modular operator-(const modular& rhs) const { return modular(*this) -= rhs; } n     modular operator*(const modular& rhs) const { return modular(*this) *= rhs; } n     modular operator/(const modular& rhs) const { return modular(*this) /= rhs; } n     modular& operator++() { return *this += 1; } n     modular& operator--() { return *this -= 1; } n     modular operator++(int) { n         modular res(*this); n         *this += 1; n         return res; n     } n     modular operator--(int) { n         modular res(*this); n         *this -= 1; n         return res; n     } n     modular operator-() const { return modular(-value); } n     bool operator==(const modular& rhs) const { return value == rhs.value; } n     bool operator!=(const modular& rhs) const { return value != rhs.value; } n     bool operator<(const modular& rhs) const { return value < rhs.value; } n }; n template <long long mod> n string to_string(const modular<mod>& x) { n     return to_string(x.value); n } n template <long long mod> n ostream& operator<<(ostream& stream, const modular<mod>& x) { n     return stream << x.value; n } n template <long long mod> n istream& operator>>(istream& stream, modular<mod>& x) { n     stream >> x.value; n     x.value %= mod; n     if (x.value < 0) x.value += mod; n     return stream; n } n  n constexpr long long mod = (long long) 1e9 + 7; n using mint = modular<mod>; n  n mint power(mint a, long long n) { n     mint res = 1; n     while (n > 0) { n         if (n & 1) { n             res *= a; n         } n         a *= a; n         n >>= 1; n     } n     return res; n } n  n vector<mint> fact(1, 1); n vector<mint> finv(1, 1); n  n mint C(int n, int k) { n     if (n < k || k < 0) { n         return mint(0); n     } n     while ((int) fact.size() < n + 1) { n         fact.emplace_back(fact.back() * (int) fact.size()); n         finv.emplace_back(mint(1) / fact.back()); n     } n     return fact[n] * finv[k] * finv[n - k]; n } n  n int main() { n     ios::sync_with_stdio(false); n     cin.tie(0); n     int n; n     cin >> n; n     vector<int> c(n), b(n - 1); n     for (int i = 0; i < n; i++) { n         cin >> c[i]; n     } n     for (int i = 0; i < n - 1; i++) { n         cin >> b[i]; n     } n     vector<int> d(n); n     for (int i = 1; i < n; i++) { n         for (int j = 0; j < i; j++) { n             d[i] += b[j]; n         } n     } n     int q; n     cin >> q; n     map<int, mint> mp; n     mp[(int) 2e9] = 0; n     mp[(int) -2e9] = 1; n     for (int i = 0; i < n; i++) { n         mp[(int) -2e9] *= c[i] + 1; n     } n     while (q--) { n         int x; n         cin >> x; n         if (mp.count(x)) { n             cout << mp[x] <<   n ; n             continue; n         } n         auto nxt = mp.lower_bound(x); n         auto pre = prev(nxt); n         if ((*pre).second == (*nxt).second) { n             cout << (*pre).second <<   n ; n             continue; n         } n         int m = 10100; n         vector<mint> dp(m); n         dp[0] = 1; n         int t = 0; n         for (int i = 0; i < n; i++) { n             vector<mint> new_dp(m); n             new_dp[0] = dp[0]; n             for (int j = 1; j < m; j++) { n                 new_dp[j] = new_dp[j - 1] + dp[j]; n                 if (j - c[i] - 1 >= 0) { n                     new_dp[j] -= dp[j - c[i] - 1]; n                 } n             } n             swap(dp, new_dp); n             t += x + d[i]; n             for (int j = 0; j < min(m, t); j++) { n                 dp[j] = 0; n             } n         } n         mp[x] = accumulate(dp.begin(), dp.end(), mint(0)); n         cout << mp[x] <<   n ; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int Day = 86400; n const long long INF = 1e18; n const int N = 4004; n long long dp[N][N], t[N], d[N]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int(i) = 0; (i) < (n); (i)++) scanf( %d%d , &t[i], &d[i]), t[i]--; n   if (n == k) return printf( %d n , Day) & 0; n   memset(dp, INF, sizeof dp); n   dp[0][0] = 0; n   for (int(i) = (1); (i) <= (n); (i)++) n     for (int(j) = (0); (j) <= (k); (j)++) n       if (j <= i) { n         long long last = dp[i - 1][j]; n         if (last != INF) { n           dp[i][j] = max(last, t[i - 1]) + d[i - 1]; n         } n         if (j > 0) dp[i][j] = min(dp[i - 1][j - 1], dp[i][j]); n       } n   long long ans = 0; n   for (int(left) = (0); (left) <= (n); (left)++) { n     int right = min(k, left); n     long long start = dp[left][right]; n     long long finish = left < n ? t[left] : Day; n     if (start >= Day || finish > Day || start >= finish) continue; n     ans = max(ans, finish - start); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int limN = 1e5 + 5; n vector<pair<long long, int> > adj[limN]; n bool usd[limN]; n long long minP[limN]; n int main() { n   int ans = 0; n   int N, E1, E2; n   priority_queue<tuple<long long, int, int> > Q; n   scanf( %d%d%d , &N, &E1, &E2); n   for (int a, b, c; E1; E1--) { n     scanf( %d%d%d , &a, &b, &c); n     a--, b--; n     adj[a].push_back({c, b}); n     adj[b].push_back({c, a}); n   } n   for (int b, c; E2; E2--) { n     scanf( %d%d , &b, &c); n     b--; n     Q.push({-c, 0, b}); n   } n   Q.push({0, 1, 0}); n   while (!Q.empty()) { n     long long dst; n     int tip, pos; n     tie(dst, tip, pos) = Q.top(); n     Q.pop(); n     if (usd[pos]) { n       ans += 1 - tip; n       continue; n     } n     dst *= -1; n     usd[pos] = true; n     for (const auto &second : adj[pos]) { n       if (!usd[second.second] || minP[second.second] > dst + second.first) { n         minP[second.second] = dst + second.first; n         Q.push({-minP[second.second], 1, second.second}); n       } n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int p[30]; n char A[30], ch[205]; n int d[405][405]; n int now[205], minv[205], minc[205]; n int fan(int x) { return (x > n) ? (x - n) : (x + n); } n int main() { n   scanf( %s , A); n   int tot = strlen(A); n   for (int i = 0; i < tot; ++i) { n     p[i] = A[i] ==  V ; n   } n   minv[0] = minc[0] = 26; n   for (int i = 0; i < tot; ++i) { n     if (p[i]) { n       minv[0] = i; n       break; n     } n   } n   for (int i = 0; i < tot; ++i) { n     if (p[i] == 0) { n       minc[0] = i; n       break; n     } n   } n   scanf( %d%d , &n, &m); n   int x, y; n   char chx[2], chy[2]; n   for (int i = 0; i < m; ++i) { n     scanf( %d%s%d%s , &x, chx, &y, chy); n     if (chx[0] ==  V ) x += n; n     if (chy[0] ==  V ) y += n; n     d[x][y] = 1; n     d[fan(y)][fan(x)] = 1; n   } n   for (int i = 1; i <= 2 * n; ++i) { n     d[i][i] = 1; n   } n   for (int k = 1; k <= 2 * n; ++k) { n     for (int i = 1; i <= 2 * n; ++i) { n       for (int j = 1; j <= 2 * n; ++j) { n         d[i][j] |= d[i][k] & d[k][j]; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     minv[i] = minv[0]; n     minc[i] = minc[0]; n     for (int j = 1; j <= n; ++j) { n       if (d[i][j] && d[i][j + n]) { n         minc[i] = 26; n       } n       if (d[i + n][j] && d[i + n][j + n]) { n         minv[i] = 26; n       } n     } n   } n   scanf( %s , ch + 1); n   for (int i = n + 1; i >= 1; --i) { n     memset(now, -1, sizeof(now)); n     int iminv = 26, iminc = 26; n     if (minv[i] != 26) n       for (int j = ch[i] -  a  + 1; j < tot; ++j) { n         if (p[j]) { n           iminv = j; n           break; n         } n       } n     if (minc[i] != 26) n       for (int j = ch[i] -  a  + 1; j < tot; ++j) { n         if (p[j] == 0) { n           iminc = j; n           break; n         } n       } n     int flag = 1; n     for (int j = 1; j < i; ++j) { n       now[j] = ch[j] -  a ; n     } n     for (int j = 1; j < i; ++j) { n       int type = p[now[j]]; n       if (type == 0 && minc[j] == 26) { n         flag = 0; n         break; n       } n       if (type == 1 && minv[j] == 26) { n         flag = 0; n         break; n       } n       for (int k = 1; k <= n; ++k) { n         if (d[j + type * n][k]) { n           if (now[k] != -1) { n             if (p[now[k]] != 0) { n               flag = 0; n               break; n             } n           } else { n             if (k != i) n               now[k] = minc[k]; n             else n               now[k] = iminc; n           } n         } n         if (d[j + type * n][k + n]) { n           if (now[k] != -1) { n             if (p[now[k]] != 1) { n               flag = 0; n               break; n             } n           } else { n             if (k != i) n               now[k] = minv[k]; n             else n               now[k] = iminv; n           } n         } n       } n     } n     for (int j = i; j <= n; ++j) { n       if (now[j] != -1) continue; n       if (j != i) { n         now[j] = min(minv[j], minc[j]); n       } else { n         now[j] = min(iminv, iminc); n       } n       int type = p[now[j]]; n       for (int k = 1; k <= n; ++k) { n         if (d[j + type * n][k]) { n           if (now[k] != -1) { n             if (p[now[k]] != 0) { n               flag = 0; n               break; n             } n           } else { n             if (k != i) n               now[k] = minc[k]; n             else n               now[k] = iminc; n           } n         } n         if (d[j + type * n][k + n]) { n           if (now[k] != -1) { n             if (p[now[k]] != 1) { n               flag = 0; n               break; n             } n           } else { n             if (k != i) n               now[k] = minv[k]; n             else n               now[k] = iminv; n           } n         } n       } n     } n     for (int i = 1; i <= n; ++i) { n       if (now[i] == 26) { n         flag = 0; n         break; n       } n     } n     if (flag) { n       for (int i = 1; i <= n; ++i) { n         printf( %c , now[i] +  a ); n       } n       return 0; n     } n   } n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int len = s.size(); n   bool flag = false; n   for (int i = 0; i < len - 1; i++) { n     if ((s[i] !=  a  && s[i] !=  e  && s[i] !=  i  && s[i] !=  o  && n          s[i] !=  u )) { n       if (s[i] ==  n ) n         continue; n       else { n         if ((s[i + 1] ==  a  || s[i + 1] ==  e  || s[i + 1] ==  i  || n              s[i + 1] ==  o  || s[i + 1] ==  u )) { n           continue; n         } else { n           flag = true; n           break; n         } n       } n     } n   } n   if ((s[len - 1] !=  a  && s[len - 1] !=  e  && s[len - 1] !=  i  && n        s[len - 1] !=  o  && s[len - 1] !=  u  && s[len - 1] !=  n )) n     flag = true; n   if (!flag) { n     cout <<  YES n ; n   } else { n     cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1007; n bool ans[MAXN]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   string s; n   cin >> s; n   int n = s.size(); n   int l = 0; n   for (int i = 0; i < n; ++i) { n     if (s[i] ==  a  && (i == n - 1 || s[i + 1] ==  b )) { n       ans[l] = 1; n       ans[i] = 1; n     } n     if (s[i] ==  b ) l = i; n   } n   for (int i = 0; i < n; ++i) cout << ans[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_MEM = (int)1e8; n int mpos = 0; n char mem[MAX_MEM]; n inline void *operator new(size_t n) { n   char *res = mem + mpos; n   mpos += n; n   return (void *)res; n } n inline void operator delete(void *) {} n struct __io_dev { n   __io_dev(const bool &__fastio = false) { n     if (__fastio) ios_base::sync_with_stdio(false), cin.tie(nullptr); n     srand(time(nullptr)); n     if (!string(  ).empty()) n       freopen( n              n            .in , n            r , stdin), n           freopen( n                  n                .out , n                w , stdout); n   } n   ~__io_dev() { fprintf(stderr,  %.6f ms n , 1e3 * clock() / CLOCKS_PER_SEC); } n } __io(false); n const long long inf = (long long)1e+9 + 7ll; n const long long linf = (long long)1e+18 + 7ll; n const long double eps = (long double)1e-9; n const long double pi = acosl((long double)-1.0); n const int alph = 26; n const int maxs = 512l; n static char buff[(int)2e6 + 17]; n long long __p[3] = {29ll, 31ll, 33ll}; n long long __mod[3] = {inf, inf + 2ll, 14881337ll}; n const int maxn = (int)2e5 + 17; n int n; n string s; n long long R, K; n void print(int R, int K) { n   string r; n   int cnt = 0; n   for (; R > 0; R /= 10) { n     r.push_back(char( 0  + R % 10)); n     ++cnt; n     if (cnt % 3 == 0) r.push_back( . ); n   } n   if (r.back() ==  . ) r.pop_back(); n   if (((int)(r.size())) == 0) r.push_back( 0 ); n   reverse(r.begin(), r.end()); n   printf( %s , r.c_str()); n   if (K != 0) printf( .%.2d , K); n } n int main() { n   scanf( %s , buff); n   s = string(buff); n   n = ((int)(s.size())); n   for (int i = 0; i < n; ++i) n     if (!( a  <= s[i] && s[i] <=  z )) { n       int r = i; n       string t =   ; n       for (; r < n && !( a  <= s[r] && s[r] <=  z ); ++r) t += s[r]; n       if (((int)(t.size())) >= 3 && t[((int)(t.size())) - 3] ==  . ) { n         K += 10 * (t[((int)(t.size())) - 2] -  0 ) + t[((int)(t.size())) - 1] - n               0 ; n         int cursize = ((int)(t.size())); n         t.resize(cursize - 3); n       } n       long long cur = 0; n       for (auto c : t) n         if ( 0  <= c && c <=  9 ) cur = cur * 10ll + c -  0 ; n       R += cur; n       i = r - 1; n     } n   R += K / 100; n   K %= 100; n   print(R, K); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, p[100002]; n bool id[100002]; n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) { n       int a; n       scanf( %d , &a); n       p[a] = i; n       id[i] = true; n     } n     id[n + 1] = 0; n     bool succeed = true; n     int num = 1; n     int tp = p[1]; n     p[1] = 0; n     id[tp] = 0; n     for (int i = 2; i <= n; i++) { n       if (id[tp + 1] == false) { n         id[p[i]] = false; n         tp = p[i]; n       } else { n         if (tp + 1 != p[i]) { n           succeed = false; n           break; n         } else { n           id[tp + 1] = false; n           tp = tp + 1; n         } n       } n     } n     if (succeed) n       printf( Yes n ); n     else n       printf( No n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1e9 + 7; n void swap(int *a, int *b) { n   int temp = *a; n   *a = *b; n   *b = temp; n } n unsigned long long int POW(unsigned long long int p, int b) { n   unsigned long long int ans = 1LL; n   while (b > 0) { n     if (b & 1) { n       ans = ans * 1LL * p; n     } n     b /= 2; n     p = p * 1LL * p; n   } n   return ans; n } n long long int power(long long int a, long long int b, long long int mod) { n   long long int x = 1; n   long long int y = a; n   while (b > 0) { n     if (b & 1) { n       x = x * y; n       x %= mod; n     } n     y = y * y; n     y %= mod; n     b /= 2; n   } n   return x; n } n long long int add(long long int a, long long int b, long long int m = MOD) { n   long long int x = a + b; n   while (x >= m) x -= m; n   while (x < 0) x += m; n   return x; n } n long long int sub(long long int a, long long int b, long long int m = MOD) { n   long long int x = a - b; n   while (x < 0) x += m; n   while (x >= m) x -= m; n   return x; n } n long long int mul(long long int a, long long int b, long long int m = MOD) { n   long long int x = a * 1ll * b; n   x %= m; n   if (x < 0) x += m; n   return x; n } n vector<char> g[1001]; n int main() { n   string str; n   cin >> str; n   string temp =   ; n   int idx = 0; n   bool ek = false; n   for (int i = 0; i < str.size();) { n     if (isdigit(str[i])) { n       int j = i; n       bool hai = false; n       for (j = i; j < str.size(); j++) { n         if (!isdigit(str[j]) and !(str[j] ==  . )) break; n         if (str[j] ==  .  and (j + 2) < str.size() and n             (j + 3 >= (int)str.size() or !isdigit(str[j + 3]) ? 1 : 0)) { n           g[idx].push_back(str[j]); n           hai = true; n           ek = true; n         } n         if (isdigit(str[j])) g[idx].push_back(str[j]); n       } n       if (!hai) { n         g[idx].push_back( . ); n         g[idx].push_back( 0 ); n         g[idx].push_back( 0 ); n       } n       i = j; n       idx++; n     } else n       i++; n   } n   if (ek == false) { n     int s = 0; n     int cnt = 0; n     int carry = 0; n     vector<char> ans; n     for (int i = 0; i < idx; i++) { n       for (int j = 0; j < 3; j++) g[i].pop_back(); n     } n     while (true) { n       s = 0; n       bool mila = false; n       for (int i = 0; i < idx; i++) { n         if (g[i].empty()) continue; n         s += (g[i].back() -  0 ); n         g[i].pop_back(); n         mila = true; n       } n       if (mila == false) break; n       if (cnt == 3) { n         ans.push_back( . ); n         cnt = 0; n       } n       s += carry; n       ans.push_back(s % 10 +  0 ); n       carry = s / 10; n       cnt++; n     } n     while (carry != 0) { n       if (cnt == 3) { n         ans.push_back( . ); n         cnt = 0; n       } n       ans.push_back(carry % 10 +  0 ); n       carry /= 10; n       cnt++; n     } n     reverse(ans.begin(), ans.end()); n     for (int i = 0; i < ans.size(); i++) cout << ans[i]; n   } else { n     vector<char> ans; n     int s = 0; n     int cnt = 0; n     int carry = 0; n     for (int i = 0; i < idx; i++) { n       s += g[i].back() -  0 ; n       g[i].pop_back(); n     } n     s += carry; n     ans.push_back(s % 10 +  0 ); n     carry = s / 10; n     s = 0; n     for (int i = 0; i < idx; i++) { n       s += g[i].back() -  0 ; n       g[i].pop_back(); n       g[i].pop_back(); n     } n     s += carry; n     ans.push_back(s % 10 +  0 ); n     carry = s / 10; n     ans.push_back( . ); n     while (true) { n       s = 0; n       bool mila = false; n       for (int i = 0; i < idx; i++) { n         if (g[i].empty()) continue; n         s += (g[i].back() -  0 ); n         g[i].pop_back(); n         mila = true; n       } n       if (mila == false) break; n       if (cnt == 3) { n         ans.push_back( . ); n         cnt = 0; n       } n       s += carry; n       ans.push_back(s % 10 +  0 ); n       carry = s / 10; n       cnt++; n     } n     while (carry != 0) { n       if (cnt == 3) { n         ans.push_back( . ); n         cnt = 0; n       } n       ans.push_back(carry % 10 +  0 ); n       carry /= 10; n       cnt++; n     } n     int value = 0; n     if (ans[0] ==  0  and ans[1] ==  0 ) value = 3; n     reverse(ans.begin(), ans.end()); n     for (int i = 0; i < ans.size() - value; i++) cout << ans[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long q, dp[105][100005], a[555555], b[555555], k, l, m, n, o, p; n map<long long, long long> mp; n vector<long long> adj[555555]; n const long long mod = 1e9 + 7; n void solve() { n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     string s =   ; n     cin >> s; n     long long op[26], po = 0; n     memset(op, 0, sizeof op); n     for (auto u : s) { n       op[u -  a ]++; n     } n     for (long long i = 0; i < 26; i++) { n       po += (1 << i) * (op[i] % 2); n     } n     mp[po]++; n     a[i] = po; n   } n   for (long long i = 1; i <= n; i++) { n     mp[a[i]]--; n     k += mp[a[i]]; n     for (long long j = 0; j < 26; j++) { n       k += mp[a[i] ^ (1 << j)]; n     } n   } n   cout << k; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   q = 1; n   while (q--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const bool debug = false; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   string s[8]; n   for (int i = 0; i < 8; i++) { n     cin >> s[i]; n   } n   int r = 0, col = 0; n   for (int i = 0; i < 8; i++) { n     int c = 0; n     for (int j = 0; j < 8; j++) { n       if (s[i][j] ==  B ) c++; n     } n     if (c == 8) r++; n   } n   for (int i = 0; i < 8; i++) { n     int c = 0; n     for (int j = 0; j < 8; j++) { n       if (s[j][i] ==  B ) c++; n     } n     if (c == 8) col++; n   } n   if (r == 0 and col == 0) { n     cout << 0; n     return 0; n   } n   if (r == 8 or col == 8) { n     cout << 8; n     return 0; n   } n   cout << r + col; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2010; n const int mod = 1000000007; n long long dp[maxn][maxn]; n long long s[maxn][maxn], ss[maxn][maxn]; n void upd(long long &t, long long k) { n   t += k; n   t %= mod; n } n int main() { n   int n, i, j, m; n   long long t; n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     for (j = 0; j + 1 < m; j++) { n       long long t = 1 + s[i - 1][j] * (j + 1) - ss[i - 1][j]; n       upd(dp[i][j], t); n     } n     s[i][0] = dp[i][0]; n     for (j = 1; j + 1 < m; j++) { n       s[i][j] = s[i][j - 1] + dp[i][j], ss[i][j] = ss[i][j - 1] + dp[i][j] * j; n       s[i][j] %= mod; n       ss[i][j] %= mod; n     } n   } n   long long ans = 0; n   for (i = 1; i <= n; i++) { n     for (j = 0; j + 1 < m; j++) { n       long long t1 = dp[i][j] - dp[i - 1][j]; n       long long t2 = dp[n - i + 1][j]; n       ans += t1 * t2 % mod * (m - j - 1); n       ans %= mod; n     } n   } n   cout << (ans + mod) % mod << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, w, x, c, ans; n int main() { n   cin >> a >> b >> w >> x >> c; n   if (c <= a) { n     cout << 0 << endl; n   } else { n     ans = ceil(1.0 * (x * (c - a) - b) / (w - x)); n     cout << ans + c - a << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, d, b, l, r, need, ans1, ans2; n long long a[500011], n1[500011], n2[500011]; n int main() { n   scanf( %lld%lld%lld , &n, &d, &b); n   long long re = (n >> 1) * b; n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (int i = 1; i <= n; i++) n     n1[i] = min(a[i], re) + n1[i - 1], re -= min(a[i], re); n   re = (n >> 1) * b; n   for (int i = n; i; i--) n     n2[i] = min(a[i], re) + n2[i + 1], re -= min(a[i], re); n   for (int i = 1; i <= n / 2; i++) { n     r = min(r + d + 1, n); n     if (need + b <= n1[r]) n       need += b; n     else n       ans1++; n   } n   l = n + 1; n   need = 0; n   for (int i = n; i >= ((n + 1) / 2) + 1; i--) { n     l = max(1LL, l - d - 1); n     if (need + b <= n2[l]) n       need += b; n     else n       ans2++; n   } n   printf( %lld n , max(ans1, ans2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s, ans; n   cin >> s; n   ans = s; n   s += s; n   for (int k = 0; k < 10; k++) { n     for (int i = 0; i < s.length(); i++) { n       s[i]++; n       if (s[i] >  9 ) s[i] =  0 ; n     } n     for (int i = 0; i < n; i++) { n       ans = min(ans, s.substr(i, n)); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str; n   cin >> str; n   str[0] = toupper(str[0]); n   cout << str; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int inf = 1e9; n int mod = 1e9 + 7; n const int M = 20; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   int n = (int)s.length(); n   int dp[(1 << M)]; n   memset(dp, 0, sizeof(dp)); n   int maxi = 0; n   for (int i = 0; i < n; i++) { n     int mask = 0; n     int cnt = 0; n     for (int j = i; j < n; j++) { n       int x = s[j] -  a ; n       if ((mask >> x) & 1) { n         break; n       } n       mask ^= (1 << x); n       cnt++; n       dp[mask] = cnt; n     } n     maxi = max(maxi, cnt); n   } n   for (int i = 0; i < M; i++) { n     for (int j = 0; j < (1 << M); j++) { n       if (j & (1 << i)) { n         dp[j] = max(dp[j], dp[j ^ (1 << i)]); n       } n     } n   } n   for (int i = 0; i < (1 << M); i++) { n     int comp = (1 << M) - 1 - i; n     maxi = max(maxi, dp[i] + dp[comp]); n   } n   cout << maxi <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxm = 2e6 + 5; n struct task { n   int t, k, d; n } tasks[maxm]; n int times[110]; n int main() { n   for (int i = 0; i < 110; ++i) { n     times[i] = 0; n   } n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; ++i) { n     scanf( %d%d%d , &tasks[i].t, &tasks[i].k, &tasks[i].d); n   } n   for (int i = 0; i < m; ++i) { n     int num = 0, j = 1, res = 0; n     if (tasks[i].k > n) { n       printf( -1 n ); n       continue; n     } n     while (j <= n) { n       if (times[j] <= tasks[i].t) { n         num++; n       } n       if (num == tasks[i].k) break; n       j++; n     } n     j = 1; n     if (num == tasks[i].k) { n       int cnt = 0; n       while (j <= n) { n         if (times[j] <= tasks[i].t) { n           res += j; n           times[j] = tasks[i].t + tasks[i].d; n           cnt++; n         } n         if (cnt == tasks[i].k) break; n         j++; n       } n       printf( %d n , res); n     } else { n       printf( -1 n ); n       continue; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 510; n int t, n, m, a, b, c; n vector<pair<int, int> > g[N]; n int dp[N][N], inDegree[N][N], source, ans[N][N]; n bool vis[N]; n void dfs(int u) { n   if (vis[u]) return; n   vis[u] = 1; n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i].first; n     int newCost = g[u][i].second + dp[source][u]; n     if (dp[source][v] == newCost) { n       inDegree[source][v]++; n       dfs(v); n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       dp[i][j] = 1e9; n     } n     dp[i][i] = 0; n   } n   for (int i = 0; i < m; ++i) { n     scanf( %d%d%d , &a, &b, &c); n     g[a].push_back(make_pair(b, c)); n     g[b].push_back(make_pair(a, c)); n     dp[a][b] = min(dp[a][b], c); n     dp[b][a] = min(dp[b][a], c); n   } n   for (int k = 1; k <= n; k++) { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]); n       } n     } n   } n   for (source = 1; source <= n; source++) { n     memset(vis, 0, sizeof vis); n     dfs(source); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       for (int k = 1; k <= n; k++) { n         if (dp[i][k] + dp[k][j] == dp[i][j]) { n           ans[i][j] += inDegree[i][k]; n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       printf( %d  , ans[i][j]); n     } n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200005]; n bool got[200004], gave[200004]; n queue<int> q; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     got[a[i]] = 1; n     if (a[i] != 0) { n       gave[i] = 1; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (!got[i]) { n       q.push(i); n     } n   } n   for (int i = 1; i <= n; i++) { n     if (!got[i] && !gave[i]) { n       int x = q.front(); n       q.pop(); n       if (x == i) { n         q.push(x); n         x = q.front(); n         q.pop(); n       } n       a[i] = x; n       gave[i] = 1; n       got[x] = 1; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (!gave[i]) { n       int x = q.front(); n       q.pop(); n       a[i] = x; n       gave[i] = 1; n       got[x] = 1; n     } n   } n   for (int i = 0; i < n; i++) { n     cout << a[i + 1] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n bool check(string pattern, string text) { n   int j = 0; n   int i = 0; n   while (i < text.size()) { n     if (pattern[j] == text[i]) { n       j++; n     } n     i++; n   } n   return j == pattern.size(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int d; n   cin >> d; n   while (d--) { n     string s, t, p; n     cin >> s >> t >> p; n     string k = s; n     s = s + p; n     map<char, long long int> m_s; n     map<char, long long int> m_t; n     for (int i = 0; i < s.size(); ++i) { n       m_s[s[i]]++; n     } n     for (int i = 0; i < t.size(); ++i) { n       m_t[t[i]]++; n     } n     bool checks = true; n     for (auto i : m_t) { n       if (m_s[i.first] < i.second) { n         checks = false; n       } n     } n     if (checks && check(k, t)) { n       cout <<  YES  n            <<   n ; n     } else { n       cout <<  NO  n            <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; 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.emplace_back(x); n   return move(v); n } n void err(vector<string>::iterator it) {} n template <typename T, typename... Args> n void err(vector<string>::iterator it, T a, Args... args) { n   cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   t ; n   err(++it, args...); n } n const long double eps = 1e-9; n const long long mod = 1e9 + 7; n pair<long long, long long> dir[8] = {{-1, 0}, {1, 0},   {0, -1}, {0, 1}, n                                      {1, 1},  {-1, -1}, {-1, 1}, {1, -1}}; n const long long nn = 3e5 + 5; n vector<long long> g[nn]; n long long par[nn]; n long long sz[nn]; n long long centroid[nn]; n void dfs(long long v) { n   sz[v] = 1; n   for (long long to : g[v]) { n     dfs(to); n     sz[v] += sz[to]; n   } n   long long bad = -1; n   for (long long to : g[v]) { n     if (sz[to] * 2 > sz[v]) bad = to; n   } n   if (bad == -1) { n     centroid[v] = v; n   } else { n     centroid[v] = centroid[bad]; n     while (sz[centroid[v]] * 2 <= sz[v]) { n       centroid[v] = par[centroid[v]]; n     } n   } n } n void robin() { n   long long n, q; n   cin >> n >> q; n   for (long long i = 2; i <= n; i++) { n     long long v; n     cin >> v; n     par[i] = v; n     g[v].push_back(i); n   } n   dfs(1); n   while (q--) { n     long long v; n     cin >> v; n     cout << centroid[v] <<   n ; n   } n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long T = 1; n   for (long long tc = 1; tc <= T; tc++) { n     robin(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int k; n   cin >> k; n   int sum = (1 << 18) - 1; n   cout <<  3 3 n ; n   cout << sum <<     << (1 << 17) <<     << 0 <<   n ; n   cout << k <<     << sum <<     << 0 <<   n ; n   cout << 0 <<     << k <<     << k <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int a[200000]; n int b[200001]; n int br[200001]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 1; i <= m; i++) cin >> b[i]; n   int minimum = 0; n   for (int i = 1; i <= m; i++) minimum += b[i]; n   int ok = 0; n   for (int i = 1; i <= m; i++) ok += !b[i]; n   int left = 0; n   int ans = n + 1; n   for (int right = 0; right < n; right++) { n     br[a[right]]++; n     if (br[a[right]] == b[a[right]]) ok++; n     while (ok == m) { n       ans = min(ans, right - left + 1); n       if (br[a[left]] == b[a[left]]) ok--; n       br[a[left]]--; n       left++; n     } n   } n   if (ans == n + 1) n     cout << -1 << endl; n   else n     cout << ans - minimum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 10; n vector<pair<string, int> > ch[MAXN]; n int nxt[MAXN][27], n, gp, ans; n string t; n void adds(string &tmp) { n   for (int i = 0; i < tmp.size(); i++) { n     gp = nxt[gp][tmp[i] -  a ]; n     if (gp == t.size()) ans++; n   } n } n void dfs(int v, int p) { n   for (int i = 0; i < ch[v].size(); i++) { n     gp = p; n     adds(ch[v][i].first); n     dfs(ch[v][i].second, gp); n   } n } n int main() { n   cin >> n; n   for (int i = 2; i <= n; i++) { n     string tmp; n     int r; n     cin >> r >> tmp; n     ch[r].push_back({tmp, i}); n   } n   cin >> t; n   nxt[0][t[0] -  a ] = 1; n   int cp = 0; n   for (int i = 1; i <= t.size(); i++) { n     for (char c =  a ; c <=  z ; c++) { n       if (t[cp] == c) n         nxt[i][c -  a ] = cp + 1; n       else n         nxt[i][c -  a ] = nxt[cp][c -  a ]; n     } n     if (i < t.size()) { n       nxt[i][t[i] -  a ] = i + 1; n       if (t[cp] == t[i]) n         cp++; n       else n         cp = nxt[cp][t[i] -  a ]; n     } n   } n   dfs(1, 0); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void gmin(T &a, T b) { n   a = a < b ? a : b; n } n template <typename T> n void gmax(T &a, T b) { n   a = a > b ? a : b; n } n const int MAXV = 410; n const int MAXE = 1650; n const int INF = 0x3f3f3f3f; n struct Edge { n   int to, cap, nxt, cost; n   Edge() {} n   Edge(int to, int cap, int nxt, int cost) n       : to(to), cap(cap), nxt(nxt), cost(cost) {} n } edge[MAXE << 1]; n int head[MAXV], cnt; n void initedge() { n   memset(head, -1, sizeof(head)); n   cnt = 0; n } n inline void addedge(int from, int to, int cap, int cost) { n   edge[cnt] = Edge(to, cap, head[from], cost); n   head[from] = cnt++; n } n inline void addedge2(int from, int to, int cap, int cost) { n   addedge(from, to, cap, cost); n   addedge(to, from, 0, -cost); n } n int dist[MAXV]; n int iter[MAXV]; n bool inq[MAXV]; n bool SPFA(int S, int T) { n   static int q[MAXV]; n   int f = 0, r = 0; n   memset(dist, INF, sizeof(dist)); n   memset(inq, 0, sizeof(inq)); n   dist[S] = 0; n   q[r++] = S; n   inq[S] = true; n   while (f != r) { n     int x = q[f++]; n     inq[x] = false; n     if (f == MAXV) f = 0; n     for (int p = head[x]; ~p; p = edge[p].nxt) { n       Edge e = edge[p]; n       if (e.cap && dist[e.to] > dist[x] + e.cost) { n         dist[e.to] = dist[x] + e.cost; n         if (!inq[e.to]) { n           q[r++] = e.to; n           inq[e.to] = true; n           if (r == MAXV) r = 0; n         } n       } n     } n   } n   return dist[T] < INF; n } n int getflow(int x, int lim, int T) { n   if (x == T) return lim; n   inq[x] = true; n   int nowflow = 0, newflow; n   for (register int &p = iter[x]; ~p; p = edge[p].nxt) { n     register Edge &e = edge[p]; n     if (!inq[e.to] && e.cap && dist[e.to] == dist[x] + e.cost) { n       newflow = getflow(e.to, min(e.cap, lim - nowflow), T); n       e.cap -= newflow; n       edge[p ^ 1].cap += newflow; n       nowflow += newflow; n       if (nowflow >= lim) break; n     } n   } n   return nowflow; n } n int mincostmaxflow(int S, int T) { n   int nowcost = 0, newflow; n   while (SPFA(S, T)) { n     for (int i = 0; i < MAXV; i++) iter[i] = head[i]; n     memset(inq, 0, sizeof(inq)); n     do { n       newflow = getflow(S, INF, T); n       nowcost += newflow * dist[T]; n     } while (newflow); n   } n   return nowcost; n } n const int MAXN = 210; n const int MAXM = 210; n int S, T, second, TT; n int n1, n2, m, r, b; n int id[MAXM]; n int delta[MAXV]; n char s[MAXN]; n int ans; n int main() { n   initedge(); n   scanf( %d%d%d%d%d , &n1, &n2, &m, &r, &b); n   S = 0; n   T = n1 + n2 + 1; n   scanf( %s , s); n   for (int i = 1; i <= n1; i++) { n     char c = s[i - 1]; n     if (c ==  R ) { n       addedge2(i, T, INF - 1, 0); n       delta[i] -= 1; n       delta[T] += 1; n     } n     if (c ==  B ) { n       addedge2(S, i, INF - 1, 0); n       delta[S] -= 1; n       delta[i] += 1; n     } n     if (c ==  U ) { n       addedge2(S, i, INF - 0, 0); n       addedge2(i, T, INF - 0, 0); n     } n   } n   scanf( %s , s); n   for (int i = 1; i <= n2; i++) { n     char c = s[i - 1]; n     if (c ==  B ) { n       addedge2(n1 + i, T, INF - 1, 0); n       delta[n1 + i] -= 1; n       delta[T] += 1; n     } n     if (c ==  R ) { n       addedge2(S, n1 + i, INF - 1, 0); n       delta[S] -= 1; n       delta[n1 + i] += 1; n     } n     if (c ==  U ) { n       addedge2(S, n1 + i, INF - 0, 0); n       addedge2(n1 + i, T, INF - 0, 0); n     } n   } n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     id[i] = cnt; n     addedge2(x, n1 + y, 1 - 0, b); n     addedge2(n1 + y, x, 1 - 0, r); n   } n   addedge2(T, S, INF - 0, 0); n   second = n1 + n2 + 2; n   TT = n1 + n2 + 3; n   int sum = 0; n   for (int i = S; i <= T; i++) { n     if (delta[i] > 0) addedge2(second, i, delta[i], 0), sum += delta[i]; n     if (delta[i] < 0) addedge2(i, TT, -delta[i], 0); n   } n   ans = mincostmaxflow(second, TT); n   sum = 0; n   for (int p = head[second]; ~p; p = edge[p].nxt) sum += edge[p].cap; n   if (!sum) { n     printf( %d n , ans); n     for (int i = 0; i < m; i++) { n       if (edge[id[i]].cap == 0) n         putchar( B ); n       else if (edge[id[i] + 2].cap == 0) n         putchar( R ); n       else n         putchar( U ); n     } n     putchar(  n ); n   } else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 810; n const int M = 10; n int mod[N][M]; n int ans[N], inv[N], a[N]; n int n; n void print() { n   if (ans[1] > n / 2) { n     for (int i = 1; i <= n; ++i) { n       ans[i] = n + 1 - ans[i]; n     } n   } n   printf( ! ); n   for (int i = 1; i <= n; ++i) { n     printf(  %d , ans[i]); n   } n   puts(  ); n } n int ask(std::vector<int> vec, int calcmod) { n   int n = vec.size(); n   printf( ? %d , n); n   for (auto u : vec) { n     printf(  %d , u); n   } n   puts(  ); n   fflush(stdout); n   int ret; n   scanf( %d , &ret); n   if (calcmod > 0) { n     if (ret) { n       int sum = 0; n       for (auto u : vec) { n         if (u != calcmod) { n           sum = (sum + ans[u]) % n; n         } n       } n       mod[calcmod][n] = (n - sum) % n; n     } n   } n   return ret; n } n int main() { n   scanf( %d , &n); n   memset(mod, -1, sizeof(mod)); n   mod[1][2] = 1; n   for (int i = 1; i < n; ++i) { n     mod[i + 1][2] = mod[i][2] ^ (1 - ask({i, i + 1}, 0)); n   } n   for (int i = 1; i <= 4 && i <= n / 2; ++i) { n     std::vector<int> todo; n     for (int j = 1; j <= n; ++j) { n       if (!ans[j]) { n         todo.emplace_back(j); n       } n     } n     for (auto j : todo) { n       std::vector<int> vec; n       for (auto k : todo) { n         if (j != k) { n           vec.emplace_back(k); n         } n       } n       if (ask(vec, 0)) { n         ans[j] = mod[j][2] == i % 2 ? i : n + 1 - i; n         inv[ans[j]] = j; n       } n     } n   } n   if (n <= 8) { n     print(); n     return 0; n   } n   for (int i = 3; i <= 7; i += 2) { n     using pii = std::pair<int, int>; n     std::vector<pii> to_check; n     std::vector<int> known; n     for (int j = 0; j <= i / 2; ++j) { n       to_check.emplace_back(1, n - 3 + j); n     } n     for (int j = 1; j <= i / 2; ++j) { n       to_check.emplace_back(i / 2 + 1, n - 3 + j); n     } n     for (int j = 0; j <= i / 2; ++j) { n       known.emplace_back(j + 1); n       known.emplace_back(j + n - 3); n     } n     for (auto p : to_check) { n       for (int j = 1; j <= n; ++j) { n         if (ans[j] || mod[j][i] != -1) { n           continue; n         } n         std::vector<int> vec = {j}; n         for (auto u : known) { n           if (u == p.first || u == p.second) { n             continue; n           } n           vec.emplace_back(inv[u]); n         } n         ask(vec, j); n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (ans[i]) { n       continue; n     } n     ask({inv[1], inv[2], inv[3], i}, i); n     if (mod[i][4] != -1) { n       continue; n     } n     ask({inv[1], inv[2], inv[4], i}, i); n     if (mod[i][4] != -1) { n       continue; n     } n     mod[i][4] = mod[i][2] == 1 ? 3 : 0; n   } n   std::vector<bool> calced(8); n   int sum = 0; n   for (int i = 1; i <= 4; ++i) { n     sum += n - 4 + i; n     sum += i; n   } n   for (int i = 1; i <= 4; ++i) { n     calced[(8 - (sum - i) % 8) % 8] = true; n   } n   for (int i = 1; i <= n; ++i) { n     if (ans[i]) { n       continue; n     } n     int pos = 0; n     for (int j = 1; j <= 4; ++j) { n       if ((sum - j) % 4 == (4 - mod[i][4]) % 4) { n         pos = j; n         break; n       } n     } n     std::vector<int> vec = {i}; n     for (int j = 1; j <= 4; ++j) { n       vec.emplace_back(inv[n - 4 + j]); n       if (j != pos) { n         vec.emplace_back(inv[j]); n       } n     } n     ask(vec, i); n     if (mod[i][8] == -1) { n       mod[i][8] = (calced[mod[i][4]] ? 4 : 0) ^ mod[i][4]; n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (ans[i]) { n       continue; n     } n     for (int j = 1; j <= n; ++j) { n       bool flag = true; n       for (auto u : {3, 5, 7, 8}) { n         if (j % u != mod[i][u]) { n           flag = false; n           break; n         } n       } n       if (flag) { n         ans[i] = j; n         break; n       } n     } n   } n   print(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     long long int x = 0, y = 0, p, q, sum = 0; n     set<pair<int, int> > ma; n     for (long long int i = 0; i < s.size(); i++) { n       p = x; n       q = y; n       if (s[i] ==  N ) n         y++; n       else if (s[i] ==  S ) n         y--; n       else if (s[i] ==  W ) n         x++; n       else n         x--; n       if (!ma.count({x + p, q + y})) { n         sum = sum + 5; n         ma.insert({x + p, q + y}); n       } else n         ++sum; n     } n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxN = 1e6 + 100; n const long long maxM = 1e3 + 100; n const long long mod = 1e9 + 7; n const long long hmod = 1e16 + 7; n const long double PI = 3.141592653; n const long double eps = 1e-8; n const long long D = 1379; n const long long INF = 1e18 + 20; n const long long Inf = 1e9 + 140; n void NO() { n   cout <<  NO  << endl; n   exit(0); n } n void YES() { n   cout <<  YES  << endl; n   exit(0); n } n long long n, k; n bool mrk[2][maxN], mark[2][maxN]; n void dfs(long long v, long long x = 0, long long W = 0) { n   if (v > n) YES(); n   if (v <= 0 || mrk[x][v] || mark[x][v] || v <= W) return; n   mark[x][v] = true; n   W++; n   dfs(v + k, x ^ 1, W); n   dfs(v + 1, x, W); n   dfs(v - 1, x, W); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   for (long long i = 1; i <= n; i++) { n     char c; n     cin >> c; n     if (c ==  X ) mrk[0][i] = true; n   } n   for (long long i = 1; i <= n; i++) { n     char c; n     cin >> c; n     if (c ==  X ) mrk[1][i] = true; n   } n   dfs(1); n   NO(); n } n


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


#include <bits/stdc++.h> n using namespace std; n double prb[(1 << 21)], p[25], ans[25]; n int vis[(1 << 21)]; n bool eq(double a, double b) { return (abs(a - b) < 1e-12); } n int main() { n   int i, n, k, tmp; n   scanf( %d , &n); n   scanf( %d , &k); n   tmp = n; n   for (i = 0; i < n; i++) { n     scanf( %lf , &p[i]); n     if (eq(p[i], 0)) tmp--; n   } n   k = min(k, tmp); n   prb[0] = 1; n   queue<int> all; n   all.push(0); n   while (!all.empty()) { n     int now = all.front(); n     all.pop(); n     if (__builtin_popcount(now) == k) n       for (i = 0; i < n; i++) n         if (now & (1 << i)) ans[i] += prb[now]; n     double gun = 0; n     for (i = 0; i < n; i++) n       if (!(now & (1 << i))) gun += p[i]; n     gun = 1 / gun; n     if (__builtin_popcount(now) < k) n       for (i = 0; i < n; i++) { n         if ((now & (1 << i)) || eq(p[i], 0)) continue; n         tmp = now ^ (1 << i); n         prb[tmp] += (p[i] * gun * prb[now]); n         if (!vis[tmp]) { n           vis[tmp] = 1; n           all.push(tmp); n         } n       } n   } n   for (i = 0; i < n; i++) printf( %.15f  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e5 + 100; n vector<int> v[MAX_N]; n int dp[MAX_N], ans, deep[MAX_N]; n void dfs(int x, int fa, int dep) { n   int i; n   deep[x] = dep; n   for (i = 0; i < v[x].size(); i++) { n     int y = v[x][i]; n     if (y == fa) continue; n     dfs(y, x, dep + 1); n   } n } n void dfs(int x, int fa) { n   int i; n   dp[x] = 0; n   for (i = 0; i < v[x].size(); i++) { n     int y = v[x][i]; n     if (y == fa) continue; n     dfs(y, x); n     ans = max(ans, dp[x] + dp[y] + 1); n     dp[x] = max(dp[x], dp[y] + 1); n   } n } n int main(void) { n   int T, n, a, b, da, db, i, x, y; n   cin >> T; n   while (T--) { n     scanf( %d%d%d%d%d , &n, &a, &b, &da, &db); n     for (i = 1; i <= n; i++) v[i].clear(); n     for (i = 1; i < n; i++) { n       scanf( %d%d , &x, &y); n       v[x].push_back(y); n       v[y].push_back(x); n     } n     dfs(a, -1, 0); n     if (deep[b] <= da) { n       puts( Alice ); n       continue; n     } n     if (da * 2 >= db) { n       puts( Alice ); n       continue; n     } n     ans = 0; n     dfs(1, -1); n     if (da * 2 >= ans) n       puts( Alice ); n     else n       puts( Bob ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Count(int ar[], int m, int n) { n   int count = 0, i; n   for (i = 0; i < n; i++) { n     if (ar[i] == m) { n       count++; n     } n   } n   return count; n } n void change(int br[], int ar[], int n, int clr, int d, int m) { n   int count = 0, i; n   for (i = 0; i < n; i++) { n     if (ar[i] == m) { n       count++; n       br[i] = ceil(float(count) / d) + clr; n       ar[i] = -1; n     } n   } n } n int main() { n   int n, i, cnt = 0; n   cin >> n; n   int ar[n], br[n]; n   for (i = 0; i < n; i++) { n     br[i] = 0; n   } n   for (i = 0; i < n; i++) { n     cin >> ar[i]; n     if (ar[i] == 0) { n       cnt++; n     } n   } n   if (cnt == n) { n     cout <<  Possible n ; n     for (i = 0; i < n; i++) { n       cout << 1 <<    ; n     } n     return 0; n   } n   if (cnt != 0) { n     cout <<  Impossible ; n     return 0; n   } n   int m, count, clr = 0; n   m = *max_element(ar, ar + n); n   while (m != -1) { n     m = *max_element(ar, ar + n); n     count = Count(ar, m, n); n     if ((n - count) > m) { n       cout <<  Impossible ; n       return 0; n     } n     if (m == n - count) { n       change(br, ar, n, clr, count, m); n       clr++; n     } else { n       int bp = m - (n - count); n       if (bp % (count - bp) == 0) { n         change(br, ar, n, clr, count - bp, m); n         clr += count / (count - bp); n       } else { n         cout <<  Impossible ; n         return 0; n       } n     } n     m = *max_element(ar, ar + n); n   } n   cout <<  Possible n ; n   for (i = 0; i < n; i++) { n     cout << br[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct hash_pair { n   template <class T1, class T2> n   size_t operator()(const pair<T1, T2>& p) const { n     auto hash1 = hash<T1>{}(p.first); n     auto hash2 = hash<T2>{}(p.second); n     return hash1 ^ hash2; n   } n }; n string ans =   ; n int flag = 0; n int res = 0; n void permut(string n, int s, int l) { n   if (flag == 1) return; n   if (s == l) { n     if ((res * 10000 + stoi(n)) % 7 == 0) { n       flag = 1; n       ans += n; n     } n     return; n   } n   for (int i = s; i <= l; i++) { n     swap(n[s], n[i]); n     permut(n, s + 1, l); n     swap(n[s], n[i]); n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   string n; n   cin >> n; n   int one = 0; n   int six = 0; n   int eight = 0; n   int nine = 0; n   string zero =   ; n   for (int i = 0; i < n.length(); i++) { n     if (n[i] ==  1  && one == 0) { n       one = 1; n     } else if (n[i] ==  6  && six == 0) { n       six = 1; n     } else if (n[i] ==  8  && eight == 0) { n       eight = 1; n     } else if (n[i] ==  9  && nine == 0) { n       nine = 1; n     } else { n       if (n[i] ==  0  && ans.length() == 0) { n         zero +=  0 ; n       } else { n         ans += n[i]; n         res *= 10; n         res += n[i] -  0 ; n         res %= 7; n       } n     } n   } n   permut( 1689 , 0, 3); n   if (ans.length() != 0) n     cout << ans + zero; n   else n     cout <<  0 ; n } n


#include <bits/stdc++.h> n int main() { n   int i, y, ans, z, b, x[2]; n   for (i = 0; i < 2; i++) { n     scanf( %d , &x[i]); n   } n   y = x[0] * x[1]; n   ans = y / 2; n   { printf( %d , ans); } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NUM = 2e5 + 10; n struct node { n   int index, q; n   bool operator<(const node &a) const { return index + q < a.index + a.q; } n } no[NUM]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d%d , &no[i].index, &no[i].q); n   sort(no, no + n); n   int ans = 1, last = 0; n   for (int i = 1; i < n; i++) { n     if (no[i].index - no[i].q >= no[last].index + no[last].q) { n       last = i; n       ans++; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-9; n const long double PI = acos(-1.0); n const int MX = 1e5 + 5; n long long mod = 1e9 + 7; n pair<long long, int> tr[5 * MX]; n long long lz[5 * MX]; n vector<int> ids[MX]; n int rnum[MX]; n inline void prop(int n, int l, int r) { n   if (lz[n]) { n     tr[n].first += lz[n]; n     if (l != r) lz[n << 1] += lz[n], lz[n << 1 | 1] += lz[n]; n     lz[n] = 0; n   } n } n const long long inf = 1e15; n void bld(int n, int l, int r) { n   if (l == r) { n     if (((int)(ids[l]).size())) n       tr[n] = {ids[l].back(), rnum[l]}; n     else n       tr[n] = {inf, 0}; n     return; n   } n   int m = (l + r) >> 1; n   bld(n << 1, l, m); n   bld(n << 1 | 1, m + 1, r); n   tr[n] = min(tr[n << 1], tr[n << 1 | 1]); n } n int I, L, R, V; n void del(int n, int l, int r) { n   prop(n, l, r); n   if (I < l or I > r) return; n   if (l == r) { n     long long aded = tr[n].first - ids[l].back(); n     ids[l].pop_back(); n     if (((int)(ids[l]).size())) n       tr[n] = {ids[l].back(), rnum[l]}; n     else n       tr[n] = {inf, rnum[l]}; n     tr[n].first += aded; n     return; n   } n   int m = (l + r) >> 1; n   del(n << 1, l, m); n   del(n << 1 | 1, m + 1, r); n   tr[n] = min(tr[n << 1], tr[n << 1 | 1]); n } n void upd(int n, int l, int r) { n   prop(n, l, r); n   if (l > R or r < L) return; n   if (l >= L and r <= R) { n     lz[n] += V; n     prop(n, l, r); n     return; n   } n   int m = (l + r) >> 1; n   upd(n << 1, l, m); n   upd(n << 1 | 1, m + 1, r); n   tr[n] = min(tr[n << 1], tr[n << 1 | 1]); n } n pair<long long, int> qry(int n, int l, int r) { n   prop(n, l, r); n   if (l > R or r < L) return {inf, 0}; n   if (l >= L and r <= R) { n     return tr[n]; n   } n   int m = (l + r) >> 1; n   pair<long long, int> a = qry(n << 1, l, m); n   pair<long long, int> b = qry(n << 1 | 1, m + 1, r); n   tr[n] = min(tr[n << 1], tr[n << 1 | 1]); n   return min(a, b); n } n vector<int> adj[MX]; n int par[MX], sz[MX], heavy[MX]; n void dfs1(int u, int p) { n   par[u] = p; n   sz[u] = 1; n   for (int v : adj[u]) { n     if (v != p) { n       dfs1(v, u); n       sz[u] += sz[v]; n       if (sz[v] > sz[heavy[u]]) heavy[u] = v; n     } n   } n } n int st[MX], chain[MX], num[MX], ed[MX], cl, cn, head[MX]; n void dfs(int u) { n   st[u] = cl; n   chain[u] = cn; n   num[u] = cl; n   rnum[cl++] = u; n   if (heavy[u]) dfs(heavy[u]); n   for (int v : adj[u]) { n     if (v != par[u] and v != heavy[u]) { n       head[++cn] = v; n       dfs(v); n     } n   } n   ed[u] = cl - 1; n } n inline int climb(int u, int v, int n) { n   pair<long long, int> res = {inf, 0}; n   while (chain[u] != chain[v]) { n     if (chain[v] > chain[u]) swap(u, v); n     R = num[u]; n     L = num[head[chain[u]]]; n     res = min(res, qry(1, 0, n - 1)); n     u = par[head[chain[u]]]; n   } n   if (num[v] > num[u]) swap(u, v); n   L = num[v], R = num[u]; n   res = min(res, qry(1, 0, n - 1)); n   if (res.first >= inf) return 0; n   int ret = ids[num[res.second]].back(); n   I = num[res.second]; n   del(1, 0, n - 1); n   return ret; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, q; n   cin >> n >> m >> q; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs1(1, 0); n   head[0] = 1; n   dfs(1); n   for (int i = 1; i <= m; i++) { n     int c; n     cin >> c; n     ids[num[c]].emplace_back(i); n   } n   for (int i = 0; i < n; i++) reverse((ids[i]).begin(), (ids[i]).end()); n   bld(1, 0, n - 1); n   while (q--) { n     int t; n     cin >> t; n     int u, v, k; n     if (t == 1) { n       cin >> u >> v >> k; n       vector<int> ans; n       while (k--) { n         int i = climb(u, v, n); n         if (i) n           ans.push_back(i); n         else n           break; n       } n       cout << ((int)(ans).size()); n       for (int i : ans) cout <<     << i; n       cout <<   n ; n     } else { n       cin >> u >> k; n       L = st[u]; n       R = ed[u]; n       V = k; n       upd(1, 0, n - 1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[105], k; n int n; n bool check(long long x) { n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     sum += (arr[i] + x - 1LL) / x; n   } n   return x * sum <= k; n } n int main(int argc, char const *argv[]) { n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> arr[i], k += arr[i]; n   long long ans = 0; n   for (long long i = 1; i <= sqrt(k) + 1; i++) { n     if (check(i)) ans = max(ans, i); n     if (check(k / i)) ans = max(ans, k / i); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int cnt, n; n   cin >> n; n   cnt = 0; n   cnt += n / 100; n   n %= 100; n   cnt += n / 20; n   n %= 20; n   cnt += n / 10; n   n %= 10; n   cnt += n / 5; n   n %= 5; n   cnt += n; n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n int Cmp(const void *a, const void *b); n int main(void) { n   int i, n, x, w, gpos = -2 * 1000000000, ans = 0, grange[200000][2]; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d%d , &x, &w); n     grange[i][0] = x - w; n     grange[i][1] = x + w; n   } n   qsort(grange, n, sizeof(int) * 2, Cmp); n   for (i = 0; i < n; i++) { n     if (gpos <= grange[i][0]) { n       ans++; n       gpos = grange[i][1]; n     } n   } n   printf( %d n , ans); n } n int Cmp(const void *a, const void *b) { n   int ta = *(*(int(*)[2])a + 1), tb = *(*(int(*)[2])b + 1); n   if (ta > tb) n     return 1; n   else if (tb > ta) n     return -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n); n     map<int, int> cur; n     set<pair<int, int>> st; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       if (!cur.count(a[i])) { n         st.insert(make_pair(a[i], i)); n       } n       cur[a[i]] = i; n     } n     if (st.size() == 1) { n       cout <<  NO  << endl; n       continue; n     } else { n       cout <<  YES  << endl; n       vector<pair<int, int>> res; n       auto e = st.begin(), g = prev(st.end()); n       for (int i = 0; i < n; i++) { n         if (a[i] != e->first) { n           res.emplace_back(i + 1, e->second + 1); n         } else if (i != g->second && i != e->second) n           res.emplace_back(i + 1, g->second + 1); n       } n       for (auto j : res) cout << j.first <<     << j.second << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool a[1000010]; n int main() { n   memset(a, 0, sizeof(a)); n   int n, ans = 0; n   cin >> n; n   int f = 2; n   for (;;) { n     if (a[f] == 0) { n       for (int i = 2 * f; i <= 1000000; i = i + f) a[i] = 1; n     } n     f++; n     if (f == 1000000) break; n   } n   for (int i = 10;; i++) { n     int i1 = i, i2 = 0; n     while (i1 > 0) { n       i2 = i2 * 10 + i1 % 10; n       i1 = i1 / 10; n     } n     if (a[i2] == 0 && a[i] == 0 && i2 != i) ans++; n     if (ans == n) { n       cout << i << endl; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Max = INT_MIN, Min = INT_MAX; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, m, mx = 0; n   cin >> n >> m; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n - 1; i++) { n     if ((a[i] - a[i + 1] - m) > mx) { n       mx = (a[i] - a[i + 1] - m); n     } n   } n   cout << ((mx > 0) ? mx : 0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, n, i, j, z, mx; n string s, s2; n int main() { n   cin >> a >> b >> c; n   mx = max(max(a, b), c); n   for (i = 1; i <= mx; i++) { n     for (j = 1; j <= mx; j++) { n       z = c / j; n       if (i * j == a && i * z == b && j * z == c) { n         cout << i * 4 + j * 4 + z * 4; n         return 0; n       } n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e6; n long long seg_t[MAXN * 4]; n long long n, k, cur, ans = 1; n void add(long long u, long long curl, long long curr, long long l, long long r, n          long long delta) { n   long long curm = (curl + curr) / 2; n   if (l == curl && r == curr) { n     seg_t[u] += delta; n     return; n   } n   if (l <= curm) { n     if (r >= curm) { n       add(u * 2, curl, curm, l, curm, delta); n     } else { n       add(u * 2, curl, curm, l, r, delta); n     } n   } n   if (r >= curm + 1) { n     if (l <= curm + 1) { n       add(u * 2 + 1, curm + 1, curr, curm + 1, r, delta); n     } else { n       add(u * 2 + 1, curm + 1, curr, l, r, delta); n     } n   } n } n long long get(long long u, long long curl, long long curr, long long x) { n   long long ret = 0; n   long long curm = (curl + curr) / 2; n   ret += seg_t[u]; n   if (curl == curr) return ret; n   if (x <= curm) { n     ret += get(u * 2, curl, curm, x); n   } else if (x >= curm + 1) { n     ret += get(u * 2 + 1, curm + 1, curr, x); n   } n   return ret; n } n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   k = min(k, n - k); n   long long r, l = 1; n   for (long long i = 0; i < n; ++i) { n     r = l + k; n     if (r > n) { n       add(1, 1, n + 1, l + 1, n + 1, 1); n       r -= n; n       if (r > 1) add(1, 1, n + 1, 1, r - 1, 1); n     } else { n       add(1, 1, n + 1, l + 1, r - 1, 1); n     } n     ans += 1 + get(1, 1, n + 1, l) + get(1, 1, n + 1, r); n     cout << ans <<    ; n     l = r; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100; n int ara[N]; n int main() { n   int n = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , ara + i); n   } n   if (n == 1) n     puts( -1 ); n   else if (n == 2 && ara[0] == ara[1]) n     puts( -1 ); n   else { n     int mn = 10000; n     int nm = 0; n     for (int i = 0; i < n; ++i) { n       if (ara[i] < mn) { n         mn = ara[i]; n         nm = i; n       } n     } n     ++nm; n     printf( 1 n%d n , nm); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define int long long n struct node{ n  int x, y, id; n  bool operator <(const node& W) const{ n   if (W.x != x) return x < W.x; n   else return y < W.y; n  } n }; n  n void work() { n  int n; n  cin >> n; n  vector<node> v(n); n  for (int i = 0; i < n; i++) { n   int x, y; n   cin >> x >> y; n   if (x > y) swap(x, y); n   v[i] = {x, y, i + 1}; n  } n  sort(v.begin(), v.end()); n  vector<int> res(n + 1); n  int pos = -1; n   n  for (int i = 0; i < v.size(); i++) { n   int j = i; n   while (j < v.size() && v[i].x == v[j].x) j++; n   j--; n   if (pos == -1) for (int k = i; k <= j; k++) res[v[k].id] = -1; n   else { n    for (int k = i; k <= j; k++)  n     if (v[k].y > v[pos].y) res[v[k].id] = v[pos].id; n     else res[v[k].id] = -1; n   } n   if (pos == -1) pos = 0; n   else if (v[i].y < v[pos].y) pos = i; n   i = j; n  } n   n  for (int i = 1; i < res.size(); i++) cout << res[i] <<    ; n  cout << endl; n } n int32_t main() { n  ios::sync_with_stdio(false); n  cin.tie(0); n  int cas; n  cin >> cas; n  while (cas--) work(); n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n vector<long long int> sieve; n vector<long long int> *Sieve(int N) { n   const long long int maxn = N; n   sieve.resize(maxn); n   for (long long int(i) = 0; (i) < (maxn); ++(i)) sieve[i] = 1; n   sieve[1] = 0; n   sieve[0] = 0; n   for (long long int(i) = 2; (i) <= (maxn); (i) += (1)) n     if (1 == sieve[i]) n       for (long long int j = i * i; j < maxn; j += i) sieve[j] = 0; n   vector<long long int> *primes = new vector<long long int>(); n   primes->push_back(2); n   for (int i = 3; i < maxn; i += 2) n     if (sieve[i]) { n       primes->push_back(i); n     } n   return primes; n } n long long int extended_GCD(long long int a, long long int b, long long int &x, n                            long long int &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long int x1, y1; n   long long int gcd = extended_GCD(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return gcd; n } n long long int ncr(long long int n, long long int k) { n   long long int r = 1; n   if (k > n - k) k = n - k; n   for (long long int i = 0; i < k; i++) { n     r *= (n - i); n     r /= (i + 1); n   } n   return r; n } n long long int power(long long int a, long long int b, n                     long long int m = 1000000007) { n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % m; n     a = (a * a) % m; n     b >>= 1; n   } n   return res; n } n long long int modinv(long long int a, long long int mod = 1000000007) { n   long long int x, y; n   extended_GCD(a, mod, x, y); n   if (x < 0) x += mod; n   return x; n } n bool prime(int n) { n   int c = 0; n   for (int i = 2; (i * i) <= n; i++) { n     if (n % i == 0) { n       c++; n       return false; n     } n   } n   if (c == 0) return true; n } n vector<int> v[200006]; n int vis[200006]; n int c; n void dfs(int n) { n   vis[n] = 1; n   c++; n   for (int i : v[n]) { n     if (!vis[i]) dfs(i); n   } n } n int a[100001]; n void solve() { n   int n, k; n   cin >> n >> k; n   int a[n]; n   for (long long int(i) = 0; (i) < (n); ++(i)) cin >> a[i]; n   int sa = 1, sb = 1; n   double ca = 0, cb = k; n   int i = 0, j = n - 1; n   double ans = 0; n   while (i <= j) { n     double t1, t2, d1, d2; n     d1 = a[i] - ca; n     d2 = cb - a[j]; n     t1 = (double)d1 / sa; n     t2 = (double)d2 / sb; n     if (t1 <= t2) { n       ans += t1; n       ca += d1; n       i++; n       sa++; n       cb -= (double)t1 * sb; n     } else { n       ans += t2; n       cb -= d2; n       j--; n       sb++; n       ca += (double)t2 * sa; n     } n   } n   ans += double(cb - ca) / (sa + sb); n   cout << fixed << setprecision(10) << ans; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long int  n int main() n { n     int t; n     cin>>t; n     while(t--) n     { n         ll n; n         cin>>n; n         vector<ll>a(n); n         for(ll i=0;i<n;i++) n         { n             cin>>a[i]; n         } n         ll maxi=INT_MIN; n         for(ll i=n-1;i>-1;i--) n         { n             ll total=0; n             total+=a[i]; n             if(i+a[i]<n) n             { n                 total+=a[i+a[i]]; n             } n             a[i]=total; n             maxi=max<ll>(maxi,total); n         } n         //cout<<  t ; n         cout<<maxi<<  n ; n     } n }


#include <bits/stdc++.h> n using namespace std; n class subtractions { n  private: n   int _a, _b; n   int _operations; n   bool even_divide(int& a, int& b) { n     if (b > a && !(b % a)) { n       _operations += (b / a); n       return true; n     } else if (a >= b && !(a % b)) { n       _operations += (a / b); n       return true; n     } n     return false; n   } n   bool quick_divide(int& a, int& b) { n     if (b > a) { n       int factor = b / a; n       b -= a * factor; n       _operations += factor; n       return true; n     } else if (a >= b) { n       int factor = a / b; n       a -= b * factor; n       _operations += factor; n       return true; n     } n     return false; n   } n  n  public: n   subtractions(int a = 0, int b = 0) : _a(a), _b(b) { _operations = 0; } n   int operate() { n     while (_a > 0 && _b > 0) { n       if (even_divide(_a, _b)) break; n       if (quick_divide(_a, _b)) continue; n       ++_operations; n     } n     return _operations; n   } n }; n int main() { n   int tests = 0; n   cin >> tests; n   while (tests > 0) { n     int a, b; n     cin >> a >> b; n     subtractions s(a, b); n     cout << s.operate() << endl; n     --tests; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n long long w[3][300500]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0, qwerty = n; i < qwerty; i++) { n     cin >> s; n     stack<char> st; n     st.push(s[0]); n     for (int j = 1, qwerty = s.size(); j < qwerty; j++) { n       char c = s[j]; n       if (!st.empty() && c ==  )  && st.top() ==  ( ) n         st.pop(); n       else n         st.push(c); n     } n     int r1 = 0, r2 = 0; n     while (!st.empty()) { n       if (st.top() ==  ( ) n         r1++; n       else n         r2++; n       st.pop(); n     } n     if (r1 && r2) continue; n     if (r1 + r2 == 0) n       w[2][0]++; n     else if (r1) n       w[0][r1]++; n     else if (r2) n       w[1][r2]++; n   } n   long long ans = w[2][0] * w[2][0]; n   if (w[2][0] == 1) ans = 1; n   for (int i = 0, qwerty = 300200; i < qwerty; i++) ans += w[0][i] * w[1][i]; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, t; n   cin >> t; n   while (t--) { n     cin >> a >> b; n     int num = abs(a - b); n     if (a > b && num % 2 != 0) n       cout << 2 << endl; n     else if (a < b && num % 2 != 0) n       cout << 1 << endl; n     else if (a > b && num % 2 == 0) n       cout << 1 << endl; n     else if (a < b && num % 2 == 0) n       cout << 2 << endl; n     else if (a == b) n       cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct DSU { n   struct Node { n     int pr; n     long long max_sum; n     long long max_pref; n     long long sum; n     long long max_suff; n   }; n   vector<Node> t; n   multiset<long long> mx; n   DSU(int n, vector<int>& c) { n     t.resize(n); n     for (int i = 0; i < n; ++i) { n       t[i].pr = i; n       t[i].sum = c[i]; n       t[i].max_sum = max(0, c[i]); n       t[i].max_pref = max(0, c[i]); n       t[i].max_suff = max(0, c[i]); n       mx.insert(t[i].max_sum); n     } n   } n   int f(int v) { n     if (t[v].pr != v) { n       t[v].pr = f(t[v].pr); n     } n     return t[v].pr; n   } n   void merge(int x, int y) { n     x = f(x); n     y = f(y); n     if (x == y) { n       return; n     } n     t[x].pr = y; n     mx.erase(mx.lower_bound(t[x].max_sum)); n     mx.erase(mx.lower_bound(t[y].max_sum)); n     Node new_node; n     new_node.sum = t[x].sum + t[y].sum; n     new_node.pr = y; n     new_node.max_sum = max(t[y].max_sum, t[x].max_sum); n     new_node.max_sum = max(new_node.max_sum, t[x].max_suff + t[y].max_pref); n     new_node.max_pref = max(t[x].max_pref, t[x].sum + t[y].max_pref); n     new_node.max_suff = max(t[y].max_suff, t[y].sum + t[x].max_suff); n     new_node.max_sum = max(new_node.max_sum, 0LL); n     new_node.max_pref = max(new_node.max_pref, 0LL); n     new_node.max_suff = max(new_node.max_suff, 0LL); n     t[y] = new_node; n     mx.insert(t[y].max_sum); n   } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   long long m; n   cin >> n >> m; n   vector<int> d(n), c(n); n   for (int i = 0; i < n; ++i) { n     cin >> d[i] >> c[i]; n     c[i] = m - c[i]; n   } n   set<pair<int, int> > q; n   for (int i = 0; i + 1 < n; ++i) { n     q.insert({d[i + 1] - d[i], i}); n   } n   q.insert({-1, -1}); n   DSU t(n, c); n   long long ans = 0; n   while (q.size()) { n     auto i = *q.begin(); n     q.erase(q.begin()); n     if (i.second != -1) { n       t.merge(i.second, i.second + 1); n       ans = max(ans, *--t.mx.end() - i.first * 1LL * i.first); n     } else { n       ans = max(ans, *--t.mx.end()); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n int main(int argc, char *argv[]) { n   int n; n   scanf( %d , &n); n   int i; n   if (n % 2 != 0) { n     printf( -1 n ); n   } else { n     if (n > 2) { n       for (i = 1; i <= n - 2; i++) { n         printf( %d  , i + 1); n         printf( %d  , i); n         i++; n       } n     } n     printf( %d  , n); n     printf( %d n , n - 1); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long int i, j, ft; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long int n; n   cin >> n; n   vector<long long int> v[n]; n   for (i = 0; i < (n - 1); i++) { n     long long int b, c; n     cin >> b >> c; n     v[b - 1].push_back(c - 1); n     v[c - 1].push_back(b - 1); n   } n   vector<long long int> l(n, 0); n   queue<long long int> s; n   s.push(0); n   l[0] = 1; n   while (!s.empty()) { n     long long int front = s.front(); n     s.pop(); n     for (i = 0; i < (v[front].size()); i++) { n       if (!l[v[front][i]]) { n         s.push(v[front][i]); n         l[v[front][i]] = l[front] + 1; n       } n     } n   } n   long long int odd = 0, even = 0; n   for (i = 0; i < (n); i++) { n     if (l[i] % 2) n       odd++; n     else n       even++; n   } n   cout << odd * even - n + 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n % 2) n     cout <<  contest ; n   else n     cout <<  home ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std;  n   n #define FASTIO           ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); n #define TEST             ll Test ; cin >> Test; while n #define TEST2            int Test = 1; while n #define READ             freopen( input.txt ,  r , stdin); freopen( output.txt ,  w , stdout); n #define INP(a, n)        for(ll i=0;i<(ll)n;i++) cin>>a[i] ; n #define INPA(a, n)       ll a[n]; for(ll i=0;i<(ll)n;i++) cin>>a[i] ; n #define INPV(a, n)       ll TrT; for(int i=0;i<(ll)n;i++){cin>>TrT; a.push_back(TrT);} n #define OUT(a, n)        for(ll i=0;i<(ll)n;i++)cout<<a[i]<<   ; n #define forp(i,a,b)      for(ll i=a;i<(ll)b;i++) n #define fore(i,a,b)      for(ll i=a;i<=(ll)b;i++) n #define fora(x)          for(auto &it: x) n #define INF              LLONG_MAX n #define sz               size() n #define len              length() n #define beg              begin() n #define en               end() n #define all(x)           x.beg,x.en n #define ff               first n #define ss               second n #define pb               push_back n #define pp               pop_back n #define lb               lower_bound n #define ub               upper_bound n #define N                  n  n #define YES(n)           cout << ((n) ?  YES  :  NO ) <<   n  ; n #define Yes(n)           cout << ((n) ?  Yes  :  No ) <<   n  ; n #define fix(f,n)         fixed << setprecision(n) << f  n #define M                1000000007 n #define MM               998244353 n  n #define TRACE n  n #ifdef TRACE n     #define d(...) __f(#__VA_ARGS__, __VA_ARGS__) n     template <typename Arg1> n         void __f(const char* name, Arg1&& arg1) { cout << name <<   =   << arg1 << endl; } n     template <typename Arg1, typename... Args> n         void __f( const char* names, Arg1&& arg1, Args&&... args) {const char* comma = strchr(names + 1,  , ); cout.write(names, comma - names) <<   =   << arg1 <<    ; __f(comma + 1, args...); } n #else n     #define d(...) n #endif n   n typedef long long int ll; n typedef long double ld; n typedef unsigned long long ull; n typedef vector<int> vi; n typedef vector<ll> vll; n typedef vector<vector<int>> vvi; n typedef vector<vector<ll>> vvll; n typedef vector<vector<ld>> vvld; n typedef pair<ll, ll> pll; n typedef vector<int> vi ; n typedef vector<pair<int, int>> vpi; n typedef vector<pair<ll,ll> > vpll; n  n  n  n void solve() { n     ll p, a, b, c, temp, ans = INF; n     cin >> p; n     ll v[3]; n     forp(i, 0, 3) cin >> v[i]; n     forp(i, 0, 3) { n         temp = p/v[i]; n         if(p % v[i] != 0) temp++; n         ll x = temp * v[i]; n         // d(x); n         ans = min(x - p, ans); n     } n     cout << ans << N; n } n  n int main() { FASTIO  n     #ifndef ONLINE_JUDGE n         // READ n     #endif  n     TEST(Test--) n     {  n         solve(); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long fac[300011], inv[300011]; n int F, W, H; n long long fastpower(long long v, long long p) { n   long long ret = 1; n   while (p > 0) { n     if (p % 2 == 1) { n       ret = ret * v; n       ret %= mod; n       p--; n     } else { n       v = v * v; n       v %= mod; n       p /= 2; n     } n   } n   return ret; n } n void init() { n   fac[0] = inv[0] = 1; n   for (int i = 1; i < 300011; ++i) { n     fac[i] = fac[i - 1] * i; n     inv[i] = inv[i - 1] * fastpower(i, mod - 2); n     fac[i] %= mod; n     inv[i] %= mod; n   } n } n long long C(int n, int k) { n   if (n < k) return 0; n   return ((fac[n] * inv[k]) % mod * inv[n - k]) % mod; n } n long long add(long long v, long long u) { return (v + u) % mod; } n long long cost(long long n, long long k, long long low) { n   n = n - k * low; n   if (n < 0) return 0; n   return C(n + k - 1, n); n } n long long calc(int num, int limit) { n   long long v1 = cost(F, num, 1) * cost(W, num, limit) * 2; n   long long v2 = cost(F, num, 1) * cost(W, num + 1, limit); n   long long v3 = cost(F, num, 1) * cost(W, num - 1, limit); n   return add(add(v1, v2), v3); n } n int main() { n   init(); n   scanf( %d%d%d , &F, &W, &H); n   H++; n   if (W == 0) { n     printf( 1 n ); n     return 0; n   } n   if (W < H) { n     printf( 0 n ); n     return 0; n   } n   if (W == 0) { n     printf( 1 n ); n     return 0; n   } n   if (F == 0) { n     printf( 1 n ); n     return 0; n   } n   long long ans = 0; n   for (int i = 1; i <= F; ++i) { n     ans += calc(i, H); n     ans %= mod; n   } n   ans = ans + mod; n   ans %= mod; n   ans = ans * fastpower(C(W + F, W), mod - 2); n   ans = ans % mod; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int m, p, l, q = 0, r, t = 0; n   long long int n, k = 0, i, j = 0; n   string s; n   getline(cin, s); n   j = 0; n   for (i = 0; i < s.size(); i++) { n     if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || s[i] ==  u ) n       j++; n   } n   if (j == 5) k++; n   j = 0; n   string s1; n   getline(cin, s1); n   j = 0; n   for (i = 0; i < s1.size(); i++) { n     if (s1[i] ==  a  || s1[i] ==  e  || s1[i] ==  i  || s1[i] ==  o  || n         s1[i] ==  u ) n       j++; n   } n   if (j == 7) k++; n   j = 0; n   string s2; n   getline(cin, s2); n   j = 0; n   for (i = 0; i < s2.size(); i++) { n     if (s2[i] ==  a  || s2[i] ==  e  || s2[i] ==  i  || s2[i] ==  o  || n         s2[i] ==  u ) n       j++; n   } n   if (j == 5) k++; n   if (k == 3) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> smax, smin; n int ox[100000], oy[100000]; n map<pair<int, int>, int> pnts; n inline int eval(int x, int y) { n   if (pnts.count({x, y})) { n     return pnts.count({x, y - 1}) + pnts.count({x - 1, y - 1}) + n            pnts.count({x + 1, y - 1}); n   } n   return 3; n } n inline bool isOk(int x, int y) { n   return (eval(x, y + 1) > 1) && (eval(x - 1, y + 1) > 1) && n          (eval(x + 1, y + 1) > 1); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cerr <<  -.- ; n   int m; n   cin >> m; n   for (int i = 0; i < m; ++i) { n     cin >> ox[i] >> oy[i]; n     pnts.insert({{ox[i], oy[i]}, i}); n   } n   for (int i = 0; i < m; ++i) { n     if (isOk(ox[i], oy[i])) { n       smax.insert(-i), smin.insert(i); n     } n   } n   int turn = 0; n   vector<int> path; n   int dd[] = {0, -1, 1, -2, 2}; n   while (((int)(smax).size())) { n     int i = (turn == 0) ? -(*smax.begin()) : (*smin.begin()); n     smin.erase(i), smax.erase(-i); n     path.push_back(i), pnts.erase({ox[i], oy[i]}); n     for (int d = 1; d < 5; ++d) { n       auto it = pnts.find({ox[i] + dd[d], oy[i]}); n       if (it != pnts.end()) { n         int j = it->second; n         if (!isOk(ox[j], oy[j])) { n           smax.erase(-j), smin.erase(j); n         } n       } n     } n     for (int d = 0; d < 3; ++d) { n       auto it = pnts.find({ox[i] + dd[d], oy[i] - 1}); n       if (it != pnts.end()) { n         int j = it->second; n         if (isOk(ox[j], oy[j])) { n           smax.insert(-j), smin.insert(j); n         } n       } n     } n     turn ^= 1; n   } n   int ans = 0; n   for (int i = 0; i < ((int)(path).size()); ++i) { n     ans = ((1ll * ans * m) + path[i]) % 1000000009; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using LL = int64_t; n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int n; n   std::cin >> n; n   std::vector<int> a(n); n   for (int &i : a) std::cin >> i; n   std::sort(a.begin(), a.end()); n   int maxa = a.back(); n   std::vector<std::vector<int>> mx(maxa + 1); n   for (auto &i : mx) i.assign(2, -1); n   std::vector<int> cnt(maxa + 1); n   for (int i : a) ++cnt[i]; n   for (int i = 1; i <= maxa; ++i) { n     if (cnt[i] >= 2) n       mx[i][0] = mx[i][1] = i; n     else if (cnt[i] == 1) { n       mx[i][0] = i; n       mx[i][1] = mx[i - 1][0]; n     } else n       mx[i] = mx[i - 1]; n     cnt[i] += cnt[i - 1]; n   } n   LL ans = 0; n   for (int y = 2; y <= maxa; ++y) { n     int more[] = {-1, -1}; n     LL cnty = 0; n     for (int k = 1; k <= maxa / y; ++k) n       cnty += (LL)k * (cnt[std::min((k + 1) * y - 1, maxa)] - cnt[k * y - 1]); n     for (int k = maxa / y; k >= 0; --k) { n       more[1] = n           std::max(more[1], mx[std::min((k + 1) * y - 1, maxa)][0] - k * y); n       if (more[0] < more[1]) std::swap(more[0], more[1]); n       more[1] = n           std::max(more[1], mx[std::min((k + 1) * y - 1, maxa)][1] - k * y); n       int x = std::min((LL)(k * y + more[0]) / 2, cnty - k); n       if (x >= 2) ans = std::max(ans, LL(x) * y); n       if (more[1] != -1) { n         x = std::min((LL)k * y + more[1], cnty - 2 * k); n         if (x >= 2) ans = std::max(ans, LL(x) * y); n       } n       if (n - cnt[std::max(0, k * y + more[0] - 1)] >= 2) { n         x = std::min((LL)k * y + more[0], cnty - 2 * k - 1); n         if (x >= 2) ans = std::max(ans, LL(x) * y); n       } n     } n   } n   std::cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using VI = vector<int>; n using PII = pair<int, int>; n const int N = 1005, INF = 1e9; n vector<PII> adj[N]; n int dis[N][N]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   vector<tuple<int, int, int>> edges; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     adj[u].emplace_back(v, w); n     adj[v].emplace_back(u, w); n     edges.emplace_back(u, v, w); n   } n   vector<PII> paths(k); n   for (auto &[u, v] : paths) cin >> u >> v; n   for (int s = 1; s <= n; s++) { n     for (int u = 1; u <= n; u++) { n       dis[s][u] = s == u ? 0 : INF; n     } n     priority_queue<PII> heap; n     heap.emplace(0, s); n     while (!heap.empty()) { n       int u = heap.top().second; n       heap.pop(); n       for (auto [v, w] : adj[u]) { n         if (dis[s][v] > dis[s][u] + w) { n           dis[s][v] = dis[s][u] + w; n           heap.emplace(-dis[s][v], v); n         } n       } n     } n   } n   ll ans = 1e18; n   for (auto [u, v, w] : edges) { n     ll cur = 0; n     for (auto [x, y] : paths) { n       cur += min({dis[x][y], dis[x][u] + dis[v][y], dis[x][v] + dis[u][y]}); n     } n     ans = min(ans, cur); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   register int x = 0, f = 1, ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n int n; n int a[1010]; n int b[1010]; n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     a[i] = read(); n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) { n     if (i & 1) n       printf( %d  , a[(i + 1) / 2]); n     else n       printf( %d  , a[n - i / 2 + 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string x; n   cin >> x; n   int xx = 0; n   int ans = 0; n   for (int i = 0; i < x.size(); i++) { n     if (x[i] ==  ( ) n       xx++; n     else if (xx) n       xx--, ans++; n   } n   cout << ans * 2; n } n


#include <bits/stdc++.h> n using namespace std; n int f[201000], l[201000], r[201000]; n int n; n int a[201000], s[201000]; n int top; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   top = 0; n   s[top] = 0; n   a[0] = 0; n   for (int i = 1; i <= n; i++) { n     while (a[s[top]] >= a[i]) top--; n     l[i] = s[top] + 1; n     top++; n     s[top] = i; n   } n   top = 0; n   s[top] = n + 1; n   a[n + 1] = 0; n   for (int i = n; i >= 1; i--) { n     while (a[s[top]] >= a[i]) top--; n     r[i] = s[top] - 1; n     top++; n     s[top] = i; n   } n   for (int i = 1; i <= n; i++) n     f[r[i] - l[i] + 1] = max(f[r[i] - l[i] + 1], a[i]); n   for (int i = n; i >= 1; i--) f[i] = max(f[i], f[i + 1]); n   for (int i = 1; i <= n; i++) cout << f[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t dfs(int64_t idx, int64_t p, vector<vector<int64_t>>& g, n             vector<int64_t>& parents, int64_t& c1, int64_t& c2) { n   int64_t n = g.size() - 1; n   parents[idx] = p; n   int64_t res = 1; n   int64_t mx = 0; n   for (auto& x : g[idx]) { n     if (x != p) { n       int64_t a = dfs(x, idx, g, parents, c1, c2); n       res += a; n       mx = max(mx, a); n     } n   } n   mx = max(mx, n - res); n   if (mx <= n / 2) { n     if (c1 == -1) { n       c1 = idx; n     } else { n       c2 = idx; n     } n   } n   return res; n } n int64_t leaf(int64_t idx, int64_t p, vector<vector<int64_t>>& g) { n   if (g[idx].size() == 1) { n     return idx; n   } else { n     auto res = -1; n     for (auto& e : g[idx]) { n       if (e != p) { n         res = leaf(e, idx, g); n         if (res != -1) { n           return res; n         } n       } n     } n   } n   return -1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int64_t tc; n   cin >> tc; n   while (tc--) { n     int64_t n; n     cin >> n; n     vector<vector<int64_t>> g(n + 1); n     for (int64_t i = 0; i < n - 1; i++) { n       int64_t a; n       int64_t b; n       cin >> a >> b; n       g[a].push_back(b); n       g[b].push_back(a); n     } n     int64_t c1 = -1; n     int64_t c2 = -1; n     vector<int64_t> p(n + 1); n     dfs(1, 0, g, p, c1, c2); n     if (c2 == -1) { n       int64_t rm = g[c1][0]; n       cout << c1 <<     << rm << endl; n       cout << c1 <<     << rm << endl; n     } else { n       if (p[c2] != c1) { n         swap(c1, c2); n       } n       int64_t rm = leaf(c2, c1, g); n       cout << rm <<     << p[rm] << endl; n       cout << rm <<     << c1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #define int long long n #define INF (1e15 + 7) n #define pii pair<int, int> n  n using namespace std; n  n struct Node { n     int x, y; n     Node(int _x = 0, int _y = 0) : x(_x), y(_y) {} n     bool operator<(const Node &u)const { n         if (x < u.x) return true; n         if (x > u.x) return false; n         return y > u.y; n     } n }; n  n const int MAX_N = 2e5 + 7; n Node in[MAX_N], de[MAX_N]; n vector<pii> ab, ba; n int a[MAX_N], b[MAX_N]; n int n, mx, dis, top; n  n inline int low_bound(vector<pii> &s, int x) { n     while (top && s[top - 1].first > x) { n         --top; n     } n     if (!top) return -1; n     return s[top - 1].second; n }    n  n signed main() { n     // freopen( in.txt ,  r , stdin); n     scanf( %lld , &n); n     for (int i = 1; i <= n; ++i) scanf( %lld , a + i); n     for (int i = 1; i <= n; ++i) scanf( %lld , b + i); n     int n1 = 0, n2 = 0; n     for (int i = 1; i <= n; ++i) { n         if (a[i] < b[i]) in[++n1] = Node(a[i], b[i]); n         else if (a[i] > b[i]) de[++n2] = Node(b[i], a[i]); n         dis += abs(a[i] - b[i]); n     } n     sort(in + 1, in + 1 + n1); n     sort(de + 1, de + 1 + n2); n     int len1 = 0, len2 = 0; n     for (int i = 1; i <= n1; ++i) { n         if (!len1 || in[i].y > ab[len1 - 1].second) { n             ab.push_back(pii(in[i].x, in[i].y)); n             ++len1; n         } n     } n     for (int i = 1; i <= n2; ++i) { n         if (!len2 || de[i].y > ba[len2 -1].second) { n             ba.push_back(pii(de[i].x, de[i].y)); n             ++len2; n         } n     } n     top = len2; n     for (int i = len1 - 1; i >= 0; --i) { n         int y = low_bound(ba, ab[i].first); n         if (~y) mx = max(mx, min(y, ab[i].second) - ab[i].first); n     } n     top = len1; n     for (int i = len2 - 1; i >= 0; --i) { n         int y = low_bound(ab, ba[i].first); n         if (~y) mx = max(mx, min(y, ba[i].second) - ba[i].first); n     } n     printf( %lld n , dis - mx * 2); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n double dp[2][605]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   int pre = 0, cur = 1; n   for (int i = 0; i < n; ++i) { n     memset(dp[cur], 0, sizeof dp[cur]); n     for (int j = 1; j < 600; ++j) n       dp[cur][j] += (1. * j / k / (j + 1) + (k - 1.) / k) * dp[pre][j] + n                     1. * (dp[pre][j + 1] + j) / ((j + 1.) * k) + 1. * j / 2 / k; n     swap(pre, cur); n   } n   printf( %.15f n , k * dp[pre][1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long tree[1000001]; n int n; n void update(int x, long long val) { n   for (int i = x; i <= n; i += i & (-i)) { n     tree[i] += val; n   } n } n long long query(int x) { n   long long sum = 0; n   while (x > 0) { n     sum += tree[x]; n     x -= x & (-x); n   } n   return sum; n } n int main() { n   int m, i, j = 2, k; n   long long l = 1; n   cin >> n >> k; n   m = 0; n   int count = 0; n   i = 1; n   while (count < n) { n     j = (i + k) % n; n     if (!j) j = n; n     m = i % n; n     if (!m) m = n; n     if (m > j) { n       l += min(query(j - 1) + query(n) - query(m), query(m - 1) - query(j)) + n            (long long)1; n     } else { n       l += min(query(j) - query(m), query(m - 1) + query(n) - query(j)) + n            (long long)1; n     } n     cout << l <<    ; n     update(m, 1); n     update(j, 1); n     count++; n     i = j; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n long long my_pow(long long a, long long n) { n   long long res = 1; n   while (n) { n     if (n & 1) res *= a; n     a *= a; n     n >>= 1; n   } n   return res; n } n const int mn = 10010; n vector<int> v[mn]; n vector<int> s(mn, 0); n void dfs(int vert, int c) { n   s[vert] = c; n   for (auto it : v[vert]) dfs(it, c); n } n int main() { n   int n, k; n   cin >> n; n   int c[n + 10]; n   for (int i = 2; i <= n; i++) { n     scanf( %d , &k); n     v[k].push_back(i); n   } n   for (int i = 1; i <= n; i++) scanf( %d , &c[i]); n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (s[i] != c[i]) { n       dfs(i, c[i]); n       ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 100010; n const int M = 30; n std::map<std::string, int> Hash; n int fa[N << 1], n, m, q; n char s[M]; n int find(int u) { return fa[u] == u ? u : fa[u] = find(fa[u]); } n void unite(int u, int v) { n   int _u = find(u), _v = find(v); n   fa[_u] = _v; n   find(u); n } n int main() { n   for (int i = 0; i < N << 1; ++i) { n     fa[i] = i; n   } n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 0; i < n; ++i) { n     scanf( %s , s); n     std::string str = s; n     Hash[str] = i; n   } n   for (int i = 0, type; i < m; ++i) { n     scanf( %d%s , &type, s); n     std::string str = s; n     int u = Hash[str]; n     scanf( %s , s); n     str = s; n     int v = Hash[str]; n     find(u), find(v), find(v + n), find(u + n); n     if (type == 1) { n       if (fa[u] == fa[v + n] || fa[v] == fa[u + n]) { n         printf( NO n ); n         continue; n       } n       printf( YES n ); n       unite(u, v); n       unite(u + n, v + n); n       continue; n     } n     if (type == 2) { n       if (fa[u] == fa[v] || fa[u + n] == fa[v + n]) { n         printf( NO n ); n         continue; n       } n       printf( YES n ); n       unite(u, v + n); n       unite(u + n, v); n     } n   } n   for (int i = 0; i < q; ++i) { n     scanf( %s , s); n     std::string str = s; n     int u = Hash[str]; n     scanf( %s , s); n     str = s; n     int v = Hash[str]; n     find(u), find(v), find(u + n), find(v + n); n     if (fa[u] == fa[v] || fa[u + n] == fa[v + n]) { n       printf( 1 n ); n     } else if (fa[u] == fa[v + n] || fa[u + n] == fa[v]) { n       printf( 2 n ); n     } else { n       printf( 3 n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int bst(int a[], int lw, int hi, int n) { n   int mid = (lw + hi) / 2; n   if (lw > hi) return -1; n   if (a[mid] > n) n     bst(a, lw, mid - 1, n); n   else if (a[mid] < n) n     bst(a, mid + 1, hi, n); n   else n     return mid; n } n long long pw(long long a, long long b, long long p) { n   if (b == 0) return 1; n   long long t = pw(a, b / 2, p); n   if (b % 2) n     return (((a * t) % p) * t) % p; n   else n     return ((t * t) % p); n } n void solve() { n   string s; n   long long ct1 = 0, ct2 = 0, V = 0, H = 0; n   cin >> s; n   if (s.size() == 1) { n     cout << 2 << endl; n     return; n   } n   vector<long long> v1, v2; n   v1.push_back(0); n   v2.push_back(0); n   long long i = 0, k = 0, t = 0; n   while (i < s.size()) { n     if (s[i] ==  W ) { n       v1.push_back(++ct1); n     } else if (s[i] ==  S ) { n       v1.push_back(--ct1); n     } else if (s[i] ==  D ) { n       v2.push_back(++ct2); n     } else { n       v2.push_back(--ct2); n     } n     i++; n   } n   if (v1.size() == 2) { n     V = 1; n   } n   if (v2.size() == 2) { n     H = 1; n   } n   long long lw1 = *min_element(v1.begin(), v1.end()), n             hi1 = *max_element(v1.begin(), v1.end()); n   long long lw2 = *min_element(v2.begin(), v2.end()), n             hi2 = *max_element(v2.begin(), v2.end()); n   vector<long long> min1_pos, min2_pos, max1_pos, max2_pos; n   for (i = 0; i < v1.size(); i++) { n     if (v1[i] == lw1) min1_pos.push_back(i); n     if (v1[i] == hi1) max1_pos.push_back(i); n   } n   for (i = 0; i < v2.size(); i++) { n     if (v2[i] == lw2) min2_pos.push_back(i); n     if (v2[i] == hi2) max2_pos.push_back(i); n   } n   bool v, h; n   long long a, b, c, d; n   a = min1_pos.back(); n   b = min1_pos.front(); n   c = max1_pos.back(); n   d = max1_pos.front(); n   if ((c < a && c < b) || (d > a && d > b)) n     v = true; n   else n     v = false; n   a = min2_pos.back(); n   b = min2_pos.front(); n   c = max2_pos.back(); n   d = max2_pos.front(); n   if ((c < a && c < b) || (d > a && d > b)) n     h = true; n   else n     h = false; n   if (V && H) { n     cout << 4 << endl; n   } else if (V) { n     if (h) n       cout << 2 * (hi2 - lw2) << endl; n     else n       cout << 2 * (hi2 - lw2 + 1) << endl; n   } else if (H) { n     if (v) n       cout << 2 * (hi1 - lw1) << endl; n     else n       cout << 2 * (hi1 - lw1 + 1) << endl; n   } else { n     if (v && h) n       cout << min((hi1 - lw1 + 1) * (hi2 - lw2), (hi1 - lw1) * (hi2 - lw2 + 1)) n            << endl; n     else if (v) n       cout << (hi1 - lw1) * (hi2 - lw2 + 1) << endl; n     else if (h) n       cout << (hi1 - lw1 + 1) * (hi2 - lw2) << endl; n     else n       cout << (hi1 - lw1 + 1) * (hi2 - lw2 + 1) << endl; n   } n } n int main() { n   long long t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e6; n long long n, K, d, a[200010]; n map<long long, long long> mp; n struct trnode { n   long long lc, rc, c, u; n } tr[400010]; n long long tot = 0; n void pushdown(long long x) { n   long long lc = tr[x].lc, rc = tr[x].rc, c = tr[x].u; n   tr[x].u = 0; n   tr[lc].c += c; n   tr[rc].c += c; n   tr[lc].u += c; n   tr[rc].u += c; n } n void change(long long x, long long l, long long r, long long fl, long long fr, n             long long c, long long op) { n   if (l == fl && r == fr) { n     if (op) n       tr[x].c = c; n     else n       tr[x].c += c, tr[x].u += c; n     return; n   } n   long long mid = (l + r) / 2; n   if (tr[x].u) pushdown(x); n   if (fr <= mid) n     change(tr[x].lc, l, mid, fl, fr, c, op); n   else if (fl > mid) n     change(tr[x].rc, mid + 1, r, fl, fr, c, op); n   else n     change(tr[x].lc, l, mid, fl, mid, c, op), n         change(tr[x].rc, mid + 1, r, mid + 1, fr, c, op); n   tr[x].c = min(tr[tr[x].lc].c, tr[tr[x].rc].c); n } n long long bt(long long l, long long r) { n   long long x = ++tot; n   tr[x].c = inf; n   if (l != r) { n     long long mid = (l + r) / 2; n     tr[x].lc = bt(l, mid); n     tr[x].rc = bt(mid + 1, r); n   } n   return x; n } n long long findans(long long x, long long l, long long r) { n   if (l == r) return tr[x].c <= K ? l : inf; n   if (tr[x].u) pushdown(x); n   long long mid = (l + r) / 2; n   if (tr[tr[x].lc].c <= K) return findans(tr[x].lc, l, mid); n   return findans(tr[x].rc, mid + 1, r); n } n long long L = 1, R = 1, s1[200010], s2[200010], t1 = 0, t2 = 0, la = 1; n int main() { n   scanf( %lld %lld %lld , &n, &K, &d); n   for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]); n   if (d == 0) { n     L = 1; n     R = 1; n     long long l = 1, r = 1; n     for (int i = 2; i <= n; i++) { n       r = i; n       if (a[i] != a[i - 1]) l = i; n       if (r - l + 1 > R - L + 1) L = l, R = r; n     } n     printf( %lld %lld , L, R); n     return 0; n   } n   bt(1, n); n   change(1, 1, n, 1, 1, 0, 1); n   s1[++t1] = 1; n   s2[++t2] = 1; n   mp[a[1]] = 1; n   for (long long i = 2; i <= n; i++) { n     long long tmp = la; n     tmp = max(tmp, mp[a[i]] + 1); n     if ((a[i] - a[i - 1]) % d != 0) tmp = i; n     mp[a[i]] = i; n     if (la < tmp) change(1, 1, n, la, tmp - 1, inf, 0), la = tmp; n     while (t1 && a[s1[t1]] <= a[i]) n       change(1, 1, n, s1[t1 - 1] + 1, s1[t1], (a[i] - a[s1[t1]]) / d, 0), t1--; n     while (t2 && a[s2[t2]] >= a[i]) n       change(1, 1, n, s2[t2 - 1] + 1, s2[t2], (a[s2[t2]] - a[i]) / d, 0), t2--; n     change(1, 1, n, i, i, 1, 1); n     change(1, 1, n, la, i, -1, 0); n     s1[++t1] = i; n     s2[++t2] = i; n     long long l = findans(1, 1, n), r = i; n     if (r - l + 1 > R - L + 1) L = l, R = r; n   } n   printf( %lld %lld , L, R); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(T& x) { n   x = 0; n   T f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) f = (ch ==  -  ? -1 : 1), ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar(); n   x *= f; n } n template <class T, class... Args> n void read(T& x, Args&... args) { n   read(x), read(args...); n } n template <class T> n void write(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n const int MAXN = 2E5 + 5; n const int MOD = 1E9 + 7; n long long n, num; n double p; n bool check(long long k) { n   return (-k * k * k + 3 * k * k + k * (4 + 3 * n * n - 9 * n)) * 10000 >= n          num * n * (n - 1) * (n - 2) * 2; n } n signed main() { n   cin >> n >> p; n   num = llround(p * 10000); n   int l = 0, r = n, ans = 0; n   while (l <= r) { n     int mid = l + r >> 1; n     if (check(mid)) { n       ans = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   cout << ans; n   return 0; n } n