#include <bits/stdc++.h> n using namespace std; n int f[505][505], g[505][505], a[505], b[505], id[505], xinyue, n, m, vis[505], n     ed; n int cmp(int x, int y) { return b[x] < b[y]; } n void dfs(int n, int m) { n   if (!n) return; n   if (g[n][m] == 1) vis[n] = 1, m--; n   dfs(n - 1, m); n } n int main() { n   scanf( %d , &xinyue); n   while (xinyue--) { n     scanf( %d%d , &n, &m); n     for (int i = 0; i <= n; i++) { n       for (int t = 0; t <= m; t++) { n         f[i][t] = -1; n       } n     } n     f[0][0] = 0; n     memset(g, 0, sizeof(g)); n     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i], &b[i]), id[i] = i; n     sort(id + 1, id + n + 1, cmp); n     for (int i = 1; i <= n; i++) { n       for (int t = 0; t <= min(i, m); t++) { n         if (f[i - 1][t] != -1) f[i][t] = f[i - 1][t] + b[id[i]] * (m - 1); n         g[i][t] = 0; n         if (t && f[i - 1][t - 1] + a[id[i]] + b[id[i]] * (t - 1) > f[i][t] && n             f[i - 1][t - 1] != -1) { n           f[i][t] = f[i - 1][t - 1] + a[id[i]] + b[id[i]] * (t - 1); n           g[i][t] = 1; n         } n       } n     } n     memset(vis, 0, sizeof(vis)); n     dfs(n, m); n     printf( %d n , m + (n - m) * 2); n     ed = 0; n     for (int i = 1; i <= n; i++) { n       if (vis[i]) { n         ed++; n         if (ed == m) { n           ed = id[i]; n           break; n         } n         printf( %d  , id[i]); n       } n     } n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) { n         printf( %d %d  , id[i], -id[i]); n       } n     } n     printf( %d n , ed); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n struct business { n   int num; n   int dif; n }; n bool compare(business x, business y) { return (x.dif < y.dif); } n int main() { n   int n; n   int x; n   cin >> n; n   vector<business> A(n + 1); n   for (int i = 1; i <= n; i++) { n     cin >> x; n     A[i].num = i; n     A[i].dif = x; n   } n   sort(A.begin(), A.end(), compare); n   int triple = 0, p1 = 0, p2 = 0; n   for (int i = 1; i < n; i++) { n     if (A[i].dif == A[i + 1].dif) n       if (p1 == 0) { n         p1 = i; n         if (i <= n - 2) n           if (A[i + 1].dif == A[i + 2].dif) { n             triple = i; n             break; n           } n       } else { n         p2 = i; n         if (i <= n - 2) n           if (A[i + 1].dif == A[i + 2].dif) triple = i; n         break; n       } n   } n   if ((triple == 0) && (p2 == 0)) n     cout <<  NO n ; n   else { n     cout <<  YES n ; n     if (triple != 0) { n       for (int i = 1; i <= n; i++) cout << A[i].num <<    ; n       cout << endl; n       for (int i = 1; i <= n; i++) { n         if (i == triple) { n           cout << A[i].num <<     << A[i + 2].num <<     << A[i + 1].num <<    ; n           i += 2; n         } else n           cout << A[i].num <<    ; n       } n       cout << endl; n       for (int i = 1; i <= n; i++) { n         if (i == triple) { n           cout << A[i + 2].num <<     << A[i + 1].num <<     << A[i].num <<    ; n           i += 2; n         } else n           cout << A[i].num <<    ; n       } n       cout << endl; n     } else { n       for (int i = 1; i <= n; i++) cout << A[i].num <<    ; n       cout << endl; n       for (int i = 1; i <= n; i++) { n         if (i == p1) { n           cout << A[i + 1].num <<     << A[i].num <<    ; n           i++; n         } else n           cout << A[i].num <<    ; n       } n       cout << endl; n       for (int i = 1; i <= n; i++) { n         if (i == p2) { n           cout << A[i + 1].num <<     << A[i].num <<    ; n           i++; n         } else n           cout << A[i].num <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   string s; n   cin >> n; n   cin >> s; n   vector<long long> cnts(60, 0); n   long long k = 0; n   for (long long i = 0; i < n; i++) { n     if (cnts[s[i] - 65] == 0) k++; n     cnts[s[i] - 65]++; n   } n   for (long long i = 0; i < 60; i++) cnts[i] = 0; n   long long l = 0; n   long long r = -1; n   long long res = 100001; n   long long cnt = 0; n   while (r < n) { n     if (cnt < k) { n       r++; n       if (r == n) break; n       cnts[s[r] - 65]++; n       if (cnts[s[r] - 65] == 1) cnt++; n     } else if (cnt == k) { n       res = min(res, r - l + 1); n       cnts[s[l] - 65]--; n       if (cnts[s[l] - 65] == 0) cnt--; n       l++; n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string Scale, left, right, rest_elements; n   int Slash; n   cin >> Scale; n   Slash = Scale.find( | ); n   left = Scale.substr(0, Slash); n   right = Scale.substr(Slash + 1, Scale.size()); n   cin >> rest_elements; n   for (auto i : rest_elements) n     if (left.size() <= right.size()) n       left += i; n     else n       right += i; n   cout << (left.size() == right.size() ? left +  |  + right :  Impossible ) n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 50050; n vector<int> e[MAX]; n vector<int> ee[MAX]; n int c[MAX][555]; n int vis[MAX]; n int n, k; n void solve(int indx) { n   c[indx][0] = 1; n   vis[indx] = 1; n   for (int i = 0; i < e[indx].size(); i++) { n     if (vis[e[indx][i]] == 1) continue; n     int cindx = e[indx][i]; n     ee[indx].push_back(cindx); n     solve(cindx); n     for (int j = 0; j <= k; j++) { n       if (c[cindx][j] == 0) break; n       c[indx][j + 1] += c[cindx][j]; n     } n   } n } n long long solve1() { n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     long long ret = 0; n     for (int j = 0; j < ee[i].size(); j++) { n       for (int K = 1; K < k; K++) { n         long long first = 0, second = 0; n         first = c[ee[i][j]][K - 1]; n         second = c[i][k - K] - c[ee[i][j]][k - K - 1]; n         ret += (first * second); n       } n     } n     ans += ret / 2; n     ans += c[i][k]; n   } n   return ans; n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     e[x].push_back(y); n     e[y].push_back(x); n   } n   solve(1); n   cout << solve1() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007ll; n vector<int> adj[100005]; n vector<pair<int, int> > grop[100005]; n int now; n int weig[100005]; n int bu[100005]; n int flag[100005]; n pair<int, int> dfs(int u) { n   if (flag[u]) return make_pair(0, 0); n   flag[u] = 1; n   pair<int, int> res = make_pair(0, 0); n   for (int i = 0; i < adj[u].size(); i++) { n     pair<int, int> tem = dfs(adj[u][i]); n     res.first += tem.first; n     res.second += tem.second; n   } n   res.first += weig[u]; n   res.second += bu[u]; n   grop[now].push_back(make_pair(weig[u], bu[u])); n   return res; n } n long long dp[100005]; n int main() { n   int n, m, w; n   scanf( %d %d %d , &n, &m, &w); n   for (int i = 1; i <= n; i++) scanf( %d , &weig[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &bu[i]); n   for (int i = 1; i <= m; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   for (int i = 1; i <= n; i++) { n     if (flag[i]) continue; n     now++; n     pair<int, int> tem = dfs(i); n     grop[now].push_back(tem); n   } n   for (int i = 1; i <= now; i++) { n     for (int j = w; j > 0; j--) { n       for (int k = 0; k < grop[i].size(); k++) { n         if (grop[i][k].first > j) continue; n         dp[j] = max(dp[j], grop[i][k].second + dp[j - grop[i][k].first]); n       } n     } n   } n   long long res = 0; n   for (int i = 0; i <= w; i++) res = max(res, dp[i]); n   printf( %I64d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n int C[1005][1005]; n void build() { n   C[0][0] = 1; n   for (int i = 1; i <= 1000; i++) { n     C[i][0] = 1; n     for (int j = 1; j <= 1000; j++) { n       C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; n     } n   } n } n int main() { n   build(); n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   if (2 * k > n - 1 || 2 * k > m - 1) { n     printf( 0 n ); n   } else { n     printf( %d n , 1LL * C[n - 1][2 * k] * C[m - 1][2 * k] % mod); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0; n   char ch = getchar(); n   bool f = 0; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = 1; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return f ? -x : x; n } n void write(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x >= 10) write(x / 10); n   putchar(x % 10 +  0 ); n } n void writeln(long long x) { n   write(x); n   puts(  ); n } n void writep(long long x) { n   write(x); n   putchar(   ); n } n const int N = 100005; n int n, S[N], a[N], top; n char s[N]; n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   for (int i = (int)(1); i <= (int)(n); i++) { n     if (s[i] ==  + ) n       a[i] = 1; n     else n       a[i] = 0; n   } n   for (int i = (int)(1); i <= (int)(n); i++) { n     S[++top] = a[i]; n     if (top > 1 && S[top - 1] == a[i]) top -= 2; n   } n   if (top) n     puts( No ); n   else n     puts( Yes ); n } n


#include <bits/stdc++.h> n using namespace std; n struct MCMF { n   using F = int; n   const static F INF = 0x3f3f3f3f; n   struct Edge { n     int v, bro; n     F cap, cost; n     Edge() {} n     Edge(int _v, int _bro, F _cap, F _cost) n         : v(_v), bro(_bro), cap(_cap), cost(_cost) {} n   }; n   vector<Edge> e; n   vector<int> pos, pre; n   vector<F> dis; n   vector<bool> trk; n   int n, s, t, m; n   MCMF(int _n, int _s, int _t) : n(_n), s(_s), t(_t), m(0) { n     pos.assign(n, -1); n     pre.resize(n); n     dis.resize(n); n     trk.resize(n); n     e.reserve(4e5); n   } n   void add(int u, int v, F cap = INF, F cost = 0) { n     assert(u < n && v < n); n     e.emplace_back(v, pos[u], cap, cost); n     pos[u] = m++; n     e.emplace_back(u, pos[v], 0, -cost); n     pos[v] = m++; n   } n   bool spfa() { n     queue<int> q; n     fill(pre.begin(), pre.end(), -1); n     fill(dis.begin(), dis.end(), INF); n     fill(trk.begin(), trk.end(), false); n     dis[s] = 0; n     trk[s] = true; n     q.push(s); n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       trk[u] = false; n       for (int i = pos[u]; i != -1; i = e[i].bro) { n         int v = e[i].v; n         if (e[i].cap > 0 && dis[v] > dis[u] + e[i].cost) { n           dis[v] = dis[u] + e[i].cost; n           pre[v] = i; n           if (!trk[v]) { n             trk[v] = true; n             q.push(v); n           } n         } n       } n     } n     return pre[t] != -1; n   } n   pair<F, F> mcmf() { n     F flow = 0, cost = 0; n     while (spfa()) { n       F f = INF; n       for (int i = pre[t]; i != -1; i = pre[e[i ^ 1].v]) f = min(f, e[i].cap); n       for (int i = pre[t]; i != -1; i = pre[e[i ^ 1].v]) { n         e[i].cap -= f; n         e[i ^ 1].cap += f; n         cost += e[i].cost * f; n       } n       flow += f; n     } n     return {flow, cost}; n   } n }; n void solve() { n   int n1, n2, m, r, b; n   cin >> n1 >> n2 >> m >> r >> b; n   string s1, s2; n   cin >> s1 >> s2; n   int L = n1 + n2, R = L + 1; n   int S = R + 1, T = S + 1; n   MCMF g(T + 1, S, T); n   vector<int> deg(S), demand(S); n   for (int _ = 0; _ < m; _++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     y += n1; n     deg[x]++; n     deg[y]++; n     demand[x]++; n     demand[y]--; n     g.add(x, y, 1, r); n     g.add(y, x, 1, b); n   } n   auto gg = []() { n     cout << -1; n     exit(0); n   }; n   for (int i = 0; i < n1; i++) { n     if (s1[i] !=  U  && deg[i] == 0) gg(); n     if (s1[i] ==  R ) { n       g.add(L, i, deg[i] - 1); n       demand[i] -= deg[i] + 1; n       demand[L] += deg[i] + 1; n     } else if (s1[i] ==  B ) { n       g.add(L, i, deg[i] - 1); n     } else { n       g.add(L, i, deg[i] << 1); n     } n   } n   for (int i = 0; i < n2; i++) { n     int k = i + n1; n     if (s2[i] !=  U  && deg[k] == 0) gg(); n     if (s2[i] ==  B ) { n       g.add(k, R, deg[k] - 1); n     } else if (s2[i] ==  R ) { n       g.add(k, R, deg[k] - 1); n       demand[k] += deg[k] + 1; n       demand[R] -= deg[k] + 1; n     } else { n       g.add(k, R, deg[k] << 1); n     } n   } n   g.add(R, L); n   int sum = 0; n   for (int i = 0; i < S; i++) { n     if (demand[i] > 0) { n       sum += demand[i]; n       g.add(i, T, demand[i]); n     } n     if (demand[i] < 0) { n       g.add(S, i, -demand[i]); n     } n   } n   int flow, cost; n   tie(flow, cost) = g.mcmf(); n   if (flow < sum) gg(); n   cout << cost <<   n ; n   for (int i = 0; i < m; i++) { n     if (g.e[i * 4 + 1].cap) { n       cout <<  R ; n     } else if (g.e[i * 4 + 3].cap) { n       cout <<  B ; n     } else { n       cout <<  U ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   ; n   int n; n   bool allSame = true; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (i > 0 and a[i] != a[i - 1]) allSame = false; n   } n   sort(a, a + n); n   if (n == 1) { n     cout <<  -1 ; n     return 0; n   } n   if (allSame) { n     cout <<  1 n  << a[0]; n     return 0; n   } n   if (n == 2) { n     if ((a[0] + a[1]) % 2 != 0) n       cout <<  2 n  << a[0] - (a[1] - a[0]) <<     << a[1] + (a[1] - a[0]); n     else n       cout <<  3 n  n            << a[0] - (a[1] - a[0]) <<     << (a[0] + a[1]) / 2 <<     n            << a[1] + (a[1] - a[0]); n     return 0; n   } n   if (n == 3) { n     int d1 = a[1] - a[0], d2 = a[2] - a[1]; n     if (d1 == d2) { n       cout <<  2 n  << a[0] - d1 <<     << a[2] + d1; n       return 0; n     } else if (d1 == 2 * d2) { n       cout <<  1 n  << a[0] + d1 / 2; n       return 0; n     } else if (2 * d1 == d2) { n       cout <<  1 n  << a[1] + d2 / 2; n       return 0; n     } n   } n   set<int> uniq; n   multiset<int> freq; n   for (int i = 1; i < n; i++) { n     uniq.insert(a[i] - a[i - 1]); n     freq.insert(a[i] - a[i - 1]); n   } n   if (uniq.size() == 1) { n     cout <<  2 n  << a[0] - *uniq.begin() <<     << a[n - 1] + *uniq.begin(); n     return 0; n   } else if (uniq.size() == 2) { n     int d1 = *uniq.begin(); n     int f1 = freq.erase(d1); n     uniq.erase(d1); n     int d2 = *uniq.begin(); n     int f2 = freq.erase(d2); n     int d = f1 > f2 ? d1 : d2; n     if (f1 > 1 and f2 > 1) { n       cout <<  0 ; n       return 0; n     } n     if (d1 == 0 or d2 == 0) { n       cout <<  0 ; n       return 0; n     } n     for (int i = 1; i < n; i++) { n       if (a[i] - a[i - 1] == 2 * d) { n         cout <<  1 n  << a[i - 1] + d; n         return 0; n       } n     } n   } n   cout <<  0 ; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, k; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> t; n   while (t--) { n     cin >> n >> k; n     if (!n && !k) n       cout << 0 <<   n ; n     else n       cout << 1440 - n * 60 - k <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   if (k < 25) { n     cout << -1 << endl; n   } else { n     int r = 0, c = 0; n     for (int i = 5; i <= sqrt(k); i++) { n       if (k % i == 0) { n         r = i; n         c = k / i; n         break; n       } n     } n     if (r == 0 or c == 0) { n       cout << -1 << endl; n     } else { n       char ch[] = { a ,  e ,  i ,  o ,  u }; n       string fr =   ; n       for (int j = 0; j < r; j++) { n         for (int i = 0; i < c; i++) { n           fr += ch[(j + i) % 5]; n         } n       } n       cout << fr << endl; n     } n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int s1, s2, s3, s4; n   cin >> s1 >> s2 >> s3 >> s4; n   unordered_set<int> s; n   s.insert(s1); n   s.insert(s2); n   s.insert(s3); n   s.insert(s4); n   int si = s.size(); n   if (si == 4) n     cout << 0; n   else if (si == 3) n     cout << 1; n   else if (si == 2) n     cout << 2; n   else n     cout << 3; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool sort_1(pair<int, int> &a, pair<int, int> &b) { return a.first < b.first; } n bool sort_2(pair<int, int> &a, pair<int, int> &b) { return a.first > b.first; } n int main() { n   int n, cnt = 0; n   scanf( %d , &n); n   vector<vector<pair<int, int>>> a(1001); n   for (int i = 0; i < n; ++i) { n     int x, y; n     scanf( %d %d , &x, &y); n     a[x / 1000].push_back(make_pair(y, i + 1)); n   } n   bool b = true; n   for (int i = 0; i < 1001; ++i) { n     if (b) n       sort(a[i].begin(), a[i].end(), sort_1); n     else n       sort(a[i].begin(), a[i].end(), sort_2); n     b = !b; n   } n   for (int i = 0; i < 1001; ++i) { n     for (int j = 0; j < a[i].size(); ++j) printf( %d  , a[i][j].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int h, l; n   std::cin >> h >> l; n   cout << fixed << setprecision(10); n   std::cout << (1.0 * l / (2.0 * h) * l - 1.0 * h / 2.0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int q; n long long r, n; n vector<int> degp[1000005]; n long long answ[1000005][21]; n long long m = 1000000007; n long long powmod(long long x, long long po) { n   if (po == 0) { n     return 1; n   } n   long long res = powmod(x, po / 2); n   res = (res * res) % m; n   if (po % 2 == 1) { n     res = (res * x) % m; n   } n   return res; n } n int main() { n   for (int i = 2; i <= 1000000; i++) { n     if (degp[i].empty()) { n       long long t = i; n       long long u = 1; n       while (t <= 1000000) { n         for (int j = 1; j <= 1000000 / t; j++) { n           if (j % i != 0) { n             degp[t * j].push_back(u); n           } n         } n         u++; n         t = t * (long long)i; n       } n     } n   } n   for (int i = 0; i <= 1000000; i++) { n     answ[i][0] = 1; n   } n   for (int i = 1; i < 21; i++) { n     answ[0][i] = 2; n     for (int j = 1; j <= 1000000; j++) { n       answ[j][i] = (answ[j - 1][i] + answ[j][i - 1]) % m; n     } n   } n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     scanf( %I64d%I64d , &r, &n); n     long long res = 1; n     for (int k = 0; k < degp[n].size(); k++) { n       res = (res * answ[r][degp[n][k]]) % m; n     } n     printf( %I64d n , res); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct no { n   int x, y, r; n }; n no A, B, b, a; n int dist(no u, no v) { n   return (u.x - v.x) * (u.x - v.x) + (u.y - v.y) * (u.y - v.y); n } n bool contido(no v, no u) { n   if (u.r < v.r) return 0; n   if ((sqrt(dist(v, u)) + (double)((v.r)) - 1e-2 < (double)(u.r))) return 1; n   return 0; n } n bool disjunto(no v, no u) { n   if (sqrt(dist(u, v)) > (double)(v.r + u.r) - 1e-2) return 1; n   return 0; n } n int main() { n   cin >> a.x >> a.y >> a.r >> A.r; n   A.x = a.x, A.y = a.y; n   cin >> b.x >> b.y >> b.r >> B.r; n   B.x = b.x, B.y = b.y; n   if (B.r < A.r) { n     swap(B, A); n     swap(a, b); n   } n   int ans; n   if (contido(A, B)) { n     if (contido(A, b)) n       ans = 4; n     else if (contido(a, b) || contido(b, a)) n       ans = 2; n     else if (disjunto(b, A)) n       ans = 2; n     else n       ans = 1; n   } else if (disjunto(A, B)) { n     ans = 4; n   } else { n     if (contido(a, b) || contido(b, a)) n       ans = 1; n     else { n       ans = 0; n       if (disjunto(a, B)) ans++; n       if (disjunto(b, A)) ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int k; n set<pair<string, int> > st; n pair<string, int> tmp; n int main() { n   cin >> s >> k; n   for (int i = 0; i < (int)s.length(); i++) { n     string q =   ; n     q += s[i]; n     st.insert(make_pair(q, i)); n   } n   while (k > 1 && (int)st.size() > 0) { n     tmp = *st.begin(); n     st.erase(st.begin()); n     if (tmp.second + 1 < (int)s.length()) { n       tmp.second++; n       tmp.first += s[tmp.second]; n       st.insert(tmp); n     } n     k--; n   } n   if ((int)st.size() > 0) { n     tmp = *st.begin(); n     cout << tmp.first << endl; n     return 0; n   } n   cout <<  No such line.  << endl; n   return 0; n } n


#include <bits/stdc++.h> n int n, q, maxn; n int a[200005]; n std::vector<int> v[1901][105]; n inline void merge(std::vector<int> &v1, std::vector<int> &v2) { n   if (v1.size() < v2.size()) std::swap(v1, v2); n   v1.insert(v1.end(), v2.begin(), v2.end()); n   v2.clear(); n } n inline void assign(int i, int x, int y, int l, int r) { n   static int vis[105] = {}; n   if ((i + 1) * maxn <= n) { n     for (int j = 1; j <= 100; j++) { n       for (int k : v[i][j]) vis[k] = j; n       v[i][j].clear(); n       v[i][j].push_back(j); n     } n     for (int j = i * maxn; j < (i + 1) * maxn; j++) a[j] = vis[a[j]]; n   } n   for (int j = l; j < r; j++) n     if (a[j] == x) a[j] = y; n } n int main() { n   scanf( %d , &n); n   maxn = sqrt(n * log2(n)) + 1; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; (i + 1) * maxn <= n; i++) n     for (int j = 1; j <= 100; j++) v[i][j].push_back(j); n   for (scanf( %d , &q); q--;) { n     int l, r, x, y, L, R; n     scanf( %d%d%d%d , &l, &r, &x, &y); n     if (x != y) { n       l--; n       L = l / maxn, R = r / maxn; n       if (L != R) { n         assign(L, x, y, l, (L + 1) * maxn); n         for (int i = L + 1; i < R; i++) merge(v[i][y], v[i][x]); n         assign(R, x, y, R * maxn, r); n       } else n         assign(L, x, y, l, r); n     } n   } n   for (int i = 0; (i + 1) * maxn <= n; i++) assign(i, 0, 0, 0, 0); n   for (int i = 0; i < n; i++) printf( %d  , a[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const signed long long int LINF = LLONG_MAX; n const double EPS = 1e-9; n const int MOD = 1000000007; n const int MAXN = 100001; n const int ALPH = 26; n const int DALPH = 52; n struct Node { n   int l, r, m; n   int minValue; n   Node *lson, *rson; n   Node(const int &al, const int &ar) n       : l(al), n         r(ar), n         m((al + ar) / 2), n         minValue(-1), n         lson(nullptr), n         rson(nullptr) { n     if (l == r) { n       return; n     } n     lson = new Node(l, m); n     rson = new Node(m + 1, r); n   } n   ~Node() { n     if (lson) { n       delete lson; n       delete rson; n     } n   } n   void set(const int &index, const int &value) { n     if (l == r) { n       minValue = value; n       return; n     } n     if (index < m + 1) { n       lson->set(index, value); n     } else { n       rson->set(index, value); n     } n     minValue = min(lson->minValue, rson->minValue); n   } n   int getMin(const int &al, const int &ar) { n     if (ar < l || r < al) { n       return INF; n     } n     if (al <= l && r <= ar) { n       return minValue; n     } n     return min(lson->getMin(al, ar), rson->getMin(al, ar)); n   } n }; n struct pt { n   int x, y; n   pt() {} n   pt(const int &ax, const int &ay) : x(ax), y(ay) {} n   void read() { scanf( %d %d , &x, &y); } n }; n bool operator<(const pt &p1, const pt &p2) { return p1.x < p2.x; } n struct query { n   int id; n   pt p1, p2; n   bool ans; n   query() {} n   query(const int &aId, const pt &aP1, const pt &aP2) n       : id(aId), p1(aP1), p2(aP2), ans(false) {} n }; n bool operator<(const query &q1, const query &q2) { return q1.p2.x < q2.p2.x; } n bool cmpid(const query &q1, const query &q2) { return q1.id < q2.id; } n int n, m, k, q; n vector<pt> rook; n vector<query> qList; n void solve() { n   sort((rook).begin(), (rook).end()); n   sort((qList).begin(), (qList).end()); n   Node *tree = new Node(1, m); n   int rptr = 0, qptr = 0; n   while (qptr < q) { n     while (rptr < k && rook[rptr].x <= qList[qptr].p2.x) { n       tree->set(rook[rptr].y, rook[rptr].x); n       ++rptr; n     } n     if (tree->getMin(qList[qptr].p1.y, qList[qptr].p2.y) >= qList[qptr].p1.x) { n       qList[qptr].ans = true; n     } n     ++qptr; n   } n   delete tree; n } n int main() { n   scanf( %d %d %d %d , &n, &m, &k, &q); n   rook.resize(k); n   for (int i = 0; i < k; ++i) { n     rook[i].read(); n   } n   qList.resize(q); n   for (int i = 0; i < q; ++i) { n     pt p1, p2; n     p1.read(); n     p2.read(); n     qList[i] = query(i, p1, p2); n   } n   solve(); n   for (int i = 0; i < k; ++i) { n     swap(rook[i].x, rook[i].y); n   } n   for (int i = 0; i < q; ++i) { n     swap(qList[i].p1.x, qList[i].p1.y); n     swap(qList[i].p2.x, qList[i].p2.y); n   } n   swap(n, m); n   solve(); n   sort((qList).begin(), (qList).end(), cmpid); n   for (int i = 0; i < q; ++i) { n     if (qList[i].ans) { n       puts( YES ); n     } else { n       puts( NO ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int q, n, x; n void f() { n   cin >> n; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     cin >> x; n     v.push_back(x); n   } n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   int maxi = v.back(); n   for (int i = v.size() - 1; i > 0 && v[i] + v[i - 1] > maxi; i--) n     for (int j = i - 1; j >= 0; j--) n       if (v[i] % v[j] != 0) { n         maxi = max(maxi, v[i] + v[j]); n         break; n       } n   for (int i = v.size() - 1; i > 0 && v[i] + v[i - 1] + v[i - 2] > maxi; i--) n     for (int j = i - 1; j > 0; j--) n       if (v[i] % v[j] != 0) n         for (int k = j - 1; k >= 0; k--) n           if (v[i] % v[k] != 0 && v[j] % v[k] != 0) { n             maxi = max(maxi, v[i] + v[j] + v[k]); n             break; n           } n   cout << maxi << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin >> q; n   for (int u = 0; u < q; u++) f(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, s; n   cin >> a >> b >> s; n   a < 0 ? a *= -1 : a *= 1; n   b < 0 ? b *= -1 : b *= 1; n   int l = min(a, b) * 2 + (max(a, b) - min(a, b)); n   cout << (l <= s ? l % 2 == s % 2 ?  YES  :  NO  :  NO ); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, x, ans; n long long findX(long long R) { n   if (R < 0) return 0; n   return (R * (R + 1)) / 2; n } n int main() { n   scanf( %lld %lld , &n, &k); n   x = 0; n   for (int i = 1; i <= n - 1; i++) { n     if (findX(i - 1) <= k) x = i; n   } n   if (findX(x - 1) + x < k) { n     printf( Impossible n ); n     return 0; n   } n   k -= findX(x - 1); n   n -= x; n   if (x) { n     for (int i = 1; i <= x; i++) { n       printf( ( ); n       if (i == k) { n         printf( () ); n         n--; n       } n     } n     for (int i = 1; i <= x; i++) { n       printf( ) ); n     } n   } n   while (n) { n     printf( () ); n     n--; n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int n, m, a, b, c, p[100010], cnt; n bool vis[100010], ed; n vector<pair<int, int> > V[100010]; n int powmod(int x, int y) { n   int res = 1, cro = x; n   while (y) { n     if (y % 2) res = 1ll * res * cro % mod; n     cro = 1ll * cro * cro % mod; n     y /= 2; n   } n   return res; n } n void dfs(int x) { n   vis[x] = 1; n   for (int i = 0; i < V[x].size(); i++) { n     int y = V[x][i].first; n     int z = V[x][i].second; n     if (vis[y]) { n       if (p[y] != p[x] ^ z) ed = 1; n       continue; n     } else { n       p[y] = p[x] ^ z; n       vis[y] = 1; n       dfs(y); n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   while (m--) { n     scanf( %d%d%d , &a, &b, &c); n     V[a].push_back(make_pair(b, c ^ 1)); n     V[b].push_back(make_pair(a, c ^ 1)); n   } n   ed = 0; n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       dfs(i); n       cnt++; n     } n   } n   if (ed) n     puts( 0 ); n   else n     printf( %d , powmod(2, cnt - 1)); n } n


#include <bits/stdc++.h> n using namespace std; n int dp[10000]; n int main() { n   int N, M; n   cin >> N >> M; n   int T; n   double D; n   int ans = 0; n   for (int i = 0; i < N; i++) { n     cin >> T >> D; n     dp[T - 1]++; n     for (int j = 0; j < T - 1; j++) dp[T - 1] = max(dp[T - 1], dp[j] + 1); n   } n   for (int i = 0; i < M; i++) ans = max(ans, dp[i]); n   cout << N - ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   if (n < 4) n     printf( NO n ); n   else if (n % 2) { n     printf( YES n ); n     printf( 1 + 5 = 6 n3 - 2 = 1 n4 * 6 = 24 n24 * 1 = 24 n ); n     for (int j = n; j > 6; j -= 2) { n       printf( %d - %d = 1 n , j, j - 1); n       printf( 24 * 1 = 24 n ); n     } n   } else { n     printf( YES n ); n     printf( 1 * 2 = 2 n2 * 3 = 6 n6 * 4 = 24 n ); n     for (int j = n; j > 5; j -= 2) { n       printf( %d - %d = 1 n , j, j - 1); n       printf( 24 * 1 = 24 n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const double PI = acos(-1.0); n const double E = exp(1.0); n const int M = 200010; n long long a[M]; n long long ans[M][2]; n int main() { n   int n, k, x; n   cin >> n >> k >> x; n   long long temp = 1; n   while (k--) temp *= x; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     ans[i][0] = (ans[i - 1][0] | a[i]); n   } n   long long mx = 0; n   for (int i = n; i > 0; --i) { n     mx = max(mx, ans[i + 1][1] | ans[i - 1][0] | (a[i] * temp)); n     ans[i][1] = ans[i + 1][1] | a[i]; n   } n   cout << mx << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long k; n vector<pair<long long, char>> aa; n void print(long long a, char c) { n   a = min(a, k); n   if (a != 0) { n     aa.push_back({a, c}); n   } n   k -= a; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m >> k; n   if (k > 4 * n * m - 2 * n - 2 * m) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES n ; n   for (long long i = 0; i < m - 1; i++) { n     print(1,  R ); n     print(n - 1,  D ); n     print(n - 1,  U ); n   } n   print(m - 1,  L ); n   for (long long i = 0; i < n - 1; i++) { n     print(1,  D ); n     print(m - 1,  R ); n     print(m - 1,  L ); n   } n   print(n - 1,  U ); n   cout << aa.size() <<   n ; n   for (auto i : aa) { n     cout << i.first <<     << i.second <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5 + 10; n int arr[MAX]; n int n; n vector<int> v[MAX]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 0; i < n; ++i) v[i].clear(); n     for (int i = 0; i < n; ++i) { n       int x, y; n       cin >> x >> y; n       v[x].push_back(y); n     } n     long long ans = 0; n     priority_queue<int, vector<int>, greater<int> > q; n     for (int i = n - 1; i >= 0; --i) { n       for (auto &j : v[i]) q.push(j); n       while (q.size() > n - i) ans += q.top(), q.pop(); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int i, a[n]; n   long long int c = 0, ans = 0; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     c += a[i]; n   } n   for (i = 1; i <= 5; i++) { n     if ((c + i) % (n + 1) != 1) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T> n inline void read(_T &f) { n   f = 0; n   _T fu = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) { n       fu = -1; n     } n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     f = (f << 3) + (f << 1) + (c & 15); n     c = getchar(); n   } n   f *= fu; n } n template <typename T> n void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x < 10) n     putchar(x + 48); n   else n     print(x / 10), putchar(x % 10 + 48); n } n template <typename T> n void print(T x, char t) { n   print(x); n   putchar(t); n } n const int N = 1e5 + 5; n int st1[16][N][17], st2[16][N][17]; n int a[N], lg[N]; n int n; n void make_st(int id) { n   for (int j = 1; j <= 16; j++) { n     for (int i = 1; i <= n - (1 << j) + 1; i++) { n       st1[id][i][j] = n           min(st1[id][i][j - 1], st1[id][i + (1 << (j - 1))][j - 1]); n       st2[id][i][j] = n           max(st2[id][i][j - 1], st2[id][i + (1 << (j - 1))][j - 1]); n     } n   } n } n int query1(int id, int l, int r) { n   int k = lg[r - l + 1]; n   return min(st1[id][l][k], st1[id][r - (1 << k) + 1][k]); n } n int query2(int id, int l, int r) { n   int k = lg[r - l + 1]; n   return max(st2[id][l][k], st2[id][r - (1 << k) + 1][k]); n } n int queryl(int base, int l, int r) { n   int ans = query1(base, max(l, 1), min(r, n)); n   if (l <= 0) ans = max(-n + 1, min(ans, query1(base, l + n, n) - n)); n   if (r > n) ans = max(-n + 1, min(ans, query1(base, 1, r - n) + n)); n   return ans; n } n int queryr(int base, int l, int r) { n   int ans = query2(base, max(l, 1), min(r, n)); n   if (l <= 0) ans = min(n * 2, max(ans, query2(base, l + n, n) - n)); n   if (r > n) ans = min(n * 2, max(ans, query2(base, 1, r - n) + n)); n   return ans; n } n int main() { n   read(n); n   if (n == 1) { n     print(0,   n ); n     return 0; n   } n   lg[0] = -1; n   for (int i = 1; i <= n; i++) { n     read(a[i]); n     lg[i] = lg[i >> 1] + 1; n     st1[0][i][0] = i - a[i]; n     st2[0][i][0] = i + a[i]; n   } n   make_st(0); n   for (int base = 1; base <= 15; base++) { n     for (int i = 1; i <= n; i++) { n       int l = st1[base - 1][i][0], r = st2[base - 1][i][0]; n       st1[base][i][0] = queryl(base - 1, l, r); n       st2[base][i][0] = queryr(base - 1, l, r); n     } n     make_st(base); n   } n   for (int i = 1; i <= n; i++) { n     int l = i, r = i, ans = 0; n     for (int j = 15; j >= 0; j--) { n       int L = queryl(j, l, r), R = queryr(j, l, r); n       if (R - L + 1 < n) l = L, r = R, ans |= (1 << j); n     } n     print(ans + 1, i == n ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, c; n vector<int> locck[567567]; n const int S = 1 << 20; n int tree[2 * S]; n void loduj() { n   cin >> n >> c; n   int x, l; n   for (int i = 0; i < n; ++i) { n     cin >> l; n     for (int j = 0; j < l; ++j) { n       cin >> x; n       locck[i].push_back(x); n     } n   } n   for (int i = 1; i < 2 * S; ++i) { n     tree[i] = 1; n   } n } n void forbRec(int p, int q, int pp, int qq, int no) { n   if (q < pp || qq < p) { n     return; n   } n   if (p <= pp && qq <= q) { n     tree[no] = 0; n     return; n   } n   int ss = (pp + qq) / 2; n   forbRec(p, q, pp, ss, 2 * no); n   forbRec(p, q, ss + 1, qq, 2 * no + 1); n } n void forb(int p, int q) { forbRec(p, q, 0, S - 1, 1); } n bool isVal(int p) { n   p += S; n   while (p) { n     if (!tree[p]) { n       return 0; n     } n     p /= 2; n   } n   return 1; n } n void cons(int x, int y) { n   if (x < y) { n     forb(c - y + 1, c - x); n   } else { n     forb(0, c - x); n     forb(c - y + 1, c - 1); n   } n } n void cons(vector<int> &u, vector<int> &v) { n   int d = 0; n   while ((d < u.size()) && (d < v.size()) && u[d] == v[d]) { n     ++d; n   } n   if (d == u.size()) { n     return; n   } n   if (d == v.size()) { n     forb(0, c - 1); n     return; n   } n   cons(u[d], v[d]); n } n void makeInts() { n   for (int i = 0; i < n - 1; ++i) cons(locck[i], locck[i + 1]); n } n int solve() { n   for (int i = 0; i < c; ++i) n     if (isVal(i)) return i; n   return -1; n } n int main() { n   ios_base::sync_with_stdio(0); n   loduj(); n   makeInts(); n   cout << solve() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long MOD = 4207849484; n int main() { n   int n, m, i, g, h, j; n   char c; n   scanf( %d%d , &n, &m); n   vector<int> a(n + 1, 0), bl(n + 1, 0); n   for (int(i) = 0; (i) < (m); ++(i)) { n     getchar(); n     scanf( %c %d , &c, &g); n     if (c ==  + ) { n       if (bl[g]) { n         puts( Already on ); n         continue; n       } n       h = g; n       int b = 0; n       for (j = 2; j * j <= h && b == 0; j++) { n         if (h % j == 0) { n           if (a[h / j] || a[j]) { n             b = max(a[h / j], a[j]); n             break; n           } n         } n       } n       b = max(b, a[g]); n       if (b == 0) { n         bl[g] = 1; n         puts( Success ); n         h = g; n         for (j = 2; j * j <= h; j++) { n           if (h % j == 0) { n             a[h / j] = a[j] = h; n           } n         } n         a[h] = h; n       } else { n         printf( Conflict with %d n , b); n       } n     } else { n       if (bl[g] == 0) { n         puts( Already off ); n       } else { n         bl[g] = 0; n         h = g; n         for (j = 2; j * j <= h; j++) { n           if (h % j == 0) { n             a[h / j] = a[j] = 0; n           } n         } n         a[h] = 0; n         puts( Success ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   assert(n >= 1 && n <= 10000 && m >= 1 && m <= 10); n   if (n == m && (n == 1 || n == 2)) n     cout << n << endl; n   else { n     if (n == m) n       cout << n << endl; n     else { n       int t2 = 0, t1 = 0; n       if (n & 1) { n         n--; n         t1++; n       } n       t2 = n / 2; n       while ((t2 + t1) % m != 0 && n > 0) { n         n = n - 2; n         t1 = t1 + 2; n         t2 = n / 2; n       } n       if (n == 0) n         cout << -1 << endl; n       else n         cout << t1 + t2 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 2e18 + 9; n const long long MAXN = 1e6 + 7; n const long long MAXN1 = 5e2 + 7; n const long long MOD = 1e9 + 7; n const long long ST = 157; n const long long ST1 = 199; n const long double EPS = 1e-9; n const long long BLOCK = 138; n void solve(); n signed main() { n   srand( a  +  l  +  e  +  x  +  X  +  5  +  1  +  2 ); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n void solve() { n   int n; n   cin >> n; n   vector<pair<long long, int>> v; n   for (int i = 0; i < n; i++) { n     long long l, r; n     cin >> l >> r; n     v.emplace_back(l, -1); n     v.emplace_back(r, 1); n   } n   sort(v.begin(), v.end()); n   vector<long long> ans(n + 1); n   int b = -1; n   for (int i = 1; i < 2 * n; i++) { n     if (v[i].second == -1) { n       if (v[i - 1].second == 1) { n         ans[-b] += v[i].first - v[i - 1].first - 1; n       } else { n         ans[-b] += v[i].first - v[i - 1].first; n       } n     } else { n       if (v[i].first != v[i - 1].first || v[i - 1].second == -1) { n         if (v[i - 1].second == 1) n           ans[-b] += v[i].first - v[i - 1].first; n         else n           ans[-b] += v[i].first - v[i - 1].first + 1; n       } n     } n     b += v[i].second; n   } n   for (int i = 1; i <= n; i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int t = 1; n   cin >> t; n   while (t--) { n     long long int p, q, x; n     cin >> p >> q; n     long long int b = 0; n     set<long long int> pf; n     long long int cq = q; n     for (long long int i = 2; i * i <= cq; i++) { n       while (cq % i == 0) { n         pf.insert(i); n         cq /= i; n       } n     } n     if (cq > 1) pf.insert(cq); n     for (long long int i : pf) { n       long long int cp = p; n       while (cp % q == 0) cp /= i; n       b = max(b, cp); n     } n     cout << b << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double v, d, l, g, r; n   cin >> l >> d >> v >> g >> r; n   double t; n   t = d / v; n   double k = 0; n   while (k <= t) { n     k += g; n     if (t < k) { n       t += (l - d) / v; n       cout << setprecision(8) << t; n       exit(0); n     } n     k += r; n     if (t < k) { n       t += (k - t); n       t += (l - d) / v; n       cout << setprecision(8) << t; n       exit(0); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1); n const double eps = 0.000000001; n double dist(double x, double y) { return x * x + y * y; } n double xx, yy, v, t, x, y, r; n int n; n vector<pair<double, int> > vt; n int main() { n   scanf( %lf %lf %lf %lf %d , &xx, &yy, &v, &t, &n); n   if (t == 0) { n     for (int i = 0; i < n; ++i) { n       scanf( %lf %lf %lf , &x, &y, &r); n       if (dist(x - xx, y - yy) <= r * r) { n         printf( 1.00000 ); n         return 0; n       } n     } n     printf( 0.00 ); n     return 0; n   } n   v *= t; n   for (int i = 0; i < n; ++i) { n     scanf( %lf %lf %lf , &x, &y, &r); n     x -= xx; n     y -= yy; n     double dd = dist(x, y); n     double d = sqrt(dd); n     if (dd < r * r + eps) { n       printf( 1.0000 ); n       return 0; n     } n     if (d - eps > v + r) continue; n     double ang, ang1, ang2; n     ang = atan2(y, x); n     if (ang < 0) ang += pi * 2; n     if (dd - r * r < v * v + eps) n       ang1 = asin(r / d); n     else { n       double tmp = 0.5 * (v * v - r * r + dd) / (d * v); n       ang1 = acos(tmp); n     } n     ang2 = ang + ang1; n     ang1 = ang - ang1; n     if (ang1 < 0) { n       vt.push_back(pair<double, int>(ang1 + pi * 2, 1)); n       vt.push_back(pair<double, int>(pi * 2, -1)); n       vt.push_back(pair<double, int>(0.0, 1)); n       vt.push_back(pair<double, int>(ang2, -1)); n     } else if (ang2 > pi * 2) { n       vt.push_back(pair<double, int>(ang1, 1)); n       vt.push_back(pair<double, int>(pi * 2, -1)); n       vt.push_back(pair<double, int>(0.0, 1)); n       vt.push_back(pair<double, int>(ang2 - pi * 2, -1)); n     } else { n       vt.push_back(pair<double, int>(ang1, 1)); n       vt.push_back(pair<double, int>(ang2, -1)); n     } n   } n   double tot = 0, beg = 0; n   int cnt = 0; n   sort(vt.begin(), vt.end()); n   for (int i = 0; i < (int)vt.size(); ++i) { n     if (cnt > 0) tot += vt[i].first - beg; n     cnt += vt[i].second; n     beg = vt[i].first; n   } n   tot /= pi * 2; n   printf( %.12lf , tot); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nexto[120]; n int ara[120]; n int main() { n   std::ios_base::sync_with_stdio(false); n   ; n   int n; n   cin >> n; n   for (int i = 0; i <= n - 1; i++) { n     cin >> ara[i]; n   } n   int tt = n; n   for (int i = n - 1; i >= 0; i--) { n     nexto[i] = tt; n     if (ara[i] == 1) { n       tt = i; n     } n   } n   if (tt == n) { n     cout << 0 <<   n ; n     return 0; n   } n   nexto[n] = n; n   long long shuru; n   if (ara[0] == 1) { n     shuru = 0; n   } else { n     shuru = nexto[0]; n   } n   long long ans = 1; n   for (;;) { n     if (shuru >= n) { n       break; n     } n     long long shesh = nexto[shuru]; n     if (shesh >= n) { n       break; n     } n     ans *= (shesh - shuru); n     shuru = shesh; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n inline void chmin(A &a, B b) { n   if (a > b) a = b; n } n template <typename A, typename B> n inline void chmax(A &a, B b) { n   if (a < b) a = b; n } n string S; n long long dp[3333333]; n signed main() { n   for (long long i = 0; i < 26; i++) S += (char)( a  + i); n   for (long long i = 0; i < 26; i++) S += (char)( A  + i); n   fill_n(dp, 1111111, INT_MAX); n   dp[1] = 0; n   for (long long i = 1; i < 1111111; i++) { n     for (long long j = 1; j <= 2; j++) { n       chmin(dp[i * j + 1], dp[i] + 1); n     } n   } n   long long n; n   cin >> n; n   string s; n   long long cur = 0; n   while (n > 1) { n     if ((n - 1) & 1) { n       s += string(1, S[cur++]); n       n--; n     } else { n       s += string(2, S[cur++]); n       n = (n - 1) / 2; n     } n   } n   for (long long i = 0; i < S.size(); i++) s += S[i]; n   cout << s <<     << S << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   int n; n   long long l, first, second; n   cin >> n >> l >> first >> second; n   vector<long long> a(n); n   map<long long, bool> flag; n   for (int i = 0; i < int(n); i++) { n     cin >> a[i]; n     flag[a[i]] = true; n   } n   bool fx = false, fy = false; n   for (int i = n - 1; i >= 0; i--) { n     if (flag.count(a[i] - first)) fx = true; n     if (flag.count(a[i] - second)) fy = true; n   } n   if (!fx && !fy) { n     long long diff = second - first; n     for (int i = 0; i < n; i++) { n       if (flag.count(a[i] - diff)) { n         if (a[i] + first <= l) { n           cout << 1 <<   n ; n           cout << a[i] + first; n           return 0; n         } n         if (a[i] - second >= 0) { n           cout << 1 <<   n ; n           cout << a[i] - second; n           return 0; n         } n       } n     } n     long long add = first + second; n     for (int i = 0; i < n; i++) { n       if (flag.count(a[i] + add)) { n         if (a[i] + first <= l) { n           cout << 1 <<   n ; n           cout << a[i] + first; n           return 0; n         } n       } n     } n     cout << 2 <<   n ; n     cout << first <<     << second; n   } else if (!fx) { n     cout << 1 <<   n ; n     cout << first; n   } else if (!fy) { n     cout << 1 <<   n ; n     cout << second; n   } else n     cout <<  0 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n template <class T> n inline bool Min(T &a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n inline bool Max(T &a, T b) { n   return a < b ? (a = b, true) : false; n } n inline int ni() { n   int a; n   scanf( %d , &a); n   return a; n } n inline ll nl() { n   ll a; n   scanf( %lld , &a); n   return a; n } n inline double nd() { n   double a; n   scanf( %lf , &a); n   return a; n } n inline void pi(int a) { printf( %d  , a); } n inline void pl(ll a) { printf( %lld  , a); } n inline void pd(double a) { printf( %.12lf  , a); } n const int N = 2e5 + 100; n vector<int> gp[N]; n bool is_university[N]; n int n, k; n int cnt[N]; n ll ans = 0; n void dfs(int v, int p) { n   cnt[v] = is_university[v]; n   for (int next : gp[v]) n     if (next != p) n       dfs(next, v), cnt[v] += cnt[next], n           ans += min(cnt[next], k + k - cnt[next]); n } n void solve() { n   n = ni(); n   k = ni(); n   for (int i = 0; i < (int)(k + k); ++i) is_university[ni()] = true; n   for (int i = 0; i < (int)(n - 1); ++i) { n     int a = ni(); n     int b = ni(); n     gp[a].push_back(b); n     gp[b].push_back(a); n   } n   dfs(1, 1); n   pl(ans); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   int a[n], b[n]; n   map<pair<int, int>, int> mpa, mpb; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   for (int i = 0, j = n - 1; i < j; i++, j--) { n     int x = a[i]; n     int y = a[j]; n     if (x > y) swap(x, y); n     mpa[{x, y}]++; n   } n   for (int i = 0, j = n - 1; i < j; i++, j--) { n     int x = b[i]; n     int y = b[j]; n     if (x > y) swap(x, y); n     mpb[{x, y}]++; n   } n   bool ok = true; n   for (auto it : mpa) { n     if (it.second != mpb[{it.first.first, it.first.second}]) { n       ok = false; n       break; n     } n   } n   if (n % 2) { n     if (a[n / 2] != b[n / 2]) ok = false; n   } n   cout << (ok ?  YES n  :  NO n ); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   int t = 1; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int isprime(long long p) { n   int i; n   double max = sqrt(p); n   for (i = 2; i <= max; i++) n     if (p % i == 0) break; n   if (i > max && p != 1) return 1; n   return 0; n } n long long gcd(long long a, long long b) { n   long long i; n   for (i = a < b ? a : b; i > 0; i--) n     if ((a % i == 0) && (b % i == 0)) break; n   return i; n } n int comp(const void *a, const void *b) { return (*(int *)a - *(int *)b); } n int issame(int *a, int *b, int l) { n   qsort(a, l, sizeof(int), comp); n   qsort(b, l, sizeof(int), comp); n   int i; n   for (i = 0; i < l; i++) n     if (a[i] != b[i]) break; n   if (i == l) return 1; n   return 0; n } n void swap(int *a, int *b) { n   int x = *a; n   *a = *b; n   *b = x; n } n int arrmax(int *a, int l) { n   int i; n   int max = a[0]; n   for (i = 1; i < l; i++) n     if (a[i] > max) max = a[i]; n   return max; n } n int arrmin(int *a, int l) { n   int i; n   int min = a[0]; n   for (i = 1; i < l; i++) n     if (a[i] < min) min = a[i]; n   return min; n } n long long fact(int a) { n   long long p = 1; n   while (a > 0) p *= a--; n   return p; n } n int min(int a, int b) { n   if (a > b) return b; n   return a; n } n int max(int a, int b) { n   if (a < b) return b; n   return a; n } n void sieve(int *a, int n) { n   n--; n   long long i, j; n   for (i = 2; i <= n; i++) a[i] = 0; n   for (i = 2; i <= n; i++) n     if (!a[i]) n       for (j = i * i; j <= n; j += i) n         if (!a[j]) a[j]++; n } n int main(void) { n   int t; n   scanf( %d , &t); n   while (t--) { n     char b[100]; n     scanf( %s , b); n     int l = strlen(b); n     char c[l / 2 + 1]; n     int i; n     for (i = 1; i < l; i += 2) c[i / 2 + 1] = b[i]; n     c[0] = b[0]; n     for (i = 0; i < l / 2 + 1; i++) printf( %c , c[i]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool chkmin(T &x, T y) { n   return y < x ? x = y, 1 : 0; n } n template <class T> n inline bool chkmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n inline long long Max(long long x, long long y) { return x > y ? x : y; } n inline long long Min(long long x, long long y) { return x < y ? x : y; } n int n, m; n int res; n map<int, int> lck; n map<int, int>::iterator it; n long long fac[100002], inv[100002]; n long long dp[100002]; n void Add(long long &x, long long y) { n   x += y; n   if (x >= 1000000007) n     x -= 1000000007; n   else if (x < 0) n     x += 1000000007; n } n bool check(int x) { n   while (x) { n     if (x % 10 != 4 && x % 10 != 7) return 0; n     x /= 10; n   } n   return 1; n } n void Init() { n   fac[0] = fac[1] = 1; n   inv[0] = inv[1] = 1; n   for (int i = (2), i_end_ = (100002); i < i_end_; i++) n     fac[i] = fac[i - 1] * i % 1000000007; n   for (int i = (2), i_end_ = (100002); i < i_end_; i++) n     inv[i] = (1000000007 - (1000000007 / i)) * inv[1000000007 % i] % 1000000007; n   for (int i = (2), i_end_ = (100002); i < i_end_; i++) n     inv[i] = inv[i] * inv[i - 1] % 1000000007; n } n long long C(int n, int m) { n   if (n < 0 || m > n) return 0; n   return fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007; n } n int main() { n   Init(); n   scanf( %d%d , &n, &m); n   for (int i = (1), i_end_ = (n); i <= i_end_; i++) { n     int x; n     scanf( %d , &x); n     if (check(x)) n       lck[x]++; n     else n       res++; n   } n   int tot = 0; n   dp[0] = 1; n   for (it = lck.begin(); it != lck.end(); it++) { n     tot++; n     for (int i = (min(tot, m)), i_end_ = (1); i >= i_end_; i--) n       Add(dp[i], dp[i - 1] * it->second % 1000000007); n   } n   long long ans = 0; n   for (int i = (0), i_end_ = (min(tot, m)); i <= i_end_; i++) n     Add(ans, dp[i] * C(res, m - i) % 1000000007); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = 1e9 + 9; n const long long N = 500500; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long T; n   cin >> T; n   while (T--) { n     long long n, k; n     cin >> n >> k; n     string s, t; n     cin >> s; n     vector<pair<long long, long long> > ans; n     for (long long i = 1; i <= k - 1; i++) { n       t +=  () ; n     } n     for (long long i = 1; i <= (n - (2 * k) + 2) / 2; i++) { n       t +=  ( ; n     } n     for (long long i = 1; i <= (n - (2 * k) + 2) / 2; i++) { n       t +=  ) ; n     } n     for (long long i = 0; i < n; i++) { n       if (s[i] == t[i]) continue; n       for (long long j = i + 1; j < n; j++) { n         if (s[j] == t[i]) { n           ans.push_back({i + 1, j + 1}); n           reverse(s.begin() + i, s.begin() + j + 1); n           break; n         } n       } n     } n     cout << ans.size() <<   n ; n     for (auto z : ans) { n       cout << z.first <<     << z.second <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, ans = 0, flag = 0; n   int arr[100]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] != arr[i + 1]) { n       flag = 1; n     } n   } n   if (flag == 0) { n     cout << ans << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     if (arr[i] == 0 && arr[i - 1] == 1 && arr[i + 1] == 1) { n       arr[i + 1] = 0; n       ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5e5 + 5, Mod = 998244353; n char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc; n int ny; n inline char gc() { n   return pp1 == pp2 && n                  (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) n              ? EOF n              : *pp1++; n } n inline int read() { n   int x = 0; n   for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;) n     if (nc == 45) ny = -1; n   if (nc < 0) return nc; n   for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF; n        x = (x << 3) + (x << 1) + (nc ^ 48)) n     ; n   return x * ny; n } n int n, k, m, ans = 1, s[MAXN], Mn[MAXN], l[MAXN], r[MAXN], c[MAXN], f[MAXN], n              q[MAXN], head, tail; n inline void add(int& x, int y) { x += y, x >= Mod ? x -= Mod : 0; } n inline void sub(int& x, int y) { x -= y, x < 0 ? x += Mod : 0; } n inline int Solve(int k) { n   memset(s, 0, sizeof(s)); n   for (int i = 1; i <= n; i++) Mn[i] = n + 1; n   for (int i = 1; i <= m; i++) { n     if (c[i] >> k & 1) n       s[l[i]]++, s[r[i] + 1]--; n     else n       Mn[l[i]] = min(Mn[l[i]], r[i]); n   } n   for (int i = 1; i <= n; i++) s[i] += s[i - 1]; n   memset(f, 0, sizeof(f)), f[n + 1] = 1, q[head = tail = 1] = n + 1; n   int sum = 1; n   for (int i = 1; i <= n; i++) { n     int tmp = 0; n     for (; q[tail] >= Mn[i] && head <= tail; n          add(tmp, f[q[tail]]), f[q[tail]] = 0, tail--) n       ; n     for (f[Mn[i]] = tmp, q[++tail] = Mn[i]; q[head] < i && head <= tail; n          sub(sum, f[q[head]]), head++) n       ; n     if (!s[i]) add(f[n + 1], sum), sum = 2 * sum % Mod; n     (q[tail] != n + 1 ? q[++tail] = n + 1 : 0); n   } n   return f[n + 1]; n } n int main() { n   n = read(), k = read(), m = read(); n   for (int i = 1; i <= m; i++) l[i] = read(), r[i] = read(), c[i] = read(); n   for (int i = 0; i <= k - 1; i++) ans = 1ll * ans * Solve(i) % Mod; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 111111; n const double inf = 0.000001; n const int INF = ~0U >> 1; n const int mod = 1000000007; n int n, a[maxn], m; n int equal(double x, double y) { n   if (x - y >= -inf && x - y <= inf) n     return 0; n   else if (x - y > inf) n     return 1; n   return -1; n } n int main() { n   scanf( %d , &n), scanf( %d , &m); n   if (m < n / 2 || (n == 1 && m)) n     printf( %d n , -1); n   else if (n == 1 && m == 0) n     printf( %d n , 1); n   else { n     int ans = m - n / 2 + 1; n     printf( %d %d , ans, ans * 2); n     ans *= 2; n     for (int i = 2; i < n; i++) printf(  %d , (++ans)); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n vector<vector<long long>> ft(12, vector<long long>(100005, 0)); n void add(long long kk, long long ind, long long val) { n   while (ind <= n) { n     ft[kk][ind] += val; n     ind += ind & -ind; n   } n } n long long sum(long long kk, long long ind) { n   long long res = 0; n   while (ind > 0) { n     res += ft[kk][ind]; n     ind -= ind & -ind; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> k; n   vector<long long> arr(n + 1); n   for (int i = 1; i < n + 1; i++) cin >> arr[i]; n   for (int i = 1; i < n + 1; i++) { n     for (int j = 1; j < 12; j++) { n       if (j == 1) n         add(1, arr[i], 1); n       else { n         long long val = sum(j - 1, arr[i] - 1); n         add(j, arr[i], val); n       } n     } n   } n   cout << sum(k + 1, n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int n, S = 0; n char x[2], s[MAXN]; n int viv[MAXN]; n bool use[MAXN]; n int cqf() { n   int l = -1, r = -1; n   int ans = MAXN, sum = 0; n   while (true) { n     while (r <= n && sum < S) { n       r++; n       if (!viv[s[r]] && use[s[r]]) sum++; n       viv[s[r]]++; n     } n     if (sum < S) break; n     ans = min(ans, r - l + 1); n     if (viv[s[l]] == 1 && use[s[l]]) sum--; n     viv[s[l]]--; n     l++; n   } n   return ans; n } n int main() { n   memset(viv, 0, sizeof(viv)); n   memset(use, 0, sizeof(use)); n   scanf( %d , &n); n   gets(x); n   gets(s); n   for (int i = 0; i < n; i++) { n     if (use[s[i]] == false) S++; n     use[s[i]] = true; n   } n   printf( %d n , cqf()); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::string input(  ), answer(  ), output(  ); n   getline(std::cin, input); n   getline(std::cin, answer); n   int count[10] = {0}; n   char minNonZero( A ); n   for (int k = 0; k < input.size(); k++) { n     ++count[input[k] -  0 ]; n     if (input[k] >  0  && input[k] < minNonZero) { n       minNonZero = input[k]; n     } n   } n   if (minNonZero ==  A ) { n     output =  0 ; n   } else { n     --count[minNonZero -  0 ]; n     output += minNonZero; n     for (int digit = 0; digit < 10; digit++) { n       while (count[digit]--) { n         output += ( 0  + digit); n       } n     } n   } n   if (answer == output) { n     puts( OK ); n   } else { n     puts( WRONG_ANSWER ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n int S[N], E[N], T[N], C[N]; n int t[N], W[N]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   int i; n   for (i = 1; i <= n; i++) { n     t[i] = 1006; n     W[i] = -1; n   } n   for (i = 1; i <= m; i++) { n     scanf( %d %d %d %d , &S[i], &E[i], &T[i], &C[i]); n     for (int j = S[i]; j <= E[i]; j++) { n       if (T[i] < t[j]) { n         t[j] = T[i]; n         W[j] = i; n       } n     } n   } n   int sum = 0; n   for (i = 1; i <= n; i++) { n     if (W[i] != -1) { n       sum += C[W[i]]; n     } n   } n   printf( %d n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long l[200001], r[200001]; n struct data { n   long long l, r, ans, num; n   bool operator<(const data &p) const { return r > p.r; } n } a[300001]; n priority_queue<data> q; n bool cmp(data p, data q) { n   if (p.l == q.l) return p.num < q.num; n   return p.l < q.l; n } n bool cmp2(data p, data q) { return p.num < q.num; } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %lld%lld , &l[i], &r[i]); n   for (int i = 1; i < n; i++) { n     a[i].l = l[i + 1] - r[i]; n     a[i].r = r[i + 1] - l[i]; n     a[i].num = i; n   } n   for (int i = n; i <= m + n - 1; i++) { n     long long x; n     scanf( %lld , &x); n     a[i].num = i; n     a[i].l = x; n   } n   sort(a + 1, a + m + n, cmp); n   for (int i = 1; i <= m + n - 1; i++) { n     if (a[i].num < n) { n       data now = a[i]; n       now.num = i; n       q.push(now); n       continue; n     } n     if (q.empty()) continue; n     data now = q.top(); n     q.pop(); n     if (now.r < a[i].l) { n       printf( No n ); n       return 0; n     } n     a[now.num].ans = a[i].num - n + 1; n   } n   if (!q.empty()) { n     printf( No n ); n     return 0; n   } n   printf( Yes n ); n   sort(a + 1, a + n + m, cmp2); n   for (int i = 1; i < n; i++) printf( %d  , a[i].ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, e, f; n   cin >> a >> b >> c >> d >> e >> f; n   long k = min(d, min(c, b)); n   long m = min(a, d); n   long cost = 0; n   if (e > f) { n     d = d - m; n     cost = m * e + min(d, min(c, b)) * f; n   } else { n     d = d - k; n     cost = k * f + min(a, d) * e; n   } n   cout << cost << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, L, K; n string s; n int cnt[26]; n string res[1000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> N >> L >> K; n   cin >> s; n   for (int i = 0; i < N * L; i++) cnt[s[i] -  a ]++; n   int l = 0; n   int t = 0; n   while (l < K - 1 and t < 26) { n     int st = cnt[t]; n     for (int j = 0, _t = cnt[t]; j < _t; j++) { n       if (res[l + j % (K - l)].size() == L) { n         l = K + 1; n         break; n       } n       res[l + j % (K - l)] += (char)(t +  a ); n       cnt[t]--; n     } n     l += st % (K - l); n     t++; n   } n   int lst = 25; n   for (int i = 0; i < K - 1; i++) { n     while (res[i].size() < L) { n       while (cnt[lst] == 0) lst--; n       res[i] += (char)(lst +  a ); n       cnt[lst]--; n     } n   } n   int fst = 0; n   for (int i = K - 1; i < N; i++) { n     while (res[i].size() < L) { n       while (cnt[fst] == 0) fst++; n       res[i] += (char)(fst +  a ); n       cnt[fst]--; n     } n   } n   sort(res, res + N); n   for (int i = 0; i < N; i++) { n     cout << res[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n > 2) n     cout << n - 2 << endl; n   else n     cout <<  7  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long int justgreater(long long int n) { n   long long int i; n   for (i = 1;; i++) n     if (i * (i + 1) / 2 > n) break; n   return i - 1; n } n int main() { n   long long int m, n, a[100009] = {0}, sum = 0, cnt = 0; n   cin >> m >> n; n   long long int up = justgreater(m + n); n   long long int tup = up; n   for (; tup >= 1; tup--) { n     if (sum + tup > m) continue; n     sum += tup; n     a[tup]++; n   } n   long long int cnt0 = 0, cnt1 = 0; n   for (long long int i = 1; i <= up; i++) n     if (a[i] == 1) n       cnt0++; n     else n       cnt1++; n   cout << cnt0 << endl; n   for (long long int i = 1; i <= up; i++) n     if (a[i] == 1) cout << i <<    ; n   cout << endl; n   cout << cnt1 << endl; n   for (long long int i = 1; i <= up; i++) n     if (a[i] == 0) cout << i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = acos(-1.0); n long long n, maxl = 2e5; n long long montonic(vector<long long> &b) { n   bool inc = true, dec = true; n   long long n = (long long)b.size(); n   for (long long i = 1; i < n; ++i) { n     if (b[i] <= b[i - 1]) { n       inc = false; n     } n     if (b[i] >= b[i - 1]) { n       dec = false; n     } n   } n   if (inc == 1) { n     return 1; n   } n   if (dec == 1) { n     return 0; n   } else n     return -1; n } n void f(vector<long long> &a, vector<long long> &b) { n   string ans =   ; n   while (true) { n     if (b == a) { n       break; n     } else { n       vector<long long> c = b; n       reverse(c.begin(), c.end()); n       if (c == a) { n         ans +=  R ; n         break; n       } n     } n     long long m = montonic(b); n     if (m == -1) { n       cout <<  IMPOSSIBLE  <<   n ; n       return; n     } else { n       if (m == 0) { n         reverse(b.begin(), b.end()); n         ans +=  R ; n       } else { n         for (long long i = n - 1; i >= 1; --i) b[i] -= b[i - 1]; n         ans +=  P ; n       } n     } n   } n   if ((long long)ans.size() > maxl) { n     cout <<  BIG  <<   n ; n     long long cnt = 0; n     for (long long i = 0; i < (long long)ans.size(); ++i) n       if (ans[i] ==  P ) ++cnt; n     cout << cnt <<   n ; n   } else { n     cout <<  SMALL  <<   n ; n     cout << (long long)ans.size() <<   n ; n     reverse(ans.begin(), ans.end()); n     cout << ans <<   n ; n   } n } n void solve() { n   cin >> n; n   if (n == 1) { n     long long a; n     cin >> a; n     long long b; n     cin >> b; n     if (b % a) { n       cout <<  IMPOSSIBLE  <<   n ; n       return; n     } else { n       long long op = b / a - 1; n       if (op > maxl) { n         cout <<  BIG  <<   n ; n         cout << op <<   n ; n       } else { n         cout <<  SMALL  <<   n ; n         cout << op <<   n ; n       } n     } n   } else if (n == 2) { n     vector<long long> a(n), b(n); n     for (long long i = 0; i < n; ++i) cin >> a[i]; n     for (long long i = 0; i < n; ++i) cin >> b[i]; n     vector<long long> c = a; n     vector<long long> d = b; n     long long popr = 0; n     sort(c.begin(), c.end()); n     sort(d.begin(), d.end()); n     long long op = 0; n     while (d[0] != c[0]) { n       if (d[0] == 0) { n         cout <<  IMPOSSIBLE  <<   n ; n         return; n       } n       op += d[1] / d[0]; n       d[1] %= d[0]; n       swap(d[0], d[1]); n     } n     if ((d[1] - c[1]) % c[0]) { n       cout <<  IMPOSSIBLE  <<   n ; n       return; n     } else n       op += (d[1] - c[1]) / c[0]; n     if (op > maxl) { n       cout <<  BIG  <<   n ; n       cout << op <<   n ; n     } else n       f(a, b); n   } else { n     vector<long long> a(n), b(n); n     for (long long i = 0; i < n; ++i) cin >> a[i]; n     for (long long i = 0; i < n; ++i) cin >> b[i]; n     f(a, b); n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1 << 30; n const long long maxn = 1e6 + 10; n int a[4], b[10] = {0, 1, 2, 0, 2, 1, 0}, c[4]; n int check(int w) { n   int sum = 0; n   for (int i = 0; i < 3; i++) c[i] = a[i]; n   for (int i = w; i < 7; i++) { n     if (c[b[i]] == 0) break; n     --c[b[i]], ++sum; n   } n   int weeks = min(c[0] / 3, min(c[1] / 2, c[2] / 2)); n   c[0] -= weeks * 3, c[1] -= weeks * 2, c[2] -= weeks * 2, sum += weeks * 7; n   for (int i = 0; i < 7; i++) { n     if (c[b[i]] == 0) break; n     --c[b[i]], ++sum; n   } n   return sum; n } n int main() { n   for (int i = 0; i < 3; i++) cin >> a[i]; n   if (a[0] == 1 && a[1] == 1 && a[2] == 2) { n     cout <<  4  << endl; n     return 0; n   } n   int ans = 0; n   for (int i = 0; i < 7; i++) { n     ans = max(ans, check(i)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5; n long long read() { n   long long s = 0; n   char c = getchar(), lc =  + ; n   while (c <  0  ||  9  < c) lc = c, c = getchar(); n   while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar(); n   return lc ==  -  ? -s : s; n } n void write(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x < 10) n     putchar(x +  0 ); n   else n     write(x / 10), putchar(x % 10 +  0 ); n } n void print(long long x, char c =   n ) { n   write(x); n   putchar(c); n } n long long a[N], n, q; n struct node { n   long long sum, len, tag; n   node() { tag = -1; } n   void update(long long x) { n     tag = x; n     sum = len * x; n   } n } t[N * 4]; n node operator+(const node &a, const node &b) { n   node ret; n   ret.sum = a.sum + b.sum; n   ret.len = a.len + b.len; n   return ret; n } n void push_down(long long w) { n   if (!~t[w].tag) return; n   t[(w * 2)].update(t[w].tag); n   t[(w * 2 + 1)].update(t[w].tag); n   t[w].tag = -1; n } n void cover(long long w, long long l, long long r, long long ql, long long qr, n            long long x) { n   if (r < ql || qr < l) return; n   if (ql <= l && r <= qr) return t[w].update(x); n   if (l < r) push_down(w); n   cover((w * 2), l, ((l + r) / 2), ql, qr, x); n   cover((w * 2 + 1), ((l + r) / 2) + 1, r, ql, qr, x); n   t[w] = t[(w * 2)] + t[(w * 2 + 1)]; n } n long long query(long long w, long long l, long long r, long long ql, n                 long long qr) { n   if (r < ql || qr < l) return 0; n   if (ql <= l && r <= qr) return t[w].sum; n   if (l < r) push_down(w); n   return query((w * 2), l, ((l + r) / 2), ql, qr) + n          query((w * 2 + 1), ((l + r) / 2) + 1, r, ql, qr); n } n void build(long long w, long long l, long long r) { n   if (l == r) { n     t[w].len = 1; n     t[w].sum = 0; n     return; n   } n   build((w * 2), l, ((l + r) / 2)); n   build((w * 2 + 1), ((l + r) / 2) + 1, r); n   t[w] = t[(w * 2)] + t[(w * 2 + 1)]; n } n set<long long> d; n void insert(long long x) { n   if (d.find(x) != d.end()) return; n   auto r = d.lower_bound(x); n   cover(1, 1, n, (*--r) + 1, x, n - x); n   d.insert(x); n } n void erase(long long x) { n   if (d.find(x) == d.end()) return; n   auto p = d.find(x), l = p, r = p; n   l--, r++; n   cover(1, 1, n, (*l) + 1, x, n - (*r)); n   d.erase(p); n } n inline long long calc(long long l, long long r) { n   return (l + r) * (r - l + 1) / 2; n } n signed main(signed bangumi, char *ss969[]) { n   (void)bangumi, (void)ss969; n   n = read(), q = read(); n   for (long long i = 1; i <= n; i++) a[i] = read(); n   build(1, 1, n); n   d.insert(0), d.insert(n); n   for (long long i = 1; i < n; i++) n     if (a[i] > a[i + 1]) insert(i); n   while (q--) { n     long long opt = read(), x = read(), y = read(); n     if (opt == 1) { n       a[x] = y; n       if (x > 1) { n         if (a[x - 1] <= a[x]) n           erase(x - 1); n         else n           insert(x - 1); n       } n       if (x < n) { n         if (a[x] <= a[x + 1]) n           erase(x); n         else n           insert(x); n       } n     } else { n       if (y == n) { n         print(calc(n - y + 1, n - x + 1) - query(1, 1, n, x, y)); n         continue; n       } n       auto p = d.upper_bound(y); n       long long tmp = max(*--p, x - 1); n       print(calc(n - y + 1, n - x + 1) - query(1, 1, n, x, tmp) - n             (y - tmp) * (n - y)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n int n; n bool M[1005][1005]; n int q; n bool ans = 0; n void setMatrix() { n   for (int i = 0; i < n; i++) n     if (M[i][i]) ans = !ans; n } n void CallEdit() { n   int i; n   scanf( %d , &i); n   ans = !ans; n } n void CallPuts() { printf( %d , ans); } n void solve() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) scanf( %d , &M[i][j]); n   setMatrix(); n   scanf( %d , &q); n   while (q--) { n     int flag; n     scanf( %d , &flag); n     switch (flag) { n       case 1: { n         CallEdit(); n         break; n       } n       case 2: { n         CallEdit(); n         break; n       } n       case 3: { n         CallPuts(); n         break; n       } n       default: n         break; n     } n   } n   printf(  n ); n   return; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 10000010; n int p[maxn]; n int main() { n   int i, j, st, a, n, maxi; n   long long ans = 0; n   scanf( %d%d , &a, &n); n   maxi = (int)(sqrt(a + n - 1) + 1e-7); n   for (i = 1; i <= maxi; i++) { n     st = (int)(a / (i * i) + 1e-7) * i * i; n     for (j = st; j <= a + n - 1; j += i * i) p[j] = i * i; n   } n   for (i = a; i <= a + n - 1; i++) ans += i / p[i]; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int main() { n   int n, m, c; n   cin >> n >> m >> c; n   for (int i = 1; i <= m; i++) { n     int x, ans; n     cin >> x; n     if (x <= c / 2) { n       for (int j = 1; j <= n; j++) { n         if (x < a[j] || a[j] == 0) { n           a[j] = x; n           ans = j; n           break; n         } n       } n     } else { n       for (int j = n; j >= 1; j--) { n         if (x > a[j] || a[j] == 0) { n           a[j] = x; n           ans = j; n           break; n         } n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n using namespace std; n const long long INF = 1LL << 60; n const double PI = acos(-1); n using ll = long long; n using P = array<ll, 2>; n template <typename T> n istream& operator>>(istream& i, vector<T>& v) { n   for (ll j = (0); j < (ll)(v.size()); ++j) i >> v[j]; n   return i; n } n template <typename T> n string join(vector<T>& v) { n   stringstream s; n   for (ll i = (0); i < (ll)(v.size()); ++i) s <<     << v[i]; n   return s.str().substr(1); n } n template <typename T> n ostream& operator<<(ostream& o, vector<T>& v) { n   if (v.size()) o << join(v); n   return o; n } n template <typename T> n string join(vector<vector<T>>& vv) { n   string s =   n ; n   for (ll i = (0); i < (ll)(vv.size()); ++i) s += join(vv[i]) +   n ; n   return s; n } n template <typename T> n ostream& operator<<(ostream& o, vector<vector<T>>& vv) { n   if (vv.size()) o << join(vv); n   return o; n } n template <typename T1, typename T2> n istream& operator>>(istream& i, pair<T1, T2>& v) { n   return i >> v.first >> v.second; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& o, pair<T1, T2>& v) { n   return o <<  (  << v.first <<  ,  << v.second <<  ) ; n } n template <typename T> n istream& operator>>(istream& i, array<T, 2>& v) { n   i >> v[0] >> v[1]; n   return i; n } n template <typename T> n ostream& operator<<(ostream& o, array<T, 2>& v) { n   return o <<  (  << v[0] <<  ,  << v[1] <<  ) ; n   return o; n } n int dx[4]{0, 1, 0, -1}; n int dy[4]{1, 0, -1, 0}; n void init_init_init() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   std::cout << fixed << setprecision(10); n } n template <class T> n T up(T a, T b) { n   assert(b); n   return (a + b - 1) / b; n } n template <typename... A> n bool eq(A const&... a) { n   auto t = {a...}; n   assert(t.size()); n   auto tar = *t.begin(); n   for (const auto& e : t) n     if (tar != e) return false; n   return true; n } n template <class T> n bool chmin(T& a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n bool chmax(T& a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n bool chmax(T& a, initializer_list<T> l) { n   return chmax(a, max(l)); n } n template <class T> n bool chmin(T& a, initializer_list<T> l) { n   return chmin(a, min(l)); n } n int main(int argc, char** argv) { n   init_init_init(); n   ll x1, y1, x2, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   ll x3, y3, x4, y4; n   cin >> x3 >> y3 >> x4 >> y4; n   ll x5, y5, x6, y6; n   cin >> x5 >> y5 >> x6 >> y6; n   x1 *= 2, x2 *= 2, x3 *= 2, x4 *= 2, x5 *= 2, x6 *= 2; n   y1 *= 2, y2 *= 2, y3 *= 2, y4 *= 2, y5 *= 2, y6 *= 2; n   bool is{false}; n   for (ll x = x1; x <= x2; x++) { n     ll y = y1; n     if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or n           (x5 <= x and x <= x6 and y5 <= y and y <= y6))) { n       is = true; n     } n     y = y2; n     if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or n           (x5 <= x and x <= x6 and y5 <= y and y <= y6))) { n       is = true; n     } n   } n   for (ll y = y1; y <= y2; ++y) { n     ll x = x1; n     if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or n           (x5 <= x and x <= x6 and y5 <= y and y <= y6))) { n       is = true; n     } n     x = x2; n     if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or n           (x5 <= x and x <= x6 and y5 <= y and y <= y6))) { n       is = true; n     } n   } n   auto ok = is; n   std::cout << (ok ?  YES  :  NO ) << std::endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n struct T { n   int id, v, c, l, r, sum, prev; n   void read(int ii) { n     id = ii; n     scanf( %d%d%d%d , &v, &c, &l, &r); n   } n   int total() { return c + l + r; } n }; n int n; n map<int, vector<T> > gr; n vector<int> ans; n int res; n map<int, pair<int, int> > d; n int main() { n   scanf( %d , &n); n   for (int i = 0, _n = (n); i < _n; i++) { n     T x; n     x.read(i); n     gr[x.total()].push_back(x); n   } n   res = 0; n   for (map<int, vector<T> >::iterator git = gr.begin(); git != gr.end(); n        ++git) { n     vector<T>& a = git->second; n     d.clear(); n     d[0] = pair<int, int>(0, -1); n     int n = (int)(a).size(); n     for (int i = 0, _n = (n); i < _n; i++) { n       map<int, pair<int, int> >::iterator it = d.find(a[i].l); n       if (it == d.end()) continue; n       a[i].prev = it->second.second; n       int newcost = it->second.first + a[i].v; n       map<int, pair<int, int> >::iterator it2 = d.find(a[i].l + a[i].c); n       if (it2 == d.end() || it2->second.first < newcost) { n         d[a[i].l + a[i].c] = pair<int, int>(newcost, i); n       } n     } n     int total = git->first; n     if (d.count(total) == 0) continue; n     if (d[total].first <= res) continue; n     res = d[total].first; n     int last = d[total].second; n     ans.clear(); n     for (; last != -1; last = a[last].prev) ans.push_back(a[last].id); n     reverse((ans).begin(), (ans).end()); n   } n   printf( %d n , (int)(ans).size()); n   for (int i = 0, _n = ((int)(ans).size()); i < _n; i++) n     printf(  %d  + (i == 0), ans[i] + 1); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline string toString(T a) { n   ostringstream os(  ); n   os << a; n   return os.str(); n } n template <typename T> n inline long long toLong(T a) { n   long long res; n   istringstream os(a); n   os >> res; n   return res; n } n template <typename T> n inline T S(T a) { n   return a * a; n } n template <typename T> n inline T gcd(T a, T b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n template <typename T> n inline unsigned long long bigmod(T a, T b, T m) { n   if (b == 0) n     return 1; n   else if (b % 2 == 0) n     return S(bigmod(a, b / 2, m)) % m; n   else n     return (a % m * bigmod(a, b - 1, m)) % m; n } n template <typename T> n inline vector<string> parse(T str) { n   vector<string> res; n   string s; n   istringstream os(str); n   while (os >> s) res.push_back(s); n   return res; n } n template <typename T> n inline unsigned long long dist(T A, T B) { n   unsigned long long res = n       (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y); n   return res; n } n template <typename T> n inline double cosAngle(T a, T b, T c) { n   double res = a * a + b * b - c * c; n   res = res / (2 * a * b); n   res = acos(res); n   return res; n } n template <typename T> n inline T power(T base, int po) { n   T res = 1; n   if (base == 0) return 0; n   for (int i = (0); i < (po); i++) res *= base; n   return res; n } n template <typename T> n inline bool isOn(T mask, T pos) { n   return mask & (1 << pos); n } n template <typename T> n inline int Off(T mask, T pos) { n   return mask ^ (1 << pos); n } n template <typename T> n inline int On(T mask, T pos) { n   return mask | (1 << pos); n } n long long arr[10005]; n vector<int> v[5000]; n long long dp[2005][2005]; n int Size[2005]; n int N; n int main() { n   int i, j, k; n   int n, q; n   long long x, y; n   int ks, cas; n   int kk; n   cin >> n >> kk; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= i; j++) { n       if (i % j == 0) { n         v[i].push_back(j); n       } n     } n   } n   for (i = 0; i <= n; i++) { n     Size[i] = v[i].size(); n   } n   memset(dp, 0, sizeof dp); n   for (i = 1; i <= n; i++) { n     dp[1][i] = 1; n   } n   for (i = 2; i <= kk; i++) { n     for (j = 1; j <= n; j++) { n       for (k = 0; k < Size[j]; k++) { n         dp[i][j] = (dp[i][j] + dp[i - 1][v[j][k]]) % 1000000007; n       } n     } n   } n   long long res = 0; n   for (i = 1; i <= n; i++) { n     res = (res + dp[kk][i]) % 1000000007; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long bigmod(long long x, int p) { n   long long res = 1; n   while (p) { n     if (p & 1) res = (res * x) % 998244353; n     x = (x * x) % 998244353; n     p >>= 1; n   } n   return res; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<long long> d(n), pref(n); n   for (int i = 0; i < n; i++) cin >> d[i]; n   sort(d.begin(), d.end()); n   pref[0] = d[0]; n   for (int i = 1; i < n; i++) pref[i] = (pref[i - 1] + d[i]) % 998244353; n   while (m--) { n     int a, b; n     cin >> a >> b; n     int x = lower_bound(d.begin(), d.end(), b) - d.begin(); n     int big = n - x; n     if (big < a) { n       cout << 0 <<   n ; n       continue; n     } n     long long big_total = (pref[n - 1] - (x > 0 ? pref[x - 1] : 0)) % 998244353; n     (big_total += 998244353) %= 998244353; n     long long ans = (big_total * (big - a)) % 998244353; n     ans = (ans * bigmod(big, 998244353 - 2)) % 998244353; n     long long tmp = ((x > 0 ? pref[x - 1] : 0) * (big + 1 - a)) % 998244353; n     tmp = (tmp * bigmod(big + 1, 998244353 - 2)) % 998244353; n     ans = (ans + tmp) % 998244353; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = 3.14159265358979323846264338327950288419716939937510, n                   EPS = 1e-9; n const int MAX = 1 << 17; n struct prav { n   long double a, b, c; n }; n pair<int, int> sred; n long double Sq(long double x) { return x * x; } n long double Dist(pair<int, int> a, pair<int, int> b) { n   return sqrt(Sq(a.first - b.first) + Sq(a.second - b.second)); n } n long double DistPrav(prav p, pair<int, int> toc) { n   return abs(p.a * toc.first + p.b * toc.second + p.c) / n          sqrt((Sq(p.a) + Sq(p.b))); n } n prav Pravac(pair<int, int> a, pair<int, int> b) { n   return prav{ n       (long double)b.second - a.second, (long double)a.first - b.first, n       (long double)b.first * a.second - (long double)a.first * b.second}; n } n pair<int, int> tocke[MAX]; n int main() { n   int n; n   scanf( %d%d%d , &n, &sred.first, &sred.second); n   for (int i = 0; i < n; i++) scanf( %d%d , &tocke[i].first, &tocke[i].second); n   long double minn = 1e15, maxx = -1e15; n   for (int i = 0; i < n; i++) { n     long double dd = Dist(sred, tocke[i]); n     minn = min(minn, dd); n     maxx = max(maxx, dd); n     int slj = (i + 1) % n; n     if (Sq(Dist(tocke[i], tocke[slj])) + Sq(Dist(tocke[i], sred)) + EPS > n             Sq(Dist(tocke[slj], sred)) && n         Sq(Dist(tocke[i], tocke[slj])) + Sq(Dist(tocke[slj], sred)) + EPS > n             Sq(Dist(tocke[i], sred))) { n       minn = min(minn, DistPrav(Pravac(tocke[i], tocke[slj]), sred)); n     } n   } n   printf( %.15lf n , (double)((Sq(maxx) - Sq(minn)) * PI)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n int n; n vector<int> nailed; n struct evn { n   int pos, type, num; n }; n vector<evn> events; n bool comp(const evn& a, const evn& b) { n   if (a.pos == b.pos && a.type == b.type) return a.num < b.num; n   if (a.pos == b.pos) return a.type == 0; n   return a.pos < b.pos; n } n int main() { n   srand(chrono::steady_clock::now().time_since_epoch().count()); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   nailed.resize(n, 0); n   int l, r; n   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n        i += 1 - 2 * ((0) > (n))) { n     cin >> l >> r; n     if (r < l) swap(l, r); n     evn a, b; n     a.pos = l; n     a.num = i; n     a.type = 0; n     events.push_back(a); n     b.pos = r; n     b.num = i; n     b.type = 1; n     events.push_back(b); n   } n   sort(events.begin(), events.end(), comp); n   queue<int> pinned; n   vector<int> ans; n   for (auto it : events) { n     if (it.type) { n       if (nailed[it.num] == 0) { n         while (!pinned.empty()) { n           int ind = pinned.front(); n           nailed[ind] = 1; n           pinned.pop(); n         } n         nailed[it.num] = 1; n         ans.push_back(it.pos); n       } n     } else { n       pinned.push(it.num); n     } n   } n   cout << (int)(ans.size()) <<   n ; n   if ((int)(ans.size()) > 0) { n     for (auto it : ans) cout << it <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5000 + 5; n int n, k, v; n int a[maxn]; n bool f[maxn][maxn]; n pair<int, int> fr[maxn][maxn]; n bool u[maxn][maxn]; n bool vis[maxn]; n struct ex { n   int cnt, x, y; n }; n vector<ex> ans; n vector<int> vec; n int read() { n   int x; n   scanf( %d , &x); n   return x; n } n int main() { n   int i, j; n   int x, y; n   n = read(); n   k = read(); n   v = read(); n   f[0][0] = true; n   for (i = 1; i <= n; i++) { n     a[i] = read(); n     for (j = 0; j < k; j++) { n       f[i][j] = f[i - 1][j]; n       fr[i][j] = make_pair(i - 1, j); n       u[i][j] = false; n     } n     for (j = 0; j < k; j++) { n       if (f[i - 1][j]) { n         if (!f[i][(j + a[i]) % k]) { n           f[i][(j + a[i]) % k] = true; n           fr[i][(j + a[i]) % k] = make_pair(i - 1, j); n           u[i][(j + a[i]) % k] = true; n         } n       } n     } n   } n   if (!f[n][v % k]) { n     printf( NO n ); n     return 0; n   } n   pair<int, int> tmp = make_pair(n, v % k); n   while (tmp.first) { n     if (u[tmp.first][tmp.second]) { n       vec.push_back(tmp.first); n       vis[tmp.first] = true; n     } n     tmp = fr[tmp.first][tmp.second]; n   } n   for (i = 1; i < vec.size(); i++) { n     x = vec[i]; n     ans.push_back((ex){a[x] / k + 1, x, vec[0]}); n     a[vec[0]] += a[x]; n     a[x] = 0; n   } n   if (v % k) { n     x = vec[0]; n     y = 1; n     if (x == 1) { n       y = 2; n     } n   } else { n     x = 1; n     y = 2; n     ans.push_back((ex){a[x] / k + 1, x, y}); n     a[y] += a[x]; n     a[x] = 0; n     vis[x] = true; n   } n   for (i = 1; i <= n; i++) { n     if (!vis[i]) { n       y = i; n       break; n     } n   } n   for (i = y + 1; i <= n; i++) { n     if (!vis[i]) { n       ans.push_back((ex){a[i] / k + 1, i, y}); n       a[y] += a[i]; n       a[i] = 0; n     } n   } n   if (a[x] >= v) { n     ans.push_back((ex){(a[x] - v) / k, x, y}); n   } else { n     if (a[x] + a[y] / k * k < v) { n       printf( NO n ); n       return 0; n     } else { n       ans.push_back((ex){(v - a[x]) / k, y, x}); n     } n   } n   printf( YES n ); n   for (ex t : ans) { n     if (t.cnt >= 1) printf( %d %d %d n , t.cnt, t.x, t.y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buffer[10]; n bool query(int x, int y) { n   cout << x <<     << y << endl; n   cout.flush(); n   cin >> buffer; n   return (buffer[0] ==  w ); n } n const int Y = 100; n bool get(int x) { return query(x, Y); } n void answer(int l, int r) { n   cout << l <<     << (Y - 1) <<    ; n   cout << r <<     << (Y + 1) <<   n ; n } n int main() { n   int n; n   cin >> n; n   const bool init = get(0); n   int l = 0, r = 1000 * 1000 * 1000; n   for (int i = 1; i < n; i++) { n     int m = (r - l) / 2 + l; n     if (get(m) == init) { n       l = m; n     } else { n       r = m; n     } n   } n   answer(l, r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n int T, n, m, ans; n char s[N], p[N]; n int ne[N], len[N]; n int main() { n   scanf( %s , s + 1); n   m = strlen(s + 1); n   cin >> T; n   while (T--) { n     scanf( %s , p + 1); n     n = strlen(p + 1); n     if (n == 1) continue; n     for (int i = 2, j = 0; i <= n; i++) { n       while (j && p[i] != p[j + 1]) j = ne[j]; n       if (p[i] == p[j + 1]) j++; n       ne[i] = j; n     } n     memset(len, 0, sizeof len); n     for (int i = 1, j = 0; i <= m; i++) { n       while (j && s[i] != p[j + 1]) j = ne[j]; n       if (s[i] == p[j + 1]) j++; n       len[i] = max(len[i - 1], j); n       if (j == n) j = ne[j]; n     } n     memset(ne, 0, sizeof ne); n     for (int i = 2, j = 0; i <= n; i++) { n       while (j && p[n - i + 1] != p[n - j]) j = ne[j]; n       if (p[n - i + 1] == p[n - j]) j++; n       ne[i] = j; n     } n     bool flag = false; n     for (int i = 1, j = 0; i <= m; i++) { n       while (j && s[m - i + 1] != p[n - j]) j = ne[j]; n       if (s[m - i + 1] == p[n - j]) j++; n       if (j && len[m - i] && (j + len[m - i] >= n)) { n         flag = true; n         break; n       } n       if (j == n) j = ne[j]; n     } n     if (flag) ans++; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int min_dist[3005][3005]; n vector<int> furthest_out[3005]; n vector<pair<int, int> > X; n vector<pair<int, int> > furthest_in[3005]; n vector<int> E[3005]; n int n; n void bfs(int source) { n   for (int j = 1; j <= n; j++) min_dist[source][j] = 1 << 30; n   min_dist[source][source] = 0; n   queue<int> Q; n   Q.push(source); n   while (!Q.empty()) { n     int v = Q.front(); n     Q.pop(); n     int d = min_dist[source][v]; n     for (int i = 0; i < E[v].size(); i++) { n       int to = E[v][i]; n       if (min_dist[source][to] >= (1 << 30)) { n         min_dist[source][to] = d + 1; n         Q.push(to); n       } n     } n   } n   X.clear(); n   for (int i = 1; i <= n; i++) { n     if (i == source) continue; n     if (min_dist[source][i] >= (1 << 30)) continue; n     X.push_back(make_pair(min_dist[source][i], i)); n     furthest_in[i].push_back(make_pair(min_dist[source][i], source)); n   } n   sort(X.begin(), X.end()); n   reverse(X.begin(), X.end()); n   for (int i = 0; i < X.size() && i < 5; i++) { n     furthest_out[source].push_back(X[i].second); n   } n } n long long v[222222]; n int main() { n   ios::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n   int m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     E[u].push_back(v); n   } n   for (int i = 1; i <= n; i++) bfs(i); n   for (int i = 1; i <= n; i++) { n     sort(furthest_in[i].begin(), furthest_in[i].end()); n     reverse(furthest_in[i].begin(), furthest_in[i].end()); n   } n   long long ans = 0; n   int x = -1, y = -1, z = -1, dd = -1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i == j) continue; n       if (min_dist[i][j] == (1 << 30)) { n         continue; n       } n       for (int k = 0; k < furthest_in[i].size() && k < 6; k++) { n         int a = furthest_in[i][k].second; n         if (i == a || j == a) continue; n         for (int p = 0; p < furthest_out[j].size() && p < 6; p++) { n           int b = furthest_out[j][p]; n           if (a == b) continue; n           if (i == b || j == b) continue; n           long long cur = min_dist[a][i] + min_dist[i][j] + min_dist[j][b]; n           if (cur > ans) { n             ans = cur; n             x = i; n             y = j; n             z = a; n             dd = b; n           } n         } n       } n     } n   } n   cout << z <<     << x <<     << y <<     << dd << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace myrand { n mt19937 mt(chrono::system_clock::now().time_since_epoch() / n            chrono::microseconds(1)); n long long Int(long long l, long long r) { n   return uniform_int_distribution<long long>(l, r)(mt); n } n }  // namespace myrand n using namespace myrand; n auto ss = chrono::system_clock::now(); n double remain_time() { n   auto en = chrono::system_clock::now(); n   return (chrono::duration_cast<chrono::nanoseconds>(en - ss).count() * 1e-9); n } n long long cnt; n long long dp[3001][3001]; n const long long mod = 998244353; n void solve(string s, string t) { n   int n = s.size(); n   int m = t.size(); n   for (int i = 0; i <= n; i++) dp[i][i] = 1; n   for (int len = 1; len <= n; len++) n     for (int i = 0; i + len <= n; i++) { n       int j = i + len; n       if (i >= m || s[len - 1] == t[i]) dp[i][j] += dp[i + 1][j]; n       if (j > m || s[len - 1] == t[j - 1]) dp[i][j] += dp[i][j - 1]; n       dp[i][j] %= mod; n     } n   for (int j = m; j <= n; j++) cnt = (cnt + dp[0][j]) % mod; n   cout << cnt; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s, t; n   cin >> s; n   cin >> t; n   solve(s, t); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k[110], v[110][110], t[110][110], res, s, i, j; n int ktra(long long &s1, long long &s2, long long f1, long long f2, int &p) { n   int res = ((s1 - s2) * (f1 - f2) < 0) || ((s1 == s2) && (p * (f1 - f2) < 0)); n   if (f1 > f2) p = 1; n   if (f1 < f2) p = -1; n   s1 = f1; n   s2 = f2; n   return res; n } n int tinh(int i, int j) { n   long long s1 = 0, s2 = 0; n   int i1 = 0, i2 = 0, t1 = t[i][0], t2 = t[j][0], d = 0, tt, p = 0; n   while (s1 < s && s2 < s) { n     tt = min(t1, t2); n     d += ktra(s1, s2, s1 + tt * v[i][i1], s2 + tt * v[j][i2], p); n     t1 -= tt; n     t2 -= tt; n     if (t1 == 0 && i1 < k[i] - 1) t1 = t[i][++i1]; n     if (t2 == 0 && i2 < k[j] - 1) t2 = t[j][++i2]; n   } n   return d; n } n int main() { n   cin >> n >> s; n   for (i = 0; i < n; i++) { n     cin >> k[i]; n     for (j = 0; j < k[i]; j++) cin >> v[i][j] >> t[i][j]; n   } n   res = 0; n   for (i = 0; i < n - 1; i++) n     for (j = i + 1; j < n; j++) res += tinh(i, j); n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int dp[300000]; n int main() { n   int r, g; n   cin >> r >> g; n   int h; n   int low = 0, high = 1000; n   while (low <= high) { n     int mid = (low + high) / 2; n     if (mid * (mid + 1) / 2 <= r + g) n       h = mid, low = mid + 1; n     else n       high = mid - 1; n   } n   int all = h * (h + 1) / 2; n   dp[0] = 1; n   for (int i = 1; i <= h; i++) { n     for (int j = r; j >= 0; j--) { n       dp[j + i] += dp[j]; n       dp[j + i] %= mod; n     } n   } n   int ans = 0; n   for (int i = min(all, r); i >= max(0, all - g); --i) { n     ans = (ans + dp[i]) % mod; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 50, B = 1111; n const long double inf = 5e18; n const long double eps = 1e-12; n int n, q, a[N], b[N], f[N], blo[N], sq, num, ll[N], rr[N], dfn[N], dfm[N], clk, n     idfn[N]; n vector<int> v[N]; n int read() { n   int x = 0, c, f = 1; n   while (!isdigit(c = getchar())) c ==  -  ? f = -1 : 0; n   while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); n   return x * f; n } n void dfs(int x) { n   dfn[x] = ++clk; n   idfn[clk] = x; n   for (int i = 0; i < v[x].size(); i++) dfs(v[x][i]); n   dfm[x] = clk; n } n long double k(long long y, int x) { n   return x ? 1.0 * y / x : y > 0 ? inf : -inf; n } n void cmax(long long &x, long long y) { y > x ? x = y : 0; } n bool cmp(int x, int y) { return b[idfn[x]] < b[idfn[y]]; } n struct node { n   int a[N], b[N], t[N], st[B][B], tp[B]; n   long long y[N]; n   vector<int> v[B]; n   void build(int i) { n     int *Q = st[i], &R = tp[i]; n     R = 0; n     for (int j = 0; j < v[i].size(); j++) { n       int x = v[i][j]; n       assert(!j || b[x] >= b[v[i][j - 1]]); n       while (R > 1 && k(y[Q[R]] - y[Q[R - 1]], b[Q[R]] - b[Q[R - 1]]) - n                               k(y[x] - y[Q[R]], b[x] - b[Q[R]]) < n                           eps) n         R--; n       Q[++R] = x; n     } n   } n   void init() { n     for (int i = 1; i <= num; i++) { n       for (int j = ll[i]; j <= rr[i]; j++) n         v[i].push_back(j), y[j] = 1ll * a[j] * b[j]; n       sort(v[i].begin(), v[i].end(), cmp); n       build(i); n     } n   } n   void change(int l, int r, int x) { n     for (int i = l; i <= min(r, rr[blo[l]]); i++) n       a[i] -= x, y[i] = 1ll * a[i] * b[i]; n     build(blo[l]); n     if (blo[l] != blo[r]) { n       for (int i = ll[blo[r]]; i <= r; i++) a[i] -= x, y[i] = 1ll * a[i] * b[i]; n       build(blo[r]); n     } n     for (int i = blo[l] + 1; i < blo[r]; i++) t[i] += x; n   } n   long long query(int l, int r) { n     long long ret = 0; n     for (int i = l; i <= min(r, rr[blo[l]]); i++) n       cmax(ret, 1ll * (a[i] - t[blo[l]]) * b[i]); n     if (blo[l] != blo[r]) n       for (int i = ll[blo[r]]; i <= r; i++) n         cmax(ret, 1ll * (a[i] - t[blo[r]]) * b[i]); n     for (int i = blo[l] + 1; i < blo[r]; i++) { n       int *Q = st[i], &R = tp[i]; n       while (R > 1 && n              k(y[Q[R]] - y[Q[R - 1]], b[Q[R]] - b[Q[R - 1]]) < t[i] + eps) n         R--; n       cmax(ret, 1ll * (a[Q[R]] - t[i]) * b[Q[R]]); n     } n     return ret; n   } n } F, G; n int main() { n   scanf( %d%d , &n, &q); n   sq = max((int)sqrt(n / 6), 1); n   for (int i = 2; i <= n; i++) v[f[i] = read()].push_back(i); n   dfs(1); n   for (int i = 1; i <= n; i++) a[i] = read() + a[f[i]]; n   for (int i = 1; i <= n; i++) b[i] = read() + b[f[i]]; n   for (int i = 1; i <= n; i++) blo[i] = (i - 1) / sq + 1; n   num = blo[n]; n   for (int i = 1; i <= num; i++) ll[i] = (i - 1) * sq + 1, rr[i] = i * sq; n   rr[num] = n; n   for (int i = 1; i <= n; i++) n     F.a[i] = G.a[i] = -a[idfn[i]], F.b[i] = b[idfn[i]], G.b[i] = -b[idfn[i]]; n   F.init(); n   for (int i = 1; i <= n; i++) b[i] = -b[i]; n   G.init(); n   for (int i = 1, op, x, y; i <= q; i++) { n     op = read(); n     x = read(); n     if (op == 1) n       y = read(), F.change(dfn[x], dfm[x], y), G.change(dfn[x], dfm[x], y); n     else n       cout << max(F.query(dfn[x], dfm[x]), G.query(dfn[x], dfm[x])) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, A[100]; n   cin >> n; n   int aux = 0, ans = 15; n   while (n--) { n     int t; n     cin >> t; n     if (t <= ans) n       ans = t + 15; n     else n       break; n   } n   if (ans > 90) ans = 90; n   cout << ans; n   return 0; n } n