#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n const int M = 100005; n int n, m; n int in_degree[N]; n bool visited[N]; n bool tree_edge[M]; n bool directed[M]; n vector<int> choose[N]; n vector<pair<int, int> > adj[N]; n inline void dfs(int u, int p) { n   visited[u] = true; n   for (auto edge : adj[u]) { n     int v = edge.first; n     int i = edge.second; n     if (v == p) { n       continue; n     } n     if (not visited[v]) { n       dfs(v, u); n       tree_edge[i] = true; n     } else if (not directed[i]) { n       in_degree[v]++; n       directed[i] = true; n       choose[v].push_back(u); n     } n   } n } n inline void solve(int u, int p) { n   for (auto edge : adj[u]) { n     int v = edge.first; n     int i = edge.second; n     if ((not tree_edge[i]) || (v == p)) { n       continue; n     } n     solve(v, u); n   } n   if (p != -1) { n     if (in_degree[u] & 1) { n       in_degree[u]++; n       choose[u].push_back(p); n     } else { n       in_degree[p]++; n       choose[p].push_back(u); n     } n   } n } n int main() { n   cin >> n >> m; n   if (m & 1) { n     cout <<  No solution  << endl; n     return 0; n   } n   for (int i = 1; i <= m; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back({v, i}); n     adj[v].push_back({u, i}); n   } n   dfs(1, -1); n   solve(1, -1); n   for (int i = 1; i <= n; i++) { n     while ((int)choose[i].size() > 0) { n       int u = choose[i].back(); n       choose[i].pop_back(); n       int v = choose[i].back(); n       choose[i].pop_back(); n       cout << u <<     << i <<     << v << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n int n, m; n long long c[maxn], ans, s; n vector<int> g[maxn]; n bool v[maxn]; n void dfs(int a) { n   s = min(s, c[a]); n   v[a] = 1; n   for (int i = 0; i < g[a].size(); i++) { n     int b = g[a][i]; n     if (!v[b]) dfs(b); n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %lld , &c[i]); n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     g[x].push_back(y); n     g[y].push_back(x); n   } n   ans = 0; n   for (int i = 1; i <= n; i++) { n     if (v[i]) continue; n     s = (1e9) + 1; n     dfs(i); n     ans += s; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool mul_overflow(long long a, long long b) { return (a > (LLONG_MAX / b)); } n bool add_overflow(long long a, long long b) { return (a > (LLONG_MAX - b)); } n const int N = 1e6 + 5; n int n; n long double a[N][3]; n bool sol(long double mid) { n   long double l = -1e8, r = 1e8; n   for (int i = 1; i <= n; i++) { n     long double rs = 2 * mid * a[i][2] - a[i][2] * a[i][2]; n     if (rs < 0) { n       l = -1e8, r = 1e8; n     } else { n       l = max(l, a[i][1] - sqrt(rs)); n       r = min(r, a[i][1] + sqrt(rs)); n     } n   } n   cout << (l <= r) <<   n ; n   return (l <= r); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i][1] >> a[i][2]; n   } n   int f = -1; n   if (a[1][1] >= 0 && a[1][2] >= 0 || a[1][2] >= 0 && a[1][1] <= 0) n     f = 1; n   else n     f = 0; n   for (int i = 2; i <= n; i++) { n     if (f == 1) { n       if (!(a[i][1] >= 0 && a[i][2] >= 0 || a[i][2] >= 0 && a[i][1] <= 0)) { n         cout <<  -1 n ; n         return 0; n       } n     } else { n       if (a[i][1] >= 0 && a[i][2] >= 0 || a[i][2] >= 0 && a[i][1] <= 0) { n         cout <<  -1 n ; n         return 0; n       } n     } n   } n   if (n == 1) { n     cout << a[1][2] / 2 <<   n ; n     return 0; n   } n   long double lo = 0, hi = 1e18; n   for (int i = 1; i <= 100; i++) { n     long double xl = -1e18, xr = 1e18; n     long double r = (lo + hi) / 2; n     bool f = 0; n     for (int i = 1; i <= n; i++) { n       long double x = a[i][1], y = abs(a[i][2]); n       long double t = 2 * y * r - y * y; n       if (t < 0) { n         f = 1; n         break; n       } n       t = sqrt(t); n       xl = max(xl, x - t); n       xr = min(xr, x + t); n     } n     if (f == false && xr > xl) { n       hi = r; n     } else n       lo = r; n   } n   cout << fixed << setprecision(11) << lo <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[1000005]; n int main() { n   while (scanf(  %s , str) != EOF) { n     int i, len = strlen(str); n     long long m, l = 0, r = 0; n     for (i = 0; i < len; i++) n       if (str[i] ==  ^ ) m = i; n     for (i = 0; i < len; i++) n       if (str[i] >=  1  && str[i] <=  9 ) { n         if (i < m) n           l += (m - i) * (str[i] -  0 ); n         else n           r += (i - m) * (str[i] -  0 ); n       } n     if (l > r) n       printf( left n ); n     else if (r > l) n       printf( right n ); n     else n       printf( balance n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int from[101], to[101], p; n int main() { n   int n, m, x, y; n   cin >> n >> m; n   memset(to, -1, sizeof to); n   for (int i = 1; i <= n; i++) { n     cin >> x >> y; n     for (int j = x; j <= y; j++) to[j] = max(to[j], y); n   } n   int now = 0; n   for (; now <= m;) { n     if (to[now] == -1 || to[now] == now) break; n     if (now == m || (now <= m and to[now] >= m)) { n       cout <<  YES ; n       return 0; n     } n     now = to[now]; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b; n   scanf( %I64d , &a); n   scanf( %I64d , &b); n   if (a == b) { n     printf( 1 n ); n     return 0; n   } n   long long cnt = 0, ans = 1; n   for (long long i = b; i >= a + 1; i--) { n     cnt++; n     if (i % 10 == 0) { n       printf( 0 n ); n       return 0; n     } n     ans *= i % 10; n     ans %= 10; n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n struct Edge { n   long long int from, to, cap, flow, index; n   Edge(long long int from, long long int to, long long int cap, n        long long int flow, long long int index) n       : from(from), to(to), cap(cap), flow(flow), index(index) {} n }; n struct PushRelabel { n   long long int N; n   vector<vector<Edge>> G; n   vector<long long> excess; n   vector<long long int> dist, active, count; n   queue<long long int> Q; n   PushRelabel(long long int N) n       : N(N), G(N), excess(N), dist(N), active(N), count(2 * N) {} n   void AddEdge(long long int from, long long int to, long long int cap) { n     G[from].push_back(Edge(from, to, cap, 0, G[to].size())); n     if (from == to) G[from].back().index++; n     G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1)); n   } n   void Enqueue(long long int v) { n     if (!active[v] && excess[v] > 0) { n       active[v] = true; n       Q.push(v); n     } n   } n   void Push(Edge &e) { n     long long int amt = min(excess[e.from], e.cap - e.flow); n     if (dist[e.from] <= dist[e.to] || amt == 0) return; n     e.flow += amt; n     G[e.to][e.index].flow -= amt; n     excess[e.to] += amt; n     excess[e.from] -= amt; n     Enqueue(e.to); n   } n   void Gap(long long int k) { n     for (long long int v = 0; v < N; v++) { n       if (dist[v] < k) continue; n       count[dist[v]]--; n       dist[v] = max(dist[v], N + 1); n       count[dist[v]]++; n       Enqueue(v); n     } n   } n   void Relabel(long long int v) { n     count[dist[v]]--; n     dist[v] = 2 * N; n     for (long long int i = 0; i < G[v].size(); i++) n       if (G[v][i].cap - G[v][i].flow > 0) n         dist[v] = min(dist[v], dist[G[v][i].to] + 1); n     count[dist[v]]++; n     Enqueue(v); n   } n   void Discharge(long long int v) { n     for (long long int i = 0; excess[v] > 0 && i < G[v].size(); i++) n       Push(G[v][i]); n     if (excess[v] > 0) { n       if (count[dist[v]] == 1) n         Gap(dist[v]); n       else n         Relabel(v); n     } n   } n   long long GetMaxFlow(long long int s, long long int t) { n     count[0] = N - 1; n     count[N] = 1; n     dist[s] = N; n     active[s] = active[t] = true; n     for (long long int i = 0; i < G[s].size(); i++) { n       excess[s] += G[s][i].cap; n       Push(G[s][i]); n     } n     while (!Q.empty()) { n       long long int v = Q.front(); n       Q.pop(); n       active[v] = false; n       Discharge(v); n     } n     long long totflow = 0; n     for (long long int i = 0; i < G[s].size(); i++) totflow += G[s][i].flow; n     return totflow; n   } n }; n void solve() { n   long long int n; n   cin >> n; n   long long int m; n   cin >> m; n   long long int x; n   cin >> x; n   vector<array<long long int, 3>> edge(m); n   for (long long int i = 0; i < m; i++) { n     cin >> edge[i][0]; n     edge[i][0]--; n     cin >> edge[i][1]; n     edge[i][1]--; n     cin >> edge[i][2]; n   } n   long double low = 0; n   long double high = 1e9; n   for (long long int i = 0; i < 100; i++) { n     long double mid = (low + high) / (long double)2; n     PushRelabel G(n); n     for (auto e : edge) { n       G.AddEdge(e[0], e[1], (long long int)(e[2] / mid)); n     } n     if (G.GetMaxFlow(0, n - 1) >= x) { n       low = mid; n     } else { n       high = mid; n     } n   } n   long double avg = (low + high) / (long double)2; n   cout << fixed << setprecision(9) << (long double)x * avg <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(); n   cerr <<  Time :   n        << 1000 * ((long double)clock()) / (long double)CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int X[] = {1, 0, -1, 0, 1, -1, -1, 1}; n int Y[] = {0, 1, 0, -1, 1, 1, -1, -1}; n void MN(long long int &a, long long int b) { n   if (a > b) a = b; n } n void MX(long long int &a, long long int b) { n   if (a < b) a = b; n } n void MN(int &a, int b) { n   if (a > b) a = b; n } n void MX(int &a, int b) { n   if (a < b) a = b; n } n long long int MOD(long long int a, long long int b) { n   return a >= 0 ? a % b : (b - abs(a % b)) % b; n } n int OneD(int row, int col, int t_n_o_r) { return row * t_n_o_r + col; } n int main() { n   int n, o = 0; n   scanf( %d , &n); n   unsigned long long int res = 0; n   vector<int> seq(n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &seq[i]); n     if (seq[i] & 1) o++; n   } n   sort(seq.begin(), seq.end()); n   if (o & 1) o--; n   for (int i = n - 1; i >= 0; i--) { n     if (seq[i] & 1) { n       if (o > 0) { n         res += seq[i]; n         o--; n       } n     } else n       res += seq[i]; n   } n   printf( %lld n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double a, b, c, s, r; n double A, B, C; n double eps = 1e-3; n double pi = acos(-1.0); n struct Point { n   double x, y; n } p[10]; n double disP2P(Point a, Point b) { n   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n } n int sgn(double x) { n   if (fabs(x) < eps) return 0; n   if (x > 0) return 1; n   return -1; n } n double fgcd(double a, double b) { n   if (sgn(b) == 0) return a; n   return fgcd(b, fmod(a, b)); n } n int main() { n   for (int i = 0; i < 3; ++i) { n     cin >> p[i].x >> p[i].y; n   } n   a = disP2P(p[0], p[1]); n   b = disP2P(p[1], p[2]); n   c = disP2P(p[2], p[0]); n   double x = (a + b + c) / 2; n   s = sqrt(x * (x - a) * (x - b) * (x - c)); n   r = a * b * c / 4 / s; n   A = acos(1 - a * a / 2 / r / r); n   B = acos(1 - b * b / 2 / r / r); n   C = 2 * pi - A - B; n   double ang = fgcd(A, fgcd(B, C)); n   double ans = pi / ang * r * r * sin(ang); n   printf( %.7f n , ans); n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n const int Max = 35010; n const ll INF  = 1e17 + 10; n  n bool sw; ll dp[2][Max]; n int A[Max]; n  n int L , R , F; n deque<int> dq[Max]; n  n void moveto(int l , int r) n { n  //cout <<  to   << l <<  ,  << r <<   n ; n  while(L > l) n  { n   L--; n   if(dq[A[L]].size() > 0) F += dq[A[L]].front(); n   dq[A[L]].push_front(L); n   if(dq[A[L]].size() > 1) F -= dq[A[L]].front(); n  } n  while(R < r) n  { n   R++; n   if(dq[A[R]].size() > 0) F -= dq[A[R]].back(); n   dq[A[R]].push_back(R); n   if(dq[A[R]].size() > 1) F += dq[A[R]].back(); n  } n  while(R > r) n  { n   if(dq[A[R]].size() > 1) F -= dq[A[R]].back(); n   dq[A[R]].pop_back(); n   if(dq[A[R]].size() > 0) F += dq[A[R]].back(); n   R--; n  } n  while(L < l) n  { n   if(dq[A[L]].size() > 1) F += dq[A[L]].front(); n   dq[A[L]].pop_front(); n   if(dq[A[L]].size() > 0) F -= dq[A[L]].front(); n   L++; n  } n } n  n void solve(int l , int r , int tl , int tr) n { n  if(r < l) return; n  int mid = (l + r) >> 1; n  int opt = -1; ll ans = INF; n  for(int i = min(tr , mid - 1) ; i >= tl ; i--) n  { n   //cout <<  res   << i + 1 <<  ,  << mid <<   =  ; n   moveto(i + 1 , mid); n   //cout << F <<   n ; n   ll nans = F + dp[!sw][i]; n   if(nans <= ans) opt = i , ans = nans; n  } n  dp[sw][mid] = ans; n  n  moveto(opt + 1 , mid); n  solve(l , mid - 1 , tl , opt); n  moveto(opt + 1 , mid); n  solve(mid + 1 , r , opt , tr); n } n int main() n { n  int n , k; cin >> n >> k; n  for(int i = 1 ; i <= n ; i++) cin >> A[i]; n  //for(int i = 1 ; i <= n ; i++) dp[sw][i] = INF; n  n  L = 1 , R = 1 , F = 0 , dq[A[1]].push_back(1); n  n   n  for(int i = 1 ; i <= n ; i++) n  { n   moveto(1 , i); n   dp[sw][i] = F; n  } n  //cout <<   n ; n  for(int i = 1 ; i < k ; i++) n  { n   moveto(1 , n); n   sw = !sw; n   solve(1 , n , 0 , n - 1); n   //for(int i = 1 ; i <= n ; i++) cout << dp[sw][i] <<    ; cout <<   n ; n  } n  cout << dp[sw][n] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int countnode(map<int, vector<int>> m, int x, int parent) { n   int count = 1; n   for (auto i : m[x]) { n     if (i != parent) count += countnode(m, i, x); n   } n   return count; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, x; n     cin >> n >> x; n     map<int, vector<int>> m; n     for (int i = 0; i < n - 1; i++) { n       int a, b; n       cin >> a >> b; n       m[a].push_back(b); n       m[b].push_back(a); n     } n     if (m[x].size() == 1 || m[x].size() == 0) n       cout <<  Ayush  << endl; n     else { n       if (countnode(m, x, x) % 2 == 0) n         cout <<  Ayush  << endl; n       else n         cout <<  Ashish  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long cumdp[2005]; n long long cumpd[2005]; n long long dp[2005][2005]; n long long pd[2005][2005]; n const long long mod = 1e9 + 7; n int main() { n   long long n, m; n   cin >> n >> m; n   for (int width = 2; width <= m; width++) { n     dp[1][width] = 1; n     pd[1][width] = 1; n   } n   for (int len = 2; len <= n; len++) { n     long long sum = 0; n     for (int width = 2; width <= m; width++) { n       sum += dp[len - 1][width]; n       sum %= mod; n       dp[len][width] = dp[len][width - 1] + sum; n       pd[len][width] = dp[len][width] - dp[len - 1][width]; n     } n   } n   long long ans = 0; n   for (int base = 1; base <= m; base++) { n     for (int len = 1; len <= n; len++) { n       cumdp[len] = cumdp[len - 1] + dp[len][base]; n       cumdp[len] %= mod; n       cumpd[len] = cumpd[len - 1] + pd[len][base]; n       cumpd[len] %= mod; n     } n     long long cur = 0; n     for (int cen = 1; cen <= n; cen++) { n       cur += (cumdp[cen] * cumpd[n - cen + 1]) % mod; n       cur %= mod; n     } n     cur *= (m - base + 1); n     cur %= mod; n     ans += cur; n     ans %= mod; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int C[200005], L[200005], N[200005]; n inline int findSet(int i) { return (N[i] == i) ? i : (N[i] = findSet(N[i])); } n inline void unionSet(int i, int j) { N[findSet(i)] = findSet(j); } n int main() { n   int n, m; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , C + i); n     N[i] = i; n   } n   N[n] = n; n   scanf( %d , &m); n   int op, k, a; n   while (m--) { n     scanf( %d %d , &op, &k); n     if (op == 1) { n       scanf( %d , &a); n       --k; n       while (k < n and a) { n         if (a > C[k] - L[k]) { n           a -= C[k] - L[k]; n           L[k] = C[k]; n           unionSet(k, k + 1); n           k = findSet(k); n         } else { n           L[k] += a; n           a = 0; n         } n       } n     } else { n       printf( %d n , L[--k]); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b; n   cin >> n; n   for (int i = 0; i <= n; i++) cin >> a >> b; n   cout << 0.5 * (n - 4) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 200179; n int n, q, k, t; n int p[M], b[M]; n vector<int> pb[M]; n set<int> last; n int main() { n   scanf( %d , &n); n   for (int t = 0; t < n; t++) { n     scanf( %d%d , &p[t], &b[t]); n     pb[p[t]].push_back(t); n   } n   last.insert(-1); n   for (int p = 1; p <= n; p++) n     if (pb[p].size()) last.insert(*pb[p].rbegin()); n   for (scanf( %d , &q); q; q--) { n     scanf( %d , &k); n     vector<int> esc(k); n     for (int i = 0; i < k; i++) n       if (scanf( %d , &esc[i]), pb[esc[i]].size()) n         last.erase(*pb[esc[i]].rbegin()); n     pair<int, int> ans = {0, 0}; n     if (last.size() > 1) { n       auto iw = last.rbegin(); n       int win = p[*iw]; n       ans = {win, b[*upper_bound(pb[win].begin(), pb[win].end(), *++iw)]}; n     } n     cout << ans.first <<     << ans.second << endl; n     for (int i = 0; i < k; i++) n       if (pb[esc[i]].size()) last.insert(*pb[esc[i]].rbegin()); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long x[200001], y[200001], dp[200001], n; n bool s[200001]; n long long find_upper_bound(long long l, long long r, long long value) { n   long long mid, index = 1; n   while (l <= r) { n     mid = l + (r - l) / 2; n     if (x[mid] >= value) { n       index = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   return index; n } n int main() { n   int t; n   t = 1; n   while (t--) { n     dp[0] = 0; n     cin >> n; n     for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> s[i]; n     long long ans = (x[n] + 1) % 998244353, temp; n     for (int i = 1; i <= n; i++) { n       temp = find_upper_bound(1, i, y[i]); n       dp[i] = x[i] - y[i]; n       if (temp != i) n         dp[i] = (dp[i] + (dp[i - 1] - dp[temp - 1] + 998244353) % 998244353) % n                 998244353; n       if (s[i]) ans = (ans + dp[i]) % 998244353; n       dp[i] = (dp[i] + dp[i - 1]) % 998244353; n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long xa, xb, ya, yb, xc, yc, t; n long long cp(long long x1, long long x2, long long y1, long long y2) { n   return x1 * y2 - x2 * y1; n } n int main() { n   cin >> xa >> ya >> xb >> yb >> xc >> yc; n   t = cp(xc - xa, xb - xa, yc - ya, yb - ya); n   if (t == 0) { n     cout <<  TOWARDS  << endl; n   } n   if (t < 0) { n     cout <<  LEFT  << endl; n   } n   if (t > 0) { n     cout <<  RIGHT  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char c[2000007]; n set<int> s; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < 2000007; i++) { n     s.insert(i); n   } n   set<int>::iterator it; n   int maxy = 0; n   for (int i = 0; i < n; i++) { n     string l; n     cin >> l; n     int k; n     scanf( %d , &k); n     while (k--) { n       int x; n       scanf( %d , &x); n       while (1) { n         it = s.lower_bound(x); n         if (it != s.end() && (*it) <= l.length() + x - 1) { n           c[*it] = l[(*it) - x]; n           maxy = max(maxy, *it); n           s.erase(it); n         } else n           break; n       } n     } n   } n   c[maxy + 1] =   0 ; n   for (int i = 1; i <= maxy; i++) { n     if (s.find(i) != s.end()) c[i] =  a ; n   } n   printf( %s n , c + 1); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const int inf = 0x3f3f3f3f; n inline long long read() { n   register long long x = 0, f = 1; n   register char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   return x * f; n } n void write(long long x) { n   if (x < 0) x = -x, putchar( - ); n   if (x >= 10) write(x / 10); n   putchar(x % 10 +  0 ); n } n void writeln(long long x) { n   write(x); n   puts(  ); n } n const int maxn = 1e4 + 233; n struct node { n   int x, y, opt, id; n   bool operator<(const node &w) const { n     return x < w.x || (x == w.x && y < w.y); n   } n } a[maxn * 2], c; n int ans[maxn], n; n node operator-(node a, node b) { return (node){a.x - b.x, a.y - b.y, 0, 0}; } n int cross(node a, node b) { return a.x * b.y - a.y * b.x; } n bool cmp(node a, node b) { return cross(a - c, b - c) > 0; } n void work(int l, int r) { n   if (l > r) return; n   int p = min_element(a + l, a + r + 1) - a; n   swap(a[l], a[p]); n   c = a[l]; n   sort(a + l + 1, a + r + 1, cmp); n   int cnt1 = 0, cnt2 = 0, k = r; n   while (!(c.opt != a[k].opt && cnt1 == cnt2)) { n     if (c.opt == a[k].opt) n       cnt1++; n     else n       cnt2++; n     k--; n   } n   if (c.opt == 1) n     ans[a[k].id] = c.id; n   else n     ans[c.id] = a[k].id; n   work(l + 1, k - 1); n   work(k + 1, r); n } n int main() { n   n = read(); n   for (register int i = (0); i < int(2 * n); ++i) { n     a[i].x = read(); n     a[i].y = read(); n     a[i].opt = i < n ? 0 : 1; n     a[i].id = i < n ? i + 1 : i - n + 1; n   } n   work(0, 2 * n - 1); n   for (register int i = (1); i <= int(n); ++i) writeln(ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int m = 10000 * 100000 + 7; n int main() { n   string s; n   cin >> s; n   int n = s.length(); n   long long p = 0, q = 1; n   for (int i = n - 1; i > 0; --i) { n     if (s[i] ==  1 ) p = (p + q) % m; n     q = q * 2 % m; n   } n   if (s[0] ==  1 ) p = (p + q) % m; n   cout << p * q % m; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct $ { n   $() { n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr); n   } n } $; n const int N = 100002; n int n, m; n vector<int> a[N]; n vector<int> pri[N]; n vector<int> ans; n vector<tuple<int, int>> where[N]; n const int NPR = 20; n int primes[NPR] = { n     2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, 23, 25, 27, 29, 31, 32, 36, 37, n }; n int mod[NPR], cnt[NPR]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     int k; n     cin >> k; n     a[i].resize(k); n     for (int j = 0; j < k; ++j) { n       cin >> a[i][j]; n       where[a[i][j]].emplace_back(i, j); n     } n     for (int j = 0; j < NPR; ++j) n       if (k % primes[j] == 0) pri[i].emplace_back(j); n   } n   ans.resize(m + 1); n   for (int i = 0; i < n; ++i) { n     const auto &v = a[i]; n     int ki = int(v.size()); n     for (int j = 0; j < ki; ++j) { n       int x = v[j]; n       if (ans[x]) continue; n       ans[x] = 1; n       auto wit = begin(where[x]); n       for (int start = -2, stop = -2; wit != end(where[x]); ++wit) { n         int row, off; n         tie(row, off) = *wit; n         if (row != stop) { n           start = stop = row; n           fill(begin(cnt), end(cnt), 0); n         } n         for (int prq : pri[stop]) { n           if (mod[prq] == off % primes[prq]) { n             ++cnt[prq]; n           } else { n             for (; cnt[prq]; ++start) { n               for (int prp : pri[start]) --cnt[prp]; n             } n             cnt[prq] = 1; n             mod[prq] = off % primes[prq]; n           } n         } n         ++stop; n         ans[x] = max(ans[x], stop - start); n       } n     } n   } n   for (int i = 1; i <= m; ++i) { n     cout << ans[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n int nrg, nrv; n string s; n bool gg(int pos) { n   if (pos < 2) return 0; n   return ((s[pos] >=  0  && s[pos] <=  9 ) && n           (s[pos - 1] >=  0  && s[pos - 1] <=  9 ) && (s[pos - 2] ==  . )); n } n deque<int> dg; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> s; n   for (int i = 0; i < s.size(); ++i) { n     if (s[i] >=  a  && s[i] <=  z ) continue; n     int l = i; n     while (i < s.size() && !(s[i] >=  a  && s[i] <=  z )) ++i; n     --i; n     int r = i; n     if (gg(r)) { n       nrv = nrv + (s[r] -  0 ) + 10 * (s[r - 1] -  0 ); n       r -= 3; n     } n     int ex = 1; n     while (r >= 0 && !(s[r] >=  a  && s[r] <=  z )) { n       if (s[r] !=  . ) nrg = nrg + ex * (s[r] -  0 ), ex = ex * 10; n       --r; n     } n   } n   nrg += nrv / 100; n   nrv %= 100; n   do { n     dg.push_front(nrg % 10); n     nrg /= 10; n   } while (nrg); n   for (int i = 0; i < dg.size(); ++i) { n     if (i && (dg.size() - i) % 3 == 0) cout <<  . ; n     cout << dg[i]; n   } n   if (nrv) { n     cout <<  . ; n     if (nrv < 10) cout <<  0 ; n     cout << nrv; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   char c; n   long long num, f = 1; n   while (c = (char)getchar(), !isdigit(c)) n     if (c ==  - ) f = -1; n   num = (long long)(c -  0 ); n   while (c = (char)getchar(), isdigit(c)) num = num * 10 + (long long)(c -  0 ); n   return num * f; n } n long long n, m; n vector<long long> a; n long long greaterCount(long long m) { n   vector<long long> s(2 * n + 1); n   long long sum = n, result = 0, add = 0; n   s[sum] = 1; n   for (long long i = 0; i < n; i++) { n     if (a[i] < m) n       sum--, add -= s[sum]; n     else n       add += s[sum], sum++; n     result += add; n     s[sum]++; n   } n   return result; n } n void work() { n   n = read(); n   m = read(); n   a = vector<long long>(n); n   for (long long i = 0; i < n; i++) a[i] = read(); n   cout << greaterCount(m) - greaterCount(m + 1) << endl; n   return; n } n signed main() { n   long long T = 1; n   for (long long Case = 1; Case <= T; Case++) { n     work(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, x, y, z, m, n, k, l, r, f, mi = 1e9; n int a[200]; n bool pr(int n) { n   for (int i = 2; i * i <= n; i++) n     if (n % i == 0) return true; n   return false; n } n int main() { n   scanf( %d , &n); n   a[1] = a[2] = a[3] = -1; n   a[4] = 1; n   for (int i = 5; i < 100; i++) { n     int t = -1; n     if (pr(i)) t = 1; n     for (int j = 4; j <= i / 2; j++) n       if (pr(j) && pr(i - j)) t = max(t, a[j] + a[i - j]); n     a[i] = t; n   } n   while (n--) { n     scanf( %d , &m); n     int ans; n     if (m < 20) n       ans = a[m]; n     else { n       ans = m / 4; n       m = m % 4; n       if (m == 1) ans--; n       if (m == 3) ans--; n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long dx[] = {-2, -1, 1, 2, -2, 1, -1, 2}; n const long long dy[] = {-1, -2, 2, 1, 1, -2, 2, -1}; n const long long Mod = 1e9 + 7; n const long long N = 5e5; n const long long inf = 1e9 + 1; n const long long N_N = 1e2; n long long n, m, x, y, cnt; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) { n     cin >> x >> y; n     cnt = max(cnt, y + x); n   } n   cout << max(cnt, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[50]; n int main() { n   int f = 2, ct[110]; n   ct[0] = 0; n   ct[1] = 0; n   ct[2] = 1; n   for (int i = 3; i <= 101; i++) { n     ct[i] = ct[i - 1] + f; n     f++; n   } n   string s; n   int n, m; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s; n     m = s[0] - 96; n     a[m]++; n   } n   int sum = 0, dis, l; n   for (int i = 1; i <= 26; i++) { n     if (a[i] != 0) { n       dis = a[i] / 2; n       l = a[i] - dis; n       sum += (ct[l] + ct[dis]); n     } n   } n   cout << sum << endl; n   return 0; n } n


#include <algorithm> n #include <cmath> n #include <cstring> n #include <iostream> n #include <limits> n #include <queue> n #include <set> n #include <sstream> n #include <stack> n #include <unordered_map> n #include <utility> n #include <vector> n  n using namespace std; n  n typedef long long ll; n typedef vector<int> vi; n typedef vector<int>::iterator vit; n typedef vector<vector<int>> vii; n  n #define REP(i, a, b) for (int i = a; i < b; i++) n #define VECITR(itr, v) for (vit itr = v.begin(); itr != v.end(); itr++) n #define PB push_back n #define MP make_pair n #define F first n #define S second n #define sq(a) ((a) * (a)) n  n int gcd(int a, int b) n { n     if (b == 0) n         return a; n     return gcd(b, a % b); n } n  n string next_valid_bracket_sequence(const string &x) n { n     string s = x; n     int n = s.size(); n     int d = 0; n     for (int i = n - 1; i >= 1; i--) n     { n         if (s[i] ==  ) ) n             d++; n         else n         { n             d--; n             if (d > 0) n             { n                 s[i] =  ) ; n                 s = s.substr(0, i + 1); n                 REP(j, 0, (n - i - d) / 2) { s +=  ( ; } n                 REP(j, 0, (n - i + d - 2) / 2) { s +=  ) ; } n                 if (s.size() < n) return s +  ) ; n                 return s; n             } n         } n     } n  n     return   ; n } n  n ll modulo(ll x, ll m)  n { n     int r = x % m; n     return r < 0 ? r + m : r; n } n  n  n int dfs(vector<vector<bool>> &change, vector<string> &arr, int i, int j, int k) n { n     return 0; n } n  n  n void run() n { n     ll n; cin >> n; n     ll copy = n; n  n     while(n % 4 == 0 && n > 4)  n         n /= 4; n  n     if (n == 2 || n == 4) { cout <<  YES n ; return; } n  n     n = copy; n  n     if (n % 2 == 0 && (n / 2) == sq(ll(sqrt(double(n / 2))))) { cout <<  YES n ; return; } n     if (n % 4 == 0 && (n / 4) == sq(ll(sqrt(double(n / 4))))) { cout <<  YES n ; return; } n     else cout <<  NO n ; n } n  n int main() n { n     cin.tie(NULL); n     ios_base::sync_with_stdio(false); n  n     int t = 1; n     cin >> t; n  n     REP(i, 0, t) { run(); } n }


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   static int r, sign; n   static char c; n   r = 0, c = getchar(), sign = 1; n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) sign = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) r = r * 10 + (c -  0 ), c = getchar(); n   return r * sign; n } n template <typename T> n inline void print(T *a, int n) { n   for (int i = 1; i < n; ++i) cout << a[i] <<    ; n   cout << a[n] << endl; n } n const int mod = (int)1e9 + 7; n int n, x = 0, y = 0; n char m[4][10010 + 1]; n int f[2][64]; n inline int get(int x, int p) { return (x >> (p - 1) * 2) & 3; } n inline void add(int &x, int y) { n   x += y; n   if (x >= mod) x -= mod; n } n int solve() { n   memset(f, 0, sizeof f); n   f[0][0] = 1; n   for (int i = 1; i <= n; ++i) { n     memset(f[i & 1], 0, sizeof f[i & 1]); n     for (int j = 0; j < 64; ++j) { n       if (!f[i & 1 ^ 1][j]) continue; n       for (int k = 0; k < 64; ++k) { n         bool ok = true; n         for (int x = 1; ok && x <= 3; ++x) { n           if (get(j, x) == 1 && get(k, x) != 2) ok = false; n           if (get(k, x) == 2 && get(j, x) != 1) ok = false; n           if (m[x][i] !=  X  && get(k, x) == 0) ok = false; n           if (m[x][i] ==  X  && get(k, x) != 0) ok = false; n         } n         if (get(k, 1) == 3 && get(k, 2) != 3) ok = false; n         if (get(k, 2) != 3 && get(k, 3) == 3) ok = false; n         if (get(k, 2) == 3 && get(k, 1) != 3 && get(k, 3) != 3) ok = false; n         if (get(k, 1) == 3 && get(k, 2) == 3 && get(k, 3) == 3) ok = false; n         if (!ok) continue; n         add(f[i & 1][k], f[i & 1 ^ 1][j]); n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < 64; ++i) { n     bool ok = true; n     for (int x = 1; ok && x <= 3; ++x) n       if (get(i, x) == 1) ok = false; n     if (!ok) continue; n     add(ans, f[n & 1][i]); n   } n   return ans; n } n const int dir[8][2] = {{0, 1},   {1, 0},  {-1, 0}, {0, -1}, n                        {-1, -1}, {-1, 1}, {1, -1}, {1, 1}}; n int main(int argc, char *argv[]) { n   scanf( %d , &n); n   scanf( %s n%s n%s n , m[1] + 1, m[2] + 1, m[3] + 1); n   for (int i = 1; !x && i <= n; ++i) n     for (int j = 1; j <= 3; ++j) n       if (m[j][i] ==  O ) x = j, y = i; n   m[x][y] =  X ; n   int ans = solve(); n   if (x == 2 && y > 1 && y < n) { n     bool need = true; n     for (int i = 0; i < 8; ++i) { n       int nx = x + dir[i][0], ny = y + dir[i][1]; n       if (m[nx][ny] ==  X ) need = false; n     } n     if (need) { n       for (int i = 0; i < 8; ++i) { n         int nx = x + dir[i][0], ny = y + dir[i][1]; n         m[nx][ny] =  X ; n       } n       ans -= 2 * solve() % mod; n       if (ans < 0) ans += mod; n     } n   } n   printf( %d n , ans); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sim(vector<int> s, int p, int x) { n   s.insert(s.begin() + p, x); n   int l = p, r = p; n   int acum = 0; n   int ans = 0; n   for (;;) { n     while (l >= 0 && s[l] == x) l--; n     while (r <= (int)s.size() - 1 && s[r] == x) r++; n     int dis = r - l - 1; n     if (dis - acum >= 3) { n       ans += dis - acum; n       acum += dis - acum; n     } else n       break; n     if (l == -1 || r == (int)s.size()) break; n     if (s[l] == s[r]) x = s[l]; n   } n   return ans - 1; n } n int main() { n   int n, k, x; n   cin >> n >> k >> x; n   vector<int> ns(n); n   for (int i = 0; i < n; i++) cin >> ns[i]; n   int ans = 0; n   for (int i = 0; i <= n; i++) { n     ans = max(ans, sim(ns, i, x)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str; n   getline(cin, str); n   char c = 0; n   int n = str.length(); n   for (int i = n - 1; i >= 0; i--) { n     if ((str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122)) { n       c = str[i]; n       break; n     } n   } n   if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  || n       c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y ) n     cout <<  YES ; n   else n     cout <<  NO ; 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.setf(ios::fixed); n   cout.precision(20); n   int m; n   cin >> m; n   string s; n   cin >> s; n   int n = s.size(); n   vector<int> cnt(26); n   vector<int> have(n); n   for (int c = 0; c < 26; ++c) { n     for (int i = 0; i < n; ++i) { n       if (s[i] -  a  == c) { n         have[i] = 1; n         ++cnt[c]; n       } n     } n     bool fl = 1; n     int lst = -1; n     for (int i = 0; i < n; ++i) { n       if (have[i]) { n         fl &= (i - lst - 1 < m); n         lst = i; n       } n     } n     fl &= (n - lst - 1 < m); n     if (!fl) { n       continue; n     } else { n       int lst = -1; n       int nxt = 0; n       for (int i = 0; i < n; ++i) { n         nxt = max(nxt, i + 1); n         while (nxt < n && !have[nxt]) ++nxt; n         if (have[i] && s[i] -  a  == c && nxt - lst - 1 < m) { n           --cnt[c]; n         } else if (have[i]) n           lst = i; n       } n       for (int i = 0; i < 26; ++i) { n         for (int j = 0; j < cnt[i]; ++j) { n           cout << char( a  + i); n         } n       } n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   if (x < 0) n     return -x; n   else n     return x; n } n int main() { n   double A, B, C, D; n   scanf( %lf%lf , &A, &B); n   scanf( %lf%lf , &C, &D); n   if (A * D > B * C) { n     swap(A, B); n     swap(D, C); n   } n   double l = 0, r = 1e9; n   for (int T = 0; T < 200; ++T) { n     double mid = (l + r) / 2.0; n     bool flag = false; n     double a = A - mid; n     for (int i = 0; i < 2; ++i) { n       double b = B - mid; n       for (int j = 0; j < 2; ++j) { n         double c = C - mid; n         for (int u = 0; u < 2; ++u) { n           double d = D - mid; n           for (int v = 0; v < 2; ++v) { n             if (a * d > b * c) { n               flag = true; n             } n             d += mid; n             d += mid; n           } n           c += mid; n           c += mid; n         } n         b += mid; n         b += mid; n       } n       a += mid; n       a += mid; n     } n     if (flag) n       r = mid; n     else n       l = mid; n   } n   printf( %.12f n , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n const int maxn = 300000 + 500; n const int maxk = 5005; n const int INF = 2e9 + 100; n int a[maxn]; n int d[maxk][maxk]; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   int large = n % k; n   int small = k - large; n   int seg = n / k; n   sort(a + 1, a + n + 1); n   for (int i = 0; i <= k; i++) n     for (int j = 0; j <= k; j++) d[i][j] = INF; n   d[0][0] = 0; n   for (int i = 0; i <= large; i++) { n     for (int j = 0; j <= small; j++) { n       int nxt = i * (seg + 1) + j * seg + 1; n       if (i < large) { n         int add = a[nxt + seg] - a[nxt]; n         d[i + 1][j] = min(d[i + 1][j], d[i][j] + add); n       } n       if (j < small) { n         int add = a[nxt + seg - 1] - a[nxt]; n         d[i][j + 1] = min(d[i][j + 1], d[i][j] + add); n       } n     } n   } n   cout << d[large][small] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n int n, k, x, arr[N]; n long long tree[2][17000]; n void build(int pos, int l, int r, int dim) { n   if (l == r) { n     if (l <= k) n       tree[dim][pos] = arr[l]; n     else n       tree[dim][pos] = -1e18; n     return; n   } n   int mid = (l + r) >> 1; n   build(pos << 1, l, mid, dim); n   build(pos << 1 | 1, mid + 1, r, dim); n   tree[dim][pos] = max(tree[dim][pos << 1], tree[dim][pos << 1 | 1]); n } n void update(int pos, int l, int r, int x, long long v, int dim) { n   if (l == r) { n     tree[dim][pos] = v; n     return; n   } n   int mid = (l + r) >> 1; n   if (mid >= x) n     update(pos << 1, l, mid, x, v, dim); n   else n     update(pos << 1 | 1, mid + 1, r, x, v, dim); n   tree[dim][pos] = max(tree[dim][pos << 1], tree[dim][pos << 1 | 1]); n } n long long get(int pos, int l, int r, int qLow, int qHigh, int dim) { n   if (l >= qLow && r <= qHigh) return tree[dim][pos]; n   int mid = (l + r) >> 1; n   long long a = -1, b = -1; n   if (mid >= qLow) a = get(pos << 1, l, mid, qLow, qHigh, dim); n   if (mid + 1 <= qHigh) b = get(pos << 1 | 1, mid + 1, r, qLow, qHigh, dim); n   return max(a, b); n } n int main() { n   scanf( %d%d%d , &n, &k, &x); n   for (int i = 1; i <= n; i++) scanf( %d , &arr[i]); n   for (int i = 1; i <= k; i++) tree[0][i] = arr[i]; n   for (int i = k + 1; i <= n; i++) tree[0][i] = -1e18; n   int p = 1; n   for (int z = 2; z <= x; z++) { n     deque<int> q; n     for (int i = max(0, z - k); i < z; i++) { n       while (!q.empty() && tree[!p][i] >= tree[!p][q.back()]) q.pop_back(); n       q.push_back(i); n     } n     for (int i = z; i <= n; i++) { n       while (!q.empty() && q.front() < i - k) q.pop_front(); n       long long zorbe7 = tree[!p][q.front()]; n       while (!q.empty() && tree[!p][i] >= tree[!p][q.back()]) q.pop_back(); n       q.push_back(i); n       long long ans = arr[i] + (zorbe7 < 0 ? -1e18 : zorbe7); n       tree[p][i] = ans; n     } n     p = !p; n   } n   long long zorbe7 = -1e18; n   for (int i = n - k + 1; i <= n; i++) zorbe7 = max(zorbe7, tree[!p][i]); n   printf( %lld , zorbe7 > 0 ? zorbe7 : -1); n   return 0; n } n


#include <bits/stdc++.h> n char a[1001][1001]; n int n, m; n int findG(int r) { n   int i; n   for (i = 0; i < m; i = i + 1) n     if (a[r][i] ==  G ) return i; n } n int findS(int r) { n   int i; n   for (i = 0; i < m; i = i + 1) n     if (a[r][i] ==  S ) return i; n } n int main() { n   scanf( %d%d , &n, &m); n   int N = n; n   while (N--) { n     scanf( %s , &a[N]); n   } n   int f[1001] = {0}; n   for (int l = 0; l < n; l++) { n     int dif = findS(l) - findG(l); n     if (dif < 0) { n       printf( -1 ); n       return 0; n     } else n       f[dif] = 1; n   } n   int s = 0; n   for (int d = 0; d < m; d++) s = s + f[d]; n   printf( %d , s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dpsm[200001][26] = {0}; n double dpfm[200001][26] = {0}; n double ans = 0; n int main() { n   int n; n   cin >> n; n   string s, f; n   cin >> s >> f; n   dpsm[0][s[0] -  A ] = 1; n   dpfm[0][f[0] -  A ] = 1; n   for (int i = 0; i < 26; ++i) { n     char c =  A  + i; n     for (int j = 1; j < s.size(); ++j) { n       if (s[j] == c) { n         dpsm[j][i] = (dpsm[j - 1][i] + j + 1); n       } else { n         dpsm[j][i] = dpsm[j - 1][i]; n       } n       if (f[j] == c) { n         dpfm[j][i] = dpfm[j - 1][i] + j + 1; n       } else { n         dpfm[j][i] = dpfm[j - 1][i]; n       } n     } n   } n   double r = (1.0 * (n) * (n + 1) * (2 * n + 1)) / 6.0; n   for (int j = 0; j < s.size(); ++j) { n     ans += 1.0 * (s.size() - j) * dpfm[j][s[j] -  A ] / r; n   } n   for (int j = 0; j < f.size(); ++j) { n     if (f[j] == s[j]) { n       ans += 1.0 * (s.size() - j) * (dpsm[j][f[j] -  A ] - j - 1) / r; n     } else { n       ans += 1.0 * (s.size() - j) * dpsm[j][f[j] -  A ] / r; n     } n   } n   printf( %.9f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a, b; n int rs, p; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> a >> b; n   if (a.size() != b.size()) return cout <<  NO , 0; n   for (int i = 0; i < a.size(); i++) n     if (a[i] != b[i]) rs++, p = i; n   if (rs != 2) return cout <<  NO , 0; n   for (int i = 0; i < a.size(); i++) n     if (a[i] != b[i] && a[i] == b[p] && a[p] == b[i]) n       return cout <<  YES , 0; n     else if (a[i] != b[i]) n       return cout <<  NO , 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(const pair<int, int> &p1, const pair<int, int> &p2) { n   if (p1.first == p2.first) { n     return p1.second < p2.second; n   } n   return p1.first > p2.first; n } n int main() { n   int n, m, e, x, y; n   cin >> n >> m; n   std::vector<pair<int, int> > E; n   for (int i = 0; i < n; ++i) { n     cin >> e; n     E.push_back(make_pair(e, i)); n   } n   sort(E.begin(), E.end(), cmp); n   int inv[n]; n   for (int i = 0; i < n; ++i) { n     inv[E[i].second] = i; n   } n   bool isThere[n]; n   for (int i = 0; i < n; ++i) isThere[i] = false; n   std::vector<vector<int> > adj(n); n   for (int i = 0; i < m; ++i) { n     cin >> x >> y; n     adj[x - 1].push_back(y - 1); n     adj[y - 1].push_back(x - 1); n   } n   long long int sum = 0; n   for (int i = 0; i < n; ++i) { n     int ind = E[i].second; n     for (int j = 0; j < adj[ind].size(); ++j) { n       if (isThere[adj[ind][j]]) continue; n       sum += E[inv[adj[ind][j]]].first; n     } n     isThere[ind] = true; n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool Prime(int a) { n   if (a == 1) return true; n   for (int i = 2; i * i <= a; i++) n     if (a % i == 0) return false; n   return true; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     int count = 0; n     for (int i = 0; i < s.length(); i++) n       if (s[i] ==  N ) count++; n     count == 1 ? cout <<  NO  : cout <<  YES ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int INF = 1234567890; n int t, T; n int fa[100000], opp[100000]; n int l[100000], r[100000]; n int col[100000]; n set<pair<int, int> > rp; n set<pair<int, int> > lp; n int find(int a) { n   if (a == -1) return -1; n   if (fa[a] == -1) return a; n   return fa[a] = find(fa[a]); n } n bool check(int a, int b) { n   if (a == -1 || b == -1) return true; n   if (a == b) return false; n   return r[a] + r[b] >= t && l[a] + l[b] <= T; n } n bool merge(int a, int b) { n   if (a == b) return true; n   if (a == -1 || b == -1) return true; n   fa[b] = a; n   lp.erase(make_pair(l[b], b)); n   rp.erase(make_pair(r[b], b)); n   if (l[b] > l[a]) { n     if (lp.find(make_pair(l[a], a)) != lp.end()) { n       lp.erase(make_pair(l[a], a)); n       lp.insert(make_pair(l[b], a)); n     } n     l[a] = l[b]; n   } n   if (r[b] < r[a]) { n     if (rp.find(make_pair(r[a], a)) != rp.end()) { n       rp.erase(make_pair(r[a], a)); n       rp.insert(make_pair(r[b], a)); n     } n     r[a] = r[b]; n   } n   return l[a] <= r[a]; n } n bool diff(int a, int b) { n   a = find(a); n   b = find(b); n   int aa = find(opp[a]); n   int bb = find(opp[b]); n   if (a == b) return false; n   if (!check(a, b)) return false; n   if (!check(aa, bb)) return false; n   if (opp[a] == -1) opp[a] = b; n   if (opp[b] == -1) opp[b] = a; n   return merge(aa, b) && merge(a, bb); n } n bool same(int a, int b) { n   a = find(a); n   b = find(b); n   int aa = find(opp[a]); n   int bb = find(opp[b]); n   if (!check(a, bb)) return false; n   if (!check(aa, b)) return false; n   if (opp[a] == -1) opp[a] = opp[b]; n   if (opp[b] == -1) opp[b] = opp[a]; n   return merge(a, b) && merge(aa, bb); n } n int get(int a) { n   if (col[a] != -1) return col[a]; n   if (fa[a] == -1) { n     col[a] = 0; n     if (opp[a] != -1) col[find(opp[a])] = 1; n     return 0; n   } n   return col[a] = get(find(a)); n } n int main() { n   while (scanf( %d%d , &t, &T) == 2) { n     rp.clear(); n     lp.clear(); n     int n, m; n     scanf( %d%d , &n, &m); n     bool f = true; n     memset(fa, -1, sizeof(fa)); n     memset(opp, -1, sizeof(opp)); n     for (int i = 0; i < n; i++) { n       scanf( %d%d , l + i, r + i); n       rp.insert(make_pair(r[i], i)); n       lp.insert(make_pair(l[i], i)); n       if (l[i] > T) f = false; n     } n     while (m--) { n       int a, b; n       scanf( %d%d , &a, &b); n       a--; n       b--; n       a = find(a); n       b = find(b); n       if (!diff(a, b)) f = false; n     } n     if (n == 1) { n       if (l[0] > T || r[0] < t) n         printf( IMPOSSIBLE n ); n       else n         printf( POSSIBLE n%d 0 n1 n , max(l[0], t)); n       continue; n     } n     for (int i = 0; i < n && f; i++) { n       if (find(i) != i) continue; n       rp.erase(rp.find(make_pair(r[i], i))); n       lp.erase(lp.find(make_pair(l[i], i))); n       while (f && !lp.empty()) { n         set<pair<int, int> >::iterator itr = lp.end(); n         itr--; n         int b = find(itr->second); n         if (b == find(opp[i])) { n           b = itr->second; n           rp.erase(make_pair(r[b], b)); n           lp.erase(make_pair(l[b], b)); n           continue; n         } n         if (r[i] < l[b]) n           f = diff(i, b); n         else n           break; n       } n       while (f && !lp.empty()) { n         set<pair<int, int> >::iterator itr = lp.end(); n         itr--; n         int b = find(itr->second); n         if (b == find(opp[i])) { n           b = itr->second; n           rp.erase(make_pair(r[b], b)); n           lp.erase(make_pair(l[b], b)); n           continue; n         } n         if (l[i] + l[b] > T) n           f = same(i, b); n         else n           break; n       } n       while (f && !lp.empty()) { n         set<pair<int, int> >::iterator itr = rp.begin(); n         int b = find(itr->second); n         if (b == find(opp[i])) { n           b = itr->second; n           rp.erase(make_pair(r[b], b)); n           lp.erase(make_pair(l[b], b)); n           continue; n         } n         if (r[i] + r[b] < t) n           f = same(i, b); n         else n           break; n       } n       if (i == find(i)) { n         rp.insert(make_pair(r[i], i)); n         lp.insert(make_pair(l[i], i)); n       } n       if (opp[i] != -1) { n         int j = find(opp[i]); n         rp.insert(make_pair(r[j], j)); n         lp.insert(make_pair(l[j], j)); n       } n     } n     if (!f) n       printf( IMPOSSIBLE n ); n     else { n       printf( POSSIBLE n ); n       memset(col, -1, sizeof(col)); n       int l0 = 0, r0 = T, l1 = 0, r1 = T; n       for (int i = 0; i < n; i++) { n         if (get(i)) { n           l1 = max(l1, l[i]); n           r1 = min(r1, r[i]); n         } else { n           l0 = max(l0, l[i]); n           r0 = min(r0, r[i]); n         } n       } n       int L = l0, R = l1; n       int ndd = t - l0 - l1; n       if (ndd > 0) { n         if (ndd + L <= r0) { n           L += ndd; n         } else { n           L = r0; n           ndd -= r0 - l0; n           R += ndd; n         } n       } n       printf( %d %d n , L, R); n       for (int i = 0; i < n; i++) printf( %d , col[i] + 1); n       printf(  n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXL = 40000; n pair<int, int> p[MAXL]; n int Init() { n   for (int i = 0; i * i < MAXL; i++) { n     for (int j = i; j * j + i * i < MAXL; j++) { n       int now = i * i + j * j; n       p[now].first = i; n       p[now].second = j; n     } n   } n   return 0; n } n inline bool cmp(pair<int, int> a, pair<int, int> b) { n   return a.first * a.first + a.second * a.second > n          b.first * b.first + b.second * b.second; n } n inline bool cmp2(pair<int, int> a, pair<int, int> b) { n   return atan2(a.second, a.first) < atan2(b.second, b.first) - (1e-8); n } n int L(int a, int b) { return a * a + b * b; } n int n; n int Solve() { n   vector<pair<int, int> > e; n   int sum = 0; n   scanf( %d , &n); n   for (int i = 0; i < MAXL && e.size() <= n; i++) { n     if (p[i].first == 0 && p[i].second == 0) continue; n     sum ^= p[i].first ^ p[i].second; n     e.push_back(p[i]); n   } n   reverse(e.begin(), e.end()); n   for (vector<pair<int, int> >::iterator it = e.begin(); it != e.end(); it++) { n     if (((sum ^ it->first ^ it->second) & 1) == 0) { n       e.erase(it); n       break; n     } n   } n   sort(e.begin(), e.end(), cmp); n   int ix = 0, iy = 0; n   for (vector<pair<int, int> >::iterator it = e.begin(); it != e.end(); it++) { n     int fx = 1, fy = 1; n     int xx = it->first, yy = it->second; n     if (ix > 0) fx = -1; n     if (iy > 0) fy = -1; n     if (L(fx * xx + ix, fy * yy + iy) < L(fx * yy + ix, fy * xx + iy)) n       *it = make_pair(fx * xx, fy * yy); n     else n       *it = make_pair(fx * yy, fy * xx); n     ix = it->first + ix; n     iy = it->second + iy; n   } n   sort(e.begin(), e.end(), cmp2); n   puts( YES ); n   for (vector<pair<int, int> >::iterator it = e.begin(); it != e.end(); it++) { n     printf( %d %d n , ix, iy); n     ix += it->first; n     iy += it->second; n   } n   return 0; n } n int main() { n   Init(); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:134217728 ) n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : -x; n } n int n; n int m; n int dx[4] = {0, 1, 0, -1}; n int dy[4] = {1, 0, -1, 0}; n string s[5001]; n vector<int> t[5001]; n string ss[5001]; n vector<pair<int, int> > root[4][5001]; n vector<pair<int, int> > next239[4][5001]; n int good(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } n int ans[10000]; n pair<int, int> get_root(int t, pair<int, int> o) { n   if (root[t][o.first][o.second] == o) return o; n   return root[t][o.first][o.second] = get_root(t, root[t][o.first][o.second]); n } n void merge(int t, pair<int, int> a, pair<int, int> b) { n   a = get_root(t, a); n   root[t][a.first][a.second] = get_root(t, b); n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < (n); i++) cin >> s[i]; n   for (int i = 0; i < (n); i++) n     for (int j = 0; j < (m); j++) n       if (s[i][j] !=  . ) { n         int c = s[i][j]; n         if (c ==  U ) t[i].push_back(3); n         if (c ==  D ) t[i].push_back(1); n         if (c ==  L ) t[i].push_back(2); n         if (c ==  R ) t[i].push_back(0); n       } else n         t[i].push_back(-1); n   for (int o = 0; o < (4); o++) { n     for (int i = 0; i < (n); i++) n       for (int j = 0; j < (m); j++) { n         int cx = i + dx[o]; n         int cy = j + dy[o]; n         while (good(cx, cy) && s[cx][cy] ==  . ) { n           cx += dx[o]; n           cy += dy[o]; n         } n         if (good(cx, cy)) n           next239[o][i].push_back(make_pair(cx, cy)); n         else n           next239[o][i].push_back(make_pair(n, m)); n       } n   } n   for (int o = 0; o < (4); o++) n     for (int i = 0; i < (n + 1); i++) root[o][i].resize(m + 1); n   for (int x = 0; x < (n); x++) n     for (int y = 0; y < (m); y++) n       if (s[x][y] !=  . ) { n         for (int i = 0; i < (n + 1); i++) n           for (int j = 0; j < (m + 1); j++) n             for (int o = 0; o < (4); o++) root[o][i][j] = make_pair(i, j); n         int cx = x, cy = y; n         int col = 1; n         while (good(cx, cy)) { n           pair<int, int> tmp = get_root(t[cx][cy], next239[t[cx][cy]][cx][cy]); n           if (!good(tmp.first, tmp.second)) break; n           for (int o = 0; o < (4); o++) { n             merge(o, make_pair(cx, cy), next239[o][cx][cy]); n           } n           cx = tmp.first; n           cy = tmp.second; n           col++; n         } n         ans[col]++; n       } n   int o = n * m; n   while (ans[o] == 0) o--; n   cout << o <<     << ans[o] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, m, ans = 0; n   cin >> n; n   long long boy[n]; n   for (long long i = 0; i < n; i++) cin >> boy[i]; n   cin >> m; n   long long girl[m]; n   for (long long i = 0; i < m; i++) cin >> girl[i]; n   sort(boy, boy + n); n   sort(girl, girl + m); n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       if (abs(boy[i] - girl[j]) <= 1) { n         ans++; n         girl[j] = 200; n         break; n       } n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); 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 inf = 1000 * 1000 * 1000 + 7; n const int mod = 1000 * 1000 * 1000 + 9; n const int num = 1000 * 1000 + 7; n const int N = 1000 + 7; n const double PI = 3.1415926535897932384626433832795; n int ux_x[5] = {0, 0, 1, -1}; n int ux_y[5] = {1, -1, 0, 0}; n int n, t, m, k; n long long a[num]; n bool used[num]; n long long ans = 0, ans1 = 0; n void solve() { n   string s; n   cin >> s; n   vector<int> v1, v2; n   for (int i = 0; i < s.length(); ++i) { n     int e = s[i] -  0 ; n     ans += e; n     if (e % 3 == 1) { n       v1.push_back(i); n     } n     if (e % 3 == 2) { n       v2.push_back(i); n     } n   } n   reverse(v1.begin(), v1.end()); n   reverse(v2.begin(), v2.end()); n   if (ans % 3 == 0) { n     cout << s << endl; n     exit(0); n   } n   if (s.length() == 1) { n     cout << -1; n     exit(0); n   } n   if (ans % 3 == 1) { n     if (v1.size() == 0) { n       if (v2.size() < 1 || s.length() == 2) { n         cout << -1; n         exit(0); n       } n       s.erase(s.begin() + v2[0]); n       s.erase(s.begin() + v2[1]); n       if (s.length() == 1) { n         cout << s << endl; n         exit(0); n       } n       int e = 0; n       while (e < s.length() && s[e] ==  0 ) e++; n       if (e == s.length()) { n         cout << 0; n         exit(0); n       } n       for (int i = e; i < s.length(); ++i) { n         cout << s[i]; n       } n       exit(0); n     } else { n       if (v1[0] == 0 && s.length() > 2 && s[1] ==  0  && s[2] ==  0  && n           v2.size() > 1) { n         s.erase(s.begin() + v2[0]); n         s.erase(s.begin() + v2[1]); n         if (s.length() == 1) { n           cout << s << endl; n           exit(0); n         } n         int e = 0; n         while (e < s.length() && s[e] ==  0 ) e++; n         if (e == s.length()) { n           cout << 0; n           exit(0); n         } n         for (int i = e; i < s.length(); ++i) { n           cout << s[i]; n         } n         exit(0); n       } n       s.erase(s.begin() + v1[0]); n       if (s.length() == 1) { n         cout << s << endl; n         exit(0); n       } n       int e = 0; n       while (e < s.length() && s[e] ==  0 ) e++; n       if (e == s.length()) { n         cout << 0; n         exit(0); n       } n       for (int i = e; i < s.length(); ++i) { n         cout << s[i]; n       } n       exit(0); n     } n   } else { n     if (v2.size() == 0) { n       if (v1.size() < 1 || s.length() == 2) { n         cout << -1; n         exit(0); n       } n       s.erase(s.begin() + v1[0]); n       s.erase(s.begin() + v1[1]); n       if (s.length() == 1) { n         cout << s << endl; n         exit(0); n       } n       int e = 0; n       while (e < s.length() && s[e] ==  0 ) e++; n       if (e == s.length()) { n         cout << 0; n         exit(0); n       } n       for (int i = e; i < s.length(); ++i) { n         cout << s[i]; n       } n       exit(0); n     } else { n       if (v2[0] == 0 && s.length() > 2 && s[1] ==  0  && s[2] ==  0  && n           v1.size() > 1) { n         s.erase(s.begin() + v1[0]); n         s.erase(s.begin() + v1[1]); n         if (s.length() == 1) { n           cout << s << endl; n           exit(0); n         } n         int e = 0; n         while (e < s.length() && s[e] ==  0 ) e++; n         if (e == s.length()) { n           cout << 0; n           exit(0); n         } n         for (int i = e; i < s.length(); ++i) { n           cout << s[i]; n         } n         exit(0); n       } n       s.erase(s.begin() + v2[0]); n       int e = 0; n       if (s.length() == 1) { n         cout << s << endl; n         exit(0); n       } n       while (e < s.length() && s[e] ==  0 ) e++; n       if (e == s.length()) { n         cout << 0; n         exit(0); n       } n       for (int i = e; i < s.length(); ++i) { n         cout << s[i]; n       } n       exit(0); n     } n   } n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int getidx(const vector<int>& ar, int x) { n   return lower_bound(ar.begin(), ar.end(), x) - ar.begin(); n } n inline long long GCD(long long a, long long b) { n   long long n; n   if (a < b) swap(a, b); n   while (b != 0) { n     n = a % b; n     a = b; n     b = n; n   } n   return a; n } n inline long long LCM(long long a, long long b) { n   if (a == 0 || b == 0) return GCD(a, b); n   return a / GCD(a, b) * b; n } n inline long long CEIL(long long n, long long d) { n   return n / d + (long long)(n % d != 0); n } n inline long long ROUND(long long n, long long d) { n   return n / d + (long long)((n % d) * 2 >= d); n } n inline long long POW(long long a, long long n) { n   if (n < 0) return 0; n   long long ret = 1; n   while (n) { n     if (n % 2) ret *= a; n     a = a * a; n     n /= 2; n   } n   return ret; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << H; n   debug_out(T...); n } n template <class T> n ostream& operator<<(ostream& os, vector<T> v) { n   os <<  [ ; n   int cnt = 0; n   for (auto vv : v) { n     os << vv; n     if (++cnt < v.size()) os <<  , ; n   } n   return os <<  ] ; n } n template <class T> n ostream& operator<<(ostream& os, set<T> v) { n   os <<  [ ; n   int cnt = 0; n   for (auto vv : v) { n     os << vv; n     if (++cnt < v.size()) os <<  , ; n   } n   return os <<  ] ; n } n template <class L, class R> n ostream& operator<<(ostream& os, pair<L, R> p) { n   return os <<  (  << p.first <<  ,  << p.second <<  ) ; n } n const int INF = 0x3fffffff, MOD = 1e9 + 7; n int n; n map<int, int> dp; n set<int> non0; n void input() { cin >> n; } n int solve() { n   dp[-INF] = 1, dp[INF] = 0; n   non0.insert(-INF); n   while (n--) { n     int x; n     string qur; n     cin >> qur >> x; n     if (qur ==  ADD ) { n       auto it = dp.lower_bound(x); n       --it; n       dp[x] = it->second; n       non0.insert(x); n     } else { n       auto hi = dp.find(x); n       auto lo = prev(hi); n       lo->second = (lo->second + hi->second) % MOD; n       non0.insert(lo->first); n       non0.erase(hi->first); n       dp.erase(hi); n       for (auto it = non0.begin(); it != non0.end();) { n         if (*it == lo->first) n           ++it; n         else n           dp[*it] = 0, it = non0.erase(it); n       } n     } n   } n   int ans = 0; n   for (auto p : dp) { n     ans = (ans + p.second) % MOD; n   } n   cout << ans <<   n ; n   return 0; n } n void execute() { input(), solve(); } n int main(void) { n   cin.tie(0); n   ios_base::sync_with_stdio(false); n   execute(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, col[N], maxx, cnt[N], p[N], eid, Son, mx[N], sz[N]; n long long sum, ans[N]; n struct edge { n   int v, nxt; n } e[N << 1]; n inline void addedge(int u, int v) { e[++eid] = (edge){v, p[u]}, p[u] = eid; } n inline void dfs0(int u, int fa) { n   sz[u] = 1; n   for (int i = p[u]; i; i = e[i].nxt) n     if (e[i].v != fa) { n       int v = e[i].v; n       dfs0(v, u), sz[u] += sz[v]; n       if (sz[v] > sz[mx[u]]) mx[u] = v; n     } n } n inline void add(int u, int fa, int d) { n   cnt[col[u]] += d; n   if (cnt[col[u]] > maxx) n     maxx = cnt[col[u]], sum = col[u]; n   else if (cnt[col[u]] == maxx) n     sum += col[u]; n   for (int i = p[u]; i; i = e[i].nxt) n     if (e[i].v != fa && e[i].v != Son) add(e[i].v, u, d); n } n inline void dfs(int u, int fa, int d) { n   for (int i = p[u]; i; i = e[i].nxt) n     if (e[i].v != fa && e[i].v != mx[u]) dfs(e[i].v, u, 0); n   if (mx[u]) dfs(mx[u], u, 1), Son = mx[u]; n   add(u, fa, 1), Son = 0, ans[u] = sum; n   if (!d) add(u, fa, -1), sum = maxx = 0; n } n int main() { n   scanf( %d , &n); n   for (int i = (1); i <= (n); i++) scanf( %d , &col[i]); n   for (int i = (1); i <= (n - 1); i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     addedge(u, v), addedge(v, u); n   } n   dfs0(1, 0), dfs(1, 0, 0); n   for (int i = (1); i <= (n); i++) printf( %lld  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n int main() { n   double d, h, v, e; n   while (scanf( %lf%lf%lf%lf , &d, &h, &v, &e) != EOF) { n     double t = v / (PI * (d / 2) * (d / 2)); n     if (t > e) { n       printf( YES n ); n       double ti = h / (t - e); n       printf( %lf n , ti); n     } else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, p, w, d; n int main() { n   cin >> n >> p >> w >> d; n   for (long long i = 0; i < w; i++) { n     if ((p - i * d) % w == 0) { n       long long x = (p - i * d) / w; n       if (x >= 0 && x + i <= n) { n         printf( %lld %lld %lld n , x, i, n - x - i); n         return 0; n       } n     } n   } n   cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 3e5; n int t, n, m, h[N], val[N]; n std::set<int> adj[N], jda[N], res; n std::map<int, std::set<int>> map; n void reset() { n   for (int i = 1; i <= n; ++i) { n     adj[i].clear(); n     jda[i].clear(); n     h[i] = 0; n     val[i] = 0; n   } n   map.clear(); n   res.clear(); n } n void dfs(int u) { n   if (h[u]) return; n   for (int v : adj[u]) { n     dfs(v); n     h[u] = std::max(h[u], h[v]); n   } n   map[-++h[u]].insert(u); n } n void turn_off(int u) { n   val[u] = n; n   for (int v : adj[u]) --val[v]; n } n void turn_on(int u) { n   --val[u]; n   for (int v : adj[u]) n     if (!++val[v]) turn_off(v); n } n int greedy(int u) { n   if (!val[u]) { n     for (int v : jda[u]) assert(val[v] > 0); n     --val[u]; n     for (int v : adj[u]) n       if (!val[v]) n         turn_on(v); n       else if (~val[v]) n         val[v] = n; n   } n   return val[u]; n } n void solve() { n   scanf( %d%d , &n, &m); n   reset(); n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].insert(v); n     jda[v].insert(u); n   } n   for (int i = 1; i <= n; ++i) dfs(i); n   for (auto pset : map) n     for (int x : pset.second) n       if (greedy(x) > 0) res.insert(x); n   printf( %u n , res.size()); n   for (int x : res) printf( %d  , x); n   printf(  n ); n } n int main() { n   scanf( %d , &t); n   for (int i = 0; i < t; ++i) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n struct el { n   long long hp, dmg, i; n }; n bool comp(el a, el b) { return (a.hp - a.dmg) > (b.hp - b.dmg); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n, a, b, i = 0; n   cin >> n >> a >> b; n   el sol[n]; n   for (i = (0); i < (n); i++) { n     cin >> sol[i].hp >> sol[i].dmg; n     sol[i].i = i; n   } n   sort(sol, sol + n, comp); n   long long sum = 0; n   for (i = (0); i < (n); i++) { n     if (i < b) n       sum += max(sol[i].hp, sol[i].dmg); n     else n       sum += sol[i].dmg; n   } n   if (b == 0) { n     cout << sum <<   n ; n     return 0; n   } n   long long x = (1LL << a); n   long long res = sum; n   for (i = (0); i < (n); i++) { n     long long temp = res; n     if (i < b) { n       temp -= max(sol[i].hp, sol[i].dmg); n       temp += (sol[i].hp) * x; n       sum = max(sum, temp); n     } else { n       temp -= sol[i].dmg; n       temp += sol[i].hp * x; n       temp -= max(sol[b - 1].hp, sol[b - 1].dmg); n       temp += sol[b - 1].dmg; n       sum = max(sum, temp); n     } n   } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n void sync_stdio() { n   cin.tie(NULL); n   ios_base::sync_with_stdio(false); n } n struct Sync_stdio { n   Sync_stdio() { n     cin.tie(NULL); n     ios_base::sync_with_stdio(false); n   } n } _sync_stdio; n int intersect(pair<int, int> a, pair<int, int> b) { n   return !(b.second <= a.first || a.second <= b.first); n } n int main() { n   int a, ta, b, tb; n   scanf( %d%d%d%d , &a, &ta, &b, &tb); n   int h, m; n   scanf( %d:%d , &h, &m); n   int tm = h * 60 + m; n   int START = 5 * 60; n   int END = 24 * 60; n   int res = 0; n   for (int i = START; i < END; i += b) { n     if (intersect({tm, tm + ta}, {i, i + tb})) { n       ++res; n     } n   } n   printf( %d , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   vector<long long> arr; n   arr.push_back(0); n   int sz = 1; n   long long max_ele = -1; n   long long pre_ind = 0; n   while (q--) { n     int x; n     cin >> x; n     if (x == 1) { n       long long v; n       cin >> v; n       if (sz == 0) n         arr.push_back(v); n       else n         arr.push_back(v + arr[sz - 1]); n       sz++; n       max_ele = v; n       continue; n     } n     if (sz == 2) { n       cout << setprecision(10) << 0.0l <<   n ; n       continue; n     } n     long long pre_sum = arr[pre_ind]; n     long long pre_numer = (pre_ind)*max_ele - pre_sum; n     long double val = (long double)pre_numer / (pre_ind + 1); n     while (pre_ind + 1 <= sz - 2) { n       if ((long double)((pre_ind + 1) * max_ele - arr[pre_ind + 1]) / n               (pre_ind + 2) > n           val) { n         val = (long double)((pre_ind + 1) * max_ele - arr[pre_ind + 1]) / n               (pre_ind + 2); n         pre_ind++; n       } else n         break; n     } n     cout << setprecision(10) << val <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> big; n vector<int> s[100010]; n vector<int> pos[100010]; n unsigned int h[100010], n, m, q; n int same[320][100010]; n unsigned int BND; n long long a[100010], sum[100010], add[100010]; n void Debug() { n   unsigned int i, j; n   printf( light: n ); n   for (i = 0; i < m; i++) { n     for (j = 0; j < s[i].size(); j++) { n       if (j) printf(   ); n       printf( %I64d , a[s[i][j]]); n     } n     if (s[i].size() > BND) n       printf(  heavy n ); n     else n       printf(  light n ); n   } n   printf(  n ); n   for (i = 0; i < big.size(); i++) n     for (j = 0; j < m; j++) printf( same:%d %d= %d n , h[i], j, same[i][j]); n } n int main() { n   unsigned int i, j, k; n   scanf( %d%d%d , &n, &m, &q); n   BND = sqrt(n); n   for (i = 0; i < n; i++) scanf( %I64d , &a[i]); n   for (i = 0; i < m; i++) { n     unsigned int cnt; n     scanf( %d , &cnt); n     for (j = 0; j < cnt; j++) { n       int tmp; n       scanf( %d , &tmp); n       tmp--; n       s[i].push_back(tmp); n       pos[tmp].push_back(i); n       sum[i] += a[tmp]; n     } n   } n   for (i = 0; i < m; i++) n     if (s[i].size() > BND) { n       big.push_back(i); n       h[big.size() - 1] = i; n       for (j = 0; j < s[i].size(); j++) { n         int tmp = s[i][j]; n         for (k = 0; k < pos[tmp].size(); k++) n           same[big.size() - 1][pos[tmp][k]]++; n       } n     } n   char o[2]; n   long long x; n   while (q--) { n     scanf( %s , o); n     if (o[0] ==  + ) { n       scanf( %d%I64d , &k, &x); n       k--; n       if (s[k].size() > BND) { n         add[k] += x; n         for (i = 0; i < big.size(); i++) n           if (h[i] != k) sum[h[i]] += x * (long long)(same[i][k]); n       } else { n         for (i = 0; i < s[k].size(); i++) a[s[k][i]] += x; n         for (i = 0; i < big.size(); i++) n           sum[h[i]] += x * (long long)(same[i][k]); n       } n     } else { n       scanf( %d , &k); n       k--; n       if (s[k].size() > BND) { n         long long ans = sum[k] + (long long)s[k].size() * add[k]; n         printf( %I64d n , ans); n       } else { n         long long ans = 0; n         for (i = 0; i < s[k].size(); i++) ans += a[s[k][i]]; n         for (i = 0; i < big.size(); i++) ans += add[h[i]] * same[i][k]; n         printf( %I64d n , ans); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Comm { n   int first; n   int second; n   Comm(int a, int b) { n     first = a; n     second = b; n   } n   bool operator<(const Comm& other) const { n     if (this->first == other.first) return this->second < other.second; n     return this->first < other.first; n   } n }; n vector<int> P; n vector<int> G; n vector<Comm> ans; n int n; n int main() { n   int x, scoP = 0, scoG = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     if (x == 1) n       scoP++; n     else n       scoG++; n     P.push_back(scoP); n     G.push_back(scoG); n   } n   int pntP = 0, pntG = 0, setP = 0, setG = 0; n   int maxPoint = max(scoP, scoG); n   for (int i = maxPoint; i > 0; i--) { n     int tar1 = i, tar2 = i; n     int pos = 0; n     setP = setG = pntG = pntP = 0; n     while (pos < n && !(pntG == pntP && pntG == n)) { n       pntP = lower_bound(P.begin() + pos, P.end(), tar1) - P.begin(); n       pntG = lower_bound(G.begin() + pos, G.end(), tar2) - G.begin(); n       if (pntP < pntG) { n         setP++; n         pos = pntP + 1; n         tar1 = P[pntP] + i; n         tar2 = G[pntP] + i; n       } n       if (pntP > pntG) { n         setG++; n         pos = pntG + 1; n         tar1 = P[pntG] + i; n         tar2 = G[pntG] + i; n       } n     } n     int tmp = max(setG, setP); n     if (tmp == setG && x == 1 || tmp == setP && x == 2 || setG == setP || n         pntG == pntP && pntG == n) { n       continue; n     } n     Comm m(tmp, i); n     ans.push_back(m); n   } n   printf( %d n , ans.size()); n   sort(ans.begin(), ans.end()); n   for (int i = 0; i < ans.size(); i++) { n     printf( %d %d n , ans[i].first, ans[i].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n const long long INF = 1e7; n signed main() { n   cin.tie(0), ios_base::sync_with_stdio(false); n   ; n   long long n, s; n   cin >> n >> s; n   vector<long long> arr(n); n   long long su = 0, mi = 1e18; n   for (long long i = 0; i < n; ++i) { n     cin >> arr[i]; n     su += arr[i]; n     if (mi > arr[i]) { n       mi = arr[i]; n     } n   } n   su -= s; n   if (su < 0) { n     cout << -1; n     return 0; n   } n   cout << min(su / n, mi); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n const int N = 2e5 + 10; n int per(int tot, int cur) { return (cur * 100 + tot / 2) / tot; } n int main() { n   int n, k; n   cin >> n >> k; n   map<pair<int, int>, int> mc; n   queue<int> q; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     q.push(x); n   } n   int cur = 0; n   map<int, int> ans; n   while (!q.empty() || !mc.empty()) { n     while (mc.size() < k && !q.empty()) { n       mc[make_pair(q.front(), q.size())] = 0; n       q.pop(); n     } n     vector<pair<int, int>> vp; n     int key = per(n, cur); n     for (auto& p : mc) { n       p.second++; n       if (p.second == key) ans[p.first.second] = 1; n       if (p.second == p.first.first) vp.emplace_back(p.first); n     } n     for (auto& p : vp) mc.erase(p), cur++; n   } n   printf( %d n , ans.size()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n int ara[200005], dist[200005], ans[200005]; n vector<int> even, odd, ad[200005]; n bool vis[200005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, i, j; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> ara[i]; n     if (ara[i] & 1) n       odd.push_back(i); n     else n       even.push_back(i); n     if (i - ara[i] >= 1) ad[i - ara[i]].push_back(i); n     if (i + ara[i] <= n) ad[i + ara[i]].push_back(i); n   } n   memset(dist, -1, sizeof dist); n   queue<int> q; n   for (i = 0; i < (int)even.size(); i++) { n     q.push(even[i]); n     dist[even[i]] = 0; n     vis[even[i]] = true; n   } n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (i = 0; i < (int)ad[u].size(); i++) { n       int v = ad[u][i]; n       if (!vis[v]) { n         vis[v] = true; n         q.push(v); n         dist[v] = dist[u] + 1; n         if (ara[v] & 1) ans[v] = dist[v]; n       } n     } n   } n   memset(vis, false, sizeof vis); n   memset(dist, -1, sizeof dist); n   for (i = 0; i < (int)odd.size(); i++) { n     q.push(odd[i]); n     dist[odd[i]] = 0; n     vis[odd[i]] = true; n   } n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (i = 0; i < (int)ad[u].size(); i++) { n       int v = ad[u][i]; n       if (!vis[v]) { n         vis[v] = true; n         q.push(v); n         dist[v] = dist[u] + 1; n         if (ara[v] % 2 == 0) ans[v] = dist[v]; n       } n     } n   } n   for (i = 1; i <= n; i++) { n     if (!ans[i]) ans[i] = -1; n     cout << ans[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 50, maxm = 5e3, inf = 1e8; n int n, m, q, k, tot, ter[maxm + 3], cap[maxm + 3], wei[maxm + 3], nxt[maxm + 3], n     lnk[maxn + 3], dist[maxn + 3], pre[maxn + 3], f[maxn + 3]; n bool in[maxn + 3]; n long long g[maxn + 3], h[maxn + 3]; n void add(int u, int v, int c, int w) { n   ter[++tot] = v, cap[tot] = c, wei[tot] = w, nxt[tot] = lnk[u], lnk[u] = tot; n } n void add_flow(int u, int v, int c, int w) { add(u, v, c, w), add(v, u, 0, -w); } n int rev(int x) { return x & 1 ? x + 1 : x - 1; } n bool spfa() { n   fill(dist + 1, dist + n + 1, inf); n   fill(pre + 1, pre + n + 1, 0); n   queue<int> Q; n   Q.push(1), dist[1] = 0, in[1] = true; n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(), in[u] = false; n     for (int i = lnk[u], v, c, w; i; i = nxt[i]) { n       v = ter[i], c = cap[i], w = wei[i]; n       if (c > 0 && dist[v] > dist[u] + w) { n         dist[v] = dist[u] + w, pre[v] = i; n         if (!in[v]) { n           in[v] = true, Q.push(v); n         } n       } n     } n   } n   return pre[n]; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1, u, v, w; i <= m; i++) { n     scanf( %d %d %d , &u, &v, &w); n     add_flow(u, v, 1, w); n   } n   while (spfa()) { n     int x = n, t; n     while (x != 1) { n       t = pre[x]; n       cap[t]--, cap[rev(t)]++; n       x = ter[rev(t)]; n     } n     f[++k] = dist[n]; n     g[k] = g[k - 1] + f[k]; n     h[k] = 1ll * k * f[k] - g[k]; n   } n   scanf( %d , &q); n   for (int x, t; q-- > 0;) { n     scanf( %d , &x); n     t = upper_bound(h + 1, h + k + 1, x) - (h + 1); n     printf( %.9lf n , 1. * (g[t] + x) / t); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long int; n int main() { n   lint n; n   cin >> n; n   vector<lint> v(n); n   for (lint i = 0; i < n; i++) { n     cin >> v[i]; n   } n   lint val = 2 * accumulate(v.begin(), v.end(), 0ll) / n; n   vector<lint> visited(n); n   for (lint i = 0; i < n; i++) { n     if (visited[i]) { n       continue; n     } n     for (lint j = i + 1; j < n; j++) { n       if (visited[j]) { n         continue; n       } n       if (v[i] + v[j] == val) { n         visited[i] = 1; n         visited[j] = 1; n         cout << (i + 1) <<     << (j + 1) << endl; n         break; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int f[55][55][55][55]; n string s[100]; n bool dfs(int n, int a, int b, int c) { n   if (n == 1) return 1; n   if (f[n][a][b][c]) return 0; n   if (s[c][0] == s[b][0] || s[c][1] == s[b][1]) n     if (dfs(n - 1, n - 3, a, c)) return 1; n   if (n > 3 && (s[c][0] == s[n - 3][0] || s[c][1] == s[n - 3][1])) n     if (dfs(n - 1, c, a, b)) return 1; n   f[n][a][b][c] = 1; n   return 0; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) cin >> s[i]; n   bool ans = dfs(n, n - 2, n - 1, n); n   if (ans == 0) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = (int)1e4 + 5, N = (int)1e5 + 5; n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int n, m, p; n int a[M], b[N]; n vector<int> fac, dp; n int fast(int a, int b) { n   int re = 1; n   while (b) { n     if (b & 1) re = (long long)re * a % p; n     a = (long long)a * a % p, b >>= 1; n   } n   return re; n } n int main() { n   scanf( %d %d %d , &n, &m, &p); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= m; i++) scanf( %d , &b[i]); n   for (int i = 1; i * i < p; i++) n     if ((p - 1) % i == 0) { n       fac.push_back(i); n       if ((p - 1) / i != i) fac.push_back((p - 1) / i); n     } n   sort(fac.begin(), fac.end()); n   int gd = p - 1; n   for (int i = 1; i <= m; i++) gd = gcd(gd, b[i]); n   dp.resize(fac.size()); n   for (int i = 1, ab, t; i <= n; i++) { n     ab = fast(a[i], gd); n     t = fac.size() - 1; n     while (fast(ab, (p - 1) / fac[t]) != 1) t--; n     dp[t] = (p - 1) / fac[t]; n   } n   long long ans = 0; n   for (int i = dp.size() - 1; i >= 0; i--) n     if (dp[i]) { n       for (int j = dp.size() - 1; j > i; j--) n         if (fac[j] % fac[i] == 0) dp[i] -= dp[j]; n       ans += dp[i]; n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int kMaxN = 1010; n struct Cell { n   int x, y, val; n   bool operator<(const Cell &p) const { return val > p.val; } n } cell[kMaxN * kMaxN]; n vector<int> vec[kMaxN]; n int g[kMaxN][kMaxN]; n int n, m; n void init() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       scanf( %d , &cell[i * m + j].val); n       cell[i * m + j].x = i; n       cell[i * m + j].y = j; n     } n   } n   sort(cell, cell + n * m); n } n void solve() { n   for (int i = 0; i < n * m; ++i) { n     int j = cell[i].y; n     int q = cell[i].x; n     for (int l = 0; l < ((int)(vec[j]).size()); ++l) { n       int p = vec[j][l]; n       if (g[p][q]) { n         printf( %d n , cell[i].val); n         return; n       } n       g[p][q] = g[q][p] = 1; n     } n     vec[j].push_back(q); n   } n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4e5 + 5; n long long a[maxn]; n long long pre[maxn]; n map<long long, long long> mp; n int main() { n   int n, l; n   scanf( %d%d , &n, &l); n   for (int i = 0; i < n; i++) { n     scanf( %I64d , &a[i]); n     mp[a[i]]++; n   } n   sort(a, a + n); n   long long cnt = unique(a, a + n) - a; n   for (int i = 1; i <= cnt; i++) { n     pre[i] = pre[i - 1] + mp[a[i - 1]]; n   } n   l *= 8; n   long long temp = log(cnt) / log(2); n   if ((1 << temp) < cnt) temp++; n   if (temp * n <= l) { n     printf( 0 n ); n     return 0; n   } n   long long sum = l / n; n   sum = (1 << sum); n   long long ans = -0x3f3f3f3f; n   for (int i = 1, j = i + sum; j <= cnt; i++, j++) { n     ans = max(ans, pre[j] - pre[i]); n   } n   printf( %I64d n , n - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char x[105]; n bool g; n int main() { n   scanf( %s , x); n   for (int i = 0; x[i]; i++) n     if (x[i] ==  a  || x[i] ==  e  || x[i] ==  i  || x[i] ==  o  || x[i] ==  u ) n       g = 0; n     else if (g) { n       puts( NO ); n       return 0; n     } else if (x[i] !=  n ) n       g = 1; n   puts(g ?  NO  :  YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool flag = false; n long long n; n long long mat[1000][1000]; n bool vis[1000][1000]; n long long ans[1000][1000]; n bool isSol() { n   long long s = 0; n   for (int i = 0; i < n; i++) { n     s += ans[i][i]; n   } n   long long s2 = 0; n   for (int i = 0; i < n; i++) { n     s2 += ans[n - i - 1][i]; n   } n   if (s2 != s) return false; n   for (int i = 0; i < n; i++) { n     s2 = 0; n     for (int j = 0; j < n; j++) { n       s2 += ans[i][j]; n     } n     if (s2 != s) return false; n   } n   for (int i = 0; i < n; i++) { n     s2 = 0; n     for (int j = 0; j < n; j++) { n       s2 += ans[j][i]; n     } n     if (s2 != s) return false; n   } n   return true; n } n void find_sol(long long pos) { n   if (flag) return; n   if (pos == n * n) { n     if (isSol()) flag = true; n     return; n   } n   long long pos_x = pos / n; n   long long pos_y = pos % n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (!vis[i][j] && !flag) { n         vis[i][j] = true; n         ans[pos_x][pos_y] = mat[i][j]; n         find_sol(pos + 1); n         vis[i][j] = false; n       } n     } n   } n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> mat[i][j]; n       vis[i][j] = false; n     } n   } n   find_sol(0); n   long long s = 0; n   for (int i = 0; i < n; i++) s += ans[i][0]; n   cout << s << endl; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cout << ans[i][j] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <cstdio> n #include <algorithm> n using namespace std; n #define ADD(x) ((x>=mod)?x-mod:x) n const int mod=1e9+7; n int n,c[110],b[110],sum[110],sum1[110],sumc[110],dp[110][10010],ans,Min,T,x; n int main() n { n  scanf( %d ,&n); n  for (int i=1;i<=n;i++) scanf( %d ,&c[i]),sumc[i]=sumc[i-1]+c[i]; n  for (int i=1;i<n;i++) scanf( %d ,&b[i]),sum[i]=sum[i-1]+b[i]; n  for (int i=1;i<=n;i++) sum1[i]=sum1[i-1]+sum[i-1]; n  scanf( %d%d ,&T,&x); n  dp[0][0]=1; n  for (int i=1;i<=n;i++) n   for (int j=x*i+sum1[i];j<=sumc[i];j++) n    for (int k=min(j,c[i]);k>=0;k--) n     dp[i][j]=ADD(dp[i][j]+dp[i-1][j-k]); n  for (int i=0;i<=sumc[n];i++) ans=ADD(ans+dp[n][i]); n  printf( %d n ,ans); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int i, int j) { n   if (j == 0) n     return i; n   else n     return gcd(j, i % j); n } n template <typename T> n inline T getint() { n   T val = 0; n   char c; n   bool neg = false; n   while ((c = getchar()) && !(c >=  0  && c <=  9 )) { n     neg |= c ==  - ; n   } n   do { n     val = (val * 10) + c -  0 ; n   } while ((c = getchar()) && (c >=  0  && c <=  9 )); n   return val * (neg ? -1 : 1); n } n const long long INF = 1e17; n const int Y = 200100; n vector<int> Ed[Y]; n int mx; n int ans[Y]; n int n, k; n int qw(int l, int r) { n   vector<int> q; n   for (int j = l; j <= r; ++j) { n     for (auto x : Ed[j]) q.push_back(x); n   } n   sort(q.begin(), q.end()); n   cout <<  ?   << q.size() <<    ; n   for (auto x : q) cout << x <<    ; n   cout << endl; n   int x; n   cin >> x; n   return x; n } n void Mrec(int l, int r) { n   if (l > r) return; n   if (r == l) { n     set<int> q; n     for (int j = 0; j < n; ++j) { n       q.insert(j + 1); n     } n     for (auto x : Ed[l]) { n       q.erase(q.find(x)); n     } n     cout <<  ?   << q.size() <<    ; n     for (auto x : q) cout << x <<    ; n     cout << endl; n     cin >> ans[l]; n     return; n   } n   int len = (r - l + 1) / 2; n   int mid = l + len - 1; n   int r1 = qw(l, mid); n   if (r1 == mx) { n     for (int j = mid + 1; j <= r; ++j) ans[j] = mx; n     if (len == 1 || l == r) { n       set<int> q; n       for (int j = 0; j < n; ++j) { n         q.insert(j + 1); n       } n       for (auto x : Ed[l]) { n         q.erase(q.find(x)); n       } n       cout <<  ?   << q.size() <<    ; n       for (auto x : q) cout << x <<    ; n       cout << endl; n       cin >> ans[l]; n       return; n     } else { n       Mrec(l, mid); n     } n   } else { n     for (int j = l; j <= mid; ++j) ans[j] = mx; n     ++mid; n     if (r == mid || l == r) { n       set<int> q; n       for (int j = 0; j < n; ++j) { n         q.insert(j + 1); n       } n       for (auto x : Ed[r]) { n         q.erase(q.find(x)); n       } n       cout <<  ?   << q.size() <<    ; n       for (auto x : q) cout << x <<    ; n       cout << endl; n       cin >> ans[r]; n       return; n     } else { n       Mrec(mid, r); n     } n   } n } n int32_t main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     for (int i = 0; i < k; ++i) ans[i] = 0; n     for (int i = 0; i < k; ++i) { n       Ed[i].clear(); n       int tt; n       cin >> tt; n       for (int j = 0; j < tt; ++j) { n         int tmp; n         cin >> tmp; n         Ed[i].push_back(tmp); n       } n     } n     cout <<  ?   << n; n     for (int i = 1; i <= n; ++i) cout <<     << i; n     cout << endl; n     cin >> mx; n     Mrec(0, k - 1); n     cout <<  !  ; n     for (int i = 0; i < k; ++i) cout << ans[i] <<    ; n     cout << endl; n     string s; n     cin >> s; n     if (s ==  Incorrect ) { n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed 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> data(n), ans(n); n   long long suma = 0; n   for (auto &i : data) cin >> i; n   for (int i = 0; i < n; ++i) { n     vector<int> data1; n     data1 = data; n     for (int j = i - 1; j >= 0; --j) data1[j] = min(data1[j], data1[j + 1]); n     for (int j = i + 1; j < n; ++j) data1[j] = min(data1[j], data1[j - 1]); n     long long sum = 0; n     for (auto i : data1) sum += i; n     if (sum > suma) { n       suma = sum; n       ans = data1; n     } n   } n   for (auto i : ans) cout << i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; n long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; n class pa3 { n  public: n   long long x; n   long long y, z; n   pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} n   bool operator<(const pa3& p) const { n     if (x != p.x) return x < p.x; n     if (y != p.y) return y < p.y; n     return z < p.z; n   } n   bool operator>(const pa3& p) const { n     if (x != p.x) return x > p.x; n     if (y != p.y) return y > p.y; n     return z > p.z; n   } n   bool operator==(const pa3& p) const { n     return x == p.x && y == p.y && z == p.z; n   } n   bool operator!=(const pa3& p) const { n     return !(x == p.x && y == p.y && z == p.z); n   } n }; n class pa4 { n  public: n   long long x; n   long long y, z, w; n   pa4(long long x = 0, long long y = 0, long long z = 0, long long w = 0) n       : x(x), y(y), z(z), w(w) {} n   bool operator<(const pa4& p) const { n     if (x != p.x) return x < p.x; n     if (y != p.y) return y < p.y; n     if (z != p.z) return z < p.z; n     return w < p.w; n   } n   bool operator>(const pa4& p) const { n     if (x != p.x) return x > p.x; n     if (y != p.y) return y > p.y; n     if (z != p.z) return z > p.z; n     return w > p.w; n   } n   bool operator==(const pa4& p) const { n     return x == p.x && y == p.y && z == p.z && w == p.w; n   } n }; n class pa2 { n  public: n   long long x, y; n   pa2(long long x = 0, long long y = 0) : x(x), y(y) {} n   pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); } n   pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); } n   bool operator<(const pa2& p) const { return y != p.y ? y < p.y : x < p.x; } n   bool operator>(const pa2& p) const { return x != p.x ? x < p.x : y < p.y; } n   bool operator==(const pa2& p) const { n     return abs(x - p.x) == 0 && abs(y - p.y) == 0; n   } n   bool operator!=(const pa2& p) const { n     return !(abs(x - p.x) == 0 && abs(y - p.y) == 0); n   } n }; n string itos(long long i) { n   ostringstream s; n   s << i; n   return s.str(); n } n long long Gcd(long long v, long long b) { n   if (v == 0) return b; n   if (b == 0) return v; n   if (v > b) return Gcd(b, v); n   if (v == b) return b; n   if (b % v == 0) return v; n   return Gcd(v, b % v); n } n long long mod; n long long extgcd(long long a, long long b, long long& x, long long& y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long d = extgcd(b, a % b, y, x); n   y -= a / b * x; n   return d; n } n pair<long long, long long> operator+(const pair<long long, long long>& l, n                                      const pair<long long, long long>& r) { n   return {l.first + r.first, l.second + r.second}; n } n pair<long long, long long> operator-(const pair<long long, long long>& l, n                                      const pair<long long, long long>& r) { n   return {l.first - r.first, l.second - r.second}; n } n ostream& operator<<(ostream& os, const vector<long long>& VEC) { n   for (auto v : VEC) os << v <<    ; n   return os; n } n ostream& operator<<(ostream& os, const pair<long long, long long>& PAI) { n   os << PAI.first <<   :   << PAI.second; n   return os; n } n ostream& operator<<(ostream& os, const pa3& PAI) { n   os << PAI.x <<   :   << PAI.y <<   :   << PAI.z; n   return os; n } n ostream& operator<<(ostream& os, const pa4& PAI) { n   os << PAI.x <<   :   << PAI.y <<   :   << PAI.z <<   :   << PAI.w; n   return os; n } n ostream& operator<<(ostream& os, n                     const vector<pair<long long, long long> >& VEC) { n   for (auto v : VEC) os << v <<    ; n   return os; n } n long long beki(long long wa, long long rr, long long warukazu) { n   if (rr == 0) return 1 % warukazu; n   if (rr == 1) return wa % warukazu; n   wa %= warukazu; n   if (rr % 2 == 1) n     return ((long long)beki(wa, rr - 1, warukazu) * (long long)wa) % warukazu; n   long long zx = beki(wa, rr / 2, warukazu); n   return (zx * zx) % warukazu; n } n long long pr[1100000]; n long long inv[1100000]; n long long comb(long long nn, long long rr) { n   if (rr < 0 || rr > nn || nn < 0) return 0; n   long long r = pr[nn] * inv[rr]; n   r %= mod; n   r *= inv[nn - rr]; n   r %= mod; n   return r; n } n void gya(long long ert) { n   pr[0] = 1; n   for (long long i = 1; i <= ert; i++) { n     pr[i] = ((long long)pr[i - 1] * i) % mod; n   } n   inv[ert] = beki(pr[ert], mod - 2, mod); n   for (long long i = ert - 1; i >= 0; i--) { n     inv[i] = (long long)inv[i + 1] * (i + 1) % mod; n   } n } n struct seg_rangeupd_getsum { n  private: n  public: n   long long cor = (1 << 18); n   long long inff = 1000000007 * 1000000ll; n   vector<long long> vec; n   vector<long long> lazy; n   void shoki1() { n     vec.resize(2 * cor + 3, 0); n     lazy.resize(2 * cor + 3, inff); n   } n   void shoki2() {} n   long long chien(long long k, long long len) { n     if (lazy[k] == inff) return vec[k]; n     if (k < cor) { n       vec[k] = lazy[k] * len; n       lazy[2 * k] = lazy[k]; n       lazy[2 * k + 1] = lazy[k]; n       lazy[k] = inff; n     } else { n       vec[k] = lazy[k]; n       lazy[k] = inff; n     } n     return vec[k]; n   } n   void clear_chien(long long r) { n     if (r == 0) return; n     long long f = 31 - __builtin_clz(r); n     long long pos = 0; n     long long len = cor; n     for (long long i = f; i >= 0; i--) { n       pos *= 2; n       pos += !!(r & (1 << i)); n       chien(pos, len); n       len /= 2; n     } n   } n   void rangeupd(long long a, long long b, long long w) { n     a += cor, b += cor; n     long long aa = a / (a & (-a)) / 2; n     long long bb = b / (b & (-b)) / 2; n     long long lenaa = 2 * (a & -a); n     long long lenbb = 2 * (b & -b); n     clear_chien(aa); n     clear_chien(bb); n     while (a < b) { n       if (a & 1) { n         lazy[a] = w; n         a++; n       } n       if (b & 1) { n         b--; n         lazy[b] = w; n       } n       a /= 2, b /= 2; n     } n     while (aa > 0 || bb > 0) { n       if (aa > bb) { n         vec[aa] = chien(2 * aa, lenaa / 2) + chien(2 * aa + 1, lenaa / 2); n         aa /= 2; n         lenaa *= 2; n       } else if (aa < bb) { n         vec[bb] = chien(2 * bb, lenbb / 2) + chien(2 * bb + 1, lenbb / 2); n         bb /= 2; n         lenbb *= 2; n       } else { n         vec[aa] = chien(2 * aa, lenaa / 2) + chien(2 * aa + 1, lenaa / 2); n         aa /= 2; n         lenaa *= 2; n         bb = aa, lenbb = aa; n       } n     } n   } n   long long getsum(long long a, long long b) { n     a += cor, b += cor; n     long long aa = a / (a & (-a)) / 2; n     long long bb = b / (b & (-b)) / 2; n     clear_chien(aa); n     clear_chien(bb); n     long long ans = 0; n     long long len = 1; n     while (a < b) { n       if (a & 1) { n         ans += chien(a, len); n         a++; n       } n       if (b & 1) { n         b--; n         ans += chien(b, len); n       } n       a /= 2, b /= 2, len *= 2; n     } n     return ans; n   } n   long long lower_bound(long long p, long long x) { n     p += cor; n     long long ima = 0; n     bool fst = 1; n     long long len = 1; n     while (1) { n       while (!(p & 1)) p /= 2, len *= 2; n       if (fst) fst = 0, clear_chien(p / 2); n       if (ima + chien(p, len) >= x) break; n       ima = ima + vec[p]; n       p++; n       if (p == (p & (-p))) return cor; n     } n     while (1) { n       if (p >= cor) return p - cor; n       p *= 2; n       len /= 2; n       if (ima + chien(p, len) < x) { n         ima += vec[p]; n         p++; n       } n     } n   } n   long long upper_bound(long long p, long long x) { n     p += cor; n     long long ima = 0; n     bool fst = 1; n     long long len = 1; n     while (1) { n       while (!(p & 1)) p /= 2, len *= 2; n       if (fst) fst = 0, clear_chien(p / 2); n       if (ima + chien(p, len) > x) break; n       ima = ima + vec[p]; n       p++; n       if (p == (p & (-p))) return cor; n     } n     while (1) { n       if (p >= cor) return p - cor; n       p *= 2; n       len /= 2; n       if (ima + chien(p, len) <= x) { n         ima += vec[p]; n         p++; n       } n     } n   } n }; n void solve() { n   long long n, q, t; n   cin >> n >> q >> t; n   string s; n   cin >> s; n   seg_rangeupd_getsum ss; n   ss.shoki1(); n   ss.shoki2(); n   for (long long i = 0; i < n; i++) { n     ss.rangeupd(i, i + 1, s[i] -  a ); n   } n   set<long long> se; n   long long dp[11][11] = {}; n   for (long long i = 0; i < n - 1; i++) { n     if (s[i] != s[i + 1]) { n       se.insert(i); n       dp[s[i] -  a ][s[i + 1] -  a ]++; n     } n   } n   se.insert(1000000007); n   while (q--) { n     long long e; n     cin >> e; n     if (e == 1) { n       long long l, r; n       char c; n       cin >> l >> r >> c; n       l--; n       auto it = se.lower_bound(l - 1); n       while (1) { n         if (*it >= r) break; n         long long mae = ss.getsum(*it, *it + 1); n         long long ato = ss.getsum(*it + 1, *it + 2); n         dp[mae][ato]--; n         it = se.erase(it); n       } n       ss.rangeupd(l, r, c -  a ); n       if (l) { n         long long mae = ss.getsum(l - 1, l); n         long long ato = ss.getsum(l, l + 1); n         if (mae != ato) dp[mae][ato]++, se.insert(l - 1); n       } n       if (r < n) { n         long long mae = ss.getsum(r - 1, r); n         long long ato = ss.getsum(r, r + 1); n         if (mae != ato) dp[mae][ato]++, se.insert(r - 1); n       } n     } else { n       string w; n       cin >> w; n       long long ans = n; n       for (long long i = 0; i < t; i++) n         for (long long j = i + 1; j < t; j++) { n           ans -= dp[w[i] -  a ][w[j] -  a ]; n         } n       cout << ans << endl; n     } n   } n } n signed main() { n   mod = 1000000007; n   cin.tie(0); n   ios::sync_with_stdio(false); n   long long n = 1; n   for (long long i = 0; i < n; i++) solve(); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define sz(x) (int)(x).size()  n #define int long long int n #define loop(i,a,b) for(int i=a;i<b;i++) n #define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i] n #define vi vector<int> n #define si set<int> n #define pii pair <int, int> n #define sii set<pii> n #define vii vector<pii> n #define mii map <int, int> n #define pb push_back n #define ff first n #define ss second n #define all(aa) aa.begin(), aa.end() n #define rall(a) a.rbegin() , a.rend() n #define read(a,b) int a,b;  cin>>a>>b n #define readt(a,b,c) int a,b,c; cin>>a>>b>>c n #define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d; n #define print(v) for(auto x:v) cout<<x<<   ;cout<<endl n #define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<   <<p.second<<endl; n #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) n  n  n void solve(int test) n { n    int n;cin>>n; n   // if(n<=9) n   // { n   //   cout<<n<<endl; n   //   return ; n   // } n   // if(n<=100) n   // { n   //  int ans=9; n   //  loop(i,10,100) n   //  { n   //   if(i%10==i/10) n   //     ans++; n   //  } n  n   //  cout<<ans<<endl; n   //  return ; n   // } n  n   int cp=n , d=0; n   while(cp!=0) n   { n     d++; n     cp/=10; n   } n  n   int ans=9*(d-1); n   int f=n/pow(10,d-1); n   ans+=f; n   int cpp=f; n   string req; n   loop(i,0,d) n   req+=to_string(f); n  n   f=stoi(req); n   // for(int i=1;i<=d-1;i++) n   // { n   //   int prev=f; n   //   f=f*pow(10,i) ; n   //   f+=prev; n   // } n  n   //cout<<f<<endl; n  n   if(f>n) n   { n     ans--; n   } n  n   cout<<ans<<endl; n } n  n int32_t main() n { n       #ifndef ONLINE_JUDGE n           freopen( input.txt ,  r , stdin); n           freopen( op.txt ,  w , stdout); n       #endif n       faster; n       //fact(mod); n       int t=1; n       cin>>t; n       for(int test=1;test<=t;test++) n       { n         //cout<< Case # <<test<< :  ; n           solve(test); n       } n }


#include <bits/stdc++.h> n using namespace std; n string st; n vector<long> v; n long r; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> st; n   st +=  + ; n   for (int i = 0; i < st.size(); i++) { n     if (st[i] ==  + ) { n       v.push_back(r); n       r = 0; n     } else n       r = r * 10 + st[i] - 48; n   } n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size(); i++) { n     if (i) cout <<  + ; n     cout << v[i]; n   } n   cout << endl; n   cin.get(); n   cin.get(); n   return 0; n } n