#include <bits/stdc++.h> n using namespace std; n class data { n  public: n   long long k, b; n   bool operator<(const data a) const { n     if (k * a.k < 0) n       return (b * a.k < a.b * k); n     else n       return (b * a.k > a.b * k); n   } n   bool operator==(const data a) const { return b * a.k == a.b * k; } n } d[100010]; n long long n, tot = 0; n int main() { n   long long x, y, cnt = 0; n   scanf( %I64d , &n); n   for (long long i = 1; i <= n; ++i) { n     ++tot; n     scanf( %I64d%I64d , &d[tot].k, &d[tot].b); n     if (d[tot].k == 0) { n       --tot; n       continue; n     } n   } n   n = tot; n   sort(d + 1, d + tot + 1); n   long long nowk = 0; n   for (long long i = 1; i <= n; ++i) n     if ((d[i - 1] == d[i]) && (i > 1)) { n       nowk += abs(d[i].k); n     } else { n       if (nowk > 0) cnt++; n       nowk = abs(d[i].k); n     } n   if (nowk) cnt++; n   printf( %I64d n , cnt); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T qmin(const T &a, const T &b) { n   return a < b ? a : b; n } n template <typename T> n inline T qmax(const T &a, const T &b) { n   return a > b ? a : b; n } n template <typename T> n inline void getmin(T &a, const T &b) { n   if (a > b) a = b; n } n template <typename T> n inline void getmax(T &a, const T &b) { n   if (a < b) a = b; n } n inline void fileio(string s) { n   freopen((s +  .in ).c_str(),  r , stdin); n   freopen((s +  .out ).c_str(),  w , stdout); n } n const int inf = 1e9 + 7; n const int N = 51, M = 2953; n const int go[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n char g[N][N]; n int tp[N][N]; n map<int, int> id; n int mask[M], cnt; n int dis[N][N][M]; n bool vis[N][N][M], can[N][N][M]; n int ans[N][N][M]; n vector<pair<pair<int, int>, int> > to[N][N][M]; n int n, m, k, sti, stj, edi, edj; n inline void bfs() { n   static queue<pair<pair<int, int>, int> > q; n   static int st, ed; n   dis[sti][stj][1] = 1; n   q.push(make_pair(make_pair(sti, stj), 1)); n   while (!q.empty()) { n     pair<pair<int, int>, int> p = q.front(); n     q.pop(); n     int i = p.first.first, j = p.first.second, comb = mask[p.second]; n     if (dis[i][j][p.second] == dis[edi][edj][1]) break; n     comb |= (~tp[i][j] ? 1 << tp[i][j] : 0); n     for (register int d = 0; d < (4); ++d) { n       int ni = i + go[d][0], nj = j + go[d][1]; n       if (ni < 1 || ni > n || nj < 1 || nj > m || (ni == sti && nj == stj)) n         continue; n       int ncomb = comb; n       if (~tp[ni][nj]) { n         ncomb &= ~(1 << tp[ni][nj]); n         if (__builtin_popcount(ncomb) >= k) continue; n       } else { n         ncomb = 0; n       } n       int cid = id[ncomb]; n       if (dis[ni][nj][cid]) { n         if (dis[ni][nj][cid] == dis[i][j][p.second] + 1) n           to[i][j][p.second].push_back(make_pair(make_pair(ni, nj), cid)); n         continue; n       } n       dis[ni][nj][cid] = dis[i][j][p.second] + 1; n       q.push(make_pair(make_pair(ni, nj), cid)); n       to[i][j][p.second].push_back(make_pair(make_pair(ni, nj), cid)); n     } n   } n } n inline bool cmp(const pair<pair<int, int>, int> &a, n                 const pair<pair<int, int>, int> &b) { n   pair<int, int> p = a.first, q = b.first; n   if (g[p.first][p.second] != g[q.first][q.second]) n     return g[p.first][p.second] < g[q.first][q.second]; n   if (p.first == edi && p.second == edj) return false; n   return cmp(to[p.first][p.second][a.second][ans[p.first][p.second][a.second]], n              to[q.first][q.second][b.second][ans[q.first][q.second][b.second]]); n } n inline void dfs(int i, int j, int k) { n   if (vis[i][j][k]) return; n   vis[i][j][k] = true; n   if (i == edi && j == edj) { n     can[i][j][k] = true; n     return; n   } n   vector<pair<int, int> > nxt; n   for (register int d = 0; d < (to[i][j][k].size()); ++d) { n     pair<pair<int, int>, int> p = to[i][j][k][d]; n     int ni = p.first.first, nj = p.first.second, nk = p.second; n     nxt.push_back(make_pair(tp[ni][nj], d)); n   } n   sort(nxt.begin(), nxt.end()); n   for (int id1 = 0, id2; id1 < nxt.size(); id1 = id2) { n     int bst = -1; n     for (id2 = id1; id2 < nxt.size() && nxt[id2].first == nxt[id1].first; n          ++id2) { n       pair<pair<int, int>, int> p = to[i][j][k][nxt[id2].second]; n       dfs(p.first.first, p.first.second, p.second); n       if (can[p.first.first][p.first.second][p.second]) { n         if (bst == -1 || cmp(p, to[i][j][k][bst])) bst = nxt[id2].second; n       } n     } n     if (~bst) { n       can[i][j][k] = true; n       ans[i][j][k] = bst; n       return; n     } n   } n } n inline void getans(pair<pair<int, int>, int> a) { n   pair<int, int> p = a.first; n   if (p.first == edi && p.second == edj) return; n   if (p.first != sti || p.second != stj) putchar(g[p.first][p.second]); n   getans(to[p.first][p.second][a.second][ans[p.first][p.second][a.second]]); n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (register int i = (1); i <= (n); ++i) { n     scanf( %s , g[i] + 1); n     for (register int j = (1); j <= (m); ++j) { n       if (g[i][j] ==  S ) { n         tp[i][j] = -1; n         sti = i, stj = j; n       } else if (g[i][j] ==  T ) { n         tp[i][j] = -1; n         edi = i, edj = j; n       } else { n         tp[i][j] = g[i][j] -  a ; n       } n     } n   } n   id[0] = ++cnt; n   mask[cnt] = 0; n   for (register int i = (1); i <= (k - 1); ++i) { n     for (int comb = (1 << i) - 1, x, y; comb < (1 << 26); n          x = comb & -comb, y = comb + x, comb = ((comb & ~y) / x >> 1) | y) { n       id[comb] = ++cnt; n       mask[cnt] = comb; n     } n   } n   bfs(); n   if (!dis[edi][edj][1]) return puts( -1 ), 0; n   dfs(sti, stj, 1); n   getans(make_pair(make_pair(sti, stj), 1)); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (1 << 29); n const int maxn = 300005; n const int mod = 1000007; n vector<pair<int, int> > color[maxn]; n int q1[maxn], q2[maxn], ans[maxn], qq; n int n, m, num[maxn], top = 0, q[maxn], tot = 0, stk[maxn]; n vector<int> edge[maxn]; n bool vis[maxn]; n long long V[maxn]; n int N[maxn], C[maxn]; n int F[mod]; n void ins(int a, int b) { n   long long hsh = 1ll * a * (n + 2) + b; n   int h = hsh % mod; n   for (int p = F[h]; p > 0; p = N[p]) { n     if (V[p] == hsh) { n       return; n     } n   } n   V[++tot] = hsh, C[tot] = 0, N[tot] = F[h], F[h] = tot; n } n void upd(int a, int b) { n   long long hsh = 1ll * a * (n + 2) + b; n   int h = hsh % mod; n   for (int p = F[h]; p > 0; p = N[p]) { n     if (V[p] == hsh) { n       C[p]++; n       return; n     } n   } n } n int calc(int a, int b) { n   long long hsh = 1ll * a * (n + 2) + b; n   int h = hsh % mod; n   for (int p = F[h]; p > 0; p = N[p]) { n     if (V[p] == hsh) { n       return C[p]; n     } n   } n   return 0; n } n void DFS(int x) { n   if (vis[x]) { n     return; n   } n   vis[x] = 1; n   stk[++top] = x; n   for (int i = 0; i < edge[x].size(); ++i) { n     DFS(edge[x][i]); n   } n } n void solve1(int c) { n   if (color[c].empty()) { n     return; n   } n   int all = 0; n   for (int i = 0; i < color[c].size(); ++i) { n     num[++all] = color[c][i].first; n     num[++all] = color[c][i].second; n   } n   sort(num + 1, num + 1 + all); n   all = unique(num + 1, num + 1 + all) - num - 1; n   for (int i = 1; i <= all; ++i) { n     edge[num[i]].clear(); n     vis[num[i]] = 0; n   } n   for (int i = 0; i < color[c].size(); ++i) { n     int a = color[c][i].first, b = color[c][i].second; n     edge[a].push_back(b), edge[b].push_back(a); n   } n   for (int i = 1; i <= all; ++i) { n     if (!vis[num[i]]) { n       top = 0; n       DFS(num[i]); n       for (int j = 1; j <= top; ++j) { n         for (int k = j + 1; k <= top; ++k) { n           int a = stk[j], b = stk[k]; n           if (a > b) { n             swap(a, b); n           } n           upd(a, b); n         } n       } n     } n   } n } n int fa[maxn]; n int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); } n void solve2(int c) { n   for (int i = 1; i <= n; ++i) { n     fa[i] = i; n   } n   for (int i = 0; i < color[c].size(); ++i) { n     int a = color[c][i].first, b = color[c][i].second; n     a = getf(a); n     b = getf(b); n     if (a != b) { n       fa[a] = b; n     } n   } n   for (int i = 1; i <= qq; ++i) { n     if (getf(q1[i]) == getf(q2[i])) { n       ans[i]++; n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     color[i].clear(); n   } n   for (int i = 1, a, b, c; i <= m; ++i) { n     scanf( %d%d%d , &a, &b, &c); n     color[c].push_back(make_pair(a, b)); n   } n   tot = 0; n   memset(F, 0, sizeof(F)); n   memset(N, 0, sizeof(N)); n   memset(C, 0, sizeof(C)); n   memset(V, 0, sizeof(V)); n   scanf( %d , &qq); n   for (int i = 1; i <= qq; ++i) { n     scanf( %d%d , q1 + i, q2 + i); n     ans[i] = 0; n     if (q1[i] > q2[i]) { n       swap(q1[i], q2[i]); n     } n     ins(q1[i], q2[i]); n   } n   int L = (int)sqrt(m); n   if (1ll * L * L < m) { n     L++; n   } n   for (int i = 1; i <= m; ++i) { n     if (color[i].size() <= L) { n       solve1(i); n     } else { n       solve2(i); n     } n   } n   for (int i = 1; i <= qq; ++i) { n     ans[i] += calc(q1[i], q2[i]); n   } n   for (int i = 1; i <= qq; ++i) { n     if (q1[i] == q2[i]) { n       ans[i] = m; n     } n   } n   for (int i = 1; i <= qq; ++i) { n     printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, n, k; n   cin >> t; n   while (t--) { n     cin >> k >> n; n     cout << n + (9 * (k - 1)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> name, name2; n const int maxn = 1e3 + 10; n string s[maxn]; n int A[maxn]; n int main() { n   int n; n   cin >> n; n   int maxx = -999999999; n   for (int i = 0; i < n; i++) { n     cin >> s[i] >> A[i]; n     name[s[i]] += A[i]; n   } n   for (int i = 0; i < n; i++) maxx = max(maxx, name[s[i]]); n   for (int i = 0; i < n; i++) { n     name2[s[i]] += A[i]; n     if (name2[s[i]] >= maxx && name[s[i]] == maxx) { n       cout << s[i]; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const double EPS = 1e-9; n const int INT_INF = 1 << 31 - 1; n const long long I64_INF = 1ll << 63 - 1ll; n const double PI = acos(-1.0); n using namespace std; n struct person { n   int c, first; n   person(int _c = 0, int _f = 0) { n     c = _c; n     first = _f; n   } n   friend bool operator<(const person& a, const person& b) { n     return a.first < b.first; n   } n }; n int n, d, S; n vector<person> a; n vector<person> b; n vector<int> sumb; n int maxCNT = 0; n int minS = 0; n void upd(int a, int b) { n   if (a > maxCNT || a == maxCNT && b < minS) { n     maxCNT = a; n     minS = b; n   } n } n pair<int, int> go(int free, int second) { n   if (free >= (int)b.size()) return make_pair((int)b.size(), 0); n   if (b[0].first > second) return make_pair(free, 0); n   int r = (int)b.size() - free; n   int l = 0; n   while (l != r - 1) { n     int m = (l + r) >> 1; n     if (sumb[m] <= second) n       l = m; n     else n       r = m; n   } n   return make_pair(free + l + 1, sumb[l]); n } n int main() { n   scanf( %d%d%d , &n, &d, &S); n   for (int i = 0; i < (int)n; i++) { n     int c, first, l; n     scanf( %d%d%d , &c, &first, &l); n     if (l < d) first = S + 1; n     if (!c) n       b.push_back(person(c, first)); n     else n       a.push_back(person(c, first)); n   } n   sort(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   if (!b.empty()) sumb.push_back(b[0].first); n   for (int i = 1; i < (int)b.size(); i++) n     if (*sumb.rbegin() > S) n       sumb.push_back(S + 1); n     else n       sumb.push_back(*sumb.rbegin() + b[i].first); n   pair<int, int> r = go(0, S); n   upd(r.first, r.second); n   int k = 0; n   int sum = 0; n   int Sum = 0; n   for (int i = 0; i < (int)a.size(); i++) { n     Sum += a[i].c; n     if (Sum > n + n) break; n   } n   for (int i = 0; i < (int)a.size(); i++) { n     k++; n     sum += a[i].first; n     if (sum > S) break; n     int x = Sum - (int)a.size() + k; n     pair<int, int> r = go(x, S - sum); n     upd((int)a.size() + r.first, sum + r.second); n   } n   printf( %d %d n , maxCNT, minS); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k = 1; n   scanf( %d%d , &n, &m); n   while (1) { n     if (m < k) break; n     m -= k; n     k = k % n + 1; n   } n   printf( %d n , m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int main() { n   int n; n   scanf( %d , &n); n   vector<int> a(n), cum(n + 1); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     cum[i + 1] = a[i] + cum[i]; n   } n   int bits = 32 - __builtin_clz(n); n   vector<vector<int>> dp(bits + 1, vector<int>(n)); n   auto sum = [&](int l, int r) { return (cum[r] - cum[l]) % 10; }; n   for (int bit = 0; bit < bits; bit++) { n     int len = 1 << bit; n     for (int i = 0; i + 2 * len <= n; i++) { n       dp[bit + 1][i] = dp[bit][i] + dp[bit][i + len] + n                        (sum(i, i + len) + sum(i + len, i + 2 * len)) / 10; n     } n   } n   int q; n   scanf( %d , &q); n   for (int qq = 0; qq < q; qq++) { n     int l, r; n     scanf( %d %d , &l, &r); n     --l; n     int bit = __builtin_ctz(r - l); n     printf( %d n , dp[bit][l]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e5 + 5, MOD = 1e9 + 7; n long long n; n long long par[MAXN]; n long long cnt1[MAXN]; n long long cnt2[MAXN]; n long long dp1[MAXN]; n long long dp2[MAXN]; n long long color[MAXN]; n bool subtree[MAXN]; n vector<long long> G[MAXN]; n void dfs_up1(long long v = 0) { n   for (long long i = 0; i < G[v].size(); i++) { n     dfs_up1(G[v][i]); n     subtree[v] |= subtree[G[v][i]]; n   } n   subtree[v] |= color[v]; n } n void dfs_up2(long long v = 0) { n   for (long long i = 0; i < G[v].size(); i++) dfs_up2(G[v][i]); n   if (!subtree[v]) { n     dp1[v] = 0; n     dp2[v] = 1; n     return; n   } n   if (color[v]) { n     dp1[v] = 1; n     for (long long i = 0; i < G[v].size(); i++) n       if (subtree[G[v][i]]) { n         if (color[G[v][i]]) dp1[v] = (dp1[v] * dp1[G[v][i]]) % MOD; n         if (!color[G[v][i]]) n           dp1[v] = (dp1[v] * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD; n       } n     dp2[v] = 0; n     return; n   } n   long long bu = 1, num = 0; n   for (long long i = 0; i < G[v].size(); i++) n     if (subtree[G[v][i]]) { n       if (color[G[v][i]]) { n         num++; n         bu = (bu * dp1[G[v][i]]) % MOD; n       } n       if (!color[G[v][i]]) bu = (bu * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD; n     } n   dp1[v] = num * bu % MOD; n   bu = 1; n   num = 0; n   for (long long i = 0; i < G[v].size(); i++) n     if (subtree[G[v][i]]) { n       if (color[G[v][i]]) bu = (bu * dp1[G[v][i]]) % MOD; n       if (!color[G[v][i]]) { n         cnt1[num] = n             ((num ? cnt1[num - 1] : 1) * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD; n         num++; n       } n     } n   long long ind = num - 1; n   for (long long i = G[v].size() - 1; ~i; i--) n     if (subtree[G[v][i]]) { n       if (!color[G[v][i]]) { n         cnt2[ind] = ((ind != num - 1 ? cnt2[ind + 1] : 1) * n                      (dp1[G[v][i]] + dp2[G[v][i]])) % n                     MOD; n         ind--; n       } n     } n   ind = 0; n   for (long long i = 0; i < G[v].size(); i++) n     if (subtree[G[v][i]]) { n       if (!color[G[v][i]]) { n         dp1[v] = (dp1[v] + bu * (ind ? cnt1[ind - 1] : 1) % MOD * n                                (ind + 1 != num ? cnt2[ind + 1] : 1) % MOD * n                                dp1[G[v][i]]) % n                  MOD; n         ind++; n       } n     } n   dp2[v] = 1; n   for (long long i = 0; i < G[v].size(); i++) n     if (subtree[G[v][i]]) { n       if (color[G[v][i]]) dp2[v] = (dp2[v] * dp1[G[v][i]]) % MOD; n       if (!color[G[v][i]]) n         dp2[v] = (dp2[v] * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD; n     } n } n int main() { n   scanf( %lld , &n); n   for (long long i = 1; i < n; i++) { n     scanf( %lld , &par[i]); n     G[par[i]].push_back(i); n   } n   for (long long i = 0; i < n; i++) scanf( %lld , &color[i]); n   dfs_up1(); n   dfs_up2(); n   printf( %lld n , dp1[0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long s, x, a, ans = 1; n void setup() { n   cin >> s >> x; n   a = s - x; n   if (a & 1) { n     cout << 0; n     exit(0); n   } n   a >>= 1; n } n void xuly() { n   long long k = a; n   while (x) { n     if (x & 1) { n       if (a & 1) { n         cout << 0; n         return; n       } n       ans <<= 1; n     } n     x >>= 1; n     a >>= 1; n   } n   if (k == 0) ans -= 2; n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   setup(); n   xuly(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   cin >> a >> b; n   int n = a.size(); n   int f = 0, s = 0; n   for (int i = 0; i < n; ++i) n     if (a[i] != b[i]) { n       if (a[i] ==  4 ) n         f++; n       else n         s++; n     } n   int ans = min(f, s); n   ans += (f - ans) + (s - ans); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000 + 5; n int n, par[N], mx1[N], mx2[N], ans[N]; n int main() { n   scanf( %d , &n); n   par[1] = mx1[1] = mx2[1] = ans[1] = 0; n   for (int i = 2; i <= n + 1; i++) { n     scanf( %d , &par[i]); n     int v = i, val; n     ans[i] = mx1[i] = mx2[i] = 0; n     while (v > 0) { n       val = max(mx1[v], mx2[v] + 1); n       if (val <= ans[v]) break; n       ans[v] = val; n       if (mx1[par[v]] < val) n         mx1[par[v]] = val; n       else if (mx2[par[v]] < val) n         mx2[par[v]] = val; n       v = par[v]; n     } n     printf( %d  , max(mx1[1], mx2[1])); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, a, b, Q; n long long W[(500000)], S[(500000)], O[(500000)]; n map<pair<int, int>, vector<pair<int, int> > > M; n void pro(int t, int b, long long* g, int& l) { n   *g = 0, l = 1; n   while (b < N) { n     long long S = W[b] + g[l - 1]; n     g[l++] = S, b += t; n   } n } n int main() { n   scanf( %d , &N); n   for (int i(0); i < N; i++) scanf( %lld , W + i); n   scanf( %d , &Q); n   for (int i(0); i < Q; i++) n     scanf( %d%d , &a, &b), --a, M[{b, a % b}].push_back({a, i}); n   for (auto& h : M) { n     pro(h.first.first, h.first.second, S, a); n     for (auto& w : h.second) n       O[w.second] = S[a - 1] - S[w.first / h.first.first]; n   } n   for (int i(0); i < Q; i++) printf( %lld n , O[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 256; n const char nxt =   n ; n inline void in(string Q) { n   Q +=  .in ; n   freopen(Q.c_str(),  r , stdin); n } n inline void out(string Q) { n   Q +=  .out ; n   freopen(Q.c_str(),  w , stdout); n } n inline void open_file(string Q) { n   in(Q); n   out(Q); n } n inline bool Pal(const string& s) { n   return equal(s.begin(), s.end(), s.rbegin()); n } n vector<string> taxi, pizza, frienD; n string change(string& X) { n   string ret =   ; n   for (auto to : X) n     if (to !=  - ) ret.push_back(to); n   return ret; n } n int check(string x) { n   x = change(x); n   if (int(x.size()) != 6) return 2; n   string cur =   ; n   cur += x[0]; n   for (auto to : x) { n     if (to != cur.back()) cur.push_back(to); n   } n   if (int(cur.size()) == 1) return 1; n   cur = x; n   sort(cur.begin(), cur.end()); n   reverse(cur.begin(), cur.end()); n   char last =  . ; n   bool ok = 1; n   for (auto to : cur) { n     if (to == last) { n       ok = 0; n       break; n     } n     last = to; n   } n   if (cur == x && ok) return 0; n   return 2; n } n map<string, int> M[10], tax, piz, fr; n vector<string> nm; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if (0) open_file(  ); n   int n; n   cin >> n; n   while (n--) { n     int kol; n     string name, phone; n     cin >> kol >> name; n     nm.push_back(name); n     M[0][name] = M[1][name] = M[2][name] = 0; n     while (kol--) { n       cin >> phone; n       int D = check(phone); n       M[D][name]++; n     } n   } n   for (int i = 0; i < 3; ++i) { n     int mx = 0; n     for (auto to : M[i]) { n       mx = max(mx, to.second); n     } n     if (!mx) { n       for (auto it : nm) { n         if (!tax[it] && i == 1) { n           tax[it] = 1; n           taxi.push_back(it); n         } n         if (!piz[it] && !i) { n           pizza.push_back(it); n           piz[it] = 1; n         } n         if (!fr[it] && i == 2) { n           fr[it] = 1; n           frienD.push_back(it); n         } n       } n       continue; n     } n     if (i == 1) { n       for (auto it : nm) { n         for (auto to : M[i]) { n           if (to.second == mx && it == to.first && !tax[it]) { n             taxi.push_back(it); n             tax[it] = 1; n           } n         } n       } n     } n     if (i == 0) { n       for (auto it : nm) { n         for (auto to : M[i]) { n           if (to.second == mx && it == to.first && !piz[it]) { n             pizza.push_back(it); n             piz[it] = 1; n           } n         } n       } n     } n     if (i == 2) { n       for (auto it : nm) { n         for (auto to : M[i]) { n           if (to.second == mx && it == to.first && !fr[it]) { n             frienD.push_back(it); n             fr[it] = 1; n           } n         } n       } n     } n   } n   cout <<  If you want to call a taxi, you should call: ; n   string ans =   ; n   for (auto to : taxi) ans +=     + to +  , ; n   ans.pop_back(); n   ans +=  . ; n   cout << ans; n   ans =   ; n   cout << nxt <<  If you want to order a pizza, you should call: ; n   for (auto to : pizza) ans +=     + to +  , ; n   ans.pop_back(); n   ans +=  . ; n   cout << ans; n   ans =   ; n   cout << nxt n        <<  If you want to go to a cafe with a wonderful girl, you should call: ; n   for (auto to : frienD) ans +=     + to +  , ; n   ans.pop_back(); n   ans +=  . ; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct rec { n   int w, h; n }; n vector<rec> v; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int w, h; n     scanf( %d %d , &w, &h); n     v.push_back({w, h}); n   } n   int last = -0x3f3f3f3f; n   for (int i = n; i > 0; i--) { n     int prev = max(v[i - 1].w, v[i - 1].h); n     int mini = min(v[i].h, v[i].w); n     int maxi = max(v[i].h, v[i].w); n     if (mini >= last && mini <= prev) { n       last = mini; n     } else if (maxi >= last && maxi <= prev) { n       last = maxi; n     } else { n       printf( NO n ); n       return 0; n     } n   } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[100001], v[100001], posa[100001], posv[100001], x, y; n int inx[100001]; n inline void kspxa(int s, int t) { n   if (s < t) { n     int i = s, j = t, k = (i + j) >> 1; n     int l = a[i]; n     a[i] = a[k]; n     a[k] = l; n     l = posa[i]; n     posa[i] = posa[k]; n     posa[k] = l; n     k = a[i]; n     l = posa[i]; n     while (i != j) { n       while (i < j && a[j] > k) --j; n       if (i < j) a[i] = a[j], posa[i++] = posa[j]; n       while (i < j && a[i] < k) ++i; n       if (i < j) a[j] = a[i], posa[j--] = posa[i]; n     } n     a[i] = k; n     posa[i] = l; n     kspxa(s, i - 1); n     kspxa(i + 1, t); n   } n } n inline void kspxv(int s, int t) { n   if (s < t) { n     int i = s, j = t, k = (i + j) >> 1; n     int l = v[i]; n     v[i] = v[k]; n     v[k] = l; n     l = posv[i]; n     posv[i] = posv[k]; n     posv[k] = l; n     k = v[i]; n     l = posv[i]; n     while (i != j) { n       while (i < j && v[j] > k) --j; n       if (i < j) v[i] = v[j], posv[i++] = posv[j]; n       while (i < j && v[i] < k) ++i; n       if (i < j) v[j] = v[i], posv[j--] = posv[i]; n     } n     v[i] = k; n     posv[i] = l; n     kspxv(s, i - 1); n     kspxv(i + 1, t); n   } n } n int main() { n   scanf( %d%d%d%d , &n, &m, &x, &y); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), posa[i] = i; n   for (int i = 1; i <= m; i++) scanf( %d , &v[i]), posv[i] = i; n   kspxa(1, n); n   kspxv(1, m); n   int left = 1, ans = 0; n   memset(inx, 0, sizeof(inx)); n   for (int i = 1; i <= n; i++) { n     if (left > m) break; n     while (left <= m && v[left] < a[i] - x) ++left; n     if (left > m) break; n     if (v[left] >= a[i] - x && v[left] <= a[i] + y) n       inx[posa[i]] = posv[left], ++left, ++ans; n   } n   printf( %d n , ans); n   for (int i = 1; i <= n; i++) n     if (inx[i]) printf( %d %d n , i, inx[i]); n } n


#include <bits/stdc++.h> n using namespace std; n template <class A, class B> n ostream &operator<<(ostream &out, const pair<A, B> &a) { n   return out <<  (  << a.first <<  ,  << a.second <<  ) ; n } n template <class A> n ostream &operator<<(ostream &out, const vector<A> &a) { n   for (const A &it : a) out << it <<    ; n   return out; n } n template <class A, class B> n istream &operator>>(istream &in, pair<A, B> &a) { n   return in >> a.first >> a.second; n } n template <class A> n istream &operator>>(istream &in, vector<A> &a) { n   for (A &i : a) in >> i; n   return in; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n, x, y; n   cin >> n >> x >> y; n   string s; n   cin >> s; n   reverse((s).begin(), (s).end()); n   long long cnt = 0; n   for (long long i = 0; i < x; i++) { n     if ((i == x || i == y)) { n       cnt += s[i] ==  0 ; n     } else n       cnt += s[i] ==  1 ; n   } n   cout << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[2005]; n vector<long long> Z; n vector<long long> F; n int main() { n   long long n, i, S = 0; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     S += a[i]; n   } n   sort(a, a + n); n   reverse(a, a + n); n   for (i = 0; i < n; i++) { n     if (a[i] % 2 == 0) n       Z.push_back(a[i]); n     else n       F.push_back(a[i]); n   } n   i = 0; n   long long j = 0, k = 1, sum1 = 0, sum2 = 0; n   while (1) { n     if (k == 0) { n       if (i >= Z.size()) break; n       sum1 += Z[i]; n       i++; n       k = 1; n     } else { n       if (j >= F.size()) break; n       sum1 += F[j]; n       j++; n       k = 0; n     } n   } n   i = 0, j = 0, k = 0; n   while (1) { n     if (k == 0) { n       if (i >= Z.size()) break; n       sum2 += Z[i]; n       i++; n       k = 1; n     } else { n       if (j >= F.size()) break; n       sum2 += F[j]; n       j++; n       k = 0; n     } n   } n   long long maxi = max(sum1, sum2); n   cout << S - maxi; n   return 0; n } n


#include <bits/stdc++.h> n long long t[105], s[105]; n long long a[105]; n int getNumber(long long add) { n   if (add == 0) n     return 1; n   else { n     int res = -1; n     for (int i = 2; i <= 101; i++) { n       long long last = i * (i - 1) * (i - 2) / 6, n                 next = i * (i - 1) * (i + 1) / 6; n       if ((next - last) == add) { n         res = i; n         break; n       } n     } n     return res; n   } n } n int main() { n   int n; n   scanf( %d%lld%lld , &n, &t[0], &s[0]); n   for (int i = 1; i <= n; i++) { n     if (i <= n - 3) n       printf( + %d n , n - i); n     else { n       if (i == n || i == n - 2) n         printf( + 1 n ); n       else n         printf( + 2 n ); n     } n     fflush(stdout); n     scanf( %lld%lld , &t[i], &s[i]); n   } n   long long add = t[n] - t[n - 1]; n   a[1] = getNumber(add) - 1; n   long long add0 = s[n] - s[n - 1], add1 = s[n - 2] - s[n - 3]; n   a[3] = add0 - add1 - 1; n   a[2] = add1 / (a[3] + 1); n   add = s[n - 1] - s[n - 2]; n   a[4] = (add - (a[3] + 1) * (a[1] + 1)) / (a[3] + 1) - 1; n   for (int i = 5; i <= n; i++) { n     long long add = s[n - i + 2] - s[n - i + 1]; n     a[i] = (add - a[i - 3] * a[i - 4] - a[i - 3] * (a[i - 1] + 1)) / n                (a[i - 1] + 1) - n            1; n   } n   a[n]++; n   printf( !  ); n   for (int i = 1; i <= n; i++) printf( %lld  , a[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long ans[100100 << 1]; n long long ksm(long long p, long long q) { n   long long res = 1; n   while (q) { n     if (q & 1) res = res * p % 1000000007; n     p = p * p % 1000000007; n     q >>= 1; n   } n   return res; n } n signed main() { n   cin >> n; n   ans[0] = 1; n   for (long long i = 1; i <= (n << 1); i++) { n     ans[i] = ans[i - 1] * i % 1000000007; n   } n   cout << (ans[n << 1] * ksm(ans[n] * ans[n] % 1000000007, 1000000007 - 2)) % n                   1000000007 - n               n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b, t, p, i; n int main() { n   cin >> n >> a >> b; n   p = b * n; n   while (n > 1) { n     t += 2 * a + 1; n     n--; n   } n   cout << t <<     << p; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s1, s2; n bool eq(int a1, int b1, int a2, int b2) { n   if ((b1 - a1) & 1) { n     while (a1 < b1) { n       if (s1[a1] != s2[a2]) return 0; n       ++a1; n       ++a2; n     } n     return 1; n   } n   int m1 = (a1 + b1) / 2; n   int m2 = (a2 + b2) / 2; n   return (eq(a1, m1, a2, m2) && eq(m1, b1, m2, b2)) || n          (eq(a1, m1, m2, b2) && eq(m1, b1, a2, m2)); n } n bool func() { n   if (s1.length() != s2.length()) return 0; n   if (eq(0, s1.length(), 0, s2.length())) { n     return 1; n   } n } n int main() { n   cin >> s1 >> s2; n   if (func()) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m, k; n   cin >> n >> m >> k; n   vector<int> dp1(m, 0); n   vector<int> pref_max(m, 0); n   vector<int> suf_max(m, 0); n   vector<vector<int> > a(n); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int x; n       cin >> x; n       a[i].push_back(x); n     } n   } n   for (int i = 0; i < n; i++) { n     vector<vector<int> > sa1(m); n     vector<vector<int> > sa2(m); n     for (int j = 0; j < m; j++) { n       sa1[j].push_back(0); n       sa2[j].push_back(0); n       for (int ii = 0; ii < k; ii++) { n         if (j + ii < m) { n           sa1[j].push_back(sa1[j][sa1[j].size() - 1] + a[i][j + ii]); n           if (i < n - 1) { n             sa2[j].push_back(sa2[j][sa2[j].size() - 1] + a[i + 1][j + ii]); n           } else { n             sa2[j].push_back(0); n           } n         } else { n           sa1[j].push_back(sa1[j][sa1[j].size() - 1]); n           sa2[j].push_back(sa2[j][sa2[j].size() - 1]); n         } n       } n     } n     vector<int> dp2(m, -1e9); n     for (int j = 0; j < m; j++) { n       if (j - k >= 0) { n         dp2[j] = pref_max[j - k]; n       } n       if (j + k < m) { n         dp2[j] = max(dp2[j], suf_max[j + k]); n       } n       for (int ii = max(0, j - k + 1); ii < min(m, j + k); ii++) { n         if (ii < j) { n           dp2[j] = max(dp2[j], dp1[ii] - sa1[j][k - (j - ii)]); n         } else { n           dp2[j] = max(dp2[j], dp1[ii] - sa1[ii][k - (ii - j)]); n         } n       } n       if (i == 0) { n         dp2[j] = sa1[j][k] + sa2[j][k]; n       } else { n         dp2[j] += sa1[j][k] + sa2[j][k]; n       } n     } n     dp1 = dp2; n     pref_max[0] = dp1[0]; n     for (int j = 1; j < m; j++) { n       pref_max[j] = max(pref_max[j - 1], dp1[j]); n     } n     suf_max[m - 1] = dp1[m - 1]; n     for (int j = m - 2; j >= 0; j--) { n       suf_max[j] = max(suf_max[j + 1], dp1[j]); n     } n   } n   cout << pref_max[m - 1]; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   solve(); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   s = s +  x ; n   int dol = 0; n   int cent = 0; n   int td = 0; n   int tc = 0; n   for (int i = 0; i < s.length(); ++i) { n     if (s[i] >=  a  && s[i] <=  z ) { n       dol += td; n       cent += tc; n       td = 0; n       tc = 0; n       continue; n     } n     if (s[i] >=  0  && s[i] <=  9 ) td = td * 10 + (int)(s[i] -  0 ); n     if (s[i] ==  . ) { n       if (s[i + 3] >=  0  && s[i + 3] <=  9 ) n         continue; n       else n         for (int j = 0; j < 2; ++j) { n           ++i; n           tc = tc * 10 + (int)(s[i] -  0 ); n         } n     } n   } n   dol = dol + cent / 100; n   cent = cent % 100; n   int storecent = cent; n   int dig = 0; n   string sd; n   string sc; n   if (dol == 0 && cent > 0) { n     sd =  .  + sd; n     sd =  0  + sd; n   } n   while (dol > 0) { n     if (dig == 0) sd =  .  + sd; n     sd = (char)((dol % 10) +  0 ) + sd; n     dol /= 10; n     dig = (dig + 1) % 3; n   } n   while (cent > 0) { n     sc = (char)((cent % 10) +  0 ) + sc; n     cent /= 10; n   } n   if (sc.length() == 1) sc =  0  + sc; n   for (int i = 0; i < sd.length() - 1; ++i) cout << sd[i]; n   if (storecent != 0) { n     cout <<  . ; n     cout << sc[0] << sc[1]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 1; n bool v[N]; n int n, m, x, y, k, q[N], t, d[N], A[N], c; n vector<int> a[N]; n void D(int x) { n   q[++t] = x, d[x] = t; n   for (int i = 0; i < a[x].size(); i++) n     if (!d[a[x][i]]) n       D(a[x][i]); n     else if (d[x] - d[a[x][i]] + 1 >= k) { n       cout << 2 <<   n  << d[x] - d[a[x][i]] + 1 <<   n ; n       for (int j = d[a[x][i]]; j <= d[x]; j++) cout << q[j] <<    ; n       exit(0); n     } n   if (!v[x]) { n     A[++c] = x; n     for (int i = 0; i < a[x].size(); i++) v[a[x][i]] = true; n   } n   t--; n } n int main() { n   cin >> n >> m; n   while (m-- && cin >> x >> y) a[x].push_back(y), a[y].push_back(x); n   k = sqrt(n - 1) + 1, D(1); n   cout << 1 <<   n ; n   for (int i = 1; i <= k; i++) cout << A[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, t, cur = 1, pre, s; n   cin >> n >> pre; n   s = n; n   n--; n   for (int i = 0; i < (int)(n); ++i) { n     cin >> t; n     if (t == pre) n       cur++; n     else if (t != pre && cur > 1) { n       s += (cur * (cur - 1) / 2); n       cur = 1; n     } n     pre = t; n   } n   if (cur > 1) s += (cur * (cur - 1) / 2); n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   string s; n   cin >> s; n   int n = s.size(); n   int ps[n + 5]; n   ps[0] = s[0] -  0 ; n   for (int i = 1; i < n; i++) ps[i] = ps[i - 1] + s[i] -  0 ; n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     int it1 = lower_bound(ps + i, ps + n, (i ? ps[i - 1] : 0) + k) - ps; n     if (it1 == n) continue; n     int it2 = lower_bound(ps + i, ps + n, (i ? ps[i - 1] : 0) + k + 1) - 1 - ps; n     ans += it2 - it1 + 1; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n long long int x; n long long int k; n long long int res; n long long int curr; n long long int exponentiation(long long int base, long long int power) { n   long long int ans = 1; n   while (power > 0) { n     if (power % 2) ans = (ans * base) % mod; n     base = (base * base) % mod; n     power /= 2; n   } n   return ans % mod; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> x >> k; n   if (x == 0) { n     res = 0; n   } else if (k == 0) { n     res = (2 * x) % mod; n   } else { n     curr = (2 * x - 1 - x + mod) % mod; n     res = n         (x + ((((curr + x) % mod) * exponentiation(2, k)) % mod - curr) + mod) % n         mod; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long N; n   cin >> N; n   long long frend[N + 1][N + 1]; n   long long i, j, k; n   for (i = 1; i <= N; i++) { n     for (j = 1; j <= N; j++) { n       cin >> frend[i][j]; n     } n   } n   long long alex[N + 1]; n   long long liking[N + 1]; n   long long c = N + 9; n   for (i = 1; i <= N; i++) { n     cin >> alex[i]; n     liking[alex[i]] = c--; n   } n   for (i = 1; i <= N; i++) { n     for (j = 1; j <= N; j++) { n       if (frend[i][j] == i) continue; n       long long mx = 0; n       for (k = 1; k <= frend[i][j]; k++) { n         if (k == i) continue; n         mx = max(mx, liking[k]); n       } n       if (mx == liking[frend[i][j]]) { n         cout << frend[i][j] <<    ; n         break; n       } n     } n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int count_inversions(vector<int> v) { n   int t = 0; n   for (int i = 0; i < (int)v.size(); ++i) n     for (int j = i + 1; j < (int)v.size(); ++j) n       if (v[i] > v[j]) t++; n   return t; n } n int main() { n   int n; n   scanf( %d , &n); n   vector<int> v(n); n   for (int i = 0; i < n; ++i) scanf( %d , &v[i]); n   int inversions = count_inversions(v); n   cout << (inversions / 2) * 4 + (inversions % 2) << endl; n } n


#include <bits/stdc++.h> n long long mod; n long long solve(int dep, long long idx, long long left, long long right, n                 long long l, long long r, long long u, long long v) { n   if (right < l) return 0; n   if (left > r) return 0; n   if (left >= l && right <= r) { n     long long delta = (1LL << dep); n     long long begin = idx, end = idx + (right - left) * delta; n     if (end < u) return 0; n     if (begin > v) return 0; n     if (begin < u) begin = begin + (u - begin) / delta * delta; n     if (begin < u) begin += delta; n     if (end > v) end = end - (end - v) / delta * delta; n     if (end > v) end -= delta; n     if (begin > end) return 0; n     long long total = (end - begin) / delta + 1; n     return ((total % mod) * ((begin + end) % mod)) % mod; n   } n   long long delta = (1LL << dep); n   long long mid = (left + right) / 2; n   return (solve(dep + 1, idx, left, mid, l, r, u, v) + n           solve(dep + 1, idx + delta, mid + 1, right, l, r, u, v)) % n          mod; n } n int main() { n   long long n; n   int m; n   while (scanf( %I64d%d%I64d , &n, &m, &mod) == 3) { n     mod *= 2; n     for (int i = 0; i < m; i++) { n       long long l, r, u, v; n       scanf( %I64d%I64d%I64d%I64d , &l, &r, &u, &v); n       printf( %I64d n , solve(0, 1, 1, n, l, r, u, v) / 2); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct _ { n   ios_base::Init i; n   _() { n     cin.sync_with_stdio(0); n     cin.tie(0); n   } n } _; n const int MAXN = -1; n int n, m; n int main() { n   int a, b; n   cin >> a >> b; n   int n = a + b + 1; n   for (int i = n - a; i <= n; ++i) cout << i <<    ; n   for (int i = n - a - 1; i >= 1; --i) cout << i <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c, s = 0; n   scanf( %I64d%I64d , &a, &b); n   while (b != 0) { n     s = s + a / b; n     c = b; n     b = a % b; n     a = c; n   } n   printf( %I64d n , s); n   return 0; n } n


#include<bits/stdc++.h> n #define X first n #define Y second n #define sz(a) (int)a.size() n #define ll long long n //#define int long long n using namespace std; n const int mod = 1e9 + 7; n const int N = 3e5; n  n signed main() n { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n     int n, k; n     cin >> n >> k; n     string s; n     cin >> s; n     vector <int> vec; n     for(int i = 0; i < n; i++) n     { n         if(s[i] ==  ? ) n         { n             vec.push_back(-1); n         } n         else n         { n             vec.push_back(s[i] -  a ); n         } n     } n     vector <vector <int> > right(k, vector <int> (n, 0)); n     for(int i = 0; i < k; i++) n     { n         for(int j = n - 1; j >= 0; j--) n         { n             if(vec[j] == i || vec[j] == -1) n             { n                 if(j == n - 1) n                 { n                     right[i][j] = 1; n                 } n                 else n                 { n                     right[i][j] = right[i][j + 1] + 1; n                 } n             } n    //         cout << right[i][j] <<    ; n         } n      //   cout <<   n ; n     } n     int l = 0, r = n + 1; n     while(r - l > 1) n     { n         int midd = (r + l) / 2; n         vector <vector <int> > mass(26); n         for(int i = 0; i < k; i++) n         { n             for(int j = 0; j < n; j++) n             { n                 if(right[i][j] >= midd) n                 { n                     mass[i].push_back(j); n                 } n             } n         } n         vector <int> dp(1 << k, 1e9); n         dp[0] = -1; n         vector <int> iter(k, 0); n         vector <vector <int> > mass1(n + 1); n         mass1[0].push_back(0); n         for(int i = 0; i < n; i++) n         { n             for(int j = 0; j < k; j++) n             { n                 while(iter[j] < sz(mass[j]) && mass[j][iter[j]] < i) n                 { n                     iter[j]++; n                 } n             } n             for(auto p : mass1[i]) n             { n                 if(dp[p] != i - 1) n                 { n                     continue; n                 } n                 for(int j = 0; j < k; j++) n                 { n                     if((1 << j) & p) n                     { n                         continue; n                     } n                     if(iter[j] < sz(mass[j])) n                     { n                         int u = mass[j][iter[j]]; n                         if(dp[(1 << j) | p] > u + midd - 1) n                         { n                             dp[(1 << j) | p] = u + midd - 1; n                             mass1[u + midd].push_back((1 << j) | p); n                         } n                     } n                 } n             } n         } n         if(dp[(1 << k) - 1] < n) n         { n             l = midd; n         } n         else n         { n             r = midd; n         } n     } n     cout << l; n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int n, k, tot, root; n int ak[30]; n int son[20000005][2], g[20000005]; n long long ans; n void calc(int v, int *a) { n   memset(a, 0, 120); n   int i = 0; n   while (v) { n     a[i++] = v & 1; n     v >>= 1; n   } n   return; n } n int make_node() { n   ++tot; n   return tot; n } n int get_ans(int x, int d) { n   if (!son[x][d]) return 0; n   return g[son[x][d]]; n } n int ax[30]; n void update(int x) { n   int nd = root; n   g[root]++; n   for (int i = 30 - 1; i >= 0; i--) { n     if (!son[nd][ax[i]]) son[nd][ax[i]] = make_node(); n     nd = son[nd][ax[i]]; n     g[nd]++; n   } n   return; n } n void query(int x) { n   int nd = root; n   for (int i = 30 - 1; i >= 0; i--) { n     if (!ak[i]) { n       ans += get_ans(nd, ax[i] ^ 1); n       nd = son[nd][ax[i]]; n     } else n       nd = son[nd][ax[i] ^ 1]; n     if (!nd) return; n   } n   ans += g[nd]; n   return; n } n int main() { n   int x, y = 0; n   scanf( %d %d , &n, &k); n   root = make_node(); n   update(0); n   calc(k, ak); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     y ^= x; n     calc(y, ax); n     query(y); n     update(y); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n vector<int> T; n int l, size; n void Stworz(int n) { n   int p = 1; n   while (p < n) p *= 2; n   l = p; n   size = 2 * p - 1; n   for (int i = 0; i <= size; ++i) T.push_back(INF); n } n void Ustaw(int a, int x) { n   a += l; n   T[a] = x; n   a /= 2; n   while (a != 0) { n     T[a] = min(T[2 * a], T[2 * a + 1]); n     a /= 2; n   } n } n int Mini(int a, int b) { n   a += l; n   b += l; n   int m = min(T[a], T[b]); n   while (a / 2 != b / 2) { n     if (a % 2 == 0) m = min(m, T[a + 1]); n     if (b % 2 == 1) m = min(m, T[b - 1]); n     a /= 2; n     b /= 2; n   } n   return m; n } n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   vector<int> a(n); n   map<int, int> wyst, pier; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     wyst[a[i]] = 0; n     pier[a[i]] = INF; n   } n   Stworz(n); n   vector<int> odp; n   for (int L = 0; L < n;) { n     int P = L; n     while (P < n) { n       ++wyst[a[P]]; n       if (pier[a[P]] == INF) pier[a[P]] = P; n       Ustaw(P, pier[a[P]]); n       if (pier[a[P]] + 1 <= P - 1) { n         int ind = Mini(pier[a[P]] + 1, P - 1); n         if (ind < pier[a[P]]) { n           odp.push_back(a[ind]); n           odp.push_back(a[P]); n           odp.push_back(a[ind]); n           odp.push_back(a[P]); n           break; n         } n       } n       if (wyst[a[P]] >= 4) { n         for (int i = 0; i < 4; ++i) odp.push_back(a[P]); n         break; n       } n       ++P; n     } n     for (int i = L; i <= min(P, n); ++i) { n       --wyst[a[i]]; n       pier[a[i]] = INF; n     } n     L = P + 1; n   } n   cout << odp.size() << endl; n   for (int i = 0; i < odp.size(); ++i) cout << odp[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, y, x, h, n; n   cin >> a >> b >> c >> d; n   y = (a * 3) / 10, x = (a - ((a / 250) * c)), h = (b * 3) / 10, n   n = (b - ((b / 250) * d)); n   if (max(y, x) > max(n, h)) n     cout <<  Misha ; n   else if (max(y, x) < max(n, h)) n     cout <<  Vasya ; n   else n     cout <<  Tie ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using P = pair<int, int>; n using Pl = pair<ll, int>; n const int mod = 1e9 + 7, INF = 1 << 30; n const double EPS = 1e-12, PI = 3.1415926535897932384626; n const ll LINF = 1LL << 60, lmod = 1e9 + 7; n const int MAX_N = 102; n vector<P> graph[MAX_N]; n int memo[2][MAX_N][MAX_N][30]; n int solve(bool is_first, int a, int b, int score) { n   if (memo[int(is_first)][a][b][score] != -1) n     return memo[int(is_first)][a][b][score]; n   if (is_first) { n     bool win = false; n     for (auto p : graph[a]) { n       int u, c; n       tie(u, c) = p; n       if (c >= score) { n         win |= (solve(false, u, b, c) == 1); n       } n     } n     if (!win) n       return memo[int(is_first)][a][b][score] = 0; n     else n       return memo[int(is_first)][a][b][score] = 1; n   } else { n     bool win = true; n     for (auto p : graph[b]) { n       int u, c; n       tie(u, c) = p; n       if (c >= score) { n         win &= (solve(true, a, u, c) == 1); n       } n     } n     if (win) n       return memo[int(is_first)][a][b][score] = 1; n     else n       return memo[int(is_first)][a][b][score] = 0; n   } n } n int main() { n   int N, M; n   cin >> N >> M; n   for (int i = 0; i < M; i++) { n     int a, b; n     char c; n     cin >> a >> b >> c; n     a--; n     b--; n     graph[a].push_back(P(b, int(c -  a ))); n   } n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < MAX_N; j++) n       for (int k = 0; k < MAX_N; k++) n         for (int l = 0; l < 30; l++) memo[i][j][k][l] = -1; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N; j++) cout << (solve(true, i, j, 0) == 1 ?  A  :  B ); n     cout <<    << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   vector<pair<int, int>> v; n   for (int i = 0; i < n; i++) { n     long long a, b; n     cin >> a >> b; n     v.push_back(make_pair(a, b)); n   } n   int c = 0; n   for (int i = 0; i < n; i++) { n     int up = 0, lo = 0, r = 0, l = 0; n     for (int j = 0; j < n; j++) { n       if (v[i].first > v[j].first && v[i].second == v[j].second) up = 1; n       if (v[i].first < v[j].first && v[i].second == v[j].second) lo = 1; n       if (v[i].first == v[j].first && v[i].second < v[j].second) l = 1; n       if (v[i].first == v[j].first && v[i].second > v[j].second) r = 1; n     } n     if (up + lo + l + r == 4) c++; n   } n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n const short int N = 1000; n short int n, m, ax[] = {0, 0, 1, -1}, ay[] = {1, -1, 0, 0}, man_dis[N][N]; n bool vis[N][N], v[N][N], g[N][N]; n void good() { n   for (short int i = 0; i < n; i++) { n     for (short int j = 0; j < m; j++) { n       bool f = 0; n       if (i and v[i][j] == v[i - 1][j]) f = 1; n       if (j and v[i][j] == v[i][j - 1]) f = 1; n       if (i < n - 1 and v[i][j] == v[i + 1][j]) f = 1; n       if (j < m - 1 and v[i][j] == v[i][j + 1]) f = 1; n       g[i][j] = f; n     } n   } n } n void man_dist() { n   queue<pair<short int, short int>> q; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (g[i][j]) man_dis[i][j] = 0, q.push({i, j}), vis[i][j] = true; n   while (q.size()) { n     short int y = q.front().first, x = q.front().second; n     q.pop(); n     for (int i = 0; i < 4; i++) { n       int nx = x + ax[i], ny = y + ay[i]; n       if (nx < 0 || ny < 0 || nx >= m || ny >= n || vis[ny][nx]) continue; n       man_dis[ny][nx] = man_dis[y][x] + 1; n       vis[ny][nx] = true; n       q.push({ny, nx}); n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tt, ii = 0; n   short int k = 0; n   cin >> n >> m >> tt; n   for (short int i = 0; i < n; i++) n     for (short int j = 0; j < m; j++) { n       char x; n       cin >> x; n       v[i][j] = (x ==  1 ); n     } n   good(); n   man_dist(); n   while (ii++ < tt) { n     short int i, j; n     long long p; n     cin >> i >> j >> p; n     i--, j--; n     if (n + m == 2) { n       cout << v[i][j] << endl; n       continue; n     } n     short int f = man_dis[i][j]; n     if (p <= f || !vis[i][j]) n       cout << v[i][j] << endl; n     else n       cout << (p - f + v[i][j]) % 2 << endl; n   } n   cerr <<  [Execution :   << (1.0 * clock()) / CLOCKS_PER_SEC <<  s] n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool oppSign(double a, double b) { n   if (a == 0 || b == 0) return false; n   if (a > 0 && b < 0) return true; n   if (a < 0 && b > 0) return true; n   return false; n } n void parr(vector<double>& a) { n   for (int i = 0; i < a.size(); ++i) { n     cout << a[i] <<    ; n   } n   cout << endl; n } n int main() { n   int n; n   cin >> n; n   double a, b; n   cin >> a >> b; n   vector<pair<double, double> > v; n   for (int i = 0; i < (n); ++i) { n     double x, y; n     scanf( %lf%lf , &x, &y); n     double y1, y2; n     y1 = x * a + y; n     y2 = x * b + y; n     v.push_back(make_pair((y1), (y2))); n   } n   sort(v.begin(), v.end()); n   vector<double> ar, br; n   for (int i = 0; i < v.size(); ++i) { n     double x = v[i].first; n     double y = v[i].second; n     ar.push_back(x); n     br.push_back(y); n   } n   vector<double> bkr(br.size()); n   bkr[br.size() - 1] = br[br.size() - 1]; n   for (int i = br.size() - 2; i >= 0; --i) { n     if (br[i] > bkr[i + 1]) n       bkr[i] = bkr[i + 1]; n     else n       bkr[i] = br[i]; n   } n   bool flag = false; n   for (int i = 0; i < ar.size() - 1; ++i) { n     if (ar[i] != ar[i + 1] && br[i] != bkr[i + 1] && n         oppSign((ar[i] - ar[i + 1]), (br[i] - bkr[i + 1]))) { n       flag = true; n       break; n     } n   } n   if (flag == false) n     cout <<  NO n ; n   else n     cout <<  YES n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long ans; n int a[150000 + 1]; n int main() { n   scanf( %d , &n); n   for (register int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     ans += 1LL * a[i] * (n - a[i] + 1); n   } n   for (register int i = 1; i <= n; ++i) n     ans -= 1LL * min(a[i], a[i + 1]) * (n - max(a[i], a[i + 1]) + 1); n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = ~0u >> 1, N = 1000005; n int n, r, x, ans, fr; n char o[N]; n void output(int x, int y) { n   for (int i = n; i; --i) n     if (x >= y) n       o[i - 1] =  T , x -= y; n     else n       o[i - 1] =  B , y -= x; n } n int evaluate(int x, int y) { n   int sta = 0, stb = 0, t; n   while (x != 0 && y != 0 && sta <= n) { n     if (x > y) { n       if (x % y != 0) { n         t = x / y; n         sta += t; n         stb += t - 1; n         x %= y; n       } else { n         t = x / y - 1; n         sta += t; n         stb += t - 1; n         x = y; n         ++sta; n         y = 0; n       } n     } else { n       if (y % x != 0) { n         t = y / x; n         sta += t; n         stb += t - 1; n         y %= x; n       } else { n         t = y / x - 1; n         sta += t; n         stb += t - 1; n         y = x; n         ++sta; n         x = 0; n       } n     } n   } n   if (x == 0 && y == 1 && sta == n) n     return stb; n   else n     return -1; n } n void nrun() { n   ans = n; n   for (int i = 1; i < r; ++i) { n     x = evaluate(i, r); n     if (x != -1 && x <= ans) ans = x, fr = i; n     x = evaluate(r, i); n     if (x != -1 && x <= ans) ans = x, fr = -i; n   } n   if (ans == n) n     printf( IMPOSSIBLE n ); n   else { n     printf( %d n , ans); n     if (fr > 0) n       output(fr, r); n     else n       output(r, -fr); n     puts(o); n   } n } n int main() { n   scanf( %d%d , &n, &r); n   if (r == 1) { n     printf(n == 1 ?  0 nT n  :  IMPOSSIBLE n ); n   } else n     nrun(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n int n, k, a, b; n vector<int> v; n int ret(int lt, int rt) { n   int id2 = upper_bound(v.begin(), v.end(), rt) - v.begin(); n   int id1 = lower_bound(v.begin(), v.end(), lt) - v.begin(); n   return id2 - id1; n } n long long dfs(int lt, int rt) { n   int nm = ret(lt, rt); n   if (!nm) return a; n   long long on = b * 1LL; n   on *= nm; n   on *= (rt - lt + 1); n   if (lt == rt) return on; n   int md = (lt + rt) / 2; n   long long tw = dfs(lt, md) + dfs(md + 1, rt); n   return min(on, tw); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k >> a >> b; n   for (int i = 1; i <= k; i++) { n     int x; n     cin >> x; n     v.push_back(x); n   } n   sort(v.begin(), v.end()); n   cout << dfs(1, 1 << n) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   int a[2 * n], ans = 0; n   for (int i = 0; i <= 2 * n - 1; i++) cin >> a[i]; n   for (int i = 0; i < 2 * n; i += 2) { n     int j = i + 1; n     while (a[j] != a[i]) j++; n     ans += j - i - 1; n     for (int k = j; k >= i + 2; k--) a[k] = a[k - 1]; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int inf = 1e9 + 9; n const long long MOD = 1e9 + 696969; n const long long INF = 1e18; n int n, m, k, a, b, c, w, h; n char s[1000100]; n int dp[1000100][26], last[1000100][26]; n pair<int, int> SECOND, MIN; n inline pair<int, int> minexc(int x) { n   if (x != MIN.second) return MIN; n   return SECOND; n } n char ret[1000100]; n int main() { n   scanf( %d%d , &n, &k) ?: 0; n   scanf( %s , s + 1) ?: 0; n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j < k; ++j) dp[i][j] = inf; n   MIN = {0, -1}; n   SECOND = {0, 0}; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < k; ++j) n       if (s[i] == (char)j +  A ) { n         dp[i][j] = minexc(j).first; n         last[i][j] = minexc(j).second; n       } else n         dp[i][j] = minexc(j).first + 1, last[i][j] = minexc(j).second; n     MIN = {inf, inf}; n     SECOND = {inf, inf}; n     for (int j = 0; j < k; ++j) n       if (dp[i][j] < MIN.first) { n         SECOND = MIN; n         MIN = make_pair(dp[i][j], j); n       } else if (dp[i][j] < SECOND.first) n         SECOND = make_pair(dp[i][j], j); n   } n   int res = inf, poz = inf; n   for (int i = 0; i < k; ++i) n     if (dp[n][i] < res) res = dp[n][i], poz = i; n   cout << res << endl; n   if (res == 0) { n     for (int i = 1; i <= n; ++i) printf( %c , s[i]); n     exit(0); n   } n   for (int i = n; i > 0; --i) { n     ret[i] = poz +  A ; n     poz = last[i][poz]; n   } n   for (int i = 1; i <= n; ++i) printf( %c , ret[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n const long long INF64 = (long long)1e18; n const long double eps = 1e-9; n const long double pi = 3.14159265358979323846; n int dp[20][50]; n int frmP[20][50], frmQ[20][50], frmE[20][50]; n long long ten[20]; n char str[60]; n vector<long long> arr; n pair<long long, long long> rev[60]; n long long num[20]; n void update(int p1, int q1, int p2, int q2, int val) { n   if (dp[p1][q1] == 0) { n     dp[p1][q1] = 1; n     frmP[p1][q1] = p2; n     frmQ[p1][q1] = q2; n     frmE[p1][q1] = val; n   } n } n void re(int p1, int q1, int dep) { n   if (p1) { n     re(frmP[p1][q1], frmQ[p1][q1], dep + 1); n     int xx, yy; n     int i; n     long long val; n     val = arr[frmE[p1][q1]]; n     xx = rev[val].first; n     yy = rev[val].second; n     for (i = 0; i < xx; i++) num[i] += (4LL * ten[dep]); n     for (i = 0; i < yy; i++) num[i + xx] += (7LL * ten[dep]); n   } n } n int main() { n   long long i, j, k; n   for (i = 0; i <= 6; i++) { n     for (j = 0; j + i <= 6; j++) { n       arr.push_back(i * 4 + 7 * j); n       rev[i * 4 + 7 * j] = (make_pair(i, j)); n     } n   } n   sort((arr).begin(), (arr).end()); n   int tn; n   int len; n   long long t; n   t = 1; n   for (i = 0; i <= 18; i++) { n     ten[i] = t; n     t *= 10LL; n   } n   cin >> tn; n   while (tn--) { n     cin >> str; n     len = strlen(str); n     memset(dp, 0, sizeof(dp)); n     dp[0][0] = 1; n     for (i = 1; i <= len; i++) { n       for (j = 0; j < 50; j++) { n         if (dp[i - 1][j]) { n           t = j * 10LL + (str[i - 1] -  0 ); n           for (k = 0; k < (int((arr).size())) && arr[k] <= t; k++) { n             if (t - arr[k] < 50LL) { n               update(i, t - arr[k], i - 1, j, k); n             } n           } n         } n       } n     } n     if (!dp[len][0]) n       printf( -1 n ); n     else { n       memset(num, 0, sizeof(num)); n       re(len, 0, 0); n       for (i = 0; i < 6; i++) { n         if (i) printf(   ); n         cout << num[i]; n       } n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 7; n const long long llinf = 1e18 + 7; n const double eps = 1e-15; n const int N = 2e5 + 5; n int cnt0[N], cnt1[N]; n long long sum(int cnt[N], int l, int r) { n   long long ret = cnt[r]; n   if (l) ret -= cnt[l - 1]; n   return ret; n } n int main() { n   string a, b; n   cin >> a >> b; n   memset(cnt0, 0, sizeof cnt0); n   memset(cnt1, 0, sizeof cnt1); n   for (int i = 0; i < b.size(); ++i) { n     cnt0[i] += b[i] ==  0 ; n     if (i) cnt0[i] += cnt0[i - 1]; n     cnt1[i] += b[i] ==  1 ; n     if (i) cnt1[i] += cnt1[i - 1]; n   } n   long long ans = 0; n   for (int i = 0; i < a.size(); ++i) { n     int lastloc = int(b.size()) - int(a.size()) + i; n     if (a[i] ==  1 ) { n       ans += sum(cnt0, i, lastloc); n     } else n       ans += sum(cnt1, i, lastloc); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, r1, r2; n   cin >> n >> r1 >> r2; n   int a[n + 2]; n   for (int i = 1; i <= n; i++) n     if (i != r1) n       cin >> a[i]; n     else n       a[i] = 0; n   int v = r2, x = a[r2]; n   do { n     int y = a[x]; n     a[x] = v; n     v = x; n     x = y; n   } while (x != 0); n   for (int i = 1; i <= n; i++) n     if (i != r2) cout << a[i] <<    ; n } n


#include<bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int,int>; n using pll = pair<ll,ll>; n #ifdef eclipse n #define debug(...) do{  n  fprintf(stderr,  LINE %d: (%s) =  ,__LINE__, #__VA_ARGS__ );   n  _do(__VA_ARGS__);   n }while(0) n template<typename T> void _do(T &&_x) {cerr << _x << endl;} n template<typename T, typename ...S> void _do(T &&_x, S &&..._t) {cerr << _x <<  ,  ; _do(_t...);} n #else n #define debug(...) n #endif n  n const int MAXN = 300005; n int n, in[MAXN], in2[MAXN]; n  n int calc() { n  int ans = 0; n  for (int i = 1; i < n - 1; ++i) { n   if (in[i] < min(in[i-1], in[i+1])) ans++; n   else if (in[i] > max(in[i-1], in[i+1])) ans++; n  }  n  return ans; n } n  n  n int calc2(int idx) { n  int x, y; x = y = 0; n  for (int i = idx - 1; i <= idx + 1; ++i) { n   if (i == 0 || i == n - 1) continue; n   if (in[i] < min(in[i-1], in[i+1])) y++; n   else if (in[i] > max(in[i-1], in[i+1])) y++; n  } n  n  for (int i = idx - 1; i <= idx + 1; ++i) { n   if (i == 0 || i == n - 1) continue; n   if (in2[i] < min(in2[i-1], in2[i+1])) x++; n   else if (in2[i] > max(in2[i-1], in2[i+1])) x++; n  } n  return x - y; n } n  n signed main (){ n  ios::sync_with_stdio(0),cin.tie(0); n  int t; n  cin >> t; n  while (t--) { n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> in[i]; n   for (int i = 0; i < n; ++i) in2[i] = in[i]; n   int ans, now = calc(); n   ans = now; n   for (int i = 1; i < n - 1; ++i) { n    int tmp = in[i]; n    in[i] = in[i-1]; n    ans = min(ans, now - calc2(i)); n    in[i] = in[i+1]; n    ans = min(ans, now - calc2(i)); n    in[i] = tmp; n   }  n   cout << ans <<   n ; n  } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n int resp; n int ask(long long x) { n   printf( ? %lld n , x); n   fflush(stdout); n   scanf( %d , &resp); n   return resp; n } n void ans(long long x) { n   printf( = %lld n , x); n   fflush(stdout); n } n void solve() { n   scanf( %lld , &n); n   if (n == 2ll) { n     resp = ask(1ll); n     resp = ask(2ll); n     if (resp) n       ans(1ll); n     else n       ans(2ll); n     return; n   } else if (n == 3ll) { n     resp = ask(2ll); n     resp = ask(1ll); n     if (resp) n       ans(1ll); n     else { n       resp = ask(3ll); n       if (resp) n         ans(2ll); n       else n         ans(3ll); n     } n     return; n   } n   vector<long long> path_mid_to_hi; n   long long lf = 1ll, rg = n - 1ll; n   for (long long md; lf <= rg;) { n     md = (lf + rg) / 2ll; n     path_mid_to_hi.push_back(md); n     if (lf == rg && md == n - 1ll) break; n     lf = md + 1ll; n   } n   long long st = n, bf = n; n   reverse(path_mid_to_hi.begin(), path_mid_to_hi.end()); n   bool go_left = 1; n   for (long long i : path_mid_to_hi) { n     bf = st; n     if (go_left) n       st -= i; n     else n       st += i; n     go_left ^= 1; n   } n   if (bf < st) n     go_left = 1; n   else n     go_left = 0; n   lf = 1ll, rg = n - 1ll; n   long long res = n; n   resp = ask(st); n   for (long long md; lf <= rg;) { n     md = (lf + rg) / 2; n     if (go_left) n       st -= md; n     else n       st += md; n     resp = ask(st); n     if (resp) { n       res = md; n       rg = md - 1; n     } else n       lf = md + 1; n     go_left ^= 1; n   } n   ans(res); n   return; n } n int main() { n   int tc; n   scanf( %d , &tc); n   for (; tc--;) solve(); 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   cout.tie(0); n   long long int n, m; n   cin >> n >> m; n   vector<long long int> v; n   long long int s = (m + 1) / 2; n   v.push_back(s); n   long long int i = 1; n   if (m % 2) { n     while (1) { n       if (s + i == m + 1) break; n       if (s - i > 0) v.push_back(s - i); n       v.push_back(s + i); n       i++; n     } n   } else { n     while (1) { n       if (s + i == m + 1) break; n       v.push_back(s + i); n       if (s - i > 0) v.push_back(s - i); n       i++; n     } n   } n   i = 0; n   while (i < n) { n     cout << v[i] <<   n ; n     v.push_back(v[i]); n     i++; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 1 << 29; n int cmp(const void* a, const void* b); n long long maxv(long long a, long long b); n long long minv(long long a, long long b); n long long gcd(long long u, long long v); n int main() { n   long long t = 1, i = 0; n   while (t--) { n     long long r, d, n; n     scanf( %lld%lld%lld , &r, &d, &n); n     long long ans = 0, x, y, cr; n     for (long long i = 0; i < (n); i++) { n       scanf( %lld%lld%lld , &x, &y, &cr); n       if (x * x + y * y <= (r - cr) * (r - cr) && 2 * cr <= d && n           x * x + y * y >= (r - d + cr) * (r - d + cr)) n         ans++; n     } n     printf( %lld n , ans); n   } n } n int cmp(const void* a, const void* b) { n   if (*(long long*)a - *(long long*)b < 0) return -1; n   if (*(long long*)a - *(long long*)b > 0) return 1; n   return 0; n } n long long maxv(long long a, long long b) { n   if (a > b) return a; n   return b; n } n long long minv(long long a, long long b) { n   if (a < b) return a; n   return b; n } n long long gcd(long long u, long long v) { n   if (v == 0) return u; n   return gcd(v, u % v); n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, -1, 1}; n void arquivo() { n   freopen(  ,  r , stdin); n   freopen(  ,  w , stdout); n } n const int N = 505050; n struct no { n   int l, r; n   int op; n   no(){}; n   no(int a, int b, int c) { n     op = a; n     l = b; n     r = c; n   } n }; n no vet[N]; n int n, m, p; n char s[N]; n inline void print() { n   p = vet[0].r; n   while (p != n + 1) { n     printf( %c , vet[p].op == 1 ?  (  :  ) ); n     p = vet[p].r; n   } n   printf(  n ); n } n inline void goRemove() { n   int p1 = p; n   int p2 = p; n   int qtd = vet[p1].op; n   while (qtd > 0) { n     p2 = vet[p2].r; n     qtd += vet[p2].op; n   } n   while (qtd < 0) { n     p2 = vet[p2].l; n     qtd += vet[p2].op; n   } n   int esq = min(p1, p2); n   int dir = max(p1, p2); n   esq = vet[esq].l; n   dir = vet[dir].r; n   vet[esq].r = dir; n   vet[dir].l = esq; n   if (dir != n + 1) n     p = dir; n   else n     p = esq; n } n int main() { n   scanf( %d %d %d , &n, &m, &p); n   vet[0].r = 1; n   vet[0].l = 0; n   for (int i = 1; i <= n; ++i) { n     char c; n     scanf(  %c , &c); n     if (c ==  ( ) n       vet[i] = no(1, i - 1, i + 1); n     else n       vet[i] = no(-1, i - 1, i + 1); n   } n   vet[n + 1].l = n; n   vet[n + 1].r = n + 1; n   scanf(  %s , s); n   int len = strlen(s); n   for (int i = 0; i < len; ++i) { n     if (s[i] ==  L ) n       p = vet[p].l; n     else if (s[i] ==  R ) n       p = vet[p].r; n     else n       goRemove(); n   } n   print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long f[305][305][5]; n struct point { n   int x, y; n   point(int x = 0, int y = 0) : x(x), y(y) {} n } a[305]; n struct edge { n   int u, v; n   double w; n   edge(int u = 0, int v = 0, double w = 0) : u(u), v(v), w(w) {} n   bool operator<(const edge b) const { return w < b.w; } n } s[305 * 305]; n int read() { n   char c = getchar(); n   int x = 0, s = 1; n   while (!isdigit(c)) { n     if (c ==  - ) s = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 3) + (x << 1) + c -  0 ; n     c = getchar(); n   } n   return x * s; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; ++i) { n     a[i].x = read(); n     a[i].y = read(); n   } n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (i != j) s[++m] = edge(i, j, atan2(a[i].y - a[j].y, a[i].x - a[j].x)); n   sort(s + 1, s + m + 1); n   for (int i = 1; i <= m; ++i) { n     int u = s[i].u, v = s[i].v; n     f[u][v][0] = 1; n     for (int k = 1; k <= 4; ++k) n       for (int j = 1; j <= n; ++j) f[j][v][k] += f[j][u][k - 1]; n   } n   long long ans = 0; n   for (int i = 1; i <= n; ++i) ans += f[i][i][4]; n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int in[30]; n int out[1050000][2]; n int oc; n int n; n int pre[30]; n int cnt[30][2]; n inline int cntf(int np, int b) { n   if (cnt[np][b] != -1) return cnt[np][b]; n   if (np == n) return cnt[np][b] = 0; n   if (!b) n     return cnt[np][b] = cntf(pre[np] + 1, b) * 2 + (pre[np] - np + 1); n   else { n     int w1 = cntf(np + 1, 0) * 2 + 1; n     int w2 = cntf(pre[np] + 1, 0) * 2 + cntf(pre[np] + 1, 1) + n              (pre[np] - np + 1) * 2; n     return cnt[np][b] = min(w1, w2); n   } n } n inline void move(int a, int b, int c, bool base, int np) { n   if (np == n) return; n   if (base) { n     int d1 = cntf(np, 1); n     int d2 = cntf(np + 1, 0) * 2 + 1; n     if (d1 == d2) { n       move(a, c, b, false, np + 1); n       out[oc][0] = a; n       out[oc][1] = b; n       oc++; n       move(c, b, a, false, np + 1); n     } else { n       move(a, b, c, false, pre[np] + 1); n       for (int i = np; i <= pre[np]; i++) { n         out[oc][0] = a; n         out[oc][1] = c; n         oc++; n       } n       move(b, a, c, false, pre[np] + 1); n       for (int i = np; i <= pre[np]; i++) { n         out[oc][0] = c; n         out[oc][1] = b; n         oc++; n       } n       move(a, b, c, true, pre[np] + 1); n     } n   } else { n     move(a, c, b, false, pre[np] + 1); n     for (int i = np; i <= pre[np]; i++) { n       out[oc][0] = a; n       out[oc][1] = b; n       oc++; n     } n     move(c, b, a, false, pre[np] + 1); n   } n } n int main() { n   int i; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &in[i]); n   } n   pre[n - 1] = n - 1; n   for (i = n - 2; i >= 0; i--) { n     if (in[i] == in[i + 1]) n       pre[i] = pre[i + 1]; n     else n       pre[i] = i; n   } n   memset(cnt, -1, sizeof(cnt)); n   oc = 0; n   move(1, 3, 2, true, 0); n   printf( %d n , oc); n   for (i = 0; i < oc; i++) printf( %d %d n , out[i][0], out[i][1]); n } n


#include <bits/stdc++.h> n using namespace std; n using std::bitset; n const double Pi = acos(-1); n inline long long read() { n   long long x = 0; n   bool fu = 0; n   char ch = 0; n   while (ch >  9  || ch <  0 ) { n     ch = getchar(); n     if (ch ==  - ) fu = 1; n   } n   while (ch <=  9  && ch >=  0 ) x = (x * 10 - 48 + ch), ch = getchar(); n   return fu ? -x : x; n } n long long n, mod, w[100002], q, l, r; n map<long long, long long> phi; n inline long long go(long long num) { n   long long rt = num; n   for (long long i = 2; i * i <= num; i++) { n     if (num % i == 0) rt = rt * (i - 1) / i; n     while (num % i == 0) num /= i; n   } n   if (num > 1) rt = rt * (num - 1) / num; n   return rt; n } n inline long long pw(long long x, long long p, long long mod) { n   bool flag = 0; n   long long rt = 1; n   while (p) { n     if (p & 1) { n       if (rt * x >= mod) flag = 1; n       rt = rt * x % mod; n     } n     if (x * x >= mod) flag = 1; n     x = x * x % mod, p >>= 1; n   } n   return rt + flag * mod; n } n inline long long dfs(long long pos, long long mod) { n   if (pos > r || mod == 1) return 1; n   return pw(w[pos], dfs(pos + 1, phi[mod]), mod); n } n signed main() { n   cin >> n >> mod; n   l = mod; n   phi[1] = 1; n   while (l > 1) phi[l] = go(l), l = phi[l]; n   for (register long long i = 1, iend = n; i <= iend; ++i) w[i] = read(); n   cin >> q; n   while (q--) { n     l = read(), r = read(); n     cout << dfs(l, mod) % mod <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const int maxn = 200; n long long x, y, l, r; n void solve() { n   set<long long> a, b, S; n   a.insert(1); n   b.insert(1); n   long long base = x; n   while (base <= INF) { n     a.insert(base); n     if (INF / base < x || x == 1) break; n     base *= x; n   } n   base = y; n   while (base <= INF) { n     b.insert(base); n     if (INF / base < y || y == 1) break; n     base *= y; n   } n   for (auto i : a) n     for (auto j : b) n       if (i + j <= r && i + j >= l) S.insert(i + j); n   S.insert(r + 1); n   long long pre = l - 1; n   long long ans = 0; n   for (auto z : S) { n     ans = max(ans, z - pre - 1); n     pre = z; n   } n   cout << ans << endl; n } n int main() { n   ios::sync_with_stdio(false); n   while (cin >> x >> y >> l >> r) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int m; n   int a[100005] = {0}; n   int b[100005] = {0}; n   cin >> s; n   s =     + s; n   cin >> m; n   for (int i = 1; i <= s.length(); i++) { n     if (s[i] == s[i + 1]) a[i] = 1; n   } n   for (int i = 1; i <= s.length(); i++) { n     b[i] = b[i - 1] + a[i]; n   } n   while (m--) { n     int l, r, flag = 0; n     cin >> l >> r; n     flag = b[r - 1] - b[l - 1]; n     cout << flag << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void test_case() { n   int n, i, cnt; n   cin >> n; n   string str; n   cin >> str; n   cnt = 0; n   vector<int> c(n + 5, 0); n   vector<int> flag(n + 5, 0); n   int fl = 0; n   for (i = n - 1; i >= 0; i--) { n     if (str[i] ==  ( ) n       cnt++; n     else n       cnt--; n     c[i] = cnt; n     if (cnt > 0) fl = 1; n     flag[i] = fl; n   } n   cnt = 0; n   int ans = 0; n   fl = 0; n   for (i = 0; i < n; i++) { n     if (fl == 0 && str[i] ==  )  && cnt + 1 == -c[i + 1] && cnt + 1 >= 0 && n         flag[i + 1] == 0) { n       ans++; n     } else if (fl == 0 && str[i] ==  (  && cnt - 1 == -c[i + 1] && n                cnt - 1 >= 0 && flag[i + 1] == 0) { n       ans++; n     } n     if (str[i] ==  ( ) n       cnt++; n     else if (str[i] ==  ) ) n       cnt--; n     if (cnt < 0) fl = 1; n   } n   cout << ans <<   n ; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int t; n   t = 1; n   while (t--) { n     test_case(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2000 + 4; n char s[maxn]; n int a[maxn]; n void get(bitset<maxn> &B) { n   scanf( %s , s); n   int m = strlen(s); n   int x = 1, y = -1; n   for (int i = 0; i < m; i++) a[m - 1 - i] = s[i] -  0 ; n   m--; n   x += m + y; n   ++x; n   for (int i = 0; i < maxn && x >= 0; i++) { n     int rem = 0; n     for (int j = m; j >= 0; j--) a[j] += rem * 10, rem = (a[j] & 1), a[j] >>= 1; n     B[i] = rem; n     while (m >= 0 && !a[m]) m--; n     x = m; n   } n } n int pos[maxn]; n bitset<maxn> b[maxn], st[maxn]; n int main() { n   if (fopen( in ,  r )) { n     freopen( in ,  r , stdin); n     freopen( out ,  w , stdout); n   } n   memset(pos, -1, sizeof(pos)); n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     get(b[i]); n     st[i][i] = 1; n     bool ok = 1; n     for (int j = 0; j < maxn; j++) n       if (b[i][j]) { n         if (pos[j] == -1) { n           ok = 0; n           pos[j] = i; n           break; n         } n         b[i] ^= b[pos[j]]; n         st[i] ^= st[pos[j]]; n       } n     if (!ok) { n       printf( 0 n ); n       continue; n     } n     st[i][i] = 0; n     printf( %d , st[i].count()); n     for (int j = 0; j < maxn; j++) n       if (st[i][j]) printf(  %d , j); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n ifstream fin; n ofstream fout; n FILE *outt, *inn; n const int N = 100009, M = 70; n int k, b[M], d[M], k2, y, yy; n unsigned long long m, c[M][M], l, r, cur; n void find() { n   for (int i = 0; i <= 64; i++) { n     for (int j = 0; j <= 64; j++) { n       if (i == 0) { n         c[i][j] = 1; n         continue; n       } n       if (i > j) continue; n       c[i][j] = c[i - 1][j - 1] + c[i][j - 1]; n     } n   } n } n int cnt; n bool is; n void binary(unsigned long long x) { n   memset(b, 0, sizeof(b)); n   is = 0; n   cnt = 69; n   while (x > 0) { n     b[--cnt] = x % 2; n     x /= 2; n   } n   b[0] = cnt; n   for (int i = b[0] + 1; i <= 68; i++) { n     if (b[i]) { n       return; n     } n   } n   is = 1; n } n unsigned long long solve(unsigned long long x) { n   cur = 0; n   binary(2 * x); n   k2 = k - 1; n   for (int i = b[0] + 1; i <= 68; i++) { n     if (b[i] == 1) { n       y = 68 - i; n       cur += c[k2][y]; n       k2--; n     } n     if (k2 == 0) { n       for (int j = i + 1; j <= 68; j++) { n         if (b[j]) { n           cur++; n           break; n         } n       } n       break; n     } n   } n   k2 = 0; n   for (int i = b[0]; i <= 68; i++) { n     if (b[i]) k2++; n   } n   if (k2 == k) cur++; n   binary(x + 1); n   if (!is) { n     k2 = k - 1; n     for (int i = b[0] + 1; i <= 68; i++) { n       if (b[i] == 0) { n         cur += c[k2 - 1][68 - i]; n       } n       if (b[i] == 1) { n         k2--; n       } n       if (k2 == 0) { n         break; n       } n     } n     k2 = 0; n     for (int i = b[0]; i <= 68; i++) { n       if (b[i]) k2++; n     } n     if (k2 == k) cur++; n   } n   return cur; n } n int main() { n   memset(c, 0, sizeof(c)); n   find(); n   cin >> m >> k; n   r = (unsigned long long)1; n   while (solve(r) < m) { n     r *= 2; n   } n   l = r / 2 + 1; n   while (l < r) { n     unsigned long long mid = (l + r) / 2; n     unsigned long long res = solve(mid); n     if (res < m) { n       l = mid + 1; n     } else if (res > m) { n       r = mid - 1; n     } else { n       cout << mid; n       return 0; n     } n   } n   cout << l; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, int>, int> ord; n vector<pair<int, int> > edges; n vector<int> adj[200000]; n int n; n int main() { n   cin >> n; n   cout << n - 1 << endl; n   for (int i = 1; i < n; i++) { n     int a, b; n     cin >> a >> b; n     edges.push_back(make_pair(a, b)); n     ord[make_pair(a, b)] = ord[make_pair(b, a)] = i; n     adj[a].push_back(b); n     adj[b].push_back(a); n     cout <<  2   << a <<     << b << endl; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < adj[i].size() - 1; j++) n       cout << ord[make_pair(i, adj[i][j])] <<     n            << ord[make_pair(i, adj[i][j + 1])] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int Max[100010 * 4], Min[100010 * 4]; n int dp_Min[100010 * 4]; n int a[100010]; n int dp[100010]; n int ql, qr, val; n void build(int l, int r, int o) { n   if (l == r) { n     Max[o] = Min[o] = a[l]; n     return; n   } n   int mid = l + (r - l) / 2; n   build(l, mid, o * 2); n   build(mid + 1, r, o * 2 + 1); n   Max[o] = max(Max[o * 2], Max[o * 2 + 1]); n   Min[o] = min(Min[o * 2], Min[o * 2 + 1]); n } n int query_max(int l, int r, int o) { n   if (ql <= l && qr >= r) { n     return Max[o]; n   } n   int mid = l + (r - l) / 2; n   int ans = -0x3f3f3f3f; n   if (ql <= mid) ans = max(ans, query_max(l, mid, o * 2)); n   if (qr > mid) ans = max(ans, query_max(mid + 1, r, o * 2 + 1)); n   return ans; n } n int query_min(int l, int r, int o) { n   if (ql <= l && qr >= r) { n     return Min[o]; n   } n   int mid = l + (r - l) / 2; n   int ans = 0x3f3f3f3f; n   if (ql <= mid) ans = min(ans, query_min(l, mid, o * 2)); n   if (qr > mid) ans = min(ans, query_min(mid + 1, r, o * 2 + 1)); n   return ans; n } n int query2(int l, int r, int o) { n   if (ql <= l && qr >= r) { n     return dp_Min[o]; n   } n   int mid = l + (r - l) / 2; n   int ans = 0x3f3f3f3f; n   if (ql <= mid) ans = min(ans, query2(l, mid, o * 2)); n   if (qr > mid) ans = min(ans, query2(mid + 1, r, o * 2 + 1)); n   return ans; n } n void update(int l, int r, int o) { n   if (l == r) { n     dp_Min[o] = val; n     return; n   } n   int mid = l + (r - l) / 2; n   if (ql <= mid) n     update(l, mid, o * 2); n   else n     update(mid + 1, r, o * 2 + 1); n   dp_Min[o] = min(dp_Min[o * 2], dp_Min[o * 2 + 1]); n } n int main() { n   int n, s, l; n   scanf( %d%d%d , &n, &s, &l); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   build(1, n, 1); n   memset(dp_Min, 0x3f3f3f3f, sizeof(dp_Min)); n   for (int i = 1; i < l; i++) dp[i] = 0x3f3f3f3f; n   for (int i = l; i <= n; i++) { n     int x = 1, y = i - l + 2; n     while (x < y) { n       int mid = x + (y - x) / 2; n       ql = mid, qr = i; n       int val = query_max(1, n, 1) - query_min(1, n, 1); n       if (val > s) n         x = mid + 1; n       else n         y = mid; n     } n     if (x == i - l + 2) { n       dp[i] = 0x3f3f3f3f; n       continue; n     } n     ql = x - 1, qr = i - l; n     if (ql <= qr && qr) n       dp[i] = query2(1, n, 1) + 1; n     else n       dp[i] = 0x3f3f3f3f; n     if (x - 1 == 0) dp[i] = 1; n     val = dp[i]; n     ql = i; n     update(1, n, 1); n   } n   printf( %d n , dp[n] >= 0x3f3f3f3f ? -1 : dp[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[100010]; n   int b[100010]; n   while (scanf( %d , &a[0]) != EOF) { n     getchar(); n     int n = 1; n     while (scanf( %d , &a[n]) != EOF) { n       n++; n       getchar(); n     } n     sort(a, a + n); n     a[n] = 9999999; n     int h = 0; n     for (int i = 0; i < n; i++) { n       if (i == 0) { n         b[h++] = a[i]; n       } else if (a[i] != a[i - 1]) { n         b[h++] = a[i]; n       } n     } n     b[h] = 99999; n     int p = b[0]; n     int q = b[0]; n     int flag = 0; n     int ff = 0; n     for (int i = 1; i <= h; i++) { n       if (b[i] == b[i - 1] + 1) { n         p = b[i]; n       } else if (b[i] != b[i - 1] + 1) { n         ff = 1; n         if (flag == 1) { n           printf( , ); n         } n         flag = 1; n         if (p == q) { n           printf( %d , p); n         } else { n           printf( %d-%d , q, p); n         } n         p = b[i]; n         q = b[i]; n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1010]; n int main() { n   long long n, k, p; n   int q; n   scanf( %I64d%I64d%d , &n, &k, &q); n   p = n - k; n   for (int i = 0; i < q; i++) scanf( %I64d , a + i); n   if (k == 0) { n     for (int i = 0; i < q; i++) printf( . ); n     return 0; n   } n   for (int i = 0; i < q; i++) { n     if (n % 2 == 0) { n       if (k <= p) { n         if (a[i] <= n - 2 * k) n           printf( . ); n         else if (a[i] % 2 == 1) n           printf( . ); n         else n           printf( X ); n       } else { n         if (a[i] > 2 * p) n           printf( X ); n         else if (a[i] % 2 == 1) n           printf( . ); n         else n           printf( X ); n       } n     } else { n       if (p < k) { n         if (a[i] <= 2 * p) { n           if (a[i] % 2 == 1) n             printf( . ); n           else n             printf( X ); n         } else n           printf( X ); n       } else { n         if (a[i] == n) n           printf( X ); n         else if (a[i] <= p - k + 1) n           printf( . ); n         else if (a[i] % 2 == 1) n           printf( . ); n         else n           printf( X ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = 3.14159265358979323846; n const int MAXN = 1e5 + 3; n long long n, a, b, p, q; n bool isLeap(int a) { n   if (a % 400 == 0) return true; n   if (a % 4 == 0 && a % 100) return true; n   return false; n } n void solve() { n   int y; n   cin >> y; n   int cnt = 0; n   bool f = 0; n   if (isLeap(y)) f = 1; n   y++; n   bool isl = 0; n   while (1) { n     cnt += 365; n     isl = isLeap(y); n     if (isl) cnt++; n     if (cnt % 7 == 0 && isl == f) break; n     y++; n   } n   cout << y; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod1 = 1e9 + 7, mod = 998244353; n const long long N = 3e5 + 7; n long long ncr[N]; n void fact(long long A) { n   auto binexp = [&](long long a, long long b) { n     long long res = 1; n     while (b) { n       if (b & 1) res *= a; n       a *= a; n       b >>= 1; n       a %= mod; n       res %= mod; n     } n     return res; n   }; n   ncr[0] = 1; n   for (long long i = 1; i <= A; i++) n     ncr[i] = ncr[i - 1] * (A - i + 1) % mod * binexp(i, mod - 2) % mod; n } n void a_b_l() { n   long long n; n   cin >> n; n   n <<= 1; n   long long ar[n]; n   for (long long i = 0; i < n; i++) cin >> ar[i]; n   sort(ar, ar + n); n   long long k = 0; n   for (long long i = 0; i < n / 2; i++) { n     k += ar[n - i - 1] - ar[i]; n     k %= mod; n   } n   fact(n); n   long long ans = k * ncr[n / 2] % mod; n   cout << ans <<   n ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   ; n   long long t = 1; n   while (t--) a_b_l(); n } n


#include <bits/stdc++.h> n using namespace std; n const double PAI = atan(1.0) * 4; n const double EPS = 1e-5; n int n; n double theta; n struct Point { n   double x, y; n   Point() {} n   Point(double _x, double _y) : x(_x), y(_y) {} n   Point operator+(const Point &r) const { return Point(x + r.x, y + r.y); } n   Point operator-(const Point &r) const { return Point(x - r.x, y - r.y); } n   Point operator*(double r) const { return Point(x * r, y * r); } n   Point operator/(double r) const { return Point(x / r, y / r); } n   Point rotate(double alpha) const { n     double s = sin(alpha), c = cos(alpha); n     return Point(x * c - y * s, x * s + y * c); n   } n   double lenght(const Point &r) const { n     return sqrt((x - r.x) * (x - r.x) + (y - r.y) * (y - r.y)); n   } n   Point cross_X(const Point &r) const { n     double l = x - r.x; n     l = l * r.y / (r.y - y); n     return Point((x * r.y - y * r.x) / (r.y - y), 0); n   } n } p[105]; n bool same(double x, double y) { return ((x - y) <= EPS && (y - x) <= EPS); } n bool check() { n   double l[105]; n   l[1] = p[1].lenght(p[n]); n   for (int i = 2; i <= n; i++) l[i] = p[i].lenght(p[i - 1]); n   for (int i = 1; i <= n; i++) { n     if (p[i].x > 1000000 || p[i].x < -1000000) return false; n     if (p[i].y > 1000000 || p[i].y < -1000000) return false; n     if (l[i] > 1000 || l[i] < 1) return false; n     for (int j = 1; j < i; j++) n       if (same(l[i], l[j])) return false; n   } n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   if (n <= 4) { n     cout <<  No solution  << endl; n     return 0; n   } n   theta = 2 * PAI / n; n   while (true) { n     p[1] = Point(0, 0); n     for (int i = 2; i <= n / 2; i++) { n       p[i] = Point(2 * i, 0); n       p[i] = p[i].rotate(theta * (i - 1)) + p[i - 1]; n     } n     p[n / 2 + 1] = Point(900, 0); n     p[n / 2 + 1] = p[n / 2 + 1].rotate(theta * (n / 2)) + p[n / 2]; n     for (int i = n / 2 + 2; i <= n; i++) { n       p[i] = Point(2 * (i - n / 2) - 1, 0); n       p[i] = p[i].rotate(theta * (i - 1)) + p[i - 1]; n     } n     p[n] = p[n - 1].cross_X(p[n]); n     if (check()) break; n   } n   for (int i = 1; i <= n; i++) printf( %lf %lf n , p[i].x, p[i].y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class point { n  public: n   int x, ind; n   point(int dx = 0, int _ind = 0) { n     x = dx; n     ind = _ind; n   } n }; n int n, k, f[210][210]; n point a[210], c[210]; n bool cmpx(point A, point B) { return A.x < B.x; } n bool cmpi(point A, point B) { return A.ind < B.ind; } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; ++i) { n     cin >> a[i].x; n     a[i].ind = i; n     c[i] = a[i]; n   } n   sort(c, c + n, cmpx); n   for (int i = 0; i < n; ++i) n     for (int j = i; j < n; ++j) n       for (int q = i; q <= j; ++q) f[i][j] += a[q].x; n   for (int i = 0; i < n; ++i) n     for (int j = i; j < n; ++j) { n       sort(a + i, a + j + 1, cmpx); n       int t = n - 1; n       int cnt = k; n       for (int q = i; q <= j; ++q) { n         while ((c[t].ind >= i) && (c[t].ind <= j) && (t >= 0)) --t; n         if ((t >= 0) && (cnt > 0) && (c[t].x > a[q].x)) { n           f[i][j] = f[i][j] - a[q].x + c[t].x; n           --t; n           --cnt; n         } else n           break; n       } n       sort(a + i, a + j + 1, cmpi); n     } n   int mx = f[0][0]; n   for (int i = 0; i < n; ++i) n     for (int j = i; j < n; ++j) n       if (mx < f[i][j]) mx = f[i][j]; n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n double h, d, c, n, mx; n int hh, mm; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> hh >> mm; n   hh = hh * 60 + mm; n   cin >> h >> d >> c >> n; n   double nec = ceil(h / n) * c; n   if (hh >= 1200 && hh < 1440) n     return cout << setprecision(5) << fixed << nec * 0.8, 0; n   mm = 20 * 60; n   int diff = mm - hh; n   double nec2 = ceil((diff * d + h) / n) * c; n   cout << setprecision(5) << fixed << min(nec2 * 0.8, nec); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static int i = 0; n int fun(long long n) { n   i++; n   if (n % 2 == 1) n     return 0; n   else n     fun(n / 2); n } n int main() { n   int n; n   long long k; n   scanf( %d %lld , &n, &k); n   fun(k); n   printf( %d , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, id[105], m, i, j; n unsigned long long cant[105], c[105], T[105], total, sol, factor, x, llevo; n bool cmp(const int i, const int j) { return c[i] < c[j]; } n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     cin >> cant[i] >> c[i]; n     total += cant[i]; n     id[i] = i; n   } n   sort(id, id + n, cmp); n   scanf( %d , &m); n   for (i = 0; i < m; i++) cin >> T[i]; n   factor = 1; n   llevo = 0; n   i = 0; n   while (total > 0 && i < m) { n     if (llevo == T[i]) factor++, i++; n     j = 0; n     while (total > 0 && i < m && llevo < T[i]) { n       x = min(cant[id[j]], T[i] - llevo); n       cant[id[j]] -= x; n       total -= x; n       sol += x * factor * c[id[j]]; n       llevo += x; n       j++; n     } n   } n   for (i = 0; i < n; i++) sol += cant[i] * factor * c[i]; n   cout << sol << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct segment { n   int l, r, p; n } seg[300005]; n struct PS { n   int l, r, val; n } P[300005 * 20]; n int n, m, k, a, b, l, r, tot; n int suf[300005]; n int get(int node, int bas, int son, int x, int y) { n   if (bas >= x && son <= y) return P[node].val; n   bool l = (((bas + son) >> 1) >= x); n   bool r = (((bas + son) >> 1) + 1 <= y); n   if (l & r) n     return max(get(P[node].l, bas, ((bas + son) >> 1), x, y), n                get(P[node].r, ((bas + son) >> 1) + 1, son, x, y)); n   if (l) return get(P[node].l, bas, ((bas + son) >> 1), x, y); n   return get(P[node].r, ((bas + son) >> 1) + 1, son, x, y); n } n void create(int& node) { n   node = ++tot; n   P[node].val = 1005000000; n } n void up(int& node, int prv, int bas, int son, int x, int val) { n   if (!node) create(node); n   if (bas == x && son == x) { n     P[node].val = min(val, P[prv].val); n     return; n   } n   if (x <= ((bas + son) >> 1)) { n     P[node].r = P[prv].r; n     up(P[node].l, P[prv].l, bas, ((bas + son) >> 1), x, val); n   } else { n     P[node].l = P[prv].l; n     up(P[node].r, P[prv].r, ((bas + son) >> 1) + 1, son, x, val); n   } n   P[node].val = max(P[P[node].l].val, P[P[node].r].val); n } n int main() { n   P[0].val = 1005000000; n   scanf( %d %d %d , &n, &m, &k); n   for (int i = 1; i <= k; i++) { n     scanf( %d %d %d , &seg[i].l, &seg[i].r, &seg[i].p); n   } n   sort(seg + 1, seg + 1 + k, [](segment a, segment b) { return a.l < b.l; }); n   for (int i = k; i >= 1; i--) { n     up(suf[i], suf[i + 1], 1, n, seg[i].p, seg[i].r); n   } n   while (m--) { n     scanf( %d %d %d %d , &a, &b, &l, &r); n     int bas = 1, son = k; n     while (bas <= son) { n       if (seg[((bas + son) >> 1)].l < l) n         bas = ((bas + son) >> 1) + 1; n       else n         son = ((bas + son) >> 1) - 1; n     } n     printf(get(suf[bas], 1, n, a, b) > r ?  no  :  yes ); n     puts(  ); n     fflush(stdout); n   } n } n