#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, U b) { n   if (a < b) a = b; n } n template <class T> n inline void gn(T &first) { n   char c, sg = 0; n   while (c = getchar(), (c >  9  || c <  0 ) && c !=  - ) n     ; n   for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ; n        c = getchar()) n     first = (first << 1) + (first << 3) + c -  0 ; n   if (sg) first = -first; n } n template <class T> n inline void print(T first) { n   if (first < 0) { n     putchar( - ); n     return print(-first); n   } n   if (first < 10) { n     putchar( 0  + first); n     return; n   } n   print(first / 10); n   putchar(first % 10 +  0 ); n } n template <class T, class T1> n inline void gn(T &first, T1 &second) { n   gn(first); n   gn(second); n } n template <class T, class T1, class T2> n inline void gn(T &first, T1 &second, T2 &z) { n   gn(first); n   gn(second); n   gn(z); n } n template <class T> n inline void println(T first) { n   print(first); n   putchar(  n ); n } n template <class T> n inline void printsp(T first) { n   print(first); n   putchar(   ); n } n template <class T1, class T2> n inline void print(T1 x1, T2 x2) { n   printsp(x1), println(x2); n } n template <class T1, class T2, class T3> n inline void print(T1 x1, T2 x2, T3 x3) { n   printsp(x1), printsp(x2), println(x3); n } n template <class T1, class T2, class T3, class T4> n inline void print(T1 x1, T2 x2, T3 x3, T4 x4) { n   printsp(x1), printsp(x2), printsp(x3), println(x4); n } n int son[400400][2], pa[400400], sz[400400]; n long long sum[400400]; n long long ans; n struct SplayTree { n   int root; n   void init(int first) { n     root = first; n     sz[first] = 1; n     sum[first] = first; n   } n   void push_up(int first) { n     sum[first] = first + sum[son[first][0]] + sum[son[first][1]]; n     sz[first] = 1 + sz[son[first][0]] + sz[son[first][1]]; n   } n   void rot(int first, int d) { n     int second = pa[first], z = pa[second]; n     son[second][!d] = son[first][d]; n     pa[son[first][d]] = second; n     pa[first] = pa[second]; n     if (son[z][0] == second) n       son[z][0] = first; n     else if (son[z][1] == second) n       son[z][1] = first; n     pa[second] = first; n     son[first][d] = second; n     push_up(second); n   } n   void splay(int first, int g) { n     while (pa[first] != g) { n       if (pa[pa[first]] == g) n         rot(first, son[pa[first]][0] == first); n       else { n         int second = pa[first], z = pa[second]; n         int d = (son[z][0] == second); n         son[second][d] == first ? rot(first, !d) : rot(second, d); n         rot(first, d); n       } n     } n     push_up(first); n     if (g == 0) root = first, pa[first] = 0; n   } n   void insert(int first, int second) { n     if (second < first) { n       if (son[first][0]) n         insert(son[first][0], second); n       else n         son[first][0] = second, pa[second] = first; n     } else { n       if (son[first][1]) n         insert(son[first][1], second); n       else n         son[first][1] = second, pa[second] = first; n     } n     push_up(first); n   } n   long long insert1(int first, int f) { n     son[first][0] = son[first][1] = 0; n     sz[first] = 1; n     insert(root, first); n     splay(first, 0); n     if (!f) return -(long long)first * sz[son[first][0]] + sum[son[first][0]]; n     return -sum[son[first][1]] + (long long)first * sz[son[first][1]]; n   } n   void get(int first, vector<int> &vec) { n     if (son[first][0]) get(son[first][0], vec); n     vec.push_back(first); n     if (son[first][1]) get(son[first][1], vec); n   } n } tree[400400]; n int id[400400], pos[400400]; n int nxt[400400]; n int find_nxt(int u) { return u == nxt[u] ? u : nxt[u] = find_nxt(nxt[u]); } n void merge(int u, int v, int f = 0) { n   if (sz[tree[u].root] < sz[tree[v].root]) swap(u, v), f = 1; n   vector<int> vec; n   tree[v].get(tree[v].root, vec); n   if (!f) reverse(vec.begin(), vec.end()); n   for (int i = 0; i < vec.size(); i++) { n     ans += tree[u].insert1(vec[i], f); n     id[pos[vec[i]]] = u; n   } n } n int main() { n   int n; n   gn(n); n   for (int i = 1; i < 400400; i++) nxt[i] = i; n   for (int i = 1; i <= n; i++) tree[i].init(i); n   for (int i = 0, a, b; i < n; i++) { n     gn(a, b); n     int aa = a; n     a = find_nxt(a); n     ans += (long long)(a - aa) * b; n     pos[b] = a; n     id[a] = b; n     nxt[a] = a + 1; n     if (nxt[a - 1] > a - 1) merge(id[a - 1], id[a]); n     if (nxt[a + 1] > a + 1) merge(id[a], id[a + 1]); n     println(ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2007; n const int mod = 998244353; n template <class I> n inline void read(I &x) { n   int f = 1; n   char c; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   for (x = 0; c >=  0  && c <=  9 ; n        x = (x << 3) + (x << 1) + (c & 15), c = getchar()) n     ; n   x *= f; n } n long long ksm(int x, int y) { n   long long res = 1; n   while (y) { n     if (y & 1) res = res * x % mod; n     y >>= 1; n     x = 1ll * x * x % mod; n   } n   return res; n } n long long f[2 * N][2 * N][2], jc[N * 2]; n int main() { n   int n, l, k; n   read(n), read(k), read(l); n   f[0][0][0] = 1; n   for (int i = 0; i <= 2 * n; i++) n     for (int j = 0; j <= i; j++) n       for (int o = 0; o <= 1; o++) { n         f[i + 1][j + 1][o] = (f[i + 1][j + 1][o] + f[i][j][o]) % mod; n         if (o == 0 && j >= k) n           f[i + 1][j][1] = (f[i + 1][j][1] + f[i][j][o]) % mod; n         if (j) f[i + 1][j - 1][o] = (f[i + 1][j - 1][o] + f[i][j][o] * j) % mod; n       } n   jc[0] = 1; n   for (int i = 1; i <= 2 * n + 1; i++) jc[i] = jc[i - 1] * i % mod; n   long long ans = f[2 * n + 1][0][1] * ksm(2, n) % mod * jc[n] % mod * n                   ksm(jc[2 * n + 1], mod - 2) % mod * l % mod; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n long long expow(long long a, long long b, long long p) { n   long long v = 1; n   for (; b; b >>= 1, a = a * a % p) n     if (b & 1) v = v * a % p; n   return v; n } n long long inv(long long a, long long p) { return expow(a, p - 2, p); } n using namespace std; n const int N = 1000 + 11; n const int M = 1000000007; n struct node { n   int a, b, c, d, e; n } p[N]; n node sub(node a, node b) { n   return (node){a.a - b.a, a.b - b.b, a.c - b.c, a.d - b.d, a.e - b.e}; n } n double mix(node a, node b) { n   return 1.0 * a.a * b.a + a.b * b.b + a.c * b.c + a.d * b.d + a.e * b.e; n } n vector<int> ans; n int main() { n   int k; n   scanf( %d , &k); n   for (int i = 0; i < k; i++) { n     scanf( %d%d%d%d%d , &p[i].a, &p[i].b, &p[i].c, &p[i].d, &p[i].e); n   } n   for (int j = 0; j < k; j++) { n     bool f = false; n     for (int i = 0; i < k; i++) n       if (i != j) { n         for (int l = 0; l < k; l++) n           if (l != i && l != j) { n             node cha = sub(p[j], p[i]), cha2 = sub(p[j], p[l]); n             double ding = mix(cha, cha2), n                    di = sqrt(mix(cha, cha)) * sqrt(mix(cha2, cha2)); n             double xx = ding / di; n             if (xx > 0 && xx <= 1) { n               f = true; n               break; n             } n           } n         if (f) break; n       } n     if (!f) ans.push_back(j + 1); n   } n   int sz = ans.size(); n   printf( %d n , sz); n   for (int j = 0; j < sz; j++) printf( %d n , ans[j]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n const int Inf = 0x3f3f3f3f; n struct Edge { n   int id; n   int u, v, w; n   Edge(int x = 0, int y = 0, int z = 0) : v(x), w(y), id(z) {} n } e[N]; n vector<Edge> edges; n vector<int> G[N]; n int ans[N], fa[N][20], dep[N], st[N][20], used[N], f[N], to[N]; n int n, m; n void addeage(int u, int v, int w, int id) { n   edges.push_back(Edge(v, w, id)); n   int tot = edges.size(); n   G[u].push_back(tot - 1); n } n void dfs(int u, int fat) { n   fa[u][0] = fat; n   for (int i = 1; i <= 18; ++i) n     fa[u][i] = fa[fa[u][i - 1]][i - 1], n     st[u][i] = max(st[u][i - 1], st[fa[u][i - 1]][i - 1]); n   for (int i = 0; i < G[u].size(); ++i) { n     Edge e = edges[G[u][i]]; n     if (e.v == fat) continue; n     to[e.v] = e.id; n     st[e.v][0] = e.w; n     dep[e.v] = dep[u] + 1; n     dfs(e.v, u); n   } n } n int LCA(int u, int v, int& d) { n   d = 0; n   if (dep[u] < dep[v]) swap(u, v); n   int t = dep[u] - dep[v]; n   for (int i = 0; i <= 18; ++i) n     if ((1 << i) & t) { n       d = max(d, st[u][i]); n       u = fa[u][i]; n     } n   if (u == v) return u; n   for (int i = 18; i >= 0; --i) { n     if (fa[u][i] != fa[v][i]) { n       d = max(d, max(st[u][i], st[v][i])); n       u = fa[u][i]; n       v = fa[v][i]; n     } n   } n   d = max(d, max(st[u][0], st[v][0])); n   return fa[u][0]; n } n int getfa(int u) { return (u == f[u]) ? u : f[u] = getfa(f[u]); } n bool cmp(Edge x, Edge y) { return x.w < y.w; } n void KrusKal() { n   int tot = 0; n   sort(e + 1, e + 1 + m, cmp); n   for (int i = 1; i <= m; ++i) { n     int u = e[i].u, v = e[i].v; n     int u1 = getfa(u), v1 = getfa(v); n     if (u1 != v1) { n       f[u1] = v1; n       used[i] = 1; n       addeage(u, v, e[i].w, e[i].id); n       addeage(v, u, e[i].w, e[i].id); n       tot++; n     } n     if (tot == n - 1) break; n   } n } n void modify(int u, int v, int d) { n   u = getfa(u); n   while (dep[u] > dep[v]) { n     ans[to[u]] = min(ans[to[u]], d); n     int y = getfa(fa[u][0]); n     f[u] = y; n     u = getfa(u); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     int u, v, w; n     scanf( %d%d%d , &u, &v, &w); n     e[i].u = u, e[i].v = v, e[i].w = w, e[i].id = i; n   } n   for (int i = 1; i <= n; ++i) f[i] = i; n   KrusKal(); n   dfs(1, 1); n   memset(ans, Inf, sizeof ans); n   for (int i = 1; i <= n; ++i) f[i] = i; n   for (int i = 1; i <= m; ++i) { n     if (used[i]) continue; n     int u = e[i].u, v = e[i].v; n     int ffa = LCA(u, v, ans[e[i].id]); n     ans[e[i].id]--; n     modify(u, ffa, e[i].w - 1); n     modify(v, ffa, e[i].w - 1); n   } n   for (int i = 1; i <= m; ++i) n     if (ans[i] == Inf) n       printf( -1  ); n     else n       printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e5 + 10, M = 26; n template <typename T = int> n inline T read() { n   T x = 0, f = 0; n   char ch = getchar(); n   while (!isdigit(ch)) f |= ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return f ? -x : x; n } n char s[N]; n int a[N], pre[N][26], suf[N][26], f[N][26], g[N], dp[27]; n inline int mex(int a) { n   int res = 0; n   while (a >> res & 1) ++res; n   return res; n } n inline int solve(int l, int r, int c) { n   if (l > r) return 0; n   if (dp[c] != -1) return dp[c]; n   int sta = 0; n   for (int i = 0; i < 26; ++i) { n     int L = suf[l][i], R = pre[r][i]; n     if (R < L) continue; n     sta |= 1 << (f[L - 1][c] ^ g[R] ^ g[L] ^ solve(R + 1, r, i)); n   } n   return dp[c] = mex(sta); n } n inline int Solve(int l, int r, int c) { n   if (l > r) return 0; n   if (dp[c] != -1) return dp[c]; n   int sta = 0; n   for (int i = 0; i < 26; ++i) { n     int L = suf[l][i], R = pre[r][i]; n     if (R < L) continue; n     sta |= 1 << (Solve(l, L - 1, i) ^ g[R] ^ g[L] ^ f[r][i]); n   } n   return dp[c] = mex(sta); n } n int main() { n   scanf( %s , s + 1); n   int n = strlen(s + 1); n   for (int i = 1; i <= n; ++i) a[i] = s[i] -  a ; n   for (int i = 0; i < 26; ++i) suf[n + 1][i] = n + 1; n   for (int i = 1; i <= n; ++i) n     memcpy(pre[i], pre[i - 1], sizeof(pre[i])), pre[i][a[i]] = i; n   for (int i = n; i >= 1; --i) n     memcpy(suf[i], suf[i + 1], sizeof(suf[i])), suf[i][a[i]] = i; n   for (int i = 1; i <= n; ++i) { n     memset(dp, -1, sizeof(dp)), g[i] = g[pre[i - 1][a[i]]] ^ f[i - 1][a[i]]; n     for (int c = 0; c < 26; ++c) f[i][c] = solve(pre[i][c] + 1, i, c); n   } n   for (int q = read(); q; --q) { n     int l = read(), r = read(); n     memset(dp, -1, sizeof(dp)); n     puts(Solve(l, r, 26) ?  Alice  :  Bob ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long n) { n   long long ans = 1; n   for (int i = 1; i <= n; i++) ans *= x; n   return ans; n } n long long gcd(long long x, long long y) { n   return (x % y == 0) ? y : gcd(y, x % y); n } n long long n, l, r; n int main() { n   cin >> n >> l >> r; n   if (n == 1) n     cout << r - l + 1; n   else if (n == 2) { n     cout << (r - l + 1) * (r - l); n   } else if (n > 30) { n     cout << 0; n   } else { n     long long ans = 0; n     for (int i = 2; i < r; i++) { n       int p = i, R = r / power(p, n - 1); n       if (R == 0) break; n       for (int j = 1; j < p; j++) { n         int q = j; n         int L = (l - 1) / power(q, n - 1) + 1; n         if (L > R) continue; n         if (gcd(p, q) == 1) { n           ans += (R - L + 1); n         } n       } n     } n     cout << ans * 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 200000 + 10; n int a[M]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   double R_L = 0; n   double R_R = 0.5 * a[n - 1] - 0.5 * a[0]; n   int num = 0; n   double C1, C2, C3; n   C2 = a[0]; n   while (num < 200) { n     double R_M = (R_L + R_R) / 2; n     double D1 = a[0] + R_M * 2; n     int ind1 = -1; n     for (int i = 0; i < n; i++) { n       if (a[i] > D1) { n         ind1 = i; n         break; n       } n     } n     double D2 = R_M * 2; n     int ind2 = -1; n     for (int i = n - 1; i >= 0; i--) { n       if (a[i] + D2 < a[n - 1]) { n         ind2 = i; n         break; n       } n     } n     if (ind1 == -1 || ind2 == -1) { n       R_R = R_M; n     } else { n       if (ind1 > ind2) { n         R_R = R_M; n       } else { n         int Dis = a[ind2] - a[ind1]; n         C2 = 0.5 * (a[ind2] + a[ind1]); n         if (Dis <= R_M * 2) { n           R_R = R_M; n         } else { n           R_L = R_M; n         } n       } n     } n     num++; n   } n   C1 = a[0] + R_R; n   C3 = a[n - 1] - R_R; n   C2 = a[0]; n   for (int i = 0; i < n; i++) { n     if (a[i] > a[0] + 2 * R_R) { n       C2 = a[i] + R_R; n       break; n     } n   } n   printf( %.10f n , R_R); n   printf( %.10f %.10f %.10f n , C1, C2, C3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 10; n using ll = long long; n using pii = pair<int, int>; n int pa[maxn]; n int sz[maxn]; n int d[maxn]; n int f[maxn]; n vector<ll> pre[maxn]; n vector<int> g[maxn], dis[maxn]; n map<pii, ll> ans; n int find(int p) { return p == pa[p] ? pa[p] : pa[p] = find(pa[p]); } n void unionPQ(int p, int q) { n   int pp = find(p); n   int pq = find(q); n   if (pp != pq) { n     pa[pp] = pq; n     sz[pq] += sz[pp]; n   } n } n int depth, id, root, flag; n void dfs(int node, int fa = -1, int h = 0) { n   if (h > depth) { n     depth = h; n     id = node; n   } n   if (f[node] < h) f[node] = h; n   if (flag) dis[root].push_back(f[node]); n   for (auto v : g[node]) n     if (v != fa) dfs(v, node, h + 1); n } n int main() { n   int n, m, q; n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 0; i < n; ++i) { n     pa[i] = i; n     sz[i] = 1; n   } n   for (int i = 0; i < m; ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--, b--; n     g[a].push_back(b); n     g[b].push_back(a); n     unionPQ(a, b); n   } n   for (int i = 0; i < n; ++i) n     if (i == pa[i]) { n       flag = false; n       root = i; n       depth = 0; n       id = i; n       dfs(i); n       depth = 0; n       dfs(id); n       d[i] = depth; n       flag = true; n       dfs(id); n       sort(dis[i].begin(), dis[i].end()); n       pre[i].resize(1 + sz[i]); n       pre[i][0] = 0; n       for (int j = 0; j < sz[i]; ++j) pre[i][j + 1] = pre[i][j] + dis[i][j]; n     } n   for (int i = 0; i < q; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     u--; n     v--; n     u = find(u); n     v = find(v); n     if (u == v) { n       printf( -1 n ); n       continue; n     } n     if (sz[u] > sz[v] || (sz[u] == sz[v] && u > v)) swap(u, v); n     if (ans.count({u, v})) { n       printf( %.10f n , (double)ans[{u, v}] / sz[u] / sz[v]); n       continue; n     } n     int maxd = max(d[u], d[v]); n     ll t = 0; n     int p = sz[v] - 1; n     for (int x : dis[u]) { n       while (p >= 0 && x + 1 + dis[v][p] > maxd) p--; n       t += (ll)maxd * (p + 1) + (ll)(x + 1) * (sz[v] - p - 1) + pre[v].back() - n            pre[v][p + 1]; n     } n     ans[{u, v}] = t; n     printf( %.10f n , (double)ans[{u, v}] / sz[u] / sz[v]); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n long long ans; n int d[100005]; n int main(){ n  int t; cin>>t; while(t--){ n   int n; scanf( %d ,&n); n   for(int i=1;i<=n;++i)scanf( %d ,&d[i]); n   sort(d+1,d+1+n); ans=d[n]; n   for(int i=1;i<=n;++i)ans+=d[i]*(n+1ll-i-i); n   printf( %lld n ,ans); n  } n }


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void solve() { n   int a, b, n; n   cin >> a >> b >> n; n   bool aturn = true; n   while (n > 0) { n     int x; n     if (aturn) { n       x = gcd(a, n); n       aturn = false; n     } else { n       x = gcd(b, n); n       aturn = true; n     } n     n -= x; n   } n   if (aturn == false) n     cout <<  0  n          <<   n ; n   else n     cout <<  1  n          <<   n ; n } n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int res = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) f = -1, c = getchar(); n   while (isdigit(c)) res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); n   return res * f; n } n const int maxn = 2e5 + 10; n int n, k, val[26]; n char s[maxn]; n int main() { n   int T = read(); n   while (T--) { n     n = read(); n     k = read(); n     int ans = 0; n     scanf( %s , s + 1); n     for (int i = 1; i <= k / 2; i++) { n       memset(val, 0, sizeof(val)); n       for (int j = 0; j < n / k; j++) { n         val[s[i + j * k] -  a ]++; n         val[s[k - i + 1 + j * k] -  a ]++; n       } n       int tmp = 0; n       for (int j = 0; j < 26; j++) tmp = max(tmp, val[j]); n       ans += n / k * 2 - tmp; n     } n     if (k & 1) { n       memset(val, 0, sizeof(val)); n       for (int j = 0; j < n / k; j++) { n         val[s[k / 2 + 1 + j * k] -  a ]++; n       } n       int tmp = 0; n       for (int j = 0; j < 26; j++) tmp = max(tmp, val[j]); n       ans += n / k - tmp; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b; n   while (cin >> a >> b) { n     long long divi = a - b, cnt = 0; n     if (a == b) n       cout <<  infinity  << endl; n     else { n       for (long long i = 1; i * i <= divi; i++) { n         if (divi % i == 0) { n           long long other = divi / i; n           if (i > b) cnt++; n           if (other > b && other != i) cnt++; n         } n       } n       cout << cnt << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long MAX = 300000; n const double PI = 3.14159265358979323846; n long long T[MAX * 2]; n long long ceil_log2(long long n) { n   long long v = 1; n   long long log = 0; n   while (v < n) { n     v <<= 1; n     log++; n   } n   return log; n } n std::bitset<64> reverse(std::bitset<64> set, long long bit_count) { n   for (long long i = 0; i < bit_count / 2; i++) { n     bool tmp = set[i]; n     set[i] = set[bit_count - 1 - i]; n     set[bit_count - 1 - i] = tmp; n   } n   return set; n } n void fft(std::complex<double> *A, long long bit_count, bool inverse = false) { n   static std::complex<double> W[MAX]; n   long long N = 1 << bit_count; n   for (long long i = 0; i < N; i++) { n     long long j = T[i]; n     if (i < j) std::swap(A[i], A[j]); n   } n   for (long long step = 1; step < N; step <<= 1) { n     double angle = -PI / step; n     if (inverse) angle = -angle; n     std::complex<double> w(1, 0), wn(std::cos(angle), std::sin(angle)); n     for (long long i = 0; i < step; i++) { n       W[i] = w; n       w *= wn; n     } n     for (long long start_even = 0; start_even < N; start_even += step * 2) { n       auto start_odd = start_even + step; n       for (long long i = 0; i < step; i++) { n         std::complex<double> U = A[start_even + i]; n         std::complex<double> V = W[i] * A[start_odd + i]; n         A[start_even + i] = U + V; n         A[start_odd + i] = U - V; n       } n     } n   } n   if (inverse) { n     for (long long i = 0; i < N; i++) A[i] /= N; n   } n } n long long C[MAX]; n long long zero_count = 0; n long long n, x; n long long C_len, bit_count, N; n void init() { n   std::fill(C, C + n + 1, 0); n   C[0] = 1; n   C_len = n + 1; n   bit_count = ceil_log2(C_len * 2); n   N = 1 << bit_count; n   for (long long i = 0; i < N; i++) { n     T[i] = reverse(i, bit_count).to_ullong(); n   } n } n void input() { n   std::cin >> n >> x; n   init(); n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     long long v; n     std::cin >> v; n     sum += v < x; n     C[sum]++; n   } n   for (long long i = 0; i <= sum; i++) n     if (C[i] > 1) zero_count += C[i] * (C[i] - 1) / 2; n } n int main() { n   input(); n   std::cout << zero_count <<    ; n   static std::complex<double> A[MAX * 2], B[MAX * 2]; n   std::copy(C, C + C_len, A); n   std::fill(A + C_len, A + N, 0); n   std::fill(B, B + 2 * n - C_len, 0); n   std::reverse_copy(C, C + C_len, B + 2 * n - C_len); n   std::fill(B + 2 * n, B + N, 0); n   fft(A, bit_count); n   fft(B, bit_count); n   for (long long i = 0; i < N; i++) A[i] *= B[i]; n   fft(A, bit_count, true); n   for (long long k = 1; k <= n; k++) n     std::cout << (long long)std::round(A[2 * n - k - 1].real()) <<    ; n   std::cout << std::endl; n   return 0; n   for (long long i = 0; i < N; i++) std::cout << A[i] <<    ; n   std::cout << std::endl; n   for (long long i = 0; i < N; i++) std::cout << B[i] <<    ; n   std::cout << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n int add_MOD(int a, int b) { n   a += b; n   if (a >= MOD) { n     return a - MOD; n   } n   if (a < 0) { n     return a + MOD; n   } n   return a; n } n int mul_MOD(int a, int b) { return a * (long long)b % MOD; } n const int N = (int)2e5 + 7; n int n; n int q; n int brute[N]; n vector<vector<int>> queries; n vector<pair<int, int>> segments[N]; n vector<bool> is[N]; n vector<int> urm[N]; n map<int, int> who_l[N]; n map<int, int> who_r[N]; n map<int, int> id[N]; n set<int> changes[N]; n struct T { n   int a; n   int b; n   int val; n }; n T segt[4 * N]; n void push(int v, int tl, int tr) { n   segt[v].val = n       add_MOD(mul_MOD(tr - tl + 1, segt[v].b), mul_MOD(segt[v].val, segt[v].a)); n   if (tl < tr) { n     segt[2 * v].a = mul_MOD(segt[2 * v].a, segt[v].a); n     segt[2 * v + 1].a = mul_MOD(segt[2 * v + 1].a, segt[v].a); n     segt[2 * v].b = add_MOD(segt[v].b, mul_MOD(segt[2 * v].b, segt[v].a)); n     segt[2 * v + 1].b = n         add_MOD(segt[v].b, mul_MOD(segt[2 * v + 1].b, segt[v].a)); n   } n   segt[v].a = 1; n   segt[v].b = 0; n } n void add(int v, int tl, int tr, int l, int r) { n   push(v, tl, tr); n   if (tr < l || r < tl) { n     return; n   } n   if (l <= tl && tr <= r) { n     segt[v].b = 1; n     push(v, tl, tr); n     return; n   } n   int tm = (tl + tr) / 2; n   add(2 * v, tl, tm, l, r); n   add(2 * v + 1, tm + 1, tr, l, r); n   segt[v].val = add_MOD(segt[2 * v].val, segt[2 * v + 1].val); n } n void mult(int v, int tl, int tr, int l, int r) { n   push(v, tl, tr); n   if (tr < l || r < tl) { n     return; n   } n   if (l <= tl && tr <= r) { n     segt[v].a = 2; n     push(v, tl, tr); n     return; n   } n   int tm = (tl + tr) / 2; n   mult(2 * v, tl, tm, l, r); n   mult(2 * v + 1, tm + 1, tr, l, r); n   segt[v].val = add_MOD(segt[2 * v].val, segt[2 * v + 1].val); n } n int get(int v, int tl, int tr, int l, int r) { n   push(v, tl, tr); n   if (tr < l || r < tl) { n     return 0; n   } n   if (l <= tl && tr <= r) { n     return segt[v].val; n   } else { n     int tm = (tl + tr) / 2; n     return add_MOD(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r)); n   } n } n void add_brute(int l, int r) { n   add(1, 1, n, l, r); n   return; n   for (int i = l; i <= r; i++) { n     brute[i] = add_MOD(brute[i], 1); n   } n } n void mult_brute(int l, int r) { n   mult(1, 1, n, l, r); n   return; n   for (int i = l; i <= r; i++) { n     brute[i] = mul_MOD(brute[i], 2); n   } n } n int get_brute(int l, int r) { n   return get(1, 1, n, l, r); n   int sol = 0; n   for (int i = l; i <= r; i++) { n     sol = add_MOD(sol, brute[i]); n   } n   return sol; n } n void add(int l, int r, int x) { n   int p = who_l[x][l]; n   int p2 = who_r[x][r]; n   while (p <= p2) { n     if (is[x][p]) { n       int until = urm[x][p]; n       if (until > p2) { n         until = p2; n       } n       mult_brute(segments[x][p].first, segments[x][until].second); n       int ant_p = p; n       p = urm[x][p] + 1; n       urm[x][ant_p] = max(urm[x][ant_p], p2); n     } else { n       is[x][p] = 1; n       add_brute(segments[x][p].first, segments[x][p].second); n       urm[x][p] = p2; n       p++; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   for (int i = 0; i < 4 * N; i++) { n     segt[i].a = 1; n   } n   cin >> n >> q; n   for (int i = 1; i <= q; i++) { n     int t, l, r; n     cin >> t >> l >> r; n     if (t == 1) { n       int x; n       cin >> x; n       queries.push_back({l, r, x}); n       changes[x].insert(l); n       changes[x].insert(r + 1); n     } else { n       queries.push_back({l, r}); n     } n   } n   for (int x = 1; x <= n; x++) { n     changes[x].insert(1); n     changes[x].insert(n + 1); n     int j = -1; n     for (auto &i : changes[x]) { n       if (j != -1) { n         segments[x].push_back({j, i - 1}); n       } n       j = i; n     } n     is[x].resize((int)segments[x].size(), 0); n     urm[x].resize((int)segments[x].size()); n     for (int j = 0; j < (int)segments[x].size(); j++) { n       who_l[x][segments[x][j].first] = j; n       who_r[x][segments[x][j].second] = j; n     } n   } n   for (auto &vec : queries) { n     if ((int)vec.size() == 3) { n       add(vec[0], vec[1], vec[2]); n     } else { n       cout << get_brute(vec[0], vec[1]) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) n #pragma GCC target( avx,tune=native ) n using namespace std; n const long long mod = 1e9 + 7; n long long w[11]; n vector<vector<long long> > mul(vector<vector<long long> >& a, n                                vector<vector<long long> >& b) { n   vector<vector<long long> > ret(a.size(), vector<long long>(a.size(), 0)); n   for (long long i = 0; i < a.size(); i++) n     for (long long j = 0; j < a.size(); j++) ret[i][j] = 0; n   for (long long i = 0; i < a.size(); i++) { n     for (long long j = 0; j < a.size(); j++) { n       for (long long k = 0; k < a.size(); k++) { n         ret[i][j] += a[i][k] * b[k][j]; n         ret[i][j] %= mod; n       } n     } n   } n   return ret; n } n vector<vector<long long> > Pow(vector<vector<long long> > a, long long k) { n   vector<vector<long long> > ret = a, m = a; n   k--; n   do { n     if (k & 1) ret = mul(ret, m); n     m = mul(m, m); n   } while (k >>= 1); n   return ret; n } n long long dp[1 << 7], tdp[1 << 7], pre; n void solve(long long x, long long times) { n   vector<vector<long long> > mat((1 << x), vector<long long>((1 << x), 0)); n   for (long long st = 0; st < (1 << x); st++) { n     for (long long ed = 0; ed < (1 << x); ed++) { n       for (long long bt = 0; bt < (1 << (x - 1)); bt++) { n         long long add = 1; n         for (long long j = 0; j < x; j++) { n           long long cnt = 0; n           if (bt & (1 << j) || j == x - 1) cnt++; n           if (j == 0 || (bt & (1 << (j - 1)))) cnt++; n           if (st & (1 << j)) cnt++; n           if (ed & (1 << j)) cnt++; n           if (cnt == 4) add = 0; n         } n         if (add) mat[st][ed]++; n         if (mat[st][ed] >= mod) mat[st][ed] -= mod; n       } n     } n   } n   mat = Pow(mat, times); n   memset(tdp, 0, sizeof tdp); n   long long or_mask = 0; n   for (long long i = pre; i < x; i++) or_mask |= (1 << i); n   for (long long i = 0; i < (1 << x); i++) { n     for (long long j = 0; j < (1 << x); j++) { n       tdp[j] += dp[i] * mat[i | or_mask][j]; n       tdp[j] %= mod; n     } n   } n   memcpy(dp, tdp, sizeof tdp); n   pre = x; n } n signed main() { n   for (long long i = 1; i <= 7; i++) cin >> w[i]; n   for (long long i = 1; i <= 7; i++) { n     if (w[i]) { n       dp[(1 << i) - 1] = 1; n       break; n     } n   } n   for (long long i = 1; i <= 7; i++) { n     if (w[i]) { n       solve(i, w[i]); n     } n   } n   for (long long i = 7; i >= 1; i--) { n     if (w[i]) { n       cout << dp[(1 << i) - 1] << endl; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1e9 + 7; n long long int dx[] = {0, 0, 1, -1}; n long long int dy[] = {1, -1, 0, 0}; n long long int m = 0, n, res = 0, k; n string s2, ch =   , s, t, s1 =   ; n vector<pair<string, long long int> > vm; n vector<pair<pair<long long int, long long int>, long long int> > vvv; n vector<pair<long long int, long long int> > vv, vv2; n vector<long long int> v[200005], v2, v1; n long long int a[500005], vis[500005], dp[500005]; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long int i = 0, x = 0, z = 0, y = 0, j = 0, q, mx = 0, idx = 0, ok = 0, n                 l = 0, r = 0, negatif = 0, positif = 0, l1, r1, p, t, d; n   set<pair<long long int, long long int> >::iterator itp; n   cin >> n >> k >> d; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     dp[i] = 0; n   } n   sort(a + 1, a + 1 + n); n   dp[0] = 1; n   dp[1] = -1; n   for (i = 1; i <= n; i++) { n     if (!dp[i - 1]) continue; n     dp[i] += dp[i - 1]; n     x = a[i] + d; n     l = i + k - 1; n     r = upper_bound(a + i, a + 1 + n, x) - a - 1; n     if (r >= l) { n       dp[l]++; n       dp[r + 1]--; n     } n   } n   if (dp[n]) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = (1 << 20); n class Disjoint_Set { n  public: n   int sz[MX], P[MX]; n   int find_(int x) { n     if (x != P[x]) P[x] = find_(P[x]); n     return P[x]; n   } n   int comp; n   void init(int N) { n     for (int j = 1; j <= N; j++) sz[j] = 1, P[j] = j; n     comp = N; n   } n   bool same(int x, int y) { return find_(x) == find_(y); } n   int compsize(int node) { return sz[find_(node)]; } n   bool merge_(int x, int y) { n     int px = find_(x), py = find_(y); n     if (px == py) return false; n     if (sz[px] < sz[py]) swap(px, py); n     P[py] = px; n     comp--; n     sz[px] += sz[py]; n     return true; n   } n } G; n int n, m; n int main() { n   scanf( %d %d , &n, &m); n   if (n != m) { n     puts( NO ); n     return 0; n   } n   G.init(n); n   int tt = 0; n   while (m--) { n     int a, b; n     scanf( %d %d , &a, &b); n     if (!G.merge_(a, b)) tt++; n   } n   if (tt == 1) n     puts( FHTAGN! ); n   else n     puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200007; n int n, m, q, p[N], a[N], apre[N], lst[N], ppre[N], fa[N], dep[N], w[N], b[N]; n vector<int> G[N]; n int max(int a, int b) { return a > b ? a : b; } n int min(int a, int b) { return a < b ? a : b; } n int read() { n   int x; n   scanf( %d , &x); n   return x; n } n void dfs(int u) { n   int i, v; n   b[dep[u]] = u, w[u] = dep[u] >= n ? b[dep[u] - (n - 1)] : m + 1; n   for (i = G[u].size() - 1; ~i; --i) v = G[u][i], dep[v] = dep[u] + 1, dfs(v); n } n int main() { n   n = read(), m = read(), q = read(); n   int i, j; n   for (i = 1; i <= n; ++i) p[i] = read(); n   p[0] = p[n]; n   for (i = 1; i <= n; ++i) ppre[p[i]] = p[i - 1]; n   for (i = 1; i <= m; ++i) { n     a[i] = read(), apre[i] = lst[a[i]], lst[a[i]] = i; n     for (j = lst[ppre[a[i]]]; j && !fa[j]; j = apre[j]) fa[j] = i; n   } n   for (i = 1; i <= m; ++i) fa[i] ? G[fa[i]].push_back(i) : G[0].push_back(i); n   dfs(0); n   for (i = m - 1; i; --i) w[i] = min(w[i + 1], w[i]); n   while (q--) i = read(), j = read(), putchar(48 + (w[i] <= j)); n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e6; n long long a[MAXN], mod = 1e9 + 7, ans; n long long power(long long x, long long y) { n   if (y == 0) return 1; n   long long mid = power(x, y / 2); n   if (y % 2 == 1) n     return mid * mid % mod * x % mod; n   else n     return mid * mid % mod; n } n int main() { n   int n; n   cin >> n; n   bool is = false, is2 = false; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] % 2 == 0) is = true; n     if (a[i] != 1) is2 = true; n   } n   for (int i = 0; i < n; i++) { n     if (i == 0) n       ans = power(2, a[i]); n     else n       ans = power(ans, a[i]); n   } n   ans = ans * power(2, mod - 2) % mod; n   long long ans2 = ans; n   long long k = -1; n   if (is) k = 1; n   ans = (ans + k) * power(3, mod - 2) % mod; n   cout << ans <<  /  << ans2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, i, j = 0, c1 = 0, c0 = 0; n   string a, b; n   vector<long long int> v0, v1; n   cin >> n; n   cin >> a; n   cin >> b; n   for (i = 0; i < n; i++) { n     if (b[i] ==  0 ) { n       if (a[i] ==  1 ) n         v1.push_back(i); n       else n         v0.push_back(i); n     } n     if (a[i] ==  0 ) n       c0++; n     else n       c1++; n   } n   j = v0.size() * c1; n   j += (v1.size() * c0); n   j -= (v1.size() * v0.size()); n   cout << j << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(long long n, long long s) { n   long long sum = 0; n   while (n) { n     sum += n % 10; n     n /= 10; n   } n   return sum == s; n } n int main() { n   long long n, s, rt, ans = -1; n   cin >> n; n   for (s = 1; s < 100; s++) { n     rt = sqrt(s * s + 4 * n); n     if (rt * rt == s * s + 4 * n) { n       if ((rt - s) % 2 == 0) { n         if (check((rt - s) / 2, s)) { n           if (ans == -1) n             ans = (rt - s) / 2; n           else n             ans = min(ans, (rt - s) / 2); n         } n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> e; n double best = -1; n int main() { n   int n, u; n   cin >> n >> u; n   for (int i = 0; i < n; i++) { n     int k = 0; n     cin >> k; n     e.push_back(k); n   } n   int k = 2; n   for (int j = 1; j < n; j++) { n     int ej = e[j]; n     int ei = e[j - 1]; n     while (k < n && e[k] - ei <= u) { n       k++; n     } n     k--; n     if (k <= j) { n       continue; n     } n     double value = ((double)(e[k] - ej)) / (e[k] - ei); n     if (value > best) { n       best = value; n     } n   } n   cout << setprecision(12) << best; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n using ui = unsigned int; n using pii = pair<int, int>; n using pll = pair<int, int>; n struct fast_ios { n   fast_ios() { n     ios::sync_with_stdio(false); n     cin.tie(NULL); n   } n } fast_ios_; n ll u, v, a; n int solve() { n   cin >> u >> v; n   if (u > v || (v - u) & 1) return puts( -1 ), 0; n   if (u + v == 0) return puts( 0 ), 0; n   if (u == v) return printf( 1 n%lld n , u), 0; n   a = (v - u) / 2; n   if (u & a) return printf( 3 n%lld %lld %lld n , u, a, a), 0; n   return printf( 2 n%lld %lld n , u + a, a), 0; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, m, u, v, q, k; n const int N = 3e5 + 500; n const int LN = 20; n const int SN = 331; n const long long mod = 1e9 + 7; n const long long INF = 1LL << 57; n long long arr[N], brr[N]; n string str, ss; n vector<int> adj[N]; n vector<int> idx[N]; n int d[N]; n int actuald[N]; n bool can[N]; n bool vis[N]; n void dfs(int v, int p) { n   if (d[v] == -1) d[v] = 0; n   vis[v] = true; n   for (int i = 0; i < adj[v].size(); ++i) { n     int u = adj[v][i]; n     if (u == p || vis[u]) continue; n     dfs(u, v); n     if (actuald[u] != d[u]) { n       can[idx[v][i]] = true; n       actuald[v]++; n       actuald[u]++; n       actuald[v] %= 2; n       actuald[u] %= 2; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m; n   int has = -1, sum = 0; n   for (int i = 1; i <= n; ++i) { n     cin >> d[i]; n     if (d[i] == -1) n       has = i; n     else n       sum += d[i]; n   } n   for (int i = 1; i <= m; ++i) { n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n     idx[u].push_back(i); n     idx[v].push_back(i); n   } n   if (sum % 2 == 1 && has == -1) { n     cout << -1 <<   n ; n     return 0; n   } n   if (sum % 2 == 1) d[has] = 1; n   dfs(1, 0); n   sum = 0; n   for (int i = 1; i <= m; ++i) { n     sum += can[i]; n   } n   cout << sum <<   n ; n   for (int i = 1; i <= m; ++i) { n     if (can[i]) cout << i <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000200; n bool Ch(int Ans); n int n, k; n int a[N]; n int c[N]; n int p[N]; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) scanf( %d , a + i), c[a[i]]++; n   for (int i = 1; i < N; i++) p[i] = c[i] + p[i - 1]; n   sort(a + 1, a + n + 1); n   for (int Ans = a[1]; Ans >= 1; Ans--) n     if (Ch(Ans)) return cout << Ans, 0; n   assert(0); n } n bool Ch(int Ans) { n   if (Ans <= k + 1) return true; n   for (int j = Ans + Ans; j <= N; j += Ans) n     if (p[j - 1] - p[j - Ans + k]) return false; n   return true; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v; n int n, m; n int f() { n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int a = 10; n     for (int j = i; j < n; j++) { n       for (int k = i; k <= j; k++) a = min(a, v[k]); n       ans += a; n     } n   } n   return ans; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     v.push_back(i); n   } n   sort(v.begin(), v.end()); n   int maxx = 0; n   do { n     maxx = max(maxx, f()); n   } while (next_permutation(v.begin(), v.end())); n   int k = 0; n   sort(v.begin(), v.end()); n   int c = 0; n   do { n     if (f() == maxx) c++; n     if (c == m) { n       for (auto i : v) cout << i <<    ; n       break; n     } n   } while (next_permutation(v.begin(), v.end())); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long powmod(long long a, long long b, long long p) { n   if (b == 0) return 1; n   if (b == 1) return a; n   long long temp = powmod(a, b / 2, p); n   temp *= temp; n   temp %= p; n   if (b % 2 == 0) return temp; n   temp = temp * a; n   temp %= p; n   return temp; n } n void solve() { n   int n, x, y, d; n   cin >> n >> x >> y >> d; n   if (abs(x - y) % d == 0) { n     cout << abs(x - y) / d << endl; n     ; n     return; n   } n   long long ans = 1e18; n   if (abs(y - 1) % d == 0) { n     ans = (y - 1) / d; n     ans += (x - 1 + d - 1) / d; n   } n   if ((n - y) % d == 0) { n     long long ans2 = (n - y) / d; n     ans2 += (n - x + d - 1) / d; n     ans = min(ans, ans2); n   } n   if (ans > 1e10) n     cout << -1 << endl; n   else n     cout << ans << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pw(long long x, long long p) { n   if (p == 0) return 1; n   long long t = pw(x, p / 2); n   if (p % 2 == 0) n     return (t * t) % 1000000007; n   else n     return (((t * t) % 1000000007) * x) % 1000000007; n } n const long long NN = 500007; n long long parent[NN], sizee[NN]; n void make_set(long long v) { n   parent[v] = v; n   sizee[v] = 1; n } n long long find_set(long long v) { n   if (v == parent[v]) return v; n   return parent[v] = find_set(parent[v]); n } n void union_sets(long long a, long long b) { n   a = find_set(a); n   b = find_set(b); n   if (a != b) { n     if (sizee[a] < sizee[b]) swap(a, b); n     parent[b] = a; n     sizee[a] += sizee[b]; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   map<long long, long long> m; n   long long i, n, M; n   long long k; n   cin >> n >> M >> k; n   long long a[n + 1]; n   for (i = 1; i <= n; i++) cin >> a[i]; n   long long x, y, cur = 0, virus, pos; n   vector<pair<long long, long long> > edges[M + 1]; n   while (M--) { n     cin >> x >> y; n     virus = a[x] ^ a[y]; n     if (m.find(virus) == m.end()) { n       m.insert({virus, cur}); n       cur++; n     } n     pos = m.find(virus)->second; n     edges[pos].push_back({x, y}); n   } n   long long siz, comp; n   long long unsafe = 0, temp; n   for (i = 0; i < cur; i++) { n     set<long long> SS; n     for (auto &x : edges[i]) { n       make_set(x.first), make_set(x.second); n       SS.insert(x.first), SS.insert(x.second); n     } n     siz = SS.size(); n     comp = siz; n     for (auto &x : edges[i]) { n       if (find_set(x.first) != find_set(x.second)) n         comp--, union_sets(x.first, x.second); n     } n     temp = (pw(2, siz) - pw(2, comp) + 1000000007) % 1000000007; n     unsafe = (unsafe + (temp * pw(2, n - siz)) % 1000000007) % 1000000007; n   } n   cout << ((pw(2, k) * pw(2, n)) % 1000000007 - unsafe + 1000000007) % n               1000000007 n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long f, n; n   long double a, b, ans; n   while (cin >> a >> b >> n) { n     long flag = 0, i, j; n     for (i = -1000; i <= 1000; i++) { n       ans = 1; n       f = 0; n       for (j = 0; j < n; j++) { n         ans *= i; n         if (abs(ans) > 1000) { n           f = 1; n           break; n         } n       } n       if (!f) n         if (a * ans == b) { n           flag = 1; n           break; n         } n     } n     if (flag) n       cout << i << endl; n     else n       cout <<  No solution n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<int> x(n); n   for (int i = 0; i < n; i++) cin >> x[i]; n   vector<int> ans(n + 1); n   for (int i = 0; i < n; i++) { n     int dominant = 0; n     vector<int> m(n + 1); n     for (int j = i; j < n; j++) { n       m[x[j]]++; n       if (m[x[j]] > m[dominant] or (m[x[j]] == m[dominant] and x[j] < dominant)) n         dominant = x[j]; n       ans[dominant]++; n     } n   } n   for (int i = 1; i < n + 1; i++) cout << ans[i] <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); 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 long long nax = 105; n long long a[nax]; n signed main() { n   long long n, cnt0 = 0, cnt1 = 0; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] == 0) n       cnt0++; n     else n       cnt1++; n   } n   if (cnt0 == n) { n     cout << 0 << endl; n     return 0; n   } else if (cnt1 == n) { n     cout << 1 << endl; n     return 0; n   } n   long long idx = 0; n   long long pdt = 1; n   for (long long i = 1; i <= n; i++) { n     if (a[i] == 1) { n       if (idx == 0) n         idx = i; n       else { n         long long temp = idx; n         pdt *= i - temp; n         idx = i; n       } n     } n   } n   cout << pdt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int y[50010] = {}; n int t[50010] = {}; n unordered_map<int, int> ha; n bool cmp(int x, int y) { return x > y; } n bool ff(int x) { n   ha.clear(); n   for (int i = 1; i <= n; i++) y[i] = t[i]; n   for (int i = 1; i <= n; i++) { n     if (y[i] <= x && ha[y[i]] == 0) { n       ha[y[i]] = 1; n     } else { n       while (1) { n         if (y[i] == 1) { n           return 0; n         } n         if (ha.find(y[i] / 2) == ha.end() && (y[i] / 2) <= x) { n           ha[y[i] / 2] = 1; n           break; n         } else n           y[i] = y[i] / 2; n       } n     } n   } n   return 1; n } n void ans(int x) { n   ha.clear(); n   for (int i = 1; i <= n; i++) y[i] = t[i]; n   for (int i = 1; i <= n; i++) { n     if (y[i] <= x && ha[y[i]] == 0) { n       ha[y[i]] = 1; n       printf( %d  , y[i]); n     } else { n       while (1) { n         if (ha.find(y[i] / 2) == ha.end() && (y[i] / 2) <= x) { n           ha[y[i] / 2] = 1; n           break; n         } else n           y[i] = y[i] / 2; n       } n       printf( %d  , y[i] / 2); n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &t[i]); n   sort(t + 1, t + n + 1, cmp); n   int l = 1; n   int r = 1000000000; n   while (l < r) { n     int mid = (l + r) / 2; n     if (ff(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   ans(l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     int m; n     cin >> n >> m; n     int arr[n]; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     map<int, int> freq; n     freq.clear(); n     for (int i = 0; i < m; i++) { n       int curr; n       cin >> curr; n       freq[curr]++; n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) n         if (arr[j] > arr[j + 1] && freq[j + 1]) { n           swap(arr[j], arr[j + 1]); n         } n     } n     bool possible = true; n     for (int i = 0; i < n - 1; i++) { n       if (arr[i] > arr[i + 1]) { n         possible = false; n         break; n       } n     } n     if (possible) { 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 void maloosh_lazma() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n int main() { n   maloosh_lazma(); n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   int l, ll; n   char q, qq; n   for (int i = 0; i < k; i++) { n     cin >> l >> ll >> q >> qq; n     --l, --ll; n     for (int j = l; j <= ll; j++) { n       if (s[j] == q) s[j] = qq; n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   ; n   int beauty[n]; n   for (int asdf = 0; asdf < n; asdf++) { n     cin >> beauty[asdf]; n   }; n   map<int, long long int> occ; n   long long int most = 0; n   for (int i = 0; i < n; i++) { n     int x = i - beauty[i]; n     if (!occ.count(x)) occ[x] = 0LL; n     occ[x] = occ[x] + beauty[i]; n     if (occ[x] > most) most = occ[x]; n   } n   cout << most; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, i, ii, c; n long long xa, xb, xc, xd, mask, a[100100], b[100100]; n int main() { n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) { n     scanf( %I64d.%I64d.%I64d.%I64d , &xa, &xb, &xc, &xd); n     a[i] = (xa << 24) + (xb << 16) + (xc << 8) + xd; n   } n   sort(a, a + n); n   for (ii = 31; ii > 0; ii--) { n     mask |= 1LL << ii; n     for (c = i = 0; i < n; i++) { n       b[i] = a[i] & mask; n       if (i == 0 || b[i] != b[i - 1]) c++; n     } n     if (c == m) { n       printf( %I64d.%I64d.%I64d.%I64d n , (mask >> 24) & 255, n              (mask >> 16) & 255, (mask >> 8) & 255, mask & 255); n       return 0; n     } n   } n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const double PI = 3.1415926535897932384626433832795; n unsigned long long mod = 1000 * 1000 * 1000 + 7; n int INF = 1000 * 1000 * 1000; n vector<int> v; n class node { n  public: n   node() { n     left = right = NULL; n     addVal = 0; n   } n   int from, to; n   int minVal, minPos, addVal; n   node *left, *right; n   void build(int i, int j) { n     from = i; n     to = j; n     if (i == j) { n       minVal = v[i]; n       minPos = i; n     } else { n       int mid = (i + j) / 2; n       if (i <= mid) { n         left = new node(); n         left->build(i, mid); n       } n       if (mid + 1 <= j) { n         right = new node(); n         right->build(mid + 1, j); n       } n       if (left->minVal < right->minVal) { n         minVal = left->minVal; n         minPos = left->minPos; n       } else { n         minVal = right->minVal; n         minPos = right->minPos; n       } n     } n   } n   pair<int, int> getMin(int i, int j) { n     if (i <= from && to <= j) return make_pair(minVal + addVal, minPos); n     if (i > to || j < from) return make_pair(INF, -1); n     pair<int, int> r1 = left->getMin(i, j); n     pair<int, int> r2 = right->getMin(i, j); n     r1.first += addVal; n     r2.first += addVal; n     return min(r1, r2); n   } n   void add(int i, int j, int val) { n     if (i <= from && to <= j) { n       addVal += val; n       return; n     } n     if (i > to || j < from) return; n     left->add(i, j, val); n     right->add(i, j, val); n     return; n   } n } * root; n int main() { n   int n; n   cin >> n; n   v.resize(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   root = new node(); n   root->build(0, n - 1); n   queue<pair<int, int> > q; n   q.push(make_pair(0, n - 1)); n   vector<pair<int, int> > res; n   while (!q.empty()) { n     pair<int, int> top = q.front(); n     q.pop(); n     pair<int, int> r = root->getMin(top.first, top.second); n     for (int i = 0; i < r.first; i++) n       res.push_back(make_pair(top.first, top.second)); n     root->add(top.first, top.second, -r.first); n     if (top.first <= r.second - 1) q.push(make_pair(top.first, r.second - 1)); n     if (r.second + 1 <= top.second) q.push(make_pair(r.second + 1, top.second)); n   } n   cout << res.size() << endl; n   for (int i = 0; i < res.size(); i++) n     cout << res[i].first + 1 <<     << res[i].second + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long n, a, b; n     cin >> n >> a >> b; n     string s; n     cin >> s; n     for (long long i = 1; i < s.length() - 1; i++) { n       if (s[i] ==  0 ) { n         if (s[i + 1] ==  1  && s[i - 1] ==  1 ) s[i] =  1 ; n       } n     } n     long long c = -1; n     long long ans = 0; n     vector<long long> v; n     for (long long i = 0; i < s.length(); i++) { n       char ch = s[i]; n       long long d = 0; n       while (s[i] == ch && i < s.length()) { n         i++; n         d++; n       } n       i--; n       ans += d * a; n       if (ch ==  0 ) n         ans += (d + 1) * b; n       else n         ans += (d + 1) * 2 * b; n       if (ch ==  0 ) v.push_back(d); n       c++; n     } n     ans += c * (a - b); n     long long p = v.size(); n     if (p > 2) { n       for (long long i = 1; i < p - 1; i++) { n         if (2 * a > b * (v[i] - 1)) { n           ans -= 2 * a; n           ans += b * (v[i] - 1); n         } n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n vector<int> P; n vector<int> vis; n vector<vector<int> > C; n vector<int> lab, sz; n void getCycle() { n   vis = vector<int>(N, 0); n   lab = vector<int>(N, 0); n   for (int i = 0; i < N; i++) { n     if (vis[i]) continue; n     C.push_back(vector<int>()); n     sz.push_back(0); n     int u = i; n     while (!vis[u]) { n       vis[u] = 1; n       lab[u] = C.size() - 1; n       C.back().push_back(u); n       sz.back()++; n       u = P[u]; n     } n   } n } n vector<int> tmp; n void mrg() { n   printf( 1  ); n   for (int i = 1; i < N; i++) { n     if (lab[i] != lab[0]) { n       printf( %d  , i + 1); n       tmp.clear(); n       tmp.push_back(0); n       for (int j = 1; j < C[lab[i]].size(); j++) { n         tmp.push_back(C[lab[i]][j]); n       } n       tmp.push_back(i); n       for (int j = 1; j < C[lab[0]].size(); j++) { n         tmp.push_back(C[lab[0]][j]); n       } n       C[lab[i]].clear(); n       for (int j = 0; j < tmp.size(); j++) { n         lab[tmp[j]] = lab[0]; n       } n       C[lab[0]] = tmp; n       return; n     } n   } n } n void split() { n   for (int i = 0; i < N; i++) { n     if (sz[lab[i]] > 1) { n       printf( %d  , i + 1); n       int idx = 1; n       for (int j = 1; j < C[lab[i]].size(); j++) { n         if (C[lab[i]][idx] > C[lab[i]][j]) { n           idx = j; n         } n       } n       printf( %d  , C[lab[i]][idx] + 1); n       tmp.clear(); n       tmp.push_back(C[lab[i]][idx]); n       for (int j = 1; j < idx; j++) { n         tmp.push_back(C[lab[i]][j]); n       } n       C.push_back(tmp); n       sz.push_back(tmp.size()); n       for (int j = 0; j < tmp.size(); j++) lab[tmp[j]] = C.size() - 1; n       tmp.clear(); n       for (int j = 0; j < C[lab[i]].size(); j++) { n         if (lab[C[lab[i]][j]] == lab[i]) { n           tmp.push_back(C[lab[i]][j]); n         } n       } n       C[lab[i]] = tmp; n       sz[lab[i]] = tmp.size(); n       return; n     } n   } n } n int main() { n   scanf( %d , &N); n   P.resize(N); n   for (int i = 0; i < N; i++) { n     scanf( %d , &P[i]); n     P[i]--; n   } n   getCycle(); n   scanf( %d , &M); n   M = N - M; n   if (C.size() < M) { n     printf( %d n , M - C.size()); n     for (int i = C.size(); i < M; i++) split(); n   } else { n     printf( %d n , C.size() - M); n     for (int i = C.size(); i > M; i--) mrg(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string p; n   cin >> p; n   bool yon; n   for (int i = 0; i < p.length(); i++) { n     if (p[i] ==  H  || p[i] ==  Q  || p[i] ==  9 ) { n       yon = true; n       break; n     } else n       yon = false; n   } n   if (yon) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int mod = 1e6 + 3; n string mm(char c) { n   if (c ==  > ) return  1000 ; n   if (c ==  < ) return  1001 ; n   if (c ==  + ) return  1010 ; n   if (c ==  - ) return  1011 ; n   if (c ==  . ) return  1100 ; n   if (c ==  , ) return  1101 ; n   if (c ==  [ ) return  1110 ; n   if (c ==  ] ) return  1111 ; n } n long long pow2(long long a, long long b, long long c = 0) { n   c = mod; n   long long res = 1; n   a %= c; n   while (b) { n     if (b & 1) res = (res * a) % c; n     a = (a * a) % c; n     b >>= 1; n   } n   return res; n } n int main() { n   string tmp; n   cin >> tmp; n   string ans =   ; n   for (auto &i : tmp) { n     ans += mm(i); n   } n   int sz = ans.length(); n   int cnt = 0; n   long long res = 0; n   for (int i = sz - 1; i >= 0; i--) { n     if (ans[i] ==  1 ) { n       res += pow2(2, cnt); n       res %= mod; n     } n     cnt++; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n class Sieve { n  public: n   vector<T> primes; n   vector<bool> is_prime; n   Sieve(int MAX = 1000000) { n     is_prime.resize(MAX + 1, true); n     is_prime[0] = is_prime[1] = false; n     for (long long int i = 2; i * i <= MAX; i++) n       if (is_prime[i]) n         for (long long int j = i * i; j <= MAX; j += i) is_prime[j] = false; n     for (long long int i = 2; i <= MAX; i++) n       if (is_prime[i]) primes.push_back(i); n   } n }; n template <typename T> n vector<vector<T>> matmul(const vector<vector<T>>& a, n                          const vector<vector<T>>& b) { n   int n = a.size(), m = b[0].size(), k = b.size(); n   vector<vector<T>> c(n, vector<T>(m)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       for (int l = 0; l < k; l++) c[i][j] += (a[i][k] * b[k][j]); n     } n   } n   return c; n } n template <typename T> n T extended_euclid(T a, T b, vector<T>& X) { n   if (b == 0) { n     X = {1, 0}; n     return a; n   } else { n     T g = extended_euclid(b, a % b, X); n     vector<vector<T>> G = {{0LL, 1LL}, {1LL, -(a / b)}}; n     X = matmul<T>(G, X); n     return g; n   } n } n template <typename T> n bool isPrime(T n) { n   if (n <= 1) n     return false; n   else if (n == 2 || n == 3) n     return true; n   else if (n % 2 == 0 || n % 3 == 0) n     return false; n   T x = 5; n   T p = 2; n   while (x * x <= n) { n     if (n % x == 0) return true; n     x += p; n     p = 6 - p; n   } n   return true; n } n long long int binpow(long long int x, long long int n, n                      long long int mod = 1000000007) { n   long long int ans = 1; n   x = x % mod; n   while (n >= 1) { n     if (n & 1) ans = (ans * x) % mod; n     x = (x * x) % mod; n     n >>= 1; n   } n   return ans; n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n template <typename T> n class Graph { n  public: n   int n; n   vector<vector<T>> adj; n   bool directed; n   Graph(int n, bool directed = false) { n     this->n = n; n     adj.resize(n + 1); n     this->directed = directed; n   } n   void add_edge(int u, int v) { n     adj[u].push_back(v); n     if (!directed) adj[v].push_back(u); n   } n   void add_edge(int u, int v, int w) { n     adj[u].push_back({v, w}); n     if (!directed) adj[v].push_back({u, w}); n   } n }; n class DisjointSets { n  public: n   int n; n   vector<int> parent; n   vector<int> rank; n   vector<int> sz; n   DisjointSets(int n, bool Rank = true) { n     this->n = n; n     parent.resize(n + 1, 0); n     (Rank ? rank.resize(n + 1, 1) : sz.resize(n + 1, 1)); n   } n   int find(int i) { n     if (i != parent[i]) parent[i] = find(parent[i]); n     return parent[i]; n   } n   void UnionByRank(int i, int j) { n     i = find(i); n     j = find(j); n     if (i == j) return; n     if (rank[i] < rank[j]) swap(i, j); n     parent[j] = i; n     rank[i] += rank[j]; n   } n   void UnionBySize(int i, int j) { n     i = find(i); n     j = find(j); n     if (i == j) return; n     if (sz[i] < sz[j]) swap(i, j); n     parent[j] = i; n     sz[i] += sz[j]; n   } n }; n template <typename T> n class SegmentTree { n  public: n   vector<T> t; n   int n, H; n   void init(int n) { n     this->n = n; n     t.resize(2 * n); n     this->H = sizeof(int) * 8 - __builtin_clz(n); n   } n   void build() { n     for (int i = n - 1; i > 0; i--) t[i] = t[i << 1] + t[(i << 1) | 1]; n   } n   void update(int pos, T val) { n     for (t[pos += n] += val; pos > 1; pos >>= 1) n       t[pos >> 1] = t[pos] + t[pos ^ 1]; n   } n   T query(int l, int r) { n     T res = 0; n     for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n       if (l & 1) res += t[l++]; n       if (r & 1) res += t[--r]; n     } n     return res; n   } n }; n bool isSubsequenceString(string x, string y) { n   int i = 0, j = 0; n   while (i < x.length() && j < y.length()) x[i] == y[j] ? i++, j++ : i++; n   return (j == y.length()); n } n int max(int a, int b, int c, int d) { return max(a, max(b, max(c, d))); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   vector<int> a(n), b(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   int tx = 0, ty = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] == 1 && b[i] == 0) n       tx++; n     else if (a[i] == 0 && b[i] == 1) n       ty++; n   } n   if (tx > ty) n     cout << 1 <<   n ; n   else if (tx == 0) n     cout <<  -1 n ; n   else { n     int dif = (ty + 1); n     cout << ceil((double)dif / tx); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using vl = vector<ll>; n using pll = pair<ll, ll>; n using vll = vector<pll>; n using MAP = map<ll, ll>; n using sl = set<ll>; n using sll = set<pll>; n using MAPs = map<ll, sl>; n using MAPv = map<ll, vl>; n const ll inf = LLONG_MAX; n const ll mod = 1e9 + 7; n const ll N = 2e5 + 5; n int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}; n int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; n int n, a[N]; n void MAIN() { n   cin >> n; n   vector<int> v; n   for (int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]); n   sort((v).begin(), (v).end()); n   int ind1 = 0, ind2 = 0, cnt = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] != v[i]) { n       cnt++; n       if (!ind1) n         ind1 = i; n       else n         ind2 = i; n     } n   } n   if (cnt > 2) { n     cout <<  NO n ; n     return; n   } n   swap(a[ind1], a[ind2]); n   for (int i = 0; i < n - 1; i++) { n     if (a[i] > a[i + 1]) { n       cout <<  NO n ; n       return; n     } n   } n   cout <<  YES 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-- > 0) { n     MAIN(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, d[128][128][8]; n string s; n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> s; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       for (int k = 0; k <= 4; k++) { n         if (s[i - 1] ==  . ) continue; n         if (!k) { n           d[i][j][k] = 1; n           continue; n         } n         if (i >= j) d[i][j][k] |= d[i - j][j][k - 1]; n         if (k == 4 && d[i][j][k]) { n           cout <<  yes  << endl; n           return 0; n         } n       } n   cout <<  no  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100100]; n int d[100100]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 0; i <= n; i++) { n     d[i] = 100100; n   } n   d[0] = 0; n   for (int i = 0; i < n; i++) { n     int l = 0; n     int r = n - 1; n     while (l < r) { n       int m = (l + r + 1) / 2; n       if (d[m] > a[i]) { n         r = m - 1; n       } else { n         l = m; n       } n     } n     d[r + 1] = a[i]; n   } n   int ans = 0; n   for (int i = 0; i <= n; i++) { n     if (d[i] < 100100) { n       ans = i; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n  n using ll=long long; n #define MOD 1000000007 n  n using namespace std; n  n void calc(double c, double m, double p, double v, double *exp, double prob, int n, int x){ n     if(x==1){ n         prob *= p; n         *exp += prob*n; n         return; n     } n     else if(x>1){ n         double prob1 = prob; n         prob1 *= p; n         *exp += prob1*n; n         if(c>0){ n             double prob2 = prob; n             prob2 *= c; n             if(c-v>1e-7){ n                 calc(c-v, ((m==0)?(0):(m+(v/2))), ((m==0)?(p+v):(p+(v/2))), v, exp, prob2, n+1, x); n             } n             else{ n                 calc(0, ((m==0)?(0):(m+(c/2))), ((m==0)?(p+c):(p+(c/2))), v, exp, prob2, n+1, x-1); n             } n         } n         if(m>0){ n             double prob3 = prob; n             prob3 *= m; n             if(m-v>1e-7){ n                 calc(((c==0)?(0):(c+(v/2))), m-v, ((c==0)?(p+v):(p+(v/2))), v, exp, prob3, n+1, x); n             } n             else{ n                 calc(((c==0)?(0):(c+(m/2))), 0, ((c==0)?(p+m):(p+(m/2))), v, exp, prob3, n+1, x-1); n             } n         } n         return; n     } n     else return; n } n  n void solve() { n     // Write your solution here n     double c, m, p, v; n     cin>>c>>m>>p>>v; n     double exp = 0.0; n     int n = 1; n     int x=3; n     calc(c, m, p, v, &exp, 1, 1, x); n     cout<<setprecision(10)<<exp<<  n ; n     return ; n } n  n int main() { n     cin.tie(nullptr)->sync_with_stdio(false); n  n     int t = 1; n     cin >> t;  // Comment out if single test case n     while (t--) { n         solve(); n     } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long n, m; n long long sum = 0; n int main() { n   scanf( %lld%lld , &n, &m); n   long long max_add = (n - 1) * n / 2; n   long long min_add; n   if (n % 2) min_add = (n / 2 + 1) * (n / 2); n   if (n % 2 == 0) { n     long long a1 = (n / 2 + 1) * (n / 2) / 2; n     long long a2 = (n / 2 - 1) * (n / 2) / 2; n     min_add = a1 + a2; n   } n   for (int i = 1; i <= m; i++) { n     long long x, d; n     scanf( %lld%lld , &x, &d); n     sum += x * n; n     if (d >= 0) n       sum += (long long)d * max_add; n     else n       sum += (long long)d * min_add; n   } n   double ans = sum / 1.0; n   ans = ans / n; n   printf( %.15lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4010; n long long O_O[N][N]; n const long long mod = 1e9 + 7; n int main() { n   int o_o; n   memset(O_O, 0, sizeof(O_O)); n   O_O[0][0] = 1; n   for (int i = 1; i <= 4000; ++i) { n     if (i < 4000) n       o_o = i; n     else n       o_o = 4000; n     for (int j = 1; j <= o_o; ++j) { n       O_O[i][j] = n           ((long long)j * O_O[i - 1][j] % mod + O_O[i - 1][j - 1]) % mod; n     } n   } n   int n; n   cin >> n; n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     ans = (ans + (O_O[n][i] * i) % mod) % mod; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 17; n int n, m, x, y, z, inf; n int bin[N], d[N][N], du[N], f[1 << N], q[N]; n int main() { n   for (register int i = 1; i <= 16; ++i) bin[i] = 1 << (i - 1); n   int sum = 0; n   scanf( %d , &n); n   scanf( %d , &m); n   memset(d, 60, sizeof(d)); n   inf = d[0][0]; n   for (register int i = 1; i <= m; ++i) { n     scanf( %d%d%d , &x, &y, &z); n     sum += z; n     du[x]++; n     du[y]++; n     d[x][y] = d[y][x] = min(d[x][y], z); n   } n   for (register int k = 1; k <= n; ++k) n     for (register int i = 1; i <= n; ++i) n       for (register int j = 1; j <= n; ++j) n         d[i][j] = min(d[i][j], d[i][k] + d[k][j]); n   for (register int i = 2; i <= n; ++i) n     if (du[i] && d[1][i] == inf) { n       puts( -1 ); n       return 0; n     } n   int tot = 0; n   for (register int i = 1; i <= n; ++i) n     if (du[i] & 1) q[++tot] = i; n   int max_statue = bin[tot + 1] - 1; n   memset(f, 60, sizeof(f)); n   f[0] = 0; n   for (register int p = 0; p < max_statue; ++p) { n     for (register int i = 1; i <= tot; ++i) n       if (!(bin[i] & p)) { n         for (register int j = i + 1; j <= tot; ++j) n           if (!(bin[j] & p)) n             f[p | bin[i] | bin[j]] = n                 min(f[p | bin[i] | bin[j]], f[p] + d[q[i]][q[j]]); n         break; n       } n   } n   sum += f[max_statue]; n   printf( %d n , sum); n   return 0; n } n


#include <bits/stdc++.h> n long long mod = 1000000007; n using namespace std; n int n, m; n long long b; n struct node { n   int money, monitors, pre; n   vector<int> G; n } a[202]; n bool cmp(node x, node y) { return x.monitors > y.monitors; } n long long dp[2][1 << 20]; n int setbit(int x, int pos) { return x | (1 << pos); } n bool checkbit(int x, int pos) { return x & (1 << pos); } n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n int has[25]; n int main() { n   int i, j, fl, test, index, mask, cnt = 0; n   scanf( %d%d%lld , &n, &m, &b); n   for (i = 0; i < n; i++) { n     scanf( %d%d%d , &a[i].money, &a[i].monitors, &j); n     while (j--) { n       scanf( %d , &fl); n       fl--; n       a[i].pre = setbit(a[i].pre, fl); n       a[i].G.push_back(fl); n       if (has[fl] == 0) { n         cnt++; n         has[fl] = 1; n       } n     } n   } n   if (cnt < m) { n     printf( -1 n ); n     return 0; n   } n   sort(a, a + n, cmp); n   int tmask, touse; n   for (index = n; index >= 0; index--) { n     for (mask = 0; mask < (1 << m); mask++) { n       touse = index % 2; n       if (mask == (1 << m) - 1) { n         dp[touse][mask] = 0ll; n         continue; n       } n       if (index == n) { n         dp[touse][mask] = -2; n         continue; n       } n       int i; n       long long op1, op2 = a[index].money, op3; n       op1 = dp[(touse + 1) % 2][mask]; n       if (mask == 0) op2 += a[index].monitors * b; n       tmask = mask; n       tmask = tmask | a[index].pre; n       op3 = dp[(touse + 1) % 2][tmask]; n       if (op1 == -2 && op3 == -2) n         dp[touse][mask] = -2; n       else if (op1 != -2 && op3 != -2) n         dp[touse][mask] = min(op1, op2 + op3); n       else if (op1 == -2) n         dp[touse][mask] = op2 + op3; n       else n         dp[touse][mask] = op1; n     } n   } n   long long ans = dp[0][0]; n   if (ans == -2) n     printf( -1 n ); n   else n     printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Number { n   array<int, 4> x = {{0, 0, 0, 0}}; n   Number() {} n   Number(int a) { n     if (a != -1) x[a]++; n   } n   long double log_value() const { n     if (x[0] > 0) return -INFINITY; n     return x[2] * log(2L) + x[3] * log(3L); n   } n   int mod() const { n     long long result = 1; n     for (int i = 0; i < 4; i++) n       for (int j = 0; j < x[i]; j++) result = (result * i) % (int)(1e9 + 7); n     return result; n   } n   bool is_zero() const { return x[0] > 0; } n }; n bool operator<(const Number& a, const Number& b) { n   return a.log_value() < b.log_value(); n } n Number operator*(const Number& a, const Number& b) { n   Number result; n   for (int i = 0; i < 4; i++) result.x[i] = a.x[i] + b.x[i]; n   return result; n } n Number operator/(const Number& a, const Number& b) { n   Number result; n   for (int i = 0; i < 4; i++) result.x[i] = a.x[i] - b.x[i]; n   return result; n } n template <typename T> n using Matrix = vector<vector<T>>; n template <typename T> n Matrix<T> matrix(int R, int C, T x = T()) { n   return Matrix<T>(R, vector<T>(C, x)); n } n struct RangeProduct { n   int N; n   Matrix<int> grid; n   Matrix<Number> hprod; n   Matrix<Number> vprod; n   bool valid(int r, int c) { return 0 <= r && r < N && 0 <= c && c < N; } n   RangeProduct(int N, Matrix<int> grid) : N(N), grid(grid) { n     hprod = matrix<Number>(N + 1, N + 1); n     vprod = matrix<Number>(N + 1, N + 1); n     for (int r = 0; r < N; r++) n       for (int c = 0; c < N; c++) { n         hprod[r][c + 1] = hprod[r][c] * Number(grid[r][c]); n         vprod[r + 1][c] = vprod[r][c] * Number(grid[r][c]); n       } n   } n   Number hquery(int r, int c, int radius) { n     int c1 = c - radius, c2 = c + radius; n     if (!valid(r, c1) || !valid(r, c2)) return Number(0); n     return hprod[r][c2 + 1] / hprod[r][c1]; n   } n   Number vquery(int r, int c, int radius) { n     int r1 = r - radius, r2 = r + radius; n     if (!valid(r1, c) || !valid(r2, c)) return Number(0); n     return vprod[r2 + 1][c] / vprod[r1][c]; n   } n   Number cross(int r, int c, int radius) { n     return hquery(r, c, radius) * vquery(r, c, radius) / Number(grid[r][c]); n   } n   Number max_cross(int r, int c) { n     int a = 0, b = N; n     while (a < b) { n       int mid = (a + b + 1) / 2; n       if (cross(r, c, mid).is_zero()) n         b = mid - 1; n       else n         a = mid; n     } n     return cross(r, c, a); n   } n }; n Number solve(int N, Matrix<int> grid) { n   RangeProduct rp(N, grid); n   Number result(0); n   for (int r = 0; r < N; r++) n     for (int c = 0; c < N; c++) result = max(result, rp.max_cross(r, c)); n   return result; n } n Matrix<int> rotate(int N, const Matrix<int>& grid, int shift) { n   auto ngrid = matrix<int>(N, N); n   for (int r = 0; r < N; r++) n     for (int c = 0; c < N; c++) n       if ((r + c) % 2 == shift) n         ngrid[(r + c) / 2][(r - c + N) / 2] = grid[r][c]; n   return ngrid; n } n int main() { n   int N; n   cin >> N; n   auto grid = matrix<int>(N, N); n   for (int i = 0; i < N; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < N; j++) grid[i][j] = s[j] -  0 ; n   } n   auto rgrid0 = rotate(N, grid, 0); n   auto rgrid1 = rotate(N, grid, 1); n   Number answer = max({solve(N, grid), solve(N, rgrid0), solve(N, rgrid1)}); n   cout << answer.mod() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long t = 1; n   cin >> t; n   while (t--) solve(); n } n void solve() { n   long long n; n   cin >> n; n   string a, b; n   cin >> a >> b; n   string c = a, d = b; n   sort(c.begin(), c.end()); n   sort(d.begin(), d.end()); n   if (c != d) { n     cout << -1 <<   n ; n     return; n   } n   long long ans[n], mx = n; n   for (long long l = 0; l < n; l++) n     for (long long k = 0; k < n; k++) { n       ans[l] = n; n       long long i = l, j = k; n       while (j != n && b[j] != a[i]) j++; n       if (j != n) { n         ans[l]--; n         i++; n         j++; n       } n       while (i != n && j != n) { n         while (i != n && j != n && a[i] != b[j]) i++; n         if (i != n) ans[l]--, j++, i++; n       } n       mx = min(ans[l], mx); n     } n   cout << mx <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 305; n int c[N], a[N], d[N]; n bool cmp(int first, int second) { n   if (a[first] != a[second]) return a[first] < a[second]; n   return first > second; n } n inline int lowbit(int first) { return first & -first; } n int query(int first) { n   int res = 0; n   for (int i = first; i; i -= lowbit(i)) res += c[i]; n   return res; n } n void modify(int first, int v) { n   for (int i = first; i < N; i += lowbit(i)) c[i] += v; n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int n, m; n     scanf( %d%d , &n, &m); n     for (int i = 1; i <= m; ++i) scanf( %d , &a[i]), d[i] = i, c[i] = 0; n     sort(d + 1, d + m + 1, cmp); n     long long res = 0; n     for (int i = 1; i <= m; ++i) { n       res += query(d[i]); n       modify(d[i], 1); n     } n     printf( %lld n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m, q; n   cin >> n >> m >> q; n   vector<vector<pair<int, int>>> pos(n, vector<pair<int, int>>(m)); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       pos[i][j] = {i, j}; n     } n   } n   vector<vector<int>> val(n, vector<int>(m, 0)); n   for (int i = 0; i < q; ++i) { n     int t; n     cin >> t; n     if (t == 1) { n       int r; n       cin >> r; n       --r; n       auto tmp = pos[r][0]; n       for (int i = 1; i < m; ++i) { n         pos[r][i - 1] = pos[r][i]; n       } n       pos[r][m - 1] = tmp; n     } else if (t == 2) { n       int c; n       cin >> c; n       --c; n       auto tmp = pos[0][c]; n       for (int i = 1; i < n; ++i) { n         pos[i - 1][c] = pos[i][c]; n       } n       pos[n - 1][c] = tmp; n     } else { n       int r, c, x; n       cin >> r >> c >> x; n       --r, --c; n       auto p = pos[r][c]; n       val[p.first][p.second] = x; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       cout << val[i][j] <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n int gru0[] = {0, 1, 2}; n int gru1[] = {0, 1, 0, 1, 2}; n int grundy(int x) { n   if (K) { n     if (x < 5) { n       return gru1[x]; n     } else if (x & 1) { n       return 0; n     } else { n       return grundy(x / 2) == 1 ? 2 : 1; n     } n   } else { n     return x <= 2 ? x : !(x & 1); n   } n } n int main() { n   if (fopen( input.txt ,  r )) { n     freopen( input.txt ,  r , stdin); n   } n   ios::sync_with_stdio(false); n   cin >> N >> K; n   K %= 2; n   int ans = 0; n   for (int i = 0, x; i < N; i++) { n     cin >> x; n     ans ^= grundy(x); n   } n   cout << (ans ?  Kevin  :  Nicky ) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h, m, n; n   cin >> h >> m >> n; n   int* id = new int[n]; n   int* hash = new int[n]; n   int* hsh = new int[h]; n   int nc = 0; n   int res = 0; n   char z; n   int i, j, k, l; n   for (i = 0; i < h; i++) { n     hsh[i] = 0; n   } n   for (i = 0; i < n; i++) { n     cin >> z; n     if (z ==  + ) { n       cin >> id[nc] >> hash[nc]; n       int chash = hash[nc]; n       while (hsh[chash] == 1) { n         res++; n         chash = (chash + m) % h; n       } n       hsh[chash] = 1; n       hash[nc] = chash; n       nc++; n     } else { n       int cid; n       cin >> cid; n       for (j = 0; j < nc; j++) { n         if (id[j] == cid) { n           hsh[hash[j]] = 0; n           break; n         } n       } n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int P = 1e9 + 7, INF = 0x3f3f3f3f; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long qpow(long long a, long long n) { n   long long r = 1 % P; n   for (a %= P; n; a = a * a % P, n >>= 1) n     if (n & 1) r = r * a % P; n   return r; n } n long long inv(long long first) { n   return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P; n } n inline int rd() { n   int first = 0; n   char p = getchar(); n   while (p <  0  || p >  9 ) p = getchar(); n   while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar(); n   return first; n } n const int N = 1e6 + 10; n int n; n long long k; n char s[N], t[N]; n int main() { n   scanf( %d%lld%s%s , &n, &k, s + 1, t + 1); n   long long ans = 0, tot = 1, INF = 1e15; n   for (int i = 1; i <= n; ++i) { n     tot <<= 1; n     if (s[i] ==  b ) --tot; n     if (t[i] ==  a ) --tot; n     ans += min(k, tot); n     tot = min(tot, INF); n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[int(1e5 + 2)][2]; n int a[int(1e5 + 2)]; n vector<int> v[2]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int mod = 998244353; n   int t; n   cin >> t; n   while (t--) { n     v[0].clear(); n     v[1].clear(); n     for (int i = 0; i < int(1e5 + 2); i++) dp[i][0] = dp[i][1] = 0; n     int n; n     cin >> n; n     for (int i = 0; i < n; i++) cin >> a[i]; n     long long ans = 0; n     for (int i = n - 1; i >= 0; i--) { n       int one = i % 2; n       dp[a[i]][one] = 1; n       v[one].push_back(a[i]); n       for (auto x : v[1 - one]) { n         int k = a[i] / x; n         if (a[i] % x != 0) k++; n         int x_ = a[i] / k; n         if (dp[x_][one] == 0) v[one].push_back(x_); n         dp[x_][one] += dp[x][1 - one]; n         ans = (ans + (i + 1) * dp[x][1 - one] * (k - 1)) % mod; n         dp[x][1 - one] = 0; n       } n       v[1 - one].clear(); n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   while (n--) { n     int q, ans = 0; n     cin >> q; n     if (q % 2) q -= 9, ans++; n     if (q < 0) n       ans = -1; n     else n       ans += q / 4; n     if (q == 2) ans = -1; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 998244353; n long long power(long long a, long long b, long long m) { n   long long res = 1; n   a %= m; n   while (b) { n     if (b & 1LL) res = res * a % m; n     a = a * a % m; n     b >>= 1; n   } n   return res; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, m, k; n   cin >> n >> m >> k; n   m = power(m, M - 2, M); n   vector<vector<long long>> dp(k + 1, vector<long long>(k + 1, 0)); n   for (long long i = 0; i <= k; ++i) { n     for (long long j = 0; j <= k; ++j) { n       long long N = n - k + i, K = j; n       if (N <= 0 || K == 0) { n         dp[i][j] = 0; n         continue; n       } n       if (K == 1) { n         dp[i][j] = N * m % M; n         continue; n       } n       if (i > 0) n         dp[i][j] = n             (dp[i][j - 1] - dp[i - 1][j - 1] * (1 - m + M) % M + M) % M * N % M; n     } n   } n   cout << dp[k][k] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T min_(T a, T b) { n   return (a < b ? a : b); n } n template <class T> n T max_(T a, T b) { n   return (a > b ? a : b); n } n const int MAX_N = 1e5 + 1; n vector<pair<unsigned long long, unsigned long long> > notes; n int main(int argc, char *argv[]) { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   int days, nnotes; n   cin >> days >> nnotes; n   notes.resize(nnotes); n   int day, h; n   int max_h = 0; n   for (int i = 0; i < nnotes; ++i) { n     cin >> day >> h; n     max_h = max(max_h, h); n     notes[i] = {day, h}; n   } n   int new_h; n   int day1, day2, h1, h2; n   day1 = notes[0].first; n   if (day1 != 1) { n     h1 = notes[0].second; n     new_h = h1 + day1 - 1; n     max_h = max(max_h, new_h); n   } n   for (int i = 0; i < nnotes; ++i) { n     day1 = notes[i].first; n     h1 = notes[i].second; n     if (i == nnotes - 1) { n       day2 = days; n       new_h = h1 + (day2 - day1); n       max_h = max(max_h, new_h); n       break; n     } n     day2 = notes[i + 1].first; n     h2 = notes[i + 1].second; n     int ddiff = day2 - day1; n     int hdiff = abs(h2 - h1); n     if (hdiff > ddiff) { n       cout <<  IMPOSSIBLE n ; n       return 0; n     } else { n       if (h1 < h2) { n         day1 = day1 + hdiff; n         ddiff = day2 - day1; n         h1 = h2; n       } else if (h1 > h2) { n         day2 = day2 - hdiff; n         ddiff = day2 - day1; n         h2 = h1; n       } n       new_h = h1 + (ddiff / 2); n       max_h = max(max_h, new_h); n     } n   } n   cout << max_h <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 500054; n const double eps = 3e-10; n inline void up(double &x, const double y) { x < y ? x = y : 0.; } n inline void down(double &x, const double y) { x > y ? x = y : 0.; } n inline double max(const double x, const double y) { return x < y ? y : x; } n struct quadratic { n   double A, B, C; n   quadratic(double A_ = 0., double B_ = 0., double C_ = 0.) n       : A(A_), B(B_), C(C_) {} n   inline double operator()(double x) const { return (A * x + B) * x + C; } n   inline std::pair<double, double> root(double y) const { n     if ((((A) <= (0) + eps) && ((A) >= (0) - eps))) n       return std::pair<double, double>((y - C) / B, NAN); n     double b = -.5 * B / A, d = b * b + (y - C) / A; n     return ((d) < (0) - eps) ? std::pair<double, double>(NAN, NAN) n                              : (d = sqrt(max(d, 0.)), n                                 std::pair<double, double>(b - d, b + d)); n   } n   inline std::pair<double, double> range(double x_min, double x_max) const { n     assert(x_min <= x_max); n     std::pair<double, double> ret = std::minmax((*this)(x_min), (*this)(x_max)); n     double mid = -.5 * B / A; n     if ((((A) <= (0) + eps) && ((A) >= (0) - eps)) || mid < x_min || n         x_max < mid) n       ; n     else n       mid = (*this)(mid), down(ret.first, mid), up(ret.second, mid); n     return ret; n   } n }; n struct vec2 { n   double x, y; n   vec2(double x0 = 0., double y0 = 0.) : x(x0), y(y0) {} n   vec2 *read() { n     scanf( %lf%lf , &x, &y); n     return this; n   } n   inline vec2 operator-() const { return vec2(-x, -y); } n   inline vec2 operator+(const vec2 &B) const { return vec2(x + B.x, y + B.y); } n   inline vec2 operator-(const vec2 &B) const { return vec2(x - B.x, y - B.y); } n   inline vec2 operator*(double k) const { return vec2(x * k, y * k); } n   inline vec2 operator/(double k) const { return *this * (1.0 / k); } n   inline double operator*(const vec2 &B) const { return x * B.x + y * B.y; } n   inline double operator^(const vec2 &B) const { return x * B.y - y * B.x; } n   inline double norm2() const { return x * x + y * y; } n   inline double norm() const { return sqrt(x * x + y * y); } n   inline bool operator<(const vec2 &B) const { n     return ((x) < (B.x) - eps) || ((x) <= (B.x) + eps) && ((y) < (B.y) - eps); n   } n   inline bool operator==(const vec2 &B) const { n     return (((x) <= (B.x) + eps) && ((x) >= (B.x) - eps)) && n            (((y) <= (B.y) + eps) && ((y) >= (B.y) - eps)); n   } n }; n int n, m, sr = 0; n vec2 p[N], unit[N]; n double C[N], co[N], u; n double st[N]; n quadratic f[N]; n std::pair<double, double> rg[N]; n inline int pred(int x) { return (x ? x : n) - 1; } n inline int succ(int x) { return ++x == n ? 0 : x; } n void append(double len, int i1, double s1, int i2, double s2) { n   if (s1 < 0) s1 += C[n]; n   if (s2 < 0) s2 += C[n]; n   st[sr + 1] = st[sr] + len; n   vec2 O = (p[i1] + unit[i1] * s1) - (p[i2] + unit[i2] * s2), n        v = unit[i1] - unit[i2]; n   f[sr++] = quadratic(v.norm2(), v * O * 2., O.norm2()); n } n namespace seg { n int n; n bool danger; n std::pair<double, double> a[N]; n inline void reset() { n = 0, danger = false; } n inline void insert(double L, double R) { n   assert(L <= R); n   int Li = L / u, Ri = R / u; n   L -= Li * u, R -= Ri * u; n   if (Li == Ri) n     a[n++] = std::pair<double, double>(L, R); n   else if (Li + 1 == Ri && L > R) n     a[n++] = std::pair<double, double>(L, u), n     a[n++] = std::pair<double, double>(0, R); n   else n     danger = true; n } n bool exist() { n   if (danger) return false; n   int i; n   double k = 0; n   std::sort(a, a + n); n   for (i = 0; i < n; ++i) { n     if (k < a[i].first) return true; n     up(k, a[i].second); n   } n   return ((k) < (u)-eps); n } n }  // namespace seg n inline bool check(double lim) { n   int i; n   double L, R, x1, x2; n   seg::reset(); n   for (i = 0; i < sr; ++i) { n     if (L = st[i], R = st[i + 1], (((L) <= (R) + eps) && ((L) >= (R)-eps))) n       continue; n     if (lim <= rg[i].first) n       seg::insert(L, R); n     else if (lim < rg[i].second) { n       std::tie(x1, x2) = f[i].root(lim), x1 += L, x2 += L; n       if (!(L <= x1 && x1 <= R)) std::swap(x1, x2); n       if (L <= x2 && x2 <= R) n         f[i].C >= lim          ? seg::insert(L, x1), n             seg::insert(x2, R) : seg::insert(x1, x2); n       else n         f[i].C >= lim ? seg::insert(L, x1) : seg::insert(x1, R); n     } n   } n   return seg::exist(); n } n int main() { n   int i, j; n   double L, R, M; n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; ++i) p[i].read(); n   p[n] = *p; n   for (i = 0; i < n; ++i) n     L = (p[i] - p[i + 1]).norm(), C[i + 1] = C[i] + L, n     unit[i] = (p[i + 1] - p[i]) / L; n   u = C[n] / m; n   for (i = 0; i < n; ++i) co[i] = fmod(C[i] + C[n] - u, C[n]); n   j = pred(std::min_element(co, co + n) - co); n   for (i = 0; i < n; ++i) { n     for (L = C[i]; C[i] <= co[succ(j)] && co[succ(j)] < C[i + 1]; n          j = succ(j), L = co[j]) n       append(co[succ(j)] - L, i, L - C[i], j, L - co[j]); n     append(C[i + 1] - L, i, L - C[i], j, L - co[j]); n   } n   for (i = 0; i < sr; ++i) rg[i] = f[i].range(0, st[i + 1] - st[i]); n   { n     vec2 *_1, *_2; n     std::tie(_1, _2) = std::minmax_element(p, p + n), R = (*_1 - *_2).norm(); n   } n   for (L = 0.; L + eps < R;) M = (L + R) * .5, check(M * M) ? R = M : L = M; n   printf( %.10lg n , (L + R) * .5); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   vector<pair<int, int>> ans; n   for (int c = 1; c < k; c++) { n     int r = 0; n     int C = c; n     while (ans.size() < n) { n       ans.emplace_back(r + 1, C + 1); n       if (C == k - 1) break; n       r++, C++; n     } n     r = k - 1; n     C = k - c - 1; n     while (ans.size() < n) { n       ans.emplace_back(r + 1, C + 1); n       if (C == 0) break; n       r--, C--; n     } n   } n   if (ans.size() != n) { n     cout <<  NO  << endl; n     return (0); n   } n   cout <<  YES  << endl; n   for (auto pp : ans) cout << pp.first <<     << pp.second <<   n ; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n struct str { n   int q, cost; n   str(int _q = 0, int _cost = 0) { n     q = _q; n     cost = _cost; n   } n   bool operator<(const str &two) const { return cost > two.cost; } n }; n struct edge { n   int u, v, cost; n   edge(int _u = 0, int _v = 0, int _cost = 0) { u = _u, v = _v, cost = _cost; } n }; n vector<str> adj[(100000 + 10)]; n int n, m, s; n int len; n int u, v, cost; n int dis[(100000 + 10)]; n vector<edge> all; n int main() { n   cin >> n >> m >> s; n   for (int i = 0; i < m; i++) { n     cin >> u >> v >> cost; n     all.push_back(edge(u, v, cost)); n     adj[u].push_back(str(v, cost)); n     adj[v].push_back(str(u, cost)); n   } n   cin >> len; n   for (int i = 1; i <= n; i++) dis[i] = 1000000000; n   dis[s] = 0; n   priority_queue<str> pq; n   pq.push(str(s, 0)); n   while (!pq.empty()) { n     str v = pq.top(); n     pq.pop(); n     int node = v.q; n     for (int i = 0; i < adj[node].size(); i++) { n       int u = adj[node][i].q; n       int cost = adj[node][i].cost; n       if (dis[node] + cost < dis[u]) { n         dis[u] = dis[node] + cost; n         pq.push(str(u, dis[u])); n       } n     } n   } n   int out = 0; n   for (int i = 1; i <= n; i++) n     if (dis[i] == len) out++; n   int one, two; n   for (int i = 0; i < all.size(); i++) { n     u = all[i].u; n     v = all[i].v; n     cost = all[i].cost; n     if (dis[u] < len && len < dis[u] + cost && n         cost - (len - dis[u]) + dis[v] > len) n       out++; n     if (dis[v] < len && len < dis[v] + cost && n         cost - (len - dis[v]) + dis[u] > len) n       out++; n     if (dis[v] < len && dis[u] < len && dis[u] + dis[v] + cost == 2 * len) n       out++; n   } n   cout << out << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n int d4x[4] = {1, 0, -1, 0}; n int d4y[4] = {0, 1, 0, -1}; n int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}; n int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1}; n const long long oo = 1e18; n const long long maxN = 1e6; n const int N = 105; n long long a[N]; n void solve() { n   int n; n   long long h; n   cin >> n >> h; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + 1 + n); n   auto ok = [&](long long x) -> bool { n     long long ans = 0; n     for (int i = 1; i <= n; i++) { n       if (i < n) n         ans += min(a[i + 1] - a[i], x); n       else n         ans += x; n       if (ans >= h) return true; n     } n     return false; n   }; n   long long L = 1, R = h, ans = 0; n   while (L <= R) { n     long long mid = (L + R) >> 1; n     if (ok(mid)) { n       ans = mid; n       R = mid - 1; n     } else n       L = mid + 1; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tc = 1, ddd = 0; n   cin >> tc; n   while (tc--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int arr[500005], sum[500005]; n bool vis[100005]; n map<long long int, long long int> hola; n map<pair<long long int, long long int>, long long int> con; n vector<pair<long long int, long long int>> conn; n int main() { n   long long int n, maxi = INT_MIN; n   cin >> n; n   for (long long int i = 0; i < n; i++) { n     cin >> arr[i]; n     hola[arr[i]]++; n   } n   for (long long int i = 0; i < n; i++) { n     if (hola[arr[i]] > maxi) maxi = hola[arr[i]]; n   } n   cout << maxi; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const int INF = 1000000000; n const int MAX = 5000; n const int MOD = 1000000007; n int C[MAX][MAX]; n int CL[MAX]; n int main() { n   int n; n   cin >> n; n   C[0][0] = 1; n   for (int i = (1); i < (n + 1); ++i) { n     C[i][0] = 1; n     for (int j = (1); j < (n + 1); ++j) { n       C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; n       if (C[i][j] >= MOD) C[i][j] -= MOD; n     } n   } n   CL[0] = 1; n   for (int i = (1); i < (n + 1); ++i) { n     CL[i] = 0; n     for (int j = (1); j < (i + 1); ++j) { n       long long c = C[i - 1][j - 1]; n       c *= CL[i - j]; n       c %= MOD; n       CL[i] += c; n       if (CL[i] >= MOD) CL[i] -= MOD; n     } n   } n   long long res = 0; n   for (int i = (1); i < (n + 1); ++i) { n     long long c = C[n][i]; n     int m = n - i; n     c *= CL[m]; n     c %= MOD; n     res += c; n     if (res >= MOD) res -= MOD; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1E-8; n const int dx4[4] = {1, 0, 0, -1}; n const int dy4[4] = {0, -1, 1, 0}; n const int inf = 0x3f3f3f3f; n const int N = 2E5 + 7; n int tree[2][N]; n int a[N], p[N]; n int n; n long long k; n int lowbit(int x) { return x & (-x); } n void update(int o, int x, int delta) { n   if (!o) x = n - x + 1; n   for (int i = x; i <= n; i += lowbit(i)) tree[o][i] += delta; n } n int Hash(int x) { return lower_bound(p + 1, p + n + 1, x) - p; } n int Sum(int o, int x) { n   if (!o) x = n - x + 1; n   int res = 0; n   for (int i = x; i >= 1; i -= lowbit(i)) res += tree[o][i]; n   return res; n } n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i], p[i] = a[i]; n   sort(p + 1, p + n + 1); n   long long total = 0; n   for (int i = n; i >= 1; i--) { n     int x = Hash(a[i]); n     a[i] = x; n     total += Sum(1, a[i] - 1); n     update(1, a[i], 1); n   } n   int r = 1; n   long long ans = 0; n   for (int l = 1; l <= n; l++) { n     total += Sum(0, a[l] + 1) + Sum(1, a[l] - 1); n     update(0, a[l], 1); n     while ((r <= l || total > k) && r <= n) { n       total -= Sum(0, a[r] + 1) + Sum(1, a[r] - 1); n       update(1, a[r], -1); n       r++; n     } n     ans += n - r + 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 25, M = 300005; n int n, a[N][N]; n long long f[M], g[N][M], d[N][M], dp[N][M]; n map<long long, long long> mp; n string st; n inline int bp(int x) { return __builtin_popcount(x); } n void dfs(int p, int s, int x, long long m) { n   if (s == n) { n     long long w = 0; n     for (int i = 0; i < (1 << n); i++) { n       if ((n + bp(i)) & 1) n         w -= d[x][i]; n       else n         w += d[x][i]; n     } n     mp[m] = w; n     return; n   } n   if (s + p > n) return; n   for (int i = 0; i < (1 << n); i++) d[x + 1][i] = d[x][i] * g[p][i]; n   dfs(p, s + p, x + 1, m * 10 + p); n   dfs(p + 1, s, x, m); n } n long long ch(int x) { n   vector<int> v; n   int s = 0; n   for (int i = 0; i < n; i++) { n     if (x >> i & 1) n       s++; n     else { n       v.push_back(s + 1); n       s = 0; n     } n   } n   sort(v.begin(), v.end()); n   long long y = 0; n   for (auto i : v) y = y * 10 + i; n   return y; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> st; n     for (int j = 0; j < n; j++) a[i][j] = (st[j] ==  1 ); n   } n   for (int i = 0; i < n; i++) dp[i][1 << i] = 1; n   for (int i = 1; i < (1 << n); i++) { n     for (int j = 0; j < n; j++) { n       if (dp[j][i]) { n         g[bp(i)][i] += dp[j][i]; n         for (int k = 0; k < n; k++) n           if (!(i >> k & 1) && a[j][k]) dp[k][i | (1 << k)] += dp[j][i]; n       } n     } n   } n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < n; j++) n       for (int s = 0; s < (1 << n); s++) n         if (s >> j & 1) g[i][s] += g[i][s ^ (1 << j)]; n   for (int i = 0; i < (1 << n); i++) d[0][i] = 1; n   dfs(1, 0, 0, 0); n   for (int i = 0; i < (1 << (n - 1)); i++) f[i] = mp[ch(i)]; n   for (int i = 0; i < n - 1; i++) n     for (int j = 0; j < (1 << (n - 1)); j++) n       if (!(j >> i & 1)) f[j] -= f[j ^ (1 << i)]; n   for (int i = 0; i < (1 << (n - 1)); i++) printf( %lld  , f[i]); n   return 0; n } n