#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   int n; n   cin >> n; n   vector<pair<string, int>> v; n   priority_queue<int, vector<int>, greater<int>> pq; n   for (int i = 0; i < n; ++i) { n     string s; n     cin >> s; n     int x; n     if (s !=  removeMin ) { n       cin >> x; n       v.push_back({s, x}); n     } else n       v.push_back({s, INT_MIN}); n   } n   vector<pair<string, int>> ans; n   for (int i = 0; i < n; ++i) { n     if (v[i].first ==  insert ) n       ans.push_back({v[i].first, v[i].second}), pq.push(v[i].second); n     else if (v[i].first ==  getMin ) { n       int val = v[i].second; n       if (pq.empty()) { n         ans.push_back({ insert , val}); n         pq.push(val); n       } n       while (!pq.empty() && val > pq.top()) { n         ans.push_back({ removeMin , INT_MIN}); n         pq.pop(); n       } n       if (!pq.empty() && val < pq.top()) { n         ans.push_back({ insert , val}); n         pq.push(val); n       } else if (pq.empty()) { n         ans.push_back({ insert , val}); n         pq.push(val); n       } n       ans.push_back({ getMin , val}); n     } else { n       if (pq.empty()) { n         ans.push_back({ insert , 0}); n         pq.push(0); n       } n       ans.push_back({ removeMin , INT_MIN}); n       pq.pop(); n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); ++i) { n     if (ans[i].first ==  removeMin ) n       cout << ans[i].first << endl; n     else n       cout << ans[i].first <<     << ans[i].second << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> parent; n vector<int> Rank; n vector<int> Count; n int root(int v) { n   if (parent[v] == v) return v; n   return parent[v] = root(parent[v]); n } n bool DSU(int a, int b) { n   a = root(a); n   b = root(b); n   if (a != b) { n     if (Rank[b] > Rank[a]) swap(a, b); n     Rank[a] += Rank[b]; n     Count[a] += Count[b]; n     parent[b] = a; n     return true; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m, k; n   cin >> n >> m >> k; n   vector<pair<long long int, pair<int, int> > > Edges(m); n   parent.resize(n + 1); n   for (int i = 1; i <= n; i++) parent[i] = i; n   Rank.resize(n + 1, 1); n   Count.resize(n + 1, 0); n   for (int i = 0; i < k; i++) { n     int a; n     cin >> a; n     Count[a] = 1; n   } n   for (int i = 0; i < m; i++) { n     int a, b; n     long long int w; n     cin >> a >> b >> w; n     Edges[i] = make_pair(w, make_pair(a, b)); n   } n   sort(Edges.begin(), Edges.end()); n   long long int last = -1; n   for (int i = 0; i < m; i++) { n     int a = Edges[i].second.first; n     int b = Edges[i].second.second; n     long long int w = Edges[i].first; n     if (a != b) { n       DSU(a, b); n       if (last == -1 && Count[root(a)] == k) { n         last = w; n       } n     } n   } n   for (int i = 0; i < k; i++) { n     cout << last <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n struct { n   inline operator int() { n     int x; n     return scanf( %d , &x), x; n   } n   inline operator long long() { n     long long x; n     return scanf( %lld , &x), x; n   } n   template <class T> n   inline void operator()(T &x) { n     x = *this; n   } n   template <class T, class... A> n   inline void operator()(T &x, A &...a) { n     x = *this; n     this->operator()(a...); n   } n } read; n const int maxn = 120005; n long long his[maxn << 2]; n int min[maxn << 2], tot[maxn << 2], mot[maxn << 2], pat[maxn << 2]; n void modi(int now, int x) { n   min[now] += x; n   mot[now] += x; n } n void pass(int now, int x) { n   his[now] += 1ll * tot[now] * x; n   pat[now] += x; n } n void push(int now) { n   if (mot[now]) { n     modi((now << 1), mot[now]); n     modi((now << 1 | 1), mot[now]); n     mot[now] = 0; n   } n   if (pat[now]) { n     if (min[(now << 1)] == min[now]) pass((now << 1), pat[now]); n     if (min[(now << 1 | 1)] == min[now]) pass((now << 1 | 1), pat[now]); n     pat[now] = 0; n   } n } n void modify(int now, int L, int R, int l, int r, int x) { n   if (r < L or l > R) return; n   if (l <= L and R <= r) return modi(now, x); n   push(now); n   int M = (L + R) >> 1; n   modify((now << 1), L, M, l, r, x); n   modify((now << 1 | 1), M + 1, R, l, r, x); n   his[now] = his[(now << 1)] + his[(now << 1 | 1)]; n   min[now] = std::min(min[(now << 1)], min[(now << 1 | 1)]); n   tot[now] = 0; n   if (min[(now << 1)] == min[now]) tot[now] += tot[(now << 1)]; n   if (min[(now << 1 | 1)] == min[now]) tot[now] += tot[(now << 1 | 1)]; n } n long long query(int now, int L, int R, int l, int r) { n   if (r < L or l > R) return 0; n   if (l <= L and R <= r) return his[now]; n   push(now); n   int M = (L + R) >> 1; n   return query((now << 1), L, M, l, r) + query((now << 1 | 1), M + 1, R, l, r); n } n void build(int now, int L, int R) { n   min[now] = L; n   tot[now] = 1; n   if (L == R) return; n   int M = (L + R) >> 1; n   build((now << 1), L, M); n   build((now << 1 | 1), M + 1, R); n } n void test(int now, int L, int R) { n   if (L == R) { n     fprintf(stderr,   %d , min[now]); n     return; n   } n   push(now); n   int M = (L + R) >> 1; n   test((now << 1), L, M); n   test((now << 1 | 1), M + 1, R); n   if (now == 1) fprintf(stderr,   n ); n } n int a[maxn]; n long long ans[maxn]; n int st1[maxn], sp1; n int st2[maxn], sp2; n std::vector<std::pair<int, int> > v[maxn]; n int main() { n   int n = read; n   for (int i = 1; i <= n; i++) read(a[i]); n   int q = read; n   for (int i = 1; i <= q; i++) { n     int l = read, r = read; n     v[r].push_back(std::pair<int, int>(l, i)); n   } n   build(1, 1, n); n   for (int r = 1; r <= n; r++) { n     while (sp2 and a[st2[sp2]] > a[r]) n       modify(1, 1, n, st2[sp2 - 1] + 1, st2[sp2], a[st2[sp2]]), --sp2; n     st2[++sp2] = r; n     modify(1, 1, n, st2[sp2 - 1] + 1, st2[sp2], -a[st2[sp2]]); n     while (sp1 and a[st1[sp1]] < a[r]) n       modify(1, 1, n, st1[sp1 - 1] + 1, st1[sp1], -a[st1[sp1]]), --sp1; n     st1[++sp1] = r; n     modify(1, 1, n, st1[sp1 - 1] + 1, st1[sp1], a[st1[sp1]]); n     modi(1, -1); n     pass(1, 1); n     for (std::pair<int, int> p : v[r]) n       ans[p.second] = query(1, 1, n, p.first, r); n   } n   for (int i = 1; i <= q; i++) printf( %lld n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[26]; n char pal[111111]; n inline bool is_pal(int k, int can) { n   vector<int> odd(0); n   for (int i = 0; i < n; ++i) { n     if (a[i] % k) return 0; n     if (a[i] % (2 * k)) odd.push_back(i); n   } n   if ((int)(odd).size() > 1) return 0; n   if ((int)(odd).size() == 1 && !can) return 0; n   int pos = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < a[i] / (2 * k); ++j) { n       pal[pos++] =  a  + i; n     } n   } n   if ((int)(odd).size()) pal[pos++] =  a  + odd[0]; n   for (int i = n - 1; i >= 0; --i) { n     for (int j = 0; j < a[i] / (2 * k); ++j) { n       pal[pos++] =  a  + i; n     } n   } n   pal[pos] = 0; n   return 1; n } n inline void die(int ans, int reps, char middle) { n   printf( %d n , ans); n   for (int i = 0; i < reps; ++i) { n     printf( %s , pal); n     if (middle !=  ! ) printf( %c , middle); n   } n   printf(  n ); n   exit(0); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n   } n   for (int ans = 111111; ans > 1; --ans) { n     if (ans % 2 == 1) { n       for (int let = 0; let < n; ++let) { n         if (a[let] >= ans) { n           a[let] -= ans; n           if (is_pal(ans, 0)) { n             die(ans, ans,  a  + let); n           } n           a[let] += ans; n         } n       } n     } else { n       for (int let = 0; let < n; ++let) { n         if (is_pal(ans / 2, 0)) { n           die(ans, ans / 2,  ! ); n         } n       } n     } n   } n   if (is_pal(1, 1)) { n     die(1, 1,  ! ); n   } n   printf( 0 n ); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < a[i]; ++j) { n       printf( %c ,  a  + i); n     } n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   char c[200005]; n   scanf( %s , c); n   int ok[26]; n   memset(ok, 0, sizeof(ok)); n   for (int i = 0; i < k; i++) { n     char cc; n     scanf(  %c , &cc); n     ok[cc -  a ] = 1; n   } n   long long cnt = 0; n   long long ans = 0; n   for (int i = 0; c[i] != 0; i++) { n     if (ok[c[i] -  a ]) n       cnt++; n     else { n       ans += cnt * (cnt + 1) / 2; n       cnt = 0; n     } n   } n   ans += cnt * (cnt + 1) / 2; n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n string s, t; n int l[200005], r[200005]; n int dp[30][200005]; n void gd() { n   cout <<  No ; n   exit(0); n } n bool check(int lr, int rl, int c) { n   return ((lr ? dp[c][lr - 1] : 0) - (rl ? dp[c][rl - 1] : 0) > 0); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> s >> t; n   s =  *  + s; n   int n = (int)s.size(); n   int m = (int)t.size(); n   for (int i = 1; i < n; ++i) { n     l[i] = l[i - 1]; n     if (s[i] == t[l[i]]) ++l[i]; n   } n   for (int i = n - 1; i; --i) { n     r[i] = r[i + 1]; n     if (s[i] == t[m - 1 - r[i]]) ++r[i]; n   } n   if (l[n - 1] != m || r[1] != m) gd(); n   for (int i = 0; i < 26; ++i) n     for (int j = 0; j < m; ++j) { n       char c = i +  a ; n       dp[i][j] = (j ? dp[i][j - 1] : 0) + (t[j] == c); n     } n   for (int i = 1; i < n; ++i) { n     int rg = m - r[i]; n     int lg = l[i]; n     if (rg > lg || !check(lg, rg, s[i] -  a )) gd(); n   } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M, K; n int color[200002]; n vector<int> edge[200002]; n int id[200002]; n int ite = 1; n int siz[200002]; n map<int, int> m[200002]; n int ans; n void dfs(int a) { n   if (id[a]) { n     return; n   } n   id[a] = ite; n   for (int i = 0; i < edge[a].size(); i++) { n     dfs(edge[a][i]); n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   if (fopen( cf731c.in ,  r )) { n     freopen( cf731c.in ,  r , stdin); n     freopen( cf731c.out ,  w , stdout); n   } n   cin >> N >> M >> K; n   for (int i = 0; i < N; i++) { n     cin >> color[i]; n   } n   for (int i = 0; i < M; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     edge[a].push_back(b); n     edge[b].push_back(a); n   } n   for (int i = 0; i < N; i++) { n     if (id[i] == 0) { n       dfs(i); n       ite++; n     } n   } n   for (int i = 0; i < N; i++) { n     siz[id[i]]++; n     m[id[i]][color[i]]++; n   } n   for (int i = 1; i < ite; i++) { n     int mx = -1; n     for (auto it = m[i].begin(); it != m[i].end(); it++) { n       mx = max(mx, it->second); n     } n     ans += (siz[i] - mx); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class A, class B> n ostream &operator<<(ostream &out, const pair<A, B> &a) { n   return out <<  (  << a.first <<  ,  << a.second <<  ) ; n } n template <class A> n ostream &operator<<(ostream &out, const vector<A> &a) { n   for (const A &it : a) out << it <<    ; n   return out; n } n template <class A, class B> n istream &operator>>(istream &in, pair<A, B> &a) { n   return in >> a.first >> a.second; n } n template <class A> n istream &operator>>(istream &in, vector<A> &a) { n   for (A &i : a) in >> i; n   return in; n } n ifstream cinn( in.txt ); n ofstream coutt( out.txt ); n int poww(const int &a, int b, const int &m = (1000000007)) { n   if (b == 0) return 1; n   int x = poww(a, b / 2, m); n   x = x * x % m; n   if (b & 1) x = x * a % m; n   return x; n } n int ceil(const int &a, const int &b) { return (a - 1) / b + 1; } n int primes[5000005]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   for (int i = 2; i < 5000005; i++) { n     if (primes[i]) continue; n     for (int j = i; j < 5000005; j += i) { n       int in = j; n       while (in % i == 0) { n         in /= i; n         primes[j]++; n       } n     } n   } n   for (int i = 1; i < 5000005; i++) primes[i] += primes[i - 1]; n   int t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     cout << primes[a] - primes[b] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s; n const int MAXN = 100005; n int tz[4 * MAXN], tx[4 * MAXN], ty[4 * MAXN]; n int cntz(int v, int tl, int tr, int l, int r) { n   if (l > r) return 0; n   if (tl == l && r == tr) return tz[v]; n   int tm = (tl + tr) / 2; n   return cntz(2 * v, tl, tm, l, min(tm, r)) + n          cntz(2 * v + 1, tm + 1, tr, max(tm + 1, l), r); n } n int cnty(int v, int tl, int tr, int l, int r) { n   if (l > r) return 0; n   if (tl == l && r == tr) return ty[v]; n   int tm = (tl + tr) / 2; n   return cnty(2 * v, tl, tm, l, min(tm, r)) + n          cnty(2 * v + 1, tm + 1, tr, max(tm + 1, l), r); n } n int cntx(int v, int tl, int tr, int l, int r) { n   if (l > r) return 0; n   if (tl == l && r == tr) return tx[v]; n   int tm = (tl + tr) / 2; n   return cntx(2 * v, tl, tm, l, min(tm, r)) + n          cntx(2 * v + 1, tm + 1, tr, max(tm + 1, l), r); n } n void buildz(int v, int tl, int tr) { n   if (tl == tr) n     tz[v] = (s[tl] ==  z ); n   else { n     int tm = (tl + tr) / 2; n     buildz(2 * v, tl, tm); n     buildz(2 * v + 1, tm + 1, tr); n     tz[v] = tz[2 * v] + tz[2 * v + 1]; n   } n } n void buildy(int v, int tl, int tr) { n   if (tl == tr) n     ty[v] = (s[tl] ==  y ); n   else { n     int tm = (tl + tr) / 2; n     buildy(2 * v, tl, tm); n     buildy(2 * v + 1, tm + 1, tr); n     ty[v] = ty[2 * v] + ty[2 * v + 1]; n   } n } n void buildx(int v, int tl, int tr) { n   if (tl == tr) n     tx[v] = (s[tl] ==  x ); n   else { n     int tm = (tl + tr) / 2; n     buildx(2 * v, tl, tm); n     buildx(2 * v + 1, tm + 1, tr); n     tx[v] = tx[2 * v] + tx[2 * v + 1]; n   } n } n int main() { n   cin >> s; n   int n, l = s.length(); n   buildz(1, 0, l - 1); n   buildy(1, 0, l - 1); n   buildx(1, 0, l - 1); n   cin >> n; n   for (int i = 0, a, b; i < n; ++i) { n     cin >> a >> b; n     int z = cntz(1, 0, l - 1, a - 1, b - 1); n     int y = cnty(1, 0, l - 1, a - 1, b - 1); n     int x = cntx(1, 0, l - 1, a - 1, b - 1); n     int t = min(x, min(y, z)); n     z -= t; n     y -= t; n     x -= t; n     if (b - a + 1 <= 2 || (z <= 1 && x <= 1 && y <= 1)) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int m; n   cin >> n >> m; n   int c[m], a[n]; n   int i, j, k; n   for (i = 0; i < n; i++) { n     a[i] = 0; n   } n   for (i = 0; i < m; i++) { n     cin >> c[i]; n     a[c[i] - 1]++; n   } n   k = a[0]; n   for (i = 0; i < n; i++) { n     if (k > a[i]) { n       k = a[i]; n     } n   } n   cout << k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const long long mod = 1e9 + 7; n const long long N = 222; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n long long n, k; n vector<long long> adj[N]; n long long dp[N][N], dp2[N][N], a[N]; n void input() { n   cin >> n >> k; n   k++; n   for (long long i = (1); i <= (n); i++) cin >> a[i]; n   for (long long i = (1); i <= (n - 1); i++) { n     long long x, y; n     cin >> x >> y; n     ; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n } n void dfs(long long cur = 1, long long prev = 0) { n   for (long long i : adj[cur]) n     if (i != prev) dfs(i, cur); n   for (long long p = (k); p >= (0); p--) { n     if (p >= (k + 1) / 2) { n       long long mx = -inf; n       for (long long i : adj[cur]) n         if (i != prev) { n           dp2[cur][p] += dp2[i][p - 1]; n           mx = max(mx, dp[i][p - 1] - dp2[i][p - 1]); n         } n       dp[cur][p] = dp2[cur][p] + mx; n     } else { n       long long mx = -inf; n       if (!p) mx = a[cur]; n       for (long long i : adj[cur]) n         if (i != prev) { n           dp[cur][p] += dp2[i][(k - p) - 1]; n           if (p) mx = max(mx, dp[i][p - 1] - dp2[i][(k - p) - 1]); n         } n       dp[cur][p] += mx; n       dp2[cur][p] = max(dp[cur][p], dp2[cur][p + 1]); n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   input(); n   dfs(); n   cout << dp2[1][0]; n } n


#include <bits/stdc++.h> n using namespace std; n struct fenwick { n   long long n, fen[100005]; n   void resize(int _n) { n     n = _n + 1; n     memset(fen, 0, sizeof fen); n   } n   int query(int ind) { n     ind++; n     int ans = 0; n     while (ind >= 1) { n       ans += fen[ind]; n       ind -= ind & -ind; n     } n     return ans; n   } n   void update(int ind, int val) { n     ind++; n     while (ind <= n) { n       fen[ind] += val; n       ind += ind & -ind; n     } n   } n   int query(int l, int r) { return query(r) - query(l - 1); } n }; n const int maxn = 100001; n int n, l, w, x, y, sz[maxn]; n long long res; n bool blocked[maxn]; n vector<pair<int, int> > c, v[maxn]; n fenwick tree; n void dfs(int node, int pnode, int curw, int curl) { n   c.push_back(make_pair(curw, curl)); n   for (auto &i : v[node]) n     if (i.first != pnode && !blocked[i.first]) n       dfs(i.first, node, curw + i.second, curl + 1); n } n long long solve(int node, int curw, int curl) { n   long long ret = 0; n   c.clear(); n   dfs(node, 0, curw, curl); n   sort(c.begin(), c.end()); n   for (auto &i : c) tree.update(i.second, 1); n   for (int i = 0, j = c.size() - 1; i < c.size(); i++) { n     while (i <= j && c[i].first + c[j].first > w) n       tree.update(c[j--].second, -1); n     if (j < i) break; n     tree.update(c[i].second, -1); n     ret += tree.query(l - c[i].second); n   } n   return ret; n } n int dfsz(int node, int pnode) { n   sz[node] = 1; n   for (auto &i : v[node]) n     if (i.first != pnode && !blocked[i.first]) sz[node] += dfsz(i.first, node); n   return sz[node]; n } n int find(int node, int pnode, int n) { n   for (auto &i : v[node]) n     if (i.first != pnode && !blocked[i.first] && 2 * sz[i.first] > n) n       return find(i.first, node, n); n   return node; n } n void decompose(int node) { n   int centroid = find(node, 0, dfsz(node, 0)); n   blocked[centroid] = 1; n   res += solve(centroid, 0, 0); n   for (auto &i : v[centroid]) n     if (!blocked[i.first]) n       res -= solve(i.first, i.second, 1), decompose(i.first); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> l >> w; n   tree.resize(n + 1); n   for (int i = 2; i <= n && cin >> x >> y; i++) { n     v[i].push_back(make_pair(x, y)); n     v[x].push_back(make_pair(i, y)); n   } n   decompose(1); n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e6 + 5; n int arr[MAX_N]; n int vis[MAX_N]; n void solve() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &arr[i]); n     vis[i] = 0; n   } n   vector<int> stk; n   for (int i = 1; true; i = i - arr[i]) { n     if (vis[i]) { n       vector<int> ans; n       for (int j = stk.size() - 1; j >= 0; j--) { n         ans.push_back(stk[j]); n         if (stk[j] == i) break; n       } n       printf( %d n , (int)ans.size()); n       for (int u : ans) { n         printf( %d  , u); n       } n       printf(  n ); n       return; n     } else { n       vis[i] = 1; n       stk.push_back(i); n     } n   } n } n int main() { n   int testc; n   scanf( %d , &testc); n   for (int i = 0; i < testc; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   long long n; n   cin >> n; n   set<long long> st; n   for (long long i = 1; i * i <= n; i++) { n     if (n % i == 0) { n       long long a = n / gcd(n, i); n       st.insert(((a * (a - 1)) / 2) * (n / a) + a); n       long long m = (n / i); n       long long b = n / gcd(n, m); n       st.insert(((b * (b - 1)) / 2) * (n / b) + b); n     } n   } n   for (auto e : st) cout << e <<    ; n   return 0; n } n


#include <bits/stdc++.h> n int mat[500][500]; n int N, K; n int main() { n   scanf( %d%d , &N, &K); n   int Cnt = 1; n   int sum = 0; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < K - 1; j++) { n       mat[i][j] = Cnt++; n     } n   } n   for (int i = 0; i < N; i++) { n     for (int j = K - 1; j < N; j++) { n       mat[i][j] = Cnt++; n     } n   } n   for (int i = 0; i < N; i++) { n     sum += mat[i][K - 1]; n   } n   printf( %d n , sum); n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N; j++) { n       printf( %d  , mat[i][j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n bool visited[2][maxn]; n int d[2][maxn]; n string s[2]; n int main() { n   int n, k; n   cin >> n >> k; n   cin >> s[0] >> s[1]; n   int dx[3] = {0, 0, 1}; n   int dy[3] = {1, -1, k}; n   queue<pair<bool, int>> q; n   q.push(make_pair(0, 0)); n   visited[0][0] = 1; n   while (q.size()) { n     pair<bool, int> k = q.front(); n     q.pop(); n     bool x = k.first; n     int y = k.second; n     for (int i = 0; i < 3; i++) { n       bool xx = x ^ dx[i]; n       int yy = y + dy[i]; n       if (yy >= n) { n         cout <<  YES  << endl; n         exit(0); n       } n       if (yy >= 0 && s[xx][yy] ==  -  && !visited[xx][yy] && yy > d[x][y]) { n         q.push(make_pair(xx, yy)); n         visited[xx][yy] = 1; n         d[xx][yy] = d[x][y] + 1; n       } n     } n   } n   cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n unordered_set<int> dict; n int main() { n   long long a, b, x; n   cin >> x >> a >> b; n   if (a % x != 0) { n     a += x - (a % x + x) % x; n   } n   if (a > b) { n     cout << 0 << endl; n   } else { n     cout << (b - a + x) / x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int a, b, n; n   cin >> n >> a >> b; n   vector<int> A(n); n   for (int &x : A) cin >> x; n   sort(A.begin(), A.end()); n   if (A[b] - A[b - 1] == 0) { n     cout <<  0 n ; n     return; n   } n   cout << A[b] - A[b - 1] <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   register int x = 0, t = 1; n   register char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) t = -1, ch = getchar(); n   while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar(); n   return x * t; n } n int n, m, top, first[301000], dep[301000]; n struct mona { n   int nxt, en; n } s[301000 << 1]; n inline void Insert(int x, int y) { n   s[++top] = (mona){first[x], y}, first[x] = top; n } n inline void Dfs(int k, int fa) { n   dep[k] = dep[fa] + 1; n   for (register int i = first[k]; i; i = s[i].nxt) { n     int en = s[i].en; n     if (en == fa) continue; n     Dfs(en, k); n   } n   return; n } n int cnt, rt[301000], Min[301000], ls[301000], rs[301000]; n pair<long long, int> val[301000]; n long long lz[301000], ans; n inline int New(pair<long long, int> x) { n   int t = ++cnt; n   val[t] = x, Min[t] = 1; n   return t; n } n inline void Pushlz(int x, long long w) { val[x].first += w, lz[x] += w; } n inline void Pushdown(int x) { n   if (!lz[x]) return; n   if (ls[x]) Pushlz(ls[x], lz[x]); n   if (rs[x]) Pushlz(rs[x], lz[x]); n   lz[x] = 0; n } n inline int Merge(int u, int v) { n   if (!u || !v) return u | v; n   int t; n   if (val[u] < val[v]) n     Pushdown(u), rs[u] = Merge(rs[u], v), t = u; n   else n     Pushdown(v), rs[v] = Merge(u, rs[v]), t = v; n   if (Min[ls[t]] < Min[rs[t]]) swap(ls[t], rs[t]); n   Min[t] = Min[rs[t]] + 1; n   return t; n } n inline void Dfs2(int k, int fa) { n   for (register int i = first[k]; i; i = s[i].nxt) { n     int en = s[i].en; n     if (en == fa) continue; n     Dfs2(en, k), rt[k] = Merge(rt[k], rt[en]); n   } n   while (rt[k] && val[rt[k]].second >= dep[k]) n     rt[k] = Merge(ls[rt[k]], rs[rt[k]]); n   if (!rt[k] && k != 1) puts( -1 ), exit(0); n   ans += val[rt[k]].first, Pushlz(rt[k], -val[rt[k]].first); n } n int main() { n   n = read(), m = read(); n   for (register int i = 1; i < n; ++i) { n     int x = read(), y = read(); n     Insert(x, y), Insert(y, x); n   } n   Dfs(1, 0); n   for (register int i = 1; i <= m; ++i) { n     int x = read(), y = read(); n     long long w = read(); n     if (dep[x] < dep[y]) swap(x, y); n     rt[x] = Merge(rt[x], New(make_pair(w, dep[y]))); n   } n   Dfs2(1, 0), printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x; n   while (cin >> n) { n     x = n - 10; n     if (x <= 0 || x > 11) n       cout << 0 << endl; n     else if (x == 10) n       cout << 15 << endl; n     else n       cout << 4 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, u, r; n int a[35]; n int b[35]; n int k[35]; n int p[35]; n int op[35]; n int tmpa[35]; n int tmmmma[35]; n long long dfs(int index, const int ta[]) { n   if (index == u) { n     long long res = 0; n     for (int i = (0); i < ((n)); ++i) res += (long long)ta[i] * k[i]; n     return res; n   } n   int tta[35]; n   long long res = -(((long long)1) << 62); n   if (index == 0 || op[index - 1] != 0) { n     op[index] = 0; n     for (int i = (0); i < ((n)); ++i) tta[i] = ta[i] ^ b[i]; n     res = max(res, dfs(index + 1, tta)); n   } n   op[index] = 1; n   for (int i = (0); i < ((n)); ++i) tta[i] = ta[p[i]] + r; n   res = max(res, dfs(index + 1, tta)); n   if ((u - index) % 2 == 0) { n     long long tmp = 0; n     for (int i = (0); i < ((n)); ++i) tmp += (long long)ta[i] * k[i]; n     res = max(res, tmp); n   } n   return res; n } n int main(void) { n   cin >> n >> u >> r; n   for (int i = (0); i < ((n)); ++i) cin >> a[i]; n   for (int i = (0); i < ((n)); ++i) cin >> b[i]; n   for (int i = (0); i < ((n)); ++i) cin >> k[i]; n   for (int i = (0); i < ((n)); ++i) cin >> p[i]; n   for (int i = (0); i < ((n)); ++i) --p[i]; n   cout << dfs(0, a) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, sx, sy, x, y; n   cin >> n >> sx >> sy; n   vector<pair<long long int, long long int> > v; n   v.push_back({sx, sy + 1}); n   v.push_back({sx, sy - 1}); n   v.push_back({sx + 1, sy}); n   v.push_back({sx - 1, sy}); n   vector<long long int> answer(4, 0); n   for (long long int i = 1; i <= n; i++) { n     cin >> x >> y; n     long long int mnx = min(sx, x); n     long long int mxx = max(sx, x); n     long long int mny = min(sy, y); n     long long int mxy = max(sy, y); n     for (int j = 0; j < 4; j++) { n       if (v[j].first >= mnx && v[j].first <= mxx && v[j].second >= mny && n           v[j].second <= mxy) { n         answer[j]++; n       } n     } n   } n   long long int ans = 0; n   for (int i = 0; i < 4; i++) ans = max(ans, answer[i]); n   cout << ans << endl; n   for (int i = 0; i < 4; i++) { n     if (answer[i] == ans && v[i].first <= 1e9 && v[i].second <= 1e9 && n         v[i].first >= 0 && v[i].second >= 0) { n       cout << v[i].first <<     << v[i].second << endl; n       return 0; 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   long long t; n   cin >> t; n   while (t--) { n     long long sum = 1; n     long long sum1 = 0; n     long long sum2 = 0; n     long long cnt1 = 0; n     long long cnt2 = 0; n     long long res = 0; n     long long flag = 0; n     long long n; n     cin >> n; n     long long bm = n; n     string s; n     string su; n     while (n--) { n       cin >> s; n       su += s; n     } n     long long len = su.length(); n     sort(su.begin(), su.end()); n     for (long long i = 0; i < len - 1; i++) { n       if (su[i] == su[i + 1]) { n         sum += 1; n       } else { n         if (sum % bm == 0) { n           sum = 1; n         } else { n           cout <<  NO  << endl; n           ; n           flag = 1; n           break; n         } n       } n     } n     if (sum % bm != 0 && flag == 0) { n       cout <<  NO  << endl; n       ; n     } else if (flag == 0) { n       cout <<  YES  << endl; n       ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = (long double)1e-9; n const long double PI = (long double)acos(-1.0); n const int inf = 1e9 + 5; n const long long linf = 1e18L + 5; n const int mod = 1e9 + 7; n void solve() { n   int n, q, r, c; n   cin >> n >> q; n   unordered_set<int> s[3]; n   set<pair<int, int> > p; n   pair<int, int> pr; n   for (int i = 0; i < q; ++i) { n     cin >> r >> c; n     if (s[r].count(c)) { n       s[r].erase(c); n       for (int j : {c - 1, c, c + 1}) { n         if (j < 1 || j > n) continue; n         if (r == 1) n           pr = {c, j}; n         else n           pr = {j, c}; n         auto it = p.find(pr); n         if (it != p.end()) p.erase(it); n       } n     } else { n       s[r].insert(c); n       for (int j : {c - 1, c, c + 1}) { n         if (j < 1 || j > n) continue; n         if (r == 1) n           pr = {c, j}; n         else n           pr = {j, c}; n         if (s[3 - r].count(j)) p.insert(pr); n       } n     } n     cout << ((int)(p).size() ?  no  :  yes ) <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int test = 1; n   while (test--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 260; n int m, n, mx[N][10], g[N][26], sl[N], L[N]; n char a[N][N]; n int kq; n unsigned long long o[N], A[N], B[N], pw[N], P[N]; n unsigned long long get(int l, int r) { return A[r] - A[l - 1] * pw[r - l + 1]; } n unsigned long long Get(int l, int r) { return B[l] - B[r + 1] * pw[r - l + 1]; } n unsigned long long GET(int l, int r) { n   int tg = L[r - l + 1]; n   return max(mx[l][tg], mx[r - (1 << tg) + 1][tg]); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> m >> n; n   pw[0] = 1; n   P[0] = 1; n   for (int i = 1, _c = 250; i <= _c; ++i) { n     pw[i] = pw[i - 1] * 257; n     L[i] = log2(i); n   } n   for (int i = 1, _c = 25; i <= _c; ++i) P[i] = P[i - 1] * 267; n   for (int i = 1, _c = m; i <= _c; ++i) n     for (int j = 1, _c = n; j <= _c; ++j) cin >> a[i][j]; n   for (int l = 1, _c = n; l <= _c; ++l) n     for (int r = l, _c = n; r <= _c; ++r) { n       if (l == r) { n         memset(o, 0, sizeof(o)); n         memset(g, 0, sizeof(g)); n         memset(sl, 0, sizeof(sl)); n       } n       for (int i = 1, _c = m; i <= _c; ++i) { n         int x = a[i][r] -  a ; n         g[i][x]++; n         if (g[i][x] % 2) n           sl[i]++; n         else n           sl[i]--; n         if (sl[i] > 1) n           mx[i][0] = 1; n         else n           mx[i][0] = 0; n         o[i] = o[i] + P[x] * x; n       } n       for (int j = 1, _c = log2(m); j <= _c; ++j) n         for (int i = 1, _c = m; i <= _c; ++i) n           mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]); n       for (int i = 1, _c = m; i <= _c; ++i) A[i] = A[i - 1] * 257 + o[i]; n       for (int i = m, _c = 1; i >= _c; --i) B[i] = B[i + 1] * 257 + o[i]; n       for (int i = 1, _c = m; i <= _c; ++i) n         if (!mx[i][0]) { n           int l = i, r = min(m, i + (i - 1)), tg = i; n           while (l <= r) { n             int mid = (l + r) / 2; n             if (get(i, mid) == Get(2 * i - mid, i) && !GET(i, mid)) { n               tg = mid; n               l = mid + 1; n             } else n               r = mid - 1; n           } n           kq += (tg - i + 1); n         } n       for (int i = 2, _c = m; i <= _c; ++i) n         if (!mx[i][0] && !mx[i - 1][0] && o[i] == o[i - 1]) { n           int l = i, r = min(m, i + (i - 2)), tg = i; n           while (l <= r) { n             int mid = (l + r) / 2; n             if (get(i, mid) == Get(2 * i - 1 - mid, i - 1) && !GET(i, mid)) { n               tg = mid; n               l = mid + 1; n             } else n               r = mid - 1; n           } n           kq += (tg - i + 1); n         } n     } n   cout << kq; n } n


#include<bits/stdc++.h> n using namespace std; n  n //MACROS n #define ll long long n #define f(i,a,b) for(i=a;i<b;i++) n #define MOD 1000000007 n #define pb push_back n #define mp make_pair n #define INF (int)1e9 n #define deb(x) cout <<  >  << #x <<   :   << x << endl; n #define cjam(t,x) cout <<  Case #  << t <<   :   << x << endl; n #define newl cout<<endl; n #define print(x) for(auto y:x) cout<<y<<   ; newl; n //MACROS n  n // DECIMAL TO BINARY CONVERSION n string toBinary(ll n) n { n     string r; n     while(n!=0) {r=(n%2==0 ? 0 : 1 )+r; n/=2;} n     return r; n } n  n // SEGMENT TREE n struct segtree n { n     int size; n     vector<ll> sums; n  n     void init(int n) n     { n         size = 1; n         while(size<n) size*=2; n         sums.assign(2*size, 0LL); n  n     } n  n     void set(int i, int v, int x, int lx, int rx) n     { n         if(rx-lx == 1) sums[x] = v; n  n         else n         { n             int m = (lx+rx)/2; n  n             if(i<m) n             { n                 set(i, v, 2*x+1, lx, m); n             } n             else n             { n                 set(i, v, 2*x+2, m, rx); n             } n             sums[x] = sums[2*x+1] + sums[2*x+2]; n         } n          n     } n  n     void set(int i, int v) n     { n         set(i ,v, 0, 0, size); n     } n  n  n     ll sum(ll l, ll r, ll x, ll lx, ll rx) n     { n         if(l>=rx || r<=lx) return(0); n         if(l<=lx && r>=rx) return(sums[x]); n  n         ll m = (lx+rx)/2; n  n         ll s1 = sum(l, r, 2*x+1, lx, m); n         ll s2 = sum(l, r, 2*x+2, m, rx); n  n         return(s1+s2); n     } n  n     ll sum(ll l, ll r) n     { n         return(sum(l, r, 0, 0, size));  n     } n      n }; n  n  n //GRAPH n struct graph n { n     bool vis[100000]; n     vector<ll> adj[100000]; n  n     void edge(int a, int b) n     { n         adj[a].push_back(b); n         adj[b].push_back(a); n     } n  n     void dfs(ll s) n     { n         int i; n         vis[s] = 1; n         cout<<s<<   ; n         f(i,0,adj[s].size()) n         { n             if(vis[adj[s][i]] == 0) n                 dfs(adj[s][i]); n         } n     } n }; n  n  n //BINARY SEARCH n ll bsearch(ll arr[], ll n, ll x) n { n     ll l=0, h=n-1; n     while(l<=h) n     { n         ll m = (l+h)/2; n         if(arr[m]==x) n         { n             return(m); n         } n         else if(arr[m]<x) n         { n             l = m+1; n         } n         else n         { n             h = m-1; n         } n     } n     return(-1); n } n  n //nCr in Constant Time n ll const mod = 1e9+7; n ll power(ll a, ll b) n { n     ll res = 1; n     while(b) n     { n         if(b&1) n             res = (res * a) % mod; n         a = (a * a) % mod; n         b /= 2; n     } n     return res; n } n  n ll inverse(ll x){ n     return power(x,mod-2); n } n  n ll const N = 1e6+55; n ll fact[N], ifact[N]; n  n void precompute() n { n     fact[0] = 1; n     for(ll i=1; i<N; i++) n         fact[i] = (fact[i-1] * i) % mod; n      n     ifact[N-1] = inverse(fact[N-1]); n     for(ll i=N-2; i>=0; i--) n         ifact[i] = ((i+1) * ifact[i+1]) % mod; n } n  n ll ncr(ll n, ll r) n { n     if(r<0 or r>n) return 0; n     if(n == r) return 1; n  n     ll res = (fact[n] * ifact[n-r]) % mod; n     res = (res * ifact[r]) % mod; n     return res; n } n  n int sieve[100001]; n  n void prime() n { n     int i,j; n     std::fill_n(sieve, 100000, 1); n     for(i=2;i*i<=100000;i++) n     { n         if(sieve[i]) n         { n             for(j=i*i;j<=100000;j+=i) n             { n                 sieve[j] = 0; n             } n         } n     } n } n  n  n ////////////////////////// n ///////DRIVER CODE//////// n ////////////////////////// n  n int main() n { n     #ifndef ONLINE_JUDGE n     freopen( input.txt , r , stdin); n     freopen( output.txt , w , stdout); n     #endif n  n     ll x,y,z,n,m,q,tt,t,i,j,k; n  n     cin>>tt; n     t=tt; n     while(tt--) n     { n         cin>>n; n         std::vector<ll> v; n         ll f = 1; n         f(i,0,2*n) n         { n             cin>>x; n             if(x&1) f = 0; n             v.pb(x); n         } n          n  n         set<ll> s(v.begin(), v.end()); n  n         if(f==0) n         { n             cout<< NO <<endl; n             continue; n         } n  n  n         if(s.size()!=n) n         { n             cout<< NO <<endl; n             continue; n         } n  n         ll sum = 0; n  n         f = 1; n  n         auto it = s.rbegin(); n  n         f(i,0,n) n         { n             x = *(it++); n             y = (x-sum)/(2*(n-i)); n             z = (x-sum)%(2*(n-i)); n             sum+=2*y; n  n             if(y<=0 or z>0) n             { n                 f = 0; n                 break; n             } n  n         } n  n         if(f) cout<< YES <<endl; n         else cout<< NO <<endl; n  n  n  n  n          n     } n  n }


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007, inf = 1000000000; n const int N = 100010; n inline int read() { n   char ch; n   while (!isdigit(ch = getchar())) n     ; n   int x = ch -  0 ; n   while (isdigit(ch = getchar())) x = (x << 1) + (x << 3) + ch -  0 ; n   return x; n } n int n, cnt; n int a[N], last[N]; n long long f[N][2]; n struct edge { n   int to, next; n } e[N << 1]; n void insert(int u, int v) { n   e[++cnt].to = v; n   e[cnt].next = last[u]; n   last[u] = cnt; n   e[++cnt].to = u; n   e[cnt].next = last[v]; n   last[v] = cnt; n } n void dfs(int x, int fa) { n   long long t1, t2; n   if (a[x] == 1) f[x][1] = 1; n   f[x][0] = f[x][1] ^ 1; n   for (int i = last[x]; i; i = e[i].next) n     if (e[i].to != fa) { n       int y = e[i].to; n       dfs(y, x); n       t1 = f[x][0] * (f[y][0] + f[y][1]); n       t2 = (f[x][1] * (f[y][0] + f[y][1]) + f[x][0] * f[y][1]); n       f[x][0] = t1 % mod; n       f[x][1] = t2 % mod; n     } n } n int main() { n   n = read(); n   for (int i = 1; i < n; i++) insert(read(), i); n   for (int i = 0; i < n; i++) a[i] = read(); n   dfs(0, 0); n   cout << f[0][1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   string str; n   cin >> str; n   vector<int> arr; n   for (int i = 0; i < str.size(); i++) { n     if (str[i] ==  . ) arr.push_back(i + 1); n   } n   for (int i = 0; i + 1 < arr.size(); i++) { n     if (arr[i] + k < arr[i + 1]) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200001]; n int main() { n   long long t, m = 0, i, n, k, ans; n   ; n   scanf( %lld%lld , &n, &k); n   for (i = 0; i < n; i++) scanf( %lld , &a[i]); n   sort(a, a + n); n   for (i = (n + 1) / 2; i < n; i++) { n     t = m; n     m += (a[i] - a[i - 1]) * (i - (n - 1) / 2); n     if (m > k) { n       ans = a[i - 1] + (k - t) / (i - (n - 1) / 2); n       break; n     } n   } n   if (i == n) ans = (k - m) / (n - (n - 1) / 2) + a[n - 1]; n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[4000005], t[4000005]; n long long ans, now; n int k; n template <class T> n inline T Max(T a, T b) { n   return a > b ? a : b; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , a + i); n   int fu = 0, zh = 0; n   for (int i = 1; i <= n; ++i) { n     int qwq = a[i] - i; n     now += qwq < 0 ? -qwq : qwq; n     if (i == n) continue; n     if (qwq <= 0) n       ++fu; n     else n       ++t[a[i] - i], ++zh; n   } n   ans = now; n   int las = n; n   for (int i = 1; i < n; ++i) { n     now += -zh + fu - (n - a[las]) + a[las] - 1; n     fu += t[i]; n     zh -= t[i]; n     if (a[las] != 1) --fu, ++zh; n     ++t[i + a[las] - 1]; n     if (now < ans) ans = now, k = i; n     --las; n   } n   printf( %lld %d n , ans, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void dbvar() { cerr <<  ]  << endl; } n template <class H, class... T> n void dbvar(H h, T... t) { n   cerr << to_string(h); n   if (sizeof...(t)) cerr <<  ,  ; n   dbvar(t...); n } n const int INF = (int)(1e9); n const long long int INFL = (long long int)(1e18); n const long double pi = acos(-1.0); n const int dx[4] = {-1, 0, 1, 0}; n const int dy[4] = {0, 1, 0, -1}; n long long int power(long long int n, long long int m) { n   if (m == 0) return 1; n   long long int val = power(n, m / 2); n   if (m % 2 == 0) n     return (val * val); n   else n     return ((val * val) * n); n } n long long int powermod(long long int n, long long int m, long long int _MOD) { n   if (m == 0) return 1; n   long long int val = powermod(n, m / 2, _MOD); n   val %= _MOD; n   if (m % 2 == 0) n     return (val * val) % _MOD; n   else n     return (((val * val) % _MOD) * n) % _MOD; n } n const int mxN = 2e5 + 100; n vector<int> tree[mxN]; n int depth[mxN], subtree[mxN], ans[mxN]; n void dfs(int v, int p) { n   depth[v] = depth[p] + 1; n   subtree[v] = 1; n   for (auto x : tree[v]) { n     if (x != p) { n       dfs(x, v); n       subtree[v] += subtree[x]; n     } n   } n   ans[v] = subtree[v] - depth[v]; n } n void solve() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     tree[x].push_back(y); n     tree[y].push_back(x); n   } n   depth[0] = 0; n   dfs(1, 0); n   sort(ans + 1, ans + n + 1, greater<int>()); n   long long int res = 0; n   for (int i = 1; i <= n - k; i++) res += ans[i]; n   cout << res <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, test, len; n   string s; n   cin >> test; n   while (test--) { n     cin >> s; n     len = s.length(); n     if (s[len - 2] ==  p  && s[len - 1] ==  o ) { n       cout <<  FILIPINO  << endl; n     } else if (s[len - 4] ==  d  && s[len - 3] ==  e  && s[len - 2] ==  s  && n                s[len - 1] ==  u ) { n       cout <<  JAPANESE  << endl; n     } else if (s[len - 4] ==  m  && s[len - 3] ==  a  && s[len - 2] ==  s  && n                s[len - 1] ==  u ) { n       cout <<  JAPANESE  << endl; n     } else { n       cout <<  KOREAN  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   string s; n   cin >> s; n   for (int cnt1 = 0; cnt1 <= n / a; ++cnt1) { n     for (int cnt2 = 0; cnt2 <= n / b; ++cnt2) n       if (a * cnt1 + b * cnt2 == n) { n         cout << cnt1 + cnt2 << endl; n         for (int i = 0; i < cnt1; ++i) { n           for (int j = 0; j < a; ++j) cout << s[j]; n           cout << endl; n           s.erase(0, a); n         } n         for (int i = 0; i < cnt2; ++i) { n           for (int j = 0; j < b; ++j) cout << s[j]; n           cout << endl; n           s.erase(0, b); n         } n         return 0; n       } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int n; n int a[N]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int ans; n   for (int i = 30; i >= 0; i--) { n     int flag = 0; n     for (int j = 0; j < n; j++) { n       if ((a[j] >> i) & 1) { n         flag++; n         ans = j; n       } n     } n     if (flag == 1) { n       break; n     } n   } n   cout << a[ans] <<    ; n   for (int i = 0; i < n; i++) { n     if (i != ans) { n       cout << a[i] <<    ; n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n char s[10010]; n char s1[10010], s2[10010], s3[10010]; n char ans[10010]; n int main() { n   scanf( %s , s + 1); n   int n = strlen(s + 1); n   for (int i = 1; i <= n; i++) { n     int b1 = i / 26 / 26; n     int b2 = (i / 26) % 26; n     int b3 = i % 26; n     s1[i] = b1 +  a ; n     s2[i] = b2 +  a ; n     s3[i] = b3 +  a ; n   } n   printf( ? %s n , s1 + 1); n   std::fflush(stdout); n   scanf( %s , s1 + 1); n   printf( ? %s n , s2 + 1); n   std::fflush(stdout); n   scanf( %s , s2 + 1); n   printf( ? %s n , s3 + 1); n   std::fflush(stdout); n   scanf( %s , s3 + 1); n   for (int i = 1; i <= n; i++) { n     int b1 = s1[i] -  a ; n     int b2 = s2[i] -  a ; n     int b3 = s3[i] -  a ; n     ans[b1 * 26 * 26 + b2 * 26 + b3] = s[i]; n   } n   printf( ! %s , ans + 1); n   std::fflush(stdout); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> A(n), B(n); n   vector<int> Ai(n - 1), Bi(n - 1); n   int t = 0; n   for (int i = 0; i < n; ++i) { n     cin >> A[i]; n     if (A[i] != 0) { n       Ai[t] = A[i]; n       t++; n     } n   } n   t = 0; n   for (int i = 0; i < n; ++i) { n     cin >> B[i]; n     if (B[i] != 0) { n       Bi[t] = B[i]; n       t++; n     } n   } n   int i0 = 0; n   for (int i = 0; i < n - 1; ++i) { n     if (Bi[i] == Ai[0]) { n       i0 = i; n       break; n     } n   } n   for (int i = 0; i < n - 1; ++i) { n     if (Bi[(i + i0) % (n - 1)] != Ai[i]) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; n bool ckmin(int& a, int b) { return b < a ? a = b, true : false; } n bool ckmax(int& a, int b) { return b > a ? a = b, true : false; } n const long long linf = 4000000000000000000LL; n const long long inf = 1000000007; n const long double pi = 3.1415926535; n void pv(vector<int> a) { n   for (auto& x : a) cout << x <<    ; n   cout <<   n ; n } n void pv(vector<long long> a) { n   for (auto& x : a) cout << x <<    ; n   cout <<   n ; n } n void pv(vector<vector<int> > a) { n   for (int i = (0); i < (int(a.size())); ++i) { n     cout << i <<   n ; n     pv(a[i]); n     cout <<   n ; n   } n } n void pv(vector<vector<long long> > a) { n   for (int i = (0); i < (int(a.size())); ++i) { n     cout << i <<   n ; n     pv(a[i]); n   } n   cout <<   n ; n } n void pv(vector<string> a) { n   for (auto& x : a) cout << x <<   n ; n   cout <<   n ; n } n void setIO(string second) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if (int(second.size())) { n     freopen((second +  .in ).c_str(),  r , stdin); n     if (second !=  test1 ) freopen((second +  .out ).c_str(),  w , stdout); n   } n } n int main() { n   setIO(  ); n   int n; n   cin >> n; n   vector<long long> a(n); n   for (auto& x : a) cin >> x; n   vector<int> count(60); n   for (int i = (0); i < (n); ++i) { n     int ans = 0; n     while (!(a[i] & 1)) { n       ans++; n       a[i] >>= 1; n     } n     a[i] <<= ans; n     count[ans]++; n   } n   int index = max_element(count.begin(), count.end()) - count.begin(); n   cout << n - count[index] <<   n ; n   if (index == 0) { n     for (int i = (0); i < (n); ++i) { n       if (a[i] & 1) n         ; n       else n         cout << a[i] <<    ; n     } n     return 0; n   } n   for (int i = (0); i < (n); ++i) { n     if ((((a[i] >> index) & 1)) && !((a[i] >> index - 1) & 1)) { n     } else { n       cout << a[i] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n int main() { n   scanf( %lld %lld , &n, &k); n   vector<long long> prime; n   for (int i = 2; i <= n; ++i) { n     if (!prime.size()) { n       prime.push_back(i); n       continue; n     } n     bool isPrime = true; n     for (int j = 0; j < prime.size(); ++j) { n       long long now = prime[j]; n       if (now * now > i) break; n       if (!(i % now)) { n         isPrime = false; n         break; n       } n     } n     if (isPrime) prime.push_back(i); n   } n   vector<int> ans; n   for (int i = 0; i < prime.size(); ++i) { n     while (!(n % prime[i]) && k > 1 && n > 1) { n       ans.push_back(prime[i]); n       --k; n       n /= prime[i]; n     } n   } n   if (n == 1) { n     puts( -1 ); n     return 0; n   } n   ans.push_back(n); n   --k; n   for (int i = 0; i < ans.size(); ++i) n     printf( %d%c , ans[i],    n [i + 1 == ans.size()]); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 85 - 69; n long long int a[maxn], su[maxn], dp[maxn]; n int n; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i < n; i++) cin >> a[i]; n   for (int i = n - 1; i > 0; i--) { n     su[i] = su[i + 1] + a[i] - (a[i] & 1); n     if (a[i] == 1) su[i] = 0; n   } n   dp[0] = 0; n   long long int sum = 0, ans = 0; n   for (int i = 1; i < n; i++) { n     sum += a[i] - (a[i] & 1); n     if (a[i] == 1) sum = 0; n     dp[i] = max(dp[i - 1] + a[i] - (a[i] % 2 == 0), sum); n     ans = max(ans, dp[i] + su[i + 1]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF64 = 1e18; n clock_t time_p = clock(); n void time() { n   time_p = clock() - time_p; n   cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ; n } n void doc() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n int main() { n   fast(); n   string s; n   cin >> s; n   long long i, j; n   long long n = s.length(); n   long long m = 0, idx = -1, x = 0, y = 0; n   for (i = 0; i < n; i++) { n     if (s[i] ==  ( ) { n       x++; n       y = 0; n       for (j = i + 1; j < n; j++) { n         if (s[j] ==  ) ) y++; n       } n       if (y >= x) { n         if (x > m) { n           m = x; n           idx = i; n         } n       } n     } n   } n   vector<long long> ans; n   for (i = 0; i <= idx; i++) n     if (s[i] ==  ( ) ans.emplace_back(i + 1); n   for (i = n - 1, j = 0; i >= 0 and j < m; i--) n     if (s[i] ==  ) ) { n       ans.emplace_back(i + 1); n       j++; n     } n   sort(ans.begin(), ans.end()); n   if (ans.size() == 0) { n     cout <<  0 ; n     exit(0); n   } n   cout <<  1  << endl << ans.size() << endl; n   for (auto i : ans) cout << i <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 0, m = 1, i = 0, j = 0, k = 0, x = 0; n   int area[51][51] = {0}; n   cin >> n; n   for (i = 0; i < n; i++) n     for (x = 0; x < n; x++) cin >> area[i][x]; n   for (i = 0; i < n; i++) n     for (x = 0; x < n; x++) n       if (area[i][x] != 1) { n         m = 1; n         for (j = 0; j < n; j++) { n           if (j == i) continue; n           for (k = 0; k < n; k++) { n             if (k == x) continue; n             if (area[i][x] == area[j][x] + area[i][k]) { n               m = 0; n               break; n             } n           } n           if (m == 0) break; n         } n         if (m == 1) { n           cout <<  NO  << endl; n           return 0; n         } n       } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 205; n const long long modulo = 1000000007; n struct point { n   long long x, y; n }; n point operator-(point A, point B) { n   point C; n   C.x = A.x - B.x; n   C.y = A.y - B.y; n   return C; n } n bool operator==(point A, point B) { return (A.x == B.x && A.y == B.y); } n long long cross(point A, point B) { return (A.x * B.y - A.y * B.x); } n long long dot(point A, point B) { return (A.x * B.x + A.y * B.y); } n struct Line { n   long long A, B, C; n   Line(point P, point R) { n     A = R.y - P.y; n     B = P.x - R.x; n     C = (P.y * R.x) - (P.x * R.y); n   } n }; n long long sgn(long long x) { n   if (x > 0) return 1; n   if (x < 0) return -1; n   if (x == 0) return 0; n } n long long f(Line L, point P) { return sgn(L.A * P.x + L.B * P.y + L.C); } n bool OnSegment(point A, point B, point X) { n   if (f(Line(A, B), X) != 0) return false; n   if (dot(A - X, B - X) < 0) n     return true; n   else n     return false; n } n bool intersect(point A, point B, point C, point D) { n   if (A == C || A == D || B == C || B == D) return false; n   if (f(Line(A, B), C) * f(Line(A, B), D) >= 0) return false; n   if (f(Line(C, D), A) * f(Line(C, D), B) >= 0) return false; n   return true; n } n point a[MAXN]; n long long dp[MAXN][MAXN]; n int main() { n   int N; n   cin >> N; n   for (int i = 1; i <= N; i++) { n     cin >> a[i].x >> a[i].y; n   } n   a[N + 1] = a[1]; n   long long Area = 0; n   for (int i = 1; i <= N; i++) { n     Area += cross(a[i], a[i + 1]); n   } n   Area = abs(Area); n   for (int d = 1; d < N - 1; d++) { n     for (int l = 1; l + d <= N; l++) { n       int r = l + d; n       if (d == 1) { n         dp[l][r] = 1; n         continue; n       } else n         dp[l][r] = 0; n       bool bad = false; n       for (int i = 1; i <= N; i++) { n         if (i != l && i != r && OnSegment(a[l], a[r], a[i])) bad = true; n       } n       if (bad) continue; n       for (int i = 1; i <= N; i++) { n         int next = i + 1; n         if (next == N + 1) next = 1; n         if (intersect(a[l], a[r], a[i], a[next])) bad = true; n       } n       if (bad) continue; n       long long AreaX = 0, AreaY = 0; n       for (int i = l; i <= r; i++) { n         int next = i + 1; n         if (next == r + 1) next = l; n         AreaX += cross(a[i], a[next]); n       } n       int j = 1; n       while (j <= N) { n         int next; n         if (j == l) n           next = r; n         else n           next = j + 1; n         if (next == N + 1) next = 1; n         AreaY += cross(a[j], a[next]); n         j = next; n         if (j == 1) j = N + 1; n       } n       if (Area != abs(AreaX) + abs(AreaY)) continue; n       for (int i = l + 1; i < r; i++) { n         dp[l][r] += (dp[l][i] * dp[i][r]) % modulo; n         dp[l][r] = dp[l][r] % modulo; n       } n     } n   } n   dp[1][N] = 0; n   for (int i = 2; i < N; i++) { n     dp[1][N] += (dp[1][i] * dp[i][N]) % modulo; n     dp[1][N] = dp[1][N] % modulo; n   } n   cout << dp[1][N] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 50; n const int maxm = 1e6 + 50; n const double eps = 1e-10; n const int max_index = 62; n const int inf = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n inline int read() { n   char c = getchar(); n   while (!isdigit(c)) c = getchar(); n   int x = 0; n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x; n } n const int offset = 2000; n struct Point { n   int x, y; n   Point(int x = 0, int y = 0) : x(x), y(y) {} n   bool operator<(const Point &rhs) const { n     if (x == rhs.x) return y < rhs.y; n     return x < rhs.x; n   } n } P[205]; n std::vector<int> G[maxm]; n int n, m; n int dis[maxm], vis[maxm]; n int get(int x, int y) { return x * m + y; } n int ans = 0; n void dfs(int u) { n   vis[u] = 1; n   int res = 0; n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i]; n     if (vis[v]) { n       puts( Poor Inna! ); n       exit(0); n     } n     if (!dis[v]) dfs(v); n     res = max(res, dis[v]); n   } n   dis[u] = res + 1; n   vis[u] = 0; n } n int dir[4][2] = {0, -1, -1, 0, 0, 1, 0, -1}; n char mp[1005][1005]; n bool judge(char x, char y) { n   bool ok = 0; n   ok |= (x ==  D  && y ==  I ); n   ok |= (x ==  I  && y ==  M ); n   ok |= (x ==  M  && y ==  A ); n   ok |= (x ==  A  && y ==  D ); n   return ok; n } n int main() { n   n = read(), m = read(); n   for (int i = 0; i < n; i++) scanf( %s , mp[i]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int u = get(i, j); n       for (int k = 0; k < 2; k++) { n         int dx = i + dir[k][0], dy = j + dir[k][1]; n         if (dx < 0 || dy < 0) continue; n         int v = get(dx, dy); n         if (judge(mp[dx][dy], mp[i][j])) { n           G[v].push_back(u); n         } else if (judge(mp[i][j], mp[dx][dy])) { n           G[u].push_back(v); n         } n       } n     } n   } n   for (int i = 0; i < m * n; i++) { n     int x = i / m, y = i % m; n     if (mp[x][y] !=  D ) continue; n     dfs(i); n     ans = max(ans, dis[i]); n   } n   if (ans < 4) n     puts( Poor Dima! ); n   else n     printf( %d n , ans / 4); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n int add(int a, int b) { n   a += b; n   return a >= mod ? a - mod : a; n } n const int MN = 1000011; n int f[MN][2], n; n inline void Main() { n   f[0][0] = f[0][1] = 1; n   scanf( %d , &n); n   for (register int i = (1), _c = (n); i <= _c; i++) n     for (register int j = (0), _c = (1); j <= _c; j++) n       if (f[i - 1][j]) { n         (f[i][j] = add(f[i][j], f[i - 1][j])); n         if (j != i % 2) (f[i][i % 2] = add(f[i][i % 2], f[i - 1][j])); n       } n   register int ans = add(add(f[n][0], f[n][1]), mod - 2); n   printf( %d n , ans); n } n int main() { n   Main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, s, ans, tot, tot1, tot2; n int siz[200010], du[200010], dep[200010], fa[200010][18]; n int q[200010], head[200010], head1[200010], head2[200010], power[18]; n bool v[200010]; n long long dis[200010]; n struct Map { n   int r, len, next; n } line[600010]; n struct Map_sp { n   int r, next; n } line1[600010], line2[600010]; n void add(int x, int y, int len) { n   tot++; n   line[tot].r = y; n   line[tot].len = len; n   line[tot].next = head[x]; n   head[x] = tot; n } n void add1(int x, int y) { n   tot1++; n   line1[tot1].r = y; n   line1[tot1].next = head1[x]; n   head1[x] = tot1; n } n void add2(int x, int y) { n   tot2++; n   line2[tot2].r = y; n   line2[tot2].next = head2[x]; n   head2[x] = tot2; n } n void spfa() { n   for (int i = 1; i <= n; i++) dis[i] = 1e18; n   int hd = 0, tl = 0; n   q[tl++] = s, dis[s] = 0, v[s] = true; n   while (hd != tl) { n     int x = q[hd]; n     for (int i = head[x]; i; i = line[i].next) { n       int rx = line[i].r, len = line[i].len; n       if (dis[x] + len < dis[rx]) { n         dis[rx] = dis[x] + len; n         if (!v[rx]) { n           v[rx] = true; n           q[tl++] = rx; n           if (tl == 200010) tl = 0; n         } n       } n     } n     v[x] = false; n     hd++; n     if (hd == 200010) hd = 0; n   } n } n void build(int x) { n   v[x] = true; n   for (int i = head[x]; i; i = line[i].next) { n     int rx = line[i].r; n     if (dis[x] + line[i].len == dis[rx]) { n       add1(x, rx), add2(rx, x); n       du[rx]++; n       if (!v[rx]) build(rx); n     } n   } n } n void dfs(int x) { n   siz[x] = 1; n   for (int i = head[x]; i; i = line[i].next) { n     int rx = line[i].r; n     dfs(rx); n     siz[x] += siz[rx]; n   } n   if (x != s) ans = max(ans, siz[x]); n } n int lca(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   int tmp = dep[x] - dep[y]; n   for (int i = 0; power[i] <= tmp; i++) n     if (tmp & power[i]) x = fa[x][i]; n   if (x == y) return x; n   for (int i = 17; i >= 0; i--) n     if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i]; n   return fa[x][0]; n } n void topo() { n   int hd = 1, tl = 0; n   q[++tl] = s, dep[s] = 1; n   while (hd <= tl) { n     int x = q[hd]; n     for (int i = head1[x]; i; i = line1[i].next) { n       int rx = line1[i].r; n       du[rx]--; n       if (!du[rx]) { n         q[++tl] = rx; n         int LCA = 0; n         for (int j = head2[rx]; j; j = line2[j].next) n           if (!LCA) n             LCA = line2[j].r; n           else n             LCA = lca(LCA, line2[j].r); n         add(LCA, rx, 0); n         fa[rx][0] = LCA; n         dep[rx] = dep[LCA] + 1; n         for (int j = 1; j <= 17; j++) fa[rx][j] = fa[fa[rx][j - 1]][j - 1]; n       } n     } n     hd++; n   } n } n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) ch = getchar(); n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x; n } n int main() { n   power[0] = 1; n   for (int i = 1; i <= 17; i++) power[i] = power[i - 1] << 1; n   n = read(), m = read(), s = read(); n   for (int i = 1; i <= m; i++) { n     int u = read(), v = read(), w = read(); n     add(u, v, w), add(v, u, w); n   } n   spfa(); n   build(s); n   tot = 0; n   memset(head, 0, sizeof(head)); n   topo(); n   dfs(s); n   printf( %d , ans); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int pri[200050]; n int que[200050]; n int ans[200050]; n int l[200050]; n int r[200050]; n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     for (int i = 1; i <= n; i++) { n       scanf( %d , &pri[i]); n       ans[i] = 0; n       l[i] = r[i] = 1; n     } n     int s = 1, e = 0; n     for (int i = 1; i <= n; i++) { n       while (s <= e && pri[que[e]] >= pri[i]) { n         l[i] = i - que[e] + l[que[e]]; n         e--; n       } n       que[++e] = i; n     } n     s = 1, e = 0; n     for (int i = n; i >= 1; i--) { n       while (s <= e && pri[que[e]] >= pri[i]) { n         r[i] = r[que[e]] + que[e] - i; n         e--; n       } n       que[++e] = i; n     } n     for (int i = 1; i <= n; i++) { n       ans[l[i]] = max(ans[l[i]], pri[i]); n       ans[r[i]] = max(ans[r[i]], pri[i]); n       ans[r[i] + l[i] - 1] = max(ans[r[i] + l[i] - 1], pri[i]); n     } n     for (int i = n - 1; i >= 1; i--) { n       ans[i] = max(ans[i], ans[i + 1]); n     } n     for (int i = 1; i <= n; i++) n       if (i == 1) n         printf( %d , ans[i]); n       else n         printf(  %d , ans[i]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 37; n long long int c[1037][1037]; n int main() { n   for (int i = 0; i < 1037; i++) { n     c[i][0] = 1; n     for (int j = 1; j < i + 1; j++) { n       c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; n     } n   } n   int n, k; n   cin >> n >> k; n   int pole[5] = {0, 0, 1, 2, 9}; n   long long int vys = 1; n   for (int i = 2; i < k + 1; i++) { n     vys += c[n][i] * pole[i]; n   } n   cout << vys << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n using lim = numeric_limits<T>; n const int maxn = 2e5; n int table[maxn * 2 + 2]; n int find(int i) { n   if (table[i] == i) n     return i; n   else n     return table[i] = find(table[i]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   for (int i = 0; i < 2 * maxn + 2; i++) table[i] = i; n   int n, m, q; n   cin >> n >> m >> q; n   int ans = n + m - 1; n   while (q--) { n     int x, y; n     cin >> x >> y; n     x = find(x); n     y = find(y + n); n     if (x == y) continue; n     ans--; n     table[x] = y; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct trio { n   int64_t first, second, trd; n   friend ostream &operator<<(ostream &o, trio &a) { n     o <<  (  << a.first <<  ,  << a.second <<  ,  << a.trd <<  ) ; n     return o; n   } n }; n template <typename T> n inline T max() { n   return numeric_limits<T>::max(); n } n template <typename T> n inline T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <typename T> n inline void get(T &&v) { n   cin >> v; n } n template <typename T, typename... Args> n inline void get(T &&v, Args &&...args) { n   cin >> v; n   get(args...); n } n template <typename T> n inline void put(T &&v) { n   cout << v <<   n ; n } n template <typename T, typename... Args> n inline void put(T &&v, Args &&...args) { n   cout << v <<    ; n   put(args...); n } n template <typename T> n inline void putc(T &&a, const string s =    ) { n   { n     for (auto &v : a) cout << v << s; n   } n   cout <<   n ; n } n ostream &operator<<(ostream &out, pair<int32_t, int32_t> &a) { n   out <<  (  << a.first <<  ,  << a.second <<  ) ; n   return out; n } n ostream &operator<<(ostream &out, pair<int64_t, int64_t> &a) { n   out <<  (  << a.first <<  ,  << a.second <<  ) ; n   return out; n } n vector<int32_t> primes; n inline void calc_primes(int32_t lmt) { n   vector<char> s(lmt); n   primes.push_back(2); n   for (int32_t i = 3; i < lmt; i += 2) { n     if (s[i]) continue; n     primes.push_back(i); n     for (int32_t j = i + (i << 1); j < lmt; j += (i << 1)) s[j] = 1; n   } n } n inline vector<pair<int32_t, int32_t> > factorize(int32_t n) { n   vector<pair<int32_t, int32_t> > a; n   int32_t cnt = __builtin_ctzl(n); n   a.push_back({2, cnt}); n   n >>= cnt; n   for (auto &d : primes) { n     cnt = 0; n     while (n % d == 0) n /= d, cnt++; n     a.push_back({d, cnt}); n     if (n == 1) break; n   } n   if (n != 1) a.push_back({n, 1}); n   return a; n } n int64_t mod = 1e9 + 9; n inline int64_t mmul(int64_t a, int64_t n) { n   if (a < 0) a += mod; n   if (n < 0) n += mod; n   int64_t r = 0; n   while (n) { n     if (n & 1) r = (r + a) % mod; n     a = (a + a) % mod; n     n >>= 1; n   } n   return r; n } n inline int64_t mpow(int64_t a, int64_t n) { n   if (a < 0) a += mod; n   if (n < 0) n += mod; n   int64_t r = 1; n   while (n) { n     if (n & 1) r = mmul(r, a); n     a = mmul(a, a); n     n >>= 1; n   } n   return r; n } n int main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr); n     cout << setprecision(20); n   }; n   int64_t n, a, b, k; n   get(n, a, b, k); n   int64_t inv_a = mpow(a, mod - 2); n   int64_t aa = mpow(a, n); n   int64_t bb = 1; n   int64_t z = 0; n   for (int64_t i = 0; i < k; ++i) { n     char c; n     cin >> c; n     int64_t sgn = (c ==  +  ? 1 : -1); n     z = (z + sgn * mmul(aa, bb)) % mod; n     aa = mmul(aa, inv_a); n     bb = mmul(bb, b); n   } n   int64_t q = mmul(bb, mpow(inv_a, k)); n   int64_t s = 0, t = (n + 1) / k; n   if (q == 1) n     s = t; n   else n     s = mmul((mod + 1 - mpow(q, t)), mpow(mod + 1 - q, mod - 2)); n   z = mmul(z, s); n   if (z < 0) z += mod; n   put(z); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n const int N = 101000; n int n, val[N]; n pair<int, int> p[N]; n long long A, cf, cm, m, s[N]; n int main() { n   scanf( %d%lld%lld%lld%lld , &n, &A, &cf, &cm, &m); n   for (int i = 1; i < n + 1; i++) { n     scanf( %d , &p[i].first); n     p[i].second = i; n   } n   sort(p + 1, p + n + 1); n   p[n + 1].first = A; n   for (int i = 1; i < n + 1; i++) s[i] = s[i - 1] + p[i].first; n   long long ans = 0; n   int ansp = 0, ansl = 0, ansv = 0; n   if (n * A - s[n] <= m) { n     ans = A * cm + n * cf; n     ansp = 0; n     ansl = 0; n     ansv = 0; n   } n   for (int i = 1; i < n + 1; i++) { n     long long c = (n - i) * A - (s[n] - s[i]); n     if (c > m) continue; n     long long rm = m - c; n     int l = 1, r = i + 1; n     while (l + 1 < r) { n       int md = (l + r) >> 1; n       long long sm = (long long)p[md].first * md - s[md]; n       if (sm <= rm) n         l = md; n       else n         r = md; n     } n     rm -= ((long long)p[l].first * l - s[l]); n     long long nv = p[l + 1].first; n     if (l == i) nv = A; n     long long mm = min(p[l].first + rm / l, nv); n     long long ret = mm * cm + (n - i) * cf; n     if (ret >= ans) { n       ans = ret; n       ansp = i; n       ansl = l; n       ansv = mm; n     } n   } n   printf( %lld n , ans); n   for (int i = ansp + 1; i < n + 1; i++) p[i].first = A; n   for (int i = 1; i < ansl + 1; i++) p[i].first = ansv; n   for (int i = 1; i < n + 1; i++) val[p[i].second] = p[i].first; n   for (int i = 1; i < n + 1; i++) printf( %d  , val[i]); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int x_search(const int &down, const int &up, const int &c) { n   int l = down, r = up, key = 0; n   while (l <= r) { n     int mid = (l + r) / 2, cnt; n     cout <<  ?   << mid <<     << 1 <<     << n <<     << n <<   n ; n     cin >> cnt; n     if (cnt >= c) { n       key = mid; n       l = mid + 1; n     } else n       r = mid - 1; n   } n   return key; n } n int u_search(const int &left, const int &right, const int &c) { n   int l = left, r = right, key = right + 1; n   while (l <= r) { n     int mid = (l + r) / 2, cnt; n     cout <<  ?   << 1 <<     << 1 <<     << mid <<     << n <<   n ; n     cin >> cnt; n     if (cnt >= c) { n       key = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   return key; n } n int y_search(const int &left, const int &right, const int &c) { n   int l = left, r = right, key = 0; n   while (l <= r) { n     int mid = (l + r) / 2, cnt; n     cout <<  ?   << 1 <<     << mid <<     << n <<     << n <<   n ; n     cin >> cnt; n     if (cnt >= c) { n       key = mid; n       l = mid + 1; n     } else n       r = mid - 1; n   } n   return key; n } n int v_search(const int &left, const int &right, const int &c) { n   int l = left, r = right, key = right + 1; n   while (l <= r) { n     int mid = (l + r) / 2, cnt; n     cout <<  ?   << 1 <<     << 1 <<     << n <<     << mid <<   n ; n     cin >> cnt; n     if (cnt >= c) { n       key = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   return key; n } n void check(int x_1, int y_1, int u_1, int v_1, int x_2, int y_2, int u_2, n            int v_2) { n   if (x_1 > u_1 || y_1 > v_1 || x_2 > u_2 || y_2 > v_2) return; n   int c1, c2; n   cout <<  ?   << x_1 <<     << y_1 <<     << u_1 <<     << v_1 <<   n ; n   cin >> c1; n   cout <<  ?   << x_2 <<     << y_2 <<     << u_2 <<     << v_2 <<   n ; n   cin >> c2; n   if (c1 == 1 && c2 == 1) n     cout <<  !   << x_1 <<     << y_1 <<     << u_1 <<     << v_1 <<     << x_2 n          <<     << y_2 <<     << u_2 <<     << v_2 <<   n ; n } n int main() { n   cin >> n; n   int x_1 = x_search(1, n, 2), x_2 = x_search(x_1, n, 1), n       u_2 = u_search(1, n, 2), u_1 = u_search(1, u_2, 1), n       y_1 = y_search(1, n, 2), y_2 = y_search(y_1, n, 1), n       v_2 = v_search(1, n, 2), v_1 = v_search(1, v_2, 1); n   int c; n   check(x_1, y_1, u_1, v_1, x_2, y_2, u_2, v_2); n   check(x_1, y_1, u_2, v_1, x_2, y_2, u_1, v_2); n   check(x_1, y_1, u_1, v_2, x_2, y_2, u_2, v_1); n   check(x_1, y_1, u_2, v_2, x_2, y_2, u_1, v_1); n   check(x_1, y_2, u_1, v_1, x_2, y_1, u_2, v_2); n   check(x_1, y_2, u_2, v_1, x_2, y_1, u_1, v_2); n   check(x_1, y_2, u_1, v_2, x_2, y_1, u_2, v_1); n   check(x_1, y_2, u_2, v_2, x_2, y_1, u_1, v_1); n } n


#include <bits/stdc++.h> n using namespace std; n constexpr long long int mod = 1e9 + 7; n constexpr long long int MAXN = 1e6 + 3; n constexpr long long int inf = 1ll << 32; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> vx(n + 2); n   int med = 0; n   for (int c = 1; c <= n; c++) { n     cin >> vx[c]; n     vx[c] += vx[c - 1]; n   } n   if (vx[n] % 2 == 0) n     med = vx[n] / 2; n   else n     med = vx[n] / 2 + 1; n   for (int c = 1; c <= n; c++) n     if (vx[c] >= med) { n       cout << c; n       return 0; n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int pos[11][1111]; n int gra[1111][1111]; n int main() { n   int n, m; n   cin >> n >> m; n   int x; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       cin >> x; n       pos[i][x - 1] = j; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       int flag = 1; n       for (int k = 0; k < m; k++) { n         flag &= (pos[k][i] < pos[k][j]); n       } n       if (flag == true) n         gra[i][j] = 1; n       else n         gra[i][j] = -INF; n     } n   } n   for (int k = 0; k < n; k++) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         gra[i][j] = max(gra[i][j], gra[i][k] + gra[k][j]); n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       ans = max(ans, gra[i][j]); n     } n   } n   cout << ans + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n using ll = long long; n using ii = pair<int, int>; n using uint = unsigned int; n const int N = 1e5 + 5, MOD = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> deg(n + 1); n   for (int i = 1, u, v; i < n; i++) { n     cin >> u >> v; n     deg[u]++; n     deg[v]++; n   } n   if (find(deg.begin(), deg.end(), 2) == deg.end()) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y; n set<pair<int, int> > S, T; n int solve(set<pair<int, int> >& s, set<pair<int, int> >& t) { n   set<pair<int, int> >::iterator it1, it2, it3, it4; n   it1 = s.begin(); n   it2 = s.end(); n   it2--; n   it3 = t.begin(); n   it4 = t.end(); n   it4--; n   while (it1->first < it2->first || it3->first < it4->first) { n     int x = it1->first; n     int xx = (++it1)->first; n     if (xx > x + 1) { n       set<pair<int, int> > res_s; n       set<pair<int, int> > res_t; n       while (1) { n         it1 = s.begin(); n         if (it1->first == xx) break; n         res_s.insert(make_pair(it1->first, it1->second)); n         res_t.insert(make_pair(it1->second, it1->first)); n         s.erase(make_pair(it1->first, it1->second)); n         t.erase(make_pair(it1->second, it1->first)); n       } n       return solve(s, t) + solve(res_s, res_t); n     } n     x = it2->first; n     xx = (--it2)->first; n     if (xx < x - 1) { n       set<pair<int, int> > res_s; n       set<pair<int, int> > res_t; n       while (1) { n         it2 = s.end(); n         it2--; n         if (it2->first == xx) break; n         res_s.insert(make_pair(it2->first, it2->second)); n         res_t.insert(make_pair(it2->second, it2->first)); n         s.erase(make_pair(it2->first, it2->second)); n         t.erase(make_pair(it2->second, it2->first)); n       } n       return solve(s, t) + solve(res_s, res_t); n     } n     int y = it3->first; n     int yy = (++it3)->first; n     if (yy > y + 1) { n       set<pair<int, int> > res_s; n       set<pair<int, int> > res_t; n       while (1) { n         it3 = t.begin(); n         if (it3->first == yy) break; n         res_s.insert(make_pair(it3->second, it3->first)); n         res_t.insert(make_pair(it3->first, it3->second)); n         s.erase(make_pair(it3->second, it3->first)); n         t.erase(make_pair(it3->first, it3->second)); n       } n       return solve(s, t) + solve(res_s, res_t); n     } n     y = it4->first; n     yy = (--it4)->first; n     if (yy < y - 1) { n       set<pair<int, int> > res_s; n       set<pair<int, int> > res_t; n       while (1) { n         it4 = t.end(); n         it4--; n         if (it4->first == yy) break; n         res_s.insert(make_pair(it4->second, it4->first)); n         res_t.insert(make_pair(it4->first, it4->second)); n         s.erase(make_pair(it4->second, it4->first)); n         t.erase(make_pair(it4->first, it4->second)); n       } n       return solve(s, t) + solve(res_s, res_t); n     } n   } n   return 1; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &x, &y); n     S.insert(make_pair(x, y)); n     T.insert(make_pair(y, x)); n   } n   printf( %d n , solve(S, T)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, sn, i, j, sum, temp, nl; n map<int, int> myMap; n vector<int> t[105]; n int main() { n   cin >> n; n   j = 0; n   sn = n * n; n   for (i = sn; i > sn / 2; i--) { n     t[j % n].push_back(i); n     t[j % n].push_back(sn - i + 1); n     j++; n   } n   for (i = 0; i < n; i++) { n     nl = t[i].size(); n     for (j = 0; j < nl; j++) cout << t[i][j] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Number[12][12]; n int Next[110]; n double dp[110]; n int main() { n   for (int i = 1; i <= 10; i++) n     for (int j = 1; j <= 10; j++) n       Number[i][j] = (10 - i) * 10 + (i % 2 == 0 ? j : 11 - j); n   for (int i = 1; i <= 10; i++) { n     for (int j = 1; j <= 10; j++) { n       int x; n       scanf( %d , &x); n       if (x == 0) n         Next[Number[i][j]] = Number[i][j]; n       else n         Next[Number[i][j]] = Number[i - x][j]; n     } n   } n   dp[100] = 0; n   double c = 1; n   for (int i = 99; i >= 94; i--) { n     dp[i] = (c + 6 - (100 - i)) / (100 - i); n     c += dp[i] + 1; n   } n   for (int i = 93; i >= 1; i--) { n     double temp = 0; n     for (int j = 1; j <= 6; j++) temp += min(dp[i + j], dp[Next[i + j]]); n     dp[i] = temp / 6 + 1; n   } n   printf( %.10f n , dp[1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     if (a < b) swap(a, b); n     if (c < d) swap(c, d); n     cout << ((a == c && b + d == a) ?  Yes n  :  No n ); n   } n } n


#include <bits/stdc++.h> n int main() { n   int64_t d1, d2, d3; n   std::cin >> d1 >> d2 >> d3; n   int64_t dist = d1 + d2 + d3; n   dist = std::min(dist, 2 * d1 + 2 * d2); n   dist = std::min(dist, 2 * d1 + 2 * d3); n   dist = std::min(dist, 2 * d2 + 2 * d3); n   std::cout << dist << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2e9; n long long gcd(long long a, long long b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n int main() { n   long long l, r, x, y; n   cin >> l >> r >> x >> y; n   long long d = 1; n   long long res = 0; n   map<int, int> m; n   while (d * d <= y) { n     if (y % d == 0) { n       if (!m[min(y / d, d * x)] && d * x >= l && d * x <= r && y / d >= l && n           y / d <= r && gcd(d * x, y / d) == x) { n         res++; n         if (d * x != y / d) res++; n         m[min(y / d, d * x)]++; n       } n     } n     d++; n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e2; n pair<pair<int, int>, bool> pr[maxn][maxn][2]; n queue<pair<pair<int, int>, bool> > q; n vector<int> neighbor[maxn]; n void bfs(int s, int t) { n   for (int i = 0; i < maxn; i++) n     for (int j = 0; j < maxn; j++) n       for (int k = 0; k < 2; k++) n         pr[i][j][k] = make_pair(make_pair(-1, -1), false); n   q.push(make_pair(make_pair(s, t), 0)); n   while (!q.empty()) { n     int v = q.front().first.second, u = q.front().first.first; n     bool b = q.front().second; n     q.pop(); n     if (!b) { n       for (int i = 0; i < neighbor[u].size(); i++) n         if (pr[neighbor[u][i]][v][!b].first.first == -1) { n           pr[neighbor[u][i]][v][!b] = make_pair(make_pair(u, v), b); n           q.push(make_pair(make_pair(neighbor[u][i], v), !b)); n         } n     } else { n       for (int i = 0; i < neighbor[v].size(); i++) n         if (pr[u][neighbor[v][i]][!b].first.first == -1 && n             neighbor[v][i] != u && (u != s || neighbor[v][i] != t)) { n           pr[u][neighbor[v][i]][!b] = make_pair(make_pair(u, v), b); n           q.push(make_pair(make_pair(u, neighbor[v][i]), !b)); n         } n     } n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     neighbor[u - 1].push_back(v - 1); n     neighbor[v - 1].push_back(u - 1); n   } n   bfs(0, n - 1); n   if (pr[n - 1][0][0].first.first == -1) n     cout << -1; n   else { n     vector<int> fi, se; n     pair<pair<int, int>, bool> kl = make_pair(make_pair(n - 1, 0), 0); n     while (kl.first.first != -1) { n       if (kl.second) n         se.push_back(kl.first.second); n       else n         fi.push_back(kl.first.first); n       kl = pr[kl.first.first][kl.first.second][kl.second]; n     } n     cout << fi.size() - 1 << endl; n     for (int i = fi.size() - 1; i > -1; i--) cout << fi[i] + 1 <<    ; n     cout << endl; n     for (int i = se.size() - 1; i > -1; i--) cout << se[i] + 1 <<    ; n     cout << 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n pair<long long, long long> seg[500000 + 1]; n long long dp[20 + 1][500000 + 1]; n signed main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (long long i = 1; i < n + 1; i++) { n     long long l, r; n     cin >> l >> r; n     seg[i] = {l, r}; n     if (dp[0][l] < r) { n       dp[0][l] = r; n     } n   } n   for (long long i = 1; i < 500000 + 1; i++) { n     dp[0][i] = max(dp[0][i], dp[0][i - 1]); n     if (dp[0][i] < i) dp[0][i] = 0; n   } n   for (long long i = 1; i < 20 + 1; i++) { n     for (long long j = 0; j < 500000 + 1; j++) { n       dp[i][j] = dp[i - 1][dp[i - 1][j]]; n       if (dp[i][j] < j) dp[i][j] = 0; n     } n   } n   for (long long j = 1; j < m + 1; j++) { n     long long x, y; n     cin >> x >> y; n     long long ans = 0; n     for (long long i = 20; i >= 0; i--) { n       if (dp[i][x] < y and dp[i][x] != 0) { n         ans += (1 << i); n         x = dp[i][x]; n       } n     } n     if (dp[0][x] >= y) n       cout << ans + 1 <<   n ; n     else n       cout << -1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int param[51][51], n, targ; n vector<int> visted(51); n stack<int> s; n bool dfs(int root) { n   if (root == targ) { n     return true; n   } n   if (visted[root] == 0) s.push(root); n   visted[root] = 1; n   int nxt = -1; n   for (int i = 1; i <= n; i++) { n     if (param[root][i] == 1 && visted[i] == 0) { n       nxt = i; n     } n   } n   if (nxt == -1 && s.size() > 1) { n     s.pop(); n     nxt = s.top(); n   } n   if (nxt != -1) n     dfs(nxt); n   else n     return false; n } n int GetNumberOfDigits(int i) { return i > 0 ? (int)log2(i) + 1 : 1; } n int main() { n   int n, m, d, mx = 0, ret = 0; n   vector<int> v; n   cin >> n >> m; n   for (int i = int(0); i < int(n); i++) { n     cin >> d; n     v.push_back(d); n   } n   int tm; n   mx = m; n   for (int i = int(0); i < int(n); i++) { n     tm = m; n     if (v[i] <= tm) { n       ret = tm / v[i]; n       tm -= (ret * v[i]); n     } else { n       continue; n     } n     for (int j = int(i + 1); j < int(n); j++) { n       int x = v[j] * ret + tm; n       if (mx < x) mx = x; n     } n   } n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 1e9 + 7; n const int N = 1e6 + 5, M = 1e5 + 10, NM1 = N - 1; n long long int OO = 1e18 + 8; n int oo = 1e9 + 8; n void readFile() {} n int n, m, l, r, x, top, arr[N], st[N]; n long long int sum[N]; n int main() { n   readFile(); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , arr + i); n   for (int i = 1; i <= n + 1; i++) { n     while (arr[i] < arr[st[top]]) { n       l = st[top] - st[top - 1]; n       r = i - st[top]; n       sum[1] += x = arr[st[top--]]; n       sum[l + 1] -= x; n       sum[r + 1] -= x; n       sum[l + r + 1] += x; n     } n     st[++top] = i; n   } n   for (int i = 1; i <= n; i++) sum[i] += sum[i - 1]; n   for (int i = 1; i <= n; i++) sum[i] += sum[i - 1]; n   scanf( %d , &m); n   for (int i = 0; i < m; i++) { n     scanf( %d , &x); n     printf( %0.12f n , (double)sum[x] / (n - x + 1.0)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n, k; n   int v[200001]; n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , v + i); n   sort(v, v + n); n   int l = 1; n   int r = 1000000000; n   int m; n   for (int it = 0; l <= r and it < 50; it++) { n     m = l + (r - l) / 2; n     auto i = upper_bound(v, v + n, m); n     if ((i - v) > k) n       r = m; n     else if ((i - v) == k) n       break; n     else n       l = m + 1; n   } n   auto i = upper_bound(v, v + n, m); n   if ((i - v) == k and (m > 0 and m <= 1000000000)) n     printf( %d n , m); n   else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 2e5 + 7; n struct Edge { n   int t, next; n } edge[MAXN << 1]; n int head[MAXN], cnt; n int size[MAXN]; n int dfn[MAXN], pos[MAXN], ts = 0; n int n, m; n int dist[MAXN], deep[MAXN]; n int f[MAXN][19]; n int t1 = 1, t2 = 1; n struct SegmentTree; n struct Questions; n SegmentTree *newNode(int, int, SegmentTree *, SegmentTree *); n struct SegmentTree { n   int l, r, mid; n   SegmentTree *lc, *rc; n   int val, add, max; n   static SegmentTree *build(int l, int r) { n     SegmentTree *ret = NULL; n     if (l == r) { n       ret = newNode(l, r, NULL, NULL); n       ret->val = ret->max = dist[pos[l]]; n       return ret; n     } else { n       int mid = l + (r - l) / 2; n       ret = newNode(l, r, build(l, mid), build(mid + 1, r)); n       ret->pushUp(); n       return ret; n     } n   } n   void pushUp() { max = std::max(lc->max, rc->max); } n   void pushDown() { n     if (add) { n       lc->plus(add), rc->plus(add); n       add = 0; n     } n   } n   void plus(int a) { n     if (l == r) val += a; n     add += a; n     max += a; n   } n   void solveAdd(int left, int right, int delta) { n     if (l == left && r == right) return plus(delta); n     pushDown(); n     if (right <= mid) n       lc->solveAdd(left, right, delta); n     else if (left > mid) n       rc->solveAdd(left, right, delta); n     else n       lc->solveAdd(left, mid, delta), rc->solveAdd(mid + 1, right, delta); n     pushUp(); n   } n   int queryMax(int left, int right) { n     if (l == left && r == right) return max; n     pushDown(); n     if (right <= mid) n       return lc->queryMax(left, right); n     else if (left > mid) n       return rc->queryMax(left, right); n     else n       return std::max(lc->queryMax(left, mid), rc->queryMax(mid + 1, right)); n   } n } * root, pool[MAXN], *tail = pool; n SegmentTree *newNode(int l, int r, SegmentTree *lc, SegmentTree *rc) { n   SegmentTree *ret = ++tail; n   ret->l = l, ret->r = r, ret->mid = l + (r - l) / 2; n   ret->lc = lc, ret->rc = rc; n   ret->val = 0, ret->add = 0, ret->max = INT_MIN; n   return ret; n } n struct Questions { n   int u, v, mid; n } q[MAXN]; n struct Ans { n   int r, node, pos, ans; n } a1[MAXN], a2[MAXN]; n std::vector<Ans> v1[MAXN], v2[MAXN]; n void add(int u, int v) { n   cnt++; n   edge[cnt].t = v; n   edge[cnt].next = head[u]; n   head[u] = cnt; n } n void dfs1(int u, int pre) { n   f[u][0] = pre; n   dfn[u] = ++ts; n   size[u] = 1; n   pos[ts] = u; n   for (int e = head[u]; e; e = edge[e].next) { n     int v = edge[e].t; n     if (v == pre) continue; n     dist[v] = dist[u] + 1; n     deep[v] = deep[u] + 1; n     dfs1(v, u); n     size[u] += size[v]; n   } n } n int getLca(int x, int y) { n   if (deep[x] > deep[y]) std::swap(x, y); n   for (int i = 18; i >= 0; i--) { n     if (deep[f[y][i]] >= deep[x]) y = f[y][i]; n   } n   if (x == y) return x; n   for (int i = 18; i >= 0; i--) { n     if (f[x][i] != f[y][i]) { n       x = f[x][i]; n       y = f[y][i]; n     } n   } n   return f[x][0]; n } n int getMid(int u, int len) { n   int e = 0; n   while (len) { n     if (len & 1) u = f[u][e]; n     len >>= 1; n     e++; n   } n   return u; n } n void dfs2(int u, int pre) { n   while (a1[t1].r == u && t1 <= m) { n     a1[t1].ans = root->queryMax(dfn[a1[t1].node], n                                 dfn[a1[t1].node] + size[a1[t1].node] - 1); n     t1++; n   } n   while (a2[t2].r == u && t2 <= m) { n     if (dfn[a2[t2].node] > 1) n       a2[t2].ans = n           std::max(a2[t2].ans, root->queryMax(1, dfn[a2[t2].node] - 1)); n     if (dfn[a2[t2].node] + size[a2[t2].node] - 1 < n) n       a2[t2].ans = std::max( n           a2[t2].ans, root->queryMax(dfn[a2[t2].node] + size[a2[t2].node], n)); n     t2++; n   } n   for (int e = head[u]; e; e = edge[e].next) { n     int v = edge[e].t; n     if (v == pre) continue; n     root->solveAdd(dfn[v], dfn[v] + size[v] - 1, -1); n     if (dfn[v] > 1) root->solveAdd(1, dfn[v] - 1, 1); n     if (dfn[v] + size[v] - 1 < n) root->solveAdd(dfn[v] + size[v], n, 1); n     dfs2(v, u); n     root->solveAdd(dfn[v], dfn[v] + size[v] - 1, 1); n     if (dfn[v] > 1) root->solveAdd(1, dfn[v] - 1, -1); n     if (dfn[v] + size[v] - 1 < n) root->solveAdd(dfn[v] + size[v], n, -1); n   } n } n bool cmp1(Ans x, Ans y) { n   if (dfn[x.r] == dfn[y.r]) return dfn[x.node] < dfn[y.node]; n   return dfn[x.r] < dfn[y.r]; n } n bool cmp2(Ans x, Ans y) { return x.pos < y.pos; } n int main(int argc, char *argv[]) { n   scanf( %d , &n); n   int u, v; n   for (int i = 1; i <= n - 1; i++) { n     scanf( %d %d , &u, &v); n     add(u, v); n     add(v, u); n   } n   deep[1] = 1; n   dfs1(1, 0); n   root = SegmentTree::build(1, n); n   for (int j = 1; j <= 18; j++) { n     for (int i = 1; i <= n; i++) { n       f[i][j] = f[f[i][j - 1]][j - 1]; n     } n   } n   int lca, len, mid; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d %d , &u, &v); n     lca = getLca(u, v); n     len = dist[u] + dist[v] - 2 * dist[lca]; n     if (deep[u] < deep[v]) std::swap(u, v); n     mid = getMid(u, (len - 1) / 2); n     q[i] = Questions{u, v, mid}; n     a1[i] = Ans{u, mid, i, INT_MIN}; n     a2[i] = Ans{v, mid, i, INT_MIN}; n   } n   std::sort(a1 + 1, a1 + m + 1, cmp1); n   std::sort(a2 + 1, a2 + m + 1, cmp1); n   dfs2(1, 0); n   std::sort(a1 + 1, a1 + m + 1, cmp2); n   std::sort(a2 + 1, a2 + m + 1, cmp2); n   for (int i = 1; i <= m; i++) { n     printf( %d n , std::max(a1[i].ans, a2[i].ans)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n vector<vector<int>> edges; n long long DP[200010]; n long long fac[200010]; n void solve(const int u, const int p) { n   DP[u] = 1; n   int tot = 0; n   for (auto& e : edges[u]) { n     if (e != p) { n       tot++; n       solve(e, u); n       DP[u] = (DP[u] * DP[e]) % MOD; n     } n   } n   DP[u] = (DP[u] * fac[tot]) % MOD; n   if (u != 1 && tot) DP[u] = ((tot + 1) * DP[u]) % MOD; n } n int main() { n   fac[0] = 1; n   for (int i = 1; i <= 200000; i++) fac[i] = (fac[i - 1] * i) % MOD; n   int N, t, f; n   scanf( %d , &N); n   edges.assign(N + 5, vector<int>()); n   for (int i = 0; i < N - 1; i++) { n     scanf( %d %d , &t, &f); n     edges[t].push_back(f); n     edges[f].push_back(t); n   } n   solve(1, 1); n   printf( %d n , int((N * DP[1]) % MOD)); n   return 0; n } n


#include <bits/stdc++.h> n long long int lcm, k, ans, a, b; n using namespace std; n int main() { n   int n; n   cin >> n; n   map<int, int> mp; n   mp[n] = 1; n   n++; n   int c = 1; n   while (1) { n     if (mp[n] == 1 && n % 10 != 0) n       break; n     else { n       if (n % 10 == 0) { n         while (n % 10 == 0) n /= 10; n       } else { n         mp[n] = 1; n         n++; n         c++; n       } n     } n   } n   cout << c <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = acos(-1); n const long long md = 1e9 + 7; n long long r, b, i, x, y; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> r >> b; n   for (i = 1; i <= r + b; i++) cin >> x >> y; n   cout << (r == b ?  Yes  :  No ) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, kecil, tamp1 = 0, tamp2 = 0, tambah = 0; n   cin >> n; n   cin >> m; n   tamp1 = n; n   tamp2 = m; n   while (n != 0) { n     n = tamp1; n     if (tambah >= 1) m += tamp2; n     if (m > n) { n       cout << -1; n       return 0; n     } n     for (int i = 0; i < m; i++) { n       if (n == m - i) n         n -= 1; n       else n         n -= 2; n     } n     tambah++; n   } n   cout << m; n } n


#include <bits/stdc++.h> n using namespace std; n void input(long long ara[], long long n) { n   for (long long i = 0; i < n; i++) cin >> ara[i]; n } n void output(long long ara[], long long n) { n   for (long long i = 0; i < n; i++) cout << ara[i] <<    ; n } n long long mx1(long long ara[], long long n) { n   long long mx = -1; n   for (long long i = 0; i < n; i++) n     if (ara[i] > mx) mx = ara[i]; n   return mx; n } n long long mn1(long long ara[], long long n) { n   long long mn = 1e18; n   for (long long i = 1; i <= n; i++) n     if (ara[i] < mn) mn = ara[i]; n   return mn; n } n int maxSubArraySum(long long a[], long long size) { n   long long max_so_far = INT_MIN, max_ending_here = 0; n   for (long long i = 0; i < size; i++) { n     max_ending_here = max_ending_here + a[i]; n     if (max_so_far < max_ending_here) max_so_far = max_ending_here; n     if (max_ending_here < 0) max_ending_here = 0; n   } n   return max_so_far; n } n int main() { n   (ios_base::sync_with_stdio(false), cin.tie(NULL)); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long ara[n + 1]; n     input(ara, n); n     long long k = 0, sum = 0; n     for (long long i = 0; i < n; i++) { n       sum += ara[i]; n       if (sum <= 0) { n         k = 1; n       } n     } n     sum = 0; n     for (long long i = n - 1; i >= 0; i--) { n       sum += ara[i]; n       if (sum <= 0) { n         k = 1; n         break; n       } n     } n     if (k == 1) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n __int128 read() { n   __int128 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 void print(__int128 x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) print(x / 10); n   putchar(x % 10 +  0 ); n } n __int128 gcd(__int128 a, __int128 b) { return b ? gcd(b, a % b) : a; } n __int128 ex_gcd(__int128 a, __int128 b, __int128& x, __int128& y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   __int128 d = ex_gcd(b, a % b, x, y); n   __int128 temp = x; n   x = y; n   y = temp - a / b * y; n   return d; n } n bool liEu(__int128 a, __int128 b, __int128 c, __int128& x, __int128& y) { n   __int128 d = ex_gcd(a, b, x, y); n   if (c % d != 0) return 0; n   __int128 k = c / d; n   x *= k; n   y *= k; n   return 1; n } n signed main() { n   __int128 n, p, w, d; n   n = read(); n   p = read(); n   w = read(); n   d = read(); n   __int128 x, y; n   if (!liEu(w, d, p, x, y)) return (std::cout <<  -1 n , 0); n   __int128 t = d / gcd(w, d); n   __int128 xt = (x % t + t) % t; n   __int128 yt = (p - w * xt) / d; n   if (xt >= 0 && yt >= 0 && xt + yt <= n) { n     print(xt); n     printf(   ); n     print(yt); n     printf(   ); n     print(n - xt - yt); n     printf(  n ); n     return 0; n   } n   t = w / gcd(w, d); n   yt = (y % t + t) % t; n   xt = (p - d * yt) / w; n   if (xt >= 0 && yt >= 0 && xt + yt <= n) { n     print(xt); n     printf(   ); n     print(yt); n     printf(   ); n     print(n - xt - yt); n     printf(  n ); n     return 0; n   } n   std::cout << -1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1); n const double eps = 1e-6; n const long long INF = 0x3f3f3f3f3f3f3f3fll; n const int inf = 0x3f3f3f3f; n const int mod = 998244353; n const int maxn = 1e6 + 100; n long long qpow(long long a, long long b) { n   long long ret = 1; n   a %= mod; n   while (b) { n     if (b & 1) ret = ret * a % mod; n     b /= 2; n     a = a * a % mod; n   } n   return ret; n } n void solve() { n   long long w, h; n   scanf( %lld%lld , &w, &h); n   cout << qpow(2LL, w + h) << endl; n } n int main() { n   solve(); n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; 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(0); n   int n; n   cin >> n; n   string s; n   cin >> s; n   int depth = 0; n   for (int i = 0; i < n; i++) { n     depth += (s[i] ==  (  ? 1 : -1); n   } n   if (depth != 2 && depth != -2) { n     cout <<  0 n ; n     return 0; n   } n   if (depth == 2) { n     depth = 0; n     int ans = 0; n     bool can = true; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  ( ) { n         if (depth - 1 >= 0) { n           ans++; n         } n       } n       depth += (s[i] ==  (  ? 1 : -1); n       if (depth <= 1) { n         ans = 0; n       } n       if (depth < 0) { n         can = false; n       } n     } n     if (!can) { n       cout <<  0 n ; n       return 0; n     } n     cout << ans <<   n ; n   } else if (depth == -2) { n     depth = 0; n     int ans = 0; n     bool can = true; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  ) ) { n         ans++; n       } n       depth += (s[i] ==  (  ? 1 : -1); n       if (depth < 0) { n         break; n       } n     } n     depth = 0; n     for (int i = 0; i < n; i++) { n       depth += (s[i] ==  (  ? 1 : -1); n       if (depth < -2) { n         can = false; n       } n     } n     if (!can) { n       cout <<  0 n ; n       return 0; n     } n     cout << ans <<   n ; n   } n   return 0; n } n