#include <bits/stdc++.h> n int32_t get_economy(std::vector<int32_t> joined_roots, int32_t** tree) { n   if (joined_roots.size() == 1) return 0; n   int32_t res = joined_roots.size() - 1; n   std::vector<int32_t> join_lists[26]; n   for (int32_t i = 0; i < joined_roots.size(); i++) n     for (int32_t j = 0; j < 26; j++) n       if (tree[joined_roots[i]][j] != -1) n         join_lists[j].push_back(tree[joined_roots[i]][j]); n   for (int32_t i = 0; i < 26; i++) n     if (join_lists[i].size() > 0) res += get_economy(join_lists[i], tree); n   return res; n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   int32_t n; n   std::cin >> n; n   int32_t** tree = new int32_t*[n]; n   for (int32_t i = 0; i < n; i++) { n     tree[i] = new int32_t[26]; n     for (int32_t j = 0; j < 26; j++) tree[i][j] = -1; n   } n   int32_t* parents = new int32_t[n]; n   for (int32_t i = 0; i < n - 1; i++) { n     int32_t src, dst; n     char ch; n     std::cin >> src >> dst >> ch; n     src--; n     dst--; n     parents[dst] = src; n     tree[src][ch -  a ] = dst; n   } n   std::vector<int32_t> removed; n   for (int32_t j = 0; j < 26; j++) n     if (tree[0][j] != -1) removed.push_back(tree[0][j]); n   int32_t min_size = n, best_cut = -1; n   int32_t cur_cut = 0; n   while (removed.size() > 0) { n     std::map<int32_t, std::vector<int32_t> > groups_per_parent; n     for (int32_t i = 0; i < removed.size(); i++) n       groups_per_parent[parents[removed[i]]].push_back(removed[i]); n     int32_t total_economy = removed.size(); n     for (auto it = groups_per_parent.begin(); it != groups_per_parent.end(); n          it++) { n       std::vector<int32_t> join_lists[26]; n       for (int32_t i = 0; i < it->second.size(); i++) n         for (int32_t j = 0; j < 26; j++) n           if (tree[it->second[i]][j] != -1) n             join_lists[j].push_back(tree[it->second[i]][j]); n       for (int32_t i = 0; i < 26; i++) n         if (join_lists[i].size() > 0) n           total_economy += get_economy(join_lists[i], tree); n     } n     if (n - total_economy < min_size) { n       min_size = n - total_economy; n       best_cut = cur_cut; n     } n     std::vector<int32_t> new_removed; n     for (int32_t i = 0; i < removed.size(); i++) n       for (int32_t j = 0; j < 26; j++) n         if (tree[removed[i]][j] != -1) n           new_removed.push_back(tree[removed[i]][j]); n     removed = new_removed; n     cur_cut++; n   } n   std::cout << min_size <<   n  << best_cut + 1; n } n


#include <bits/stdc++.h> n using namespace std; n  n #ifdef LOCAL n #define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__) n #else n #define DEBUG(...) 6 n #endif n  n template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os <<  (  << p.first <<  ,   << p.second <<  ) ;} n template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr> n ostream& operator << (ostream &os, const C &c) {bool f = true; os <<  [ ; for (const auto &x : c) {if (!f) os <<  ,  ; f = false; os << x;} return os <<  ] ;} n template<typename T> void debug(string s, T x) {cerr << s <<   =   << x <<   n ;} n template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] ==  (  || s[i] ==  { ) b++; else n if (s[i] ==  )  || s[i] ==  } ) b--; else if (s[i] ==  ,  && b == 0) {cerr << s.substr(0, i) <<   =   << x <<   |  ; debug(s.substr(s.find_first_not_of(   , i + 1)), args...); break;}} n  n template<int MOD> n struct ModInt { n     long long v; n     ModInt(long long _v = 0) {v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; if (v < 0) v += MOD;} n     ModInt& operator += (const ModInt &other) {v += other.v; if (v >= MOD) v -= MOD; return *this;} n     ModInt& operator -= (const ModInt &other) {v -= other.v; if (v < 0) v += MOD; return *this;} n     ModInt& operator *= (const ModInt &other) {v = v * other.v % MOD; return *this;} n     ModInt& operator /= (const ModInt &other) {return *this *= inverse(other);} n     bool operator == (const ModInt &other) const {return v == other.v;} n     bool operator != (const ModInt &other) const {return v != other.v;} n     friend ModInt operator + (ModInt a, const ModInt &b) {return a += b;} n     friend ModInt operator - (ModInt a, const ModInt &b) {return a -= b;} n     friend ModInt operator * (ModInt a, const ModInt &b) {return a *= b;} n     friend ModInt operator / (ModInt a, const ModInt &b) {return a /= b;} n     friend ModInt operator - (const ModInt &a) {return 0 - a;} n     friend ModInt power(ModInt a, long long b) {ModInt ret(1); while (b > 0) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;} n     friend ModInt inverse(ModInt a) {return power(a, MOD - 2);} n     friend istream& operator >> (istream &is, ModInt &m) {is >> m.v; m.v = (-MOD < m.v && m.v < MOD) ? m.v : m.v % MOD; if (m.v < 0) m.v += MOD; return is;} n     friend ostream& operator << (ostream &os, const ModInt &m) {return os << m.v;} n }; n typedef ModInt<998244353> M; n  n int main() { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n  n     int n, m; n     cin >> n >> m; n     vector<vector<int>> d(n, vector<int>(m)); n     for (int i=0; i<n; i++) n         for (int j=0; j<m; j++) n             cin >> d[i][j]; n  n     M fact = 1; n     for (int i=1; i<=n; i++) n         fact *= i; n  n     M ret = m * fact; n     for (int j=0; j<m; j++) { n         vector<int> cnt(n + 1); n         for (int i=0; i<n; i++) n             cnt[n - d[i][j] + 1]++; n         M cur = 1; n         int tot = 0; n         for (int i=0; i<n; i++) { n             tot += cnt[i]; n             cur *= tot--; n         } n         ret -= cur; n     } n     cout << ret / fact <<   n ; n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool setmax(T &_a, T _b) { n   if (_a < _b) { n     _a = _b; n     return true; n   } n   return false; n } n inline void Boost() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n int main() { n   int n, k; n   cin >> n >> k; n   map<string, pair<vector<int>, vector<int> > > m1; n   map<string, vector<int> > m2; n   for (int i = 0; i < n; i++) { n     string s, rs; n     int val; n     cin >> s >> val; n     rs = s; n     reverse(rs.begin(), rs.end()); n     if (s == rs) { n       auto it = m2.find(s); n       if (it == m2.end()) n         m2.insert({s, {val}}); n       else n         it->second.push_back(val); n     } else { n       auto it = m1.find(s); n       if (it != m1.end()) { n         it->second.first.push_back(val); n       } else { n         it = m1.find(rs); n         if (it != m1.end()) n           it->second.second.push_back(val); n         else n           m1.insert({s, {{val}, {}}}); n       } n     } n   } n   int ans = 0, bonus = 0; n   for (auto &it : m1) { n     auto &v1 = it.second.first; n     auto &v2 = it.second.second; n     sort(v1.begin(), v1.end()); n     sort(v2.begin(), v2.end()); n     while (!v1.empty() && !v2.empty()) { n       int cur = v1.back() + v2.back(); n       if (cur < 0) break; n       ans += cur; n       v1.pop_back(); n       v2.pop_back(); n     } n   } n   for (auto &it : m2) { n     auto &v = it.second; n     sort(v.begin(), v.end()); n     while (v.size() >= 2 && v[v.size() - 2] > 0) { n       ans += v[v.size() - 2] + v[v.size() - 1]; n       v.pop_back(); n       v.pop_back(); n     } n     if (v.size() >= 2 && v[v.size() - 2] + v[v.size() - 1] > 0) { n       assert(v[v.size() - 2] <= 0); n       ans += v[v.size() - 2] + v[v.size() - 1]; n       setmax(bonus, -v[v.size() - 2]); n     } else if (v.size() >= 1 && v.back() > 0) n       setmax(bonus, v.back()); n   } n   cout << ans + bonus; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, u, v, a[200005], el, ans; n vector<int> adj[200005]; n queue<int> q; n bool vis[200005]; n int depth[200005], depthn[200005]; n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> k; n   for (int i = 1; i <= k; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i <= m; i++) { n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) { n     vis[i] = 0; n   } n   q.push(1); n   vis[1] = 1; n   depth[1] = 0; n   int node; n   while (!q.empty()) { n     node = q.front(); n     q.pop(); n     for (int x : adj[node]) { n       if (vis[x]) continue; n       vis[x] = 1; n       depth[x] = depth[node] + 1; n       q.push(x); n     } n   } n   for (int i = 1; i <= n; i++) { n     vis[i] = 0; n   } n   q.push(n); n   vis[n] = 1; n   depthn[n] = 0; n   while (!q.empty()) { n     node = q.front(); n     q.pop(); n     for (int x : adj[node]) { n       if (vis[x]) continue; n       vis[x] = 1; n       depthn[x] = depthn[node] + 1; n       q.push(x); n     } n   } n   vector<pair<int, int> > v; n   int cek = 0, ee = 0, cekn = 0, een = 0; n   for (int i = 1; i <= k; i++) { n     if (depth[a[i]] >= depth[n]) { n       cek++; n       ee = a[i]; n     } n     if (depthn[a[i]] >= depthn[1]) { n       cekn++; n       een = a[i]; n     } n     if (cek == 2 || cekn == 2) { n       cout << depth[n] << endl; n       return 0; n     } n     if (ee != a[i] && een != a[i]) v.push_back(make_pair(depth[a[i]], a[i])); n   } n   sort(v.begin(), v.end()); n   int minn = 1e9; n   for (int i = 1; i < v.size(); i++) { n     minn = min(minn, v[i].first - v[i - 1].first); n   } n   if (minn < 1e9) ans = depth[n] - max(0, minn - 1); n   if (cek == 0 && cekn == 0) { n     cout << ans << endl; n     return 0; n   } n   if (cek == 1 && cekn == 0) { n     cout << max(ans, min(depth[n], v[k - 2].first + 1 + depthn[ee])) << endl; n   } else if (cek == 0 && cekn == 1) { n     cout << max(ans, min(depth[n], depthn[v[0].second] + 1 + depth[een])) n          << endl; n   } else { n     ans = max(ans, min(depth[een] + 1 + depthn[ee], depth[n])); n     if (v.size() > 0) { n       ans = max(ans, min(depth[n], v[k - 3].first + 1 + depthn[ee])); n       ans = max(ans, min(depth[n], depthn[v[0].second] + 1 + depth[een])); n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n struct BIT { n   long long val[500005]; n   void add(int x, int w) { n     for (; x <= m; x += x & -x) val[x] += w; n     return; n   } n   long long sum(int x) { n     long long sum = 0; n     for (; x; x -= x & -x) sum += val[x]; n     return sum; n   } n   long long query(int l, int r) { return sum(r) - sum(l - 1); } n } T; n struct DSU { n   int fa[500005 << 1], val[500005 << 1]; n   void init() { n     for (int i = 1; i <= n * 2; ++i) fa[i] = i, val[i] = 1; n     return; n   } n   int find(int x) { n     if (fa[x] == x) return x; n     int p = find(fa[x]); n     val[x] = max(val[x], val[fa[x]]); n     return fa[x] = p; n   } n   void merge(int x, int y) { n     fa[find(x)] = find(y); n     return; n   } n } D; n int fa[500005], sz[500005], id[500005]; n long long ans[500005]; n vector<pair<int, int> > op[500005], son[500005], qu[500005]; n int read(); n void dfs(int); n int main() { n   n = read(), m = read(); n   D.init(); n   int cnt = n; n   for (int i = 1; i <= n; ++i) id[i] = i, sz[i] = 1; n   for (int i = 1; i <= m; ++i) { n     char ch = getchar(); n     int x = read(), y; n     if (ch ==  U ) n       fa[y = read()] = x, son[x].push_back(make_pair(y, i)), sz[x] += sz[y]; n     if (ch ==  M ) { n       y = read(); n       ++cnt; n       D.merge(id[x], cnt); n       D.merge(id[y], cnt); n       id[x] = cnt; n     } n     if (ch ==  A ) op[x].push_back(make_pair(sz[x], i)); n     if (ch ==  Z ) D.val[id[x]] = i; n     if (ch ==  Q ) { n       D.find(x), qu[x].push_back(make_pair(i, D.val[x])); n     } n   } n   memset(ans, -1, sizeof ans); n   for (int i = 1; i <= n; ++i) n     if (!fa[i]) dfs(i); n   for (int i = 1; i <= m; ++i) n     if (ans[i] != -1) printf( %lld n , ans[i]); n   return 0; n } n int read() { n   int x = 0; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     ; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48); n   return x; n } n void dfs(int u) { n   int sz1 = son[u].size(), sz2 = op[u].size(), pos = sz2 - 1; n   for (int i = sz1 - 1; ~i; --i) { n     int tm = son[u][i].second, v = son[u][i].first; n     while (~pos && op[u][pos].second > tm) n       T.add(op[u][pos].second, op[u][pos].first), --pos; n     dfs(v); n   } n   while (~pos) T.add(op[u][pos].second, op[u][pos].first), --pos; n   int sz3 = qu[u].size(); n   for (int i = 0; i < sz3; ++i) n     ans[qu[u][i].first] = T.query(qu[u][i].second, qu[u][i].first); n   for (int i = 0; i < sz2; ++i) T.add(op[u][i].second, -op[u][i].first); n   return; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, max, min, r, k, i, flag = 0, ans = 0, temp = 0, pos = 0, neg = 0, n                             cnt = 0, d = 0, size; n   char s[109]; n   for (int j = 0; j < 100; j++) { n     cin.getline(s, 105); n     if (strlen(s) == 0) { n       break; n     } n     if (s[0] ==  + ) temp++; n     if (s[0] ==  - ) temp--; n     if (s[0] !=  +  && s[0] !=  - ) { n       i = 0; n       cnt = 0; n       while (s[i] !=  : ) { n         cnt++; n         i++; n       } n       k = (strlen(s) - cnt - 1); n       ans = ans + temp * k; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class CElections { n  public: n   struct person { n     long long p, c; n   }; n   int n, m; n   person arr[3100]; n   vector<long long> parties[3100]; n   long long sol(int votes) { n     int total_votes_needed = votes - (int)parties[0].size(); n     vector<long long> rem; n     long long ans = 0; n     for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m)); n          i += 1 - 2 * ((0) > (m))) { n       if (!i) continue; n       int num = (int)parties[i].size() - votes + 1; n       if (num > 0) { n         total_votes_needed -= num; n         for (__typeof(num) j = (0) - ((0) > (num)); j != (num) - ((0) > (num)); n              j += 1 - 2 * ((0) > (num))) n           ans += parties[i][j]; n       } n       for (int j = max(num, 0); j < parties[i].size(); j++) n         rem.push_back(parties[i][j]); n     } n     if (total_votes_needed > 0) { n       nth_element(rem.begin(), rem.begin() + total_votes_needed, rem.end()); n       for (__typeof(total_votes_needed) i = (0) - ((0) > (total_votes_needed)); n            i != (total_votes_needed) - ((0) > (total_votes_needed)); n            i += 1 - 2 * ((0) > (total_votes_needed))) n         ans += rem[i]; n     } n     return ans; n   } n   void solve(std::istream &in, std::ostream &out) { n     in >> n >> m; n     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n          i += 1 - 2 * ((0) > (n))) n       in >> arr[i].p >> arr[i].c, arr[i].p--, n           parties[arr[i].p].push_back(arr[i].c); n     sort(arr, arr + n, [](person a, person b) { return a.c < b.c; }); n     for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m)); n          i += 1 - 2 * ((0) > (m))) n       sort(parties[i].begin(), parties[i].end()); n     int low = max(1, (int)parties[0].size()), high = n; n     while (low < high) { n       int mid = (low + high) / 2; n       if (sol(mid) < sol(mid + 1)) { n         high = mid; n       } else { n         low = mid + 1; n       } n     } n     long long ans = sol(low); n     out << ans <<   n ; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   CElections solver; n   std::istream &in(std::cin); n   std::ostream &out(std::cout); n   solver.solve(in, out); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[int(1e2) + 10][int(1e2) + 10]; n vector<pair<int, int> > com[int(1e2) + 10]; n int n, m, s, e; n int ans[int(1e2) + 10], tt[int(1e2) + 10]; n bool mark[int(1e2) + 10]; n int dfs(int v, int tail) { n   if (v == tail) return ans[v]; n   if (mark[v]) return tt[v]; n   mark[v] = true; n   tt[v] = 0; n   for (int i = 1; i <= n; i++) { n     if (dp[v][i] + dp[i][tail] == dp[v][tail] && dp[v][i] == 1) { n       tt[v] = max(tt[v], dfs(i, tail)); n     } n     tt[v] = min(ans[v], tt[v]); n   } n   return tt[v]; n } n int main() { n   std::ios::sync_with_stdio(false); n   for (int i = 0; i < int(1e2) + 10; i++) n     fill(dp[i], dp[i] + int(1e2) + 10, int(1e9)), dp[i][i] = 0; n   fill(ans, ans + int(1e2) + 10, 1000); n   cin >> n >> m >> s >> e; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     dp[a][b] = 1; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       for (int k = 1; k <= n; k++) n         dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]); n   if (dp[s][e] >= int(1e9)) return cout << -1, 0; n   int q; n   cin >> q; n   for (int l = 1; l <= q; l++) { n     int a, b; n     cin >> a >> b; n     if (dp[a][b] >= int(1e9)) continue; n     for (int i = 1; i <= n; i++) { n       if (dp[a][b] == dp[a][i] + dp[i][b]) { n         bool flag = false; n         for (int j = 1; j <= n; j++) { n           if (j != i && dp[a][i] == dp[a][j] && dp[i][b] == dp[j][b]) { n             flag = 1; n             break; n           } n         } n         if (!flag) { n           com[l].push_back({dp[a][i], i}); n         } n       } n     } n   } n   for (int i = 1; i <= q; i++) sort(com[i].begin(), com[i].end()); n   fill(ans, ans + int(1e2) + 10, 500); n   fill(tt, tt + int(1e2) + 10, 500); n   ans[e] = 0; n   for (int c = 0; c <= 500; c++) { n     for (int i = 1; i <= q; i++) { n       fill(mark, mark + int(1e2) + 10, false); n       for (pair<int, int> b : com[i]) { n         int temp = dfs(b.second, com[i][com[i].size() - 1].second) + 1; n         ans[b.second] = min(ans[b.second], temp); n       } n     } n   } n   cout << (ans[s] > 200 ? -1 : ans[s]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, b, mn1 = 1000000, mn2 = 0, temp; n   cin >> n >> m >> b; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     mn1 = min(mn1, x); n   } n   for (int i = 0; i < m; i++) { n     int x; n     cin >> x; n     mn2 = max(mn2, x); n   } n   if (mn1 < mn2) { n     temp = b / mn1; n     b -= mn1 * temp; n     b += temp * mn2; n   } n   cout << b <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k, rm, fr = 1, l, r, li = 0, ri = 0, c = 0; n   cin >> n >> m >> k; n   if (n == 1) { n     cout << m << endl; n     return 0; n   } n   l = k - 1; n   r = n - k; n   rm = m - n; n   while (1) { n     if (c + li + ri + 1 <= rm) { n       c += (li + ri + 1); n       fr++; n     } else n       break; n     if (l > li) li++; n     if (r > ri) ri++; n   } n   cout << fr << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k; n   cin >> n >> k; n   long long int arr[n]; n   map<long long int, bool> mp; n   deque<long long int> dq; n   for (long long int i = 0; i < n; i++) { n     cin >> arr[i]; n     mp[arr[i]] = false; n   } n   for (long long int i = 0; i < n; i++) { n     if (!mp[arr[i]]) { n       mp[arr[i]] = true; n       if (dq.size() == k) { n         mp[dq.back()] = false; n         dq.pop_back(); n       } n       dq.push_front(arr[i]); n     } n   } n   cout << dq.size() << endl; n   for (auto x : dq) { n     cout << x <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using vi = vector<int>; n using pi = pair<int, int>; n int a, b, p; n string second; n void solve() { n   cin >> a >> b >> p >> second; n   int n = (int)(second).size(); n   ll t = 0; n   for (int i = 0; i < n;) { n     int c = 0; n     t += second[i] ==  A  ? a : b; n     while (i < n && second[i] == second[i - c]) { n       ++c; n       ++i; n     } n   } n   if (second[n - 1] != second[n - 2]) t -= second[n - 1] ==  A  ? a : b; n   int i = 0; n   while (t > p && i < n) { n     t -= second[i] ==  A  ? a : b; n     int c = 0; n     while (i < n && second[i] == second[i - c]) { n       ++c; n       ++i; n     } n   } n   cout << min(n, i + 1) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int mod = 1e9 + 7; n vector<long long int> dp(2e5 + 1, 1); n int main() { n   long long int t, q = 1, n, k; n   ; n   while (q--) { n     for (long long int i = 1; i < 2e5 + 1; i++) n       dp[i] = ((dp[i - 1] % 998244353) * 10) % 998244353; n     cin >> n; n     for (int i = 1; i < n; i++) { n       long long int ans = 0; n       ans = 2 * 10 * 9 * dp[n - i - 1]; n       ans %= 998244353; n       ans += (n - i - 1) * 10 * 9 * 9 * dp[n - i - 2]; n       ans %= 998244353; n       cout << ans <<    ; n     } n     cout <<  10 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T max(T a, T b, T c) { n   return max(a, max(b, c)); n } n int nextInt() { n   int x = 0, p = 1; n   char c; n   do { n     c = getchar(); n   } while (c <= 32); n   if (c ==  - ) { n     p = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * p; n } n const int max_len = 100500, max_alpha = 26; n int t[max_len][max_alpha]; n int szT; n int newT() { return ++szT; } n int n, k, root; n char s[max_len]; n bool win[max_len], lose[max_len]; n void addTrie(char* s) { n   int len = strlen(s); n   int v = root; n   for (int i = 0; i < len; i++) { n     int c = s[i] -  a ; n     if (t[v][c] == 0) t[v][c] = newT(); n     v = t[v][c]; n   } n } n void dfs(int v) { n   win[v] = false; n   lose[v] = false; n   bool isLeaf = true; n   for (int i = 0; i < max_alpha; i++) { n     if (t[v][i] != 0) { n       isLeaf = false; n       int to = t[v][i]; n       dfs(to); n       win[v] |= !win[to]; n       lose[v] |= !lose[to]; n     } n   } n   if (isLeaf) { n     lose[v] = true; n   } n } n void answer(bool res) { n   puts(res ?  First  :  Second ); n   exit(0); n } n int main() { n   n = nextInt(); n   k = nextInt(); n   root = newT(); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s); n     addTrie(s); n   } n   dfs(root); n   if (k == 1) n     answer(win[root]); n   else if (!win[root]) n     answer(win[root]); n   else if (lose[root]) n     answer(win[root]); n   else if (k % 2 == 1) n     answer(win[root]); n   else n     answer(!win[root]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   long long result = n / 2; n   if (n & 1) { n     result -= n; n   } n   cout << result << endl; n   return 0; n } n


#include <bits/stdc++.h> n long long n, k, l, m, ans; n struct mat { n   long long a[3][3]; n } A, B; n inline mat operator*(mat x, mat y) { n   mat c; n   memset(c.a, 0, sizeof c.a); n   for (int k = (0), __ = (2); k < __; ++k) n     for (int i = (0), __ = (2); i < __; ++i) n       for (int j = (0), __ = (2); j < __; ++j) n         (c.a[i][j] += (x.a[i][k] * y.a[k][j]) % m) %= m; n   return c; n } n inline mat operator^(mat a, long long y) { n   mat c; n   for (int i = (0), __ = (2); i < __; ++i) n     for (int j = (0), __ = (2); j < __; ++j) c.a[i][j] = (i == j); n   while (y) { n     if (y & 1) c = c * a; n     a = a * a; n     y >>= 1; n   } n   return c; n } n long long Pow(long long x) { n   long long s = 1, c = 2; n   while (x) { n     if (x & 1) s = (s * c) % m; n     c = c * c % m; n     x >>= 1; n   } n   return s; n } n int main() { n   mat p, x; n   p.a[0][0] = 0; n   p.a[0][1] = 1; n   p.a[1][0] = 1; n   p.a[1][1] = 1; n   x.a[0][0] = 1; n   x.a[0][1] = 2; n   x.a[1][0] = 0; n   x.a[1][1] = 0; n   std::cin >> n >> k >> l >> m; n   ans = 0; n   if (l == 64 || (1ull << l) > k) { n     ++ans; n     p = p ^ n; n     x = x * p; n     long long t1 = x.a[0][0]; n     long long t2 = (m + Pow(n) - t1) % m; n     for (int i = (0), __ = (l); i < __; ++i) { n       if (k & (1ull << i)) n         ans = ans * t2 % m; n       else n         ans = ans * t1 % m; n     } n   } n   std::cout << ans % m << std::endl; n   return 0; n } n


// Author : deetav n // Happy stalking ! ^_^ n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #include <bits/stdc++.h> n using namespace std; n #define endl   n  n  n int main() n { n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr); n     int64_t t=1; n     cin>>t; n     while(t--) n     { n         int n,x;cin>>n>>x; n         vector <int> lol,v; n         for(int i=0,z;i<n;i++){ n             cin>>z; n             lol.push_back(z);v.push_back(z); n         } n         sort(lol.begin(),lol.end()); n         if(lol==v){ n             cout<<0<<endl;continue; n         } n         bool sorted=false; n        for(int i=0;i<n && !is_sorted(v.begin(),v.end());i++){ n            for(int ii=0;ii<n;ii++){ n                if(v[ii]>x){ n                    swap(x,v[ii]);break; n                } n            } n            if(is_sorted(v.begin(),v.end())){ n                sorted=true; n                cout<<i+1<<endl;break; n            } n        } n        if(!sorted){ n            cout<<-1<<endl; n        } n     } n     return EXIT_SUCCESS; n }


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 5e5; n struct team { n   long long t, w, id; n } a[maxn]; n priority_queue<long long> Qf; n priority_queue<pair<long long, long long> > Qb; n long long n, i, j, x, y, z, ans, T, W; n bool cmpw(team a, team b) { return a.t > b.t || (a.t == b.t && a.id < b.id); } n void solve() { n   if (ans == 1) return; n   for (;;) { n     long long u = -Qf.top() + 1; n     Qf.pop(); n     if (u > T) return; n     T -= u; n     while (!Qb.empty() && Qb.top().first > T) { n       pair<long long, long long> u = Qb.top(); n       Qb.pop(); n       Qf.push(u.first - u.second); n     } n     long long x = Qf.size() + 1; n     ans = min(ans, x); n     if (ans == 1) return; n   } n } n int main() { n   scanf( %lld , &n); n   for (i = 1; i <= n; i++) { n     scanf( %lld%lld , &x, &y); n     a[i] = (team){x, y, i}; n   } n   sort(a + 1, a + n + 1, cmpw); n   for (i = 1; i <= n; i++) n     if (a[i].id == 1) { n       ans = i; n       T = a[i].t; n       W = a[i].w; n       break; n     } n   for (i = 1; i < ans; i++) Qf.push(a[i].t - a[i].w); n   for (i = ans + 1; i <= n; i++) Qb.push(make_pair(a[i].t, a[i].w)); n   solve(); n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (!b) return a; n   return gcd(b, a % b); n } n char str[5]; n int main() { n   int t = 0, x = 0; n   scanf( %d , &t); n   for (int i = 0; i < t; i++) { n     cin >> str; n     if (strcmp(str,  ++X ) == 0 || strcmp(str,  X++ ) == 0) { n       x++; n     } else n       x--; n   } n   printf( %d , x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct keycompare { n   bool operator()(const pair<long long, long long>& v, const long long& k) { n     return (v.first < k); n   } n   bool operator()(const long long& k, const pair<long long, long long>& v) { n     return (k < v.first); n   } n }; n long long mod1 = 998244353, mod2 = 1000000007, limit = 9223372036854775807; n long double pi = 3.1415926535897932; n long long modpow(long long x, long long n, long long m) { n   if (x > m) { n     x %= m; n   } n   if (n == 0) return 1 % m; n   long long u = modpow(x, n / 2, m); n   u = (u * u) % m; n   if (n % 2 == 1) u = (u * x) % m; n   return u; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool isprime(long long n) { n   if (n == 2) return true; n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) return false; n   } n   return true; n } n long long power(long long x, long long n) { n   long long x_n = 1; n   for (long long i = 0; i < n; i++) { n     x_n *= x; n   } n   return x_n; n } n long double arr[100005]; n int n; n long double l; n long double time1(long double mid) { n   long double last = 1; n   long double timer = 0; n   for (int i = 1; i <= n + 1; i++) { n     if (arr[i] < mid) { n       timer += (arr[i] - arr[i - 1]) / last; n     } else { n       timer += (mid - arr[i - 1]) / last; n       break; n     } n     last++; n   } n   return timer; n } n long double time2(long double mid) { n   long double last = 1; n   long double timer = 0; n   for (int i = n; i >= 0; i--) { n     if (arr[i] > mid) { n       timer += (arr[i + 1] - arr[i]) / last; n     } else { n       timer += (arr[i + 1] - mid) / last; n       break; n     } n     last++; n   } n   return timer; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> l; n     arr[0] = 0; n     arr[n + 1] = l; n     for (int i = 1; i <= n; i++) { n       cin >> arr[i]; n     } n     long double left = 0, right = l; n     while (abs(left - right) > 1e-9) { n       long double mid = (left + right) / 2; n       if (time1(mid) < time2(mid)) { n         left = mid; n       } else { n         right = mid; n       } n     } n     cout << setprecision(15) << time1(left) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 2e9; n const int N = 1e6; n int n; n string s, x =  BGR ; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> s; n   int k = oo; n   string ans; n   do { n     int cnt = 0; n     string t = s; n     for (int i = 0; i < n; i++) n       if (t[i] != x[i % 3]) { n         cnt++; n         t[i] = x[i % 3]; n       } n     if (cnt < k) { n       k = cnt; n       ans = t; n     } n   } while (next_permutation(x.begin(), x.end())); n   cout << k <<   n  << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct ad { n   int l, r, i; n   bool operator<(const ad a) const { n     if (l != a.l) return l < a.l; n     return r > a.r; n   } n }; n const int INF = 1000000000; n const int MAXN = 200005; n const int SZ = 1 << 18; n int N, M, A, B; n long long res, resi, resj, C; n pair<int, int> arr[2 * SZ]; n ad S[MAXN]; n vector<ad> T; n set<pair<int, int> > Q, R; n void build() { n   for (int i = SZ - 1; i > 0; i--) { n     arr[i] = max(arr[2 * i], arr[2 * i + 1]); n   } n } n inline pair<int, int> rmq(int l, int r) { n   l += SZ, r += SZ + 1; n   pair<int, int> res(0, 0); n   for (; l < r; l /= 2, r /= 2) { n     if (l & 1) res = max(res, arr[l++]); n     if (r & 1) res = max(res, arr[--r]); n   } n   return res; n } n inline long long calc(ad &a, int A, int B) { n   if (a.l > B || a.r < A) return 0; n   return min(a.r, B) - max(a.l, A); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> N >> M; n   for (int i = 0; i < N; i++) { n     cin >> S[i].l >> S[i].r; n     S[i].i = i; n   } n   sort(S, S + N); n   for (int i = 0; i < N; i++) { n     if (i > 0 && T.back().r >= S[i].r) n       continue; n     else n       T.push_back(S[i]); n   } n   for (int i = 0; i < T.size(); i++) { n     arr[SZ + i] = pair<int, int>(T[i].r - T[i].l, i); n     Q.insert(pair<int, int>(T[i].l, i)); n     R.insert(pair<int, int>(T[i].r, i)); n   } n   build(); n   for (int i = 0; i < M; i++) { n     cin >> A >> B >> C; n     set<pair<int, int> >::iterator it, jt; n     it = Q.upper_bound(pair<int, int>(A, INF)); n     jt = R.lower_bound(pair<int, int>(B, -INF)); n     if (it != Q.begin()) { n       it--; n       long long k = calc(T[it->second], A, B) * C; n       if (k > res) { n         res = k; n         resi = T[it->second].i + 1; n         resj = i + 1; n       } n     } n     if (jt != R.end()) { n       long long k = calc(T[jt->second], A, B) * C; n       if (k > res) { n         res = k; n         resi = T[jt->second].i + 1; n         resj = i + 1; n       } n     } n     it = Q.lower_bound(pair<int, int>(A, -INF)); n     jt = R.upper_bound(pair<int, int>(B, INF)); n     if (it != Q.end() && jt != R.begin()) { n       jt--; n       if (it->second <= jt->second) { n         pair<int, int> p = rmq(it->second, jt->second); n         if (p.first * C > res) { n           res = p.first * C; n           resi = T[p.second].i + 1; n           resj = i + 1; n         } n       } n     } n   } n   cout << res <<   n ; n   if (res > 0) { n     cout << resi <<     << resj <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int fastio() { n   ios_base::sync_with_stdio(false); n   cout << fixed << setprecision(10); n   cin.tie(nullptr); n   return 0; n } n int __fastio = fastio(); n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void solve() { n   int n, m; n   cin >> n >> m; n   vector<int> res(n + 1); n   set<int> alive; n   for (int i = 1; i <= n; i++) alive.insert(i); n   vector<tuple<int, int, int>> events; n   for (int i = 0; i < m; i++) { n     int l, r, x; n     cin >> l >> r >> x; n     events.emplace_back(l, r, x); n   } n   for (auto [l, r, x] : events) { n     auto lb = alive.lower_bound(l); n     vector<int> killed; n     while (lb != alive.end() && *lb <= r) { n       killed.push_back(*lb); n       ++lb; n     } n     for (auto &k : killed) { n       if (k != x) { n         res[k] = x; n         alive.erase(k); n       } n     } n   } n   for (int i = 1; i <= n; i++) cout << res[i] <<    ; n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n const long long N = 2e5 + 5, MOD = 1e9 + 7; n using namespace std; n int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; n int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; n long long n, m, a[N], cnt, ans; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> a[i], a[i] += a[i - 1]; n   for (long long i = 1, x; i <= m; i++) { n     cin >> x; n     long long lb = lower_bound(a + 1, a + n + 1, x) - a; n     cout << lb <<     << x - a[lb - 1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n enum { MAXN = 100010 }; n pair<long long, long long> d[MAXN]; n int x[MAXN], t[MAXN]; n long long minv[MAXN]; n int solveB(int n) { n   int mans = 0; n   for (int i = 0; i < n; i++) { n     int f = upper_bound(minv, minv + mans, d[i].second) - minv + 1; n     if (f > mans) { n       minv[mans] = d[i].second; n       mans = f; n     } else n       minv[f - 1] = min(minv[f - 1], d[i].second); n   } n   return mans; n } n int solveA(int n) { n   int mans = 1; n   minv[0] = 0; n   for (int i = 0; i < n; i++) n     if (d[i].first >= 0) { n       int f = upper_bound(minv, minv + mans, d[i].second) - minv + 1; n       if (f > 1) { n         if (f > mans) { n           minv[mans] = d[i].second; n           mans = f; n         } else n           minv[f - 1] = min(minv[f - 1], d[i].second); n       } n     } n   return mans - 1; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &t[i]); n   int v; n   scanf( %d , &v); n   for (int i = 0; i < n; i++) n     d[i] = make_pair(x[i] + (long long)t[i] * v, -x[i] + (long long)t[i] * v); n   sort(d, d + n); n   int ansA = solveA(n); n   int ansB = solveB(n); n   printf( %d n%d n , ansA, ansB); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   long long arr[n]; n   for (long long i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   if (n == 1) { n     cout << 1 <<     << 1 <<   n ; n     cout << 1 <<   n ; n     cout << 1 <<     << 1 <<   n ; n     cout << 1 <<   n ; n     cout << 1 <<     << 1 <<   n ; n     cout << -(arr[0] + 2) <<   n ; n     return 0; n   } n   if (n == 2) { n     cout <<  1  n          <<     n          <<  1  n          <<   n ; n     cout << n - arr[0] <<   n ; n     cout << 2 <<     << 2 <<   n ; n     cout << n - arr[1] <<   n ; n     cout << 1 <<     << 2 <<   n ; n     cout << -n <<     << -n <<   n ; n     return 0; n   } n   long long dist[n]; n   for (long long i = 0; i < n; ++i) { n     dist[i] = n - (arr[i] % n); n     dist[i] %= n; n   } n   vector<long long> vec; n   for (long long i = 0; i < n - 1; ++i) { n     long long X = ((n - 1) - dist[i]) % (n - 1); n     X %= (n - 1); n     X += n - 1; n     X %= (n - 1); n     long long temp = (dist[i] + n * X); n     vec.push_back(temp); n     assert(temp >= -1000000000000000000 && temp <= 1000000000000000000); n     assert(temp % (n - 1) == 0); n   } n   cout <<  1   << n - 1 <<   n ; n   for (long long i = 0; i < vec.size(); ++i) { n     cout << vec[i] <<    ; n     arr[i] = arr[i] + vec[i]; n     assert(arr[i] % n == 0); n   } n   cout <<   n ; n   cout << n <<     << n <<   n ; n   cout << dist[n - 1] <<   n ; n   arr[n - 1] += dist[n - 1]; n   assert(arr[n - 1] % n == 0); n   cout << 1 <<     << n <<   n ; n   for (long long i = 0; i < n; ++i) { n     cout << -arr[i] <<    ; n     assert(arr[i] % n == 0); n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   int a; n   for (int i = 0; i < t; i++) { n     int n, m; n     cin >> n >> m; n     if (n == 1 && m == 1) { n       cout << 1 << endl; n     } else if ((n == 1 && m != 1) || (m == 1 && n != 1)) { n       if ((n * m) % 2 == 0) { n         a = (n * m) / 2; n         cout << a << endl; n       } else { n         a = (n * m) / 2; n         cout << a + 1 << endl; n       } n     } n     if ((n * m) % 2 == 1 && n != 1 && m != 1) { n       a = (n * m) / 2; n       a++; n       cout << a << endl; n     } n     if ((n * m) % 2 == 0 && n != 1 && m != 1) { n       a = (n * m) / 2; n       cout << a << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n const int TMXN = 1e6 * 4 + 1; n const int INF = 1e9 + 7; n const long long INFL = 1e18; n int n, k; n char a[N]; n int mink = INF; n int pref[N]; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (!(a[i] - 48)) { n       pref[i] = pref[i - 1] + 1; n     } else { n       pref[i] = pref[i - 1]; n     } n   } n   for (int i = n + 1; i <= N; i++) { n     pref[i] = pref[i - 1]; n   } n   for (int i = 1; i <= n; i++) { n     int l = 0; n     int r = max(n - i, i - 1) + 1; n     if (a[i] ==  0 ) { n       while (r - l > 1) { n         int mid = (r + l) / 2; n         if (pref[i + mid] - pref[max(i - mid - 1, 0)] >= k + 1) { n           r = mid; n         } else { n           l = mid; n         } n       } n       if (pref[i + r] - pref[max(i - r - 1, 0)] >= k + 1) { n         mink = min(mink, r); n       } n       if (pref[i + l] - pref[max(i - l - 1, 0)] >= k + 1) { n         mink = min(mink, l); n       } n     } n   } n   cout << mink; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   int64_t t; n   cin >> t; n   for (int64_t i = 0; i < t; i++) { n     int64_t a, b; n     cin >> a >> b; n     if (a == b) { n       cout << 0 << endl; n       continue; n     } n     int64_t k = abs(b - a); n     int64_t ans = k / 5; n     k %= 5; n     ans += k / 2; n     k %= 2; n     ans += k; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> all[2010]; n int dist(pair<int, int> a, pair<int, int> b) { n   return abs(a.first - b.first) + abs(a.second - b.second); n } n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       all[i].push_back(j); n     } n   } n   for (int q = 0; q < k; q++) { n     int x, y; n     scanf( %d%d , &x, &y); n     int d = sqrt(q); n     pair<int, int> ans(1000000, 1000000); n     for (int j = 0; j <= n && j <= dist(ans, make_pair(x, y)); j++) { n       for (int k = 0; k < 2; k++) { n         int i = x; n         if (k) n           i = min(n, i + j); n         else n           i = max(0, i - j); n         if (all[i].size() == 0) continue; n         int t = lower_bound(all[i].begin(), all[i].end(), y) - all[i].begin(); n         int p1 = all[i][(t == all[i].size() ? t - 1 : t)]; n         int p2 = all[i][(t - 1 == -1 ? t : t - 1)]; n         pair<int, int> now(i, p2); n         if (abs(p1 - y) < abs(p2 - y)) now.second = p1; n         if (dist(make_pair(x, y), ans) > dist(make_pair(x, y), now)) ans = now; n         if (dist(make_pair(x, y), ans) == dist(make_pair(x, y), now) && n             now < ans) n           ans = now; n       } n     } n     printf( %d %d n , ans.first, ans.second); n     all[ans.first].erase( n         lower_bound(all[ans.first].begin(), all[ans.first].end(), ans.second)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, i0, n, m, a[105]; n bool vis[100]; n vector<int> ans; n int main() { n   while (scanf( %d , &n) != EOF) { n     for (i = 0; i < n; i++) scanf( %d , &a[i]); n     sort(a, a + n); n     for (i = 0; i < n; i++) { n       if (a[i] == 0) { n         ans.push_back(a[i]); n         vis[0] = 1; n         break; n       } n     } n     for (i = 0; i < n; i++) { n       if (a[i] < 10 && a[i] != 0) { n         ans.push_back(a[i]); n         vis[1] = 1; n         break; n       } n     } n     for (i = 0; i < n; i++) { n       if (a[i] < 100 && a[i] % 10 == 0 && a[i] >= 10) { n         ans.push_back(a[i]); n         vis[2] = 1; n         break; n       } n     } n     for (i = 0; i < n; i++) { n       if (a[i] == 100) { n         ans.push_back(a[i]); n         vis[3] = 1; n         break; n       } n     } n     if (vis[1] == 0 && vis[2] == 0) { n       for (i = 0; i < n; i++) n         if (a[i] < 100 && a[i] >= 10) { n           ans.push_back(a[i]); n           break; n         } n     } n     printf( %d n , ans.size()); n     for (i = 0; i < ans.size(); i++) { n       printf( %d , ans[i]); n       if (ans.size() - 1 == i) n         printf(  n ); n       else n         printf(   ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   string second; n   cin >> second; n   for (int i = 0; i < (int)n; i++) { n     if (i < n - 2 && second[i] ==  o  && second[i + 1] ==  g  && n         second[i + 2] ==  o ) { n       cout <<  *** ; n       int j = i + 3; n       bool flag = false; n       while (j < n - 1) { n         if (second[j] ==  g  && second[j + 1] ==  o ) { n           flag = true; n           j += 2; n         } else n           break; n       } n       i = j - 1; n     } else { n       cout << second[i]; n     } n   } n } n


#include <bits/stdc++.h> n int f[1000001]; n int main() { n   int n; n   scanf( %d , &n); n   f[0] = 0; n   f[1] = 1; n   f[2] = 1; n   int i, j, k; n   for (i = 3;; i++) { n     f[i] = f[i - 1] + f[i - 2]; n     if (f[i] > 1000000000) break; n   } n   int idx = i; n   int no = 0; n   for (i = 0; i < idx; i++) { n     for (j = i; j < idx; j++) { n       for (k = i; k < idx; k++) { n         if ((long long)f[i] + (long long)f[j] + (long long)f[k] == n) { n           no = 1; n           printf( %d %d %d n , f[i], f[j], f[k]); n           break; n         } n       } n       if (no) break; n     } n     if (no) break; n   } n   if (no == 0) printf( I m too stupid to solve this problem n ); n   scanf(   ); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int n, nn, sz[133333], p; n vector<int> g[133333], V; n void dfs_sz(int x, int par) { n   sz[x] = 1; n   for (int to : g[x]) { n     if (to != par) { n       dfs_sz(to, x); n       sz[x] += sz[to]; n     } n   } n   if (sz[x] == n / 2 || sz[x] == n / 2 + 1) { n     V.push_back(x); n     if (~par) V.push_back(par); n   } n } n int dp[133333]; n int dfs(int x, int par) { n   if (g[x].size() - (par != -1) == 0) { n     dp[x] = 1; n     return dp[x]; n   } n   vector<int> v; n   for (int to : g[x]) { n     if (to != par) { n       dfs(to, x); n       v.push_back(dp[to]); n     } n   } n   sort(v.begin(), v.end()); n   if (v.size() == 1) { n     if (v[0] == 1) { n       dp[x] = -2; n       p = x; n     } else { n       dp[x] = inf; n     } n   } else if (v.size() == 2) { n     if (v[1] < 0) { n       dp[x] = inf; n     } else if (v[0] < 0) { n       if (v[0] + v[1] == 0) n         dp[x] = v[0] - 1; n       else n         dp[x] = inf; n     } else { n       if (v[0] == v[1]) { n         dp[x] = v[0] + 1; n       } n     } n   } else if (v.size() == 3) { n     if (v[0] == v[1] && v[2] == v[1] + 1) { n       dp[x] = -v[2] - 1; n       p = x; n     } else { n       dp[x] = inf; n     } n   } n   return dp[x]; n } n int main() { n   cin >> nn; n   n = (1 << nn) - 2; n   for (int i = 1; i < n; i++) { n     int x, y; n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dfs_sz(1, -1); n   set<int> ans; n   for (int x : V) { n     p = 0; n     dfs(x, -1); n     if (dp[x] == -nn && p) ans.insert(p); n   } n   cout << ans.size() << endl; n   for (int x : ans) { n     cout << x <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, s =   ; n   int b; n   cin >> b; n   for (int i = -1; i < b; i++) { n     getline(cin, a); n     int len = a.length(); n     if (len >= 2 and a.substr(len - 2, 2) ==  po ) { n       s +=  FILIPINO ; n       s +=   n ; n     } else if (len >= 4 and a.substr(len - 4, 4) ==  masu  or n                len >= 4 and a.substr(len - 4, 4) ==  desu ) { n       s +=  JAPANESE ; n       s +=   n ; n     } else if (len >= 5 and a.substr(len - 5, 5) ==  mnida ) { n       s +=  KOREAN ; n       s +=   n ; n     } n   } n   cout << s; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n int type0, type1; n void dfs(int s, bool visited[], vector<int> adj[], int type[], int ctr) { n   if (visited[s]) return; n   visited[s] = true; n   type[s] = ctr; n   if (ctr == 0) n     type0++; n   else n     type1++; n   ctr = (ctr + 1) % 2; n   for (auto u : adj[s]) dfs(u, visited, adj, type, ctr); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     bool visited[n + 1]; n     memset(visited, false, sizeof(visited)); n     vector<int> adj[n + 1]; n     for (int i = 0; i < m; i++) { n       int a, b; n       cin >> a >> b; n       adj[a].push_back(b); n       adj[b].push_back(a); n     } n     int type[n + 1]; n     memset(type, -1, sizeof(type)); n     type0 = 0; n     type1 = 0; n     int ctr = 0; n     for (int i = 1; i <= n; i++) { n       if (!visited[i]) { n         dfs(i, visited, adj, type, ctr); n       } n     } n     if (type0 <= type1) { n       cout << type0 <<   n ; n       for (int i = 1; i <= n; i++) { n         if (type[i] == 0) cout << i <<    ; n       } n     } else { n       cout << type1 <<   n ; n       for (int i = 1; i <= n; i++) { n         if (type[i] == 1) cout << i <<    ; n       } n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:16777216 ) n const double EPS = 1e-7; n double iabs(const double a) { return (a < -EPS) ? -a : a; } n double imin(const double a, const double b) { return (a - b > EPS) ? b : a; } n double imax(const double a, const double b) { return (a - b > EPS) ? a : b; } n template <class I> n I iabs(const I a) { n   return (a < 0) ? -a : a; n } n template <class I> n I imin(const I a, const I b) { n   return (a < b) ? a : b; n } n template <class I> n I imax(const I a, const I b) { n   return (a < b) ? b : a; n } n template <class I> n inline I mod_pow(const I& x, const long long p, const I& m) { n   if (p == 0) return 1; n   I mult = (p & 1) ? x : 1; n   I t = mod_pow(x, p / 2, m) % m; n   return (((mult * t) % m) * t) % m; n } n template <class T> n inline T ipow(const T& x, const long long p) { n   if (p == 0) return 1; n   T mult = (p & 1) ? x : 1; n   T h = ipow(x, p / 2); n   return h * h * mult; n } n unsigned long long gcd(unsigned long long a, unsigned long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n template <int SIZE> n class DSU { n  public: n   int parent[SIZE]; n   int rank[SIZE]; n   int count; n   void clear() { n     for (int i = 0; i < SIZE; i++) { n       this->parent[i] = -1; n       this->rank[i] = 0; n     } n     this->count = 0; n   } n   DSU() { this->clear(); } n   void make(int x) { n     this->parent[x] = x; n     this->rank[x] = 1; n     this->count++; n   } n   bool in_a_set(int x) { return this->parent[x] != -1; } n   int find(int x) { n     if (x == this->parent[x]) return x; n     return this->parent[x] = find(this->parent[x]); n   } n   void combine(int x, int y) { n     x = this->find(x); n     y = this->find(y); n     if (x != y) { n       if (this->rank[x] > this->rank[y]) n         this->parent[x] = y; n       else n         this->parent[y] = x; n     } n   } n }; n class BigInt { n  public: n   const static unsigned int N = 1000; n   const static unsigned int base = 10; n   unsigned int len; n   short sign; n   unsigned int digits[N]; n   BigInt(const BigInt& bi) { n     this->len = bi.len; n     this->sign = bi.sign; n     for (unsigned int i = 0; i < this->len; ++i) (*this)[i] = bi[i]; n   } n   BigInt(long long n) { n     this->len = 0; n     this->sign = (n >= 0) ? 1 : -1; n     this->digits[0] = 0; n     while (n) { n       this->digits[this->len] = n % this->base; n       n /= this->base; n       this->len++; n     } n     if (this->len == 0) this->len = 1; n   } n   BigInt(string s) { n     this->sign = (s[0] ==  - ) ? 1 : -1; n     this->digits[0] = 0; n     if (s[0] ==  - ) s = s.substr(1, s.length() - 1); n     this->len = s.length(); n     for (unsigned int i = 0; i < this->len; i++) n       (*this)[i] = s[this->len - i - 1] -  0 ; n   } n   string toString() const { n     stringstream ss; n     for (int i = this->len - 1; i >= 0; --i) ss << (*this)[i]; n     return ss.str(); n   } n   unsigned int& operator[](const unsigned int i) { return digits[i]; } n   unsigned int operator[](const unsigned int i) const { n     if (i < this->len) return this->digits[i]; n     return 0; n   } n   bool iszero() const { n     if (this->len <= 1 && this->digits[0] == 0) return true; n     return false; n   } n   BigInt& operator=(const BigInt& rval) { n     if (this != &rval) { n       this->len = rval.len; n       this->sign = rval.sign; n       for (unsigned int i = 0; i < this->len; ++i) (*this)[i] = rval[i]; n     } n     return *this; n   } n   BigInt operator+(const BigInt& rhs) const { n     BigInt s(0); n     unsigned long long r = 0, d, i; n     for (i = 0; i < max(this->len, rhs.len); i++) { n       d = (*this)[i] + rhs[i] + r; n       r = d / this->base; n       s[i] = d % this->base; n     } n     s.len = max(this->len, rhs.len); n     if (r) s[s.len++] = r; n     return s; n   } n   BigInt operator+(unsigned long long rhs) const { n     BigInt s(*this); n     unsigned long long r = 0, d, i = 0; n     while (rhs != 0 || r != 0) { n       d = s[i] + (rhs % s.base) + r; n       rhs /= s.base; n       r = d / s.base; n       s[i] = d % s.base; n       i++; n     } n     if (i > s.len) s.len = i; n     return s; n   } n   BigInt operator*(unsigned long long rhs) const { n     if (rhs == 0) return BigInt(0); n     BigInt s(*this); n     unsigned long long r = 0, d, i; n     for (i = 0; i < s.len; ++i) { n       d = s[i] * rhs + r; n       r = d / this->base; n       s[i] = d % this->base; n     } n     while (r) s[s.len++] = r % this->base, r /= this->base; n     return s; n   } n   BigInt operator*(const BigInt& rhs) const { n     BigInt s(0); n     if (rhs.iszero()) return s; n     unsigned long long r, d, i, j, k; n     for (i = 0; i < this->N; i++) s[i] = 0; n     for (i = 0; i < this->len; i++) { n       r = 0; n       for (j = 0, k = i; j < rhs.len; j++, k++) { n         d = (*this)[i] * rhs[j] + r + s[k]; n         r = d / this->base; n         s[k] = d % this->base; n       } n       while (r) s[k++] = r % this->base, r /= this->base; n       if (k > s.len) s.len = k; n     } n     while (s.len > 1 && s[s.len - 1] == 0) s.len--; n     return s; n   } n   unsigned int operator%(unsigned int rhs) { n     BigInt t(*this); n     unsigned long long pow = 1; n     unsigned long long mod = 0; n     for (unsigned int i = 0; i < this->len && pow != 0; i++) { n       mod = (((*this)[i] % rhs) * pow + mod) % rhs; n       pow = (pow * this->base) % rhs; n     } n     return mod; n   } n }; n vector<long long> genprimes(const int n) { n   vector<long long> res; n   res.push_back(2); n   long long m, t, j; n   for (int i = 3; i <= n; i++) { n     j = 0; n     m = res.size(); n     t = (long long)sqrt(i * 1.0) + 1; n     while (j < m && res[j] < t && i % res[j] != 0) j++; n     if (j == m || res[j] >= t) res.push_back(i); n   } n   return res; n } n const unsigned long long N = 1000; n const long long INF = 100000000; n long long n, m, i, j, k, t, d; n int main(int argc, char* argv[]) { n   cin >> n; n   if (n < 3) n     cout <<  -1 n ; n   else { n     for (i = n; i > 0; i--) cout << i <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> l[1000000]; n int main() { n   int n; n   cin >> n; n   int a[n], b[n], c[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     l[a[i]].push_back(i + 1); n   } n   int q = 0; n   for (int i = 0; i < n; i++) { n     int j = a[i]; n     if (a[j - 1] != j) q = 1; n   } n   int m = 1; n   for (int i = 1; i <= n; i++) { n     int z = 0; n     for (std::vector<int>::iterator it = l[i].begin(); it != l[i].end(); ++it) { n       b[*it - 1] = m; n       z = 1; n     } n     if (z == 1) { n       c[m - 1] = i; n       m++; n     } n   } n   if (q == 0) { n     cout << m - 1 << endl; n     for (int i = 0; i < n; i++) { n       cout << b[i] <<    ; n     } n     cout << endl; n     for (int i = 0; i < m - 1; i++) { n       cout << c[i] <<    ; n     } n   } else n     cout <<  -1 ; n } 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 n; n   cin >> n; n   long long mxmx = -1, mnmx = -1; n   while (n--) { n     long long x, y, h, w; n     char c; n     cin >> c; n     if (c ==  + ) { n       cin >> x >> y; n       if (x < y) swap(x, y); n       mxmx = max(mxmx, x); n       mnmx = max(mnmx, y); n     } else { n       cin >> h >> w; n       if (max(h, w) >= mxmx && min(h, w) >= mnmx) n         cout <<  YES  n              <<   n ; n       else n         cout <<  NO  n              <<   n ; n     } 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   } else { n     return gcd(b, a % b); n   } n } n long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); } n void solve() { n   long long n; n   cin >> n; n   vector<long long> arr(n); n   map<long long, vector<long long>> vec; n   for (long long i = 0; i < n; i++) { n     cin >> arr[i]; n     for (long long k = 0; k < 32; k++) { n       if (arr[i] & 1 << k) { n         vec[k].push_back(i); n       } n     } n   } n   long long ans = -1; n   for (auto itr = vec.rbegin(); itr != vec.rend(); itr++) { n     if (itr->second.size() == 1) { n       ans = *itr->second.begin(); n       cout << arr[ans] <<    ; n       break; n     } n   } n   for (long long i = 0; i < n; i++) { n     if (i == ans) { n       continue; n     } n     cout << arr[i] <<    ; n   } n   cout <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin.tie(0); n   cout.tie(0); n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n #define inf 0x3f3f3f3f n #define IOS ios_base::sync_with_stdio(0); cin.tie(0); n #define rep(i, a, n) for(int i = a; i <= n; ++ i) n #define per(i, a, n) for(int i = n; i >= a; -- i) n //#define ONLINE_JUDGE n using namespace std; n typedef long long ll; n const int mod=1e9+7; n template<typename T>void write(T x) n { n     if(x<0) n     { n         putchar( - ); n         x=-x; n     } n     if(x>9) n     { n         write(x/10); n     } n     putchar(x%10+ 0 ); n } n  n template<typename T> void read(T &x) n { n     x = 0;char ch = getchar();ll f = 1; n     while(!isdigit(ch)){if(ch ==  - )f*=-1;ch=getchar();} n     while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f; n } 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/gcd(a,b)*b;}; n ll ksm(ll a,ll n){ n  ll ans=1; n  while(n){ n   if(n&1) ans=(ans*a)%mod; n   a=a*a%mod; n   n>>=1; n  } n  return ans%mod; n } n //============================================================== n #define int ll n const int maxn=1e3+100; n int t,n,k,a[maxn]; n ll cnt[maxn]; n map<int,int>need; n ll f[maxn],finv[maxn]; n void init(){ n  f[0]=1; n  rep(i,1,maxn-1)f[i]=f[i-1]*i%mod; n  finv[maxn-1]=ksm(f[maxn-1],mod-2); n  per(i,0,maxn-2){ n   finv[i]=(finv[i+1]*(i+1))%mod; n  } n } n ll C(ll n,ll k){ n  return (f[n]*finv[n-k]%mod*finv[k]%mod)%mod; n } n  n signed main() n { n  #ifndef ONLINE_JUDGE n  freopen( in.txt , r ,stdin); n  freopen( out.txt , w ,stdout); n  #endif n  //clock_t c1 = clock(); n  //=========================================================== n  read(t); n  init(); n  while(t--){ n   need.clear(); n   read(n),read(k); n   rep(i,1,n) read(a[i]); n   sort(a+1,a+1+n); n   int mx=0; n   ll ans=1; n   per(i,n-k+1,n)mx+=a[i],need[a[i]]++; n   rep(i,1,n)cnt[a[i]]++; n   for(auto x:need){ n    int now=x.first; n    int num=x.second; n    ans=(ans*C(cnt[now],num))%mod; n   } n   write(ans%mod),putchar(  n ); n   fill(cnt,cnt+n+1,0); n  } n  //=========================================================== n  //std::cerr <<  Time:  << clock() - c1 <<  ms  << std::endl; n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, j, n, m, f1, f2, t, k, a, b, x1, x2, w; n long long ans = -1; n vector<long long> vis; n vector<vector<long long>> adj; n long long dfs(long long v) { n   vis[v] = 1; n   long long value = 1; n   for (long long u : adj[v]) { n     if (!vis[u]) { n       value += dfs(u); n     } n   } n   if (value % 2 == 0) ans++; n   return value; n } n int main() { n   t = 1; n   while (t--) { n     cin >> n; n     adj.assign(n + 1, {}); n     vis.assign(n + 1, 0); n     for (i = 1; i < n; i++) { n       cin >> a >> b; n       adj[a].push_back(b); n       adj[b].push_back(a); n     } n     if (n & 1) { n       cout << -1; n       return 0; n     } n     dfs(1); n     cout << ans; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long sum(long long a[], long long n, long long s) { n   for (long long i = 0; i < n; i++) s += a[i]; n   return s; n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n void solve() { n   long double a, b, x, y, z; n   cin >> a >> b; n   x = int((a + b) / (2 * b)); n   y = 2.0 * x; n   z = (1.0 * a + 1.0 * b) / y; n   if (a < b) { n     cout << -1 << endl; n     return; n   } n   cout << setprecision(12) << z << endl; n   return; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long t, T; n   T = 1; n   for (t = 1; t <= T; t++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e3 + 9; n char s[N]; n bool vis[N]; n struct Point { n   long long x, y, id; n   Point(long long _x = 0, long long _y = 0, long long _id = 0) { n     x = _x; n     y = _y; n     id = _id; n   } n   Point operator-(const Point& b) const { return Point(x - b.x, y - b.y); } n } p[N], p0, tem[N]; n long long cross(Point a, Point b) { return a.x * b.y - b.x * a.y; } n bool cmp(Point a, Point b) { return cross(a - p0, b - p0) >= 0; } n int main() { n   int n; n   scanf( %d , &n); n   p0 = Point(10000000000, 10000000000); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld %lld , &p[i].x, &p[i].y); n     p[i].id = i; n     if (p[i].y < p0.y || (p0.y == p[i].y && p[i].x < p0.x)) p0 = p[i]; n   } n   scanf( %s , s); n   vector<int> ans; n   ans.push_back(p0.id); n   vis[p0.id] = 1; n   int sp = 0; n   for (int i = 2; i <= n; ++i, ++sp) { n     int cnt = 0; n     for (int j = 1; j <= n; ++j) { n       if (vis[j]) continue; n       tem[++cnt] = p[j]; n     } n     sort(tem + 1, tem + 1 + cnt, cmp); n     int nex; n     if (s[sp] ==  L ) n       nex = tem[1].id; n     else n       nex = tem[cnt].id; n     ans.push_back(nex); n     vis[nex] = 1; n     p0 = p[nex]; n   } n   for (int i = 0; i < (int)ans.size(); ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans; n int a[100005]; n vector<int> v[100005]; n void solve() { n   int i, j, k, flag = 0, ok, sz, tmp; n   for (i = 1; i <= 500; i++) { n     ok = 1; n     random_shuffle(a + 1, a + n + 1); n     for (j = 1; j <= m; j++) { n       sz = v[a[j]].size(); n       for (k = 0; k < sz; k++) { n         if (j == n) n           tmp = 1; n         else n           tmp = j + 1; n         if (v[a[j]][k] == a[tmp]) { n           ok = 0; n           break; n         } n       } n     } n     if (ok) { n       flag = 1; n       for (j = 1; j <= m; j++) { n         if (j == n) n           tmp = 1; n         else n           tmp = j + 1; n         printf( %d %d n , a[j], a[tmp]); n       } n       break; n     } n   } n   if (!flag) printf( -1 n ); n } n int main() { n   int i, j, l, r; n   while (~scanf( %d%d , &n, &m)) { n     for (i = 1; i <= n; i++) { n       v[i].clear(); n       a[i] = i; n     } n     for (i = 1; i <= m; i++) { n       scanf( %d%d , &l, &r); n       v[l].push_back(r); n       v[r].push_back(l); n     } n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const double PI = 3.14159265359; n int n, k; n long long S; n vector<vector<long long>> dp(25); n vector<long long> fact(20, 1ll); n long long getFactVal(int mask, vector<long long>& vi) { n   long long ans = 0; n   int m = vi.size(); n   for (int i = 0; i < m; i++) { n     if ((1 << i) & mask) { n       if (vi[i] > 19) { n         return S + 1; n       } else { n         ans += fact[vi[i]]; n       } n     } n     if (ans > S) { n       return S + 1; n     } n   } n   return ans; n } n long long getVal(int mask, vector<long long>& vi) { n   long long ans = 0; n   int m = vi.size(); n   for (int i = 0; i < m; i++) { n     if ((1 << i) & mask) { n       ans += vi[i]; n     } n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k >> S; n   vector<long long> v1, v2; n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     if (i < n / 2) n       v1.push_back(x); n     else n       v2.push_back(x); n   } n   fact.push_back(0ll); n   for (int i = 1; i <= 19; i++) { n     fact[i] = fact[i - 1] * i; n   } n   for (int mask2 = 0; mask2 < (1 << v2.size()); mask2++) { n     auto val = getFactVal(mask2, v2); n     if (val <= S) { n       for (int mask1 = 0; mask1 < (1 << v2.size()); mask1++) { n         if (!(mask1 & mask2)) { n           auto val2 = getVal(mask1, v2); n           if (val + val2 <= S) { n             dp[__builtin_popcount(mask2)].push_back(val + val2); n           } n         } n       } n     } n   } n   long long ans = 0; n   for (int i = 0; i < 25; i++) { n     if (dp[i].size()) { n       sort(dp[i].begin(), dp[i].end()); n     } n   } n   for (int mask2 = 0; mask2 < (1 << v1.size()); mask2++) { n     auto val = getFactVal(mask2, v1); n     int k1 = __builtin_popcount(mask2); n     if (val <= S && k1 <= k) { n       for (int mask1 = 0; mask1 < (1 << v1.size()); mask1++) { n         if (!(mask1 & mask2)) { n           auto val2 = getVal(mask1, v1) + val; n           if (val2 <= S) { n             for (int i = 0; i <= min(k - k1, 13); i++) { n               if (dp[i].size()) { n                 ans += upper_bound(dp[i].begin(), dp[i].end(), S - val2) - n                        lower_bound(dp[i].begin(), dp[i].end(), S - val2); n               } n             } n           } n         } n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int count = 0; n   int len = s.size(); n   bool small = false; n   for (int i = 0; i < len; i++) { n     if (s[i] <  a ) { n       count++; n     } n     if (s[0] >=  a ) { n       small = true; n     } n   } n   if (count == len || (count == len - 1 && small)) { n     for (int i = 0; i < len; i++) { n       if (i == 0 && count == len) { n         s[i] = s[i] + 32; n       } else if (i == 0 && small) { n         s[i] = s[i] - 32; n       } else { n         s[i] = s[i] + 32; n       } n     } n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int deep[200000 + 10], to[200000 + 10]; n int len; n string s; n stack<int> tmp; n int best_deep[200000 + 10]; n void dfs(int l, int r, int dep) { n   deep[l] = dep; n   if (l == r - 1) { n     best_deep[l] = dep; n     return; n   } n   int now = l + 1; n   int MAX_ = 0; n   while (now < r - 1) { n     dfs(now, to[now], dep + 1); n     MAX_ = max(MAX_, best_deep[now]); n     now = to[now] + 1; n   } n   best_deep[l] = MAX_; n } n int res[200000 + 10]; n void recover(int l, int r, int dep) { n   if (dep - 1 == best_deep[l] >> 1) { n     for (int i = l; i <= r; ++i) { n       res[i] = 1; n     } n     return; n   } n   if (l == r - 1) { n     return; n   } n   int now = l + 1; n   while (now < r - 1) { n     recover(now, to[now], dep + 1); n     now = to[now] + 1; n   } n } n int main() { n   scanf( %d , &len); n   cin >> s; n   for (int i = 0; i <= len - 1; ++i) { n     if (s[i] ==  ( ) n       tmp.push(i); n     else { n       to[tmp.top()] = i; n       tmp.pop(); n     } n   } n   int now = 0; n   while (now < len - 1) { n     dfs(now, to[now], 1); n     now = to[now] + 1; n   } n   now = 0; n   while (now < len - 1) { n     for (int i = now; i <= to[now]; ++i) { n       best_deep[i] = best_deep[now]; n     } n     now = to[now] + 1; n   } n   now = 0; n   while (now < len - 1) { n     recover(now, to[now], 1); n     now = to[now] + 1; n   } n   for (int i = 0; i <= len - 1; ++i) { n     printf( %d , res[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int R, x1, y1, x2, y2; n   scanf( %d%d%d%d%d , &R, &x1, &y1, &x2, &y2); n   if ((long long)(x2 - x1) * (x2 - x1) + (long long)(y2 - y1) * (y2 - y1) >= n       (long long)R * R) { n     printf( %.12f %.12f %.12f n , (double)x1, (double)y1, (double)R); n   } else if (x1 == x2 && y1 == y2) { n     printf( %.12f %.12f %.12f n , x1 + R / 2.0, (double)y1, R / 2.0); n   } else { n     double L = R + hypot(x2 - x1, y2 - y1); n     L /= 2; n     double dx = x1 - x2, dy = y1 - y2, dl = hypot(dx, dy); n     dx = dx / dl * L + x2; n     dy = dy / dl * L + y2; n     printf( %.12f %.12f %.12f n , dx, dy, L); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n struct node { n   int ou, j1, j2, j3; n } a[10020]; n void setup() { n   int i, j; n   int ou = 2, ji = 1; n   for (i = 1; i <= 10010; i++) { n     while (ou % 3 == 0) ou += 2; n     a[i].ou = ou; n     ou += 2; n     a[i].j1 = ji; n     a[i].j2 = ji + 2; n     a[i].j3 = ji + 4; n     ji += 6; n   } n } n int main() { n   int i, j; n   setup(); n   while (scanf( %d%d , &n, &k) != EOF) { n     printf( %d n , a[n].j3 * k); n     for (i = 1; i <= n; i++) n       printf( %d %d %d %d n , a[i].ou * k, a[i].j1 * k, a[i].j2 * k, n              a[i].j3 * k); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1000000000000000ll; n long long b[230400], h[230400], d[230400], ans, t[230400], n, m; n struct node { n   long long c, e; n } a[230400]; n struct seg { n   long long l, r, val, z; n } s[230400 * 4]; n bool cmp(node u, node v) { n   if (u.c == v.c) return u.e < v.e; n   return u.c < v.c; n } n void build(long long p, long long l, long long r) { n   s[p].l = l; n   s[p].r = r; n   if (l == r) { n     s[p].val = t[l]; n     s[p].z = 0; n     return; n   } n   long long mid = (l + r) >> 1; n   build(p << 1, l, mid); n   build((p << 1) | 1, mid + 1, r); n   s[p].val = min(s[p << 1].val, s[(p << 1) | 1].val); n   s[p].z = 0; n } n void pass(long long p) { n   s[p].val += s[p].z; n   if (s[p].l != s[p].r) s[p << 1].z += s[p].z, s[(p << 1) | 1].z += s[p].z; n   s[p].z = 0; n } n void update(long long p, long long l, long long r, long long w) { n   if (s[p].l > r || s[p].r < l) { n     pass(p); n     return; n   } n   if (s[p].l >= l && s[p].r <= r) { n     s[p].z += w; n     pass(p); n     return; n   } n   pass(p); n   update(p << 1, l, r, w); n   update((p << 1) | 1, l, r, w); n   s[p].val = min(s[p << 1].val, s[(p << 1) | 1].val); n } n long long qry(long long p, long long l, long long r) { n   pass(p); n   if (s[p].l > r || s[p].r < l) return inf; n   if (s[p].l >= l && s[p].r <= r) return s[p].val; n   return min(qry(p << 1, l, r), qry((p << 1) | 1, l, r)); n } n int main() { n   scanf( %d%d , &n, &m); n   for (long long i = 1; i <= n; i++) scanf( %lld , &b[i]); n   d[n] = b[n]; n   for (long long i = n - 1; i; i--) d[i] = max(d[i + 1], b[i]); n   for (long long i = 1; i <= n; i++) t[i] = t[i - 1] + b[i]; n   build(1, 1, n); n   for (long long i = 0; i < m; i++) scanf( %lld , &a[i].e); n   for (long long i = 0; i < m; i++) scanf( %lld , &a[i].c); n   sort(a, a + m, cmp); n   for (long long i = 0; i < m; i++) { n     if (d[1] < a[i].e) continue; n     long long lf, rt, mid; n     lf = 0; n     rt = n + 1; n     while (rt - lf > 1) { n       mid = (lf + rt) >> 1; n       if (d[mid] < a[i].e) n         rt = mid; n       else n         lf = mid; n     } n     if (qry(1, lf, n) >= a[i].c) update(1, lf, n, -a[i].c), ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 1e5 + 9, maxV = 536, MOD = 1e9 + 7, AND = (1 << 20) - 1, n           lg = 21; n vector<int> farg[maxN], adj[maxN], adjc[maxN], elems[maxN]; n int incom[maxN], comp[maxN], idx; n set<pair<int, int> > mys; n stack<int> stc; n bool vi[maxN]; n void dfs(int nd) { n   if (vi[nd]) return; n   vi[nd] = 1; n   for (int sn : adj[nd]) dfs(sn); n   stc.push(nd); n } n void sfd(int nd) { n   if (vi[nd]) return; n   vi[nd] = 1; n   for (int sn : farg[nd]) sfd(sn); n   comp[nd] = idx; n   elems[idx].push_back(nd); n } n bool makeQuery(int a, int b) { n   cout <<  ?   << a + 1 <<     << b + 1 <<   n ; n   cout.flush(); n   int ans; n   cin >> ans; n   return ans == 1; n } n void procesavec(vector<int> &one, vector<int> &two) { n   while (one.size() && two.size()) { n     if (makeQuery(one.back(), two.back())) { n       two.pop_back(); n     } else { n       one.pop_back(); n     } n   } n } n int n, m; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int u, v, i = 0; i < m; i++) { n     cin >> u >> v; n     u--; n     v--; n     adj[u].push_back(v); n     farg[v].push_back(u); n   } n   for (int i = 0; i < n; i++) dfs(i); n   memset(vi, 0, sizeof vi); n   while (stc.size()) { n     while (stc.size() && vi[stc.top()]) stc.pop(); n     if (stc.empty()) break; n     sfd(stc.top()); n     idx++; n   } n   for (int i = 0; i < n; i++) { n     for (int to : adj[i]) { n       if (comp[to] == comp[i]) continue; n       incom[comp[to]]++; n       adjc[comp[i]].push_back(comp[to]); n     } n   } n   for (int i = 0; i < idx; i++) { n     mys.insert(pair<int, int>(incom[i], i)); n   } n   int nd = mys.begin()->second; n   mys.erase(mys.begin()); n   while (mys.size() && mys.begin()->first == 0) { n     int frontup = mys.begin()->second; n     mys.erase(pair<int, int>(incom[frontup], frontup)); n     procesavec(elems[nd], elems[frontup]); n     if (elems[nd].empty()) swap(nd, frontup); n     for (int cmp : adjc[frontup]) { n       mys.erase(pair<int, int>(incom[cmp]--, cmp)); n       mys.insert(pair<int, int>(incom[cmp], cmp)); n     } n   } n   cout <<  !   << elems[nd].back() + 1 <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n int cnt[200005]; n int calc(int t) { n   int res = 0; n   for (int i = 1; i <= 200000; i++) { n     res += cnt[i] / t; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     cnt[a]++; n   } n   int lf = 1, ri = 200005, mid; n   while (lf < ri) { n     mid = (lf + ri) / 2; n     if (calc(mid) < k) n       ri = mid; n     else n       lf = mid + 1; n   } n   if (calc(mid) < k) mid--; n   int p, tot = 0; n   while (tot < k) { n     for (int i = 1; i <= 200000; i++) { n       if (tot == k) break; n       p = cnt[i] / mid; n       for (int j = 0; j < p; j++) { n         cout << i <<    ; n         tot++; n         if (tot == k) break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int n; n   cin >> n; n   pair<long long int, long long int> a[n]; n   for (long long int i = 0; i < n; i++) cin >> a[i].first >> a[i].second; n   sort(a, a + n); n   long long int x1 = -1, y1 = -1, x2 = -1, y2 = -1; n   for (long long int i = 0; i < n; i++) { n     long long int x = a[i].first, y = a[i].second; n     if (x > y1) { n       x1 = x, y1 = y; n       continue; n     } n     if (x > y2) { n       x2 = x, y2 = y; n       continue; n     } n     return cout <<  NO , 0; n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, s, n, e; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> s >> n >> e; n     long long l = 0, r = e + 1, m; n     if (e == 0) { n       if (s > n) n         cout << 1 << endl; n       else n         cout << 0 << endl; n       continue; n     } n     while (r - l > 1) { n       m = (r + l) / 2; n       if (n + m < s + e - m) { n         l = m; n       } else n         r = m; n     } n     if (n < s + e) l++; n     cout << l << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000 + 10; n inline int read() { n   int x = 0; n   bool f = true; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = false; n     c = getchar(); n   } n   while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   return f ? x : -x; n } n int n, c[N], t[N], a[N], b[N]; n int main() { n   n = read(); n   for (register int i = 1; i <= n; ++i) c[i] = read(); n   for (register int i = 1; i <= n; ++i) t[i] = read(); n   for (register int i = 1; i <= n; ++i) n     a[i] = c[i] - c[i - 1], b[i] = t[i] - t[i - 1]; n   sort(a + 2, a + n + 1), sort(b + 2, b + n + 1); n   for (register int i = 1; i <= n; ++i) n     if (a[i] != b[i]) return puts( No ) & 0; n   puts( Yes ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n int main() { n   int n; n   cin >> n; n   int x[n], y[n], dx[n], dy[n], s[n]; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i] >> dx[i] >> dy[i] >> s[i]; n   } n   float ans = -1; n   int eff_s; n   float t1, t2; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (dx[i] * dy[j] == dx[j] * dy[i]) { n         if (dx[i] * (y[j] - y[i]) == dy[i] * (x[j] - x[i])) { n           eff_s = 0; n           if (dy[i] * (y[j] - y[i]) > 0) eff_s += s[i]; n           if (dy[j] * (y[i] - y[j]) > 0) eff_s += s[j]; n           if (eff_s != 0) { n             t1 = sqrt((y[j] - y[i]) * (y[j] - y[i]) + n                       (x[j] - x[i]) * (x[j] - x[i])) / n                  eff_s; n             if (ans == -1 || ans > t1) { n               ans = t1; n             } n           } n         } n       } else { n         t1 = (sqrt(dx[i] * dx[i] + dy[i] * dy[i]) * n               (dy[j] * (x[j] - x[i]) - dx[j] * (y[j] - y[i]))) / n              (s[i] * (dx[i] * dy[j] - dx[j] * dy[i])); n         t2 = (sqrt(dx[j] * dx[j] + dy[j] * dy[j]) * n               (dy[i] * (x[i] - x[j]) - dx[i] * (y[i] - y[j]))) / n              (s[j] * (dx[j] * dy[i] - dx[i] * dy[j])); n         if (t1 >= 0 && t2 >= 0 && (ans == -1 || ans > max(t1, t2))) { n           ans = max(t1, t2); n         } n       } n     } n   } n   if (ans == -1) n     cout <<  No show :( ; n   else n     cout << setprecision(14) << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n namespace Xrocks {} n using namespace Xrocks; n namespace Xrocks { n class in { n } user_input; n class out { n } output; n in& operator>>(in& X, int& Y) { n   scanf( %d , &Y); n   return X; n } n in& operator>>(in& X, char* Y) { n   scanf( %s , Y); n   return X; n } n in& operator>>(in& X, float& Y) { n   scanf( %f , &Y); n   return X; n } n in& operator>>(in& X, double& Y) { n   scanf( %lf , &Y); n   return X; n } n in& operator>>(in& X, char& C) { n   scanf( %c , &C); n   return X; n } n in& operator>>(in& X, string& Y) { n   cin >> Y; n   return X; n } n in& operator>>(in& X, long long& Y) { n   scanf( %lld , &Y); n   return X; n } n template <typename T> n in& operator>>(in& X, vector<T>& Y) { n   for (auto& x : Y) user_input >> x; n   return X; n } n template <typename T> n out& operator<<(out& X, const T& Y) { n   cout << Y; n   return X; n } n template <typename T> n out& operator<<(out& X, vector<T>& Y) { n   for (auto& x : Y) output << x <<    ; n   return X; n } n out& operator<<(out& X, const int& Y) { n   printf( %d , Y); n   return X; n } n out& operator<<(out& X, const char& C) { n   printf( %c , C); n   return X; n } n out& operator<<(out& X, const string& Y) { n   printf( %s , Y.c_str()); n   return X; n } n out& operator<<(out& X, const long long& Y) { n   printf( %lld , Y); n   return X; n } n out& operator<<(out& X, const float& Y) { n   printf( %f , Y); n   return X; n } n out& operator<<(out& X, const double& Y) { n   printf( %lf , Y); n   return X; n } n out& operator<<(out& X, const char Y[]) { n   printf( %s , Y); n   return X; n } n template <typename T> n T max(T A) { n   return A; n } n template <typename T, typename... args> n T max(T A, T B, args... S) { n   return max(A > B ? A : B, S...); n } n template <typename T> n T min(T A) { n   return A; n } n template <typename T, typename... args> n T min(T A, T B, args... S) { n   return min(A < B ? A : B, S...); n } n template <typename T> n void vectorize(int y, vector<T>& A) { n   A.resize(y); n } n template <typename T, typename... args> n void vectorize(int y, vector<T>& A, args&&... S) { n   A.resize(y); n   vectorize(y, S...); n } n long long fast(long long a, long long b, long long pr) { n   if (b == 0) return 1 % pr; n   long long ans = 1 % pr; n   while (b) { n     if (b & 1) ans = (ans * a) % pr; n     b >>= 1; n     a = (a * a) % pr; n   } n   return ans; n } n int readInt() { n   int n = 0; n   int ch = getchar_unlocked(); n   int sign = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar_unlocked(); n   } n   while (ch >=  0  && ch <=  9 ) n     n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked(); n   n = n * sign; n   return n; n } n long long readLong() { n   long long n = 0; n   int ch = getchar_unlocked(); n   int sign = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar_unlocked(); n   } n   while (ch >=  0  && ch <=  9 ) n     n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked(); n   n = n * sign; n   return n; n } n long long readBin() { n   long long n = 0; n   int ch = getchar_unlocked(); n   int sign = 1; n   while (ch <  0  || ch >  1 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar_unlocked(); n   } n   while (ch >=  0  && ch <=  1 ) n     n = (n << 1) + (ch -  0 ), ch = getchar_unlocked(); n   return n; n } n long long inv_(long long val, n                long long pr = static_cast<long long>(998244353)) { n   return fast(val, pr - 2, pr); n } n }  // namespace Xrocks n class solve { n  public: n   solve() { n     int n, m, k; n     user_input >> n >> m >> k; n     vector<pair<int, int> > Edges(m); n     vector<int> Ans(m); n     vector<int> degree(n); n     vector<vector<pair<int, int> > > adj(n); n     set<pair<int, int> > Good_set; n     vector<int> in_good_set(n, true); n     for (int i = 0; i < m; i++) { n       user_input >> Edges[i].first >> Edges[i].second; n       Edges[i].first--; n       Edges[i].second--; n       adj[Edges[i].first].push_back({Edges[i].second, i}); n       adj[Edges[i].second].push_back({Edges[i].first, i}); n       degree[Edges[i].first]++; n       degree[Edges[i].second]++; n     } n     for (int i = 0; i < n; i++) { n       Good_set.insert({degree[i], i}); n     } n     while (!Good_set.empty() && Good_set.begin()->first < k) { n       int node = Good_set.begin()->second; n       for (auto& y : adj[node]) { n         int x = y.first; n         if (in_good_set[x]) { n           Good_set.erase({degree[x], x}); n           --degree[x]; n           Good_set.insert({degree[x], x}); n         } n       } n       Good_set.erase({degree[node], node}); n       in_good_set[node] = false; n     } n     for (int i = m - 1; i >= 0; i--) { n       Ans[i] = Good_set.size(); n       int u = Edges[i].first, v = Edges[i].second; n       if (in_good_set[u] && in_good_set[v]) { n         Good_set.erase({degree[u], u}); n         --degree[u]; n         Good_set.insert({degree[u], u}); n         Good_set.erase({degree[v], v}); n         --degree[v]; n         Good_set.insert({degree[v], v}); n         while (!Good_set.empty() && Good_set.begin()->first < k) { n           int node = Good_set.begin()->second; n           for (auto& y : adj[node]) { n             int x = y.first; n             if (y.second >= i) continue; n             if (in_good_set[x]) { n               Good_set.erase({degree[x], x}); n               --degree[x]; n               Good_set.insert({degree[x], x}); n             } n           } n           Good_set.erase({degree[node], node}); n           in_good_set[node] = false; n         } n       } n     } n     for (int i = 0; i < m; i++) { n       output << Ans[i] <<   n ; n     } n   } n }; n int32_t main() { n   int t = 1, i = 1; n   if (0 || 0) scanf( %d , &t); n   while (t--) { n     if (0) printf( Case #%d:  , i++); n     new solve; n   } n   output <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Solved() { n   int n; n   cin >> n; n   int one = 0; n   int two = 0; n   vector<int> ans; n   long long sum = 0; n   for (int i = 1; i <= n; i++) { n     int te; n     cin >> te; n     if (te % 2 == 0) { n       two++; n     } else { n       one++; n     } n   } n   if (two > 0) { n     sum += 2; n     ans.push_back(2); n     two--; n   } n   while (1) { n     if (two == 0 && one == 0) { n       break; n     } n     if (sum % 2 == 0) { n       if (one > 0) { n         ans.push_back(1); n         sum += 1; n         one--; n       } else { n         ans.push_back(2); n         sum += 2; n         two--; n       } n     } else { n       if (two > 0) { n         ans.push_back(2); n         sum += 2; n         two--; n       } else { n         ans.push_back(1); n         one--; n         sum += 1; n       } n     } n   } n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] <<    ; n   } n   cout << endl; n } n int main() { n   Solved(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (ll i = 0; i < v.size(); ++i) os << v[i] <<    ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& v) { n   for (auto it : v) os << it <<    ; n   return os; n } n template <typename T, typename S> n ostream& operator<<(ostream& os, const pair<T, S>& v) { n   os << v.first <<     << v.second; n   return os; n } n const ll mod = 1e9 + 7; n const ll inf = 2e18; n const ll ninf = -2e18; n ll takemod(ll a) { return ((a % mod) + mod) % mod; } n ll pow(ll a, ll b, ll m) { n   ll ans = 1; n   a %= m; n   while (b) { n     if (b & 1) ans = (ans * a) % m; n     b /= 2; n     a = (a * a) % m; n   } n   return ans; n } n ll modinv(ll a) { return takemod(pow(takemod(a), mod - 2, mod)); } n void solve() { n   ll n; n   cin >> n; n   string s1, s2; n   cin >> s1 >> s2; n   ll arr[26][26]; n   memset(arr, 0, sizeof(arr)); n   for (ll i = 0; i < n; i++) { n     ll a = s1[i] -  a ; n     ll b = s2[i] -  a ; n     if (a == b) continue; n     if (a > b) { n       cout << -1 <<   n ; n       return; n     } n     arr[a][b]++; n   } n   ll ans = 0; n   for (ll i = 0; i <= 20; i++) { n     for (ll j = i + 1; j <= 20; j++) { n       if (!arr[i][j]) continue; n       for (ll k = j + 1; k <= 20; k++) { n         if (arr[i][k]) { n           arr[j][k] += arr[i][k]; n           arr[i][k] = 0; n         } n       } n       ans++; n     } n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   time_t t1, t2; n   t1 = clock(); n   ll t; n   cin >> t; n   while (t--) solve(); n   t2 = clock(); n   cerr <<   n  << t2 - t1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n string i2s(T x) { n   ostringstream o; n   o << x; n   return o.str(); n } n template <class T> n vector<T> split(const string& s) { n   vector<T> v; n   istringstream is(s); n   T t; n   while (is >> t) v.push_back(t); n   return v; n } n vector<string> splitStr(const string& s, const string& d =   , n                         bool keepEmpty = false) { n   if (d.empty()) return split<string>(s); n   vector<string> v; n   string t; n   for (int _n = ((int((s).size()))), i = 0; i < _n; ++i) n     if (d.find(s[i]) != string::npos) { n       if (keepEmpty || !t.empty()) { n         v.push_back(t); n         t =   ; n       } n     } else n       t += s[i]; n   if (!t.empty()) v.push_back(t); n   return v; n } n int main() { n   std::ios::sync_with_stdio(false); n   int N, M; n   string s; n   cin >> N >> M; n   vector<string> v(N); n   for (int _n = (N), i = 0; i < _n; ++i) { n     cin >> v[i]; n   } n   int mini = 1000, maxi = 0, minj = 1000, maxj = 0; n   for (int _n = (N), i = 0; i < _n; ++i) n     for (int _n = (M), j = 0; j < _n; ++j) n       if (v[i][j] ==  X ) { n         mini = min(i, mini); n         minj = min(j, minj); n         maxi = max(i, maxi); n         maxj = max(j, maxj); n       } n   bool poss = true; n   for (int i = (mini); i <= (maxi); ++i) n     for (int j = (minj); j <= (maxj); ++j) n       if (v[i][j] !=  X ) { n         poss = false; n         break; n       } n   string ans = (poss ?  YES  :  NO ); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int a[n]; n   long long int sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += 1ll * a[i]; n   } n   long long int m = ceil(sum / 2); n   long long int temp = 0; n   for (int i = 0; i < n; i++) { n     temp += 1ll * a[i]; n     if (2 * temp >= sum) { n       cout << i + 1 <<   n ; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename TYPE> n inline TYPE sqr(const TYPE& a) { n   return a * a; n } n const long double EPS = 1e-9; n const long double PI = 2 * acos(0.0); n const int N = 300010; n int a[N]; n int main() { n   int n; n   scanf( %d , &n); n   long long s = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     s += a[i]; n   } n   sort(a, a + n); n   long long ans = s; n   for (int i = 0; i + 1 < n; ++i) { n     ans += s; n     s -= a[i]; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n inline int read(); n const int M = 200016, MOD = 1000000007; n int sz; n int ch[M][26], len[M], link[M], pre[M]; n void extend(const char *s) { n   for (int i = 0, lst = 0; s[i]; ++i) { n     int c = s[i] -  a , cur = ++sz; n     len[cur] = len[lst] + 1; n     int p = lst; n     while (!ch[p][c]) ch[p][c] = cur, p = link[p]; n     if (ch[p][c] != cur) { n       int q = ch[p][c]; n       if (len[p] + 1 == len[q]) n         link[cur] = q; n       else { n         int clone = ++sz; n         memcpy(ch[clone], ch[q], sizeof(ch[q])); n         link[clone] = link[q]; n         len[clone] = len[p] + 1; n         while (ch[p][c] == q) ch[p][c] = clone, p = link[p]; n         link[q] = link[cur] = clone; n       } n     } n     lst = cur; n     pre[cur] = i + 1; n   } n } n pair<int, int> qrys[M * 2 * 26]; n int qcnt; n int qans[M * 2 * 26]; n vector<int> sons[M]; n vector<int> qry[M]; n set<int> st[M]; n int tar[M]; n void merge(int a, int b) { n   if (st[tar[a]].size() < st[tar[b]].size()) swap(a, b); n   for (auto x : st[tar[b]]) st[tar[a]].insert(x); n   st[tar[b]].clear(); n   tar[b] = tar[a]; n } n void solve(int u) { n   for (auto v : sons[u]) solve(v), merge(u, v); n   for (auto qid : qry[u]) { n     int l = qrys[qid].first, r = qrys[qid].second; n     auto it = st[tar[u]].lower_bound(l); n     if (it != st[tar[u]].end() && *it <= r) qans[qid] = 1; n   } n } n char tex[M], pat[M * 2]; n int lef[M], rig[M], pid[M], pln[M], pcnt; n int solved[M]; n void foreach_query(int ftq, int id, int now, int tag) { n   if (pat[id] && ch[now][pat[id] -  a ]) n     foreach_query(ftq, id + 1, ch[now][pat[id] -  a ], tag); n   for (int c = pat[id] ? pat[id] + 1 :  a ; c <=  z ; ++c) { n     int tmp = ch[now][c -  a ]; n     if (tmp && rig[ftq] - lef[ftq] >= id - pid[ftq]) { n       ++qcnt; n       if (tag == 0) { n         qrys[qcnt] = {lef[ftq] + id - pid[ftq], rig[ftq]}; n         qry[tmp].push_back(qcnt); n       } else if (qans[qcnt] == 1 && !solved[ftq]) { n         solved[ftq] = 1; n         for (int xj = pid[ftq]; xj < id; ++xj) putchar(pat[xj]); n         putchar(c); n         printf(  n ); n       } n     } n   } n } n int main(void) { n   scanf( %s , tex); n   extend(tex); n   for (int i = 1; i <= sz; ++i) sons[link[i]].push_back(i); n   for (int i = 0; i <= sz; ++i) { n     tar[i] = i; n     if (pre[i]) st[i].insert(pre[i]); n   } n   int q = read(); n   for (int i = 1; i <= q; ++i) { n     lef[i] = read(), rig[i] = read(), pid[i] = pcnt; n     scanf( %s , pat + pid[i]); n     pln[i] = strlen(pat + pid[i]); n     pcnt += pln[i] + 1; n     foreach_query(i, pid[i], 0, 0); n   } n   solve(0); n   qcnt = 0; n   for (int i = 1; i <= q; ++i) { n     foreach_query(i, pid[i], 0, 1); n     if (!solved[i]) printf( -1 n ); n   } n   return 0; n } n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   int arr[n]; n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; ++j) { n       if (j == i) continue; n       for (int k = 0; k < n; ++k) { n         if (j == k) n           continue; n         else if (i == k) n           continue; n         if (arr[j] + arr[k] == arr[i]) { n           cout << i + 1 <<     << k + 1 <<     << j + 1; n           return 0; n         } n       } n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int lowbit(int x) { return x & -x; } n int read() { n   int kkk = 0, x = 1; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) c = getchar(), x = -1; n   while (c >=  0  && c <=  9 ) kkk = kkk * 10 + (c -  0 ), c = getchar(); n   return kkk * x; n } n int n, K, p, minn[101], dp[500001], tree[110], DP[10001][101], a[500001]; n inline int MOD(int x) { return x + ((x >> 31) & p); } n void sbsolve() { n   memset(DP, 0x3f, sizeof(DP)); n   DP[0][0] = 0; n   for (int j = 1; j <= K; ++j) { n     memset(minn, 0x3f, sizeof(minn)); n     for (int i = j - 1; i <= n; ++i) { n       for (int k = 0; k < p; ++k) n         DP[i][j] = min(DP[i][j], minn[k] + MOD(a[i] - k)); n       minn[a[i]] = min(minn[a[i]], DP[i][j - 1]); n     } n   } n   printf( %d n , DP[n][K]); n } n void xg(int zone, int v) { n   while (zone <= p) { n     tree[zone] = max(tree[zone], v); n     zone += lowbit(zone); n   } n } n int cx(int zone) { n   int bck = 0; n   while (zone) { n     bck = max(tree[zone], bck); n     zone -= lowbit(zone); n   } n   return bck; n } n int main() { n   n = read(), K = read(), p = read(); n   for (int i = 1; i <= n; ++i) a[i] = MOD(a[i - 1] + read() % p - p); n   if (n < K * p) { n     sbsolve(); n     return 0; n   } n   int ans = a[n]; n   for (int i = 1; i <= n; ++i) a[i] += 1; n   dp[1] = 1; n   xg(a[1], dp[1]); n   for (int i = 2; i <= n; ++i) { n     dp[i] = cx(a[i]) + 1; n     xg(a[i], dp[i]); n   } n   if (dp[n] >= K) n     printf( %d n , ans); n   else n     printf( %d n , ans + p); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int max_n = 1000, max_k = 100; n int dp[max_n][max_k]; n int p[max_n + 5]; n int main() { n   int n, k, mod; n   cin >> n >> k >> mod; n   p[0] = 10 % k; n   for (int i = 0; i < n; i++) p[i + 1] = p[i] * 10 % k; n   memset(dp, 0, sizeof dp); n   for (int dig = 1; dig < 10; dig++) n     dp[0][dig % k] = (1 + dp[0][dig % k]) % mod; n   for (int i = 0; i < n - 1; i++) n     for (int dig = (i + 1 == n - 1); dig < 10; dig++) { n       if (dig) { n         int newr = dig * p[i] % k; n         dp[i + 1][newr] = (1 + dp[i + 1][newr]) % mod; n       } n       for (int r = 0; r < k; r++) { n         int newr = r ? (dig * p[i] + r) % k : 0; n         dp[i + 1][newr] = (dp[i][r] + dp[i + 1][newr]) % mod; n       } n     } n   cout << dp[n - 1][0] << endl; n   return 0; n } n