#include <bits/stdc++.h> n #pragma GCC optimize( -O2 ) n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a << endl; n   err(++it, args...); n } n const int LIM = 1e5 + 5, MOD = 1e9 + 7; n int t, n, m, k, x, y; n int is_com[LIM]; n vector<int> pr; n void sieve() { n   for (int i = 2; i < LIM; i++) { n     if (!is_com[i]) pr.push_back(i); n     for (auto &it : pr) { n       if (it * i >= n) break; n       is_com[i * it] = 1; n       if (i % it == 0) { n         break; n       } n     } n   } n } n long long int powm(long long int x, long long int pw, long long int MOD) { n   long long int res = 1; n   while (pw) { n     if (pw & 1LL) res = ((res * x)) % MOD; n     pw >>= 1; n     x = ((x * x)) % MOD; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   sieve(); n   long long int x, y; n   cin >> x >> y; n   long long int ans = 0; n   if (y % x == 0) { n     map<int, int> fac; n     y /= x; n     long long int cp = y; n     for (auto &it : pr) { n       if (cp == 1) break; n       while (cp % it == 0) fac[it]++, cp /= it; n     } n     if (cp > 1) fac[cp]++; n     for (long long int i = 1; i < (long long int)1e5; ++i) { n       if (i * i > y) break; n       if (y % i == 0) { n         map<int, int> f; n         cp = i; n         for (auto &it : fac) { n           if (cp == 1) break; n           while (cp % it.first == 0) f[it.first]++, cp /= it.first; n         } n         int mu = 1; n         for (auto &it : f) { n           if (it.second > 1) n             mu = 0; n           else n             mu *= -1; n         } n         ans += mu * powm(2, y / i - 1, MOD); n         if (y / i != i) { n           map<int, int> f; n           cp = y / i; n           for (auto &it : fac) { n             if (cp == 1) break; n             while (cp % it.first == 0) f[it.first]++, cp /= it.first; n           } n           int mu = 1; n           for (auto &it : f) { n             if (it.second > 1) n               mu = 0; n             else n               mu *= -1; n           } n           ans += mu * powm(2, i - 1, MOD); n         } n         ans %= MOD; n       } n     } n     cout << (ans + MOD) % MOD <<   n ; n   } else n     cout << 0 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, m; n   char ch[51]; n   scanf( %s , &ch); n   n = strlen(ch); n   if (n == 1) n     printf( %c , ch[0]); n   else { n     if (n % 2 == 0) n       m = (n / 2) - 1; n     else n       m = (n / 2); n     printf( %c , ch[m]); n     int j = 1; n     for (int i = 1; i <= n / 2; i++) { n       if (j < n) printf( %c , ch[m + i]); n       j++; n       if (j < n) printf( %c , ch[m - i]); n       j++; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, m, n, a = 0, b = 0; n   cin >> n >> m; n   k = n; n   k = k / 9; n   n = n % 9; n   if (n != 0) k++; n   for (i = 0; i < k; i++) cout << 54; n   cout << endl; n   for (i = 0; i < k - 1; i++) cout << 45; n   cout << 46; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int query(int l, int r) { n   if (l < 1 || r > n) return false; n   string re; n   cout << 1 <<     << l <<     << r << endl; n   cin >> re; n   return re ==  TAK ; n } n int get(int l, int r) { n   if (l > r) return false; n   while (l < r) { n     int mid = (l + r) >> 1; n     if (query(mid, mid + 1)) n       r = mid; n     else n       l = mid + 1; n   } n   return l; n } n int main() { n   cin >> n >> k; n   int x, y; n   x = get(1, n); n   y = get(1, x - 1); n   if (!query(y, x)) y = get(x + 1, n); n   cout << 2 <<     << x <<     << y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m, tot, cnt; n long long geta(long long limit) { n   long long res = 1; n   while (res * res * res <= limit) res++; n   return res - 1; n } n void dfs(long long limit, long long num, long long vol) { n   if (limit == 0) { n     if (cnt < num) { n       cnt = num; n       tot = vol; n     } n     return; n   } n   long long a = geta(limit); n   dfs(limit - a * a * a, num + 1, vol + a * a * a); n   if (a > 1) { n     dfs(a * a * a - 1 - (a - 1) * (a - 1) * (a - 1), num + 1, n         vol + (a - 1) * (a - 1) * (a - 1)); n   } n } n int main() { n   while (scanf( %I64d , &m) != EOF) { n     cnt = 0, tot = 0; n     dfs(m, 0, 0); n     printf( %I64d %I64d n , cnt, tot); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename C> n class mcmf { n  public: n   static constexpr T eps = (T)1e-9; n   struct edge { n     int from; n     int to; n     T c; n     T f; n     C cost; n   }; n   vector<vector<int> > g; n   vector<edge> edges; n   vector<C> d; n   vector<int> q; n   vector<bool> in_queue; n   vector<int> pe; n   int n; n   int st, fin; n   T flow; n   C cost; n   mcmf(int _n, int _st, int _fin) : n(_n), st(_st), fin(_fin) { n     assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin); n     g.resize(n); n     d.resize(n); n     in_queue.resize(n); n     pe.resize(n); n     flow = 0; n     cost = 0; n   } n   void clear_flow() { n     for (const edge &e : edges) { n       e.f = 0; n     } n     flow = 0; n   } n   void add(int from, int to, T forward_cap, T backward_cap, C cost) { n     assert(0 <= from && from < n && 0 <= to && to < n); n     g[from].push_back((int)edges.size()); n     edges.push_back({from, to, forward_cap, 0, cost}); n     g[to].push_back((int)edges.size()); n     edges.push_back({to, from, backward_cap, 0, -cost}); n   } n   bool expath() { n     fill(d.begin(), d.end(), numeric_limits<C>::max()); n     q.clear(); n     q.push_back(st); n     d[st] = 0; n     in_queue[st] = true; n     int beg = 0; n     bool found = false; n     while (beg < (int)q.size()) { n       int i = q[beg++]; n       if (i == fin) { n         found = true; n       } n       in_queue[i] = false; n       for (int id : g[i]) { n         const edge &e = edges[id]; n         if (e.c - e.f > eps && d[i] + e.cost < d[e.to]) { n           d[e.to] = d[i] + e.cost; n           pe[e.to] = id; n           if (!in_queue[e.to]) { n             q.push_back(e.to); n             in_queue[e.to] = true; n           } n         } n       } n     } n     if (d[fin] >= 0) found = 0; n     if (found) { n       T push = numeric_limits<T>::max(); n       int v = fin; n       while (v != st) { n         const edge &e = edges[pe[v]]; n         push = min(push, e.c - e.f); n         v = e.from; n       } n       v = fin; n       while (v != st) { n         edge &e = edges[pe[v]]; n         e.f += push; n         edge &back = edges[pe[v] ^ 1]; n         back.f -= push; n         v = e.from; n       } n       flow += push; n       cost += push * d[fin]; n     } n     return found; n   } n   pair<T, C> max_flow_min_cost() { n     while (expath()) { n     } n     return make_pair(flow, cost); n   } n }; n const int MG1 = 1e5; n int n1, n2, m, r, b; n string s1, s2; n int eu[200], ev[200], er[200]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n1 >> n2 >> m >> r >> b >> s1 >> s2; n   mcmf<int, int> a(n1 + n2 + 2, n1 + n2, n1 + n2 + 1); n   memset(er, -1, sizeof(er)); n   for (int i = 0, j = 0; i < m; ++i) { n     cin >> eu[i] >> ev[i], --eu[i], --ev[i]; n     if (s1[eu[i]] ==  U  && s2[ev[i]] ==  U ) continue; n     if (s1[eu[i]] ==  U  && s2[ev[i]] ==  R ) { n       a.add(n1 + n2, n1 + ev[i], 1, 0, r); n       er[i] = j++; n       continue; n     } n     if (s1[eu[i]] ==  U  && s2[ev[i]] ==  B ) { n       a.add(n1 + ev[i], n1 + n2 + 1, 1, 0, b); n       er[i] = j++; n       continue; n     } n     if (s1[eu[i]] ==  R  && s2[ev[i]] ==  U ) { n       a.add(eu[i], n1 + n2 + 1, 1, 0, r); n       er[i] = j++; n       continue; n     } n     if (s1[eu[i]] ==  B  && s2[ev[i]] ==  U ) { n       a.add(n1 + n2, eu[i], 1, 0, b); n       er[i] = j++; n       continue; n     } n     a.add(eu[i], n1 + ev[i], 1, 0, r); n     a.add(n1 + ev[i], eu[i], 1, 0, b); n     er[i] = j; n     j += 2; n   } n   int tmg = 0; n   for (int i = 0; i < n1; ++i) { n     if (s1[i] ==  R ) { n       a.add(n1 + n2, i, 1, 0, -MG1); n       a.add(n1 + n2, i, 200, 0, 0); n       tmg -= MG1; n     } else if (s1[i] ==  B ) { n       a.add(i, n1 + n2 + 1, 1, 0, -MG1); n       a.add(i, n1 + n2 + 1, 200, 0, 0); n       tmg -= MG1; n     } n   } n   for (int i = 0; i < n2; ++i) { n     if (s2[i] ==  R ) { n       a.add(n1 + i, n1 + n2 + 1, 1, 0, -MG1); n       a.add(n1 + i, n1 + n2 + 1, 200, 0, 0); n       tmg -= MG1; n     } else if (s2[i] ==  B ) { n       a.add(n1 + n2, n1 + i, 1, 0, -MG1); n       a.add(n1 + n2, n1 + i, 200, 0, 0); n       tmg -= MG1; n     } n   } n   pair<int, int> p = a.max_flow_min_cost(); n   int cost = p.second - tmg; n   if (cost >= MG1) { n     cout << -1; n     return 0; n   } n   cout << cost <<   n ; n   for (int i = 0; i < m; ++i) { n     if (s1[eu[i]] ==  U  && s2[ev[i]] ==  U ) { n       cout <<  U ; n       continue; n     } n     if (s1[eu[i]] ==  U  && s2[ev[i]] ==  R ) { n       if (a.edges[2 * er[i]].f) n         cout <<  R ; n       else n         cout <<  U ; n       continue; n     } n     if (s1[eu[i]] ==  U  && s2[ev[i]] ==  B ) { n       if (a.edges[2 * er[i]].f) n         cout <<  B ; n       else n         cout <<  U ; n       continue; n     } n     if (s1[eu[i]] ==  R  && s2[ev[i]] ==  U ) { n       if (a.edges[2 * er[i]].f) n         cout <<  R ; n       else n         cout <<  U ; n       continue; n     } n     if (s1[eu[i]] ==  B  && s2[ev[i]] ==  U ) { n       if (a.edges[2 * er[i]].f) n         cout <<  B ; n       else n         cout <<  U ; n       continue; n     } n     if (a.edges[2 * er[i]].f) n       cout <<  R ; n     else if (a.edges[2 * (er[i] + 1)].f) n       cout <<  B ; n     else n       cout <<  U ; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2,unroll-loops ) n using namespace std; n const int inf = 1000000010; n const long long INF = 10000000000000010LL; n const int mod = 1000000007; n const int MAXN = 300010, LOG = 20; n int n, m, k, u, v, x, y, t, a, b, ans; n int par[MAXN], h[MAXN], leaf[MAXN]; n vector<int> G[MAXN]; n void dfs(int node) { n   h[node] = h[par[node]] + 1; n   leaf[node] = 1; n   for (int v : G[node]) n     if (!h[v]) { n       par[v] = node; n       dfs(v); n       leaf[node] = 0; n     } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> k; n   while (m--) { n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   dfs(1); n   for (int v = 1; v <= n; v++) n     if (h[v] * k >= n) { n       cout <<  PATH   << h[v] <<   n ; n       while (v) { n         cout << v <<    ; n         v = par[v]; n       } n       return 0; n     } n   cout <<  CYCLES n ; n   for (int v = 2; v <= n && k; v++) n     if (leaf[v]) { n       k--; n       int done = 0, x = 0, y = 0; n       for (int u : G[v]) n         if (u != par[v]) { n           if ((h[v] - h[u] + 1) % 3) { n             cout << h[v] - h[u] + 1 <<   n ; n             x = v; n             while (1) { n               cout << x <<    ; n               if (x == u) break; n               x = par[x]; n             } n             cout <<   n ; n             done = 1; n             break; n           } n           if (x) n             y = u; n           else n             x = u; n         } n       if (done) continue; n       assert(x && y); n       cerr <<  {  n            <<  x  n            <<  ,   n            <<  y  n            <<  } = {  << (x) <<  ,   << (y) <<  }  << endl; n       if (h[x] < h[y]) swap(x, y); n       cout << h[x] - h[y] + 2 <<   n ; n       while (1) { n         cout << x <<    ; n         if (x == y) break; n         x = par[x]; n       } n       cout << v <<   n ; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 1 << 30; n int ds[500500], par[500500], parEdge[500500], depth[500500], anc[500500], n     ans[500500]; n vector<pair<int, int>> a[500500]; n int get(int ds[], int x) { return x == ds[x] ? x : ds[x] = get(ds, ds[x]); } n void dfs(int x) { n   for (auto [y, id] : a[x]) n     if (y != par[x]) { n       par[y] = x; n       parEdge[y] = id; n       depth[y] = depth[x] + 1; n       dfs(y); n     } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, k, m; n   cin >> n >> k >> m; n   for (int i = 1; i <= n; i++) ds[i] = i; n   for (int i = 0; i < k; i++) { n     int x, y; n     cin >> x >> y; n     a[x].push_back({y, i}); n     a[y].push_back({x, i}); n     ds[get(ds, x)] = get(ds, y); n     ans[i] = oo; n   } n   vector<tuple<int, int, int>> unusedEdges; n   for (int i = 0; i < m; i++) { n     int x, y, z; n     cin >> x >> y >> z; n     int dx = get(ds, x), dy = get(ds, y); n     if (dx == dy) n       unusedEdges.push_back({x, y, z}); n     else { n       ds[dx] = dy; n       a[x].push_back({y, -1}); n       a[y].push_back({x, -1}); n     } n   } n   dfs(1); n   for (int i = 1; i <= n; i++) anc[i] = i; n   for (auto [x, y, z] : unusedEdges) n     while (1) { n       x = get(anc, x); n       y = get(anc, y); n       if (x == y) break; n       int dx = depth[x], dy = depth[y]; n       if (dx >= dy) { n         if (parEdge[x] >= 0 && ans[parEdge[x]] == oo) ans[parEdge[x]] = z; n         x = anc[x] = par[x]; n       } n       if (dy >= dx) { n         if (parEdge[y] >= 0 && ans[parEdge[y]] == oo) ans[parEdge[y]] = z; n         y = anc[y] = par[y]; n       } n     } n   long long sum = 0; n   for (int i = 0; i < k; i++) n     if (ans[i] < oo) n       sum += ans[i]; n     else { n       cout << -1 << endl; n       return 0; n     } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 112345; n vector<int> v[N]; n int read() { n   int x; n   scanf( %d , &x); n   return x; n } n int cnt[N]; n bool used[N]; n bool t[N]; n bool never[N]; n int main() { n   int n, m, i, j, x, y; n   n = read(); n   for (i = 2; i <= n; i++) { n     x = read(); n     y = read(); n     v[x].push_back(y); n     cnt[x]++; n     cnt[y]++; n     v[y].push_back(x); n   } n   queue<int> q; n   for (int i = 1; i <= n; i++) { n     if (cnt[i] == 1) { n       q.push(i); n       used[i] = 1; n     } n   } n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (int i = 0; i < v[x].size(); i++) { n       int to = v[x][i]; n       if (!used[to]) { n         if (cnt[to] <= 2 && !t[x] && !never[to]) { n           used[to] = 1; n           q.push(to); n         } else if (cnt[to] == 3 && !t[x] && !never[to]) { n           t[to] = 1; n         } else { n           never[to] = 1; n         } n         cnt[to]--; n       } n     } n   } n   for (i = 1; i <= n; i++) { n     if (cnt[i] >= 3) { n       puts( no ); n       return 0; n     } n   } n   puts( yes ); n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, co; n   int a[100019]; n   cin >> n >> co; n   int count = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     count += a[i] / 10; n     a[i] %= 10; n   } n   sort(a, a + n); n   reverse(a, a + n); n   for (int i = 0; i < n; i++) { n     if (co >= 10 - a[i]) { n       count++; n       co -= (10 - a[i]); n     } n   } n   cout << min(10 * n, count + co / 10) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n const double pi = acos(-1); n void print() { cout <<   n ; } n template <typename T, typename... Params> n void print(const T& var1, const Params&... var2) { n   cout << var1 <<    ; n   print(var2...); n } n template <typename T> n void pr(const T& v) { n   for (auto c : v) cout << c <<    ; n   cout <<   n ; n } n long long int power(long long int a, long long int b, long long int p) { n   if (b == 0) return 1; n   long long int c = power(a, b / 2, p); n   if (b % 2 == 0) n     return (c * c) % p; n   else n     return (((c * c) % p) * a) % p; n } n long long int invmod(long long int n, long long int p) { n   return power(n, p - 2, p); n } n bool isPrime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n const int maxN = 100001; n int tree[4 * maxN][2]; n int A[100000], n; n void build(int node, int start, int end) { n   if (start == end) n     tree[node][0] = A[start], tree[node][1] = start; n   else { n     int mid = (start + end) / 2; n     build(2 * node, start, mid); n     build(2 * node + 1, mid + 1, end); n     tree[node][0] = min(tree[2 * node][0], tree[2 * node + 1][0]); n     if (tree[2 * node][0] < tree[2 * node + 1][0]) n       tree[node][1] = tree[2 * node][1]; n     else n       tree[node][1] = tree[2 * node + 1][1]; n   } n } n pair<int, int> query(int node, int start, int end, int l, int r) { n   if (r < start or end < l) { n     return {1e9, 1e9}; n   } n   if (l <= start and end <= r) { n     return make_pair(tree[node][0], tree[node][1]); n   } n   int mid = (start + end) / 2; n   pair<int, int> p1 = query(2 * node, start, mid, l, r); n   pair<int, int> p2 = query(2 * node + 1, mid + 1, end, l, r); n   if (p1.first < p2.first) n     return p1; n   else n     return p2; n } n vector<pair<int, int> > v; n int count(int l, int r, int val) { n   if (l > r) return 0; n   pair<int, int> q = query(1, 0, n - 1, l, r); n   int mini = q.first; n   int idx = q.second; n   mini -= val; n   for (long long int i = 0; i < mini; i++) v.push_back({l + 1, r + 1}); n   return (mini + count(l, idx - 1, val + mini) + count(idx + 1, r, val + mini)); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (long long int i = 0; i < n; i++) cin >> A[i]; n   build(1, 0, n - 1); n   print(count(0, n - 1, 0)); n   for (long long int i = 0; i < ((long long int)(v).size()); i++) n     print(v[i].first, v[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n; n double a, d; n double p[maxn], t[maxn], v[maxn], s[maxn]; n int main() { n   scanf( %d %lf %lf , &n, &a, &d); n   for (int i = 0; i < n; i++) n     scanf( %lf%lf , &t[i], &v[i]), p[i] = t[i] + v[i] / a; n   s[0] = t[0] + v[0] / a + (d - 0.5 * a * v[0] / a * v[0] / a) / v[0]; n   if (0.5 * a * v[0] / a * v[0] / a > d) n     s[0] = min(s[0], t[0] + sqrt((d * 2) / a)); n   for (int i = 1; i < n; i++) { n     s[i] = t[i] + v[i] / a + (d - 0.5 * a * v[i] / a * v[i] / a) / v[i]; n     if (0.5 * a * v[i] / a * v[i] / a > d) n       s[i] = min(s[i], t[i] + sqrt((d * 2) / a)); n     s[i] = max(s[i], s[i - 1]); n   } n   for (int i = 0; i < n; i++) printf( %.6f n , s[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n const long long inf = 9e18; n struct NODE { n   long long v, id; n   bool operator<(const NODE& other) const { n     return v > other.v || (v == other.v && id > other.id); n   } n } node[N]; n long long a[N], b[N]; n long long n; n long long f(long long x, long long y) { return x - 3LL * y * y + 3LL * y - 1; } n long long find(long long v, long long x) { n   long long l, r, mid; n   l = 0; n   r = x + 1; n   while (r - l > 1) { n     mid = (l + r) >> 1; n     if (f(x, mid) >= v) n       l = mid; n     else n       r = mid; n   } n   return l; n } n long long solve(long long x) { n   long long tot = 0, i; n   for (i = 1; i <= n; i++) { n     tot += (b[i] = find(x, a[i])); n   } n   return tot; n } n int main() { n   long long k, i, cnt = 0; n   long long l = inf, r = -inf, mid, tot; n   cin >> n >> k; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     l = min(l, f(a[i], a[i])); n     r = max(r, f(a[i], 1)); n   } n   while (r - l > 1) { n     mid = (l + r) >> 1; n     if (solve(mid) <= k) n       r = mid; n     else n       l = mid; n   } n   tot = solve(r); n   for (i = 1; i <= n; i++) n     if (b[i] < a[i]) node[++cnt].v = f(a[i], b[i] + 1), node[cnt].id = i; n   sort(node + 1, node + cnt + 1); n   for (i = 1; i <= cnt; i++) { n     if (tot == k) break; n     b[node[i].id]++; n     tot++; n   } n   for (i = 1; i <= n; i++) cout << b[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10 + 1e5; n const int MOD = 1e9 + 7; n int n, m; n int a[MAXN], c[MAXN]; n void Inout() { n   freopen( n        ABC  n        .inp , n        r , stdin); n   freopen( n        ABC  n        .out , n        w , stdout); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   long long ans = 0; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     c[i] = max(c[i - 1], a[i] + 1); n   } n   for (int i = n - 1; i; --i) c[i] = max(c[i], c[i + 1] - 1); n   for (int i = 1; i <= n; ++i) { n     ans += c[i] - a[i] - 1; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const long long mod = 1e9 + 7; n const long long N = 2e5 + 10; n inline long long add(long long x, long long y) { n   x += y; n   if (x >= mod) x -= mod; n   return x; n } n inline long long mul(long long x, long long y) { n   x = (1LL * x * y) % mod; n   return x; n } n long long first[N]; n long long lvl[N]; n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n, k; n   cin >> n >> k; n   long long maxv = 0; n   vector<long long> v(n); n   for (long long i = 0; i <= n - 1; ++i) { n     cin >> v[i]; n     first[v[i]]++; n     maxv = max(maxv, v[i]); n   } n   long long ans = INF; n   for (long long i = 0; i <= maxv; ++i) { n     queue<long long> q; n     q.push(i); n     lvl[i] = 0; n     long long val = 0; n     long long cc = 0; n     while (!q.empty()) { n       long long x = q.front(); n       q.pop(); n       if (cc + first[x] > k) { n         val += (k - cc) * lvl[x]; n         cc = k; n         break; n       } else { n         cc += first[x]; n         val += first[x] * lvl[x]; n         if (i == 0) { n         } n       } n       if (cc >= k) break; n       if (2 * x <= 2e5 and x > 0) { n         q.push(2 * x); n         lvl[2 * x] = 1 + lvl[x]; n       } n       if (2 * x + 1 <= 2e5) { n         q.push(2 * x + 1); n         lvl[2 * x + 1] = 1 + lvl[x]; n       } n     } n     if (cc < k) val = INF; n     ans = min(ans, val); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[1000000]; n map<char, int> M; n int main() { n   for (int i = 0; i <= 63; i++) n     for (int j = 0; j <= 63; j++) A[i & j]++; n   for (int i = 0; i <= 9; i++) M[i +  0 ] = i; n   for (int i = 0; i < 26; i++) M[i +  A ] = i + 10; n   for (int i = 0; i < 26; i++) M[i +  a ] = i + 36; n   M[ _ ] = 63, M[ - ] = 62; n   string s; n   cin >> s; n   long long ans = 1; n   long long mod = 1e9 + 7; n   for (int i = 0; i < s.size(); i++) ans = ans * A[M[s[i]]] % mod; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 1000 + 10; n int n, maxLevel; n vector<int> edge[maxn]; n vector<int> gu; n int dis[maxn]; n vector<int> level[maxn]; n int fa[maxn]; n bool used[maxn]; n void print(int a[], int n, int st = 0) { n   for (int i = 0; i < n; i++) { n     if (i != 0) printf(   ); n     printf( %d , a[i + st]); n   } n   printf(  n ); n } n void init() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) edge[i].clear(); n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     edge[x].push_back(y); n     edge[y].push_back(x); n   } n } n void guess(vector<int> a, int &u, int &value) { n   printf( ? %d , int(a.size())); n   for (int i = 0; i < a.size(); i++) printf(  %d , a[i]); n   printf(  n ); n   fflush(stdout); n   scanf( %d%d , &u, &value); n } n void answer(int u1, int u2) { n   char s[20]; n   printf( ! %d %d n , u1, u2); n   fflush(stdout); n   scanf( %s , s); n } n void dfs(int u) { n   for (int i = 0; i < edge[u].size(); i++) { n     int v = edge[u][i]; n     if (dis[v] == -1) { n       dis[v] = dis[u] + 1; n       fa[v] = u; n       maxLevel = max(maxLevel, dis[v]); n       level[dis[v]].push_back(v); n       dfs(v); n     } n   } n } n void doit() { n   int r, len, k1, k2; n   gu.clear(); n   for (int i = 1; i <= n; i++) gu.push_back(i); n   guess(gu, r, len); n   for (int i = 0; i <= n; i++) level[i].clear(); n   for (int i = 0; i <= n; i++) dis[i] = -1; n   dis[r] = 0; n   level[0].push_back(r); n   maxLevel = 0; n   dfs(r); n   int left = (len + 1) / 2, right = min(len, maxLevel), mid, ans, u, d; n   while (left <= right) { n     mid = (left + right) >> 1; n     guess(level[mid], u, d); n     if (d <= len) { n       ans = mid; n       k1 = u; n       left = mid + 1; n     } else { n       right = mid - 1; n     } n   } n   if (ans == len) { n     answer(r, k1); n     return; n   } n   u = k1; n   for (int i = 1; i <= n; i++) used[i] = false; n   while (u != r) { n     used[u] = true; n     u = fa[u]; n   } n   gu.clear(); n   for (int i = 0; i < level[len - ans].size(); i++) { n     if (!used[level[len - ans][i]]) { n       gu.push_back(level[len - ans][i]); n     } n   } n   guess(gu, k2, d); n   answer(k1, k2); n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     init(); n     doit(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, ans, n, a[3001]; n   while (cin >> n) { n     for (i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a, a + n); n     if (a[0] > 1) n       ans = 1; n     else { n       for (i = 1; i < n; i++) { n         if (a[i] - a[i - 1] > 1) { n           ans = a[i - 1] + 1; n           break; n         } n       } n     } n     if (ans <= 0) ans = a[n - 1] + 1; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct event { n   long long x, type; n   event() {} n   event(long long _x, long long _type) { n     x = _x; n     type = _type; n   } n }; n string a, b; n long long n; n long double ans = 0; n vector<long long> v[500]; n vector<event> d[500]; n bool operator<(const event& a, const event& b) { n   return a.x < b.x || (a.x == b.x && a.type < b.type); n } n int main() { n   cin >> n; n   cin >> a >> b; n   for (long long i = 0; i < n; i++) { n     v[a[i]].push_back(i); n     d[a[i]].push_back(event(i, 0)); n     d[b[i]].push_back(event(i, 1)); n   } n   long long all = 0; n   for (long long i = 1; i <= n; i++) { n     all += i * i; n   } n   for (long long i = 0; i < 500; i++) { n     sort(d[i].begin(), d[i].end()); n     long long x = 0, y = 0; n     for (long long j = 0; j < d[i].size(); j++) { n       event q = d[i][j]; n       y += (n - q.x) * (1 - q.type); n     } n     for (long long j = 0; j < d[i].size(); j++) { n       event q = d[i][j]; n       if (!q.type) { n         y -= n - q.x; n         x += q.x + 1; n       } else { n         ans += (long double)((q.x + 1) * y) / (long double)all; n         ans += (long double)((n - q.x) * x) / (long double)all; n       } n     } n   } n   cout.precision(18); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:300000000 ) n const long double eps = 1e-20; n const long double pi = acos(-1.0); n const long long inf = 1000 * 1000 * 1000 * 1000 * 1000 * 1000; n const long long base = 1000 * 1000 * 1000 + 7; n using namespace std; n int n, m, z, a[111111], x, y; n bool fl; n set<int> g[111111]; n int main() { n   ios_base ::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < (m); i++) { n     cin >> x >> y; n     x; n     y; n     g[x].insert(y); n     g[y].insert(x); n   } n   for (int i = 0; i < (n); i++) a[i] = i + 1; n   if (n < 9) { n     do { n       z = 0; n       fl = true; n       for (int i = 0; i < (n); i++) { n         if (z == m) break; n         if (g[a[i]].find(a[(i + 1) % n]) != g[a[i]].end()) { n           fl = false; n           break; n         } n         if (!fl) break; n         z++; n       } n       if (fl && z == m) { n         z = 0; n         for (int i = 0; i < (n); i++) { n           if (z == m) return 0; n           cout << a[i] <<     << a[(i + 1) % n] << endl; n           z++; n         } n         return 0; n       } n     } while (next_permutation(a, a + n)); n     cout <<  -1 ; n     return 0; n   } n   for (int test = 0; test < (666); test++) { n     random_shuffle(a, a + n); n     z = 0; n     fl = true; n     for (int i = 0; i < (n); i++) { n       if (z == m) break; n       if (g[a[i]].find(a[(i + 1) % n]) != g[a[i]].end()) { n         fl = false; n         break; n       } n       if (!fl) break; n       z++; n     } n     if (fl && z == m) { n       z = 0; n       for (int i = 0; i < (n); i++) { n         if (z == m) return 0; n         cout << a[i] <<     << a[(i + 1) % n] << endl; n         z++; n       } n       return 0; n     } n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     vector<long long> nums(n); n     for (int i = 0; i < n; i++) { n       cin >> nums[i]; n     } n     bool hasAns = false; n     for (int i = 31; i >= 0; i--) { n       long long num = 1; n       num = num << i; n       bool hasRes = false; n       long long res = 0; n       int count = 0; n       for (int j = 0; j < nums.size(); j++) { n         if (nums[j] & num) { n           if (hasRes) { n             res &= nums[j]; n           } else { n             res = nums[j]; n           } n           count++; n           hasRes = true; n         } n       } n       if (count == 0 || (res % num)) { n         continue; n       } n       hasAns = true; n       cout << count << endl; n       for (int j = 0; j < nums.size(); j++) { n         if (nums[j] & num) { n           cout << nums[j] <<    ; n         } n       } n       cout << endl; n       break; n     } n     if (!hasAns) { n       cout << nums.size() << endl; n       for (int j = 0; j < nums.size(); j++) { n         cout << nums[j] <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int add = 1e9; n const int INF = 2e9; n const long long mod = 1e9 + 7; n const long long mod1 = 3e9 + 19; n const long long mod2 = 3e9 - 71; n const long long longINF = 3e18; n const long long ph = 31; n const long double pi = acos(-1); n const long double eps = 1e-8; n const int M = 1 << 18; n int n, a[105], res; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   if (!(n & 1)) { n     cout <<  No ; n     return 0; n   } n   for (int i = 0; i < n; i++) cin >> a[i]; n   if (a[0] % 2 == 0 || a[n - 1] % 2 == 0) { n     cout <<  No ; n     return 0; n   } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int tu[200], a[200]; n   int f[200]; n   int n, m, k; n   int min; n   int i, j; n   scanf( %d %d %d , &n, &m, &k); n   for (i = 0; i < m; i++) { n     scanf( %d , &f[i]); n     a[i] = 0; n   } n   for (i = 0; i < k; i++) scanf( %d , &tu[i]); n   for (i = 0; i < m; i++) n     for (j = 0; j < k; j++) n       if (tu[j] % f[i] == 0) a[i] += 1; n   min = 1000; n   for (i = 0; i < m; i++) { n     if (min > a[i]) min = a[i]; n   } n   j = 0; n   for (i = 0; i < m; i++) { n     if (a[i] == min) tu[j++] = i; n   } n   for (i = 0; i < j; i++) { n     for (k = i + 1; k < j; k++) { n       if (tu[i] > tu[k]) { n         min = tu[k]; n         tu[k] = tu[i]; n         tu[i] = min; n       } n     } n   } n   printf( %d n , j); n   for (i = 0; i < j; i++) printf( %d  , tu[i] + 1); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     string word =   ; n     for (auto x : s) { n       if (x ==  _ ) { n         word =   ; n       } else { n         word = word + x; n       } n     } n     if (word.substr(word.length() - 2) ==  po ) n       cout <<  FILIPINO n ; n     else if (word.substr(word.length() - 4) ==  desu  || n              word.substr(word.length() - 4) ==  masu ) n       cout <<  JAPANESE n ; n     else if (word.substr(word.length() - 5) ==  mnida ) n       cout <<  KOREAN n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   t = 1; n   while (t--) { n     long long int n; n     cin >> n; n     long long int x, y, i; n     long long int suma = 0, sumb = 0; n     bool found = false; n     vector<char> v; n     for (i = 0; i < n; i++) { n       cin >> x >> y; n       suma += x; n       if (abs(suma - sumb) <= 500 && !found) n         v.push_back( A ); n       else { n         suma -= x; n         sumb += y; n         if (abs(suma - sumb) <= 500 && !found) n           v.push_back( G ); n         else n           found = true; n       } n     } n     if (found) n       cout <<  -1 n ; n     else { n       for (i = 0; i < v.size(); i++) cout << v[i]; n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int MOD = 1e9 + 7; n const int MAXN = 1e6 + 3; n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long power(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = res * x; n     y = y >> 1; n     x = x * x; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     vector<long long> a(n + 1); n     set<long long> st; n     for (long long i = 1; i <= (n); ++i) { n       cin >> a[i]; n       st.insert(a[i]); n     } n     if (st.size() == 1) n       cout << n <<   n ; n     else n       cout << 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 20; n const int MOD = 1e9 + 7; n const int INF = 0x3f3f3f3f; n const long long LLINF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1.0); n const double RATE = 0.995; n const double eps = 1e-4; n int arr[MAXN]; n signed main() { n   int n; n   long long k; n   scanf( %d%lld , &n, &k); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &arr[i]); n   } n   sort(arr + 1, arr + 1 + n); n   long long ans = arr[n] - arr[1]; n   for (int i = 1; i < (n + 1) / 2; ++i) { n     long long t = n         min(1ll * (arr[n - i + 1] - arr[n - i] + arr[i + 1] - arr[i]), k / i); n     ans -= t; n     k -= i * t; n   } n   if (n % 2 == 0) { n     long long t = min(1ll * (arr[n / 2 + 1] - arr[n / 2]), k / (n / 2)); n     ans -= t; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxN = (int)1e5 + 5; n int n, ar[mxN]; n void solve() { n   ar[0] = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> ar[i]; n   int mx = 0; n   for (int i = 1; i <= n; i++) { n     mx = max(mx, ar[i]); n   } n   cout << mx; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t = 1, i = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, h[300005], tot; n map<pair<int, int>, int> c; n struct edge { n   int to, nxt, val; n } e[300005 << 1]; n void add(int x, int y, int z) { n   e[++tot].nxt = h[x]; n   h[x] = tot; n   e[tot].to = y; n   e[tot].val = z; n } n priority_queue<pair<long long, int> > q; n vector<int> a[300005]; n long long d[300005]; n int v[300005], fa[300005]; n void dij() { n   memset(d, 0x3f, sizeof(d)); n   d[1] = 0; n   q.push(make_pair(0, 1)); n   while (!q.empty()) { n     int x = q.top().second; n     q.pop(); n     v[x] = 1; n     for (int i = h[x]; i; i = e[i].nxt) n       if (d[x] + e[i].val < d[e[i].to]) { n         d[e[i].to] = d[x] + e[i].val; n         fa[e[i].to] = x; n         q.push(make_pair(-d[e[i].to], e[i].to)); n       } n     while (!q.empty() && v[q.top().second]) q.pop(); n   } n   for (int i = 2; i <= n; i++) a[fa[i]].push_back(i); n } n void dfs(int x) { n   if (k && x != 1) k--, printf( %d  , c[make_pair(fa[x], x)]); n   if (!k) return; n   for (int i = 0; i < (int)a[x].size(); i++) dfs(a[x][i]); n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   k = min(k, n - 1); n   for (int i = 1; i <= m; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     add(x, y, z); n     add(y, x, z); n     c[make_pair(x, y)] = c[make_pair(y, x)] = i; n   } n   dij(); n   printf( %d n , k); n   dfs(1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int count = 0; n   int n, d; n   cin >> n >> d; n   int arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       if (abs(arr[i] - arr[j]) <= d) count++; n     } n   } n   cout << count << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long x = 0; n bool vis[100010] = {false}; n vector<int> adj[100010]; n long long pow(long long a, long long b, long long m) { n   stack<int> k; n   int j = 128; n   int l = 1; n   int an = 1; n   while (b) { n     if (b >= j) { n       k.push(j); n       b -= j; n     } n     j /= 2; n   } n   while (!k.empty()) { n     if (k.top() == l) { n       an = (an * a) % mod; n       k.pop(); n     } n     a = (a * a) % mod; n     l *= 2; n   } n   return an; n } n long long gcd(long a, long b) { n   return b == 0 ? (a < 0 ? -a : a) : gcd(b, a % b); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   int n, m, k; n   cin >> n >> m >> k; n   int ma = 0, mi = 10000; n   for (int i = 0; i < n; ++i) { n     int t; n     cin >> t; n     if (t < mi) { n       mi = t; n     } n   } n   for (int i = 0; i < m; ++i) { n     int t; n     cin >> t; n     if (t > ma) { n       ma = t; n     } n   } n   if (ma > mi) { n     int j = k / mi; n     k -= (j)*mi; n     k += j * ma; n   } n   cout << k << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using Int = long long; n constexpr static int mod = 1e9 + 7; n constexpr static int inf = (1 << 30) - 1; n constexpr static Int infll = (1LL << 61) - 1; n int Competitive_Programming = n     (ios_base::sync_with_stdio(false), cin.tie(nullptr), n      cout << fixed << setprecision(15), 0); n #pragma GCC target( avx2 ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n template <typename A, typename B> n string to_string(pair<A, B> p); n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n string to_string(const string &s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(vector<bool> v) { n   bool first = true; n   string res =  { ; n   for (int i = 0; i < static_cast<int>(v.size()); i++) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(v[i]); n   } n   res +=  } ; n   return res; n } n template <size_t N> n string to_string(bitset<N> v) { n   string res =   ; n   for (size_t i = 0; i < N; i++) { n     res += static_cast<char>( 0  + v[i]); n   } n   return res; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ) ; n } n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n int func(string &s) { n   int ret = 0, ctr = 0, mi = inf; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  ( ) n       ctr++; n     else n       ctr--; n     mi = min(ctr, mi); n   } n   ctr = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  ( ) n       ctr++; n     else n       ctr--; n     if (ctr == mi) ret++; n   } n   return ret; n } n int main() { n   int N; n   cin >> N; n   string s; n   cin >> s; n   int op = 0, ed = 0; n   for (int i = 0; i < N; i++) { n     if (s[i] ==  ( ) n       op++; n     else n       ed++; n   } n   if (op != ed) { n     cout << 0 <<   n ; n     cout << 1 <<     << 1 <<   n ; n     return 0; n   } n   int ans = 0, l = 1, r = 1; n   for (int i = 0; i < N; i++) { n     for (int j = i + 1; j < N; j++) { n       swap(s[i], s[j]); n       int cnt = func(s); n       if (cnt > ans) { n         ans = cnt, l = i + 1, r = j + 1; n       } n       swap(s[i], s[j]); n     } n   } n   cout << ans <<   n ; n   cout << l <<     << r <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD; n inline void modulas(long long a) { MOD = a; } n inline void normal(long long &a) { n   a %= MOD; n   (a < 0) && (a += MOD); n } n inline long long modMul(long long a, long long b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   return (a * b) % MOD; n } n inline long long modAdd(long long a, long long b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   return (a + b) % MOD; n } n inline long long modSub(long long a, long long b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   a -= b; n   normal(a); n   return a; n } n inline long long modPow(long long b, long long p) { n   long long r = 1; n   while (p) { n     if (p & 1) r = modMul(r, b); n     b = modMul(b, b); n     p >>= 1; n   } n   return r; n } n inline long long modInverse(long long a) { return modPow(a, MOD - 2); } n inline long long modDiv(long long a, long long b) { n   return modMul(a, modInverse(b)); n } n vector<bool> isPrime(10000010, true); n inline void seivePrime(long long L, long long R) { n   long long lim = sqrt(R); n   for (long long i = 2; i <= lim; ++i) { n     for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i) n       isPrime[j - L] = false; n   } n   if (L == 1) isPrime[0] = false; n } n inline long long chckPrime(long long L, long long prme) { n   return isPrime[prme - L]; n } n inline long long cntPrime(long long L, long long R) { n   return count(isPrime.begin(), isPrime.begin() + R - L + 1, true); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t = 1; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int ar[n]; n     for (int i = 0; i < n; i++) cin >> ar[i]; n     int s = 0, sum = 0; n     for (int i = 0; i < n; i++) { n       if (ar[i] == 0) { n         ar[i] = 1; n         s++; n       } n       sum += ar[i]; n     } n     if (sum == 0) { n       sort(ar, ar + n); n       if (ar[n - 1] > 0) n         cout << s + 1 <<   n ; n       else if (ar[0] == -1) n         cout << s + 2 <<   n ; n       else n         cout << s + 1 <<   n ; n     } else n       cout << s <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool solve() { n   int n; n   bool ret = false; n   int m = 0; n   scanf( %d , &n); n   int a; n   scanf( %d , &a); n   while ((a & 1) == 0) a >>= 1; n   while (a % 3 == 0) a /= 3; n   m = a; n   for (int i = 1; i < n; i++) { n     int a; n     scanf( %d , &a); n     while ((a & 1) == 0) a >>= 1; n     while (a % 3 == 0) a /= 3; n     if (m != a) return false; n   } n   return true; n } n int main() { n   if (solve()) n     puts( Yes ); n   else n     puts( No ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return val < a ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n template <class T> n inline T isqrt(T k) { n   T r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n template <class T> n inline T icbrt(T k) { n   T r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; } n inline int sign(long double x, long double y) { return sign(x - y); } n int p = (int)1e9 + 7; n template <class T, class mul, class dvd> n struct FiniteField { n   T x; n   template <class G> n   T normalize(G x) { n     if (x >= 0 && x < p) return x; n     x %= p; n     if (x < 0) n       x += p; n     else if (x >= p) n       x -= p; n     return x; n   } n   FiniteField() : x(0) {} n   template <class G> n   FiniteField(const G& y) { n     x = normalize(y); n   } n   FiniteField(const FiniteField& rhs) : x(rhs.x) {} n   template <class G> n   FiniteField operator()(const G& y) { n     x = normalize(y); n     return *this; n   } n   template <class G> n   FiniteField operator=(const G& y) { n     x = normalize(y); n     return *this; n   } n   int operator==(const FiniteField& rhs) const { return x == rhs.x; } n   int operator!=(const FiniteField& rhs) const { return x != rhs.x; } n   int operator<(const FiniteField& rhs) const { return x < rhs.x; } n   FiniteField operator++(int) { n     FiniteField res = *this; n     if ((++x) >= p) x -= p; n     return res; n   } n   FiniteField operator++() { n     if ((++x) >= p) x -= p; n     return *this; n   } n   FiniteField operator--(int) { n     FiniteField res = *this; n     if ((--x) < 0) x += p; n     return res; n   } n   FiniteField operator--() { n     if ((--x) < 0) x += p; n     return *this; n   } n   template <class G> n   FiniteField operator+=(const G& y) { n     if ((x += normalize(y)) >= p) x -= p; n     return *this; n   } n   template <class G> n   FiniteField operator-=(const G& y) { n     if ((x -= normalize(y)) < 0) x += p; n     return *this; n   } n   FiniteField operator+=(const FiniteField& rhs) { n     if ((x += rhs.x) >= p) x -= p; n     return *this; n   } n   FiniteField operator-=(const FiniteField& rhs) { n     if ((x -= rhs.x) < 0) x += p; n     return *this; n   } n   FiniteField operator+(const FiniteField& rhs) const { n     FiniteField res; n     res.x = x + rhs.x; n     if (res.x >= p) res.x -= p; n     return res; n   } n   FiniteField operator-(const FiniteField& rhs) const { n     FiniteField res; n     res.x = x - rhs.x; n     if (res.x < 0) res.x += p; n     return res; n   } n   template <class G> n   FiniteField operator*=(const G& y) { n     x = mul()(x, normalize(y), p); n     return *this; n   } n   template <class G> n   FiniteField operator/=(const G& y) { n     x = dvd()(x, normalize(y), p); n     return *this; n   } n   template <class G> n   FiniteField operator*(const G& y) const { n     FiniteField res; n     res.x = mul()(x, res.normalize(y), p); n     return res; n   } n   template <class G> n   FiniteField operator/(const G& y) const { n     FiniteField res; n     res.x = dvd()(x, res.normalize(y), p); n     return res; n   } n   FiniteField operator*(const FiniteField& rhs) const { n     FiniteField res; n     res.x = mul()(x, rhs.x, p); n     return res; n   } n   FiniteField operator/(const FiniteField& rhs) const { n     FiniteField res; n     res.x = dvd()(x, rhs.x, p); n     return res; n   } n   template <class G> n   friend FiniteField operator*(const G& y, const FiniteField& rhs) { n     FiniteField res; n     res.x = res.normalize(y); n     return res * rhs; n   } n   template <class G> n   friend FiniteField operator/(const G& y, const FiniteField& rhs) { n     FiniteField res; n     res.x = res.normalize(y); n     return res / rhs; n   } n   template <class G> n   FiniteField operator^=(G k) { n     if (k == 0) { n       x = 1; n       return *this; n     } n     T t = x; n     k--; n     while (k > 0) { n       if (k & 1) x = mul()(x, t, p); n       t = mul()(t, t, p); n       k >>= 1; n     } n     return *this; n   } n   template <class G> n   FiniteField operator^(G k) const { n     if (k == 0) return 1; n     T r = x, t = x; n     k--; n     while (k > 0) { n       if (k & 1) r = mul()(r, t, p); n       t = mul()(t, t, p); n       k >>= 1; n     } n     return r; n   } n   friend istream& operator>>(istream& is, FiniteField& rhs) { n     is >> rhs.x; n     return is; n   } n   friend ostream& operator<<(ostream& os, const FiniteField& rhs) { n     os << rhs.x; n     return os; n   } n }; n template <class T> n class mul { n  public: n   T operator()(const T& x, const T& y, const T& p) { n     return (long long)x * y % p; n   } n }; n template <class T> n class dvd { n  public: n   T operator()(const T& x, const T& y, const T& p) { n     pair<T, T> r = euclid(y, p); n     return mul<T>()(x, (r.first % p + p) % p, p); n   } n  n  private: n   pair<T, T> euclid(T a, T b) { n     if (b == 0) return make_pair(1, 0); n     pair<T, T> r = euclid(b, a % b); n     return make_pair(r.second, r.first - a / b * r.second); n   } n }; n const int maxn = 100000 + 5; n int m, n; n FiniteField<int, mul<int>, dvd<int> > a[maxn]; n map<FiniteField<int, mul<int>, dvd<int> >, int> hs; n void solve() { n   cin >> m >> n; n   p = m; n   for (int i = (0); i < (n); i++) cin >> a[i]; n   if (n == 1) { n     cout << a[0] <<     << 0 <<   n ; n     return; n   } n   if (n == p) { n     cout << 0 <<     << 1 <<   n ; n     return; n   } n   FiniteField<int, mul<int>, dvd<int> > sum = 0, sqsum = 0; n   for (int i = (0); i < (n); i++) sum += a[i], sqsum += a[i] * a[i], hs[a[i]]; n   for (int i = (0); i < (n); i++) { n     FiniteField<int, mul<int>, dvd<int> > x = a[i]; n     FiniteField<int, mul<int>, dvd<int> > d = (sum / n - x) * 2 / (n - 1); n     if (d == 0) continue; n     if (sqsum != n         x * x * n + x * d * n * (n - 1) + d * d * (n - 1) * n * (2 * n - 1) / 6) n       continue; n     int ok = 1; n     for (int j = (0); j < (n); j++) { n       if (!hs.count(x + j * d)) { n         ok = 0; n         break; n       } n     } n     if (ok) { n       cout << x <<     << d <<   n ; n       return; n     } n   } n   cout << -1 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   int n, x; n   cin >> n; n   int i = 0; n   while (n--) { n     cin >> x; n     if (x > b && x < c) i++; n   } n   cout << i; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T By(T x, T y, T P) { n   T F1 = 0; n   while (y) { n     if (y & 1) { n       F1 += x; n       if (F1 < 0 || F1 >= P) F1 -= P; n     } n     x <<= 1; n     if (x < 0 || x >= P) x -= P; n     y >>= 1; n   } n   return F1; n } n template <class T> n T Mul(T x, T y, T P) { n   T F1 = 1; n   x %= P; n   while (y) { n     if (y & 1) { n       F1 = By(F1, x, P); n     } n     x = By(x, x, P); n     y >>= 1; n   } n   return F1; n } n template <class T> n T Gcd(T x, T y) { n   if (y == 0) return x; n   T z; n   while (z = x % y) { n     x = y, y = z; n   } n   return y; n } n struct EDGE { n   int T; n   EDGE *Nxt; n }; n template <class T> n void UpdataMin(T &x, T y) { n   if (y < x) { n     x = y; n   } n } n template <class T> n void UpdataMax(T &x, T y) { n   if (x < y) { n     x = y; n   } n } n int F[100001]; n int L, R, N, M, QN; n int main() { n   cin >> N >> M; n   QN = N; n   for (int i = 1; i <= (N); ++i) { n     cin >> F[i]; n   } n   sort(F + 1, F + N + 1); n   L = lower_bound(F + 1, F + N + 1, M) - F; n   R = upper_bound(F + 1, F + N + 1, M) - F - 1; n   while (L > (N + 1) / 2 || R < (N + 1) / 2) { n     ++N; n     ++R; n   } n   cout << N - QN << endl; n   cin >> N; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18, minf = 1e18 * (-1); n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int k, b; n   cin >> k >> b; n   int xyr[k][2], xyb[b][2]; n   for (long long i = 0; i < k; i++) cin >> xyr[i][0] >> xyr[i][1]; n   for (long long i = 0; i < b; i++) cin >> xyb[i][0] >> xyb[i][1]; n   if (k != b) n     cout <<  No ; n   else n     cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1 << 30; n const int N = 100100; n int n, a[N], q; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     set<int> se; n     for (int i = 1; i <= n; i++) { n       scanf( %d , a + i); n       se.insert(a[i]); n     } n     printf( %d n , (int)se.size()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2e9 + 10, MAXN = 1e5 + 10; n int seg[4][MAXN * 4]; n int n, S, l; n void update(int ind) { n   seg[1][ind] = min(seg[1][((ind)*2)], seg[1][(((ind)*2) + 1)]); n   seg[2][ind] = max(seg[2][((ind)*2)], seg[2][(((ind)*2) + 1)]); n   seg[3][ind] = min(seg[3][((ind)*2)], seg[3][(((ind)*2) + 1)]); n } n void add(int s, int e, int ind, int x, int val, int t) { n   if (s > x or e <= x) return; n   if (s + 1 == e) { n     seg[t][ind] = val; n     return; n   } n   int mid = (s + e) / 2; n   add(s, mid, ((ind)*2), x, val, t); n   add(mid, e, (((ind)*2) + 1), x, val, t); n   update(ind); n } n int fin(int s, int e, int ind, int x, int y, int t) { n   if (s >= y or e <= x) return (t == 1 or t == 3) ? inf : -inf; n   if (s >= x and e <= y) return seg[t][ind]; n   int mid = (s + e) / 2; n   if (t == 1 or t == 3) n     return min(fin(s, mid, ((ind)*2), x, y, t), n                fin(mid, e, (((ind)*2) + 1), x, y, t)); n   return max(fin(s, mid, ((ind)*2), x, y, t), n              fin(mid, e, (((ind)*2) + 1), x, y, t)); n } n void show() { n   for (int i = 0; i < n; i++) n     cerr << fin(0, n, 1, i, i + 1, 1) <<     << fin(0, n, 1, i, i + 1, 2) n          << endl; n } n int main() { n   scanf( %d%d%d , &n, &S, &l); n   fill(seg[1], seg[1] + MAXN * 4, inf); n   fill(seg[3], seg[3] + MAXN * 4, inf); n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     add(0, n, 1, i, x, 1); n     add(0, n, 1, i, x, 2); n   } n   for (int i = 0; i < n; i++) { n     int s = -1, e = i; n     while (e - s > 1) { n       int mid = (s + e) / 2; n       if (fin(0, n, 1, mid, i + 1, 2) - fin(0, n, 1, mid, i + 1, 1) <= S) n         e = mid; n       else n         s = mid; n     } n     if (e == 0 and i + 1 >= l) { n       int res = 1; n       add(0, n, 1, i, res, 3); n       if (i == n - 1) { n         printf( 1 n ); n         return 0; n       } n     } else if (i - e + 1 >= l) { n       int res = fin(0, n, 1, e - 1, i - l + 1, 3); n       res = min(res + 1, inf); n       add(0, n, 1, i, res, 3); n       if (i == n - 1) { n         if (res == inf) n           printf( -1 n ); n         else n           printf( %d n , res); n         return 0; n       } n     } n   } n   printf( -1 n ); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long int modExp(long long int base, long long int power) { n   if (power == 0) { n     return 1; n   } else { n     long long int cur = modExp(base, power / 2); n     cur = cur * cur; n     cur = cur % 1000000007; n     if (power % 2 == 1) cur = cur * base; n     cur = cur % 1000000007; n     return cur; n   } n } n void solve() { n   long long int n, k, l, r, sall, sk; n   cin >> n >> k >> l >> r >> sall >> sk; n   vector<long long int> ans; n   long long int temp = sk / k; n   long long int num = sk - temp * k; n   for (long long int i = 0; i < num; i++) { n     ans.push_back(temp + 1); n   } n   for (long long int i = 0; i < k - num; i++) { n     ans.push_back(temp); n   } n   if (n - k != 0) { n     temp = (sall - sk) / (n - k); n     num = (sall - sk) - (temp * (n - k)); n     for (long long int i = 0; i < num; i++) { n       ans.push_back(temp + 1); n     } n     for (long long int i = 0; i < n - k - num; i++) { n       ans.push_back(temp); n     } n   } n   sort(ans.begin(), ans.end()); n   for (long long int i = 0; i < n; i++) { n     cout << ans[i] <<    ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct subject { n   long long a, b; n   int c, r, s; n   bool operator<(subject const &T) const { return c < T.c; } n }; n int n, m, rex, rey, fx[55][55][105], fy[55][55][105]; n long long rat, val, tmp, old, dp[55][55][105], ret; n subject a[55]; n void trace(int x, int y, int z) { n   if (y) trace(fx[x][y][z], y - 1, fy[x][y][z]); n   printf( %d %I64d n , a[x].r, a[x].a + z); n } n int main() { n   scanf( %d%d%I64d , &n, &m, &rat); n   for (int i = 0; i < m; i++) { n     scanf( %I64d%I64d%d , &a[i].a, &a[i].b, &a[i].c); n     a[i].r = i + 1; n     a[i].s = a[i].b - a[i].a; n   } n   sort(a, a + m); n   memset(dp, -1, sizeof(dp)); n   for (int i = 0; i < m; i++) { n     for (int j = 0; j <= a[i].s; j++) { n       dp[i][0][j] = val = a[i].a + j; n       for (int k = 1; k <= i; k++) { n         for (int l = 0; l < i; l++) { n           if (a[l].c == a[i].c) continue; n           if (val % rat == 0) { n             tmp = val / rat - a[l].a; n             if (0 <= tmp && tmp <= a[l].s) { n               old = dp[l][k - 1][tmp]; n               if (old != -1 && dp[i][k][j] < old + val) { n                 dp[i][k][j] = old + val; n                 fx[i][k][j] = l; n                 fy[i][k][j] = tmp; n               } n             } n           } n           if (val > rat) { n             tmp = val - rat - a[l].a; n             if (0 <= tmp && tmp <= a[l].s) { n               old = dp[l][k - 1][tmp]; n               if (old != -1 && dp[i][k][j] < old + val) { n                 dp[i][k][j] = old + val; n                 fx[i][k][j] = l; n                 fy[i][k][j] = tmp; n               } n             } n           } n         } n       } n       if (dp[i][n - 1][j] > ret) ret = dp[i][n - 1][j], rex = i, rey = j; n     } n   } n   if (ret) { n     printf( YES n , ret); n     trace(rex, n - 1, rey); n   } else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int b[100000], c = 0, d, e, f; n   int a; n   cin >> a; n   f = a; n   for (int i = 0; i < a; ++i) { n     cin >> b[i]; n     if (i == b[i]) c = c + 1; n   } n   for (int i = 0; i < a; ++i) { n     if (i != b[i]) { n       if (b[b[i]] == i) { n         c = c + 2; n         cout << c; n         return 0; n       } n     } n   } n   if (c == f) n     cout << c; n   else n     cout << c + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace jenga { n inline char get_unempty_char() { n   char ch; n   while (isspace(ch = getchar())) n     ; n   return ch; n } n const double eps(1e-10), Inf = 1e+64; n const int RED = 1, BLUE = 2, GREEN = 3, EMPTY = 0, N = 6, Base = 67, n           mod = 3000007; n int n, last[mod] = {}, next[mod] = {}, total_edge = 0, s[N * 3 - 1] = {}, n        tot = 0; n unsigned long long hv[mod] = {}; n double f[mod] = {}; n inline void add(unsigned long long hash, double v) { n   int u = hash % mod; n   next[++total_edge] = last[u]; n   last[u] = total_edge; n   f[total_edge] = v; n   hv[total_edge] = hash; n } n inline int get_num(char ch) { n   if (ch ==  R ) return RED; n   if (ch ==  B ) return BLUE; n   if (ch ==  G ) return GREEN; n   if (ch ==  E ) return EMPTY; n   assert(false); n } n void init() { n   n = get_unempty_char() -  0 ; n   for (int i = 1; i <= n; ++i) { n     s[i] |= get_num(get_unempty_char()) << 0; n     s[i] |= get_num(get_unempty_char()) << 2; n     s[i] |= get_num(get_unempty_char()) << 4; n   } n   tot = n; n } n inline unsigned long long hash(int *s, int k, int up) { n   static int v[N * 3 + 10] = {}; n   unsigned long long h = 0; n   int tot = 0; n   for (int i = 1; i <= k; ++i) { n     int c1 = (s[i] >> 4) & 3, c2 = (s[i]) & 3, c3 = (s[i] >> 2) & 3; n     v[++tot] = n         c1 > c2 ? (c3 << 2) | c1 | (c2 << 4) : (c3 << 2) | c2 | (c1 << 4); n   } n   sort(v + 1, v + tot + 1); n   int c1 = (up >> 4) & 3, c2 = up & 3, c3 = (up >> 2) & 3; n   if (c1 > c2) up = c1 | (c2 << 4) | (c3 << 2); n   for (int i = 1; i <= tot; ++i) h = h * Base + v[i]; n   h = h * Base + up; n   return h; n } n double work(int *s, int tot, int up) { n   unsigned long long h = hash(s, tot, up); n   for (int i = last[h % mod]; i; i = next[i]) n     if (hv[i] == h) return f[i]; n   double v[4] = {Inf, Inf, Inf, Inf}; n   int to = tot, D = 6; n   if ((up & 3) && ((up >> 2) & 3) && ((up >> 4) & 3)) s[++to] = up, up = 0; n   for (int i = 1; i <= tot; ++i) { n     int c1 = s[i] & 3, c2 = (s[i] >> 2) & 3, c3 = (s[i] >> 4) & 3, ns = s[i]; n     if (c1 && c2 && c3 && v[c2] > eps) { n       s[i] = 0; n       if (!(up & 3)) n         v[c2] = min(v[c2], work(s, to, up | c2)); n       else if (!(up >> 4 & 3)) n         v[c2] = min(v[c2], work(s, to, up | c2 << 4)); n       if (!(up >> 2 & 3)) v[c2] = min(v[c2], work(s, to, up | c2 << 2)); n       s[i] = ns; n     } n     if (c1 && c2 && v[c1] > eps) { n       s[i] = c3 == 0 ? 0 : s[i] & ~3; n       if (!(up & 3)) n         v[c1] = min(v[c1], work(s, to, up | c1)); n       else if (!(up >> 4 & 3)) n         v[c1] = min(v[c1], work(s, to, up | c1 << 4)); n       if (!(up >> 2 & 3)) v[c1] = min(v[c1], work(s, to, up | c1 << 2)); n       s[i] = ns; n     } n     if (c2 && c3 && v[c3] > eps) { n       s[i] = c1 == 0 ? 0 : s[i] & ~48; n       if (!(up & 3)) n         v[c3] = min(v[c3], work(s, to, up | c3)); n       else if (!(up >> 4 & 3)) n         v[c3] = min(v[c3], work(s, to, up | c3 << 4)); n       if (!(up >> 2 & 3)) v[c3] = min(v[c3], work(s, to, up | c3 << 2)); n       s[i] = ns; n     } n   } n   double sum = 0; n   if (v[1] != Inf) sum += v[1], D -= 1; n   if (v[2] != Inf) sum += v[2] * 2, D -= 2; n   if (v[3] != Inf) sum += v[3] * 2, D -= 2; n   sum = D == 6 ? 0 : (sum + 6) / (6 - D); n   add(h, sum); n   return sum; n } n int Main() { n   init(); n   printf( %.15f n , work(s, tot - 1, s[tot])); n   return 0; n } n }  // namespace jenga n int main() { n   jenga::Main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, pair<int, int> > > v; n int main() { n   ios_base::sync_with_stdio(false); n   ; n   int n; n   cin >> n; n   cout << (long long)(n - 2) * (n - 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n long long fast_exp(long long base, long long exp, long long mod) { n   long long res = 1; n   while (exp > 0) { n     if (exp % 2 == 1) res = (res * base) % mod; n     base = (base * base) % mod; n     exp /= 2; n   } n   return res; n } n int n, k, a, b, q; n int ta[211111]; n int tb[211111]; n long long bita[211111]; n long long flaga[211111]; n long long bitb[211111]; n long long flagb[211111]; n void upd(long long* arr, int p, int v) { n   for (; p <= n; p += (p & (-p))) arr[p] += v; n } n long long sum(long long* arr, int b) { n   long long sm = 0; n   for (; b > 0; b -= (b & (-b))) sm += arr[b]; n   return sm; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> k >> a >> b >> q; n   while (q--) { n     int type, d, ai; n     cin >> type; n     if (type == 1) { n       cin >> d >> ai; n       long long value = sum(bita, d) - sum(bita, d - 1); n       if (value + ai <= a && !ta[d]) n         upd(bita, d, ai); n       else { n         ta[d] = 1; n         upd(bita, d, -value); n         long long fl = sum(flaga, d) - sum(flaga, d - 1); n         if (fl == 0) upd(flaga, d, 1); n       } n       value = sum(bitb, d) - sum(bitb, d - 1); n       if (value + ai <= b && !tb[d]) n         upd(bitb, d, ai); n       else { n         tb[d] = 1; n         upd(bitb, d, -value); n         long long fl = sum(flagb, d) - sum(flagb, d - 1); n         if (fl == 0) upd(flagb, d, 1); n       } n     } else { n       int p; n       cin >> p; n       long long before = sum(bitb, p - 1) + b * sum(flagb, p - 1); n       long long after = sum(bita, n) - sum(bita, p + k - 1) + n                         (sum(flaga, n) - sum(flaga, p + k - 1)) * a; n       cout << (before + after) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long A; n vector<pair<long long, int> > ls; n vector<long long> M2[100000]; n vector<long long> ls2; n long long my_stp(long long first, int stp) { n   if (stp == 0) { n     return 1ll; n   } n   long long res = my_stp(first, stp / 2); n   res = res * res; n   if (stp & 1) { n     res = res * first; n   } n   return res; n } n inline pair<bool, long long> sqrtn(long long first, int stp) { n   long long t = (long long)pow((long double)first, (long double)1 / stp); n   for (long long k = max(2ll, t - 1); k <= t + 1; k++) { n     if (my_stp(k, stp) == first) { n       return make_pair(true, k); n     } n   } n   return make_pair(false, 0ll); n } n inline bool is_prime(long long first) { n   for (long long i = 2; i * i <= first; i++) { n     if (first % i == 0) return false; n   } n   return true; n } n void obr(long long term, int id) { n   for (int i = 1; (1ll << i) <= term - 1; i++) { n     pair<bool, long long> sq = sqrtn(term - 1, i); n     if (sq.first && is_prime(sq.second)) { n       ls2.push_back(sq.second); n       M2[id].push_back(sq.second); n       break; n     } n   } n } n vector<long long> ls3; n void bct(int k, long long mul, int id) { n   if (k == (int)(ls).size()) { n     obr(mul, id); n     ls3[id] = mul; n     return; n   } n   for (int j = 0; j <= ls[k].second; j++) { n     bct(k + 1, mul, id * (ls[k].second + 1) + j); n     mul *= ls[k].first; n   } n } n vector<pair<int, int> > G[100000]; n void bct2(int k, int mul1, int mul2) { n   if (k == (int)(ls).size()) { n     if (mul2 != mul1) G[mul1].push_back(make_pair(mul2 - mul1, mul2)); n     return; n   } n   for (int j = 0; j <= ls[k].second; j++) { n     for (int j1 = j; j1 <= ls[k].second; j1++) { n       bct2(k + 1, mul1 * (ls[k].second + 1) + j, n            mul2 * (ls[k].second + 1) + j1); n     } n   } n } n int main() { n   cin >> A; n   long long cur = A; n   for (long long i = 2; i * i <= cur; i++) { n     int cnt = 0; n     while (cur % i == 0) { n       cnt++; n       cur /= i; n     } n     if (cnt) { n       ls.push_back(make_pair(i, cnt)); n     } n   } n   if (cur > 1) { n     ls.push_back(make_pair(cur, 1)); n   } n   int szls3 = 1; n   for (auto first : ls) { n     szls3 *= (first.second + 1); n   } n   ls3.resize(szls3); n   bct(0, (long long)1, 0); n   { n     sort((ls2).begin(), (ls2).end()), n         ls2.resize(unique((ls2).begin(), (ls2).end()) - ls2.begin()); n   }; n   bct2(0, 0, 0); n   vector<vector<int> > DP((int)(ls3).size(), n                           vector<int>((int)(ls2).size() + 1, 0)); n   DP[0][0] = 1; n   for (int first = 0; first < (int)(ls3).size(); first++) { n     for (auto& second : M2[first]) { n       second = lower_bound((ls2).begin(), (ls2).end(), second) - ls2.begin(); n     } n   } n   for (int i = 0; i < (int)(ls3).size(); i++) { n     for (int j = 0; j < (int)(ls2).size(); j++) { n       DP[i][j + 1] += DP[i][j]; n     } n     for (auto first : G[i]) { n       for (int second : M2[first.first]) { n         DP[first.second][second + 1] += DP[i][second]; n       } n     } n   } n   cout << DP[(int)(ls3).size() - 1][(int)(ls2).size()] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int N = 3e3 + 1; n int a[N], dp[N][N], nxt[N], prv[N], lst[N]; n int main() { n   cin.tie(0), ios::sync_with_stdio(0); n   int t, n; n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 0; i < n; ++i) { n       cin >> a[i], --a[i]; n     } n     memset(lst, -1, n * sizeof *lst); n     n = unique(a, a + n) - a; n     memset(prv, -1, n * sizeof *prv); n     memset(nxt, 127, n * sizeof *nxt); n     for (int i = 0; i < n; ++i) { n       if (lst[a[i]] != -1) { n         prv[i] = lst[a[i]]; n         nxt[lst[a[i]]] = i; n       } n       lst[a[i]] = i; n     } n     for (int le = 2; le <= n; ++le) n       for (int i = 0; i + le <= n; ++i) { n         int j = i + le - 1; n         dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]); n         bool use_j = 0; n         if (a[i] != a[j]) { n           int cnti = 0, cntj = 0; n           for (int z = nxt[i]; z <= j; z = nxt[z]) ++cnti; n           for (int z = prv[j]; z >= i; z = prv[z]) ++cntj; n           use_j = cntj < cnti; n         } n         if (!use_j) { n           for (int z = nxt[i]; z <= j; z = nxt[z]) { n             dp[i][j] = max(dp[i][j], dp[i + 1][z - 1] + dp[z][j] + 1); n           } n         } else { n           for (int z = prv[j]; z >= i; z = prv[z]) { n             dp[i][j] = max(dp[i][j], dp[i][z] + dp[z + 1][j - 1] + 1); n           } n         } n       } n     cout << n - dp[0][n - 1] - 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char t[50], s[50]; n   scanf( %s , t); n   int l = strlen(t), k = l / 2, j = 0; n   if (l % 2 == 0) { n     k = l / 2 - 1; n   } n   for (int i = 0; i < l; i++) { n     s[i] = t[k]; n     j++; n     if (i % 2 == 0) { n       k = k + j; n     } else { n       k = k - j; n     } n   } n   for (int i = 0; i < l; i++) { n     printf( %c , s[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n #pragma GCC optimize( -ffloat-store ) n const long long INF = 9e18; n const long long N = 998244353; n const double eps = 1e-9; n const auto start_time = std::chrono::high_resolution_clock::now(); n void zark() {} n void solve() { n   long long n, k; n   cin >> n >> k; 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   sort((a).begin(), (a).end()); n   sort((b).begin(), (b).end()); n   long long s = 0; n   long long i = 0, j = n - 1, cnt = 0; n   while (cnt < k && i < n && j >= 0) { n     if (a[i] < b[j]) n       s += b[j], cnt++, j--, i++; n     else n       break; n   } n   for (long long ii = i; ii < n; ii++) s += a[ii]; n   cout << s <<   n ; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) solve(); n   zark(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t1, t2, t0, a, b, c, d, x1, x2, lo, mid, hi, ans; n int fun(long long x1, long long x2) { n   return (x1 * t1 + x2 * t2 >= t0 * (x1 + x2)); n } n void fun2(long long x1, long long x2) { n   long long pt = (t1 * x1 + t2 * x2) * (a + b); n   long long et = (t1 * a + t2 * b) * (x1 + x2); n   if (pt < et) { n     a = x1; n     b = x2; n   } n   if (pt == et && (a + b) < (x2 + x1)) { n     a = x1; n     b = x2; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   a = 0; n   b = x2; n   if (t1 == t2) { n     cout << x1 <<     << x2; n     return 0; n   } n   for (int i(0), _n(x1 + 1); i < _n; ++i) { n     lo = 0; n     hi = x2 + 1, ans = 1061109567LL; n     while (lo < hi) { n       mid = lo + hi; n       mid /= 2; n       if (fun(i, mid)) { n         hi = mid; n         ans = min(ans, mid); n       } else n         lo = mid + 1; n     } n     if (ans != 1061109567LL) fun2(i, ans); n   } n   cout << a <<     << b; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   vector<string> v; n   vector<string> res; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     v.push_back(s); n   } n   bool flag = 0; n   string t =   , pal =   ; n   for (int i = 0; i < v.size(); i++) { n     string s = v[i]; n     t = s; n     reverse(s.begin(), s.end()); n     auto it = find(v.begin(), v.end(), s); n     if (it != v.end()) { n       if (*it == t) { n         flag = 1; n         pal = t; n         continue; n       } n       res.push_back(v[i]); n       v.erase(it); n     } n   } n   string out =   ; n   for (auto x : res) { n     out += x; n   } n   string p = out; n   if (flag) out += pal; n   reverse(p.begin(), p.end()); n   out += p; n   cout << out.length() <<   n ; n   cout << out; n } n


#include <bits/stdc++.h> n using namespace std; n struct SCIENT { n   int index; n   int k; n   int inv; n   long long a[200009]; n } sc[3]; n vector<pair<int, int> > v; n int K[3]; n int dynam[2100][2100][3]; n int recurse(int k1, int k2, int which) { n   int last; n   if (k1 == K[1] && k2 == K[2]) n     last = INT_MIN; n   else if (which == 0) n     last = sc[which + 1].a[k1 + 1]; n   else n     last = sc[which + 1].a[k2 + 1]; n   if (dynam[k1][k2][which] != -1) return dynam[k1][k2][which]; n   if (k1 == 0 && k2 == 0) return dynam[k1][k2][which] = 0; n   if (k1 == 0) { n     return dynam[k1][k2][which] = recurse(k1, k2 - 1, 1) + (sc[2].a[k2] < last); n   } n   if (k2 == 0) { n     return dynam[k1][k2][which] = recurse(k1 - 1, k2, 0) + (sc[1].a[k1] < last); n   } n   int p1 = recurse(k1 - 1, k2, 0) + (sc[1].a[k1] < last); n   int p2 = recurse(k1, k2 - 1, 1) + (sc[2].a[k2] < last); n   if (p1 < p2) { n     return dynam[k1][k2][which] = p1; n   } else { n     return dynam[k1][k2][which] = p2; n   } n } n int reconstruct(int k1, int k2, int which) { n   if (k1 == 0 && k2 == 0) return 0; n   int last; n   if (k1 == K[1] && k2 == K[2]) n     last = INT_MIN; n   else if (which == 0) n     last = sc[which + 1].a[k1 + 1]; n   else n     last = sc[which + 1].a[k2 + 1]; n   if (k1 == 0) { n     v.push_back(make_pair(sc[2].a[k2], 2)); n     return reconstruct(k1, k2 - 1, 1) + (sc[2].a[k2] < last); n   } n   if (k2 == 0) { n     v.push_back(make_pair(sc[1].a[k1], 1)); n     return reconstruct(k1 - 1, k2, 0) + (sc[1].a[k1] < last); n   } n   int p1 = dynam[k1 - 1][k2][0] + (sc[1].a[k1] < last); n   int p2 = dynam[k1][k2 - 1][1] + (sc[2].a[k2] < last); n   if (p1 < p2) { n     v.push_back(make_pair(sc[1].a[k1], 1)); n     reconstruct(k1 - 1, k2, 0); n     return p1; n   } else { n     v.push_back(make_pair(sc[2].a[k2], 2)); n     reconstruct(k1, k2 - 1, 1); n     return p2; n   } n } n int main() { n   int N; n   scanf( %d , &N); n   memset(dynam, 0xff, sizeof(dynam)); n   for (int i = 1; i <= N; i++) { n     long long k, a, x, y, m; n     cin >> k >> a >> x >> y >> m; n     K[i] = k; n     sc[i].k = k; n     sc[i].index = i; n     sc[i].a[1] = a; n     sc[i].inv = 0; n     for (int j = 2; j <= k; j++) sc[i].a[j] = (sc[i].a[j - 1] * x + y) % m; n     reverse(sc[i].a + 1, sc[i].a + k + 1); n   } n   int n = recurse(sc[1].k, sc[2].k, 2); n   reconstruct(sc[1].k, sc[2].k, 2); n   cout << n << endl; n   for (int i = 0; i < v.size(); i++) { n     cout << v[i].first <<     << v[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 998244353; n const long long N = 2005; n void init() {} n long long n, m, k; n long long dp[N][N]; n void solve() { n   scanf( %lld%lld%lld , &n, &m, &k); n   dp[1][0] = m; n   for (long long i = 2; i <= n; i++) { n     for (long long j = 0; j < i; j++) { n       dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD; n       if (j) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * (m - 1) % MOD) % MOD; n     } n   } n   printf( %lld n , dp[n][k]); n } n signed main() { n   long long TTT = 1; n   while (TTT--) { n     init(); n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int T, t, a, b, n, k, temp; n   scanf( %d , &T); n   for (t = 0; t < T; t++) { n     scanf( %d%d%d , &a, &b, &n); n     k = 0; n     while (a <= n) { n       if (a > b) { n         temp = a; n         a = b; n         b = temp; n       } n       a += b; n       k++; n     } n     printf( %d n , k); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int chr[1000006]; n long long int freq[1000006]; n long long int Z[2000006]; n void Zalgo(int end) { n   int l = 1, r = 1; n   for (int i = 2; i < end; ++i) { n     if (r > i) { n       int pre = Z[i - l + 1]; n       if (pre + i < r) { n         Z[i] = pre; n       } else { n         l = i; n         while (r < end && chr[r] == chr[r - i + 1] && n                freq[r] == freq[r - i + 1]) { n           ++r; n         } n         Z[i] = r - l; n       } n     } else { n       l = r = i; n       while (r < end && chr[r] == chr[r - i + 1] && n              freq[r] == freq[r - i + 1]) { n         ++r; n       } n       Z[i] = r - l; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   string s, t; n   cin >> n >> m; n   chr[0] = -1; n   freq[0] = 0; n   int index = 1; n   for (int i = 1; i <= n; ++i) { n     string s; n     cin >> s; n     if (s[s.size() - 1] -  a  == chr[index - 1]) { n       freq[index - 1] += stoi(s, nullptr, 10); n     } else { n       chr[index] = s[s.size() - 1] -  a ; n       freq[index] += stoi(s, nullptr, 10); n       ++index; n     } n   } n   int mid = index; n   chr[index] = -1; n   freq[index++] = 0; n   for (int i = 1; i <= m; ++i) { n     string s; n     cin >> s; n     if (s[s.size() - 1] -  a  == chr[index - 1]) { n       freq[index - 1] += stoi(s, nullptr, 10); n     } else { n       chr[index] = s[s.size() - 1] -  a ; n       freq[index] += stoi(s, nullptr, 10); n       ++index; n     } n   } n   reverse(chr, chr + index); n   reverse(freq, freq + index); n   mid = index - mid - 1; n   index--; n   Zalgo(index); n   long long int ans = 0; n   chr[index] = -1; n   freq[index] = 0; n   for (int i = mid + 1; i <= index; ++i) { n     if (Z[i] == mid - 1 && chr[0] == chr[i - 1] && freq[0] <= freq[i - 1]) { n       if (mid == 1) { n         ans += freq[i - 1] - freq[0] + 1; n       } else { n         ++ans; n       } n     } else if (Z[i] == mid - 2 && chr[0] == chr[i - 1] && n                freq[0] <= freq[i - 1] && chr[mid - 1] == chr[i + mid - 2] && n                freq[mid - 1] <= freq[i + mid - 2]) { n       ++ans; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct InputReader { n   char buf[1048576]; n   int p; n   inline InputReader() { p = 1048576; } n   inline void Flush() { n     p = 0; n     fread(buf, 1, 1048576, stdin); n   } n   inline char C() { n     if (p >= 1048576) Flush(); n     return buf[p++]; n   } n   inline char Readnum() { n     char ch = C(); n     while (!isdigit(ch) && ch !=  - ) ch = C(); n     return ch; n   } n   inline void Readalpha(char &c) { n     c = C(); n     while (!isalpha(c)) c = C(); n   } n   int operator()() { n     int ans = 0, fu = 1; n     char ch = Readnum(); n     if (ch ==  - ) fu = -1, ch = C(); n     while (ch >=  0  && ch <=  9 ) { n       ans = ans * 10 + ch -  0 ; n       ch = C(); n     } n     return ans * fu; n   } n   long long Readll() { n     long long ans = 0LL, fu = 1LL; n     char ch = Readnum(); n     if (ch ==  - ) fu = -1LL, ch = C(); n     while (ch >=  0  && ch <=  9 ) { n       ans = ans * 10LL + ch -  0 ; n       ch = C(); n     } n     return ans * fu; n   } n   inline void Readstring(string &x) { n     x.clear(); n     char ch = C(); n     while (!isdigit(ch) && !isalpha(ch) && ch !=  #  && ch !=  . ) ch = C(); n     while (isdigit(ch) || isalpha(ch) || ch ==  #  || ch ==  . ) { n       x += ch; n       ch = C(); n     } n   } n   inline void Readchstring(char s[]) { n     int len = 0; n     char ch = C(); n     while (!isdigit(ch) && !isalpha(ch)) ch = C(); n     while (isdigit(ch) || isalpha(ch)) { n       s[len++] = ch; n       ch = C(); n     } n     s[len] =   0 ; n   } n   inline void Specialread(char &c) { n     c = C(); n     while (!isdigit(c) && !isalpha(c) && c !=  #  && c !=  .  && c !=  =  && n            c !=  B ) n       c = C(); n   } n } In; n inline void Read(int &x) { x = In(); } n inline void Read(int &x, int &y) { n   x = In(); n   y = In(); n } n inline void Read(int &x1, int &x2, int &x3) { n   x1 = In(); n   x2 = In(); n   x3 = In(); n } n inline void Read(int &x1, int &x2, int &x3, int &x4) { n   x1 = In(); n   x2 = In(); n   x3 = In(); n   x4 = In(); n } n inline void Read(long long &x) { x = In.Readll(); } n inline void Read(long long &x, long long &y) { n   x = In.Readll(); n   y = In.Readll(); n } n inline void Read(long long &x1, long long &x2, long long &x3) { n   x1 = In.Readll(); n   x2 = In.Readll(); n   x3 = In.Readll(); n } n inline void Read(long long &x1, long long &x2, long long &x3, long long &x4) { n   x1 = In.Readll(); n   x2 = In.Readll(); n   x3 = In.Readll(); n   x4 = In.Readll(); n } n template <typename T> n void Read(T a[], int st, int ed) { n   for (int(i) = (st); (i) <= (ed); ++(i)) Read(a[i]); n } n inline void FILEIO() {} n inline void FILEIO(string pname) { n   freopen((pname +  .in ).c_str(),  r , stdin); n   freopen((pname +  .out ).c_str(),  w , stdout); n } n inline void FILEIO_OICONTEST(string pname) { n   freopen((pname +  .in ).c_str(),  r , stdin); n   freopen((pname +  .out ).c_str(),  w , stdout); n } n void Printtime() {} n void END() { n   Printtime(); n   exit(0); n } n template <typename T> n void END(T mes) { n   cout << mes << endl; n   END(); n } n template <typename T> n void Print(T a[], int s, int t, char sp =    , char ed =   n ) { n   if (s > t) return; n   for (int i = s; i < t; i++) cout << a[i] << sp; n   cout << a[t] << ed; n   cout.flush(); n } n template <typename T> n void Print(T a, int s = 0, int t = -1, char sp =    , char ed =   n ) { n   if (t == -1) t = a.size() - 1; n   for (int i = s; i <= t; i++) cout << a[i] << sp; n   cout << ed; n   cout.flush(); n } n vector<int> Range(int l, int r) { n   vector<int> ret{}; n   for (int(i) = (l); (i) <= (r); ++(i)) ret.push_back(i); n   return ret; n } n const long long MOD = 998244353; n template <typename T> n T Mymo(const T &x) { n   return x >= MOD ? x - MOD : x; n } n template <typename T> n void Mymod(T &x) { n   x = x >= MOD ? x - MOD : x; n } n inline long long Pow(long long a, long long b, const long long p = MOD) { n   long long ret = 1; n   for (; b; a = a * a % p, b >>= 1LL) n     if (b & 1LL) ret = ret * a % p; n   return ret; n } n inline long long Inv(long long a, const long long p = MOD) { n   return Pow(a, p - 2LL, p); n } n const int MAXN = 1024; n int n, k; n int a[MAXN], mxa; n long long ansl[131072]; n int dpsum[MAXN][MAXN]; n int Solve(int delta) { n   if (delta > mxa / (k - 1)) return 0; n   for (int(i) = 1; (i) <= (n); ++(i)) memset(dpsum[i], 0, k + 1 << 2); n   int pre = 0; n   int ans = 0; n   for (int(i) = 1; (i) <= (n); ++(i)) { n     while (pre != i - 1 and a[i] - a[pre + 1] >= delta) ++pre; n     for (int(j) = (2); (j) <= (((i) < (k) ? (i) : (k))); ++(j)) { n       int u = j == 2 ? pre : dpsum[pre][j - 1]; n       dpsum[i][j] = Mymo(dpsum[i - 1][j] + u); n       if (j == k) { n         ans = Mymo(ans + u); n         Mymod(ans); n       } n     } n   } n   return ans; n } n int main() { n   FILEIO(); n   Read(n, k); n   Read(a, 1, n); n   sort(a + 1, a + 1 + n); n   mxa = a[n]; n   for (int(i) = (0); (i) <= (mxa); ++(i)) { n     ansl[i] = Solve(i); n   } n   long long ans = 0; n   for (int(i) = (0); (i) <= (mxa); ++(i)) { n     long long cnt = ansl[i] - ansl[i + 1] + MOD; n     ans += cnt * i % MOD; n     Mymod(ans); n   } n   cout << ans << endl; n   END(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = (long long)1e18; n const long long MOD = (long long)1e9 + 7; n long long n, r[200000], a[200000], bad, brd, odd, ll, rr, cnt[200000], n     cntl[200000], i, j, ans; n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; ++i) scanf( %d , &r[i]), ++cnt[r[i]]; n   for (i = 0; i < 200000; ++i) n     if (cnt[i] % 2LL) ++odd; n   if (odd > 1) { n     printf( %d n , 0); n     return 0; n   } n   for (i = 0; i < 200000; ++i) cnt[i] = 0; n   for (i = 0; i < n / 2LL && r[i] == r[n - i - 1]; ++i) ++brd; n   for (i = brd; i < n - brd; ++i) a[i - brd] = r[i], ++cnt[r[i]]; n   if (n - 2LL * brd <= 1LL) { n     printf( %lld n , (n * (n + 1LL)) / 2LL); n     return 0; n   } n   n -= 2LL * brd; n   if (n % 2LL) { n     long long gmid = 0; n     if (cnt[a[n / 2LL]] % 2LL) { n       while (a[n / 2 - gmid] == a[n / 2 + gmid]) ++gmid; n     } n     for (i = n / 2 - gmid + 1; i <= n / 2 + gmid - 1; ++i) --cnt[a[i]]; n     long long minl, minr; n     bad = 0; n     for (i = 0; i < 200000; ++i) n       if (cnt[i]) ++bad; n     for (i = 0; i < 200000; ++i) cntl[i] = 0; n     for (i = 0; i < n; ++i) { n       ++cntl[a[i]]; n       if (i >= n / 2 - gmid + 1 && i <= n / 2 + gmid - 1) --cntl[a[i]]; n       if (cntl[a[i]] && cntl[a[i]] == (cnt[a[i]] + 1) / 2LL) --bad; n       if (i == n / 2 + gmid - 1) { n         for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j) { n           ++cntl[a[j]]; n           ++cnt[a[j]]; n         } n         for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j) n           if (cntl[a[j]] == (cnt[a[j]] + 1) / 2LL) --bad; n       } n       if (!bad) { n         minl = i; n         break; n       } n     } n     gmid = 0; n     if (cnt[a[n / 2LL]] % 2LL) { n       while (a[n / 2 - gmid] == a[n / 2 + gmid]) ++gmid; n     } n     for (i = n / 2 - gmid + 1; i <= n / 2 + gmid - 1; ++i) --cnt[a[i]]; n     bad = 0; n     for (i = 0; i < 200000; ++i) n       if (cnt[i]) ++bad; n     for (i = 0; i < 200000; ++i) cntl[i] = 0; n     for (i = n - 1; i >= 0; --i) { n       ++cntl[a[i]]; n       if (i >= n / 2 - gmid + 1 && i <= n / 2 + gmid - 1) --cntl[a[i]]; n       if (cntl[a[i]] && cntl[a[i]] == (cnt[a[i]] + 1) / 2LL) --bad; n       if (i == n / 2 - gmid + 1) { n         for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j) { n           ++cntl[a[j]]; n           ++cnt[a[j]]; n         } n         for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j) n           if (cntl[a[j]] == (cnt[a[j]] + 1) / 2LL) --bad; n       } n       if (!bad) { n         minr = i; n         break; n       } n     } n     printf( %lld n , (brd + 1LL) * (brd + (n - minl)) + n                          (brd + 1LL) * (brd + (minr + 1LL)) - n                          (brd + 1LL) * (brd + 1LL)); n   } else { n     long long gmid = 0; n     while (a[n / 2 - gmid - 1] == a[n / 2 + gmid]) ++gmid; n     for (i = n / 2 - gmid; i <= n / 2 + gmid - 1; ++i) --cnt[a[i]]; n     long long minl, minr; n     bad = 0; n     for (i = 0; i < 200000; ++i) n       if (cnt[i]) ++bad; n     for (i = 0; i < 200000; ++i) cntl[i] = 0; n     for (i = 0; i < n; ++i) { n       ++cntl[a[i]]; n       if (i >= n / 2 - gmid && i <= n / 2 + gmid - 1) --cntl[a[i]]; n       if (cntl[a[i]] == cnt[a[i]] / 2LL) --bad; n       if (i == n / 2 + gmid - 1) n         for (j = n / 2 - gmid; j <= n / 2 + gmid - 1; ++j) { n           ++cntl[a[j]]; n           if (cntl[a[j]] == cnt[a[j]] / 2LL) --bad; n         } n       if (!bad) { n         minl = i; n         break; n       } n     } n     bad = 0; n     for (i = 0; i < 200000; ++i) n       if (cnt[i]) ++bad; n     for (i = 0; i < 200000; ++i) cntl[i] = 0; n     for (i = n - 1; i >= 0; --i) { n       ++cntl[a[i]]; n       if (i >= n / 2 - gmid && i <= n / 2 + gmid - 1) --cntl[a[i]]; n       if (cntl[a[i]] == cnt[a[i]] / 2LL) --bad; n       if (i == n / 2 - gmid) n         for (j = n / 2 - gmid; j <= n / 2 + gmid - 1; ++j) { n           ++cntl[a[j]]; n           if (cntl[a[j]] == cnt[a[j]] / 2LL) --bad; n         } n       if (!bad) { n         minr = i; n         break; n       } n     } n     printf( %lld n , (brd + 1LL) * (brd + (n - minl)) + n                          (brd + 1LL) * (brd + (minr + 1LL)) - n                          (brd + 1LL) * (brd + 1LL)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100005]; n int dp[100005]; n int main() { n   int n; n   cin >> n; n   arr[0] = -2000; n   for (long long i = 1; i < n + 1; i++) { n     cin >> arr[i]; n     dp[i] = 1e9; n   } n   dp[0] = 0; n   int pay = 0; n   for (long long i = 1; i < n + 1; i++) { n     int x = upper_bound(arr, arr + i, arr[i] - 1) - arr; n     x--; n     dp[i] = min(dp[i], dp[x] + 20); n     x = upper_bound(arr, arr + i, arr[i] - 90) - arr; n     x--; n     dp[i] = min(dp[i], dp[x] + 50); n     x = upper_bound(arr, arr + i, arr[i] - 1440) - arr; n     x--; n     dp[i] = min(dp[i], dp[x] + 120); n     cout << dp[i] - pay <<   n ; n     pay = dp[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n; n string s[maxn]; n map<int, pair<int, int>> mp; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n; n   int correct = 0; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n     int balance = 0; n     int min_balance = 0; n     for (char c : s[i]) { n       if (c ==  ( ) { n         balance++; n       } else { n         balance--; n       } n       min_balance = min(min_balance, balance); n     } n     if (min_balance >= 0) { n       if (balance == 0) { n         correct++; n       } else { n         mp[balance].first++; n       } n     } else { n       if (min_balance == balance) { n         mp[-balance].second++; n       } n     } n   } n   int res = correct / 2; n   for (auto& it : mp) { n     res += min(it.second.first, it.second.second); n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n int n, a[200005]; n long double eps = 1e-11, b[200005], s[200005]; n long double f(long double first) { n   long double mn = 0, ans = 0; n   for (int i = 1; i <= n; i++) { n     b[i] = -first + a[i]; n     s[i] = s[i - 1] + b[i]; n     ans = max(ans, abs(s[i] - mn)); n     mn = min(mn, s[i]); n   } n   mn = 0; n   for (int i = 1; i <= n; i++) { n     ans = max(ans, abs(s[i] - mn)); n     mn = max(mn, s[i]); n   } n   return ans; n } n int32_t main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(); n   cout.tie(); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   long double l = -1e9, r = 1e9; n   for (int i = 1; i <= 200; i++) { n     long double mid1 = (l * 2 + r) / 3, mid2 = (l + r * 2) / 3; n     if (f(mid1) > f(mid2)) n       l = mid1; n     else if (f(mid1) < f(mid2)) n       r = mid2; n     else n       l = mid1, r = mid2; n   } n   cout << fixed << setprecision(7) << f(l); n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[1000010] = {}; n void pre() { n   for (int i = 1; i < 1000010; i++) { n     for (int j = i; j < 1000010; j += i) { n       cnt[j]++; n     } n   } n } n long long int tree[2 * 1000010]; n int n; n void build() { n   for (int i = n - 1; i > 0; i--) { n     tree[i] = tree[i << 1] + tree[(i << 1) | 1]; n   } n } n void update(int idx, long long int val) { n   tree[idx + n] = val; n   for (int i = idx + n; i > 0; i >>= 1) { n     tree[i >> 1] = tree[i] + tree[i ^ 1]; n   } n } n long long int query(int l, int r) { n   long long int ans = 0; n   l += n; n   r += n; n   for (; l < r; l >>= 1, r >>= 1) { n     if (l & 1) { n       ans += tree[l]; n       l++; n     } n     if (r & 1) { n       r--; n       ans += tree[r]; n     } n   } n   return ans; n } n int main() { n   pre(); n   int m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %lld , &tree[n + i]); n   } n   build(); n   set<int> s; n   for (int i = 0; i < n; i++) { n     if (tree[n + i] > 2) { n       s.insert(i); n     } n   } n   while (m--) { n     int t, l, r; n     scanf( %d %d %d , &t, &l, &r); n     l--; n     r--; n     if (t == 2) { n       printf( %lld n , query(l, r + 1)); n     } else { n       l--; n       vector<int> v; n       if (s.empty()) { n         continue; n       } n       if (s.upper_bound(l) == s.end()) { n         continue; n       } n       int idx = *s.upper_bound(l); n       while (idx <= r) { n         s.erase(idx); n         long long int x = tree[n + idx]; n         update(idx, (long long int)cnt[x]); n         if (cnt[x] > 2) { n           v.push_back(idx); n         } n         if (s.empty()) { n           break; n         } n         if (s.upper_bound(l) == s.end()) { n           break; n         } n         idx = *s.upper_bound(l); n       } n       for (int u : v) { n         s.insert(u); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5e3 + 10, MOD = 1e9 + 7; n int n, ans, l = -1, r = 1e4 + 10, mid, mark[MAXN]; n pair<int, int> a[MAXN]; n bool first; n vector<int> adj[MAXN]; n inline int Dis(int i, int j) { n   return abs(a[i].first - a[j].first) + abs(a[i].second - a[j].second); n } n inline void Make(int mid) { n   memset(mark, 0ll, sizeof(mark)); n   for (int i = 0; i < n; i++) adj[i].clear(); n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) n       if (Dis(i, j) > mid) adj[i].push_back(j), adj[j].push_back(i); n } n inline void DFS(int v) { n   for (auto u : adj[v]) { n     if (!mark[u]) n       mark[u] = 3 ^ mark[v], DFS(u); n     else n       first &= (mark[v] != mark[u]); n   } n } n inline bool Check(int mid) { n   Make(mid); n   ans = first = 1; n   for (int i = 0; i < n; i++) n     if (!mark[i]) mark[i] = 1, ans <<= 1, ans %= MOD, DFS(i); n   return first; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second; n   while (r - l > 1) { n     mid = (l + r) >> 1; n     if (Check(mid)) n       r = mid; n     else n       l = mid; n   } n   Check(r); n   cout << r <<   n  << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     int a[n], b[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     sort(a, a + n); n     sort(b, b + n); n     int j = 0, k = n - 1; n     while (m--) { n       if (a[j] < b[k]) swap(a[j], b[k]); n       j++; n       k--; n     } n     int sum = 0; n     for (int i = 0; i < n; i++) sum = sum + a[i]; n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300500; n int n, m, q; n vector<int> g[maxn]; n bool used[maxn]; n int p[maxn], sz[maxn], diameter[maxn]; n int maxi, maxiV; n void dfs(int v, int depth, int p) { n   if (depth > maxi) { n     maxi = depth; n     maxiV = v; n   } n   for (size_t i = 0; i < g[v].size(); i++) { n     int to = g[v][i]; n     if (to != p) dfs(to, depth + 1, v); n   } n } n int findLongestWay(int v) { n   maxi = -1; n   dfs(v, 0, -1); n   maxi = -1; n   dfs(maxiV, 0, -1); n   return maxi; n } n void init() { n   for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1, diameter[i] = 0; n } n int getSet(int v) { n   if (p[v] == v) return v; n   return p[v] = getSet(p[v]); n } n void unionSets1(int x, int y) { n   x = getSet(x); n   y = getSet(y); n   if (sz[x] > sz[y]) swap(x, y); n   sz[y] += sz[x]; n   p[x] = y; n } n int rad(int x) { return (diameter[x] + 1) / 2; } n void unionSets2(int x, int y) { n   x = getSet(x); n   y = getSet(y); n   if (x == y) return; n   if (sz[x] > sz[y]) swap(x, y); n   sz[y] += sz[x]; n   p[x] = y; n   diameter[y] = max(rad(x) + rad(y) + 1, max(diameter[x], diameter[y])); n } n int query(int x) { return diameter[getSet(x)]; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   ; n   cin >> n >> m >> q; n   init(); n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n     unionSets1(x, y); n   } n   for (int i = 1; i <= n; i++) { n     int pp = getSet(i); n     if (!used[pp]) { n       used[pp] = 1; n       diameter[pp] = findLongestWay(i); n     } n   } n   while (q--) { n     int t, x, y; n     cin >> t; n     if (t == 2) { n       cin >> x >> y; n       unionSets2(x, y); n     } else { n       cin >> x; n       printf( %d n , query(x)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1000010; n const double eps = 1e-6; n const double pi = 4 * atan(1); n long long n, a[N], k, res = 1e18; n int solve() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   if (n == 2) n     cout <<  1  << endl; n   else if (n == 3) n     cout <<  2  << endl; n   else { n     long long x = 2, y = 3, k = 2; n     res = y; n     while (res < n) { n       if (x + y > n) break; n       res = x + y; n       x = y; n       y = res; n       k++; n     } n     cout << k << endl; n   } n   return 0; n } n int main() { return solve(); } n