#include <bits/stdc++.h> n using namespace std; n int main() { n   string x, y, z; n   cin >> x; n   cin >> y; n   cin >> z; n   x += y; n   sort(x.begin(), x.end()); n   sort(z.begin(), z.end()); n   if (x.length() != z.length()) n     cout <<  NO  n          <<   n ; n   else { n     for (int i = 0; i < x.length(); i++) { n       if (x[i] != z[i]) { n         cout <<  NO  n              <<   n ; n         return 0; n       } n     } n     cout <<  YES  n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 510; n int n, k; n int a[MAX], b[MAX]; n void init() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   cin >> k; n   for (int i = 1; i <= k; i++) cin >> b[i]; n } n bool valid(int i, int l, int r) { n   int x = i, y = i, sum = a[i]; n   while (true) { n     int old_x = x, old_y = y; n     while (x - 1 >= l && sum > a[x - 1]) { n       x--; n       sum += a[x]; n     } n     while (y + 1 <= r && sum > a[y + 1]) { n       y++; n       sum += a[y]; n     } n     if (old_x == x && old_y == y) break; n   } n   return x == l && y == r; n } n void print(int i, int l, int r) { n   int x = i, y = i, sum = a[i]; n   while (true) { n     int old_x = x, old_y = y; n     while (x - 1 >= l && sum > a[x - 1]) { n       cout << x <<   L  <<   n ; n       x--; n       sum += a[x]; n     } n     while (y + 1 <= r && sum > a[y + 1]) { n       cout << x <<   R  <<   n ; n       y++; n       sum += a[y]; n     } n     if (old_x == x && old_y == y) break; n   } n } n void process() { n   vector<pair<int, pair<int, int> > > p; n   bool found = true; n   int l, r = n, pb = k; n   while (r >= 1 && pb >= 1) { n     l = r; n     int sum = a[r]; n     while (l - 1 >= 1 && a[l - 1] + sum <= b[pb]) { n       l--; n       sum += a[l]; n     } n     if (sum == b[pb]) { n       bool exist = false; n       for (int i = l; i <= r; i++) n         if (valid(i, l, r)) { n           exist = true; n           p.push_back(make_pair(i, make_pair(l, r))); n           break; n         } n       if (exist) { n         sum = 0; n         pb--; n       } else { n         found = false; n         break; n       } n     } else { n       found = false; n       break; n     } n     r = l - 1; n   } n   if (r != 0 || pb != 0) found = false; n   if (!found) n     cout <<  NO ; n   else { n     cout <<  YES  <<   n ; n     for (int i = 0; i < (int)p.size(); i++) n       print(p[i].first, p[i].second.first, p[i].second.second); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   init(); n   process(); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void debug(T a, T b) { n   ; n } n template <class T> n void chmin(T& a, const T& b) { n   if (a > b) a = b; n } n template <class T> n void chmax(T& a, const T& b) { n   if (a < b) a = b; n } n namespace std { n template <class S, class T> n ostream& operator<<(ostream& out, const pair<S, T>& a) { n   out <<  (  << a.first <<  ,  << a.second <<  ) ; n   return out; n } n }  // namespace std n long long int readL() { n   long long int res; n   scanf( %I64d , &res); n   return res; n } n void printL(long long int res) { printf( %I64d , res); } n int n, m, n2; n int g[2005][2005]; n int order[2005], low[2005], cnt; n stack<int> cur; n int group[2005], gcnt; n int dfs(int v, int p) { n   order[v] = cnt++; n   low[v] = order[v]; n   cur.push(v); n   for (int i = 0; i < (n); ++i) n     if (g[v][i]) { n       int to = i; n       if (to == p) continue; n       if (order[to] != -1) { n         low[v] = min(low[v], order[to]); n       } else { n         low[v] = min(low[v], dfs(to, v)); n       } n     } n   if (low[v] < order[v]) return low[v]; n   while (!cur.empty() && cur.top() != v) { n     group[cur.top()] = gcnt; n     cur.pop(); n   } n   group[cur.top()] = gcnt; n   cur.pop(); n   ++gcnt; n   return low[v]; n } n vector<int> g2[2005]; n int size[2005]; n int subsize[2005]; n void prep(int v, int p) { n   subsize[v] = size[v]; n   for (auto to : g2[v]) { n     if (to == p) continue; n     prep(to, v); n     subsize[v] += subsize[to]; n   } n } n bool tmp[4005]; n int dfs2(int v, int p) { n   int res = 0; n   for (auto to : g2[v]) { n     if (to == p) continue; n     res += dfs2(to, v); n   } n   if (p != -1) { n     res += size[v] * (subsize[v] - size[v]); n   } else { n     res += size[v] * (subsize[v] - size[v]); n     int sub = subsize[v] - size[v]; n     memset((tmp), 0, sizeof(tmp)); n     tmp[0] = true; n     for (auto to : g2[v]) { n       for (int j = n2; j >= 0; --j) n         if (tmp[j]) tmp[j + subsize[to]] = true; n     } n     int maxi = -1; n     for (int i = 0; i < (n2 + 1); ++i) n       if (tmp[i]) chmax(maxi, i * (sub - i)); n     res += maxi; n   } n   return res; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < (m); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     --a; n     --b; n     g[a][b] = g[b][a] = 1; n   } n   memset(order, -1, sizeof(order)); n   dfs(0, -1); n   n2 = n; n   ; n   ; n   debug(group, group + n); n   for (int i = 0; i < (n); ++i) { n     size[group[i]]++; n     for (int j = 0; j < (n); ++j) n       if (g[i][j] && group[i] != group[j] && i > j) { n         g2[group[i]].push_back(group[j]); n         g2[group[j]].push_back(group[i]); n       } n   }; n   ; n   n = gcnt; n   for (int i = 0; i < (n); ++i) debug((g2[i]).begin(), (g2[i]).end()); n   int res = 0; n   for (int i = 0; i < (n); ++i) { n     prep(i, -1); n     bool fail = 0; n     for (auto to : g2[i]) n       if (subsize[to] * 2 > n2) { n         fail = 1; n       } n     if (!fail) { n       int tmp = dfs2(i, -1); n       chmax(res, tmp); n     } n   } n   for (int i = 0; i < (n); ++i) res += size[i] * size[i]; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[2 * 50004]; n int main(void) { n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= 2 * n; i++) { n     a[i] = i; n   } n   for (int i = 1; i <= k; i++) { n     swap(a[2 * i], a[2 * i - 1]); n   } n   for (int i = 1; i <= 2 * n; i++) { n     cout << a[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[5] = {0, -1, 1, 0, 0}, dy[5] = {0, 0, 0, -1, 1}; n int n, m, k, i, j, dis[2005][2005], vis[2005][2005], s1, s2; n bool check(int x, int y, int d, bool f = 0) { n   int i, l = max(1, x - d), r = min(n, x + d); n   if (f) l = s1; n   for (i = l; i <= r; i++) { n     int t = d - abs(x - i); n     if (i >= 1 && i <= n && y - t >= 1 && y - t <= m && !vis[i][y - t]) { n       s1 = i; n       s2 = y - t; n       return 1; n     } n     if (i >= 1 && i <= n && y + t >= 1 && y + t <= m && !vis[i][y + t]) { n       s1 = i; n       s2 = y + t; n       return 1; n     } n   } n   return 0; n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   int lx = -1, ly = -1; n   while (k--) { n     int x, y; n     scanf( %d%d , &x, &y); n     for (i = max(1, x - 5); i <= min(n, x + 5); i++) { n       for (j = max(1, y - 5); j <= min(m, y + 5); j++) { n         dis[x][y] = max(dis[x][y], dis[i][j] - abs(i - x) - abs(j - y)); n       } n     } n     if (x == lx && y == ly) { n       if (!check(x, y, dis[x][y], 1)) n         while (!check(x, y, dis[x][y])) dis[x][y]++; n     } else n       while (!check(x, y, dis[x][y])) dis[x][y]++; n     vis[s1][s2] = 1; n     printf( %d %d n , s1, s2); n     lx = x; n     ly = y; 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), cout.tie(0); n   int n, m; n   cin >> n >> m; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   cout <<  0  ; n   vector<int> cnt(110, 0); n   cnt[a[0]]++; n   for (int w = 1; w < n; ++w) { n     int s = a[w]; n     int k = 0; n     for (int i = 1; i <= 100; ++i) { n       if (s + i * cnt[i] <= m) { n         s += i * cnt[i]; n         k += cnt[i]; n       } else { n         int l = -1, r = cnt[i] + 1; n         while (r - l > 1) { n           int mid = (l + r) / 2; n           if (s + i * mid <= m) { n             l = mid; n           } else { n             r = mid; n           } n         } n         k += l; n         break; n       } n     } n     cout << w - k <<    ; n     cnt[a[w]]++; n   } n } n


#include <bits/stdc++.h> n const int N = 100010; n using namespace std; n namespace YKY { n inline int rnd() { n   int res = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     res = res * 10 + ch -  0 ; n     ch = getchar(); n   } n   return res * f; n } n inline void wr(int x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) wr(x / 10); n   putchar(x % 10 +  0 ); n } n char s[N]; n int n, m, k; n int Main() { n   n = rnd(); n   m = rnd(); n   k = rnd(); n   scanf( %s , s + 1); n   m = m + k; n   for (int i = 1, opt, l, r, c; i <= m; i++) { n     opt = rnd(); n     l = rnd(); n     r = rnd(); n     c = rnd(); n     if (opt == 1) n       memset(s + l, c +  0 , r - l + 1); n     else n       puts(memcmp(s + l, s + l + c, r - l - c + 1) ?  NO  :  YES ); n   } n   return 0; n } n }  // namespace YKY n int main() { return YKY ::Main(); } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y; n   bool operator<(const point &other) const { n     return x <= other.x && y <= other.y; n   } n }; n map<int, set<point> > m; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     point p; n     scanf( %d %d , &p.x, &p.y); n     m[p.y - p.x].insert(p); n   } n   vector<point> v; n   bool ok = true; n   for (int i = 0; i < n; i++) { n     int d; n     scanf( %d , &d); n     if (m.find(d) == m.end()) n       ok = false; n     else if (m[d].size() == 0) n       ok = false; n     else { n       v.push_back(*m[d].begin()); n       m[d].erase(m[d].begin()); n     } n   } n   if ((int)v.size() != n || !ok) { n     printf( NO ); n     return 0; n   } n   for (int i = 1; i < v.size(); i++) { n     if (v[i] < v[i - 1]) { n       printf( NO n ); n       return 0; n     } n   } n   printf( YES n ); n   for (int i = 0; i < v.size(); i++) { n     printf( %d %d n , v[i].x, v[i].y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int a[maxn]; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   if (n > min(m, k)) n     printf( No n ); n   else n     printf( Yes n ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n inline int read() { n   int x = 0, 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()) n     x = (x << 1) + (x << 3) + ch -  0 ; n   return x * f; n } n const int N = 250025; n const int M = 1e6 + 10; n int n, m, k, w0, w1, tot; n int u[M], nex[M], a[5]; n int h[N], b[N], deep[N], fa[N]; n void addedge(int w0, int w1) { n   u[++tot] = w1; n   nex[tot] = h[w0]; n   h[w0] = tot; n } n void dfs(int w, int depth) { n   if (depth > w1) w0 = w; n   deep[w] = depth; n   bool leaf = true; n   for (int i = h[w]; i; i = nex[i]) n     if (!deep[u[i]]) { n       fa[u[i]] = w; n       dfs(u[i], depth + 1); n       leaf = false; n     } n   if (leaf) b[tot++] = w; n } n int main() { n   n = read(); n   m = read(); n   k = read(); n   while (m--) { n     w0 = read(); n     w1 = read(); n     addedge(w0, w1); n     addedge(w1, w0); n   } n   w1 = n / k; n   w0 = tot = 0; n   fa[1] = 1; n   dfs(1, 1); n   if (w0) { n     printf( PATH n%d n , deep[w0]); n     for (; w0 != 1; w0 = fa[w0]) printf( %d  , w0); n     printf( 1 n ); n   } else { n     printf( CYCLES n ); n     for (int i = 0; i < k; i++) { n       int j = h[w0 = b[i]]; n       tot = 0; n       for (int cnt = 3; cnt; j = nex[j], cnt--) n         if (u[j] != fa[w0]) a[tot++] = u[j]; n       if ((deep[w0] - deep[a[0]] + 1) % 3 != 0) { n         printf( %d n , deep[w0] - deep[a[0]] + 1); n         for (; w0 != a[0]; w0 = fa[w0]) printf( %d  , w0); n         printf( %d n , a[0]); n       } else if ((deep[w0] - deep[a[1]] + 1) % 3 != 0) { n         printf( %d n , deep[w0] - deep[a[1]] + 1); n         for (; w0 != a[1]; w0 = fa[w0]) printf( %d  , w0); n         printf( %d n , a[1]); n       } else { n         if (deep[a[0]] < deep[a[1]]) swap(a[0], a[1]); n         printf( %d n , deep[a[0]] - deep[a[1]] + 2); n         printf( %d  , w0); n         for (w0 = a[0]; w0 != a[1]; w0 = fa[w0]) printf( %d  , w0); n         printf( %d n , a[1]); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cur; n bool c[1011][1011]; n int x[33], y[33], z[33]; n void connect(int target, int between) { n   for (int i = (1), _b = (between); i <= _b; i++) z[i] = ++cur; n   z[between + 1] = target; n   z[0] = 1; n   for (int i = (0), _b = (between); i <= _b; i++) c[z[i]][z[i + 1]] = true; n } n int main() { n   int n; n   while (cin >> n) { n     memset(c, 0, sizeof c); n     cur = 2; n     for (int i = (1), _b = (30); i <= _b; i++) x[i] = ++cur; n     for (int i = (1), _b = (30); i <= _b; i++) y[i] = ++cur; n     c[x[30]][2] = c[y[30]][2] = true; n     for (int i = (1), _b = (29); i <= _b; i++) { n       c[x[i]][x[i + 1]] = true; n       c[y[i]][y[i + 1]] = true; n       c[y[i]][x[i + 1]] = true; n       c[x[i]][y[i + 1]] = true; n     } n     for (int i = (29), _b = (0); i >= _b; i--) n       if ((1 << i) <= n) { n         n -= 1 << i; n         connect(x[30 - i], 30 - i - 1); n       } n     cout << cur << endl; n     for (int i = (1), _b = (cur); i <= _b; i++) { n       for (int j = (1), _b = (cur); j <= _b; j++) n         if (c[i][j] || c[j][i]) n           putchar( Y ); n         else n           putchar( N ); n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int t; n   cin >> t; n   bool even; n   bool odd; n   for (int i = 1; i <= t; i++) { n     int size; n     even = false; n     odd = false; n     cin >> size; n     int arr[size]; n     for (int j = 0; j < size; j++) cin >> arr[j]; n     for (int j = 0; j < size; j++) n       if (arr[j] % 2 == 0) n         even = true; n       else n         odd = true; n     if (even == true && odd == true) n       cout <<  YES  << endl; n     else if (even == false && size % 2 != 0) 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 using vint = vector<int>; n using pint = pair<int, int>; n using vpint = vector<pint>; n template <typename A, typename B> n inline void chmin(A& a, B b) { n   if (a > b) a = b; n } n template <typename A, typename B> n inline void chmax(A& a, B b) { n   if (a < b) a = b; n } n template <class A, class B> n ostream& operator<<(ostream& ost, const pair<A, B>& p) { n   ost <<  {  << p.first <<  ,  << p.second <<  } ; n   return ost; n } n template <class T> n ostream& operator<<(ostream& ost, const vector<T>& v) { n   ost <<  { ; n   for (int i = 0; i < v.size(); i++) { n     if (i) ost <<  , ; n     ost << v[i]; n   } n   ost <<  } ; n   return ost; n } n struct Cactus { n   vector<vector<int>> G; n   vector<vector<int>> cs; n   vector<int> vis, par, dep; n   void dfs(int v) { n     vis[v] = 1; n     for (auto u : G[v]) { n       if (!vis[u]) { n         par[u] = v; n         dep[u] = dep[v] + 1; n         dfs(u); n       } else if (dep[u] < dep[v]) { n         int w = v; n         vector<int> c{w}; n         while (true) { n           w = par[w]; n           c.push_back(w); n           if (w == u) break; n         } n         cs.push_back(c); n       } n     } n   } n   Cactus(const vector<vector<int>>& G) : G(G) { n     vis.resize(G.size()); n     par.resize(G.size()); n     dep.resize(G.size()); n     dfs(0); n   } n }; n int N, M; n int A[555555], B[555555]; n int info[555555]; n int dp[555555]; n int memA[555555], memB[555555]; n signed main() { n   scanf( %d%d , &N, &M); n   vint lis; n   vector<vint> G(N); n   map<pint, int> edgeID; n   for (int i = 0; i < (M); i++) { n     scanf( %d%d , &A[i], &B[i]); n     A[i]--; n     B[i]--; n     G[A[i]].push_back(B[i]); n     G[B[i]].push_back(A[i]); n     edgeID[{A[i], B[i]}] = i; n     edgeID[{B[i], A[i]}] = i; n   } n   Cactus cac(G); n   fill_n(info, M, -1); n   for (auto c : cac.cs) { n     if (c.size() == 2) continue; n     vint id; n     for (int i = 0; i < (c.size()); i++) { n       int a = c[i]; n       int b = c[(i + 1) % c.size()]; n       id.push_back(edgeID[{a, b}]); n     } n     rotate(id.begin(), min_element((id).begin(), (id).end()), id.end()); n     int m = max_element((id).begin(), (id).end()) - id.begin(); n     bool ok = true; n     for (int i = 0; i < m; i++) n       if (id[i] > id[i + 1]) ok = false; n     for (int i = m; i + 1 < id.size(); i++) n       if (id[i] < id[i + 1]) ok = false; n     if (!ok) continue; n     info[id[0]] = id[m]; n   } n   for (int i = 0; i < (N); i++) dp[i] = 1; n   for (int i = M - 1; i >= 0; i--) { n     int addA = dp[B[i]]; n     int addB = dp[A[i]]; n     if (info[i] != -1) { n       int k = info[i]; n       int tmp = memA[k] + memB[k]; n       addA -= tmp; n       addB -= tmp; n     } n     memA[i] = dp[A[i]]; n     memB[i] = dp[B[i]]; n     dp[A[i]] += addA; n     dp[B[i]] += addB; n   } n   for (int i = 0; i < (N); i++) dp[i]--; n   for (int i = 0; i < (N); i++) { n     if (i) printf(   ); n     printf( %d , dp[i]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n const int mod = 1000000007; n using namespace std; n pair<int, int> a[12345]; n vector<int> ans[3]; n map<pair<int, int>, bool> used; n map<int, int> cnts; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i].first); n     a[i].second = i + 1; n     cnts[a[i].first]++; n   } n   int x = 0, y = 0; n   for (map<int, int>::iterator it = cnts.begin(); it != cnts.end(); ++it) { n     if (it->second >= 3) n       y++; n     else { n       if (it->second == 2) { n         x++; n       } n     } n   } n   if (x >= 2 || y >= 1) { n     puts( YES ); n     sort(a, a + n); n     for (int i = 0; i < n; ++i) { n       ans[0].push_back(a[i].second); n       if (i != n) { n         used[make_pair(i, i + 1)] = false; n         used[make_pair(i + 1, i)] = false; n       } n     } n     int temp; n     for (int i = 0; i < n - 1; ++i) { n       if (!used[make_pair(i, i + 1)] && a[i].first == a[i + 1].first) { n         temp = a[i].second; n         a[i].second = a[i + 1].second; n         a[i + 1].second = temp; n         used[make_pair(i, i + 1)] = true; n         used[make_pair(i + 1, i)] = true; n         break; n       } n     } n     for (int i = 0; i < n; ++i) { n       ans[1].push_back(a[i].second); n     } n     for (int i = 0; i < n - 1; ++i) { n       if (!used[make_pair(i, i + 1)] && a[i].first == a[i + 1].first) { n         temp = a[i].second; n         a[i].second = a[i + 1].second; n         a[i + 1].second = temp; n         used[make_pair(i, i + 1)] = true; n         used[make_pair(i + 1, i)] = true; n         break; n       } n     } n     for (int i = 0; i < n; ++i) { n       ans[2].push_back(a[i].second); n     } n     for (int i = 0; i < 3; ++i) { n       for (int j = 0; j < ans[i].size(); ++j) { n         printf( %d  , ans[i][j]); n       } n       printf(  n ); n     } n   } else { n     cout <<  NO  << endl; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void max_swap(T& a, const T& b) { n   a = max(a, b); n } n template <class T> n void min_swap(T& a, const T& b) { n   a = min(a, b); n } n const double EPS = 1e-8; n const double PI = acos(-1.0); n const int dx[] = {0, 1, 0, -1}; n const int dy[] = {1, 0, -1, 0}; n bool valid_pos(int x, int y, int w, int h) { n   return 0 <= x && x < w && 0 <= y && y < h; n } n int main() { n   ios::sync_with_stdio(false); n   string s, t; n   cin >> s >> t; n   int n = s.size(), m = t.size(); n   static int dp[5555][5555]; n   const int mod = 1000000007; n   for (int i = 0; i < n; ++i) { n     int sum = 0; n     for (int j = 0; j < m; ++j) { n       if (s[i] == t[j]) { n         (dp[i + 1][j + 1] += sum + 1) %= mod; n       } n       (sum += dp[i][j + 1]) %= mod; n     } n   } n   int res = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) (res += dp[i + 1][j + 1]) %= mod; n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char block[][3][4] = {{ ### ,  .#. ,  .#. }, n                       { #.. ,  ### ,  #.. }, n                       { .#. ,  .#. ,  ### }, n                       { ..# ,  ### ,  ..# }}; n int cell[10][10], anscell[10][10]; n int bcnt, ans; n bool isPlacable(int i, int j, int k) { n   for (int p = 0; p < 3; ++p) n     for (int q = 0; q < 3; ++q) { n       if (cell[i + p][j + q] != -1 && block[k][p][q] ==  # ) return false; n     } n   return true; n } n void setBlock(int i, int j, int k) { n   for (int p = 0; p < 3; ++p) n     for (int q = 0; q < 3; ++q) { n       if (block[k][p][q] ==  # ) cell[i + p][j + q] = bcnt; n     } n   ++bcnt; n } n void removeBlock(int i, int j, int k) { n   for (int p = 0; p < 3; ++p) n     for (int q = 0; q < 3; ++q) { n       if (block[k][p][q] ==  # ) cell[i + p][j + q] = -1; n     } n   --bcnt; n } n void go(int i, int j) { n   if (j >= m - 2) { n     go(i + 1, 0); n     return; n   } n   if (i == n - 2) { n     if (ans < bcnt) { n       ans = bcnt; n       memcpy(anscell, cell, sizeof(cell)); n     } n     return; n   } n   if (bcnt + (n * m - (i * m + j)) / 6 <= ans) { n     return; n   } n   for (int k = 0; k < 4; ++k) { n     if (isPlacable(i, j, k)) { n       setBlock(i, j, k); n       go(i, j + (k == 3 ? 3 : 2)); n       removeBlock(i, j, k); n     } n   } n   go(i, j + 1); n } n int main() { n   memset(cell, -1, sizeof(cell)); n   memset(anscell, -1, sizeof(anscell)); n   scanf( %d %d , &n, &m); n   if (n >= 3 && m >= 3) go(0, 0); n   printf( %d n , ans); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       putchar(anscell[i][j] == -1 ?  .  : ( A  + anscell[i][j])); n     } n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, i, o = 0, e = 0; n   cin >> n; n   for (i = 0; i < n; i = i + 1) { n     long long int x; n     cin >> x; n     if (x % 2 == 0) n       e = e + 1; n     else n       o = o + 1; n   } n   long long int res = min(o, e); n   o = o - res; n   res = res + (o / 3); n   cout << res << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n const long long N = 1e5 + 5; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   string s; n   cin >> s; n   vector<long long> pref(n + 2), suff(n + 2); n   for (long long i = 1; i <= n; i++) { n     if (s[i - 1] ==  G ) { n       pref[i] = 1; n       pref[i] += pref[i - 1]; n     } n   } n   for (long long i = n; i >= 1; i--) { n     if (s[i - 1] ==  G ) { n       suff[i] = 1; n       suff[i] += suff[i + 1]; n     } n   } n   long long ans = 0; n   long long cnt = 0; n   for (long long i = 1; i <= n; i++) { n     if (s[i - 1] ==  G ) cnt++; n     ans = max(ans, pref[i]); n   } n   for (long long i = 1; i <= n; i++) { n     if (s[i - 1] ==  S ) { n       if (i == 4) { n         debug() <<   [  n                 <<  pref[i - 1]  n                     :   n                 << (pref[i - 1]) n                 <<  ]   n                      [  n                 <<  suff[i + 1]  n                     :   n                 << (suff[i + 1]) <<  ]  ; n       } n       if (pref[i - 1] + suff[i + 1] < cnt) n         ans = max(ans, pref[i - 1] + suff[i + 1] + 1); n       else if (pref[i - 1] + suff[i + 1] == cnt) { n         ans = max(ans, pref[i - 1] + suff[i + 1]); n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n using cd = complex<ld>; n int query(int l, int r) { n   cout <<  ?   << l <<     << r << endl; n   cin >> l; n   return l; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   vector<int> sums; n   for (int i = 1; i < n; i++) { n     sums.push_back(query(i, i + 1)); n   } n   int sum123 = query(1, 3); n   vector<int> a(n); n   int a2 = sums[0] + sums[1] - sum123; n   a[0] = sums[0] - a2; n   a[1] = a2; n   for (int i = 2; i < n; i++) { n     a[i] = sums[i - 1] - a[i - 1]; n   } n   cout <<  !  ; n   for (int x : a) { n     cout << x <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ar[100009], f[100009], b[100009], fl = 1; n map<long long, long long> mb, mf; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) { n     cin >> f[i]; n     mf[f[i]]++; n     ar[f[i]] = i; n   } n   for (long long i = 1; i <= m; i++) { n     cin >> b[i]; n     mb[b[i]]++; n   } n   for (auto pp : mb) { n     long long x = pp.first; n     if (mf[x] == 0) { n       cout <<  Impossible  << endl; n       return 0; n     } n     if (mf[x] != 1) fl = 0; n   } n   if (!fl) n     cout <<  Ambiguity  << endl; n   else { n     cout <<  Possible  << endl; n     for (long long i = 1; i <= m; i++) { n       long long x = b[i]; n       cout << ar[x] <<    ; n     } n     cout << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n vector<long long> foo; n long long add = 0; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     foo.push_back(k); n   } n   cout << n + 1 <<   n ; n   for (int i = foo.size() - 1; i >= 0; i--) { n     foo[i] += add; n     foo[i] %= n; n     int q = i - foo[i] + n; n     add += q; n     cout << 1 <<     << i + 1 <<     << q <<   n ; n   } n   cout << 2 <<     << n <<     << n; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, c, d, num, e; n   int flag = 1; n   scanf(  %d , &num); n   num++; n   while (1) { n     e = num; n     a = num % 10; n     num = num / 10; n     b = num % 10; n     num = num / 10; n     c = num % 10; n     d = num / 10; n     if (a != b && a != c && a != d && b != c && b != d && c != d) { n       break; n     } else { n       e++; n       num = e; n     } n   } n   printf( %d , e); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const int MMAX = 1e4 + 7; n const int MAXDEG = 55; n long long v[MAXDEG][MMAX]; n vector<long long int> revs = {0}; n void rev_begin() { n   vector<long long int> y; n   long long t = MOD - 2; n   while (t > 0) { n     y.push_back(t % 2); n     t /= 2; n   } n   for (int i = 1; i < MAXDEG; i++) { n     vector<long long int> a; n     long long s = i; n     for (int j = 0; j < 100; j++) { n       a.push_back(s % MOD); n       s = s * s; n       s %= MOD; n     } n     long long ansy = 1; n     for (int j = 0; j < y.size(); j++) { n       if (y[j] == 1) { n         ansy *= a[j]; n         ansy %= MOD; n       } n     } n     revs.push_back(ansy); n   } n } n void clr() { n   for (int i = 0; i < MMAX; i++) n     for (int j = 0; j < MAXDEG; j++) v[j][i] = 0; n } n void show() { n   for (int i = 0; i < 10; i++) { n     for (int j = 0; j < 5; j++) { n       cout << v[i][j] <<    ; n     } n     cout << endl; n   } n } n void doit(long long int u, int alpha) { n   clr(); n   long long p = 1; n   for (int j = 0; j < alpha + 1; j++) { n     v[j][0] = p % MOD; n     p *= u; n     p %= MOD; n   } n   for (int i = 1; i < MMAX; i++) { n     for (int j = 0; j < alpha + 1; j++) { n       for (int l = 0; l <= j; l++) { n         v[j][i] += (v[l][i - 1] * revs[j + 1]) % MOD; n         v[j][i] %= MOD; n       } n     } n   } n } n int main() { n   long long n, k; n   rev_begin(); n   cin >> n >> k; n   long long ans = 1; n   long long t = 2; n   while (t * t <= n) { n     while (t * t <= n && n % t != 0) t++; n     if (n % t == 0) { n       int alpha = 0; n       while (n % t == 0) { n         alpha++; n         n /= t; n       } n       doit(t, alpha); n       ans *= v[alpha][k]; n       ans %= MOD; n     } n   } n   if (n > 1) { n     t = n; n     doit(t, 1); n     ans *= v[1][k]; n     ans %= MOD; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long ans = 0; n   int n; n   cin >> n; n   char str[65000]; n   cin >> str; n   for (int i = 0; i < n; i++) { n     if ((str[i] -  0 ) % 2 == 0) { n       ans += i + 1; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a[2000007]; n vector<int> deg(2000007, 0); n vector<pair<int, int>> ans; n int n, m; n void bfs(int node) { n   vector<bool> used(n); n   used[node] = true; n   queue<int> q; n   q.push(node); n   while (!q.empty()) { n     int currnode = q.front(); n     q.pop(); n     for (auto x : a[currnode]) { n       if (used[x]) continue; n       ans.push_back({x, currnode}); n       used[x] = true; n       q.push(x); n     } n   } n } n void solve() { n   cin >> n >> m; n   int u, v; n   for (int i = 0; i < m; i++) { n     cin >> u >> v; n     u--; n     v--; n     a[u].push_back(v); n     a[v].push_back(u); n     deg[u]++; n     deg[v]++; n   } n   int maxnode = 0; n   for (int i = 0; i < n; i++) { n     if (deg[maxnode] < deg[i]) maxnode = i; n   } n   bfs(maxnode); n   for (auto x : ans) { n     cout << x.first + 1 <<     << x.second + 1 << endl; n   } n } n int main() { n   int t; n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<int, int> > s0, s; n int K; n long long xx[200010], yy[200010]; n void func(long long x, long long y) { n   while (K > 0 && yy[K - 1] < y) K--; n   while (K >= 2) { n     long long tmp = (x - xx[K - 2]) * (yy[K - 1] - yy[K - 2]) - n                     (xx[K - 1] - xx[K - 2]) * (y - yy[K - 2]); n     if (tmp < 0) n       K--; n     else n       break; n   } n   xx[K] = x; n   yy[K] = y; n   K++; n } n int main(void) { n   int N, M, x, y, i; n   cin >> N >> M >> x >> y; n   for ((i) = 0; (i) < (int)(N); (i)++) { n     scanf( %d%d , &x, &y); n     s0.insert(make_pair(x, y)); n     s.insert(make_pair(x, -y)); n   } n   for ((i) = 0; (i) < (int)(M); (i)++) { n     scanf( %d%d , &x, &y); n     s.insert(make_pair(x, -y)); n   } n   for (__typeof((s).begin()) itr = (s).begin(); itr != (s).end(); itr++) { n     x = (*itr).first; n     y = (*itr).second; n     func(x, -y); n   } n   int tp; n   string ans =  Min ; n   for ((i) = 0; (i) < (int)(K); (i)++) { n     if (s0.find(make_pair(xx[i], yy[i])) != s0.end()) ans =  Max ; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   char s[1001]; n   char t[1001]; n   scanf( %s %s , s, t); n   int idx = 0; n   while (s[idx] !=   0 ) { n     if (t[idx] ==   0 ) { n       puts( No ); n       return 0; n     } n     char cs = s[idx]; n     char ct = t[idx]; n     int cvowel = 0; n     int tvowel = 0; n     if (cs ==  a  || cs ==  e  || cs ==  i  || cs ==  o  || cs ==  u ) n       cvowel = 1; n     if (ct ==  a  || ct ==  e  || ct ==  i  || ct ==  o  || ct ==  u ) n       tvowel = 1; n     if (cvowel != tvowel) { n       puts( No ); n       return 0; n     } n     idx++; n   } n   if (t[idx] !=   0  && s[idx] ==   0 ) { n     puts( No ); n     return 0; n   } n   puts( Yes ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int kolvo = 0; n   int kolvo1 = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] == 5) { n       kolvo++; n     } n     if (a[i] == 0) { n       kolvo1++; n     } n   } n   sort(a.rbegin(), a.rend()); n   if ((kolvo / 9) > 0 and kolvo1 > 0) { n     for (int i = 0; i < (kolvo / 9) * 9; i++) { n       cout << a[i]; n     } n     sort(a.begin(), a.end()); n     for (int i = 0; i < kolvo1; i++) { n       cout << a[i]; n     } n   } else { n     if (kolvo1 > 0) { n       cout << 0; n     } else { n       cout << -1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200200; n vector<long long int> g[N], e[N]; n set<pair<long long int, long long int> > S; n int n, m; n long long int d[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     long long int x, y, z; n     cin >> x >> y >> z; n     g[x].push_back(y); n     e[x].push_back(z); n     g[y].push_back(x); n     e[y].push_back(z); n   } n   for (int i = 1; i <= n; i++) { n     cin >> d[i]; n     S.insert(make_pair(d[i], i)); n   } n   while (S.size() != 0) { n     int u = S.begin()->second; n     S.erase(S.begin()); n     for (int i = 0; i < g[u].size(); i++) { n       long long int v = g[u][i]; n       long long int cost = e[u][i]; n       if (cost * 2 + d[u] < d[v]) { n         S.erase(make_pair(d[v], v)); n         d[v] = cost * 2 + d[u]; n         S.insert(make_pair(d[v], v)); n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     cout << d[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long mod = 1000000007; n const double e = 2.718281828459; n long long gcd(long long a, long long b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long gcd1(int a, int b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long pow_mod(long long a, long long b, long long c) { n   long long ans = 1; n   a = a % c; n   while (b > 0) { n     if (b % 2 == 1) ans = (ans * a) % c; n     b = b / 2; n     a = (a * a) % c; n   } n   return ans; n } n int pow_int(int a, int b) { n   int ans = 1; n   while (b > 0) { n     if (b % 2 == 1) ans = ans * a; n     b = b / 2; n     a = a * a; n   } n   return ans; n } n long long pow_llong(long long a, long long b) { n   long long ans = 1; n   while (b > 0) { n     if (b % 2 == 1) ans = ans * a; n     b = b / 2; n     a = a * a; n   } n   return ans; n } n const int dx[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0}; n const int dy[9] = {0, 1, 0, -1, -1, -1, 0, 1, 1}; n int Scan() { n   int res = 0, flag = 0; n   char ch; n   if ((ch = getchar()) ==  - ) { n     flag = 1; n   } else if (ch >=  0  && ch <=  9 ) { n     res = ch -  0 ; n   } n   while ((ch = getchar()) >=  0  && ch <=  9 ) { n     res = res * 10 + (ch -  0 ); n   } n   return flag ? -res : res; n } n void Out(int a) { n   if (a < 0) { n     putchar( - ); n     a = -a; n   } n   if (a >= 10) { n     Out(a / 10); n   } n   putchar(a % 10 +  0 ); n } n long long jc_mod(long long a, long long b, long long mod) { n   long long ans = 1; n   b = max(b, a - b); n   for (long long i = a; i > b; i--) { n     ans *= i; n     ans %= mod; n   } n   return ans; n } n double lg(double a) { return (log(a) / log(10.0)); } n int lowbit(int x) { return x & -x; } n inline int read() { n   int f = 1, x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n void lisan(int *x, int n) { n   int data[100010]; n   for (int i = 1; i <= n; i++) data[i] = x[i]; n   sort(data + 1, data + 1 + n); n   int o = unique(data + 1, data + 1 + n) - data - 1; n   for (int i = 1; i <= n; i++) n     x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data; n } n long long calc(int M) { return 1; } n int sanfen(int L, int R) { n   int M, RM; n   while (L + 1 < R) { n     M = (L + R) / 2; n     RM = (M + R) / 2; n     if (calc(M) < calc(RM)) n       R = RM; n     else n       L = M; n   } n   return L; n } n int CaculateWeekDay(int y, int m, int d) { n   if (m == 1 || m == 2) { n     m += 12; n     y--; n   } n   int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; n   return iWeek; n } n map<string, int> mm; n map<char, int> cc; n string a; n char t[100]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     cin >> a; n     int q = 0; n     cc.clear(); n     int len = a.length(); n     for (int i = 0; i < len; i++) { n       if (!cc[a[i]]) { n         cc[a[i]] = 1; n         t[q++] = a[i]; n       } n     } n     t[q] = 0; n     sort(t, t + q); n     string y = t; n     mm[y] = 1; n   } n   printf( %d n , mm.size()); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, h, m, h0, m0, c(1), cash(1); n   scanf( %d , &n); n   scanf( %d%d , &h0, &m0); n   while (--n) { n     scanf( %d%d , &h, &m); n     if (h == h0 && m == m0) { n       c += 1; n       if (c > cash) { n         cash = c; n       } n     } else { n       c = 1; n     } n     h0 = h; n     m0 = m; n   } n   printf( %d n , cash); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int count = 0; n   vector<long long> ans; n   int k = 0; n   for (int i = 0; i < n; i++) { n     int u; n     scanf( %d , &u); n     if (count > 0 && u != 0) { n       if (k != 0) n         ans.push_back(count + 1); n       else { n         ans.push_back(1); n         k = 1; n       } n       count = 0; n     } else if (count > 0 && u == 0) { n       count++; n     } else if (u == 0) { n       count++; n     } else { n       k = 1; n     } n   } n   if (count > 0 && k != 0) { n     ans.push_back(1); n   } else if (count > 0 && k == 0) { n     ans.push_back(0); n   } n   long long ans1 = 1; n   for (int i = 0; i < ans.size(); i++) { n     ans1 = ans1 * (ans[i]); n   } n   printf( %lld n , ans1); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, long long> > V1, V2; n int n, s; n int main() { n   while (~scanf( %d%d , &n, &s)) { n     V1.clear(); n     V2.clear(); n     long long sum1 = 0; n     long long sum2 = 0; n     long long ans = 0; n     for (int i = 0; i < n; i++) { n       long long a, b, c; n       scanf( %lld%lld%lld , &c, &a, &b); n       if (a > b) { n         sum1 += c; n         ans += c * a; n         V1.push_back(make_pair(a - b, c)); n       } else { n         sum2 += c; n         ans += c * b; n         V2.push_back(make_pair(b - a, c)); n       } n     } n     sum1 %= s; n     sum2 %= s; n     if (sum1 + sum2 > s) { n       cout << ans << endl; n       continue; n     } else { n       sort(V1.begin(), V1.end()); n       sort(V2.begin(), V2.end()); n       long long tmp1 = 0; n       long long tmp2 = 0; n       int len = V1.size(); n       for (int i = 0; i < len; i++) { n         tmp1 += min(sum1, V1[i].second) * V1[i].first; n         sum1 -= min(sum1, V1[i].second); n       } n       len = V2.size(); n       for (int i = 0; i < len; i++) { n         tmp2 += min(sum2, V2[i].second) * V2[i].first; n         sum2 -= min(sum2, V2[i].second); n       } n       cout << ans - min(tmp1, tmp2) << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, k; n   cin >> n >> k; n   vector<long long> a(n); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   vector<long long> step(100, 0); n   for (long long i = 0; i < n; i++) { n     long long x = 0; n     while (a[i] > 0) { n       step[x] += a[i] % k; n       a[i] /= k; n       x++; n     } n   } n   for (long long i = 0; i < 100; i++) { n     if (step[i] > 1) { n       cout <<  NO  << endl; n       return; n     } n   } n   cout <<  YES  << endl; n } n signed main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   map<int, int> m; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     m[a[i]] = i; n   } n   long long int b[n]; n   map<int, int> freq; n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n     int shift = m[b[i]] - i; n     if (m[b[i]] - i < 0) shift = (n - i + m[b[i]]); n     freq[shift]++; n   } n   int ans = 0; n   for (auto i : freq) { n     ans = max(ans, i.second); n   } n   cout << ans <<   n ; n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int size[3010], fa[3010], sum[3010], head[10010]; n struct node { n   int x, y, next; n } e[3010]; n int find(int x) { n   if (x != fa[x]) fa[x] = find(fa[x]); n   return fa[x]; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int x, y, w; n     scanf( %d%d%d , &x, &y, &w); n     e[i].x = x; n     e[i].y = y; n     e[i].next = head[w]; n     head[w] = i; n   } n   int s = 0; n   for (int i = 1; i <= n; i++) { n     fa[i] = i; n     size[i] = 1; n     scanf( %d , &sum[i]); n     s += sum[i]; n   } n   for (int i = 1; i <= 10000; i++) { n     int p = head[i]; n     while (p) { n       int x = find(e[p].x), y = find(e[p].y); n       fa[y] = x; n       size[x] += size[y]; n       sum[x] += sum[y]; n       if (size[x] + sum[x] > s) { n         printf( %d n , i); n         return 0; n       } n       p = e[p].next; n     } n   } n   puts( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n const int maxx = 2e6 + 5; n using namespace std; n long long a[maxx]; n long long biaoji[maxx] = {0}; n int main() { n   long long t, i, j, m, n; n   cin >> n; n   long long maxl = 0; n   for (i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     maxl = max(maxl, a[i]); n     biaoji[a[i]]++; n   } n   long long sum1 = 0, sum2 = 0; n   long long cishu = 0; n   long long weizhi = 0; n   for (i = 1; i <= maxl + 1; i++) { n     if (biaoji[i] > 0) { n       if (biaoji[i + 1] > 0 && biaoji[i + 2] > 0) { n         sum1++; n         i += 2; n       } else if (biaoji[i + 1] > 0) { n         sum1++; n         i++; n       } else if (biaoji[i + 2] > 0) { n         sum1++; n         i += 2; n       } else { n         sum1++; n         i += 2; n       } n     } n   } n   for (i = 0; i <= maxl + 1; i++) { n     if (i >= 1 && biaoji[i - 1] >= 1) { n       sum2++; n     } else if (biaoji[i] == 0) { n       if (biaoji[i + 1] >= 1) { n         biaoji[i + 1]--; n         sum2++; n       } n     } else if (biaoji[i] >= 1) { n       biaoji[i]--; n       sum2++; n     } n   } n   printf( %lld %lld n , sum1, sum2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   long long val, sum = 0, minOdd = 1000000001; n   for (int i = 0; i < n; i++) { n     scanf( %lld , &val); n     if (val & 1) minOdd = min(minOdd, val); n     sum += val; n   } n   printf( %lld n , (sum & 1) ? sum - minOdd : sum); n   return 0; n } n


#include <bits/stdc++.h> n namespace pb_ds { n namespace io { n const int MaxBuff = 1 << 15; n const int Output = 1 << 23; n char B[MaxBuff], *S = B, *T = B; n char Out[Output], *iter = Out; n inline void flush() { n   fwrite(Out, 1, iter - Out, stdout); n   iter = Out; n } n }  // namespace io n template <class Type> n inline Type Read() { n   using namespace io; n   register char ch; n   register Type ans = 0; n   register bool neg = 0; n   while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T) n                    ? 0 n                    : *S++), n          (ch <  0  || ch >  9 ) && ch !=  - ) n     ; n   ch ==  -  ? neg = 1 : ans = ch -  0 ; n   while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T) n                    ? 0 n                    : *S++), n           0  <= ch && ch <=  9 ) n     ans = ans * 10 + ch -  0 ; n   return neg ? -ans : ans; n } n template <class Type> n inline void Print(register Type x, register char ch =   n ) { n   using namespace io; n   if (!x) n     *iter++ =  0 ; n   else { n     if (x < 0) *iter++ =  - , x = -x; n     static int s[100]; n     register int t = 0; n     while (x) s[++t] = x % 10, x /= 10; n     while (t) *iter++ =  0  + s[t--]; n   } n   *iter++ = ch; n } n }  // namespace pb_ds n using namespace pb_ds; n using namespace std; n const int N = 55; n const int inf = 2e9; n struct edge { n   int next, to; n } a[N << 1]; n int head[N], cnt; n inline void add(int u, int v) { n   a[++cnt].to = v; n   a[cnt].next = head[u]; n   head[u] = cnt; n } n int n, m, st, now, ans = inf; n int w[N][N], c[N], deg[N]; n int dp[N][N][N][N], f[2][N]; n void dfs(int x, int fa) { n   for (int i = head[x]; i; i = a[i].next) { n     int y = a[i].to; n     if (y == fa) continue; n     dfs(y, x), c[x] += c[y]; n   } n } n int solve(int u, int v, int s1, int s2) { n   if (!s1) return s2 ? inf : 0; n   if (~dp[u][v][s1][s2]) return dp[u][v][s1][s2]; n   if (deg[v] == 1) return dp[u][v][s1][s2] = (solve(v, u, s2, 0) + w[u][v]); n   for (int i = head[v]; i; i = a[i].next) { n     int y = a[i].to; n     if (y == u) continue; n     for (int j = 0; j <= s1; ++j) solve(v, y, j, s1 + s2 - j); n   } n   memset(f[0], 0, sizeof(f[0])), f[now = 0][0] = inf; n   for (int i = head[v]; i; i = a[i].next) { n     int y = a[i].to; n     if (y == u) continue; n     now ^= 1; n     memset(f[now], 0, sizeof(f[now])); n     for (int j = 0; j <= s1; ++j) { n       for (int k = 0; j + k <= s1; ++k) { n         f[now][j + k] = n             max(f[now][j + k], min(f[now ^ 1][j], solve(v, y, k, s1 + s2 - k))); n       } n     } n   } n   return (dp[u][v][s1][s2] = (f[now][s1] + w[u][v])); n } n int main() { n   n = Read<int>(); n   for (int i = 1; i < n; ++i) { n     int u = Read<int>(), v = Read<int>(); n     w[u][v] = w[v][u] = Read<int>(); n     add(u, v), add(v, u); n     ++deg[u], ++deg[v]; n   } n   st = Read<int>(), m = Read<int>(); n   for (int i = 1; i <= m; ++i) ++c[Read<int>()]; n   dfs(st, 0), memset(dp, -1, sizeof(dp)); n   for (int i = head[st]; i; i = a[i].next) n     ans = min(ans, solve(st, a[i].to, c[a[i].to], m - c[a[i].to])); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const double pi = std::acos(-1); n using namespace std; n const long long int mod = 1000000000 + 7; n long long int power(long long int x, long long int y, long long int md) { n   long long int res = 1; n   x = x % md; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % md; n     y = y >> 1; n     x = (x * x) % md; n   } n   return res; n } n long long int m_mul(long long int a, long long int b) { n   a = a % mod; n   b = b % mod; n   return (a * b + mod) % mod; n } n long long int m_add(long long int a, long long int b) { n   a = a % mod; n   b = b % mod; n   return (a + b + mod) % mod; n } n int main() { n   long long int tc; n   cin >> tc; n   while (tc--) { n     long long int n, x; n     cin >> n >> x; n     long long int arr[n]; n     for (long long int i = 0; i < n; i++) cin >> arr[i]; n     sort(arr, arr + n, greater<long long int>()); n     long long int a1 = 1; n     long long int k = 0; n     for (long long int i = 0; i < n; i++) { n       if (arr[i] * a1 >= x) { n         a1 = 1; n         k++; n       } else { n         a1++; n       } n     } n     cout << k <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int a, long long int b) { n   long long int result = 1; n   while (b > 0) { n     int lastbit = (b & 1); n     if (lastbit) { n       result = (result * a); n     } n     a = (a * a); n     b = b >> 1; n   } n   return result; n } n long long int power2(long long int a, long long int b, long long int p) { n   long long int result = 1; n   while (b > 0) { n     int lastbit = (b & 1); n     if (lastbit) { n       result = (result * a) % p; n     } n     a = (a * a) % p; n     b = b >> 1; n   } n   return result % p; n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n vector<int> SieveOfEratosthenes(int n) { n   bool prime[n + 1]; n   memset(prime, true, sizeof(prime)); n   for (int p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (int i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   vector<int> v; n   v.push_back(0); n   for (int p = 2; p <= n; p++) n     if (prime[p]) v.push_back(p); n   return v; n } n void InverseofNumber(long long int p) { n   long long int n[1000001]; n   n[0] = n[1] = 1; n   for (int i = 2; i <= 1000000; i++) n[i] = n[p % i] * (p - p / i) % p; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int xxx; n   cin >> xxx; n   for (int tt = 1; tt <= xxx; tt++) { n     long long int n; n     cin >> n; n     long long int t = ceil(sqrt(n)); n     long long int x = n / t; n     if (n % t == 0) { n       x--; n     } n     cout << t + x - 1; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string s, t; n   cin >> n; n   vector<vector<int> > DP(26, vector<int>(26, -10000000)); n   for (int i = 0; i < n; i++) { n     t = s; n     cin >> s; n     if (i > 0) n       DP[t[0] -  a ][t[t.length() - 1] -  a ] = n           max(DP[t[0] -  a ][t[t.length() - 1] -  a ], (int)t.length()); n     for (int j = 0; j < 26; j++) n       DP[j][s[s.length() - 1] -  a ] = max(DP[j][s[s.length() - 1] -  a ], n                                            DP[j][s[0] -  a ] + (int)s.length()); n   } n   t = s; n   DP[t[0] -  a ][t[t.length() - 1] -  a ] = n       max(DP[t[0] -  a ][t[t.length() - 1] -  a ], (int)t.length()); n   int Ans = 0; n   for (int i = 0; i < 26; i++) Ans = max(Ans, DP[i][i]); n   cout << Ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long int w, x[200005]; n int main() { n   cin >> n >> w; n   for (int i = 0; i < n * 2; i++) cin >> x[i]; n   sort(x, x + n * 2); n   double mid; n   mid = min((double)x[n] / 2, (double)x[0]); n   mid = (mid + mid * 2) * n; n   mid = min(mid, (double)w); n   printf( %.6f n , mid); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, t, f, k, y = 0, w, j = 0, x = 0; n   cin >> a >> t >> f >> k; n   w = t; n   for (;;) { n     if (x == 0) { n       if (j % 2 == 1) j++; n       if (j == k) break; n       if (w >= f) { n         x = f; n         w -= f; n       } else { n         cout << -1; n         return 0; n       } n     } else if (x == f) { n       if (j % 2 == 0) { n         if (w >= (a - f) * 2) { n           x = a; n           w -= (a - f); n         } else if (w >= a - f) { n           if (j == k - 1) { n             x = a; n             w -= (a - f); n           } else { n             w = t; n             x = a; n             w -= (a - f); n             y++; n           } n         } else { n           if (t >= a - f) { n             w = t; n             x = a; n             w -= (a - f); n             y++; n           } else { n             cout << -1; n             return 0; n           } n         } n       } else { n         if (w >= f * 2) { n           x = 0; n           w -= f; n         } else if (w >= f) { n           if (j == k - 1) { n             x = 0; n             w -= f; n           } else { n             w = t; n             x = 0; n             w -= f; n             y++; n           } n         } else { n           if (t >= f) { n             w = t; n             x = 0; n             w -= f; n             y++; n           } else { n             cout << -1; n             return 0; n           } n         } n       } n     } else if (x == a) { n       if (j % 2 == 0) j++; n       if (j == k) break; n       if (w >= a - f) { n         x = f; n         w -= (a - f); n       } else { n         cout << -1; n         return 0; n       } n     } n     if (j == k) break; n   } n   cout << y; n } n


#include <bits/stdc++.h> n using namespace std; n void cp() { n   ios ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n int main() { n   cp(); n   { n     string s, t; n     cin >> s >> t; n     if (s.length() == t.length() + 1) { n       long long m = 0; n       long long in = -1; n       char f; n       long long j = 0; n       for (long long i = 0; i < s.length(); i += 1) { n         if (s[i] != t[j]) { n           f = s.at(i); n           in = i; n           m++; n           j--; n         } n         j++; n       } n       vector<long long> ans; n       if (m == 1) { n         while (in > -1) { n           if (s[in] == f) { n             in--; n           } else { n             break; n           } n         } n         in++; n         while (in < s.length()) { n           if (s[in] == f) { n             ans.push_back(in + 1); n             in++; n           } else { n             break; n           } n         } n         cout << ans.size(); n         cout << endl; n         ; n         for (long long i = 0; i < ans.size(); i += 1) cout << ans[i] <<    ; n       } else { n         cout <<  0 n ; n       } n     } else { n       cout <<  0 n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 100 * 1000 + 7; n int a[MX]; n int hup[MX], hdown[MX]; n long long cup[MX], cdown[MX]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i <= n; i++) { n     int cost = 0; n     if (a[i] <= hup[i - 1]) cost = (hup[i - 1] + 1 - a[i]); n     hup[i] = a[i] + cost; n     cup[i] = cup[i - 1] + cost; n   } n   for (int i = n; i >= 1; i--) { n     int cost = 0; n     if (a[i] <= hdown[i + 1]) cost = (hdown[i + 1] + 1 - a[i]); n     hdown[i] = a[i] + cost; n     cdown[i] = cdown[i + 1] + cost; n   } n   long long res = (long long)1e18; n   for (int i = 1; i <= n; i++) { n     int need = max(hup[i - 1] + 1, hdown[i + 1] + 1); n     int cost = 0; n     if (a[i] < need) cost = need - a[i]; n     res = min(res, cup[i - 1] + cdown[i + 1] + cost); n   } n   printf( %lld n , res); n } n


#include <bits/stdc++.h> n using namespace std; n struct ww { n   long long x, y; n } c[400][400]; n int i, j, k, n, m, ma, ren, C, kuai; n int cov[400], zhi[400]; n long long b[400][400], s[400][400]; n vector<int> a[100010]; n inline void gao(int x) { n   int i, n = kuai - 1, g[400], r = 0; n   long long jum[400]; n   for (i = 0; i <= n; i++) b[x][i] += cov[x]; n   cov[x] = 0; n   s[x][0] = b[x][0]; n   for (i = 1; i <= n; i++) s[x][i] = s[x][i - 1] + b[x][i]; n   for (i = 0; i <= n; i++) { n     long long A = s[x][i], F = 0; n     for (; r; r--) { n       int wei = g[r]; n       long long B = s[x][wei]; n       int cha = i - wei; n       if (A >= B) continue; n       long long ci = (B - A) / cha + ((B - A) % cha > 0); n       if (jum[r] >= ci) n         continue; n       else { n         F = ci; n         break; n       } n     } n     g[++r] = i, jum[r] = F; n   } n   jum[r + 1] = 100010; n   for (i = 1; i <= r; i++) c[x][i] = (ww){g[i], jum[i + 1]}; n   zhi[x] = 1; n } n inline void jian(int x) { n   int A = x / kuai, B = x % kuai; n   b[A][B] -= x; n   gao(A); n } n inline void jia(int x) { n   if (x < 0) return; n   int A = x / kuai, B = x % kuai, i; n   for (i = 0; i <= A - 1; i++) { n     cov[i]++; n     if (c[i][zhi[i]].y == cov[i]) zhi[i]++; n   } n   for (i = 0; i <= B; i++) b[A][i]++; n   gao(A); n } n inline long long suan(int x) { n   ww A = c[x][zhi[x]]; n   return s[x][A.x] + 1ll * cov[x] * (A.x + 1); n } n inline ww cal() { n   int i, id; n   long long ma, sum; n   ma = -1, sum = 0; n   for (i = 0; i <= 400 - 1; i++) { n     long long re = sum + suan(i); n     if (re > ma) ma = re, id = i * kuai + c[i][zhi[i]].x; n     sum += s[i][kuai - 1] + 1ll * cov[i] * kuai; n   } n   return (ww){ma, id}; n } n int main() { n   kuai = 300; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     a[y].push_back(x - 1); n     ma = max(ma, y); n   } n   for (i = 0; i <= 400 - 1; i++) gao(i); n   ren = n; n   for (C = 0; C <= ma + 1; C++) { n     ww re = cal(); n     printf( %I64d %I64d n , 1ll * ren * C * m + re.x, re.y + 1); n     for (j = 0; j < a[C].size(); j++) { n       int A = a[C][j]; n       ren--; n       jia(A); n       jian(A + 1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, x, y, arr1[2] = {0, 0}, arr2[2] = {0, 0}; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> t >> x >> y; n     if (t == 1) { n       arr1[0] += x; n       arr1[1] += y; n     } n     if (t == 2) { n       arr2[0] += x; n       arr2[1] += y; n     } n   } n   if (arr1[0] >= arr1[1]) { n     cout <<  LIVE  << endl; n   } n   if (arr1[0] < arr1[1]) { n     cout <<  DEAD  << endl; n   } n   if (arr2[0] >= arr2[1]) { n     cout <<  LIVE  << endl; n   } n   if (arr2[0] < arr2[1]) { n     cout <<  DEAD  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v; n bitset<101> usado; n long long dfs(long long nodo) { n   if (usado[nodo]) return 0; n   usado.set(nodo); n   return 1 + dfs(v[nodo]); n } n long long calcmcd(long long a, long long b) { n   if (a % b == 0) return b; n   return calcmcd(b, a % b); n } n int main() { n   ios::sync_with_stdio(false); n   bool puede = true; n   long long n, aux, resp, mcd, mcm; n   vector<long long> pararesp; n   cin >> n; n   v.resize(n + 1); n   for (long long i = 1; i <= n; i++) { n     cin >> v[i]; n     if (usado[v[i]]) n       puede = false; n     else n       usado.set(v[i]); n   } n   if (puede) { n     usado.reset(); n     for (long long i = 1; i <= n; i++) { n       while (i <= n && (usado[i] || v[i] == i)) i++; n       if (i <= n) { n         aux = dfs(i); n         if (aux % 2 == 0) aux /= 2; n         pararesp.push_back(aux); n       } n     } n     if (pararesp.empty()) n       resp = 1; n     else { n       if (pararesp.size() == 1) n         resp = pararesp[0]; n       else { n         mcm = pararesp[pararesp.size() - 1]; n         for (int i = pararesp.size() - 2; i >= 0; i--) { n           if (pararesp[i] > mcm) n             mcd = calcmcd(pararesp[i], mcm); n           else n             mcd = calcmcd(mcm, pararesp[i]); n           mcm = mcm * pararesp[i] / mcd; n         } n         resp = mcm; n         pararesp.clear(); n       } n     } n     cout << resp <<   n ; n   } else n     cout <<  -1 n ; n   v.clear(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( Ofast,no-stack-protector ) n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   n ; n   err(++it, args...); n } n function<void(void)> ____ = []() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n }; n template <typename T> n vector<T> &operator<<(vector<T> &__container, T x) { n   __container.push_back(x); n   return __container; n } n template <typename T> n ostream &operator<<(ostream &out, vector<T> &__container) { n   for (T _ : __container) out << _ <<    ; n   return out; n } n void sci() {} n template <typename... Args> n void sci(int &x, Args &...args) { n   scanf( %d , &x); n   sci(args...); n } n void scl() {} n template <typename... Args> n void scl(long long int &x, Args &...args) { n   scanf( %lld , &x); n   scl(args...); n } n const int MAXN = 1e6 + 7; n int n, m; n struct SegmentTree { n   int w[MAXN << 2], l[MAXN << 2], r[MAXN << 2]; n   void build(int L, int R, int rt = 1) { n     l[rt] = L; n     r[rt] = R; n     w[rt] = 0; n     if (L + 1 == R) return; n     int mid = (L + R) >> 1; n     build(L, mid, rt << 1); n     build(mid, R, rt << 1 | 1); n   } n   void down(int rt) { n     if (w[rt]) w[rt << 1] = w[rt << 1 | 1] = w[rt], w[rt] = 0; n   } n   void modify(int L, int R, int x, int rt = 1) { n     if (L >= r[rt] or l[rt] >= R) return; n     if (L <= l[rt] and r[rt] <= R) { n       w[rt] = x; n       return; n     } n     down(x); n     modify(L, R, x, rt << 1); n     modify(L, R, x, rt << 1 | 1); n   } n   int query(int pos, int rt = 1) { n     if (l[rt] + 1 == r[rt]) return w[rt]; n     down(rt); n     int mid = (l[rt] + r[rt]) >> 1; n     if (pos < mid) n       return query(pos, rt << 1); n     else n       return query(pos, rt << 1 | 1); n   } n } seg; n struct FenwickTree { n   long long int sum[MAXN]; n   void modify(int pos, int x) { n     while (pos < MAXN) sum[pos] += x, pos += (pos & (-pos)); n   } n   long long int qsum(int pos) { n     long long int ret = 0; n     while (pos) ret += sum[pos], pos -= (pos & (-pos)); n     return ret; n   } n } bit; n struct Query { n   char op; n   int x, y, id, qid; n } Q[MAXN]; n struct Disjoint_Set_Union { n   int fa[MAXN]; n   Disjoint_Set_Union() { n     for (int i = 0; i < MAXN; i++) fa[i] = i; n   } n   int findx(int x) { return x == fa[x] ? x : fa[x] = findx(fa[x]); } n   void merge(int x, int y) { n     if (findx(x) != findx(y)) fa[findx(x)] = findx(y); n   } n } dsu[2]; n struct Graph { n   vector<int> g[MAXN]; n   int tot, dfn[MAXN], idx, sz[MAXN], ed[MAXN]; n   Graph() { tot = idx = 0; } n   void dfs(int u) { n     dfn[u] = ++idx; n     sz[u] = u <= n ? 1 : 0; n     for (int v : g[u]) dfs(v), sz[u] += sz[v]; n     ed[u] = idx; n   } n } G[2]; n long long int ret[MAXN]; n void solve() { n   static char buf[233]; n   sci(n, m); n   G[0].tot = G[1].tot = n; n   for (int i = 1; i <= m; i++) { n     scanf( %s , buf); n     Q[i].id = i; n     Q[i].op = buf[0]; n     if (buf[0] ==  U ) { n       sci(Q[i].x, Q[i].y); n       G[1].tot++; n       G[1].g[G[1].tot] << dsu[1].findx(Q[i].x) << dsu[1].findx(Q[i].y); n       dsu[1].merge(Q[i].x, G[1].tot); n       dsu[1].merge(Q[i].y, G[1].tot); n     } else if (buf[0] ==  M ) { n       sci(Q[i].x, Q[i].y); n       G[0].tot++; n       G[0].g[G[0].tot] << dsu[0].findx(Q[i].x) << dsu[0].findx(Q[i].y); n       dsu[0].merge(Q[i].x, G[0].tot); n       dsu[0].merge(Q[i].y, G[0].tot); n     } else if (buf[0] ==  A ) n       sci(Q[i].x), Q[i].x = dsu[1].findx(Q[i].x); n     else if (buf[0] ==  Z ) n       sci(Q[i].x), Q[i].x = dsu[0].findx(Q[i].x); n     else if (buf[0] ==  Q ) n       sci(Q[i].x); n   } n   G[0].tot++; n   for (int i = 1; i < G[0].tot; i++) n     if (dsu[0].findx(i) == i) G[0].g[G[0].tot] << i; n   G[0].dfs(G[0].tot); n   G[1].tot++; n   for (int i = 1; i < G[1].tot; i++) n     if (dsu[1].findx(i) == i) G[1].g[G[1].tot] << i; n   G[1].dfs(G[1].tot); n   vector<Query> vec; n   seg.build(1, MAXN); n   int queryid = 0; n   for (int i = 1; i <= m; i++) { n     if (Q[i].op ==  A ) n       vec << Q[i]; n     else if (Q[i].op ==  Z ) { n       int st = G[0].dfn[Q[i].x], ed = G[0].ed[Q[i].x]; n       seg.modify(st, ed + 1, i); n     } else if (Q[i].op ==  Q ) { n       Q[i].y = 1; n       Q[i].qid = ++queryid; n       vec << Q[i]; n       int p = seg.query(G[0].dfn[Q[i].x]); n       if (p != 0) { n         Q[i].y = -1; n         Q[i].id = p; n         vec << Q[i]; n       } n     } n   } n   sort(vec.begin(), vec.end(), n        [&](const Query &A, const Query &B) { return A.id < B.id; }); n   for (Query &qs : vec) { n     if (qs.op ==  A ) { n       int sz = G[1].sz[qs.x], st = G[1].dfn[qs.x], ed = G[1].ed[qs.x]; n       bit.modify(st, sz); n       bit.modify(ed + 1, -sz); n     } else if (qs.op ==  Q ) n       ret[qs.qid] += qs.y * bit.qsum(G[1].dfn[qs.x]); n   } n   for (int i = 1; i <= queryid; i++) cout << ret[i] <<   n ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using std::vector; n const long double EPS = 1e-10; n int n; n int x[5], y[5], r[5]; n inline int sqr(int x) { return x * x; } n namespace solver2 { n bool get(int a, int b) { n   int dist2 = sqr(x[a] - x[b]) + sqr(y[a] - y[b]); n   return dist2 < sqr(r[a] + r[b]) && dist2 > sqr(r[a] - r[b]); n } n bool in(int x0, int y0, int a) { n   return (sqr(x0 - x[a]) + sqr(y0 - y[a])) < sqr(r[a]); n } n bool sta[10]; n void main() { n   int p = 240; n   for (int i = 1; i <= n; i++) x[i] *= p, y[i] *= p, r[i] *= p; n   for (int i = 1, x = -20 * p; i <= p * 40; i++, x++) { n     for (int j = 1, y = -20 * p; j <= p * 40; j++, y++) { n       int tmp = 0; n       for (int k = 1; k <= n; k++) { n         tmp += in(x, y, k) << (k - 1); n       } n       sta[tmp] = 1; n     } n   } n   int ans = 1; n   for (int i = 1; i < (1 << n); i++) ans += sta[i]; n   printf( %d n , ans); n } n }  // namespace solver2 n namespace geometry { n inline long double sqr(long double x) { return x * x; } n inline int sgn(long double x) { return x < -EPS ? -1 : x > EPS; } n struct Vector { n   long double x, y; n   Vector(long double x = 0, long double y = 0) : x(x), y(y) {} n   long double len() { return sqrt(sqr(x) + sqr(y)); } n   long double norm() { return sqr(x) + sqr(y); } n   Vector unit() { return *this / len(); } n   long double angle() { return atan2(y, x); } n   bool operator==(const Vector &rhs) const { n     return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0; n   } n   bool operator<(const Vector &rhs) const { n     return sgn(x - rhs.x) < 0 || (sgn(x - rhs.x) == 0 && sgn(y - rhs.y) < 0); n   } n   Vector operator+(const Vector &__rhs) const { n     return Vector(x + __rhs.x, y + __rhs.y); n   } n   Vector operator-(const Vector &__rhs) const { n     return Vector(x - __rhs.x, y - __rhs.y); n   } n   Vector operator*(const long double __rhs) const { n     return Vector(x * __rhs, y * __rhs); n   } n   Vector operator/(const long double __rhs) const { n     return Vector(x / __rhs, y / __rhs); n   } n }; n long double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } n long double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } n Vector rotate(Vector a, Vector b) { n   b = b.unit(); n   return Vector(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); n } n struct Line { n   Vector u; n   Vector v; n   Line() {} n   Line(Vector a, Vector b) : u(a), v((b - a).unit()) {} n }; n struct Circle { n   Vector o; n   long double r; n   Circle() {} n   Circle(Vector o, long double r) : o(o), r(r) {} n }; n Vector mid_point(Vector a, Vector b) { n   return Vector((a.x + b.x) / 2, (a.y + b.y) / 2); n } n Line divide_angle(Vector u, Vector v1, Vector v2) { n   return Line(u, v1.unit() + v2.unit()); n } n long double distance_to_line(Vector u, Line l) { n   return fabs(cross(u - l.u, l.v)) / l.v.len(); n } n Vector perpendicular_foot(Vector u, Line l) { n   return l.u + l.v * dot(l.v, u - l.u); n } n Line move(Line l, long double d) { n   return Line(l.u + rotate(l.v, Vector(0, 1)).unit() * d, l.v); n } n Vector intersection(Line l1, Line l2) { n   return l1.u + l1.v * (cross(l2.v, l1.u - l2.u) / cross(l1.v, l2.v)); n } n vector<Vector> intersection(Circle c1, Circle c2) { n   if (sgn(c1.r - c2.r) < 0) std::swap(c1, c2); n   long double d = (c1.o - c2.o).len(); n   if (sgn(c1.r + c2.r - d) < 0 || sgn(fabs(c1.r - c2.r) - d) > 0) { n     return {}; n   } else if (sgn(c1.r + c2.r - d) == 0 || sgn(fabs(c1.r - c2.r) - d) == 0) { n     return {c1.o + (c2.o - c1.o).unit() * c1.r}; n   } else { n     long double cos_alpha = (sqr(d) + sqr(c1.r) - sqr(c2.r)) / (2 * d * c1.r); n     long double sin_alpha = sqrt(1 - sqr(cos_alpha)); n     Vector delta1 = rotate(c2.o - c1.o, Vector(cos_alpha, sin_alpha)), n            delta2 = rotate(c2.o - c1.o, Vector(cos_alpha, -sin_alpha)); n     return {c1.o + delta1.unit() * c1.r, c1.o + delta2.unit() * c1.r}; n   } n } n vector<Vector> intersection(Line l, Circle c) { n   long double d = distance_to_line(c.o, l); n   if (sgn(d - c.r) > 0) { n     return {}; n   } else if (sgn(d - c.r) == 0) { n     return {perpendicular_foot(c.o, l)}; n   } else { n     Vector p = perpendicular_foot(c.o, l); n     long double delta = sqrt(sqr(c.r) - sqr(d)); n     return {p + l.v * delta, p - l.v * delta}; n   } n } n }  // namespace geometry n using namespace geometry; n namespace solver1 { n bool get(int a, int b) { n   int dist2 = sqr(x[a] - x[b]) + sqr(y[a] - y[b]); n   return dist2 < sqr(r[a] + r[b]) && dist2 > sqr(r[a] - r[b]); n } n bool in(int x0, int y0, int a) { n   return (sqr(x0 - x[a]) + sqr(y0 - y[a])) < sqr(r[a]); n } n bool sta[10]; n void main() { n   if (n == 1) { n     puts( 2 ); n     return; n   } else if (n == 2) { n     if (get(1, 2)) { n       puts( 4 ); n     } else n       puts( 3 ); n     return; n   } else { n     Circle c[5]; n     for (int i = 1; i <= n; i++) c[i] = Circle(Vector(x[i], y[i]), r[i]); n     vector<Vector> i12 = intersection(c[1], c[2]), n                    i13 = intersection(c[1], c[3]), n                    i23 = intersection(c[2], c[3]); n     vector<Vector> p; n     for (auto i : i12) p.push_back(i); n     for (auto i : i13) p.push_back(i); n     for (auto i : i23) p.push_back(i); n     std::sort(p.begin(), p.end()); n     p.erase(std::unique(p.begin(), p.end()), p.end()); n     int cnt[5]; n     memset(cnt, 0, sizeof cnt); n     for (auto i : p) { n       for (int j = 1; j <= 3; j++) { n         if (sgn((i - c[j].o).len() - r[j]) == 0) cnt[j]++; n       } n     } n     int tot = 0; n     for (int i = 1; i <= 3; i++) tot += cnt[i] ? cnt[i] : 1; n     printf( %d , tot + 2 - std::max((int)p.size(), 1)); n   } n } n }  // namespace solver1 n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d%d%d , &x[i], &y[i], &r[i]); n   solver1::main(); n } n


#include <bits/stdc++.h> n using namespace std; n void fun() {} n long long mod = 1000000000 + 7; n long long powe(long long x, long long y) { n   x = x % mod, y = y % (mod - 1); n   long long ans = 1; n   while (y > 0) { n     if (y & 1) { n       ans = (1ll * x * ans) % mod; n     } n     y >>= 1; n     x = (1ll * x * x) % mod; n   } n   return ans; n } n map<pair<long long, long long>, long long> m; n long long ncr(long long n, long long r) { return n * (n - 1) * (n - 2) / 6; } n int32_t main() { n   fun(); n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t, temp; n   long long n, s, k; n   cin >> t; n   while (t--) { n     cin >> n >> s >> k; n     long long a[k]; n     long long i; n     long long num; n     for (i = 0; i < k; i++) { n       cin >> num; n       a[i] = num; n     } n     sort(a, a + k); n     long long num1 = INT_MAX, num2 = INT_MAX; n     for (i = s; i >= 1; i--) { n       if (!binary_search(a, a + k, i)) { n         num1 = i; n         break; n       } n     } n     for (i = s; i <= n; i++) { n       if (!binary_search(a, a + k, i)) { n         num2 = i; n         break; n       } n     } n     if (num1 == INT_MAX) n       cout << num2 - s <<   n ; n     else if (num2 == INT_MAX) n       cout << s - num1 <<   n ; n     else n       cout << min(s - num1, num2 - s) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n double x[100010], y[100010], X, Y, mem[100010]; n int id[100010], len; n int cmp(int i, int j) { n   if (fabs(x[i] - x[j]) > 1e-8) return x[i] < x[j]; n   return y[i] > y[j]; n } n int main() { n   int n, i, j, k, A, B, C, D; n   scanf( %d %d/%d %d/%d , &n, &A, &B, &C, &D); n   for (i = 0; i < n; i++) { n     scanf( %lf %lf , &X, &Y); n     x[i] = X; n     y[i] = Y; n     if (C && D) x[i] -= Y / C * D; n     if (A && B) y[i] -= X / B * A; n     id[i] = i; n   } n   sort(id, id + n, cmp); n   len = 0; n   for (i = 0; i < n; i++) n     if (x[id[i]] > 0 && y[id[i]] > 0) { n       k = lower_bound(mem, mem + len, y[id[i]] - 1e-8) - mem; n       if (k == len) len++; n       mem[k] = y[id[i]]; n     } n   printf( %d n , len); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; 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 const long long L = 1e5 + 5; n long long arr[L]; n long long bo[L]; n long long gi[L]; n long long bg[L]; n priority_queue<long long> val; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long i, b, g; n   cin >> b >> g; n   long long ans = 0; n   long long x = -1e18, y = 1e18; n   for (i = 0; i < b; i++) { n     bg[i] = 1; n     cin >> bo[i]; n     arr[i] = g - 1; n     ans += bo[i]; n     x = max(bo[i], x); n   } n   for (i = 0; i < g; i++) { n     cin >> gi[i]; n     ans += gi[i]; n     val.push(gi[i]); n     y = min(gi[i], y); n   } n   if (y < x) { n     cout << -1 << endl; n     return 0; n   } n   sort(bo, bo + b); n   i = b - 1; n   while (!val.empty() && i >= 0) { n     if (val.top() >= bo[i]) { n       if (arr[i] == 0) { n         if (bo[i] == val.top()) { n           ans -= bo[i]; n           val.pop(); n         } n         i--; n         continue; n       } n       arr[i]--; n       val.pop(); n     } else n       i--; n   } n   for (i = 0; i < b; i++) ans += arr[i] * bo[i]; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 111; n int a[maxn]; n int getid[maxn]; n int b[maxn]; n int lpos[maxn]; n vector<int> savepos[maxn]; n vector<int> G[maxn]; n vector<int> v; n int n, m, q; n int vis[maxn]; n void dfs(int pos, int fa) { n   v.push_back(pos); n   vis[pos] = 1; n   if (v.size() >= n) { n     int id = v.size() - n; n     lpos[pos] = v[id]; n   } n   for (int d : G[pos]) { n     if (d == fa) continue; n     dfs(d, pos); n   } n   v.pop_back(); n } n int main() { n   cin >> n >> m >> q; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     getid[a[i]] = i; n   } n   for (int i = 1; i <= m; i++) { n     scanf( %d , &b[i]); n     savepos[b[i]].push_back(i); n   } n   for (int i = 1; i <= m; i++) { n     int nowval = b[i]; n     int preid = getid[nowval] - 1; n     if (!preid) preid = n; n     int preval = a[preid]; n     int id = lower_bound(savepos[preval].begin(), savepos[preval].end(), i) - n              savepos[preval].begin() - 1; n     if (id >= 0) { n       G[savepos[preval][id]].push_back(i); n     } n     savepos[nowval].push_back(i); n   } n   for (int i = 1; i <= m; i++) { n     if (!vis[i]) { n       v.clear(); n       dfs(i, -1); n     } n   } n   int p = 0; n   for (int i = 1; i <= m; i++) { n     lpos[i] = max(lpos[i - 1], lpos[i]); n   } n   while (q--) { n     int l, r; n     scanf( %d %d , &l, &r); n     if (l <= lpos[r]) { n       cout << 1; n     } else { n       cout << 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int flag[100005]; n int ok, a[100005], b[100005], vis[100005]; n vector<int> G[100005]; n void Sech(int u, int p) { n   int i, v; n   vis[u] = 1; n   if (flag[u] == 1) ok = -1; n   flag[u] = -1; n   for (i = 0; i < G[u].size(); i++) { n     v = G[u][i]; n     if (v == p || vis[v]) continue; n     Sech(v, u); n   } n } n int main(void) { n   ok = 1; n   int n, m, i, j, len2, len1, ans; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     if (i == 1) { n       scanf( %d , &len2); n       for (j = 1; j <= len2; j++) scanf( %d , &b[j]); n       continue; n     } n     for (j = 1; j <= len2; j++) a[j] = b[j]; n     len1 = len2; n     scanf( %d , &len2); n     for (j = 1; j <= len2; j++) scanf( %d , &b[j]); n     for (j = 1; j <= min(len1, len2); j++) { n       if (a[j] < b[j]) { n         G[b[j]].push_back(a[j]); n         break; n       } else if (a[j] > b[j]) { n         if (flag[a[j]] == 1 || flag[b[j]] == -1) ok = -1; n         flag[a[j]] = -1, flag[b[j]] = 1; n         break; n       } n     } n     if (len1 > len2 && j == len2 + 1) { n       printf( No n ); n       return 0; n     } n   } n   if (ok == -1) { n     printf( No n ); n     return 0; n   } n   for (i = 1; i <= m; i++) { n     if (vis[i] == 0 && flag[i] == -1) Sech(i, -1); n     if (ok == -1) break; n   } n   if (ok == -1) { n     printf( No n ); n     return 0; n   } n   printf( Yes n ); n   ans = 0; n   for (i = 1; i <= m; i++) { n     if (flag[i] == -1) ans++; n   } n   printf( %d n , ans); n   for (i = 1; i <= m; i++) { n     if (flag[i] == -1) printf( %d  , i); n   } n   if (ans != 0) printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int toint(char a) { return (a -  0 ); } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tst; n   cin >> tst; n   while (tst--) { n     string a, s; n     cin >> a >> s; n     long long int num = stoll(a); n     long long int sum = stoll(s); n     if (s.length() < a.length()) { n       cout <<  -1 n ; n     } else if (a.length() == s.length()) { n       bool no = false; n       for (int i = s.length() - 1; i >= 0; i--) { n         if ((toint(s[i]) - toint(a[i])) < 0) { n           cout <<  -1 n ; n           no = true; n           break; n         } n       } n       if (!no) { n         cout << stoll(s) - stoll(a) <<   n ; n       } n     } else if (a.length() < s.length()) { n       int lastdigit; n       int lastsub; n       string ans; n       bool no = 0; n       int strlen = s.length(); n       while (strlen > 0) { n         lastsub = num % 10; n         if (sum % 10 - num % 10 < 0) { n           lastdigit = (sum % 10) + ((sum % 100) - (sum % 10)); n           sum /= 100; n           num /= 10; n           strlen -= 2; n         } else { n           lastdigit = sum % 10; n           sum /= 10; n           num /= 10; n           strlen--; n         } n         if (lastdigit - lastsub >= 0 && lastdigit - lastsub <= 9) { n           if (strlen != 0) { n             ans = to_string(lastdigit - lastsub) + ans; n           } else { n             if (lastdigit - lastsub != 0) { n               ans = to_string(lastdigit - lastsub) + ans; n             } n           } n         } else { n           cout <<  -1 n ; n           no = true; n           break; n         } n       } n       if (!no) { n         cout << ans <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100001], i, l, r, n, j, c44, c1, c4, c, x, ans, h, y, m, step[101], n     v, b[100500], d[100500]; n string s; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b + 1, b + n + 1); n   for (i = 1; i <= n; i++) { n     if (l <= b[i]) { n       c++; n       l += b[i]; n     } n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000030; n int num[MAXN]; n int a[MAXN], b[MAXN]; n int dex[MAXN]; n int res[MAXN]; n int bsch(int le, int ri, int key) { n   int l = le, r = ri; n   while (l <= r) { n     int m = (l + r) / 2; n     if (res[m] == key) n       return m; n     else if (res[m] > key) n       r = m - 1; n     else n       l = m + 1; n   } n   return l; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &b[i]); n     dex[b[i]] = i; n   } n   for (int i = 1; i <= n; i++) { n     num[i] = dex[a[i]]; n   } n   for (int i = 1; i <= n / 2; i++) { n     swap(num[i], num[n - i + 1]); n   } n   for (int i = 1; i <= n; i++) { n     res[i] = 1 << 30; n   } n   int maxv = 1; n   res[1] = num[1]; n   for (int i = 2; i <= n; i++) { n     int s = bsch(1, n, num[i]); n     res[s] = num[i]; n     if (maxv < s) maxv = s; n   } n   printf( %d n , maxv); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n int n, m, num[40][40], len = 0, stat[20], sv[20], ans = 0; n bool vis[10][10], vis2[10][10], usedr[10], have = false; n string s[40]; n vector<pair<int, int> > coo[400]; n vector<int> pr[20]; n bool stane = false; n bool check(int pos) { n   map<pair<int, int>, int> mp; n   mp.clear(); n   for (int i = 0; i < pr[pos].size(); ++i) { n     int x = stat[pos], y = stat[pr[pos][i]]; n     if (vis[x][y] || mp[make_pair(x, y)]) return false; n     mp[make_pair(x, y)] = mp[make_pair(y, x)] = true; n   } n   return true; n } n void add(int pos, bool val) { n   for (int i = 0; i < pr[pos].size(); ++i) { n     int x = stat[pos], y = stat[pr[pos][i]]; n     vis[x][y] = vis[y][x] = val; n   } n } n void dfs(int pos, int curc) { n   if (pos == 14) { n     ++ans; n     if (!have) { n       have = true; n       for (int i = 0; i < 14; ++i) sv[i] = stat[i]; n     } n     return; n   } n   if (curc < 7) { n     stat[pos] = curc; n     if (check(pos)) { n       add(pos, true); n       dfs(pos + 1, curc + 1); n       add(pos, false); n     } n   } n   for (int i = 0; i < curc; ++i) { n     if (usedr[i]) continue; n     stat[pos] = i; n     if (check(pos)) { n       usedr[i] = true; n       add(pos, true); n       dfs(pos + 1, curc); n       usedr[i] = false; n       add(pos, false); n     } n   } n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     cin >> s[i]; n     for (int j = 0; j < m; ++j) n       if (s[i][j] ==  A ) n         s[i][j] =  z  + 1; n       else if (s[i][j] ==  B ) n         s[i][j] =  z  + 2; n   } n   for (int i = 0; i < n + 5; ++i) n     for (int j = 0; j < m + 5; ++j) num[i][j] = -1; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) n       if ( a  <= s[i][j] && s[i][j] <=  z  + 2) { n         coo[s[i][j]].push_back(make_pair(i, j)); n         if (num[i][j] == -1) { n           for (int k = i; k < i + 2; ++k) n             for (int p = j; p < j + 2; ++p) num[k][p] = len; n           ++len; n         } n       } n   for (int i =  a ; i <=  z  + 2; ++i) { n     int x = coo[i][0].first, y = coo[i][0].second, xx = coo[i][1].first, n         yy = coo[i][1].second; n     pr[max(num[x][y], num[xx][yy])].push_back(min(num[x][y], num[xx][yy])); n   } n   dfs(0, 0); n   cout << ans * 5040 << endl; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (!( a  <= s[i][j] && s[i][j] <=  z  + 2)) n         cout <<  . ; n       else n         cout << sv[num[i][j]]; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int m, k; n   cin >> m >> k; n   if (m % 2 == 0) { n     printf( %d n , m + k * 2); n   } else { n     int t; n     for (int i = 3; i <= m; i += 2) { n       if (m % i == 0) { n         t = i; n         break; n       } n     } n     k--; n     m += t; n     printf( %d n , m + k * 2); n   } n } n int main() { n   int n; n   cin >> n; n   while (n--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m = 1e9 + 7; n double eps = 1e-6; n bool good[256]; n long long n, spos = -1; n int main(int argc, char *argv[]) { n   ios::sync_with_stdio(0); n   string g, pat; n   cin >> g; n   cin >> pat; n   cin >> n; n   for (int i = 0; (i) < (256); ++i) good[i] = false; n   for (int i = 0; (i) < (((int)(pat).size())); ++i) n     if (pat[i] ==  * ) spos = i; n   for (int i = 0; (i) < (((int)(g).size())); ++i) { n     good[int(g[i])] = true; n   } n   for (int i = 0; (i) < (n); ++i) { n     string s; n     bool pass = true; n     cin >> s; n     if (spos == -1) { n       if (((int)(pat).size()) != ((int)(s).size())) n         cout <<  NO  << endl; n       else { n         for (int j = 0; (j) < (((int)(pat).size())); ++j) { n           if (pat[j] !=  ?  && pat[j] != s[j]) n             pass = false; n           else if (pat[j] ==  ?  && !good[int(s[j])]) n             pass = false; n         } n         if (pass) n           cout <<  YES  << endl; n         else n           cout <<  NO  << endl; n       } n     } else { n       if (((int)(s).size()) - ((int)(pat).size()) < -1) n         cout <<  NO  << endl; n       else { n         long long offset = ((int)(s).size()) - ((int)(pat).size()); n         for (int j = 0; (j) < (spos); ++j) { n           if (pat[j] !=  ?  && pat[j] != s[j]) n             pass = false; n           else if (pat[j] ==  ?  && !good[int(s[j])]) n             pass = false; n         } n         for (long long j = spos + 1 + offset; j < ((int)(s).size()); j++) { n           if (pat[j - offset] !=  ?  && pat[j - offset] != s[j]) n             pass = false; n           else if (pat[j - offset] ==  ?  && !good[int(s[j])]) n             pass = false; n         } n         for (long long j = spos; j <= spos + offset; j++) n           if (good[int(s[j])]) pass = false; n         if (pass) n           cout <<  YES  << endl; n         else n           cout <<  NO  << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   vector<int> s(n, 0); n   s[n - 1] = a[n - 1]; n   for (int i = n - 2; i >= 0; i--) s[i] = max(a[i], s[i + 1]); n   for (int i = 0; i < n - 1; i++) cout << max(0, s[i + 1] - a[i] + 1) <<    ; n   cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pr { n   int a, b, n, x; n   pr(int a, int b, int n) : a(a), b(b), n(n) {} n   pr() : a(0), b(0), n(-1) {} n }; n int n, m; n vector<pr> a, b; n void connect(int x1, int& x2, int& y2) { n   if ((x2 != -1 && x2 != x1) || (y2 != -1 && y2 != x1)) { n     cout << -1; n     exit(0); n   } n   x2 = y2 = x1; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     a.push_back(pr(x, y, -1)); n   } n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     b.push_back(pr(x, y, -1)); n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i].a == b[j].a && a[i].b != b[j].b) n         connect(a[i].a, a[i].n, b[j].n); n       else if (a[i].b == b[j].b && a[i].a != b[j].a) n         connect(a[i].b, a[i].n, b[j].n); n       else if (a[i].a == b[j].b && a[i].b != b[j].a) n         connect(a[i].a, a[i].n, b[j].n); n       else if (a[i].b == b[j].a && a[i].a != b[j].b) n         connect(a[i].b, a[i].n, b[j].n); n     } n   } n   int ans = -1; n   for (int i = 0; i < n; i++) { n     if (a[i].n != -1) { n       if (ans == -1 || ans == a[i].n) n         ans = a[i].n; n       else { n         cout << 0; n         return 0; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 70, MAXM = 100, MOD = 1e9 + 7, INF = 1e9; n char c[] = { c ,  o ,  d ,  e ,  f ,  o ,  r ,  c ,  e ,  s }; n void solve() { n   long long n; n   cin >> n; n   long long x = 0, x1 = 0; n   while (pow(x + 1, 10) <= n) x++; n   while (pow(x, 10 - x1) * pow(x + 1, x1) < n) x1++; n   for (int i = 0; i < 10; i++) { n     if (i < x1) n       for (int j = 0; j <= x; j++) cout << c[i]; n     else n       for (int j = 0; j < x; j++) cout << c[i]; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const double SUCK = 999999999999999999.99; n const int MX = 51 * 101; n int n; n int r; n int f[55]; n int s[55]; n int p[55]; n double cp[55]; n double dp[55][MX]; n bool isOk(double det) { n   for (int i = 0; i <= r; i++) { n     dp[n][i] = 0; n   } n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j <= r; j++) { n       dp[i][j] = det; n       double togo = 0; n       if (j + f[i] > r) { n         togo = det; n       } else { n         togo += cp[i] * (f[i] + dp[i + 1][j + f[i]]); n         if (j + s[i] > r) n           togo += (1 - cp[i]) * (s[i] + det); n         else n           togo += (1 - cp[i]) * (s[i] + dp[i + 1][j + s[i]]); n       } n       dp[i][j] = min(det, togo); n     } n   } n   if (dp[0][0] >= det) return false; n   return true; n } n const double eps = 0.000000001; n time_t bg; n double getTime() { n   time_t en = clock(); n   double ret = (double)(en - bg) / CLOCKS_PER_SEC; n   return ret; n } n double bsearch(double l, double r) { n   double m = (l + r) / 2; n   if (r - l < eps) return m; n   if (getTime() >= 1.95) return m; n   if (isOk(m)) n     return bsearch(l, m); n   else n     return bsearch(m, r); n } n int main() { n   bg = clock(); n   scanf( %d%d , &n, &r); n   for (int i = 0; i < n; i++) scanf( %d%d%d , &f[i], &s[i], &p[i]); n   for (int i = 0; i < n; i++) cp[i] = 0.010000 * p[i]; n   double ans = bsearch(n, 50000000); n   printf( %.12f , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 400010, inf = 1 << 30; n int N, M, father[maxn], nxt[maxn], toit[maxn], len[maxn], side[maxn], id[maxn], n     seq[maxn], D[maxn], cnt; n int DFN, dfn[maxn], top[maxn], size[maxn], con[maxn], ans[maxn], n     tree[maxn << 2], cover[maxn << 2]; n bool exist[maxn]; n inline int find(int a) { n   if (father[a] != a) father[a] = find(father[a]); n   return father[a]; n } n inline void add(int a, int b, int c, int d) { n   nxt[++cnt] = side[a]; n   side[a] = cnt; n   toit[cnt] = b; n   len[cnt] = c; n   id[cnt] = d; n } n inline void ins(int a, int b, int c, int d) { n   add(a, b, c, d); n   add(b, a, c, d); n } n inline int gi() { n   char ch; n   int ret = 0, f = 1; n   do ch = getchar(); n   while (!(ch >=  0  && ch <=  9 ) && ch !=  - ); n   if (ch ==  - ) f = -1, ch = getchar(); n   do ret = ret * 10 + ch -  0 , ch = getchar(); n   while (ch >=  0  && ch <=  9 ); n   return ret * f; n } n struct Edge { n   int u, v, c, id; n   inline void read(int i) { n     id = i; n     u = gi(), v = gi(), c = gi(); n   } n   inline void bind() { n     int a = find(u), b = find(v); n     if (a != b) { n       father[a] = b; n       exist[id] = true; n       ins(u, v, c, id); n     } n   } n   friend inline bool operator<(const Edge &a, const Edge &b) { n     return a.c < b.c; n   } n } edge[maxn]; n inline void Div(int now, int Top) { n   dfn[now] = ++DFN; n   seq[DFN] = now; n   top[now] = Top; n   int heavy = 0; n   for (int i = side[now]; i; i = nxt[i]) n     if (toit[i] != father[now] && size[toit[i]] > size[heavy]) heavy = toit[i]; n   if (!heavy) return; n   Div(heavy, Top); n   for (int i = side[now]; i; i = nxt[i]) n     if (toit[i] != father[now] && toit[i] != heavy) Div(toit[i], toit[i]); n } n inline void dfs(int now) { n   size[now] = 1; n   for (int i = side[now]; i; i = nxt[i]) n     if (toit[i] != father[now]) { n       father[toit[i]] = now, con[toit[i]] = i; n       D[toit[i]] = D[now] + 1, dfs(toit[i]); n       size[now] += size[toit[i]]; n     } n } n inline void mst() { n   sort(edge + 1, edge + M + 1); n   cnt = 1; n   for (int i = 1; i <= N; ++i) father[i] = i; n   for (int i = 1; i <= M; ++i) edge[i].bind(); n   father[1] = 0; n   dfs(1); n   Div(1, 1); n } n inline int ask(int now, int l, int r, int ql, int qr) { n   if (l == ql && r == qr) return tree[now]; n   int mid = (l + r) >> 1; n   if (qr <= mid) n     return ask(now << 1, l, mid, ql, qr); n   else if (ql > mid) n     return ask(now << 1 | 1, mid + 1, r, ql, qr); n   else n     return max(ask(now << 1, l, mid, ql, mid), n                ask(now << 1 | 1, mid + 1, r, mid + 1, qr)); n } n inline void modify(int now, int l, int r, int ql, int qr, int c) { n   if (l == ql && r == qr) { n     cover[now] = min(cover[now], c); n     return; n   } n   int mid = (l + r) >> 1; n   if (qr <= mid) n     modify(now << 1, l, mid, ql, qr, c); n   else if (ql > mid) n     modify(now << 1 | 1, mid + 1, r, ql, qr, c); n   else { n     modify(now << 1, l, mid, ql, mid, c); n     modify(now << 1 | 1, mid + 1, r, mid + 1, qr, c); n   } n } n inline int Query(int a, int b, int c) { n   int ret = -inf; n   while (top[a] != top[b]) { n     if (D[top[a]] < D[top[b]]) swap(a, b); n     ret = max(ret, ask(1, 1, N, dfn[top[a]], dfn[a])); n     modify(1, 1, N, dfn[top[a]], dfn[a], c); n     a = father[top[a]]; n   } n   if (D[a] < D[b]) swap(a, b); n   if (a != b) { n     ret = max(ret, ask(1, 1, N, dfn[b] + 1, dfn[a])); n     modify(1, 1, N, dfn[b] + 1, dfn[a], c); n   } n   return ret; n } n inline void build(int now, int l, int r) { n   cover[now] = inf; n   if (l == r) { n     tree[now] = len[con[seq[l]]]; n     return; n   } n   int mid = (l + r) >> 1; n   build(now << 1, l, mid); n   build(now << 1 | 1, mid + 1, r); n   tree[now] = max(tree[now << 1], tree[now << 1 | 1]); n } n inline int query(int now, int l, int r, int pos) { n   if (l == r) return cover[now]; n   int mid = (l + r) >> 1; n   if (pos <= mid) n     return min(cover[now], query(now << 1, l, mid, pos)); n   else n     return min(cover[now], query(now << 1 | 1, mid + 1, r, pos)); n } n inline void work() { n   build(1, 1, N); n   for (int i = 1; i <= M; ++i) n     if (!exist[edge[i].id]) n       ans[edge[i].id] = Query(edge[i].u, edge[i].v, edge[i].c); n   for (int i = 2; i <= N; ++i) ans[id[con[i]]] = query(1, 1, N, dfn[i]); n   for (int i = 1; i <= M; ++i) { n     if (ans[i] == inf) n       ans[i] = -1; n     else n       --ans[i]; n     printf( %d  , ans[i]); n   } n } n int main() { n   N = gi(); n   M = gi(); n   for (int i = 1; i <= M; ++i) edge[i].read(i), ans[i] = inf; n   mst(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char a = getchar(); n   for (; !isdigit(a); a = getchar()) n     if (a ==  - ) f = -1; n   for (; isdigit(a); a = getchar()) x = x * 10 + a -  0 ; n   return x * f; n } n const unsigned long long INF = 1ULL << 63; n const int N = 200 + 5; n const int M = 50 + 5; n int IG, IN, IM, n, ipt[N]; n int issuf[N]; n int vis[N][M][M]; n unsigned long long f[N][M][M]; n vector<pair<int, int> > ed[N]; n int ch[M][2], fail[M * 2], ok[M * 2], tot = 1; n void ins(int *A, int len) { n   int x = 1; n   for (int i = 1; i <= len; i++) { n     if (!ch[x][A[i]]) ch[x][A[i]] = ++tot; n     x = ch[x][A[i]]; n   } n   ok[x] = 1; n } n void buildfail() { n   queue<int> q; n   for (int i = 0; i <= 1; i++) n     if (ch[1][i]) n       fail[ch[1][i]] = 1, q.push(ch[1][i]); n     else n       ch[1][i] = 1; n   while (q.size()) { n     int x = q.front(); n     q.pop(); n     for (int i = 0; i <= 1; i++) n       if (ch[x][i]) { n         fail[ch[x][i]] = ch[fail[x]][i]; n         ok[ch[x][i]] |= ok[fail[ch[x][i]]]; n         q.push(ch[x][i]); n       } else n         ch[x][i] = ch[fail[x]][i]; n   } n } n int id[M * 2], loc[M * 2]; n struct Node { n   int x, fr, to; n   unsigned long long val; n   Node(int X = 0, int F = 0, int T = 0, unsigned long long V = 0) n       : x(X), fr(F), to(T), val(V) {} n   inline friend bool operator<(const Node &a, const Node &b) { n     return a.val > b.val; n   } n }; n priority_queue<Node> hp; n int main() { n   IG = read() - 1; n   IN = read(); n   IM = read(); n   n = IG; n   for (int i = 1; i <= IN; i++) { n     int a = read(), k = read(); n     for (int j = 1; j <= k; j++) ipt[j] = read(), issuf[j + n] = 1; n     for (int j = 2; j <= k; j++) { n       ed[n + j].push_back({n + j - 1, ipt[j - 1]}); n       ed[ipt[j - 1]].push_back({n + j - 1, n + j}); n     } n     ed[ipt[k]].push_back({n + k, -1}); n     ed[n + 1].push_back({a, -1}); n     n += k; n   } n   for (int i = 1; i <= IM; i++) { n     int len = read(); n     for (int j = 1; j <= len; j++) ipt[j] = read(); n     ins(ipt, len); n   } n   buildfail(); n   int cnt = 0; n   for (int i = 1; i <= tot; i++) n     if (ok[i] == 0) id[i] = ++cnt, loc[cnt] = i; n   for (int i = 0; i <= n; i++) n     for (int j = 1; j <= cnt; j++) n       for (int k = 1; k <= cnt; k++) f[i][j][k] = INF; n   for (int i = 1; i <= cnt; i++) { n     int x = loc[i]; n     if (id[ch[x][0]]) { n       f[0][i][id[ch[x][0]]] = 1; n       hp.push(Node(0, i, id[ch[x][0]], 1)); n     } n     if (id[ch[x][1]]) { n       f[1][i][id[ch[x][1]]] = 1; n       hp.push(Node(1, i, id[ch[x][1]], 1)); n     } n   } n   while (hp.size()) { n     Node tmp = hp.top(); n     hp.pop(); n     int x = tmp.x, fr = tmp.fr, to = tmp.to; n     unsigned long long val = tmp.val; n     if (vis[x][fr][to]) continue; n     vis[x][fr][to] = 1; n     for (auto e : ed[x]) { n       int y = e.first, w = e.second; n       if (w == -1) { n         if (f[y][fr][to] > val) { n           f[y][fr][to] = val; n           hp.push(Node(y, fr, to, f[y][fr][to])); n         } n       } else { n         if (issuf[x] == 0) { n           for (int j = 1; j <= cnt; j++) n             if (f[y][fr][j] > val + f[w][to][j]) { n               f[y][fr][j] = val + f[w][to][j]; n               hp.push(Node(y, fr, j, f[y][fr][j])); n             } n         } else { n           for (int j = 1; j <= cnt; j++) n             if (f[y][j][to] > f[w][j][fr] + val) { n               f[y][j][to] = f[w][j][fr] + val; n               hp.push(Node(y, j, to, f[y][j][to])); n             } n         } n       } n     } n   } n   for (int i = 2; i <= IG; i++) { n     unsigned long long ans = INF; n     for (int j = 1; j <= cnt; j++) ans = min(ans, f[i][1][j]); n     if (ans == INF) n       printf( YES n ); n     else n       printf( NO %lld n , ans); n   } n   return 0; n } n