#include <bits/stdc++.h> n template <class T> n int gmax(T &a, T b) { n   if (b > a) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n int gmin(T &a, T b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n using namespace std; n string to_string(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 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> 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 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 const int MAXN = 2e5 + 5; n int X[MAXN]; n int solve(int x, int y) { n   if (x > y) n     return y; n   else if (x == y) n     return 0; n   else n     return y - 1; n } n int has[MAXN]; n int main() { n   int n, m; n   while (~scanf( %d %d , &n, &m)) { n     memset(has, 0, sizeof(has)); n     map<int, long long> m1; n     map<int, long long> m2; n     map<int, int> m3; n     long long tmp = 0; n     for (int i = 0; i < m; ++i) { n       scanf( %d , &X[i]); n     } n     for (int i = 1; i < m; ++i) { n       if (X[i] == X[i - 1]) continue; n       tmp += abs(X[i] - X[i - 1]); n       m1[X[i]] += abs(X[i] - X[i - 1]); n       m1[X[i - 1]] += abs(X[i] - X[i - 1]); n       m2[X[i]] += solve(X[i], X[i - 1]); n       m2[X[i - 1]] += solve(X[i - 1], X[i]); n       m3[X[i]]++; n       m3[X[i - 1]]++; n       int t1 = X[i]; n       int t2 = X[i - 1]; n       if (t1 > t2) swap(t1, t2); n       has[t1]++; n       has[t2 + 1]--; n     } n     for (int i = 1; i <= n; ++i) has[i] += has[i - 1]; n     vector<long long> result; n     result.push_back(tmp); n     for (int i = 2; i <= n; ++i) { n       long long tmp2 = tmp - m1[i]; n       result.push_back(tmp2 + m2[i] - (has[i] - m3[i])); n     } n     for (int i = 0; i < n; ++i) { n       if (i) printf(   ); n       printf( %lld , result[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2005; n struct Point { n   long long x, y; n   Point() {} n   Point(long long x, long long y) : x(x), y(y) {} n   bool operator<(const Point& rhs) const { n     if (y != rhs.y) n       return y < rhs.y; n     else n       return x < rhs.x; n   } n }; n Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); } n Point operator*(Point v, long long mul) { return Point(v.x * mul, v.y * mul); } n long long cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } n int n; n Point p[MAXN]; n inline long long C(long long x) { return x * (x - 1) / 2; } n long long calc(Point o, vector<pair<Point, int> >& v) { n   sort(v.begin(), v.end(), n        [&o](const pair<Point, int>& a, const pair<Point, int>& b) -> bool { n          return cross(a.first - o, b.first - o) < 0; n        }); n   long long cnt[2] = {0}, ret = 0; n   for (auto& i : v) cnt[i.second]++; n   for (auto& i : v) { n     cnt[i.second]--; n     ret += C(cnt[0]) * C(cnt[1]); n     cnt[i.second ^ 1]++; n   } n   return ret; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %lld%lld , &p[i].x, &p[i].y); n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     vector<pair<Point, int> > v; n     for (int j = 0; j < n; j++) n       if (j != i) { n         if (p[i] < p[j]) n           v.emplace_back(p[j], 1); n         else n           v.emplace_back(p[i] * 2 - p[j], 0); n       } n     ans += calc(p[i], v); n   } n   ans /= 2; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using VI = vector<int>; n const int NN = 200011; n int a[NN], b[NN], arr[NN]; n VI vec[NN], cyc[NN]; n int nc; n int dp[NN], vst[NN]; n int n, s; n void dfs(int u) { n   while (not vec[u].empty()) { n     int v = vec[u].back(); n     vec[u].pop_back(); n     dfs(a[v]); n     cyc[nc].push_back(v); n   } n } n int solve() { n   cin >> n >> s; n   for (int i = 1; i <= n; i++) scanf( %d , a + i), arr[i] = a[i], dp[i] = i; n   sort(arr + 1, arr + n + 1); n   int m = unique(arr + 1, arr + n + 1) - arr - 1; n   for (int i = 1; i <= n; i++) { n     b[i] = a[i] = lower_bound(arr + 1, arr + m + 1, a[i]) - arr; n   } n   sort(b + 1, b + n + 1); n   for (int i = 1; i <= n; i++) n     if (a[i] ^ b[i]) { n       vec[b[i]].push_back(i); n     } n   for (int i = 1; i <= m; i++) { n     if (not vec[i].empty()) { n       dfs(i); n       int r = ((int)cyc[nc].size()); n       for (int j = 0; j < r; j++) { n         dp[cyc[nc][(j + 1) % r]] = cyc[nc][j]; n         s--; n       } n       nc++; n     } n     if (s < 0) return puts( -1 ); n   } n   s = min(s, nc); n   if (s >= 2) { n     cout << nc - s + 2 << endl; n     cout << s << endl; n     for (int i = 0; i < s; i++) printf( %d  , cyc[i][0]); n     puts(  ); n     int tmp = dp[cyc[s - 1][0]]; n     for (int i = s; --i;) { n       dp[cyc[i][0]] = dp[cyc[i - 1][0]]; n     } n     dp[cyc[0][0]] = tmp; n   } else n     cout << nc << endl; n   for (int i = 1; i <= n; i++) { n     if (dp[i] == i or vst[i]) continue; n     VI ans; n     for (int u = i; not vst[u];) { n       ans.push_back(u); n       vst[u] = 1; n       u = dp[u]; n     } n     printf( %d n , ans.size()); n     for (int u : ans) printf( %d  , u); n     puts(  ); n   } n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n long long int n, i, j, t, ans, arr[3009], crr[3009][3009]; n int main() { n   scanf( %lld , &t); n   while (t--) { n     scanf( %lld , &n); n     ans = 0; n     for (i = 1; i <= n; i++) scanf( %lld , &arr[i]); n     for (i = n; i >= 1; i--) { n       for (j = i - 1; j >= 1; j--) { n         ans += crr[arr[i]][arr[j]]; n       } n       for (j = i + 1; j <= n; j++) { n         crr[arr[j]][arr[i]]++; n       } n     } n     printf( %lld n , ans); n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) crr[i][j] = 0; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, k; n int a[2000000]; n int dem; n int maxa; n int dp[10000001]; n void mmax(int &a, int b) { a = max(a, b); } n bool ok(int len) { n   for (int i = 0; i <= maxa; i++) dp[i] = 0; n   dp[len] = 1; n   for (int i = len + 1; i <= maxa; i++) { n     mmax(dp[i], dp[i - 1]); n     mmax(dp[i], dp[i >> 1] + dp[(i + 1) >> 1]); n   } n   long long sum = 0; n   for (int i = 1; i <= n; i++) sum += dp[a[i]]; n   return sum >= k; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i], maxa = max(maxa, a[i]); n   int d = 1, c = 10000000, g, fin = -1; n   while (d <= c) { n     g = (d + c) / 2; n     if (ok(g)) { n       fin = g; n       d = g + 1; n     } else n       c = g - 1; n   } n   cout << fin; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> mp1, mp2; n long long n, x, yy, c; n vector<pair<int, int>> v; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x >> yy; n     v.push_back({x, yy}); n     mp1[x + yy]++; n     mp2[x - yy]++; n   } n   for (int i = 0; i < n; i++) { n     x = v[i].first; n     yy = v[i].second; n     c += mp1[x + yy]; n     c += mp2[x - yy]; n     c -= 2; n   } n   cout << c / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200010; n int nowarn; n int n, m; n namespace Tree { n int head[MAXN], nxt[MAXN], to[MAXN], eidx; n void init() { n   eidx = 0; n   memset(head, -1, sizeof(head)); n } n void adde(int u, int v) { to[eidx] = v, nxt[eidx] = head[u], head[u] = eidx++; } n }  // namespace Tree n namespace DFN { n int dfn[MAXN], dfn_cnt, son[MAXN], dep[MAXN], top[MAXN], size[MAXN], pa[MAXN]; n void dfs1(int u, int fa, int d) { n   using namespace Tree; n   pa[u] = fa, dep[u] = d, son[u] = 0, size[u] = 1; n   for (int i = head[u]; ~i; i = nxt[i]) { n     int v = to[i]; n     dfs1(v, u, d + 1); n     size[u] += size[v]; n     if (size[v] > size[son[u]]) son[u] = v; n   } n } n void dfs2(int u, int tp) { n   using namespace Tree; n   top[u] = tp, dfn[u] = ++dfn_cnt; n   if (son[u]) dfs2(son[u], tp); n   for (int i = head[u]; ~i; i = nxt[i]) { n     int v = to[i]; n     if (v == son[u]) continue; n     dfs2(v, v); n   } n } n void prelude() { n   size[0] = dfn_cnt = 0; n   dfs1(1, 0, 1); n   dfs2(1, 1); n } n int lca(int u, int v) { n   while (top[u] != top[v]) { n     if (dep[top[u]] < dep[top[v]]) swap(u, v); n     u = pa[top[u]]; n   } n   return min(u, v); n } n }  // namespace DFN n int lowbit(int x) { return x & (-x); } n struct BIT { n   long long c[MAXN]; n   void init() { memset(c, 0, sizeof(c)); } n   void add(int p, long long v) { n     for (; p <= n; p += lowbit(p)) c[p] += v; n   } n   long long sum(int p) const { n     long long s = 0; n     for (; p; p -= lowbit(p)) s += c[p]; n     return s; n   } n   long long sum(int l, int r) const { return sum(r) - sum(l - 1); } n }; n struct Triple { n   int first, second, val; n   Triple() {} n   Triple(int a, int b, int c) : first(a), second(b), val(c) {} n }; n vector<Triple> chain[MAXN]; n BIT sf, sg; n long long query(int u, int v, const BIT &bit) { n   using namespace DFN; n   long long s = 0; n   while (top[u] != top[v]) { n     s += bit.sum(dfn[top[v]], dfn[v]); n     v = pa[top[v]]; n   } n   s += bit.sum(dfn[u], dfn[v]); n   return s; n } n long long f[MAXN], g[MAXN]; n void dp(int u) { n   using namespace Tree; n   using namespace DFN; n   g[u] = 0; n   for (int i = head[u]; ~i; i = nxt[i]) dp(to[i]), g[u] += f[to[i]]; n   sg.add(dfn[u], g[u]); n   f[u] = g[u]; n   for (int i = 0; i < (int)chain[u].size(); ++i) { n     Triple tp = chain[u][i]; n     int s = tp.first, t = tp.second, w = tp.val; n     if (t == u) swap(s, t); n     if (s == u) { n       f[u] = max(f[u], query(u, t, sg) - query(u, t, sf) + w); n     } else { n       f[u] = max(f[u], query(u, s, sg) + query(u, t, sg) - g[u] - n                            query(u, s, sf) - query(u, t, sf) + w); n     } n   } n   sf.add(dfn[u], f[u]); n } n int main() { n   nowarn = scanf( %d%d , &n, &m); n   Tree::init(); n   for (int i = 2; i <= n; ++i) { n     int p; n     nowarn = scanf( %d , &p); n     Tree::adde(p, i); n   } n   DFN::prelude(); n   while (m--) { n     int u, v, w; n     nowarn = scanf( %d%d%d , &u, &v, &w); n     int lca = DFN::lca(u, v); n     chain[lca].push_back(Triple(u, v, w)); n   } n   sf.init(), sg.init(); n   dp(1); n   printf( %lld n , f[1]); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   long long broj = 3; n   int i; n   for (i = 0; i < 3 * n - 1; i++) { n     broj *= 3; n     broj %= 1000000007; n   } n   long long broj1 = 7; n   for (i = 0; i < n - 1; i++) { n     broj1 *= 7; n     broj1 %= 1000000007; n   } n   cout << (broj - broj1 + 1000000007) % 1000000007 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int a[N], cnt[N]; n int f[N], bj[N]; n vector<int> d[N]; n int n, mx; n long long ans; n void init(int n) { n   for (int i = 1; i <= n; i++) f[i] = 1; n   for (int i = 2; i <= n; i++) { n     if (bj[i]) continue; n     f[i] = -1; n     for (int j = i * 2; j <= n; j += i) { n       bj[j] = 1; n       f[j] = (j % (i * i)) ? f[j] * -1 : 0; n     } n   } n } n int count(int x) { n   int res = 0; n   for (int i = 0; i < d[x].size(); i++) { n     res += f[d[x][i]] * cnt[d[x][i]]; n   } n   return res; n } n void add(int x, int v) { n   for (int i = 0; i < d[x].size(); i++) { n     cnt[d[x][i]] += v; n   } n } n int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     a[x]++; n     mx = max(mx, x); n   } n   ans = mx; n   for (int i = 1; i <= mx; i++) { n     for (int j = i; j <= mx; j += i) { n       d[j].push_back(i); n     } n   } n   init(mx); n   for (int g = 1; g <= mx; g++) { n     stack<int> st; n     for (int i = mx / g; i >= 1; i--) { n       if (!a[i * g]) continue; n       int c = count(i); n       while (c) { n         if (gcd(i, st.top()) == 1) { n           ans = max(ans, (long long)i * g * st.top()); n           c--; n         } n         add(st.top(), -1); n         st.pop(); n       } n       st.push(i); n       add(i, 1); n     } n     while (!st.empty()) { n       add(st.top(), -1); n       st.pop(); n     } n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1005, mod = 1e9 + 7; n int yh[N][N], a[N]; n long long kpow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return ans; n } n int main() { n   for (int i = (0); i < (N); ++i) yh[i][0] = 1; n   for (int i = (1); i < (N); ++i) n     for (int j = (1); j < (N); ++j) { n       yh[i][j] = yh[i - 1][j - 1] + yh[i - 1][j]; n       if (yh[i][j] >= mod) yh[i][j] -= mod; n     } n   int n, m; n   cin >> n >> m; n   a[0] = 0; n   a[m + 1] = n + 1; n   for (int i = (1); i < (m + 1); ++i) cin >> a[i]; n   sort(a + 1, a + m + 1); n   long long ans = 1, k = n - m; n   for (int i = (1); i < (m + 2); ++i) { n     int c = a[i] - a[i - 1] - 1; n     ans = ans * yh[k][c] % mod; n     if (i != 1 && i != m + 1 && c) ans = ans * kpow(2, c - 1) % mod; n     k -= c; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[81][81][81], n, m, i, j, k, ans, inf = 1000007, x, y, l, len; n pair<int, int> p; n vector<pair<int, int> > g[82]; n int main() { n   cin >> n >> m; n   if (m > n) { n     cout << -1 << endl; n     return 0; n   } n   cin >> k; n   for (i = 0; i < k; i++) { n     cin >> x >> y >> l; n     if (x == y) continue; n     p.first = y; n     p.second = l; n     g[x].push_back(p); n   } n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) n       for (k = 1; k <= n; k++) dp[i][j][k] = inf; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) dp[i][j][1] = 0; n   for (k = 2; k <= m; k++) n     for (j = 1; j < n; j++) n       for (i = 1; i <= n - j; i++) { n         len = g[i].size(); n         for (l = 0; l < len; l++) { n           if (g[i][l].first < i) continue; n           if (g[i][l].first > i + j) continue; n           dp[i][i + j][k] = n               min(dp[i][i + j][k], min(dp[g[i][l].first][i + 1][k - 1], n                                        dp[g[i][l].first][i + j][k - 1]) + n                                        g[i][l].second); n         } n         len = g[i + j].size(); n         for (l = 0; l < len; l++) { n           if (g[i + j][l].first > i + j) continue; n           if (g[i + j][l].first < i) continue; n           dp[i + j][i][k] = n               min(dp[i + j][i][k], min(dp[g[i + j][l].first][i + j - 1][k - 1], n                                        dp[g[i + j][l].first][i][k - 1]) + n                                        g[i + j][l].second); n         } n       } n   ans = inf; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) ans = min(ans, dp[i][j][m]); n   if (ans == inf) n     cout << -1 << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int n; n long long arr[MAXN][3]; n map<pair<long long, long long>, pair<long long, int> > height; n void update(long long x, long long y, long long z, int id) { n   if (height.find(make_pair((x), (y))) == height.end()) n     height[make_pair((x), (y))] = make_pair((z), (id)); n   else n     height[make_pair((x), (y))] = n         max(height[make_pair((x), (y))], make_pair((z), (id))); n } n int main() { n   cin >> n; n   int idx1 = 0, idx2[2] = {0, 0}; n   long long best1 = 0, best2 = 0; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; n     sort(arr[i], arr[i] + 3); n     if (arr[i][0] > best1) { n       best1 = arr[i][0]; n       idx1 = i; n     } n     if (height.find(make_pair((arr[i][1]), (arr[i][2]))) != height.end()) { n       long long t = n           min(arr[i][0] + height[make_pair((arr[i][1]), (arr[i][2]))].first, n               min(arr[i][1], arr[i][2])); n       if (t > best2) { n         idx2[0] = i; n         idx2[1] = height[make_pair((arr[i][1]), (arr[i][2]))].second; n         best2 = t; n       } n     } n     update(arr[i][0], arr[i][1], arr[i][2], i); n     update(arr[i][0], arr[i][2], arr[i][1], i); n     update(arr[i][1], arr[i][2], arr[i][0], i); n   } n   if (best1 > best2) n     cout << 1 << endl << idx1 << endl; n   else n     cout << 2 << endl << idx2[0] <<     << idx2[1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int len; n int main() { n   cin >> len; n   cin >> s; n   int sum = 0; n   cout << s[0]; n   for (int i = 1;; i++) { n     sum += i; n     if (sum >= len) break; n     cout << s[sum]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (long long int i = (long long int)0; i < (long long int)n; i++) n       cout << i + 1 <<    n [i == n - 1]; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1000000000 ) n #pragma GCC optimize( Ofast,no-stack-protector ) n using namespace std; n const int maxn = (int)2e5 + 10; n vector<int> ed[maxn]; n int t[maxn], h[maxn]; n long long dp[maxn][2]; n void go(int v, int p) { n   vector<pair<long long, int> > g; n   int in = 0; n   int out = 0; n   long long sc = 0; n   for (int u : ed[v]) { n     if (u == p) { n       continue; n     } n     go(u, v); n     if (h[u] > h[v]) { n       out++; n       sc += dp[u][0]; n     } else if (h[u] < h[v]) { n       in++; n       sc += dp[u][1]; n     } else { n       out++; n       g.push_back(make_pair(-dp[u][0] + dp[u][1], u)); n       sc += dp[u][0]; n     } n   } n   sort((g).begin(), (g).end()); n   for (int it = 0; it < 2; it++) { n     if (p != -1) n       if (it == 0) { n         in++; n       } else { n         out++; n       } n     long long ans = (long long)1e18; n     long long cur = sc; n     for (int i = 0; i <= (int)g.size(); i++) { n       ans = min(ans, cur + max(in + i, out - i) * (long long)t[v]); n       if (i != (int)g.size()) cur += g[i].first; n     } n     dp[v][it] = ans; n     if (p != -1) n       if (it == 0) { n         in--; n       } else { n         out--; n       } n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     scanf( %d , &t[i]); n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &h[i]); n   } n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     x--; n     y--; n     ed[x].push_back(y); n     ed[y].push_back(x); n   } n   go(0, -1); n   cout << dp[0][0] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n pair<long double, pair<long long, long long> > c[250001]; n long double p, q, abcd, ABCD; n long long a, b, n, i, x, y; n bool comp(pair<long double, pair<long long, long long> > a, n           pair<long double, pair<long long, long long> > b) { n   if (a.first < b.first) return 1; n   if (a.first > b.first) return 0; n   if (a.second.second < b.second.second) return 1; n   if (a.second.second == b.second.second && a.second.first < b.second.first) n     return 1; n   return 0; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> x >> y >> n; n   abcd = x; n   ABCD = y; n   for (i = 1; i <= n; i++) { n     b = i; n     a = x * b / y; n     p = a; n     q = b; n     c[i * 2 - 1] = make_pair(abs(abcd / ABCD - p / q), make_pair(a, b)); n     b = i; n     a = (x * b + y - 1) / y; n     p = a; n     q = b; n     c[i * 2] = make_pair(abs(abcd / ABCD - p / q), make_pair(a, b)); n   } n   sort(c + 1, c + 1 + n * 2, comp); n   cout << c[1].second.first <<  /  << c[1].second.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k, t, x, y, z, w, ct, ans, f; n string s, l; n long long a[200005]; n set<long long> si; n queue<long long> qi; n map<long long, long long> mi; n vector<long long> vi; n priority_queue<long long> pqdi; n priority_queue<long long, vector<long long>, greater<long long>> pqai; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cerr.tie(NULL); n   cin >> t; n   while (t--) { n     si.clear(); n     vi.clear(); n     cin >> n; n     for (long long i = 1; i <= n; i++) { n       cin >> a[i]; n       si.insert(a[i]); n     } n     if (si.size() != n) { n       cout <<  NO  n            <<   n ; n     } else { n       f = 0; n       vector<long long> diff; n       sort(a + 1, a + n + 1); n       for (long long i = 2; i < n + 1; i++) { n         for (long long j = 1; j < i; j++) { n           diff.push_back(a[i] - a[j]); n         } n       } n       long long valid[1000000]; n       long long j = 2; n       memset(valid, 0, sizeof(valid)); n       vi.push_back(1); n       valid[1] = 1; n       for (long long i = 1; i < n; i++) { n         for (auto it : diff) { n           valid[(vi[i - 1] + it)] = 1; n         } n         while (valid[j]) j++; n         vi.push_back(j); n         valid[j] = 1; n         if (j > 1000000) { n           f = 1; n           break; n         } n       } n       if (f) n         cout <<  NO  n              <<   n ; n       else { n         cout <<  YES  n              <<   n ; n         ; n         for (long long i = 1; i <= n; i++) cout << vi[i - 1] <<    ; n         cout <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 10; n const int MAXN = 1e4 + 10; n const int MOD = 1e9 + 7; n const int inf = 1e9; n const double pi = acos(-1.0); n const double eps = 1e-6; n int dx[] = {0, -1, 0, 1}; n int dy[] = {1, 0, -1, 0}; n map<int, int> mymap, mymap1; n int n, m; n vector<int> Ve, Vo; n int save[200100]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   int res = 0; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     if (x % 2) { n       if (!mymap[x]) { n         Vo.push_back(x); n         mymap[x] = 1; n         mymap1[x] = i; n       } n     } else { n       if (!mymap[x]) { n         Ve.push_back(x); n         mymap[x] = 1; n         mymap1[x] = i; n       } n     } n   } n   int o = Vo.size(); n   int e = Ve.size(); n   int r = -1; n   if (o >= n / 2 && e <= n / 2) n     r = min(o - n / 2, n / 2 - e); n   else if (o <= n / 2 && e >= n / 2) n     r = min(n / 2 - o, e - n / 2); n   if (r != -1) { n     res += r; n     if (o <= n / 2) { n       o += r; n       e -= r; n     } else { n       o -= r; n       e += r; n     } n   } n   res += max(n / 2 - o, 0); n   res += max(n / 2 - e, 0); n   for (int i = 1; i <= min(n, m); i++) n     if (i % 2) { n       if (!mymap[i]) { n         mymap[i] = 1; n         Vo.push_back(i); n       } n     } else { n       if (!mymap[i]) { n         mymap[i] = 1; n         Ve.push_back(i); n       } n     } n   o = Vo.size(); n   e = Ve.size(); n   if (o >= n / 2 && e >= n / 2) { n     cout << res << endl; n     vector<int> K; n     K.clear(); n     for (int i = 0; i < n / 2; i++) n       if (mymap1[Vo[i]]) n         save[mymap1[Vo[i]]] = Vo[i]; n       else n         K.push_back(Vo[i]); n     for (int i = 0; i < n / 2; i++) n       if (mymap1[Ve[i]]) n         save[mymap1[Ve[i]]] = Ve[i]; n       else n         K.push_back(Ve[i]); n     int p = 1; n     int q = 0; n     while (p <= n && q < K.size()) n       if (save[p]) n         p++; n       else { n         save[p] = K[q]; n         p++; n         q++; n       } n     for (int i = 1; i <= n; i++) cout << save[i] <<    ; n   } else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n template <typename T> n struct modular { n   constexpr modular() : val(0) {} n   constexpr modular(const modular<T>& _m) : val(_m.val) {} n   template <typename U> n   constexpr modular(const U& _r = U()) { n     val = -MOD <= _r && _r < MOD ? _r : _r % MOD; n     if (val < 0) { n       val += MOD; n     } n   } n   const T operator()() { return val; } n   template <typename U> n   explicit operator U() const { n     return static_cast<U>(val); n   } n   modular<T>& operator+=(const modular<T>& _m) { n     if ((val += _m.val) >= MOD) { n       val -= MOD; n     } n     return *this; n   } n   modular<T>& operator-=(const modular<T>& _m) { n     if ((val -= _m.val) < 0) { n       val += MOD; n     } n     return *this; n   } n   modular<T>& operator*=(const modular<T>& _m) { n     val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val)) n               .val; n     return *this; n   } n   modular<T>& operator/=(const modular<T>& _m) { n     T a = _m.val, b = MOD, u = 0, v = 1; n     while (a != 0) { n       T q = b / a; n       b -= q * a; n       swap(a, b); n       u -= q * v; n       swap(u, v); n     } n     return *this *= u; n   } n   modular<T>& operator=(const modular<T>& _m) { n     val = _m.val; n     return *this; n   } n   template <typename U> n   modular<T>& operator+=(const U& _r) { n     return *this += modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator-=(const U& _r) { n     return *this -= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator*=(const U& _r) { n     return *this *= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator/=(const U& _r) { n     return *this /= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator=(const U& _r) { n     val = modular<T>(_r).val; n     return *this; n   } n   modular<T> operator-() { return modular<T>(-val); } n   template <typename U> n   friend bool operator==(const modular<U>&, const modular<U>&); n   friend std::istream& operator>>(std::istream& os, modular<T>& _m) { n     os >> _m.val; n     _m *= 1; n     return os; n   } n   friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) { n     return os << _m.val; n   } n   template <typename U> n   modular<T> exp(U e) { n     modular<T> res = 1; n     modular<T> b = val; n     if (e < 0) { n       b = 1 / b; n       e *= -1; n     } n     for (; e; e >>= 1) { n       if (e & 1) { n         res *= b; n       } n       b *= b; n     } n     return res; n   } n  n  private: n   T val; n }; n template <typename T> n inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T, typename U> n inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T, typename U> n inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T> n inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T, typename U> n inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T, typename U> n inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T> n inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T, typename U> n inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T, typename U> n inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T> n inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T, typename U> n inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T, typename U> n inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T> n inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) { n   return _lhs.val == _rhs.val; n } n template <typename T, typename U> n inline bool operator==(const modular<T>& _lhs, const U& _rhs) { n   return _lhs == modular<T>(_rhs); n } n template <typename T, typename U> n inline bool operator==(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) == _rhs; n } n template <typename T> n inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) { n   return !(_lhs == _rhs); n } n template <typename T, typename U> n inline bool operator!=(const modular<T>& _lhs, const U& _rhs) { n   return !(_lhs == _rhs); n } n template <typename T, typename U> n inline bool operator!=(const U& _lhs, const modular<T>& _rhs) { n   return !(_lhs == _rhs); n } n string to_string(string s) { return     + s +    ; } n string to_string(bool x) { return (x ?  T  :  F ); } n string to_string(modular<int> x) { return to_string(int(x)); } n string to_string(const char* s) { return to_string((string)s); } 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 V> n string to_string(V v) { n   bool f = true; n   string res =  [ ; n   for (const auto& x : v) { n     if (!f) res +=  ,  ; n     f = false; n     res += to_string(x); n   } n   res +=  ] ; n   return res; n } n void debug() { cerr << endl; } n template <typename H, typename... T> n void debug(H h, T... t) { n   cerr <<     << to_string(h); n   debug(t...); n } n const int N = 5050; n modular<int> a[N], c[N], dn[N][N << 1], res[N << 1]; n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> a[i]; n   } n   c[1] = 1; n   for (int i = 1; i < n; i++) { n     c[i + 1] = c[i] * a[i]; n   } n   for (int i = n; i >= 1; i--) { n     dn[i][0] = 1; n     for (int j = 1; i + j <= n; j++) { n       dn[i][j] = a[i] * dn[i + 1][j - 1]; n       res[j] += dn[i][j] * c[i]; n     } n   } n   for (int i = 1; i <= n; i++) { n     dn[i][0] = 1; n     for (int j = 2 * n - 2; j >= 1; j--) { n       dn[i][j] = dn[i - 1][j - 1]; n       res[j] += dn[i][j] * c[i]; n       dn[i][j] += (a[i] - 1) * dn[i + 1][j - 1]; n     } n   } n   modular<int> half = modular<int>(1) / 2; n   for (int j = 1; j <= 2 * n - 2; j++) { n     cout << res[j] * half <<    ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   cout << endl; n } n


/** n  * Author: Daniel n  * Created Time: 2021-05-20 00:17:05 n **/ n  n // time-limit: 2000 n // problem-url: https://codeforces.com/contest/1525/problem/E n #include <bits/stdc++.h> n  n using namespace std; n  n #define F first  n #define S second n #define ER erase n #define IS insert n #define PI acos(-1) n #define PB pop_back n #define MP make_pair n #define MT make_tuple n #define LB lower_bound n #define UB upper_bound n #define EB emplace_back n #define lowbit(x) (x & -x) n #define SZ(x) ((int)x.size()) n #define ALL(x) x.begin(), x.end() n #define RALL(x) x.rbegin(), x.rend() n #define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10) n  n typedef long long LL; n typedef vector<LL> VL; n typedef vector<int> VI; n typedef vector<bool> VB; n typedef pair<LL, LL> PLL; n typedef vector<string> VS; n typedef vector<double> VD; n typedef pair<int, int> PII; n typedef unsigned long long ULL; n typedef pair<double, double> PDD; n typedef vector<pair<LL, LL> > VPLL; n typedef vector<pair<int, int> > VPII; n  n template <typename A> using VE = vector<A>; n template <typename A> using USET = unordered_set<A>; n template <typename A> using HEAP = priority_queue<A>; n template <typename A, typename B> using PA = pair<A, B>; n template <typename A, typename B> using UMAP = unordered_map<A, B>; n template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >; n  n template <typename A> A MAX(const A &a) { return a; } n template <typename A> A MIN(const A &a) { return a; } n template <typename A> A MAX(const A *a, const A *b) { return *max_element(a, b); } n template <typename A> A MIN(const A *a, const A *b) { return *min_element(a, b); } n template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); } n template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); } n template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { return *max_element(a, b); } n template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { return *min_element(a, b); } n  n mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count()); n  n template <typename A, typename B> n string to_string(pair<A, B> p); n  n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n  n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n  n string to_string(const string& s) { return     + s +    ; } n  n string to_string(const char* s) { return to_string((string)s); }  n  n string to_string(const char c) { return to_string((string)   + c); }  n  n string to_string(bool b) { return (b ?  true  :  false ); } n  n string to_string(vector<bool> v)  n { n     bool first = true; n     string res =  { ; n     for (int i = 0; i < static_cast<int>(v.size()); i++)  n     { n         if (!first) res +=  ,  ; n         first = false; n         res += to_string(v[i]); n     } n     res +=  } ; n     return res; n } n  n template <size_t N> n string to_string(bitset<N> v) n { n     string res =   ; n     for (size_t i = 0; i < N; i++) res += static_cast<char>( 0  + v[i]); n     return res; n } n  n template <typename A> n string to_string(A v) n { n     bool first = true; n     string res =  { ; n     for (const auto &x : v) n     { n         if (!first) res +=  ,  ; n         first = false; n         res += to_string(x); n     } n     res +=  } ; n     return res; n } n  n template <typename A, typename B> n string to_string(pair<A, B> p) { 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) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + 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) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; } n  n void debug_out() { cout <<   n ; } n  n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { cout <<     << to_string(H); debug_out(T...); } n  n #ifdef LOCAL n #define debug(...) cout <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__) n #else n #define debug(...) 42 n #endif n  n /////////////////////////////////////////////////////////////////////////// n //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// n /////////////////////////////////////////////////////////////////////////// n  n // check the limitation!!! n const int N = 100010, M = 1010, mod = 998244353; n  n int qp(int a, int b) n { n     int res = 1; n     while (b) n     { n         if (b & 1) res = (LL)res * a % mod; n         a = (LL)a * a % mod; n         b >>= 1; n     } n     return res; n } n  n // read the question carefully!!! n int main() n { n     SOS; n  n     int n, m; n     cin >> n >> m; n     VE<VI> d(n, VI(m)); n     for (auto &u : d) n         for (auto &v : u) n             cin >> v; n     int fact_inv = 1; n     for (int i = 1; i <= n; i ++ ) fact_inv = (LL)fact_inv * i % mod; n     fact_inv = qp(fact_inv, mod - 2); n     int res = 0; n     for (int j = 0; j < m; j ++ ) n     { n         VI cnt(n + 1); n         for (int i = 0; i < n; i ++ ) cnt[n - d[i][j] + 1] ++ ; n         int ans = 1, tot = 0; n         for (int i = 0; i < n; i ++ ) n         { n             tot += cnt[i]; n             ans = (LL)ans * tot % mod; n             tot = max(0, tot - 1); n         } n         res = (res + 1 - (LL)fact_inv * ans) % mod; n     } n     res = (res + mod) % mod; n     cout << res <<   n ; n     return 0; n } n  n // GOOD LUCK!!! n


#include <bits/stdc++.h> n using namespace std; n long long n, s, a, ans, a11, r; n vector<long long> aa, ab, c; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> s >> a; n     if (s == 11) { n       a11++; n       ans += a; n     } n     if (s == 0) c.push_back(a); n     if (s == 10) aa.push_back(a); n     if (s == 1) ab.push_back(a); n   } n   sort(aa.begin(), aa.end()); n   reverse(aa.begin(), aa.end()); n   sort(ab.begin(), ab.end()); n   reverse(ab.begin(), ab.end()); n   r = min(aa.size(), ab.size()); n   for (int i = r; i < aa.size(); i++) { n     c.push_back(aa[i]); n   } n   for (int i = r; i < ab.size(); i++) { n     c.push_back(ab[i]); n   } n   sort(c.begin(), c.end()); n   reverse(c.begin(), c.end()); n   for (int i = 0; i < min(a11, (long long)c.size()); i++) ans += c[i]; n   for (int i = 0; i < r; i++) { n     ans += aa[i]; n     ans += ab[i]; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = (int)(0); i < (int)(n); ++i) cin >> v[i]; n   sort(v.begin(), v.end()); n   cout << v[(n - 1) / 2] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int toInt(string s) { n   int v; n   istringstream sin(s); n   sin >> v; n   return v; n } n template <class T> n inline string toString(T x) { n   ostringstream sout; n   sout << x; n   return sout.str(); n } n const double EPS = 1e-10; n const double PI = acos(-1.0); n vector<int> x, y; n int xo, yo; n int n, d; n int dp[1000][1000]; n int sqr(int a) { return a * a; } n int dfs(int x1, int y1) { n   if (sqr(x1) + sqr(y1) > sqr(d)) return dp[x1 + 500][y1 + 500] = 1; n   if (dp[x1 + 500][y1 + 500] != -1) return dp[x1 + 500][y1 + 500]; n   for (int i = (0); i < (int((x).size())); ++i) n     if (!dfs(x1 + x[i], y1 + y[i])) return dp[x1 + 500][y1 + 500] = 1; n   return dp[x1 + 500][y1 + 500] = 0; n } n int main(int argc, char *argv[]) { n   ios::sync_with_stdio(false); n   memset(dp, -1, sizeof dp); n   cin >> xo >> yo >> n >> d; n   for (int i = (0); i < (n); ++i) { n     int xi, yi; n     cin >> xi >> yi; n     x.push_back(xi); n     y.push_back(yi); n   } n   if (dfs(xo, yo)) n     cout <<  Anton  << endl; n   else n     cout <<  Dasha  << endl; n   return 0; n } n


#include <bits/stdc++.h> n long long mpow(long long a, long long n, long long mod) { n   long long ret = 1; n   long long b = a; n   while (n) { n     if (n & 1) ret = (ret * b) % mod; n     b = (b * b) % mod; n     n >>= 1; n   } n   return (long long)ret; n } n using namespace std; n vector<int> v, v1; n pair<int, int> p[100004]; n int a[100004], b[100004]; n int main() { n   int n, i, j; n   cin >> n; n   for (j = 0; j < n; j++) { n     cin >> p[j].first; n     p[j].second = j; n   } n   sort(p, p + n); n   long long z = 0; n   int need = n - (n + 2) / 3; n   for (j = n - need; j < n; j++) { n     if (z % 2 == 0) { n       a[p[j].second] = p[j].first - z / 2; n       b[p[j].second] = z / 2; n     } else { n       a[p[j].second] = z / 2; n       b[p[j].second] = p[j].first - z / 2; n     } n     z++; n   } n   for (j = 0; j < n - need; j++) { n     a[p[j].second] = 0; n     b[p[j].second] = p[j].first; n   } n   cout <<  YES  << endl; n   for (j = 0; j < n; j++) cout << a[j] <<    ; n   cout << endl; n   for (j = 0; j < n; j++) cout << b[j] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, ans = -1; n int a1[1000001], b1[1000001], a[1000001], b[1000001], t[1000001], d[1000001], n     in[1000001], Max[2000001]; n int s = 1; n int getmax(int v, int vl, int vr, int l, int r) { n   if (l > vr || r < vl) { n     return 0; n   } n   if (vl >= l && vr <= r) { n     return Max[v]; n   } n   return max(getmax(v * 2, vl, (vl + vr) / 2, l, r), n              getmax(v * 2 + 1, (vl + vr) / 2 + 1, vr, l, r)); n } n void update(int v) { n   v /= 2; n   if (v <= 0) { n     return; n   } n   Max[v] = max(Max[v * 2], Max[v * 2 + 1]); n   update(v); n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a1[i]; n     t[a1[i]] = i + 1; n   } n   for (int i = 0; i < n; i++) { n     cin >> b1[i]; n   } n   for (int i = 0; i < n; i++) { n     a[i] = i; n     b[i] = t[b1[i]]; n   } n   while (n > s) { n     s *= 2; n     k++; n   } n   for (int i = 1; i < 2 * s; i++) { n     Max[i] = 0; n   } n   for (int i = 0; i < n; i++) { n     d[i] = getmax(1, 1, s, b[i], n) + 1; n     Max[s + b[i] - 1] = d[i]; n     update(s + b[i] - 1); n   } n   for (int i = 0; i < n; i++) { n     ans = max(ans, d[i]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3fffffff; n const int SINF = 0x7fffffff; n const long long LINF = 0x3fffffffffffffff; n const long long SLINF = 0x7fffffffffffffff; n const long double DINF = pow(2, 100); n const int MAXN = 1007; n const int MOD = static_cast<int>(1e9 + 7); n const long double EPS = 1e-11; n struct cT { n   cT() : x(0), y(0) {} n   cT(long double _x, long double _y) : x(_x), y(_y) {} n   cT operator+(const cT &a) const { return cT(x + a.x, y + a.y); } n   cT operator-(const cT &a) const { return cT(x - a.x, y - a.y); } n   cT operator/(const int a) { return cT(x / a, y / a); } n   bool operator==(const cT &a) const { n     return ((((x - a.x) >= 0) ? (x - a.x) : (-(x - a.x))) < EPS && n             (((y - a.y) >= 0) ? (y - a.y) : (-(y - a.y))) < EPS); n   } n   bool operator!=(const cT &a) const { return !((*this) == a); } n   bool operator<(const cT &a) const { n     return ((((x - a.x) >= 0) ? (x - a.x) : (-(x - a.x))) > EPS) n                ? x < a.x n                : y < a.y - EPS; n   } n   long double getk() { n     return (((x) >= 0) ? (x) : (-(x))) < EPS ? DINF : (y / x); n   } n   long double x, y; n } cr[MAXN]; n struct dT { n   dT() : k(0) {} n   dT(cT _cr, long double _k) : cr(_cr), k(_k) {} n   bool operator<(const dT &a) const { n     return (cr != a.cr) ? cr < a.cr : k < a.k - EPS; n   } n   cT cr; n   long double k; n } med[MAXN * MAXN]; n int n; n int km; n void init(); n void input(); n void work(); n int getans(int l, int r); n int add(int x, int y) { n   x += y; n   if (x >= MOD) x -= MOD; n   return x; n } n void addv(int &x, int y) { n   x += y; n   if (x >= MOD) x -= MOD; n } n int dec(int x, int y) { n   x -= y; n   if (x < 0) x += MOD; n   return x; n } n void decv(int &x, int y) { n   x -= y; n   if (x < 0) x += MOD; n } n int main() { n   init(); n   input(); n   work(); n } n void init() { ios::sync_with_stdio(false); } n void input() { n   scanf( %d , &n); n   int a, b, c, d; n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d%d%d , &a, &b, &c, &d); n     cr[i].x = static_cast<long double>(a * b * d * d) / n               (a * a * d * d + b * b * c * c); n     cr[i].y = static_cast<long double>(c * d * b * b) / n               (a * a * d * d + b * b * c * c); n   } n } n void work() { n   for (int i = 1; i <= n; ++i) { n     for (int j = i + 1; j <= n; ++j) { n       med[++km] = dT((cr[i] + cr[j]) / 2, (cr[j] - cr[i]).getk()); n     } n   } n   sort(med + 1, med + 1 + km); n   med[km + 1] = dT(cT(DINF, DINF), 1); n   int pre = 1, ans = 0; n   for (int i = 1; i <= km + 1; ++i) { n     if (med[i].cr != med[pre].cr) { n       addv(ans, getans(pre, i - 1)); n       pre = i; n     } n   } n   cout << ans << endl; n } n int getans(int l, int r) { n   int pre = l; n   int ans = 1; n   for (int i = l; i <= r; ++i) { n     if ((((med[i].k - med[pre].k) >= 0) ? (med[i].k - med[pre].k) n                                         : (-(med[i].k - med[pre].k))) > EPS) { n       ans = static_cast<long long>(ans) * (i - pre + 1) % MOD; n       pre = i; n     } n   } n   ans = static_cast<long long>(ans) * (r - pre + 2) % MOD; n   return dec(ans, r - l + 2); n } n


#include <bits/stdc++.h> n using namespace std; n char s[1010]; n int main() { n   int f1 = 0, f2 = 0; n   scanf( %s , s); n   int len = strlen(s); n   for (int i = 0; i < len; i++) { n     if (s[i] ==  0 ) { n       if (f1 == 0) { n         printf( 1 1 n ); n         f1 = 1; n       } else { n         printf( 3 1 n ); n         f1 = 0; n       } n     } n     if (s[i] ==  1 ) { n       if (f2 == 0) { n         printf( 4 3 n ); n         f2 = 1; n       } else { n         printf( 4 1 n ); n         f2 = 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int oo = 1000000000; n long long n; n long long a[100005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr), cout.tie(nullptr); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   if (n == 1) { n     cout << 1 <<     << 1 << endl; n     cout << -a[1] << endl; n     a[1] = 0; n     cout << 1 <<     << 1 << endl; n     cout << -a[1] << endl; n     cout << 1 <<     << 1 << endl; n     cout << -a[1] << endl; n     return 0; n   } n   cout << 1 <<     << 1 << endl; n   cout << n - (a[1] % n) << endl; n   a[1] += n - (a[1] % n); n   cout << 2 <<     << n << endl; n   for (int i = 2; i <= n; i++) { n     cout << (a[i] % n) * (n - 1) <<    ; n     a[i] += (a[i] % n) * (n - 1); n   } n   cout << endl; n   cout << 1 <<     << n << endl; n   for (int i = 1; i <= n; i++) cout << -a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> me; n long long sum(long long x) { return (x * (x + 1)) / 2; } n int main() { n   int k; n   string s; n   cin >> k >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  1 ) { n       me.push_back(i); n     } n   } n   long long ans = 0, cnt = 0, idx = -1; n   if (k == 0) { n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  1 ) { n         ans += sum(cnt); n         cnt = 0; n       } else { n         cnt++; n       } n     } n     ans += sum(cnt); n   } else { n     long long fst = -1; n     for (int i = 0; i < me.size(); i++) { n       int idx = me[i]; n       cnt = 0; n       if ((i + k - 1) == me.size() - 1) { n         ans += ((idx - fst) * (s.size() - me[i + k - 1])); n       } else if (i + k - 1 < me.size() - 1) { n         ans += ((idx - fst) * (me[i + k] - me[i + k - 1])); n       } n       fst = me[i]; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int f[50][50], mn[50], mx[50]; n const int INF = 1e9; n int gm, gg, sm, ss; n long long d[51][51] = {}, nd[51][51]; n bool cang[50], cans[50], canb[50]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < (int)(n); ++i) n     for (int j = 0; j < (int)(n); ++j) f[i][j] = INF; n   for (int i = 0; i < (int)(n); ++i) f[i][i] = 0; n   for (int i = 0; i < (int)(m); ++i) { n     int from, to, w; n     scanf( %d%d%d , &from, &to, &w), --from, --to; n     f[from][to] = min(f[from][to], w); n     f[to][from] = min(f[to][from], w); n   } n   scanf( %d%d%d%d , &gm, &gg, &sm, &ss); n   for (int k = 0; k < (int)(n); ++k) n     for (int i = 0; i < (int)(n); ++i) n       for (int j = 0; j < (int)(n); ++j) { n         f[i][j] = min(f[i][j], f[i][k] + f[k][j]); n       } n   for (int i = 0; i < (int)(n); ++i) { n     mn[i] = INF, mx[i] = -INF; n     for (int j = 0; j < (int)(n); ++j) n       if (i != j) { n         mn[i] = min(mn[i], f[i][j]); n         mx[i] = max(mx[i], f[i][j]); n       } n   } n   long long ans = 0; n   for (int gco = 0; gco < (int)(n); ++gco) n     for (int bco = 0; bco < (int)(n); ++bco) n       if (mn[gco] < mx[bco] || (mn[gco] == mx[bco] && gco < bco)) { n         if (gco == bco) continue; n         bool ok = true; n         for (int i = 0; i < (int)(n); ++i) { n           if (i == gco) { n             cang[i] = true; n             cans[i] = canb[i] = false; n           } else if (i == bco) { n             canb[i] = true; n             cang[i] = cans[i] = false; n           } else { n             cang[i] = mn[i] < mn[gco] || (mn[i] == mn[gco] && i < gco); n             canb[i] = mx[i] > mx[bco] || (mx[i] == mx[bco] && i > bco); n             cans[i] = false; n             for (int j = 0; j < (int)(n); ++j) n               if (j != i && n                   (f[i][j] > mn[gco] || (f[i][j] == mn[gco] && i > gco)) && n                   (f[i][j] < mx[bco] || (f[i][j] == mx[bco] && i < bco))) { n                 cans[i] = true; n                 break; n               } n             if (!cang[i] && !cans[i] && !canb[i]) { n               ok = false; n               break; n             } n           } n         } n         if (!ok) continue; n         memset(d, 0, sizeof d); n         d[0][0] = 1; n         for (int i = 0; i < (int)(n); ++i) { n           memset(nd, 0, sizeof nd); n           for (int g = 0; g < (int)(gg + 1); ++g) n             for (int s = 0; s < (int)(ss + 1); ++s) n               if (d[g][s] != 0) { n                 if (cang[i]) { n                   nd[g + 1][s] += d[g][s]; n                 } n                 if (cans[i]) { n                   nd[g][s + 1] += d[g][s]; n                 } n                 if (canb[i]) { n                   nd[g][s] += d[g][s]; n                 } n               } n           memcpy(d, nd, sizeof nd); n         } n         for (int g = gm; g <= gg; ++g) n           for (int s = sm; s <= ss; ++s) { n             ans += d[g][s]; n           } n         d[gg][ss] -= ans; n       } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n struct P { n   long long x, y; n   P() {} n   P(long long _x, long long _y) : x(_x), y(_y) {} n   P operator+(const P &o) { return P(x + o.x, y + o.y); } n   P operator-(const P &o) { return P(x - o.x, y - o.y); } n   long long operator*(const P &o) { n     if (!x && !o.x) return 0; n     if (!x) return -y; n     if (!o.x) return o.y; n     if (fabs(1.0 * o.y / o.x - 1.0 * y / x) < 1e-10) { n       return 0; n     } n     if (1.0 * y / x < 1.0 * o.y / o.x) { n       return 1; n     } else { n       return -1; n     } n   } n   bool operator<(const P &o) const { return x == o.x ? y < o.y : x < o.x; } n }; n struct E { n   int tot; n   int lnk[N], nxt[N << 1], son[N << 1]; n   P w[N << 1]; n   E() { tot = 1; } n   void add(int x, int y, P pt) { n     nxt[++tot] = lnk[x], son[tot] = y, w[tot] = pt, lnk[x] = tot; n   } n   void adde(int x, int y, P pt) { add(x, y, pt), add(y, x, pt); } n } S, T; n int n, m, k, all, mx, gid, gu, gv; n int cnt, na, nb, s1, s2, qaq; n int las[N], sz[N], dl[N]; n P pa[N << 3], qa[N << 3], qb[N << 3], ans[N << 3]; n void build(int x, int p) { n   for (int j = S.lnk[x]; j; j = S.nxt[j]) { n     if (S.son[j] != p) { n       T.adde(las[x], ++k, P(0, 0)); n       T.adde(k, S.son[j], S.w[j]); n       las[x] = k; n       build(S.son[j], x); n     } n   } n } n void dfs_sz(int x, int p) { n   sz[x] = 1; n   for (int j = T.lnk[x], v; j; j = T.nxt[j]) { n     if (!dl[j >> 1] && T.son[j] != p) { n       dfs_sz(T.son[j], x); n       sz[x] = sz[x] + sz[T.son[j]]; n       v = min(sz[T.son[j]], all - sz[T.son[j]]); n       if (mx < v) { n         mx = v; n         gid = j; n         gu = x, gv = T.son[j]; n       } n     } n   } n } n void dfs_calc(int x, int p, P pt) { n   pa[++cnt] = pt; n   for (int j = T.lnk[x]; j; j = T.nxt[j]) { n     if (!dl[j >> 1] && T.son[j] != p) { n       dfs_calc(T.son[j], x, pt + T.w[j]); n     } n   } n } n void making(int &num, P *pt) { n   sort(pa + 1, pa + cnt + 1); n   pt[num = 1] = pa[1]; n   for (int i = 2; i <= cnt; ++i) { n     for (; num >= 2; --num) { n       if ((pa[i] - pt[num - 1]) * (pt[num] - pt[num - 1]) > 0) { n         break; n       } n     } n     pt[++num] = pa[i]; n   } n } n void merge() { n   if (!na || !nb) { n     for (int i = 1, t = max(na, nb); i <= t; ++i) { n       ans[++qaq] = na ? qa[i] : qb[i]; n     } n     return; n   } n   ans[++qaq] = qa[1] + qb[1]; n   for (int u = 2, v = 2; u <= na || v <= nb;) { n     if (u > na) { n       ans[++qaq] = qa[u - 1] + qb[v++]; n     } else if (v > nb) { n       ans[++qaq] = qa[u++] + qb[v - 1]; n     } else { n       P du = qa[u] - qa[u - 1], dv = qb[v] - qb[v - 1]; n       if (du * dv < 0) { n         ans[++qaq] = qa[u++] + qb[v - 1]; n       } else { n         ans[++qaq] = qa[u - 1] + qb[v++]; n       } n     } n   } n } n void divide(int x, int t) { n   if (t == 1) { n     return; n   } n   all = t, mx = gu = gv = 0; n   dfs_sz(x, 0); n   int x1 = gv, s1 = sz[gv], x2 = gu, s2 = all - s1; n   dl[gid >> 1] = 1; n   cnt = 0, dfs_calc(x1, x2, P(0, 0)), making(na, qa); n   cnt = 0, dfs_calc(x2, x1, T.w[gid]), making(nb, qb); n   merge(); n   divide(x1, s1); n   divide(x2, s2); n } n long long val(P pt, int sl) { return pt.x * sl + pt.y; } n int main() { n   scanf( %d%d , &n, &m), k = n; n   for (int i = 1, x, y, z1, z2; i < n; ++i) { n     scanf( %d%d%d%d , &x, &y, &z1, &z2); n     S.adde(x, y, P(z1, z2)); n   } n   for (int i = 1; i <= n; ++i) { n     las[i] = i; n   } n   build(1, 0); n   divide(1, k); n   cnt = qaq; n   memcpy(pa, ans, sizeof pa); n   making(qaq, ans); n   for (int i = 0, cur = 1; i < m; ++i) { n     for (; cur < qaq; ++cur) { n       if (val(ans[cur], i) > val(ans[cur + 1], i)) { n         break; n       } n     } n     printf( %lld , val(ans[cur], i)); n     putchar(i < m - 1 ?     :   n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool Check(long long A, long long B, long long T1, long long T2) { n   if (!A && !B) return !T1 && !T2; n   return !((T1 * A + T2 * B) % (A * A + B * B)) && n          !((T2 * A - T1 * B) % (A * A + B * B)); n } n int main() { n   long long X0, Y0, X1, Y1, X2, Y2; n   cin >> X0 >> Y0 >> X1 >> Y1 >> X2 >> Y2; n   cout << ((Check(X2, Y2, X1 - X0, Y1 - Y0) || n             Check(X2, Y2, Y1 - X0, -X1 - Y0) || n             Check(X2, Y2, -X1 - X0, -Y1 - Y0) || n             Check(X2, Y2, -Y1 - X0, X1 - Y0)) n                ?  YES  n                :  NO ) n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   ; n   cin.tie(NULL); n   ; n   int n, b; n   double total = 0, maxx = 0; n   cin >> n >> b; n   double ar[n]; n   for (int i = 0; i < n; i++) { n     cin >> ar[i]; n     total += ar[i]; n     maxx = max(maxx, ar[i]); n   } n   if (b + total < maxx * n) { n     cout << -1 << endl; n   } else { n     double e = (b + total) / n; n     for (int i = 0; i < n; i++) { n       cout << fixed << setprecision(6) << e - ar[i] << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int l, r; n   cin >> l >> r; n   cout <<  YES  << endl; n   for (long long int i = l; i <= r; i += 2) { n     cout << i <<     << i + 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long n, m; n char s[111111], t[111111]; n bool ar[111111]; n long long fail[111111], f[111111], ff[111111], dp[111111]; n void kmp() { n   int i = 0, j = -1; n   fail[0] = -1; n   while (i < m) { n     while (j > -1 && t[i] != t[j]) j = fail[j]; n     i++, j++; n     fail[i] = j; n   } n   i = 1, j = 0; n   while (i <= n) { n     while (j > -1 && s[i] != t[j]) j = fail[j]; n     j++; n     if (j == m) ar[i] = 1, j = fail[j]; n     i++; n   } n } n int main() { n   scanf( %s , s + 1); n   scanf( %s , t); n   n = strlen(s + 1); n   m = strlen(t); n   kmp(); n   for (int i = 1; i <= n; i++) dp[i] = (ar[i] ? i - m + 1 : dp[i - 1]); n   for (int i = 1; i <= n; i++) { n     int l = dp[i]; n     if (l) { n       f[i] = (f[i - 1] + l) % mod; n       f[i] = (f[i] + ff[l - 1]) % mod; n       ff[i] = (ff[i - 1] + f[i]) % mod; n     } n   } n   cout << f[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const int dx4[] = {-1, 0, 1, 0}; n const int dy4[] = {0, 1, 0, -1}; n const int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1}; n const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1}; n const int dxk[] = {-2, -2, -1, -1, 1, 1, 2, 2}; n const int dyk[] = {-1, 1, -2, 2, -2, 2, -1, 1}; n inline long long Int() { n   long long inputNumber = 0; n   char c = getchar_unlocked(); n   bool sign = true; n   while (!((c >=  0  && c <=  9 ) || c ==  - )) c = getchar_unlocked(); n   if (c ==  - ) sign = false, c = getchar_unlocked(); n   while (c >=  0  && c <=  9 ) n     inputNumber = (inputNumber << 1) + (inputNumber << 3) + c -  0 , n     c = getchar_unlocked(); n   return sign ? inputNumber : -inputNumber; n } n template <class S, class T> n ostream& operator<<(ostream& out, const pair<S, T>& Pair) { n   out <<  {  << Pair.first <<  ,   << Pair.second <<  } ; n   return out; n } n template <class T> n ostream& operator<<(ostream& out, const vector<T>& Vector) { n   out <<  [ ; n   for (int i = 0; i < (int)Vector.size(); ++i) { n     out << Vector[i]; n     if (i + 1 < (int)Vector.size()) out <<  ,  ; n   } n   out <<  ] ; n   return out; n } n template <class S, class T> n ostream& operator<<(ostream& out, const map<S, T>& Map) { n   out <<  [ n ; n   for (const auto& x : Map) { n     out <<  { Key:   << x.first <<   , Value:   << x.second <<   } n ; n   } n   out <<  ] n ; n   return out; n } n template <class T> n ostream& operator<<(ostream& out, const multiset<T>& Set) { n   out <<  { ; n   for (auto it = Set.begin(); it != Set.end();) { n     out << *it; n     it++; n     if (it != Set.end()) out <<  ,  ; n   } n   out <<  } ; n   return out; n } n void solve(); n int main() { solve(); } n const double eps = 1e-10; n const int mod = 1e9 + 7; n const int N = 2e5 + 5; n void solve() { n   string s; n   cin >> s; n   int len = ((int)(s).size()); n   string sd =   ; n   string org =   ; n   int br = -1; n   for (int i = len - 1; i >= 0; --i) { n     if (s[i] !=  a ) { n       sd += s[i]; n     } else { n       br = i; n       break; n     } n   } n   if (sd ==   ) { n     bool ok = true; n     for (int i = 0; i < (((int)(s).size())); ++i) { n       if (s[i] !=  a ) { n         ok = false; n         break; n       } n     } n     if (ok) { n       cout << s; n     } else { n       puts( :( ); n     } n     return; n   } n   reverse((sd).begin(), (sd).end()); n   for (int i = 0; i <= br; ++i) { n     org += s[i]; n   } n   string strip =   ; n   for (int i = 0; i < (((int)(org).size())); ++i) n     if (org[i] !=  a ) strip += org[i]; n   if (strip == sd) { n     cout << org; n     return; n   } n   string tot = strip + sd; n   if (((int)(tot).size()) % 2) { n     puts( :( ); n     return; n   } n   int mid = ((int)(tot).size()) / 2; n   string a = tot.substr(0, mid); n   string b = tot.substr(mid); n   if (a != b) { n     puts( :( ); n     return; n   } n   reverse((s).begin(), (s).end()); n   reverse((a).begin(), (a).end()); n   if (s.substr(0, mid) == a) { n     reverse((s).begin(), (s).end()); n     int len = ((int)(s).size()) - mid; n     for (int i = 0; i < (len); ++i) putchar(s[i]); n     return; n   } n   puts( :( ); n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e9; n const long long inf64 = 1e18; n const long long MOD = inf + 7; n long long a[100005], p[100005]; n long long n, m; n bool check(long long mid) { n   long long last = 0; n   for (long long i = 0; i < (long long)n; i++) { n     if (last == m) return true; n     if (p[last] > a[i]) { n       while (last < m && p[last] - a[i] <= mid) last++; n       continue; n     } n     long long mn = a[i] - mid; n     if (mn > p[last]) return false; n     long long id1 = n         upper_bound(p, p + m, a[i] + mid - 2 * (a[i] - p[last])) - p; n     long long id2 = n         upper_bound(p, p + m, a[i] + (mid - (a[i] - p[last])) / 2) - p; n     last = max(last, id1); n     last = max(last, id2); n   } n   return (last == m); n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(nullptr); n   ; n   cin >> n >> m; n   for (long long i = 0; i < (long long)n; i++) cin >> a[i]; n   for (long long i = 0; i < (long long)m; i++) cin >> p[i]; n   long long ans, low = 0, high = 1e18, mid; n   while (low <= high) { n     mid = (low + high) / 2; n     if (check(mid)) { n       ans = mid; n       high = mid - 1; n     } else { n       low = mid + 1; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1007, K = 1007, INF = LONG_MAX; n int i, j, n, x, y; n int gcd(int x, int y) { n   while (x && y) { n     if (x > y) n       x %= y; n     else n       y %= x; n   } n   return x | y; n } n multiset<int> m; n vector<int> ans; n int main() { n   cin >> n; n   for (i = 0; i < n * n; i++) { n     cin >> x; n     m.insert(x); n   } n   ans.push_back(*--m.end()); n   m.erase(--m.end()); n   while (!m.empty()) { n     x = *--m.end(); n     m.erase(--m.end()); n     for (j = 0; j < ans.size(); j++) { n       int v = gcd(x, ans[j]); n       m.erase(m.find(v)); n       m.erase(m.find(v)); n     } n     ans.push_back(x); n   } n   for (i = 0; i < ans.size(); i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e7 + 5; n const int M = 25; n int A[M], B[M], n, m, x, y, cnt; n int dp[M * 4][M * 4]; n void Min(int &x, int y) { x = min(x, y); } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> A[i]; n   for (int i = 0; i < n; ++i) cin >> B[i]; n   memset(dp, 0x3f, sizeof(dp)); n   dp[0][0] = 0; n   for (int i = 0; i < n * 4; ++i) { n     for (int j = 0; j <= n + n; ++j) n       if (dp[i][j] <= 1e9) { n         Min(dp[i + 1][j + 1], dp[i][j] + A[i % n]); n         if (j) Min(dp[i + 1][j - 1], dp[i][j] + B[i % n]); n       } n   } n   if (m <= 3) n     cout << dp[n * m][0] << endl; n   else n     cout << dp[n * 4][0] + (m - 4) / 2 * (dp[n * 4][0] - dp[n * 2][0]) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 2 * acos(0.0); n const int INF = 0x3f3f3f3f; n const double inf = 1.0 / 0.0; n void solve(); n void Adi() { n   ios::sync_with_stdio(false); n   cin.tie(0); n } n int main() { n   Adi(); n   solve(); n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  n        <<   n ; n   return 0; n } n void solve() { n   long long n, x, tt = 0, dis = 0, rem = 0; n   char s; n   cin >> n >> x; n   vector<long long> v; n   for (int i = 0; i < n; i++) { n     long long q; n     cin >> s >> q; n     if (s ==  - ) q = -q; n     v.push_back(q); n   } n   for (int i = 0; i < n; i++) { n     if (v[i] >= 0) n       x += v[i]; n     else if (v[i] < 0) { n       if (x >= abs(v[i])) n         x += v[i]; n       else n         dis++; n     } n   } n   cout << x <<     << dis; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, z, t1, t2, t3; n   cin >> x >> y >> z >> t1 >> t2 >> t3; n   unsigned long long xy, xz; n   if (x > y) { n     xy = x - y; n   } else { n     xy = y - x; n   } n   if (x > z) { n     xz = x - z; n   } else { n     xz = z - x; n   } n   unsigned long long stair = xy * t1; n   unsigned long long lift = (xz + xy) * t2 + t3 * 3; n   if (lift > stair) { n     cout <<  NO ; n   } else { n     cout <<  YES ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int mat[1010][1010]; n int counts = 0; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) scanf( %d , &mat[i][j]); n   } n   counts = 0; n   for (int i = 1; i <= n; i++) counts += mat[i][i]; n   counts %= 2; n   int m; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     int a; n     scanf( %d , &a); n     if (a == 1 || a == 2) { n       int b; n       scanf( %d , &b); n       mat[b][b] = 1 - mat[b][b]; n       counts = 1 - counts; n     } else n       printf( %d , counts); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 20; n int x[maxn], y[maxn]; n int main() { n   int n, m; n   while (cin >> n >> m) { n     for (int i = 1; i <= n; i++) scanf( %d , &x[i]); n     for (int j = 1; j <= m; j++) scanf( %d , &y[j]); n     int ans = 0; n     int p1 = 1, p2 = 1; n     long long sum1 = 0, sum2 = 0; n     while (p1 <= n || p2 <= m) { n       if (sum1 <= sum2) { n         if (p1 > n) break; n         sum1 += x[p1++]; n       } else { n         if (p2 > m) break; n         sum2 += y[p2++]; n       } n       if (sum1 == sum2) ans++; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int w, h, k; n   cin >> w >> h >> k; n   int s = 0; n   w -= 2; n   for (int i = 0; i < k; i++) { n     s += (w + h) * 2; n     w -= 4; n     h -= 4; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n long long w[100005], mon[305], droz[305], wlazi[305], t; n long long dfs(long long co) { n   long long x; n   if (!droz[co]) return mon[co]; n   x = dfs(droz[co]); n   t -= x; n   mon[co] += x; n   return mon[co]; n } n int main() { n   long long n, q, a, b, c, mod = 1000000007; n   scanf( %I64d%I64d%I64d , &n, &q, &t); n   for (a = 1; a <= n; a++) scanf( %I64d , &mon[a]); n   while (q--) { n     scanf( %I64d%I64d , &a, &b); n     droz[b] = a; n     wlazi[a] = 1; n   } n   for (a = 1; a <= n; a++) { n     for (b = droz[a]; b && b != a; b = droz[b]) n       ; n     if (b == a) { n       printf( 0 n ); n       return 0; n     } n   } n   for (a = 1; a <= n; a++) n     if (!wlazi[a]) dfs(a); n   if (t < 0) { n     printf( 0 n ); n     return 0; n   } n   w[0] = 1; n   for (a = 1; a <= n; a++) { n     for (b = mon[a]; b <= t; b++) { n       w[b] += w[b - mon[a]]; n       w[b] %= mod; n     } n   } n   printf( %I64d n , w[t]); n   getchar(); n   getchar(); n   return 0; n } n


#include <bits/stdc++.h> n const bool DEBUG = false; n using namespace std; n const long long maxn = 2e5 + 5; n const long long INF = 1e18 + 1; n const long long M = 1e9 + 7; n const int lg = 21; n int n, m, x[maxn], b[maxn], a[maxn], y[maxn]; n vector<pair<int, int> > v; n set<int> s; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; n   for (int i = 0; i < m; i++) cin >> a[i] >> b[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[j] == b[j] or x[i] == y[i]) continue; n       if (a[j] == x[i] and b[j] == y[i]) continue; n       if (a[j] == y[i] and b[j] == x[i]) continue; n       if (a[j] != x[i] and a[j] != y[i] and b[j] != x[i] and b[j] != y[i]) n         continue; n       if (a[j] == x[i] or a[j] == y[i]) n         s.insert(a[j]); n       else n         s.insert(b[j]); n     } n   } n   if (s.size() == 1) return cout << (*s.begin()) << endl, 0; n   for (int i = 0; i < n; i++) { n     vector<int> v; n     set<int> s; n     for (int j = 0; j < m; j++) { n       if (a[j] == b[j] or x[i] == y[i]) continue; n       if (a[j] == x[i] and b[j] == y[i]) continue; n       if (a[j] == y[i] and b[j] == x[i]) continue; n       if (a[j] != x[i] and a[j] != y[i] and b[j] != x[i] and b[j] != y[i]) n         continue; n       if (x[i] == a[j] or x[i] == b[j]) n         s.insert(x[i]); n       else n         s.insert(y[i]); n     } n     if (s.size() > 1) return cout << -1 << endl, 0; n   } n   for (int i = 0; i < m; i++) { n     vector<int> v; n     set<int> s; n     for (int j = 0; j < n; j++) { n       if (a[i] == b[i] or x[j] == y[j]) continue; n       if (a[i] == x[j] and b[i] == y[j]) continue; n       if (a[i] == y[j] and b[i] == x[j]) continue; n       if (a[i] != x[j] and a[i] != y[j] and b[i] != x[j] and b[i] != y[j]) n         continue; n       if (x[j] == a[i] or a[i] == y[j]) n         s.insert(a[i]); n       else n         s.insert(b[i]); n     } n     if (s.size() > 1) return cout << -1 << endl, 0; n   } n   cout << 0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int list[100000]; n   for (int i = 0; i < n; i++) { n     cin >> list[i]; n   } n   int max = 1; n   int temp = 1; n   for (int i = 0; i < n - 1; i++) { n     if (list[i] < list[i + 1]) { n       temp++; n     } else { n       if (max < temp) { n         max = temp; n       } n       temp = 1; n     } n   } n   if (max < temp) { n     max = temp; n   } n   cout << max <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long T, A, B, res; n vector<long long> P; n int main() { n   cin >> T >> A >> B; n   if (T == 1) { n     if (A == 1) { n       if (B == 1) { n         res = -1; n       } n     } else { n       if (B % A == 0) { n         ++res; n       } n       while (B > 0) { n         P.push_back(B % A); n         B /= A; n       } n       long long cp = 1; n       for (int i = 0; i < ((int)P.size()); i++) { n         A -= P[i] * cp; n         cp *= T; n       } n       if (A == 0) { n         ++res; n       } n     } n   } else { n     if (A < T) { n       if (B == A) { n         res = 1; n       } n     } else if (A == T) { n       if (B == A) { n         res = 2; n       } n     } else { n       if (A == B) { n         ++res; n       } n       while (B > 0) { n         P.push_back(B % A); n         B /= A; n       } n       long long cp = 1; n       for (int i = 0; i < ((int)P.size()); i++) { n         A -= P[i] * cp; n         cp *= T; n       } n       if (A == 0) { n         ++res; n       } n     } n   } n   if (res == -1) { n     cout <<  inf n ; n   } else { n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000 * 1000 * 1000 + 7; n const int N = 1000 * 1000 + 7; n long long a[N]; n multiset<long long> st; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) scanf( %I64d , a + i); n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     if (st.size() > 0) { n       if (*st.begin() < a[i]) { n         ans += a[i] - *st.begin(); n         st.erase(st.begin()); n         st.insert(a[i]); n       } n     } n     st.insert(a[i]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[200010], cnt, id, k[200010]; n double ans = -1, pre[200010]; n double f(long long x, long long mid) { n   return ((pre[n] - pre[n - x]) + (pre[mid] - pre[mid - x - 1])) / (x * 2 + 1); n } n signed main() { n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   sort(a + 1, a + 1 + n); n   for (long long i = 1; i <= n; i++) { n     pre[i] = pre[i - 1] + a[i]; n   } n   for (long long i = 1; i <= n; i++) { n     long long l = 1, r = min(i - 1, n - i); n     long long num = 0; n     while (l <= r) { n       long long mid = (l + r) / 2; n       if (f(mid, i) >= f(mid - 1, i)) n         l = mid + 1, num = mid; n       else n         r = mid - 1; n     } n     if (f(num, i) - (pre[i] - pre[i - 1]) > ans) { n       ans = f(num, i) - (pre[i] - pre[i - 1]); n       cnt = num, id = i; n     } n   } n   printf( %lld n , 2 * cnt + 1); n   for (long long i = id - cnt; i <= id; i++) printf( %lld  , a[i]); n   for (long long i = n - cnt + 1; i <= n; i++) printf( %lld  , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n const int MAX = 1e5; n const long long MOD = 1e9 + 7; n const long long inf = 1e18; n int a[MAX + 5]; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m, r, i, j; n   long long ans = 0; n   cin >> n >> m; n   a[0] = 1; n   for ((i) = (1); (i) <= (m); ++i) cin >> a[i]; n   i = 0; n   while (i < m) { n     if (a[i + 1] > a[i]) n       ans += (a[i + 1] - a[i]); n     else if (a[i + 1] < a[i]) n       ans += (n - a[i] + a[i + 1]); n     i++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e5 + 10; n class Edge { n  public: n   long long dest, weight, cost; n   Edge() { n     dest = 0; n     weight = 0; n     cost = 0; n   } n }; n class Compare { n  public: n   bool operator()(pair<long long, long long>& a, n                   pair<long long, long long>& b) { n     long long cura = a.first * a.second; n     long long curb = b.first * b.second; n     long long futa = (a.first / 2) * a.second; n     long long futb = (b.first / 2) * b.second; n     return (cura - futa) < (curb - futb); n   } n }; n vector<Edge> adj[MAXN]; n long long numLeaves[MAXN], par[MAXN]; n bool visited[MAXN]; n void dfs(long long cur) { n   visited[cur] = true; n   if (adj[cur].size() == 1 && visited[adj[cur][0].dest]) { n     numLeaves[cur] = 1; n     return; n   } n   numLeaves[cur] = 0; n   for (auto i : adj[cur]) { n     if (!visited[i.dest]) { n       par[i.dest] = cur; n       dfs(i.dest); n       numLeaves[cur] += numLeaves[i.dest]; n     } n   } n } n void solve() { n   long long n, s; n   cin >> n >> s; n   for (long long i = 0; i < n + 1; i++) { n     adj[i].clear(); n     numLeaves[i] = 0; n     par[i] = -1; n     visited[i] = false; n   } n   for (long long i = 1; i < n; i++) { n     long long x, y, w, c; n     cin >> x >> y >> w >> c; n     x--, y--; n     Edge cur; n     cur.dest = y; n     cur.weight = w; n     cur.cost = c; n     adj[x].push_back(cur); n     cur.dest = x; n     adj[y].push_back(cur); n   } n   dfs(0); n   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, n                  Compare> n       oneCost, twoCost; n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     for (auto j : adj[i]) { n       if (par[j.dest] == i) { n         sum += (numLeaves[j.dest]) * (j.weight); n         if (j.cost == 1) n           oneCost.push(make_pair(j.weight, numLeaves[j.dest])); n         else n           twoCost.push(make_pair(j.weight, numLeaves[j.dest])); n       } n     } n   } n   vector<long long> oneDif, twoDif; n   while (!oneCost.empty()) { n     pair<long long, long long> cur = oneCost.top(); n     oneCost.pop(); n     long long fut = (cur.first / 2) * (cur.second); n     long long dif = (cur.first) * (cur.second) - fut; n     oneDif.push_back(dif); n     cur.first /= 2; n     if (cur.first != 0) oneCost.push(cur); n   } n   while (!twoCost.empty()) { n     pair<long long, long long> cur = twoCost.top(); n     twoCost.pop(); n     long long fut = (cur.first / 2) * (cur.second); n     long long dif = (cur.first) * (cur.second) - fut; n     twoDif.push_back(dif); n     cur.first /= 2; n     if (cur.first != 0) twoCost.push(cur); n   } n   long long cost = LLONG_MAX; n   for (long long i = 1; i < oneDif.size(); i++) oneDif[i] += oneDif[i - 1]; n   for (long long i = 1; i < twoDif.size(); i++) twoDif[i] += twoDif[i - 1]; n   if (sum <= s) cost = 0; n   long long l = 0, h = twoDif.size() - 1; n   long long ans = -1; n   while (l <= h) { n     long long mid = (l + h) / 2; n     if (sum - twoDif[mid] <= s) { n       ans = mid; n       h = mid - 1; n     } else n       l = mid + 1; n   } n   if (ans != -1) { n     cost = min(cost, 2 * (ans + 1)); n   } n   for (long long i = 0; i < oneDif.size(); i++) { n     long long l = 0, h = twoDif.size() - 1; n     long long cur = sum - oneDif[i]; n     if (cur <= s) { n       cost = min(cost, i + 1); n       break; n     } n     long long ans = -1; n     while (l <= h) { n       long long mid = (l + h) / 2; n       if (cur - twoDif[mid] <= s) { n         ans = mid; n         h = mid - 1; n       } else n         l = mid + 1; n     } n     if (ans != -1) { n       long long temp = (i + 1) + (ans + 1) * 2; n       cost = min(temp, cost); n     } n   } n   cout << cost <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, mx, now, ans; n int main() { n   scanf( %lld , &n); n   mx = 2 * n - 1; n   while (now * 10 + 9 <= mx) now = now * 10 + 9; n   for (long long k = now; k <= mx; k += now + 1) { n     long long d = max(k - n, 1ll), u = max(k - d, d); n     ans += (u - d + 1) / 2; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n const long long mo = 1e9 + 7; n int n, m, k, nn; n template <typename T> n inline void read(T &X) { n   X = 0; n   int w = 0; n   char ch = 0; n   while (!isdigit(ch)) { n     w |= ch ==  - ; n     ch = getchar(); n   } n   while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); n   if (w) X = -X; n } n vector<pair<int, int>> vc[3], vv[3], ys[maxn * 5]; n int sum[(maxn * 5) << 2], fg[(maxn * 5) << 2]; n void build(int rt, int l, int r, int v) { n   sum[rt] = fg[rt] = v; n   if (l == r) { n     return; n   } n   int mid = (l + r) >> 1; n   build((rt << 1), l, mid, v); n   build((rt << 1 | 1), mid + 1, r, v); n } n void pu(int rt) { sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; } n void pd(int rt) { n   if (fg[rt]) { n     sum[(rt << 1)] += fg[rt]; n     sum[(rt << 1 | 1)] += fg[rt]; n     fg[(rt << 1)] += fg[rt]; n     fg[(rt << 1 | 1)] += fg[rt]; n     fg[rt] = 0; n   } n } n void pdd(int rt) { n   if (fg[rt]) { n     sum[(rt << 1)] = sum[rt]; n     sum[(rt << 1 | 1)] = sum[rt]; n     fg[(rt << 1)] = fg[(rt << 1 | 1)] = 1; n     fg[rt] = 0; n   } n } n void update(int rt, int l, int r, int ql, int qr, int v) { n   if (ql <= l && r <= qr) { n     sum[rt] = v; n     fg[rt] = 1; n     return; n   } n   pdd(rt); n   int mid = (l + r) >> 1; n   if (ql <= mid) update((rt << 1), l, mid, ql, qr, v); n   if (qr > mid) update((rt << 1 | 1), mid + 1, r, ql, qr, v); n } n void add(int rt, int l, int r, int p, int v) { n   if (p <= l && r <= p) { n     sum[rt] += v; n     fg[rt] += v; n     return; n   } n   pd(rt); n   int mid = (l + r) >> 1; n   if (p <= mid) add((rt << 1), l, mid, p, v); n   if (p > mid) add((rt << 1 | 1), mid + 1, r, p, v); n   pu(rt); n } n int query1(int rt, int l, int r, int q) { n   if (q <= l && r <= q) { n     return sum[rt]; n   } n   pdd(rt); n   int mid = (l + r) >> 1; n   if (q <= mid) return query1((rt << 1), l, mid, q); n   if (q > mid) return query1((rt << 1 | 1), mid + 1, r, q); n } n long long query2(int rt, int l, int r, int ql, int qr) { n   if (ql <= l && r <= qr) { n     return sum[rt]; n   } n   pd(rt); n   int mid = (l + r) >> 1; n   long long ans = 0; n   if (ql <= mid) ans = query2((rt << 1), l, mid, ql, qr); n   if (qr > mid) ans += query2((rt << 1 | 1), mid + 1, r, ql, qr); n   return ans; n } n void solve() { n   nn = 1000000; n   read(n); n   read(m); n   for (int i = (1); i <= (n); i++) { n     int y, lx, rx; n     read(y); n     read(lx); n     read(rx); n     if (lx == 0) n       vc[0].push_back({rx, y}); n     else n       vc[1].push_back({lx, y}); n   } n   for (int i = (1); i <= (m); i++) { n     int x, ly, ry; n     read(x); n     read(ly); n     read(ry); n     if (ly == 0) n       vv[0].push_back({x, ry}); n     else n       vv[1].push_back({x, ly}); n   } n   for (int i = (0); i <= (1); i++) { n     if (!vc[i].empty()) sort(vc[i].begin(), vc[i].end()); n     if (!vv[i].empty()) sort(vv[i].begin(), vv[i].end()); n   } n   reverse(vc[1].begin(), vc[1].end()); n   int sz0 = vv[0].size() - 1; n   int sz1 = vv[1].size() - 1; n   build(1, 0, nn, 0); n   for (auto i : vc[1]) { n     int fg = 1; n     while (fg) { n       fg = 0; n       if (sz1 >= 0 && sz0 >= 0 && vv[0][sz0].first < vv[1][sz1].first && n           vv[1][sz1].first >= i.first) { n         update(1, 0, nn, vv[1][sz1].second, nn, vv[1][sz1].first); n         sz1--; n         fg = 1; n       } else if (sz0 < 0 && sz1 >= 0 && vv[1][sz1].first >= i.first) { n         update(1, 0, nn, vv[1][sz1].second, nn, vv[1][sz1].first); n         sz1--; n         fg = 1; n       } else if (sz1 >= 0 && sz0 >= 0 && vv[0][sz0].first > vv[1][sz1].first && n                  vv[0][sz0].first >= i.first) { n         update(1, 0, nn, 0, vv[0][sz0].second, vv[0][sz0].first); n         sz0--; n         fg = 1; n       } else if (sz1 < 0 && sz0 >= 0 && vv[0][sz0].first >= i.first) { n         update(1, 0, nn, 0, vv[0][sz0].second, vv[0][sz0].first); n         sz0--; n         fg = 1; n       } n     } n     int pos = query1(1, 0, nn, i.second); n     ys[pos].push_back(i); n   } n   build(1, 0, nn, 0); n   int j = 0, k = 0; n   vv[0].push_back({nn, nn}); n   int nj = vv[0].size(), nk = vv[1].size(); n   for (auto i : vc[0]) { n     add(1, 0, nn, i.second, 1); n   } n   int i = 0, ni = vc[0].size(); n   long long ans = 0; n   while (j < nj || k < nk) { n     pair<int, int> p; n     if (j == nj) n       p = vv[1][k++]; n     else if (k == nk) n       p = vv[0][j++]; n     else if (vv[0][j].first < vv[1][k].first) n       p = vv[0][j++]; n     else n       p = vv[1][k++]; n     while (i < ni && vc[0][i].first < p.first) { n       add(1, 0, nn, vc[0][i].second, -1); n       i++; n     } n     if (k && p == vv[1][k - 1]) n       ans += query2(1, 0, nn, p.second, nn); n     else n       ans += query2(1, 0, nn, 0, p.second); n     if (p.second == nn) ans++; n     for (auto s : ys[p.first]) add(1, 0, nn, s.second, 1); n   } n   printf( %lld n , ans); n } n int main() { n   int T = 1, cas = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n ostream &operator<<(ostream &os, pair<T1, T2> &p); n template <class T> n ostream &operator<<(ostream &os, vector<T> &v); n template <class T> n ostream &operator<<(ostream &os, set<T> &v); n template <class T1, class T2> n ostream &operator<<(ostream &os, map<T1, T2> &v); n const long long mod = 100000007; n const int N = 15; n int n, k; n bool check(vector<int> &a, int x) { n   bool flag = true; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     if (v.size() == k) break; n     if ((int)v.size() % 2) { n       v.push_back(a[i]); n     } else if (a[i] <= x) { n       v.push_back(a[i]); n     } n   } n   if (v.size() == k) { n     return true; n   } n   v.clear(); n   for (int i = 0; i < n; i++) { n     if (v.size() == k) break; n     if ((int)v.size() % 2 == 0) { n       v.push_back(a[i]); n     } else if (a[i] <= x) { n       v.push_back(a[i]); n     } n   } n   if (v.size() == k) { n     return true; n   } n   return false; n } n void TEST_CASES(int cas) { n   scanf( %d %d , &n, &k); n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   int low = *min_element(a.begin(), a.end()), n       high = *max_element(a.begin(), a.end()); n   int ans = -1; n   while (low <= high) { n     int mid = (low + high) / 2; n     ; n     ; n     if (check(a, mid)) { n       high = mid - 1; n       ans = mid; n     } else { n       low = mid + 1; n     } n   } n   printf( %d n , ans); n } n int main() { n   int t = 1, cas = 0; n   while (t--) { n     TEST_CASES(++cas); n   } n   return 0; n } n template <class T1, class T2> n ostream &operator<<(ostream &os, pair<T1, T2> &p) { n   os <<  {  << p.first <<  ,   << p.second <<  }  ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, vector<T> &v) { n   os <<  [  ; n   for (int i = 0; i < v.size(); i++) { n     os << v[i] <<    ; n   } n   os <<   ] ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, set<T> &v) { n   os <<  [  ; n   for (T i : v) { n     os << i <<    ; n   } n   os <<   ] ; n   return os; n } n template <class T1, class T2> n ostream &operator<<(ostream &os, map<T1, T2> &v) { n   for (auto i : v) { n     os <<  Key :   << i.first <<   , Value :   << i.second << endl; n   } n   return os; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int num[maxn]; n long long ret; n int n; n void init() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &num[i]); n } n void print() { n   for (int i = 1; i < n; i++) { n     int j = 0; n     for (; j < 30; j++) n       if (i + (1 << j) > n) break; n     j--; n     ret += num[i]; n     num[i + (1 << j)] += num[i]; n     printf( %I64d n , ret); n   } n } n int main() { n   init(); n   print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, cont = 0, z = 0, x, n; n   int a[] = {1, 3, 6}; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> n; n     x = n; n     while (x > 0) { n       x = x / 10; n       z++; n     } n     if (z == 4) { n       for (int k = 1; k <= 9; k++) { n         if (n % 10 == k) { n           cout << k * 10 << endl; n         } n       } n     } else { n       for (int j = 0; j < 3; j++) { n         if (z == (j + 1)) { n           cont += a[j]; n         } n       } n       for (int l = 1; l <= 9; l++) { n         if (n % 10 == l) { n           cout << ((l - 1) * 10) + cont << endl; n         } n       } n     } n     cont = 0; n     z = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int T = 1; n   cin >> T; n   while (T--) { n     int64_t w, h; n     cin >> w >> h; n     vector<int64_t> hor1, hor2, ver1, ver2; n     int64_t k; n     int64_t q; n     cin >> k; n     for (int i = 0; i < k; ++i) cin >> q, hor1.push_back(q); n     cin >> k; n     for (int i = 0; i < k; ++i) cin >> q, hor2.push_back(q); n     cin >> k; n     for (int i = 0; i < k; ++i) cin >> q, ver1.push_back(q); n     cin >> k; n     for (int i = 0; i < k; ++i) cin >> q, ver2.push_back(q); n     cout << max({(hor1.back() - hor1[0]) * h, (hor2.back() - hor2[0]) * h, n                  (ver1.back() - ver1[0]) * w, (ver2.back() - ver2[0]) * w}) n          <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   long long i; n   cin >> n >> m; n   long long cnt = 0; n   for (i = 1; i <= n; i++) { n     cnt += (m + i) / 5 - i / 5; n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, size_t N> n long long SIZE(const T (&t)[N]) { n   return N; n } n template <typename T> n long long SIZE(const T &t) { n   return t.size(); n } n string to_string(const string s, long long x1 = 0, long long x2 = 1e9) { n   return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ; n } n string to_string(const char *s) { return to_string((string)s); } n string to_string(const bool b) { return (b ?  true  :  false ); } n string to_string(const char c) { return string({c}); } n template <size_t N> n string to_string(const bitset<N> &b, long long x1 = 0, long long x2 = 1e9) { n   string t =   ; n   for (long long __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); n        __iii__ <= __jjj__; ++__iii__) { n     t += b[__iii__] +  0 ; n   } n   return     + t +    ; n } n template <typename A, typename... C> n string to_string(const A(&v), long long x1 = 0, long long x2 = 1e9, n                  C... coords); n long long l_v_l_v_l = 0, t_a_b_s = 0; n template <typename A, typename B> n string to_string(const pair<A, B> &p) { n   l_v_l_v_l++; n   string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n   l_v_l_v_l--; n   return res; n } n template <typename A, typename... C> n string to_string(const A(&v), long long x1, long long x2, C... coords) { n   long long rnk = rank<A>::value; n   string tab(t_a_b_s,    ); n   string res =   ; n   bool first = true; n   if (l_v_l_v_l == 0) res +=   n ; n   res += tab +  [ ; n   x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); n   auto l = begin(v); n   advance(l, x1); n   auto r = l; n   advance(r, (x2 - x1) + (x2 < SIZE(v))); n   for (auto e = l; e != r; e = next(e)) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     l_v_l_v_l++; n     if (e != l) { n       if (rnk > 1) { n         res +=   n ; n         t_a_b_s = l_v_l_v_l; n       }; n     } else { n       t_a_b_s = 0; n     } n     res += to_string(*e, coords...); n     l_v_l_v_l--; n   } n   res +=  ] ; n   if (l_v_l_v_l == 0) res +=   n ; n   return res; n } n void dbgm() { ; } n template <typename Heads, typename... Tails> n void dbgm(Heads H, Tails... T) { n   cerr << to_string(H) <<   |  ; n   dbgm(T...); n } n void FIO() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const long long N = 2e5 + 6; n int32_t main() { n   FIO(); n   long long tc; n   cin >> tc; n   while (tc--) { n     long long x, y; n     cin >> x >> y; n     long long n = x; n     if (x == y) n       n = x; n     else if (x > y) { n       n = x * y + y; n     } else { n       long long r = y % x; n       n = y - r / 2; n     } n     assert(n <= (long long)2e18 and (n % x == y % n)); n     cout << n <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n int k[1000010]; n long long qpow(long long x, int n) { n   long long ans = 1; n   for (; n; n >>= 1, x = x * x % mod) n     if (n & 1) ans = ans * x % mod; n   return ans; n } n long long lpow(long long x, int n) { n   long long ans = 1; n   for (; n; n >>= 1, x *= x) { n     if (n && x > mod) return mod; n     if (n & 1) ans *= x; n     if (ans > mod) return mod; n   } n   return ans; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n, p; n     scanf( %d%d , &n, &p); n     for (int i = 0; i < n; i++) scanf( %d , &k[i]); n     sort(k, k + n); n     long long d = 0; n     long long sl = 0, sr = 0, q = k[n - 1]; n     for (int i = n - 1; i >= 0; i--) { n       if (q > k[i]) { n         sl = sl * qpow(p, q - k[i]) % mod; n         sr = sr * qpow(p, q - k[i]) % mod; n         d = min(d * lpow(p, q - k[i]), mod); n         q = k[i]; n       } n       if (d) n         d--, sr++; n       else n         d++, sl++; n     } n     sl = sl * qpow(p, q) % mod; n     sr = sr * qpow(p, q) % mod; n     printf( %lld n , (sl - sr + mod) % mod); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int UNDEF = -1; n const long long INF = 1e18; n template <typename T> n inline bool chkmax(T &aa, T bb) { n   return aa < bb ? aa = bb, true : false; n } n template <typename T> n inline bool chkmin(T &aa, T bb) { n   return aa > bb ? aa = bb, true : false; n } n int rint(); n char rch(); n long long rlong(); n const int mv = 160; n const int mc = ((mv * (mv - 1)) / 2) + 1; n const int ma = 31; n bitset<mc> f[mv][ma]; n void reset() { n   for (int v = 0; v < mv; v++) n     for (int ai = 0; ai < ma; ai++) f[v][ai].reset(); n } n vector<int> solve(vector<int> &a) { n   vector<int> fail; n   sort(a.begin(), a.end()); n   int alim = a.size(); n   f[0][0][a[0]] = true; n   { n     int v = 0; n     int klim = (v * (v + 1)) / 2; n     if (f[(v)][alim - 1][klim]) { n       return vector<int>({a[0]}); n     } n   } n   for (int v = 1; v < mv; v++) { n     for (int sai = 0; sai < alim; sai++) { n       for (int dai = sai; dai <= min(alim - 1, sai + 1); dai++) { n         int shift = a[dai]; n         f[(v)][dai] |= (f[(v)-1][sai] << shift); n       } n     } n     int klim = (v * (v + 1)) / 2; n     if (f[(v)][alim - 1][klim]) { n       vector<int> final; n       int ai = alim - 1; n       int k = klim; n       for (int x = v; x >= 1; x--) { n         final.push_back(a[ai]); n         k -= a[ai]; n         if (f[x - 1][ai][k]) { n           ai = ai; n         } else { n           ai--; n         } n       } n       final.push_back(a[0]); n       sort(final.begin(), final.end()); n       return final; n     } n     bitset<mc> filt; n     filt.set(); n     filt >>= klim; n     filt <<= klim; n     for (int ai = 0; ai < alim; ai++) { n       f[(v)][ai] &= filt; n     } n   } n   return fail; n } n bool vans[mv + 2][mv + 2]; n void recurse(vector<int> &r) { n   int n = r.size() - 1; n   if (n == 0) return; n   vector<int> R; n   R.push_back(-1); n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     sum += r[i]; n     R.push_back(sum); n   } n   int s = n - 1 - r[n]; n   vector<int> F; n   F.resize(n + 1); n   for (int v = 1; v <= n; v++) F[v] = R[v] - (v * (v - 1)) / 2; n   int j = 1; n   vector<int> rp = r; n   for (int x = 1; x <= n; x++) vans[n][x] = 1; n   vans[n][n] = 0; n   vector<int> vj; n   vj.resize(s + 1); n   for (int d = 1; d <= s; d++) { n     int vmin = max(1, vj[d - 1] + 1); n     int ans = vmin; n     for (int v = n - 1; v >= vmin; v--) { n       if (F[v] < d) { n         ans = v + 1; n         break; n       } n     } n     vj[d] = ans; n   } n   for (int d = 1; d <= s; d++) { n     int j = vj[d]; n     assert(j <= n - 1); n     vans[n][j] = 0; n     vans[j][n] = 1; n     rp[j]--; n   } n   rp.resize(rp.size() - 1); n   recurse(rp); n } n vector<int> fgot; n int comb(vector<int> &va) { n   auto got = solve(va); n   fgot = got; n   if (got.size() == 0) { n     printf( =( n ); n     return 0; n   } else { n     vector<int> r; n     r.push_back(-1); n     for (auto &w : got) r.push_back(w); n     recurse(r); n     int sz = got.size(); n     printf( %d n , sz); n     for (int x = 1; x <= sz; x++) { n       for (int y = 1; y <= sz; y++) { n         printf( %d , (int)vans[x][y]); n       } n       printf(  n ); n     } n     return sz; n   } n } n void test() { n   reset(); n   memset(vans, 0, sizeof vans); n   vector<int> va; n   int p = (rand() % 100); n   for (int x = 0; x <= 30; x++) { n     if (rand() % 100 <= p) va.push_back(x); n   } n   if (va.size() == 0) va.push_back(rand() % 31); n   int got = comb(va); n   if (got != 0) { n     set<int> s; n     for (int x = 1; x <= got; x++) { n       assert(vans[x][x] == 0); n       int degout = 0; n       for (int y = 1; y <= got; y++) { n         degout += vans[x][y]; n       } n       s.insert(degout); n     } n     for (int x = 1; x <= got; x++) { n       for (int y = 1; y <= got; y++) { n         if (x == y) continue; n         assert(vans[x][y] + vans[y][x] == 1); n       } n     } n     set<int> sa; n     for (auto &w : va) sa.insert(w); n     if (s != sa) { n       for (auto &w : sa) printf( %d  , w); n       printf(  sa n ); n       for (auto &w : s) printf( %d  , w); n       printf(  s n ); n       for (auto &w : fgot) printf( %d  , w); n       printf(  fgot n ); n       exit(1); n     } n   } n } n void go() { n   for (int k = 0; k < 100000; k++) { n     srand(clock()); n     test(); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n = rint(); n   vector<int> va; n   va.reserve(n); n   for (int i = 0; i < n; i++) { n     int x = rint(); n     va.push_back(x); n   } n   comb(va); n } n static char stdinBuffer[1024]; n static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer); n static const char *stdinPos = stdinDataEnd; n void readAhead(size_t amount) { n   size_t remaining = stdinDataEnd - stdinPos; n   if (remaining < amount) { n     memmove(stdinBuffer, stdinPos, remaining); n     size_t sz = fread(stdinBuffer + remaining, 1, n                       sizeof(stdinBuffer) - remaining, stdin); n     stdinPos = stdinBuffer; n     stdinDataEnd = stdinBuffer + remaining + sz; n     if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0; n   } n } n int rint() { n   readAhead(16); n   int x = 0; n   bool neg = false; n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   if (*stdinPos ==  - ) { n     ++stdinPos; n     neg = true; n   } n   while (*stdinPos >=  0  && *stdinPos <=  9 ) { n     x *= 10; n     x += *stdinPos -  0 ; n     ++stdinPos; n   } n   return neg ? -x : x; n } n char rch() { n   readAhead(16); n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   char ans = *stdinPos; n   ++stdinPos; n   return ans; n } n long long rlong() { n   readAhead(32); n   long long x = 0; n   bool neg = false; n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   if (*stdinPos ==  - ) { n     ++stdinPos; n     neg = true; n   } n   while (*stdinPos >=  0  && *stdinPos <=  9 ) { n     x *= 10; n     x += *stdinPos -  0 ; n     ++stdinPos; n   } n   return neg ? -x : x; n } n


#include <bits/stdc++.h> n using namespace std; n bool ps[1111111]; n const int mod = 1e9 + 7; n int main() { n   int p, k, c = 0; n   long long ans = 1; n   scanf( %d%d , &p, &k); n   for (int i = 0; i < p; ++i) { n     if (ps[i]) continue; n     c++; n     long long b = i; n     while (!ps[b]) ps[b] = 1, b = (b * k) % p; n   } n   if (k != 1) c--; n   while (c--) ans = (ans * p) % mod; n   printf( %d n , int(ans)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   if (m == 3 && (n == 5 || n == 6)) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 0; i < m; ++i) printf( %d %d n , i, i * i + 10000000); n   for (int i = 0; i < n - m; ++i) printf( %d %d n , i, -i * i - 10000000); n   return 0; n } n