#include <bits/stdc++.h> n using namespace std; n static int N, K, M, G, U[500003], V[500003], W[500003], fa[500003], sup[500003], n     dep[500003]; n static bool spe[500003]; n static vector<pair<bool, int>> edge[500003]; n static long long ans; n int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } n void dfs(int u, int f) { n   dep[u] = dep[sup[u] = f] + 1; n   for (auto v : edge[u]) n     if (v.second != f) { n       spe[v.second] = v.first; n       dfs(v.second, u); n     } n } n int main() { n   scanf( %d%d%d , &N, &K, &M); n   for (int i = 1; i <= N; i++) fa[i] = i; n   for (int i = 0, x, y; i < K; i++) { n     scanf( %d%d , &x, &y); n     edge[x].push_back(make_pair(true, y)); n     edge[y].push_back(make_pair(true, x)); n     fa[find(x)] = find(y); n   } n   for (int i = 0; i < M; i++) { n     scanf( %d%d%d , &U[G], &V[G], &W[G]); n     int u = find(U[G]), v = find(V[G]); n     if (u != v) { n       edge[U[G]].push_back(make_pair(false, V[G])); n       edge[V[G]].push_back(make_pair(false, U[G])); n       fa[u] = v; n     } else n       G++; n   } n   dfs(1, 0); n   for (int i = 1; i <= N; i++) fa[i] = i; n   for (int i = 0; i < G; i++) { n     int u = find(U[i]), v = find(V[i]); n     while (u != v) { n       if (dep[u] < dep[v]) swap(u, v); n       ans += spe[u] ? W[i] : 0; n       u = fa[u] = find(sup[u]); n     } n   } n   for (int i = 1; i <= N; i++) n     for (auto v : edge[i]) n       if (v.first && find(v.second) != find(i)) return puts( -1 ), 0; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int k, a, b, v; n   int sections; n   scanf( %d%d%d%d , &k, &a, &b, &v); n   sections = a / v; n   sections += ((a % v) != 0); n   int box = 0; n   k--; n   while (b > 0) { n     box++; n     if (b >= k) { n       b -= k; n       sections -= (k + 1); n     } else { n       sections -= (b + 1); n       b = 0; n     } n     if (sections <= 0) break; n   } n   if (sections > 0) box += sections; n   printf( %d n , box); 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   vector<vector<char> > v; n   v.resize(n, vector<char>(m)); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) cin >> v[i][j]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if ((i + j) % 2 == 0 && v[i][j] ==  . ) { n         cout <<  B ; n         if (j == m - 1) cout <<   n ; n       } else if ((i + j) % 2 == 1 && v[i][j] ==  . ) { n         cout <<  W ; n         if (j == m - 1) cout <<   n ; n       } else { n         cout <<  - ; n         if (j == m - 1) cout <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 5; n struct bing { n   int fa[N]; n   void init() { n     for (int i = (1); i < (N); i++) fa[i] = i; n   } n   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } n   void unite(int x, int y) { fa[find(x)] = find(y); } n   bool same(int x, int y) { return find(x) == find(y); } n } bi[2]; n int n, m1, m2; n int main() { n   for (int i = (0); i < (2); i++) bi[i].init(); n   cin >> n >> m1 >> m2; n   int op = m1 > m2 ? 0 : 1; n   for (int i = (1); i < (m1 + 1); i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     bi[op].unite(u, v); n   } n   for (int i = (1); i < (m2 + 1); i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     bi[1 - op].unite(u, v); n   } n   printf( %d n , min(n - 1 - m1, n - 1 - m2)); n   for (int i = (1); i < (n + 1); i++) n     if (!bi[0].same(1, i) && !bi[1].same(1, i)) { n       bi[0].unite(1, i), bi[1].unite(1, i); n       printf( %d %d n , 1, i); n     } n   for (int a = 2, b = 2; a <= n; a++) { n     if (bi[0].same(1, a)) continue; n     while (b <= n && bi[1].same(1, b)) b++; n     if (b <= n) { n       bi[0].unite(a, b), bi[1].unite(a, b); n       printf( %d %d n , a, b); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, m, n, rez = 0; n   int a[300]; n   bool b[300] = {0}; n   bool c; n   cin >> n >> k; n   for (i = 1; i <= 2 * n + 1; i++) cin >> a[i]; n   for (j = 0; j < k; j++) { n     c = true; n     i = 2; n     while (c) { n       if (!b[i] && a[i] > a[i - 1] + 1 && a[i] > a[i + 1] + 1) { n         a[i]--; n         b[i] = true; n         c = false; n       } n       i += 2; n     } n   } n   for (i = 1; i <= 2 * n + 1; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10; n const int MAXM = 1e6 + 10; n const int MAXLOG = 20; n struct Edge { n   int x, y, w; n   int id; n } edge[MAXM]; n int T, n, m, i; n int val; n vector<pair<int, int> > e[MAXN]; n int fa[MAXN], anc[MAXN][MAXLOG], dep[MAXN]; n int ans[MAXM]; n int mx[MAXN][MAXLOG]; n bool on_mst[MAXM]; n inline bool cmp(Edge a, Edge b) { return a.w < b.w; } n inline int get_root(int x) { n   if (fa[x] == x) return x; n   return fa[x] = get_root(fa[x]); n } n inline void kruskal() { n   int i, x, y, sx, sy; n   int w; n   for (i = 1; i <= n; i++) fa[i] = i; n   sort(edge + 1, edge + m + 1, cmp); n   for (i = 1; i <= m; i++) { n     x = edge[i].x; n     y = edge[i].y; n     w = edge[i].w; n     sx = get_root(x); n     sy = get_root(y); n     if (sx != sy) { n       fa[sx] = sy; n       on_mst[edge[i].id] = 1; n       e[x].push_back(make_pair(y, w)); n       e[y].push_back(make_pair(x, w)); n     } n   } n } n inline void build(int u) { n   int i, v; n   for (i = 1; i < MAXLOG; i++) { n     anc[u][i] = anc[anc[u][i - 1]][i - 1]; n     mx[u][i] = max(mx[u][i - 1], mx[anc[u][i - 1]][i - 1]); n   } n   for (i = 0; i < e[u].size(); i++) { n     v = e[u][i].first; n     if (anc[u][0] != v) { n       dep[v] = dep[u] + 1; n       anc[v][0] = u; n       mx[v][0] = e[u][i].second; n       build(v); n     } n   } n } n inline int get(int x, int y) { n   int i, t; n   int ans = 0; n   if (dep[x] > dep[y]) swap(x, y); n   t = dep[y] - dep[x]; n   for (i = 0; i < MAXLOG; i++) { n     if (t & (1 << i)) { n       ans = max(ans, mx[y][i]); n       y = anc[y][i]; n     } n   } n   if (x == y) return ans; n   for (i = MAXLOG - 1; i >= 0; i--) { n     if (anc[x][i] != anc[y][i]) { n       ans = max(ans, max(mx[x][i], mx[y][i])); n       x = anc[x][i]; n       y = anc[y][i]; n     } n   } n   return max(ans, max(mx[x][0], mx[y][0])); n } n int main() { n   scanf( %d%d , &n, &m); n   if (m == n - 1) return 0; n   for (i = 1; i <= m; i++) { n     scanf( %d%d%d , &edge[i].x, &edge[i].y, &edge[i].w); n     edge[i].id = i; n   } n   kruskal(); n   build(1); n   for (int i = 1; i <= m; ++i) { n     if (!on_mst[edge[i].id]) ans[edge[i].id] = get(edge[i].x, edge[i].y); n   } n   for (int i = 1; i <= m; ++i) n     if (!on_mst[i]) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int M1(int x) { return x >= 1000000007 ? x - 1000000007 : x; } n int M2(int x) { return x >= 1000000009 ? x - 1000000009 : x; } n struct Hash { n   int a, b; n   Hash() { a = b = 0; } n   Hash(int a, int b) : a(a), b(b) {} n   Hash(int a) : a(a), b(a) {} n   bool operator<(const Hash& h) const { return a == h.a ? b < h.b : a < h.a; } n   bool operator!=(const Hash& h) const { return a != h.a || b != h.b; } n   bool operator==(const Hash& h) const { return a == h.a && b == h.b; } n   Hash operator+(const Hash& h) const { return Hash(M1(a + h.a), M2(b + h.b)); } n   Hash operator-(const Hash& h) const { n     return Hash(M1(a - h.a + 1000000007), M2(b - h.b + 1000000009)); n   } n   Hash operator*(const Hash& h) const { n     return Hash(((long long)a * h.a) % 1000000007, n                 ((long long)b * h.b) % 1000000009); n   } n   Hash inv() const { return Hash(M1(1000000007 - a), M2(1000000009 - b)); } n }; n struct Hash_map { n   Hash v[11009989 + 1]; n   int val[11009989 + 1], head[11009989 + 1], nxt[11009989 + 1], ptr; n   void clear() { ptr = 0; } n   void insert(Hash a) { n     int x = (19260817ll * a.a + a.b) % 11009989; n     for (int y = head[x]; y; y = nxt[y]) n       if (v[y] == a) return; n     v[++ptr] = a, nxt[ptr] = head[x], head[x] = ptr; n   } n   int count(Hash a) { n     int x = (19260817ll * a.a + a.b) % 11009989; n     for (int y = head[x]; y; y = nxt[y]) n       if (v[y] == a) return true; n     return false; n   } n   int& operator[](Hash a) { n     int x = (19260817ll * a.a + a.b) % 11009989; n     for (int y = head[x]; y; y = nxt[y]) n       if (v[y] == a) return val[y]; n     v[++ptr] = a, nxt[ptr] = head[x], head[x] = ptr; n     return val[ptr]; n   } n } st; n Hash pw[100100], _pw[100100]; n struct Data { n   int len, id; n   Hash h; n }; n int anses[100100], prec[100100], dep[100100], fa[21][100100], n, m; n vector<pair<int, int> > G[100100]; n vector<Data> Q[100100]; n void dfs(int u, int f) { n   fa[0][u] = f; n   for (auto c : G[u]) n     if (c.first != f) { n       dep[c.first] = dep[u] + 1; n       pw[c.first] = pw[u] * Hash(19260817, 20010911) + Hash(c.second, c.second); n       prec[c.first] = c.second; n       dfs(c.first, u); n     } n } n Hash get(int l, int r) { return pw[l] - pw[r] * _pw[dep[l] - dep[r]]; } n int lca(int u, int v) { n   if (dep[u] < dep[v]) swap(u, v); n   int d = dep[u] - dep[v]; n   for (int i = 0; d >> i; i++) n     if (d >> i & 1) u = fa[i][u]; n   if (u == v) return u; n   for (int i = 19; i >= 0; --i) n     if (fa[i][u] ^ fa[i][v]) u = fa[i][u], v = fa[i][v]; n   return fa[0][u]; n } n int jmp(int u, int d) { n   for (int i = 0; d >> i; i++) n     if (d >> i & 1) u = fa[i][u]; n   return u; n } n Hash geth(char* s) { n   Hash ret = 0; n   for (int i = 0; s[i]; i++) ret = ret * Hash(19260817, 20010911) + (s[i]); n   return ret; n } n int kmp(char* t, char* s) { n   static int f[100100]; n   int ns = strlen(s); n   for (int i = 0; i < ns; ++i) f[i] = 0; n   f[0] = -1; n   for (int i = 1; s[i]; i++) { n     int j = f[i - 1]; n     while (j != -1 && s[j + 1] != s[i]) j = f[j]; n     if (s[j + 1] == s[i]) j++; n     f[i] = j; n   } n   int ans = 0; n   for (int i = 0, x = -1; t[i]; i++) { n     while (x != -1 && s[x + 1] != t[i]) x = f[x]; n     if (s[x + 1] == t[i]) x++; n     if (x == ns - 1) ans++; n   } n   return ans; n } n void dfs2(int u, int f) { n   for (int i = 1, x = f; i <= 100 && x; i++) { n     st[get(u, x)]++; n     x = fa[0][x]; n   } n   for (auto c : Q[u]) { n     anses[abs(c.id)] += (c.id > 0 ? 1 : -1) * st[c.h]; n   } n   for (auto c : G[u]) n     if (c.first != f) dfs2(c.first, u); n   for (int i = 1, x = f; i <= 100 && x; i++) st[get(u, x)]--, x = fa[0][x]; n } n int main() { n   scanf( %d , &n); n   _pw[0] = Hash(1, 1); n   for (int i = 1; i <= n; ++i) _pw[i] = _pw[i - 1] * Hash(19260817, 20010911); n   for (int i = 2, u, v; i <= n; ++i) { n     char s[2]; n     scanf( %d%d%s , &u, &v, s); n     G[u].push_back(pair<int, int>(v, s[0])); n     G[v].push_back(pair<int, int>(u, s[0])); n   } n   dfs(1, 0); n   for (int i = 1; i < 20; ++i) n     for (int j = 1; j <= n; ++j) fa[i][j] = fa[i - 1][fa[i - 1][j]]; n   scanf( %d , &m); n   for (int i = 1, u, v; i <= m; ++i) { n     char s[200], t[300]; n     int tp = 0; n     scanf( %d%d%s , &u, &v, s); n     int lc = lca(u, v), len = strlen(s); n     int zu = jmp(u, max(0, dep[u] - dep[lc] - len)); n     int zv = jmp(v, max(0, dep[v] - dep[lc] - len)); n     Q[zv].push_back(Data{len, -i, geth(s)}); n     Q[v].push_back(Data{len, i, geth(s)}); n     reverse(s, s + len); n     Q[zu].push_back(Data{len, -i, geth(s)}); n     Q[u].push_back(Data{len, i, geth(s)}); n     reverse(s, s + len); n     while (zu != lc) t[tp++] = prec[zu], zu = fa[0][zu]; n     int xp = tp; n     while (zv != lc) t[tp++] = prec[zv], zv = fa[0][zv]; n     reverse(t + xp, t + tp); n     t[tp] = 0; n     anses[i] = kmp(t, s); n   } n   dfs2(1, 0); n   for (int i = 1; i <= m; ++i) printf( %d n , anses[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int l = s.length(); n   vector<vector<int>> dp(5000, vector<int>(5000, 0)); n   vector<int> kk(s.size() + 1, 0); n   for (int length = 1; length <= l; length++) { n     for (int right = 0; right < s.size(); right++) { n       int r = right + length - 1; n       if (r >= s.size()) break; n       if (s[right] != s[r]) continue; n       if (right == r) { n         dp[r][r] = 1; n       } else if (length == 2) { n         dp[right][r] = 2; n       } else if (dp[right + 1][r - 1] > 0) { n         int haf = length / 2; n         int ml = right + haf - 1; n         int mr = r - haf + 1; n         dp[right][r] = 1 + min(dp[right][ml], dp[mr][r]); n       } n       kk[dp[right][r]]++; n     } n   } n   for (int i = l; i >= 1; i--) { n     kk[i - 1] = kk[i] + kk[i - 1]; n   } n   for (int i = 1; i <= l; i++) { n     string pt = to_string(kk[i]) +    ; n     cout << pt; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int Z = (int)3e3 + 111; n const int N = (int)1e6 + 111; n const int INF = (int)1e9 + 111; n const int MOD = (int)1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string t, ans; n   cin >> t; n   int k; n   if (t.size() % 2) n     k = 1; n   else n     k = 0; n   int po1(0), po2(t.size() - 1); n   while (ans.size() != t.size()) { n     if (k) { n       ans = t[po1] + ans; n       po1++; n     } else { n       ans = t[po2] + ans; n       po2--; n     } n     k = !k; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-8; n const long long mod = (int)1e9 + 7; n int dx[] = {0, 0, -1, 1, 1, 1, -1, -1}; n int dy[] = {1, -1, 0, 0, 1, -1, -1, 1}; n const int N = 1000001; n void stop() {} n void file() {} n struct point { n   long long x, y; n }; n unsigned long long gcd(unsigned long long a, unsigned long long b) { n   return !b ? a : gcd(b, a % b); n } n long long fixMod(long long a, long long b) { return ((a % b) + b) % b; } n double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) { n   return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.; n }; n long long dis(pair<long long, long long> a, pair<long long, long long> b) { n   long long x = a.first - b.first, y = a.second - b.second; n   return abs(x) + abs(y); n } n unsigned long long LCM(unsigned long long a, unsigned long long b) { n   return a / gcd(a, b) * b; n } n long long power(long long x, long long y) { n   if (y == 0) return 1; n   if (y == 1) return x; n   long long r = power(x, y / 2); n   return r * r * power(x, y % 2); n } n bool isPrime(long long x) { n   if (x <= 1 || (x % 2 == 0 && x != 2)) return 0; n   for (long long i = 3; i * i <= x; i += 2) { n     if (x % i == 0) return 0; n   } n   return 1; n } n vector<vector<int>> v; n int n; n vector<int> dep; n int dfs(int node, int pr = -1) { n   int ret = 1; n   for (auto ch : v[node]) { n     if (ch != pr) { n       ret += dfs(ch, node); n     } n   } n   dep[node] = ret; n   return ret; n } n int aa = -1, bb = -1; n int x = -1; n void sol(int node, int pr = -1) { n   if (v[node].size() == 1 && aa == -1) { n     aa = node; n     bb = pr; n   } n   for (auto ch : v[node]) { n     if (ch != pr && ch != x) { n       sol(ch, node); n     } n   } n } n void solve() { n   cin >> n; n   v.clear(); n   v.resize(n); n   dep.clear(); n   map<pair<int, int>, bool> mp; n   int mx = 0; n   int st = 0; n   dep.resize(n); n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     mp[{a, b}] = true; n     v[a].push_back(b); n     v[b].push_back(a); n   } n   for (int i = 0; i < n; i++) { n     if (v[i].size() > mx) { n       mx = v[i].size(); n       st = i; n     } n   } n   int ans = dfs(st); n   if (count(((dep).begin()), ((dep).end()), ans / 2) == 0 || ans & 1) { n     for (auto i : mp) { n       cout << i.first.first + 1 <<     << i.first.second + 1 <<   n ; n       cout << i.first.first + 1 <<     << i.first.second + 1 <<   n ; n       break; n     } n   } else { n     aa = -1; n     bb = -1; n     x = -1; n     for (int i = 0; i < n; i++) { n       if (dep[i] * 2 == ans) { n         x = i; n         break; n       } n     } n     sol(st); n     if (mp[{aa, bb}] == true) { n       cout << aa + 1 <<     << bb + 1 <<   n ; n     } else { n       cout << bb + 1 <<     << aa + 1 <<   n ; n     } n     if (v[aa].size() == 1) { n       cout << x + 1 <<     << aa + 1 <<   n ; n     } else { n       cout << x + 1 <<     << bb + 1 <<   n ; n     } n   } n   mp.clear(); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, first, second, third, fourth; n   cin >> a >> b >> c; n   first = a + b + c; n   second = 2 * (a + b); n   third = 2 * (b + c); n   fourth = 2 * (a + c); n   cout << min(first, min(second, min(third, fourth))); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:200000000 ) n using namespace std; n template <typename T> n inline T Abs(T x) { n   return (x >= 0) ? x : -x; n } n template <typename T> n inline T sqr(T x) { n   return x * x; n } n template <typename T> n string toStr(T x) { n   stringstream st; n   st << x; n   string s; n   st >> s; n   return s; n } n inline int nextInt() { n   int x; n   if (scanf( %d , &x) != 1) throw; n   return x; n } n inline long long nextInt64() { n   long long x; n   if (scanf( %I64d , &x) != 1) throw; n   return x; n } n inline double nextDouble() { n   double x; n   if (scanf( %lf , &x) != 1) throw; n   return x; n } n const int INF = (int)1E9; n const long long INF64 = (long long)1E18; n const long double EPS = 1E-9; n const long double PI = 3.1415926535897932384626433832795; n const int MAXN = 100100; n unsigned long long d[MAXN], ans; n vector<int> g[MAXN]; n int n; n unsigned long long DFS(int v, int prev) { n   if (prev != -1) g[v].erase(find((g[v]).begin(), (g[v]).end(), prev)); n   d[v] = 0; n   long long sum2 = 0; n   for (int i = 0; i < (int)(g[v].size()); i++) { n     unsigned long long cur = DFS(g[v][i], v); n     sum2 += 1LL * d[v] * cur; n     d[v] += cur; n   } n   d[v]++; n   ans -= sqr(sum2); n   ans -= 2LL * sum2 * ((n - d[v] + 1) * d[v] - 1); n   ans -= 2LL * (d[v] - 1) * ((n - d[v] + 1) * d[v] - 1) - sqr(d[v] - 1); n   return d[v]; n } n int main() { n   n = nextInt(); n   for (int i = 0; i < (int)(n - 1); i++) { n     int v = nextInt() - 1; n     int u = nextInt() - 1; n     g[v].push_back(u); n     g[u].push_back(v); n   } n   ans = sqr(1LL * n * (n - 1) / 2); n   DFS(0, -1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, count = 0; n   string s; n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  8 ) count++; n   } n   if (n < 11) n     cout <<  0  << endl; n   else { n     cout << min(count, n / 11) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int a[maxn], n, x, k, l; n long long ans = 0; n int main() { n   cin >> n >> x; n   for (int i = 1; i <= n; i++) { n     cin >> k >> l; n     ans += min(k, l); n     a[i] = min(max(l - k, 0), k); n   } n   sort(a + 1, a + 1 + n); n   for (int i = 1; i <= x; i++) ans += a[n - i + 1]; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500005, M = 60; n int q, fa[N], n = 1; n double dp[N][M + 5]; n int main() { n   ios::sync_with_stdio(false); n   cin >> q; n   int opt, pos; n   for (int i = 0; i <= M; i++) dp[1][i] = 1; n   for (int _ = 1; _ <= q; _++) { n     cin >> opt >> pos; n     if (opt == 1) { n       fa[++n] = pos; n       for (int i = 0; i <= M; i++) dp[n][i] = 1; n       double pre = 1; n       int pp = n; n       for (int i = 0, cur = pos; cur && i <= M; i++, cur = fa[cur]) { n         double tmp = dp[cur][i]; n         dp[cur][i] /= 0.5 * (pre + 1); n         if (i) n           dp[cur][i] *= 0.5 * (1 + dp[pp][i - 1]); n         else n           dp[cur][i] *= 0.5; n         pp = cur; n         pre = tmp; n       } n     } else { n       double ans = 0; n       for (int i = 1; i <= M; i++) ans += (dp[pos][i] - dp[pos][i - 1]) * i; n       printf( %.10lf n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > all; n int isable[100005], cnt[100005]; n int main() { n   int i, n, k; n   scanf( %d , &n); n   scanf( %d , &k); n   long long b; n   scanf( %I64d , &b); n   for (i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     cnt[i] = x; n     if (i != n - 1) all.push_back(make_pair(x, i)); n   } n   sort(all.begin(), all.end()); n   i = all.size() - 1; n   long long sm = 0; n   int choto; n   while (k) { n     sm += all[i].first; n     choto = all[i].first; n     isable[all[i].second] = 1; n     k--; n     i--; n   } n   for (i = 0; i < n - 1; i++) { n     long long temp = sm; n     if (!isable[i]) { n       temp -= choto; n       temp += cnt[i]; n     } n     if (temp > b) break; n   } n   printf( %d n , i + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   string b; n   cin >> a >> b; n   long long int len1 = a.length(); n   long long int len2 = b.length(); n   if (a.compare(b) == 0) { n     cout <<  -1 n ; n   } else { n     if (len1 > len2) n       cout << len1 <<   n ; n     else n       cout << len2 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 10; n const double eps = 1e-6; n int n, m; n int sum, res; n int f[21][1 << 21], col[MAX]; n char s[MAX]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %s , s); n     for (int j = 0; j < m; j++) n       if (s[j] ==  1 ) col[j] |= (s[j] ==  1 ) << i; n   } n   for (int i = 0; i < m; i++) f[0][col[i]]++; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 1 << n; j++) { n       sum = i < 2 ? 0 : (i - 2 - n) * f[i - 2][j]; n       for (int k = 0; k < n; k++) sum += f[i - 1][j ^ (1 << k)]; n       f[i][j] = sum / i; n     } n   } n   res = n * m; n   for (int i = 0; i < 1 << n; i++) { n     sum = 0; n     for (int j = 0; j <= n; j++) sum += (j < n - j ? j : n - j) * f[j][i]; n     res = res < sum ? res : sum; n   } n   printf( %d , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = int; n namespace SEG { n static const ll STAR = 1, FINI = 2e5 + 110; n struct NODE { n   ll l, r, min; n   NODE() : l(0), r(0), min(0) {} n } node[1000000 * 10 + 110]; n ll newnode(ll pre = 0) { n   static ll cnt = 0; n   node[++cnt] = node[pre]; n   return cnt; n } n ll& lson(ll now) { return node[now].l; } n ll& rson(ll now) { return node[now].r; } n ll ins(ll pre, ll val, ll pos, ll star = STAR, ll fini = FINI) { n   ll now = newnode(pre); n   if (star < fini) { n     if (val <= ((star + fini) / 2)) n       lson(now) = ins(lson(pre), val, pos, star, ((star + fini) / 2)); n     else n       rson(now) = ins(rson(pre), val, pos, ((star + fini) / 2) + 1, fini); n     node[now].min = min(node[lson(now)].min, node[rson(now)].min); n   } else { n     node[now].min = pos; n   } n   return now; n } n ll ask(ll now, ll limit, ll star = STAR, ll fini = FINI) { n   if (star == fini) return star; n   if (node[lson(now)].min < limit) n     return ask(lson(now), limit, star, ((star + fini) / 2)); n   else n     return ask(rson(now), limit, ((star + fini) / 2) + 1, fini); n } n void debug(ll now, ll star = STAR, ll fini = FINI) { n   if (star > fini or now == 0) return; n   if (star == fini) { n     if (star == STAR) cout <<  SEG::debug::  << endl; n     if (node[now].min != INT64_MAX) n       cout << star <<     << node[now].min << endl; n     if (star == FINI) cout << endl; n     return; n   } n   debug(lson(now), star, ((star + fini) / 2)); n   debug(rson(now), ((star + fini) / 2) + 1, fini); n } n }  // namespace SEG n vector<ll> pos[100000 + 110]; n ll date[100000 + 110]; n static ll T[100000 + 110]; n bool check(ll val) { n   for (ll i = 1; i < pos[val].size(); i++) n     if (pos[val][i - 1] < pos[val][i] - 1) { n       if (SEG::ask(T[pos[val][i] - 1], pos[val][i - 1] + 1) == val) { n         return 1; n       } n     } n   return 0; n } n int main() { n   ll n; n   cin >> n; n   for (ll i = 1; i <= n + 10; i++) pos[i].push_back(0); n   for (ll i = 1; i <= n; i++) { n     cin >> date[i]; n     pos[date[i]].push_back(i); n     T[i] = SEG::ins(T[i - 1], date[i], i); n   } n   for (ll i = 1; i <= n + 10; i++) pos[i].push_back(n + 1); n   for (ll i = 1; i <= n + 10; i++) n     if (check(i) == 0) { n       cout << i <<   n ; n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 250005; n int qr[maxn], qp[maxn], wm[maxn], loc[maxn]; n int pp[maxn], pr[maxn], pm[maxn]; n long long pd[maxn]; n stack<int> f[maxn]; n bool used[maxn]; n int n, nx, ny, totm; n long long dist(int x, int y) { return (long long)x * x + (long long)y * y; }; n bool cmp(int a, int b) { return pd[a] > pd[b]; }; n int main() { n   int i, x, y, h, t; n   long long d; n   scanf( %d%d%d%d%d , &nx, &ny, qp + 1, qr + 1, &n); n   for (i = 1; i <= n; ++i) { n     scanf( %d%d%d%d%d , &x, &y, pm + i, pp + i, pr + i); n     pd[i] = dist(x - nx, y - ny); n     wm[i - 1] = pm[i]; n     loc[i] = i; n   } n   sort(wm, wm + n); n   totm = unique(wm, wm + n) - wm; n   for (i = 1; i <= n; ++i) pm[i] = lower_bound(wm, wm + totm, pm[i]) - wm + 1; n   sort(loc + 1, loc + n + 1, cmp); n   for (i = 1; i <= n; ++i) n     for (x = pm[loc[i]]; x <= totm; x += x & -x) f[x].push(loc[i]); n   for (h = 1, t = 1; h <= t; ++h) { n     x = upper_bound(wm, wm + totm, qp[h]) - wm; n     d = (long long)qr[h] * qr[h]; n     for (; x > 0; x -= x & -x) n       while (!f[x].empty() && pd[f[x].top()] <= d) { n         y = f[x].top(); n         f[x].pop(); n         if (!used[y]) { n           used[y] = true; n           ++t; n           qp[t] = pp[y]; n           qr[t] = pr[y]; n         } n       } n   } n   printf( %d n , t - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[20]; n   a[0] = 2; n   a[1] = 3; n   a[2] = 5; n   a[3] = 7; n   a[4] = 11; n   a[5] = 13; n   a[6] = 17; n   a[7] = 19; n   a[8] = 23; n   a[9] = 29; n   a[10] = 31; n   a[11] = 37; n   a[12] = 41; n   a[13] = 43; n   a[14] = 47; n   a[15] = 4; n   a[16] = 9; n   a[17] = 25; n   a[18] = 49; n   char s[10]; n   long int i, flag = 0; n   for (i = 0; i <= 18; i++) { n     printf( %ld n , a[i]); n     fflush(stdout); n     scanf( %s , s); n     if (s[0] ==  y ) { n       flag++; n     } n     if (flag == 2) { n       printf( composite n ); n       fflush(stdout); n       break; n     } n   } n   if (flag < 2) printf( prime n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5 * 100000; n vector<int> g[MAXN + 1], e[MAXN + 1]; n int col[MAXN + 1], cur = 1, used[MAXN + 1]; n void dfs(int v, int p) { n   int num = 1; n   vector<int> del; n   for (auto x : g[v]) { n     del.push_back(col[x]); n     used[col[x]] = 1; n   } n   for (auto x : g[v]) { n     if (col[x]) continue; n     while (used[num]) num++; n     used[num] = 1; n     del.push_back(num); n     col[x] = num; n   } n   for (auto x : del) used[x] = 0; n   for (auto x : e[v]) { n     if (x == p) continue; n     dfs(x, v); n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int pos = 0; n   for (int i = 1; i <= n; i++) { n     int sz; n     scanf( %d , &sz); n     for (int j = 0; j < sz; j++) { n       int x; n       scanf( %d , &x); n       g[i].push_back(x); n     } n     if (g[i].size() > g[pos].size()) pos = i; n     sort(g[i].begin(), g[i].end()); n   } n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     e[a].push_back(b); n     e[b].push_back(a); n   } n   for (auto x : g[pos]) col[x] = cur++, used[cur] = 1; n   dfs(pos, -1); n   cout << max(1, *max_element(col + 1, col + 1 + m)) <<   n ; n   for (int i = 1; i <= m; i++) { n     if (!col[i]) col[i] = 1; n     printf( %d  , col[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Person { n   int a; n   int id; n }; n bool operator<(Person a, Person b) { return a.a < b.a; } n class TSolver { n  public: n   int n; n   vector<Person> persons; n   explicit TSolver(std::istream& in) { n     in >> n; n     persons.resize(n); n     for (int i = 0; i < n; ++i) { n       in >> persons[i].a; n       persons[i].id = i; n     } n   } n   bool ok = true; n   vector<int> ans; n   void Solve() { n     sort((persons).begin(), (persons).end()); n     ans.resize(n); n     int color = 1; n     for (int i = 0; ok && i < n;) { n       int same = n - persons[i].a; n       ok = ok && i + same <= n; n       for (int j = 0; ok && j < same; ++j) { n         if (persons[i + j].a != persons[i].a) { n           ok = false; n         } n         ans[persons[i + j].id] = color; n       } n       i += same; n       ++color; n     } n   } n   void PrintAnswer(std::ostream& out) const { n     if (ok) { n       out <<  Possible n ; n       for (int i = 0; i < n; ++i) { n         out << ans[i] <<    n [i + 1 == n]; n       } n     } else { n       out <<  Impossible n ; n     } n   } n }; n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   std::cout.tie(nullptr); n   { n     auto solver = std::make_shared<TSolver>(std::cin); n     solver->Solve(); n     solver->PrintAnswer(std::cout); n   } n   do { n   } while (false); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long binpow(long long a, long long b) { n   long long exp = 10e9; n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = ((res % exp) * (a % exp)) % exp; n     a = ((a % exp) * (a % exp)) % exp; n     b >>= 1; n   } n   return res; n } n bool isprime(int x) { n   for (int d = 2; d * d <= x; d++) { n     if (x % d == 0) return false; n   } n   return true; n } n unsigned int cntsb(unsigned int n) { n   unsigned int count = 0; n   while (n) { n     count += n & 1; n     n >>= 1; n   } n   return count; n } n void solve(int cas) {} n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int number = 0; n   long long n; n   cin >> n; n   int last = n % 10; n   if (last <= 5) n     n -= last; n   else n     n += (10 - last); n   cout << n; n } n


#include <bits/stdc++.h>  n using namespace std;  n  n #define vec vector  n #define PB push_back  n  n #define MP make_pair  n #define MT make_tuple  n #define F first  n #define S second  n  n using ll = long long int; // watch out for overflows in your code n using pii = pair<int,int>; n //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n  n void debug() { cout <<   n ; }; n template <typename T, typename... Targs>  n void debug(T t, Targs... args) { n     cout << t <<    ; n     debug(args...); n } n  n template <typename T1, typename T2>  n inline ostream& operator << (ostream& os, const pair<T1,T2>& p) { n     return os <<  (  << p.F <<  ,   << p.S <<  ) ; n } n  n template <typename T>  n inline ostream& operator << (ostream& os, const vec<T>& v) { n     for(auto& t : v) { n         os << t <<    ; n     } n     return os; n } n  n template <typename T>  n inline ostream& operator << (ostream& os, const vec<vec<T>>& m) { n     for(auto& v : m) { n         for(auto& t : v) { n             os << t <<    ; n         } n         os <<   n ; n     } n     return os; n } n  n template <typename T>  n inline ostream& operator << (ostream& os, const set<T>& v) { n     for(auto& t : v) { n         os << t <<    ; n     } n     return os; n } n  n template <typename K, typename V>  n inline ostream& operator << (ostream& os, const map<K,V>& m) { n     for(auto& p : m) { n         os << p.F <<   ->   << p.S <<   n ; n     } n     return os; n } n  n const int INF = 2 * 1e9; n int T, N, M; n vec<int> A, B; n  n int increment(int& i, const vec<int>& v) { n     int S = v.size(); n     if(i >= S) { n         return -INF; n     } n     int P = v[i++]; n     while(i < S && P < 0) { n         P += v[i]; n         i++; n     } n     while(i < S && P <= P + v[i]) { n         P = P + v[i]; n         ++i; n     } n     return P; n } n  n int compute() { n     int j = 0, i = 0; n     int pa, pb; n     int S = 0; n     int ans = 0; n  n     pa = increment(i, A); n     pb = increment(j, B); n  n     while(i <= N || j <= M) { n         //debug( pa , pa,  pb , pb); n         if(pa < 0 && pb < 0) { n             break; n         } n         if(pa >= pb) { n             S += pa; n             pa = increment(i, A); n         } n         else { n             S += pb; n             pb = increment(j, B); n         } n         ans = max(ans, S); n     } n     return ans; n } n  n //////////////////////////////////////////////////////////////////////// n  n int main() { n     ios::sync_with_stdio(0); n     cin.tie(0); n  n     cin >> T; n     while(T--) { n         cin >> N; n         A.assign(N, 0); n         for(int i = 0; i < N; ++i) { n             cin >> A[i]; n         } n         cin >> M; n         B.assign(M, 0); n         for(int j = 0; j < M; ++j) { n             cin >> B[j]; n         } n         cout << compute() <<   n ; n     } n  n } n  n


#include <bits/stdc++.h> n using namespace std; n const int N = 100; n const int M = 2e6 + 7; n const int inf = 1e9; n int n, m, mx, p[N], minn[N], D[M][2], sum = 0; n int a[N][N]; n bool check() { n   for (int t = 0, tE = (1 << mx) - 1; t <= tE; t++) { n     int ds = 0, bs = 0; n     for (int i = 1, iE = mx; i <= iE; i++) n       if (t & (1 << (i - 1))) ds += p[i]; n     if (!ds) continue; n     for (int i = 1, iE = mx; i <= iE; i++) n       if (t & (1 << (i - 1))) n         for (int j = 1, jE = mx; j <= jE; j++) n           if (t & (1 << (j - 1))) bs += a[i][j]; n     if (bs >= ds) return 0; n   } n   return 1; n } n int Cnt(int x) { return x == 0 ? 0 : Cnt(x / 10) + 1; } n char sa[N], sb[N]; n bool get() { n   for (int x = 1, xE = mx; x <= xE; x++) n     for (int i = 1, iE = mx; i <= iE; i++) n       if (a[x][i]) { n         a[x][i]--, p[x]--; n         if (check()) return printf( %d %d n , minn[x] + p[x], minn[i]), 1; n         a[x][i]++, p[x]++; n         a[x][i]--, p[i]--; n         if (check()) return printf( %d %d n , minn[x], minn[i] + p[i]), 1; n         a[x][i]++, p[i]++; n       } n   return 0; n } n int main() { n   scanf( %d , &n), mx = Cnt(n); n   for (int i = 1, iE = n; i <= iE; i++) p[Cnt(i)]++; n   minn[1] = 1; n   for (int i = 2, iE = mx; i <= iE; i++) minn[i] = minn[i - 1] * 10; n   for (int i = 1, iE = n - 1; i <= iE; i++) n     scanf( %s%s , sa, sb), D[i][0] = strlen(sa), D[i][1] = strlen(sb), n                            a[D[i][0]][D[i][1]]++; n   if (!check()) return puts( -1 ), 0; n   while (get()) sum++; n   for (int x = 1, xE = mx; x <= xE; x++) n     for (int i = 1, iE = mx; i <= iE; i++) n       if (a[x][i]) n         printf( %d %d n , minn[x] + p[x] - 1, minn[i] + p[i] - 1), sum++; n   if (sum != n - 1) assert(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, l, n, m, A[11] = {0}, count = 0, B[2000], sum1, sum2, last, n                         flag = 0; n   char ch; n   for (i = 1; i <= 10; i++) { n     scanf( %c , &ch); n     if (ch ==  1 ) n       A[i] = 1; n     else n       A[i] = 0; n   } n   scanf( %d , &m); n   for (k = 1; k <= 10; k++) { n     if (A[k] == 1) { n       flag = 0; n       sum1 = k; n       sum2 = 0; n       last = k; n       B[0] = k; n       i = 1; n       while (i < m) { n         for (j = 1; j <= 10; j++) { n           if (A[j] == 1) { n             if (sum2 + j > sum1 && last != j) { n               sum2 += j; n               last = j; n               B[i++] = j; n               break; n             } n           } n         } n         if (j == 11) { n           flag = 1; n           break; n         } n         if (i == m) break; n         for (j = 1; j <= 10; j++) { n           if (A[j] == 1) { n             if (sum1 + j > sum2 && last != j) { n               sum1 += j; n               last = j; n               B[i++] = j; n               break; n             } n           } n         } n         if (j == 11) { n           flag = 1; n           break; n         } n       } n     } n     if (i == m) break; n   } n   if (k == 11) n     printf( NO n ); n   else if (i == m) { n     printf( YES n ); n     for (i = 0; i < m; i++) { n       if (i != m - 1) n         printf( %d  , B[i]); n       else n         printf( %d n , B[i]); n     } n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n  n void solve() n { n     int x,y; n     cin>>x>>y; n     string s; n     cin>>s; n     int cR=0,cU=0,cL=0,cD=0; n     for(int i=0;i<s.size();i++) n     { n         if(s[i]== R ) n             cR++; n         else if(s[i]== U ) n             cU++; n         else if(s[i]== L ) n             cL++; n         else n             cD++; n     } n     //cout<<cR<<   <<cL<<   <<cU<<   <<cD<<  n ; n     if(x>0&&y>0) n     { n         if(cR>=x&&cU>=y) n             cout<< YES n ; n         else n             cout<< NO n ; n     } n     else if(x>0&&y<0) n     { n         if(cR>=x&&cD>=abs(y)) n             cout<< YES n ; n         else n             cout<< NO n ; n     } n     else if(x<0&&y>0) n     { n         if(cL>=abs(x)&&cU>=y) n             cout<< YES n ; n         else n             cout<< NO n ; n     } n     else if(x<0&&y<0) n     { n         if(cL>=abs(x)&&cD>=abs(y)) n             cout<< YES n ; n         else n             cout<< NO n ; n     } n     else n     { n         if(x>0&&y==0) n         { n             if(cR>=x) n                 cout<< YES n ; n             else n                 cout<< NO n ; n         } n         else if(x<0&&y==0) n         { n             if(cL>=abs(x)) n                 cout<< YES n ; n             else n                 cout<< NO n ; n         } n         else if(x==0&&y>0) n         { n             if(cU>=y) n                 cout<< YES n ; n             else n                 cout<< NO n ; n         } n         else if(x==0&&y<0) n         { n             if(cD>=abs(y)) n                 cout<< YES n ; n             else n                 cout<< NO n ; n         } n         else n             cout<< NO n ; n     } n } n int main() n { n    int t; n    ios::sync_with_stdio(false); n    cin>>t; n    cin.tie(0); n    cout.tie(0); n    while(t--) n     solve(); n    return 0; n } n  n  n  n  n  n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int f = 1, ans = 0; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     ans = ans * 10 + c -  0 ; n     c = getchar(); n   } n   return f * ans; n } n const int MAXN = 4e5 + 11; n vector<int> vec[MAXN]; n int ch[MAXN][27], las = 1, tot = 1, TT = 0, N, Q, len[MAXN], fa[MAXN], rt[MAXN], n                   all; n char S[MAXN]; n struct Segment { n   int ls[MAXN * 34], rs[MAXN * 34]; n   void Modify(int &k, int l, int r, int ps) { n     if (!k) k = ++TT; n     if (l == r) return; n     int mid = (l + r) >> 1; n     if (ps <= mid) Modify(ls[k], l, mid, ps); n     if (mid < ps) Modify(rs[k], mid + 1, r, ps); n     return; n   } n   void print(int k, int l, int r) { n     if (!k) return; n     if (l == r) { n       printf( %d  , l); n       return; n     } n     int mid = (l + r) >> 1; n     print(ls[k], l, mid), print(rs[k], mid + 1, r); n   } n   int merge(int p, int q) { n     if (!p || !q) return p + q; n     int u = (++TT); n     ls[u] = merge(ls[p], ls[q]), rs[u] = merge(rs[p], rs[q]); n     return u; n   } n   bool Query(int k, int l, int r, int x, int y) { n     if (!k) return 0; n     if (x <= l && r <= y) return 1; n     int mid = (l + r) >> 1; n     bool res = 0; n     if (x <= mid) res |= Query(ls[k], l, mid, x, y); n     if (mid < y) res |= Query(rs[k], mid + 1, r, x, y); n     return res; n   } n   void debug(int k) { n     print(rt[k], 1, N); n     printf(  n ); n     return; n   } n } T; n void ins(int c) { n   int p = las, np = las = ++tot; n   len[np] = len[p] + 1; n   T.Modify(rt[np], 1, N, len[np]); n   for (; p && !ch[p][c]; p = fa[p]) ch[p][c] = np; n   if (!p) { n     fa[np] = 1; n     return; n   } n   int q = ch[p][c]; n   if (len[p] + 1 == len[q]) { n     fa[np] = q; n     return; n   } n   int nq = ++tot; n   len[nq] = len[p] + 1, fa[nq] = fa[q]; n   for (int i = 0; i < 27; i++) ch[nq][i] = ch[q][i]; n   fa[q] = fa[np] = nq; n   for (; p && ch[p][c] == q; p = fa[p]) ch[p][c] = nq; n   return; n } n void dfs(int u) { n   for (auto v : vec[u]) dfs(v), rt[u] = T.merge(rt[u], rt[v]); n } n int L, R, LEN; n char Ans[MAXN]; n bool ff = 1; n void calc(int now, int len, bool f) { n   if (!f) { n     for (int i = 1; i < len; i++) printf( %c , Ans[i]); n     printf(  n ); n     ff = 0; n     return; n   } n   int be; n   if (!f || len > LEN) n     be = 0; n   else n     be = S[len] -  a ; n   for (int i = be; i < 26; i++) { n     int u = ch[now][i]; n     if (!u) continue; n     if (!T.Query(rt[u], 1, N, L + len - 1, R)) continue; n     Ans[len] = i +  a ; n     calc(u, len + 1, f & (i == (S[len] -  a ))); n     if (!ff) return; n   } n } n int main() { n   scanf( %s , S + 1); n   N = strlen(S + 1); n   Q = read(); n   for (int i = 1; i <= N; i++) ins(S[i] -  a ); n   for (int i = 2; i <= tot; i++) vec[fa[i]].push_back(i); n   dfs(1); n   while (Q--) { n     L = read(), R = read(); n     scanf( %s , S + 1); n     LEN = strlen(S + 1); n     ff = 1; n     calc(1, 1, 1); n     if (ff) printf( -1 n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, k; n   cin >> n >> k; n   vector<long long> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   ; n   sort(a.begin(), a.end()); n   long long mm = a[n / 2]; n   for (int i = n / 2; i < n - 1; i++) { n     long long r = a[i + 1] - a[i]; n     if (k >= r * (i - n / 2 + 1)) n       k -= r * (i - n / 2 + 1); n     else if (k > 0) { n       mm += k / (i - n / 2 + 1); n       k = 0; n       break; n     } else n       break; n     mm = a[i + 1]; n   } n   if (k > 0) mm += k / (n / 2 + 1); n   cout << mm <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 200005; n int n, m, tot, ans; n struct Node { n   int u, v, w; n } node[M]; n int vis[M], match[M]; n int sum1[M], sum2[M]; n int head[M], Nxt[M], ver[M]; n bool v[M], flag = 0; n vector<int> e[M]; n inline bool dfs(long long x) { n   for (int i = 0; i < e[x].size(); i++) { n     long long y = e[x][i]; n     if (!vis[y]) { n       vis[y] = 1; n       if (!match[y] || dfs(match[y])) { n         match[y] = x; n         return 1; n       } n     } n   } n   return 0; n } n bool cmp(Node a, Node b) { return a.w > b.w; } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &node[i].u, &node[i].v, &node[i].w); n     sum1[node[i].u]++; n     sum2[node[i].v]++; n     e[node[i].u].push_back(node[i].v); n   } n   for (int i = 1; i <= n; i++) { n     memset(vis, 0, sizeof(vis)); n     if (dfs(i)) ans++; n   } n   if (ans != n) { n     printf( -1 n ); n     return 0; n   } n   sort(node + 1, node + 1 + m, cmp); n   for (int i = 1; i <= m; i++) { n     sum1[node[i].u]--; n     sum2[node[i].v]--; n     if (sum1[node[i].u] == 0 || sum2[node[i].v] == 0) { n       printf( %d n , node[i].w); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int z = 0; z < t; z++) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     bool found = false; n     for (int i = 0; i <= n - 11; i++) { n       if (s[i] ==  8 ) { n         cout <<  YES  << endl; n         found = true; n         break; n       } n     } n     if (found) { n       continue; n     } n     cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void show(const vector<T> &a) { n   for (T x : a) cout << x <<    ; n   cout <<   n ; n } n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); n vector<long long> xx = {1, 0, -1, 0}; n vector<long long> yy = {0, 1, 0, -1}; n string dir =  LRUD ; n const long long N = 3e5 + 50, oo = 2e18 + 500; n const long long mod = 998244353; n const long long M2 = 1000000093, x2 = 27162; n const long long M1 = 1000000087, x1 = 241; n const double eps = 1e-12, PI = 2 * acos(0.0); n long long n, m, k; n long long cnt = 0; n long long lg = 18; n vector<vector<long long>> g; n vector<vector<long long>> rg; n signed main() { n   ios::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   string s; n   cin >> s; n   n = ((long long)(s.size())); n   vector<vector<string>> vc(26); n   for (long long i = 0; i < n; i++) { n     string t = s.substr(i, n - i) + s.substr(0, i); n     vc[s[i] -  a ].push_back(t); n   } n   double ans = 0; n   for (long long i = 0; i < 26; i++) { n     if (!((long long)(vc[i].size()))) continue; n     long long val = 0; n     for (long long j = 0; j < n; j++) { n       vector<long long> count_letters(26); n       for (long long z = 0; z < ((long long)(vc[i].size())); z++) { n         count_letters[vc[i][z][j] -  a ]++; n       } n       bool fl = 1; n       long long cur = 0; n       for (long long z = 0; z < 26; z++) { n         if (count_letters[z] == 1) { n           cur++; n         } else { n           if (count_letters[z]) fl = 0; n         } n       } n       if (fl) { n         val = ((long long)(vc[i].size())); n         break; n       } n       val = max(val, cur); n       ; n     } n     cnt += val; n   } n   ans = (double)cnt / (double)n; n   cout << fixed << setprecision(10) << ans; n } n


#include<bits/stdc++.h> n using namespace std ; n  n # define all(v) (v).begin() , (v).end() n # define allrev(v) (v).rbegin() , (v).rend() n # define allcomp(v) (v).begin() , (v).end() , comp n  n # define ll long long n  n # define line cout <<   n  ; n # define fast ios_base :: sync_with_stdio ( false ) ; cin.tie ( 0 ) ; n  n # define pii pair < int , int > n # define pll pair < ll , ll > n  n # define F first n # define S second n  n const int mod = 998244353  ; n  n const int dx[] = { -1 , 0 , 1 , 0 , -1 , -1 , 1 , 1 } ; n const int dy[] = { 0 , 1 , 0 , -1 , -1 , 1 , -1 , 1 } ; n  n ll mod_pow ( ll a , ll b ) n { n     if ( b == 0 ) n         return 1 ; n  n     if ( b == 1 ) n         return a%mod ; n  n     if ( b == 2 ) n     { n         return ((a%mod) * (a%mod))%mod ; n     } n  n     return (mod_pow ( mod_pow ( a , b>>1 ) , 2 ) * mod_pow ( a , b&1 ))%mod ; n } n  n void solve ( int test_case ) n { n     int n ; n     cin >> n ; n  n     int bak = n ; n  n     int nr = 0 ; n     if ( n <= 2 ) n         nr = 1 ; n  n  n     else n     { n         n -= 2 ; n         ll a = 1 , b = 1 ; n  n         while ( n -- ) n         { n             b += a ; n             a = b - a ; n  n             a %= mod ; n             b %= mod ; n         } n  n         nr = b ; n     } n  n     ll f = 1 ; n     for ( int i = 1 ; i <= bak ; i ++ ) n         f <<= 1 , f %= mod ; n  n //    cout <<  nr :   << nr <<   and dr :   << f ; line ; n  n     f = mod_pow ( f , mod - 2 ) ; n  n  n  n     ll ans = nr * f ; n     ans %= mod ; n  n     cout << ans ; line ; n } n  n int main() n {fast n     int t = 1 ; n     // cin >> t ; n  n     for ( int i = 1 ; i <= t ; i ++ ) n     { n         solve ( i ) ; n     } n  n     return 0 ; n } n  n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> mp; n void Hash(string str, long long B, long long mod) { n   long long power = 1, h = 0; n   long long m = (int)str.length(); n   for (long long i = m - 1; i >= 0; i--) { n     h = h + (power * (str[i] -  a  + 1)) % mod; n     h = h % mod; n     power = (power * B) % mod; n   } n   mp[h]++; n } n bool match(string str, long long B, long long mod) { n   long long power = 1, h = 0; n   long long m = (int)str.length(); n   for (long long i = m - 1; i >= 0; i--) { n     h = h + (power * (str[i] -  a  + 1)) % mod; n     h = h % mod; n     power = (power * B) % mod; n   } n   power = 1; n   for (long long i = m - 1; i >= 0; i--) { n     long long t1, t2; n     if (str[i] ==  a ) { n       t1 = h + power; n       t1 = t1 % mod; n       t2 = t1 + power; n       t2 = t2 % mod; n     } else if (str[i] ==  b ) { n       t1 = h - power; n       t1 = (t1 + mod) % mod; n       t2 = h + power; n       t2 = (t2 + mod) % mod; n     } else { n       t1 = h - power; n       t1 = (t1 + mod) % mod; n       t2 = t1 - power; n       t2 = (t2 + mod) % mod; n     } n     power = (power * B) % mod; n     if (mp[t1] != 0) return true; n     if (mp[t2] != 0) return true; n   } n   return false; n } n int main() { n   long long B[10], mod[10]; n   B[0] = 137, B[1] = 347; n   mod[0] = 100404001, mod[1] = 1000000007; n   int n, m; n   scanf( %d %d , &n, &m); n   string str[n], query[m]; n   for (int i = 0; i < n; i++) cin >> str[i]; n   for (int i = 0; i < m; i++) cin >> query[i]; n   bool ans[m]; n   memset(ans, true, sizeof ans); n   for (int i = 0; i < 2; i++) { n     mp.clear(); n     for (int j = 0; j < n; j++) { n       Hash(str[j], B[i], mod[i]); n     } n     for (int j = 0; j < m; j++) { n       if (match(query[j], B[i], mod[i]) == false) ans[j] = false; n     } n   } n   for (int j = 0; j < m; j++) { n     if (ans[j]) n       printf( YES n ); n     else n       printf( NO n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int l = n - k; n   int max_1 = 0; n   for (int i = 0; i < (n - k); i++) { n     max_1 = max(max_1, a[i] + a[2 * (n - k) - i - 1]); n   } n   max_1 = max(max_1, a[n - 1]); n   cout << max_1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long max(long long a, long long b) { n   if (a < b) return b; n   return a; n } n long long min(long long a, long long b) { n   if (a < b) return a; n   return b; n } n long long X; n vector<long long> x; n long long dfs(long long node, long long par, vector<vector<long long> > &v) { n   long long cnt = 0; n   for (int i = 0; i < v[node].size(); i++) { n     long long adj = v[node][i]; n     if (adj == par) continue; n     long long y = dfs(adj, node, v); n     if (node == X) x.push_back(y); n     cnt += y; n   } n   return cnt + 1; n } n void solve() { n   x.clear(); n   long long n; n   cin >> n >> X; n   vector<vector<long long> > v(n + 1); n   long long degree[n + 1]; n   memset(degree, 0, sizeof(degree)); n   vector<vector<long long> > comp; n   for (int i = 0; i < n - 1; i++) { n     long long a, b; n     cin >> a >> b; n     degree[a]++, degree[b]++; n     v[a].push_back(b); n     v[b].push_back(a); n   } n   if (degree[X] == 1 || n == 1) n     cout <<  Ayush n ; n   else { n     dfs(X, -1, v); n     long long cnt = 0; n     for (int i = 0; i < x.size(); i++) cnt += max(0, x[i] - 1); n     cnt += max(0, v[X].size() - 1); n     if (cnt % 2 == 0) { n       cout <<  Ayush n ; n     } else n       cout <<  Ashish n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long test = 0; n   cin >> test; n   while (test--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using std::bitset; n using namespace std; n int g[302][302][302], f[302][302]; n int s[10]; n int n, ans; n void updateg(int a, int b, int c) { n   int i, j, tem, t; n   for (i = c + 1; i < 300; i++) { n     g[a][b][i] = 1; n     g[a][c][i] = 1; n     g[b][c][i] = 1; n   } n   for (i = b + 1; i <= c; i++) { n     g[a][i][c] = 1; n     g[b][i][c] = 1; n   } n   for (i = a + 1; i <= b; i++) g[i][b][c] = 1; n   for (t = 1; c + t < 300; t++) g[a + t][b + t][c + t] = 1; n } n void updatef(int a, int b) { n   int i, j, tem, t; n   for (i = b + 1; i < 300; i++) { n     f[a][i] = 1; n     f[b][i] = 1; n   } n   for (i = a + 1; i <= b; i++) f[i][b] = 1; n   for (t = 1; b + t < 300; t++) f[a + t][b + t] = 1; n } n void init() { n   int i, j, tem; n   memset(g, -1, sizeof(g)); n   ; n   int a, b, c; n   for (a = 0; a < 300; a++) n     for (b = a; b < 300; b++) n       for (c = b; c < 300; c++) { n         if (g[a][b][c] == -1) { n           g[a][b][c] = 0; n           updateg(a, b, c); n         } n       } n   memset(f, -1, sizeof(f)); n   ; n   for (a = 0; a < 300; a++) n     for (b = a; b < 300; b++) { n       if (f[a][b] == -1) { n         f[a][b] = 0; n         updatef(a, b); n       } n     } n } n int main() { n   int i, j, tem; n   init(); n   while (scanf( %d , &n) != EOF) { n     memset(s, 0, sizeof(s)); n     ; n     for (i = 1; i <= n; i++) scanf( %d , &s[i]); n     if (n == 1) { n       if (s[1] != 0) n         printf( BitLGM n ); n       else n         printf( BitAryo n ); n     } else if (n == 2) { n       if (s[1] > s[2]) swap(s[1], s[2]); n       if (f[s[1]][s[2]] == 1) n         printf( BitLGM n ); n       else n         printf( BitAryo n ); n     } else { n       sort(s + 1, s + 1 + 3); n       if (g[s[1]][s[2]][s[3]] == 1) n         printf( BitLGM n ); n       else n         printf( BitAryo n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t, n, a, b, p, q, z, k; n   cin >> t; n   while (t--) { n     z = 0; n     k = 0; n     cin >> a >> b >> n; n     p = max(a, b); n     q = min(a, b); n     while (k <= n) { n       z++; n       k = q + p; n       q = p; n       p = k; n     } n     cout << z << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int t, a[30], n, b[2010], r; n vector<int> aux[30]; n int val(int x, int y) { n   int hr = 0, hxt = 0; n   for (int i = 1; i <= aux[x].size() / 2; i++) { n     hxt = lower_bound(aux[y].begin(), aux[y].end(), aux[x][aux[x].size() - i]) - n           upper_bound(aux[y].begin(), aux[y].end(), aux[x][i - 1]); n     if (hxt > 0) hr = max(hr, 2 * i + hxt); n   } n   return hr; n } n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     for (int i = 1; i <= 26; i++) aux[i].clear(); n     r = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &b[i]); n       aux[b[i]].push_back(i); n       int h = aux[b[i]].size(); n       r = max(r, h); n     } n     for (int i = 1; i < 26; i++) n       for (int j = i + 1; j <= 26; j++) r = max(r, max(val(i, j), val(j, i))); n     printf( %d n , r); n   } n   return 0; n } n


#pragma GCC optimize(3,  Ofast ,  inline ) n  n #include <bits/stdc++.h> n  n #define rep(i,a,b) for(int i=(a);i<=(b);i++) n using namespace std; n typedef long long ll; n typedef unsigned long long ull; n typedef pair<int, int> P; n typedef pair<double, double> Pd; n typedef pair<ll, ll> pll; n const int maxn = 1e6+10; n  n  n  n int n,m; n int a[111][111]; n struct node n { n  int x,y; n  int v; n }e[10005]; n  n int tot = 0; n bool cmp(node A,node B) { n  return A.v<B.v; n } n int main() n { n #ifndef ONLINE_JUDGE n     freopen( /volumes/D/acm/1.txt ,  r , stdin); n #endif n    n     int T; n     scanf( %d ,&T); n     while(T--) { n      tot = 0; n      scanf( %d%d ,&n,&m); n      rep(i,1,n) { n       rep(j,1,m) { n        scanf( %d ,&a[i][j]); n        e[++tot]={i,j,a[i][j]}; n       } n      } n      sort(e+1,e+1+tot,cmp); n      for(int i=1;i<=m;i++) { n       int x = e[i].x; n       int y = e[i].y; n       int z = e[i].v; n       for(int j=i+1;j<=m;j++) { n        if(e[j].v==a[x][i]&&e[j].x==x&&e[j].y==i) { n         e[j].y=y; n         break; n        } n       } n       swap(a[x][i],a[x][y]); n      } n      rep(i,1,n) { n       rep(j,1,m) { n        printf( %d ,a[i][j]); n        if(j!=m) printf(   ); n        else printf(  n ); n       } n      } n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200100; n mt19937 rnd; n struct Treap { n   int id, y, best; n   Treap *l, *r; n   Treap(int id) : id(id), y(rnd()), best(id), l(NULL), r(NULL) {} n }; n int n, m; n int x[MAXN]; n long long len[MAXN]; n int p[MAXN], b[MAXN]; n set<pair<int, int> > alive; n int c[MAXN]; n void update(Treap *&t) { n   if (t) { n     t->best = t->id; n     if (t->l && x[t->l->best] < x[t->best]) t->best = t->l->best; n     if (t->r && x[t->r->best] < x[t->best]) t->best = t->r->best; n   } n } n void merge(Treap *&t, Treap *l, Treap *r) { n   if (!l) n     t = r; n   else if (!r) n     t = l; n   else if (l->y < r->y) { n     merge(l->r, l->r, r); n     t = l; n   } else { n     merge(r->l, l, r->l); n     t = r; n   } n   update(t); n } n void split(Treap *t, Treap *&l, Treap *&r, long long k, int id) { n   if (!t) { n     l = r = NULL; n   } else if (x[t->id] + len[t->id] < k || n              (x[t->id] + len[t->id] == k && t->id < id)) { n     split(t->r, t->r, r, k, id); n     l = t; n   } else { n     split(t->l, l, t->l, k, id); n     r = t; n     update(t); n   } n } n Treap *t; n void insert(int id) { n   Treap *L, *R; n   split(t, L, R, x[id] + len[id], id); n   merge(t, L, new Treap(id)); n   merge(t, t, R); n } n void erase(Treap *&t, int id) { n   if (t->id == id) { n     merge(t, t->l, t->r); n   } else if (x[t->id] + len[t->id] < x[id] + len[id] || n              (x[t->id] + len[t->id] == x[id] + len[id] && t->id < id)) { n     erase(t->r, id); n   } else { n     erase(t->l, id); n   } n   update(t); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   rnd = mt19937(0xdeadbeef); n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     cin >> x[i] >> len[i]; n     insert(i); n   } n   for (int i = 0; i < m; ++i) { n     cin >> p[i] >> b[i]; n     Treap *L, *R; n     split(t, L, R, p[i], 0); n     int best = R ? R->best : -1; n     merge(t, L, R); n     if (best != -1 && x[best] <= p[i]) { n       erase(t, best); n       len[best] += b[i]; n       insert(best); n       ++c[best]; n       while (true) { n         auto it = alive.upper_bound(make_pair(x[best] - 1, 1e9)); n         if (it != alive.end() && it->first <= x[best] + len[best]) { n           ++c[best]; n           erase(t, best); n           len[best] += b[it->second]; n           insert(best); n           alive.erase(it); n         } else n           break; n       } n     } else { n       alive.insert(make_pair(p[i], i)); n     } n   } n   for (int i = 0; i < n; ++i) cout << c[i] <<     << len[i] <<   n ; 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     string s, s1, s2; n     cin >> s >> s1 >> s2; n     bool lock = false; n     for (int i = 0; i < s.length(); i++) { n       if (s[i] == s2[i]) { n         swap(s1[i], s2[i]); n       } else { n         if (s1[i] == s2[i]) { n           swap(s[i], s2[i]); n         } else { n           lock = true; n           break; n         } n       } n     } n     if (lock) n       cout <<  NO  << endl; n     else { n       if (s == s1) n         cout <<  YES  << endl; n       else n         cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int sz = 2e5; n long long int col[sz], vis[sz]; n vector<long long int> adj[sz]; n long long int n; n void reset() { n   long long int i; n   for (i = 0; i < n + 14; i++) { n     col[i] = -1; n     adj[i].clear(); n     vis[i] = 0; n   } n } n void coloring(long long int n, long long int c) { n   vis[n] = 1; n   col[n] = c; n   for (auto it : adj[n]) { n     if (vis[it] == 0) coloring(it, c ^ 1); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int i, j, k, len, x, y, z, c, f, flag, p, q, mx, mn, l, r, sum, ans, n       tmp, it, pos, avg, m, cnt; n   long long int t; n   cin >> t; n   while (t--) { n     f = 0; n     flag = 0; n     ans = 0; n     cnt = 0; n     sum = 0; n     mn = LLONG_MAX; n     mx = LLONG_MIN; n     string s; n     cin >> n >> m; n     reset(); n     for (i = 0; i < m; i++) { n       cin >> l >> r; n       adj[l].push_back(r); n       adj[r].push_back(l); n     } n     coloring(1, 0); n     vector<long long int> sol1, sol2; n     for (i = 1; i <= n; i++) { n       if (col[i]) n         sol1.push_back(i); n       else n         sol2.push_back(i); n     } n     if (sol2.size() < sol1.size()) { n       cout << sol2.size() <<   n ; n       for (auto dsp : sol2) cout << dsp <<    ; n       cout <<   n ; n       ; n     } else { n       cout << sol1.size() <<   n ; n       for (auto dsp : sol1) cout << dsp <<    ; n       cout <<   n ; n       ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int lbracket = s.length(), rbracket = -1, lcolon = s.length(), rcolon = -1; n   for (int i = 0; i < s.length(); i++) n     if (s[i] ==  [ ) { n       lbracket = i; n       break; n     } n   for (int i = lbracket; i < s.length(); i++) n     if (s[i] ==  : ) { n       lcolon = i; n       break; n     } n   for (int i = s.length() - 1; i > -1; i--) n     if (s[i] ==  ] ) { n       rbracket = i; n       break; n     } n   for (int i = rbracket; i > -1; i--) n     if (s[i] ==  : ) { n       rcolon = i; n       break; n     } n   if (lcolon < rcolon) { n     int ans = 4; n     for (int i = lcolon + 1; i < rcolon; i++) n       if (s[i] ==  | ) ans++; n     cout << ans; n   } else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 1001000; n long long a[NMAX * 2]; n long long n, l, t; n long long cnt(int i, int j) { n   long long v = (a[i] - a[j] + t * 2 + l) / l; n   return v; n } n long double ans(int i) { n   int lo = i + 2, hi = i + n; n   long long tv = cnt(i, i + 1); n   while (lo < hi) { n     int m = (lo + hi) / 2; n     if (cnt(i, m) < tv) { n       hi = m; n     } else { n       lo = m + 1; n     } n   } n   if (hi == i + n) { n     long double v = (long double)tv * (n - 1) / 4; n     return v; n   } n   long double v = n       (long double)((tv - 1) * (i + n - hi) + tv * (hi - i - 1)) / 4; n   return v; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   cin >> n >> l >> t; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     a[i + n] = a[i] + l; n   } n   long double out = 0; n   for (int i = 0; i < n; ++i) { n     out += ans(i); n   } n   cout << fixed << setprecision(5) << out << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Mod = 1e9 + 7; n const long long maxn = 700 + 10; n long long n; n long long brac[maxn]; n char s[maxn]; n stack<long long> sta; n inline long long read() { n   long long x = 0; n   bool fopt = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) fopt = 0; n   for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - 48; n   return fopt ? x : -x; n } n long long f[maxn][maxn][3][3]; n void dfs(long long l, long long r) { n   if (r == l + 1) n     return f[l][r][0][1] = f[l][r][1][0] = f[l][r][0][2] = f[l][r][2][0] = 1, n            void(); n   if (brac[l] == r) { n     dfs(l + 1, r - 1); n     for (long long i = 0; i <= 2; i++) n       for (long long j = 0; j <= 2; j++) { n         if (i != 1) n           f[l][r][1][0] = (f[l][r][1][0] + f[l + 1][r - 1][i][j]) % Mod; n         if (i != 2) n           f[l][r][2][0] = (f[l][r][2][0] + f[l + 1][r - 1][i][j]) % Mod; n         if (j != 1) n           f[l][r][0][1] = (f[l][r][0][1] + f[l + 1][r - 1][i][j]) % Mod; n         if (j != 2) n           f[l][r][0][2] = (f[l][r][0][2] + f[l + 1][r - 1][i][j]) % Mod; n       } n   } else { n     dfs(l, brac[l]); n     dfs(brac[l] + 1, r); n     for (long long i = 0; i <= 2; i++) n       for (long long j = 0; j <= 2; j++) n         for (long long k = 0; k <= 2; k++) n           for (long long q = 0; q <= 2; q++) n             if (!(j && j == k)) n               f[l][r][i][q] = n                   (f[l][r][i][q] + n                    f[l][brac[l]][i][j] * f[brac[l] + 1][r][k][q] % Mod) % n                   Mod; n   } n } n signed main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   for (long long i = 1; i <= n; i++) { n     if (s[i] ==  ( ) n       sta.push(i); n     else n       brac[sta.top()] = i, sta.pop(); n   } n   dfs(1, n); n   long long ans = 0; n   for (long long i = 0; i <= 2; i++) n     for (long long j = 0; j <= 2; j++) ans = (ans + f[1][n][i][j]) % Mod; n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h> n #pragma GCC optimize ( -O3 ) n #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); n #define ll long long n #define double long double n #define pb push_back n #define mod 1000000007 n #define int long long n #define endl   n  n #define ss second n #define ff first n #define INF 1000000000 n #define all(a) a.begin(),a.end() n #define gcd(a, b) __gcd((a), (b)) n //ceil(a/b) is equal to (a+b-1)/b n using namespace std; n  n  n int power(int a,int n,int p) n { n     int res=1; n     while(n) n     { n         if(n%2) n         { n         res=(res*a)%p; n         n--;} n         else n         { n         a=(a*a)%p; n         n=n/2;} n     } n     return res; n } n  n   n int binarySearch(int arr[],int l,int r,int x)  n {  n     int mid; n     while(l<=r) n     { n         mid=(l+r)/2; n         if(arr[mid]==x) n             return mid; n         if(arr[mid]<x) n             l=mid+1; n         else n             r=mid-1; n     } n     return -1; n }  n   n  n int fact(int n,int k)       //for calculating nCk n { n     int ans=1; n     if(k>n-k) n     { n         k=n-k; n     } n     for(int i=1;i<=k;i++) n     { n         ans*=(n-i+1); n         ans/=i; n     } n     return ans; n } n // cout << std::fixed; n // std::cout << std::setprecision(9);  n // auto it = lower_bound(v.begin(), v.end(), n);  n  n  n  int32_t main() n { n     IOS; n     int t; n     cin>>t; n     while(t--) n     { n         int n; n         cin>>n; n         int a[n+1]; n            std::map<int, int> m; n         for(int i=0;i<n;i++){ n             cin>>a[i]; n             m[a[i]]++; n         } n         set<int>s; n         std::map<int, int> m1; n         for(auto x:m) n         { n             s.insert(x.ss); n             m1[x.ss]++; n         } n         int ans=INF; n         for(int x:s) n         { n             int cnt=0; n             for(auto y:m1) n             { n                 if(y.ff<x){ n                     cnt+=y.ss*y.ff; n                 } n                 else n                 { n                     cnt+=abs(y.ff-x)*y.ss; n                 } n             } n             ans=min(ans,cnt); n         } n  n         cout<<ans<<endl; n  n     } n }         n      n  n  n  n  n          n


#include <bits/stdc++.h> n using namespace std; n const int N = 15e4 + 10; n long long a[N]; n bool vis[N]; n int main() { n   int n; n   scanf( %d , &n); n   set<pair<long long, int> > se; n   for (int i = 0; i < n; i++) { n     scanf( %lld , a + i); n     se.insert(pair<long long, int>(a[i], i)); n   } n   int sz = n; n   while (!se.empty()) { n     pair<long long, int> x = *se.begin(); n     if (!se.empty()) { n       se.erase(se.begin()); n       pair<long long, int> y = *se.begin(); n       if (x.first == y.first) { n         se.erase(se.begin()); n         se.insert(pair<long long, int>(y.first * 2, y.second)); n         vis[x.second] = true; n         sz--; n         a[y.second] = y.first * 2; n       } n     } else n       break; n   } n   printf( %d n , sz); n   for (int i = 0; i < n; i++) { n     if (vis[i]) continue; n     printf( %lld  , a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 2005; n int n; n int p[Maxn], b[Maxn]; n int inb[Maxn]; n int res; n int best[Maxn]; n vector<pair<int, int> > seq; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &p[i]); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &b[i]); n     inb[b[i]] = i; n   } n   for (int i = 1; i <= n; i++) p[i] = inb[p[i]]; n   for (int i = 1; i <= n; i++) { n     int pos = i; n     while (p[pos] != i) pos++; n     res += pos - i; n     best[i] = p[i]; n     for (int j = i + 1; j < pos; j++) best[j] = max(best[j - 1], p[j]); n     for (int j = pos - 1; j >= i; j--) n       if (best[j] == p[j]) { n         seq.push_back(pair<int, int>(j, pos)); n         swap(p[j], p[pos]); n         pos = j; n       } n   } n   printf( %d n , res); n   printf( %d n , seq.size()); n   for (int i = 0; i < seq.size(); i++) n     printf( %d %d n , seq[i].first, seq[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<pair<int, int> > p; n set<pair<int, int> > h; n set<pair<int, int> > v; n int cut(); n int cut(set<pair<int, int> >::iterator s, set<pair<int, int> >::iterator e) { n   int c = 0; n   vector<int> all; n   while (s != e) { n     all.push_back(s->second); n     ++s; n   } n   for (int &x : all) { n     h.erase(pair<int, int>(p[x].first, x)); n     v.erase(pair<int, int>(p[x].second, x)); n   } n   c += cut(); n   h.clear(); n   v.clear(); n   for (int &x : all) { n     h.insert(pair<int, int>(p[x].first, x)); n     v.insert(pair<int, int>(p[x].second, x)); n   } n   c += cut(); n   return c; n } n int cut() { n   set<pair<int, int> >::iterator xs = h.begin(); n   set<pair<int, int> >::iterator ys = v.begin(); n   set<pair<int, int> >::iterator xe = h.end(); n   set<pair<int, int> >::iterator ye = v.end(); n   --xe; n   --ye; n   for (int i = 0; i < (int)h.size() / 2; ++i) { n     set<pair<int, int> >::iterator nxs = xs; n     ++nxs; n     if (xs->first + 1 < nxs->first) { n       return cut(h.begin(), nxs); n     } n     ++xs; n     set<pair<int, int> >::iterator nxe = xe; n     --xe; n     if (xe->first + 1 < nxe->first) { n       return cut(nxe, h.end()); n     } n     set<pair<int, int> >::iterator nys = ys; n     ++nys; n     if (ys->first + 1 < nys->first) { n       return cut(v.begin(), nys); n     } n     ++ys; n     set<pair<int, int> >::iterator nye = ye; n     --ye; n     if (ye->first + 1 < nye->first) { n       return cut(nye, v.end()); n     } n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     int x, y; n     cin >> x >> y; n     p.push_back(pair<int, int>(x, y)); n     h.insert(pair<int, int>(x, i)); n     v.insert(pair<int, int>(y, i)); n   } n   cout << cut() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans, x, mn = 100001; n vector<int> A, B; n map<int, int> Ps1, Ps2, Mn; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     Ps1[x] = i; n   } n   for (int i = 0; i < n; i++) { n     cin >> x; n     Ps2[i] = Ps1[x]; n   } n   for (int i = n - 1; i >= 0; i--) { n     mn = min(mn, Ps2[i]); n     Mn[i] = mn; n   } n   for (int i = 0; i < n; i++) { n     if (Ps2[i] > Mn[i]) ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int num[5005]; n int rmq(int l, int r) { n   int ans = 1 << 30, tmp = l; n   for (int i = l; i <= r; i++) { n     if (ans > num[i]) { n       ans = num[i]; n       tmp = i; n     } n   } n   return tmp; n } n int get(int l, int r, int h) { n   if (l > r) return 0; n   if (l == r) { n     if (num[l] == h) n       return 0; n     else n       return 1; n   } n   int tmp = rmq(l, r); n   int ans = 0; n   ans = min(r - l + 1, get(l, tmp - 1, num[tmp]) + get(tmp + 1, r, num[tmp]) + n                            num[tmp] - h); n   return ans; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &num[i]); n   int ans = get(0, n - 1, 0); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int g2[1002][1002]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = n; i <= m; i++) { n     int ind = 0; n     string s = to_string(i); n     string m = s; n     sort(s.begin(), s.end()); n     for (int p = 1; p < s.size(); p++) n       if (s[p] == s[p - 1]) { n         ind = 1; n         break; n       } n     if (ind == 1) continue; n     cout << m; n     return 0; n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int c1, c2, x, y; n long long int comp(long long int t) { n   long long int r1 = t / x, r2 = t / y, l = x * y, both = t / l; n   long long int left = t - r1 - r2 + both; n   r1 = r1 - both; n   r2 = r2 - both; n   long long int left1 = c1 - r2, left2 = c2 - r1; n   if (left1 < 0) left1 = 0; n   if (left2 < 0) left2 = 0; n   if (left1 + left2 <= left) n     return 1; n   else n     return 0; n } n long long int bs() { n   long long int st = 0, en = 1e18; n   while (en - st > 1) { n     long long int mid = (st + en) / 2; n     if (comp(mid)) n       en = mid; n     else n       st = mid; n   } n   return en; n } n int main() { n   cin >> c1 >> c2 >> x >> y; n   cout << bs(); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, cnt; n long long arr[100000], h[100000]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (long long i = 0; i <= n - 1; i++) { n     cin >> arr[i]; n     h[i] = arr[i]; n   } n   sort(h, h + n); n   for (long long i = 0; i <= n - 1; i++) { n     if (arr[i] != h[i]) cnt++; n   } n   if (cnt > 2) n     cout <<  NO n ; n   else n     cout <<  YES n ; n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:1608864 ) n void ASS(bool b) { n   if (!b) ++*(int*)0; n } n int main() { n   int n, m, k; n   scanf( %d %d %d , &n, &m, &k); n   const int inf = 1 << 30; n   vector<int> v(m, inf); n   for (int i = 0; i < (int)(n); i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     x--; n     v[x] = min(v[x], y); n   } n   int res = 0; n   for (int i = 0; i < (int)(m); i++) res += v[i]; n   res = min(res, k); n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y; n   point(){}; n   point(int xx, int yy) { n     x = xx; n     y = yy; n   } n   point friend operator+(point a, point b) { n     return point(a.x + b.x, a.y + b.y); n   } n   point friend operator-(point a, point b) { n     return point(a.x - b.x, a.y - b.y); n   } n   long long friend operator*(point a, point b) { n     return (long long)a.x * b.y - (long long)a.y * b.x; n   } n } a[5050], s[5050]; n int n, tot; n long long S; n bool cmp(point a, point b) { n   if (a.x != b.x) return a.x < b.x; n   return a.y < b.y; n } n void put(point a) { printf( %d %d n , a.x, a.y); } n long long area(int i, int j, int k) { n   return abs((s[j] - s[i]) * (s[k] - s[i])); n } n int main() { n   scanf( %d%I64d , &n, &S); n   for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].y); n   sort(a + 1, a + 1 + n, cmp); n   for (int i = 1; i <= n; i++) { n     while (tot > 1 && (a[i] - s[tot - 1]) * (s[tot] - s[tot - 1]) <= 0) tot--; n     s[++tot] = a[i]; n   } n   int k = tot; n   for (int i = n - 1; i > 0; i--) { n     while (tot > k && (a[i] - s[tot - 1]) * (s[tot] - s[tot - 1]) <= 0) tot--; n     s[++tot] = a[i]; n   } n   tot--; n   S = 0; n   int ii, jj, kk; n   for (int i = 1; i < tot - 1; i++) { n     int tmp = i + 2; n     for (int j = i + 1; j <= tot; j++) { n       while (tmp < tot && area(i, j, tmp + 1) > area(i, j, tmp)) tmp++; n       if (area(i, j, tmp) > S) { n         S = area(i, j, tmp); n         ii = i; n         jj = j; n         kk = tmp; n       } n     } n   } n   put(s[ii] + s[jj] - s[kk]); n   put(s[jj] + s[kk] - s[ii]); n   put(s[kk] + s[ii] - s[jj]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 23333; n int aa[maxn]; n int p[maxn]; n int main() { n   int a, b, w, x, c; n   scanf( %d%d%d%d%d , &a, &b, &w, &x, &c); n   c -= a; n   if (c <= 0) { n     printf( 0 n ); n     return 0; n   } n   int m = 0, haj; n   for (int i = b; !p[i];) { n     p[i] = ++m; n     if (i >= x) { n       i -= x; n       aa[m] = 1; n     } else { n       i = w - x + i; n     } n     if (p[i]) haj = p[i]; n   } n   for (int i = 1; i < haj; ++i) { n     c -= aa[i]; n     if (c <= 0) { n       printf( %d n , i); n       return 0; n     } n   } n   long long sum = (long long)haj - 1; n   int s = 0; n   for (int i = haj; i <= m; ++i) s += aa[i]; n   sum += (long long)((c - 1) / s) * (long long)(m - haj + 1); n   c -= ((c - 1) / s) * s; n   for (int i = haj; i <= m && c > 0; ++i) { n     c -= aa[i]; n     ++sum; n   } n   printf( %I64d n , sum); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 50; n int t, m, n; n long long su, s[maxn], cf[maxn]; n int a[maxn], b[maxn], c[maxn], x, y; n int main() { n   scanf( %d %d , &n, &m); n   scanf( %d , a + 1); n   for (int i = 2; i <= m; ++i) { n     scanf( %d , a + i); n     su += abs(a[i] - a[i - 1]); n   } n   for (int i = 1; i <= n; ++i) s[i] = su; n   for (int i = 1; i <= m - 1; ++i) { n     x = min(a[i], a[i + 1]), y = max(a[i], a[i + 1]); n     if (x == y) continue; n     s[x] += x - 1; n     s[y] += 2 * x - y; n     if (x + 1 == y) continue; n     b[i] = x + 1; n     c[i] = y - 1; n   } n   for (int i = 1; i <= m - 1; ++i) { n     x = b[i]; n     y = c[i]; n     --cf[x]; n     ++cf[y + 1]; n   } n   for (int i = 1; i <= n; i++) { n     cf[i] = cf[i - 1] + cf[i]; n     s[i] += cf[i]; n   } n   for (int i = 1; i <= n; ++i) printf( %lld  , s[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n int n, m; n vector<int> g[MAXN]; n int max1[MAXN], max2[MAXN]; n bool vis[MAXN]; n void dfs(int v) { n   vis[v] = true; n   for (auto to : g[v]) { n     if (!vis[to]) { n       dfs(to); n       if (max1[v] <= max1[to] + 1) { n         max2[v] = max1[v]; n         max1[v] = max1[to] + 1; n       } else if (max2[v] < max1[to] + 1) { n         max2[v] = max1[to] + 1; n       } n     } n   } n } n int ans; n int main() { n   cin >> n >> m; n   while (m--) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) dfs(i); n   for (int i = 1; i <= n; i++) ans = max(ans, max1[i] + max2[i]); n   cout << ans; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) n #define f first n #define s second n #define for1(i,a,b) for (int i = a; i < b; i++) n #define for2(i,a,b) for (int i = a; i > b; i--) n #define arrin(a,n) for (int i = 0; i < n; i++) cin >> a[i]; n #define arrout(a,n) for (int i = 0; i < n; i++) cout << a[i] <<    ; cout <<   n ; n #define arrin2d(a,m,n) for (int i = 0; i < m; i++){for (int j = 0; j < n; j++) cin >> a[i][j];} n #define arrout2d(a,m,n) for (int i = 0; i < m; i++){for (int j = 0; j < n; j++) cout << a[i][j] <<    ; cout <<   n ;} n #define w(t) int t; cin >> t; while(t--) n #define strin(s) getline(cin,s) n #define pushb push_back n #define popb pop_back n #define pushf push_front n #define popf pop_front n #define mp make_pair n #define lower_bound lb n #define upper_bound ub n #define yes cout <<  YES n  n #define no cout <<  NO n  n  n typedef long long ll; n typedef long double ld; n typedef vector<int> vi; n typedef vector<ll> vll; n typedef vector<pair<int,int>> vp; n typedef vector<char> vch; n typedef vector<string> vstr; n typedef set<ll> sll; n typedef pair<int,int> pi; n typedef map<int,int> mi; n typedef map<int,char> mch; n //typedef __int128_t vvlint; n  n const int inf = 1e9 + 7; n /* n freopen( input.txt ,  r , stdin); n freopen( output.txt ,  w , stdout); n */ n  n void tc() n { n  int a1,a2,a3,a4,a5,c1,c2,c3; n  cin >> c1 >> c2 >> c3; n  cin >> a1 >> a2 >> a3 >> a4 >> a5; n   n  if (a1 <= c1 && a2 <= c2 && a3 <= c3) n  { n      c1 -= a1; n      c2 -= a2; n      c3 -= a3; n       n      a4 -= min(a4,c1); n      a5 -= min(a5,c2); n       n      if (a4 + a5 <= c3) n          yes; n      else n          no; n  } n  else n      no; n } n  n int main() n { n  fastio; n   n  w(t) n  { n   tc();  n  } n   n  return 0;  n }


#include <bits/stdc++.h> n int n; n char a[11][11], b[11][11], c[11][11]; n void turn() { n   int i, j, k, l; n   for (i = n - 1, k = 0; i >= 0; --i, ++k) n     for (j = 0, l = 0; j < n; ++j, ++l) c[k][l] = a[j][i]; n   for (i = 0; i < n; ++i) n     for (j = 0; j < n; ++j) a[i][j] = c[i][j]; n } n int same() { n   int i, j; n   for (i = 0; i < n; ++i) n     for (j = 0; j < n; ++j) n       if (a[i][j] != b[i][j]) return 0; n   return 1; n } n void p() { n   int i, j; n   printf(  n n ); n   for (i = 0; i < n; ++i) { n     for (j = 0; j < n; ++j) printf( %c , a[i][j]); n     printf(  n ); n   } n   printf(  n n ); n } n void f() { n   int i, j; n   for (i = 0; i < 3; ++i) { n     if (same()) { n       printf( Yes n ); n       return; n     } n     turn(); n   } n   if (same()) { n     printf( Yes n ); n     return; n   } n   for (i = 0; i < n; ++i) n     for (j = 0; j < n; ++j) c[i][j] = a[i][n - j - 1]; n   for (i = 0; i < n; ++i) n     for (j = 0; j < n; ++j) a[i][j] = c[i][j]; n   for (i = 0; i < 3; ++i) { n     if (same()) { n       printf( Yes n ); n       return; n     } n     turn(); n   } n   if (same()) { n     printf( Yes n ); n     return; n   } n   printf( No n ); n   return; n } n int main() { n   scanf( %d , &n); n   int i, j; n   for (i = 0; i < n; ++i) scanf( %s , a[i]); n   for (i = 0; i < n; ++i) scanf( %s , b[i]); n   f(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 1e6 + 6; n bool us[N], use[N]; n long long a[N]; n long long n, x, k, q, x1, x2, y, ibibibibbibibibiibigbabypanfewewf, y2, ans, m; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> x1; n   for (int I = 0; I < x1; I++) { n     cin >> n; n     y = 0; n     ibibibibbibibibiibigbabypanfewewf = 1e9 + 7; n     for (int i = 1; i <= n; i++) { n       cin >> k >> q; n       y = max(y, k); n       ibibibibbibibibiibigbabypanfewewf = n           min(ibibibibbibibibiibigbabypanfewewf, q); n     } n     cout << max(0ll, y - ibibibibbibibibiibigbabypanfewewf) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int n, long long int p) { n   long long int result = 1; n   while (n > 0) { n     if (n % 2 == 1) result = (result % p * x % p) % p; n     x = (x % p * x % p) % p; n     n = n / 2; n   } n   return result % p; n } n void solve() { n   long long int n, m; n   cin >> n >> m; n   vector<long long int> cnt(1005); n   for (long long int i = 0; i <= n - 1; i++) { n     long long int a1; n     cin >> a1; n     cnt[a1] = 1; n   } n   for (long long int i = 0; i <= m - 1; i++) { n     long long int a2; n     cin >> a2; n     if (cnt[a2] == 1) cnt[a2]++; n   } n   for (long long int i = 1; i <= 1000; i++) { n     if (cnt[i] >= 2) { n       cout <<  YES  << endl; n       cout <<  1   << i << endl; n       return; n     } n   } n   cout <<  NO  << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int i, a[26], ans = 0, tot = 0; n   string s; n   map<pair<long long int, long long int>, long long int> mp; n   for (i = 0; i < 26; i++) cin >> a[i]; n   cin >> s; n   for (i = 0; i < s.length(); i++) { n     ans += mp[{s[i] -  a , tot}]; n     tot += a[s[i] -  a ]; n     mp[{s[i] -  a , tot}]++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n T max(T a, T b, T c) { n   return max(a, max(b, c)); n } n using namespace std; n int main() { n   cin.tie(NULL), ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     if (a > b) { n       if ((b - a) % 2 == 0) n         cout << 1 <<   n ; n       else n         cout << 2 <<   n ; n     } else if (a == b) n       cout << 0 <<   n ; n     else { n       if ((b - a) % 2 != 0) n         cout << 1 <<   n ; n       else n         cout << 2 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n double pi = 3.14159265359; n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   string a, b; n   cin >> a >> b; n   string c(a.size(),  0 ); n   int count = 0; n   for (unsigned int i = 0; i < a.size(); i++) n     if (a[i] == b[i]) c[i] = a[i], count++; n   if ((a.size() - count) % 2) n     cout <<  impossible ; n   else { n     bool ok = 0; n     for (unsigned int i = 0; i < a.size(); i++) n       if (a[i] != b[i] && !ok) n         c[i] = a[i], ok = 1; n       else if ((a[i] != b[i] && ok)) n         c[i] = b[i], ok = 0; n     cout << c <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mul[100010], inv[100010]; n const int mod = 998244353; n const int maxn = 5050; n void init() { n   mul[0] = 1; n   for (int i = 1; i < maxn; i++) mul[i] = (mul[i - 1] * i) % mod; n   inv[0] = inv[1] = 1; n   for (int i = 2; i < maxn; i++) n     inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod; n   for (int i = 1; i < maxn; i++) inv[i] = (inv[i - 1] * inv[i]) % mod; n } n long long C(int n, int m) { return mul[n] * inv[m] % mod * inv[n - m] % mod; } n long long f(long long a, long long b) { n   long long ans = 0; n   for (int i = 0; i <= min(a, b); i++) n     ans = (ans + C(a, i) * C(b, i) % mod * mul[i] % mod) % mod; n   return ans; n } n int main() { n   int a, b, c; n   init(); n   cin >> a >> b >> c; n   cout << f(a, b) * f(a, c) % mod * f(b, c) % mod << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n int rev(int n) { n   int ret = 0; n   while (n != 0) { n     ret = (10 * ret) + (n % 10); n     n /= 10; n   } n   return ret; n } n int main() { n   int mx, my, w; n   int i, j, k, t; n   int ax, ay; n   vector<int> v; n   map<pair<int, int>, vector<int> > mp; n   scanf( %d%d%d , &mx, &my, &w); n   for (i = 1; i <= my; i++) { n     j = rev(i); n     k = gcd(i, j); n     mp[make_pair(i / k, j / k)].push_back(i); n   } n   vector<int> vec(my + 1, 0); n   vector<vector<int> > vv; n   vv.push_back(v); n   for (i = 1; i <= mx; i++) { n     j = rev(i); n     k = gcd(i, j); n     v = mp[make_pair(j / k, i / k)]; n     for (j = 0; j < v.size(); j++) vec[v[j]]++; n     vv.push_back(v); n   } n   long long ans = -1; n   for (i = mx, j = 0, k = 0; i > 0; i--) { n     if (k < w && j < my) { n       do { n         j++; n         k += vec[j]; n       } while (k < w && j < my); n     } n     if (k >= w && (ans == -1 || ans > (long long)i * j)) { n       ans = (long long)i * j; n       ax = i; n       ay = j; n     } n     for (t = 0; t < vv[i].size(); t++) { n       if (vv[i][t] <= j) k--; n       vec[vv[i][t]]--; n     } n   } n   if (ans == -1) n     printf( -1 n ); n   else n     printf( %d %d n , ax, ay); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5e5 + 10; n int n, a[N], b[N], c[N], p[N]; n vector<int> v; n int main() { n   cin >> n; n   for (int i = 1; i < N; i++) p[i] = i; n   for (int i = 1; i <= n; i++) { n     cin >> a[i] >> b[i]; n     if (a[i] == 2) cin >> c[i]; n   } n   for (int i = n; i >= 1; i--) { n     if (a[i] == 1) n       v.push_back(p[b[i]]); n     else if (a[i] == 2) n       p[b[i]] = p[c[i]]; n   } n   for (int i = v.size() - 1; i >= 0; i--) printf( %d  , v[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n queue<int> qQuit; n int ind[100000], n; n bool entered[100000]; n priority_queue<pair<int, int>, vector<pair<int, int> >, n                greater<pair<int, int> > > n     qLeft, qRight; n int data[100000]; n int main(void) { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int temp; n     scanf( %d , &temp); n     ind[temp - 1] = i; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , data + i); n     data[i]--; n   } n   for (int i = 0; i < n; i++) { n     qQuit.push(data[i]); n     if (i >= ind[data[i]]) n       qRight.push(make_pair(i - ind[data[i]], data[i])); n     else { n       qLeft.push(make_pair(ind[data[i]] - i, data[i])); n       entered[data[i]] = true; n     } n   } n   for (int i = 0; i < n; i++) { n     int minVal = 99999999; n     int minFrom; n     if (qRight.size()) { n       if (minVal > qRight.top().first - i) minFrom = qRight.top().second; n       minVal = min(minVal, qRight.top().first - i); n     } n     while (qLeft.size() && entered[qLeft.top().second] == false) qLeft.pop(); n     if (qLeft.size()) { n       if (minVal > qLeft.top().first + i) minFrom = qLeft.top().second; n       minVal = min(minVal, qLeft.top().first + i); n     } n     printf( %d n , minVal); n     while (qRight.size() && qRight.top().first - i == 0) { n       pair<int, int> val = qRight.top(); n       qRight.pop(); n       qLeft.push(make_pair(-i, val.second)); n       entered[val.second] = true; n     } n     int toQuit = qQuit.front(); n     qQuit.pop(); n     entered[toQuit] = false; n     qRight.push(make_pair(n - 1 - ind[toQuit] + (i + 1), toQuit)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dque[500005]; n int s = 0, t = 0, num = 0, q, maxi; n double mean = 0; n int main() { n   memset(dque, 0, sizeof(dque)); n   scanf( %d , &q); n   while (q--) { n     int type, x; n     scanf( %d , &type); n     if (type == 1) { n       scanf( %d , &x); n       if (num != 0) { n         mean = (mean * num + x - maxi) / num; n         dque[t++] = maxi; n       } else { n         mean = x; n         num++; n       } n       maxi = x; n       while (s < t && dque[s] < mean) { n         mean = (mean * num + dque[s]) / (num + 1); n         num++; n         s++; n       } n     } else n       printf( %.10f n , (double)maxi - mean); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   deque<int> vec(300000); n   int l = 0, r = 0; n   for (int i = 0; i < n; i++) { n     string s; n     int id; n     cin >> s >> id; n     if (!i) { n       vec[id] = l; n       l--, r++; n     } else { n       if (s ==  L ) { n         vec[id] = l; n         l--; n       } n       if (s ==  R ) { n         vec[id] = r; n         r++; n       } n       if (s ==  ? ) { n         cout << min(abs(vec[id] - l), abs(vec[id] - r)) - 1 << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> adj[1002]; n map<long long, long long> vis; n map<pair<long long, long long>, long long> dia; n long long st[1002], en[1002]; n void dfs(long long tar, long long cur, bool &found, long long mini, n          long long &mini2) { n   vis[cur] = 1; n   if (tar == cur) { n     found = true; n     mini2 = min(mini, mini2); n     return; n   } n   for (long long i = 0; i < adj[cur].size(); i++) { n     if (vis[adj[cur][i]] == 0) { n       dfs(tar, adj[cur][i], found, min(mini, dia[{cur, adj[cur][i]}]), mini2); n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long t, n, num, m, k; n   cin >> n >> k; n   for (long long i = 0; i < k; i++) { n     long long a, b, d; n     cin >> a >> b >> d; n     adj[a].push_back(b); n     adj[b].push_back(a); n     st[a]++; n     en[b]++; n     dia[{a, b}] = d; n     dia[{b, a}] = d; n   } n   vector<long long> v1, v2; n   for (long long i = 1; i <= n; i++) { n     if (en[i] == 0 && st[i] == 1) { n       v1.push_back(i); n     } n     if (st[i] == 0 && en[i] == 1) { n       v2.push_back(i); n     } n   } n   cout << v1.size() <<   n ; n   for (long long i = 0; i < v1.size(); i++) { n     for (long long j = 0; j < v2.size(); j++) { n       bool found = false; n       long long mini2 = LLONG_MAX; n       dfs(v2[j], v1[i], found, LLONG_MAX, mini2); n       vis.clear(); n       if (found) { n         cout << v1[i] <<     << v2[j] <<     << mini2 <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char mp[1001][1001]; n int visit[1001][1001]; n int dist[1001][1001]; n int N, M; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, 1, -1}; n bool chk(int x, int y) { return 0 <= x && x < N && 0 <= y && y < M; } n void dfs(int x, int y, bool isfirst) { n   visit[x][y] = 1; n   if (!isfirst) dist[x][y] = 1; n   for (int i = 0; i < 4; i++) { n     int nx = x + dx[i]; n     int ny = y + dy[i]; n     if (chk(nx, ny) && mp[x][y] == mp[nx][ny] && visit[nx][ny] == 0) { n       dist[x][y] = 1; n       dfs(nx, ny, false); n     } n   } n } n int main(int argc, char *argv[]) { n   int Q; n   scanf( %d %d %d , &N, &M, &Q); 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       if (visit[i][j] == 0) dfs(i, j, true); n     } n   } n   queue<pair<int, int> > q; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < M; j++) { n       if (dist[i][j] == 1) q.push({i, j}); n     } n   } n   while (!q.empty()) { n     auto [x, y] = q.front(); n     q.pop(); n     for (int i = 0; i < 4; i++) { n       int nx = x + dx[i], ny = y + dy[i]; n       if (chk(nx, ny) && dist[nx][ny] == 0) { n         dist[nx][ny] = dist[x][y] + 1; n         q.push({nx, ny}); n       } n     } n   } n   while (Q--) { n     long long x, y, t; n     scanf( %lld %lld %lld , &x, &y, &t); n     printf( %lld n , dist[x - 1][y - 1] n                          ? ((mp[x - 1][y - 1] -  0 ) + n                             max(t - (dist[x - 1][y - 1] - 1), 0LL)) % n                                2 n                          : mp[x - 1][y - 1] -  0 ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-15; n const double pi = acos(-1.0); n const long long Mod = 1000000007; n const int N = 1e3 + 5; n int ks = 0; n int n, m, s, t; n long long dis[N], cost[N * 10], L; n int used[N], deleted[N * 10]; n pair<int, int> parent[N]; n vector<pair<int, int> > g[N]; n struct edge { n   int x, y; n   long long z; n   bool operator<(const edge &f) const { return z > f.z; } n } E[N * 10]; n void SPFA() { n   for (int i = 0; i < n; i++) { n     dis[i] = LLONG_MAX; n     used[i] = 0; n   } n   priority_queue<pair<long long, int>, vector<pair<long long, int> >, n                  greater<pair<long long, int> > > n       q; n   q.emplace(0, s); n   dis[s] = 0; n   while (q.size()) { n     int from = q.top().second; n     used[from] = 1; n     q.pop(); n     for (auto i : g[from]) { n       int to = i.first; n       int id = i.second; n       if (dis[from] + cost[id] < dis[to]) { n         dis[to] = dis[from] + cost[id]; n         parent[to] = {from, id}; n         if (!used[to]) q.emplace(dis[to], to); n       } n     } n   } n } n int main() { n   scanf( %d%d%I64d%d%d , &n, &m, &L, &s, &t); n   for (int i = 0; i < m; i++) { n     scanf( %d%d%I64d , &E[i].x, &E[i].y, &E[i].z); n   } n   sort(E, E + m); n   int last = 0; n   for (int i = 0; i < m && E[i].z; i++, last++) { n     cost[i] = E[i].z; n     g[E[i].x].emplace_back(E[i].y, i); n     g[E[i].y].emplace_back(E[i].x, i); n   } n   SPFA(); n   if (dis[t] < L) { n     puts( NO ); n     return 0; n   } n   for (int i = last; i < m; i++) { n     deleted[i] = cost[i] = 1; n     g[E[i].x].emplace_back(E[i].y, i); n     g[E[i].y].emplace_back(E[i].x, i); n   } n   SPFA(); n   if (dis[t] > L) { n     puts( NO ); n     return 0; n   } n   puts( YES ); n   while (dis[t] < L) { n     int cur = t; n     while (cur != s) { n       int id = parent[cur].second; n       cur = parent[cur].first; n       if (deleted[id]) { n         cost[id] += L - dis[t]; n         break; n       } n     } n     SPFA(); n   } n   bool done[N]; n   memset(done, false, sizeof done); n   for (int i = 0; i < n; i++) { n     for (auto j : g[i]) { n       if (done[j.first]) continue; n       cout << i <<     << j.first <<     << cost[j.second] <<   n ; n     } n     done[i] = true; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int pre = INT_MIN; n   int cur; n   int state = 0; n   for (int i = 0; i < n; i++) { n     cin >> cur; n     if (cur > pre) { n       if (state == 0) { n         pre = cur; n         continue; n       } else { n         cout <<  NO  << endl; n         return 0; n       } n     } else if (cur == pre) { n       if (state == 1) { n         pre = cur; n         continue; n       } n       if (state == 0) { n         pre = cur; n         state = 1; n         continue; n       } n       cout <<  NO  << endl; n       return 0; n     } else { n       if (state == 2) { n         pre = cur; n         continue; n       } n       if (state < 2) { n         pre = cur; n         state = 2; n         continue; n       } n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main(int argc, const char* argv[]) { n   int n; n   std::cin >> n; n   std::string s; n   std::cin >> s; n   std::vector<int> v0(n); n   for (int i = 0; i < n; i++) v0[i] = s[i] -  0 ; n   bool add = true; n   std::vector<int> v1(n); n   for (int i = 0; i < n; i++) { n     if (add) n       v1[i] = v0[i] + 1; n     else n       v1[i] = v0[i]; n     if (v1[i] == 2) { n       add = true; n       v1[i] = 0; n     } else n       add = false; n   } n   int count = 0; n   for (int i = 0; i < n; i++) n     if (v0[i] != v1[i]) count++; n   std::cout << count << std::endl; n   return 0; n } n