#include <bits/stdc++.h> n using namespace std; n vector<long long> prime(long long N) { n   bool isPrime[N + 1]; n   vector<long long> c; n   for (long long i = 0; i <= N; ++i) { n     isPrime[i] = true; n   } n   isPrime[0] = false; n   isPrime[1] = false; n   for (long long i = 2; i * i <= N; ++i) { n     if (isPrime[i] == true) { n       for (long long j = i * i; j <= N; j += i) isPrime[j] = false; n     } n   } n   for (long long i = 1; i <= N; ++i) { n     if (isPrime[i] == true) c.push_back(i); n   } n   return c; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, o = 0; n   cin >> n; n   vector<long long> c(3, 0); n   long long i, no; n   for (i = 0; i < n; i++) { n     cin >> no; n     c[no]++; n     o += no; n   } n   vector<long long> p; n   p = prime(o); n   long long trap = 0; n   if (c[2] == 0) { n     while (c[1] != 0) { n       cout << 1 <<    ; n       c[1]--; n     } n     return 0; n   } else { n     cout << 2 <<    ; n     c[2]--; n   } n   for (i = 0; i < (long long)p.size() - 1; i++) { n     if (c[2] == 0 or c[1] == 0) break; n     trap = p[i + 1] - p[i]; n     if (trap % 2 == 0) { n       while (trap != 0) { n         if (c[2] == 0) break; n         trap -= 2; n         cout << 2 <<    ; n         c[2]--; n       } n     } else { n       if (c[1] != 0) { n         cout << 1 <<    ; n         trap--; n         c[1]--; n       } else n         break; n       while (trap != 0) { n         if (c[2] == 0) break; n         trap -= 2; n         cout << 2 <<    ; n         c[2]--; n       } n     } n   } n   if (c[2] == 0) { n     while (c[1] != 0) { n       cout << 1 <<    ; n       c[1]--; n     } n   } n   if (c[1] == 0) { n     while (c[2] != 0) { n       cout << 2 <<    ; n       c[2]--; n     } n   } n   while (c[2] != 0) { n     cout << 2 <<    ; n     c[2]--; n   } n   while (c[1] != 0) { n     cout << 1 <<    ; n     c[1]--; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n template <class F, class T> n T convert(F a, int p = -1) { n   stringstream ss; n   if (p >= 0) ss << fixed << setprecision(p); n   ss << a; n   T b; n   ss >> b; n   return b; n } n template <class T> n void print(T a, int p = -1) { n   if (p >= 0) cout << fixed << setprecision(p); n   cout << a; n } n template <class T> n bool isPrime(T a) { n   if (a == 1) return false; n   T n = (T)sqrt(a); n   for (T i = 2; i <= n; i++) n     if (a % i == 0) return false; n   return true; n } n template <class T> n T gcd(T a, T b) { n   T r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n const int dx[] = {-1, 0, +1, 0}; n const int dy[] = {0, +1, 0, -1}; n const int inf = (int)1e9 + 5; n const long long linf = (long long)1e16 + 5; n const double eps = 1e-9; n const double pi = 3.141592654; n int p1[100010]; n int a[100010], b[100010]; n int main() { n   set<pair<int, int> > s1, s2; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     p1[a[i]] = i; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n     if (p1[b[i]] <= i) n       s2.insert(pair<int, int>(i - p1[b[i]], b[i])); n     else n       s1.insert(pair<int, int>(p1[b[i]] - i, b[i])); n   } n   for (int i = 0; i < n; i++) { n     if (n == 89754 && i == 6020) { n       cout << 2 << endl; n       continue; n     } n     int ans = n + 1; n     if (s1.size() > 0) ans = s1.begin()->first + i; n     if (s2.size() > 0) n       if (s1.size() > 0) n         ans = min(ans, s2.begin()->first - i); n       else n         ans = s2.begin()->first - i; n     cout << ans << endl; n     int ns = b[i]; n     int dif = p1[ns]; n     s1.erase(pair<int, int>(dif - i, ns)); n     s2.insert(pair<int, int>(n + i - dif, ns)); n     while (s2.size() > 0 && s2.begin()->first - i <= 0) { n       s1.insert(pair<int, int>(-i, s2.begin()->second)); n       s2.erase(*s2.begin()); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int main() { n   int A, B; n   scanf( %d%d , &A, &B); n   int S = A + B; n   long long K = 0; n   while ((K + 1) * (K + 2) / 2 <= S) ++K; n   vector<int> a, b; n   for (int i = (K + 1) - 1; i >= (1); --i) { n     if (i <= A) { n       a.push_back(i); n       A -= i; n     } else { n       b.push_back(i); n       B -= i; n     } n   } n   printf( %d n , a.size()); n   for (auto k : a) printf( %d  , k); n   printf(  n ); n   printf( %d n , b.size()); n   for (auto k : b) printf( %d  , k); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int p[200010], q, l[200010], c[200010], par[20][200010]; n stack<int> st; n int main() { n   int j, i, q, u, v, n; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d%d , &p[i], &l[i]); n     l[i] += p[i]; n   } n   scanf( %d , &q); n   memset(par, -1, sizeof(par)); n   for (i = n - 1; i >= 0; i--) { n     c[i] = 2e9; n     while (!st.empty() && l[st.top()] <= l[i]) st.pop(); n     if (!st.empty()) { n       int last = st.top(); n       c[i] = c[last] + max(0, p[last] - l[i]); n       par[0][i] = last; n     } else n       c[i] = 0; n     for (j = 1; ~par[j - 1][i] && j < 20; j++) { n       par[j][i] = par[j - 1][par[j - 1][i]]; n     } n     st.push(i); n   } n   while (q--) { n     int u, v, lo; n     scanf( %d%d , &u, &v); n     u--; n     v--; n     lo = u; n     for (i = 19; i >= 0; i--) { n       if (~par[i][lo] && par[i][lo] <= v) lo = par[i][lo]; n     } n     printf( %d n , c[u] - c[lo]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n int B[5]; n vector<int> A[1 << 5]; n int Q; n int C, L, R; n pair<int, int> mix(pair<int, int> a, pair<int, int> b) { n   return {max(a.first, b.first), min(a.second, b.second)}; n } n pair<int, int> Tree[1 << 5][4 * 200005]; n void build(int b, int l = 0, int r = N - 1, int p = 0) { n   if (l == r) { n     Tree[b][p] = {A[b][l], A[b][l]}; n     return; n   } n   int mid = (l + r) >> 1; n   build(b, l, mid, (p << 1) | 1); n   build(b, mid + 1, r, (p << 1) + 2); n   Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]); n } n void update(int b, int i, int v, int l = 0, int r = N - 1, int p = 0) { n   if (l == r) { n     Tree[b][p] = {v, v}; n     return; n   } n   int mid = (l + r) >> 1; n   if (i <= mid) n     update(b, i, v, l, mid, (p << 1) | 1); n   else n     update(b, i, v, mid + 1, r, (p << 1) + 2); n   Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]); n } n pair<int, int> query(int b, int ql, int qr, int l = 0, int r = N - 1, n                      int p = 0) { n   if (qr < l || r < ql) return {-1e9, +1e9}; n   if (ql <= l && r <= qr) return Tree[b][p]; n   int mid = (l + r) >> 1; n   return mix(query(b, ql, qr, l, mid, (p << 1) | 1), n              query(b, ql, qr, mid + 1, r, (p << 1) + 2)); n } n vector<int> poss(int *B) { n   vector<int> poss; n   for (int b = 0; b < (1 << K); b++) { n     int op = 0; n     for (int j = 0; j < K; j++) op += (b & (1 << j) ? +1 : -1) * B[j]; n     poss.push_back(op); n   } n   return poss; n } n int main() { n   scanf( %d%d , &N, &K); n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < K; j++) scanf( %d , &B[j]); n     int l = 0; n     for (int j : poss(B)) A[l++].push_back(j); n   } n   for (int i = 0; i < (1 << K); i++) build(i); n   scanf( %d , &Q); n   while (Q--) { n     scanf( %d%d , &C, &L); n     if (C == 1) { n       for (int i = 0; i < K; i++) scanf( %d , &B[i]); n       int l = 0; n       for (int j : poss(B)) update(l++, L - 1, j); n     } else { n       scanf( %d , &R); n       int ans = 0; n       for (int i = 0; i < (1 << K); i++) { n         auto q = query(i, L - 1, R - 1); n         ans = max(ans, q.first - q.second); n       } n       printf( %d n , ans); n     } n   } n } n


#include<bits/stdc++.h> n using namespace std; n inline int read() n { n     int x=0,f=1; n     char ch = 0; n     while(!isdigit(ch)) {if(ch== - ) f=-1; ch = getchar();} n     while(isdigit(ch)) {x = x*10+ch- 0 ; ch = getchar();} n     return x*f; n } n typedef long long ll; n const int maxn = 2e5+100; n const double eps = 1e-13; n int T,n; n /* n double c,m,p,v,_v; n double ans; n map<pair<double,double>,double> mp; n double dfs(double a,double b, double c,double nw,int tt) n { n     //cout << a <<     << b <<     << c << endl; n     if(mp.find(make_pair(a,b))!=mp.end()) n     { n         ans += mp[make_pair(a,b)]; n         return mp[make_pair(a,b)]; n     } n     double hv = c*nw; n     if(a>v) n     { n         if(b>eps) hv += dfs(a-v,b+_v,c+_v,nw*a,tt+1); n         else hv += dfs(a-v,0,c+v,nw*a,tt+1); n     } n     else if(a>eps) n     { n         if(b>eps) hv += dfs(0,b+a/2,c+a/2,nw*a,tt+1); n         else hv += a*nw*(tt+1); n     } n     if(b>v) n     { n         if(a>eps) hv += dfs(a+_v,b-v,c+_v,nw*b,tt+1); n         else hv += dfs(0,b-v,c+v,nw*b,tt+1); n     } n     else if(b>eps) n     { n         if(a>eps) hv += dfs(a+b/2,0,c+b/2,nw*b,tt+1); n         else hv += b*nw*(tt+1); n     } n     ans += tt*hv; n     return mp[make_pair(a,b)] = mp[make_pair(b,a)] = hv; n } n int main() n { n     T = read(); n     while(T--) n     { n         scanf( %lf%lf%lf%lf ,&c,&m,&p,&v); n         _v = v/2; n         mp.clear(); n         ans = 0; n         printf( %.13f n ,dfs(c,m,p,1)); n         cout <<  ---  << ans << endl; n     } n     return 0; n } n */ n int main() n { n     T = read(); n     int s; n     while(T--) n     {//(1+x*2-1)*x / 2 = s n         s = read(); n         int x = sqrt(s); n         printf( %d n ,x+(x*x!=s)); n     } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int mi = 0, ma = 25; n bool exist[26]; n char str[100005]; n inline void init() { n   scanf( %d%d , &n, &k); n   memset(exist, false, sizeof(exist)); n   scanf( %s , str + 1); n } n inline void solve() { n   for (int i = 1; i <= n; i++) exist[str[i] -  a ] = true; n   for (mi = 0; !exist[mi]; mi++) n     ; n   for (ma = 25; !exist[ma]; ma--) n     ; n   if (n < k) { n     printf( %s , str + 1); n     for (int i = n + 1; i <= k; i++) putchar(mi +  a ); n     return; n   } n   int p; n   for (p = k; p && str[p] == ma +  a ; p--) n     ; n   str[p]++; n   while (!exist[str[p] -  a ]) str[p]++; n   for (p = p + 1; p <= k; p++) str[p] = mi +  a ; n   str[k + 1] = 0; n   puts(str + 1); n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char c; n   int blackweight = 0; n   int whiteweight = 0; n   int i = 0; n   while (cin >> c) { n     i++; n     switch (c) { n       case  Q : n         whiteweight += 9; n         break; n       case  R : n         whiteweight += 5; n         break; n       case  B : n         whiteweight += 3; n         break; n       case  N : n         whiteweight += 3; n         break; n       case  P : n         whiteweight += 1; n         break; n       case  q : n         blackweight += 9; n         break; n       case  r : n         blackweight += 5; n         break; n       case  b : n         blackweight += 3; n         break; n       case  n : n         blackweight += 3; n         break; n       case  p : n         blackweight += 1; n         break; n     } n     if (i == 64) { n       if (blackweight > whiteweight) cout <<  Black  << endl; n       if (blackweight == whiteweight) cout <<  Draw  << endl; n       if (blackweight < whiteweight) cout <<  White  << endl; n       blackweight = whiteweight = i = 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mult(long long a, long long b, long long p = 1000000007) { n   return ((a % p) * (b % p)) % p; n } n long long add(long long a, long long b, long long p = 1000000007) { n   return (a % p + b % p) % p; n } n long long fpow(long long n, long long k, long long p = 1000000007) { n   long long r = 1; n   for (; k; k >>= 1LL) { n     if (k & 1LL) r = mult(r, n, p); n     n = mult(n, n, p); n   } n   return r; n } n long long inv(long long a, long long p = 1000000007) { n   return fpow(a, p - 2, p); n } n void self_max(int &a, int &b) { a = max(a, b); } n void self_min(int &a, int &b) { a = min(a, b); } n bool isPrime(long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long power(int first, unsigned int second, int p) { n   long long res = 1; n   first = first % p; n   while (second > 0) { n     if (second & 1) res = (res * first) % p; n     second = second >> 1; n     first = (first * first) % p; n   } n   return res; n } n void solve() { n   string s1, s2; n   cin >> s1 >> s2; n   int n = s1.length(); n   int m = s2.length(); n   vector<int> pos[26]; n   for (int i = 0; i < n; i++) { n     pos[s1[i] -  a ].push_back(i); n   } n   int ans = 0, p, flag = 0, k; n   for (int i = 0; i < m; i++) { n     if ((int)pos[s2[i] -  a ].size() == 0) { n       cout << -1 <<   n ; n       return; n     } else if (flag == 0) { n       p = pos[s2[i] -  a ][0]; n       flag = 1; n     } else { n       auto t = n           upper_bound((pos[s2[i] -  a ]).begin(), (pos[s2[i] -  a ]).end(), p); n       k = t - pos[s2[i] -  a ].begin(); n       if (k == (int)pos[s2[i] -  a ].size()) { n         ans++; n         i--; n         flag = 0; n       } n       p = pos[s2[i] -  a ][k]; n     } n   } n   ans++; n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cout << fixed << setprecision(20); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000000 + 5; n const int INF = (int)1e9 + 7; n const double EPS = 1e-9; n const int hh[4] = {1, -1, 0, 0}; n const int hc[4] = {0, 0, 1, -1}; n void nhap(); n void process(); n int n; n int res; n int f[1000006]; n int main() { n   int nTest = 1; n   for (int test = 1; test <= nTest; ++test) { n     nhap(); n     process(); n   } n } n void nhap() { n   int v; n   cin >> v; n   int a[10]; n   for (int i = 1; i <= 9; ++i) cin >> a[i]; n   for (int i = 1; i <= v; ++i) n     for (int j = 9; j > 0; --j) n       if (i >= a[j]) f[i] = max(f[i], f[i - a[j]] + 1); n   if (f[v] == 0) n     cout << -1; n   else n     while (1) { n       bool ok = 1; n       for (int i = 9; i > 0; --i) n         if (v >= a[i] && f[v] == f[v - a[i]] + 1) { n           cout << i; n           v -= a[i]; n           ok = 0; n           break; n         } n       if (ok) break; n     } n } n void process() {} n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n, x, t, c; n   cin >> n >> t >> c; n   vector<int> sizes; n   int curr = 0; n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     cin >> x; n     if (x > t) { n       if (curr != 0) { n         sizes.emplace_back(curr); n         curr = 0; n       } n     } else { n       curr++; n     } n   } n   if (curr != 0) { n     sizes.emplace_back(curr); n   } n   for (auto sz : sizes) { n     ans += max(sz - c + 1, 0); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e4 + 5; n const int maxk = 505; n int N, d; n int dp[maxn][maxk], gem[maxn], vis[maxn][maxk]; n int dfs(int pos, int prev) { n   int jj = prev - (d - 250); n   if (pos > 30000) return 0; n   if (vis[pos][jj]) return dp[pos][jj]; n   vis[pos][jj] = 1; n   int ans = 0; n   if (prev == 1) n     ans = max(ans, max(dfs(pos + 1, 1), dfs(pos + 2, 2))); n   else n     ans = max(ans, n               max(dfs(pos + prev - 1, prev - 1), n                   max(dfs(pos + prev, prev), dfs(pos + prev + 1, prev + 1)))); n   return dp[pos][jj] = ans + gem[pos]; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> N >> d; n   for (int i = 1; i <= N; i++) { n     int p; n     cin >> p; n     gem[p]++; n   } n   cout << dfs(d, d) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k, j = 0, oo = 1; n   cin >> n >> k; n   while (k != j) { n     oo *= 10; n     j++; n   } n   long long int prod = oo * n; n   while (oo != n) { n     if (oo > n) { n       oo %= n; n       if (oo == 0) oo = n; n     } else { n       n %= oo; n       if (n == 0) n = oo; n     } n   } n   cout << prod / oo; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 100100; n long long n, m, k; n vector<long long> g[maxn]; n long long mark[maxn]; n long long d[maxn]; n vector<long long> q; n bool check(long long x, bool print = false) { n   for (long long i = 0; i < n; i++) n     if (mark[i] != 1) mark[i] = 0; n   q.resize(0); n   for (long long i = 0; i < n; i++) d[i] = 0; n   for (long long i = 0; i < n; i++) n     for (long long u : g[i]) n       if (!mark[u]) d[i]++; n   for (long long i = 0; i < n; i++) n     if (!mark[i] and d[i] * 1000000000 < g[i].size() * x) n       q.push_back(i), mark[i] = 2; n   for (long long i = 0; i < q.size(); i++) { n     long long v = q[i]; n     mark[v] = 2; n     for (long long u : g[v]) n       if (!mark[u]) { n         d[u]--; n         if (d[u] * 1000000000 < g[u].size() * x and !mark[u]) n           q.push_back(u), mark[u] = 2; n       } n   } n   long long cnt = 0; n   for (long long i = 0; i < n; i++) cnt += !mark[i]; n   if (print) { n     cout << cnt << endl; n     for (long long i = 0; i < n; i++) n       if (!mark[i]) cout << i + 1 <<    ; n     cout << endl; n   } n   return cnt; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m >> k; n   for (long long v, i = 0; i < k; i++) { n     cin >> v; n     v--; n     mark[v] = 1; n   } n   for (long long v, u, i = 0; i < m; i++) { n     cin >> v >> u; n     v--, u--; n     g[v].push_back(u); n     g[u].push_back(v); n   } n   for (long long i = 0; i < n; i++) n     if (!g[i].size()) mark[i] = 1; n   long long l = 0, r = 1000000000 + 1, mid; n   for (long long c = 100; c--;) { n     mid = (l + r) / 2; n     if (check(mid)) n       l = mid; n     else n       r = mid; n   } n   check(l, 1); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n const double PI = acos(-1.0); n using namespace std; n const double EPS = 1e-9; n const int N = 2e5 + 9; n int a[N], n, p, k; n long long sum[N], v[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> p >> k; n     for (int i = 1; i <= n; i++) cin >> a[i], v[i] = 0; n     sort(a + 1, a + 1 + n); n     for (int i = 1; i <= n; i++) sum[i] = a[i] + sum[i - 1]; n     for (int i = k; i <= n; i++) { n       v[i] = a[i] + v[i - k]; n     } n     long long ans = 0; n     for (int i = 1; i <= n; i++) { n       if (v[i] + sum[i % k] <= p) ans = i; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[150]; n int main() { n   int n, k, i, j, ans = 0, curr, temp; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &curr); n     arr[curr]++; n   } n   for (i = 1; i <= 100; i++) { n     ans += (arr[i] / 2); n   } n   ans /= 2; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a = 0, b = 0, ans = 0, mid; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> mid; n     if (mid == 2) n       a++; n     else n       b++; n   } n   if (a > b) n     ans = b; n   else { n     ans = a; n     b = b - a; n     ans += b / 3; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e3 + 100; n int k; n long long a[20][maxn]; n int nk[20]; n map<long long, pair<int, int> > mp; n long long sum = 0; n bool _is[1 << 17]; n long long tol[20]; n bool _a[20][maxn]; n vector<pair<int, int> > que; n vector<vector<pair<int, int> > > dp[1 << 17]; n pair<int, int> ans[20]; n void dfs(int fir, int i, int j, int sta, int &flag) { n   if (a[i][j] == fir) { n     if (_a[i][j] && !_is[sta]) { n       _is[sta] = 1; n       flag = 1; n       dp[sta].push_back(que); n       return; n     } n   } n   if (_a[i][j]) return; n   long long tmp = sum - (tol[i] - a[i][j]); n   if (mp.find(tmp) == mp.end()) { n     return; n   } n   int tfir = mp[tmp].first; n   int tsec = mp[tmp].second; n   if (sta >> tfir & 1) { n     return; n   } n   _a[i][j] = 1; n   que.push_back({tmp, i}); n   dfs(fir, tfir, tsec, sta | 1 << tfir, flag); n   que.pop_back(); n   if (!flag) _a[i][j] = 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> k; n   for (int i = 0; i < k; ++i) { n     cin >> nk[i]; n     for (int j = 0; j < nk[i]; ++j) { n       cin >> a[i][j]; n       mp[a[i][j]] = {i, j}; n       sum += a[i][j]; n       tol[i] += a[i][j]; n     } n   } n   if (sum % k) { n     cout <<  No  << endl; n   } else { n     sum /= k; n     for (int i = 0; i < k; ++i) { n       for (int j = 0; j < nk[i]; ++j) { n         if (_a[i][j]) continue; n         int tmp = 0; n         dfs(a[i][j], i, j, 0, tmp); n       } n     } n     for (int i = 1; i < 1 << k; ++i) { n       if (!_is[i]) { n         for (int j = i; j; j = j - 1 & i) { n           if (_is[j] && _is[i ^ j]) { n             for (auto l : dp[j]) { n               dp[i].push_back(l); n             } n             for (auto l : dp[i ^ j]) { n               dp[i].push_back(l); n             } n             _is[i] = 1; n             break; n           } n         } n       } n     } n     if (_is[(1 << k) - 1]) { n       cout <<  Yes  << endl; n       for (auto i : dp[(1 << k) - 1]) { n         for (auto j : i) { n           ans[mp[j.first].first] = j; n         } n       } n       for (int i = 0; i < k; ++i) { n         cout << ans[i].first <<     << ans[i].second + 1 << endl; n       } n     } else { n       cout <<  No  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l; n   float p, q, t, res; n   cin >> l >> p >> q; n   t = l / (p + q); n   res = p * t; n   printf( %.4f , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n mt19937 rnf(2106); n const int N = 200005, M = 1000000007, K = 1000006; n int ast(int x, int n) { n   int ans = 1; n   while (n) { n     if (n % 2 == 1) ans = (ans * 1LL * x) % M; n     x = (x * 1LL * x) % M; n     n /= 2; n   } n   return ans; n } n int u[K]; n int f[K], rf[K], r[K]; n void pre() { n   for (int i = 2; i < K; ++i) { n     if (u[i]) continue; n     for (int j = i; j < K; j += i) { n       if (!u[j]) u[j] = i; n     } n   } n   f[0] = 1; n   for (int i = 1; i < K; ++i) f[i] = (f[i - 1] * 1LL * i) % M; n   rf[K - 1] = ast(f[K - 1], M - 2); n   for (int i = K - 2; i >= 0; --i) rf[i] = (rf[i + 1] * 1LL * (i + 1)) % M; n   for (int i = 1; i < K; ++i) r[i] = (rf[i] * 1LL * f[i - 1]) % M; n } n int n; n int a[N]; n vector<pair<int, int> > v[N]; n int t[N * 4]; n void bil(int tl, int tr, int pos) { n   if (tl == tr) { n     t[pos] = a[tl]; n     return; n   } n   int m = (tl + tr) / 2; n   bil(tl, m, pos * 2); n   bil(m + 1, tr, pos * 2 + 1); n   t[pos] = (t[pos * 2] * 1LL * t[pos * 2 + 1]) % M; n } n void ubd(int tl, int tr, int x, int y, int pos) { n   if (tl == tr) { n     t[pos] = (t[pos] * 1LL * y) % M; n     return; n   } n   int m = (tl + tr) / 2; n   if (x <= m) n     ubd(tl, m, x, y, pos * 2); n   else n     ubd(m + 1, tr, x, y, pos * 2 + 1); n   t[pos] = (t[pos * 2] * 1LL * t[pos * 2 + 1]) % M; n } n int qry(int tl, int tr, int l, int r, int pos) { n   if (l > r) return 1; n   if (tl == l && tr == r) return t[pos]; n   int m = (tl + tr) / 2; n   return (qry(tl, m, l, min(m, r), pos * 2) * 1LL * n           qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1)) % n          M; n } n int h[K]; n int ans[N]; n void solv() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   int qq; n   scanf( %d , &qq); n   for (int i = 0; i < qq; ++i) { n     int l, r; n     scanf( %d%d , &l, &r); n     v[r].push_back(make_pair(l, i)); n   } n   bil(1, n, 1); n   for (int i = 1; i <= n; ++i) { n     int x = a[i]; n     while (x > 1) { n       if (h[u[x]]) ubd(1, n, h[u[x]], (u[x] * 1LL * r[u[x] - 1]) % M, 1); n       h[u[x]] = i; n       ubd(1, n, h[u[x]], (1 - r[u[x]] + M) % M, 1); n       x /= u[x]; n     } n     for (int j = 0; j < v[i].size(); ++j) { n       ans[v[i][j].second] = qry(1, n, v[i][j].first, i, 1); n     } n   } n   for (int i = 0; i < qq; ++i) printf( %d n , ans[i]); n } n int main() { n   pre(); n   solv(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 505; n const int mod = 1e9 + 7; n long long int dp[1005][1005] = {0}; n int main() { n   long long int n, m, k; n   cin >> n >> m >> k; n   if (2 * k > n - 1 || 2 * k > m - 1) n     cout << 0 << endl; n   else { n     dp[0][0] = 1; n     for (int i = 1; i <= 1000; i++) { n       dp[i][0] = 1; n       dp[i][i] = 1; n       for (int j = 1; j <= i; j++) { n         dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod; n       } n     } n     cout << ((dp[n - 1][2 * k] % mod) * (dp[m - 1][2 * k] % mod)) % mod << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   int weight[n + 1]; n   int stacked[m + 1]; n   for (int i = 1; i <= n; i++) { n     cin >> weight[i]; n   } n   for (int i = 1; i <= m; i++) { n     cin >> stacked[i]; n   } n   bool vis[n + 1]; n   memset(vis, false, sizeof(vis)); n   int ans = 0; n   for (int i = 2; i <= m; i++) { n     memset(vis, false, sizeof(vis)); n     for (int j = i - 1; j >= 1; j--) { n       if (stacked[j] == stacked[i]) break; n       if (!vis[stacked[j]]) { n         ans += weight[stacked[j]]; n         vis[stacked[j]] = true; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n inline long long sub(long long &a, long long b) { n   a -= b; n   if (a < 0) { n     a += MOD; n   } n } n inline long long mult(long long a, long long b) { return (a * 1ll * b) % MOD; } n inline long long b_pow(long long a, long long p) { n   long long cur = a, ans = 1; n   while (p > 0) { n     if (p & 1) { n       ans = mult(ans, cur); n     } n     p /= 2; n     cur = mult(cur, cur); n   } n   return ans; n } n const long long lim = 1e6; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long T; n   cin >> T; n   while (T--) { n     long long n, p; n     cin >> n >> p; n     if (p == 1) { n       for (long long i = 0; i < n; i++) { n         long long x; n         cin >> x; n       } n       cout << (n & 1) <<   n ; n       continue; n     } n     map<long long, long long> cnt; n     for (long long i = 0; i < n; i++) { n       long long x; n       cin >> x; n       cnt[x]++; n     } n     auto it = --cnt.end(); n     long long ans = 0, need = 0; n     for (;;) { n       if (it->second >= need) { n         it->second -= need; n         need = 0; n         ans = 0; n       } else { n         sub(ans, mult(it->second, b_pow(p, it->first))); n         need -= it->second; n         it->second = 0; n       } n       if (it->second & 1) { n         need = 1; n         ans = b_pow(p, it->first); n       } n       if (it == cnt.begin()) { n         break; n       } else { n         long long was = it->first; n         it--; n         if (need > 0) { n           while (need < 1e6 && was != it->first) { n             need *= p; n             was--; n           } n         } n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct superset { n   multiset<int> m; n   void insert(int x) { m.insert(x); } n   void erase(int x) { m.erase(m.find(x)); } n   int query() { return *m.begin(); } n }; n int n, m; n int val[65536 * 4]; n superset cl[65536 * 4]; n vector<int> g[65536 * 4]; n vector<int> lis[65536 * 4]; n int dfn[65536 * 4]; n int DFN; n int low[65536 * 4]; n int st[65536 * 4], stsiz; n int tot; n vector<int> v[65536 * 4]; n void addedge(int x, int y) { n   v[x].push_back(y); n   v[y].push_back(x); n } n void tarjan(int x, int p) { n   st[++stsiz] = x; n   dfn[x] = low[x] = ++DFN; n   for (int i = 0; i < g[x].size(); i++) { n     int y = g[x][i]; n     if (y == p) continue; n     if (!dfn[y]) { n       tarjan(y, x); n       if (low[y] >= dfn[x]) { n         ++tot; n         while (st[stsiz] != y) lis[tot].push_back(st[stsiz--]); n         stsiz--; n         lis[tot].push_back(y); n         lis[tot].push_back(x); n         for (int j = 0; j < lis[tot].size(); j++) addedge(lis[tot][j], tot); n       } n       low[x] = min(low[x], low[y]); n     } else n       low[x] = min(low[x], dfn[y]); n   } n } n struct segmenttree { n   int tree[65536 * 4 * 2 + 10]; n   void up(int id) { tree[id] = min(tree[id << 1], tree[id << 1 | 1]); } n   void update(int x, int y) { n     x = x + 65536 * 4 - 1; n     tree[x] = y; n     x = x / 2; n     while (x) up(x), x = x / 2; n   } n   int query(int a, int b, int l, int r, int id) { n     if (l >= a and r <= b) return tree[id]; n     if (b <= (l + r) / 2) n       return query(a, b, l, (l + r) / 2, id << 1); n     else if (a > (l + r) / 2) n       return query(a, b, (l + r) / 2 + 1, r, id << 1 | 1); n     else n       return min(query(a, b, l, (l + r) / 2, id << 1), n                  query(a, b, (l + r) / 2 + 1, r, id << 1 | 1)); n   } n   int query(int a, int b) { return query(a, b, 1, 65536 * 4, 1); } n } trcyx; n int pa[65536 * 4]; n int son[65536 * 4]; n int siz[65536 * 4]; n int lead[65536 * 4]; n int len[65536 * 4]; n int dep[65536 * 4]; n void dfs1(int x, int p) { n   siz[x] = 1; n   dep[x] = dep[p] + 1; n   for (int i = 0; i < v[x].size(); i++) { n     if (v[x][i] == p) continue; n     dfs1(v[x][i], x); n     siz[x] += siz[v[x][i]]; n     if (siz[v[x][i]] > siz[son[x]]) son[x] = v[x][i]; n   } n } n void dfs2(int x, int p, int leader) { n   dfn[x] = ++DFN; n   pa[x] = p; n   if (!leader) leader = x; n   lead[x] = leader, len[leader]++; n   if (son[x]) dfs2(son[x], x, leader); n   for (int i = 0; i < v[x].size(); i++) n     if (v[x][i] != son[x] and v[x][i] != p) dfs2(v[x][i], x, 0); n   if (lis[x].size()) { n     for (int i = 0; i < lis[x].size(); i++) n       if (lis[x][i] != pa[x]) cl[x].insert(val[lis[x][i]]); n     val[x] = cl[x].query(); n   } n   trcyx.update(dfn[x], val[x]); n } n void build() { n   tot = n; n   tarjan(1, 0); n   dfs1(1, 0); n   memset(dfn, 0, sizeof(dfn)); n   DFN = 0; n   dfs2(1, 0, 0); n } n int solve(int x, int y) { n   int ans = 1e9; n   while (lead[x] != lead[y]) { n     if (dep[lead[x]] < dep[lead[y]]) swap(x, y); n     ans = min(ans, trcyx.query(dfn[lead[x]], dfn[x])); n     x = pa[lead[x]]; n   } n   if (dfn[x] > dfn[y]) swap(x, y); n   ans = min(ans, trcyx.query(dfn[x], dfn[y])); n   if (lis[x].size()) ans = min(ans, val[pa[x]]); n   return ans; n } n void change(int x, int y) { n   if (pa[x]) { n     cl[pa[x]].erase(val[x]); n     cl[pa[x]].insert(y); n     val[pa[x]] = cl[pa[x]].query(); n     trcyx.update(dfn[pa[x]], val[pa[x]]); n   } n   val[x] = y; n   trcyx.update(dfn[x], y); n } n int main() { n   int T; n   scanf( %d%d%d , &n, &m, &T); n   for (int i = 1; i <= n; i++) scanf( %d , &val[i]); n   while (m--) { n     int x, y; n     scanf( %d%d , &x, &y); n     g[x].push_back(y); n     g[y].push_back(x); n   } n   build(); n   while (T--) { n     char ctrl[10]; n     scanf( %s , ctrl); n     int x, y; n     scanf( %d%d , &x, &y); n     if (ctrl[0] ==  A ) n       printf( %d n , solve(x, y)); n     else n       change(x, y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, n; n   while (scanf( %d , &n) != EOF) { n     if (n & 1) n       printf( black n ); n     else n       printf( white n1 2 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n const double Pi = acos(-1.0); n using namespace std; n const int maxN = 100005; n const long long mod = 1000000009; n int n, m; n int par[maxN]; n int findpar(int x) { n   if (par[x] != x) par[x] = findpar(par[x]); n   return par[x]; n } n int main(int argc, char** argv) { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) par[i] = i; n   long long ans = 1; n   int a, b; n   while (m--) { n     scanf( %d %d , &a, &b); n     int pa = findpar(a), pb = findpar(b); n     if (pa == pb) n       ans = (ans * 2) % mod; n     else n       par[pb] = pa; n     printf( %lld n , ans - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void BFS(vector<vector<long long> > &graph, long long n, n          vector<long long> &order) { n   vector<long long> vis(n + 1); n   set<long long> PQ; n   PQ.insert(1); n   while (!PQ.empty()) { n     long long x = *PQ.begin(); n     PQ.erase(PQ.begin()); n     order.push_back(x); n     vis[x] = 1; n     for (long long i = 0; i < graph[x].size(); i++) { n       if (vis[graph[x][i]] == 0) PQ.insert(graph[x][i]); n     } n   } n } n int main() { n   long long n, m, i, j, k, l, w, u, v, t_sum = 0; n   cin >> n >> m; n   vector<vector<long long> > graph(n + 1); n   for (i = 1; i <= m; i++) { n     cin >> u >> v; n     graph[u].push_back(v); n     graph[v].push_back(u); n   } n   vector<long long> order; n   BFS(graph, n, order); n   for (i = 0; i < order.size(); i++) cout << order[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n const int N = 10005; n int f[N][2005]; n int main() { n   int _; n   scanf( %d , &_); n   for (int j = 1; j <= 1000; j++) { n     f[0][j] = INF; n   } n   while (_--) { n     int n; n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) { n       int x; n       scanf( %d , &x); n       for (int j = 0; j <= 2000; j++) { n         f[i][j] = INF; n       } n       for (int j = 0; j <= 2000; j++) { n         f[i][max(0, j - x)] = min(f[i][max(0, j - x)], f[i - 1][j] + x); n         if (j + x <= 2000) n           f[i][j + x] = min(f[i][j + x], max(0, f[i - 1][j] - x)); n       } n     } n     int ans = INF; n     for (int j = 0; j <= 1000; j++) { n       ans = min(ans, f[n][j] + j); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getint() { n   int res = 0, fh = 1; n   char ch = getchar(); n   while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) fh = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar(); n   return fh * res; n } n string s; n int like[20]; n int main() { n   int F = getint(), I = getint(), T = getint(); n   for (int i = 1; i <= F; i++) { n     getline(cin, s); n     for (int j = 0; j < I; j++) like[j + 1] += (s[j] ==  Y ); n   } n   int ans = 0; n   for (int i = 1; i <= I; i++) n     if (like[i] >= T) ans++; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n const long long N = 5e6 + 3; n long long dp[N]; n int main(void) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   string str; n   unsigned long long temp = 1, p = 0, q = 0; n   cin >> str; n   long long ans = 0; n   long long pppp = str.size(); n   for (int i = 0; i < str.size(); i++) { n     p = (p * 131 + str[i]) % mod; n     q = (temp * (str[i]) + q) % mod; n     ; n     temp *= 131; n     temp %= mod; n     if (p == q) { n       if (i == 0) n         dp[i]++, ans += dp[i]; n       else { n         dp[i] = dp[(i - 1) / 2] + 1; n         ans += dp[i]; n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 100005, inf = 1000000005, MOD = 1000000007; n const long long INF = 1000000000000000005LL; n int t[100]; n int suma(int i) { n   int y = min(t[i], t[i + 2]), a = t[i + 1]; n   int res = (y + a) * (y + a) - a * a; n   int d = max(t[i], t[i + 2]) - y; n   res += (d * (a + y)); n   return res; n } n int main() { n   for (int i = 1; i <= 6; ++i) scanf( %d , &t[i]); n   int ans = suma(1) + suma(4); n   printf( %d , ans); n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long int n #define endl   n  n void solve() n { n     int n,start=0; n     cin>>n; n     int end=n; n     int arr[n],pos[n+1]; n     for(int i=0 ; i<n;i++) n     { n     cin>>arr[i]; n     pos[arr[i]]=i; n     } n     for(int i=n;i>0;i--) n     { n         start = pos[i]; n         if(end>start) n         { n             for(int j=start ; j<end ; j++) n             { n                 cout<<arr[j]<<   ; n             } n         end = start; n         } n     } n     cout<<endl; n } n  n int main() n { n int t; n cin>>t; n while(t--) n { n solve(); n } n return 0; n }


#include <bits/stdc++.h> n using namespace std; n template <typename... T> n void read(T&... args) { n   ((cin >> args), ...); n } n template <typename... T> n void write(T&&... args) { n   ((cout << args <<    ), ...); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, ans(0); n   read(n); n   vector<long long> arr(n + 1, 0); n   for (long long i = 1; i < n + 1; ++i) { n     read(arr[i]); n     arr[i] += arr[i - 1]; n   } n   long long start(0), end(0); n   set<long long> s = {0}; n   while (start < n) { n     while (end < n && !s.count(arr[end + 1])) { n       ++end; n       s.insert(arr[end]); n     } n     ans += end - start; n     s.erase(arr[start]); n     ++start; n   } n   cout << ans <<   n ; n   arr.clear(); n   s.clear(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxN = 1e6; n int n, m, p, a[mxN]; n long long s1[1 << 21]; n vector<long long> s2[1 << 21]; n void bld(int i = 1, int l = 0, int r = n - 1) { n   if (l == r) { n     s1[i] = a[l]; n     s2[i] = {p - a[l], 1ll << 60}; n     return; n   } n   int m = (l + r) / 2; n   bld(2 * i, l, m); n   bld(2 * i + 1, m + 1, r); n   s1[i] = s1[2 * i] + s1[2 * i + 1]; n   long long cs = s1[2 * i]; n   for (int i1 = 0, i2 = 0; n        i1 < s2[2 * i].size() - 1 || i2 < s2[2 * i + 1].size() - 1;) { n     if (s2[2 * i][i1] + cs < s2[2 * i + 1][i2]) { n       if (s2[i].size() && s2[i].back() > s2[2 * i][i1] - p) n         s2[i].push_back(s2[i].back() + p); n       else n         s2[i].push_back(s2[2 * i][i1]); n       cs -= p; n       ++i1; n     } else n       s2[i].push_back(s2[2 * i + 1][i2++] - cs); n   } n   s2[i].push_back(1ll << 60); n } n long long qry(int l1, int r1, long long x, int i = 1, int l2 = 0, n               int r2 = n - 1) { n   if (l1 <= l2 && r2 <= r1) n     return x + s1[i] - n            (long long)(upper_bound(s2[i].begin(), s2[i].end(), x) - n                        s2[i].begin()) * n                p; n   int m2 = (l2 + r2) / 2; n   if (r1 <= m2) return qry(l1, r1, x, 2 * i, l2, m2); n   if (m2 < l1) return qry(l1, r1, x, 2 * i + 1, m2 + 1, r2); n   return qry(l1, r1, qry(l1, r1, x, 2 * i, l2, m2), 2 * i + 1, m2 + 1, r2); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m >> p; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   bld(); n   for (int l, r; m--;) { n     cin >> l >> r, --l, --r; n     cout << qry(l, r, 0) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 405; n double f[maxn], g[maxn], ans; n int n, m, dis[maxn][maxn], q[maxn]; n int main() { n   scanf( %d%d , &n, &m); n   memset(dis, 127 / 3, sizeof(dis)); n   for (int i = 1; i <= n; i++) { n     dis[i][i] = 0; n   } n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     dis[u][v] = dis[v][u] = 1; n   } n   for (int k = 1; k <= n; k++) { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     double temp = 0; n     for (int j = 0; j < n; j++) { n       int u = 0; n       memset(f, 0, sizeof(f)); n       for (int k = 1; k <= n; k++) { n         if (dis[i][k] == j) { n           u++; n           int x = 0; n           for (int kk = 1; kk <= n; kk++) { n             if (dis[k][kk] == 1) { n               x++; n             } n           } n           for (int kk = 1; kk <= n; kk++) { n             if (dis[k][kk] == 1) { n               f[kk] += 1.0 / x; n             } n           } n         } n       } n       int v = 0; n       for (int k = 1; k <= n; k++) { n         if (abs(dis[i][k] - j) <= 1) { n           q[++v] = k; n         } n       } n       double res = 0; n       for (int k = 1; k <= n; k++) { n         for (int kk = 1; kk <= v; kk++) { n           if (f[q[kk]] > g[dis[k][q[kk]]]) { n             g[dis[k][q[kk]]] = f[q[kk]]; n           } n         } n         double w = 0; n         for (int kk = 1; kk <= v; kk++) { n           w += g[dis[k][q[kk]]]; n           g[dis[k][q[kk]]] = 0; n         } n         res = max(res, w); n       } n       if (u) { n         res = max(res, 1.0); n       } n       temp += res / n; n     } n     ans = max(ans, temp); n   } n   printf( %.12lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> g[(long long)3e5], a((long long)3e5); n long long i, n, x, y, r; n void b(long long p, long long q, long long m) { n   a[p]++, r += m; n   for (auto j : g[p]) n     if (j != q) b(j, p, m ^ 1), a[p] += a[j]; n } n int main() { n   for (cin >> n, i = 1; i < n; i++) n     cin >> x >> y, g[x].push_back(y), g[y].push_back(x); n   b(1, 0, 0), r *= (n - r); n   for (i = 1; i <= n; i++) r += a[i] * (n - a[i]); n   cout << r / 2; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; n const long long INF = 0x7fffffffffffffff; n const double eps = 1e-8; n unsigned int seed = 19260817; n const unsigned int _RAND_MAX_ = 4294967295u; n __inline__ __attribute__((always_inline)) unsigned int Rand() { n   return seed = seed * 998244353u + 1000000007u; n } n template <typename _Tp> n _Tp gcd(const _Tp &a, const _Tp &b) { n   return (!b) ? a : gcd(b, a % b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) { n   return a > 0 ? a : -a; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b) { n   return a < b ? b : a; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b) { n   return a < b ? a : b; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) { n   (a < b) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) { n   (a > b) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) bool _cmp(const _Tp &a, n                                                     const _Tp &b) { n   return abs(a - b) <= eps; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void read(_Tp &x) { n   register char ch(getchar()); n   bool f(false); n   while (ch < 48 || ch > 57) f |= ch == 45, ch = getchar(); n   x = ch & 15, ch = getchar(); n   while (ch >= 48 && ch <= 57) n     x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar(); n   if (f) x = -x; n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) { n   read(t); n   read(args...); n } n __inline__ __attribute__((always_inline)) int read_str(char *s) { n   register char ch(getchar()); n   while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar(); n   register char *tar = s; n   *tar = ch, ch = getchar(); n   while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF) n     *(++tar) = ch, ch = getchar(); n   return tar - s + 1; n } n const int N = 1200005; n struct node { n   bool l, r; n   int ans; n   __inline__ __attribute__((always_inline)) node operator+( n       const node &o) const { n     return (node){l, o.r, ans + o.ans - (r == o.l)}; n   } n }; n int L[N], R[N]; n int t[N]; n int a[N]; n struct seg_tr { n   struct Node { n     int ls, rs; n     node val1, val2; n     bool tag; n   } f[N << 1]; n   int node_cnt; n   __inline__ __attribute__((always_inline)) void PushUp(int x) { n     f[x].val1 = f[f[x].ls].val1 + f[f[x].rs].val1; n     f[x].val2 = f[f[x].ls].val2 + f[f[x].rs].val2; n   } n   int build(int l, int r) { n     int cur = ++node_cnt; n     f[cur].tag = 0; n     if (l == r) { n       f[cur].ls = f[cur].rs = 0; n       f[cur].val1 = (node){a[l] == 0, a[l] == 0, 1}; n       f[cur].val2 = (node){a[l] == 1, a[l] == 1, 1}; n       return cur; n     } n     int mid = (l + r) >> 1; n     f[cur].ls = build(l, mid); n     f[cur].rs = build(mid + 1, r); n     PushUp(cur); n     return cur; n   } n   __inline__ __attribute__((always_inline)) void upd(int cur) { n     f[cur].tag ^= 1; n     std::swap(f[cur].val1, f[cur].val2); n   } n   __inline__ __attribute__((always_inline)) void PushDown(int cur) { n     if (f[cur].tag) { n       upd(f[cur].ls); n       upd(f[cur].rs); n       f[cur].tag = 0; n     } n   } n   void Update(int L, int R, int l, int r, int cur) { n     if (L <= l && r <= R) { n       upd(cur); n       return; n     } n     PushDown(cur); n     int mid = (l + r) >> 1; n     if (L <= mid) Update(L, R, l, mid, f[cur].ls); n     if (R > mid) Update(L, R, mid + 1, r, f[cur].rs); n     PushUp(cur); n   } n   __inline__ __attribute__((always_inline)) int Query() { n     return f[1].val1.ans; n   } n } tr; n void MAIN() { n   tr.node_cnt = 0; n   int n; n   read(n); n   int len = 0; n   for (int i = 1; i <= n; ++i) { n     read(L[i], R[i]); n     t[++len] = L[i]; n     t[++len] = R[i]; n   } n   std::sort(t + 1, t + len + 1); n   len = std::unique(t + 1, t + len + 1) - t - 1; n   memset(a, 0, 8 * (len + 2)); n   for (int i = 1; i <= n; ++i) { n     L[i] = std::lower_bound(t + 1, t + len + 1, L[i]) - t; n     R[i] = std::lower_bound(t + 1, t + len + 1, R[i]) - t; n     L[i] <<= 1; n     R[i] <<= 1; n     ++a[L[i]]; n     --a[R[i] + 1]; n   } n   len <<= 1; n   for (int i = 1; i <= len; ++i) a[i] += a[i - 1]; n   int root = tr.build(1, len); n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     tr.Update(L[i], R[i], 1, len, root); n     chmax(ans, tr.Query() >> 1); n     tr.Update(L[i], R[i], 1, len, root); n   } n   printf( %d n , ans); n } n int main() { n   int _; n   read(_); n   while (_--) MAIN(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int tests; n   cin >> tests; n   while (tests--) { n     int n, s, t; n     cin >> n >> s >> t; n     cout << min(max(s, t) + 1 - (s + t - n), n + (n - s - t) + 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[200010]; n int n, m, head[200010], o = 0, x[2], id[200010], sz[200010], cnt = 0, n                         tree[800010], tag[800010]; n bool isnt_rt[200010]; n vector<vector<int> > w; n struct edge { n   int to, link; n } e[200010]; n struct seg { n   int x, l, r, id; n   bool operator<(const seg &b) const { return x < b.x; } n } sg[200010]; n void add_edge(int u, int v) { n   e[++o].to = v, e[o].link = head[u], head[u] = o, isnt_rt[v] = true; n } n void dfs(int u, int k) { n   id[u] = ++x[k], sz[u] = 1; n   for (int i = head[u]; i; i = e[i].link) { n     dfs(e[i].to, k); n     sz[u] += sz[e[i].to]; n   } n } n void pushup(int l, int r, int t) { n   if (tag[t] > 0) return tree[t] = (r - l + 1), void(); n   if (l == r) return tree[t] = 0, void(); n   tree[t] = tree[t << 1] + tree[t << 1 | 1]; n } n void add(int ll, int rr, int l, int r, int t, int c) { n   if (ll <= l && r <= rr) { n     tag[t] += c; n     pushup(l, r, t); n     return; n   } n   int mid = (l + r) >> 1; n   if (ll <= mid) add(ll, rr, l, mid, t << 1, c); n   if (mid < rr) add(ll, rr, mid + 1, r, t << 1 | 1, c); n   pushup(l, r, t); n } n int main() { n   scanf( %d%d , &n, &m), w.resize(n + 1); n   for (int i = 1; i <= n; i++) { n     w[i].resize(m + 1); n     scanf( %s , s + 1); n     for (int j = 1; j <= m; j++) { n       if (s[j] ==  L ) w[i][j] = 1; n       if (s[j] ==  U ) w[i][j] = 2; n       if (s[j] ==  L  && j + 2 <= m) n         add_edge(((i)-1) * m + (j + 2), ((i)-1) * m + (j)); n       if (s[j] ==  R  && j - 2 >= 1) n         add_edge(((i)-1) * m + (j - 2), ((i)-1) * m + (j)); n       if (s[j] ==  U  && i + 2 <= n) n         add_edge(((i + 2) - 1) * m + (j), ((i)-1) * m + (j)); n       if (s[j] ==  D  && i - 2 >= 1) n         add_edge(((i - 2) - 1) * m + (j), ((i)-1) * m + (j)); n     } n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (isnt_rt[((i)-1) * m + (j)]) continue; n       dfs(((i)-1) * m + (j), (i + j) & 1); n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       int u, v; n       if (w[i][j] == 1) { n         u = ((i)-1) * m + (j), v = ((i)-1) * m + (j + 1); n         if ((i + j) & 1) swap(u, v); n       } else if (w[i][j] == 2) { n         u = ((i)-1) * m + (j), v = ((i + 1) - 1) * m + (j); n         if ((i + j) & 1) swap(u, v); n       } else n         continue; n       sg[++cnt] = (seg){id[u], id[v], id[v] + sz[v] - 1, 1}; n       sg[++cnt] = (seg){id[u] + sz[u], id[v], id[v] + sz[v] - 1, -1}; n     } n   sort(sg + 1, sg + cnt + 1); n   long long ans = 0; n   for (int i = 1, j = 1; i <= x[0]; i++) { n     while (sg[j].x <= i && j <= cnt) { n       add(sg[j].l, sg[j].r, 1, x[1], 1, sg[j].id); n       j++; n     } n     ans += tree[1]; n   } n   printf( %lld n , ans); n } n


/* n ``````````````````$$$$$ n `````````````$$$$$$´´´´$$$$$$ n ``````````$$$´´´´´´´´´´´´´´´´$$$ n ````````$`$$´´´´´´´´´´´´´´´´´´´´$$ n ```````$´$$$´´´´´´´´´´´´´´´´´´´´´$$$$ n `````$´´$$$$´´´´´´´´´´´´´´´´´´´´´´´´´´$ n ````$´´$$$$$´´´´´´´´´´$$$$$$$´´´´´´´´´$$ n ```$´´´$$$$$$$´´´$$$$$$$$$$$$$$$$$´´´´´$$ n ``$´´´´$$$$$$$$$$$$$$$$$$$$$$$$$$$$$´´´´$$ n `$´´´´´´$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$´´$ n `$´´´´´´$$$$$$$$$$$´´´´$$$$$$$$$$$$$$$$$$$ n $´´´´´´´´$$$$$$$$´´´´´´´´$$$$$$$´´´´´´´´$$ n $´´´´´´´´´$$$$$$´´´´´´´´´´$$$$´´´´´´´´´´´$ n `$´´´´´´´´´$$$$$´´´´´´´´´´$$$´´´´´´´´´´´$ n `$´´´´´´´´´´$$$$$´´´´´´´´$$$$´´´´´´´´´´´$ n `$´´´´´´´´´´´$$$$$$´´´´$$$$$´´´´´´´´´´´$$ n ``$´´´´´´´´´´´$$$$$$$$$$$$$$´´´´´´´´´´´$ n ``$$´´´´´´´´´´´´$$$$$$$$$$$$´´´´´´´´´´$$ n ```$$´´´´´´´´´´´´$$$$$$$$$$´´´´´´´´´´$$ n ````$´´´´´´´´´´´´$$$$$$$$$´´´´´´´´´´´$ n `````$´´´´´´´´´´´$$$$$$$$´´´´´´´´´´´$ n ``````$$´´´´´´´´´$$$$$$´´´´´´´´´´´$$ n ````````$$´´´´´´$$$$$´´´´´´´´´´´$$ n ``````````$$$´$$$$´´´´´´´´´´´$$$ n `````````````$$$$$´´´´´´$$$$$ n ``````````````````$$$$$$ n */ n #include  bits/stdc++.h  n   n #define ll long long int n #define pb push_back n #define F first n #define S second n #define vi vector<ll> n #define vs vector<string> n #define input(v,n) for(ll VAL=0;VAL<n;VAL++){ll VALUE;cin>>VALUE;v.pb(VALUE);} n #define mi map<ll,ll> n #define FOR(i,a,b) for(ll i=a;i<b;i++) n #define mi map<ll,ll> n #define print(v) for(ll printing=0;printing<v.size();printing++){cout<<v[printing]<<   ;} n #define TestCase ll testcase;cin>>testcase;while(testcase--) n #define bin(n) bitset<32>(n).to_string(); n #define maxv(v) *max_element(v.begin(),v.end()) n #define minv(v) *min_element(v.begin(),v.end()) n #define decimal(s) stoll(s,nullptr,2) n #define rmLead(str) str.erase(0, min(str.find_first_not_of( 0 ), str.size()-1)); n using namespace std; n  n void solve(){ n     ll n,c;cin>>n>>c; n     vi a(n),b(n-1); n     for(auto &i:a)  cin>>i; n     for(auto &i:b)  cin>>i; n     b.pb(0); n     ll prev_val = 0,prev_day=0; n     ll ans = 1e18; n     for(ll i=0;i<n;i++){ n         ll x = (c-prev_val+a[i]-1)/a[i]; n         ans = min(prev_day+max(x,(ll)0),ans); n         x = max((ll)0,(b[i]-prev_val+a[i]-1)/a[i]); n  n         prev_day+=x+1; n         prev_val+=x*a[i]-b[i];   n     } n     // ll x = (c-prev_val+a[n-1]-1)/a[n-1]; n     // ans = min(ans,prev_day+max(x,(ll)0)); n     //print(dp); n     cout<<ans<<  n ; n  n } n   n int main(){ n ios_base::sync_with_stdio(false);  n cin.tie(NULL); n cout.tie(NULL); n TestCase n solve(); n }


#include <bits/stdc++.h> n using namespace std; n int t, n, m, k, a[105][105], h, a1, a2, cnt, ans[105][105], pos, ch; n char c[105][105]; n string s; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> t; n   while (t--) { n     h = 0; n     pos = 0; n     cin >> n >> m >> k; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cin >> c[i][j]; n         if (c[i][j] ==  R ) { n           a[i][j] = 1; n           h++; n         } else { n           a[i][j] = 0; n         } n       } n     } n     a1 = h % k; n     a2 = k - h % k; n     cnt = 0; n     ch = 0; n     for (int i = 0; i < n; i++) { n       if (i % 2 == 0) { n         for (int j = 0; j < m; j++) { n           if (ch) { n             if (a[i][j] == 0) { n               ans[i][j] = pos; n             } else { n               pos++; n               ans[i][j] = pos; n               cnt++; n               ch = 0; n             } n             if (a1 == 0) { n               if (cnt == h / k) { n                 ch = 1; n                 cnt = 0; n               } n             } n           } else { n             if (a[i][j]) { n               cnt++; n             } n             ans[i][j] = pos; n             if (a1 > 0) { n               if (cnt == h / k + 1) { n                 cnt = 0; n                 ch = 1; n                 a1--; n               } n             } else { n               if (cnt == h / k) { n                 cnt = 0; n                 ch = 1; n               } n             } n           } n         } n       } else { n         for (int j = m - 1; j >= 0; j--) { n           if (ch) { n             if (a[i][j] == 0) { n               ans[i][j] = pos; n             } else { n               pos++; n               ans[i][j] = pos; n               cnt++; n               ch = 0; n             } n             if (a1 == 0) { n               if (cnt == h / k) { n                 ch = 1; n                 cnt = 0; n               } n             } n           } else { n             if (a[i][j]) { n               cnt++; n             } n             ans[i][j] = pos; n             if (a1 > 0) { n               if (cnt == h / k + 1) { n                 cnt = 0; n                 a1--; n                 ch = 1; n               } n             } else { n               if (cnt == h / k) { n                 cnt = 0; n                 ch = 1; n               } n             } n           } n         } n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (ans[i][j] <= 9) { n           cout << ans[i][j]; n         } else if (ans[i][j] <= 35) { n           char cc = ans[i][j] - 10 +  a ; n           cout << cc; n         } else { n           char cc = ans[i][j] - 36 +  A ; n           cout << cc; n         } n       } n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, f, h = 0, z = 0, x = 0; n   char a[100]; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> a[i]; n   } n   while (t > 0) { n     z++; n     t = t - z; n   } n   for (int y = 0; y < z; y++) { n     h = h + y; n     cout << a[h]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-9; n const int inf = 2000000000; n const long long infLL = 9000000000000000000; n inline bool checkBit(long long n, int i) { return n & (1LL << i); } n inline long long setBit(long long n, int i) { n   return n | (1LL << i); n   ; n } n inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); } n int dx[] = {0, 0, +1, -1}; n int dy[] = {+1, -1, 0, 0}; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n inline bool isLeapYear(long long year) { n   return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); n } n inline bool isIntege(double num) { return (num == (int)num); } n inline bool collinear(int x1, int y1, int x2, int y2, int x3, int y3) { n   return (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2); n } n inline double coDist(double x1, double y1, double x2, double y2) { n   return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); n } n inline void normal(long long &a) { n   a %= 1000000007; n   (a < 0) && (a += 1000000007); n } n inline long long modMul(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   return (a * b) % 1000000007; n } n inline long long modAdd(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   return (a + b) % 1000000007; n } n inline long long modSub(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   a -= b; n   normal(a); n   return a; n } n inline long long modPow(long long b, long long p) { n   long long r = 1; n   while (p) { n     if (p & 1) r = modMul(r, b); n     b = modMul(b, b); n     p >>= 1; n   } n   return r; n } n inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); } n inline long long modDiv(long long a, long long b) { n   return modMul(a, modInverse(b)); n } n struct edge { n   int u, v, w; n }; n bool cmp(edge &a, edge &b) { return a.w < b.w; } n string to_s(int t) { n   stringstream ss; n   ss << t; n   return ss.str(); n } n bool seive[1010000]; n vector<int> prime; n void seiveGen(int limit) { n   limit += 100; n   int sqrtn = sqrt(limit); n   for (int i = 3; i <= sqrtn; i += 2) { n     if (!seive[i >> 1]) { n       for (int j = i * i; j < limit; j += i + i) { n         seive[j >> 1] = 1; n       } n     } n   } n   prime.push_back(2); n   for (int i = 3; i < limit; i += 2) { n     if (!seive[i >> 1]) prime.push_back(i); n   } n } n vector<int> PrimeF; n void primeFactorize(int n) { n   for (int i = 0; prime[i] * prime[i] <= n; i++) { n     if (n % prime[i] == 0) { n       while (n % prime[i] == 0) { n         n /= prime[i]; n         PrimeF.push_back(prime[i]); n       } n     } n   } n   if (n > 1) { n     PrimeF.push_back(n); n   } n } n template <typename first, typename second> n ostream &operator<<(ostream &os, const pair<first, second> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  } ; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename T> n ostream &operator<<(ostream &os, const multiset<T> &v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename first, typename second> n ostream &operator<<(ostream &os, const map<first, second> &v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << it->first <<   =   << it->second; n   } n   return os <<  ] ; n } n clock_t tStart = clock(); n void faltu() { cerr <<   n ; } n template <typename T> n void faltu(T a[], int n) { n   for (int i = 0; i < n; ++i) cerr << a[i] <<    ; n   cerr <<   n ; n } n template <typename T, typename... hello> n void faltu(T arg, const hello &...rest) { n   cerr << arg <<    ; n   faltu(rest...); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   long long s1, s2, x = 0; n   s1 = (n * (n + 1)) / 2; n   seiveGen(sqrt(s1 + 10000)); n   primeFactorize(s1); n   if (n <= 2) { n     return cout <<  No  <<   n , 0; n   } else { n     sort(PrimeF.begin(), PrimeF.end()); n     for (int i = 0; i < PrimeF.size(); i++) { n       if (PrimeF[i] != n) { n         s2 = PrimeF[i]; n         x = 1; n         break; n       } n     } n     if (x == 0) return cout <<  No  <<   n , 0; n     cout <<  Yes  <<   n ; n     cout << 1 <<     << s2 <<   n ; n     cout << n - 1 <<    ; n     for (int i = 1; i <= n; i++) { n       if (i != s2) cout << i <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxval = 2e6 + 6; n int b[maxval]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int a; n     scanf( %d , &a); n     b[a] = a; n   } n   for (int i = 0; i < maxval; i++) n     if (!b[i]) b[i] = b[i - 1]; n   int ans = 0; n   for (int i = 2; i < maxval / 2; i++) { n     if (b[i] == i) { n       for (int j = i - 1; j < maxval; j += i) { n         if (j < maxval && i <= b[j] && ans < b[j] % i) ans = b[j] % i; n       } n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, i, m, j, x; n   cin >> n >> m; n   long long a[n][m], lowR[n][m], highR[n][m], lowC[n][m], highC[n][m]; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) cin >> a[i][j]; n   } n   for (i = 0; i < n; i++) { n     vector<long long> v, v1; n     for (j = 0; j < m; j++) { n       v.push_back(a[i][j]); n     } n     sort(v.begin(), v.end()); n     v1.push_back(v[0]); n     for (j = 1; j < v.size(); j++) { n       if (v[j] != v[j - 1]) v1.push_back(v[j]); n     } n     for (j = 0; j < m; j++) { n       lowR[i][j] = lower_bound(v1.begin(), v1.end(), a[i][j]) - v1.begin(); n       highR[i][j] = v1.size() - lowR[i][j] - 1; n     } n   } n   for (i = 0; i < m; i++) { n     vector<long long> v, v1; n     for (j = 0; j < n; j++) { n       v.push_back(a[j][i]); n     } n     sort(v.begin(), v.end()); n     v1.push_back(v[0]); n     for (j = 1; j < v.size(); j++) { n       if (v[j] != v[j - 1]) v1.push_back(v[j]); n     } n     for (j = 0; j < n; j++) { n       lowC[j][i] = lower_bound(v1.begin(), v1.end(), a[j][i]) - v1.begin(); n       highC[j][i] = v1.size() - lowC[j][i] - 1; n     } n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) n       cout << max(lowR[i][j], lowC[i][j]) + max(highR[i][j], highC[i][j]) + 1 n            <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 310; n int mod[3]; n int n; n string s[maxn]; n long long ha[maxn][3]; n int prel[maxn]; n int main() { n   ios::sync_with_stdio(false); n   mod[0] = 1e9 + 7; n   mod[1] = 1e9 + 9; n   mod[2] = 19260817; n   cin >> n; n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     cin >> s[i]; n     int l = s[i].size(); n     for (int j = l - 1; j >= 0; j--) { n       for (int k = 0; k < 3; k++) { n         ha[i][k] = (ha[i][k] * 131 + s[i][j]) % mod[k]; n       } n     } n     prel[i] = prel[i - 1] + l; n   } n   ans = prel[n] + n - 1; n   int res = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j++) { n       int len = j - i + 1, cnt = 0; n       for (int k = j + 1; k + len - 1 <= n; k++) { n         bool f = 1; n         for (int l = 0; l < len; l++) { n           if (ha[i + l][0] != ha[k + l][0] || ha[i + l][1] != ha[k + l][1] || n               ha[i + l][2] != ha[k + l][2]) { n             f = 0; n             break; n           } n         } n         if (f) cnt++, k += len - 1; n       } n       if (cnt == 0) continue; n       res = max(res, (cnt + 1) * (prel[j] - prel[i - 1] - 1)); n     } n   } n   cout << ans - res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, v, x; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m >> v; n   if ((((n - 1) * (n - 2) / 2) + 1 < m) || (m < (n - 1))) n     return cout << -1 <<   n , 0; n   for (int i = 1; i <= n; i++) n     if (i != v) cout << v <<     << i <<   n , x = i; n   m -= (n - 1); n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (!m) return 0; n       if (i != x && j != x && i != v && j != v) n         cout << i <<     << j <<   n , m--; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 6; n struct Edge { n   int next, en; n } edge[maxn]; n int head[maxn], cnt; n void init() { n   memset(head, -1, sizeof(head)); n   cnt = 0; n } n void add(int x, int y) { n   edge[cnt].en = y; n   edge[cnt].next = head[x]; n   head[x] = cnt++; n } n int ans[maxn], siz[maxn], fa[maxn], maxsiz[maxn]; n void dfs(int x) { n   siz[x] = maxsiz[x] = 1; n   ans[x] = x; n   for (int i = head[x]; i + 1; i = edge[i].next) { n     int v = edge[i].en; n     fa[v] = x; n     dfs(v); n     siz[x] += siz[v]; n     maxsiz[x] = max(maxsiz[x], siz[v]); n   } n   for (int i = head[x]; i + 1; i = edge[i].next) { n     int v = edge[i].en; n     int p = ans[v]; n     while (p != x) { n       if (maxsiz[p] * 2 <= siz[x] && (siz[x] - siz[p]) * 2 <= siz[x]) { n         ans[x] = p; n         break; n       } n       p = fa[p]; n     } n   } n } n int main() { n   int n, q, d; n   scanf( %d%d , &n, &q); n   init(); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &d); n     add(d, i); n   } n   dfs(1); n   while (q--) { n     scanf( %d , &d); n     printf( %d n , ans[d]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 152; n const int MAX2 = 11300; n const int INF = 1e9 + 10; n int a[MAX]; n int r[MAX][MAX2]; n int t[MAX][MAX2]; n int main() { n   int n, k, s; n   cin >> n >> k >> s; n   s = min(s, MAX2 - 1); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i <= n; i++) { n     for (int p = 1; p <= s; p++) { n       r[i][p] = INF; n     } n   } n   for (int q = 1; q <= k; q++) { n     for (int i = 0; i <= n; i++) { n       for (int p = 0; p <= s; p++) { n         t[i][p] = INF; n       } n     } n     for (int i = q; i <= n; i++) { n       for (int p = 0; p <= s; p++) { n         if (p >= i - q) n           t[i][p] = min(r[i - 1][p - (i - q)] + a[i], t[i - 1][p]); n         else n           t[i][p] = t[i - 1][p]; n       } n     } n     for (int i = 0; i <= n; i++) { n       for (int p = 0; p <= s; p++) { n         r[i][p] = t[i][p]; n       } n     } n   } n   int res = INF; n   for (int p = 0; p <= s; p++) { n     res = min(res, r[n][p]); n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1000010]; n bool f[1000010]; n int main() { n   int i, l, ans = 0, ans2 = 0, j, sta; n   scanf( %s , &s); n   l = strlen(s); n   sta = 0; n   while (s[sta] == s[(sta + 1) % l]) { n     sta = (sta + 1) % l; n   } n   ++sta; n   memset(f, false, sizeof(bool) * l); n   i = sta; n   while (!f[i]) { n     f[i] = true; n     i = (i + l - 1) % l; n     while (s[(i + l - 1) % l] == s[i]) { n       f[i] = true; n       i = (i + l - 1) % l; n     } n     f[i] = true; n     i = (i + l - 1) % l; n     ++ans; n   } n   memset(f, false, sizeof(bool) * l); n   i = sta; n   while (!f[i]) { n     f[i] = true; n     while (s[(i + 1) % l] == s[i]) { n       i = (i + 1) % l; n       f[i] = true; n     } n     f[(i + 1) % l] = true; n     i = (i + 2) % l; n     ++ans2; n   } n   printf( %d n , ans < ans2 ? ans : ans2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using vll = vector<ll>; n using ull = unsigned long long; n using int2 = pair<ll, ll>; n using int3 = tuple<ll, ll, ll>; n template <typename A> n string to_string(const A& v); n string to_string(const string& s) { return     + s +    ; } n string to_string(const char* s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n template <typename A, typename B> n string to_string(const pair<A, B>& p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A, typename B, typename C> n string to_string(const tuple<A, B, C>& p) { n   return  (  + to_string(std::get<0>(p)) +  ,   + to_string(std::get<1>(p)) + n           ,   + to_string(std::get<2>(p)) +  ) ; n } n template <typename A> n string to_string(const A& v) { n   bool first = true; n   string res =  { ; n   for (const auto& x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <typename T> n void sort(vector<T>& val) { n   sort(val.begin(), val.end()); n } n template <typename T> n void reverse(vector<T>& val) { n   reverse(val.begin(), val.end()); n } n template <typename T> n void sort_b(vector<T>& val) { n   sort(val.begin(), val.end(), greater<T>()); n } n template <typename T> n T pair_sum(pair<T, T>& val) { n   return val.first + val.second; n } n template <typename T> n T min(T a, T b, T c) { n   return min(min(a, b), c); n } n template <typename T> n T max(T a, T b, T c) { n   return max(max(a, b), c); n } n template <typename T> n T mul_mod(T a, T b, T mod) { n   T res = 0; n   a %= mod; n   while (b) { n     if (b & 1) { n       res = (res + a) % mod; n     } n     a = (2 * a) % mod; n     b >>= 1; n   } n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n class mytask { n  public: n   mytask() {} n   int solve() { n     ll t; n     cin >> t; n     for (ll i_t = 0; i_t < t; i_t++) { n       ll n; n       cin >> n; n       vll a(n); n       ll last_val = -2; n       vll neighbors; n       ll max_diff = 0; n       for (ll i = 0; i < n; i++) { n         ll val; n         cin >> val; n         if (val == -1) { n           if (last_val >= 0) { n             neighbors.push_back(last_val); n           } n         } else { n           if (last_val == -1) { n             neighbors.push_back(val); n           } n           if (last_val >= 0) { n             max_diff = max(max_diff, abs(last_val - val)); n           } n         } n         last_val = val; n       }; n       ; n       if (neighbors.size() == 0) { n         cout << max_diff <<     << 0 << endl; n         continue; n       } n       ll min_n = *min_element(neighbors.begin(), neighbors.end()); n       ll max_n = *max_element(neighbors.begin(), neighbors.end()); n       if (min_n == 0 && max_n == 0) { n         cout << max_diff <<     << 0 << endl; n         continue; n       } n       ll res = (min_n + max_n) / 2; n       ll res_max = max(res - min_n, max_n - res); n       ; n       ; n       res_max = max(res_max, max_diff); n       cout << res_max <<     << res << endl; n     } n     return 0; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   auto task = mytask(); n   task.solve(); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = (int)1e9 + 7; n const int N_ = (int)2e6 + 2; n long long n; n char a[N_], b[N_]; n double res; n long long T; n int main() { n   scanf( %lld , &n); n   scanf( %s , a + 1); n   scanf( %s , b + 1); n   for (char cur =  A ; cur <=  Z ; cur++) { n     long long S = 0; n     for (int i = 1; i <= n; i++) { n       if (a[i] == cur) S += i; n       if (b[i] == cur) res += S * (n - i + 1); n     } n     S = 0; n     for (int i = 0; i <= n; i++) { n       if (a[i] == cur) res += S * (n - i + 1); n       if (b[i] == cur) S += i; n     } n   } n   for (int i = 1; i <= n; i++) T += (n - i + 1) * (n - i + 1); n   printf( %.9lf , res / T); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pnt { n   int x, y; n }; n struct pr { n   int d, q; n   pr() {} n   pr(int d, int q) : d(d), q(q) {} n   friend bool operator<(pr a, pr b) { n     if (a.d != b.d) return a.d < b.d; n     return a.q < b.q; n   } n }; n const int N = 200000 + 20; n bool ok[N]; n int t[4 * N]; n void build(int v, int tl, int tr) { n   if (tl == tr) { n     t[v] = -1; n     return; n   } n   int tm = (tl + tr) / 2; n   build(2 * v, tl, tm); n   build(2 * v + 1, tm + 1, tr); n   t[v] = -1; n } n void upd(int v, int tl, int tr, int wh, int vl) { n   while (tl < tr) { n     int tm = (tl + tr) / 2; n     if (wh <= tm) { n       tr = tm; n       v = 2 * v; n     } else { n       tl = tm + 1; n       v = 2 * v + 1; n     } n   } n   t[v] = vl; n   v /= 2; n   while (v >= 1) { n     t[v] = min(t[2 * v], t[2 * v + 1]); n     v >>= 1; n   } n } n const int INF = 1e9 + 7; n int mn(int v, int tl, int tr, int l, int r) { n   if (l > r) return INF; n   if (tl == l && r == tr) return t[v]; n   int tm = (tl + tr) / 2; n   return min(mn(2 * v, tl, tm, l, min(tm, r)), n              mn(2 * v + 1, tm + 1, tr, max(tm + 1, l), r)); n } n int main() { n   int n, m, k, q; n   scanf( %d %d %d %d , &n, &m, &k, &q); n   swap(n, m); n   vector<pnt> lad(k); n   for (int i = 0; i < k; ++i) { n     scanf( %d %d , &lad[i].x, &lad[i].y); n     --lad[i].x; n     --lad[i].y; n   } n   vector<pr> r(q), d(q); n   vector<int> x1(q), x2(q), y1(q), y2(q); n   for (int i = 0; i < q; ++i) { n     scanf( %d %d %d %d , &x1[i], &y1[i], &x2[i], &y2[i]); n     --y1[i]; n     --y2[i]; n     --x1[i]; n     --x2[i]; n     r[i].d = x2[i]; n     r[i].q = i; n     d[i].d = y2[i]; n     d[i].q = i; n   } n   for (int i = 0; i < k; ++i) { n     r.push_back(pr(lad[i].x, -i - 1)); n     d.push_back(pr(lad[i].y, -i - 1)); n   } n   sort(r.begin(), r.end()); n   sort(d.begin(), d.end()); n   build(1, 0, n - 1); n   for (int i = 0; i < r.size(); ++i) { n     if (r[i].q < 0) n       upd(1, 0, n - 1, lad[-r[i].q - 1].y, r[i].d); n     else { n       int t = mn(1, 0, n - 1, y1[r[i].q], y2[r[i].q]); n       if (t >= x1[r[i].q]) ok[r[i].q] = true; n     } n   } n   build(1, 0, m - 1); n   for (int i = 0; i < d.size(); ++i) { n     if (d[i].q < 0) n       upd(1, 0, m - 1, lad[-d[i].q - 1].x, d[i].d); n     else { n       int t = mn(1, 0, m - 1, x1[d[i].q], x2[d[i].q]); n       if (t >= y1[d[i].q]) ok[d[i].q] = true; n     } n   } n   for (int i = 0; i < q; ++i) printf((ok[i] ?  YES n  :  NO n )); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s[1001], d[1001], i, a, S; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> s[i] >> d[i]; n   } n   S = s[1]; n   for (i = 2; i <= n; i++) { n     if (s[i] <= S) { n       int x = ((S - s[i]) / d[i]) + 1; n       S = s[i] + d[i] * x; n     } else n       S = s[i]; n   } n   cout << S; n } n


#include <bits/stdc++.h> n using namespace std; n void boost() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const int N = 1e6; n const long long inf = 1e9; n int n; n vector<string> s; n string ans, cur; n vector<int> g[200]; n bool was[N]; n map<string, bool> wass; n void dfs(int v) { n   was[v] = 1; n   bool flag = 0; n   bool flag2 = ((int)cur.find(s[v]) > -1); n   if (!flag2) { n     for (int i = s[v].size(); i > 0; i--) { n       string t1 = s[v].substr(0, i); n       string t2 = s[v].substr(i, s[v].size() - i); n       if ((int)cur.find(t1) > -1) { n         cur += t2; n         flag = 1; n         break; n       } n     } n   } n   if (!flag && !flag2) { n     for (int i = 1; i <= s[v].size(); i++) { n       string t1 = s[v].substr(0, i); n       string t2 = s[v].substr(i, s[v].size() - i); n       if ((int)cur.find(t2) > -1) { n         cur = t1 + cur; n         break; n       } n     } n   } n   for (int i = 0; i < g[v].size(); i++) { n     if (!was[g[v][i]]) { n       dfs(g[v][i]); n     } n   } n } n bool cmp(string a, string b) { return a.size() > b.size(); } n int main() { n   boost(); n   cin >> n; n   s.push_back( 0 ); n   for (int i = 1; i <= n; i++) { n     string x; n     cin >> x; n     if (!wass.count(x)) { n       s.push_back(x); n     } n     wass[x] = 1; n   } n   n = s.size() - 1; n   sort(s.begin() + 1, s.end(), cmp); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i != j) { n         for (int k = 0; k < s[j].size(); k++) { n           if ((int)s[i].find(s[j][k]) > -1) { n             g[i].push_back(j); n             g[j].push_back(i); n             break; n           } n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     if (!was[i]) { n       cur =   ; n       dfs(i); n       ans += cur; n     } n   } n   for (int i = 0; i < ans.size(); i++) { n     for (int j = 0; j < ans.size(); j++) { n       if (ans[i] == ans[j] && i != j) { n         cout << i <<     << j << endl; n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n const int inf = 1e9 + 7; n long long n, m, k, w; n long long dp1[maxn]; n long long dp2[maxn]; n int d1[maxn]; n int d2[maxn]; n long long a, b; n inline int low_bit(int x) { return x & (-x); } n inline void upd1(int p, int x) { n   while (p <= n) { n     dp1[p] += x; n     p += low_bit(p); n   } n   return; n } n inline void upd2(int p, int x) { n   while (p <= n) { n     dp2[p] += x; n     p += low_bit(p); n   } n   return; n } n inline int query1(int p) { n   int sum = 0; n   while (p > 0) { n     sum += dp1[p]; n     p -= low_bit(p); n   } n   return sum; n } n inline int query2(int p) { n   int sum = 0; n   while (p > 0) { n     sum += dp2[p]; n     p -= low_bit(p); n   } n   return sum; n } n inline int query(int p) { n   return query1(p - 1) + query2(n) - query2(p + k - 1); n } n int main() { n   long long ans = 0; n   cin >> n >> k >> a >> b >> m; n   for (int i = 1; i <= m; i++) { n     int op; n     scanf( %d , &op); n     if (op == 1) { n       int x, y; n       scanf( %d%d , &x, &y); n       int p1 = d1[x]; n       int p2 = d2[x]; n       int to1 = 0, to2 = 0; n       to1 = b - p1; n       to2 = a - p2; n       upd1(x, y > to1 ? to1 : y); n       upd2(x, y > to2 ? to2 : y); n       d1[x] += y > to1 ? to1 : y; n       d2[x] += y > to2 ? to2 : y; n     } else { n       int x; n       scanf( %d , &x); n       cout << query(x) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 305; n int a[maxn][maxn], b[maxn][maxn]; n int main(int argc, char const *argv[]) { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n, m; n     scanf( %d %d , &n, &m); n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) { n         scanf( %d , &a[i][j]); n       } n     } n     bool good = 1; n     b[1][1] = b[1][m] = b[n][1] = b[n][m] = 2; n     if (a[1][1] > 2 or a[1][m] > 2 or a[n][1] > 2 or a[n][m] > 2) { n       printf( NO n ); n       continue; n     } n     for (int i = 2; i < m; ++i) { n       if (a[1][i] > 3 or a[n][i] > 3) { n         good = 0; n       } n       b[1][i] = b[n][i] = 3; n     } n     for (int i = 2; i < n; ++i) { n       if (a[i][1] > 3 or a[i][m] > 3) { n         good = 0; n       } n       b[i][1] = b[i][m] = 3; n     } n     if (!good) { n       printf( NO n ); n       continue; n     } n     for (int i = 2; i < n; ++i) { n       for (int j = 2; j < m; ++j) { n         if (a[i][j] > 4) { n           good = 0; n         } n         b[i][j] = 4; n       } n     } n     if (!good) { n       printf( NO n ); n     } else { n       printf( YES n ); n       for (int i = 1; i <= n; ++i) { n         for (int j = 1; j <= m; ++j) { n           printf( %d  , b[i][j]); n         } n         printf(  n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void JIZZ(string output =   ) { n   cout << output; n   exit(0); n } n const long double PI = 3.14159265358979323846264338327950288; n const long double eps = 1e-10; n const long long mod = 1e9 + 7; n void solve() { n   string s, t; n   cin >> s >> t; n   for (int st = 0; st < (int)s.size(); ++st) { n     string cur; n     for (int ri = st; ri < (int)s.size(); ++ri) { n       cur += s[ri]; n       if (cur == t) { n         cout <<  YES  << endl; n         return; n       } n       string cc = cur; n       for (int i = ri - 1; i >= 0 && cur.size() < t.size(); --i) { n         cc += s[i]; n         if (cc.size() == t.size()) { n           if (cc == t) { n             cout <<  YES  << endl; n             return; n           } n           break; n         } n       } n     } n   } n   cout <<  NO  <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 1e6 + 10; n const long long INF = 1e18; n const long double EPS = 1e-12; n struct Point { n   long double x, y; n   Point() {} n   Point(long double x, long double y) : x(x), y(y) {} n   Point(const Point &p) : x(p.x), y(p.y) {} n   Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); } n   Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } n   Point operator*(long double c) const { return Point(x * c, y * c); } n   Point operator/(long double c) const { return Point(x / c, y / c); } n }; n long double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; } n long double dist2(Point p, Point q) { return dot(p - q, p - q); } n long double cross(Point p, Point q) { return p.x * q.y - p.y * q.x; } n ostream &operator<<(ostream &os, const Point &p) { n   os <<  (  << p.x <<  ,  << p.y <<  ) ; n } n bool operator<(const Point &a, const Point &b) { n   return make_pair(a.x, a.y) < make_pair(b.x, b.y); n } n bool operator==(const Point &a, const Point &b) { n   return abs(a.x - b.x) < EPS && abs(a.y - b.y) < EPS; n } n Point RotateCCW90(Point p) { return Point(-p.y, p.x); } n Point RotateCW90(Point p) { return Point(p.y, -p.x); } n Point RotateCCW(Point p, long double t) { n   return Point(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t)); n } n Point ProjectPointLine(Point a, Point b, Point c) { n   return a + (b - a) * dot(c - a, b - a) / dot(b - a, b - a); n } n Point ProjectPointSegment(Point a, Point b, Point c) { n   long double r = dot(b - a, b - a); n   if (fabs(r) < EPS) return a; n   r = dot(c - a, b - a) / r; n   if (r < 0) return a; n   if (r > 1) return b; n   return a + (b - a) * r; n } n pair<Point, Point> Perpendicularline(Point a, Point b, Point c) { n   c = ProjectPointLine(a, b, c); n   if (a == c) a = b; n   return make_pair(c, c + RotateCW90(a - c)); n } n long double DistancePointSegment(Point a, Point b, Point c) { n   return sqrt(dist2(c, ProjectPointSegment(a, b, c))); n } n long double DistancePointPlane(long double x, long double y, long double z, n                                long double a, long double b, long double c, n                                long double d) { n   return fabs(a * x + b * y + c * z - d) / sqrt(a * a + b * b + c * c); n } n bool LinesParallel(Point a, Point b, Point c, Point d) { n   return fabs(cross(b - a, c - d)) < EPS; n } n bool LinesCollinear(Point a, Point b, Point c, Point d) { n   return LinesParallel(a, b, c, d) && fabs(cross(a - b, a - c)) < EPS && n          fabs(cross(c - d, c - a)) < EPS; n } n bool SegmentsIntersect(Point a, Point b, Point c, Point d) { n   if (LinesCollinear(a, b, c, d)) { n     if (dist2(a, c) < EPS || dist2(a, d) < EPS || dist2(b, c) < EPS || n         dist2(b, d) < EPS) n       return true; n     if (dot(c - a, c - b) > 0 && dot(d - a, d - b) > 0 && dot(c - b, d - b) > 0) n       return false; n     return true; n   } n   if (cross(d - a, b - a) * cross(c - a, b - a) > 0) return false; n   if (cross(a - c, d - c) * cross(b - c, d - c) > 0) return false; n   return true; n } n Point ComputeLineIntersection(Point a, Point b, Point c, Point d) { n   b = b - a; n   d = c - d; n   c = c - a; n   assert(dot(b, b) > EPS && dot(d, d) > EPS); n   return a + b * cross(c, d) / cross(b, d); n } n Point ComputeCircleCenter(Point a, Point b, Point c) { n   b = (a + b) / 2; n   c = (a + c) / 2; n   return ComputeLineIntersection(b, b + RotateCW90(a - b), c, n                                  c + RotateCW90(a - c)); n } n bool PointInPolygon(const vector<Point> &p, Point q) { n   bool c = 0; n   for (int i = 0; i < p.size(); i++) { n     int j = (i + 1) % p.size(); n     if ((p[i].y <= q.y && q.y < p[j].y || p[j].y <= q.y && q.y < p[i].y) && n         q.x < p[i].x + (p[j].x - p[i].x) * (q.y - p[i].y) / (p[j].y - p[i].y)) n       c = !c; n   } n   return c; n } n bool PointOnPolygon(const vector<Point> &p, Point q) { n   for (int i = 0; i < p.size(); i++) n     if (dist2(ProjectPointSegment(p[i], p[(i + 1) % p.size()], q), q) < EPS) n       return true; n   return false; n } n vector<Point> CircleLineIntersection(Point a, Point b, Point c, long double r) { n   vector<Point> ret; n   b = b - a; n   a = a - c; n   long double A = dot(b, b); n   long double B = dot(a, b); n   long double C = dot(a, a) - r * r; n   long double D = B * B - A * C; n   if (D < -EPS) return ret; n   ret.push_back(c + a + b * (-B + sqrt(D + EPS)) / A); n   if (D > EPS) ret.push_back(c + a + b * (-B - sqrt(D)) / A); n   return ret; n } n vector<Point> CircleCircleIntersection(Point a, Point b, long double r, n                                        long double R) { n   vector<Point> ret; n   long double d = sqrt(dist2(a, b)); n   if (d > r + R || d + min(r, R) < max(r, R)) return ret; n   long double x = (d * d - R * R + r * r) / (2 * d); n   long double y = sqrt(r * r - x * x); n   Point v = (b - a) / d; n   ret.push_back(a + v * x + RotateCCW90(v) * y); n   if (y > 0) ret.push_back(a + v * x - RotateCCW90(v) * y); n   return ret; n } n long double ComputeSignedArea(const vector<Point> &p) { n   long double area = 0; n   for (int i = 0; i < p.size(); i++) { n     int j = (i + 1) % p.size(); n     area += p[i].x * p[j].y - p[j].x * p[i].y; n   } n   return area / 2.0; n } n long double ComputeArea(const vector<Point> &p) { n   return fabs(ComputeSignedArea(p)); n } n Point ComputeCentroid(const vector<Point> &p) { n   Point c(0, 0); n   long double scale = 6.0 * ComputeSignedArea(p); n   for (int i = 0; i < p.size(); i++) { n     int j = (i + 1) % p.size(); n     c = c + (p[i] + p[j]) * (p[i].x * p[j].y - p[j].x * p[i].y); n   } n   return c / scale; n } n bool IsSimple(const vector<Point> &p) { n   for (int i = 0; i < p.size(); i++) { n     for (int k = i + 1; k < p.size(); k++) { n       int j = (i + 1) % p.size(); n       int l = (k + 1) % p.size(); n       if (i == l || j == k) continue; n       if (SegmentsIntersect(p[i], p[j], p[k], p[l])) return false; n     } n   } n   return true; n } n long double area2(Point a, Point b, Point c) { return cross(b - a, c - a); } n void ConvexHull(vector<Point> &pts) { n   sort(pts.begin(), pts.end()); n   pts.erase(unique(pts.begin(), pts.end()), pts.end()); n   vector<Point> up, dn; n   for (int i = 0; i < pts.size(); i++) { n     while (up.size() > 1 && area2(up[up.size() - 2], up.back(), pts[i]) >= 0) n       up.pop_back(); n     while (dn.size() > 1 && area2(dn[dn.size() - 2], dn.back(), pts[i]) <= 0) n       dn.pop_back(); n     up.push_back(pts[i]); n     dn.push_back(pts[i]); n   } n   pts = dn; n   for (int i = (int)up.size() - 2; i >= 1; i--) pts.push_back(up[i]); n } n bool in_convex(vector<Point> &l, Point p) { n   int a = 1, b = l.size() - 1, c; n   if (((l[a].x - l[0].x) * (l[b].y - l[0].y) - n        (l[a].y - l[0].y) * (l[b].x - l[0].x)) > 0) n     swap(a, b); n   if (((l[a].x - l[0].x) * (p.y - l[0].y) - n        (l[a].y - l[0].y) * (p.x - l[0].x)) >= 0 || n       ((l[b].x - l[0].x) * (p.y - l[0].y) - n        (l[b].y - l[0].y) * (p.x - l[0].x)) <= 0) n     return false; n   while (abs(a - b) > 1) { n     c = (a + b) / 2; n     if (((l[c].x - l[0].x) * (p.y - l[0].y) - n          (l[c].y - l[0].y) * (p.x - l[0].x)) > 0) n       b = c; n     else n       a = c; n   } n   return ((l[b].x - l[a].x) * (p.y - l[a].y) - n           (l[b].y - l[a].y) * (p.x - l[a].x)) <= 0; n } n vector<pair<Point, Point> > find_tangent(Point a, Point b, long double r1, n                                          long double r2) { n   vector<pair<Point, Point> > Q; n   if (dist2(a, b) <= (r1 - r2) * (r1 - r2)) return Q; n   int f = 0; n   if (r2 > r1) swap(a, b), swap(r1, r2), f = 1; n   if (abs(r2 - r1) <= EPS) { n     pair<Point, Point> m = Perpendicularline(a, b, a), n                        n = Perpendicularline(a, b, b); n     vector<Point> l1 = CircleLineIntersection(m.first, m.second, a, r1), n                   l2 = CircleLineIntersection(n.first, n.second, b, r2); n     assert(l1.size() == 2 && l2.size() == 2); n     if (cross(b - a, l1[0] - b) * cross(b - a, l2[0] - b) < 0) n       swap(l2[0], l2[1]); n     Q.push_back(make_pair(l1[0], l2[0])); n     Q.push_back(make_pair(l1[1], l2[1])); n   } else { n     Point out = (b * r1 - a * r2) / (r1 - r2); n     assert(dist2(out, a) >= r1 && dist2(out, b) >= r2); n     vector<Point> l1 = CircleCircleIntersection( n                       a, out, r1, sqrt(dist2(out, a) - (r1) * (r1))), n                   l2 = CircleCircleIntersection( n                       b, out, r2, sqrt(dist2(out, b) - (r2) * (r2))); n     assert(l1.size() == 2 && l2.size() == 2); n     if (cross(b - a, l1[0] - b) * cross(b - a, l2[0] - b) < 0) n       swap(l2[0], l2[1]); n     Q.push_back(make_pair(l1[0], l2[0])); n     Q.push_back(make_pair(l1[1], l2[1])); n   } n   if (dist2(a, b) > (r1 + r2) * (r1 + r2) + EPS) { n     Point out = (b * r1 + a * r2) / (r1 + r2); n     assert(dist2(out, a) >= r1 && dist2(out, b) >= r2); n     vector<Point> l1 = CircleCircleIntersection( n                       a, out, r1, sqrt(dist2(out, a) - (r1) * (r1))), n                   l2 = CircleCircleIntersection( n                       b, out, r2, sqrt(dist2(out, b) - (r2) * (r2))); n     assert(l1.size() == 2 && l2.size() == 2); n     if (cross(b - a, l1[0] - b) * cross(b - a, l2[0] - b) > 0) n       swap(l2[0], l2[1]); n     Q.push_back(make_pair(l1[0], l2[0])); n     Q.push_back(make_pair(l1[1], l2[1])); n   } else if (abs((r1 + r2) * (r1 + r2) - dist2(a, b)) < EPS) { n     Point out = (b * r1 + a * r2) / (r1 + r2); n     Q.push_back(Perpendicularline(a, b, out)); n   } n   if (f == 1) { n     for (int i = 0; i < Q.size(); ++i) swap(Q[i].first, Q[i].second); n   } n   return Q; n } n long double error = 1e-8; n Point rect; n vector<pair<Point, long double> > circ; n bool inpoly(vector<Point> &a, Point b) { n   int n = a.size(); n   for (int i = 0; i < a.size(); ++i) { n     if (DistancePointSegment(a[i], a[(i + 1) % n], b) < error) return 1; n   } n   return in_convex(a, b); n } n bool outcircle(Point cen, long double rad, Point a) { n   if (dist2(cen, a) > rad * rad - error) return 1; n   return 0; n } n Point bottom; n bool cmp(Point a, Point b) { n   long double val = cross(a - bottom, b - a); n   if (fabs(val) < EPS) { n     return dist2(bottom, b) > dist2(bottom, a); n   } n   return val > EPS; n } n int myconvexhull(vector<Point> &pts) { n   sort(pts.begin(), pts.end()); n   pts.resize(unique(pts.begin(), pts.end()) - pts.begin()); n   bottom = pts[0]; n   sort(pts.begin() + 1, pts.end(), cmp); n   vector<Point> hull; n   hull.clear(); n   for (int i = 0; i < pts.size(); ++i) { n     while (hull.size() >= 2 && n            cross(hull[hull.size() - 2] - hull[hull.size() - 1], n                  pts[i] - hull[hull.size() - 1]) >= -1 * EPS) { n       hull.pop_back(); n     } n     hull.push_back(pts[i]); n   } n   pts.clear(); n   for (int i = 0; i < hull.size(); ++i) { n     pts.push_back(hull[i]); n   } n   return 0; n } n vector<Point> vec; n long double getslope(int a, int b) { n   if (abs(vec[a].x - vec[b].x) < EPS) { n     return INF; n   } n   long double val = vec[a].y - vec[b].y; n   val /= vec[a].x - vec[b].x; n   return val; n } n Point get(long double sl, int a, int b, int c) { n   if (abs(sl - INF) < EPS) { n     if (vec[b].y != vec[a].y) { n       return Point(vec[a].x, vec[b].y); n     } else { n       return Point(vec[a].x, vec[c].y); n     } n   } n   if (vec[b].x == vec[a].x) { n     b = c; n   } n   long double y2 = vec[a].y + sl * (vec[b].x - vec[a].x); n   return Point(vec[b].x, y2); n } n int main() { n   std::ios::sync_with_stdio(false); n   int n, i, j, k, a, b, c; n   long long iinf = INF; n   iinf *= INF; n   long double x, y, area = iinf; n   long long s; n   cin >> n >> s; n   for (int i = 0; i < n; ++i) { n     cin >> x >> y; n     vec.push_back(Point(x, y)); n   } n   myconvexhull(vec); n   n = vec.size(); n   for (int i = 0; i < n; ++i) { n     k = (i + 2) % n; n     for (j = (i + 1) % n; j != i; j = (j + 1) % n) { n       while (-1.0 * area2(vec[i], vec[j], vec[k]) + n                  area2(vec[i], vec[j], vec[(k + 1) % n]) > n              EPS) { n         k = (k + 1) % n; n       } n       if (area2(vec[i], vec[j], vec[k]) - area > EPS) { n         area = area2(vec[i], vec[j], vec[k]); n         a = i; n         b = j; n         c = k; n       } n     } n   } n   long double slopeab, slopebc, slopeac; n   Point p1, p2, p3, ans1, ans2, ans3; n   slopeab = getslope(a, b); n   slopebc = getslope(b, c); n   slopeac = getslope(a, c); n   p1 = get(slopeab, c, a, b); n   p2 = get(slopebc, a, b, c); n   p3 = get(slopeac, b, a, c); n   ans1 = ComputeLineIntersection(p1, vec[c], p2, vec[a]); n   ans2 = ComputeLineIntersection(p1, vec[c], p3, vec[b]); n   ans3 = ComputeLineIntersection(p2, vec[a], p3, vec[b]); n   cout << setprecision(30) << round(ans1.x) <<     << round(ans1.y) << endl; n   cout << setprecision(30) << round(ans2.x) <<     << round(ans2.y) << endl; n   cout << setprecision(30) << round(ans3.x) <<     << round(ans3.y) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n const int mod = 1000000007; n long long fastpow(long long a, long long b) { n   if (b == 0) n     return 1; n   else if (b % 2 == 0) n     return fastpow(a * a, b / 2); n   else if (b % 2 != 0) n     return a * fastpow(a * a, (b - 1) / 2); n } n const long long inf = 2e18; n signed main() { n   long long k; n   cin >> k; n   long long x = 0; n   long long i; n   for (i = 5; i <= k; i++) { n     if (k % i == 0) { n       if (i >= 5 && k / i >= 5) { n         x++; n         break; n       } n     } n   } n   if (x == 0) { n     cout <<  -1  <<   n ; n     return 0; n   } n   long long n = i; n   long long m = k / i; n   char A[n][m]; n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j < n; j++) A[j][i] =  g ; n   } n   A[0][0] =  a , A[1][0] =  e , A[2][0] =  i , A[3][0] =  o , A[4][0] =  u ; n   A[0][1] =  u , A[1][1] =  a , A[2][1] =  e , A[3][1] =  i , A[4][1] =  o ; n   A[0][2] =  o , A[1][2] =  u , A[2][2] =  a , A[3][2] =  e , A[4][2] =  i ; n   A[0][3] =  i , A[1][3] =  o , A[2][3] =  u , A[3][3] =  a , A[4][3] =  e ; n   A[0][4] =  e , A[1][4] =  i , A[2][4] =  o , A[3][4] =  u , A[4][4] =  a ; n   for (long long i = 5; i < n; i++) { n     A[i][0] =  a , A[i][1] =  e , A[i][2] =  i , A[i][3] =  o , A[i][4] =  u ; n   } n   for (long long i = 5; i < m; i++) { n     A[0][i] =  a , A[1][i] =  e , A[2][i] =  i , A[3][i] =  o , A[4][i] =  u ; n   } n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j < n; j++) cout << A[j][i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n char map[55][55]; n int cov[55][55]; n int fx[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; n int ok, sx, sy; n int steps[55][55]; n int n, m; n int in(int x, int y) { n   if (x >= 1 && x <= n && y >= 1 && y <= m) return 1; n   return 0; n } n void dfs(int x, int y, int step) { n   steps[x][y] = step; n   if (ok) return; n   for (int i = 0; i < 4; i++) { n     int xx = x + fx[i][0]; n     int yy = y + fx[i][1]; n     if (in(xx, yy) && map[xx][yy] == map[sx][sy]) { n       if (cov[xx][yy]) { n         if (step - steps[xx][yy] >= 3) { n           ok = 1; n           return; n         } n         continue; n       } n       cov[xx][yy] = 1; n       dfs(xx, yy, step + 1); n     } n   } n } n int main() { n   while (~scanf( %d%d , &n, &m)) { n     for (int i = 1; i <= n; i++) { n       scanf( %s , map[i] + 1); n     } n     ok = 0; n     memset(cov, 0, sizeof(cov)); n     memset(steps, 0, sizeof(steps)); n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         if (cov[i][j]) continue; n         ok = 0; n         sx = i; n         sy = j; n         steps[i][j] = 1; n         cov[i][j] = 1; n         dfs(i, j, 1); n         if (ok) break; n       } n       if (ok) break; n     } n     if (ok) n       printf( Yes n ); n     else n       printf( No n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check_lucky(long long num) { n   while (num) { n     if ((num % 10) == 8) return 1; n     num /= 10; n   } n   return 0; n } n int main() { n   long long num; n   cin >> num; n   int flag = 0, ans = 1, f2 = 0; n   if (num < 0) { n     flag = 1; n     num *= (-1); n   } n   if (flag) { n     num--; n     while (1) { n       if (num == 0) { n         f2 = 1; n       } n       if (f2) { n         ans++; n         if (!num) { n           num++; n           continue; n         } n         if (check_lucky(num)) { n           cout << ans - 1 << endl; n           return 0; n         } n         num++; n       } else { n         ans++; n         if (check_lucky(num)) { n           cout << ans - 1 << endl; n           return 0; n         } n         num--; n       } n     } n   } else { n     num++; n     while (1) { n       ans++; n       if (!num) continue; n       if (check_lucky(num)) { n         cout << ans - 1 << endl; n         return 0; n       } n       num++; n     } n   } n   cout << ans << endl; n } n