#include <bits/stdc++.h> n using namespace std; n int main() { n   long long k, sum = 0, i, j, n, cnt = 0; n   int a[20] = {0}, value; n   string s; n   cin >> k; n   cin >> s; n   for (i = 0; i < ((int)s.size()); ++i) { n     n = s[i] -  0 ; n     sum += n; n     a[n]++; n   } n   if (sum >= k) { n     cout << cnt << endl; n     return 0; n   } n   for (i = 0; i < 10; ++i) { n     value = 9 - i; n     for (j = 1; j <= a[i]; ++j) { n       sum += value; n       cnt++; n       if (sum >= k) { n         cout << cnt << endl; n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long x, y; n int main() { n   ios_base::sync_with_stdio(0); n   ; n   cin >> x >> y; n   if ((long long)sqrt(x * x + y * y + 0.5) == sqrt(x * x + y * y)) { n     cout <<  black  n          <<   n ; n     return 0; n   } n   long long d = sqrt(x * x + y * y); n   if ((x > 0 && y > 0) || (x < 0 && y < 0)) { n     if (d % 2 == 0) n       cout <<  black  n            <<   n ; n     else n       cout <<  white  n            <<   n ; n   } else { n     if (d % 2 == 0) n       cout <<  white  n            <<   n ; n     else n       cout <<  black  n            <<   n ; n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n typedef long long ll; n typedef pair<int,int> pii; n typedef vector<int> vi; n typedef vector<vi> vvi; n typedef vector<ll> vl; n typedef vector<vl> vvl; n typedef vector<string> vs; n typedef vector<vs> vvs; n typedef vector<pii> vpii; n typedef set<int> si; n typedef unordered_set<int> usi; n typedef multiset<int> msi; n typedef map<int,int> mi; n typedef unordered_map<int,int> umi; n typedef multimap<int,int> mmi; n  n #define f1(a,b,c) for(int(a)=(b);(a)<(c);(a)++) n #define f2(a,b,c) for(int(a)=(b);(a)<=(c);(a)++) n #define f3(a,b,c) for(int(a)=(b);(a)>(c);(a)--) n #define f4(a,b,c) for(int(a)=(b);(a)>=(c);(a)--) n #define fi(a,b) for(auto(a)=b.begin();(a)!=b.end();(a)++) n #define pb push_back n #define all(v) v.begin(),v.end() n #define nper next_permutation n #define pper prev_permutation n #define mp make_pair n #define F first n #define S second n  n int main() n { n  ios_base::sync_with_stdio(false); n  cin.tie(NULL); n  int t; n  cin>>t; n  f1(i,0,t) n  { n   int n,k,x=1; n   cin>>n>>k; n   f1(j,0,(2*k)-n-1) n   { n    cout<<x<<   ;x++; n   } n   x=k; n   f1(j,0,n-k+1) n   { n    cout<<x<<   ;x--; n   } n   cout<<  n ; n  } n  /*f1(i,0,t) n  { n   cout<<v[i]<<  n ; n  }*/ n  return 0; n } n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   return x * f; n } n inline void write(long long x) { n   if (x < 0) x = -x, putchar( - ); n   if (x >= 10) write(x / 10); n   putchar(x % 10 +  0 ); n } n inline void writeln(long long x) { n   write(x); n   putchar(  n ); n } n inline void wri(long long x) { n   write(x); n   putchar(   ); n } n const int maxn = 1e5 + 233; n const int mod = 1e9 + 7; n int f[maxn]; n int main() { n   int n = read(), m = read(); n   f[0] = 1; n   f[1] = 1; n   for (register int i = (2); i <= int(maxn - 1); ++i) n     f[i] = (f[i - 1] + f[i - 2]) % mod; n   writeln(2ll * (f[n] + f[m] - 1) % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 7; n int vis1[MAXN], vis2[MAXN], dis[MAXN]; n int st, ed, n, ans; n queue<int> q; n vector<int> G[MAXN]; n void Bfs1() { n   for (; !q.empty();) q.pop(); n   q.push(1); n   vis1[1] = 1; n   for (; !q.empty();) { n     int u = q.front(); n     q.pop(); n     for (auto v : G[u]) { n       if (vis1[v]) continue; n       q.push(v); n       vis1[v] = u; n     } n     st = u; n   } n } n void Bfs2() { n   for (; !q.empty();) q.pop(); n   q.push(st); n   vis2[st] = st; n   for (; !q.empty();) { n     int u = q.front(); n     q.pop(); n     for (auto v : G[u]) { n       if (vis2[v]) continue; n       q.push(v); n       vis2[v] = u; n     } n     ed = u; n   } n } n int degree(int x) { return (int)G[x].size(); } n bool check(int root) { n   int Tim = 0; n   for (int i = 1; i <= n; i++) vis1[i] = dis[i] = 0; n   for (; !q.empty();) q.pop(); n   q.push(root); n   vis1[root] = 1; n   for (; !q.empty();) { n     int u = q.front(); n     q.pop(); n     for (auto v : G[u]) { n       if (vis1[v]) continue; n       if (++Tim == n) { n       } n       q.push(v); n       vis1[v] = vis1[u] + 1; n       if (!dis[vis1[v]]) dis[vis1[v]] = v; n       if (degree(v) != degree(dis[vis1[v]])) return false; n     } n   } n   ans = root; n   return true; n } n bool checkCenter() { n   int Tim = 0; n   int D = 0; n   for (int u = ed; u != st; u = vis2[u]) D++; n   if (D & 1) return false; n   int center = ed; n   for (int i = 0; i != D / 2; i++, center = vis2[center]) n     ; n   if (check(center)) return true; n   for (int i = 1; i <= n; i++) vis1[i] = dis[i] = 0; n   for (; !q.empty();) q.pop(); n   q.push(center); n   vis1[center] = 1; n   for (; !q.empty();) { n     int u = q.front(); n     q.pop(); n     for (auto v : G[u]) { n       if (vis1[v]) continue; n       if (++Tim == n) { n       } n       q.push(v); n       vis1[v] = vis1[u] + 1; n       if (!dis[vis1[v]]) dis[vis1[v]] = v; n       if (degree(v) != degree(dis[vis1[v]])) { n         for (int x = v, tim = 0;;) { n           if (++tim == n) break; n           if (G[x].size() == 1) { n             if (check(x)) n               return true; n             else n               break; n           } else n             x = (vis1[G[x][0]] == 0) ? G[x][0] : G[x][1]; n         } n         for (int x = dis[vis1[v]], tim = 0;;) { n           if (++tim == n) break; n           if (G[x].size() == 1) { n             if (check(x)) n               return true; n             else n               break; n           } else n             x = (vis1[G[x][0]] == 0) ? G[x][0] : G[x][1]; n         } n         return false; n       } n     } n   } n   ans = center; n   return true; n } n int main() { n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   Bfs1(); n   Bfs2(); n   if (check(st) || check(ed)) n     cout << ans; n   else if (checkCenter()) n     cout << ans; n   else n     cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n long long K[5], T[5]; n int main() { n   queue<pair<long long, long long> > Q[5][2]; n   string ln; n   int n; n   getline(cin, ln); n   istringstream(ln) >> K[1] >> K[2] >> K[3]; n   getline(cin, ln); n   istringstream(ln) >> T[1] >> T[2] >> T[3]; n   getline(cin, ln); n   istringstream(ln) >> n; n   getline(cin, ln); n   istringstream in(ln); n   long long t0; n   for (int i = 0; i < n; i++) { n     in >> t0; n     Q[1][0].push(pair<long long, long long>(t0, t0)); n   } n   long long t = 0; n   for (int i = 1; i <= 3; i++) { n     while (Q[i][0].size()) { n       t = Q[i][0].front().first; n       t = max(t, Q[i][0].front().first); n       t0 = Q[i][0].front().second; n       Q[i][0].pop(); n       if (Q[i][1].size() < K[i]) { n         Q[i][1].push(pair<long long, long long>(t + T[i], t0)); n       } else { n         t = max(Q[i][1].front().first, t); n         Q[i + 1][0].push(Q[i][1].front()); n         Q[i][1].pop(); n         Q[i][1].push(pair<long long, long long>(t + T[i], t0)); n       } n     } n     while (Q[i][1].size()) { n       Q[i + 1][0].push(Q[i][1].front()); n       Q[i][1].pop(); n     } n   } n   long long res = 0; n   while (Q[4][0].size()) { n     res = max(res, Q[4][0].front().first - Q[4][0].front().second); n     Q[4][0].pop(); n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n inline int read() { n   char c = getchar(); n   int x = 0, f = 1; n   while ((c <  0  || c >  9 ) && c -  - ) c = getchar(); n   if (c ==  - ) f = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + c - 48; n     c = getchar(); n   } n   return x * f; n } n const int N = 3e5 + 10; n int n, rev[N]; n long long f[N], g[N], jc[N], inv[N], z[N]; n const long long mo = 998244353, Gi = 3; n inline long long qp(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a) % mo; n     a = (a * a) % mo; n     b >>= 1; n   } n   return ans; n } n int lim = 1, l = 0; n inline void ntt(long long a[], int pan) { n   for (int i = 0; i < lim; i++) n     if (i > rev[i]) swap(a[i], a[rev[i]]); n   for (int bj = 1; bj < lim; bj <<= 1) { n     long long wn = qp(Gi, (mo - 1) / (bj << 1)); n     if (pan) wn = qp(wn, mo - 2); n     for (int ks = 0; ks < lim; ks += (bj << 1)) { n       long long w = 1; n       for (int i = 0; i < bj; i++, w = (w * wn) % mo) { n         long long x = a[ks + i], y = w * a[ks + i + bj] % mo; n         a[ks + i] = (x + y) % mo; n         a[ks + i + bj] = ((x - y) % mo + mo) % mo; n       } n     } n   } n   if (pan) { n     long long ni = qp(lim, mo - 2); n     for (int i = 0; i < lim; i++) a[i] = (a[i] * ni) % mo; n   } n } n void gao(int t) { n   if (t == 1) { n     f[1] = 1; n     return; n   } n   int mi = t / 2; n   gao(mi); n   for (int i = 0; i <= mi; i++) z[i] = f[i], f[i] = f[i] * jc[i] % mo; n   long long c = mi, gu = 1; n   g[mi] = inv[0]; n   for (int i = mi - 1; i >= 0; i--) { n     gu = (gu * c) % mo; n     g[i] = gu * inv[mi - i] % mo; n   } n   lim = 1, l = 0; n   while (lim <= (mi << 1)) lim <<= 1, l++; n   for (int i = 0; i < lim; i++) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1); n   ntt(f, 0); n   ntt(g, 0); n   for (int i = 0; i < lim; i++) f[i] = (f[i] * g[i]) % mo, g[i] = 0; n   ntt(f, 1); n   long long ji = f[mi]; n   for (int i = mi; i >= 1; i--) { n     f[i] = f[i + mi]; n     f[i + mi] = 0; n   } n   f[0] = ji; n   for (int i = 0; i <= mi; i++) f[i] = (f[i] * inv[i]) % mo; n   lim = 1, l = 0; n   while (lim <= (mi << 1)) lim <<= 1, l++; n   for (int i = 0; i < lim; i++) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1); n   ntt(z, 0); n   ntt(f, 0); n   for (int i = 0; i < lim; i++) z[i] = (z[i] * f[i]) % mo; n   ntt(z, 1); n   for (int i = 0; i < lim; i++) f[i] = z[i], z[i] = 0; n   if (t % 2) { n     z[0] = (f[0] * (t - 1)) % mo; n     for (int i = 1; i <= (mi << 1) + 1; i++) n       z[i] = (f[i - 1] + (f[i] * (t - 1))) % mo; n     for (int i = 1; i <= (mi << 1) + 1; i++) f[i] = z[i], z[i] = 0; n   } n } n int A, B; n int main() { n   jc[0] = inv[0] = 1; n   for (int i = 1; i <= N - 10; i++) jc[i] = (jc[i - 1] * i) % mo; n   inv[N - 10] = qp(jc[N - 10], mo - 2); n   for (int i = N - 11; i >= 1; i--) inv[i] = (inv[i + 1] * (i + 1)) % mo; n   n = read(); n   A = read(); n   B = read(); n   if (n == 1) { n     if (A + B == 2) n       cout <<  1 n ; n     else n       cout <<  0 n ; n     return 0; n   } n   if (!A || !B || A + B > n + 1) { n     cout <<  0 n ; n     return 0; n   } n   gao(n - 1); n   cout << f[A + B - 2] * jc[A + B - 2] % mo * inv[A - 1] % mo * inv[B - 1] % mo n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double PI = acos(-1.); n const int MXN = 200005; n const int MOD = 1000000000; n int a[MXN], n, m; n long long fib[MXN]; n long long prefib[MXN]; n struct SEG { n   int l, r; n   long long lazy; n   long long g[2]; n   SEG() {} n   SEG(int _l, int _r) { l = _l, r = _r; } n } SGT[MXN << 2]; n void create(SEG &T, int t) { n   T.lazy = 0; n   T.g[0] = T.g[1] = a[t]; n } n void fresh(SEG &T, SEG &L, SEG &R) { n   int left = L.r - L.l + 1; n   T.lazy = 0; n   if (left == 1) { n     T.g[0] = (L.g[0] + R.g[1]) % MOD; n     T.g[1] = (L.g[0] + R.g[0] + R.g[1]) % MOD; n     return; n   } n   T.g[0] = n       (L.g[0] + fib[left - 2] * R.g[0] % MOD + fib[left - 1] * R.g[1] % MOD) % n       MOD; n   T.g[1] = n       (L.g[1] + fib[left - 1] * R.g[0] % MOD + fib[left] * R.g[1] % MOD) % MOD; n } n void build(int id, int l, int r) { n   SGT[id] = SEG(l, r); n   int mid = (l + r) / 2; n   if (l != r) { n     build(id * 2, l, mid); n     build(id * 2 + 1, mid + 1, r); n     fresh(SGT[id], SGT[id << 1], SGT[id << 1 | 1]); n   } else n     create(SGT[id], l); n } n void update(int id, int l, int r, long long w) { n   SEG &T = SGT[id]; n   int mid = (T.l + T.r) / 2; n   if (T.l == l && T.r == r) { n     T.lazy = (T.lazy + w) % MOD; n     T.g[0] = (T.g[0] + w * prefib[T.r - T.l] % MOD) % MOD; n     T.g[1] = (T.g[1] + w * (prefib[T.r - T.l + 1] - 1) % MOD) % MOD; n     return; n   } n   if (T.lazy) { n     update(id << 1, T.l, mid, T.lazy); n     update(id << 1 | 1, mid + 1, T.r, T.lazy); n     T.lazy = 0; n   } n   if (r <= mid) n     update(id << 1, l, r, w); n   else if (l > mid) n     update(id << 1 | 1, l, r, w); n   else { n     update(id << 1, l, mid, w); n     update(id << 1 | 1, mid + 1, r, w); n   } n   fresh(T, SGT[id << 1], SGT[id << 1 | 1]); n } n long long single(int id, int t) { n   SEG &T = SGT[id]; n   int mid = (T.l + T.r) / 2; n   if (T.l == T.r) return T.g[0]; n   if (t <= mid) n     return T.lazy + single(id << 1, t); n   else n     return T.lazy + single(id << 1 | 1, t); n } n void query(int id, SEG &A) { n   SEG &T = SGT[id]; n   int mid = (T.l + T.r) / 2; n   if (A.l == T.l && A.r == T.r) { n     A = T; n     return; n   } n   if (T.lazy && T.l != T.r) { n     update(id << 1, T.l, mid, T.lazy); n     update(id << 1 | 1, mid + 1, T.r, T.lazy); n     T.lazy = 0; n   } n   if (A.r <= mid) n     query(id << 1, A); n   else if (A.l > mid) n     query(id << 1 | 1, A); n   else { n     SEG L(A.l, mid), R(mid + 1, A.r); n     query(id << 1, L); n     query(id << 1 | 1, R); n     fresh(A, L, R); n   } n } n int main() { n   int i, j; n   fib[0] = 1; n   fib[1] = 1; n   for (i = 2; i < MXN; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD; n   prefib[0] = 1; n   for (i = 1; i < MXN; i++) prefib[i] = (prefib[i - 1] + fib[i]) % MOD; n   while (~scanf( %d%d , &n, &m)) { n     for (i = 1; i <= n; i++) scanf( %d , &a[i]); n     build(1, 1, n); n     while (m--) { n       int q; n       scanf( %d , &q); n       if (q == 1) { n         int x, v; n         scanf( %d%d , &x, &v); n         long long tp = single(1, x); n         update(1, x, x, v - tp); n       } n       if (q == 2) { n         int l, r; n         scanf( %d%d , &l, &r); n         SEG A(l, r); n         query(1, A); n         printf( %I64d n , ((A.g[0] % MOD) + MOD) % MOD); n       } n       if (q == 3) { n         int l, r, d; n         scanf( %d%d%d , &l, &r, &d); n         update(1, l, r, d); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2005; n const char vow[] = { a ,  e ,  i ,  o ,  u ,  y }; n char str[maxn]; n bool check(char ch) { n   for (int i = 0; i < 6; ++i) { n     if (ch == vow[i]) return true; n   } n   return false; n } n int main() { n   int n; n   while (~scanf( %d , &n)) { n     scanf( %s , str); n     for (int i = 0; i < n; ++i) { n       if (check(str[i])) { n         for (int j = i + 1; j < n; ++j) { n           if (str[i] == 0) continue; n           if (check(str[j])) n             str[j] = 0; n           else n             break; n         } n       } n     } n     for (int i = 0; i < n; ++i) { n       if (str[i]) putchar(str[i]); n     } n     puts(  ); 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 void fast() { std::ios_base::sync_with_stdio(0); } n vector<vector<int>> seq(1e5 + 9); n int main() { n   int n, x; n   cin >> n; n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     seq[x].push_back(i); n   } n   bool flag = true; n   vector<pair<int, int>> ans; n   for (int i = 0; i <= 1e5; i++) { n     flag = true; n     if (seq[i].size() == 0) n       continue; n     else if (seq[i].size() == 1) n       ans.push_back({i, 0}); n     else if (seq[i].size() == 2) n       ans.push_back({i, seq[i][1] - seq[i][0]}); n     else { n       for (int j = 2; j < seq[i].size() && flag; j++) { n         if (seq[i][j] - seq[i][j - 1] != seq[i][j - 1] - seq[i][j - 2]) n           flag = false; n       } n       if (flag) { n         ans.push_back({i, seq[i][1] - seq[i][0]}); n       } n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     printf( %d %d n , ans[i].first, ans[i].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     long int a[n + 1][m + 1]; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         cin >> a[i][j]; n       } n     } n     long int b[n + 1][m + 1]; n     for (int i = 1; i <= n; i++) { n       b[i][1] = 3; n       b[i][m] = 3; n     } n     for (int i = 1; i <= m; i++) { n       b[1][i] = 3; n       b[n][i] = 3; n     } n     b[1][1] = 2; n     b[1][m] = 2; n     b[n][1] = 2; n     b[n][m] = 2; n     for (int i = 2; i <= n - 1; i++) { n       for (int j = 2; j <= m - 1; j++) { n         b[i][j] = 4; n         b[i][j] = 4; n       } n     } n     int f = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         if (a[i][j] > b[i][j]) { n           f = 1; n           break; n         } n       } n     } n     if (f == 1) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n       for (int i = 1; i <= n; i++) { n         for (int j = 1; j <= m; j++) { n           cout << b[i][j] <<    ; n         } n         cout << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n typedef long long LL; n const double INF = 1e100; n const int oo = ~0u >> 2; n const double pi = acos(-1.0); n const double EPS = 1e-8; n const int MAXN = 100033; n double a, b, c; n double x11, x2; n int main() { n   scanf( %lf%lf%lf , &a, &b, &c); n   x11 = sqrt(b * b - 4.0 * a * c); n   if (a > 0) { n     x2 = (-b - x11) / 2.0 / a; n     x11 = (-b + x11) / 2.0 / a; n   } else { n     x2 = (-b + x11) / 2.0 / a; n     x11 = (-b - x11) / 2.0 / a; n   } n   printf( %.012lf n%.012lf n , x11, x2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   long long t; n   cin >> t; n   while (t--) { n     vector<long long> A(3); n     for (auto &a : A) cin >> a; n     sort((A).begin(), (A).end(), greater<long long>()); n     long long a, b, c; n     a = A[0]; n     b = A[1]; n     c = A[2]; n     long long ans = 0; n     if (a > 0) { n       a--; n       ans++; n     } n     if (b > 0) { n       b--; n       ans++; n     } n     if (c > 0) { n       c--; n       ans++; n     } n     if (a > 0 && b > 0) { n       a--; n       b--; n       ans++; n     } n     if (c > 0 && b > 0) { n       c--; n       b--; n       ans++; n     } n     if (a > 0 && c > 0) { n       a--; n       c--; n       ans++; n     } n     if (a > 0 && b > 0 && c > 0) { n       a--; n       b--; n       c--; n       ans++; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   { n     long long int r, n, c, m, i, j, count = 0, x, a, b, y, sum = 0; n     long long int mn = 1e18, mx = 0, ans = 0, k, ind; n     long long int br = 0, T, rz = 0; n     string s =   ; n     cin >> n; n     long long int a1, a2, a3, b1, b2, b3; n     cin >> a1 >> a2 >> a3; n     cin >> b1 >> b2 >> b3; n     mx = max(mx, a1 - b1 - b3); n     mx = max(mx, a2 - b1 - b2); n     mx = max(mx, a3 - b2 - b3); n     mn = 0; n     mn += min(a1, b2); n     mn += min(a2, b3); n     mn += min(a3, b1); n     cout << mx <<     << mn << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void open(const char *s) {} n inline int rd() { n   static int x, f; n   x = 0; n   f = 1; n   char ch = getchar(); n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ; n   return f > 0 ? x : -x; n } n const int N = 1000010; n int R, C, n, rt = 0, Lr; n vector<int> a[N]; n pair<int, int> b[N]; n namespace LCT { n struct tree { n   int ch[2], fa, rev; n   tree() { ch[0] = ch[1] = fa = rev = 0; } n } tr[N]; n int cnt = 0; n inline bool isrt(int x) { n   return tr[tr[x].fa].ch[0] != x && tr[tr[x].fa].ch[1] != x; n } n inline void pushdown(int x) { n   if (!tr[x].rev) return; n   swap(tr[x].ch[0], tr[x].ch[1]); n   if (tr[x].ch[0]) tr[tr[x].ch[0]].rev ^= 1; n   if (tr[x].ch[1]) tr[tr[x].ch[1]].rev ^= 1; n   tr[x].rev = 0; n } n inline void clr(int x) { n   static int st[N], tt; n   for (st[tt = 1] = x; !isrt(x); x = tr[x].fa) st[++tt] = tr[x].fa; n   while (tt) pushdown(st[tt--]); n } n inline void rotate(int x) { n   static int y, z, t1, t2; n   y = tr[x].fa; n   z = tr[y].fa; n   t1 = tr[y].ch[1] == x; n   t2 = t1 ^ 1; n   if (!isrt(y)) tr[z].ch[tr[z].ch[1] == y] = x; n   tr[x].fa = z; n   tr[y].fa = x; n   if (tr[x].ch[t2]) tr[tr[x].ch[t2]].fa = y; n   tr[y].ch[t1] = tr[x].ch[t2]; n   tr[x].ch[t2] = y; n } n inline void splay(int x) { n   for (clr(x); !isrt(x); rotate(x)) { n     int y = tr[x].fa, z = tr[y].fa; n     if (isrt(y)) continue; n     if ((tr[y].ch[0] == x) ^ (tr[z].ch[0] == y)) n       rotate(x); n     else n       rotate(y); n   } n } n inline void access(int x) { n   for (int s = 0; x; s = x, x = tr[x].fa) { n     splay(x); n     tr[x].ch[1] = s; n   } n } n inline void makert(int x) { n   access(x); n   splay(x); n   tr[x].rev ^= 1; n } n inline int findrt(int x) { n   access(x); n   splay(x); n   pushdown(x); n   while (tr[x].ch[0]) x = tr[x].ch[0], pushdown(x); n   return x; n } n inline void link(int x, int y) { n   makert(x); n   access(y); n   splay(y); n   tr[x].fa = y; n } n inline void cut(int x, int y) { n   makert(y); n   access(x); n   splay(x); n   tr[tr[x].ch[0]].fa = 0; n   tr[x].ch[0] = 0; n } n }  // namespace LCT n namespace Seg { n struct tree { n   int ls, rs, mx, cmx, tag; n   tree() { ls = rs = mx = cmx = tag = 0; } n } tr[N << 1]; n int cnt = 0; n inline void pushup(int o) { n   tr[o].mx = max(tr[tr[o].ls].mx, tr[tr[o].rs].mx); n   tr[o].cmx = 0; n   if (tr[o].mx == tr[tr[o].ls].mx) tr[o].cmx += tr[tr[o].ls].cmx; n   if (tr[o].mx == tr[tr[o].rs].mx) tr[o].cmx += tr[tr[o].rs].cmx; n } n inline void pushdown(int o) { n   if (!tr[o].tag) return; n   static int ls, rs; n   ls = tr[o].ls, rs = tr[o].rs; n   tr[ls].mx += tr[o].tag; n   tr[ls].tag += tr[o].tag; n   tr[rs].mx += tr[o].tag; n   tr[rs].tag += tr[o].tag; n   tr[o].tag = 0; n } n void build(int &o, int l, int r) { n   o = ++cnt; n   if (l == r) return tr[o].mx = l, tr[o].cmx = 1, void(); n   int mid = (l + r) >> 1; n   build(tr[o].ls, l, mid); n   build(tr[o].rs, mid + 1, r); n   pushup(o); n } n void modify(int o, int l, int r, int L, int R, int d) { n   if (l == L && r == R) return tr[o].mx += d, tr[o].tag += d, void(); n   pushdown(o); n   int mid = (l + r) >> 1; n   if (L <= mid) modify(tr[o].ls, l, mid, L, min(mid, R), d); n   if (R > mid) modify(tr[o].rs, mid + 1, r, max(mid + 1, L), R, d); n   pushup(o); n } n pair<int, int> query(int o, int l, int r, int L, int R) { n   if (l == L && r == R) return pair<int, int>(tr[o].mx, tr[o].cmx); n   pushdown(o); n   int mid = (l + r) >> 1; n   pair<int, int> res = pair<int, int>(0, 0), tmp; n   if (L <= mid) res = query(tr[o].ls, l, mid, L, min(mid, R)); n   if (R > mid) { n     tmp = query(tr[o].rs, mid + 1, r, max(mid + 1, L), R); n     if (res.first == tmp.first) n       res.second += tmp.second; n     else n       res = max(res, tmp); n   } n   return res; n } n }  // namespace Seg n inline bool check(int p) { n   static int d[5], tt, x, y; n   tt = 0; n   x = b[p].first, y = b[p].second; n   if (x > 1 && a[x - 1][y] >= Lr && a[x - 1][y] < p) n     d[++tt] = LCT::findrt(a[x - 1][y]); n   if (y > 1 && a[x][y - 1] >= Lr && a[x][y - 1] < p) n     d[++tt] = LCT::findrt(a[x][y - 1]); n   if (x < R && a[x + 1][y] >= Lr && a[x + 1][y] < p) n     d[++tt] = LCT::findrt(a[x + 1][y]); n   if (y < C && a[x][y + 1] >= Lr && a[x][y + 1] < p) n     d[++tt] = LCT::findrt(a[x][y + 1]); n   sort(d + 1, d + tt + 1); n   for (int i = 1; i <= tt - 1; i++) n     if (d[i] == d[i + 1]) return 0; n   return 1; n } n inline void del(int p) { n   static int x, y; n   x = b[p].first, y = b[p].second; n   if (x > 1 && a[x - 1][y] >= p) LCT::cut(a[x - 1][y], p); n   if (y > 1 && a[x][y - 1] >= p) LCT::cut(a[x][y - 1], p); n   if (x < R && a[x + 1][y] >= p) LCT::cut(a[x + 1][y], p); n   if (y < C && a[x][y + 1] >= p) LCT::cut(a[x][y + 1], p); n } n inline void gao(int p) { n   static int x, y; n   for (; !check(p); ++Lr) del(Lr); n   x = b[p].first, y = b[p].second; n   if (x > 1 && a[x - 1][y] >= Lr && a[x - 1][y] < p) { n     LCT::link(a[x - 1][y], p); n     Seg::modify(rt, 1, n, 1, a[x - 1][y], 1); n   } n   if (y > 1 && a[x][y - 1] >= Lr && a[x][y - 1] < p) { n     LCT::link(a[x][y - 1], p); n     Seg::modify(rt, 1, n, 1, a[x][y - 1], 1); n   } n   if (x < R && a[x + 1][y] >= Lr && a[x + 1][y] < p) { n     LCT::link(a[x + 1][y], p); n     Seg::modify(rt, 1, n, 1, a[x + 1][y], 1); n   } n   if (y < C && a[x][y + 1] >= Lr && a[x][y + 1] < p) { n     LCT::link(a[x][y + 1], p); n     Seg::modify(rt, 1, n, 1, a[x][y + 1], 1); n   } n } n int main() { n   open( hh ); n   R = rd(); n   C = rd(); n   for (int i = 1; i <= R; i++) { n     a[i].resize(C + 1); n     for (int j = 1; j <= C; j++) b[a[i][j] = rd()] = pair<int, int>(i, j); n   } n   n = R * C; n   Seg::build(rt, 1, n); n   Lr = 1; n   long long ans = 1; n   for (int i = 2; i <= n; i++) { n     gao(i); n     pair<int, int> res = Seg::query(rt, 1, n, Lr, i); n     ans += res.first == i ? res.second : 0; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ntest = 0, test = 0; n inline void init(); n inline void run(); n inline void stop() { ntest = test - 1; } n int main() { n   init(); n   while (++test <= ntest) { n     run(); n   } n   return 0; n } n const int INF = (int)1E9 + 5; n const double EPS = 1E-11; n const long long MOD = (long long)1E9 + 7; n const int dx[] = {-1, 0, 0, 1}; n const int dy[] = {0, -1, 1, 0}; n inline void init() { ntest = 1; } n long long mu(long long a, long long n) { n   long long rs = 1; n   for (; n; n >>= 1) { n     if (n & 1) rs = (rs * a) % MOD; n     a = (a * a) % MOD; n   } n   return rs; n } n vector<int> a; n inline void run() { n   int n, k; n   cin >> n >> k; n   a.resize(n); n   for (int i = 0; i < (n); i++) cin >> a[i]; n   if (k == 0) { n     for (int i = 0; i < (n); i++) cout << a[i] <<    ; n     return; n   } n   for (int i = 0; i < (n); i++) { n     long long total = a[i]; n     long long cur = 1; n     for (int j = (1); j <= (i); j++) { n       cur = (cur * (k + j - 1)) % MOD; n       cur = (cur * mu(j, MOD - 2)) % MOD; n       total = (total + (cur * a[i - j]) % MOD) % MOD; n     } n     cout << total <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const long long LL_INF = (long long)9.22e18; n string s; n int main() { n   cin >> s; n   bool isFirst = true; n   int cnt = 0; n   for (char ch : s) { n     if (ch ==  1  && isFirst) { n       isFirst = false; n       continue; n     } n     if (ch ==  0  && !isFirst) { n       cnt++; n     } n   } n   if (cnt >= 6 && !isFirst) { n     cout <<  yes  << endl; n   } else { n     cout <<  no  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int ans, pre, cnt; n int main() { n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     pre += s[i] -  0 ; n     cnt++; n     if (cnt == 3 || (s[i] -  0 ) % 3 == 0 || pre % 3 == 0) n       ans++, pre = 0, cnt = 0; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n using pii = pair<int, int>; n using UI = unsigned int; n const int mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n const double EPS = 1e-8; n const double PI = acos(-1.0); n const int N = 5e5 + 10; n const int M = N + (1 << 20); n int n, a[N][2]; n int deg[1 << 20]; n bool vis[N << 1]; n vector<pii> G[M]; n vector<int> ans; n void dfs(int x, int idx) { n   pii p; n   while (G[x].size()) { n     p = G[x].back(); n     G[x].pop_back(); n     if (!vis[p.second]) { n       vis[p.second] = 1; n       dfs(p.first, p.second); n     } n   } n   if (idx != -1) { n     ans.emplace_back(idx); n   } n } n void add_edge(int x, int y, int idx) { n   G[x].emplace_back(y, idx); n   G[y].emplace_back(x, idx); n } n bool ok(int k) { n   int mask = (1 << k) - 1; n   for (int i = (0); i < ((1 << k)); ++i) { n     deg[i] = 0; n   } n   for (int i = (0); i < ((1 << k) + n); ++i) { n     G[i].clear(); n   } n   int x, y, z; n   int offset = 1 << k; n   for (int i = (0); i < (n); ++i) { n     x = a[i][0] & mask; n     y = a[i][1] & mask; n     deg[x] += 1; n     deg[y] += 1; n     add_edge(x, i + offset, i << 1); n     add_edge(y, i + offset, i << 1 | 1); n   } n   for (int i = (0); i < (1 << k); ++i) { n     if (deg[i] & 1) return 0; n   } n   for (int i = (0); i < (n << 1); ++i) { n     vis[i] = 0; n   } n   ans.clear(); n   for (int i = (0); i < (n + (1 << k)); ++i) { n     if (G[i].size()) { n       dfs(i, -1); n       break; n     } n   } n   if (ans.size() < n * 2) { n     return 0; n   } n   printf( %d n , k); n   for (int i = (0); i < (ans.size()); ++i) { n     printf( %d  , ans[i] + 1); n   } n   puts(  ); n   return 1; n } n int main() { n   scanf( %d , &n); n   for (int i = (0); i < (n); ++i) { n     scanf( %d %d , &a[i][0], &a[i][1]); n   } n   for (int i = (20); i > (0); --i) { n     if (ok(i)) { n       return 0; n     } n   } n   puts( 0 ); n   for (int i = (1); i < (n + 1); ++i) { n     printf( %d %d  , i * 2 - 1, i * 2); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int tinf = (int)1e9 + 7; n const long long inf = (long long)1e18 + 7; n const int N = 1e5 + 5; n long long n, x[10000], y[10000], ans; n int main() { n   { n     ios ::sync_with_stdio(false); n     cin.tie(0); n   } n   cin >> n; n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; n   for (int i = 1; i < n - 1; i++) n     if (y[i] > y[i - 1] && x[i + 1] < x[i]) n       ans++; n     else if (y[i] < y[i - 1] && x[i + 1] > x[i]) n       ans++; n     else if (x[i] > x[i - 1] && y[i + 1] > y[i]) n       ans++; n     else if (x[i] < x[i - 1] && y[i + 1] < y[i]) n       ans++; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long second = 0; n   int r, m; n   cin >> m >> r; n   long long koef = 0, koef2 = 0; n   for (int i = 1; i <= m; ++i) { n     long long lef = i - 2, rig = m - i - 1; n     if (lef < 0) lef = 0; n     if (rig < 0) rig = 0; n     koef2 += i != 1; n     koef2 += i != m; n     koef += lef + rig; n     second += 2; n     if (i != 1) second += 2; n     if (i != m) second += 2; n     second += (lef + 1) * lef; n     second += (rig + 1) * rig; n   } n   long double ans = second + (2 * koef + koef2) * sqrt(2.0); n   printf( %.10f n , double(ans / (1LL * m * m) * r)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long spf[100001]; n long long fac[100001]; n void sieve() { n   spf[1] = 1; n   for (long long i = 2; i < 100001; i++) spf[i] = i; n   for (long long i = 4; i < 100001; i += 2) spf[i] = 2; n   for (long long i = 3; i * i < 100001; i++) { n     if (spf[i] == i) { n       for (long long j = i * i; j < 100001; j += i) n         if (spf[j] == j) spf[j] = i; n     } n   } n } n map<long long, long long> getfactor(long long a) { n   map<long long, long long> m; n   while (a > 1) { n     m[spf[a]]++; n     a /= spf[a]; n   } n   return m; n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long inverse(long long a, long long p) { return power(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[r], p) % p * inverse(fac[n - r], p) % p) % p; n } n void solve() { n   long long n; n   cin >> n; n   long long a[n]; n   long long hah[100001] = {0}, ans[100001] = {0}; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     hah[a[i]]++; n   } n   for (long long i = 100000; i >= 1; i--) { n     long long sum = 0; n     for (long long j = i; j <= 100000; j += i) { n       sum += hah[j]; n       ans[i] = (ans[i] - ans[j] + 1000000007) % 1000000007; n       if (ans[i] < 0) ans[i] = (ans[i] + 1000000007) % 1000000007; n     } n     ans[i] = (ans[i] % 1000000007 + power(2, sum, 1000000007) - 1 + 1000000007 + n               1000000007) % n              1000000007; n   } n   cout << ans[1] <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e6 + 100; n const long long INF = 9 * (long long)(1e18); n const long double PI = 3.14159265358979323846; n long long int modexp(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   if (y == 0) n     return 1; n   else if (x == 0) n     return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res % p; n } n vector<long long int> is_prime(N + 1, 1); n void sieve(long long int n) { n   for (long long int i = 1; i <= n; i++) is_prime[i] = i; n   for (long long int i = 2; i * i <= n; i++) { n     if (is_prime[i] == i) { n       for (long long int j = i * i; j <= n; j += i) n         is_prime[j] = min(i, is_prime[j]); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int foo; n   cin >> foo; n   while (foo--) { n     long long int n; n     cin >> n; n     long long int x = (n + 3) / 4; n     string s = string(x,  8 ); n     n -= x; n     string s2 = string(n,  9 ); n     cout << s2 + s <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 50 + 10, dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; n int main() { n   int n, m, x, y; n   while (~scanf( %d%d , &n, &m)) { n     getchar(); n     char a[N][N]; n     for (int i = 0; i < n; i++) { n       scanf( %s , a[i]); n       for (int j = 0; j < m; j++) { n         if (a[i][j] ==  S ) { n           x = i; n           y = j; n         } n       } n     } n     string str; n     cin >> str; n     int sum = 0, mmp[5], sz[5]; n     memset(sz, 0, sizeof(sz)); n     for (int i = 0; i < 4; i++) { n       mmp[0] = i; n       sz[i] = 1; n       for (int j = 0; j < 4; j++) { n         if (!sz[j]) { n           sz[j] = 1; n           mmp[1] = j; n           for (int k = 0; k < 4; k++) { n             if (!sz[k]) { n               mmp[2] = k; n               sz[k] = 1; n               for (int l = 0; l < 4; l++) { n                 if (!sz[l]) { n                   mmp[3] = l; n                   int nx = x, ny = y; n                   for (int zz = 0; zz < str.size(); zz++) { n                     nx += dx[mmp[str[zz] -  0 ]]; n                     ny += dy[mmp[str[zz] -  0 ]]; n                     if (a[nx][ny] ==  #  || n                         !(nx >= 0 && nx < n && ny >= 0 && ny < m)) n                       break; n                     if (a[nx][ny] ==  E ) { n                       sum++; n                       break; n                     } n                   } n                 } n               } n               sz[k] = 0; n             } n           } n           sz[j] = 0; n         } n       } n       sz[i] = 0; n     } n     printf( %d n , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct MyStruct { n   long long val; n   long long under; n   long long scorev; n   long long scoreu; n   MyStruct(long long v, long long u, long long sv, long long su) n       : val(v), under(u), scorev(sv), scoreu(su) {} n   bool operator<(const MyStruct& m) const { return val < m.val; } n }; n int main() { n   ios_base::sync_with_stdio(false); n   long long n; n   cin >> n; n   long long a1[n], a2[n], b1[n], b2[n]; n   for (long long i = 0; i < n; ++i) cin >> a1[i] >> b1[i] >> a2[i] >> b2[i]; n   long long ans = 0; n   priority_queue<MyStruct> pq; n   for (long long i = 0; i < n; ++i) { n     long long cnum = a1[i] + b1[i], dnum = a2[i] + b2[i]; n     if (cnum < dnum) { n       if (a1[i] > b2[i]) { n         ans += a1[i] - b2[i]; n       } else if (b1[i] > a2[i]) { n         ans -= b1[i] - a2[i]; n       } n       continue; n     } n     if (cnum == dnum) { n       ans += (a1[i] - b2[i]); n       continue; n     } n     pq.push(MyStruct(cnum, dnum, a1[i], a2[i])); n   } n   bool first = true; n   while (!pq.empty()) { n     MyStruct top = pq.top(); n     pq.pop(); n     if (first) n       ans += top.scorev; n     else n       ans += (top.scorev - top.val); n     if (top.under != -1) pq.push(MyStruct(top.under, -1, top.scoreu, -1)); n     first = !first; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 9e18; n const int mod = 4e4 + 7; n vector<int> prime; n bool p[100005]; n void init() { n   p[1] = true; n   for (int i = 2; i <= 100005; i++) { n     if (!p[i]) { n       prime.push_back(i); n       for (int j = i + i; j < 100005; j += i) p[j] = true; n     } n   } n } n bool isp(int n) { n   for (int i = 2; i <= sqrt(n); i++) n     if (n % i == 0) return false; n   return true; n } n int main() { n   init(); n   int n; n   cin >> n; n   int s[100005]; n   int mx = 0; n   for (int i = 0; i < n; i++) scanf( %d , &s[i]), mx = max(mx, s[i]); n   sort(s, s + n); n   int ans = 1; n   int num[100005]; n   for (int i = 2; i <= mx; i++) n     num[i] = upper_bound(s, s + n, i) - lower_bound(s, s + n, i); n   for (int i = 0; i < prime.size(); i++) { n     int sum = 0; n     int x = prime[i]; n     for (int j = x; j <= mx; j++) { n       if (j % x == 0) sum += num[j]; n     } n     ans = max(ans, sum); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> v(n); n   int sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n     sum += v[i]; n   } n   int req = sum / 2 - v[0] + 1; n   vector<pair<int, int> > v1; n   for (int i = 1; i < n; i++) { n     if (v[i] <= v[0] / 2) v1.push_back(make_pair(v[i], i)); n   } n   vector<int> v2; n   if (req > 0) n     for (int j = 0; j < v1.size(); j++) { n       req -= v1[j].first; n       v2.push_back(v1[j].second + 1); n       if (req <= 0) break; n     } n   if (req > 0) n     cout << 0 << endl; n   else { n     cout << v2.size() + 1 << endl; n     cout <<  1  ; n     for (int i = 0; i < v2.size(); i++) cout << v2[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long int t, n, i, j, k, sum = 0, res = 0, maxi = -1, mini = 1000000100; n   cin >> n; n   long long int a[n + 1]; n   for (i = 0; i < n; i++) cin >> a[i]; n   long long int idx = 0; n   for (i = 31; i >= 0; i--) { n     long long int cnt = 0; n     for (j = 0; j < n; j++) { n       if ((a[j] >> i) & 1) { n         cnt++; n         idx = j; n       } n       if (cnt == 2) break; n     } n     if (cnt == 1) break; n   } n   swap(a[idx], a[0]); n   for (i = 0; i < n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n const int MOD = 1E9 + 7; n const int N = 150000 + 5; n const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; n const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; n using namespace std; n struct Edge { n   int nex, to; n   int w; n   Edge() {} n   Edge(int nex, int to, int w) : nex(nex), to(to), w(w) {} n } edge[5151111]; n int head[N]; n int cnt; n void addEdge(int from, int to, int w) { n   edge[++cnt].nex = head[from]; n   edge[cnt].to = to; n   edge[cnt].w = w; n   head[from] = cnt++; n } n vector<int> G[N]; n vector<int> nex[N]; n int dis[N]; n bool vis[N]; n int Find(int y, int w) { n   int left = 0, right = G[y].size() - 1; n   while (left <= right) { n     int mid = (left + right) / 2; n     if (G[y][mid] > w) n       right = mid - 1; n     else if (G[y][mid] < w) n       left = mid + 1; n     else n       return nex[y][mid]; n   } n   return w; n } n int SPFA(int s, int n) { n   memset(dis, 0x3f3f3f3f, sizeof(dis)); n   memset(vis, false, sizeof(vis)); n   vis[s] = true; n   dis[s] = Find(1, 0); n   queue<int> Q; n   Q.push(s); n   while (!Q.empty()) { n     int x = Q.front(); n     Q.pop(); n     vis[x] = false; n     for (int i = head[x]; i != -1; i = edge[i].nex) { n       int y = edge[i].to; n       int w = edge[i].w; n       int times = dis[x] + w; n       if (y != n) times = Find(y, times); n       if (dis[y] > times) { n         dis[y] = times; n         if (!vis[y]) { n           vis[y] = true; n           Q.push(y); n         } n       } n     } n   } n   return dis[n]; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   memset(head, -1, sizeof(head)); n   for (int i = 1; i <= m; i++) { n     int x, y, w; n     scanf( %d%d%d , &x, &y, &w); n     addEdge(x, y, w); n     addEdge(y, x, w); n   } n   for (int i = 1; i <= n; i++) { n     int t; n     scanf( %d , &t); n     while (t--) { n       int x; n       scanf( %d , &x); n       G[i].push_back(x); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = G[i].size() - 1; j >= 0; j--) { n       int before; n       if (j == G[i].size() - 1 || G[i][j] != G[i][j + 1] - 1) n         before = G[i][j] + 1; n       nex[i].push_back(before); n     } n     reverse(nex[i].begin(), nex[i].end()); n   } n   int res = SPFA(1, n); n   if (res == 0x3f3f3f3f) res = -1; n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 105; n const int INF = 0x3f3f3f3f; n const double pi = acos(-1.0); n const double eps = 1e-9; n int a[maxn]; n int n; n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   sort(a, a + n); n   int now = 10; n   int ans = 0; n   int anscnt = 0; n   bool flag = true; n   for (int i = 0; i < n; ++i) { n     if (flag) { n       now += a[i]; n       if (now == 360) { n         anscnt += i + 1; n         flag = false; n       } else if (now > 360) { n         anscnt += i; n         if (now <= 720) { n           flag = false; n           anscnt++; n           ans += now - 360; n         } else n           break; n       } n     } else { n       now += a[i]; n       if (now <= 720) { n         anscnt++; n         ans += now - 360; n       } else n         break; n     } n   } n   if (now <= 360) { n     anscnt = n; n     ans = 0; n   } n   cout << anscnt <<     << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x, r, r1, s, s1, pos, pos1, nx = 0; n   int digits[19], index = 0; n   cin >> x; n   pos = 1; n   do { n     pos1 = pos; n     pos *= 10; n     r = x % pos; n     s = (x - r) / pos; n     r1 = r % pos1; n     s1 = (r - r1) / pos1; n     digits[index] = s1; n     index++; n   } while (s != 0); n   for (int i = index - 1; i >= 0; i--) { n     if (!(i == index - 1) || !(digits[i] == 9)) { n       if (digits[i] > 4) digits[i] = 9 - digits[i]; n       nx = nx + digits[i] * pos1; n     } else { n       nx = nx + digits[i] * pos1; n     } n     pos1 /= 10; n   } n   cout << nx << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int val[105]; n   memset(val, 0, sizeof val); n   char arr[105]; n   scanf( %s , arr); n   int n = strlen(arr); n   for (int i = 0; i < n; i++) { n     if (arr[i] ==  A ) { n       if (i > 0) { n         val[i - 1] |= 1; n       } n       val[i] |= 1; n       if (i < n - 1) { n         val[i + 1] |= 1; n       } n     } else if (arr[i] ==  B ) { n       if (i > 0) { n         val[i - 1] |= (1 << 1); n       } n       val[i] |= (1 << 1); n       if (i < n - 1) { n         val[i + 1] |= (1 << 1); n       } n     } else if (arr[i] ==  C ) { n       if (i > 0) { n         val[i - 1] |= (1 << 2); n       } n       val[i] |= (1 << 2); n       if (i < n - 1) { n         val[i + 1] |= (1 << 2); n       } n     } n   } n   bool flag = false; n   for (int i = 0; i < n; i++) { n     if (val[i] == 7) { n       flag = true; n       break; n     } n   } n   if (flag) { n     printf( Yes n ); n   } else { n     printf( No n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long lcm(long long a, long long b) { n   long long g = gcd(a, b); n   long long ans = (a * b) / g; n   return ans; n } n vector<long long> primes; n bool prime[10005]; n void seive() { n   memset(prime, 1, sizeof(prime)); n   prime[0] = 0; n   prime[1] = 0; n   for (long long i = 2; i <= 10000; i++) { n     if (prime[i] == 1) { n       for (long long j = i * i; j <= 10000; j += i) prime[j] = 0; n     } n   } n } n long long power(long long a, long long b) { n   long long ans = 1; n   while (b > 0) { n     if (b % 2 == 1) ans = (ans % 1000000007 * a % 1000000007) % 1000000007; n     a = (a * a) % 1000000007; n     b = b / 2; n   } n   return ans; n } n template <typename T> n std::string NumberToString(T Number) { n   std::ostringstream ss; n   ss << Number; n   return ss.str(); n } n long long gcdExtended(long long a, long long b, long long *x, long long *y); n long long modInverse(long long b, long long m) { n   long long x, y; n   long long g = gcdExtended(b, m, &x, &y); n   if (g != 1) return -1; n   return (x % m + m) % m; n } n long long modDivide(long long a, long long b, long long m) { n   a = a % m; n   long long inv = modInverse(b, m); n   return (inv * a) % m; n } n long long gcdExtended(long long a, long long b, long long *x, long long *y) { n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } n long long n; n vector<long long> v[100005]; n vector<long long> ans; n void dfs(long long u, long long p) { n   if (v[u].size() == 1 and p != 0) { n     ans.push_back(u); n     return; n   } n   for (auto x : v[u]) { n     if (x != p) { n       dfs(x, u); n     } n   } n } n void solve() { n   cin >> n; n   long long i, j; n   for (i = 0; i < n - 1; i++) { n     long long x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   long long ct = 0, root = 1; n   for (long long i = 1; i <= n; i++) { n     if (v[i].size() > 2) { n       root = i; n       ct++; n     } n   } n   if (ct > 1) { n     cout <<  No ; n     return; n   } n   cout <<  Yes  <<   n ; n   dfs(root, 0); n   cout << ans.size() <<   n ; n   for (i = 0; i < ans.size(); i++) { n     cout << root <<     << ans[i] <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   bool codechef = 0; n   long long t = 1; n   if (codechef) { n     cin >> t; n   } n   while (t--) { n     solve(); n   } n   return 0; 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 template <typename T> n inline bool smin(T &a, const T &b) { n   return a > b ? a = b : a; n } n template <typename T> n inline bool smax(T &a, const T &b) { n   return a < b ? a = b : a; n } n const int N = (int)1 << 15, mod = (int)998244353; n int a[N], b[N], dp[N]; n int pw(int a, int b) { n   return b != 0 ? (long long)pw((long long)a * a % mod, b >> 1) * n                       (b & 1 ? a : 1) % mod n                 : 1; n } n void NTT(int a[], int lg, bool inverse) { n   int N = 1 << lg; n   for (int i = 0; i < N; ++i) { n     int rev = 0; n     for (int j = 0; j < lg; ++j) n       if (i >> j & 1) rev |= 1 << (lg - j - 1); n     if (rev > i) swap(a[rev], a[i]); n   } n   for (int len = 2; len <= N; len <<= 1) { n     int wn = pw(3, (mod - 1) / len); n     if (inverse) wn = pw(wn, mod - 2); n     for (int j = 0; j < N; j += len) { n       int w = 1; n       for (int first = j, second = j + len / 2; second < j + len; n            ++first, ++second) { n         int u = a[first], v = (long long)a[second] * w % mod; n         a[first] = u + v; n         a[second] = u - v + mod; n         while (a[first] >= mod) a[first] -= mod; n         while (a[second] >= mod) a[second] -= mod; n         w = (long long)w * wn % mod; n       } n     } n   } n   if (inverse) { n     int div = pw(N, mod - 2); n     for (int i = 0; i < N; ++i) a[i] = (long long)a[i] * div % mod; n   } n } n int res[17][N], tmpa[17][N], tmpb[17][N]; n void solve(int b, int e, int a[N], int d = 0) { n   if (b + 1 == e) { n     res[d][0] = 1; n     res[d][1] = a[b]; n     return; n   } n   int m = b + e >> 1; n   solve(b, m, a, d + 1); n   for (int j = 0; j <= (m - b); ++j) n     tmpa[d][j] = res[d + 1][j], res[d + 1][j] = 0; n   solve(m, e, a, d + 1); n   for (int j = 0; j <= (e - m); ++j) n     tmpb[d][j] = res[d + 1][j], res[d + 1][j] = 0; n   int lg = 0; n   while ((1 << lg) <= e - b) ++lg; n   NTT(tmpa[d], lg, false); n   NTT(tmpb[d], lg, false); n   for (int j = 0; j < (1 << lg); ++j) n     res[d][j] = (long long)tmpa[d][j] * tmpb[d][j] % mod, n     tmpa[d][j] = tmpb[d][j] = 0; n   NTT(res[d], lg, true); n } n int32_t main() { n   int n, k; n   cin >> n >> k; n   for (int j = 0; j < n; ++j) cin >> a[j]; n   int qm; n   cin >> qm; n   while (qm--) { n     int c; n     cin >> c; n     if (c == 1) { n       int q, p, d; n       cin >> q >> p >> d; n       --p; n       for (int j = 0; j < n; ++j) b[j] = q - a[j]; n       b[p] = q - d; n     } else { n       int q, l, r, d; n       cin >> q >> l >> r >> d; n       --l; n       for (int j = 0; j < n; ++j) b[j] = q - a[j]; n       for (int j = l; j < r; ++j) b[j] -= d; n     } n     for (int j = 0; j < n; ++j) b[j] = (b[j] % mod + mod) % mod; n     memset(res, 0, sizeof res); n     solve(0, n, b); n     cout << res[0][k] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 25; n int main() { n   int n, m, l, r, t, c; n   cin >> n >> m; n   pair<int, int> s[n + 1]; n   for (int i = (1), _b = (n + 1); i < (_b); ++i) s[i] = make_pair(0, 0); n   for (int i = (0), _b = (m); i < (_b); ++i) { n     cin >> l >> r >> t >> c; n     for (int j = (l), _b = (r + 1); j < (_b); ++j) { n       if (!s[j].second) n         s[j] = make_pair(t, c); n       else { n         if (t < s[j].first) { n           s[j] = make_pair(t, c); n         } n       } n     } n   } n   int ret = 0; n   for (int i = (1), _b = (n + 1); i < (_b); ++i) { n     ret += s[i].second; n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, A, B, scc[75], tot[75], fa[75], ans[75], f[75][1 << 16]; n int c, To[405], nxt[405], cst[405], Head[75]; n bool vis[75][1 << 16]; n inline int Read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch < 48 || ch > 57) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch > 47 && ch < 58) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n inline void Write(int x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) Write(x / 10); n   putchar(48 + x % 10); n } n void ad_ed(int u, int v, int ct) { n   nxt[++c] = Head[u]; n   To[c] = v; n   cst[c] = ct; n   Head[u] = c; n } n int Find(int x) { n   if (fa[x] != x) fa[x] = Find(fa[x]); n   return fa[x]; n } n void Merge(int x, int y) { n   int rx = Find(x), ry = Find(y); n   if (rx != ry) fa[ry] = rx, tot[rx] += tot[ry]; n } n struct info { n   int id, dis, st; n   friend bool operator<(info a, info b) { return a.dis > b.dis; } n }; n priority_queue<info> q; n int main() { n   n = Read(); n   m = Read(); n   A = Read(); n   B = Read(); n   if (A > B) swap(A, B); n   for (int i = 1; i <= n; i++) fa[i] = i, tot[i] = 1, ans[i] = 0x3f3f3f3f; n   memset(f, 0x3f, sizeof(f)); n   for (int i = 1; i <= m; i++) { n     int u = Read(), v = Read(), ct = Read(); n     ad_ed(u, v, ct); n     ad_ed(v, u, ct); n     if (ct == A) Merge(u, v); n   } n   int idx = 0; n   for (int i = 1; i <= n; i++) n     if (!scc[i] && tot[Find(i)] > 3) { n       idx++; n       for (int j = 1; j <= n; j++) n         if (Find(j) == Find(i)) scc[j] = idx; n     } n   int beg_st = (!scc[1] ? 0 : 1 << scc[1]); n   f[1][beg_st] = 0; n   q.push(info{1, 0, beg_st}); n   while (!q.empty()) { n     info x = q.top(); n     q.pop(); n     if (vis[x.id][x.st]) continue; n     vis[x.id][x.st] = 1; n     ans[x.id] = min(ans[x.id], x.dis); n     for (int i = Head[x.id]; i; i = nxt[i]) { n       int v = To[i], ct = cst[i]; n       if (ct == A) { n         if (f[x.id][x.st] + ct < f[v][x.st]) { n           f[v][x.st] = f[x.id][x.st] + ct; n           q.push(info{v, f[v][x.st], x.st}); n         } n       } else if (ct == B) { n         if (Find(x.id) == Find(v)) continue; n         if (scc[v] && ((x.st >> scc[v]) & 1)) continue; n         int net = x.st | (1 << scc[v]); n         if (f[x.id][x.st] + ct < f[v][net]) { n           f[v][net] = f[x.id][x.st] + ct; n           q.push(info{v, f[v][net], net}); n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) Write(ans[i]), putchar(   ); n   return 0; n } n


#include <bits/stdc++.h> n const long long INF = (1 << 30) - 1; n const int MAXN = 100001; n struct Node { n   int l, r; n   long long num; n   long long num2; n   long long delta; n }; n int n, m; n long long t[MAXN]; n int l[MAXN], r[MAXN]; n long long q[MAXN]; n Node tree[MAXN << 2]; n void build(int cur, int l, int r) { n   tree[cur].l = l; n   tree[cur].r = r; n   tree[cur].delta = tree[cur].num = tree[cur].num2 = 0; n   if (l + 1 != r) { n     tree[cur].delta = 0; n     build((cur << 1) + 1, l, (l + r) >> 1); n     build((cur << 1) + 2, (l + r) >> 1, r); n   } n } n void update(int cur) { n   tree[(cur << 1) + 1].delta |= tree[cur].delta; n   tree[(cur << 1) + 2].delta |= tree[cur].delta; n   tree[(cur << 1) + 1].num |= tree[cur].delta; n   tree[(cur << 1) + 2].num |= tree[cur].delta; n   tree[(cur << 1) + 1].num2 |= tree[cur].delta; n   tree[(cur << 1) + 2].num2 |= tree[cur].delta; n   tree[cur].delta = 0; n } n void change(int cur, int l, int r, int delta) { n   if (l <= tree[cur].l && tree[cur].r <= r) { n     tree[cur].delta |= delta; n     tree[cur].num |= delta; n     tree[cur].num2 |= delta; n   } else { n     if (tree[cur].delta != 0) update(cur); n     int mid = (tree[cur].l + tree[cur].r) >> 1; n     if (l < mid) change((cur << 1) + 1, l, r, delta); n     if (r > mid) change((cur << 1) + 2, l, r, delta); n     tree[cur].num = tree[(cur << 1) + 1].num | tree[(cur << 1) + 2].num; n     tree[cur].num = tree[(cur << 1) + 1].num & tree[(cur << 1) + 2].num; n   } n } n long long query(int cur, int l, int r) { n   if (l <= tree[cur].l && tree[cur].r <= r) { n     return tree[cur].num2; n   } else { n     if (tree[cur].delta != 0) update(cur); n     int mid = (tree[cur].l + tree[cur].r) >> 1; n     long long ans = INF; n     if (l < mid) ans &= query((cur << 1) + 1, l, r); n     if (r > mid) ans &= query((cur << 1) + 2, l, r); n     return ans; n   } n } n int main() { n   scanf( %d%d , &n, &m); n   memset(t, 0LL, sizeof(t)); n   build(0, 1, n + 1); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%I64d , &l[i], &r[i], &q[i]); n     change(0, l[i], r[i] + 1, q[i]); n   } n   bool ok = true; n   for (int i = 1; i <= m; i++) { n     long long te = query(0, l[i], r[i] + 1); n     if (te != q[i]) { n       ok = false; n       break; n     } n   } n   if (ok) { n     printf( YES n ); n     for (int i = 1; i <= n; i++) { n       printf( %I64d  , query(0, i, i + 1)); n     } n     printf(  n ); n   } else { n     printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n struct Node { n   Node(int v = 1, int pos = 1e9) { min = (v == 1 ? int(1e9) : pos); } n   Node(Node l, Node r) { min = std::min(l.min, r.min); } n   int min; n }; n template <class i_t, class e_t> n class SegmentTree { n  public: n   void init(std::vector<e_t> base) { n     n = base.size(); n     tree.resize(2 * n); n     for (int i = 0; i < n; i++) { n       tree[i + n] = i_t(base[i], i); n     } n     for (int i = n - 1; i > 0; i--) { n       tree[i] = i_t(tree[i + i], tree[i + i + 1]); n     } n   } n   i_t qry(int l, int r) { n     i_t lp, rp; n     for (l += n, r += n; l < r; l /= 2, r /= 2) { n       if (l & 1) lp = i_t(lp, tree[l++]); n       if (r & 1) rp = i_t(tree[--r], rp); n     } n     return i_t(lp, rp); n   } n   void upd(int x, e_t v) { n     x += n; n     tree[x] = i_t(v, x - n); n     build(x); n   } n  n  private: n   int n; n   std::vector<i_t> tree; n   void build(int x) { n     for (x /= 2; x > 0; x /= 2) { n       tree[x] = i_t(tree[x + x + 1], tree[x + x]); n     } n   } n }; n struct Bucket { n   int n; n   SegmentTree<Node, int> tree; n   void init(int n) { n     this->n = n; n     tree.init(std::vector<int>(n, 0)); n   } n   void erase(int pos) { tree.upd(pos, 0); } n   int insert(int pos) { n     int x = tree.qry(pos, n).min; n     int ans = 0; n     if (x >= n) { n       x = tree.qry(0, pos).min; n       ans += n - pos + x; n     } else { n       ans += x - pos; n     } n     tree.upd(x, 1); n     return ans; n   } n }; n int main() { n   int h, m, n; n   std::cin >> h >> m >> n; n   int size = 1; n   for (int i = 2; i <= h; i++) { n     if (h % i == 0 && m % i == 0) { n       size = i; n     } n   } n   std::vector<Bucket> buckets(size); n   std::vector<int> hashBucket(h, 0); n   std::vector<int> posBucket(h, 0); n   std::map<int, std::pair<int, int> > idBucket; n   for (int i = 0; i < size; i++) { n     for (int j = 0, pos = i; j < h / size; j++, pos = (pos + m) % h) { n       posBucket[pos] = j; n       hashBucket[pos] = i; n     } n     buckets[i].init(h / size); n   } n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     char t; n     int id; n     scanf(  %c %d , &t, &id); n     if (t ==  + ) { n       int hash; n       scanf( %d , &hash); n       int got = buckets[hashBucket[hash]].insert(posBucket[hash]); n       idBucket[id] = std::pair<int, int>(hashBucket[hash], n                                          (posBucket[hash] + got) % (h / size)); n       ans += got; n     } else { n       auto it = idBucket.find(id); n       buckets[it->second.first].erase(it->second.second); n       idBucket.erase(it); n     } n   } n   std::cout << ans << std::endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n vector<long long> fact(10005); n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long power(long long x, long long y) { n   long long temp; n   if (y == 0) return 1; n   temp = power(x, y / 2); n   if (y % 2 == 0) n     return temp * temp; n   else n     return x * temp * temp; n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long modInv(long long n, long long p) { return power(n, p - 2, p); } n long long ncr(long long n, long long r) { n   return (n >= r ? (fact[n] * modInv(fact[r], mod)) % mod * n                        modInv(fact[n - r], mod) % mod n                  : 0); n } n long long add(long long a, long long b) { n   long long z = a + b; n   if (z >= mod) z -= mod; n   return z; n } n long long mul(long long a, long long b) { return (a * b) % mod; } n long long sub(long long a, long long b) { return (a - b + mod) % mod; } n int main() { n   long long t = 1, n, i, j, m, cnt, f, ff; n   cin >> t; n   while (t--) { n     cin >> n >> mod; n     long long z = log2(n) - 1; n     long long ans = (n - (1 << (z + 1)) + 2) % mod; n     for (i = 0; i <= z; i++) { n       ans = mul(ans, (1 << i) + 1); n     } n     if (ans == 0) n       cout << mod - 1 <<   n ; n     else n       cout << ans - 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n vector<int> gr[(ll)(1e5 + 4)]; n set<int> g[(ll)(1e5 + 4)]; n bool vis[(ll)(1e5 + 4)]; n int par[(ll)(1e5 + 4)], si[(ll)(1e5 + 4)]; n int find(int no) { n   if (par[no] != no) { n     par[no] = find(par[no]); n   } n   return par[no]; n } n void join(int a, int b) { n   if (find(a) == find(b)) { n     return; n   } n   int pa = par[a], pb = par[b]; n   if (si[pa] < si[pb]) { n     swap(pa, pb); n   } n   si[pa] += si[pb]; n   si[pb] = 0; n   par[pb] = pa; n } n void dfs(int node) { n   cout << node <<    ; n   vis[node] = 1; n   for (int x : gr[node]) { n     if (!vis[x]) { n       dfs(x); n     } n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int ar[n][3]; n     for (int i = 0; i < n - 2; i++) { n       for (int j = 0; j < 3; j++) { n         cin >> ar[i][j]; n         int a = ar[i][j]; n         g[a].insert(i); n       } n     } n     set<pair<int, int>> sp; n     for (int i = 1; i <= n; i++) { n       par[i] = i, si[i] = 1; n       sp.insert(make_pair(g[i].size(), i)); n     } n     vector<int> qp; n     while (sp.size()) { n       auto p = *sp.begin(); n       sp.erase(sp.begin()); n       int ind = *g[p.second].begin(); n       qp.push_back(ind + 1); n       for (int j = 0; j < 3; j++) { n         int u = p.second; n         int v = ar[ind][j]; n         if (find(u) != find(v)) { n           gr[u].push_back(v); n           gr[v].push_back(u); n         } n         join(u, v); n         g[v].erase(ind); n         if (g[v].size()) { n           sp.insert(make_pair(g[v].size(), v)); n         } n       } n       while (sp.size() && sp.begin()->first > g[sp.begin()->second].size()) { n         sp.erase(sp.begin()); n       } n     } n     for (int i = 1; i <= n; i++) { n       if (gr[i].size() == 1 && vis[i] == 0) { n         dfs(i); n         cout <<   n ; n       } n     } n     for (int i = 0; i < qp.size(); i++) { n       cout << qp[i] <<    ; n     } n     cout <<   n ; n     for (int i = 0; i <= n; i++) { n       vis[i] = 0, gr[i].clear(), g[i].clear(); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, fwt[262144]; n vector<int> a1, b1, c1, d1, e1, ans; n void add(int x, int k) { n   for (; x < 262144; x += x & -x) { n     fwt[x] += k; n   } n } n int sum(int x) { n   int res = 0; n   for (; x; x -= x & -x) { n     res += fwt[x]; n   } n   return res; n } n int findSidx(int sum) { n   int x = 0; n   for (int j = 262144 / 2; j; j /= 2) { n     if (sum >= fwt[x + j]) { n       sum -= fwt[x + j]; n       x += j; n     } n   } n   return x; n } n vector<int> deB(vector<int>& a) { n   memset(fwt, 0, sizeof fwt); n   vector<int> res; n   for (int i = 0; i < n; ++i) { n     add(i + 1, 1); n   } n   for (int i = 0; i < n; ++i) { n     add(a[i] + 1, -1); n     res.push_back(sum(a[i] + 1)); n   } n   return res; n } n void makeA() { n   memset(fwt, 0, sizeof fwt); n   ans.resize(n, 0); n   for (int i = 0; i < n; ++i) { n     add(i + 1, 1); n   } n   for (int i = 0; i < n; ++i) { n     ans[i] = findSidx(e1[i]); n     add(ans[i] + 1, -1); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   a1.resize(n); n   b1.resize(n); n   e1.resize(n, 0); n   for (int i = 0; i < n; ++i) { n     cin >> a1[i]; n   } n   for (int j = 0; j < n; ++j) { n     cin >> b1[j]; n   } n   c1 = deB(a1), d1 = deB(b1); n   for (int i = n - 1; i >= 0; --i) { n     e1[i] += c1[i] + d1[i]; n     if (i) { n       e1[i - 1] += e1[i] / (n - i); n     } n     e1[i] %= (n - i); n   } n   makeA(); n   for (int i = 0; i < n; ++i) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, temp, i, x = 0, arr[100] = {0}; n   map<long long, long long> inx; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> temp; n     inx[temp] = i; n   } n   for (map<long long int, long long int>::iterator it = inx.begin(); n        it != inx.end(); ++it) { n     arr[it->second] = it->first; n   } n   cout << inx.size() << endl; n   for (i = 0; i < n; i++) { n     if (arr[i] != 0) cout << arr[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, ans; n string str; n long long solve() { n   cin >> n; n   long long v[1001]; n   for (long long i = 0; i <= n - 1; ++i) { n     long long t; n     cin >> t; n     v[i + 1] = t; n   } n   for (long long i = 1; i <= n; ++i) { n     long long a[n + 1]; n     for (long long i = 0; i <= n; ++i) a[i] = 0; n     a[i]++; n     long long t = i; n     while (1) { n       t = v[t]; n       a[t]++; n       if (a[t] == 2) { n         cout << t <<    ; n         break; n       } n     } n   } n   return 0; n } n signed main() { n   ios::sync_with_stdio(0); n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, i; n   scanf( %d %d , &n, &t); n   if (n == 1 && t == 10) { n     printf( -1 n ); n   } else { n     if (t == 10) { n       t = 1; n     } n     printf( %d , t); n     for (i = 0; i < n - 1; i++) { n       printf( 0 ); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n1, n2; n int k1, k2; n int main() { n   cin >> n1 >> n2 >> k1 >> k2; n   if (n1 > n2) n     cout <<  First  << endl; n   else n     cout <<  Second  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[500001], t[500001]; n long long nt[10000001], n, k, m; n long long c[2]; n void kmp(long long x, char a[]) { n   int i, j; n   for (nt[0] = j = -1, i = 1; i < x; nt[i++] = j) { n     while (~j && a[j + 1] != a[i]) j = nt[j]; n     if (a[j + 1] == a[i]) j++; n   } n } n int main() { n   scanf( %s , s); n   scanf( %s , t); n   n = strlen(t); n   kmp(n, t); n   k = nt[n - 1]; n   m = strlen(s); n   for (int i = 0; i < m; i++) c[s[i] -  0 ]++; n   for (int i = 0, j = 0; i < m; i++) { n     if (c[0] == 0) n       printf( 1 ); n     else if (c[1] == 0) n       printf( 0 ); n     else { n       printf( %c , t[j]); n       c[t[j] -  0 ]--; n       if (j == n - 1) j = nt[j]; n       j++; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, x, m, s; n vector<int> f, t, f1; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> x >> m; n     f.push_back(x); n     t.push_back(m); n   } n   for (int i = 0; i < n; i++) { n     if (t[i] < k) { n       f1.push_back(f[i]); n     } else { n       s = f[i] - (t[i] - k); n       f1.push_back(s); n     } n   } n   sort(f1.begin(), f1.end()); n   cout << f1.back(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, k, a[205], b[205]; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int j = 1; j <= k; j++) cin >> b[j]; n   if (k >= 2) { n     cout <<  Yes  << endl; n     return 0; n   } n   if (a[1] == 0) a[1] = b[1]; n   for (int i = 2; i <= n; i++) { n     if (a[i] == 0) a[i] = b[1]; n     if (a[i] <= a[i - 1]) { n       cout <<  Yes  << endl; n       return 0; n     } n   } n   cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void dbg(T a) {} n template <typename T, typename... Arg> n void dbg(T a, Arg... arg) {} n const int maxn = (1e6) + 7; n const int inf = (1e9) + 7; n const long long LLinf = (1e18) + 7; n const long double eps = 1e-9; n const long long mod = 1e9 + 7; n int ile(vector<int> V) { n   int res = 0; n   while (((int)(V).size()) && V.back() == 0) { n     V.pop_back(); n     res++; n   } n   if (((int)(V).size()) == 0) return 10000; n   return res; n } n int rob(vector<int> V, int a, int b) { n   int cnt = 0; n   for (int i = 0; i < ((int)(V).size()); i++) n     if (V[i] == a) { n       for (int j = i - 1; j >= 0; j--) { n         swap(V[j], V[j + 1]); n         cnt++; n       } n       break; n     } n   for (int i = 1; i < ((int)(V).size()); i++) n     if (V[i] == b) { n       for (int j = i - 1; j > 0; j--) { n         swap(V[j], V[j + 1]); n         cnt++; n       } n       break; n     } n   if (V[0] == a && V[1] == b) n     return cnt + ile(V); n   else n     return 1000; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<int> V; n   while (n > 0) { n     V.push_back(n % 10); n     n /= 10LL; n   } n   int res = 1000; n   res = min(res, rob(V, 0, 0)); n   res = min(res, rob(V, 5, 2)); n   res = min(res, rob(V, 0, 5)); n   res = min(res, rob(V, 5, 7)); n   if (res < 100) n     cout << res; n   else n     cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e6 + 5, inf = 1e9 + 7; n long long n, k, cumm[N], m[26]; n set<pair<long long, long long> > st; n string s; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long i, j, a, b, ans = 1; n   cin >> n >> k >> s; n   s =  #  + s; n   for (i = 0; i < k; i++) st.insert(pair<long long, long long>(m[i], i)); n   for (i = 1; i < n + s.size(); i++) { n     if (i < s.size()) n       a = s[i] -  a ; n     else n       a = st.begin()->second; n     st.erase(st.find(pair<long long, long long>(m[a], a))); n     if (m[a]) n       cumm[i] = cumm[i - 1] - cumm[m[a] - 1]; n     else n       cumm[i] = cumm[i - 1] + 1; n     m[a] = i; n     st.insert(pair<long long, long long>(m[a], a)); n     cumm[i] = (cumm[i] % inf + cumm[i - 1] + inf) % inf; n   } n   cout << (cumm[i - 1] + 1) % inf; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3007; n const int M = 998244353; n int n, m, dp[N][N]; n string s, t; n bool matches(int i, char c) { n   if (i > m) n     return true; n   else n     return t[i - 1] == c; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> s >> t; n   n = s.size(); n   m = t.size(); n   for (int i = 1; i <= n + 1; i++) dp[i][i - 1] = 1; n   for (int d = 1; d <= n; d++) { n     char c = s[d - 1]; n     for (int i = 1, j = d; j <= n; i++, j++) { n       if (matches(i, c)) { n         dp[i][j] = (dp[i][j] + dp[i + 1][j]) % M; n       } n       if (matches(j, c)) { n         dp[i][j] = (dp[i][j] + dp[i][j - 1]) % M; n       } n     } n   } n   int ans = 0; n   for (int i = m; i <= n; i++) { n     ans = (ans + dp[1][i]) % M; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n char ans[100]; n int n; n int main() { n   scanf( %s%d , ans, &n); n   for (int i = 0; i < strlen(ans); i++) { n     if (ans[i] <  a ) ans[i] +=  a  -  A ; n     if (ans[i] < 97 + n) ans[i] +=  A  -  a ; n   } n   printf( %s n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     int a[3]; n     cin >> a[0] >> a[1] >> a[2]; n     sort(a, a + 3); n     if (a[0] + a[1] >= a[2] - 1) { n       cout <<  Yes n ; n     } else n       cout <<  No n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void sf(T &res) { n   int f = 1; n   char c; n   res = 0; n   while (c = getchar(), !isdigit(c)) n     ; n   if (c ==  - ) f = -1, c = getchar(); n   do res = (res << 1) + (res << 3) + (c ^ 48); n   while (c = getchar(), isdigit(c)); n   res *= f; n } n long long h, q, L, R, pos, ANS; n struct node { n   long long l, r; n   bool operator<(const node &a) const { n     if (l != a.l) return l < a.l; n     return r < a.r; n   } n }; n vector<node> v; n int main() { n   sf(h), sf(q); n   L = 1ll << (h - 1); n   R = (1ll << h) - 1; n   while (q--) { n     long long l, r; n     int f, ans; n     sf(f), sf(l), sf(r), sf(ans); n     for (int j = f; j < h; j++) l *= 2, r = r * 2 + 1; n     if (ans) { n       if (L <= l - 1) v.push_back((node){L, l - 1}); n       if (r + 1 <= R) v.push_back((node){r + 1, R}); n     } else n       v.push_back((node){l, r}); n   } n   pos = L, ANS = -1; n   v.push_back((node){R + 1, R + 1}); n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size(); i++) { n     long long x = v[i].l, y = v[i].r; n     if (x > pos) { n       if (x - pos == 1) { n         if (ANS == -1) n           ANS = pos; n         else { n           puts( Data not sufficient! ); n           return 0; n         } n       } else { n         puts( Data not sufficient! ); n         return 0; n       } n     } n     pos = max(pos, y + 1); n   } n   if (ANS == -1) n     puts( Game cheated! ); n   else n     cout << ANS << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<char, char> > V; n char R[18][18], S[18][18]; n int main(void) { n   int n, m; n   cin >> n >> m; n   bool test1 = (n >= 6 && m >= 3) || (n >= 3 && m >= 6); n   if (test1 == false) { n     cout <<  No solution.  << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       string w; n       cin >> w; n       R[i][j] = w[0]; n       S[i][j] = w[1]; n       V.insert(pair<char, char>(R[i][j], S[i][j])); n     } n   } n   set<pair<char, char> > Q; n   char TR[13] = { 2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 , n                   9 ,  T ,  J ,  Q ,  K ,  A }; n   char TS[4] = { C ,  D ,  H ,  S }; n   for (int i = 0; i < 4; i++) { n     for (int j = 0; j < 13; j++) { n       if (V.find(pair<char, char>(TR[j], TS[i])) == V.end()) { n         Q.insert(pair<char, char>(TR[j], TS[i])); n       } n     } n   } n   int jk1r, jk1c, jk2r, jk2c; n   jk1r = jk1c = jk2r = jk2c = -1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (R[i][j] ==  J  && S[i][j] ==  1 ) { n         jk1r = i; n         jk1c = j; n       } else if (R[i][j] ==  J  && S[i][j] ==  2 ) { n         jk2r = i; n         jk2c = j; n       } n     } n   for (int r1 = 0; r1 + 2 < n; r1++) n     for (int c1 = 0; c1 + 2 < m; c1++) { n       for (int r2 = 0; r2 + 2 < n; r2++) n         for (int c2 = 0; c2 + 2 < m; c2++) { n           bool test2 = (r2 <= r1 + 2) && (r1 <= r2 + 2) && (c2 <= c1 + 2) && n                        (c1 <= c2 + 2); n           if (test2) continue; n           for (int jr1 = 0; jr1 < 13; jr1++) n             for (int js1 = 0; js1 < 4; js1++) { n               for (int jr2 = 0; jr2 < 13; jr2++) n                 for (int js2 = 0; js2 < 4; js2++) { n                   char cr1 = TR[jr1], cr2 = TR[jr2], cs1 = TS[js1], n                        cs2 = TS[js2]; n                   if (jr1 == jr2 && js1 == js2) continue; n                   if (Q.find(pair<char, char>(cr1, cs1)) == Q.end() || n                       Q.find(pair<char, char>(cr2, cs2)) == Q.end()) n                     continue; n                   if (jk1r != -1) { n                     R[jk1r][jk1c] = cr1; n                     S[jk1r][jk1c] = cs1; n                   } n                   if (jk2r != -1) { n                     R[jk2r][jk2c] = cr2; n                     S[jk2r][jk2c] = cs2; n                   } n                   bool ok1 = true; n                   for (int i = 0; i < 3; i++) n                     for (int j = 0; j < 3; j++) { n                       if (S[r1][c1] != S[r1 + i][c1 + j]) { n                         ok1 = false; n                         break; n                       } n                     } n                   bool ok2 = true; n                   bool used2[256]; n                   memset(used2, false, sizeof(used2)); n                   for (int i = 0; i < 3; i++) n                     for (int j = 0; j < 3; j++) { n                       if (used2[(int)R[r1 + i][c1 + j]]) { n                         ok2 = false; n                         break; n                       } n                       used2[(int)R[r1 + i][c1 + j]] = true; n                     } n                   bool ok3 = true; n                   for (int i = 0; i < 3; i++) n                     for (int j = 0; j < 3; j++) { n                       if (S[r2][c2] != S[r2 + i][c2 + j]) { n                         ok3 = false; n                         break; n                       } n                     } n                   bool ok4 = true; n                   bool used4[256]; n                   memset(used4, false, sizeof(used4)); n                   for (int i = 0; i < 3; i++) n                     for (int j = 0; j < 3; j++) { n                       if (used4[(int)R[r2 + i][c2 + j]]) { n                         ok4 = false; n                         break; n                       } n                       used4[(int)R[r2 + i][c2 + j]] = true; n                     } n                   if ((ok1 || ok2) && (ok3 || ok4)) { n                     cout <<  Solution exists.  << endl; n                     if (jk1r == -1 && jk2r == -1) { n                       cout <<  There are no jokers.  << endl; n                     } else if (jk1r != -1 && jk2r != -1) { n                       cout <<  Replace J1 with   << R[jk1r][jk1c] n                            << S[jk1r][jk1c] <<   and  ; n                       cout <<  J2 with   << R[jk2r][jk2c] << S[jk2r][jk2c] n                            <<  .  << endl; n                     } else if (jk1r != -1) { n                       cout <<  Replace J1 with   << R[jk1r][jk1c] n                            << S[jk1r][jk1c] <<  .  << endl; n                     } else if (jk2r != -1) { n                       cout <<  Replace J2 with   << R[jk2r][jk2c] n                            << S[jk2r][jk2c] <<  .  << endl; n                     } n                     cout <<  Put the first square to (  << r1 + 1 <<  ,   n                          << c1 + 1 <<  ).  << endl; n                     cout <<  Put the second square to (  << r2 + 1 <<  ,   n                          << c2 + 1 <<  ).  << endl; n                     return 0; n                   } n                 } n             } n         } n     } n   cout <<  No solution.  << endl; n   return 0; n } n


#include <bits/stdc++.h> n char buf[1 << 21], *p1 = buf, *p2 = buf; n using namespace std; n template <class T> n void rd(T &k) { n   char c = n       (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) n            ? EOF n            : *p1++); n   int f = 1; n   k = 0; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f *= -1; n     c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) n              ? EOF n              : *p1++); n   } n   while (c >=  0  && c <=  9 ) { n     k = k * 10 + c -  0 ; n     c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) n              ? EOF n              : *p1++); n   } n   k *= f; n } n const int N = 300005; n int n, m, k, t, x, a[N], f[N]; n int c[N], d[N]; n long long ans; n char p[N]; n queue<int> q; n int ok(int x) { n   if (a[x] > 0 && c[x - 1] + 1 <= 9 && c[x] + 1 <= 9) return 1; n   if (a[x] < 0 && c[x - 1] - 1 >= 0 && c[x] - 1 >= 0) return 1; n   return 0; n } n int main() { n   cin >> n; n   cin >> p + 1; n   for (int i = 1; i <= n; ++i) c[i] = p[i] - 48; n   cin >> p + 1; n   for (int i = 1; i <= n; ++i) d[i] = p[i] - 48; n   for (register int i = 1; i < n; ++i) { n     a[i + 1] = d[i] - (c[i] + a[i]); n     ans += abs(a[i + 1]); n   } n   if (c[n] + a[n] != d[n]) return cout << -1, 0; n   cout << ans <<   n ; n   int xx = min(ans, 100000ll); n   for (register int i = 2; i <= n; ++i) { n     if (a[i] > 0 && c[i - 1] + 1 <= 9 && c[i] + 1 <= 9) q.push(i), f[i] = 1; n     if (a[i] < 0 && c[i - 1] - 1 >= 0 && c[i] - 1 >= 0) q.push(i), f[i] = 1; n   } n   int x; n   while (xx--) { n     x = q.front(); n     q.pop(); n     while (f[x] == 0) { n       x = q.front(); n       q.pop(); n     } n     if (a[x] > 0) { n       cout << x - 1 <<   1 n ; n       ++c[x - 1]; n       ++c[x]; n       --a[x]; n     } else { n       cout << x - 1 <<   -1 n ; n       --c[x - 1]; n       --c[x]; n       ++a[x]; n     } n     if (ok(x)) n       q.push(x); n     else n       f[x] = 0; n     if (x >= 3) { n       if (ok(x - 1)) { n         if (f[x - 1] == 0) q.push(x - 1); n         f[x - 1] = 1; n       } else n         f[x - 1] = 0; n     } n     if (x <= n - 1) { n       if (ok(x + 1)) { n         if (f[x + 1] == 0) q.push(x + 1); n         f[x + 1] = 1; n       } else n         f[x + 1] = 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n string a, b; n int main() { n   cin >> a >> b; n   if (a == b) { n     cout << a << endl; n     return 0; n   } else { n     cout << 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool gmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool gmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n const long long N = 110; n const long long K = 100010; n const long long INF = 1e12; n long long a[N], b[N], dp[N][2 * K]; n long long n, k; n long long Rec(long long idx, long long sum) { n   if (idx == n) { n     return sum ? -INF : 0; n   } n   long long& ans = dp[idx][sum + K]; n   if (ans + 1) return ans; n   ans = -INF; n   gmax(ans, Rec(idx + 1, sum)); n   gmax(ans, a[idx] + Rec(idx + 1, sum + a[idx] - b[idx])); n   return ans; n } n void solve() { n   cin >> n >> k; n   for (long long i = 0; i < (n); i++) cin >> a[i]; n   for (long long i = 0; i < (n); i++) cin >> b[i]; n   for (long long i = 0; i < (n); i++) b[i] *= k; n   memset(dp, (long long)(-1), sizeof(dp)); n   long long Ans = Rec(0, 0); n   cout << (Ans <= 0 ? -1 : Ans) <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool check(string a) { n   bool flag = true; n   for (int i = 1; i <= a.size(); i++) n     if (abs(a[i] - a[i - 1]) == 1) flag = false; n   return flag; n } n int main() { n   int T; n   cin >> T; n   while (T--) { n     string s, one, two; n     cin >> s; n     for (int i = 0; i < s.size(); i++) n       if (s[i] % 2) n         one += s[i]; n       else n         two += s[i]; n     sort(one.begin(), one.end()); n     sort(two.begin(), two.end()); n     if (check(one + two)) n       cout << one + two <<   n ; n     else if (check(two + one)) n       cout << two + one <<   n ; n     else n       cout <<  No answer n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, t, k, x; n string s; n int main() { n   cin >> s; n   n = s.size(); n   for (int k = 0;; k++) { n     if (s[k] ==  . ) { n       t = k; n       break; n     } n   } n   if (s[t - 1] == 9 +  0 ) n     cout <<  GOTO Vasilisa. ; n   else if (s[t + 1] < 5 +  0 ) { n     for (int i = 0; i < t; i++) cout << s[i]; n   } else if (s[t + 1] >= 5 +  0 ) { n     for (int i = 0; i < t - 1; i++) cout << s[i]; n     cout << s[t - 1] -  0  + 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1}, n                        {-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; n const long long int LLINF = 9e18; n const int INF = 2e9; n const int MOD = 1e9 + 7; n const double EPS = 1e-10; n const double PI = acos(-1); n const int SIZE = 200005; n int N; n long long int A[SIZE]; n int cnt[SIZE], pos[SIZE]; n vector<pair<int, pair<int, int> > > ans; n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) { n     scanf( %lld , &A[i]); n     cnt[A[i]]++; n     pos[A[i]] = i; n   } n   int num, Mx = 0, idx; n   for (int i = 0; i < SIZE; i++) { n     if (Mx < cnt[i]) { n       num = i; n       Mx = cnt[i]; n       idx = pos[i]; n     } n   } n   for (int i = idx; i <= N; i++) { n     if (num < A[i]) { n       ans.push_back(make_pair(2, make_pair(i, i - 1))); n     } else if (num > A[i]) { n       ans.push_back(make_pair(1, make_pair(i, i - 1))); n     } n   } n   for (int i = idx; i >= 1; i--) { n     if (num < A[i]) { n       ans.push_back(make_pair(2, make_pair(i, i + 1))); n     } else if (num > A[i]) { n       ans.push_back(make_pair(1, make_pair(i, i + 1))); n     } n   } n   int n = ans.size(); n   printf( %d n , n); n   for (int i = 0; i < n; i++) { n     printf( %d %d %d n , ans[i].first, ans[i].second.first, n            ans[i].second.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b, da, db; n vector<long long> v[100005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     cin >> n >> a >> b >> da >> db; n     for (long long i = 0; i < n + 2; i++) v[i].clear(); n     for (long long i = 0; i < n - 1; i++) { n       long long x, y; n       cin >> x >> y; n       v[x].push_back(y); n       v[y].push_back(x); n     } n     long long vis[n + 1]; n     memset(vis, 0, sizeof(vis)); n     vis[a] = 1; n     queue<long long> q; n     q.push(a); n     long long dis[n + 1]; n     dis[a] = 0; n     while (!q.empty()) { n       long long u = q.front(); n       q.pop(); n       for (auto it : v[u]) { n         if (!vis[it]) { n           dis[it] = dis[u] + 1; n           vis[it] = 1; n           q.push(it); n         } n       } n     } n     if (db <= 2 * da || dis[b] <= da) { n       cout <<  Alice n ; n       continue; n     } n     dis[b] = 0; n     memset(vis, 0, sizeof(vis)); n     vis[b] = 1; n     q.push(b); n     while (!q.empty()) { n       long long u = q.front(); n       q.pop(); n       for (auto it : v[u]) { n         if (!vis[it]) { n           dis[it] = dis[u] + 1; n           vis[it] = 1; n           q.push(it); n         } n       } n     } n     long long node, maxi = 0; n     for (long long i = 1; i <= n; i++) { n       if (dis[i] > maxi) { n         maxi = dis[i]; n         node = i; n       } n     } n     dis[node] = 0; n     memset(vis, 0, sizeof(vis)); n     vis[node] = 1; n     q.push(node); n     while (!q.empty()) { n       long long u = q.front(); n       q.pop(); n       for (auto it : v[u]) { n         if (!vis[it]) { n           dis[it] = dis[u] + 1; n           vis[it] = 1; n           q.push(it); n         } n       } n     } n     maxi = 0; n     for (long long i = 1; i <= n; i++) { n       if (dis[i] > maxi) { n         maxi = dis[i]; n       } n     } n     if (maxi > 2 * da) { n       cout <<  Bob n ; n     } else n       cout <<  Alice n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   long long r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n int const nmax = 1010; n int k, n; n vector<pair<int, int> > st, pe; n vector<int> ans[nmax]; n bool dc[nmax]; n long double p[nmax]; n void solve() { n   memset(dc, 0, sizeof(dc)); n   cin >> k >> n; n   for (int i = 0; i < k; i++) { n     int c, t; n     cin >> c >> t; n     p[i] = c; n     if (t == 1) n       st.push_back(pair<int, int>(c, i)); n     else n       pe.push_back(pair<int, int>(c, i)); n   } n   sort(st.begin(), st.end()); n   sort(pe.begin(), pe.end()); n   int k = 0; n   while (!st.empty()) { n     if (k >= n) k = n - 1; n     dc[k] = 1; n     ans[k].push_back(st.back().second); n     st.pop_back(); n     k++; n   } n   for (int i = n - 1; i >= 0; i--) { n     if (int((ans[i]).size()) > 0) break; n     ans[i].push_back(pe.front().second); n     pe.erase(pe.begin()); n   } n   while (!pe.empty()) { n     if (k >= n) k = n - 1; n     ans[k].push_back(pe.back().second); n     pe.pop_back(); n     k++; n   } n   long double sum = 0; n   for (int i = 0; i < n; i++) { n     long double m = INT_MAX; n     for (int j = 0; j < int((ans[i]).size()); j++) { n       int k = ans[i][j]; n       sum += p[k]; n       m = ((m) > (p[k]) ? (p[k]) : (m)); n     } n     if (dc[i]) sum -= m / 2; n   } n   cout << fixed << setprecision(1) << sum <<   n ; n   for (int i = 0; i < n; i++) { n     cout << int((ans[i]).size()) <<    ; n     for (int j = 0; j < int((ans[i]).size()); j++) cout << ans[i][j] + 1 <<    ; n     cout <<   n ; n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 9; n int n, q, c[N]; n void modify(int x, int v) { n   if (x == 0) return; n   for (int i = x; i <= n; i += i & -i) c[i] += v; n } n int query(int x) { n   int s = 0; n   for (int i = x; i >= 1; i -= i & -i) s += c[i]; n   return s; n } n void work(int a, int b, bool le) { n   for (int i = a; i <= b; ++i) { n     int t = query(i) - query(i - 1); n     modify(i, -t); n     if (le) { n       modify(a - (i - a + 1), t); n     } else n       modify(b + (b - i + 1), t); n   } n } n int L, R; n int get(int x) { n   if (L <= R) n     return x + L - 1; n   else n     return L + 1 - x; n } n int len() { return abs(L - R) + 1; } n int main() { n   scanf( %d%d , &n, &q); n   L = 1, R = n; n   for (int i = 1; i <= n; ++i) modify(i, 1); n   while (q--) { n     int cmd, p, l, r; n     scanf( %d , &cmd); n     if (cmd == 1) { n       scanf( %d , &p); n       if (L <= R) { n         if (p > len() - p) { n           work(get(p + 1), R, 1); n           R = get(p); n           swap(L, R); n         } else { n           work(get(1), get(p), 0); n           L = get(p + 1); n         } n       } else { n         if (p > len() - p) { n           work(R, get(p + 1), 0); n           R = get(p); n           swap(L, R); n         } else { n           work(get(p), get(1), 1); n           L = get(p + 1); n         } n       } n     } else { n       scanf( %d%d , &l, &r); n       l++; n       l = get(l), r = get(r); n       if (l > r) swap(l, r); n       int s = query(r) - query(l - 1); n       printf( %d n , s); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   string aux =  CODEFORCES ; n   int i = 0; n   cin >> s; n   if (s.length() < aux.length()) n     cout <<  NO  << endl; n   else { n     while (aux[i] == s[i] && i < aux.length()) i++; n     if (i == aux.length()) n       cout <<  YES  << endl; n     else { n       int j; n       for (j = i; j < aux.length(); j++) { n         if (aux[j] != s[s.length() - aux.length() + j]) break; n       } n       if (j == aux.length()) n         cout <<  YES  << endl; n       else n         cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     if (n < k) n       cout << k - n << endl; n     else { n       if ((n & 1) == (k & 1)) n         cout << 0 << endl; n       else n         cout << 1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, m; n int a[maxn], b[maxn]; n int main() { n   cin >> n >> m; n   m--; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   if (a[0] == 0) { n     cout <<  NO ; n     return 0; n   } n   if (b[m] == 0 && a[m] == 0) { n     cout <<  NO ; n     return 0; n   } n   if (a[m] != 0) { n     cout <<  YES ; n     return 0; n   } n   for (int i = m; i < n; i++) { n     if (b[i] == 1 && a[i] == 1) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char a[110], b[110]; n   scanf( %s%s , a, b); n   if (strcmp(a, b) == 0) n     printf( %s n , a); n   else n     printf( 1 n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 5; n const int dir[8][2] = {{0, 1},  {1, 1},   {1, 0},  {1, -1}, n                        {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}}; n const int dir8x[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; n const int dir8y[8] = {-1, 0, 1, 1, -1, -1, 0, 1}; n const long long mod = 1e9 + 7; n const double PI = acos(-1.0); n long long po(long long a, long long b, long long mod) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long gcd(long long a, long long b) { n   if (a == 0) { n     return b; n   } else { n     return gcd(b % a, a); n   } n } n int n; n long long val[maxn], dp[maxn]; n void solve() { n   scanf( %d , &(n)); n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &val[i]); n   } n   int last = 1; n   for (int i = 2; i <= n; i++) { n     dp[i] = max(dp[last - 1] + labs(val[i] - val[last]), n                 dp[last] + labs(val[i] - val[last + 1])); n     if (val[i] <= val[i + 1] && val[i] <= val[i - 1]) { n       last = i; n     } n     if (val[i] >= val[i + 1] && val[i] >= val[i - 1]) { n       last = i; n     } n   } n   long long res = dp[n]; n   printf( %lld , res); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     unsigned long long int mino = LONG_MAX; n     unsigned long long int minc = LONG_MAX; n     unsigned long long int ans = 0; n     unsigned long long int n; n     cin >> n; n     unsigned long long int o[n], c[n]; n     for (unsigned long long int i = 0; i < n; i++) { n       unsigned long long int ora; n       cin >> ora; n       o[i] = ora; n       if (ora < mino) { n         mino = ora; n       } n     } n     for (unsigned long long int i = 0; i < n; i++) { n       unsigned long long int ca; n       cin >> ca; n       c[i] = ca; n       if (ca < minc) { n         minc = ca; n       } n     } n     for (unsigned long long int i = 0; i < n; i++) { n       unsigned long long int w = min(o[i] - mino, c[i] - minc); n       ans = ans + w; n       o[i] = o[i] - w; n       c[i] = c[i] - w; n       if (o[i] == mino) { n         ans = ans + c[i] - minc; n       } else { n         ans = ans + o[i] - mino; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> split(string s) { n   vector<int> xs; n   stringstream ss(s); n   string item; n   while (getline(ss, item,  , )) { n     xs.push_back(stoi(item)); n   } n   return xs; n } n int main() { n   string s; n   getline(cin, s); n   vector<int> xxs = split(s); n   sort(xxs.begin(), xxs.end()); n   vector<pair<int, int>> sol; n   for (int i = 0; i < xxs.size(); i++) { n     int st = xxs[i]; n     int e = st; n     while (i < xxs.size() - 1 && (e + 1 == xxs[i + 1] || e == xxs[i + 1])) { n       e = xxs[i + 1]; n       i++; n     } n     sol.push_back(make_pair(st, e)); n   } n   for (int i = 0; i < sol.size(); i++) { n     if (sol[i].first != sol[i].second) { n       cout << sol[i].first <<  -  << sol[i].second; n     } else { n       cout << sol[i].first; n     } n     if (i != sol.size() - 1) { n       cout <<  , ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int kMaxN = 5000; n std::vector<int> way[kMaxN], cost[kMaxN]; n int f[kMaxN], c[kMaxN]; n short hash[kMaxN][kMaxN], father[kMaxN][2 * kMaxN]; n int a[kMaxN], id[kMaxN], t[kMaxN]; n inline bool cmp(int x, int y) { return a[x] < a[y]; } n void BuildTree(int u, int ff) { n   f[u] = ff; n   for (size_t i = 0; i < way[u].size(); ++i) { n     int v = way[u][i]; n     if (v == ff) continue; n     c[v] = cost[u][i]; n     BuildTree(v, u); n   } n } n int Find(short *f, int x) { n   int y = x, z; n   while (f[y] != -1) y = f[y]; n   while (x != y) { n     z = x; n     x = f[x]; n     f[z] = y; n   } n   return y; n } n int Put(int x) { n   int t = 0; n   while (x != 0) { n     ++t; n     if (f[x] == 0) return t; n     int ff = f[x]; n     t = Find(father[ff], t); n     if (++hash[ff][t] == c[ff]) { n       father[ff][t] = t + 1; n     } n     x = ff; n   } n   return 0; n } n int main() { n   int n, x, y, cc; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , a + i); n     id[i] = i; n   } n   std::sort(id, id + n, cmp); n   for (int j = 1; j < n; ++j) { n     scanf( %d%d%d , &x, &y, &cc); n     --x; n     --y; n     way[x].push_back(y); n     way[y].push_back(x); n     cost[x].push_back(cc); n     cost[y].push_back(cc); n   } n   BuildTree(0, -1); n   memset(father, -1, sizeof(father)); n   for (int i = 0; i < n; ++i) { n     t[id[i]] = Put(id[i]); n   } n   for (int i = 0; i < n; ++i) { n     if (i != 0) printf(   ); n     printf( %d , t[i]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isthere(string s1, string s2); n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     string s1, s2; n     cin >> s1 >> s2; n     if (s2.size() == s1.size()) { n       if (isthere(s1, s2)) { n         cout <<  YES  << endl; n       } else { n         cout <<  NO  << endl; n       } n       continue; n     } n     if (s2.size() < s1.size()) { n       cout <<  NO  << endl; n       continue; n     } n     bool y = 0; n     for (int i = 0; i <= (s2.size() - s1.size()); i++) { n       string s = s2.substr(i, s1.size()); n       if (isthere(s1, s)) { n         cout <<  YES  << endl; n         y = 1; n         break; n       } n     } n     if (y == 0) { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n bool isthere(string s1, string s2) { n   sort(s1.begin(), s1.end()); n   sort(s2.begin(), s2.end()); n   if (s1.compare(s2) == 0) { n     return true; n   } n   return false; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   char lowestChar =  z  + 1; n   string s; n   cin >> s; n   vector<int> ans(s.size(), 0); n   for (int i = 0; i < s.size(); ++i) { n     char c = s[i]; n     if (c < lowestChar) { n       ans[i] = 1; n       lowestChar = c; n     } else if (c == lowestChar) { n       ans[i - 1] ^= 1; n       ans[i] = 1; n     } n   } n   for (auto& x : ans) cout << x <<    ; n   cout << endl; n   return 0; n } n