#include <bits/stdc++.h> n using namespace std; n template <typename flow_t = int, typename cost_t = int> n struct mcSFlow { n   struct Edge { n     cost_t c; n     flow_t f; n     int to, rev; n     Edge(int _to, cost_t _c, flow_t _f, int _rev) n         : c(_c), f(_f), to(_to), rev(_rev) {} n   }; n   const cost_t INFCOST = numeric_limits<cost_t>::max() / 2; n   const cost_t INFFLOW = numeric_limits<flow_t>::max() / 2; n   cost_t epsilon; n   int N, S, T; n   vector<vector<Edge> > G; n   vector<unsigned int> isEnqueued, state; n   mcSFlow(int _N, int _S, int _T) : epsilon(0), N(_N), S(_S), T(_T), G(_N) {} n   void add_edge(int a, int b, cost_t cost, flow_t cap) { n     if (a == b) { n       assert(cost >= 0); n       return; n     } n     cost *= N; n     epsilon = max(epsilon, abs(cost)); n     assert(a >= 0 && a < N && b >= 0 && b < N); n     G[a].emplace_back(b, cost, cap, G[b].size()); n     G[b].emplace_back(a, -cost, 0, G[a].size() - 1); n   } n   flow_t calc_max_flow() { n     vector<flow_t> dist(N), state(N); n     vector<Edge *> path(N); n     auto cmp = [](Edge *a, Edge *b) { return a->f < b->f; }; n     flow_t addFlow, retflow = 0; n     ; n     do { n       fill(dist.begin(), dist.end(), -1); n       dist[S] = 0; n       auto head = state.begin(), tail = state.begin(); n       for (*tail++ = S; head != tail; ++head) { n         for (Edge const &e : G[*head]) { n           if (e.f && dist[e.to] == -1) { n             dist[e.to] = dist[*head] + 1; n             *tail++ = e.to; n           } n         } n       } n       addFlow = 0; n       fill(state.begin(), state.end(), 0); n       auto top = path.begin(); n       Edge dummy(S, 0, INFFLOW, -1); n       *top++ = &dummy; n       while (top != path.begin()) { n         int n = (*prev(top))->to; n         if (n == T) { n           auto next_top = min_element(path.begin(), top, cmp); n           flow_t flow = (*next_top)->f; n           while (--top != path.begin()) { n             Edge &e = **top, &f = G[e.to][e.rev]; n             e.f -= flow; n             f.f += flow; n           } n           addFlow = 1; n           retflow += flow; n           top = next_top; n           continue; n         } n         for (flow_t &i = state[n], i_max = G[n].size(), need = dist[n] + 1;; n              ++i) { n           if (i == i_max) { n             dist[n] = -1; n             --top; n             break; n           } n           if (dist[G[n][i].to] == need && G[n][i].f) { n             *top++ = &G[n][i]; n             break; n           } n         } n       } n     } while (addFlow); n     return retflow; n   } n   vector<flow_t> excess; n   vector<cost_t> h; n   void push(Edge &e, flow_t amt) { n     if (e.f < amt) amt = e.f; n     e.f -= amt; n     excess[e.to] += amt; n     G[e.to][e.rev].f += amt; n     excess[G[e.to][e.rev].to] -= amt; n   } n   void relabel(int vertex) { n     cost_t newHeight = -INFCOST; n     for (unsigned int i = 0; i < G[vertex].size(); ++i) { n       Edge const &e = G[vertex][i]; n       if (e.f && newHeight < h[e.to] - e.c) { n         newHeight = h[e.to] - e.c; n         state[vertex] = i; n       } n     } n     h[vertex] = newHeight - epsilon; n   } n   const int scale = 2; n   pair<flow_t, cost_t> minCostFlow() { n     cost_t retCost = 0; n     for (int i = 0; i < N; ++i) { n       for (Edge &e : G[i]) { n         retCost += e.c * (e.f); n       } n     } n     flow_t retFlow = calc_max_flow(); n     excess.resize(N); n     h.resize(N); n     queue<int> q; n     isEnqueued.assign(N, 0); n     state.assign(N, 0); n     for (; epsilon; epsilon >>= scale) { n       fill(state.begin(), state.end(), 0); n       for (int i = 0; i < N; ++i) n         for (auto &e : G[i]) n           if (h[i] + e.c - h[e.to] < 0 && e.f) push(e, e.f); n       for (int i = 0; i < N; ++i) { n         if (excess[i] > 0) { n           q.push(i); n           isEnqueued[i] = 1; n         } n       } n       while (!q.empty()) { n         int cur = q.front(); n         q.pop(); n         isEnqueued[cur] = 0; n         while (excess[cur] > 0) { n           if (state[cur] == G[cur].size()) { n             relabel(cur); n           } n           for (unsigned int &i = state[cur], max_i = G[cur].size(); i < max_i; n                ++i) { n             Edge &e = G[cur][i]; n             if (h[cur] + e.c - h[e.to] < 0) { n               push(e, excess[cur]); n               if (excess[e.to] > 0 && isEnqueued[e.to] == 0) { n                 q.push(e.to); n                 isEnqueued[e.to] = 1; n               } n               if (excess[cur] == 0) break; n             } n           } n         } n       } n       if (epsilon > 1 && epsilon >> scale == 0) { n         epsilon = 1 << scale; n       } n     } n     for (int i = 0; i < N; ++i) { n       for (Edge &e : G[i]) { n         retCost -= e.c * (e.f); n       } n     } n     return make_pair(retFlow, retCost / 2 / N); n   } n   flow_t getFlow(Edge const &e) { return G[e.to][e.rev].f; } n }; n const int N = 260, M = 30, inf = 1e5 + 42; n int a[N]; n char var[N]; n int val[M]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   int act_source = 0, source = 1, sink = 2 * n + 2; n   mcSFlow<long long, long long> mf(sink + 1, act_source, sink); n   mf.add_edge(act_source, source, 0, m); n   mf.add_edge(source, sink, 0, inf); n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     mf.add_edge(source, 2 * i, __builtin_popcount(a[i]), inf); n     mf.add_edge(2 * i, 2 * i + 1, -inf, 1); n     mf.add_edge(2 * i + 1, sink, 0, inf); n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = i + 1; j <= n; ++j) { n       mf.add_edge(2 * i + 1, 2 * j, n                   (a[i] == a[j]) ? 0 : __builtin_popcount(a[j]), inf); n     } n   } n   auto ans = mf.minCostFlow(); n   assert(ans.first == m); n   ans.second += n * inf; n   char nxt_var =  a ; n   for (int i = 1; i <= n; ++i) { n     if (!var[i]) { n       var[i] = nxt_var++; n     } n     for (auto &e : mf.G[2 * i + 1]) { n       if (mf.getFlow(e) == 1 and e.to != sink) { n         var[e.to / 2] = var[i]; n         break; n       } n     } n   } n   vector<string> events; n   for (int i = 1; i <= n; ++i) { n     if (val[var[i] -  a ] != a[i]) { n       val[var[i] -  a ] = a[i]; n       events.push_back(var[i] + string( = ) + to_string(a[i])); n     } n     events.push_back(string( print( ) + var[i] + string( ) )); n   } n   cout << events.size() <<     << ans.second <<   n ; n   for (auto &s : events) { n     cout << s <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000010; n int n, a, b, cur, h[maxn], nxt[maxn * 2], p[maxn * 2]; n void add_edge(int x, int y) { n   cur++; n   nxt[cur] = h[x]; n   h[x] = cur; n   p[cur] = y; n } n int tid, dfn[maxn], dep[maxn], lg[maxn], fa[maxn][25]; n void dfs(int x, int f) { n   dfn[x] = ++tid; n   for (int j = h[x]; j; j = nxt[j]) n     if (p[j] != f) fa[p[j]][0] = x, dep[p[j]] = dep[x] + 1, dfs(p[j], x); n } n int LCA(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   int k = dep[x] - dep[y]; n   for (int i = lg[k]; i >= 0; i--) n     if (k & (1 << i)) x = fa[x][i]; n   if (x == y) return x; n   for (int i = lg[dep[x]]; i >= 0; i--) n     if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i]; n   return fa[x][0]; n } n int q, k, s[maxn], st[maxn], top, f[maxn], gg[maxn]; n bool tf[maxn], jud; n bool cmp(int x, int y) { return dfn[x] < dfn[y]; } n int lst[maxn]; n vector<pair<int, int> > g[maxn]; n void DP(int x) { n   f[x] = 0; n   gg[x] = 0; n   for (vector<pair<int, int> >::iterator it = g[x].begin(); it != g[x].end(); n        it++) { n     DP(it->first); n     f[x] += f[it->first]; n     if (tf[x] && tf[it->first] && it->second == 1) jud = false; n   } n   if (tf[x]) { n     gg[x] = 1; n     for (vector<pair<int, int> >::iterator it = g[x].begin(); it != g[x].end(); n          it++) n       f[x] += gg[it->first]; n     return; n   } else { n     int cnt = 0; n     for (vector<pair<int, int> >::iterator it = g[x].begin(); it != g[x].end(); n          it++) n       if (gg[it->first]) cnt++; n     if (cnt == 0) n       gg[x] = 0; n     else if (cnt == 1) n       gg[x] = 1; n     else n       f[x]++; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) lg[i] = lg[i / 2] + 1; n   for (int i = 1; i < n; i++) n     scanf( %d%d , &a, &b), add_edge(a, b), add_edge(b, a); n   dep[1] = 1; n   dfs(1, 0); n   for (int i = 1; i <= lg[n]; i++) n     for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1]; n   scanf( %d , &q); n   for (int T = 1; T <= q; T++) { n     scanf( %d , &k); n     for (int i = 1; i <= k; i++) scanf( %d , s + i), tf[s[i]] = true; n     sort(s + 1, s + k + 1, cmp); n     top = 0; n     st[++top] = 0; n     for (int i = 1; i <= k; i++) { n       int t = LCA(s[i], st[top]); n       if (t != st[top]) { n         while (dfn[t] <= dfn[st[top - 1]]) { n           if (lst[st[top - 1]] < T) n             g[st[top - 1]].clear(), lst[st[top - 1]] = T; n           g[st[top - 1]].push_back({st[top], dep[st[top]] - dep[st[top - 1]]}); n           top--; n         } n         if (t != st[top]) { n           if (lst[t] < T) g[t].clear(), lst[t] = T; n           g[t].push_back({st[top], dep[st[top]] - dep[t]}); n           st[top] = t; n         } n       } n       st[++top] = s[i]; n     } n     while (top > 1) { n       if (lst[st[top - 1]] < T) g[st[top - 1]].clear(), lst[st[top - 1]] = T; n       g[st[top - 1]].push_back({st[top], dep[st[top]] - dep[st[top - 1]]}); n       top--; n     } n     jud = true; n     DP(st[1]); n     if (!jud) n       printf( -1 n ); n     else n       printf( %d n , f[st[1]]); n     for (int i = 1; i <= k; i++) tf[s[i]] = false; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int N, M, Max = 0, Maxj = 0, A[1000][1000], arr[1000][1] = {}; n int main() { n   cin >> N >> M; n   for (int i = 0; i < M; i++) { n     Max = -1; n     for (int j = 0; j < N; j++) { n       cin >> A[i][j]; n       if (Max < A[i][j]) { n         Max = A[i][j]; n         Maxj = j; n       } n     } n     arr[Maxj][0]++; n   } n   long long int max = 0, ind = 1; n   for (int i = 0; i < N; i++) { n     if (max < arr[i][0]) { n       max = arr[i][0]; n       ind = i + 1; n     } n   } n   cout << ind; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2 * 1e5 + 100; n long long n, k, s, t, c[N], v[N], g[N], d[N], sum[N]; n inline long long read() { n   long long f = 1, x = 0; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = x * 10 + s -  0 ; n     s = getchar(); n   } n   return x * f; n } n signed main() { n   n = read(); n   k = read(); n   s = read(); n   t = read(); n   for (long long i = 1; i <= n; i++) c[i] = read(), v[i] = read(); n   for (long long i = 1; i <= k; i++) g[i] = read(); n   sort(g + 1, g + 1 + k); n   for (long long i = 1; i <= k; i++) d[i] = g[i] - g[i - 1]; n   d[k + 1] = s - g[k]; n   k++; n   sort(d + 1, d + 1 + k); n   for (long long i = 1; i <= k; i++) sum[i] = sum[i - 1] + d[i]; n   if (t < s) { n     printf( -1 n ); n     return 0; n   } n   long long MIN = 0x3f3f3f3f; n   for (long long i = 1; i <= n; i++) { n     if (v[i] < d[k]) continue; n     long long pos = upper_bound(d + 1, d + 1 + k, v[i] / 2) - d - 1; n     long long all = sum[pos] + (sum[k] - sum[pos]) * 3 - (k - pos) * v[i]; n     if (all <= t) MIN = min(MIN, c[i]); n   } n   if (MIN == 0x3f3f3f3f) n     printf( -1 n ); n   else n     printf( %lld n , MIN); n } n


#include  bits/stdc++.h  n using namespace std; n  n int main() n { n  ios::sync_with_stdio (0) ; cin.tie (0) ; n  int T ; n  cin >> T ; n  while ( T-- ) n  { n   long x, y; n   cin >> x >> y ; n   cout << x - 1 <<     << y << endl ; n  } n }


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, m; n   cin >> n >> m; n   long long vmax = n - (m - 1); n   long long kmax = vmax * (vmax - 1) / 2; n   long long vmin = n / m; n   long long vmin_add = n - vmin * m; n   long long kmin = n       (m - vmin_add) * vmin * (vmin - 1) / 2 + vmin_add * (vmin + 1) * vmin / 2; n   cout << kmin <<     << kmax; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; } n inline int read() { n   int x = 0, f = 1; n   char cc = getchar(); n   while (cc <  0  || cc >  9 ) { n     if (cc ==  - ) f = -1; n     cc = getchar(); n   } n   while (cc >=  0  && cc <=  9 ) { n     x = x * 10 + cc -  0 ; n     cc = getchar(); n   } n   return x * f; n } n const int maxn = 100; n int c[maxn]; n int n, a, b; n int main() { n   n = read(); n   a = read(); n   b = read(); n   int cost = 0; n   for (int i = 0; i < n; i++) scanf( %d , c + i); n   for (int i = 0; i < n / 2; i++) { n     if (c[i] != 2 && c[n - 1 - i] != 2) { n       if (c[i] != c[n - 1 - i]) { n         puts( -1 ); n         return 0; n       } n     } else if (c[i] == 1 || c[n - i - 1] == 1) { n       cost += b; n     } else if (c[i] == 2 && c[n - i - 1] == 2) { n       cost += 2 * min(a, b); n     } else n       cost += a; n   } n   if (n % 2) { n     if (c[n / 2] == 2) { n       cost += min(a, b); n     } n   } n   cout << cost << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class ConvexHullTrick { n  public: n   vector<long long int> a, b; n   int size = -1; n   bool can_remove(int a, int b, int c, int d) { n     if (a / b != c / d) return a / b < c / d; n     a %= b; n     c %= d; n     if (a == 0) return true; n     if (c == 0) return false; n     return can_remove(d, c, b, a); n   } n   void add(long long int i, long long int j) { n     size++; n     a.push_back(i); n     b.push_back(j); n     while (size >= 2 && n            can_remove(b[size - 1] - b[size], a[size] - a[size - 1], n                       b[size - 2] - b[size - 1], a[size - 1] - a[size - 2])) { n       a.erase(a.end() - 2); n       b.erase(b.end() - 2); n       size--; n     } n   } n   double iniInterval(int i) { n     if (i == 0) return -1000000010; n     return ((double)b[i] - b[i - 1]) / (a[i - 1] - a[i]); n   } n   long long int query(int x) { n     int i = 0, j = size; n     while (i < j) { n       int m = (i == j - 1) ? j : (i + j) / 2; n       if (iniInterval(m) <= (double)x) n         i = m; n       else n         j = m - 1; n     } n     return a[i] * x + b[i]; n   } n }; n struct node { n   int ini, fim; n   ConvexHullTrick CHT; n } SEG[4 * 100010]; n int n, q, n1, n2; n int v[100010]; n long long int sv[100010]; n void merge(int i, int f1, int f2) { n   int p = 0, q = 0; n   for (; p <= SEG[f1].CHT.size && q <= SEG[f2].CHT.size;) { n     long long int a1 = SEG[f1].CHT.a[p]; n     long long int b1 = SEG[f1].CHT.b[p]; n     long long int a2 = SEG[f2].CHT.a[q]; n     long long int b2 = SEG[f2].CHT.b[q]; n     if (a1 == a2) { n       SEG[i].CHT.add(a1, min(b1, b2)); n       p++; n       q++; n     } else if (a1 > a2) { n       SEG[i].CHT.add(a1, b1); n       p++; n     } else { n       SEG[i].CHT.add(a2, b2); n       q++; n     } n   } n   for (; p <= SEG[f1].CHT.size;) { n     SEG[i].CHT.add(SEG[f1].CHT.a[p], SEG[f1].CHT.b[p]); n     p++; n   } n   for (; q <= SEG[f2].CHT.size;) { n     SEG[i].CHT.add(SEG[f2].CHT.a[q], SEG[f2].CHT.b[q]); n     q++; n   } n } n void build(int id, int i, int j) { n   SEG[id].ini = i; n   SEG[id].fim = j; n   if (i == j) return void(SEG[id].CHT.add(v[i], v[i] * i - sv[i])); n   int m = (i + j) / 2; n   build(2 * id, i, m); n   build(2 * id + 1, m + 1, j); n   merge(id, 2 * id, 2 * id + 1); n } n long long int query(int id, int i, int j, int k) { n   if (SEG[id].ini > j || SEG[id].fim < i) n     return ((long long int)1000000010) * 1000000010; n   if (SEG[id].ini >= i && SEG[id].fim <= j) return SEG[id].CHT.query(k); n   return min(query(2 * id, i, j, k), query(2 * id + 1, i, j, k)); n } n int main() { n   scanf( %d , &n); n   for (int g = 1; g <= n; g++) { n     scanf( %d , &v[g]); n     sv[g] = sv[g - 1] + v[g]; n   } n   build(1, 1, n); n   scanf( %d , &q); n   for (int g = 0; g < q; g++) { n     scanf( %d %d , &n1, &n2); n     printf( %lld n , query(1, n2 - n1 + 1, n2, n1 - n2) + sv[n2]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int bits(int num) { n   int c = 0; n   while (num > 0) { n     c++; n     num = num / 2; n   } n   return c; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int i; n     long long int a[n]; n     for (i = 0; i < n; i++) cin >> a[i]; n     vector<long long int> v; n     for (i = 0; i < n; i++) { n       int temp = bits(a[i]); n       v.push_back(temp); n     } n     map<long long int, long long int> mp; n     for (i = 0; i < v.size(); i++) { n       mp[v[i]]++; n     } n     long long int ans = 0; n     map<long long int, long long int>::iterator it; n     for (it = mp.begin(); it != mp.end(); it++) { n       ans = ans + ((it->second) * (it->second - 1)) / 2; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[100][100]; n vector<long long> can; n int test; n int r(long long a, long long b) { n   if ((a == 0) || (b == 0)) return 0; n   int k = r(b % a, a); n   if (k == 0) return 1; n   long long v = (b % a); n   v += a; n   long long c = (b - v) / a; n   if (a & 1) { n     int res = (c & 1); n     return res; n   } n   c %= (a + 1); n   if (c == a) return 1; n   int res = (c & 1); n   return res; n } n int brut(int a, int b) { n   if (dp[a][b] != -1) return dp[a][b]; n   if ((a == 0) || (b == 0)) return 0; n   int res = brut(b % a, a); n   if (res == 0) return dp[a][b] = 1; n   int v = a; n   while (b - v >= 0) { n     int nb = b - v; n     res = min(res, brut(min(nb, a), max(nb, a))); n     v *= a; n   } n   res ^= 1; n   return dp[a][b] = res; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     long long a, b; n     cin >> a >> b; n     if (a > b) swap(a, b); n     int res = r(a, b); n     if (res) n       printf( First n ); n     else n       printf( Second n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n const int LOG = 20; n const int CNTSZ = 30; n const long long INF = 1e18; n const int MOD = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m, k; n   cin >> n >> m >> k; n   vector<pair<long long, pair<int, int>>> edges(m); n   for (int i = 0; i < int(m); i++) { n     cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first; n     edges[i].second.first--; n     edges[i].second.second--; n   } n   sort(edges.begin(), edges.end()); n   set<int> vrt; n   for (int i = 0; i < int(min(m, k)); i++) n     vrt.insert(edges[i].second.first), vrt.insert(edges[i].second.second); n   vector<int> vertex; n   for (int x : vrt) vertex.push_back(x); n   n = (int)(vrt).size(); n   vector<vector<long long>> dp(n, vector<long long>(n, INF)); n   for (int i = 0; i < int(n); i++) dp[i][i] = 0; n   for (int i = 0; i < int(min(m, k)); i++) { n     int u = n         (int)(lower_bound(vertex.begin(), vertex.end(), edges[i].second.first) - n               vertex.begin()); n     int v = (int)(lower_bound(vertex.begin(), vertex.end(), n                               edges[i].second.second) - n                   vertex.begin()); n     dp[u][v] = dp[v][u] = min(dp[u][v], edges[i].first); n   } n   for (int l = 0; l < int(n); l++) { n     for (int i = 0; i < int(n); i++) { n       for (int j = 0; j < int(n); j++) { n         dp[i][j] = min(dp[i][j], dp[i][l] + dp[l][j]); n       } n     } n   } n   vector<long long> ans; n   for (int i = 0; i < int(n); i++) n     for (int j = 0; j < int(i); j++) ans.push_back(dp[i][j]); n   sort(ans.begin(), ans.end()); n   cout << ans[k - 1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct ako { n   int b2, c2, d; n   ako(int B = -1, int C = -1, int D = -1) : b2(B), c2(C), d(D) {} n }; n const int minb = -2000, maxb = 4000, maxa = 1005; n ako vis[maxb - minb + 79][maxa]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int a; n   cin >> a; n   queue<pair<int, int>> q; n   q.push({0, 0}); n   while (!q.empty() && vis[-minb][0].d == -1) { n     int b = q.front().first, c = q.front().second; n     q.pop(); n     for (int d = 0; d < 10; d++) { n       if (b == 0 && c == 0 && d == 0) continue; n       int nwb = b + a * ((c + a * d) % 10) - d, nwc = (c + a * d) / 10; n       if (minb > nwb || maxb < nwb || vis[nwb - minb][nwc].d != -1) continue; n       vis[nwb - minb][nwc] = ako(b, c, d); n       q.push({nwb, nwc}); n     } n   } n   string ans; n   if (vis[-minb][0].d != -1) { n     int b = 0, c = 0; n     while (true) { n       ako k = vis[b - minb][c]; n       if (!ans.empty() || k.d) ans.push_back( 0  + k.d); n       if (k.b2 == 0 && k.c2 == 0) break; n       tie(b, c) = {k.b2, k.c2}; n     } n   } else n     ans =  -1 ; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1E5 + 5; n int MOD = (int)1E9 + 7; n namespace CHT { n struct cnode { n   int s; n   int e; n   int ls; n   int rs; n   int res; n } nodes[N * 40]; n void copy(int s, int d) { n   nodes[d].s = nodes[s].s; n   nodes[d].e = nodes[s].e; n   nodes[d].ls = nodes[s].ls; n   nodes[d].rs = nodes[s].rs; n   nodes[d].res = nodes[s].res; n } n int roots[N << 1]; n int allo = 0; n int build(int s, int e) { n   if (s == e) { n     nodes[allo] = {s, e, -1, -1, 0}; n     return allo++; n   } n   int m = s + e >> 1; n   int temp = allo++; n   int l = build(s, m); n   int r = build(m + 1, e); n   nodes[temp] = {s, e, l, r, 0}; n   return temp; n } n void add(int i, int pos, int val) { n   roots[i] = allo++; n   int c1 = roots[i - 1]; n   int c2 = roots[i]; n   while (1) { n     copy(c1, c2); n     nodes[c2].res += val; n     if (nodes[c1].s == nodes[c1].e) break; n     int m = nodes[c1].s + nodes[c1].e >> 1; n     if (pos <= m) { n       nodes[c2].ls = allo++; n       c2 = nodes[c2].ls; n       c1 = nodes[c1].ls; n     } else { n       nodes[c2].rs = allo++; n       c2 = nodes[c2].rs; n       c1 = nodes[c1].rs; n     } n   } n } n int query(int s, int e, int r) { n   if (s == nodes[r].s && e == nodes[r].e) return nodes[r].res; n   int m = nodes[r].s + nodes[r].e >> 1; n   if (e <= m) { n     return query(s, e, nodes[r].ls); n   } else if (s >= m + 1) { n     return query(s, e, nodes[r].rs); n   } else { n     int p1 = query(s, m, nodes[r].ls); n     int p2 = query(m + 1, e, nodes[r].rs); n     return p1 + p2; n   } n } n }  // namespace CHT n using namespace CHT; n namespace fastIO { n void read(int &n) { n   char ch =    ; n   int q = 0, w = 1; n   for (; (ch !=  - ) && ((ch <  0 ) || (ch >  9 )); ch = getchar()) n     ; n   if (ch ==  - ) w = -1, ch = getchar(); n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) q = q * 10 + ch - 48; n   n = q * w; n } n void read(long long &n) { n   char ch =    ; n   long long q = 0, w = 1; n   for (; (ch !=  - ) && ((ch <  0 ) || (ch >  9 )); ch = getchar()) n     ; n   if (ch ==  - ) w = -1, ch = getchar(); n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) q = q * 10 + ch - 48; n   n = q * w; n } n void write(long long x) { n   if (x == 0) { n     putchar( 0 ); n     return; n   } n   if (x < 0) x = -x, putchar( - ); n   int d[21]; n   d[0] = 0; n   while (x) d[++d[0]] = x % 10, x /= 10; n   for (; d[0]; d[0]--) putchar(d[d[0]] +  0 ); n } n };  // namespace fastIO n using namespace fastIO; n vector<int> vs[N]; n void solve() { n   int n, k, temp, q; n   read(n); n   read(k); n   roots[0] = build(1, n); n   for (int i = 1; i <= n; i++) { n     read(temp); n     vs[temp].push_back(i); n     if (vs[temp].size() > k) { n       add(2 * i - 1, vs[temp][vs[temp].size() - 1 - k], -1); n     } else { n       add(2 * i - 1, 1, 0); n     } n     add(2 * i, i, 1); n   } n   read(q); n   int last = 0; n   for (int i = 0; i < q; i++) { n     int a, b; n     read(a), read(b); n     a = (last + a) % n + 1; n     b = (last + b) % n + 1; n     if (a > b) swap(a, b); n     last = query(a, b, roots[2 * b]); n     write(last); n     printf(  n ); n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   cin >> a; n   stack<char> s; n   for (int i = 0; i < a.size(); i++) { n     if (s.empty() || s.top() != a[i]) n       s.push(a[i]); n     else n       s.pop(); n   } n   if (s.empty()) n     cout <<  Yes ; n   else n     cout <<  No ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, d, m, s; n   cin >> n >> d; n   vector<pair<int, int> > v; n   vector<int> money; n   for (int i = 0; i < n; i++) { n     cin >> m >> s; n     pair<int, int> p = make_pair(m, s); n     v.push_back(p); n     money.push_back(m); n   } n   sort(v.begin(), v.end()); n   sort(money.begin(), money.end()); n   vector<unsigned long long> pref; n   pref.push_back(0); n   int i; n   for (i = 0; i < n; i++) { n     pref.push_back(v[i].second + pref[i]); n   } n   for (i = 0; i <= n; i++) { n   } n   unsigned long long max = 0; n   int index; n   for (i = 0; i < n; i++) { n     vector<int>::iterator up; n     up = upper_bound(money.begin(), money.end(), v[i].first + d - 1); n     if (pref[up - money.begin()] - pref[i] > max) n       max = pref[up - money.begin()] - pref[i]; n   } n   cout << max << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long a[1001]; n   long i, j, k = 0, l, n; n   scanf( %ld , &n); n   for (i = 0; i < n; i++) { n     scanf( %ld , &a[i]); n   } n   sort(a, a + n); n   if (a[0] == a[1] && a[0] != 0) k++; n   for (i = 2; i < n; i++) { n     if (a[i] == a[i - 1] && a[i - 1] == a[i - 2] && a[i] != 0) { n       printf( -1 n ); n       return 0; n     } else if (a[i] == a[i - 1] && a[i] != 0) { n       k++; n     } n   } n   printf( %ld n , k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pairvar { n   int a; n   int b; n }; n bool isPrime(long long x) { n   if (x == 1) { n     return false; n   } n   long long a = (long long)x; n   for (int i = 2; i <= (long long)sqrt((double)a); i++) { n     if (a % i == 0) { n       return false; n     } n   } n   return true; n } n int gcd(int a, int b) { n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n long long factorial(long long x) { n   long long sum = 1; n   for (long long i = 1; i <= x; i++) { n     sum *= i; n   } n   return sum; n } n int toint(string s) { n   int x = 0; n   int k = (int)pow(10, (double)s.length() - 1); n   for (int i = 0; i < (int)s.length(); i++) { n     x += (s[i] -  0 ) * k; n     k /= 10; n   } n   return x; n } n string tostr(int x) { n   if (x == 0) { n     return  0 ; n   } n   string s =   ; n   bool f = x < 0; n   x = abs(x); n   while (x != 0) { n     s += (x % 10) +  0 ; n     x /= 10; n   } n   string t =   ; n   if (f) { n     t =  - ; n   } n   for (int i = s.length() - 1; i >= 0; i--) { n     t += s[i]; n   } n   return t; n } n int lcm(int a, int b) { return (a * b) / gcd(a, b); } n string tobin(int a) { n   string s; n   while (a != 0) { n     s +=  0  + (a % 2); n     a /= 2; n   } n   string r =   ; n   for (int i = s.length() - 1; i >= 0; i--) { n     r += s[i]; n   } n   return r; n } n bool cmp(const pair<int, int> &a, const pair<int, int> &b) { n   if (a.first == b.first) { n     return a.second < b.second; n   } n   return a.first < b.first; n } n int cnt[2000005]; n int main() { n   int n; n   cin >> n; n   set<int> w; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     w.insert(x); n     cnt[x] = i; n   } n   int mn = 1000000000; n   int ans = 0; n   for (int i = 0; i < 200005; i++) { n     if (cnt[i] < mn && cnt[i] && w.find(i) != w.end()) { n       mn = cnt[i]; n       ans = i; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int f[100010]; n int main() { n   int x; n   cin >> n; n   for (int i = 0; i <= n - 1; i++) { n     cin >> x; n     f[x]++; n   } n   for (int i = 100000; i >= 0; i--) { n     if (f[i] & 1) { n       printf( Conan n ); n       return 0; n     } n   } n   printf( Agasa n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x60000000; n const int MINF = -1000000000; n const int mod = 1000000007; n const int cons = 100001; n const double pi = 3.141592653589793; n const int sqrtMax = 317; n const int blocks = cons / 3; n const int MOD = 100000; n long long dp[1000001]; n int ans[5001]; n int main() { n   int m; n   scanf( %d , &m); n   for (int n = 1; n <= 50; n++) { n     int cnt = 0; n     int sum = 0; n     memset(dp, 0, sizeof(dp)); n     for (int i = 0; i <= n; i++) { n       for (int j = 0; j <= n; j++) { n         for (int k = 0; k <= n; k++) { n           for (int p = 0; p <= n; p++) { n             if (i + j + k + p == n) { n               sum = i * 1 + j * 5 + k * 10 + p * 50; n               dp[sum]++; n               if (dp[sum] > 1) { n               } else if (dp[sum] == 1) n                 cnt++; n             } n           } n         } n       } n     } n     ans[n] = cnt; n   } n   if (m > 50) { n     printf( %lld n , (long long)ans[50] + 49LL * (m - 50)); n   } else { n     printf( %d n , ans[m]); n   } n   return 0; n } n


#include <bits/stdc++.h> n struct Widget { n   std::string name; n   long long width, height; n   Widget(const std::string& name, long long width, long long height) n       : name(name), width(width), height(height) {} n   ~Widget() {} n   virtual void calculateSize() {} n }; n struct Box : public Widget { n   int spacing, border; n   std::vector<Widget*> children; n   Box(const std::string& name) : Widget(name, 0, 0), spacing(0), border(0) {} n }; n struct HBox : public Box { n   HBox(const std::string& name) : Box(name) {} n   virtual void calculateSize() { n     if (children.empty()) { n       width = 0; n       height = 0; n       return; n     } n     if (width == 0 && height == 0) { n       for (std::vector<Widget*>::iterator i = children.begin(); n            i != children.end(); ++i) { n         (*i)->calculateSize(); n         width += (*i)->width; n         height = std::max(height, (*i)->height); n       } n       width += (children.size() - 1) * spacing + 2 * border; n       height += 2 * border; n     } n   } n }; n struct VBox : public Box { n   VBox(const std::string& name) : Box(name) {} n   virtual void calculateSize() { n     if (children.empty()) { n       width = 0; n       height = 0; n       return; n     } n     if (width == 0 && height == 0) { n       for (std::vector<Widget*>::iterator i = children.begin(); n            i != children.end(); ++i) { n         (*i)->calculateSize(); n         width = std::max(width, (*i)->width); n         height += (*i)->height; n       } n       height += (children.size() - 1) * spacing + 2 * border; n       width += 2 * border; n     } n   } n }; n int main() { n   int n; n   std::cin >> n; n   std::map<std::string, Widget*> map; n   for (int i = 0; i < n; ++i) { n     std::string s; n     std::cin >> s; n     if (s ==  Widget ) { n       std::cin >> s; n       std::string::size_type lparen = s.find( ( ); n       std::string name = s.substr(0, lparen); n       std::string::size_type comma = s.find( , , lparen + 1); n       std::string::size_type rparen = s.find( ) , comma + 1); n       int width = n           strtol(s.substr(lparen + 1, comma - lparen - 1).c_str(), 0, 10); n       int height = n           strtol(s.substr(comma + 1, rparen - comma - 1).c_str(), 0, 10); n       map[name] = new Widget(name, width, height); n     } else if (s ==  VBox ) { n       std::cin >> s; n       map[s] = new VBox(s); n     } else if (s ==  HBox ) { n       std::cin >> s; n       map[s] = new HBox(s); n     } else { n       std::string::size_type dot = s.find( . ); n       std::string::size_type lparen = s.find( ( , dot + 1); n       std::string::size_type rparen = s.find( ) , lparen + 1); n       std::string name = s.substr(0, dot); n       std::string method = s.substr(dot + 1, lparen - dot - 1); n       if (method ==  pack ) { n         std::string child = s.substr(lparen + 1, rparen - lparen - 1); n         static_cast<Box*>(map[name])->children.push_back(map[child]); n       } else if (method ==  set_border ) { n         int border = n             strtol(s.substr(lparen + 1, rparen - lparen - 1).c_str(), 0, 10); n         static_cast<Box*>(map[name])->border = border; n       } else if (method ==  set_spacing ) { n         int spacing = n             strtol(s.substr(lparen + 1, rparen - lparen - 1).c_str(), 0, 10); n         static_cast<Box*>(map[name])->spacing = spacing; n       } n     } n   } n   for (std::map<std::string, Widget*>::iterator i = map.begin(); i != map.end(); n        ++i) { n     Widget* widget = (*i).second; n     widget->calculateSize(); n     std::cout << widget->name <<     << widget->width <<     << widget->height n               << std::endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, t; n   cin >> n >> t; n   string str; n   cin >> str; n   long long ptr = 0; n   while (str[ptr] !=  . ) ptr++; n   long long tmp = ptr; n   ptr++; n   while (ptr < n and str[ptr] <  5 ) ptr++; n   if (ptr == n) { n     cout << str <<   n ; n     return 0; n   } n   while (t) { n     if (str[ptr] <  5 ) { n       break; n     } n     if (str[ptr] >=  5 ) { n       str[ptr] =   0 ; n       if (str[ptr - 1] !=  . ) { n         str[ptr - 1] = str[ptr - 1] + 1; n         t--; n         ptr--; n       } else { n         str[ptr - 1] =   0 ; n         if (str[ptr - 2] ==  9 ) { n           ptr = ptr - 2; n           while (ptr >= 0 and str[ptr] ==  9 ) str[ptr--] =  0 ; n           if (ptr == -1) { n             cout <<  1  << str.substr(0, tmp) <<   n ; n             return 0; n           } n           str[ptr] = str[ptr] + 1; n           cout << str.substr(0, tmp) <<   n ; n           return 0; n         } n         str[ptr - 2] += 1; n         cout << str.substr(0, tmp) <<   n ; n         return 0; n       } n     } n   } n   long long len = 0; n   while (str[len] !=   0 ) len++; n   cout << str.substr(0, len) <<   n ; n } n


#include <bits/stdc++.h> n template <class T> n inline T gcd(T a, T b) { n   a = abs(a); n   b = abs(b); n   if (!b) return a; n   return __gcd(b, a % b); n } n template <class T> n inline T lcm(T a, T b) { n   a = abs(a); n   b = abs(b); n   return (a / __gcd(a, b)) * b; n } n template <class T> n inline T ncr(T n, T r) { n   return n * (n - 1) / r; n } n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n, a; n   cin >> n >> a; n   double total = ((n - 2) * 180) / float(n); n   double temp = total; n   double mi = float(180) / n; n   double ans = 10000000000; n   int loc = -1; n   for (int i = 1; i <= n - 2; i++) { n     if (abs(temp - a) < ans) { n       ans = abs(temp - a); n       loc = i; n     } n     temp -= mi; n   } n   cout << 1 <<     << loc + 1 <<     << loc + 2; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #include<algorithm> n #include<map> n #include<fstream> n #define ll long long n #define ld long double n #define pb push_back n #define fi first n #define se second n #define endl   n  n #define For(i,n) for(long long i=0; i<n; i++) n #define FOR(i,f,l) for(long long i=f; i<l; i++) n #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); n #define mod 1000000007 n  n void solve(){ n   ll n; n   cin>>n; n   vector<ll> v(n),ans; n   For(i,n){ n     cin>>v[i]; n   } n   if(n==1){ n     cout<<0<<endl; n   } n   else{ n     ans.pb(0); n     for(ll i=1; i<n; i++){ n         if((v[i]&v[i-1])==v[i-1]){ n             ans.pb(0); n         } n         else{ n             ll temp = v[i]^v[i-1]; n             temp = temp&v[i-1]; n           //  cout<<i<<endl; n            // cout<<temp<<   <<1<<endl; n             ans.pb(temp); n             v[i] = v[i]+temp; n           //  cout<<v[i]<<   <<2<<endl; n         } n     } n     for(ll i=0; i<n; i++){ n         cout<<ans[i]<<   ; n     } n     cout<<endl; n   } n  n } n  n  n int main(){ n    fastio n    ll t; n    cin>>t; n    while(t--){ n      solve(); n    } n } n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     double a, b, c, d, k; n     cin >> a >> b >> c >> d >> k; n     if (ceil(a / c) + ceil(b / d) > k) { n       cout << -1 << endl; n     } else { n       cout << ceil(a / c) <<     << ceil(b / d) << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9 + 34; n const int N = (int)1e6 + 34; n int p[N], sz[N]; n int fnd(int v) { return (p[v] == v ? v : fnd(p[v])); } n void uniq(int v1, int v2) { n   v1 = fnd(v1); n   v2 = fnd(v2); n   if (v1 == v2) return; n   p[v1] = v2; n   sz[v2] += sz[v1]; n } n int a[N]; n void solve() { n   int n; n   cin >> n; n   map<int, vector<int>> mp; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     p[i] = i; n     sz[i] = 1; n     mp[a[i]].push_back(i); n   } n   int tot = 0, lst = -1; n   int ansL = 1; n   int ansK = mp.rbegin()->first; n   map<int, int> num; n   for (auto it = mp.begin(); it != mp.end(); it++) { n     auto v = it->second; n     for (int ps : v) { n       tot++; n       num[1]++; n       lst = 1; n       if (ps > 0 && a[ps] >= a[ps - 1]) { n         int v1 = fnd(ps); n         int v2 = fnd(ps - 1); n         if (v1 != v2) { n           tot--; n           num[sz[v1]]--; n           num[sz[v2]]--; n           uniq(v1, v2); n           lst = sz[fnd(ps)]; n           num[lst]++; n         } n       } n       if (ps + 1 < n && a[ps] >= a[ps + 1]) { n         int v1 = fnd(ps); n         int v2 = fnd(ps + 1); n         if (v1 != v2) { n           tot--; n           num[sz[v1]]--; n           num[sz[v2]]--; n           uniq(v1, v2); n           lst = sz[fnd(ps)]; n           num[lst]++; n         } n       } n     } n     if (tot == num[lst]) { n       int curK = it->first; n       int curL = num[lst]; n       if (curL > ansL || (curL == ansL && curK < ansK)) { n         ansL = curL; n         ansK = curK; n       } n     } n   } n   cout << ansK + 1 <<   n ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int *a = new int[n]; n   int max = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     max += a[i]; n   } n   for (int del = 2; del < n; del++) { n     int vLeft = n / del; n     if (n % del == 0 && vLeft > 2) { n       for (int j = 0; j < n; j++) { n         int done = 0; n         int start = j; n         int sum = 0; n         while (done < vLeft) { n           if (start >= n) start -= n; n           sum += a[start]; n           start += del; n           done++; n         } n         if (sum > max) max = sum; n       } n     } n   } n   cout << max; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace fastIO1 { n inline char read() { n   static const int IN_LEN = 1000000; n   static char buf[IN_LEN], *s, *t; n   return (s == t               ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), n           (s == t ? -1 : *s++) : *s++); n } n template <class T> n inline void read(T &x) { n   static bool iosig; n   static char c; n   for (iosig = false, c = read(); !isdigit(c); c = read()) { n     if (c ==  - ) iosig = true; n     if (c == -1) return; n   } n   for (x = 0; isdigit(c); c = read()) x = ((x + (x << 2)) << 1) + (c ^  0 ); n   if (iosig) x = -x; n } n inline char readc(char &c) { n   for (c = read(); !isalpha(c) && !isdigit(c); c = read()) n     if (c == -1) return 0; n } n const int OUT_LEN = 10000000; n char obuf[OUT_LEN], *ooh = obuf; n inline void print(char c) { n   if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf; n   *ooh++ = c; n } n template <class T> n inline void print(T x) { n   static int buf[30], cnt; n   if (x == 0) n     print( 0 ); n   else { n     if (x < 0) print( - ), x = -x; n     for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48; n     while (cnt) print((char)buf[cnt--]); n   } n } n inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); } n }  // namespace fastIO1 n namespace fastIO2 { n template <class T> n inline void read(T &x) { n   static bool iosig; n   static char c; n   for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) { n     if (c ==  - ) iosig = true; n     if (c == -1) return; n   } n   for (x = 0; isdigit(c); c = getchar()) x = ((x + (x << 2)) << 1) + (c ^  0 ); n   if (iosig) x = -x; n } n }  // namespace fastIO2 n using namespace fastIO1; n long long n, ans, f[2][(135)][2]; n long long calc(int x, int lena, int lenb, long long sum) { n   memset(f, 0, sizeof(f)), f[1][0][0] = 1; n   int now = 0, pre = 1; n   for (int i = 0; (1ll << i) <= sum; i++, now ^= 1, pre ^= 1) { n     for (int j = 0; j <= x; j++) f[now][j][0] = f[now][j][1] = 0; n     for (int j = 0; j < 2; j++) n       if (i < lena || !j) n         for (int k = 0; k < 2; k++) n           if (i < lenb || !k) n             for (int l = 0; l < 2; l++) { n               int S = j + k + l; n               if (((sum >> i) & 1) ^ (S & 1)) continue; n               for (int m = 0; m + j + k <= x; m++) n                 f[now][m + j + k][S >> 1] += f[pre][m][l]; n             } n   } n   return f[pre][x][0]; n } n int main() { n   read(n); n   for (int i = 0; i <= 60; i++) n     for (int j = 0; j <= 60; j++) { n       long long mul = (1ll << i + 1) + (1ll << j + 1) - 3; n       if (n < mul) break; n       long long ret = n % mul - (1ll << j) + 1; n       if (ret < 0) continue; n       for (int k = (ret & 1); k <= i + j; k += 2) n         ans += calc(k, i - 1, j - 1, (ret + k) >> 1); n     } n   cout << ans; n } n


#include<bits/stdc++.h> n using namespace std; n  n #define sz(s) (int)s.size() n #define f first n #define s second n #define pb push_back n #define all(s) s.begin(), s.end() n  n #define vi vector<int> n #define vvi vector<vi> n  n #define ll long long n #define vll vector<ll> n  n #define ii pair<int, int> n #define vii vector<ii> n #define vvii vector<vii> n  n const int INF = 1e9 + 7; n const int mod = 1e9 + 7; n const int N = 1e6 + 7; n const int T = 1 << 20; n #define ld long double n  n int n; n  n int suma[T + T]; n int maxi[T + T]; n  n void set_val(int poz, int val){ n     poz += T; n     suma[poz] = val; n     maxi[poz] = max(val, 0); n     poz /= 2; n  n     while(poz > 0){ n         suma[poz] = suma[poz + poz] + suma[poz + poz + 1]; n         maxi[poz] = max(maxi[poz + poz + 1], suma[poz + poz + 1] + maxi[poz + poz]); n         poz /= 2; n     } n } n  n int max_suf(int poz){ n     poz += T; n     int ret = 1; n     int temp_suma = 1; n  n     while(poz > 0){ n         if(poz % 2 == 1){ n             ret = max(ret, maxi[poz - 1] + temp_suma); n             temp_suma += suma[poz - 1]; n         } n         poz /= 2; n     }    n     return ret; n } n  n vector<int> policz(vector<int> tab){ n     for(auto & u : tab) n         assert(u >= 0 and u <= n); n  n     for(int i = 0; i < T + T; i++) n         suma[i] = maxi[i] = 0; n  n     for(int i = T; i < T + n; i++) n         suma[i] = maxi[i] = 1; n     for(int i = T - 1; i > 0; i--) n         suma[i] = maxi[i] = suma[i + i] + suma[i + i + 1]; n  n     vector<vector<int> > values(n + 1); n  n     for(int i = 0; i < n; i++) n         values[tab[i]].pb(i); n  n     vector<int> ret(n); n  n     for(int i = 0; i <= n; i++){ n         for(auto & poz : values[i]) n             ret[poz] = max_suf(poz); n         for(auto & poz : values[i]) n             set_val(poz, -1); n     } n     return ret; n } n  n void solve(){ n     cin >> n; n  n     vector<int> tab(n); n     for(int i = 0; i < n; i++) n         cin >> tab[i]; n  n     // for(auto & u : tab) n     //     cout << u <<    ; n     // cout << endl; n  n     vector<int> ans(n); n  n     for(int faza = 0; faza < 2; faza++){ n         // cout <<  Tab:  ; n         // for(auto & u : tab) n             // cout << u <<    ; n         // cout << endl; n         auto a = policz(tab); n         reverse(all(tab)); n         auto b = policz(tab); n         reverse(all(b)); n         reverse(all(tab)); n  n         // cout <<  a :  ; n         // for(auto & u : a) n         //     cout << u <<    ; n         // cout << endl; n         // cout <<  b :  ; n         // for(auto & u : b) n         //     cout << u <<    ; n         // cout << endl; n          n         for(int i = 0; i < n; i++) n             ans[i] = max(ans[i], (a[i] + b[i] - 1 - faza) / 2); n      n         for(auto & u : tab) n             u = -u + n;     n     } n  n     for(int i = 0; i < n; i++) n         cout << ans[i] <<    ; n     cout <<   n ; n } n  n signed main(){ n     ios::sync_with_stdio(0); n     cin.tie(0); n  n     int test = 1; n     // cin >> test; n  n     for(int i = 0; i < test; i++) n         solve(); n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10, mod = 998244353; n int mu[maxn], n, m, l[51], r[51], prime[maxn], cnt; n bool is_composite[maxn]; n int dp[maxn], pre[maxn]; n int cal(int d) { n   int M = m / d; n   for (int i = 1; i <= M; i++) dp[i] = 0; n   dp[0] = 1; n   for (int i = 1; i <= n; i++) { n     int L = (l[i] + d - 1) / d, R = r[i] / d; n     if (L > R) return 0; n     pre[0] = dp[0]; n     for (int j = 1; j <= M; j++) pre[j] = (pre[j - 1] + dp[j]) % mod; n     for (int j = 0; j <= M; j++) { n       dp[j] = (((j - L >= 0) ? pre[j - L] : 0) - n                ((j - R - 1 >= 0) ? pre[j - R - 1] : 0)) % n               mod; n     } n   } n   pre[0] = dp[0]; n   for (int j = 0; j <= M; j++) pre[j] = (pre[j - 1] + dp[j]) % mod; n   return pre[M]; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) scanf( %d%d , &l[i], &r[i]); n   mu[1] = 1; n   for (int i = 2; i <= m; i++) { n     if (!is_composite[i]) { n       prime[++cnt] = i; n       mu[i] = mod - 1; n     } n     for (int j = 1; j <= cnt && i * prime[j] <= m; j++) { n       is_composite[i * prime[j]] = true; n       if (i % prime[j]) n         mu[i * prime[j]] = (mod - mu[i]) % mod; n       else n         break; n     } n   } n   int ans = 0; n   for (int d = 1; d <= m; d++) { n     ans = (ans + 1LL * cal(d) * mu[d]) % mod; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 100000; n typedef struct P { n   int x, y; n   P() {} n   P(int x, int y) : x(x), y(y) {} n } P; n bool operator<(const P &a, const P &b) { n   if (a.x != b.x) return a.x < b.x; n   return a.y > b.y; n } n P operator-(const P &a, const P &b) { return P(a.x - b.x, a.y - b.y); } n long long operator^(const P &a, const P &b) { n   return (long long)a.x * b.y - (long long)a.y * b.x; n } n int side(const P &a, const P &b, const P &c) { n   long long ret = (b - a) ^ (c - a); n   return ret < 0 ? -1 : ret > 0 ? +1 : 0; n } n void makehull(int &n, P p[MAXN + 2]) { n   sort(p, p + n); n   int nh = 0; n   for (int i = (0); i < (n); ++i) { n     while (nh >= 2 && side(p[nh - 2], p[nh - 1], p[i]) >= 0) --nh; n     p[nh++] = p[i]; n   } n   n = nh; n } n int n[2]; n P s; n P p[2][MAXN + 2]; n void run() { n   for (int i = (0); i < (2); ++i) scanf( %d , &n[i]); n   scanf( %d%d , &s.x, &s.y); n   for (int i = (0); i < (2); ++i) n     for (int j = (0); j < (n[i]); ++j) scanf( %d%d , &p[i][j].x, &p[i][j].y); n   for (int i = (0); i < (2); ++i) { n     int hx = p[i][0].x; n     for (int j = (1); j < (n[i]); ++j) n       if (p[i][j].x > hx) hx = p[i][j].x; n     p[i][n[i]].x = hx, p[i][n[i]].y = 0, ++n[i]; n   } n   for (int i = (0); i < (2); ++i) { n     int hy = p[i][0].y; n     for (int j = (1); j < (n[i]); ++j) n       if (p[i][j].y > hy) hy = p[i][j].y; n     p[i][n[i]].x = 0, p[i][n[i]].y = hy, ++n[i]; n   } n   for (int i = (0); i < (2); ++i) makehull(n[i], p[i]); n   int j = 0; n   for (int i = (0); i < (n[0]); ++i) { n     while (j + 2 < n[1] && p[1][j + 1] < p[0][i]) ++j; n     if (side(p[1][j], p[0][i], p[1][j + 1]) <= 0) { n       printf( Max n ); n       return; n     } n   } n   printf( Min n ); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n char s[2000005]; n int sign[2000005], o[2000005], n, m, L; n int main() { n   scanf( %s , s), n = strlen(s), m = 0; n   for (int i = 0; i < n; i++) { n     int x = s[n - 1 - i] - 48; n     if (x) { n       if (m == 1) o[L++] = i - 1; n       m += m < 2; n     } else if (m == 1) n       sign[L] = 1, o[L++] = i + m - 2, m = 0; n     else if (m == 2) n       m--; n   } n   if (m) sign[L] = 1, o[L++] = n + m - 2; n   printf( %d n , L); n   for (int i = 0; i < L; i++) printf( %c2^%d n , sign[i] ?  +  :  - , o[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e5 + 5; n int n, q, num, b0[N], b[N], c[2][N], ans[N]; n struct data { n   int p, s, b; n } a[N]; n struct qry { n   int x, y, id; n } Q[N]; n bool cmp(qry a, qry b) { return a.x < b.x; } n bool cmp1(data a, data b) { return a.p < b.p; } n bool cmp2(data a, data b) { return a.s < b.s; } n void mdf(int *c, int o, int x) { n   while (o <= num) c[o] += x, o += (o & -o); n } n int qry(int *c, int o) { n   int s = 0; n   while (o) s += c[o], o -= (o & -o); n   return s; n } n int calc(int x, int y) { n   int res = 0; n   res += qry(c[0], upper_bound(b + 1, b + num + 1, x + y) - b - 1); n   res += qry(c[1], upper_bound(b + 1, b + num + 1, x - y) - b - 1); n   return res - qry(c[0], num); n } n int main() { n   scanf( %d%d , &n, &q); n   for (int i = (1); i <= (n); ++i) scanf( %d , &a[i].p); n   for (int i = (1); i <= (n); ++i) scanf( %d , &a[i].s); n   for (int i = (1); i <= (n); ++i) scanf( %d , &a[i].b); n   for (int i = (1); i <= (n); ++i) n     b0[i] = a[i].p + a[i].b, b0[i + n] = a[i].p - a[i].b; n   sort(b0 + 1, b0 + n * 2 + 1); n   b[++num] = b0[1]; n   for (int i = (2); i <= (n << 1); ++i) n     if (b0[i] != b0[i - 1]) b[++num] = b0[i]; n   for (int i = (1); i <= (q); ++i) scanf( %d , &Q[i].x); n   for (int i = (1); i <= (q); ++i) scanf( %d , &Q[i].y); n   for (int i = (1); i <= (q); ++i) Q[i].id = i; n   sort(Q + 1, Q + q + 1, cmp); n   sort(a + 1, a + n + 1, cmp1); n   int j = 1; n   for (int i = (1); i <= (q); ++i) { n     while (j <= n && a[j].p <= Q[i].x) { n       int x = lower_bound(b + 1, b + num + 1, a[j].p + a[j].b) - b; n       int y = lower_bound(b + 1, b + num + 1, a[j].p - a[j].b) - b; n       mdf(c[0], x, 1), mdf(c[1], y, 1), ++j; n     } n     ans[Q[i].id] += calc(Q[i].x, Q[i].y); n   } n   memset(c, 0, sizeof(c)); n   sort(a + 1, a + n + 1, cmp2); n   j = 1; n   for (int i = (1); i <= (q); ++i) { n     while (j <= n && a[j].s < Q[i].x) { n       int x = lower_bound(b + 1, b + num + 1, a[j].p + a[j].b) - b; n       int y = lower_bound(b + 1, b + num + 1, a[j].p - a[j].b) - b; n       mdf(c[0], x, 1), mdf(c[1], y, 1), ++j; n     } n     ans[Q[i].id] -= calc(Q[i].x, Q[i].y); n   } n   for (int i = (1); i <= (q); ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> l[100010], r[100010], chosenl[100010], chosenr[100010]; n vector<bool> badl[100010], badr[100010]; n bool monst[100010]; n int ans[100010]; n vector<pair<int, int> > edges[100010]; n int cnt[100010], toFather[100010], fromFather[100010]; n void longPathChild(int v, int f) { n   if (monst[v]) n     ans[v] = 0; n   else n     ans[v] = -1000000000; n   for (int i = 0; i < edges[v].size(); i++) { n     if (edges[v][i].first != f) { n       longPathChild(edges[v][i].first, v); n       ans[v] = max(ans[v], ans[edges[v][i].first] + edges[v][i].second); n     } n   } n } n int longPathFather(int v, int f, int u) { n   for (int i = 0; i <= edges[v].size(); i++) { n     l[v].push_back(0); n     badl[v].push_back(true); n     chosenl[v].push_back(-1); n     r[v].push_back(0); n     badr[v].push_back(true); n     chosenr[v].push_back(-1); n   } n   l[v][0] = r[v][edges[v].size()] = -1000000000; n   if (monst[v]) l[v][0] = 0; n   for (int i = 0; i < edges[v].size(); i++) { n     int t; n     if (edges[v][i].first != f) n       t = ans[edges[v][i].first] + edges[v][i].second; n     else n       t = u; n     if (t > l[v][i]) { n       l[v][i + 1] = t; n       badl[v][i + 1] = false; n       chosenl[v][i + 1] = edges[v][i].first; n     } else if (t == l[v][i]) { n       l[v][i + 1] = l[v][i]; n       badl[v][i + 1] = true; n       chosenl[v][i + 1] = edges[v][i].first; n     } else { n       l[v][i + 1] = l[v][i]; n       badl[v][i + 1] = badl[v][i]; n       chosenl[v][i + 1] = chosenl[v][i]; n     } n   } n   for (int i = edges[v].size() - 1; i >= 0; i--) { n     int t; n     if (edges[v][i].first != f) n       t = ans[edges[v][i].first] + edges[v][i].second; n     else n       t = u; n     if (t > r[v][i + 1]) { n       r[v][i] = t; n       badr[v][i] = false; n       chosenr[v][i] = edges[v][i].first; n     } else if (t == r[v][i + 1]) { n       r[v][i] = r[v][i + 1]; n       badr[v][i] = true; n       chosenr[v][i] = edges[v][i].first; n     } else { n       r[v][i] = r[v][i + 1]; n       badr[v][i] = badr[v][i + 1]; n       chosenr[v][i] = chosenr[v][i + 1]; n     } n   } n   int ret = 0; n   for (int i = 0; i < edges[v].size(); i++) n     if (edges[v][i].first != f) { n       int t = longPathFather(edges[v][i].first, v, n                              max(l[v][i], r[v][i + 1]) + edges[v][i].second); n       if (l[v][i] > r[v][i + 1] && l[v][i] == u && !badl[v][i]) ret += t; n       if (r[v][i + 1] > l[v][i] && r[v][i + 1] == u && !badr[v][i + 1]) n         ret += t; n       cnt[v] += t; n     } n   if (monst[v] && l[v][edges[v].size()] == u && !badl[v][edges[v].size()]) n     ret++; n   return (toFather[v] = ret); n } n void fillFromFather(int v, int f) { n   cnt[v] += fromFather[v]; n   for (int i = 0; i < edges[v].size(); i++) { n     if (max(l[v][i], r[v][i + 1]) < 0) continue; n     if (edges[v][i].first != f) { n       if (l[v][i] > r[v][i + 1] && !badl[v][i] && chosenl[v][i] != f) n         fromFather[chosenl[v][i]] += toFather[edges[v][i].first]; n       if (r[v][i + 1] > l[v][i] && !badr[v][i + 1] && chosenr[v][i + 1] != f) n         fromFather[chosenr[v][i + 1]] += toFather[edges[v][i].first]; n     } else { n       if (l[v][i] > r[v][i + 1] && !badl[v][i] && chosenl[v][i] != f) n         fromFather[chosenl[v][i]] += fromFather[v]; n       if (r[v][i + 1] > l[v][i] && !badr[v][i + 1] && chosenr[v][i + 1] != f) n         fromFather[chosenr[v][i + 1]] += fromFather[v]; n     } n   } n   if (monst[v] && !badl[v][edges[v].size()] && chosenl[v][edges[v].size()] != f) n     fromFather[chosenl[v][edges[v].size()]]++; n   for (int i = 0; i < edges[v].size(); i++) n     if (edges[v][i].first != f) fillFromFather(edges[v][i].first, v); n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a; n     cin >> a; n     monst[a] = true; n   } n   for (int i = 0; i < n - 1; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     edges[a].push_back(pair<int, int>(b, c)); n     edges[b].push_back(pair<int, int>(a, c)); n   } n   longPathChild(1, -1); n   longPathFather(1, -1, -1000000000); n   fillFromFather(1, -1); n   int best = 0, bestcnt = 0; n   for (int i = 1; i <= n; i++) { n     if (monst[i]) continue; n     if (cnt[i] > best) { n       best = cnt[i]; n       bestcnt = 1; n     } else if (cnt[i] == best) n       bestcnt++; n   } n   cout << best <<     << bestcnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10; n const int maxm = 3e5 + 10; n vector<pair<int, int> > g[maxn]; n stack<int> S; n struct edge { n   int x, y; n } e[maxm]; n int n, m, cnt, dfn; n int d[maxn], low[maxn], fa[maxn], pre[maxn]; n void tarjan(int now, int f) { n   d[now] = low[now] = ++dfn; n   S.push(now); n   for (int i = 0; i < g[now].size(); i++) { n     int son = g[now][i].first, id = g[now][i].second; n     if (id == f) continue; n     if (!d[son]) { n       fa[son] = now; n       tarjan(son, id); n       low[now] = min(low[now], low[son]); n     } else n       low[now] = min(low[now], d[son]); n   } n   if (low[now] > d[fa[now]]) { n     cnt++; n     while (!S.empty()) { n       int x = S.top(); n       pre[x] = cnt; n       S.pop(); n       if (x == now) break; n     } n   } n } n int pos, far; n void dfs(int now, int f, int dep) { n   if (dep > far) { n     far = dep; n     pos = now; n   } n   for (int i = 0; i < g[now].size(); i++) { n     int son = g[now][i].first; n     if (son == f) continue; n     dfs(son, now, dep + 1); n   } n } n void init() { n   dfn = cnt = 0; n   while (!S.empty()) S.pop(); n   memset(d, 0, sizeof d); n   memset(low, 0, sizeof low); n   for (int i = 1; i <= n; i++) g[i].clear(); n } n void input() { n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     g[x].push_back({y, i}); n     g[y].push_back({x, i}); n     e[i] = (edge){x, y}; n   } n } n int main() { n   while (cin >> n >> m) { n     if (n == 0 && m == 0) break; n     init(); n     input(); n     tarjan(1, 0); n     for (int i = 1; i <= n; i++) g[i].clear(); n     for (int i = 1; i <= m; i++) { n       int u = e[i].x, v = e[i].y; n       if (pre[u] != pre[v]) { n         u = pre[u]; n         v = pre[v]; n         g[u].push_back({v, 0}); n         g[v].push_back({u, 0}); n       } n     } n     far = pos = 0; n     dfs(1, 0, 0); n     int s = pos; n     far = pos = 0; n     dfs(s, 0, 0); n     cout << far << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n const long long INF = 1e15 + 7; n const long long N = 2e5 + 10; n const long long mod = 998244353; n long long pow(long long x, long long y) { n   long long res = 1; n   while (y > (long long)0) { n     if (y & (long long)1) res = ((res) * (x)); n     y = y >> (long long)1; n     x = ((x) * (x)); n   } n   return res; n } n long long powm(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > (long long)0) { n     if (y & (long long)1) res = (res * x) % p; n     y >>= (long long)1; n     x = (x * x) % p; n   } n   return res; n } n void solve() { n   long long n; n   cin >> n; n   string s; n   cin >> s; n   long long w = 0, b = 0; n   vector<long long> v; n   for (long long i = 0; i < n; i++) { n     if (s[i] ==  B ) n       b++; n     else n       w++; n   } n   if (b % 2 != 0 && w % 2 != 0) { n     cout << -1 << endl; n     return; n   } n   if (b % 2 == 0) { n     for (long long i = 0; i < n - 1; i++) { n       if (s[i] ==  B ) { n         s[i] =  W ; n         if (s[i + 1] ==  B ) n           s[i + 1] =  W ; n         else n           s[i + 1] =  B ; n         v.push_back(i + 1); n       } n     } n   } else if (w % 2 == 0) { n     for (long long i = 0; i < n - 1; i++) { n       if (s[i] ==  W ) { n         s[i] =  B ; n         if (s[i + 1] ==  B ) n           s[i + 1] =  W ; n         else n           s[i + 1] =  B ; n         v.push_back(i + 1); n       } n     } n   } n   cout << v.size() << endl; n   for (auto i : v) cout << i <<    ; n   cout << endl; n   return; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long ts = 1; n   while (ts--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void magic(int n) { n   int cnt = 0; n   set<vector<vector<int>>> s; n   vector<pair<int, string>> ans; n   map<int, int> mp; n   function<void(vector<vector<int>>)> f = [&](const vector<vector<int>> &x) { n     if (s.find(x) != s.end()) return; n     s.insert(x); n     if (x.size() == 1) { n       ++cnt; n       ans.push_back({0,   }); n       for (auto &i : x) n         for (auto j : i) { n           ans.back().second.push_back( 0  + j); n           ans.back().first += j; n         } n       return; n     } n     for (size_t i = 1; i < x.size(); ++i) { n       vector<vector<int>> y = x; n       y.erase(y.begin() + i); n       for (auto &z : x[i]) y[i - 1].push_back(z); n       for (auto &z : y[i - 1]) z ^= 1; n       f(y); n     } n   }; n   vector<vector<int>> a(n, vector<int>(1, 1)); n   f(a); n   cout << cnt <<   n ; n   sort(ans.begin(), ans.end()); n   for (auto i : ans) { n     cout << i.first <<     << i.second <<   n ; n     ++mp[i.first]; n   } n   for (auto i : mp) { n     cout << i.first <<     << i.second <<   n ; n   } n } n void brute(vector<long long> a) { n   long long ans = numeric_limits<long long>::min(); n   set<vector<long long>> s; n   function<void(vector<long long>)> f = [&](const vector<long long> &x) { n     if (x.size() == 1) { n       ans = max(ans, x[0]); n       return; n     } n     if (s.find(x) != s.end()) return; n     s.insert(x); n     for (size_t i = 1; i < x.size(); ++i) { n       vector<long long> y = x; n       y.erase(y.begin() + i); n       y[i - 1] = -x[i - 1] - x[i]; n       f(y); n     } n   }; n   f(a); n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n; n   cin >> n; n   vector<pair<long long, int>> a(n); n   for (auto &i : a) cin >> i.first, i.second = &i - &a[0]; n   long long sum = 0; n   for (auto i : a) sum += -i.first; n   for (auto &i : a) i.first *= 2; n   sort(a.rbegin(), a.rend()); n   int t = n % 3; n   if (t == 2) n     t = 0; n   else if (t == 0) n     t = 2; n   a.insert(a.begin(), {0, 0}); n   for (int i = 1; i <= n; ++i) a[i].first += a[i - 1].first; n   auto get = [&](int p) { return a[p].first - a[p - 1].first; }; n   long long rans = numeric_limits<long long>::min(); n   for (; t <= n; t += 3) { n     if (n > 1 && (n & 1) && t == (n + 1) / 2) { n       bool bad = true; n       for (int i = 1; i <= t; ++i) bad &= ~a[i].second & 1; n       rans = max(rans, sum + a[t].first + bad * (-get(t) + get(t + 1))); n     } else n       rans = max(rans, sum + a[t].first); n   } n   cout << rans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long num; n   cin >> n; n   set<long> s; n   while (n > 0) { n     cin >> num; n     while (num % 2 == 0) { n       num = num / 2; n     } n     while (num % 3 == 0) { n       num = num / 3; n     } n     s.insert(num); n     n--; n   } n   if (s.size() == 1) { n     cout <<  Yes ; n   } else { n     cout <<  No ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n template <typename t1> n t1 gcd(t1 a, t1 b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <typename t1> n t1 lcm(t1 a, t1 b) { n   return a * (b / gcd(a, b)); n } n int main() { n   int n, d, h; n   while (cin >> n >> d >> h) { n     if (h == 1 && d == 1 && n > 2) n       cout << -1 << endl; n     else if (d < h) n       cout << -1 << endl; n     else if (n <= d || d > 2 * h) n       cout << -1 << endl; n     else if (h == d) { n       { n         int l = h; n         int now = 1; n         while (l--) { n           cout << now <<     << now + 1 << endl; n           now++; n         } n         now++; n         int nnn = 2; n         int tem = d + 1; n         while (now <= n) { n           cout << nnn <<     << now++ << endl; n         } n       } n     } else { n       int l = h; n       int now = 1; n       while (l--) { n         cout << now <<     << now + 1 << endl; n         now++; n       } n       now++; n       int rem = d - h; n       while (now <= n) { n         int flag = 0; n         int noww = 1; n         int nrem = rem; n         while (nrem--) { n           if (now > n) { n             flag = 1; n             break; n           } n           cout << noww <<     << now << endl; n           noww = now; n           now++; n         } n         if (flag) break; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int start; n int tail; n int head[150500], to[150500], nxt[150500], wei[150500], cost[150500], tot = 1; n int dis[5050], pre[5050], pres[5050]; n bool vis[5050]; n queue<int> que; n int n, sum, k; n int used, flow; n char str[105]; n int numstr[30], numstr1[105][30], num[105]; n void add(int x, int y, int z, int w) { n   tot++, to[tot] = y, nxt[tot] = head[x], head[x] = tot, cost[tot] = w, n          wei[tot] = z; n   tot++, to[tot] = x, nxt[tot] = head[y], head[y] = tot, cost[tot] = -w, n          wei[tot] = 0; n } n bool spfa() { n   memset(dis, inf, sizeof(dis)); n   memset(vis, 0, sizeof(vis)); n   dis[start] = 0; n   que.push(start); n   int now; n   do { n     now = que.front(); n     vis[now] = 0; n     que.pop(); n     for (int i = head[now]; i; i = nxt[i]) { n       if (dis[to[i]] > dis[now] + cost[i] && wei[i]) { n         dis[to[i]] = dis[now] + cost[i]; n         pre[to[i]] = now; n         pres[to[i]] = i; n         if (!vis[to[i]]) { n           que.push(to[i]); n           vis[to[i]] = 1; n         } n       } n     } n   } while (!que.empty()); n   return dis[tail] != inf; n } n void f() { n   int now = tail; n   int low = inf; n   while (now != start) { n     low = min(low, wei[pres[now]]); n     now = pre[now]; n   } n   used += low * dis[tail]; n   flow += low; n   now = tail; n   while (now != start) { n     wei[pres[now]] -= low; n     wei[pres[now] ^ 1] += low; n     now = pre[now]; n   } n } n int main() { n   int len; n   cin >> str; n   len = strlen(str); n   for (int i = 0; i < strlen(str); i++) { n     numstr[str[i] -  a  + 1]++; n   } n   cin >> k; n   start = 0, tail = 30; n   for (int i = 1; i <= k; i++) { n     cin >> str >> num[i]; n     for (int j = 0; j < strlen(str); j++) { n       numstr1[i][str[j] -  a  + 1]++; n     } n   } n   for (int i = 1; i <= 26; i++) { n     if (!numstr[i]) continue; n     add(start, i, numstr[i], 0); n     for (int j = 1; j <= k; j++) { n       if (!numstr1[j][i]) continue; n       add(i, j + 30, numstr1[j][i], j); n     } n   } n   for (int i = 1; i <= k; i++) { n     add(i + 30, tail, num[i], 0); n   } n   while (spfa()) { n     f(); n   } n   if (flow != len) { n     cout << -1 << endl; n   } else { n     cout << used << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n int n, u; n int e[N]; n double ans = -1; n int search(int l, int r, int k) { n   int m, p = -1; n   while (l <= r) { n     m = (l + r) / 2; n     if (e[m] <= k) { n       p = m; n       l = m + 1; n     } else n       r = m - 1; n   } n   return p; n } n void solve() { n   for (int i = 0; i < n - 2; i++) { n     int k = search(i + 2, n - 1, e[i] + u); n     if (k == -1) continue; n     ans = max(ans, 1.0 * (e[k] - e[i + 1]) / (e[k] - e[i])); n   } n   if (ans > 0) n     printf( %.9f n , ans); n   else n     puts( -1 ); n } n int main() { n   cin >> n >> u; n   for (int i = 0; i < n; i++) { n     cin >> e[i]; n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 600005; n int n, m, l, r, ma, a[N], f[N][22]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &l, &r); n     a[l] = max(a[l], r); n     ma = max(ma, r); n   } n   for (int i = 1; i <= ma; i++) a[i] = max(a[i], a[i - 1]); n   for (int i = 0; i <= ma; i++) f[i][0] = a[i]; n   for (int i = 1; i <= 20; i++) n     for (int j = 0; j <= ma; j++) f[j][i] = f[f[j][i - 1]][i - 1]; n   while (m--) { n     cin >> l >> r; n     int ans = 0; n     for (int i = 20; i >= 0; i--) n       if (f[l][i] < r) { n         ans += 1 << i; n         l = f[l][i]; n       } n     if (a[l] >= r) n       printf( %d n , ans + 1); n     else n       cout << -1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1000000 + 5; n const long long MOD = 1000000007; n long long n, m, k; n long long ans; n long long v[N], sum[N]; n long long Pow(long long x, long long k) { n   long long z = 1; n   for (; k; k >>= 1, (x *= x) %= MOD) n     if (k & 1) (z *= x) %= MOD; n   return z; n } n int main() { n   scanf( %I64d %I64d %I64d , &n, &m, &k); n   long long a, b, flag = 0, st = 0, ed = 0; n   for (long long i = 1; i <= m; i++) { n     scanf( %I64d %I64d , &a, &b); n     if (a >= b) flag = 1; n     if (b - a == 1 || b - a == k + 1) n       ; n     else n       flag = 1; n     if (b - a == k + 1) { n       v[a] = 1; n       if (!st) st = a; n       ed = a; n     } n   } n   if (flag || (ed - st >= k + 1)) n     printf( 0 n ); n   else { n     for (long long i = 1; i <= n; i++) sum[i] = sum[i - 1] + v[i]; n     n -= ++k; n     for (long long i = 1; i <= n; i++) n       if (!st || (!v[i] && abs(i - st) + 1 <= k && abs(i - ed) + 1 <= k)) { n         long long tmp = st ? ((((i) < (st) ? (i) : (st)) + k - 1) < (n) n                                   ? (((i) < (st) ? (i) : (st)) + k - 1) n                                   : (n)) n                            : n; n         long long r = ((k - 1) < (tmp - i) ? (k - 1) : (tmp - i)); n         (ans += Pow(2, r - (sum[i + r] - sum[i]))) %= MOD; n       } n     printf( %I64d n , ans + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int _ = 1e5 + 7, P = 1e9 + 7; n int N, A[_], prm[_], cprm, phi[_], cnt[_]; n bool nprm[_]; n vector<int> lst[_]; n void sieve() { n   phi[1] = 1; n   for (int i = 2; i <= 1e5; ++i) { n     if (!nprm[i]) { n       prm[++cprm] = i; n       phi[i] = i - 1; n     } n     for (int j = 1; prm[j] * i <= 1e5; ++j) { n       nprm[prm[j] * i] = 1; n       if (i % prm[j] == 0) { n         phi[i * prm[j]] = phi[i] * prm[j]; n         break; n       } n       phi[i * prm[j]] = phi[i] * (prm[j] - 1); n     } n   } n   for (int i = 1; i <= 1e5; ++i) n     for (int j = i; j <= 1e5; j += i) lst[j].push_back(i); n } n int main() { n   ios::sync_with_stdio(0); n   sieve(); n   cin >> N; n   for (int i = 1; i <= N; ++i) cin >> A[i]; n   int ans = 0; n   vector<int> vis; n   for (int d = 1; d <= N; ++d) { n     for (int t = d; t <= N; t += d) n       for (auto v : lst[A[t]]) n         if (!(cnt[v]++)) vis.push_back(v); n     for (auto t : vis) { n       ans = (ans + 1ll * phi[d] * phi[t] % P * cnt[t] * cnt[t]) % P; n       cnt[t] = 0; n     } n     vis.clear(); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   pair<int, int> a[555555]; n   double n, k, t, l = -1, r = 1e12, c, maxx, yes = 0; n   int i; n   cin >> n; n   for (i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second); n   for (k = 0; k < 300; k++) { n     maxx = -1e30; n     c = (l + r) * 0.5; n     t = 0; n     for (i = 0; i < n; i++) n       if (a[i].second > 0) n         maxx = max(maxx, a[i].first + a[i].second * c); n       else if (maxx >= a[i].first + a[i].second * c) { n         t = 1; n         break; n       } n     if (t) { n       yes = 1; n       r = c; n     } else n       l = c; n   } n   cout.precision(20); n   if (yes == 0) r = -1; n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   cin.ignore(); n   string arr; n   getline(cin, arr); n   int mx = 0; n   int cur = 0; n   for (int i = 0; i < n; i++) { n     if (arr[i] ==    ) { n       mx = max(mx, cur); n       cur = 0; n       continue; n     } n     if (isupper(arr[i])) { n       cur++; n     } n   } n   mx = max(mx, cur); n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, l, x, y, z, m, n, a, b, ans, p, q, r; n int numbers[800000]; n int gcd(int x, int y) { n   if (y == 0) n     return x; n   else n     return gcd(y, x % y); n } n int main() { n   scanf( %d %d %d , &a, &b, &n); n   ans = gcd(a, b); n   m = sqrt(ans); n   for (i = 1, k = 0; i <= m; i++) { n     if (ans % i == 0) { n       p = ans / i; n       numbers[k] = p; n       k++; n       numbers[k] = i; n       k++; n     } n   } n   sort(numbers, numbers + k); n   p = 0; n   q = 0; n   for (i = 1; i <= n; i++) { n     scanf( %d %d , &x, &y); n     if (x > ans) { n       printf( -1 n ); n       continue; n     } n     p = lower_bound(numbers, numbers + k, (x)) - numbers; n     q = lower_bound(numbers, numbers + k, (y)) - numbers; n     r = 0; n     for (j = q + 1; j >= p - 1; j--) { n       if (numbers[j] >= x && numbers[j] <= y) { n         printf( %d n , numbers[j]); n         r = 1; n         break; n       } n     } n     if (!r) printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(int argc, char *argv[]) { n   std::string s; n   std::cin >> s; n   int yes = 0; n   int len = s.length(); n   if (len < 3) { n     std::cout <<  No ; n     return 0; n   } n   for (int i = 0; i < len - 2; i++) { n     std::string ss = s.substr(i, 3); n     if (ss ==  ABC  || ss ==  ACB  || ss ==  BAC  || ss ==  BCA  || n         ss ==  CAB  || ss ==  CBA ) { n       yes = 1; n       break; n     } n   } n   if (yes) { n     std::cout <<  Yes ; n   } else { n     std::cout <<  No ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> v(n); n     vector<int> ans(n); n     for (int i = 0; i < n; i++) cin >> v[i]; n     int flagie = 1; n     for (int i = 1; i < n; i++) n       if (v[i] != v[i - 1]) flagie = 0; n     if (flagie == 1) { n       cout << 1 << endl; n       for (auto x : ans) cout << 1 <<    ; n       cout << endl; n     } else { n       if (n % 2 == 0) { n         ans[0] = 1; n         for (int i = 1; i < n; i++) { n           ans[i] = 3 - ans[i - 1]; n         } n         cout << 2 << endl; n         for (auto x : ans) cout << x <<    ; n         cout << endl; n       } else { n         if (v[0] == v[n - 1]) { n           cout << 2 << endl; n           ans[0] = 1; n           for (int i = 1; i < n; i++) { n             ans[i] = 3 - ans[i - 1]; n           } n           for (auto x : ans) cout << x <<    ; n           cout << endl; n         } else { n           int i; n           for (i = 0; i < n - 1; i++) { n             if (v[i] == v[i + 1]) break; n           } n           if (i == n - 1) { n             ans[0] = 1; n             for (int i = 1; i < n; i++) { n               ans[i] = 3 - ans[i - 1]; n             } n             ans[n - 1] = 3; n             cout << 3 << endl; n             for (auto x : ans) cout << x <<    ; n             cout << endl; n           } else { n             int flag = 1; n             ans[0] = 1; n             for (int i = 1; i < n; i++) { n               if (v[i] == v[i - 1] && flag == 1) { n                 ans[i] = ans[i - 1]; n                 flag = 0; n               } else { n                 ans[i] = 3 - ans[i - 1]; n               } n             } n             cout << 2 << endl; n             for (auto x : ans) cout << x <<    ; n             cout << endl; n           } n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n namespace patch { n template <typename T> n std::string to_string(const T& n) { n   std::ostringstream stm; n   stm << n; n   return stm.str(); n } n }  // namespace patch n int m, lim, len; n long long dp[1 << 18][101]; n string s; n long long fac[19]; n int freq[10]; n long long solve(int mask, int mod) { n   if (mask == lim) { n     if (mod == 0) return 1; n     return 0; n   } n   if (dp[mask][mod] != -1) return dp[mask][mod]; n   long long ans = 0; n   for (int i = 0; i < len; ++i) { n     if (!(mask & (1 << i))) { n       if (mask == 0) { n         if (s[i] ==  0 ) continue; n       } n       ans += solve(mask | (1 << i), (mod * 10 + (s[i] -  0 )) % m); n     } n   } n   return dp[mask][mod] = ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   fac[0] = fac[1] = 1; n   for (int i = 2; i <= 18; ++i) fac[i] = fac[i - 1] * (long long)i; n   memset(dp, -1, sizeof dp); n   cin >> s >> m; n   len = s.size(); n   for (int i = 0; i < len; ++i) { n     freq[s[i] -  0 ]++; n   } n   lim = (1 << len) - 1; n   long long ans = solve(0, 0); n   for (int i = 0; i < 10; ++i) { n     if (freq[i]) ans /= fac[freq[i]]; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int n, a[N]; n int cnt[N], odd, neg, sum; n int f[N]; n long long res; n bool check(int L, int R) { n   for (int i = 1; i <= n; ++i) n     if (!(L <= (i) && (i) <= R) && !(L <= (n - i + 1) && (n - i + 1) <= R) && n         a[i] != a[n - i + 1]) n       return 0; n   for (int i = 1; i <= n; ++i) cnt[i] = 0; n   for (int i = 1; i <= n; ++i) { n     if ((L <= (i) && (i) <= R)) { n       ++cnt[a[i]]; n     } else if ((L <= (n - i + 1) && (n - i + 1) <= R)) n       --cnt[a[i]]; n   } n   int sum = 0; n   for (int i = 1; i <= n; ++i) n     if (cnt[i] < 0) n       return 0; n     else n       sum += (cnt[i] & 1); n   return sum <= (n & 1); n } n bool ok(int l, int r) { n   if (r <= n / 2) return (f[r] - f[l - 1] == sum); n   if (l >= (n + 1) / 2 + 1) { n     l = n - l + 1; n     r = n - r + 1; n     return (f[l] - f[r - 1] == sum); n   } n   r = n - r + 1; n   return (f[n / 2] - f[min(l, r) - 1] == sum); n } n void work() { n   int i, j, k; n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (i = 1; i <= n / 2; ++i) f[i] = f[i - 1] + (a[i] != a[n - i + 1]); n   sum = f[n / 2]; n   i = 1, j = 0; n   while (i <= n) { n     while (j <= n && (j < i || (!ok(i, j) || neg || odd > (n & 1)))) { n       ++j; n       k = n - j + 1; n       if (cnt[a[j]] < 0) --neg; n       if (cnt[a[j]] & 1) --odd; n       if (a[j] != a[k]) { n         if (cnt[a[k]] < 0) --neg; n         if (cnt[a[k]] & 1) --odd; n       } n       ++cnt[a[j]]; n       if (i <= k && k <= j) { n         if (j != k) ++cnt[a[j]]; n       } else n         --cnt[a[k]]; n       if (cnt[a[j]] < 0) ++neg; n       if (cnt[a[j]] & 1) ++odd; n       if (a[j] != a[k]) { n         if (cnt[a[k]] < 0) ++neg; n         if (cnt[a[k]] & 1) ++odd; n       } n     } n     k = n - i + 1; n     if (cnt[a[i]] < 0) --neg; n     if (cnt[a[i]] & 1) --odd; n     if (a[i] != a[k]) { n       if (cnt[a[k]] < 0) --neg; n       if (cnt[a[k]] & 1) --odd; n     } n     --cnt[a[i]]; n     if (i < k && k <= j) { n       if (i != k) --cnt[a[i]]; n     } else { n       ++cnt[a[k]]; n     } n     if (cnt[a[i]] < 0) ++neg; n     if (cnt[a[i]] & 1) ++odd; n     if (a[i] != a[k]) { n       if (cnt[a[k]] < 0) ++neg; n       if (cnt[a[k]] & 1) ++odd; n     } n     res += n - j + 1; n     ++i; n   } n   cout << res << endl; n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Mod = 1e9 + 7; n const long long INF = (long long)(1e18) + 5; n const long long N = 2e5 + 5, M = 18; n int n, m, p; n int a[N]; n tuple<long long, long long, long long> b[N]; n long long suf_s[N], suf_c[N]; n long long dp[N], prev_dp[N]; n void solve(int i, int j, int l, int r) { n   if (j < i) return; n   int mid = i + j >> 1; n   long long best = INF, idx = -1; n   long long cnt = 0, sum = 0; n   if (mid < l) { n     sum += suf_s[mid] - suf_s[l]; n     cnt += suf_c[mid] - suf_c[l]; n   } n   for (int k = max(mid, l); k <= r; k++) { n     auto [t, c, s] = b[k]; n     sum += s; n     cnt += c; n     long long cur = sum + cnt * t + prev_dp[k + 1]; n     if (cur < best) best = cur, idx = k; n   } n   dp[mid] = best; n   solve(i, mid - 1, l, idx); n   solve(mid + 1, j, idx, r); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m >> p; n   for (int i = 1; i < n; i++) cin >> a[i], a[i] += a[i - 1]; n   map<long long, long long> cnt, sum; n   long long ans2 = 0; n   for (int i = 0; i < m; i++) { n     int h, t; n     cin >> h >> t; n     h--; n     cnt[t - a[h]]++; n     sum[t - a[h]] += a[h] - t; n   } n   m = 0; n   for (auto [i, j] : cnt) b[m++] = {i, j, sum[i]}; n   for (int i = m; i >= 0; i--) { n     auto [t, c, s] = b[i]; n     suf_s[i] = s + suf_s[i + 1]; n     suf_c[i] = c + suf_c[i + 1]; n   } n   for (int i = 0; i < m; i++) dp[i] = INF; n   while (p--) { n     swap(dp, prev_dp); n     solve(0, m - 1, 0, m - 1); n   } n   cout << dp[0] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = 1e9 + 9; n const long long N = 500500; n signed main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout.precision(10); n   cout << fixed; n   long long v; n   cin >> v; n   if (v == 2) { n     cout << 2; n     return 0; n   } n   cout << 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void dfs(bool* visit, vector<int>* am, int n, int sv, vector<int>& v) { n   visit[sv] = true; n   v.push_back(sv); n   for (int p = 0; p < am[sv].size(); ++p) { n     if (visit[am[sv][p]] == false) { n       dfs(visit, am, n, am[sv][p], v); n     } n   } n   return; n } n int main() { n   int n, m; n   cin >> n >> m; n   int* arr = new int[n]; n   vector<int>* graph = new vector<int>[n]; n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     graph[a - 1].push_back(b - 1); n     graph[b - 1].push_back(a - 1); n   } n   bool* visit = new bool[n](); n   long long count = 1; n   for (int cur = 0; cur < n; ++cur) { n     if (visit[cur] == false) { n       vector<int> v; n       dfs(visit, graph, n, cur, v); n       int p = v.size() - 1; n       for (int j = 1; j <= p; ++j) { n         count = count * 2; n       } n     } n   } n   cout << count << endl; n } n


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


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


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int n, m; n int a[300000]; n int s[300000]; n int main() { n   int i, j, k, l; n   cin >> n >> m; n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   m--; n   int ans = 0; n   if (a[m] != 0) ans = 1, a[m] = 0; n   if (n == 1) return !printf( %d , ans); n   for (i = 0; i < n; i++) s[a[i]]++; n   int z = 0; n   int now = 0; n   int mi = 0x3f3f3f3f; n   for (i = 1; i < n; i++) { n     if (s[i] == 0) z++; n     now += s[i]; n     mi = min(mi, max(n - 1 - now, z)); n   } n   cout << ans + mi; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i; n   printf( 9 ? ?>> ? ?0 n ); n   for (i = 8; i >= 0; i--) printf( %d ? ?<>%d n , i, i + 1); n   printf(  ? ?<>1 n ); n   for (i = 9; i >= 0; i--) printf( ?%d>>%d? n , i, i); n   printf( >>? n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const long long mod = 1e9 + 7; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   unsigned long long n; n   cin >> n; n   unsigned long long c = 2 * 3 * 4 * 5 * 7 * 3; n   if (c > n) { n     cout <<  0 n ; n     return 0; n   } n   cout << n / c <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n //using namespace atcoder; n struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; n #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) n #define REP(i, n) FOR(i,0,n) n #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) n #define IREP(i, n) IFOR(i,0,n) n #define Sort(v) sort(v.begin(), v.end()) n #define Reverse(v) reverse(v.begin(), v.end()) n #define all(v) v.begin(),v.end() n #define SZ(v) ((int)v.size()) n #define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x)) n #define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x)) n #define chmax(a, b) a = max(a, b) n #define chmin(a, b) a = min(a, b) n #define bit(n) (1LL<<(n)) n #define debug(x) cout << #x <<  =  << x << endl; n #define vdebug(v) { cout << #v <<  =  << endl; REP(i_debug, v.size()){ cout << v[i_debug] <<  , ; } cout << endl; } n #define mdebug(m) { cout << #m <<  =  << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] <<  , ; } cout << endl;} } n #define pb push_back n #define fi first n #define se second n #define int long long n #define INF 1000000000000000000 n template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; } n template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; } n template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout <<  (  << p.first <<  ,  << p.second <<  ) ; return os; } n template<typename T> void Out(T x) { cout << x << endl; } n template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); } n  n using vec = vector<int>; n using mat = vector<vec>; n using Pii = pair<int, int>; n using v_bool = vector<bool>; n using v_Pii = vector<Pii>; n  n //int dx[4] = {1,0,-1,0}; n //int dy[4] = {0,1,0,-1}; n //char d[4] = { D , R , U , L }; n  n const int mod = 1000000007; n //const int mod = 998244353; n  n struct edge{int to, cost, id;}; n  n class Graph n { n public: n     int N; n     vector<vector<edge>> G; n  n     Graph(int N): N(N){ n         G = vector<vector<edge>>(N, vector<edge>(0)); n     } n  n     void add_Directed_edge(int from, int to, int cost = 1, int id = 0){ n         G[from].push_back(edge({to, cost, id})); n     } n  n     void add_Undirected_edge(int v1, int v2, int cost = 1, int id = 0){ n         add_Directed_edge(v1, v2, cost, id); n         add_Directed_edge(v2, v1, cost, id); n     } n  n     //二部グラフ判定 n     vector<int> color; n     bool is_bipartite(){ n         color = vec(N, -1); n         REP(i, N) if(color[i] == -1){ n             if(!dfs_for_check_bipartite(i, 0)) return false; n         } n         return true; n     } n     bool dfs_for_check_bipartite(int v, int c){ n         if(color[v] != -1){ n             if(color[v] == c) return true; n             else return false; n         } n         color[v] = c; n         for(auto e: G[v]) if(!dfs_for_check_bipartite(e.to, (c + e.cost) & 1)) return false; n         return true; n     } n  n  n     vec bellman_ford(int s, bool &ok){ n         ok = false; n         vec d(N); n         fill(d.begin(), d.end(), INF); n         d[s] = 0; n         REP(t, N){ n             bool update = false; n             REP(v, N){ n                 REP(i, G[v].size()){ n                     edge e = G[v][i]; n                     if(d[v] != INF && d[e.to] > d[v] + e.cost){ n                         d[e.to] = d[v] + e.cost; n                         update = true; n                     } n                 } n             } n             if(!update){ n                 ok = true; n                 break; n             } n         } n         return d; n     } n  n }; n  n void imp(){ n     Out( NO ); n     exit(0); n } n  n signed main(){ n  n     int n, m; cin >> n >> m; n     Graph G(n); n     REP(_, m){ n         int i, j, b; cin >> i >> j >> b; n         i--; j--; n         if(b == 0){ n             G.add_Directed_edge(i, j, 1); n             G.add_Directed_edge(j, i, 1); n         }else{ n             G.add_Directed_edge(i, j, 1); n             G.add_Directed_edge(j, i, -1); n         } n     } n  n     if(!G.is_bipartite()) imp(); n  n     vec ans(n); n     int M = -1; n     REP(s, n){ n         bool ok; n         vec d = G.bellman_ford(s, ok); n         if(!ok) continue; n         int mm = INF, MM = -INF; n         REP(i, n){ n             chmin(mm, d[i]); n             chmax(MM, d[i]); n         } n         if(MM - mm > M){ n             M = MM - mm; n             REP(i, n) ans[i] = d[i] - mm; n         } n     } n  n     if(M == -1) imp(); n     Out( YES ); n     Out(M); n     REP(i, n) cout << ans[i] <<    ; n     cout << endl; n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y, neg, pos; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     if (x < 0) n       neg++; n     else n       pos++; n   } n   if (pos <= 1 || neg <= 1) 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   long long n, i, x1, y1, x2, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   cout << (x2 - x1) * (y2 - y1) + 1 <<   n ; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tt; n   cin >> tt; n   while (tt--) { n     solve(); 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 const int maxN = 1e5 + 5; n long double N, t; n long double Pow(long double b, long long e) { n   if (e == 0) return 1; n   long double ret = Pow(b, e / 2); n   ret *= ret; n   if (e % 2) return ret * b; n   return ret; n } n int main() { n   cin >> N >> t; n   N *= Pow(1.000000011, t); n   printf( %.12lf , (double)N); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long i, j, c = 0, k, n, x = 0, y = 0; n   char ch; n   string s; n   cin >> n; n   cin >> s; n   for (i = 0; i < n - 1; i++) { n     if (s[i] ==  U ) { n       y = y + 1; n     } n     if (s[i] ==  R ) { n       x = x + 1; n     } n     if (x == y) { n       ch = s[i]; n       if (s[i + 1] == ch) { n         c++; n       } n     } n   } n   cout << c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, m, k, fa[N], cnt[N], vis[N]; n vector<int> G[N]; n vector<pair<int, int> > p, q[N]; n int findset(int x) { return x == fa[x] ? x : fa[x] = findset(fa[x]); } n void dfs(int x) { n   vis[x] = 1; n   for (auto it : G[x]) dfs(it); n   for (auto it : q[x]) n     if (vis[it.first]) cnt[it.second]++; n   vis[x] = 0; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i <= n; i++) fa[i] = i; n   int opt, x, y; n   while (m--) { n     scanf( %d %d , &opt, &x); n     if (opt == 1) n       scanf( %d , &y), fa[x] = y, G[y].push_back(x); n     else if (opt == 2) n       p.push_back({findset(x), x}); n     else { n       scanf( %d , &y); n       q[x].push_back({p[y - 1].first, k}); n       q[p[y - 1].second].push_back({x, k}); n       k++; n     } n   } n   for (int i = 1; i <= n; i++) n     if (fa[i] == i) dfs(i); n   for (int i = 0; i < k; i++) printf( %s n , cnt[i] == 2 ?  YES  :  NO ); n   return 0; n } n