#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1 << 20; n const long long MOD = 2305843009255636993, RT = 5; n struct CD { n   double r, i; n   CD(double r = 0, double i = 0) : r(r), i(i) {} n   double real() const { return r; } n   void operator/=(const int c) { r /= c, i /= c; } n }; n CD operator*(const CD& a, const CD& b) { n   return CD(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); n } n CD operator+(const CD& a, const CD& b) { return CD(a.r + b.r, a.i + b.i); } n CD operator-(const CD& a, const CD& b) { return CD(a.r - b.r, a.i - b.i); } n const double pi = acos(-1.0); n CD cp1[MAXN + 9], cp2[MAXN + 9]; n int R[MAXN + 9]; n void dft(CD* a, int n, bool inv) { n   for (int i = 0, ThxDem = n; i < ThxDem; ++i) n     if (R[i] < i) swap(a[R[i]], a[i]); n   for (int m = 2; m <= n; m *= 2) { n     double z = 2 * pi / m * (inv ? -1 : 1); n     CD wi = CD(cos(z), sin(z)); n     for (int j = 0; j < n; j += m) { n       CD w(1); n       for (int k = j, k2 = j + m / 2; k2 < j + m; k++, k2++) { n         CD u = a[k]; n         CD v = a[k2] * w; n         a[k] = u + v; n         a[k2] = u - v; n         w = w * wi; n       } n     } n   } n   if (inv) n     for (int i = 0, ThxDem = n; i < ThxDem; ++i) a[i] /= n; n } n vector<long long> multiply(vector<long long>& p1, vector<long long>& p2) { n   int n = p1.size() + p2.size() + 1; n   int m = 1, cnt = 0; n   while (m <= n) m += m, cnt++; n   for (int i = 0, ThxDem = m; i < ThxDem; ++i) { n     R[i] = 0; n     for (int j = 0, ThxDem = cnt; j < ThxDem; ++j) n       R[i] = (R[i] << 1) | ((i >> j) & 1); n   } n   for (int i = 0, ThxDem = m; i < ThxDem; ++i) cp1[i] = 0, cp2[i] = 0; n   for (int i = 0, ThxDem = p1.size(); i < ThxDem; ++i) cp1[i] = p1[i]; n   for (int i = 0, ThxDem = p2.size(); i < ThxDem; ++i) cp2[i] = p2[i]; n   dft(cp1, m, false); n   dft(cp2, m, false); n   for (int i = 0, ThxDem = m; i < ThxDem; ++i) cp1[i] = cp1[i] * cp2[i]; n   dft(cp1, m, true); n   vector<long long> res; n   n -= 2; n   for (int i = 0, ThxDem = n; i < ThxDem; ++i) n     res.push_back((long long)floor(cp1[i].real() + 0.5)); n   return res; n } n int spf[MAXN]; n vector<int> ds; n vector<pair<int, int> > prs; n void gen(int x, int pos) { n   if (pos == int(prs.size())) n     ds.push_back(x); n   else { n     for (int i = 0, ThxDem = prs[pos].second + 1; i < ThxDem; ++i) { n       if (i || prs[pos].first != 2) gen(x, pos + 1); n       x *= prs[pos].first; n     } n   } n } n vector<int> dis[MAXN]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (int i = 2, ThxDem = MAXN; i < ThxDem; ++i) n     if (!spf[i]) n       for (int j = i; j < MAXN; j += i) n         if (!spf[j]) spf[j] = i; n   for (int i = 2, ThxDem = MAXN; i < ThxDem; ++i) n     if (i % 2 == 0) { n       prs.clear(); n       ds.clear(); n       int x = i; n       while (x > 1) { n         int now = spf[x], pw = 0; n         while (x % now == 0) x /= now, pw++; n         prs.push_back({now, pw}); n       } n       gen(1, 0); n       sort(ds.begin(), ds.end()); n       reverse(ds.begin(), ds.end()); n       dis[i] = ds; n     } n   int n, x, y; n   cin >> n >> x >> y; n   n++; n   vector<int> a(n); n   int off = x + 1; n   vector<long long> neg(2 * (x + 1)), pos(2 * (x + 1)); n   for (int i = 0, ThxDem = n; i < ThxDem; ++i) { n     cin >> a[i]; n     neg[x + 1 - a[i]] = 1; n     pos[off + a[i]] = 1; n   } n   auto ws = multiply(neg, pos); n   int q; n   cin >> q; n   vector<int> ans(q, -1); n   for (int j = 0, ThxDem = q; j < ThxDem; ++j) { n     int v; n     cin >> v; n     for (auto tt : dis[v]) { n       int len = tt - 2 * y; n       if (len <= 0 || len % 2) continue; n       len /= 2; n       if (2 * off + len < int(ws.size()) && ws[2 * off + len] > 0) { n         ans[j] = tt; n         break; n       } n     } n   } n   for (auto x : ans) cout << x <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long int pow(long long int x, long long int y, long long int m) { n   long long int res = 1; n   x = x % m; n   while (y > 0) { n     if (y & 1) res = ((res % m) * (x % m)) % m; n     y = y >> 1; n     x = ((x % m) * (x % m)) % m; n   } n   return res % m; n } n template <typename Arg1> n void ZZ(const char* name, Arg1&& arg1) { n   std::cerr << name <<   =   << arg1 << endl; n } n template <typename Arg1, typename... Args> n void ZZ(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   std::cerr.write(names, comma - names) <<   =   << arg1; n   ZZ(comma, args...); n } n const long long int INF = 0xFFFFFFFFFFFFFFFL; n long long int clz(unsigned long long N) { n   return N ? 64LL - __builtin_clzll(N) : -INF; n } n clock_t time_p = clock(); n void abhigyan10() { n   time_p = clock() - time_p; n   cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ; n } n long long int seed; n mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count()); n inline long long int rnd(long long int l = 0, long long int r = INF) { n   return uniform_int_distribution<long long int>(l, r)(rng); n } n const long long int mod = 1000000007; n long long int modinv(long long int x) { return pow(x, mod - 2, mod); } n vector<long long int> a; n int bs(long long int x, long long int n) { n   long long int l = 0, h = n - 1, m, ans = 0; n   while (l <= h) { n     m = (l + h) / 2; n     if (a[m] <= x) { n       l = m + 1; n       ans = max(ans, m); n     } else { n       h = m - 1; n     } n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int s = 0, t, n, p, i; n   cin >> n >> p; n   a.resize(n); n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a.begin(), a.end()); n   for (i = 0; i < n; i++) s = max(s, a[i] - i); n   t = a[n - 1]; n   for (i = 0; i < n;) { n     int d = t + i; n     int u = bs(d, n) + 1 - i; n     if (u < p) n       i++; n     else n       t--; n     if (t < s) break; n   } n   cout << max(0LL, t - s + 1) <<   n ; n   for (i = s; i <= t; i++) cout << i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n long long powmod(long long a, long long l, long long md) { n   long long res = 1; n   while (l) { n     if (l & 1) res = res * a % md; n     l /= 2; n     a = a * a % md; n   } n   return res; n } n long long binpow(long long a, long long l) { n   long long res = 1; n   while (l) { n     if (l & 1) res = res * a; n     l /= 2; n     a = a * a; n   } n   return res; n } n long long __set(long long b, long long i) { return b | (1 << i); } n long long __unset(long long b, long long i) { return b & (~(1UL << i)); } n long long __check(long long b, long long i) { return b & (1 << i); } n long long mulmod(long long a, long long b, long long md) { n   return ((a % md) * (b % md)) % md; n } n long long addmod(long long a, long long b, long long md) { n   return (a + b) % md; n } n long long submod(long long a, long long b, long long md) { n   return (((a - b) % md) + md) % md; n } n long long divmod(long long a, long long b, long long md) { n   return mulmod(a, powmod(b, md - 2, md), md); n } n const long long inf = 0xFFFFFFFFFFFFFFFL; n priority_queue<long long, vector<long long>, greater<long long> > pq; n clock_t time_p = clock(); n void time() { n   time_p = clock() - time_p; n   cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ; n } n long long d[3][10]; n signed main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   for (long long i = 0; i < 3; i++) { n     string s; n     cin >> s; n     if (s[1] ==  m ) { n       d[0][s[0] -  0 ]++; n     } else if (s[1] ==  p ) { n       d[1][s[0] -  0 ]++; n     } else { n       d[2][s[0] -  0 ]++; n     } n   } n   long long mx = 3; n   for (long long i = 0; i < 3; i++) { n     for (long long j = 1; j <= 9; j++) mx = min(mx, 3 - min(3ll, d[i][j])); n     for (long long j = 1; j <= 7; j++) { n       long long tp = 0; n       if (!d[i][j]) tp++; n       if (!d[i][j + 1]) tp++; n       if (!d[i][j + 2]) tp++; n       mx = min(mx, tp); n     } n   } n   cout << mx <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n const int N = 1205; n const int INF = 0x3f3f3f3f; n template <class T> n bool read(T& x) { n   char c; n   while (!isdigit(c = getchar()) && c !=  -  && c != EOF) n     ; n   if (c == EOF) return false; n   T flag = 1; n   if (c ==  - ) { n     flag = -1; n     x = 0; n   } else n     x = c -  0 ; n   while (isdigit(c = getchar())) x = x * 10 + c -  0 ; n   x *= flag; n   return true; n } n template <class T, class... R> n bool read(T& a, R&... b) { n   if (!read(a)) return false; n   return read(b...); n } n mt19937 gen(steady_clock::now().time_since_epoch().count()); n struct edge { n   int to, cap, next; n } e[N * 4]; n int head[N], cnt, depth[N], group[N]; n void add(int u, int v, int c) { n   e[cnt] = {v, c, head[u]}; n   head[u] = cnt++; n } n void add_edge(int u, int v, int c) { n   add(u, v, c); n   add(v, u, 0); n } n bool isap_bfs(int s, int t) { n   memset(depth, -1, sizeof(depth)); n   memset(group, 0, sizeof(group)); n   group[depth[t] = 0]++; n   queue<int> q; n   q.push(t); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = head[u]; ~i; i = e[i].next) { n       int v = e[i].to; n       if (~depth[v]) continue; n       group[depth[v] = depth[u] + 1]++; n       q.push(v); n     } n   } n   return ~depth[s]; n } n int isap_dfs(int u, int t, int c) { n   if (u == t) return c; n   int tmp = c; n   for (int i = head[u]; tmp && ~i; i = e[i].next) { n     int v = e[i].to; n     if (depth[v] + 1 == depth[u] && e[i].cap) { n       int d = isap_dfs(v, t, min(tmp, e[i].cap)); n       e[i].cap -= d; n       e[i ^ 1].cap += d; n       tmp -= d; n     } n   } n   if (tmp) { n     if (!--group[depth[u]]) depth[t] = -1; n     group[++depth[u]]++; n   } n   return c - tmp; n } n int isap(int s, int t) { n   if (!isap_bfs(s, t)) return 0; n   int max_flow = 0; n   while (~depth[t]) max_flow += isap_dfs(s, t, INF); n   return max_flow; n } n int deg[N], x[N], y[N], xe[N], ye[N]; n vector<int> edg[N]; n int main() { n   time_point<steady_clock> start = steady_clock::now(); n   int T, n, m, k; n   read(T); n   while (T--) { n     read(n, m, k); n     int s = 0, t = n + m + 1; n     cnt = 0; n     for (int i = s; i <= t; i++) { n       head[i] = -1; n       deg[i] = 0; n       edg[i].clear(); n     } n     for (int i = 1; i <= m; i++) { n       read(x[i], y[i]); n       deg[x[i]]++; n       deg[y[i]]++; n       edg[x[i]].push_back(i); n       edg[y[i]].push_back(i); n     } n     for (int i = 1; i <= n; i++) { n       if (deg[i] > 2 * k) { n         k = -1; n         break; n       } n     } n     if (k == -1) { n       for (int i = 1; i <= m; i++) printf( 0  ); n       puts(  ); n       continue; n     } n     int tot = 0; n     for (int i = 1; i <= n; i++) { n       if (deg[i] > k) { n         tot += deg[i] - k; n         add_edge(m + i, t, 2 * (deg[i] - k)); n       } n     } n     tot *= 2; n     for (int i = 1; i <= m; i++) { n       add_edge(s, i, 1); n       add_edge(i, m + x[i], 1); n       xe[i] = cnt - 1; n       add_edge(i, m + y[i], 1); n       ye[i] = cnt - 1; n     } n     if (isap(s, t) == tot) { n       for (int i = 1; i <= m; i++) deg[i] = 0; n       k = 1; n       for (int i = 1; i <= n; i++) { n         int c = 0; n         for (auto j : edg[i]) { n           if (x[j] == i && e[xe[j]].cap || y[j] == i && e[ye[j]].cap) { n             if (c == 0) n               deg[j] = k; n             else n               deg[j] = k++; n             c ^= 1; n           } n         } n       } n       for (int i = 1; i <= m; i++) n         if (!deg[i]) deg[i] = k++; n       for (int i = 1; i <= m; i++) printf( %d  , deg[i]); n       puts(  ); n     } else { n       for (int i = 1; i <= m; i++) printf( 0  ); n       puts(  ); n     } n   } n   cerr << endl n        <<  ------------------------------  << endl n        <<  Time:   n        << duration<double, milli>(steady_clock::now() - start).count() <<   ms.  n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500001; n int a[maxn][2]; n int cur, n; n int r[maxn][2], tot; n void dosth() { n   int i; n   a[1][cur ^ 1] = a[1][cur]; n   a[n][cur ^ 1] = a[n][cur]; n   for (i = 2; i < n; ++i) n     a[i][cur ^ 1] = a[i - 1][cur] + a[i][cur] + a[i + 1][cur] > 1 ? 1 : 0; n   cur ^= 1; n } n int count() { n   int f = !a[1][0], i, j, ans = 0, tmp = 1; n   a[0][0] = a[1][0]; n   for (i = 2; i <= n; ++i) { n     if (a[i][0] != ((i + f) & 1)) { n       if (1) { n         for (j = 1; j <= tmp / 2; ++j) a[i - j][0] = a[i][0]; n         for (j = tmp / 2 + 1; j <= tmp; ++j) a[i - j][0] = a[i - tmp - 1][0]; n       } n       ans = max(ans, tmp), tmp = 1, f ^= 1; n     } else n       tmp++; n   } n   for (j = 1; j <= tmp / 2; ++j) a[i - j][0] = a[n][0]; n   for (j = tmp / 2 + 1; j <= tmp; ++j) a[i - j][0] = a[i - tmp - 1][0]; n   return (max(ans, tmp) - 1) / 2; n } n int main() { n   scanf( %d , &n); n   int i, j; n   cur = 0; n   for (i = 1; i <= n; ++i) { n     char c; n     do c = getchar(); n     while (!isdigit(c)); n     a[i][0] = c - 48; n   } n   printf( %d n , count()); n   for (i = 1; i <= n; ++i) putchar(a[i][0] +  0 ), putchar(   ); n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int num[100005]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %1d , num + i); n   for (int i = 1; i <= n && k; i++) { n     if (num[i] == 4 && num[i + 1] == 7) { n       if (i % 2 == 0 && num[i - 1] == 4) { n         if (k % 2) { n           num[i] = 7; n         } n         break; n       } n       if (i % 2 == 1 && i + 2 <= n && num[i + 2] == 7) { n         if (k % 2) { n           num[i + 1] = 4; n         } n         break; n       } n       if (i % 2 == 0) n         num[i] = 7; n       else n         num[i + 1] = 4; n       k--; n     } n   } n   for (int i = 1; i <= n; i++) printf( %d , num[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int ans = 1; n   for (int i = 6; i <= n; i++) { n     if (n % i == 0) { n       int k1 = 0, k0 = 0; n       int f = 0; n       int x = i; n       while (x > 1 and f == 0) { n         int x2 = x % 2; n         if (x2 == 1 and k0 > 0) n           k1++; n         else if (x2 == 0 and k1 == 0) n           k0++; n         else n           f = 1; n         x /= 2; n       } n       if (k1 - k0 == 0 and f == 0) ans = i; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, ans[2005]; n char a[2010][2010]; n void load() { n   scanf( %d%d%d n , &n, &m, &k); n   for (int i = 0; i < n; i++) { n     scanf( %s , a[i]); n   } n } n void solve() { n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  L ) { n         if (j - i >= 0) { n           ans[j - i]++; n         } n       } n       if (a[i][j] ==  R ) { n         if (j + i < m) { n           ans[j + i]++; n         } n       } n       if (a[i][j] ==  U ) { n         if (i % 2 == 0) { n           ans[j]++; n         } n       } n     } n   } n   for (int i = 0; i < m; i++) { n     if (i > 0) printf(   ); n     printf( %d , ans[i]); n   } n   printf(  n ); n } n int main() { n   load(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m; n   cin >> m; n   int c[m]; n   int sum1 = 0; n   for (int i = 0; i < m; i++) { n     cin >> c[i]; n     sum1 += c[i]; n   } n   int x, y; n   cin >> x >> y; n   int flag = 0; n   int k = 1; n   int sum2 = 0; n   if (sum2 >= x && sum2 <= y && sum1 - sum2 >= x && sum1 - sum2 <= y) { n     flag = 1; n     cout <<  1  << endl; n   } else { n     for (int i = 1; i <= m; i++) { n       k = i; n       sum2 += c[i - 1]; n       if (sum2 >= x && sum2 <= y && sum1 - sum2 >= x && sum1 - sum2 <= y) { n         flag = 1; n         cout << i + 1 << endl; n         break; n       } n     } n   } n   if (flag == 0) { n     cout <<  0  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y; n char a[100005]; n int main(void) { n   scanf( %d%d%d , &n, &x, &y); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   if (a[x] == a[y]) n     puts( 0 ); n   else n     puts( 1 ); n } n


#include <bits/stdc++.h> n using namespace std; n int kk[(100010)]; n map<int, int> possible; n int main() { n   int t, m, k, tj, rj, pre(0); n   bool first(false), already(false); n   scanf( %d , &t); n   for (int i = 0; i < t; ++i) { n     first = false; n     already = false; n     pre = 0; n     possible.clear(); n     scanf( %d%d , &m, &k); n     for (int j = 1; j <= k; ++j) { n       scanf( %d , &kk[j]); n     } n     for (int j = 0; j < m - 1; ++j) { n       scanf( %d%d , &tj, &rj); n       if (rj == 1 && !first) { n         first = true; n         for (int l = 1; l <= k; ++l) { n           if (kk[l] == 0) { n             already = true; n             break; n           } n         } n         if (!already) { n           for (int l = 1; l <= k; ++l) { n             if (kk[l] <= pre) { n               possible[l] = kk[l]; n             } n           } n         } n       } n       if (tj == 0) { n         pre += 1; n       } else { n         kk[tj] -= 1; n         if (first && !already) { n           if (possible[tj] != 0) { n             possible.erase(tj); n           } n         } n       } n     } n     if (!already && first) { n       int min = 100001; n       map<int, int>::iterator it = possible.begin(); n       while (it != possible.end()) { n         int count = (*it).second; n         if (count != 0 && count < min) { n           min = (*it).second; n         } n         it++; n       } n       pre -= min; n     } n     for (int j = 1; j <= k; ++j) { n       if (possible[j] != 0) { n         printf( %c ,  Y ); n       } else if (kk[j] <= pre) { n         printf( %c ,  Y ); n       } else { n         printf( %c ,  N ); n       } n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int B = 257; n char s[1000100]; n char t[1000100]; n int n; n int m; n unsigned long long int hash1[1000100]; n unsigned long long int hash2[1000100]; n struct resp { n   unsigned long long int count; n   unsigned long long int indices[1000100]; n } indice; n long long int expBinaria(long long int a, long long int b) { n   long long int res = 1; n   while (b) { n     if (b % 2) res = res * a; n     b = b / 2; n     a = a * a; n   } n   return res; n } n void armaHashes() { n   hash1[0] = 0; n   for (int i = 1; i <= n; i++) { n     hash1[i] = hash1[i - 1] * B + s[i - 1]; n   } n   hash2[0] = 0; n   for (int i = 1; i <= m; i++) { n     hash2[i] = hash2[i - 1] * B + t[i - 1]; n   } n } n long long int h_1(int i, int j) { n   return hash1[j] - hash1[i - 1] * expBinaria(B, j - i + 1); n } n long long int h_2(int i, int j) { n   return hash2[j] - hash2[i - 1] * expBinaria(B, j - i + 1); n } n void solve() { n   long long int cuenta = 0; n   if (h_1(2, n) == h_2(1, m)) { n     indice.indices[cuenta] = 1; n     cuenta++; n   } n   for (int i = 2; i < n; i++) { n     if (h_1(1, i - 1) == h_2(1, i - 1) && h_1(i + 1, n) == h_2(i, m)) { n       indice.indices[cuenta] = i; n       cuenta++; n     } n   } n   if (h_1(1, n - 1) == h_2(1, m)) { n     indice.indices[cuenta] = n; n     cuenta++; n   } n   indice.count = cuenta; n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> s; n   cin >> t; n   n = strlen(s); n   m = strlen(t); n   armaHashes(); n   solve(); n   cout << indice.count; n   cout <<   n ; n   for (int i = 0; i < indice.count; i++) { n     cout << indice.indices[i]; n     cout <<   t ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n vector<int> gr[50005]; n int n, k; n bool vis[50005]; n int lev[50005][505]; n long long int dp[50005]; n void dfs(int v) { n   vis[v] = true; n   lev[v][0] = 1; n   for (auto ed : gr[v]) { n     if (!vis[ed]) { n       dfs(ed); n       for (long long int i = 1; i < k + 1; i++) lev[v][i] += lev[ed][i - 1]; n     } n   } n } n void solve(int v) { n   vis[v] = true; n   for (auto ed : gr[v]) { n     if (!vis[ed]) { n       solve(ed); n       for (long long int i = 1; i < k; i++) n         dp[v] += lev[ed][i - 1] * (lev[v][k - i] - lev[ed][k - i - 1]); n     } n   } n   dp[v] /= 2; n   dp[v] += lev[v][k]; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   int a, b; n   for (long long int i = 0; i < n - 1; i++) { n     cin >> a >> b; n     gr[a].push_back(b); n     gr[b].push_back(a); n   } n   memset(lev, 0, sizeof(lev)); n   memset(vis, false, sizeof(vis)); n   dfs(1); n   memset(vis, false, sizeof(vis)); n   memset(dp, 0, sizeof(dp)); n   solve(1); n   long long int ans = 0; n   for (long long int i = 1; i < n + 1; i++) ans += dp[i]; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n vector<bool> Prime(20000000 + 1, 1); n vector<bool> Pal(20000000 + 1, 1); n void gen1() { n   long long int n = 2000000; n   Prime[1] = 0; n   for (long long int i = 2; i <= 20000000; i++) { n     if (Prime[i]) { n       for (long long int j = i + i; j <= n; j += i) Prime[j] = false; n     } n   } n } n void gen2() { n   long long int n = 20000000; n   long long int num, rev = 0, digit; n   for (long long int i = 1; i <= 20000000; i++) { n     num = i; n     while (num > 0) { n       digit = num % 10; n       rev = rev * 10 + digit; n       num = num / 10; n     } n     if (i != rev) Pal[i] = false; n     rev = 0; n   } n } n long long int a, b; n int main() { n   ios::sync_with_stdio(false); n   gen1(), gen2(); n   cin >> a >> b; n   long long int ans = 1, primes = 0, pals = 0; n   for (long long int i = 1; i <= 20000000; i++) { n     if (Prime[i]) primes++; n     if (Pal[i]) pals++; n     if (b * primes <= a * pals) ans = max(ans, i); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<6> a, b; n int main() { n   int n; n   cin >> n; n   a = bitset<6>(n); n   b.set(5, a[5]); n   b.set(4, a[0]); n   b.set(3, a[2]); n   b.set(2, a[3]); n   b.set(1, a[1]); n   b.set(0, a[4]); n   cout << b.to_ulong(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, c[100000], b[100000], a[100000], s1 = 0, s2 = 0, s3 = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     s1 += a[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     cin >> b[i]; n     s2 += b[i]; n   } n   for (int i = 0; i < n - 2; i++) { n     cin >> c[i]; n     s3 += c[i]; n   } n   cout << s1 - s2 << endl << s2 - s3; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool a[30][30]; n void fun(int x, int y) { a[x][y] = a[y][x] = true; } n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     memset(a, false, sizeof a); n     int n, p; n     cin >> n >> p; n     if (n % 2 == 0) { n       for (int i = 1; i <= n; i++) { n         fun(i, i + 1); n       } n       fun(1, n); n       int last; n       for (int i = 1; i + 2 <= n; i += 2) { n         fun(i, i + 2); n         last = i + 2; n       } n       fun(2, last); n       for (int i = 2; i + 2 <= n - 2; i += 2) { n         if (i + 2 == n - 2) { n           fun(i, i + 4); n           last = i + 2; n         } else n           fun(i, i + 2); n         last = i + 2; n       } n       fun(last, last + 2); n       fun(1, last); n       for (int i = 1; i <= n; i++) n         for (int j = 1; j <= n and p > 0; j++) { n           if (i != j and a[i][j] == false) { n             p--; n             fun(i, j); n           } n         } n       for (int i = 1; i <= n; i++) n         for (int j = 1; j <= n; j++) n           if (i < j and a[i][j]) cout << i <<     << j << endl; n     } else { n       for (int i = 1; i <= n; i++) { n         fun(i, i + 1); n       } n       fun(1, n); n       int last; n       for (int i = 1; i + 2 <= n; i += 2) { n         fun(i, i + 2); n         last = i + 2; n       } n       fun(2, last); n       for (int i = 2; i + 2 <= n; i += 2) { n         fun(i, i + 2); n         last = i + 2; n       } n       fun(1, last); n       for (int i = 1; i <= n; i++) n         for (int j = 1; j <= n and p > 0; j++) { n           if (i != j and a[i][j] == false) { n             p--; n             fun(i, j); n           } n         } n       for (int i = 1; i <= n; i++) n         for (int j = 1; j <= n; j++) n           if (i < j and a[i][j]) cout << i <<     << j << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   if (n < k * 1ll * (k + 1) / 2) { n     cout <<  NO  << endl; n     return 0; n   } n   int nn = n - k * (k + 1) / 2; n   vector<int> a(k); n   for (int i = 0; i < k; ++i) { n     a[i] = i + 1 + (nn / k) + (i >= k - nn % k); n   } n   if (nn != k - 1) { n     cout <<  YES  << endl; n     for (int i = 0; i < k; ++i) cout << a[i] <<    ; n     cout << endl; n   } else { n     if (k > 3) { n       --a[1]; n       ++a[k - 1]; n     } n     if (k == 2 || k == 3) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n       for (int i = 0; i < k; ++i) cout << a[i] <<    ; n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5, mod = 1e9 + 7; n long long a[N], x, n, sum; n long long fastpower(long long b, long long p) { n   if (p == 0) return 1; n   long long halfpower = fastpower(b, p / 2) % mod; n   halfpower *= halfpower; n   halfpower %= mod; n   if (p % 2) halfpower = (halfpower * (b % mod)) % mod; n   return halfpower; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> x; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   map<long long, long long> mp; n   for (int i = 0; i < n; i++) mp[sum - a[i]]++; n   for (auto i : mp) { n     mp[i.first + 1] += (i.second / x); n     if (i.second % x) { n       cout << fastpower(x, min(i.first, sum)); n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n == 1) { n     cout <<  1 1  << endl <<  1 ; n     return 0; n   } n   cout << 5 * (n - 1) <<     n        <<  2  << endl n        <<  1 5 ; n } n


#include <bits/stdc++.h> n int const maxn = 255; n int const mod = 1e9 + 7; n long long a[maxn]; n long long c[maxn][maxn]; n long long pow(long long a, long long b, long long p) { n   long long r = 1; n   while (b) { n     if (b & 1) r = (r * a) % p; n     a = (a * a) % p; n     b >>= 1; n   } n   return r; n } n int main() { n   int n, k, i, j; n   for (i = 0; i < maxn; i++) { n     c[i][0] = c[i][i] = 1; n     for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; n   } n   scanf( %d%d , &n, &k); n   for (i = 1; i <= n; i++) n     a[i] = pow(pow(k, i, mod) - pow(k - 1, i, mod), n, mod); n   long long ans = a[n]; n   for (i = 1; i <= n; i++) { n     if (i & 1) n       ans = (ans - ((c[n][i] * pow(k - 1, i * n, mod)) % mod * a[n - i]) % mod + n              mod) % n             mod; n     else n       ans = n           (ans + ((c[n][i] * pow(k - 1, i * n, mod)) % mod * a[n - i]) % mod) % n           mod; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long a, long long b) { n   long long res = 1; n   a = a % 1000000007; n   while (b > 0) { n     if (b & 1) { n       res = (res * a) % 1000000007; n       b--; n     } n     a = (a * a) % 1000000007; n     b >>= 1; n   } n   return res; n } n long long fermat_inv(long long y) { return power(y, 1000000007 - 2); } n long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t--) { n     int n, q; n     cin >> n >> q; n     set<int> s; n     for (int i = 0; i < n; i++) { n       int a; n       cin >> a; n       s.insert(a); n     } n     map<long long, int> m; n     for (auto it = s.begin(); it != s.end();) { n       int val = *it; n       val = -val; n       it++; n       if (it == s.end()) break; n       val += (*it); n       m[val]++; n     } n     auto it = m.end(); n     if (it == m.begin()) n       cout <<  0 n ; n     else { n       auto it1 = s.begin(); n       auto it2 = s.end(); n       it2--; n       long long ans = (*it2) - (*it1); n       it--; n       ans -= it->first; n       cout << ans <<   n ; n     } n     while (q--) { n       int ty, x; n       cin >> ty >> x; n       if (ty == 0) { n         auto it = s.lower_bound(x); n         int ctr = 0; n         long long val1 = 0; n         if (it != s.begin()) { n           it--; n           long long val = x - (*it); n           val1 += val; n           ctr++; n           m[val]--; n           if (m[val] == 0) m.erase(val); n         } n         auto it1 = s.upper_bound(x); n         if (it1 != s.end()) { n           long long val = (*it1) - x; n           m[val]--; n           ctr++; n           val1 += val; n           if (m[val] == 0) m.erase(val); n         } n         if (ctr == 2) m[val1]++; n         s.erase(x); n       } else { n         int ctr = 0; n         auto it = s.lower_bound(x); n         long long val1 = 0; n         if (it != s.begin()) { n           it--; n           long long val = x - (*it); n           val1 += val; n           ctr++; n           m[val]++; n         } n         auto it1 = s.upper_bound(x); n         if (it1 != s.end()) { n           long long val = (*it1) - x; n           val1 += val; n           ctr++; n           m[val]++; n         } n         if (ctr == 2) m[val1]--; n         if (m[val1] == 0) m.erase(val1); n         s.insert(x); n       } n       auto it = m.end(); n       if (it == m.begin()) n         cout <<  0 n ; n       else { n         auto it1 = s.begin(); n         auto it2 = s.end(); n         it2--; n         long long ans = (*it2) - (*it1); n         it--; n         ans -= it->first; n         cout << ans <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1000 * 1000 * 1000 + 7; n const long long int INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; n const long long int MOD2 = 998244353; n const long double PI = 3.141592653589793; n long long int gcd(long long int a, long long int b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x %= p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int power1(long long int x, long long int y) { n   long long int res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n long long int lcm(long long int a, long long int b) { n   return (a * b) / gcd(a, b); n } n long long int max(long long int a, long long int b) { n   if (a > b) return a; n   return b; n } n long long int min(long long int a, long long int b) { n   if (a > b) return b; n   return a; n } n bool sortbysec(const pair<long long int, long long int> &a, n                const pair<long long int, long long int> &b) { n   return a.second < b.second; n } n vector<long long int> prime; n bool val[500]; n void sieve() { n   memset(val, true, sizeof(val)); n   val[1] = false; n   val[0] = false; n   for (long long int i = 2 * 2; i <= 500; i += 2) { n     val[i] = false; n   } n   for (long long int i = 3; i <= 500; i++) { n     if (val[i] == false) continue; n     for (long long int j = i * i; j <= 500; j += i) { n       val[j] = false; n     } n   } n   for (int i = 0; i <= 500; i++) { n     if (val[i] == true) { n       prime.push_back(i); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     long long int arr[n]; n     for (long long int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     if (n == 1) { n       cout << k + 1 <<   n ; n       continue; n     } n     if (k < 9) { n       cout << k + 1 <<   n ; n       continue; n     } n     long long int ans = 0; n     long long int flag = 0; n     long long int count = 0; n     long long int count1 = 0; n     for (long long int i = 1; i < n; i++) { n       long long int num = power1(10, arr[i]) - 1; n       count = 0; n       for (long long int j = i - 1; j >= 0; j--) { n         count += num / power1(10, arr[j]); n         num -= ((num / power1(10, arr[j])) * power1(10, arr[j])); n       } n       if (count > k) { n         cout << power1(10, arr[i - 1]) * (k - count1 + 1) + n                     power1(10, arr[i - 1]) - 1 n              <<   n ; n         flag = 1; n         break; n       } n       count1 = count; n     } n     if (flag == 0) { n       cout << (power1(10, arr[n - 1]) - 1) + n                   power1(10, arr[n - 1]) * (k - count1 + 1) n            <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b; n int ans[60]; n void dfs(int dep) { n   long long cur = ans[dep - 1]; n   long long x = cur << 1; n   long long y = cur * 10 + 1; n   if (x == b || y == b) { n     puts( YES ); n     cout << dep + 1 << endl; n     for (int i = 0; i < dep; i++) cout << ans[i] <<    ; n     cout << b << endl; n     exit(0); n   } n   ans[dep] = x; n   if (x < b) dfs(dep + 1); n   ans[dep] = y; n   if (y < b) dfs(dep + 1); n } n int main() { n   cin >> a >> b; n   ans[0] = a; n   dfs(1); n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, x, y, z, r = 0; n   scanf( %d%d%d%d%d%d , &a, &b, &c, &x, &y, &z); n   if (a > x) { n     r += (a - x) / 2; n     a -= r * 2; n   } n   if (b > y) { n     r += (b - y) / 2; n     b -= (b - y) / 2 * 2; n   } n   if (c > z) { n     r += (c - z) / 2; n     c -= (c - z) / 2 * 2; n   } n   if (a < x) { n     r -= x - a; n     a += x - a; n   } n   if (r < 0) { n     printf( No ); n     return 0; n   } n   if (b < y) { n     r -= y - b; n     b += y - b; n   } n   if (r < 0) { n     printf( No ); n     return 0; n   } n   if (c < z) { n     r -= z - c; n     c += z - c; n   } n   if (r < 0) { n     printf( No ); n     return 0; n   } n   printf( Yes ); n   return 0; n } n


#include <bits/stdc++.h> n int a[6] = {0, 2, 3, 1, 2, 1}; n int main() { n   int n; n   scanf( %d , &n); n   printf( %d n , a[n]); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:20000000 ) n #pragma warning(disable : 4146) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const int inf = 1e9; n const long long lnf = 1e18; n const long long h1 = 239017, h2 = 731604233; n const long long mod = 1000000007, mod2 = 1000000009; n const long double pi = 3.141592653589793238462643383279; n const long double EPS = 1e-9; n struct rectangle { n   int x1, x2; n   int y1, y2; n   rectangle(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {} n }; n vector<rectangle> v; n int n, x, y, first, second; n int xm[2005], ym[2005]; n bool obs[2005][2005], a[2005][2005]; n map<int, int> mx, my; n void dfs(int x, int y) { n   if (x < 0 || x >= first || y < 0 || y >= second || obs[x][y] || a[x][y]) n     return; n   a[x][y] = true; n   dfs(x + 1, y); n   dfs(x - 1, y); n   dfs(x, y + 1); n   dfs(x, y - 1); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   cout.tie(); n   cout << setprecision(20); n   cin >> n; n   for (int i = 0; i < (n); i++) { n     char dir; n     int d; n     cin >> dir >> d; n     if (dir ==  L ) { n       rectangle r = {x - d, y, x + 1, y + 1}; n       v.push_back(r); n       x -= d; n     } n     if (dir ==  R ) { n       rectangle r = {x, y, x + d + 1, y + 1}; n       v.push_back(r); n       x += d; n     } n     if (dir ==  U ) { n       rectangle r = {x, y, x + 1, y + d + 1}; n       v.push_back(r); n       y += d; n     } n     if (dir ==  D ) { n       rectangle r = {x, y - d, x + 1, y + 1}; n       v.push_back(r); n       y -= d; n     } n   } n   for (int i = 0; i < (n); i++) { n     mx[v[i].x1] = mx[v[i].x2] = 0; n     my[v[i].y1] = my[v[i].y2] = 0; n   } n   for (auto &it : mx) { n     it.second = first; n     xm[first++] = it.first; n   } n   for (auto &it : my) { n     it.second = second; n     ym[second++] = it.first; n   } n   --first, --second; n   for (int i = 0; i < (n); i++) { n     int x1 = mx[v[i].x1], x2 = mx[v[i].x2], y1 = my[v[i].y1], y2 = my[v[i].y2]; n     for (int j = x1; j < x2; ++j) n       for (int k = y1; k < y2; ++k) obs[j][k] = true; n   } n   for (int i = 0; i < (first); i++) n     for (int j = 0; j < (second); j++) n       if (!i || i == first - 1 || !j || j == second - 1) dfs(i, j); n   long long ans = 0; n   for (int i = 0; i < (first); i++) n     for (int j = 0; j < (second); j++) n       if (!a[i][j]) { n         long long dx = xm[i + 1] - xm[i], dy = ym[j + 1] - ym[j]; n         ans += dx * dy; n       } n   cout << ans << endl; n   cerr <<  Time used :   << (double)clock() * 1.0 / 1000 <<   seconds. n  n        << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n const int N = 100005; n using namespace std; n long long n, a, b, k; n char s[N]; n long long mod = 1e9 + 9; n long long pow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % mod; n     b >>= 1; n     a = a * a % mod; n   } n   return ans; n } n long long ex_gcd(long long a, long long b, long long &x, long long &y) { n   if (!b) { n     x = 1, y = 0; n     return a; n   } n   long long tmp = ex_gcd(b, a % b, x, y); n   long long t = x; n   x = y; n   y = t - (a / b) * x; n   return tmp; n } n long long inv(long long x) { n   long long a, b; n   ex_gcd(x, mod, a, b); n   return (a + mod) % mod; n } n int main() { n   scanf( %lld%lld%lld%lld , &n, &a, &b, &k); n   scanf( %s , s); n   long long ans = 0, m = (n + 1) / k; n   for (int i = 0; i < k; i++) { n     long long x = pow(a, n - i), y = pow(b, i); n     long long now = x * y % mod; n     if (s[i] ==  + ) n       ans += now; n     else n       ans -= now; n     ans = (ans + mod) % mod; n   } n   long long q = pow(inv(a), k) * pow(b, k) % mod; n   if (q == 1) n     ans = ans * m % mod; n   else { n     long long x = inv(q - 1) % mod; n     ans = (ans * (pow(q, m) - 1) % mod) * x % mod; n   } n   ans = (ans + mod) % mod; n   printf( %lld n , ans); n   return 0; 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 const long long mod = 1000000007; n long long r(pair<int, int> a) { n   long long x = a.first; n   long long y = a.second; n   return x * x + y * y; n } n pair<int, int> operator+(pair<int, int> a, pair<int, int> b) { n   return make_pair(a.first + b.first, a.second + b.second); n } n pair<int, int> operator-(pair<int, int> a, pair<int, int> b) { n   return make_pair(a.first - b.first, a.second - b.second); n } n int main() { n   ios_base::sync_with_stdio(false); n   int N; n   cin >> N; n   vector<pair<pair<int, int>, vector<int>>> a; n   for (int i = 1; i <= N; i++) { n     int x, y; n     cin >> x >> y; n     a.push_back({{x, y}, {i}}); n   } n   shuffle(a.begin(), a.end(), rng); n   while (a.size() >= 3) { n     int i = a.size() - 1; n     int j = a.size() - 2; n     int wj = 1; n     pair<int, int> mnn = {1e8, 1e8}; n     for (int x = a.size() - 3; x < (int)a.size(); x++) { n       for (int y = x + 1; y < (int)a.size(); y++) { n         if (x == y) continue; n         pair<int, int> v1 = a[x].first + a[y].first; n         pair<int, int> v2 = a[x].first - a[y].first; n         if (r(v1) < r(mnn)) { n           mnn = v1; n           i = x; n           j = y; n           wj = 1; n         } n         if (r(v2) < r(mnn)) { n           mnn = v2; n           i = x; n           j = y; n           wj = -1; n         } n       } n     } n     a[i].first = a[j].first = mnn; n     if (a[j].second.size() < a[i].second.size()) { n       for (int c : a[j].second) { n         a[i].second.push_back(c * wj); n       } n       a.erase(a.begin() + j); n     } else { n       if (wj == 1) { n         for (int c : a[i].second) { n           a[j].second.push_back(c * wj); n         } n         a.erase(a.begin() + i); n       } else { n         a[j].first = make_pair(0, 0) - a[j].first; n         for (int c : a[i].second) { n           a[j].second.push_back(-c); n         } n         a.erase(a.begin() + i); n       } n     } n   } n   if (a.size() == 2) { n     if (r(a[0].first - a[1].first) < r(a[0].first + a[1].first)) { n       for (int &i : a[1].second) i *= -1; n     } n   } n   int w[N + 1]; n   for (auto ii : a) { n     for (int i : ii.second) { n       if (i > 0) n         w[i] = 1; n       else n         w[-i] = -1; n     } n   } n   for (int i = 1; i <= N; i++) cout << w[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y, z, q, sum; n int main() { n   ios_base::sync_with_stdio(0); n   for (cin >> n; n; --n) n     cin >> x >> y >> z >> q, sum += (z - x + 1) * (q - y + 1); n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N(200009); n struct LnkNode { n   int v, w, nxt; n } edge[N << 3]; n int etot = 1, fst[N], cur[N]; n void addedge_(int u, int v, int w) { n   ++etot; n   edge[etot].v = v; n   edge[etot].w = w; n   edge[etot].nxt = fst[u]; n   fst[u] = etot; n } n void addedge(int u, int v, int w) { addedge_(u, v, w), addedge_(v, u, 0); } n void deledge_(int u) { fst[u] = edge[fst[u]].nxt; } n int n, m, r, b, x[N], y[N], cntx[N], cnty[N], x_[N], y_[N], limx[N], limy[N], n     dt[N], mf, d[N], q[N], Head, Tail; n bool bfs(int s, int t) { n   memset(d + 1, 0x3f, ((n << 1) + 4) << 2); n   Head = Tail = 0; n   d[q[Tail++] = s] = 0; n   while (Head ^ Tail) { n     int &x = q[Head++]; n     for (int i = fst[x]; i; i = edge[i].nxt) { n       int &y = edge[i].v, &w = edge[i].w; n       if (w && d[y] > d[x] + 1) d[q[Tail++] = y] = d[x] + 1; n     } n   } n   return d[t] != 0x3f3f3f3f; n } n int dfs(int x, int t, int f) { n   if (x == t) return f; n   int r = f; n   for (int &i = cur[x]; i; i = edge[i].nxt) { n     int &y = edge[i].v, &w = edge[i].w; n     if (w && d[y] == d[x] + 1) { n       int k = dfs(y, t, min(r, w)); n       w -= k, edge[i ^ 1].w += k; n       if (!(r -= k)) break; n     } n   } n   return f - r; n } n char res[N]; n int main() { n   scanf( %d%d%d%d , &n, &m, &r, &b); n   for (int i = 1; i <= n; ++i) scanf( %d%d , x + i, y + i); n   memcpy(x_ + 1, x + 1, n << 2); n   sort(x_ + 1, x_ + 1 + n); n   memcpy(y_ + 1, y + 1, n << 2); n   sort(y_ + 1, y_ + 1 + n); n   for (int i = 1; i <= n; ++i) { n     ++cntx[x[i] = lower_bound(x_ + 1, x_ + 1 + n, x[i]) - x_]; n     ++cnty[y[i] = lower_bound(y_ + 1, y_ + 1 + n, y[i]) - y_]; n     addedge(x[i], n + y[i], 1); n   } n   for (int i = 1; i <= n; ++i) limx[i] = limy[i] = n; n   int t, l, d; n   while (m--) { n     scanf( %d%d%d , &t, &l, &d); n     switch (t) { n       case 1: { n         int t_ = lower_bound(x_ + 1, x_ + 1 + n, l) - x_; n         if (t_ <= n && x_[t_] == l && limx[t_] > d) limx[t_] = d; n         break; n       } n       case 2: { n         int t_ = lower_bound(y_ + 1, y_ + 1 + n, l) - y_; n         if (t_ <= n && y_[t_] == l && limy[t_] > d) limy[t_] = d; n         break; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (cntx[i]) { n       int lb = (cntx[i] > limx[i] n                     ? (((cntx[i] - limx[i]) >> 1) + ((cntx[i] - limx[i]) & 1)) n                     : 0), n           rb = (cntx[i] + limx[i]) >> 1; n       if (lb > rb) return puts( -1 ), 0; n       dt[(n << 1) + 1] -= lb, dt[i] += lb, addedge((n << 1) + 1, i, rb - lb); n     } n     if (cnty[i]) { n       int lb = (cnty[i] > limy[i] n                     ? (((cnty[i] - limy[i]) >> 1) + ((cnty[i] - limy[i]) & 1)) n                     : 0), n           rb = (cnty[i] + limy[i]) >> 1; n       if (lb > rb) return puts( -1 ), 0; n       dt[n + i] -= lb, dt[(n << 1) + 2] += lb, n           addedge(n + i, (n << 1) + 2, rb - lb); n     } n   } n   for (int i = 1; i <= (n << 1) + 2; ++i) { n     if (dt[i] > 0) n       addedge((n << 1) + 3, i, dt[i]); n     else if (dt[i] < 0) n       addedge(i, (n << 1) + 4, -dt[i]); n   } n   addedge((n << 1) + 2, (n << 1) + 1, 0x7fffffff); n   int f; n   while (bfs((n << 1) + 3, (n << 1) + 4)) { n     memcpy(cur + 1, fst + 1, ((n << 1) + 4) << 2); n     while (dfs((n << 1) + 3, (n << 1) + 4, 0x7fffffff)) n       ; n   } n   for (int i = fst[(n << 1) + 3]; i; i = edge[i].nxt) n     if (edge[i].w) return puts( -1 ), 0; n   mf += edge[etot].w; n   deledge_((n << 1) + 1), deledge_((n << 1) + 2); n   while (bfs((n << 1) + 1, (n << 1) + 2)) { n     memcpy(cur + 1, fst + 1, ((n << 1) + 4) << 2); n     while ((f = dfs((n << 1) + 1, (n << 1) + 2, 0x7fffffff))) mf += f; n   } n   printf( %lld n , (long long)mf * min(r, b) + (long long)(n - mf) * max(r, b)); n   for (int i = 1; i <= n; ++i) putchar((edge[i << 1].w ^ (r < b)) ?  r  :  b ); n   putchar(10); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nmax = 123456; n int n; n int a[nmax], b[nmax], c[nmax]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) n     if (i == a[i]) { n       printf( YES n ); n       for (int j = 1; j <= n; j++) n         if (j != i) printf( %d %d n , i, j); n       return 0; n     } n   for (int i = 1; i <= n; i++) n     if (i == a[a[i]]) { n       int bb = 0; n       b[i] = 1; n       b[a[i]] = 1; n       for (int j = 1; j <= n; j++) n         if (b[j] != 1) { n           int dd = j; n           int cc = 0; n           while (b[dd] != 1) { n             cc++; n             b[dd] = 1; n             dd = a[dd]; n           } n           bb += cc % 2; n         } n       if (bb >= 1) { n         printf( NO ); n         return 0; n       } else { n         printf( YES n ); n         for (int j = 1; j <= n; j++) b[j] = 0; n         b[i] = 1; n         b[a[i]] = 1; n         int y = i; n         for (int j = 1; j <= n; j++) n           if (b[j] != 1) { n             int x = j; n             while (b[x] != 1) { n               printf( %d %d n , y, x); n               b[x] = 1; n               x = a[x]; n               y = a[y]; n             } n           } n         printf( %d %d , i, a[i]); n         return 0; n       } n     } n   printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long a[5], b[5], n, cu, medal, x, y; n   cin >> a[1] >> a[2] >> a[3]; n   cu = a[1] + a[2] + a[3]; n   cin >> b[1] >> b[2] >> b[3]; n   medal = b[1] + b[2] + b[3]; n   cin >> n; n   if (cu % 5 == 0) n     x = cu / 5; n   else n     x = cu / 5 + 1; n   if (medal % 10 == 0) n     y = medal / 10; n   else n     y = medal / 10 + 1; n   if (n == 1 && cu > 0 && medal > 0 || x + y > n) n     cout <<  NO ; n   else n     cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int si, lef, t0; n int a1, t1, p1; n int a2, t2, p2; n int main() { n   cin >> si >> lef >> t0; n   cin >> a1 >> t1 >> p1; n   cin >> a2 >> t2 >> p2; n   if (t1 > t2) { n     swap(a1, a2); n     swap(t1, t2); n     swap(p1, p2); n   } n   long long ans = 1LL * inf * inf; n   for (int i = 0;; ++i) { n     if ((long long)a1 * t1 * (i - 1) > lef) { n       break; n     } n     long long t = 0; n     if (i && 1LL * a1 * i >= si && 1LL * a1 * (i - 1) < si) { n       t = 1LL * a1 * t1 * (i - 1) + 1LL * (si - 1LL * a1 * (i - 1)) * t1; n       if (t <= lef) { n         ans = min(ans, (long long)p1 * i); n       } n     } else if (1LL * a1 * i < si) { n       t += 1LL * a1 * t1 * i; n       long long ts = si - a1 * i; n       if (t + 1LL * ts * t0 <= lef) { n         ans = min(ans, (long long)p1 * i); n       } else { n         if (t2 < t0) { n           long long byte = (t + 1LL * ts * t0 - lef + t0 - t2 - 1) / (t0 - t2); n           if (byte <= ts) { n             long long bug = (byte + a2 - 1) / a2; n             ans = min(ans, 1LL * i * p1 + 1LL * bug * p2); n           } n         } n       } n     } n   } n   if (ans == 1LL * inf * inf) { n     ans = -1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct comp { n   double x, y; n } a[65600], b[65600], c[65600], fft[65600], tp[17][65600]; n double pi = acos(-1.0); n comp operator+(comp a, comp b) { return (comp){a.x + b.x, a.y + b.y}; } n comp operator-(comp a, comp b) { return (comp){a.x - b.x, a.y - b.y}; } n comp operator*(comp a, comp b) { n   return (comp){a.x * b.x - a.y * b.y, a.y * b.x + b.y * a.x}; n } n comp operator/(comp a, double b) { return (comp){a.x / b, a.y / b}; } n int rev[65600], n, m, p, s[65600][2], as; n void dft(int s, comp *a, int t) { n   for (int i = 0; i < s; i++) n     rev[i] = (rev[i >> 1] >> 1) + (i & 1) * (s >> 1), fft[rev[i]] = a[i]; n   for (int l = 2, lg = 1; l <= s; l <<= 1, lg++) n     for (int j = 0; j < s; j += l) n       for (int k = j; k < j + (l >> 1); k++) { n         comp sp = tp[lg][k - j]; n         if (t == -1) sp.y *= -1; n         comp tp1 = fft[k], tp2 = fft[k + (l >> 1)] * sp; n         fft[k] = tp1 + tp2, fft[k + (l >> 1)] = tp1 - tp2; n       } n   int inv = t == -1 ? s : 1; n   for (int i = 0; i < s; i++) a[i] = fft[i] / inv; n } n void solve(int x) { n   if (x == 0) return; n   if (x == 1) { n     s[1][1] = 1; n     as = 1; n     return; n   } n   int tp = x / 2; n   solve(tp); n   int l = 1; n   while (l <= n * 2 + 1) l <<= 1; n   for (int i = 0; i < l; i++) n     a[i].x = a[i].y = b[i].x = b[i].y = c[i].x = c[i].y = 0; n   for (int i = 1; i <= n; i++) a[i].x = s[i][0], b[i].x = s[i][1]; n   dft(l, a, 1), dft(l, b, 1); n   for (int i = 0; i < l; i++) c[i] = (a[i] + b[i] + (comp){1, 0}) * a[i]; n   dft(l, c, -1); n   for (int i = 1; i <= n; i++) n     s[i][tp & 1] = (s[i][tp & 1] + (long long)(c[i].x + 0.1)) % p; n   for (int i = 0; i < l; i++) c[i] = (a[i] + b[i] + (comp){1, 0}) * b[i]; n   dft(l, c, -1); n   for (int i = 1; i <= n; i++) n     s[i][~tp & 1] = ((long long)(c[i].x + 0.1) + s[i][~tp & 1]) % p; n   if (x & 1) n     for (int i = n; i > 1; i--) n       s[i][1] = (s[i][1] + s[i - 1][1] + s[i - 1][0]) % p; n   if (x & 1) s[1][1] = (s[1][1] + 1) % p; n   for (int i = 1; i <= n; i += 2) as = (as + s[i][1]) % p; n } n void init() { n   for (int i = 1; i < 17; i++) n     for (int j = 0; j < 1 << i; j++) n       tp[i][j] = (comp){cos(2 * pi / (1 << i) * j), sin(2 * pi / (1 << i) * j)}; n } n int main() { n   scanf( %d%d%d , &n, &m, &p); n   init(); n   solve(m / 2); n   printf( %d n , as); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[26]; n int visited[26]; n int p[26], deg[26]; n string ans; n bool fail; n void dfs(int u) { n   visited[u] = 2; n   ans += (char)(u +  a ); n   for (int i = 0; i < (int)g[u].size(); i++) { n     int v = g[u][i]; n     if (visited[v] == 0) { n       p[v] = u; n       dfs(v); n     } else if (visited[v] == 2) { n       if (p[u] != v) { n         fail = true; n       } n     } n   } n   visited[u] = 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int tt; n   cin >> tt; n   while (tt--) { n     string s; n     cin >> s; n     int n = s.size(); n     ans =   ; n     for (int i = 0; i < 26; i++) { n       g[i].clear(); n       visited[i] = 0; n       p[i] = -1; n       deg[i] = 0; n     } n     map<pair<int, int>, int> m; n     for (int i = 1; i < n; i++) { n       int v = (s[i] -  a ); n       int u = (s[i - 1] -  a ); n       int uu = min(u, v); n       int vv = max(u, v); n       if (m[make_pair(uu, vv)] == 0) { n         g[u].push_back(v); n         g[v].push_back(u); n         deg[u]++; n         deg[v]++; n         m[make_pair(uu, vv)]++; n       } n     } n     fail = false; n     for (int i = 0; i < 26; i++) { n       if (deg[i] > 2) { n         fail = true; n       } n       if (!visited[i] && deg[i] < 2) { n         dfs(i); n       } n     } n     if (fail || ans.size() < 26) { n       cout <<  NO  <<   n ; n     } else { n       cout <<  YES  <<   n ; n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int bench, more, temp; n   vector<int> v; n   cin >> bench >> more; n   for (int i = 0; i < bench; i++) { n     cin >> temp; n     v.push_back(temp); n   } n   int min, max = *max_element(v.begin(), v.end()); n   ; n   min = *min_element(v.begin(), v.end()); n   int max_val = max + more; n   for (int i = 0; i < more; i++) { n     sort(v.begin(), v.end()); n     v[0]++; n   } n   std::sort(v.begin(), v.end(), std::greater<int>()); n   int min_val = v[0]; n   cout << min_val <<     << max_val; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 1e6 + 10; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n inline int read() { n   static char buf[1000000], *p1 = buf, *p2 = buf; n   register int x = false; n   register char ch = n       p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n           ? EOF n           : *p1++; n   ; n   register bool sgn = false; n   while (ch !=  -  && (ch <  0  || ch >  9 )) n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   if (ch ==  - ) n     sgn = true, n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   while (ch >=  0  && ch <=  9 ) n     x = (x << 1) + (x << 3) + (ch ^ 48), n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   return sgn ? -x : x; n } n long long fpow(long long a, int b, int mod) { n   long long res = 1; n   for (; b > 0; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long a[N]; n double ans[N]; n long long sum[N]; n int s[N]; n int idx = 1; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     sum[i] = sum[i - 1] + a[i]; n   } n   for (int i = 1; i <= n; i++) { n     while (idx > 1 && (sum[i] - sum[s[idx]]) * (i - s[idx - 1]) <= n                           (sum[i] - sum[s[idx - 1]]) * (i - s[idx])) n       idx--; n     s[++idx] = i; n   } n   for (int i = 2; i <= idx; i++) { n     double res = 1.0 * (sum[s[i]] - sum[s[i - 1]]) / (s[i] - s[i - 1]); n     for (int j = 1; j <= s[i] - s[i - 1]; j++) { n       printf( %.10f n , res); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 10; n int n, k; n int v[MAXN]; n int f[MAXN]; n int search(int num) { n   int l = 1, r = n; n   while (l < r) { n     int mid = (l + r) / 2; n     if (v[mid] < num) { n       l = mid + 1; n     } else { n       r = mid; n     } n   } n   return l; n } n bool check(int len) { n   memset(f, 0, sizeof(f)); n   for (int i = 1; i <= n; i++) { n     int t = search(v[i] - len); n     if (t == 1 && i - t + 1 >= k) { n       if (i == n) { n         return true; n       } n       f[i] += f[i - 1] + 1; n     } else if (t >= 2 && i - t + 1 >= k && f[i - k] - f[t - 2] > 0) { n       if (i == n) { n         return true; n       } n       f[i] += f[i - 1] + 1; n     } else { n       f[i] = f[i - 1]; n     } n   } n   return false; n } n int main(int argc, const char* argv[]) { n   scanf( %d , &(n)); n   scanf( %d , &(k)); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &(v[i])); n   } n   sort(v + 1, v + 1 + n); n   int l = 0, r = 1000000000; n   while (l < r) { n     int mid = (l + r) / 2; n     if (check(mid)) { n       r = mid; n     } else { n       l = mid + 1; n     } n   } n   printf( %d n , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   bool visited; n   short prex; n   short prey; n   short val; n   node() { visited = false; } n   void print() { n     cout << visited <<   (  << prex <<  ,   << prey <<  )   << val << endl; n   } n }; n struct coord { n   int x, y; n   coord(int x, int y) { n     this->x = x; n     this->y = y; n   } n }; n class SpecialNum { n  public: n   SpecialNum(int d, int s) { n     this->d = d; n     this->s = s; n     init(); n   } n   bool get() { return get(0, s); } n   bool get(int x, int y); n  n  private: n   int d, s; n   node** table = 0; n   void init() { n     table = new node*[d]; n     for (int i = 0; i < d; i++) table[i] = new node[s + 1]; n     bfs(); n   } n   void bfs(); n }; n void SpecialNum::bfs() { n   queue<coord> que; n   int nextx = 0, nexty = 0; n   que.push(coord(0, 0)); n   while (!que.empty()) { n     coord cur = que.front(); n     que.pop(); n     for (int i = 0; i < 10; i++) { n       nextx = (10 * cur.x + i) % d; n       nexty = cur.y + i; n       if (table[nextx][nexty].visited || nexty > s) continue; n       table[nextx][nexty].visited = true; n       table[nextx][nexty].prex = cur.x; n       table[nextx][nexty].prey = cur.y; n       table[nextx][nexty].val = i; n       que.push(coord(nextx, nexty)); n     } n   } n } n bool SpecialNum::get(int x, int y) { n   if (!table[x][y].visited || (x == 0 && y == 0)) return false; n   get(table[x][y].prex, table[x][y].prey); n   cout << table[x][y].val; n   return true; n } n int main() { n   int d, s; n   cin >> d >> s; n   SpecialNum* sn = new SpecialNum(d, s); n   if (!sn->get()) cout << -1; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n void chis(int x) { n   switch (x) { n     case 0: n       cout <<  zero  << endl; n       break; n     case 1: n       cout <<  one  << endl; n       break; n     case 2: n       cout <<  two  << endl; n       break; n     case 3: n       cout <<  three  << endl; n       break; n     case 4: n       cout <<  four  << endl; n       break; n     case 5: n       cout <<  five  << endl; n       break; n     case 6: n       cout <<  six  << endl; n       break; n     case 7: n       cout <<  seven  << endl; n       break; n     case 8: n       cout <<  eight  << endl; n       break; n     case 9: n       cout <<  nine  << endl; n       break; n   } n } n void chis2(int x) { n   switch (x) { n     case 2: n       cout <<  twenty ; n       break; n     case 3: n       cout <<  thirty ; n       break; n     case 4: n       cout <<  forty ; n       break; n     case 5: n       cout <<  fifty ; n       break; n     case 6: n       cout <<  sixty ; n       break; n     case 7: n       cout <<  seventy ; n       break; n     case 8: n       cout <<  eighty ; n       break; n     case 9: n       cout <<  ninety ; n       break; n   } n } n void chis3(int x) { n   switch (x) { n     case 10: n       cout <<  ten  << endl; n       break; n     case 11: n       cout <<  eleven  << endl; n       break; n     case 12: n       cout <<  twelve  << endl; n       break; n     case 13: n       cout <<  thirteen  << endl; n       break; n     case 14: n       cout <<  fourteen  << endl; n       break; n     case 15: n       cout <<  fifteen  << endl; n       break; n     case 16: n       cout <<  sixteen  << endl; n       break; n     case 17: n       cout <<  seventeen  << endl; n       break; n     case 18: n       cout <<  eighteen  << endl; n       break; n     case 19: n       cout <<  nineteen  << endl; n       break; n   } n } n void read() { n   cin >> n; n   if (n <= 9) n     chis(n); n   else { n     int des = n / 10; n     if (des == 1) n       chis3(n); n     else { n       chis2(des); n       int ost = n % 10; n       if (ost == 0) n         cout << endl; n       else { n         cout <<  - ; n         chis(ost); n       } n     } n   } n } n int main() { n   read(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   if (n == 1) n     cout <<  1 ; n   else if (n <= 5 && n != 3) n     cout <<  3 ; n   else if (n <= 13) n     cout <<  5 ; n   else if (n <= 25) n     cout <<  7 ; n   else if (n <= 41) n     cout <<  9 ; n   else if (n <= 61) n     cout <<  11 ; n   else if (n <= 85) n     cout <<  13 ; n   else n     cout <<  15 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n, x, y, a, b; n   cout <<  YES n ; n   cin >> n; n   while (n--) { n     cin >> x >> y >> a >> b; n     cout << (abs(2 * (x % 2)) + abs(y % 2)) + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a, b, ms[111][111], d[111], w[111], dd[111]; n double f[111], ff[111], ans; n int main() { n   cin >> n >> m; n   memset(ms, 63, sizeof(ms)); n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     ms[a][b] = ms[b][a] = 1; n   } n   memset(d, 63, sizeof(d)); n   d[0] = 0; n   f[0] = 1; n   memset(w, 0, sizeof(w)); n   for (int i = 0; i < n; i++) { n     int o = 1e9, l; n     for (int i = 0; i < n; i++) n       if (!w[i] && d[i] < o) o = d[i], l = i; n     w[l] = 1; n     for (int i = 0; i < n; i++) n       if (o + ms[l][i] < d[i]) { n         d[i] = o + ms[l][i]; n         f[i] = f[l]; n       } else if (o + ms[l][i] == d[i]) n         f[i] += f[l]; n   } n   memset(dd, 63, sizeof(dd)); n   dd[n - 1] = 0; n   ff[n - 1] = 1; n   memset(w, 0, sizeof(w)); n   for (int i = 0; i < n; i++) { n     int o = 1e9, l; n     for (int i = 0; i < n; i++) n       if (!w[i] && dd[i] < o) o = dd[i], l = i; n     w[l] = 1; n     for (int i = 0; i < n; i++) n       if (o + ms[l][i] < dd[i]) { n         dd[i] = o + ms[l][i]; n         ff[i] = ff[l]; n       } else if (o + ms[l][i] == dd[i]) n         ff[i] += ff[l]; n   } n   for (int i = 0; i < n; i++) { n     double o = 0; n     for (int j = 0; j < n; j++) n       if (ms[i][j] == 1) { n         if (d[i] + 1 + dd[j] == d[n - 1]) o += f[i] * ff[j]; n         if (dd[i] + 1 + d[j] == d[n - 1]) o += ff[i] * f[j]; n       } n     ans = max(ans, o); n   } n   printf( %.10lf n , ans / f[n - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3; n int a[N]; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + 1 + n); n   cout << a[n - k + 1]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int d, L, v1, v2; n   cin >> d >> L >> v1 >> v2; n   printf( %lf n , 1.0 * (L - d) / (v1 + v2)); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 77, Mod = 1e9 + 7; n int n, d1[N], d2[N], P1, P2, Mx, deg[N], p1[N], p2[N]; n long long A; n vector<pair<int, pair<int, int> > > R; n vector<int> a[N]; n void dfs(int v, int prev, bool t) { n   for (int u : a[v]) { n     if (u == prev) { n       continue; n     } n     if (t) { n       d1[u] = d1[v] + 1; n       p1[u] = v; n     } else { n       d2[u] = d2[v] + 1; n       p2[u] = v; n     } n     dfs(u, v, t); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int v, u; n     scanf( %d %d , &v, &u); n     deg[v]++; n     deg[u]++; n     a[v].push_back(u); n     a[u].push_back(v); n   } n   dfs(1, 1, 1); n   for (int i = 1; i <= n; i++) { n     if (d1[i] > Mx) { n       Mx = d1[i]; n       P1 = i; n     } n   } n   d1[P1] = 0; n   dfs(P1, P1, 1); n   Mx = 0; n   for (int i = 1; i <= n; i++) { n     if (d1[i] > Mx) { n       Mx = d1[i]; n       P2 = i; n     } n   } n   dfs(P2, P2, 0); n   vector<int> Leaves; n   for (int i = 1; i <= n; i++) { n     if (i == P1 || i == P2 || deg[i] > 1) continue; n     Leaves.push_back(i); n   } n   while (Leaves.size()) { n     int v = Leaves.back(); n     Leaves.pop_back(); n     if (d1[v] >= d2[v]) { n       A += d1[v]; n       R.push_back(make_pair(v, make_pair(P1, v))); n     } else { n       A += d2[v]; n       R.push_back(make_pair(v, make_pair(P2, v))); n     } n     deg[v]--; n     for (int u : a[v]) { n       deg[u]--; n       if (deg[u] == 1) Leaves.push_back(u); n     } n   } n   while (p2[P1]) { n     R.push_back(make_pair(P1, make_pair(P2, P1))); n     A += d2[P1]; n     P1 = p2[P1]; n   } n   printf( %I64d n , A); n   for (auto x : R) n     printf( %d %d %d n , x.first, x.second.first, x.second.second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int a, b, c; n   cin >> a >> b >> c; n   long int temp = b - a; n   if (c == 0 || b == a) { n     if (b == a) n       cout <<  YES ; n     else n       cout <<  NO ; n   } else if (temp % c == 0) { n     if ((temp < 0 && c < 0) || (temp > 0 && c > 0)) n       cout <<  YES ; n     else n       cout <<  NO ; n   } else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, j, k, m, n, t, x; n string s, u; n int main() { n   for (scanf( %lld , &t); t--;) { n     i = 1; n     cin >> x >> s; n     for (; s.size() < x; i++) { n       if (s[i - 1] > 49) { n         u = s.substr(i); n         for (k = s[i - 1] - 48; --k;) s += u; n       } n     } n     m = s.size(); n     for (; i <= x; i++) n       m = (m + (s[i - 1] - 49) * (m - i + 1000000007)) % 1000000007; n     cout << m << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = acos(-1.0); n template <typename T> n T abs(T x) { n   return x > 0 ? x : -x; n } n template <typename T> n T sqr(T x) { n   return x * x; n } n template <typename T> n bool chmin(T &x, T y) { n   if (x > y) { n     x = y; n     return true; n   } n   return false; n } n template <typename T> n bool chmax(T &x, T y) { n   if (x < y) { n     x = y; n     return true; n   } n   return false; n } n template <typename U, typename V> n ostream &operator<<(ostream &s, const pair<U, V> &x) { n   s <<  (  << x.fst <<  ,   << x.snd <<  ) ; n   return s; n } n template <typename U> n ostream &operator<<(ostream &s, const vector<U> &x) { n   s <<  [ ; n   bool was = false; n   for (auto it : x) { n     if (was) { n       s <<  ,  ; n     } n     was = true; n     s << it; n   } n   s <<  ] ; n   return s; n } n template <typename U> n ostream &operator<<(ostream &s, const set<U> &x) { n   s <<  { ; n   bool was = false; n   for (auto it : x) { n     if (was) { n       s <<  ,  ; n     } n     was = true; n     s << it; n   } n   s <<  } ; n   return s; n } n template <int sz> n ostream &operator<<(ostream &s, const bitset<sz> &x) { n   for (int i = 0; i < sz; i++) { n     s << x[i]; n   } n   return s; n } n int main() { n   srand(time(0)); n   int k; n   cin >> k; n   int maxi = 25; n   while (k--) { n     int p; n     cin >> p; n     chmax(maxi, p); n   } n   cout << maxi - 25 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, A, cf, cm, m; n long long L, ans[100005], f, ansA, ansL; n long long s[100005]; n struct data { n   long long id, v; n } a[100005]; n bool cmp(data a, data b) { return a.v < b.v || a.v == b.v && a.id < b.id; } n long long findL(long long m, long long R) { n   long long l = 0, r = A, ans = 0; n   while (l <= r) { n     long long mid = (l + r) >> 1; n     int p = lower_bound(a + 1, a + n + 1, (data){0, mid}, cmp) - a - 1; n     if (p > R) p = R; n     if (p * mid - s[p] <= m) { n       ans = mid; n       l = mid + 1; n     } else n       r = mid - 1; n   } n   return ans; n } n void init() { n   cin >> n >> A >> cf >> cm >> m; n   for (int i = 1; i <= n; i++) { n     cin >> a[i].v; n     a[i].id = i; n   } n   sort(a + 1, a + n + 1, cmp); n   for (int i = 1; i <= n; i++) { n     s[i] = s[i - 1] + a[i].v; n   } n   for (int i = 0; i <= n; i++) { n     long long p = A * i - s[n] + s[n - i]; n     if (p <= m) { n       L = findL(m - p, n - i); n       if (cm * L + cf * i > f) { n         f = cm * L + cf * i; n         ansA = i; n         ansL = L; n       } n     } n   } n   cout << f << endl; n   for (int j = 1; j <= n; j++) { n     if (j > n - ansA) { n       ans[a[j].id] = A; n     } else if (a[j].v <= ansL) { n       ans[a[j].id] = ansL; n     } else n       ans[a[j].id] = a[j].v; n   } n   for (int i = 1; i <= n; i++) { n     cout << ans[i] <<    ; n   } n } n int main() { n   init(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3E5 + 7, mod = 998244353; n long long n, a[N], inv[N], ans; n signed main() { n   scanf( %lld , &n); n   for (long long i = 1; i <= n << 1; i++) scanf( %lld , &a[i]); n   sort(a + 1, a + 2 * n + 1); n   for (long long i = 1; i <= n; i++) ans = (ans - a[i] + mod) % mod; n   for (long long i = n + 1; i <= n << 1; i++) ans = (ans + a[i]) % mod; n   for (long long i = n << 1; i >= n + 1; i--) ans = ans * i % mod; n   inv[1] = 1; n   for (long long i = 2; i <= n; i++) { n     inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod; n     ans = 1ll * ans * inv[i] % mod; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int n; n   cin >> n; n   int a[n], b[n], i; n   for (i = 0; i < n; ++i) cin >> a[i] >> b[i]; n   for (i = 0; i < n; ++i) { n     if (a[i] != b[i]) break; n   } n   if (i == n) { n     for (i = 1; i < n; ++i) { n       if (a[i] <= a[i - 1]) n         continue; n       else n         break; n     } n     if (i == n) n       cout <<  maybe ; n     else n       cout <<  unrated ; n   } else n     cout <<  rated ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int MOD = 1000000007; n template <typename T, typename U> n std::istream& operator>>(std::istream& i, pair<T, U>& p) { n   i >> p.first >> p.second; n   return i; n } n template <typename T> n std::istream& operator>>(std::istream& i, vector<T>& t) { n   for (auto& v : t) { n     i >> v; n   } n   return i; n } n template <typename T> n std::ostream& operator<<(std::ostream& o, const vector<T>& t) { n   for (size_t i = 0; i < t.size(); ++i) { n     o << t[i] <<    n [i == t.size() - 1]; n   } n   return o; n } n template <typename T> n using minheap = priority_queue<T, vector<T>, greater<T>>; n template <typename T> n using maxheap = priority_queue<T, vector<T>, less<T>>; n auto fraclt = [](const std::pair<int, int>& a, const std::pair<int, int>& b) { n   return (long long)a.first * b.second < (long long)b.first * a.second; n }; n struct cmpfrac { n   bool operator()(const std::pair<int, int>& a, n                   const std::pair<int, int>& b) const { n     return (long long)a.first * b.second < (long long)b.first * a.second; n   } n }; n template <typename T> n bool in(T a, T b, T c) { n   return a <= b && b < c; n } n unsigned int logceil(long long first) { n   unsigned int b = 0; n   while (first) { n     first >>= 1; n     ++b; n   } n   return b; n } n namespace std { n template <typename T, typename U> n struct hash<pair<T, U>> { n   hash<T> t; n   hash<U> u; n   size_t operator()(const pair<T, U>& p) const { n     return t(p.first) ^ (u(p.second) << 7); n   } n }; n }  // namespace std n template <typename T, typename F> n T bsh(T l, T h, const F& f) { n   T r = -1, m; n   while (l <= h) { n     m = (l + h) / 2; n     if (f(m)) { n       l = m + 1; n       r = m; n     } else { n       h = m - 1; n     } n   } n   return r; n } n template <typename T, typename F> n T bsl(T l, T h, const F& f) { n   T r = -1, m; n   while (l <= h) { n     m = (l + h) / 2; n     if (f(m)) { n       h = m - 1; n       r = m; n     } else { n       l = m + 1; n     } n   } n   return r; n } n template <typename T> n T gcd(T a, T b) { n   if (a < b) swap(a, b); n   return b ? gcd(b, a % b) : a; n } n template <typename T> n class vector2 : public vector<vector<T>> { n  public: n   vector2() {} n   vector2(size_t a, size_t b, T t = T()) n       : vector<vector<T>>(a, vector<T>(b, t)) {} n }; n template <typename T> n class vector3 : public vector<vector<vector<T>>> { n  public: n   vector3() {} n   vector3(size_t a, size_t b, size_t c, T t = T()) n       : vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, t))) {} n }; n template <typename T> n struct bounded_priority_queue { n   inline bounded_priority_queue(unsigned int X) : A(X), B(0) {} n   inline void push(unsigned int L, T V) { n     B = max(B, L); n     A[L].push(V); n   } n   inline const T& top() const { return A[B].front(); } n   inline void pop() { n     A[B].pop(); n     while (B > 0 && A[B].empty()) --B; n   } n   inline bool empty() const { return A[B].empty(); } n   inline void clear() { n     B = 0; n     for (auto& a : A) a = queue<T>(); n   } n  n  private: n   vector<queue<T>> A; n   unsigned int B; n }; n struct UnionFind { n   UnionFind(size_t N) : P(N, -1), comp(N) {} n   int find(int first) { n     while (P[first] >= 0) { n       first = P[first]; n     } n     return first; n   } n   bool united(int first, int second) { return find(first) == find(second); } n   bool unite(int first, int second) { n     first = find(first); n     second = find(second); n     if (first == second) { n       return false; n     } n     --comp; n     if (P[first] > P[second]) { n       swap(first, second); n     } n     P[first] += P[second]; n     P[second] = first; n     return true; n   } n   vector<int> P; n   size_t comp; n }; n unsigned long long mulull(unsigned long long a, unsigned long long z, n                           unsigned long long mod) { n   __int128 result = ((__int128)a * (__int128)z) % (__int128)mod; n   return (unsigned long long)result; n } n pair<unsigned long long, unsigned long long> mulull(unsigned long long a, n                                                     unsigned long long b) { n   __int128 result = (__int128)a * (__int128)b; n   return {(unsigned long long)(result >> 64), (unsigned long long)result}; n } n bool fractionGreaterOrEqual(long long a, long long b, long long c, n                             long long d) { n   if (b < 0) { n     b = -b; n     a = -a; n   } n   if (d < 0) { n     d = -d; n     c = -c; n   } n   return a < 0 && c < 0 ? mulull(-a, d) <= mulull(-c, b) n                         : (a >= 0) && (c < 0 || mulull(a, d) >= mulull(c, b)); n } n bool fractionGreaterOrEqual(double a, double b, double c, double d) { n   return a / b >= c / d; n } n namespace Envelope { n template <typename T> n struct Line { n   T m, b; n   mutable function<const Line<T>*()> succ; n   bool operator<(const Line& rhs) const { n     if (rhs.b != numeric_limits<T>::min()) return m < rhs.m; n     const Line* s = succ(); n     if (!s) return 0; n     return b - s->b < (s->m - m) * rhs.m; n   } n }; n template <typename T> n struct Upper : public multiset<Envelope::Line<T>> { n   using parent = multiset<Line<T>>; n   bool bad(typename parent::iterator second) { n     auto z = next(second); n     if (second == parent::begin()) { n       return z != parent::end() && second->m == z->m && second->b <= z->b; n     } else { n       auto first = prev(second); n       if (z == parent::end()) { n         return second->m == first->m && second->b <= first->b; n       } else { n         return fractionGreaterOrEqual(first->b - second->b, n                                       second->m - first->m, second->b - z->b, n                                       z->m - second->m); n       } n     } n   } n   void insert_line(T m, T b) { n     auto second = parent::insert({m, b}); n     second->succ = [=] { n       return next(second) == parent::end() ? 0 : &*next(second); n     }; n     if (bad(second)) { n       parent::erase(second); n       return; n     } n     while (next(second) != parent::end() && bad(next(second))) n       parent::erase(next(second)); n     while (second != parent::begin() && bad(prev(second))) n       parent::erase(prev(second)); n   } n   T operator[](T first) const { n     auto l = parent::lower_bound({first, numeric_limits<T>::min()}); n     return l == parent::end() ? numeric_limits<T>::min() : l->m * first + l->b; n   } n }; n template <typename T> n struct Lower : public Upper<T> { n   void insert_line(T m, T b) { Upper<T>::insert_line(-m, -b); } n   T operator[](T first) const { return -Upper<T>::operator[](first); } n }; n }  // namespace Envelope n struct Sieve : public std::vector<bool> { n   explicit Sieve(unsigned int n) : vector<bool>(n + 1, true), n(n) { n     at(0) = false; n     at(1) = false; n     for (unsigned int i = 2; i * i <= n; ++i) { n       if (at(i)) n         for (int j = i * i; j <= n; j += i) (*this)[j] = false; n     } n   } n   vector<int> primes() const { n     vector<int> ans; n     for (int i = 2; i <= n; ++i) n       if (at(i)) ans.push_back(i); n     return ans; n   } n  n  private: n   int n; n }; n struct Moebius : public std::vector<std::pair<int, int>> { n   explicit Moebius(unsigned int n) : Moebius(n, Sieve{n}.primes()) {} n   Moebius(int n, const vector<int>& primes) { n     search(-1, 1, 1, n, primes); n     std::sort(begin(), end()); n   } n  n  private: n   void search(int i, int first, int second, int n, const vector<int>& primes) { n     push_back({first, second}); n     while (++i < primes.size() && (long long)first * primes[i] <= n) n       search(i, first * primes[i], -second, n, primes); n   } n }; n struct LargePrimes : public vector<int> { n   LargePrimes() n       : vector<int>{ n             7,     9,     21,    33,    87,    93,    97,    103,   123, n             181,   207,   223,   241,   271,   289,   297,   321,   349, n             363,   403,   409,   411,   427,   433,   439,   447,   453, n             459,   483,   513,   531,   579,   607,   613,   637,   663, n             711,   753,   787,   801,   829,   861,   871,   891,   901, n             919,   931,   933,   993,   1011,  1021,  1053,  1087,  1099, n             1137,  1161,  1203,  1213,  1237,  1263,  1269,  1273,  1279, n             1311,  1329,  1333,  1351,  1371,  1393,  1413,  1447,  1449, n             1491,  1501,  1531,  1537,  1539,  1581,  1617,  1621,  1633, n             1647,  1663,  1677,  1699,  1759,  1773,  1789,  1791,  1801, n             1803,  1819,  1857,  1887,  1917,  1927,  1957,  1963,  1969, n             2043,  2089,  2103,  2139,  2149,  2161,  2173,  2187,  2193, n             2233,  2239,  2277,  2307,  2359,  2361,  2431,  2449,  2457, n             2499,  2571,  2581,  2607,  2631,  2637,  2649,  2667,  2727, n             2791,  2803,  2821,  2823,  2827,  2907,  2937,  2989,  3009, n             3013,  3051,  3057,  3097,  3111,  3133,  3153,  3157,  3163, n             3211,  3241,  3247,  3253,  3267,  3271,  3273,  3283,  3309, n             3337,  3351,  3357,  3373,  3379,  3397,  3469,  3471,  3513, n             3519,  3559,  3577,  3579,  3601,  3621,  3643,  3651,  3663, n             3679,  3709,  3747,  3751,  3769,  3777,  3787,  3793,  3843, n             3853,  3871,  3889,  3891,  3909,  3919,  3931,  3951,  3957, n             3967,  3987,  3999,  4023,  4059,  4099,  4119,  4123,  4207, n             4233,  4249,  4251,  4263,  4321,  4329,  4381,  4389,  4437, n             4449,  4459,  4497,  4507,  4519,  4539,  4567,  4569,  4581, n             4609,  4611,  4627,  4633,  4647,  4693,  4699,  4717,  4771, n             4777,  4783,  4791,  4807,  4839,  4843,  4849,  4857,  4867, n             4869,  4891,  4893,  4897,  4927,  4933,  4977,  4981,  5001, n             5029,  5053,  5067,  5103,  5133,  5187,  5197,  5203,  5233, n             5277,  5287,  5299,  5317,  5329,  5341,  5353,  5361,  5403, n             5407,  5437,  5443,  5449,  5451,  5469,  5491,  5527,  5541, n             5547,  5583,  5631,  5647,  5683,  5731,  5737,  5751,  5763, n             5791,  5823,  5827,  5833,  5847,  5863,  5899,  5907,  5947, n             5953,  5959,  5971,  5973,  5991,  5997,  6019,  6027,  6037, n             6039,  6061,  6093,  6099,  6127,  6129,  6177,  6193,  6211, n             6223,  6229,  6307,  6313,  6331,  6349,  6379,  6393,  6417, n             6421,  6457,  6459,  6477,  6541,  6571,  6577,  6583,  6607, n             6621,  6661,  6663,  6697,  6717,  6751,  6781,  6837,  6867, n             6901,  6957,  6961,  6967,  6981,  7003,  7023,  7027,  7089, n             7117,  7137,  7147,  7159,  7191,  7209,  7237,  7243,  7257, n             7279,  7321,  7347,  7383,  7389,  7417,  7429,  7447,  7453, n             7467,  7479,  7497,  7513,  7521,  7531,  7537,  7557,  7633, n             7647,  7651,  7653,  7681,  7707,  7719,  7741,  7759,  7773, n             7803,  7819,  7837,  7873,  7887,  7909,  7923,  7927,  7929, n             7941,  8041,  8083,  8089,  8101,  8109,  8127,  8173,  8181, n             8223,  8257,  8259,  8271,  8277,  8311,  8313,  8343,  8349, n             8397,  8403,  8419,  8431,  8439,  8487,  8511,  8557,  8593, n             8617,  8637,  8649,  8661,  8671,  8679,  8719,  8727,  8761, n             8773,  8791,  8797,  8803,  8811,  8829,  8853,  8899,  8917, n             8937,  8967,  9009,  9013,  9063,  9081,  9093,  9099,  9123, n             9133,  9163,  9183,  9211,  9223,  9259,  9277,  9279,  9289, n             9301,  9321,  9331,  9363,  9399,  9403,  9421,  9441,  9457, n             9469,  9487,  9519,  9529,  9531,  9541,  9559,  9561,  9567, n             9573,  9579,  9597,  9601,  9609,  9631,  9651,  9667,  9679, n             9711,  9733,  9739,  9757,  9789,  9831,  9859,  9867,  9961, n             9999,  10029, 10051, 10069, 10101, 10153, 10173, 10189, 10197, n             10233, 10243, 10251, 10267, 10281, 10303, 10321, 10327, 10351, n             10357, 10381, 10449, 10467, 10483, 10503, 10513, 10549, 10593, n             10597, 10611, 10633, 10659, 10699, 10707, 10723, 10747, 10749, n             10761, 10773, 10777, 10801, 10833, 10903, 10953, 10969, 10971, n             10981, 10987, 11007, 11011, 11071, 11083, 11091, 11107, 11109, n             11137, 11149, 11161, 11223, 11239, 11253, 11269, 11277, 11283, n             11289, 11301, 11317, 11329, 11371, 11377, 11391, 11421, 11479, n             11487, 11497, 11517, 11533, 11539, 11559, 11583, 11601, 11619, n             11631, 11659, 11673, 11679, 11707, 11763, 11767, 11769, 11773, n             11799, 11811, 11821, 11823, 11847, 11869, 11967, 11983, 11989, n             12019, 12037, 12121, 12157, 12177, 12187, 12217, 12219, 12231, n             12241, 12253, 12297, 12309, 12333, 12337, 12339, 12361, 12367, n             12399, 12411, 12459, 12463, 12483, 12501, 12513, 12523, 12547, n             12553, 12577, 12609, 12631, 12649, 12679, 12681, 12703, 12723, n             12733, 12747, 12753, 12759, 12799, 12847, 12877, 12891, 12901, n             12903, 12927, 12939, 12963, 13011, 13017, 13029, 13039, 13081, n             13087, 13089, 13101, 13107, 13137, 13141, 13143, 13153, 13191, n             13207, 13213, 13237, 13323, 13369, 13419, 13437, 13447, 13477, n             13519, 13537, 13561, 13563, 13587, 13591, 13723, 13741, 13759, n             13789, 13801, 13857, 13881, 13897, 13921, 13923, 13939, 13999, n             14011, 14073, 14077, 14083, 14097, 14121, 14131, 14143, 14157, n             14161, 14167, 14181, 14193, 14209, 14241, 14259, 14271, 14293, n             14361, 14391, 14397, 14437, 14529, 14551, 14581, 14583, 14599, n             14607, 14611, 14643, 14727, 14761, 14773, 14779, 14791, 14823, n             14853, 14881, 14889, 14901, 14931, 14937, 14997, 15031, 15043, n             15057, 15063, 15069, 15097, 15103, 15109, 15117, 15141, 15147, n             15187, 15199, 15217, 15231, 15253, 15271, 15279, 15283, 15307, n             15339, 15349, 15351, 15363, 15369, 15409, 15427, 15447, 15477, n             15487, 15553, 15579, 15591, 15649, 15651, 15673, 15693, 15703, n             15717, 15727, 15747, 15799, 15811, 15823, 15859, 15889, 15963, n             15981, 16009, 16021, 16029, 16047, 16063, 16089, 16093, 16107, n             16153, 16167, 16191, 16201, 16231, 16233, 16261, 16267, 16273, n             16317, 16323, 16411, 16419, 16431, 16489, 16491, 16513, 16539, n             16617, 16621, 16623, 16627, 16651, 16659, 16671, 16711} { n     for (int& i : *this) i += 1000000000; n   } n }; n bool isPrime(long long n) { n   for (int p : n        {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,  43, n         47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101, 103, 107, n         109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, n         191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257}) n     if (p < n && n % p == 0) return false; n   long long d = n - 1, r = 0; n   while (d % 2 == 0) { n     d /= 2; n     r += 1; n   } n   auto composite = [=](int a) { n     long long first = 1, p = a, e = d; n     while (e > 0) { n       if (e % 2 > 0) { n         first = mulull(first, p, n); n       } n       e /= 2; n       p = mulull(p, p, n); n     } n     if (first == 1 || first == n - 1) return false; n     for (int i = 1; i < r; ++i) { n       first = mulull(first, first, n); n       if (first == 1) return true; n       if (first == n - 1) return false; n     } n     return true; n   }; n   return !(composite(2)) && (n < 2047 || !composite(3)) && n          (n < 1373653 || !composite(5)) && (n < 25326001 || !composite(7)) && n          (n < 3215031751LL || !composite(11)) && n          (n < 2152302898747LL || !composite(13)) && n          (n < 3474749660383LL || !composite(17)) && n          (n < 341550071728321LL || (!composite(19) && !composite(23))) && n          (n < 3825123056546413051LL || n           (!composite(29) && !composite(31) && !composite(37))); n } n class TaskB { n  public: n   void solve(istream& cin, ostream& cout) { n     int N, X, Y; n     cin >> N >> X >> Y; n     vector<int> C(2000001, 0), PC(2000001, 0); n     vector<long long> S(2000001, 0), PS(2000001, 0); n     for (int i = 0; i < N; ++i) { n       int a; n       cin >> a; n       C[a]++; n       S[a] += a; n     } n     for (int i = 1; i < 2000001; ++i) { n       PC[i] = PC[i - 1] + C[i]; n       PS[i] = PS[i - 1] + S[i]; n     } n     int maxDiff = X / Y + 1; n     long long ans = numeric_limits<long long>::max(); n     for (int p : Sieve{1000000}.primes()) { n       long long cost = 0; n       for (int i = p; i - p <= 1000000; i += p) { n         cost += Y * ((long long)i * (PC[i] - PC[i - min(maxDiff, p)]) - n                      (PS[i] - PS[i - min(p, maxDiff)])); n         cost += X * (long long)(PC[i - min(maxDiff, p)] - PC[i - p]); n       } n       ans = min(ans, cost); n     } n     cout << ans << endl; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   TaskB solver; n   std::istream& in(std::cin); n   std::ostream& out(std::cout); n   solver.solve(in, out); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n; n   char a[1000][10]; n   cin >> n; n   cin >> a[0]; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   if (n % 2 == 0) n     cout <<  home ; n   else n     cout <<  contest ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> v[1010]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     int aux, aux2; n     scanf( %d , &aux); n     for (int j = 0; j < aux; ++j) { n       scanf( %d , &aux2); n       v[i].push_back(aux2); n     } n     sort(v[i].begin(), v[i].end()); n   } n   int r = 0; n   for (int i = 0; i < n; ++i) { n     int pnt1 = 0, pnt2 = 0; n     int pr = (i - 1 + n) % n, ne = (i + 1) % n; n     for (int j = 0; j < v[i].size() - 1; ++j) { n       int q1 = 0, q2 = 0; n       while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j]) pnt1++; n       while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j + 1]) pnt1++, q1++; n       while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j]) pnt2++; n       while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j + 1]) pnt2++, q2++; n       if (q1 != q2) r++; n     } n   } n   printf( %d n , r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int b[111111], n; n int check(int k) { n   int l = n / k; n   for (int i = 0; i < l; i++) { n     int ok = 1; n     int cur = i; n     for (int j = 0; ok && j < k; j++) { n       if (!b[cur]) ok = 0; n       cur += l; n       cur %= n; n     } n     if (ok) return 1; n   } n   return 0; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> b[i]; n   int flag = 0; n   for (int i = 3; i <= n; i++) { n     if (n % i == 0) { n       if (check(i)) flag = 1; n     } n   } n   printf(flag ?  YES n  :  NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, b, h; n   cin >> a >> b; n   h = (b * b - a * a) / (2 * a); n   h = h + (1 / 1000000); n   cout << fixed << setprecision(13) << h << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int a[3]; n   int s = 0; n   int count = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 3; j++) { n       cin >> a[j]; n       if (a[j] == 1) count++; n     } n     if (count >= 2) s++; n     count = 0; n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void amin(T &a, const T &b) { n   if (b < a) a = b; n } n template <class T> n inline void amax(T &a, const T &b) { n   if (a < b) a = b; n } n struct Data { n   int sx, sy; n   int le, ri, to, bo; n   bool operator<(const Data &y) const { return sx < y.sx; } n }; n int N, Q; n int main() { n   scanf( %d%d , &N, &Q); n   set<Data> S; n   S.insert((Data){1, 1, 1, N, 1, N}); n   Data seek; n   for (int $ = 0, $_len = (Q); $ < $_len; ++$) { n     int col, row; n     char buf[8], dir; n     scanf( %d%d%s , &col, &row, buf); n     dir = buf[0]; n     int ans = 0; n     seek.sx = col; n     set<Data>::iterator it = S.upper_bound(seek); n     if (it != S.begin()) { n       it--; n       if (it->sx <= col && col <= it->ri) { n         Data D = *it; n         S.erase(it); n         if (dir ==  U ) { n           ans = row - D.to + 1; n           if (D.sx < col) n             S.insert((Data){D.sx, row + 1, D.le, col - 1, D.to, D.bo}); n           if (col < D.ri) n             S.insert((Data){col + 1, D.sy, col + 1, D.ri, D.to, row - 1}); n         } else { n           ans = col - D.le + 1; n           if (D.sy < row) n             S.insert((Data){col + 1, D.sy, D.le, D.ri, D.to, row - 1}); n           if (row < D.bo) n             S.insert((Data){D.sx, row + 1, D.le, col - 1, row + 1, D.bo}); n         } n       } else { n         ans = 0; n       } n     } else { n       ans = 0; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include<cstdio> n #include<cstring> n #include<vector> n typedef long long ll; n int main() n { n     int t,a[120]; n     scanf( %d ,&t); n     while(t--) n     { n         int n,u,v; n         scanf( %d%d%d ,&n,&u,&v); n  n         for(int i=1;i<=n;i++) n         { n            scanf( %d ,&a[i]); n         } n         int j,b=0; n         for(j=2;j<=n;j++) n         { n             if(a[j]==a[j-1]+1||a[j]==a[j-1]-1) n                 {b=1;} n             if(a[j]>a[j-1]+1||a[j]<a[j-1]-1) n             { n                 b=2;break; n             } n         } n         if(b==0) n            { n                if(u<v) n         printf( %d n ,u+v); n         else n             printf( %d n ,2*v); n            } n         else if(b==2) n         { n             printf( 0 n ); n         } n         else n         { n             if(u>v)printf( %d n ,v); n             else printf( %d n ,u); n         } n     } n     return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n inline long long getint() { n   long long _x = 0, _tmp = 1; n   char _tc = getchar(); n   while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar(); n   if (_tc ==  - ) _tc = getchar(), _tmp = -1; n   while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar(); n   return _x * _tmp; n } n inline long long add(long long _x, long long _y, n                      long long _mod = 1000000007LL) { n   _x += _y; n   return _x >= _mod ? _x - _mod : _x; n } n inline long long sub(long long _x, long long _y, n                      long long _mod = 1000000007LL) { n   _x -= _y; n   return _x < 0 ? _x + _mod : _x; n } n inline long long mul(long long _x, long long _y, n                      long long _mod = 1000000007LL) { n   _x *= _y; n   return _x >= _mod ? _x % _mod : _x; n } n long long mypow(long long _a, long long _x, long long _mod) { n   if (_x == 0) return 1LL; n   long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod); n   if (_x & 1) _ret = mul(_ret, _a, _mod); n   return _ret; n } n long long mymul(long long _a, long long _x, long long _mod) { n   if (_x == 0) return 0LL; n   long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod); n   if (_x & 1) _ret = add(_ret, _a, _mod); n   return _ret; n } n inline bool equal(double _x, double _y) { n   return _x > _y - 1e-9 && _x < _y + 1e-9; n } n int __ = 1, _cs; n struct Mat { n   int n, a[101][101]; n   Mat(int _n) { n     n = _n; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) a[i][j] = 0; n   } n   Mat operator*(const Mat& he) const { n     Mat ret(n); n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) n         for (int k = 0; k < n; k++) n           ret.a[i][j] = add(ret.a[i][j], mul(a[i][k], he.a[k][j])); n     return ret; n   } n   Mat operator^(int tms) const { n     Mat ret(n), tmp(n); n     for (int i = 0; i < n; i++) { n       ret.a[i][i] = 1; n       for (int j = 0; j < n; j++) tmp.a[i][j] = a[i][j]; n     } n     while (tms > 0) { n       if (tms & 1) ret = ret * tmp; n       tmp = tmp * tmp; n       tms >>= 1; n     } n     return ret; n   } n }; n void build() {} n int n, l, m, s[1010101], u[1010101], o[1010101]; n void init() { n   n = getint(); n   l = getint(); n   m = getint(); n   for (int i = 0; i < n; i++) s[i] = getint(); n   for (int i = 0; i < n; i++) u[i] = getint(); n   for (int i = 0; i < n; i++) o[i] = getint(); n } n int cnt[111], sc[111], oc[111][111]; n void solve() { n   Mat tmp(m); n   for (int i = 0; i < n; i++) cnt[u[i] % m]++; n   for (int i = 0; i < m; i++) n     for (int j = 0; j < m; j++) { n       int dlt = (i - j + m) % m; n       tmp.a[i][j] = cnt[dlt]; n     } n   for (int i = 0; i < n; i++) sc[s[i] % m]++; n   for (int i = 0; i < n; i++) oc[u[i] % m][o[i] % m]++; n   tmp = tmp ^ (l - 2); n   int ans = 0; n   for (int i = 0; i < m; i++) n     if (sc[i]) n       for (int j = 0; j < m; j++) n         for (int k = 0; k < m; k++) { n           if (oc[j][k] == 0) continue; n           int tar = (m - (i + j + k) % m) % m; n           ans = add(ans, mul(sc[i], mul(oc[j][k], tmp.a[tar][0]))); n         } n   printf( %d n , ans); n } n int main() { n   build(); n   while (__--) { n     init(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string one, two; n   map<string, string> m; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> one >> two; n     bool found = false; n     for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) { n       if (it->second == one) { n         it->second = two; n         found = true; n       } n     } n     if (!found) { n       m.insert(pair<string, string>(one, two)); n     } n   } n   cout << m.size() <<   n ; n   for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) { n     cout << it->first <<     << it->second <<   n ; n   } n   cout << flush; n   return 0; n } n


// Author:  HolyK n // Created: Thu Jul  8 09:48:07 2021 n #include <bits/stdc++.h> n #define dbg(a...) fprintf(stderr, a) n template <class T, class U> n inline bool smin(T &x, const U &y) { n   return y < x ? x = y, 1 : 0; n } n template <class T, class U> n inline bool smax(T &x, const U &y) { n   return x < y ? x = y, 1 : 0; n } n  n using LL = long long; n using PII = std::pair<int, int>; n  n int ask(int x) { n   std::cout << x << std::endl; n   int r; n   std::cin >> r; n   return r; n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int t; n   std::cin >> t; n   while (t--) { n     int n, k; n     std::cin >> n >> k; n     if (ask(0)) continue; n     for (int i = 1; i < n; i++) { n       int x = 0; n       for (int j = 1; j <= i; j *= k) { n  int u = (i / j - (i - 1) / j) % k; n  if (i & 1) u = (k - u) % k; n  x += u * j; n       } n       if (ask(x)) break; n     } n   } n   return 0; n } n /* n 0 n  */ n


#include <bits/stdc++.h> n using namespace std; n void computeLcp(string &s1, string &s2, int LCP[][5005]) { n   for (int i = ((int)s1.size()) - 1; i >= 0; i--) { n     for (int j = ((int)s2.size()) - 1; j >= 0; j--) { n       if (s1[i] == s2[j]) { n         LCP[i][j] = 1 + LCP[i + 1][j + 1]; n       } else { n         LCP[i][j] = 0; n       } n     } n   } n } n int lcp[5005][5005]; n int mUA[5005]; n int mUB[5005]; n int main() { n   ios_base::sync_with_stdio(0); n   string A, B; n   cin >> A >> B; n   memset((lcp), (0), sizeof(lcp)); n   ; n   computeLcp(A, A, lcp); n   int ans = (1 << 30); n   for (int i = 0; i < ((int)A.size()); i++) { n     int minUniqueLength = 0; n     for (int j = 0; j < ((int)A.size()); j++) { n       if (i == j) continue; n       minUniqueLength = max(minUniqueLength, lcp[i][j]); n     } n     minUniqueLength++; n     mUA[i] = minUniqueLength; n   } n   memset((lcp), (0), sizeof(lcp)); n   ; n   computeLcp(B, B, lcp); n   for (int i = 0; i < ((int)B.size()); i++) { n     int minUniqueLength = 0; n     for (int j = 0; j < ((int)B.size()); j++) { n       if (i == j) continue; n       minUniqueLength = max(minUniqueLength, lcp[i][j]); n     } n     minUniqueLength++; n     mUB[i] = minUniqueLength; n   } n   memset((lcp), (0), sizeof(lcp)); n   ; n   computeLcp(A, B, lcp); n   for (int i = 0; i < ((int)A.size()); i++) { n     for (int j = 0; j < ((int)B.size()); j++) { n       if (lcp[i][j] >= max(mUA[i], mUB[j])) { n         ans = min(ans, max(mUA[i], mUB[j])); n       } n     } n   } n   if (ans >= (1 << 30)) ans = -1; n   cout << ans << endl; n   return 0; n } n