#include <bits/stdc++.h> n using std::max; n using std::min; n const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; n const long long INF = 0x3f3f3f3f3f3f3f3f; n __inline__ __attribute__((always_inline)) unsigned int rnd() { n   static unsigned int seed = 416; n   return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13; n } n template <typename _Tp> n _Tp gcd(const _Tp &a, const _Tp &b) { n   return (!b) ? a : gcd(b, a % b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) { n   return a >= 0 ? a : -a; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) { n   (a < b) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) { n   (b < a) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void read(_Tp &x) { n   char ch(getchar()); n   bool f(false); n   while (!isdigit(ch)) f |= ch == 45, ch = getchar(); n   x = ch & 15, ch = getchar(); n   while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar(); n   f && (x = -x); n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) { n   read(t); n   read(args...); n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b, n                                                   const Args &...args) { n   return a < b ? min(a, args...) : min(b, args...); n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b, n                                                   const Args &...args) { n   return a < b ? max(b, args...) : max(a, args...); n } n __inline__ __attribute__((always_inline)) int read_str(char *s) { n   char ch(getchar()); n   while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar(); n   char *tar = s; n   *tar = ch, ch = getchar(); n   while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF) n     *(++tar) = ch, ch = getchar(); n   return tar - s + 1; n } n const int N = 100005; n const int MAXN = 10000005; n bool pr[MAXN]; n int _p[MAXN >> 3], _pos; n int md[MAXN]; n void sieve() { n   for (int i = 2; i < MAXN; ++i) { n     if (!pr[i]) { n       _p[++_pos] = i; n       md[i] = i; n     } n     for (int j = 1; j <= _pos && i * _p[j] < MAXN; ++j) { n       pr[i * _p[j]] = true; n       md[i * _p[j]] = _p[j]; n       if (!(i % _p[j])) break; n     } n   } n } n std::vector<int> p[N], d[N]; n int c[MAXN], cnt[1 << 8], mul[1 << 8]; n int calc(int id) { n   int siz = ((int)p[id].size()), ans = 0; n   for (int i = 0; i < siz; ++i) mul[1 << i] = p[id][i]; n   for (int i = 1; i < 1 << siz; ++i) { n     cnt[i] = cnt[i >> 1] + (i & 1); n     mul[i] = mul[i ^ ((i) & (-(i)))] * mul[((i) & (-(i)))]; n     if (cnt[i] & 1) n       ans += c[mul[i]]; n     else n       ans -= c[mul[i]]; n   } n   return ans; n } n int a[N]; n int _val[11], _cnt[11], pos, cur_id; n void dfs(int dep, int val) { n   if (dep == pos + 1) { n     d[cur_id].push_back(val); n     return; n   } n   for (int i = 0; i <= _cnt[dep]; ++i) { n     dfs(dep + 1, val); n     if (i < _cnt[dep]) val *= _val[dep]; n   } n } n bool ban[N], vis[N]; n int deg[N]; n int f(int mid) { n   while (ban[mid]) --mid; n   if (!mid) return false; n   int qwq = 0; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) { n       ++qwq; n       for (auto it : d[i]) ++c[it]; n     } n   int ans = 0; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i] && calc(i) != qwq) ++ans; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) n       for (auto it : d[i]) --c[it]; n   return ans; n } n std::vector<int> getnodes(int mid) { n   while (ban[mid]) --mid; n   std::vector<int> nd; n   int qwq = 0; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) { n       ++qwq; n       for (auto it : d[i]) ++c[it]; n     } n   for (int i = 1; i <= mid; ++i) n     if (!ban[i] && calc(i) != qwq) nd.push_back(i); n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) n       for (auto it : d[i]) --c[it]; n   return nd; n } n int main() { n   mul[0] = 1; n   sieve(); n   int n, k; n   read(n, k); n   for (int i = 1; i <= n; ++i) { n     read(a[i]); n     ++c[a[i]]; n     int cur = a[i], last = 0; n     pos = 0; n     while (cur > 1) { n       if (md[cur] != last) n         p[i].push_back(md[cur]), _val[++pos] = md[cur], _cnt[pos] = 1; n       else n         ++_cnt[pos]; n       last = md[cur]; n       cur /= last; n     } n     cur_id = i; n     dfs(1, 1); n   } n   for (int j = 1; j <= _pos; ++j) n     for (int i = (MAXN - 1) / _p[j]; i >= 1; --i) c[i] += c[i * _p[j]]; n   std::vector<int> nd; n   for (int i = 1; i <= n; ++i) { n     if ((deg[i] = calc(i)) <= n - 2) { n       nd.push_back(i); n       for (int j = 1; j <= n && ((int)nd.size()) < 3; ++j) n         if (i != j && gcd(a[i], a[j]) == 1) nd.push_back(j); n       break; n     } n   } n   if (nd.empty()) { n     std::vector<int> clique, rest; n     for (int i = 1; i <= n; ++i) n       if (deg[i] == n) n         clique.push_back(i); n       else n         rest.push_back(i); n     if (((int)clique.size()) > k) clique.resize(k); n     for (int i = 1; i <= n && ((int)clique.size()) < k; ++i) { n       if (!vis[i] && deg[i] == n - 1) { n         clique.push_back(i); n         for (auto it : rest) n           if (gcd(a[it], a[i]) == 1) vis[it] = true; n       } n     } n     for (auto it : clique) printf( %d  , it); n     printf(  n ); n     return 0; n   } n   assert(((int)nd.size()) == 3); n   if (k == 3) { n     for (auto it : nd) printf( %d  , it); n     printf(  n ); n     return 0; n   } n   for (auto it : nd) ban[it] = true; n   for (auto id : nd) n     for (auto it : d[id]) --c[it]; n   std::vector<int> clique; n   for (int i = 1; i <= n; ++i) n     if (!ban[i] && ((deg[i] = calc(i)) == n - 3)) clique.push_back(i); n   if (((int)clique.size()) >= k) { n     clique.resize(k); n     for (auto it : clique) printf( %d  , it); n     printf(  n ); n     return 0; n   } n   memset(c, 0, sizeof(c)); n   int l = 1, r = n; n   while (l < r) { n     int mid = (l + r) >> 1; n     if (f(mid) + 3 >= k) n       r = mid; n     else n       l = mid + 1; n   } n   std::vector<int> v1 = getnodes(l - 1); n   std::vector<int> v2 = getnodes(l); n   assert(f(l - 1) == ((int)v1.size())); n   assert(f(l) == ((int)v2.size())); n   assert(((int)v1.size()) + 3 < k); n   assert(((int)v2.size()) + 3 >= k); n   std::sort(v1.begin(), v1.end()); n   std::vector<int> qwq; n   for (auto it : v2) { n     auto _ = std::lower_bound(v1.begin(), v1.end(), it); n     if (_ == v1.end() || *_ != it) qwq.push_back(it); n   } n   std::sort(qwq.begin(), qwq.end()); n   assert(((int)v1.size()) + ((int)qwq.size()) == ((int)v2.size())); n   if (((int)v1.size()) + 3 + 1 == k && ((int)qwq.size()) != 1) n     v1.push_back(nd[0]), v1.push_back(nd[1]); n   else n     v1.push_back(nd[0]), v1.push_back(nd[1]), v1.push_back(nd[2]); n   while (((int)v1.size()) < k) { n     v1.push_back(qwq.back()); n     qwq.pop_back(); n   } n   assert(((int)v1.size()) == k); n   for (auto it : v1) printf( %d  , it); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const int N = 500005; n const int MOD = 1e9 + 7; n int i, n, m, k, rs, x, y; n long long val[N]; n map<int, int> p; n map<long long, vector<pair<int, int>>> M; n int Pow(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = ((long long)ans * a) % MOD, --b; n     a = ((long long)a * a) % MOD; n     b /= 2; n   } n   return ans; n } n int pfind(int x) { n   if (!p.count(x)) return p[x] = x; n   if (p[x] == x) return p[x] = x; n   return p[x] = pfind(p[x]); n } n void punite(int x, int y) { n   if (rand() & 1) n     p[pfind(x)] = pfind(y); n   else n     p[pfind(y)] = pfind(x); n } n int main() { n   scanf( %d %d %d , &n, &m, &k); n   rs = Pow(2, n + k); n   for (i = 1; i <= n; ++i) scanf( %lld , val + i); n   while (m--) { n     scanf( %d %d , &x, &y); n     M[val[x] ^ val[y]].push_back(make_pair(x, y)); n   } n   for (auto it : M) { n     vector<pair<int, int>> v = it.second; n     x = n; n     p.clear(); n     for (auto it : v) n       if (pfind(it.first) != pfind(it.second)) { n         punite(it.first, it.second); n         --x; n       } n     rs -= Pow(2, n); n     rs += Pow(2, x); n     if (rs < 0) n       rs += MOD; n     else n       rs %= MOD; n   } n   printf( %d n , rs); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int arr = 9e5 + 10; n signed main() { n   long long a, b; n   cin >> a >> b; n   a = min(a, b); n   long long ans = 1; n   for (long long i = 1; i <= a; i++) ans *= i; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int n, a[maxn], b[maxn], v[maxn]; n unordered_map<int, int> mp; n void dfs(int x, int l, int r) { n   if (v[x] <= r && v[x] >= l) mp[v[x]] = 1; n   if (a[x] != -1) { n     if (l < v[x]) dfs(a[x], l, min(v[x] - 1, r)); n   } n   if (b[x] != -1) { n     if (r > v[x]) dfs(b[x], max(l, v[x] + 1), r); n   } n } n bool f[maxn]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> v[i] >> a[i] >> b[i]; n     if (a[i] != -1) f[a[i]] = 1; n     if (b[i] != -1) f[b[i]] = 1; n   } n   int root = 1; n   for (int i = 1; i <= n; i++) n     if (!f[i]) root = i; n   dfs(root, 0, 1000000000); n   int ret = 0; n   for (int i = 1; i <= n; i++) n     if (mp.find(v[i]) != mp.end()) ret++; n   cout << n - ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 205; n const int mod = 1e9 + 7; n int n, m, t, q; n vector<int> G[N]; n map<int, int> M; n set<int> S; n int a[N], in[N], iinn[N], vis[N]; n long long sum; n void topsort(int id) { n   int cnt = 0; n   while (1) { n     for (int i = (1); i <= (n); i++) { n       if (iinn[i] == 0 && vis[i] == 0 && a[i] == id) { n         cnt++; n         vis[i] = 1; n         sum++; n         int len = G[i].size(); n         for (int j = (0); j <= (len - 1); j++) { n           iinn[G[i][j]]--; n         } n         i = 0; n       } n     } n     if (cnt == n) break; n     id = (id % 3) + 1; n     sum++; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = (1); i <= (n); i++) scanf( %d , &a[i]); n   for (int i = (1); i <= (n); i++) { n     int len, num; n     scanf( %d , &len); n     for (int j = (1); j <= (len); j++) { n       scanf( %d , &num); n       G[num].push_back(i); n       in[i]++; n       iinn[i]++; n     } n   } n   long long ans = 1ll << 62; n   sum = 0; n   topsort(1); n   ans = min(ans, sum); n   sum = 0; n   memset(vis, 0, sizeof(vis)); n   for (int i = (1); i <= (n); i++) iinn[i] = in[i]; n   topsort(2); n   ans = min(ans, sum); n   sum = 0; n   memset(vis, 0, sizeof(vis)); n   for (int i = (1); i <= (n); i++) iinn[i] = in[i]; n   topsort(3); n   ans = min(ans, sum); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int len; n   string s; n   cin >> len; n   cin >> s; n   vector<char> vect; n   while (len != 0) { n     if (len % 2 == 1) { n       vect.push_back(s[0]); n     } else { n       vect.insert(vect.begin(), s[0]); n     } n     s.erase(0, 1); n     len = s.length(); n   } n   for (int i = 0; i < vect.size(); i++) { n     cout << vect[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, d; n   vector<pair<int, int>> v; n   vector<int> ans; n   set<pair<int, int>> st; n   scanf( %d %d %d , &n, &m, &d); n   ans.resize(n); n   for (int i = 0; i < n; ++i) { n     int t; n     scanf( %d , &t); n     v.push_back(make_pair(t, i)); n   } n   sort(v.begin(), v.end()); n   st.insert(make_pair(v[0].first + d + 1, 1)); n   ans[v[0].second] = 1; n   for (int i = 1; i < v.size(); ++i) { n     int minute = v[i].first; n     int id = v[i].second; n     auto it = st.begin(); n     int cur_min_available_minute = it->first; n     int day = it->second; n     if (cur_min_available_minute <= m && minute >= cur_min_available_minute) { n       st.erase(it); n       st.insert(make_pair(minute + d + 1, day)); n       ans[id] = day; n     } else { n       st.insert(make_pair(minute + d + 1, st.size() + 1)); n       ans[id] = st.size(); n     } n   } n   printf( %d n , (int)st.size()); n   for (int i = 0; i < n; ++i) { n     printf( %d  , ans[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double d, h, v, e; n   cin >> d >> h >> v >> e; n   double V = e * 3.14159265358979 * (d / 2) * (d / 2); n   if (v <= V) { n     cout <<  NO ; n   } else { n     double S = 3.14159265358979 * (d / 2) * (d / 2) * h; n     cout <<  YES  << endl << fixed << setprecision(12) << S / (v - V); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   iostream::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> nums(n); n   map<int, int> counts; n   for (int i = 0; i < n; i++) { n     cin >> nums[i]; n     counts[nums[i]]++; n   } n   map<int, int> last; n   int k = 0, previous; n   for (auto it = counts.begin(); it != counts.end(); it++) { n     if (k++ > 0) { n       if (previous < it->second) { n         cout << -1 << endl; n         return 0; n       } n     } n     if (k != it->first) { n       cout << -1 << endl; n       return 0; n     } n     previous = it->second; n     last[it->first] = 1; n   } n   int total = 0; n   vector<int> ans(n); n   for (int i = 0; i < n; i++) { n     ans[i] = last[nums[i]]++; n     total = max(ans[i], total); n   } n   cout << total << endl; n   for (int i = 0; i < n; i++) { n     if (i) cout <<    ; n     cout << ans[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, ans = 0, cnt = 0; n   cin >> n; n   vector<long long> a(n), pref(n + 1); n   for (auto& i : a) cin >> i; n   pref[0] = a[0]; n   for (int i = 1; i < n; ++i) pref[i] += pref[i - 1] + a[i]; n   if (pref[n - 1] % 3 || n < 3) return cout << 0, 0; n   long long s = pref[n - 1] / 3; n   for (int i = 0; i < n - 1; ++i) { n     if (pref[i] == 2 * s) ans += cnt; n     if (pref[i] == s) ++cnt; n   } n   cout << ans <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long n, i, j, m, x, c, count, nr, OK, suma, k, level, val, y[100], z; n void inmultire_y(long long nr) { n   int i = 0; n   int j = 0; n   int Max = 0; n   for (; i < 100; i++) y[i] = 0; n   long long x2 = nr; n   int n = 0; n   while (x2) { n     n++; n     x2 /= 10; n   } n   x2 = nr; n   for (i = 1; i <= n; i++) { n     long long x1 = nr; n     for (j = 1; j <= n; j++) { n       y[i + j - 1] += (x2 % 10) * (x1 % 10); n       Max = max(Max, i + j - 1); n       if (y[i + j - 1] >= 10) { n         Max = max(Max, i + j); n         y[i + j] += y[i + j - 1] / 10; n         y[i + j - 1] = y[i + j - 1] % 10; n       } n       x1 /= 10; n     } n     x2 /= 10; n   } n   y[0] = Max; n } n long long impartire_y(long long X) { n   long long i; n   unsigned long R = 0; n   for (i = y[0]; i; i--) { n     y[i] = (R = 10 * R + y[i]) / X; n     R %= X; n   } n   while (!y[y[0]] && y[0] > 1) y[0]--; n   long long r = 0; n   for (i = 100; i > 0; i--) { n     if (y[i]) { n       for (long long j = i; j > 0; j--) { n         r = r * 10 + y[j]; n       } n       break; n     } n   } n   return r; n } n int main() { n   cin >> n; n   val = 2; n   for (level = 2; level <= n + 1; level++) { n     x = level * (level - 1); n     while (1) { n       inmultire_y(x); n       z = impartire_y(level - 1); n       z = z - val / (level - 1); n       break; n     } n     val = x; n     cout << z <<   n ; n   } n   return 0; n } n


#include <algorithm> n #include <array> n #include <cassert> n #include <chrono> n #include <cmath> n #include <cstring> n #include <functional> n #include <iomanip> n #include <iostream> n #include <map> n #include <numeric> n #include <queue> n #include <random> n #include <set> n #include <vector> n using namespace std; n  n template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os <<  (  << p.first <<  ,   << p.second <<  ) ; } n template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os <<  { ; string sep; for (const T &x : v) os << sep << x, sep =  ,  ; return os <<  } ; } n  n void dbg_out() { cerr << endl; } n template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr <<     << H; dbg_out(T...); } n  n #ifdef NEAL_DEBUG n #define dbg(...) cerr <<  (  << #__VA_ARGS__ <<  ): , dbg_out(__VA_ARGS__) n #else n #define dbg(...) n #endif n  n  n const int INF = int(1e9) + 5; n  n int main() { n     ios::sync_with_stdio(false); n #ifndef NEAL_DEBUG n     cin.tie(nullptr); n #endif n  n     int N, A, B; n     string str; n     cin >> N >> A >> B >> str; n     vector<int> S(N); n     vector<int> char_to_index(128, -1); n     string chars; n     int C = 0; n  n     for (int i = 0; i < N; i++) { n         char ch = str[i]; n  n         if (char_to_index[ch] < 0) { n             char_to_index[ch] = C++; n             chars += ch; n         } n  n         S[i] = char_to_index[ch]; n     } n  n     dbg(chars); n  n     vector<int> char_start(C, INF); n     vector<int> char_end(C, -INF); n     vector<int> occur(C, 0); n  n     for (int i = 0; i < N; i++) { n         char_start[S[i]] = min(char_start[S[i]], i); n         char_end[S[i]] = max(char_end[S[i]], i + 1); n         occur[S[i]]++; n     } n  n     vector<bool> succeeds(1 << C, false); n  n     for (int mask = 1; mask < 1 << C; mask++) { n         int start = INF, end = -INF, count = 0; n  n         for (int c = 0; c < C; c++) n             if (mask >> c & 1) { n                 start = min(start, char_start[c]); n                 end = max(end, char_end[c]); n                 count += occur[c]; n             } n  n         succeeds[mask] = count * B >= (end - start) * A; n  n         if (succeeds[mask]) n             dbg(mask,  succeeds ); n     } n  n     vector<int> dp(1 << C, 0); n  n     for (int c = 0; c < C; c++) n         dp[1 << c] = 1 << c; n  n     for (int mask = 0; mask < 1 << C; mask++) { n         for (int split = 0; split < C; split++) { n             int lower = mask & ((1 << split) - 1); n             int upper = mask & -(1 << split); n             assert((lower | upper) == mask && (lower & upper) == 0); n  n             if (succeeds[lower] && dp[lower] != 0) dp[mask] |= dp[upper]; n             if (succeeds[upper] && dp[upper] != 0) dp[mask] |= dp[lower]; n         } n  n         for (int single = 0; single < C; single++) n             if (mask >> single & 1) { n                 int without = mask & ~(1 << single); n  n                 if (succeeds[without] && dp[without] != 0) n                     dp[mask] |= 1 << single; n             } n  n         dbg(mask, dp[mask]); n     } n  n     int answer = dp[(1 << C) - 1]; n     cout << __builtin_popcount(answer); n     string sorted; n  n     for (int c = 0; c < C; c++) n         if (answer >> c & 1) n             sorted += chars[c]; n  n     sort(sorted.begin(), sorted.end()); n  n     for (auto &ch : sorted) n         cout <<     << ch; n  n     cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, d, x, y, r; n   int i, n; n   scanf( %lf%lf%d , &a, &d, &n); n   for (i = 1; i <= n; i++) { n     r = fmod(i * d, 4 * a); n     if (r <= a) n       x = r, y = 0; n     else if (r <= 2 * a) n       x = a, y = r - a; n     else if (r <= 3 * a) n       x = a - (r - 2 * a), y = a; n     else n       x = 0, y = a - (r - 3 * a); n     printf( %.10f %.10f n , x, y); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   bool cap = false, low = false, num = false; n   for (int i = 0; i < s.size(); ++i) { n     if (s[i] >=  a  && s[i] <=  z ) n       low = true; n     else if (s[i] >=  A  && s[i] <=  Z ) n       cap = true; n     else if (s[i] >=  0  && s[i] <=  9 ) n       num = true; n   } n   if (s.size() >= 5 && cap && low && num) n     cout <<  Correct  << endl; n   else n     cout <<  Too weak  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e5 + 10; n long long int vis[N]; n vector<vector<int> > v; n int dfs(int t) { n   vis[t] = 1; n   for (int i = 0; i < v[t].size(); i++) { n     if (vis[v[t][t]] == 0) { n       dfs(v[t][i]); n     } n   } n   return 0; n } n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int lcm(int a, int b) { return a * (b / gcd(a, b)); } n int main() { n   long long int n, m; n   cin >> n >> m; n   while (1) { n     if (n == 0 or m == 0) break; n     if (n >= 2 * m) n       n = n % (2 * m); n     else if (m >= 2 * n) n       m = m % (2 * n); n     else n       break; n   } n   cout << n <<     << m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ((void)0); n   ((void)0); n   ((void)0); n   int T, N, M1, M2, s, e; n   long long X; n   for (cin >> T; T--;) { n     M1 = M2 = 0x7fffffff; n     s = 0; n     e = 1e9; n     for (cin >> N >> X; N--;) { n       int d, h; n       cin >> d >> h; n       M1 = min(M1, -d); n       M2 = min(M2, h - d); n     } n     if (X + M1 <= 0) { n       cout <<  1 n ; n       continue; n     } n     while (s <= e) { n       int m = (s + e) >> 1; n       if (X + 1LL * m * M2 + M1 <= 0) n         e = m - 1; n       else n         s = m + 1; n     } n     if (s > 1e9) n       cout <<  -1 n ; n     else n       cout << s + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sum(int n) { n   int c = 0; n   while (n > 0) { n     c += n % 10; n     n /= 10; n   } n   return c; n } n void showarr(int arr[], int n) { n   for (int i = 0; i < n; i++) { n     cout << arr[i] <<    ; n   } n   cout <<   n ; n } n int arr[8001], f[8001]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int i, j, t; n   cin >> t; n   while (t--) { n     int s, k, n, q, m = 0; n     cin >> n; n     for (int i = 0; i < n; ++i) { n       cin >> arr[i]; n       f[i + 1] = 0; n     } n     int ans = 0, cnt = 0; n     for (i = 0; i < n; i++) { n       cnt = arr[i]; n       for (j = i + 1; j < n; j++) { n         cnt += arr[j]; n         if (cnt > n) break; n         f[cnt] = 1; n       } n     } n     for (i = 0; i < n; i++) { n       if (f[arr[i]]) ans++; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline int QuickPow(int x, int y) { n   int Res = 1, Temp = x; n   while (y) { n     if (y & 1) Res = Res * Temp % 1000000007; n     Temp = Temp * Temp % 1000000007; n     y /= 2; n   } n   return Res; n } n inline void Swap(int &x, int &y) { n   int Temp = x; n   x = y; n   y = Temp; n } n inline int Max(int x, int y) { return x > y ? x : y; } n inline int Min(int x, int y) { return x < y ? x : y; } n inline void read(int &x) { n   x = 0; n   int f = 1; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = (x << 3) + (x << 1) + (s ^ 48); n     s = getchar(); n   } n   x *= f; n } n struct node { n   int v, Index; n   node() {} n   node(int V, int INDEX) { n     v = V; n     Index = INDEX; n   } n }; n stack<int> S; n vector<node> G[400005]; n int Dfn[400005], Low[400005], Bel[400005], Cnt, Col, Size[400005], Maxx, Root; n bool InStack[400005]; n void Tarjan(int x, int Pre) { n   Dfn[x] = Low[x] = ++Cnt; n   S.push(x); n   InStack[x] = 1; n   int l = G[x].size(); n   for (register int i = 0; i < l; ++i) { n     int to = G[x][i].v; n     if (to == Pre) continue; n     if (!Dfn[to]) { n       Tarjan(to, x); n       Low[x] = Min(Low[x], Low[to]); n     } else if (InStack[to]) n       Low[x] = Min(Low[x], Dfn[to]); n   } n   if (Dfn[x] == Low[x]) { n     Col++; n     int u; n     do { n       Size[Col]++; n       u = S.top(); n       S.pop(); n       InStack[u] = 0; n       Bel[u] = Col; n     } while (u != x); n     if (Size[Col] > Maxx) Maxx = Size[Col], Root = x; n   } n } n bool Pan[400005]; n int From[400005 * 2], To[400005 * 2]; n void Dfs(int x) { n   Pan[x] = 1; n   int l = G[x].size(); n   for (register int i = 0; i < l; ++i) { n     int to = G[x][i].v, Id = G[x][i].Index; n     if (Pan[to]) { n       From[Id] = x, To[Id] = to; n       continue; n     } n     if (Low[to] != Low[x]) n       From[Id] = to, To[Id] = x; n     else n       From[Id] = x, To[Id] = to; n     Dfs(to); n   } n } n int main() { n   int n, m; n   read(n); n   read(m); n   for (register int i = 1; i <= m; ++i) { n     int u, v; n     read(u); n     read(v); n     G[u].push_back(node(v, i)); n     G[v].push_back(node(u, i)); n   } n   for (register int i = 1; i <= n; ++i) n     if (!Dfn[i]) Tarjan(i, i); n   printf( %d n , Maxx); n   Dfs(Root); n   for (register int i = 1; i <= m; ++i) printf( %d %d n , From[i], To[i]); n   return 0; n } n


#include <bits/stdc++.h> n struct compare { n   bool operator()(const int& l, const int& r) { return l > r; } n }; n using namespace std; n priority_queue<int, vector<int>, compare> pq; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     if (k % 3 && n % 3 == 0) { n       cout <<  Bob n ; n     } else if (k % 3 == 0) { n       n %= (k + 1); n       if (n % 3 == 0 && n != k) { n         cout <<  Bob n ; n       } else { n         cout <<  Alice n ; n       } n     } else { n       cout <<  Alice n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long double pi = 2.0 * acos(0.0); n mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); n long long int N; n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int a, b, c, i, j, k, first, r, x, y, z; n   long long int n, m, p, q, t; n   long long int A[1000005]; n   long long int B[1000005]; n   first = 0; n   r = 0; n   cin >> n; n   k = (n) / 2; n   cout << k <<   n ; n   for (i = 0; i < k - 1; i++) cout <<  2  ; n   cout << (2 + (n % 2)); n   return 0; n } n


#include<bits/stdc++.h> n  n #define ll long long n #define rep(A,B,C) for(A=B;A<C;++A) n #define pii pair<int,int> n #define pll pair<ll,ll> n  n #define fi first n #define se second n #define all(A) A.begin(),A.end() n  n using namespace std; n  n ///////////////////////////////////////////////////// n #define vv vector n #define Nmx 303030 n #define lNmx 20 n  n ll N,M; n vv<pll> uvv[Nmx + 3]; n pll xyv[Nmx + 3]; n ll dblp[Nmx + 3][lNmx + 3]; n ll dps[Nmx + 3]; n ll mked[Nmx + 3], mkcm[Nmx + 3]; n vv<pll> cmv[Nmx + 3]; n ll an[Nmx + 3]; n ll i, j, k; n  n  n ll dfs1(ll a,ll p,ll d){ n      n     dblp[a][0] = p; n     dps[a] = d; n     ll i = 0, pi = 0; n     ll c = 0; n     c += mked[a] - mkcm[a]; n     rep(i,0,uvv[a].size()){ n         ll b = uvv[a][i].fi; n         if(b==p){ n             pi = i; n             continue; n         } n         ll rb= dfs1(b, a, d + 1); n         //printf( %lld,%lld,%lld n , a, b, rb); n         uvv[a][i].se = rb; n         c += rb; n         //assert(false); n     } n     an[a] = c; n     uvv[a][pi].se = c - mkcm[a]; n     //printf( %lld,%lld,%lld,%lld n , a, p, d,uvv[1][0].se); n     return uvv[a][pi].se; n } n  n void dblinit(){ n     ll i, j; n     rep(j,0,lNmx) n         rep(i,0,N+1) n             dblp[i][j + 1] = dblp[dblp[i][j]][j]; n } n  n pll lcap(ll a,ll b){ n     if(a==b) n         return {-1, -1}; n     if(dps[a]<dps[b]) n         swap(a, b); n     ll i = lNmx; n     while(dps[a]-dps[b]>1){ n         if((1<<i)<=dps[a]-dps[b]-1) n             a = dblp[a][i]; n         --i; n     } n     if(dps[a]>dps[b]){ n         if(dblp[a][0]==b) n             return {a, -1}; n         a = dblp[a][0]; n     } n     i = lNmx; n     while(i>=0){ n         if(dblp[a][i]!=dblp[b][i]){ n             a = dblp[a][i]; n             b = dblp[b][i]; n         } n         --i; n     } n     if(a>b) n         swap(a, b); n     return {a, b}; n } n  n ll calc(ll a){ n     ll i; n     map<ll, ll> mp; n     rep(i,0,uvv[a].size()){ n         mp[uvv[a][i].fi] = i; n     } n     ll ans = 0; n     map<pll, ll> mp2; n     rep(i,0,cmv[a].size()){ n          n         ll aa = --an[a]; n         ll p1 = cmv[a][i].fi, p2 = cmv[a][i].se; n         //printf( %lld:%lld,%lld,%lld,%lld  ,a, i,p1,p2, an[a]); n         if(p1!=-1){ n             ll I = mp[p1]; n             aa -= --uvv[a][I].se; n             //printf( a%lld, , uvv[a][I].se); n         } n         if(p2!=-1){ n             ll I = mp[p2]; n             aa -= --uvv[a][I].se; n             //printf( b%lld, , uvv[a][I].se); n         } n         if(p1!=-1&&p2!=-1){ n             //printf( c%lld, , mp2[cmv[a][i]]); n             aa += mp2[cmv[a][i]]++; n         } n         //printf(  n ); n         ans += aa; n     } n     return ans; n } n  n  n void solve(){ n     dfs1(1, 0, 1); n     dblinit(); n      n     //assert(false); n     rep(i,0,M){ n         pll xy = xyv[i]; n         if(xy.fi>xy.se) n             swap(xy.fi, xy.se); n         ++mked[xy.fi]; n         ++mked[xy.se]; n         //printf( ccc%lld,%lld, n , xy.fi, xy.se); n         if(xy.fi==xy.se){ n             cmv[xy.fi].push_back({-1, -1}); n             ++mkcm[xy.fi]; n             continue; n         } n         pll cmp = lcap(xy.fi, xy.se); n         //printf( ddd%lld,%lld,%lld n , cmp.fi, cmp.se,dblp[cmp.fi][0]); n          n         ll cm = dblp[cmp.fi][0]; n         cmv[cm].push_back(cmp); n         ++mkcm[cm]; n     } n      n     dfs1(1, 0, 1); n     /*rep(i,0,N+1){ n         printf(  n%lld-%lld: n , i, an[i]); n         rep(j,0,uvv[i].size()){ n             printf( %lld,%lld n , uvv[i][j].fi, uvv[i][j].se); n         } n     }*/ n     ll ans=0; n     rep(i,0,N+1){ n         ll a = calc(i); n         //printf( %lld,%lld n , i, a); n         ans += a; n     } n  n     printf( %lld n , ans); n } n  n  n  n int main(){ n     scanf( %lld , &N); n      n     rep(i,1,N){ n         ll u, v; n         scanf( %lld%lld , &u, &v); n         uvv[u].push_back({v, 0}); n         uvv[v].push_back({u, 0}); n     } n     uvv[1].push_back({0, 0}); n     scanf( %lld , &M); n     rep(i,0,M){ n         ll u, v; n         scanf( %lld%lld , &u, &v); n         xyv[i] = {u, v}; n     } n     solve(); n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n vector<int> g[100005]; n int sz[100005], answer[100005]; n long long ans = 0; n vector<int> spis; n void clears(int v, int pr) { n   sz[v] = 1; n   int pos = -1; n   for (int i = 0; i < (int)g[v].size(); i++) { n     int u = g[v][i]; n     if (u == pr) n       pos = i; n     else { n       clears(u, v); n       sz[v] += sz[u]; n     } n   } n   if (pos != -1) { n     swap(g[v][pos], g[v].back()); n     g[v].pop_back(); n   } n   return; n } n void dfs(int v, int len) { n   ans += (long long)2 * len; n   spis.push_back(v); n   for (int i = 0; i < (int)g[v].size(); i++) { n     int u = g[v][i]; n     dfs(u, len + 1); n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(v), g[v].push_back(u); n   } n   clears(1, -1); n   int cen = 1; n   while (true) { n     int mx = -1; n     for (int i = 0; i < (int)g[cen].size(); i++) { n       int u = g[cen][i]; n       if (2 * sz[u] > sz[cen]) mx = i; n     } n     if (mx == -1) break; n     int newcen = g[cen][mx]; n     swap(g[cen][mx], g[cen].back()); n     g[cen].pop_back(); n     g[newcen].push_back(cen); n     sz[cen] -= sz[newcen]; n     sz[newcen] += sz[cen]; n     cen = newcen; n   } n   dfs(cen, 0); n   cout << ans <<   n ; n   if (n % 2 == 0) { n     for (int i = 0; i < n / 2; i++) n       answer[spis[i]] = spis[i + n / 2], answer[spis[i + n / 2]] = spis[i]; n   } else { n     for (int i = 1; i < n / 2; i++) n       answer[spis[i]] = spis[i + n / 2], answer[spis[i + n / 2]] = spis[i]; n     answer[spis[0]] = spis[n / 2], answer[spis[n / 2]] = spis[n - 1], n     answer[spis[n - 1]] = spis[0]; n   } n   for (int i = 1; i <= n; i++) cout << answer[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : -x; n } n int n; n int m; n int main() { n   int mas[100000]; n   cin >> n; n   for (int i = 0; i < (n); i++) { n     scanf( %d , &mas[i]); n     if (i < n / 2) n       mas[i] -= i; n     else n       mas[i] -= n - i - 1; n   } n   sort(mas, mas + n); n   int l = 0; n   int ans = 0; n   for (int i = 1; i <= n; i++) n     if (mas[i] != mas[l] || i == n) { n       if (mas[l] >= 1) ans = max(ans, i - l); n       l = i; n     } n   cout << n - ans << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, s; n   cin >> n >> s; n   long long a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   long long l = 0, r = n, total = 0; n   while (l < r) { n     long long mid = (l + r) / 2; n     long long cost[n]; n     for (int i = 0; i < n; i++) { n       cost[i] = a[i] + mid * (i + 1); n     } n     sort(cost, cost + n); n     total = 0; n     for (int i = 0; i < mid; i++) { n       total += cost[i]; n     } n     if (s < total) { n       r = mid; n     } else { n       l = mid; n     } n     if (r - l == 1) { n       int cost[n]; n       mid = r; n       for (int i = 0; i < n; i++) { n         cost[i] = a[i] + mid * (i + 1); n       } n       sort(cost, cost + n); n       total = 0; n       for (int i = 0; i < mid; i++) { n         total += cost[i]; n       } n       if (s >= total) { n         l = r; n       } else { n         mid = l; n         for (int i = 0; i < n; i++) { n           cost[i] = a[i] + mid * (i + 1); n         } n         sort(cost, cost + n); n         total = 0; n         for (int i = 0; i < mid; i++) { n           total += cost[i]; n         } n       } n       break; n     } n   } n   cout << l <<     << total <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #define endl   n  n  n using namespace std; n  n typedef long long lld; n  n void solve(){ n     int n; n     cin>>n; n     vector<lld> a(n+1), b(n+1), p(n+2,0); n     for(int i=1;i<=n;i++){ n         cin>>a[i]; n     } n     for(int i=1;i<=n;i++){ n         cin>>b[i]; n         p[i]=a[i]*b[i]+p[i-1]; n     } n     lld ans=p[n]; n     for(int i=1;i<=n;i++){ n         lld curr=a[i]*b[i]; n         for(int l=i-1, r=i+1; l>=1 && r<=n; l--, r++){ n             curr+=a[r]*b[l]+a[l]*b[r]; n             ans=max(ans,curr+p[l-1]+p[n]-p[r]); n         } n         curr=0; n         for(int l=i, r=i+1; l>=1 && r<=n; l--, r++){ n             curr+=a[r]*b[l]+a[l]*b[r]; n             ans=max(ans,curr+p[l-1]+p[n]-p[r]); n         } n     } n     cout<<ans<<endl; n } n  n int32_t main(){ n     ios_base::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n     solve(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long a, b, c, d; n     cin >> a >> b >> c >> d; n     if (a > (b * c)) { n       cout << (-1) << endl; n       continue; n     } n     long long k = (a / (d * b)); n     cout << (a * (k + 1)) - (d * b * k * (k + 1) / 2) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> V[500500]; n vector<int> SV[500500]; n vector<int> MAX1[500500], MAX2[500500], MIN1[500500], MIN2[500500]; n vector<pair<int, int>> T; n int R[505000]; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tc; n   cin >> tc; n   for (int t = 1; t <= tc; t++) { n     int n, m; n     cin >> n >> m; n     for (int i = 0; i < n; i++) { n       V[i].clear(); n       SV[i].clear(); n     } n     T.clear(); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         int x; n         cin >> x; n         V[i].push_back(x); n       } n       T.push_back(make_pair(V[i][0], i)); n     } n     sort(T.begin(), T.end()); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         SV[i].push_back(V[T[i].second][j]); n       } n       R[T[i].second] = i; n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         MAX1[i].push_back(0); n         MAX2[i].push_back(0); n         MIN1[i].push_back(0); n         MIN2[i].push_back(0); n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         int m1 = i == 0 ? -1 : MAX1[i - 1][j]; n         int m2 = j == 0 ? -1 : MAX1[i][j - 1]; n         MAX1[i][j] = max(max(m1, m2), SV[i][j]); n       } n     } n     for (int i = n - 1; i >= 0; i--) { n       for (int j = m - 1; j >= 0; j--) { n         int m1 = (i == n - 1) ? -1 : MAX2[i + 1][j]; n         int m2 = (j == m - 1) ? -1 : MAX2[i][j + 1]; n         MAX2[i][j] = max(max(m1, m2), SV[i][j]); n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = m - 1; j >= 0; j--) { n         int m1 = i == 0 ? 9999999 : MIN1[i - 1][j]; n         int m2 = (j == m - 1) ? 9999999 : MIN1[i][j + 1]; n         MIN1[i][j] = min(min(m1, m2), SV[i][j]); n       } n     } n     for (int i = n - 1; i >= 0; i--) { n       for (int j = 0; j < m; j++) { n         int m1 = (i == n - 1) ? 9999999 : MIN2[i + 1][j]; n         int m2 = (j == 0) ? 9999999 : MIN2[i][j - 1]; n         MIN2[i][j] = min(min(m1, m2), SV[i][j]); n       } n     } n     int ansx = -1, ansy = -1; n     for (int i = 0; i < n - 1; i++) { n       for (int j = 0; j < m - 1; j++) { n         if (MAX1[i][j] < MIN2[i + 1][j] && n             MAX2[i + 1][j + 1] < MIN1[i][j + 1]) { n           ansx = i; n           ansy = j; n           break; n         } n       } n     } n     if (ansx == -1 && ansy == -1) n       cout <<  NO n ; n     else { n       cout <<  YES n ; n       for (int i = 0; i < n; i++) { n         if (R[i] <= ansx) n           cout <<  B ; n         else n           cout <<  R ; n       } n       cout <<    ; n       cout << ansy + 1; n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000000000 ) n using namespace std; n const double INF = 2e50; n double sqr(double a) { return a * a; } n int get_ch(double x, double y) { n   if (x <= 0 && y <= 0) return 1; n   if (x <= 0 && y >= 0) return 4; n   if (x >= 0 && y <= 0) return 2; n   return 3; n } n struct pt { n   double x, y; n   pt(double x, double y) : x(x), y(y) {} n   pt() {} n   void read() { cin >> x >> y; } n   double d() { return sqrt(sqr(x) + sqr(y)); } n   pt operator-(pt ot) { return pt(x - ot.x, y - ot.y); } n   bool operator==(pt ot) { return x == ot.x && y == ot.y; } n   double operator*(const pt ot) const { return (x * ot.y - y * ot.x); } n   bool operator<(const pt f) const { n     int a = get_ch(x, y); n     int b = get_ch(f.x, f.y); n     return (a < b || (a == b && (*this) * f >= 0)); n   } n }; n inline double get_an(pt f, pt s) { n   return acos((f.x * s.x + f.y * s.y) / f.d() / s.d()); n } n inline double vec_m(pt f, pt s) { return (f.x * s.y - f.y * s.x); } n double with_a[501][501], with_b[501][501]; n int main() { n   int n, m; n   cin >> n >> m; n   if (!m) { n     cout << n * (n - 1) * (n - 2) / 6; n     return 0; n   } n   vector<pt> f(n), s(m); n   for (int i = 0; i < n; i++) { n     f[i].read(); n   } n   for (int i = 0; i < m; i++) { n     s[i].read(); n   } n   double ans = 0; n   for (int i = 0; i < n; i++) { n     vector<pair<pt, pair<int, int> > > ev(n + m - 1 - i); n     int sz = 0; n     for (int j = i + 1; j < n; j++) { n       if (j == i) continue; n       ev[sz++] = make_pair(f[j] - f[i], make_pair(0, j)); n     } n     for (int j = 0; j < m; j++) { n       ev[sz++] = make_pair(s[j] - f[i], make_pair(1, j)); n     } n     sort(ev.begin(), ev.end()); n     for (int j = 0; j < (int)ev.size(); j++) { n       pt maxi = pt(INF, INF); n       int id = ev[j].second.second; n       if (ev[j].second.first) continue; n       for (int k = (j + 1) % (int)ev.size();; k = (k + 1) % (int)ev.size()) { n         if (k == j) break; n         int type = ev[k].second.first; n         int to_id = ev[k].second.second; n         pt temp = (type ? s[to_id] : f[to_id]); n         double to_an = vec_m(f[id] - f[i], temp - f[i]); n         if (to_an < 0) break; n         if (type) { n           if (maxi == pt(INF, INF) || vec_m(maxi - f[id], temp - f[id]) > 0) { n             maxi = temp; n           } n         } else { n           if (maxi == pt(INF, INF) || vec_m(maxi - f[id], temp - maxi) > 0) { n             ans++; n           } n         } n       } n     } n   } n   cout << fixed << setprecision(0) << ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n string tos(T a) { n   stringstream ss; n   string ret; n   ss << a; n   ss >> ret; n   return ret; n } n string st; n int l, memo[1000009][2]; n int get(int pos, int carry) { n   if (pos < 0) return carry; n   int &ret = memo[pos][carry]; n   if (ret != -1) return ret; n   ret = 9999999; n   if (carry == 0) { n     if (st[pos] ==  0 ) n       return ret = get(pos - 1, 0); n     else { n       int ra = get(pos - 1, carry) + 1; n       int rb = get(pos - 1, 1 - carry) + 1; n       ret = min(ra, rb); n       return ret; n     } n   } else { n     if (st[pos] ==  1 ) n       return ret = get(pos - 1, carry); n     else { n       int ra = get(pos - 1, 0) + 1; n       int rb = get(pos - 1, 1) + 1; n       ret = min(ra, rb); n       return ret; n     } n   } n } n int print_path(int pos, int carry) { n   if (pos < 0) { n     if (carry) printf( +2^%d n , l - pos - 1); n     return 0; n   } n   if (carry == 0) { n     if (st[pos] ==  0 ) n       return print_path(pos - 1, 0); n     else { n       int ra = get(pos - 1, carry) + 1; n       if (ra == memo[pos][carry]) { n         printf( +2^%d n , l - pos - 1); n         return print_path(pos - 1, carry); n       } else { n         printf( -2^%d n , l - pos - 1); n         return print_path(pos - 1, 1 - carry); n       } n     } n   } else { n     if (st[pos] ==  1 ) n       return print_path(pos - 1, carry); n     else { n       int ra = get(pos - 1, 0) + 1; n       if (ra == memo[pos][carry]) { n         printf( +2^%d n , l - pos - 1); n         return print_path(pos - 1, 0); n       } else { n         printf( -2^%d n , l - pos - 1); n         return print_path(pos - 1, 1); n       } n     } n   } n } n int main() { n   while (cin >> st) { n     memset(memo, -1, sizeof memo); n     ; n     l = st.size(); n     cout << get(l - 1, 0) << endl; n     print_path(l - 1, 0); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n signed main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     long long a, b, c, d; n     cin >> a >> b >> c >> d; n     long long x = gcd(c, d); n     c /= x; n     d /= x; n     if (c == 0 && a != 0) { n       cout << -1 <<   n ; n       continue; n     } n     if (c == 0 && a == 0) { n       cout <<  0 n ; n       continue; n     } n     if (c == d && a != b) { n       cout << -1 <<   n ; n       continue; n     } n     if (c == d && a == b) { n       cout <<  0 n ; n       continue; n     } n     long long l = (a + c - 1) / c - 1; n     long long r = (long long)2e18 / d; n     while (r - l > 1) { n       long long m = (r + l) / 2; n       if (m * d >= b + m * c - a) { n         r = m; n       } else { n         l = m; n       } n     } n     cout << r * d - b <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n = 0, a = 0; n   cin >> n >> a; n   long long int ar[n]; n   long long int i = 0; n   for (i = 0; i < n; i++) cin >> ar[i]; n   long long int pos = a - 1; n   if (n == 1) { n     if (ar[0] == 1) n       cout <<  1  << endl; n     else n       cout <<  0  << endl; n   } else if (n == 2) { n     if ((ar[0] == 1) && (ar[1] == 1)) n       cout <<  2  << endl; n     else if ((ar[0] == 1) || (ar[1] == 1)) n       cout <<  1  << endl; n     else n       cout <<  0  << endl; n   } else { n     long long int low = pos - 1; n     long long int high = pos + 1; n     long long int ans = 0; n     if (ar[pos] == 1) ans++; n     while ((low >= 0) || (high < n)) { n       long long int l1 = ar[low]; n       long long int l2 = ar[high]; n       if ((low >= 0) && (high < n) && (l1 == 1) && (l2 == 1)) n         ans += 2; n       else if ((low >= 0) && (high >= n) && (l1 == 1)) n         ans++; n       else if ((low < 0) && (high < n) && (l2 == 1)) n         ans++; n       else n         ans = ans; n       low--; n       high++; n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100][100]; n int main() { n   int n, a, b; n   scanf( %d , &n); n   for (int i = 0; i < n * n; i++) { n     scanf( %d%d , &a, &b); n     if (!arr[a][b]) { n       printf( %d  , i + 1); n       for (int y = 0; y <= n; y++) { n         arr[a][y] = 1; n         arr[y][b] = 1; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <typename A, typename B = A> n using pr = pair<A, B>; n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr); n   cout << fixed << setprecision(10); n   int sy, a, b; n   cin >> sy >> a >> b; n   sy = -sy; n   int n; n   cin >> n; n   vector<pr<int>> segs(n); n   for (auto &[x, y] : segs) cin >> y >> x; n   sort((segs).begin(), (segs).end()); n   vector<ll> pref(n + 1); n   for (int i = 0; i < n; i++) n     pref[i + 1] = pref[i] + segs[i].first - segs[i].second; n   int q; n   cin >> q; n   while (q--) { n     int x, y; n     cin >> x >> y; n     auto get = [&](int k) { return (k - x) * double(y) / (sy + y); }; n     double x1 = x + get(a); n     double x2 = x + get(b); n     auto find = [&](double x) { n       return int(upper_bound((segs).begin(), (segs).end(), n                              pr<int>{ceil(x + 1e-6), -1}) - n                  segs.begin()); n     }; n     int i1 = find(x1); n     int i2 = find(x2); n     double sum = 0; n     if (i2 != i1) { n       sum += pref[i2] - pref[i1 + 1]; n       if (i1 != -1) n         sum += n             min<double>(segs[i1].first - segs[i1].second, segs[i1].first - x1); n       if (i2 != n) sum += max<double>(0, x2 - segs[i2].second); n     } else { n       int i = i2; n       if (i != -1 && i != n) n         sum += max<double>(0, min<double>(segs[i].first, x2) - n                                   max<double>(segs[i].second, x1)); n     } n     cout << sum * (sy + y) / y <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int limit = 3000000; n const int tope = 100000; n int absolut(int x) { n   if (x < 0) return -x; n   return x; n } n void die() { n   cout << -1 << endl; n   exit(0); n } n int n; n int a[limit]; n int b[limit]; n int add[limit]; n long long int nsol; n vector<pair<int, int> > vsol; n void fix(int pos) { n   while (int(vsol.size()) < tope and add[pos] > 0 and a[pos] < 9 and n          a[pos + 1] < 9) { n     a[pos]++; n     a[pos + 1]++; n     add[pos]--; n     vsol.push_back(pair<int, int>(pos, 1)); n   } n   while (int(vsol.size()) < tope and add[pos] < 0 and a[pos] > 0 and n          a[pos + 1] > 0) { n     a[pos]--; n     a[pos + 1]--; n     add[pos]++; n     vsol.push_back(pair<int, int>(pos, -1)); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     char c; n     cin >> c; n     a[i] = c -  0 ; n   } n   for (int i = 1; i <= n; i++) { n     char c; n     cin >> c; n     b[i] = c -  0 ; n   } n   for (int i = 1; i < n; i++) { n     add[i] = b[i] - (a[i] + add[i - 1]); n     nsol += absolut(add[i]); n   } n   if (a[n] + add[n - 1] != b[n]) die(); n   while (int(vsol.size()) < nsol and int(vsol.size()) < tope) { n     for (int pos = 1; pos < n and int(vsol.size()) < tope; pos++) fix(pos); n     for (int pos = n - 1; pos >= 1 and int(vsol.size()) < tope; pos--) fix(pos); n   } n   cout << nsol << endl; n   for (int i = 0; i < int(vsol.size()) and i < tope; i++) n     cout << vsol[i].first <<     << vsol[i].second << endl; n } n


#include <bits/stdc++.h> n using namespace std; n priority_queue<int, vector<int>, greater<int> > q; n int tar[100005]; n int n, k, add; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> tar[i]; n   long long ans = 0; n   cin >> add; n   int tmp; n   for (int i = 1; i <= n; i++) { n     cin >> tmp; n     q.push(tmp); n     while (k < tar[i]) { n       if (q.empty()) { n         cout << -1 << endl; n         return 0; n       } n       k += add; n       ans += q.top(); n       q.pop(); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int tu(int val) { return (1 << val); } n bool iset(int mask, int id) { n   if ((mask & tu(id)) != 0) return true; n   return false; n } n void doset(int &mask, int id) { mask |= tu(id); } n void dounset(int &mask, int id) { mask = mask & (~tu(id)); } n template <typename T> n string tos(T a) { n   stringstream ss; n   string ret; n   ss << a; n   ss >> ret; n   return ret; n } n const long long LM = 1e18; n long long N, K; n vector<long long> pms, PA, push_back, temp; n void proc(vector<long long> &ans, const vector<long long> &now) { n   ans.clear(); n   ans.push_back(1); n   int l = now.size(); n   for (int(x) = (0); (x) < (l); (x)++) { n     long double p = now[x]; n     int la = ans.size(); n     temp.clear(); n     for (int(i) = (0); (i) < (la); (i)++) { n       long double v = p * ans[i]; n       while (v <= LM) { n         temp.push_back(v); n         v *= p; n       } n     } n     la = temp.size(); n     for (int(i) = (0); (i) < (la); (i)++) ans.push_back(temp[i]); n   } n   sort(ans.begin(), ans.end()); n   int la = ans.size(); n   for (int(i) = (1); (i) < (la); (i)++) assert(ans[i] != ans[i - 1]); n } n long long count(long long val) { n   int la = PA.size(); n   int lb = push_back.size(); n   int ia = 0; n   int ib = lb - 1; n   long long ret = 0; n   while (ia < la && ib >= 0) { n     unsigned long long va = PA[ia] * push_back[ib]; n     if (va > val) n       ib--; n     else { n       ret += ib + 1; n       ia++; n     } n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   while (cin >> N) { n     vector<long long> pa, pb; n     pms.clear(); n     pms.resize(N); n     for (int(i) = (0); (i) < (N); (i)++) cin >> pms[i]; n     sort(pms.begin(), pms.end()); n     cin >> K; n     for (int(i) = (0); (i) < (N); (i)++) { n       if ((i % 2) == 0) n         pa.push_back(pms[i]); n       else n         pb.push_back(pms[i]); n     } n     proc(PA, pa); n     proc(push_back, pb); n     long long ans = -1; n     long long lo = 1; n     long long hi = LM; n     while (true) { n       if (hi - lo < 5) { n         for (long long x = lo; x <= hi; x++) { n           long long k = count(x); n           if (k == K) { n             ans = x; n             break; n           } n         } n         break; n       } n       long long m = (lo + hi) / 2; n       long long k = count(m); n       if (k >= K) n         hi = m; n       else n         lo = m; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string ans_t =  YES ; n string ans_f =  NO ; n void judge(int n) { n   if (n < 6 + 10 + 14 + 1) { n     cout << ans_f << endl; n   } else { n     cout << ans_t << endl; n     int tmp = n - 6 - 10 - 14; n     if (tmp == 6 || tmp == 10 || tmp == 14) { n       cout <<  6 10   << 14 + 1 <<     << tmp - 1 << endl; n     } else { n       cout <<  6 10 14   << tmp << endl; n     } n   } n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     judge(n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int HX = 0x3F3F3F3F; n int n, m, p, q; n long long k; n int f[1111]; n int main() { n   cin >> n >> m >> k; n   memset(f, 0x3F, sizeof f); n   for (int i = 0; i < (n); ++i) { n     cin >> p >> q; n     f[p] = min(f[p], q); n   } n   long long ans = 0; n   for (int i = (1); i <= (m); ++i) ans += f[i]; n   cout << min(ans, k) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2 * 1000 * 100 + 100; n int n, m, w[N], deg[N], ans[N]; n vector<pair<int, int>> adj[N]; n bool vis[N]; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> w[i]; n   for (int i = 1, v, u; i <= m; i++) { n     cin >> v >> u; n     deg[v]++, deg[u]++; n     adj[v].push_back({u, i}); n     adj[u].push_back({v, i}); n   } n   queue<int> q; n   for (int i = 1; i <= n; i++) n     if (deg[i] <= w[i]) q.push(i), vis[i] = true; n   int ind = m; n   while (q.size()) { n     int x = q.front(); n     q.pop(); n     for (auto u : adj[x]) { n       deg[u.first]--, deg[x]--; n       if (deg[u.first] <= w[u.first] && !vis[u.first]) n         vis[u.first] = true, q.push(u.first); n       if (!ans[u.second]) ans[u.second] = ind--; n     } n   } n   vector<int> res(m + 10); n   for (int i = 1; i <= m; i++) { n     if (!ans[i]) return cout <<  DEAD n , 0; n     res[ans[i]] = i; n   } n   cout <<  ALIVE n ; n   for (int i = 1; i <= m; i++) cout << res[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > adj(601); n vector<int> unvisited, even, odd; n int d[601], parent[601]; n bool visited[601]; n map<vector<int>, int> M; n void RemoveFromUnvisited(int v) { n   int i = 0; n   for (; i < unvisited.size() && unvisited[i] != v; ++i) n     ; n   unvisited.erase(unvisited.begin() + i); n } n void PrintQueryOrAnswer(char c, vector<int> &A) { n   printf( %c %lu n , c, A.size()); n   for (auto x : A) { n     printf( %d  , x); n   } n   printf(  n ); n   fflush(stdout); n } n int PrintQuery(vector<int> A) { n   sort(A.begin(), A.end()); n   if (M.find(A) != M.end()) { n     return M[A]; n   } n   PrintQueryOrAnswer( ? , A); n   int m; n   scanf( %d , &m); n   M[A] = m; n   return m; n } n int Query(vector<int> &A, int s = 0) { n   if (s) { n     A.push_back(s); n   } n   int m = PrintQuery(A); n   if (s) { n     A.pop_back(); n   } n   return m; n } n int NextChild(int i, vector<int> A) { n   if (A.size() == 0) { n     return 0; n   } n   int m1 = Query(A, i); n   if (m1 == 0) { n     return 0; n   } n   if (A.size() == 1) { n     return A.back(); n   } n   int m2 = Query(A); n   if (m2 == m1) { n     return 0; n   } n   int j = NextChild(i, vector<int>(A.begin(), A.begin() + (A.size() / 2))); n   if (j == 0) { n     j = NextChild(i, vector<int>(A.begin() + (A.size() / 2), A.end())); n   } n   return j; n } n void AddEdge(int i, int j) { n   adj[i].push_back(j); n   adj[j].push_back(i); n } n void AddEdgeDFS(int i, bool markEvenOdd) { n   RemoveFromUnvisited(i); n   if (markEvenOdd) { n     if (d[i]) { n       odd.push_back(i); n     } else { n       even.push_back(i); n     } n   } n   for (int j = NextChild(i, unvisited); j > 0; j = NextChild(i, unvisited)) { n     AddEdge(i, j); n     if (markEvenOdd) { n       d[j] = 1 - d[i]; n     } n     AddEdgeDFS(j, markEvenOdd); n   } n } n pair<int, int> BipartiteDFS(int i, int p) { n   parent[i] = p; n   d[i] = 1 + d[p]; n   visited[i] = 1; n   pair<int, int> ans = make_pair(0, 0); n   for (auto j : adj[i]) { n     if (j == p) { n       continue; n     } n     if (visited[j]) { n       if ((d[i] - d[j]) % 2 == 0 && d[i] > d[j]) { n         return make_pair(i, j); n       } n       continue; n     } n     ans = max(ans, BipartiteDFS(j, i)); n   } n   return ans; n } n void AddEdges(vector<int> v, bool markEvenOdd) { n   unvisited = vector<int>(v); n   while (unvisited.size()) { n     AddEdgeDFS(unvisited.back(), markEvenOdd); n   } n } n int main() { n   int n; n   vector<int> V; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     V.push_back(i); n   } n   AddEdges(V, true); n   AddEdges(even, false); n   AddEdges(odd, false); n   pair<int, int> p = make_pair(0, 0); n   for (int i = 1; i <= n; ++i) { n     if (visited[i]) { n       continue; n     } n     p = max(p, BipartiteDFS(i, 0)); n   } n   int u, v; n   tie(u, v) = p; n   vector<int> ans; n   if (u == 0) { n     for (int i = 1; i <= n; ++i) { n       if (d[i] % 2) { n         ans.push_back(i); n       } n     } n   } else { n     for (; u != parent[v]; u = parent[u]) { n       ans.push_back(u); n     } n   } n   PrintQueryOrAnswer(v ?  N  :  Y , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int pow2[30]; n int ar[1000900], mark[1000090]; n int main() { n   int n; n   int a, b; n   pow2[0] = 1; n   for (int i = 1, _n = 30; i < _n; i++) pow2[i] = pow2[i - 1] * 2; n   while (cin >> n) { n     memset(mark, -1, sizeof(mark)); n     int m = n - 1, r = 0; n     while (m > 1) { n       if (m % 2) r = 1; n       m /= 2; n     } n     if (n != 2 && !r) { n       mark[1] = 0; n       mark[0] = 1; n     } n     for (int i = n; i >= 0; i--) { n       if (mark[i] == -1) { n         int hi = 29, low = 0, x = 0; n         while (hi >= low) { n           int mid = (hi + low) / 2; n           if (pow2[mid] > i) { n             hi = mid - 1; n           } else if (pow2[mid] <= i) n             low = mid + 1, x = pow2[mid]; n         } n         int d = i - x; n         mark[i] = x - d - 1; n         mark[x - d - 1] = i; n       } n     } n     long long ret = 0; n     for (int i = 0, _n = n + 1; i < _n; i++) ret += (i ^ max(mark[i], 0)); n     cout << ret << endl; n     for (int i = 0, _n = n + 1; i < _n; i++) { n       if (i) cout <<    ; n       if (mark[i] == -1) mark[i] = 0; n       cout << mark[i]; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long T, n, a[300010], c[300010], l[300010], r[300010]; n long long lowbit(long long x) { return x & (-x); } n void add(long long x, long long k) { n   for (long long i = x; i <= n; i += lowbit(i)) c[i] += k; n } n long long query(long long x) { n   long long sum = 0; n   for (long long i = x; i >= 1; i -= lowbit(i)) sum += c[i]; n   return sum; n } n signed main() { n   memset(l, 0, sizeof(l)); n   memset(r, 0, sizeof(r)); n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]); n   memset(c, 0, sizeof(c)); n   for (long long i = 1; i <= n; i++) { n     if (2 * a[i] - 1 <= n) n       l[i] = query(2 * a[i] - 1); n     else n       l[i] = query(n) - query(2 * a[i] - n - 1); n     add(a[i], a[i]); n   } n   memset(c, 0, sizeof(c)); n   for (long long i = n; i >= 1; i--) { n     if (2 * a[i] - 1 <= n) n       r[i] = query(2 * a[i] - 1); n     else n       r[i] = query(n) - query(2 * a[i] - n - 1); n     add(a[i], a[i]); n   } n   long long f = 0; n   for (long long i = 1; i <= n; i++) n     if (l[i] % (2 * a[i]) && r[i] % (2 * a[i])) { n       printf( YES n ); n       f = 1; n       break; n     } n   if (!f) printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   vector<pair<int, int> > v_p; n   int x1, y1, x2, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   if (x2 < x1) swap(x1, x2); n   if (y2 < y1) swap(y1, y2); n   for (int i = y1; i <= y2; i++) { n     v_p.push_back(make_pair(x1, i)); n     v_p.push_back(make_pair(x2, i)); n   } n   for (int i = x1 + 1; i < x2; i++) { n     v_p.push_back(make_pair(i, y1)); n     v_p.push_back(make_pair(i, y2)); n   } n   int n, x, y, r; n   cin >> n; n   vector<tuple<int, int, int> > v; n   for (int i = 0; i < n; i++) { n     cin >> x >> y >> r; n     v.push_back(make_tuple(x, y, r)); n   } n   int cnt = 0; n   for (int i = 0; i < v_p.size(); i++) { n     bool flag = 1; n     for (int j = 0; j < n; j++) { n       int x2 = get<0>(v[j]); n       int y2 = get<1>(v[j]); n       int r = get<2>(v[j]); n       if (r * r >= ((v_p[i].first - x2) * (v_p[i].first - x2)) + n                        ((v_p[i].second - y2) * (v_p[i].second - y2))) { n         flag = 0; n         break; n       } n     } n     if (flag) cnt++; n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   int n; n   cin >> n; n   while (n--) { n     string s; n     cin >> s; n     int szs = s.size(); n     bool z = 0, e = 0; n     int sum = 0; n     for (int i = 0; i < szs; i++) { n       sum += s[i] -  0 ; n       e |= (!((s[i] -  0 ) & 1) && ((s[i] -  0 ) || z)); n       z |= (s[i] ==  0 ); n     } n     if (sum == 0 || (z && e && !(sum % 3))) n       cout <<  red n ; n     else n       cout <<  cyan n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 1; n namespace fastinput { n inline int readChar(); n template <class T = int> n inline T readInt(); n template <class T> n inline void writeInt(T x, char end = 0); n inline void writeChar(int x); n inline void writeWord(const char *s); n static const int buf_size = 16384; n inline int getChar() { n   static char buf[buf_size]; n   static int len = 0, pos = 0; n   if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin); n   if (pos == len) return -1; n   return buf[pos++]; n } n inline int readChar() { n   int c = getChar(); n   while (c <= 32) c = getChar(); n   return c; n } n template <class T> n inline T readInt() { n   int s = 1, c = readChar(); n   T x = 0; n   if (c ==  - ) s = -1, c = getChar(); n   while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar(); n   return s == 1 ? x : -x; n } n static int write_pos = 0; n static char write_buf[buf_size]; n inline void writeChar(char x) { n   if (write_pos == buf_size) n     fwrite(write_buf, 1, buf_size, stdout), write_pos = 0; n   write_buf[write_pos++] = x; n } n template <class T> n inline void writeInt(T x, char end) { n   if (x < 0) writeChar( - ), x = -x; n   char s[24]; n   int n = 0; n   while (x || !n) s[n++] =  0  + x % 10, x /= 10; n   while (n--) writeChar(s[n]); n   if (end) writeChar(end); n } n inline void writeWord(const char *s) { n   while (*s) writeChar(*s++); n } n struct Flusher { n   ~Flusher() { n     if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0; n   } n } flusher; n }  // namespace fastinput n using namespace fastinput; n const string arr[6] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL }; n int decode(string s) { n   for (int i = 0; i < 6; ++i) n     if (s == arr[i]) return i; n } n int cnt[6]; n int answer[N]; n pair<int, int> want[N]; n int give[N]; n map<pair<int, int>, vector<int> > whowant; n void NO() { n   puts( NO ); n   exit(0); n } n int main() { n   ::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   for (int i = 0; i < 6; ++i) cin >> cnt[i]; n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     string t; n     cin >> t; n     size_t x = t.find( , ); n     if (x != std::string::npos) { n       want[i].first = decode(t.substr(0, x)); n       want[i].second = decode(t.substr(x + 1)); n     } else n       want[i].first = decode(t), want[i].second = -1; n     whowant[want[i]].push_back(i); n   } n   for (int i = 0; i < 6; ++i) { n     vector<int> tmp = whowant[{i, -1}]; n     while (cnt[i] > 0 && tmp.size() > 0) { n       give[tmp.back()] = i; n       tmp.pop_back(); n       --cnt[i]; n     } n     if (tmp.size() > 0) NO(); n     tmp = whowant[{i - 1, i}]; n     while (cnt[i] > 0 && tmp.size() > 0) { n       give[tmp.back()] = i; n       tmp.pop_back(); n       --cnt[i]; n     } n     if (tmp.size() > 0) NO(); n     tmp = whowant[{i, i + 1}]; n     while (cnt[i] > 0 && tmp.size() > 0) { n       give[tmp.back()] = i; n       tmp.pop_back(); n       --cnt[i]; n     } n     whowant[{i, i + 1}] = tmp; n   } n   cout <<  YES n ; n   for (int i = 0; i < n; ++i) cout << arr[give[i]] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n long long S[500005]; n void add(int first, int a) { n   for (int i = first; i < 500005; i += i & -i) { n     S[i] += a; n   } n } n long long query(int first) { n   long long res = 0; n   for (int i = first; i > 0; i -= i & -i) { n     res += S[i]; n   } n   return res; n } n struct node { n   node *l, *r; n   int a, b; n   long long Min; n   long long tag; n   node(int _a, int _b) : l(NULL), r(NULL) { n     a = _a; n     b = _b; n     Min = 1e18; n     tag = 0; n   } n } * root; n void build(node *n) { n   if (n->a == n->b) return; n   int mid = (n->a + n->b) / 2; n   n->l = new node(n->a, mid); n   n->r = new node(mid + 1, n->b); n   build(n->l); n   build(n->r); n } n long long Min(node *n) { return n->Min + n->tag; } n void pull(node *n) { n->Min = min(Min(n->l), Min(n->r)); } n void push(node *n) { n   n->l->tag += n->tag; n   n->r->tag += n->tag; n   n->tag = 0; n } n void Set(node *n, int first, long long k) { n   if (n->a == n->b) { n     n->Min = k; n     n->tag = 0; n     return; n   } n   push(n); n   int mid = (n->a + n->b) / 2; n   if (first <= mid) n     Set(n->l, first, k); n   else n     Set(n->r, first, k); n   pull(n); n } n void add(node *n, int l, int r, int k) { n   if (n->a >= l && n->b <= r) { n     n->tag += k; n     return; n   } n   if (n->b < l || n->a > r) return; n   push(n); n   add(n->l, l, r, k); n   add(n->r, l, r, k); n   pull(n); n } n int loc[500005]; n map<int, vector<int> > qu; n int dfs(node *n) { n   if (Min(n) >= 0) { n     return 0; n   } n   if (n->a == n->b) return 1; n   push(n); n   int ret = dfs(n->l) + dfs(n->r); n   pull(n); n   return ret; n } n int main() { n   int q; n   scanf( %d , &q); n   vector<pair<char, int> > v; n   v.push_back(make_pair(( + ), (0))); n   vector<pair<int, int> > num; n   num.push_back(make_pair((0), (0))); n   for (int i = 1; i <= q; i++) { n     char c; n     int first; n     scanf(  %c %d , &c, &first); n     v.push_back(make_pair((c), (first))); n     if (c ==  + ) num.push_back(make_pair((first), (i))); n   } n   sort(num.begin(), num.end()); n   for (int i = 1; i < num.size(); i++) { n     loc[num[i].second] = i; n     qu[num[i].first].push_back(i); n   } n   for (auto &it : qu) { n     reverse(it.second.begin(), it.second.end()); n   } n   root = new node(1, num.size() - 1); n   int R = num.size() - 1; n   build(root); n   int sum = 0; n   for (int i = 1; i <= q; i++) { n     char c; n     c = v[i].first; n     if (c ==  + ) { n       sum++; n       int first; n       first = v[i].second; n       int Index = loc[i]; n       long long val = query(Index - 1) * 2 - first; n       add(root, Index + 1, R, first * 2); n       Set(root, Index, val); n       add(Index, first); n     } else { n       sum--; n       int first; n       first = v[i].second; n       int Index = qu[first].back(); n       qu[first].pop_back(); n       add(root, Index + 1, R, -first * 2); n       Set(root, Index, 1e18); n       add(Index, -first); n     } n     printf( %d n , sum - dfs(root)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int r, idx; n } p, q, t; n struct Fin { n   int x, y, z; n   Fin(){}; n   Fin(int _x, int _y, int _z) { x = _x, y = _y, z = _z; } n }; n bool operator<(Node a, Node b) { return a.r < b.r; } n priority_queue<Node> que; n vector<Fin> vec; n vector<Node> tmp; n int main() { n   int n, mini = 110; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     scanf( %d , &p.r), p.idx = i, que.push(p), mini = min(mini, p.r); n   while (1) { n     tmp.clear(); n     tmp.push_back(que.top()); n     que.pop(); n     while (!que.empty()) { n       if (tmp[0].r == que.top().r) n         tmp.push_back(que.top()), que.pop(); n       else n         break; n     } n     if (que.empty()) { n       mini = tmp[0].r; n       break; n     } n     if (tmp.size() == 1) tmp.push_back(que.top()), que.pop(); n     for (int i = 0; i < tmp.size(); i++) tmp[i].r = max(0, tmp[i].r - 1); n     if (tmp.size() & 1) { n       for (int i = 0; i < tmp.size() - 3; i += 2) n         vec.push_back(Fin(tmp[i].idx, tmp[i + 1].idx, 0)), que.push(tmp[i]), n             que.push(tmp[i + 1]); n       vec.push_back(Fin(tmp[tmp.size() - 3].idx, tmp[tmp.size() - 2].idx, n                         tmp[tmp.size() - 1].idx)); n       que.push(tmp[tmp.size() - 3]), que.push(tmp[tmp.size() - 2]), n           que.push(tmp[tmp.size() - 1]); n     } else n       for (int i = 0; i < tmp.size(); i += 2) n         vec.push_back(Fin(tmp[i].idx, tmp[i + 1].idx, 0)), que.push(tmp[i]), n             que.push(tmp[i + 1]); n   } n   printf( %d n%d n , mini, vec.size()); n   for (int i = 0; i < vec.size(); i++) { n     for (int j = 1; j <= n; j++) { n       if (j == vec[i].x || j == vec[i].y || j == vec[i].z) n         printf( 1 ); n       else n         printf( 0 ); n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ok[1 << 20]; n int F[1 << 9][1 << 9]; n int d[1 << 9]; n int bfs(int n) { n   d[0] = 0; n   for (int i = 1; i <= n; ++i) d[i] = -1; n   queue<int> Q; n   Q.push(0); n   while (!Q.empty() && d[n] == -1) { n     int node = Q.front(); n     Q.pop(); n     for (int i = 0; i <= n; ++i) n       if (d[i] == -1 && F[node][i]) Q.push(i), d[i] = node; n   } n   if (d[n] == -1) return 0; n   int flow = 1e9; n   for (int vertex = n; vertex; vertex = d[vertex]) n     flow = min(flow, F[d[vertex]][vertex]); n   for (int vertex = n; vertex; vertex = d[vertex]) n     F[d[vertex]][vertex] -= flow, F[vertex][d[vertex]] += flow; n   return flow; n } n vector<int> order; n int mark[1 << 9]; n void dfs(int node, int n, int how) { n   mark[node] = 1; n   order.push_back(node); n   for (int i = 1; i <= n; ++i) n     if (!mark[i] && (F[node][i] == how && F[i][node] != how)) n       dfs(i, n, 1 - how); n } n int Val[1 << 9]; n int main(void) { n   int n; n   for (int i = 2; i <= 1e6; ++i) ok[i] = 1; n   for (int i = 2; i <= 1e3; ++i) n     if (ok[i]) n       for (int j = i * i; j <= 1e6; j += i) ok[j] = 0; n   cin >> n; n   vector<int> a, b, pa, pb; n   for (int i = 1; i <= n; ++i) { n     int val; n     cin >> val; n     Val[i] = val; n     if (val & 1) n       a.push_back(val), pa.push_back(i); n     else n       b.push_back(val), pb.push_back(i); n   } n   if (a.size() != b.size()) return puts( Impossible ) * 0; n   int sz = a.size(); n   for (int i = 1; i <= sz; ++i) F[0][i] = 2; n   for (int i = 1; i <= sz; ++i) F[i + sz][sz + sz + 1] = 2; n   for (int i = 0; i < sz; ++i) n     for (int j = 0; j < sz; ++j) n       if (ok[a[i] + b[j]]) F[i + 1][j + 1 + sz] = 1; n   int flow = 0; n   int cnt = 0; n   while ((cnt = bfs(sz + sz + 1)) != 0) flow += cnt; n   if (flow != sz + sz) return puts( Impossible ) * 0; n   vector<vector<int> > cycles; n   for (int i = 1; i <= sz + sz; ++i) n     if (!mark[i]) { n       order.clear(); n       dfs(i, sz + sz, 0); n       for (auto &it : order) n         if (it <= sz) n           it = pa[it - 1]; n         else n           it = pb[it - sz - 1]; n       cycles.push_back(order); n     } n   cout << (cycles.size()) <<   n ; n   for (auto cycle : cycles) { n     cout << cycle.size() <<    ; n     for (auto it : cycle) cout << it <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int pearls = 0, links = 0; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  - ) n       links++; n     else n       pearls++; n   } n   if (pearls == 0) n     cout <<  yes  << endl; n   else if (links % pearls == 0) n     cout <<  yes  << endl; n   else n     cout <<  no  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int n, m, q; n int a[210000]; n int nxt[210000][20]; n int loc[210000]; n int p[210000]; n int rp[210000]; n int ans[210000]; n pair<pair<int, int>, int> queries[210000]; n int main() { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 0; i < n; i++) { n     scanf( %d , &p[i]); n     p[i]--; n     rp[p[i]] = i; n   } n   for (int i = 0; i < m; i++) { n     scanf( %d , &a[i]); n     a[i]--; n     a[i] = rp[a[i]]; n   } n   for (int i = 0; i < q; i++) { n     int l, r; n     scanf( %d %d , &l, &r); n     r--; n     l--; n     queries[i] = {{r, l}, i}; n   } n   memset(loc, -1, sizeof(loc)); n   for (int i = 0; i < m; i++) { n     int prev = (a[i] + n - 1) % n; n     nxt[i][0] = loc[prev]; n     loc[a[i]] = i; n   } n   for (int lvl = 1; lvl < 20; lvl++) { n     for (int i = 0; i < m; i++) { n       if (nxt[i][lvl - 1] == -1) n         nxt[i][lvl] = -1; n       else n         nxt[i][lvl] = nxt[nxt[i][lvl - 1]][lvl - 1]; n     } n   } n   sort(queries, queries + q); n   int cur_query = 0; n   int best = -1; n   for (int i = 0; i < m; i++) { n     int cur = i; n     for (int lvl = 0; lvl < 20; lvl++) n       if ((1 << lvl) & (n - 1)) cur = nxt[cur][lvl]; n     best = max(best, cur); n     for (; cur_query < q && queries[cur_query].first.first == i; cur_query++) { n       ans[queries[cur_query].second] = n           (best >= queries[cur_query].first.second); n     } n   } n   for (int i = 0; i < q; i++) { n     printf( %d , ans[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n struct Matrix { n   long long a, b, c, d; n   Matrix(long long _a = 0, long long _b = 0, long long _c = 0, n          long long _d = 0) { n     a = _a; n     b = _b; n     c = _c; n     d = _d; n   } n   void normalize(Matrix& mat) { n     mat.a %= mod; n     mat.b %= mod; n     mat.c %= mod; n     mat.d %= mod; n   } n   const Matrix operator+(const Matrix& mat) { n     Matrix tmp(this->a + mat.a, this->b + mat.b, this->c + mat.c, n                this->d + mat.d); n     normalize(tmp); n     return tmp; n   } n   const Matrix operator*(const Matrix& mat) { n     Matrix tmp( n         this->a * mat.a + this->b * mat.c, this->a * mat.b + this->b * mat.d, n         this->c * mat.a + this->d * mat.c, this->c * mat.b + this->d * mat.d); n     normalize(tmp); n     return tmp; n   } n   bool operator==(const Matrix& mat) const { n     if (this->a == mat.a && this->b == mat.b && this->c == mat.c && n         this->d == mat.d) n       return true; n     return false; n   } n   bool operator!=(const Matrix& mat) const { return !(*this == mat); } n   void pprint() { n     return; n     cerr <<  ---------------------------  << endl; n     cerr << this->a <<   |   << this->b << endl; n     cerr << this->c <<   |   << this->d << endl; n     cerr <<  ---------------------------  << endl; n   } n }; n class SegmentTree { n  private: n   vector<Matrix> A, st, lazy; n   int n; n   Matrix lazyId; n   int left(int p) { return p << 1; } n   int right(int p) { return (p << 1) + 1; } n   void build(int p, int l, int r) { n     if (r - l == 1) { n       st[p] = A[l]; n       return; n     } n     int mid = (l + r) / 2; n     build(left(p), l, mid); n     build(right(p), mid, r); n     st[p] = st[left(p)] + st[right(p)]; n   } n   void apply(int p, int l, int r) { n     st[p] = lazy[p] * st[p]; n     if (r - l > 1) { n       lazy[left(p)] = lazy[p] * lazy[left(p)]; n       lazy[right(p)] = lazy[p] * lazy[right(p)]; n     } n     lazy[p] = lazyId; n   } n   void lazyUpdate(int p, int l, int r, int i, int j, Matrix& val) { n     if (lazy[p] != lazyId) apply(p, l, r); n     if (j <= l || r <= i) return; n     if (i <= l && r <= j) { n       lazy[p] = lazy[p] * val; n       apply(p, l, r); n       return; n     } n     int mid = (l + r) / 2; n     lazyUpdate(left(p), l, mid, i, j, val); n     lazyUpdate(right(p), mid, r, i, j, val); n     st[p] = st[left(p)] + st[right(p)]; n   } n   Matrix query(int p, int l, int r, int i, int j) { n     if (j <= l || r <= i) return Matrix(); n     if (lazy[p] != lazyId) apply(p, l, r); n     if (i <= l && r <= j) return st[p]; n     int mid = (l + r) / 2; n     Matrix uno = query(left(p), l, mid, i, j); n     Matrix dos = query(right(p), mid, r, i, j); n     return uno + dos; n   } n  n  public: n   SegmentTree(vector<Matrix> v) { n     A = v; n     n = v.size(); n     st.assign(4 * n, Matrix()); n     lazyId = Matrix(1, 0, 0, 1); n     lazy.assign(4 * n, lazyId); n     build(1, 0, n); n   } n   void update(int i, int j, Matrix& val) { lazyUpdate(1, 0, n, i, j, val); } n   Matrix query(int i, int j) { return query(1, 0, n, i, j); } n }; n Matrix pot(Matrix b, int k) { n   if (k == 0) return Matrix(1, 0, 0, 1); n   if (k % 2 == 0) { n     Matrix tmp = pot(b, k / 2); n     return tmp * tmp; n   } else { n     return b * pot(b, k - 1); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   int n, m; n   cin >> n >> m; n   Matrix base = Matrix(1, 1, 1, 0); n   vector<Matrix> vec; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     Matrix tmp = pot(base, a); n     vec.push_back(tmp); n     ; n     ; n     tmp.pprint(); n   } n   SegmentTree st(vec); n   for (int i = 0; i < m; i++) { n     int t; n     cin >> t; n     if (t == 1) { n       int l, r, x; n       cin >> l >> r >> x; n       l--; n       r--; n       Matrix tmp = pot(base, x); n       ; n       ; n       tmp.pprint(); n       st.update(l, r + 1, tmp); n     } else { n       int l, r; n       cin >> l >> r; n       l--; n       r--; n       Matrix tmp = st.query(l, r + 1); n       tmp.pprint(); n       long long res = tmp.c % mod; n       cout << res << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10, p = 1e9 + 7; n map<int, int> mp; n char s[N]; n inline void A(int &x, int y) { x = (x + y >= p ? x + y - p : x + y); } n inline void Append(int w) { n   int v1 = 0, v2 = 0; n   map<int, int>::iterator it; n   for (it = mp.begin(); it != mp.end() && it->first <= w; ++it) { n     A(v1, it->second); n     v2 = (v2 + 1ll * it->second * (w - it->first + 1)) % p; n   } n   mp.erase(mp.begin(), it); n   A(mp[w + 1], v1); n   mp[0] = v2; n } n int main() { n   scanf( %s , s + 1); n   int ln = 1, rn = strlen(s + 1); n   int time_l = 1, time_r = 1; n   while (s[ln] ==  0 ) ++time_l, ++ln; n   if (ln > rn) { n     printf( %d n , rn); n     return 0; n   } n   while (s[rn] ==  0 ) ++time_r, --rn; n   mp[0] = 1; n   while (ln != rn) { n     ++ln; n     int w = 0; n     while (s[ln] ==  0 ) ++ln, ++w; n     Append(w); n   } n   int ans = 0; n   for (auto x : mp) A(ans, x.second); n   printf( %lld n , 1ll * ans * time_l % p * time_r % p); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> odd, even; n int main() { n   int cnt1 = 0, cnt2 = 0, tem = -1; n   int n, k, p, x; n   scanf( %d%d%d , &n, &k, &p); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     if (x % 2 == 0) { n       cnt2++; n       even.push_back(x); n     } else { n       if (cnt1 >= k - p) { n         if (tem == -1) n           tem = x; n         else { n           even.push_back(tem); n           even.push_back(x); n           cnt2++; n           tem = -1; n         } n       } else { n         cnt1++; n         odd.push_back(x); n       } n     } n   } n   if (cnt1 < k - p || cnt2 < p || tem != -1) n     printf( NO n ); n   else { n     printf( YES n ); n     if (p == 0) { n       for (int i = 0; i < k - p - 1; i++) printf( %d %d n , 1, odd[i]); n       printf( %d , n - (k - p - 1)); n       for (int i = 0; i < even.size(); i++) printf(  %d , even[i]); n       printf(  %d n , odd[k - p - 1]); n       return 0; n     } n     for (int i = 0; i < k - p; i++) printf( %d %d n , 1, odd[i]); n     int tem2 = 0, cur = 0; n     while (tem2 < p - 1) { n       if (even[cur] % 2 == 0) { n         printf( %d %d n , 1, even[cur]); n         cur++; n       } else { n         printf( %d %d %d n , 2, even[cur], even[cur + 1]); n         cur++; n         cur++; n       } n       tem2++; n     } n     if (even.size() > cur) printf( %d , even.size() - cur); n     for (int i = cur; i < even.size(); i++) printf(  %d , even[i]); n   } n   return 0; n } n


#include<iostream> n #include<stdio.h> n using namespace std; n  int main() n {long int max,x,y,t; n cin>>t; n  n  while(t--) n {   cin>>x>>y; n     if(x==y) n     {cout<<2*x<<endl; n     continue; n             n          n     } n     max=x; n      n     if(x<y) n     { n         max=y; n     } n     cout<<2*max-1<<endl; n      n } n     return 0; n  n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int n; n int L; n int R; n struct data { n   int u; n   int f; n   int dis; n   int dep; n }; n queue<data> q1, q2; n struct ed { n   int v; n   int val; n   int siz; n   int ori; n   friend bool operator<(ed a, ed b) { return a.siz < b.siz; } n }; n vector<ed> v[N]; n int ng[N]; n int tim; n int nsiz[N]; n int w[N]; n int nu[N]; n int siz[N]; n bool cut[N]; n int ans1; n int ans2; n struct dq { n   int q[3 * N]; n   int hd; n   int tl; n   inline void clr() { n     hd = 1; n     tl = 0; n   } n   inline bool emp() { return hd <= tl; } n   inline void ins(int j) { n     while (hd <= tl && w[j] >= w[q[tl]]) tl--; n     q[++tl] = j; n   } n   inline void del(int k) { n     while (hd <= tl && q[hd] > k) hd++; n   } n   inline int qmx() { return q[hd]; } n } q; n inline void clear(queue<data>& q) { n   queue<data> emp; n   swap(q, emp); n } n inline int dfs1(int u, int f) { n   siz[u] = 1; n   for (vector<ed>::iterator it = v[u].begin(); it != v[u].end(); ++it) n     if (it->v != f && !cut[it->v]) siz[u] += dfs1(it->v, u); n   return siz[u]; n } n inline int find(int u, int f, const int& tot) { n   for (vector<ed>::iterator it = v[u].begin(); it != v[u].end(); ++it) n     if (it->v != f && !cut[it->v] && 2 * siz[it->v] >= tot) n       return find(it->v, u, tot); n   return u; n } n inline int dfs3(int u, int f) { n   int mx = 0; n   for (vector<ed>::iterator it = v[u].begin(); it != v[u].end(); ++it) n     if (it->v != f && !cut[it->v]) mx = max(mx, dfs3(it->v, u)); n   return mx + 1; n } n inline bool bfs(data st, int mxsiz) { n   q.clr(); n   clear(q1); n   clear(q2); n   int j = min(R, mxsiz); n   for (; j >= L; j--) q.ins(j); n   for (q1.push(st); !q1.empty();) { n     data nw = q1.front(); n     q2.push(nw); n     q1.pop(); n     if (nw.dep > R) continue; n     int dl = max(L - nw.dep, 0); n     int dr = min(R - nw.dep, mxsiz); n     for (; j >= dl; j--) q.ins(j); n     q.del(dr); n     if (q.emp()) { n       int p = q.qmx(); n       if (nw.dis + w[p] >= 0) { n         ans1 = nu[p]; n         ans2 = nw.u; n         return true; n       } n     } n     for (vector<ed>::iterator it = v[nw.u].begin(); it != v[nw.u].end(); ++it) n       if (it->v != nw.f && !cut[it->v]) n         q1.push((data){it->v, nw.u, nw.dis + it->val, nw.dep + 1}); n   } n   for (; !q2.empty(); q2.pop()) { n     data a = q2.front(); n     if (w[a.dep] < a.dis) w[a.dep] = a.dis, nu[a.dep] = a.u; n   } n   return false; n } n inline bool solve(int u) { n   ++tim; n   int g; n   if (ng[tim] == -1) { n     dfs1(u, 0); n     g = find(u, 0, siz[u]); n     cut[g] = true; n     ng[tim] = g; n     nsiz[tim] = siz[u]; n     if (siz[u] == 1) return false; n     for (int i = 1; i <= siz[u]; i++) w[i] = -0x3f3f3f3f, nu[i] = 0; n     for (vector<ed>::iterator it = v[g].begin(); it != v[g].end(); ++it) n       if (!cut[it->v]) it->siz = dfs3(it->v, g); n     sort(v[g].begin(), v[g].end()); n     w[0] = 0; n     nu[0] = g; n   } else { n     g = ng[tim]; n     cut[g] = true; n     if (nsiz[tim] == 1) return false; n     for (int i = 1; i <= nsiz[tim]; i++) w[i] = -0x3f3f3f3f, nu[i] = 0; n     w[0] = 0; n     nu[0] = g; n   } n   for (vector<ed>::iterator it = v[g].begin(); it != v[g].end(); ++it) n     if (!cut[it->v]) n       if (bfs((data){it->v, g, it->val, 1}, it->siz)) return true; n   for (vector<ed>::iterator it = v[g].begin(); it != v[g].end(); ++it) n     if (!cut[it->v]) n       if (solve(it->v)) return true; n   return false; n } n inline bool jud(int mid) { n   tim = 0; n   for (int i = 1; i <= n; i++) n     for (vector<ed>::iterator it = v[i].begin(); it != v[i].end(); ++it) n       it->val = (it->ori >= mid) ? 1 : -1; n   for (int i = 1; i <= n; i++) cut[i] = false; n   return solve(1); n } n int main() { n   scanf( %d%d%d , &n, &L, &R); n   int l = 0; n   int r = 0; n   for (int i = 1; i <= n; i++) ng[i] = -1; n   for (int i = 1, u, V, va; i < n; i++) { n     scanf( %d%d%d , &u, &V, &va); n     r = max(r, va); n     v[u].push_back((ed){V, 0, 0, va}); n     v[V].push_back((ed){u, 0, 0, va}); n   } n   while (l != r) { n     int mid = (l + r + 1) / 2; n     if (jud(mid)) n       l = mid; n     else n       r = mid - 1; n   } n   jud(l); n   printf( %d %d , ans1, ans2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n long long fact[200001], invfact[200001]; n int n50 = 0, n100 = 0, k = 0; n struct node { n   int l[2], r[2], b; n }; n long long nways[51][51][51][51][2], shortest[51][51][51][51][2]; n queue<node> q; n long long pmod(long long base, long long p) { n   if (p == 0) return 1LL; n   long long ret = pmod(base, p / 2); n   ret = (ret * ret) % MOD; n   if (p % 2 == 1) ret = (ret * base) % MOD; n   return ret; n } n long long invEuler(long long x) { return pmod(x, MOD - 2); } n long long nCr(long long n, long long r) { n   long long ret = 1; n   ret *= fact[n]; n   ret = (ret * invfact[r]) % MOD; n   ret = (ret * invfact[n - r]) % MOD; n   return ret; n } n void bfs() { n   memset(nways, 0, sizeof(nways)); n   memset(shortest, -1, sizeof(shortest)); n   nways[n50][n100][0][0][0] = 1; n   shortest[n50][n100][0][0][0] = 0; n   node temp; n   temp.l[0] = n50; n   temp.l[1] = n100; n   temp.r[0] = 0; n   temp.r[1] = 0; n   temp.b = 0; n   q.push(temp); n   while (!q.empty()) { n     temp = q.front(); n     q.pop(); n     int l0, l1, r0, r1, b; n     l0 = temp.l[0]; n     l1 = temp.l[1]; n     r0 = temp.r[0]; n     r1 = temp.r[1]; n     b = temp.b; n     if (b == 0) { n       for (int i = 0; i <= l0; ++i) { n         for (int j = 0; j <= l1; ++j) { n           if (50 * i + 100 * j > k || (!i && !j)) continue; n           int _l0 = l0 - i, _l1 = l1 - j, _r0 = r0 + i, _r1 = r1 + j, _b = !b; n           if (shortest[_l0][_l1][_r0][_r1][_b] == -1 || n               shortest[_l0][_l1][_r0][_r1][_b] > n                   shortest[l0][l1][r0][r1][b] + 1) { n             shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b]; n             nways[_l0][_l1][_r0][_r1][_b] = n                 (((nCr(l0, i) * nCr(l1, j)) % MOD) * nways[l0][l1][r0][r1][b]) % n                 MOD; n             temp.l[0] = _l0; n             temp.l[1] = _l1; n             temp.r[0] = _r0; n             temp.r[1] = _r1; n             temp.b = _b; n             q.push(temp); n           } else if (shortest[_l0][_l1][_r0][_r1][_b] == n                      shortest[l0][l1][r0][r1][b] + 1) n             nways[_l0][_l1][_r0][_r1][_b] = n                 (nways[_l0][_l1][_r0][_r1][_b] + n                  (((nCr(l0, i) * nCr(l1, j)) % MOD) * n                   nways[l0][l1][r0][r1][b]) % n                      MOD) % n                 MOD; n         } n       } n     } else { n       for (int i = 0; i <= r0; ++i) { n         for (int j = 0; j <= r1; ++j) { n           if (50 * i + 100 * j > k || (!i && !j)) continue; n           int _l0 = l0 + i, _l1 = l1 + j, _r0 = r0 - i, _r1 = r1 - j, _b = !b; n           if (shortest[_l0][_l1][_r0][_r1][_b] == -1 || n               shortest[_l0][_l1][_r0][_r1][_b] > n                   shortest[l0][l1][r0][r1][b] + 1) { n             shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b]; n             nways[_l0][_l1][_r0][_r1][_b] = n                 (((nCr(r0, i) * nCr(r1, j)) % MOD) * nways[l0][l1][r0][r1][b]) % n                 MOD; n             temp.l[0] = _l0; n             temp.l[1] = _l1; n             temp.r[0] = _r0; n             temp.r[1] = _r1; n             temp.b = _b; n             q.push(temp); n           } else if (shortest[_l0][_l1][_r0][_r1][_b] == n                      shortest[l0][l1][r0][r1][b] + 1) n             nways[_l0][_l1][_r0][_r1][_b] = n                 (nways[_l0][_l1][_r0][_r1][_b] + n                  (((nCr(r0, i) * nCr(r1, j)) % MOD) * n                   nways[l0][l1][r0][r1][b]) % n                      MOD) % n                 MOD; n         } n       } n     } n   } n } n int main() { n   int n, in; n   fact[0] = 1; n   fact[1] = 1; n   invfact[0] = invEuler(1); n   invfact[1] = invfact[0]; n   for (int i = 2; i < 200001; ++i) { n     fact[i] = (fact[i - 1] * i) % MOD; n     invfact[i] = invEuler(fact[i]); n   } n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &in); n     if (in == 50) n       n50++; n     else n       n100++; n   } n   bfs(); n   cout << shortest[0][0][n50][n100][1] << endl << nways[0][0][n50][n100][1]; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long xor128() { n   static unsigned long x = time(NULL), y = 362436069, z = 521288629, n                        w = 88675123; n   unsigned long t = (x ^ (x << 11)); n   x = y; n   y = z; n   z = w; n   return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); n } n double dot(complex<double> a, complex<double> b) { n   return a.real() * b.real() + a.imag() * b.imag(); n } n double gyaku_dot(complex<double> a, complex<double> b) { n   return a.real() * b.imag() - a.imag() * b.real(); n } n double leng(complex<double> a) { n   return sqrt(a.real() * a.real() + a.imag() * a.imag()); n } n double angles(complex<double> a, complex<double> b) { n   double cosine = dot(a, b) / (leng(a) * leng(b)); n   double sine = gyaku_dot(a, b) / (leng(a) * leng(b)); n   double kaku = acos(min((double)1.0, max((double)-1.0, cosine))); n   if (sine <= 0) { n     kaku = 2 * 3.141592653589793 - kaku; n   } n   return kaku; n } n vector<int> convex_hull(vector<complex<double>> a) { n   vector<int> ans; n   double now_minnest = a[0].real(); n   int now_itr = 0; n   for (long long i = 0; i < a.size(); ++i) { n     if (now_minnest > a[i].real()) { n       now_minnest = a[i].real(); n       now_itr = i; n     } n   } n   ans.push_back(now_itr); n   complex<double> ba(0, 1); n   while (true) { n     int now_go = 0; n     double now_min = 0; n     double now_length = 0; n     int starter = ans[ans.size() - 1]; n     for (int i = 0; i < a.size(); ++i) { n       if (i != starter) { n         double goa = angles(ba, a[i] - a[starter]); n         if (goa - now_min >= 1e-5 || n             (abs(goa - now_min) <= 1e-5 && n              (abs(a[i] - a[starter]) - now_length) >= 1e-5)) { n           now_min = goa; n           now_go = i; n           now_length = abs(a[i] - a[starter]); n         } n       } n     } n     if (now_go == ans[0]) break; n     ans.push_back(now_go); n     ba = complex<double>(a[now_go] - a[starter]); n   } n   return ans; n } n int ruiseki[1000000]; n int main() { n   int test_case; n   cin >> test_case; n   for (long long i = 0; i < test_case; ++i) { n     string s; n     cin >> s; n     int ans = 0; n     ruiseki[0] = 0; n     for (int i = 0; i < s.length(); ++i) { n       if (i != 0) ruiseki[i] = ruiseki[i - 1]; n       if (s[i] ==  1 ) { n         ruiseki[i]++; n       } n     } n     for (int i = 0; i < s.length(); ++i) { n       int now = 0; n       for (int q = i; q >= 0; --q) { n         if (i - q > 25) { n           int now_back = i - now + 1; n           int now_front = q; n           if (now_back > now_front) break; n           if (now_back < 0) break; n           int hoge = ruiseki[now_front]; n           if (now_back != 0) { n             hoge -= ruiseki[now_back - 1]; n           } n           if (hoge == 0) ans++; n           break; n         } n         if (s[q] ==  1 ) { n           now += (1 << (i - q)); n         } n         if (now == i - q + 1) ans++; n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[212345]; n int cnts[212345]; n int lft[212345]; n int rght[212345]; n int cumsum[212345]; n int get_right_ans(int i) { return cumsum[rght[i]] - cumsum[i]; } n int get_left_ans(int i) { n   if (lft[i]) return cumsum[i - 1] - cumsum[lft[i] - 1]; n   return cumsum[i - 1]; n } n void print_ans(int fin_ans, int slope) { n   if (cnts[fin_ans] < 1) { n     return; n   } n   if (cnts[fin_ans] < 2) { n     cnts[fin_ans] -= 1; n     printf( %d  , fin_ans); n     return; n   } n   printf( %d  , fin_ans); n   cnts[fin_ans] -= 1; n   print_ans(fin_ans + slope, slope); n   while (cnts[fin_ans]) { n     printf( %d  , fin_ans); n     cnts[fin_ans]--; n   } n } n int main() { n   int n, tmp, fnd; n   scanf( %d , &n); n   ; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     ; n     cnts[a[i]] += 1; n   } n   int lst_val = -1; n   for (int i = 0; i < 212345; i++) { n     lft[i] = lst_val; n     if (cnts[i] < 2) lst_val = i; n   } n   lst_val = 212345; n   for (int i = 212345 - 1; i >= 0; i--) { n     rght[i] = lst_val; n     if (cnts[i] < 2) lst_val = i; n   } n   for (int i = 1; i < 212345; i++) cumsum[i] = cumsum[i - 1] + cnts[i]; n   int maxi = 0; n   int fin_ans = -1; n   for (int i = 1; i < 212345; i++) { n     if (cnts[i] == 1) { n       if (1 + max(get_right_ans(i), get_left_ans(i)) > maxi) { n         maxi = max(maxi, 1 + max(get_right_ans(i), get_left_ans(i))); n         fin_ans = i; n       } n     } else if (cnts[i] > 1) { n       if (cnts[i] + get_right_ans(i) + get_left_ans(i) > maxi) { n         maxi = max(maxi, cnts[i] + get_right_ans(i) + get_left_ans(i)); n         fin_ans = i; n       } n     } n   } n   printf( %d n , maxi); n   if (cnts[fin_ans] == 1) { n     printf( %d  , fin_ans); n     if (get_left_ans(fin_ans) > get_right_ans(fin_ans)) n       print_ans(fin_ans - 1, -1); n     else n       print_ans(fin_ans + 1, +1); n   } else { n     if (get_left_ans(fin_ans)) { n       printf( %d  , fin_ans); n       print_ans(fin_ans - 1, -1); n       cnts[fin_ans] -= 1; n     } n     if (get_right_ans(fin_ans)) { n       printf( %d  , fin_ans); n       print_ans(fin_ans + 1, 1); n       cnts[fin_ans] -= 1; n     } n     while (cnts[fin_ans]) { n       printf( %d  , fin_ans); n       cnts[fin_ans]--; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = 1e10; n template <typename T> n void cmax(T &a, T b) { n   a = max(a, b); n } n template <typename T> n void cmin(T &a, T b) { n   a = min(a, b); n } n signed main() { n   string s; n   cin >> s; n   long long a[5555] = {}; n   long long b[5555] = {}; n   for (long long i = 0; i < (s.size()); i++) { n     a[i + 1] += a[i]; n     b[i + 1] += b[i]; n     if (s[i] ==  a ) n       a[i + 1]++; n     else n       b[i + 1]++; n   } n   long long ans = 0; n   for (long long i = 0; i < (s.size() + 1); i++) n     for (long long j = (i); j < (s.size() + 1); j++) n       cmax(ans, a[s.size()] - a[j] + b[j] - b[i] + a[i]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(double S, double a, double b, double c, double* result) { n   if ((a == 0) && (b == 0) && (c == 0)) { n     result[0] = S; n   } else if ((a == 0) && (b == 0) && (c > 0)) { n     result[2] = S; n   } else if ((a == 0) && (b > 0) && (c == 0)) { n     result[1] = S; n   } else if ((a > 0) && (b == 0) && (c == 0)) { n     result[0] = S; n   } else if ((a == 0) && (b > 0) && (c > 0)) { n     result[1] = S * b / (b + c); n     result[2] = S * c / (b + c); n   } else if ((a > 0) && (b == 0) && (c > 0)) { n     result[0] = S * a / (a + c); n     result[2] = S * c / (a + c); n   } else if ((a > 0) && (b > 0) && (c == 0)) { n     result[0] = S * a / (a + b); n     result[1] = S * b / (a + b); n   } else if ((a > 0) && (b > 0) && (c > 0)) { n     result[0] = S * (a * (a + b)) / ((a + b) * (a + b + c)); n     result[1] = S * (b * (a + b)) / ((a + b) * (a + b + c)); n     result[2] = S * c / (a + b + c); n   } n } n int main() { n   unsigned int S(0), a(0), b(0), c(0); n   double result[3] = {0.0, 0.0, 0.0}; n   cin >> S; n   cin >> a; n   cin >> b; n   cin >> c; n   solve((double)S, (double)a, (double)b, (double)c, result); n   cout << std::fixed << std::setprecision(10) << result[0] <<     << result[1] n        <<     << result[2]; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (a == 0) return 0; n   return gcd(b % a, a) + b / a; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   while (n--) { n     int a, b; n     cin >> a >> b; n     cout << gcd(a, b) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long p, ans, num; n int n; n string s[500000]; n int main() { n   cin >> n >> p; n   p /= 2; n   for (int i = 1; i <= n; ++i) { n     cin >> s[i]; n   } n   for (int i = n; i >= 1; --i) { n     num *= 2; n     if (s[i] ==  halfplus ) num++; n     ans += num; n   } n   cout << ans * p << endl; n } n