#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3fffffff; n const int SINF = 0x7fffffff; n const long long LINF = 0x3fffffffffffffff; n const long long SLINF = 0x7fffffffffffffff; n const int MAXN = 30007; n const int MAXD = 6; n const int MOD = 998244353; n int n, d; n int a[MAXN][MAXD][MAXD]; n int tmp[MAXD][MAXD]; n int ans[MAXN]; n int m1[MAXN], m2[MAXN]; n map<vector<int>, int> mp; n map<vector<int>, int>::iterator it; n void init(); n void input(); n void work(); n vector<int> gauss(int a[][MAXD]); n int add(int x, int y) { n   x += y; n   if (x >= MOD) x -= MOD; n   return x; n } n void addv(int &x, int y) { n   x += y; n   if (x >= MOD) x -= MOD; n } n int dec(int x, int y) { n   x -= y; n   if (x < 0) x += MOD; n   return x; n } n void decv(int &x, int y) { n   x -= y; n   if (x < 0) x += MOD; n } n int qpow(int a, int b) { n   long long base = a, ans = 1; n   while (b) { n     if (b & 1) (ans *= base) %= MOD; n     (base *= base) %= MOD; n     b >>= 1; n   } n   return static_cast<int>(ans); n } n int main() { n   init(); n   input(); n   work(); n } n void init() { ios::sync_with_stdio(false); } n void input() { n   scanf( %d%d , &n, &d); n   int nk; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &nk); n     for (int j = 1; j <= nk; ++j) { n       for (int k = 1; k <= d; ++k) scanf( %d , &a[i][j][k]); n     } n   } n } n void work() { n   int kc = 0; n   vector<int> v; n   for (int i = 1; i <= n; ++i) { n     v = gauss(a[i]); n     if ((it = mp.find(v)) == mp.end()) n       mp[v] = ans[i] = ++kc; n     else n       ans[i] = it->second; n   } n   for (int i = 1; i <= n; ++i) printf( %d  , ans[i]); n   putchar(  n ); n } n vector<int> gauss(int a[][MAXD]) { n   for (int i = 1; i <= d; ++i) m1[i] = m2[i] = 0; n   for (int i = 1; i <= d; ++i) n     for (int j = 1; j <= d; ++j) tmp[i][j] = (a[i][j] + MOD) % MOD; n   long long g; n   int ni = 1; n   for (int i = 1; i <= d; ++i) { n     for (int j = ni; j <= d; ++j) { n       if (tmp[j][i]) { n         for (int k = 1; k <= d; ++k) swap(tmp[ni][k], tmp[j][k]); n       } n     } n     if (tmp[ni][i]) { n       m1[ni] = i, m2[i] = ni; n       for (int j = ni + 1; j <= d; ++j) { n         g = qpow(tmp[ni][i], MOD - 2) * static_cast<long long>(tmp[j][i]) % MOD; n         for (int k = i; k <= d; ++k) decv(tmp[j][k], g * tmp[ni][k] % MOD); n       } n       ++ni; n     } n   } n   for (int i = ni - 1; i > 0; --i) { n     for (int j = m1[i] + 1; j <= d; ++j) { n       if (m2[j]) { n         g = qpow(tmp[m2[j]][j], MOD - 2) * static_cast<long long>(tmp[i][j]) % n             MOD; n         for (int k = j; k <= d; ++k) decv(tmp[i][k], tmp[m2[j]][k] * g % MOD); n       } n     } n   } n   for (int i = 1; i < ni; ++i) { n     g = qpow(tmp[i][m1[i]], MOD - 2); n     for (int j = m1[i]; j <= d; ++j) n       tmp[i][j] = static_cast<long long>(tmp[i][j]) * g % MOD; n   } n   vector<int> ans; n   for (int i = 1; i < ni; ++i) n     for (int j = 1; j <= d; ++j) ans.push_back(tmp[i][j]); n   return ans; n } n


#include <bits/stdc++.h> n using namespace std; n int a[150005]; n int main() { n   int n, k, q; n   scanf( %d %d %d , &n, &k, &q); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   multiset<int> t; n   for (int i = 1; i <= q; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     if (x == 1) { n       t.insert(a[y]); n       if ((int)t.size() > k) { n         t.erase(t.begin()); n       } n     } else { n       auto it = t.find(a[y]); n       printf(it != t.end() ?  YES n  :  NO n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10; n const int LG = 20; n int go[N][LG]; n int a[N]; n int last[LG]; n int main() { n   int n, qq; n   scanf( %d %d , &n, &qq); n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n   } n   for (int i = 0; i < LG; i++) { n     go[n][i] = n; n     last[i] = n; n   } n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j < LG; j++) { n       go[i][j] = n; n     } n     for (int j = 0; j < LG; j++) { n       if ((a[i] >> j) & 1) { n         for (int k = 0; k < LG; k++) { n           go[i][k] = min(go[i][k], go[last[j]][k]); n         } n         last[j] = i; n         go[i][j] = i; n       } n     } n   } n   while (qq--) { n     int x, y; n     scanf( %d %d , &x, &y); n     x--; n     y--; n     bool ok = false; n     for (int i = 0; i < LG; i++) { n       ok |= (((a[y] >> i) & 1) && go[x][i] <= y); n     } n     puts(ok ?  Shi  :  Fou ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   long long k; n   cin >> k; n   vector<int> a(n); n   int i; n   int mx_pos = -1; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == n) { n       mx_pos = i; n     } n   } n   int p1 = -1, p2 = -1; n   long long w = 0; n   for (i = 0; w < k && i < mx_pos; i++) { n     if (p1 == -1) { n       p1 = a[i]; n     } else if (p2 == -1) { n       p2 = a[i]; n     } n     if (p2 != -1) { n       if (p1 < p2) { n         p1 = p2; n         p2 = -1; n         w = 1; n       } else { n         p2 = -1; n         w++; n       } n     } n   } n   if (w == k) { n     cout << p1; n   } else { n     cout << n; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   long long d, n, m; n   cin >> d >> n >> m; n   vector<pair<long long, long long> > stations(m + 2); n   stations[0] = pair<long long, long long>(0, 0); n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     stations[i] = pair<long long, long long>(x, y); n   } n   stations[m + 1] = pair<long long, long long>(d, 0); n   sort(stations.begin(), stations.end()); n   long long cost = 0, current = n, i = 0; n   while (i < m + 1) { n     bool found = false; n     int last = i + 1; n     while (stations[last].first <= stations[i].first + n) { n       if (stations[last].second <= stations[i].second) { n         int needed = n             max(0LL, stations[last].first - stations[i].first - current); n         current += needed - stations[last].first + stations[i].first; n         cost += needed * stations[i].second; n         i = last; n         if (last == m + 1) { n           cout << cost << endl; n           return 0; n         } n         found = true; n       } n       last++; n     } n     if (!found) { n       if (last == i + 1) { n         cout << -1 << endl; n         return 0; n       } n       cost += (n - current) * stations[i].second; n       current = n - (stations[i + 1].first - stations[i].first); n       i++; n     } n   } n   cout << -1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 3e5 + 5; n vector<int> ic[MAX]; n vector<int> adj[MAX]; n int used[MAX]; n int cn; n vector<int> tr; n int ans[MAX]; n void dfs(int s, int p) { n   for (int i = 0; i < ic[s].size(); i++) { n     int u = ic[s][i]; n     if (!ans[u] || used[ans[u]]) { n       tr.push_back(u); n     } else { n       used[ans[u]] = 1; n     } n   } n   int cur = 1; n   for (int i = 0; i < tr.size(); i++) { n     int u = tr[i]; n     while (used[cur]) { n       cur++; n     } n     ans[u] = cur; n     cur++; n   } n   cn = max(cn, cur); n   tr.clear(); n   for (int i = 0; i < ic[s].size(); i++) { n     int u = ic[s][i]; n     used[ans[u]] = 0; n   } n   for (int i = 0; i < adj[s].size(); i++) { n     int u = adj[s][i]; n     if (u != p) { n       dfs(u, s); n     } n   } n } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     int cnt; n     scanf( %d , &cnt); n     for (int j = 1; j <= cnt; j++) { n       int a; n       scanf( %d , &a); n       ic[i].push_back(a); n     } n   } n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   dfs(1, 0); n   if ((cn - 1) == 0) { n     printf( 1 n ); n     for (int i = 1; i <= m; i++) { n       printf( 1  ); n     } n   } else { n     printf( %d n , cn - 1); n     for (int i = 1; i <= m; i++) { n       if (ans[i] == 0) { n         ans[i] = 1; n       } n       printf( %d  , ans[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const int Max = 256; n const int MaxE = Max * 2; n struct edge { n   int to; n   edge *s; n }; n edge E[MaxE], *hd[Max], *cp; n int n, k, D[Max]; n int mp[Max][Max]; n int F[Max][Max]; n int A[Max], R[Max]; n void addEdge(int x, int y) { cp->to = y, cp->s = hd[x], hd[x] = cp++; } n inline void update(int &r, int d) { n   if (d < r) r = d; n } n void dfs(int x, int f) { n   for (edge *p = hd[x]; p; p = p->s) n     if (p->to != f) dfs(p->to, x); n   for (int i = 1; i <= n; i++) { n     int &cr = F[x][i] = 0; n     int dx = mp[x][i]; n     for (edge *p = hd[x]; p; p = p->s) n       if (p->to != f) { n         int y = p->to; n         cr += dx < mp[y][i] ? min(R[y], F[y][i]) : F[y][i]; n       } n     cr += D[dx]; n     if (x == i) cr += k; n     if (dx < mp[f][i]) update(R[x], cr); n   } n } n void aDfs(int x, int f, int g) { n   if (g == 0) { n     for (int i = 1; i <= n; i++) n       if (mp[x][i] < mp[f][i] && F[x][i] == R[x]) { n         aDfs(x, f, i); n         return; n       } n   } n   A[x] = g; n   for (edge *p = hd[x]; p; p = p->s) n     if (p->to != f) { n       int y = p->to; n       aDfs(y, x, mp[x][g] < mp[y][g] && R[y] < F[y][g] ? 0 : g); n     } n } n int main() { n   while (scanf( %d%d , &n, &k) != EOF && n) { n     for (int i = 1; i < n; i++) scanf( %d , &D[i]); n     D[n] = oo; n     memset(hd, 0, sizeof(hd)); n     memset(mp, 0x3f, sizeof(mp)); n     cp = E; n     for (int i = 1; i < n; i++) { n       int x, y; n       scanf( %d%d , &x, &y); n       mp[x][y] = mp[y][x] = 1; n       addEdge(x, y); n       addEdge(y, x); n     } n     for (int z = 1; z <= n; z++) n       for (int x = 1; x <= n; x++) n         for (int y = 1; y <= n; y++) update(mp[x][y], mp[x][z] + mp[z][y]); n     for (int x = 1; x <= n; x++) mp[x][x] = 0; n     memset(R, 0x3f, sizeof(R)); n     dfs(1, 0); n     printf( %d n , R[1]); n     aDfs(1, 0, 0); n     for (int i = 1; i <= n; i++) printf( %d%c , A[i], i == n ?   n  :    ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n double EPS = 1e-9; n int INF = 2000000000; n long long INFF = 8000000000000000000LL; n double PI = acos(-1); n int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; n int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; n inline string IntToString(int a) { n   char x[100]; n   sprintf(x,  %d , a); n   string s = x; n   return s; n } n inline int StringToInt(string a) { n   char x[100]; n   int res; n   strcpy(x, a.c_str()); n   sscanf(x,  %d , &res); n   return res; n } n inline string GetString(void) { n   char x[1000005]; n   scanf( %s , x); n   string s = x; n   return s; n } n inline string uppercase(string s) { n   int n = (int)s.size(); n   for (int(i) = (0); (i) < (n); ++(i)) n     if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ; n   return s; n } n inline string lowercase(string s) { n   int n = (int)s.size(); n   for (int(i) = (0); (i) < (n); ++(i)) n     if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ; n   return s; n } n inline void OPEN(string s) { n   freopen((s +  .in ).c_str(),  r , stdin); n   freopen((s +  .out ).c_str(),  w , stdout); n } n int k, n = 500; n int sisa[1005]; n void process(int a, int b) { n   sisa[a] = k - 1; n   for (int(i) = (a + 1); (i) <= (b); ++(i)) sisa[i] = k; n   for (int(i) = (a); (i) <= (b); ++(i)) { n     vector<pair<int, int> > besar; n     for (int(j) = (i + 1); (j) <= (b); ++(j)) n       if (i != j) besar.push_back(make_pair(sisa[j], j)); n     sort(besar.begin(), besar.end()); n     reverse(besar.begin(), besar.end()); n     for (int(j) = (0); (j) < (sisa[i]); ++(j)) { n       printf( %d %d n , i, besar[j].second); n       --sisa[besar[j].second]; n     } n     sisa[i] = 0; n   } n } n int main() { n   scanf( %d , &k); n   if (k == 1) { n     puts( YES ); n     puts( 2 1 ); n     puts( 1 2 ); n     return 0; n   } n   if (k % 2 == 0) { n     puts( NO ); n     return 0; n   } n   puts( YES ); n   printf( %d %d n , n, (k * n) / 2); n   process(1, n / 2 - 1); n   process(n / 2, n); n   printf( %d %d n , 1, n / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, q; n   scanf( %d %d , &n, &q); n   string s; n   cin >> s; n   int size = s.size(); n   int cnt = 0; n   for (int i = 1; i < size; i++) { n     if (s[i] ==  .  && s[i] == s[i - 1]) cnt++; n   } n   while (q--) { n     int n1; n     char x; n     scanf( %d %c , &n1, &x); n     n1--; n     if (isalpha(x) == isalpha(s[n1])) n       ; n     else if (x ==  .  && s[n1] !=  . ) { n       if (n1 < n - 1) n         if (s[n1 + 1] ==  . ) cnt++; n       if (n1 > 0) n         if (s[n1 - 1] ==  . ) cnt++; n     } else { n       if (n1 < n - 1) n         if (s[n1 + 1] ==  . ) cnt--; n       if (n1 > 0) n         if (s[n1 - 1] ==  . ) cnt--; n     } n     s[n1] = x; n     printf( %d n , cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int u[1005], v[1005], fa[1005], n, m, k; n bool zt[1005][1005]; n int getv(int x) { n   if (x == fa[x]) return x; n   fa[x] = getv(fa[x]); n   return fa[x]; n } n void merge(int x, int y) { n   x = getv(x); n   y = getv(y); n   if (x == y) return; n   if (x < y) { n     int t = x; n     x = y; n     y = t; n   } n   fa[x] = y; n   for (int i = 1; i <= m; i++) { n     if (zt[x][i]) zt[y][i] = true; n   } n } n unsigned long long ha(char zf[1005]) { n   unsigned long long rt = 0; n   for (int i = 0; zf[i]; i++) rt = rt * 13131 + zf[i]; n   return rt; n } n map<unsigned long long, int> mp; n char zf[1005]; n int wz[1005], rw[1005], yw[1005]; n int w2[1005], r2[1005], y2[1005]; n bool b1[1005], b2[1005]; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; i++) fa[i] = i; n   for (int i = 1; i <= m; i++) scanf( %d%d , &u[i], &v[i]); n   for (int i = 1; i <= k; i++) { n     int a, s; n     scanf( %s%d%d , zf, &a, &s); n     rw[i] = a; n     mp[ha(zf)] = i; n     for (int j = 0; j < s; j++) { n       int b; n       scanf( %d , &b); n       zt[a][b] = 1; n       yw[b] = a; n     } n   } n   for (int a = 1; a <= m; a++) { n     for (int i = 1; i <= m; i++) { n       if (!b1[i] && (zt[getv(u[i])][i] || zt[getv(v[i])][i])) { n         merge(u[i], v[i]); n         b1[i] = true; n       } n     } n   } n   for (int i = 1; i <= n; i++) wz[i] = getv(i); n   for (int i = 1; i <= m; i++) yw[i] = getv(yw[i]); n   for (int i = 1; i <= k; i++) rw[i] = getv(rw[i]); n   for (int i = 1; i <= n; i++) { n     fa[i] = i; n     for (int j = 1; j <= m; j++) zt[i][j] = 0; n   } n   for (int i = 1; i <= k; i++) { n     int a, s; n     scanf( %s%d%d , zf, &a, &s); n     r2[mp[ha(zf)]] = a; n     for (int j = 0; j < s; j++) { n       int b; n       scanf( %d , &b); n       zt[a][b] = 1; n       y2[b] = a; n     } n   } n   for (int a = 1; a <= m; a++) { n     for (int i = 1; i <= m; i++) { n       if (!b2[i] && (zt[getv(u[i])][i] || zt[getv(v[i])][i])) { n         merge(u[i], v[i]); n         b2[i] = true; n       } n     } n   } n   for (int i = 1; i <= n; i++) w2[i] = getv(i); n   for (int i = 1; i <= m; i++) y2[i] = getv(y2[i]); n   for (int i = 1; i <= k; i++) r2[i] = getv(r2[i]); n   bool zd = false; n   for (int i = 1; i <= n; i++) { n     if (wz[i] != w2[i]) zd = true; n   } n   for (int i = 1; i <= k; i++) { n     if (rw[i] != r2[i]) zd = true; n   } n   for (int i = 1; i <= m; i++) { n     if (yw[i] != y2[i]) zd = true; n   } n   for (int i = 1; i <= m; i++) { n     if (b1[i] != b2[i]) zd = true; n   } n   if (zd) n     printf( NO ); n   else n     printf( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 55; n long long n, m; n int sol[MAXN]; n void solve(int l, int r, long long k) { n   if (l == r) { n     assert(k == 1); n     sol[l] = n; n     return; n   } n   int len = r - l + 1; n   long long cant = (1LL << (len - 1)); n   if (k <= cant / 2) { n     sol[l] = n - len + 1; n     solve(l + 1, r, k); n   } else { n     sol[r] = n - len + 1; n     solve(l, r - 1, k - cant / 2); n   } n } n int main() { n   cin >> n >> m; n   solve(0, n - 1, m); n   for (int i = 0; i < n; i++) cout << sol[i] <<    n [i == n - 1]; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 3e-5; n double x, h, l; n int main() { n   cin >> x; n   for (double h = 1.0; h <= (10.0 + eps); h += 1.0) { n     if (h + eps < x) continue; n     l = h / (sqrt((h * h) / (x * x) - 1)) * 2.0; n     for (double q = 1.0; q <= (10.0 + eps); q += 1.0) { n       if (l - q < eps && q - l < eps) { n         printf( %d %d n , (int)q, (int)h); n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n void precalc(); n int main() { n   string s =  change me please ; n   int t = 1; n   while (t--) solve(); n   return 0; n } n void solve() { n   int n; n   cin >> n; n   vector<int> a(n), h(n); n   for (int i = 0; i < n; ++i) cin >> a[i] >> h[i]; n   int ans = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < n; ++j) n       if (a[i] == h[j]) ++ans; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string A; n   cin >> A; n   if (A.size() > 1 and A.size() % 2 == 0) { n     int x = (A.size() / 2) - 1; n     cout << A[x]; n     for (int i = 1; i <= x; i++) { n       cout << A[x + i] << A[x - i]; n     } n     cout << A[2 * x + 1]; n   } else if (A.size() % 2 != 0 and A.size() > 1) { n     int x = (A.size() / 2); n     cout << A[x]; n     for (int i = 1; i <= x; i++) { n       cout << A[x + i] << A[x - i]; n     } n   } else { n     cout << A[0]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 3; n const long long INF = 4e18 + 3; n vector<long long> v[3]; n int r[3]; n long long ans; n auto iter1 = v[0].begin(); n auto iter2 = v[1].begin(); n long long X, Y; n void rob(int a, int b, int c) { n   for (auto it : v[b]) { n     if (it < v[a][0] || it > v[c].back()) continue; n     iter1 = upper_bound(v[a].begin(), v[a].end(), it); n     iter1--; n     iter2 = lower_bound(v[c].begin(), v[c].end(), it); n     X = *iter1; n     Y = *iter2; n     ans = n         min(ans, (X - Y) * (X - Y) + (X - it) * (X - it) + (Y - it) * (Y - it)); n   } n } n int main() { n   int z; n   long long x; n   scanf( %d , &z); n   while (z--) { n     ans = INF; n     for (int i = 0; i < 3; i++) v[i].clear(); n     for (int i = 0; i < 3; i++) scanf( %d , &r[i]); n     for (int i = 0; i < 3; i++) { n       for (int j = 1; j <= r[i]; j++) { n         scanf( %lld , &x); n         v[i].push_back(x); n       } n     } n     for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end()); n     rob(0, 1, 2); n     rob(0, 2, 1); n     rob(1, 0, 2); n     rob(1, 2, 0); n     rob(2, 0, 1); n     rob(2, 1, 0); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int t = 1; n   while (t--) { n     long long int n; n     cin >> n; n     vector<long long int> v(n); n     for (long long int i = 0; i < n; i++) cin >> v[i]; n     long long int maxi = 1; n     long long int l = 1; n     for (long long int i = 1; i < n; i++) { n       if (v[i] <= 2 * v[i - 1]) n         l++; n       else n         l = 1; n       maxi = max(maxi, l); n     } n     cout << maxi << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool chkmin(T &a, const T &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T> n inline bool chkmax(T &a, const T &b) { n   return a < b ? a = b, 1 : 0; n } n const int oo = 0x3f3f3f3f; n const int maxn = 100000, maxlog = 12; n long long pw[maxlog]; n int n, qn; n long long a[maxn + 5]; n struct lab_type { n   bool ty; n   long long val; n   lab_type() : ty(0), val(0) {} n   lab_type(int _ty, const long long &_val) : ty(_ty), val(_val) {} n   bool empty() { return !ty && !val; } n   friend lab_type &operator+=(lab_type &first, const lab_type &second) { n     if (second.ty) return first = second; n     if (!first.ty || first.val) first.val += second.val; n     return first; n   } n   friend long long &operator+=(long long &first, const lab_type &second) { n     if (second.ty) return first = second.val; n     if (!first) return first; n     return first += second.val; n   } n }; n struct node { n   node *c[2]; n   long long Max; n   lab_type label; n   node() : Max(0) { memset(c, 0, sizeof c); } n   void update() { n     Max = 0; n     for (int i = (0), _end_ = (2); i < _end_; ++i) n       if (c[i]) chkmax(Max, c[i]->Max); n   } n   void flag_label(const lab_type &_label) { n     label += _label; n     Max += _label; n   } n   void push_down() { n     if (!label.empty()) { n       for (int i = (0), _end_ = (2); i < _end_; ++i) n         if (c[i]) c[i]->flag_label(label); n       label = lab_type(); n     } n   } n }; n const int max0 = 100000; n node *nd_pool; n int nd_res = 0; n node *newnode() { n   if (!nd_res) nd_pool = new node[max0], nd_res = max0; n   return nd_pool + (--nd_res); n } n node *rt[maxlog]; n int seg_x, seg_y; n lab_type seg_z; n long long seg_ret; n int seg_id; n void add(node *&rt, int l, int r) { n   if (seg_x <= l && r <= seg_y) { n     rt->flag_label(seg_z); n     return; n   } n   int mid = (l + r) >> 1; n   rt->push_down(); n   if (seg_x < mid) add(rt->c[0], l, mid); n   if (seg_y > mid) add(rt->c[1], mid, r); n   rt->update(); n } n void doit(node *rt, int l, int r) { n   if (!rt) return; n   if (rt->Max <= pw[seg_id]) return; n   if (r - l <= 1) { n     rt->Max = 0; n     return; n   } n   if (rt->label.ty) { n     rt->flag_label(lab_type(1, 0)); n     return; n   } n   rt->push_down(); n   int mid = (l + r) >> 1; n   doit(rt->c[0], l, mid); n   doit(rt->c[1], mid, r); n   rt->update(); n } n void query(node *rt, int l, int r) { n   if (!rt) return; n   if (seg_x <= l && r <= seg_y) { n     chkmax(seg_ret, rt->Max); n     return; n   } n   rt->push_down(); n   int mid = (l + r) >> 1; n   if (seg_x < mid) query(rt->c[0], l, mid); n   if (seg_y > mid) query(rt->c[1], mid, r); n   rt->update(); n } n void build(node *&rt, int l, int r) { n   if (!rt) rt = newnode(); n   if (r - l <= 1) { n     if (a[l] <= pw[seg_id]) n       rt->Max = a[l]; n     else n       rt->Max = 0; n     return; n   } n   rt->push_down(); n   int mid = (l + r) >> 1; n   build(rt->c[0], l, mid); n   build(rt->c[1], mid, r); n   rt->update(); n } n int main() { n   pw[0] = 1; n   for (int i = (1), _end_ = (maxlog); i < _end_; ++i) pw[i] = pw[i - 1] * 42; n   scanf( %d%d , &n, &qn); n   for (int i = (0), _end_ = (n); i < _end_; ++i) scanf( %I64d , a + i); n   for (int i = (0), _end_ = (maxlog); i < _end_; ++i) { n     seg_id = i; n     build(rt[i], 0, n); n   } n   for (int i = (0), _end_ = (qn); i < _end_; ++i) { n     int ty, l, r, first; n     scanf( %d , &ty); n     if (ty == 1) { n       scanf( %d , &first), --first; n       seg_x = first, seg_y = first + 1, seg_ret = 0; n       query(rt[maxlog - 1], 0, n); n       printf( %I64d n , seg_ret); n     } else { n       scanf( %d%d%d , &l, &r, &first), --l; n       seg_x = l, seg_y = r; n       if (ty == 2) { n         seg_z = lab_type(1, first); n         for (int i = maxlog - 1; i >= 0; --i) { n           if (first > pw[i]) seg_z.val = 0; n           add(rt[i], 0, n); n         } n       } else { n         static long long Max[maxlog]; n         static long long cnt[maxlog]; n         for (int i = (0), _end_ = (maxlog); i < _end_; ++i) { n           seg_ret = 0; n           query(rt[i], 0, n); n           Max[i] = seg_ret; n           cnt[i] = 0; n         } n         while (1) { n           bool ok = 1; n           for (int i = (0), _end_ = (maxlog); i < _end_; ++i) { n             cnt[i] += first; n             if (Max[i] && Max[i] + cnt[i] > pw[i]) { n               seg_z = lab_type(0, cnt[i]); n               add(rt[i], 0, n); n               cnt[i] = 0; n               seg_id = i; n               doit(rt[i], 0, n); n               seg_ret = 0; n               query(rt[i], 0, n); n               Max[i] = seg_ret; n             } n             if (Max[i] && Max[i] + cnt[i] == pw[i]) ok = 0; n           } n           if (ok) break; n         } n         for (int i = (0), _end_ = (maxlog); i < _end_; ++i) n           if (cnt[i]) { n             seg_z = lab_type(0, cnt[i]), add(rt[i], 0, n), cnt[i] = 0; n             assert(rt[i]->Max != pw[i]); n           } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long s, n; n   cin >> n >> s; n   if (n >= s) n     cout <<  1 n ; n   else { n     int div = s / n; n     (s % n == 0) ? cout << div << endl : cout << (div + 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-11; n const int mod = 1e7 + 9; n const int oo = (1 << 31) - 1; n template <class T> n inline void readInt(T &n) { n   n = 0; n   T ch = getchar(); n   int sign = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     n = (n << 3) + (n << 1) + ch -  0 , ch = getchar(); n   n = n * sign; n } n const int maxn = 100005; n int n, m, q, x, y, a[505][505], b[505]; n int main() { n   cin >> n >> m >> q; n   for (int i = ((int)(0)); i < ((int)(n)); i++) b[i] = 0; n   for (int i = ((int)(0)); i < ((int)(n)); i++) n     for (int j = ((int)(0)); j < ((int)(m)); j++) cin >> a[i][j]; n   for (int i = ((int)(0)); i < ((int)(n)); i++) { n     int c = a[i][0]; n     for (int j = ((int)(1)); j < ((int)(m)); j++) { n       if (a[i][j] == 0) { n         if (a[i][j - 1] == 1) b[i] = max(b[i], c); n         c = 0; n         continue; n       } n       if (a[i][j - 1] == 0) n         c = 1; n       else n         c++; n     } n     b[i] = max(b[i], c); n   } n   for (int i = ((int)(0)); i < ((int)(q)); i++) { n     cin >> x >> y; n     --x; n     --y; n     a[x][y] = 1 - a[x][y]; n     int res = 0, c = a[x][0]; n     for (int j = ((int)(1)); j < ((int)(m)); j++) { n       if (a[x][j] == 0) { n         if (a[x][j - 1] == 1) res = max(res, c); n         c = 0; n         continue; n       } n       if (a[x][j - 1] == 0) n         c = 1; n       else n         c++; n     } n     res = max(res, c); n     b[x] = res; n     res = 0; n     for (int j = ((int)(0)); j < ((int)(n)); j++) n       if (b[j] > res) res = b[j]; n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n namespace fdd { n int n, m1, m2; n std::priority_queue<int> q[1010]; n std::vector<int> v1, v2; n void solve() { n   std::cin >> n; n   for (int i = 3; i < n; i++) { n     scanf( %d%d , &m1, &m2); n     if (m1 > m2) std::swap(m1, m2); n     q[m1].push(m2); n   } n   for (int i = 2; i <= n; i++) { n     while (!q[i].empty()) { n       m1 = q[i].top(); n       q[i].pop(); n       v1.push_back(i); n       v1.push_back(m1); n     } n   } n   for (int i = 3; i < n; i++) { n     scanf( %d%d , &m1, &m2); n     if (m1 > m2) std::swap(m1, m2); n     q[m1].push(m2); n   } n   for (int i = 2; i <= n; i++) { n     while (!q[i].empty()) { n       m1 = q[i].top(); n       q[i].pop(); n       if (q[i].empty()) n         m2 = i + 1; n       else n         m2 = q[i].top(); n       v2.push_back(1); n       v2.push_back(m2); n     } n   } n   printf( %d n , (v1.size() + v2.size()) >> 1); n   int l = v1.size(); n   for (int i = 0; i < l; i += 2) printf( %d %d n , v1[i], v1[i + 1]); n   l = v2.size(); n   for (int i = l - 1; i >= 0; i -= 2) printf( %d %d n , v2[i - 1], v2[i]); n } n }  // namespace fdd n int main() { n   fdd::solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native ) n #pragma GCC optimize( Ofast,O3,unroll-loops ) n using namespace std; n struct cplx { n   long double a, b; n   cplx(long double a = 0, long double b = 0) : a(a), b(b) {} n   const cplx operator+(const cplx &c) const { return cplx(a + c.a, b + c.b); } n   const cplx operator-(const cplx &c) const { return cplx(a - c.a, b - c.b); } n   const cplx operator*(const cplx &c) const { n     return cplx(a * c.a - b * c.b, a * c.b + b * c.a); n   } n   const cplx operator/(const long double &x) const { n     return cplx(a / x, b / x); n   } n   const cplx conj() const { return cplx(a, -b); } n }; n const long double PI = acosl(-1); n const int N = (1 << 20) + 5; n int rev[N]; n cplx w[N]; n void prepare(int &n) { n   int sz = __builtin_ctz(n); n   for (int i = 1; i < n; ++i) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (sz - 1)); n   w[0] = 0, w[1] = 1, sz = 1; n   while (1 << sz < n) { n     cplx w_n = n         cplx(cosl(2 * PI / (1 << (sz + 1))), sinl(2 * PI / (1 << (sz + 1)))); n     for (int i = 1 << (sz - 1); i < (1 << sz); ++i) { n       w[i << 1] = w[i], w[i << 1 | 1] = w[i] * w_n; n     } n     ++sz; n   } n } n void fft(cplx *a, int n) { n   for (int i = 1; i < n - 1; ++i) { n     if (i < rev[i]) swap(a[i], a[rev[i]]); n   } n   for (int h = 1; h < n; h <<= 1) { n     for (int s = 0; s < n; s += h << 1) { n       for (int i = 0; i < h; ++i) { n         cplx &u = a[s + i], &v = a[s + i + h], t = v * w[h + i]; n         v = u - t, u = u + t; n       } n     } n   } n } n static cplx f[N]; n vector<long long> multiply(vector<long long> a, vector<long long> b) { n   int n = a.size(), m = b.size(), sz = 1; n   while (sz < n + m - 1) sz <<= 1; n   prepare(sz); n   for (int i = 0; i < sz; ++i) f[i] = cplx(i < n ? a[i] : 0, i < m ? b[i] : 0); n   fft(f, sz); n   for (int i = 0; i <= (sz >> 1); ++i) { n     int j = (sz - i) & (sz - 1); n     cplx x = (f[i] * f[i] - (f[j] * f[j]).conj()) * cplx(0, -0.25); n     f[j] = x, f[i] = x.conj(); n   } n   fft(f, sz); n   vector<long long> c(n + m - 1); n   for (int i = 0; i < n + m - 1; ++i) c[i] = f[i].a / sz + 0.3; n   return c; n } n int main() { n   long long a, b, c, d; n   cin >> a >> b >> c >> d; n   long long ans = (b - a + 1) * (c - b + 1) * (d - c + 1); n   std::vector<long long> A(b + 1); n   std::vector<long long> B(c + 1); n   for (int i = a; i <= b; i++) A[i] = 1; n   for (int i = b; i <= c; i++) B[i] = 1; n   std::vector<long long> C = multiply(A, B); n   long long prev = 0; n   for (int i = 0; i <= d; i++) { n     if (i < C.size()) prev += C[i]; n     if (i >= c) { n       ans -= prev; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans[60]; n int main() { n   long long t, a, n, m, b, v, xmin, xmax, act, sum, i, vmi; n   cin >> t; n   while (t--) { n     cin >> a >> b >> m; n     if (a == b) { n       cout <<  1   << a <<   n ; n       continue; n     } n     for (n = 2; n <= 50; n++) { n       v = ((1ll) << (n - 2)); n       xmin = v * a + v; n       xmax = v * a + v * m; n       if (xmin > b) { n         n = 51; n         break; n       } n       if (b <= xmax) { n         act = xmax; n         ans[1] = a; n         sum = ans[1]; n         for (i = 2; i <= n; i++) { n           v = ((1ll) << (max(n - i - 1, 0ll))); n           vmi = m - (act - b) / v; n           vmi = max(vmi, 1ll); n           ans[i] = sum + vmi; n           sum = sum + ans[i]; n           act -= (m - vmi) * v; n         } n         if (i <= n || ans[n] != b) continue; n         cout << n <<    ; n         for (i = 1; i <= n; i++) cout << ans[i] <<    ; n         cout <<   n ; n         break; n       } n     } n     if (n == 51) { n       cout << -1 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n int n, m, k, ans, a; n vector<int> adj[N], lan[N]; n bool mark[N]; n void input() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> k; n     if (k == 0) a++; n     while (k--) { n       int v; n       cin >> v; n       lan[v].push_back(i); n     } n   } n } n void aa_adj() { n   for (int i = 1; i <= m; i++) { n     if (lan[i].size() == 0) continue; n     for (int j = 0; j < lan[i].size() - 1; j++) { n       adj[lan[i][j]].push_back(lan[i][j + 1]), n           adj[lan[i][j + 1]].push_back(lan[i][j]); n     } n   } n } n void dfs(int v) { n   mark[v] = true; n   for (int u : adj[v]) n     if (!mark[u]) dfs(u); n } n void find_ans() { n   for (int i = 1; i <= n; i++) { n     if (!mark[i]) { n       dfs(i), ans++; n     } n   } n   if (a == n) n     cout << ans << endl; n   else n     cout << ans - 1 << endl; n } n int main() { n   input(); n   aa_adj(); n   find_ans(); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:167177216 ) n using namespace std; n const int MAXN = 9; n int main() { n   long long n, A; n   scanf( %I64d %I64d , &n, &A); n   long long sum = 0; n   vector<int> d(n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &d[i]); n     sum += d[i]; n   } n   for (int i = 0; i < n; i++) { n     long long without = sum - d[i]; n     long long need = A - without; n     if (need <= 0) { n       long long need = A - (n - 1); n       if (d[i] <= need) n         cout << 0 <<    ; n       else { n         cout << d[i] - need <<    ; n       } n     } else { n       long long ans = need - 1; n       long long razn = d[i] - need; n       if (without - (n - 1) < razn) ans += (razn - without + (n - 1)); n       cout << ans <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double EPS = 1e-6; n const int MOD = 1e9 + 7; n const int MAXN = 110; n const double PI = acos(-1.0); n int ipt[MAXN][MAXN]; n int main() { n   int n, m, k; n   while (~scanf( %d%d%d , &n, &m, &k)) { n     int ans = INF, all = 1 << m; n     for (int i = 0; i < (n); ++i) n       for (int j = 0; j < (m); ++j) scanf( %d , &ipt[i][j]); n     if (n < m) { n       for (int i = 0; i < (n); ++i) n         for (int j = (i + 1); j < (m); ++j) swap(ipt[i][j], ipt[j][i]); n       swap(n, m); n     } n     if (n > k) { n       for (int i = 0; i < (n); ++i) { n         int tans = 0; n         for (int j = 0; j < (n); ++j) { n           int cnt = 0; n           for (int k = 0; k < (m); ++k) cnt += ipt[i][k] ^ ipt[j][k]; n           tans += min(cnt, m - cnt); n         } n         ans = min(ans, tans); n       } n     } else { n       for (int mask = 0; mask < all; mask++) { n         int tans = 0; n         for (int i = 0; i < (n); ++i) { n           int cnt = 0; n           for (int j = 0; j < (m); ++j) cnt += ipt[i][j] ^ (mask >> j & 1); n           tans += min(cnt, m - cnt); n         } n         ans = min(ans, tans); n       } n     } n     printf( %d n , ans <= k ? ans : -1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n int t, n; n int cnt, num, maxx; n int a[maxn]; n int vis[maxn]; n int m1[maxn]; n int m2[maxn]; n void init() { n   num = 0; n   maxx = 0; n   memset(vis, 0, sizeof(vis)); n } n int main() { n   scanf( %d , &t); n   while (t--) { n     cnt = 0; n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     for (int i = 1; i <= n; i++) m1[i] = 0, m2[i] = 0; n     init(); n     for (int i = 1; i <= n; i++) { n       maxx = max(maxx, a[i]); n       if (!vis[a[i]]) { n         num++; n         vis[a[i]] = 1; n       } else n         break; n       if (num == maxx) n         m1[i] = 1; n       else n         m1[i] = 0; n     } n     init(); n     for (int i = n; i >= 1; i--) { n       maxx = max(maxx, a[i]); n       if (!vis[a[i]]) { n         num++; n         vis[a[i]] = 1; n       } else n         break; n       if (num == maxx) { n         m2[i] = 1; n         if (i > 1 && m1[i - 1]) cnt++; n       } else n         m2[i] = 0; n     } n     printf( %d n , cnt); n     for (int i = 1; i < n; i++) n       if (m1[i] && m2[i + 1]) printf( %d %d n , i, n - i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100, M = 10000; n int n, m, a[N + 9], ca; n double x, ans; n void into() { n   scanf( %d%lf , &n, &x); n   int p = 0; n   for (int i = 1; i <= n; ++i) { n     int t; n     scanf( %d , &t); n     t << 1 <= x ? ans += t : m += a[++ca] = t; n   } n   x /= 2; n } n double dp[N + 9][M + 9]; n void Get_dp() { n   dp[0][0] = 1; n   for (int i = 1; i <= ca; ++i) n     for (int j = i; j >= 1; --j) n       for (int k = m; k >= a[i]; --k) n         dp[j][k] += dp[j - 1][k - a[i]] * j / (ca - j + 1); n } n void Get_ans() { n   for (int i = 1; i <= ca; ++i) n     for (int j = 0; j <= m; ++j) n       ans += dp[i][j] * min((1.0 * n / i + 1) * x, 1.0 * j / i); n } n void work() { n   Get_dp(); n   Get_ans(); n } n void outo() { printf( %.12lf n , ans); } n int main() { n   into(); n   work(); n   outo(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (1 << 30); n const int MAXN = 100000; n struct node { n   int le, ri; n   set<int> Set; n   int mx, mn; n } tree[24 * MAXN + 5]; n bool tag[MAXN + 5]; n void pushup(int x) { n   if (tree[x].le == tree[x].ri) n     tree[x].mx = tree[x].mn = *tree[x].Set.rbegin(); n   else { n     tree[x].mn = n         max(*tree[x].Set.rbegin(), min(tree[x << 1].mn, tree[x << 1 | 1].mn)); n     tree[x].mx = n         max(*tree[x].Set.rbegin(), max(tree[x << 1].mx, tree[x << 1 | 1].mx)); n   } n   if (tree[x].mx < tree[x].mn) tree[x].mx = -1; n   if (tree[x].mx != -1 && tag[tree[x].mx]) tree[x].mx = -1; n } n void build(int x, int l, int r) { n   tree[x].le = l, tree[x].ri = r; n   tree[x].mx = tree[x].mn = 0; n   tree[x].Set.clear(); n   tree[x].Set.insert(0); n   if (l == r) return; n   int mid = (l + r) >> 1; n   build(x << 1, l, mid); n   build(x << 1 | 1, mid + 1, r); n } n void modify(int x, int l, int r, int k, int type) { n   if (l > tree[x].ri || r < tree[x].le) return; n   if (l <= tree[x].le && tree[x].ri <= r) { n     if (type) n       tree[x].Set.insert(k); n     else n       tree[x].Set.erase(k); n     pushup(x); n     return; n   } n   modify(x << 1, l, r, k, type); n   modify(x << 1 | 1, l, r, k, type); n   pushup(x); n } n void update(int x, int l, int r) { n   if (l > tree[x].ri || r < tree[x].le) return; n   if (l <= tree[x].le && tree[x].ri <= r) { n     pushup(x); n     return; n   } n   update(x << 1, l, r); n   update(x << 1 | 1, l, r); n   pushup(x); n } n int N; n int Xa[MAXN + 5], Xb[MAXN + 5], Ya[MAXN + 5], Yb[MAXN + 5]; n int dct[2][6 * MAXN + 5], dcnt[2]; n void discrete() { n   for (int i = 0; i < 2; i++) sort(dct[i] + 1, dct[i] + dcnt[i] + 1); n   for (int i = 0; i < 2; i++) n     dcnt[i] = unique(dct[i] + 1, dct[i] + dcnt[i] + 1) - dct[i] - 1; n   for (int i = 1; i <= N; i++) { n     Xa[i] = lower_bound(dct[0] + 1, dct[0] + dcnt[0] + 1, Xa[i]) - dct[0]; n     Xb[i] = lower_bound(dct[0] + 1, dct[0] + dcnt[0] + 1, Xb[i]) - dct[0]; n     Ya[i] = lower_bound(dct[1] + 1, dct[1] + dcnt[1] + 1, Ya[i]) - dct[1]; n     Yb[i] = lower_bound(dct[1] + 1, dct[1] + dcnt[1] + 1, Yb[i]) - dct[1]; n   } n } n void insert_dct(int val, int type) { dct[type][++dcnt[type]] = val; } n struct query { n   int le, ri, num; n   bool type; n   query(int _l = 0, int _r = 0, int _n = 0, bool _t = 0) n       : le(_l), ri(_r), num(_n), type(_t) {} n }; n vector<query> vec[6 * MAXN + 5]; n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) { n     scanf( %d%d%d%d , &Xa[i], &Ya[i], &Xb[i], &Yb[i]); n     Xb[i]--, Yb[i]--; n     insert_dct(Xa[i], 0); n     insert_dct(Xa[i] + 1, 0); n     insert_dct(Xa[i] - 1, 0); n     insert_dct(Xb[i], 0); n     insert_dct(Xb[i] + 1, 0); n     insert_dct(Xb[i] - 1, 0); n     insert_dct(Ya[i], 1); n     insert_dct(Ya[i] + 1, 1); n     insert_dct(Ya[i] - 1, 1); n     insert_dct(Yb[i], 1); n     insert_dct(Yb[i] + 1, 1); n     insert_dct(Yb[i] - 1, 1); n   } n   discrete(); n   for (int i = 1; i <= N; i++) { n     vec[Xa[i]].push_back(query(Ya[i], Yb[i], i, 1)); n     vec[Xb[i] + 1].push_back(query(Ya[i], Yb[i], i, 0)); n   } n   build(1, 1, dcnt[1]); n   Ya[0] = 1; n   Yb[0] = dcnt[1]; n   for (int i = 1; i <= dcnt[0]; i++) { n     for (int j = 0; j < vec[i].size(); j++) n       modify(1, vec[i][j].le, vec[i][j].ri, vec[i][j].num, vec[i][j].type); n     while (tree[1].mx != -1) { n       tag[tree[1].mx] = true; n       update(1, Ya[tree[1].mx], Yb[tree[1].mx]); n     } n   } n   int ans = 0; n   for (int i = 0; i <= N; i++) n     if (tag[i]) ans++; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n using PII = pair<int, int>; n using PLL = pair<long long, long long>; n using VLL = vector<long long>; n using VI = vector<int>; n inline void fastio() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fL; n const int mod1 = 998244353; n const int mod2 = 1e9 + 7; n void solve() { n   int n, m, k; n   cin >> n >> m >> k; n   if (k <= 1) { n     cout <<  NO  << endl; n     return; n   } n   if (m < n - 1) { n     cout <<  NO  << endl; n     return; n   } n   long long cnt = 1ll * n * (n - 1) / 2; n   if (m > cnt) { n     cout <<  NO  << endl; n     return; n   } n   if (k == 2 && n > 1) { n     cout <<  NO  << endl; n     return; n   } n   if (k >= 2 && n == 1) { n     cout <<  YES  << endl; n     return; n   } n   if (k > 3) { n     cout <<  YES  << endl; n     return; n   } n   if (m == cnt) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n } n signed main() { n   fastio(); n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool prime[100000 + 5]; n int ans[100000 + 5]; n int main() { n   long long int n; n   cin >> n; n   for (int i = 0; i <= n; i++) prime[i] = true; n   long long int k = 1; n   for (int p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       ans[p] = k; n       for (int i = p * p; i <= n; i += p) { n         if (i <= n) { n           prime[i] = false; n           ans[i] = k; n         } n       } n       prime[p] = false; n       k++; n     } n   } n   for (int p = 2; p <= n; p++) { n     if (prime[p] == true) { n       for (int i = p; i <= n; i += p) { n         if (i <= n) { n           prime[i] = false; n           ans[i] = k; n         } n       } n       k++; n     } n   } n   for (int p = 2; p <= n; p++) cout << ans[p] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   string s; n   cin >> n >> k; n   cin >> s; n   int isThere[26]; n   for (int i = 0; i < 26; i++) isThere[i] = 0; n   bool ok = true; n   for (int i = 0; i < n; i++) { n     isThere[s[i] -  a ]++; n     if (isThere[s[i] -  a ] > k) { n       ok = false; n       break; n     } n   } n   if (ok) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXD = 60 + 5; n const int MAXN = 2e3 * 60 + 5; n const int mod = 1e9 + 7; n inline long long pw(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return res; n } n inline int get_lb(long long x) { n   int res = 0; n   while (x >> res) ++res; n   return res - 1; n } n int d; n long long a[MAXN]; n int b[MAXN]; n long long pt[MAXN]; n int pcnt = 0, must[MAXN], dp[MAXN][5]; n int f[MAXD]; n inline int get(long long u) { n   int pos = lower_bound(pt + 1, pt + pcnt + 1, u) - pt; n   if (pos > pcnt || pt[pos] != u) return -1; n   return pos; n } n inline vector<int> get_dp(long long u) { n   int id = get(u); n   if (id != -1) n     return vector<int>(dp[id], dp[id] + 3); n   else n     return vector<int>(3, f[d - get_lb(u)]); n } n int main(void) { n   int n; n   scanf( %d%d , &d, &n); n   for (int i = 1; i <= n; ++i) { n     static char t[100]; n     scanf( %lld%s , &a[i], t + 1); n     b[i] = t[1] ==  w  || t[1] ==  y  ? 1 : t[1] ==  g  || t[1] ==  b  ? 2 : 3; n   } n   f[1] = 1; n   for (int i = 2; i <= d; ++i) f[i] = 4ll * f[i - 1] * f[i - 1] % mod; n   pt[++pcnt] = 1; n   for (int i = 1; i <= n; ++i) { n     long long u = a[i]; n     while (u) { n       pt[++pcnt] = u; n       u >>= 1; n     } n   } n   sort(pt + 1, pt + pcnt + 1); n   pcnt = unique(pt + 1, pt + pcnt + 1) - pt - 1; n   for (int i = 1; i <= n; ++i) must[get(a[i])] = b[i]; n   for (int i = pcnt; i >= 1; --i) { n     if (pt[i] >= (1ll << (d - 1))) { n       if (!must[i]) n         dp[i][0] = dp[i][1] = dp[i][2] = 1; n       else n         dp[i][must[i] - 1] = 1; n       continue; n     } n     long long u = pt[i]; n     vector<int> ls = get_dp(u << 1); n     vector<int> rs = get_dp(u << 1 | 1); n     for (int x = 0; x < 3; ++x) { n       if (must[i] && x != must[i] - 1) continue; n       for (int y = 0; y < 3; ++y) n         if (y != x) n           for (int z = 0; z < 3; ++z) n             if (z != x) dp[i][x] = (dp[i][x] + (long long)ls[y] * rs[z]) % mod; n     } n   } n   int ans = 0; n   for (int i = 0; i < 3; ++i) ans = (ans + dp[1][i]) % mod; n   ans = ans * pw(2, (1ll << d) - 1 - n) % mod; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> ans; n bool check(string s, int L, int R) { n   if (s[L] ==  0 ) { n     if (R == L + 1) { n       return true; n     } n     return false; n   } n   int n = 0; n   for (int i = L; i < R; i++) { n     n *= 10; n     n += s[i] -  0 ; n   } n   return (n >= 0 && n < 256); n } n void func(string s) { n   int N = s.length(); n   for (int i = 1; i <= 3; i++) { n     for (int j = i + 1; j <= i + 3; j++) { n       for (int k = j + 1; k <= j + 3; k++) { n         if (N - k >= 1 && N - k <= 3) { n           if (check(s, 0, i) && check(s, i, j) && check(s, j, k) && n               check(s, k, N)) { n             string final; n             final = s.substr(0, i) +  .  + s.substr(i, j - i) +  .  + n                     s.substr(j, k - j) +  .  + s.substr(k, N - k); n             ans.push_back(final); n           } n         } n       } n     } n   } n } n void dfs(int L, string s, int mask, int pos, int used) { n   if (pos == L) { n     if (used == mask) { n       func(s); n       return; n     } n   } n   int pos2 = L - 1 - pos; n   if (pos2 < pos) { n     if (mask != used) { n       return; n     } n     char c = s[pos2]; n     dfs(L, s + c, mask, pos + 1, used); n   } else { n     char c; n     for (int i = 0; i < 10; i++) { n       if (mask & (1 << i)) { n         c = i +  0 ; n         dfs(L, s + c, mask, pos + 1, (used | (1 << i))); n       } n     } n   } n } n int main() { n   int n; n   int a[11]; n   cin >> n; n   int mask = 0; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     mask |= (1 << a[i]); n   } n   if (n <= 6) { n     for (int i = 4; i <= 12; i++) { n       dfs(i,   , mask, 0, 0); n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i].c_str() << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long int a; n   long long int b; n }; n node p[100005]; n bool comp(node x, node y) { n   if (x.b < y.b) return true; n   return false; n } n int main() { n   long long int n, r, avg; n   cin >> n >> r >> avg; n   long long int s = 0; n   for (int i = (0); i < (n); ++i) { n     cin >> p[i].a >> p[i].b; n     s += p[i].a; n   } n   long long int cc = avg * n; n   if (s >= cc) n     cout << 0 << endl; n   else { n     long long int to = avg * n; n     long long int add = to - s; n     long long int count = 0; n     sort(p, p + n, comp); n     for (int j = (0); j < (n); ++j) { n       if (add == 0) break; n       long long int maxim = r - p[j].a; n       if (r < p[j].a) continue; n       if (add > maxim) { n         add = add - maxim; n         count += p[j].b * maxim; n       } else { n         count += add * p[j].b; n         add = 0; n       } n     } n     cout << count << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int columns[n + 1]; n   memset(columns, 0, sizeof(columns)); n   for (int i = 0; i < m; i++) { n     int tmp; n     cin >> tmp; n     columns[tmp]++; n   } n   int ans = 1001; n   for (int i = 1; i <= n; i++) { n     ans = min(ans, columns[i]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int head[100005]; n struct edge { n   int vet, next; n } E[200005]; n int i, j, k, n, m, s, t, tot, L; n int top[100005]; n int fa[100005]; n int dep[100005]; n int a[100005]; n int dist[3005][3005]; n double ans; n int X, Y, all; n int cyc[100005]; n int getf(int x) { n   if (x != fa[x]) fa[x] = getf(fa[x]); n   return fa[x]; n } n void add(int u, int v) { n   E[++tot] = (edge){v, head[u]}; n   head[u] = tot; n } n void getroad(int u, int dad) { n   if (u == Y) { n     L = cyc[u] = 1; n     return; n   } n   for (int e = head[u]; e != -1; e = E[e].next) n     if (e != dad) { n       getroad(E[e].vet, e ^ 1); n       if (cyc[E[e].vet] > 0) { n         cyc[u] = cyc[E[e].vet] + 1; n         L = max(L, cyc[u]); n       } n     } n } n void dfs(int u, const int &anc, int dad, int deep) { n   dep[u] = deep; n   top[u] = anc; n   for (int e = head[u]; e != -1; e = E[e].next) n     if (e != dad && cyc[E[e].vet] == 0) dfs(E[e].vet, anc, e ^ 1, deep + 1); n } n void getdis(int u, const int &anc, int dad, int D) { n   dist[anc][u] = D; n   for (int e = head[u]; e != -1; e = E[e].next) n     if (e != dad) getdis(E[e].vet, anc, e ^ 1, D + 1); n } n void DO() { n   for (int i = 1; i <= n; i++) getdis(i, i, -1, 0); n } n int main() { n   tot = -1; n   memset(head, -1, sizeof(head)); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) fa[i] = i; n   for (int i = 1; i <= n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x++; n     y++; n     if (getf(x) == getf(y)) { n       X = x; n       Y = y; n       continue; n     } n     add(x, y); n     add(y, x); n     fa[getf(x)] = getf(y); n   } n   DO(); n   getroad(X, -1); n   for (int i = 1; i <= n; i++) n     if (cyc[i] > 0) dfs(i, i, -1, 0); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (i != j) { n         if (top[i] == top[j]) n           ans += 1.0 / (dist[i][j] + 1); n         else { n           int x = dep[i] + dep[j]; n           int y = abs(cyc[top[i]] - cyc[top[j]]); n           int z = L - y; n           ans += 1.0 / (x + y + 1) + 1.0 / (x + z + 1) - 1.0 / (x + L); n         } n       } n   ans += n; n   printf( %.14f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[4], y[4], a[4], b[4]; n vector<int> v[2]; n void yes() { n   puts( YES ); n   exit(0); n } n void add(bool is, int at, int to) { n   if (is) n     v[is].push_back(y[at]), v[is].push_back(y[to]); n   else n     v[is].push_back(x[at]), v[is].push_back(x[to]); n } n void can(int a, int b) { n   if (v[0][0] <= a && v[0][1] >= a && v[1][0] <= b && v[1][1] >= b) yes(); n } n int main() { n   for (int i = 0; i < 4; i++) scanf( %d%d , x + i, y + i); n   add(x[0] == x[1], 0, 1); n   add(x[1] == x[2], 1, 2); n   sort(v[0].begin(), v[0].end()); n   sort(v[1].begin(), v[1].end()); n   for (int i = 0; i < 4; i++) { n     scanf( %d%d , a + i, b + i); n     can(a[i], b[i]); n   } n   can((a[0] + a[2]) / 2, (b[0] + b[2]) / 2); n   int dis = b[0] != b[2] ? abs(b[0] - b[2]) : abs(a[0] - a[2]), n       mx = (a[0] + a[2]) / 2, my = (b[0] + b[2]) / 2; n   for (int i = 0; i < 4; i++) { n     int dis1 = abs(x[i] - mx) + abs(y[i] - my); n     if (dis1 * 2 <= dis) yes(); n   } n   puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n double pi = 2 * acos(0.0); n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   for (const auto &x : v) os <<     << x; n   return os <<  } ; n } n void solve() { n   long long int l, r, m; n   cin >> l >> r >> m; n   long long int a, b, c; n   long long int mm = r - l; n   long long int p, q, ss; n   if (m < l) { n     a = l; n     b = l; n     c = l + (l - m); n     cout << a <<     << b <<     << c << endl; n     return; n   } n   for (long long int i = l; i <= r; i++) { n     p = m % i; n     q = m / i; n     q++; n     ss = q * i; n     ss -= m; n     if (p <= mm) { n       a = i; n       c = l; n       b = c + p; n       break; n     } else if (ss <= mm) { n       a = i; n       b = l; n       c = l + ss; n       break; n     } n   } n   cout << a <<     << b <<     << c << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int test_cases; n   cin >> test_cases; n   for (int tc = 1; tc <= test_cases; tc++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n long long mod = 1e9 + 7, mod2 = 998244353; n using namespace std; n long long fac[10000000]; n long long gcd(long long x, long long y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n long long fexp(long long a, long long b, long long m) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % m; n     b /= 2; n     a = a * a % m; n   } n   return ans; n } n long long inverse(long long a, long long p) { return fexp(a, p - 2, p); } n long long ncr(long long n, long long r, long long p) { n   if (r == 0) return 1; n   return (fac[n] * inverse(fac[n - r], p) % p * inverse(fac[r], p) % p) % p; n } n vector<long long> za(string s) { n   long long n = s.size(); n   vector<long long> z(n); n   long long x = 0, y = 0, p = 0; n   for (long long i = 1; i < n; i++) { n     z[i] = max(p, min(z[i - x], y - i + 1)); n     while (i + z[i] < n && s[z[i]] == s[i + z[i]]) { n       x = i; n       y = i + z[i]; n       z[i]++; n     } n   } n   return z; n } n void subset(long long a[], long long k) { n   for (int i = 1; i < pow(2, k); i++) { n     for (int j = 0; j < k; j++) { n       if (i & 1 << j) { n         cout << a[j] <<    ; n       } n     } n     cout <<   n ; n     ; n   } n } n vector<long long> pr(string s) { n   long long n = s.length(); n   vector<long long> pi(n); n   for (int i = 1; i < n; i++) { n     int j = pi[i - 1]; n     while (j > 0 && s[i] != s[j]) j = pi[j - 1]; n     if (s[i] == s[j]) j++; n     pi[i] = j; n   } n   return pi; n } n long long d[100005]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n, s, l, r, x = 0; n   cin >> n >> s; n   for (long long i = 1; i < n; i++) { n     cin >> l >> r; n     d[l]++; n     d[r]++; n   } n   for (long long i = 1; i <= n; i++) { n     if (d[i] == 1) x++; n   } n   cout << fixed << setprecision(50) << ((2 * s) / (1.0 * x)); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n map<int, int> mp; n int a[11], aa[11]; n int b[11]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n     if (a[b[i]] == 0) { n       a[b[i]]++; n       mp[b[i]]++; n     } n   } n   for (int i = 0; i < m; i++) { n     int x; n     cin >> x; n     if (aa[x] == 0) { n       aa[x]++; n       mp[x]++; n     } n   } n   for (int i = 0; i < n; i++) { n     if (mp[b[i]] == 2) cout << b[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y, a = 0, b = 0; n   cin >> n; n   vector<pair<int, int>> v; n   while (n--) { n     cin >> x >> y; n     a += x; n     b += y; n     v.push_back(make_pair(x, y)); n   } n   bool ok = 0; n   if (a % 2 == 0 && b % 2 == 0) { n     cout << 0; n     return 0; n   } n   if (a % 2 && b % 2) { n     for (auto i : v) { n       if ((i.first % 2 == 0 && i.second % 2) || n           (i.first % 2 && i.second % 2 == 0)) { n         ok = 1; n         break; n       } n     } n   } n   cout << (ok ? 1 : -1); n } n


#include <bits/stdc++.h> n const int MAXN = 3000 + 1000; n int n, sum; n int in[MAXN], out[MAXN]; n struct Union_Find_Set { n   int f[MAXN]; n   void Init(int N) { n     for (int i = 1, _ = N; i <= _; i++) f[i] = i; n   } n   int Find(int x) { return x == f[x] ? x : f[x] = Find(f[x]); } n   bool Union(int x, int y) { n     x = Find(x); n     y = Find(y); n     if (x == y) return 0; n     in[x] += in[y]; n     out[x] += out[y]; n     f[y] = x; n     if (in[x] + out[x] > sum) return 1; n     return 0; n   } n } t; n struct Edge { n   int u, v, w; n   Edge() {} n   Edge(int u, int v, int w) : u(u), v(v), w(w) {} n   bool operator<(const Edge &a) const { return w < a.w; } n } G[MAXN]; n void Init() { n   int u, v, w; n   scanf( %d , &n); n   t.Init(n); n   for (int i = 1, _ = n - 1; i <= _; i++) { n     scanf( %d%d%d , &u, &v, &w); n     G[i] = Edge(u, v, w); n   } n   for (int i = 1, _ = n; i <= _; i++) { n     scanf( %d , &out[i]); n     sum += out[i]; n     in[i] = 1; n   } n } n void Solve() { n   if (n == 1) { n     puts( 0 ); n     return; n   } n   int u, v; n   std::sort(G + 1, G + n); n   for (int i = 1, _ = n - 1; i <= _; i++) { n     if (t.Union(G[i].u, G[i].v)) { n       printf( %d n , G[i].w); n       return; n     } n   } n } n int main() { n   Init(); n   Solve(); n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n namespace _buff { n const size_t BUFF = 1 << 19; n char buff[BUFF], *begin = buff, *end = buff; n char getc() { n   if (begin == end) { n     begin = buff; n     end = buff + fread(buff, 1, BUFF, stdin); n   } n   return begin == end ? -1 : *begin++; n } n }  // namespace _buff n LL read() { n   using namespace _buff; n   LL ret = 0; n   bool pos = true; n   char c = getc(); n   for (; (c <  0  || c >  9 ) && c !=  - ; c = getc()) { n     assert(~c); n   } n   if (c ==  - ) { n     pos = false; n     c = getc(); n   } n   for (; c >=  0  && c <=  9 ; c = getc()) { n     ret = (ret << 3) + (ret << 1) + (c ^ 48); n   } n   return pos ? ret : -ret; n } n const size_t N = 100 + 5; n const int MOD = 1e9 + 7; n void add(int &dp, LL val) { dp = (dp + val) % MOD; } n int f[N][N], g[N][N][N], cnt3[N], d[N]; n LL getG(int i, int j, int k) { n   if (i < 0 || j < 0 || k < 0) return 0; n   return g[i][j][k]; n } n int main() { n   int n = read(); n   for (int i = 1; i <= n; ++i) { n     cnt3[i] = cnt3[i - 1] + ((d[i] = read()) & 1); n   } n   g[0][0][0] = 1; n   for (int c0 = 0; c0 <= n; ++c0) { n     for (int c2 = 0; c2 <= n; ++c2) { n       for (int c1 = !c2; c1 <= n; ++c1) { n         int &cg = g[c0][c1][c2]; n         if (c2 > 0) { n           add(cg, getG(c0 - 2, c1, c2 - 1) * c0 * (c0 - 1) / 2); n           add(cg, getG(c0 - 1, c1 + 1, c2 - 2) * c0 * (c2 - 1)); n           add(cg, getG(c0, c1 + 2, c2 - 3) * (c2 - 1) * (c2 - 2) / 2); n           add(cg, getG(c0, c1, c2 - 2) * (c2 - 1) * c1); n           add(cg, getG(c0 - 1, c1 - 1, c2 - 1) * c0 * c1); n           add(cg, getG(c0, c1 - 2, c2 - 1) * c1 * (c1 - 1) / 2); n         } else { n           add(cg, getG(c0 - 1, c1 - 1, c2) * c0); n           add(cg, getG(c0, c1 - 2, c2) * (c1 - 1)); n         } n       } n     } n   } n   f[n + 1][n] = 1; n   for (int l = n; l >= 2; --l) { n     for (int r = l; r <= n; ++r) { n       int c2 = cnt3[r] - cnt3[l - 1]; n       int c1 = r - l + 1 - c2; n       for (int k = 0; k + r <= n; ++k) { n         add(f[l][r], static_cast<LL>(f[r + 1][r + k]) * g[k][c1][c2]); n       } n     } n   } n   printf( %d n , f[2][d[1] + 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void func(void) { n   freopen( input.c ,  r , stdin); n   freopen( output.c ,  w , stdout); n } n void print(vector<long long> &v) { n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) { n     printf( %lld  , v[i]); n   } n   printf(  n ); n } n void print(vector<pair<long long, long long> > &v) { n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) { n     printf( %lld %lld n , v[i].first, v[i].second); n   } n } n void print(double d) { cout << fixed << setprecision(10) << d << endl; } n void print(string s, double d) { n   cout << s <<    ; n   cout << fixed << setprecision(10) << d << endl; n } n int main() { n   long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m, n                      fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000, n                      mn1 = 8000000000000000000; n   cin >> t; n   while (t--) { n     cin >> n; n     vector<int> v1, v2, temp1; n     for (int i = 0; i < n; i++) { n       cin >> x; n       v1.push_back(x); n     } n     for (int i = 0; i < n; i++) { n       cin >> x; n       v2.push_back(x); n     } n     int mid = (n + 1) / 2; n     vector<pair<int, int> > vp1, vp2; n     for (int i = 0; i < mid; i++) { n       vp1.push_back({v1[i], v1[n - i - 1]}); n       vp2.push_back({v2[i], v2[n - i - 1]}); n       if (vp1[i].first > vp1[i].second) swap(vp1[i].first, vp1[i].second); n       if (vp2[i].first > vp2[i].second) swap(vp2[i].first, vp2[i].second); n     } n     sort(vp1.begin(), vp1.end()); n     sort(vp2.begin(), vp2.end()); n     if (vp1 == vp2) { n       cout <<  Yes n ; n     } else n       cout <<  No n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int INF = 1e9; n const int MAXN = 20010; n const int MAXK = 110; n int N, K; n int A[MAXN]; n int ord[MAXN]; n int lo[MAXN], hi[MAXN]; n struct line { n   int k, b; n   line() {} n   line(int k_, int b_) : k(k_), b(b_) {} n   int eval(int x) const { return k * x + b; } n }; n bool bad(const line& a, const line& b, const line& c) { n   return ll(b.b - a.b) * (b.k - c.k) <= ll(c.b - b.b) * (a.k - b.k); n } n void insert_hull(vector<line>& hull, const line& l) { n   while (hull.size() >= 2 && bad(hull.end()[-2], hull.end()[-1], l)) { n     hull.pop_back(); n   } n   hull.push_back(l); n } n int get_min(vector<line>& hull, int x) { n   if (hull.empty()) { n     return INF; n   } n   while (hull.size() >= 2 && hull.back().eval(x) >= hull.end()[-2].eval(x)) { n     hull.pop_back(); n   } n   return hull.back().eval(x); n } n vector<line> segg[2 * MAXN]; n void update_g(int a, const line& l) { n   for (a += N + 1; a >= 1; a /= 2) { n     insert_hull(segg[a], l); n   } n } n int query_g(int a, int b, int x) { n   int res = INF; n   for (a += N + 1, b += N + 1; a < b; a /= 2, b /= 2) { n     if (a & 1) { n       res = min(res, get_min(segg[a], x)); n       a++; n     } n     if (b & 1) { n       b--; n       res = min(res, get_min(segg[b], x)); n     } n   } n   return res; n } n vector<line> segdp[2 * MAXN]; n void update_dp(int a, int b, const line& l) { n   for (a += N + 1, b += N + 1; a < b; a /= 2, b /= 2) { n     if (a & 1) { n       insert_hull(segdp[a], l); n       a++; n     } n     if (b & 1) { n       b--; n       insert_hull(segdp[b], l); n     } n   } n } n int query_dp(int a, int x) { n   int res = INF; n   for (a += N + 1; a >= 1; a /= 2) { n     res = min(res, get_min(segdp[a], x)); n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> N >> K; n   for (int i = 1; i <= N; i++) { n     cin >> A[i]; n   } n   iota(ord, ord + N + 1, 0); n   sort(ord, ord + N + 1, [&](int i, int j) { return A[i] < A[j]; }); n   vector<int> st; n   for (int i = 0; i <= N; i++) { n     while (st.size() && A[i] >= A[st.back()]) st.pop_back(); n     if (st.size()) { n       lo[i] = st.back(); n     } else { n       lo[i] = 0; n     } n     st.push_back(i); n   } n   A[N + 1] = INF; n   st = {N + 1}; n   for (int i = N; i >= 1; i--) { n     while (A[i] >= A[st.back()]) st.pop_back(); n     hi[i] = st.back(); n     st.push_back(i); n   } n   vector<int> dp(N + 1, INF); n   dp[0] = 0; n   for (int k = 0; k < K; k++) { n     for (int i = 1; i < 2 * (N + 1); i++) { n       segg[i].clear(); n       segdp[i].clear(); n     } n     for (int i = 0; i <= N; i++) { n       if (dp[i] != INF) { n         update_g(i, line(i, dp[i])); n       } n     } n     vector<int> vals(N + 1); n     for (int o = N; o >= 0; o--) { n       int i = ord[o]; n       vals[o] = query_g(lo[i], i, -A[i]); n     } n     for (int o = 0; o <= N; o++) { n       int i = ord[o]; n       if (vals[o] < INF) { n         update_dp(i, hi[i], line(A[i], vals[o])); n       } n     } n     for (int i = 0; i <= N; i++) { n       dp[i] = query_dp(i, i); n     } n   } n   cout << dp[N] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int kMaxN = 1000005; n int aib[2 * kMaxN]; n int x[kMaxN], poz[kMaxN]; n int el[2 * kMaxN]; n bool first[kMaxN]; n void aib_update(int ind, int val) { n   while (ind < 2 * kMaxN) { n     aib[ind] += val; n     ind += ind & (-ind); n   } n   return; n } n int aib_search(int val) { n   int p = 20; n   int rez = 0; n   for (; p >= 0; --p) n     if ((1 << p) + rez < 2 * kMaxN) n       if (aib[(1 << p) + rez] < val) { n         val -= aib[(1 << p) + rez]; n         rez += (1 << p); n       } n   return rez + 1; n } n int main() { n   int n, m; n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 1; i <= m; ++i) cin >> x[i] >> poz[i]; n   int st = m + 2; n   for (int i = st; i < st + n; ++i) { n     el[i] = 0; n     aib_update(i, +1); n   } n   bool ok = true; n   for (int i = 1; i <= m and ok; ++i) { n     st--; n     int p = aib_search(poz[i]); n     if (first[x[i]] == false) { n       if (el[p] != false) ok = false; n       el[p] = x[i]; n       first[x[i]] = true; n       el[st] = x[i]; n       aib_update(p, -1); n       aib_update(st, +1); n     } else { n       if (el[p] != x[i]) ok = false; n       aib_update(p, -1); n       aib_update(st, +1); n       el[st] = x[i]; n     } n   } n   if (not ok) n     cout <<  -1 n ; n   else { n     int st = m + 2; n     int dr = 1; n     for (int i = st; i < st + n; ++i) n       if (el[i] == 0) { n         while (first[dr] != 0) ++dr; n         cout << dr <<    ; n         ++dr; n       } else { n         cout << el[i] <<    ; n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   unsigned long long t; n   cin >> t; n   while (t--) { n     unsigned long long x1, x2, y1, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     if (x1 == x2 || y1 == y2) { n       cout << 1 <<   n ; n     } else { n       unsigned long long d = x2 - x1; n       unsigned long long r = y2 - y1; n       cout << d * r + 1 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int p[N], used[N]; n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> p[i]; n   } n   for (int i = 1; i <= n; i++) { n     if (p[i] == i) { n       cout <<  YES n ; n       for (int j = 1; j <= n; j++) { n         if (i == j) continue; n         cout << i <<     << j <<   n ; n       } n       return; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (used[i]) continue; n     int j = i, length = 0; n     while (!used[j]) { n       used[j] = 1; n       length++; n       j = p[j]; n     } n     if (length & 1) { n       cout <<  NO ; n       return; n     } n   } n   memset(used, 0, sizeof used); n   for (int i = 1; i <= n; i++) { n     int j = p[i]; n     if (p[j] == i) { n       cout <<  YES n ; n       cout << i <<     << j <<   n ; n       for (int l = 1; l <= n; l++) { n         if (l == i || l == j || used[l]) continue; n         int v = l, xr = 0; n         while (!used[v]) { n           used[v] = 1; n           cout << v <<     << (xr == 0 ? i : j) <<   n ; n           xr ^= 1; n           v = p[v]; n         } n       } n       return; n     } n   } n   cout <<  NO ; n } n int main() { n   ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); n   cout.setf(ios::fixed), cout.precision(20); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 111; n vector<pair<int, int> > g[N]; n void printAns(int id, int v, int u, double x) { n   if (x >= 1) { n     swap(v, u); n     x -= 1; n   } n   x = 1 - x; n   printf( 1 %d %d %d %.12lf n , id, u, v, x); n } n void dfs(int v, int par, double x) { n   for (pair<int, int> e : g[v]) { n     if (e.first == par) continue; n     x += 2. / (int)g[v].size(); n     if (x >= 2) x -= 2; n     printAns(e.second, v, e.first, x); n     double y = x + 1; n     if (y >= 2) y -= 2; n     dfs(e.first, v, y); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int v, u; n     scanf( %d%d , &v, &u); n     g[v].push_back(make_pair(u, i)); n     g[u].push_back(make_pair(v, i)); n   } n   printf( %d n , n - 1); n   double x = 0; n   for (pair<int, int> e : g[1]) { n     printAns(e.second, 1, e.first, x); n     double y = x + 1; n     if (y >= 2) y -= 2; n     dfs(e.first, 1, y); n     x += 2. / (int)g[1].size(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5 * 100005; n int sum[N]; n char str[5 * 100005]; n int costf[5 * 100005]; n int costb[5 * 100005]; n int n, a, b, t; n int main() { n   scanf( %d , &n); n   scanf( %d , &a); n   scanf( %d , &b); n   scanf( %d , &t); n   cin >> str; n   if (str[0] ==  h ) n     costf[1] = 1; n   else n     costf[1] = 1 + b; n   for (int i = 2; i <= n; i++) { n     if (str[i - 1] ==  h ) n       costf[i] = (costf[i - 1] + 1 + a); n     else n       costf[i] = (costf[i - 1] + 1 + a + b); n   } n   if (str[n - 1] ==  h ) n     costb[n] = 1; n   else n     costb[n] = (1 + b); n   for (int i = n - 1; i >= 1; i--) { n     if (str[i - 1] ==  h ) n       costb[i] = (costb[i + 1] + 1 + a); n     else n       costb[i] = (costb[i + 1] + 1 + a + b); n   } n   vector<int> v; n   for (int i = n; i >= 1; i--) { n     v.push_back(costb[i]); n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int x = t; n     if (costf[i] > x) { n       break; n     } else { n       int temp = 0; n       temp += i; n       x -= costf[i]; n       x -= (a * i); n       if (x > 0) temp += (upper_bound(v.begin(), v.end(), x) - v.begin()); n       if (temp > n) temp = n; n       ans = max(ans, temp); n     } n   } n   vector<int> vv; n   for (int i = 2; i <= n; i++) { n     vv.push_back(costf[i] - a - costf[1]); n   } n   for (int i = n; i >= 1; i--) { n     int x = t; n     if (costb[i] + costf[1] + a > x) n       break; n     else { n       int temp = 0; n       temp += (n - i + 1); n       temp += 1; n       x -= (costb[i] + a + costf[1]); n       x -= (n - i + 2) * a; n       if (x > 0) temp += (upper_bound(vv.begin(), vv.end(), x) - vv.begin()); n       if (temp > n) temp = n; n       ans = max(ans, temp); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T BM(T p, T e, T M) { n   long long int ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return (T)ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T MDINV(T a, T M) { n   return BM(a, M - 2, M); n } n template <class T> n inline T PW(T p, T e) { n   long long int ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p); n     p = (p * p); n   } n   return (T)ret; n } n template <class T> n string NTS(T Number) { n   stringstream ss; n   ss << Number; n   return ss.str(); n } n template <class T> n T stringtonumber(const string &Text) { n   istringstream ss(Text); n   T result; n   return ss >> result ? result : 0; n } n string h; n long long int b; n long long int vis[13][2][13]; n long long int dp(long long int i, long long int choto, long long int ld) { n   if (i == h.size()) { n     if (ld == b) n       return 1; n     else n       return 0; n   } n   long long int &ret = vis[i][choto][ld]; n   if (ret != -1) return ret; n   ret = 0; n   if (!choto) { n     long long int ab = h[i] -  0 ; n     for (long long int j = 0; j <= ab; j++) { n       if (j == ab) { n         if (j == 4 || j == 7) n           ret += dp(i + 1, choto, ld + 1); n         else n           ret += dp(i + 1, choto, ld); n       } else { n         if (j == 4 || j == 7) n           ret += dp(i + 1, 1, ld + 1); n         else n           ret += dp(i + 1, 1, ld); n       } n     } n   } else { n     for (long long int j = 0; j <= 9; j++) { n       if (j == 4 || j == 7) n         ret += dp(i + 1, 1, ld + 1); n       else n         ret += dp(i + 1, 1, ld); n     } n   } n   return ret; n } n long long int fact(long long int num1, long long int num2) { n   if (num1 < num2) return 0; n   if (num1 == num2) n     return 1; n   else { n     long long int sum = num1 - num2; n     long long int res = 1; n     for (long long int i = sum + 1; i <= num1; i++) { n       res = (res * i) % 1000000007LL; n     } n     for (long long int i = 1; i <= num2; i++) { n       res = (res * MDINV(i, 1000000007LL)) % 1000000007LL; n     } n     return res; n   } n } n long long int digi[12]; n long long int vi[12][100][7]; n long long int dp1(long long int i, long long int ld, long long int nu) { n   if (i == b) { n     if (nu == 6 && ld < b) n       return 720; n     else n       return 0; n   } n   if (nu == 6) { n     if (ld < b) n       return 720; n     else n       return 0; n   } n   long long int &ret = vi[i][ld][nu]; n   if (ret != -1) return ret; n   ret = 0; n   for (long long int j = 1; j <= min(6 - nu, digi[i]); j++) { n     ret = (ret + fact(digi[i], j) * dp1(i + 1, j * i + ld, nu + j)) % n           1000000007LL; n   } n   ret = (ret + dp1(i + 1, ld, nu)) % 1000000007LL; n   return ret; n } n int main() { n   long long int n, m; n   scanf( %lld , &n); n   h = NTS(n); n   long long int tot = 0; n   for (long long int i = 1; i <= ((int)h.size()); i++) { n     b = i; n     memset(vis, -1, sizeof vis); n     digi[i] = dp(0, 0, 0); n     tot += digi[i]; n   } n   long long int res = 0; n   digi[0] = n - tot; n   for (int j = 1; j <= ((int)h.size()); j++) { n     b = j; n     memset(vi, -1, sizeof vi); n     res = (res + digi[j] * dp1(0, 0, 0)) % 1000000007LL; n   } n   printf( %lld n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(1); n   cout << fixed; n   double n, x, y; n   cin >> n >> x >> y; n   double s = (y * n) / 100; n   int p = ceil(s) - x; n   if (p >= 0) n     cout << p; n   else n     cout << 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n; n   cin >> n; n   int a, b; n   int s1 = 0; n   int s2 = 0; n   int flag = 0; n   while (n--) { n     cin >> a >> b; n     if ((a & 1) != (b & 1)) flag = 1; n     s1 += a; n     s2 += b; n   } n   cerr << s1 <<     << s2 << endl; n   int ans = 0; n   if (s1 % 2 != s2 % 2) { n     ans = -1; n   } else { n     if (s1 % 2 == 0) n       ans = 0; n     else if (!flag) n       ans = -1; n     else n       ans = 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n; n   int i; n   cin >> m >> n; n   double p[m]; n   double pre[m]; n   p[0] = pow(1.0 / m, n); n   pre[0] = p[0]; n   for (i = 1; i < m; i++) { n     p[i] = pow(double(i + 1) / m, n) - pre[i - 1]; n     pre[i] = pre[i - 1] + p[i]; n   } n   double a = 0; n   for (int k = 1; k <= m; k++) { n     a += k * p[k - 1]; n   } n   cout << a << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int arr[200] = {}, i, j, k, w, ans = 0; n   for (i = 0; i < n; i++) cin >> arr[i]; n   cin >> w; n   sort(arr, arr + n); n   for (i = 0; i < n; i++) { n     int c = 1; n     for (j = i + 1; j < n; j++) { n       if (arr[j] - arr[i] <= w) n         c++; n       else n         break; n     } n     ans = (ans > c ? ans : c); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nmax = 200001; n long long n, k; n int main() { n   cin >> n >> k; n   int p = (n / k) % 2; n   cout << (p % 2 == 1 ?  YES  :  NO ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2010; n const int INF = (int)1e9; n char ch[N][N]; n int n, m, k; n int CountSpider(int x, int y, int time) { n   int ans = 0; n   if (x - time >= 1 && ch[y][x - time] ==  R ) ans++; n   if (x + time <= m && ch[y][x + time] ==  L ) ans++; n   if (y - time >= 1 && ch[y - time][x] ==  D ) ans++; n   if (y + time <= n && ch[y + time][x] ==  U ) ans++; n   return ans; n } n int main() { n   scanf( %d%d%d n , &n, &m, &k); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) scanf( %c , &ch[i][j]); n     scanf(  n ); n   } n   for (int j = 1; j <= m; ++j) { n     int time = 0; n     int ans = 0; n     for (int i = 1; i <= n; ++i) { n       ans += CountSpider(j, i, time); n       time++; n     } n     printf( %d  , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N, F, M; n   cin >> N >> F >> M; n   int FR[200], MO[200]; n   vector<int> V; n   int mi = 10000; n   for (int i = 0; i < F; ++i) cin >> FR[i]; n   for (int j = 0; j < M; ++j) cin >> MO[j]; n   for (int i = 0; i < F; ++i) { n     int cnt = 0; n     for (int j = 0; j < M; ++j) n       if (MO[j] % FR[i] == 0) cnt++; n     if (cnt < mi) { n       V.clear(); n       V.push_back(i + 1); n       mi = cnt; n     } else if (mi == cnt) n       V.push_back(i + 1); n   } n   cout << V.size() << endl; n   for (int i = 0; i < V.size(); ++i) { n     if (i < V.size() - 1) n       cout << V[i] <<    ; n     else n       cout << V[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n  n  n void solve(){ n     int n; scanf( %d , &n); n     if (n == 2){ n         printf( 1 n2 1 n1 n2 1 n ); n     } n     else if (n == 3){ n         printf( 5 n2 3 1 n2 n1 3 n2 3 n ); n     } n     else { n         long long t = 0; n         vector<int> ans; n         vector<pair<int, int>> vc; n         ans.push_back(n / 2 + 1); n         for (int i = 3; i <= n / 2; ++i) ans.push_back(i); n         ans.push_back(1); n         for (int i = n / 2 + 2; i <= n; ++i) ans.push_back(i); n         ans.push_back(2); n         for (int i = 2; i <= n / 2; ++i){ n             vc.push_back({i, n}); n             t += (long long)(n - i) * (n - i); n         } n         for (int i = n / 2 + 1; i <= n; ++i){ n             vc.push_back({i, 1}); n             t += (long long)(i - 1) * (i - 1); n         } n         printf( %lld n , t); n         for (int it : ans) printf( %d  , it); n         printf(  n ); n         printf( %d n , n - 1); n         for (auto it : vc){ n             printf( %d %d n , it.first, it.second); n         } n     } n } n  n int main(){ n     int T; scanf( %d , &T); n     while (T--) solve(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long n, k; n long long bmm(long long x, long long y) { n   if (y) return bmm(y, x % y); n   return x; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   long long d = k; n   for (long long i = 0; i < n; i++) { n     long long x; n     cin >> x; n     d = bmm(d, x % k); n   } n   if (d == k) { n     cout << 1 <<   n ; n     cout << 0 <<   n ; n   } else { n     n = (k + d - 1) / d; n     cout << n <<   n ; n     for (long long i = 0; i < n; i++) cout << i * d <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int N = 2e5 + 4; n int main() { n   string s; n   int n; n   scanf( %d , &n); n   cin >> s; n   int pre[n], suf[n], minm = 0, bal = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  ( ) { n       pre[i] = 1; n       suf[i] = -1; n     } else { n       pre[i] = -1; n       suf[i] = 1; n     } n     bal += pre[i]; n     minm = min(minm, bal); n   } n   if (bal == 0) { n     if (minm > -2) { n       printf( Yes ); n       return 0; n     } n   } n   printf( No ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, o = 0, x = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     if (a) n       x++; n     else n       o++; n   } n   int s = x / 9; n   if (s && o) { n     for (int i = 0; i < 9 * s; i++) { n       cout << 5; n     } n     for (int i = 0; i < o; i++) { n       cout << 0; n     } n   } else if (o) n     cout << 0; n   else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n char a[200005], b[200005], c[200005]; n int v[200005], n, m; n bool verif(int poz) { n   int i, j; n   for (i = 1; i <= n; i++) c[i] = a[i]; n   for (i = 1; i <= poz; i++) c[v[i]] = 0; n   for (i = 1, j = 1; i <= n && j <= m; i++) n     if (c[i] == b[j]) j++; n   if (j == m + 1) return true; n   return false; n } n int main() { n   int i, st, dr, mij, rasp = 0; n   char ch; n   ch = fgetc(stdin); n   while (ch >=  a  && ch <=  z ) { n     n++; n     a[n] = ch; n     ch = fgetc(stdin); n   } n   ch = fgetc(stdin); n   while (ch >=  a  && ch <=  z ) { n     m++; n     b[m] = ch; n     ch = fgetc(stdin); n   } n   for (i = 1; i <= n; i++) fscanf(stdin,  %d , &v[i]); n   st = 1; n   dr = n; n   while (st <= dr) { n     mij = (st + dr) / 2; n     if (verif(mij) == true) { n       rasp = mij; n       st = mij + 1; n     } else { n       dr = mij - 1; n     } n   } n   fprintf(stdout,  %d , rasp); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b, c, ans; n int main() { n   cin >> n >> a >> b >> c; n   if (n >= b) n     ans = (n - ((n - b) / (b - c) + 1) * (b - c)) / a + (n - b) / (b - c) + 1; n   cout << max(n / a, ans); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native ) n using namespace std; n int a1, b1, c1, a2, b2, c2; n int d1, d2, d3, d4, d5, d6, d7; n int f1, f2, f3, f4, f5, f6, f7; n bool check() { n   return f1 <= d1 && f2 <= d2 && f3 <= d3 && f4 <= d4 && f5 <= d5 && f6 <= d6 && n          f7 <= d7 && (f1 + f2 + f3 + f4 <= a1) && (f1 + f2 + f5 + f6 <= b1) && n          (f1 + f3 + f5 + f7 <= c1) && n          (f1 + f2 + f3 + f4 >= d1 + d2 + d3 + d4 - a2) && n          (f1 + f2 + f5 + f6 >= d1 + d2 + d5 + d6 - b2) && n          (f1 + f3 + f5 + f7 >= d1 + d3 + d5 + d7 - c2); n } n void solve() { n   cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; n   cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6 >> d7; n   if (d1 + d2 + d3 + d4 > a1 + a2 || d1 + d2 + d5 + d6 > b1 + b2 || n       d1 + d3 + d5 + d7 > c1 + c2) { n     cout <<  -1 n ; n     return; n   } n   int t = d2 + d3 + d5; n   for (int A = 0; A <= a1; ++A) { n     for (int B = 0; B <= t; ++B) { n       int lf3 = max({0, A + B - b1}); n       int rf3 = min({d3, A + B + b2 - d1 - d2 - d5}); n       int lf5 = max({0, A + B - a1}); n       int rf5 = min({d5, A + B + a2 - d1 - d2 - d3}); n       int lf3f5 = max({0, B - d2, d1 + d3 + d5 - A - c2}); n       int rf3f5 = min({d3 + d5, c1 - A, B}); n       if (rf3 < lf3 || rf5 < lf5 || rf3f5 < lf3f5) continue; n       f3 = lf3; n       f5 = lf5; n       if (f3 + f5 > rf3f5) continue; n       if (f3 + f5 < lf3f5) { n         int tmp; n         int delta = lf3f5 - (f3 + f5); n         tmp = min(delta, rf3 - f3); n         f3 += tmp; n         delta -= tmp; n         tmp = min(delta, rf5 - f5); n         f5 += tmp; n         delta -= tmp; n         if (delta > 0) continue; n       } n       f1 = A; n       f2 = B - f3 - f5; n       f4 = max(0, d1 + d2 + d3 + d4 - a2 - A - B + f5); n       f6 = max(0, d1 + d2 + d5 + d6 - b2 - A - B + f3); n       f7 = max(0, d1 + d3 + d5 + d7 - c2 - A - B + f2); n       if (check()) { n         cout << f1 <<     << f2 <<     << f3 <<     << f4 <<     << f5 <<     n              << f6 <<     << f7 <<   n ; n         return; n       } n     } n   } n   cout <<  -1 n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline string to_string(char c) { n   string s; n   s.push_back(c); n   return s; n } n struct Node { n   bool can_delete_all = true; n   char first_cant = 0; n   bool more = false; n   string first =   ; n   string last =   ; n   int ans_len = 0; n   Node(bool can_delete_all = true, char first_cant = 0, bool more = false, n        string first =   , string last =   , int ans_len = 0) n       : can_delete_all(can_delete_all), n         first_cant(first_cant), n         more(more), n         first(first), n         last(last), n         ans_len(ans_len) {} n   friend Node operator+(pair<int, char> p, Node n) { n     auto [len, c] = p; n     if (n.can_delete_all) n       return Node(len % 2 == 0, c, false, (len % 2 == 0 ?    : to_string(c)), n                   (len % 2 == 0 ?    : to_string(c)), len % 2); n     auto add = [](string &first, string &last, int len, char c, int &ans_len) { n       ans_len += len; n       reverse(last.begin(), last.end()); n       for (int i = 0; i < len && (int)last.size() < 2; i++) last.push_back(c); n       reverse(last.begin(), last.end()); n       reverse(first.begin(), first.end()); n       for (int i = 0; i < len && i < 12; i++) first.push_back(c); n       reverse(first.begin(), first.end()); n       while ((int)first.size() > 12) first.pop_back(); n     }; n     if (c == n.first_cant) { n       if (n.more) n         add(n.first, n.last, len, c, n.ans_len); n       else n         add(n.first, n.last, len % 2, c, n.ans_len); n       return n; n     } n     if (c < n.first_cant) { n       add(n.first, n.last, len, c, n.ans_len); n       n.more = true; n       n.first_cant = c; n       return n; n     } n     assert(c > n.first_cant); n     if (len % 2 == 0) return n; n     add(n.first, n.last, 1, c, n.ans_len); n     n.more = false; n     n.first_cant = c; n     return n; n   } n   void print() { n     cout << ans_len <<    ; n     if (ans_len <= 10) n       cout << first <<   n ; n     else n       cout << first.substr(0, 5) <<  ...  << last <<   n ; n   } n }; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   string s; n   cin >> s; n   int n = (int)s.size(); n   vector<pair<int, int>> segs; n   for (int i = 0; i < n;) { n     int j = i; n     while (j < n && s[i] == s[j]) j++; n     segs.emplace_back(i, j); n     i = j; n   } n   int m = (int)segs.size(); n   segs.emplace_back(n, n); n   vector<Node> dp(m + 1); n   for (int i = m - 1; i >= 0; i--) n     dp[i] = pair<int, char>{segs[i].second - segs[i].first, s[segs[i].first]} + n             dp[i + 1]; n   int segi = 0; n   pair<int, char> cur; n   for (int i = 0; i < n; i++) { n     while (segs[segi].first < i) segi++; n     if (segs[segi].first == i) { n       dp[segi].print(); n       cur = {segs[segi].second - segs[segi].first, s[segs[segi].first]}; n       cur.first--; n     } else { n       (cur + dp[segi]).print(); n       cur.first--; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000005; n int a[MAXN], ans[MAXN]; n pair<int, int> tab[MAXN]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) { n     cin >> tab[i].first; n     tab[i].second = i; n   } n   sort(a, a + n, greater<int>()); n   sort(tab, tab + n); n   for (int i = 0; i < n; i++) ans[tab[i].second] = a[i]; n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int a[15][123]; n int b[15][123]; n int c[15][123]; n vector<int> v; n bool cmp(int x, int y) { return x > y; } n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < m; j++) cin >> a[i][j] >> b[i][j] >> c[i][j]; n   } n   int ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       v.clear(); n       for (int h = 0; h < m; h++) n         for (int t = 0; t < c[i][h]; t++) n           if (b[j][h] - a[i][h] > 0) v.push_back(b[j][h] - a[i][h]); n       sort(v.begin(), v.end(), cmp); n       int tmp = 0; n       for (int h = 0; h < min(k, (int)v.size()); h++) tmp += v[h]; n       ans = max(ans, tmp); n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const inf = 1000 * 1000 * 1000; n long long const inf64 = 1ll * inf * inf; n struct Fenwick { n   int n; n   vector<long long> fen; n   Fenwick() { n = 0; } n   Fenwick(int nn) { n     n = nn; n     fen.resize(n + 1); n   } n   void put(int pos, int val) { n     for (int cur = pos; cur <= n; cur |= (cur + 1)) fen[cur] += val; n   } n   long long get(int pos) { n     long long res = 0; n     for (int cur = pos; cur > 0; cur = (cur & (cur + 1)) - 1) res += fen[cur]; n     return res; n   } n   long long get(int l, int r) { return get(r) - get(l - 1); } n }; n bool solve() { n   int n, m, k; n   scanf( %d %d %d , &n, &m, &k); n   vector<vector<pair<pair<int, int>, int> > > add(m + 1); n   for (int i = 1; i <= m; i++) add[i].reserve(n); n   for (int len, i, j, w, iter = 0; iter < k; iter++) { n     scanf( %d , &len); n     for (int iter2 = 0; iter2 < len; iter2++) { n       scanf( %d %d %d , &i, &j, &w); n       add[j].push_back({{i, w}, iter}); n     } n   } n   int q; n   scanf( %d , &q); n   vector<char> type(q); n   vector<int> sw(q); n   vector<pair<int, int> > ask(q); n   vector<vector<long long> > res(2005, vector<long long>(k)); n   vector<vector<int> > era(m + 1), ins(m + 1); n   vector<int> ide(q); n   char buffer[10]; n   for (int i, x1, y1, x2, y2, iter = 0; iter < q; iter++) { n     scanf( %s , buffer); n     if (string(buffer) ==  SWITCH ) { n       scanf( %d , &i); n       type[iter] = 0; n       sw[iter] = i - 1; n     } else { n       scanf( %d %d %d %d , &x1, &y1, &x2, &y2); n       type[iter] = 1; n       ask[iter] = {x1, x2}; n       ins[y1].push_back(iter); n       era[y2].push_back(iter); n       static int rectange_size = 0; n       ide[iter] = rectange_size++; n     } n   } n   vector<Fenwick> fen(k, Fenwick(n)); n   for (int pos, value, id, l, r, j = 1; j <= m; j++) { n     for (int iter : ins[j]) { n       tie(l, r) = ask[iter]; n       for (int kk = 0; kk < k; kk++) { n         res[ide[iter]][kk] -= fen[kk].get(l, r); n       } n     } n     for (auto _iter : add[j]) { n       tie(pos, value) = _iter.first; n       id = _iter.second; n       fen[id].put(pos, value); n     } n     for (int iter : era[j]) { n       tie(l, r) = ask[iter]; n       for (int kk = 0; kk < k; kk++) { n         res[ide[iter]][kk] += fen[kk].get(l, r); n       } n     } n   } n   vector<char> state(k, 1); n   for (int iter = 0; iter < q; iter++) { n     if (type[iter] == 0) { n       state[sw[iter]] ^= 1; n     } else { n       long long result = 0; n       for (int i = 0; i < k; i++) { n         if (state[i]) result += res[ide[iter]][i]; n       } n       printf( %I64d n , result); n     } n   } n   return true; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, int>, int> id; n vector<int> a[100005]; n int main() { n   int i, j, k, n; n   cin >> n; n   cout << n - 1 << endl; n   int idd = 1; n   for (k = (1); k <= (n - 1); k++) { n     cin >> i >> j; n     a[i].push_back(j); n     a[j].push_back(i); n     id[make_pair(i, j)] = idd; n     id[make_pair(j, i)] = idd++; n     printf( 2 %d %d n , i, j); n   } n   for (i = (1); i <= (n); i++) n     for (j = 1; j < a[i].size(); j++) { n       cout << id[make_pair(i, a[i][j - 1])] <<     << id[make_pair(i, a[i][j])] n            << endl; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n char a[30]; n int main() { n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     int len = s.size(), id = 0; n     for (int i = 0; i < len; i++) { n       int temp = 1; n       while (s[i + 1] == s[i]) { n         i++; n         temp++; n       } n       if (temp % 2 == 0) continue; n       int flag = 0; n       for (int j = 0; j < id; j++) { n         if (a[j] == s[i]) { n           flag = 1; n           break; n         } n       } n       if (!flag) a[id++] = s[i]; n     } n     if (!id) n       cout << endl; n     else { n       sort(a, a + id); n       for (int i = 0; i < id; i++) cout << a[i]; n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void swap(long long &a, long long &b) { n   long long t = a; n   a = b; n   b = t; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     set<long long> s; n     long long arr[n]; n     for (long long i = 0; i < n; i++) { n       cin >> arr[i]; n       s.insert(arr[i]); n     } n     if (n > 1 && s.size() > 1 && k == 1) { n       cout << -1 << endl; n       continue; n     } n     if (s.size() == 1) { n       cout << 1 << endl; n       continue; n     } n     long long count = 0; n     while (1) { n       if (s.size() == 1) { n         break; n       } n       set<long long> s1; n       long long j = 0; n       long long last = 0; n       for (auto x : s) { n         if (j < k) { n           s1.insert(0); n           j++; n           last = x; n         } else { n           s1.insert(x - last); n           j++; n         } n       } n       count++; n       s = s1; n     } n     cout << count << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 19; n int a[1 << N]; n int main() { n   int n, q; n   cin >> n >> q; n   long long sum = 0; n   for (int i = 0; i < (1 << n); i++) cin >> a[i], sum += a[i]; n   cout << setprecision(10) << 1.0 * sum / (1 << n) <<   n ; n   for (int i = 0; i < q; i++) { n     int id, v; n     cin >> id >> v; n     sum += v - a[id]; n     a[id] = v; n     cout << setprecision(10) << 1.0 * sum / (1 << n) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int p(string s) { n   string a = s; n   s +=  # ; n   reverse(a.begin(), a.end()); n   s += a; n   int n = s.size(); n   vector<int> pi(n); n   pi[0] = 0; n   int j = 0; n   for (int i = 1; i < n; i++) { n     j = pi[i - 1]; n     while (j > 0 && s[i] != s[j]) j = pi[j - 1]; n     if (s[i] == s[j]) j++; n     pi[i] = j; n   } n   return j; n } n int main() { n   int t = 1; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     int cnt = 0; n     int n = s.size(); n     for (int i = 0; i < n / 2; i++) { n       if (s[i] != s[n - 1 - i]) break; n       cnt++; n     } n     string ans; n     if (cnt > 0) cout << s.substr(0, cnt); n     ; n     string a = s; n     reverse(a.begin(), a.end()); n     int pos = p(s.substr(cnt, n - 2 * cnt)); n     string w = s.substr(cnt, pos); n     pos = p(a.substr(cnt, n - 2 * cnt)); n     w = (pos > w.length()) ? a.substr(cnt, pos) : w; n     cout << w; n     if (cnt > 0) cout << s.substr(n - cnt, cnt); n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   string s; n   deque<char> vec; n   cin >> s; n   for (int i = 0; i < s.size(); ++i) vec.push_back(s[i]); n   int cnt = 0, i; n   while (vec.size() > 1) { n     if (vec[vec.size() - 1] ==  0 ) { n       ++cnt; n       vec.pop_back(); n     } else { n       for (i = vec.size() - 1; i >= 0; --i) { n         if (vec[i] ==  0 ) break; n         vec[i] =  0 ; n       } n       if (i < 0) n         vec.push_front( 1 ); n       else n         vec[i] =  1 ; n       ++cnt; n     } n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005, M = 998244353; n int read(int x = 0, int f = 1, char c = getchar()) { n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n int n, a[N][N], f[N][N], p[N], fac[N], ans; n struct Tree { n   int t[N], v[N]; n   void Add(int x, int w) { n     if (w == -1 && !v[x]) return; n     v[x] ^= 1; n     for (; x <= n; x += x & -x) t[x] += w; n   } n   int Ask(int x, int w = 0) { n     for (; x; x -= x & -x) w += t[x]; n     return w; n   } n   void Init() { n     for (int i = 1; i <= n; ++i) t[i] = i & -i, v[i] = 1; n   } n } t1, t2; n int main() { n   n = read(); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) a[i][j] = read(); n   f[0][0] = 1; n   f[1][1] = 0; n   f[2][2] = 1; n   for (int i = 3; i <= n; ++i) n     f[i][i] = 1ll * (i - 1) * (f[i - 1][i - 1] + f[i - 2][i - 2]) % M; n   for (int i = 1; i <= n; ++i) n     for (int j = i - 1; j >= 0; --j) n       if ((f[i][j] = f[i][j + 1] + f[i - 1][j]) >= M) f[i][j] -= M; n   fac[0] = p[0] = 1; n   for (int i = 1; i <= n; ++i) { n     fac[i] = 1ll * fac[i - 1] * i % M; n     p[i] = 1ll * p[i - 1] * f[n][n] % M; n   } n   t1.Init(); n   for (int j = 1; j <= n; ++j) n     t1.Add(a[1][j], -1), ans = (ans + 1ll * t1.Ask(a[1][j]) * fac[n - j]) % M; n   ans = 1ll * ans * p[n - 1] % M; n   for (int i = 2; i <= n; ++i) { n     int sum = 0; n     t1.Init(); n     t2.Init(); n     for (int j = 1; j <= n; ++j) { n       int tot, cnt, tmp; n       t1.Add(a[i][j], -1); n       tot = t1.Ask(a[i][j]); n       if (a[i - 1][j] < a[i][j] && t1.v[a[i - 1][j]]) tot--; n       t2.Add(a[i - 1][j], -1); n       tmp = t2.Ask(n); n       cnt = t2.Ask(a[i][j] - 1); n       sum = (sum + 1ll * cnt * f[n - j][tmp - 1] + n              1ll * (tot - cnt) * f[n - j][tmp]) % n             M; n       t2.Add(a[i][j], -1); n     } n     ans = (ans + 1ll * sum * p[n - i]) % M; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n vector<long long> v; n vector<pair<pair<long long, long long>, long long> > vv; n vector<long long> ary; n void update(int pos, long long val, int mx) { n   while (pos <= mx) { n     ary[pos] += val; n     pos += pos & -pos; n   } n } n long long get(int pos, int mx) { n   long long re = 0; n   while (pos > 0) { n     re += ary[pos]; n     pos -= pos & -pos; n   } n   return re; n } n int main(void) { n   ios_base::sync_with_stdio(0); n   cin >> n >> m >> k; n   v.resize(n); n   for (int i = 0; i < (n); i++) cin >> v[i]; n   vv.resize(m); n   for (int i = 0; i < (m); i++) n     cin >> vv[i].first.first >> vv[i].first.second >> vv[i].second; n   ary.resize(m + 1, 0); n   for (int i = 0; i < (k); i++) { n     long long t, tt; n     cin >> t >> tt; n     update(t, 1, m); n     update(tt + 1, -1, m); n   } n   for (int i = 0; i < (m); i++) { n     vv[i].second *= get(i + 1, m); n   } n   ary.clear(); n   ary.resize(n + 2, 0); n   for (int i = 0; i < (m); i++) { n     update(vv[i].first.first, vv[i].second, n); n     update(vv[i].first.second + 1, -vv[i].second, n); n   } n   for (int i = 0; i < (n); i++) { n     v[i] += get(i + 1, n); n   } n   for (int i = 0; i < (n); i++) cout << v[i] <<    ; n   return 0; n } n