#include <bits/stdc++.h> n using namespace std; n const int MN = 111; n int a[MN], n, g[MN][MN], c[MN]; n struct Block { n   int f[MN][MN]; n   void cal1() { n     memset(f, 0, sizeof f); n     for (int from = (1), _b = (100); from <= _b; from++) { n       for (int to = (from), _b = (100); to <= _b; to++) f[from][to] = 0; n       memset(g, 0, sizeof g); n       for (int i = (1), _b = (n); i <= _b; i++) { n         for (int to = (from), _b = (100); to <= _b; to++) n           g[i][to] = g[i - 1][to]; n         if (a[i] >= from) { n           g[i][a[i]] = max(g[i][a[i]], 1); n           for (int prev = (from), _b = (a[i]); prev <= _b; prev++) n             g[i][a[i]] = max(g[i][a[i]], g[i - 1][prev] + 1); n         } n       } n       for (int to = (from), _b = (100); to <= _b; to++) f[from][to] = g[n][to]; n     } n   } n   void print() { n     for (int from = (1), _b = (4); from <= _b; from++) { n       for (int to = (1), _b = (4); to <= _b; to++) cout << f[from][to] <<    ; n       cout << endl; n     } n     cout <<  ----  << endl; n   } n } f[30], trans; n Block operator+(const Block& a, const Block& b) { n   Block res; n   memset(res.f, 0, sizeof res.f); n   for (int from = (1), _b = (100); from <= _b; from++) { n     for (int to = (1), _b = (100); to <= _b; to++) { n       res.f[from][to] = a.f[from][to]; n       for (int mid = (from), _b = (to); mid <= _b; mid++) n         res.f[from][to] = max(res.f[from][to], a.f[from][mid] + b.f[mid][to]); n     } n   } n   return res; n } n void RR() { n   for (int i = (1), _b = (n); i <= _b; i++) c[i] = a[i]; n   sort(c + 1, c + n + 1); n   int sc = unique(c + 1, c + n + 1) - c - 1; n   for (int i = (1), _b = (n); i <= _b; i++) n     a[i] = lower_bound(c + 1, c + n + 1, a[i]) - c; n } n int main() { n   ios ::sync_with_stdio(false); n   int T; n   while (cin >> n >> T) { n     for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i]; n     RR(); n     f[0].cal1(); n     for (int i = (1), _b = (23); i <= _b; i++) f[i] = f[i - 1] + f[i - 1]; n     bool first = true; n     for (int bit = 0, _a = (24); bit < _a; bit++) n       if ((T >> bit) & 1) { n         if (first) { n           first = false; n           trans = f[bit]; n         } else n           trans = trans + f[bit]; n       } n     int res = 0; n     for (int from = (1), _b = (100); from <= _b; from++) n       for (int to = (from), _b = (100); to <= _b; to++) { n         res = max(res, trans.f[from][to]); n         if (res == 8) { n           cout << from <<     << to << endl; n           assert(0); n         } n       } n     cout << res << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300 + 10; n const int maxm = maxn * maxn; n const int INF = 0x3f3f3f3f; n int connect[maxn][maxn], edgecnt[maxn]; n int price[maxn], vis[maxn * 2], match[maxn * 2]; n int n; n bool extend(int u) { n   vis[u] = true; n   for (int i = 1; i <= edgecnt[u]; i++) { n     int v = connect[u][i] + n; n     if (vis[v] || v == match[u]) continue; n     vis[v] = true; n     if (match[v] == 0 || extend(match[v])) { n       match[u] = v; n       match[v] = u; n       return true; n     } n   } n   return false; n } n void Match() { n   memset(match, 0, sizeof(match)); n   for (int i = 1; i <= n; i++) { n     if (match[i]) continue; n     memset(vis, 0, sizeof(vis)); n     extend(i); n   } n   for (int i = 1; i <= 2 * n; i++) { n   } n } n int S, T; n struct Edge { n   Edge *n, *o; n   int v, c, w; n   void init(int _v, int _c, int _w) { n     v = _v; n     c = _c; n     w = _w; n   } n }; n Edge *E[maxn * 2], Er[maxn * maxn * 2]; n int Es = 0; n void addedge(int u, int v, int c, int w) { n   static Edge *P1, *P2; n   P1 = &Er[++Es]; n   P2 = &Er[++Es]; n   P1->init(v, c, w); n   P1->n = E[u]; n   P1->o = P2; n   E[u] = P1; n   P2->init(u, 0, -w); n   P2->n = E[v]; n   P2->o = P1; n   E[v] = P2; n } n int H[maxn * 2]; n bool V[maxn * 2]; n bool BFS() { n   static int Q[maxn * 20], bot, u, v; n   memset(H, INF, sizeof(H)); n   memset(V, true, sizeof(V)); n   H[Q[bot = 1] = S] = 0; n   V[S] = false; n   for (int top = 1; top <= bot; top++) { n     u = Q[top]; n     for (Edge *P = E[u]; P; P = P->n) n       if (P->c && H[P->v] > H[u] + 1) { n         H[P->v] = H[u] + 1; n         if (V[P->v]) { n           Q[++bot] = P->v; n           V[P->v] = false; n         } n       } n     V[u] = true; n   } n   return H[T] < INF; n } n int extend(int u, int lefts) { n   if (u == T) { n     return lefts; n   } n   V[u] = false; n   int ret = 0, t; n   for (Edge *P = E[u]; P && ret < lefts; P = P->n) { n     if (P->c && V[P->v] && H[u] + 1 == H[P->v]) { n       t = extend(P->v, min(lefts - ret, P->c)); n       ret += t; n       P->c -= t; n       P->o->c += t; n     } n   } n   V[u] = true; n   if (ret < lefts) H[u] = INF; n   return ret; n } n int maxflow() { n   int ret = 0, cnt = 0; n   while (BFS()) { n     ret += extend(S, INF); n   } n   return ret; n } n void build() { n   memset(E, 0, sizeof(E)); n   for (int i = 1; i <= n; i++) { n     if (price[i] >= 0) { n       addedge(S, i, price[i], 1); n     } else { n       addedge(i, T, -price[i], 1); n     } n     for (int j = 1; j <= edgecnt[i]; j++) { n       int t = match[connect[i][j] + n]; n       addedge(i, t, INF, 1); n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &edgecnt[i]); n     for (int j = 1; j <= edgecnt[i]; j++) { n       scanf( %d , &connect[i][j]); n     } n   } n   S = 0; n   T = 2 * n + 1; n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , price + i); n     price[i] *= -1; n     if (price[i] >= 0) ans += price[i]; n   } n   Match(); n   build(); n   ans = maxflow() - ans; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int v[200010]; n int c[200010]; n int ans[200010]; n string s; n priority_queue<pair<int, pair<int, int> > > pi, pe; n int main() { n   memset(c, 0, sizeof c); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> v[i]; n     pi.push({0, {-v[i], i}}); n   } n   string s; n   cin >> s; n   for (int i = 0; i < (int)s.size(); ++i) { n     if (s[i] ==  0 ) { n       int no = pi.top().first; n       int wd = pi.top().second.first; n       int id = pi.top().second.second; n       pi.pop(); n       ans[i] = id; n       pe.push({100, {-wd, id}}); n     } else { n       int no = pe.top().first; n       int wd = pe.top().second.first; n       int id = pe.top().second.second; n       pe.pop(); n       ans[i] = id; n     } n   } n   for (int i = 0; i < (int)s.size(); ++i) cout << ans[i] + 1 <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[101]; n int main() { n   int n, i, l; n   long long int ans = 0; n   scanf( %s , a); n   l = strlen(a); n   for (i = 0; i < l; i++) { n     if (a[i] ==  4 ) n       a[i] =  1 ; n     else n       a[i] =  2 ; n   } n   long long int c = 1; n   for (i = l - 1; i >= 0; i--) { n     ans = ans + c * (a[i] -  0 ); n     c = c * 2; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const int LEN = 8; n const int MASK = (1 << LEN); n const int maxn = 240; n double f[2][LEN + 1][MASK][2][maxn + 1]; n int old, now; n double result; n int n, original; n double add1, time2; n void init() { n   int P; n   scanf( %d%d%d , &original, &n, &P); n   time2 = P / 100.0; n   add1 = 1 - time2; n } n int numlen(int x) { n   int len = 0; n   if (x == 0) return 1; n   while (x) { n     ++len; n     x = (x >> 1); n   } n   return len; n } n int count0(int x) { n   int g0 = 0; n   while ((x > 0) && ((x & 1) == 0)) { n     x = (x >> 1); n     ++g0; n   } n   return g0; n } n int count1(int x) { n   int g1 = 0; n   while ((x > 0) && ((x & 1) == 1)) { n     x = (x >> 1); n     ++g1; n   } n   return g1; n } n inline void calc(int &d, int &plen, int nd, int &d2, int &plen2) { n   if (nd == d) { n     d2 = d; n     plen2 = plen + 1; n   } else { n     d2 = nd; n     plen2 = 1; n   } n } n void work() { n   int i, len, num, digit, prelen, tmp, len2, num2, digit2, prelen2; n   now = 0; n   for (len = 1; len <= LEN; ++len) n     for (num = 0; num < (1 << len); ++num) n       for (digit = 0; digit < 2; ++digit) n         for (prelen = 0; prelen <= maxn; ++prelen) n           f[now][len][num][digit][prelen] = 0; n   if (numlen(original) <= LEN) n     f[now][numlen(original)][original][0][0] = 1; n   else { n     tmp = original >> LEN; n     if ((tmp & 1) == 0) n       f[now][LEN][original & ((1 << LEN) - 1)][0][count0(tmp)] = 1; n     else n       f[now][LEN][original & ((1 << LEN) - 1)][1][count1(tmp)] = 1; n   } n   for (i = 1; i <= n; ++i) { n     old = now; n     now = 1 - now; n     for (len = 1; len <= LEN; ++len) n       for (num = 0; num < (1 << len); ++num) n         for (digit = 0; digit < 2; ++digit) n           for (prelen = 0; prelen <= maxn; ++prelen) n             f[now][len][num][digit][prelen] = 0; n     for (len = 1; len <= LEN; ++len) n       for (num = 0; num < (1 << len); ++num) n         for (digit = 0; digit < 2; ++digit) n           for (prelen = 0; prelen <= maxn; ++prelen) n             if (f[old][len][num][digit][prelen] > 1e-16) { n               len2 = len; n               num2 = num; n               digit2 = digit; n               prelen2 = prelen; n               if (len < LEN) { n                 len2 = len + 1; n                 num2 = num << 1; n               } else { n                 if (num & (1 << (LEN - 1))) n                   calc(digit, prelen, 1, digit2, prelen2); n                 else n                   calc(digit, prelen, 0, digit2, prelen2); n                 num2 = ((num << 1) & ((1 << LEN) - 1)); n               } n               f[now][len2][num2][digit2][prelen2] += n                   f[old][len][num][digit][prelen] * time2; n               len2 = len; n               num2 = num; n               digit2 = digit; n               prelen2 = prelen; n               if (num + 1 < (1 << len)) n                 num2 = num + 1; n               else { n                 if (len < LEN) { n                   num2 = num + 1; n                   len2 = len + 1; n                 } else { n                   num2 = 0; n                   if (digit == 0) { n                     digit2 = 1; n                     prelen2 = 1; n                   } else { n                     digit2 = 0; n                     prelen2 = prelen; n                   } n                 } n               } n               f[now][len2][num2][digit2][prelen2] += n                   f[old][len][num][digit][prelen] * add1; n             } n   } n } n void output() { n   int i, j, d, k; n   int g0; n   result = 0; n   for (i = 1; i <= LEN; ++i) n     for (j = 0; j < (1 << i); ++j) n       for (d = 0; d < 2; ++d) n         for (k = 0; k <= maxn; ++k) { n           if (j == 0) { n             g0 = i; n             if (d == 0) g0 += k; n           } else n             g0 = count0(j); n           result += f[now][i][j][d][k] * g0; n         } n   printf( %.10lf n , result); n } n int main() { n   init(); n   work(); n   output(); n   return 0; n } n


#include <bits/stdc++.h> n int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; n int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; n const double PI = acos(-1), EPS = 1e-7; n const int OO = 0x3f3f3f3f, N = 1e6 + 5, mod = 1e9 + 7; n using namespace std; n long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); } n long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); } n void file() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int n, red, blue, cnt; n vector<vector<int>> g; n vector<int> col; n pair<int, int> DFS(int v, int p = -1) { n   int r = (col[v] == 1), b = (col[v] == 2); n   for (auto u : g[v]) n     if (u != p) { n       auto tmp = DFS(u, v); n       cnt += (tmp.first == red && tmp.second == 0); n       cnt += (tmp.first == 0 && tmp.second == blue); n       r += tmp.first; n       b += tmp.second; n     } n   return make_pair(r, b); n } n int main() { n   file(); n   cin >> n; n   g = vector<vector<int>>(n + 1); n   col = vector<int>(n + 1); n   for (int i = 1; i <= n; i++) { n     cin >> col[i]; n     if (col[i] == 1) red++; n     if (col[i] == 2) blue++; n   } n   n--; n   while (n--) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   DFS(1, -1); n   cout << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n int num[200000 + 5]; n int main() { n   int i, j, k, n, m; n   cin >> n; n   long long sum = 0; n   for (i = 0; i < n; i++) { n     cin >> num[i]; n     sum += num[i]; n   } n   long long ans = 0; n   sum++; n   sum /= 2; n   for (i = 0; i < n; i++) { n     ans += num[i]; n     if (ans >= sum) { n       cout << i + 1 << endl; n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n queue<int> d[110]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     for (int j = (n / 2) * (i - 1) + 1, g = 1; g <= (n / 2); j++, g++) { n       d[i].push(j); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = (n / 2) * (n + i - 1) + 1, g = 1; g <= (n / 2); j++, g++) { n       d[n - i + 1].push(j); n     } n   } n   for (int i = 1; i <= n; i++) { n     while (!d[i].empty()) { n       printf( %d  , d[i].front()); n       d[i].pop(); n     } n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10; n const int block = 450; n int n, p[maxn], l[maxn], cost[maxn], nxt[maxn], f[maxn], g[maxn], aft[maxn], n     bit[maxn << 2]; n void update(int pos, int x) { n   for (; pos <= n; pos += (pos & -pos)) bit[pos] = max(bit[pos], x); n } n int get(int pos) { n   int res = 0; n   for (; pos > 0; pos -= (pos & -pos)) res = max(res, bit[pos]); n   return res; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) scanf( %d%d , &p[i], &l[i]); n   for (int i = n - 1; i > -1; i--) { n     int pos = upper_bound(p, p + n, p[i] + l[i]) - p; n     f[i] = max(get(pos), p[i] + l[i]); n     update(i + 1, f[i]); n     aft[i] = upper_bound(p, p + n, f[i]) - p; n     if (i / block == (n - 1) / block) continue; n     if (aft[i] / block > i / block) { n       nxt[i] = aft[i]; n       g[i] = f[i]; n     } else { n       nxt[i] = nxt[aft[i]]; n       g[i] = g[aft[i]]; n       cost[i] = cost[aft[i]] + p[aft[i]] - f[i]; n     } n   } n   int q; n   cin >> q; n   while (q--) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--, y--; n     int ans = 0; n     while (x / block < y / block && g[x] < p[y]) { n       ans += cost[x] + p[nxt[x]] - g[x]; n       x = nxt[x]; n     } n     if (x / block < y / block) { n       ans += cost[x]; n       printf( %d n , ans); n       continue; n     } n     while (f[x] < p[y]) { n       ans += p[aft[x]] - f[x]; n       x = aft[x]; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> f(200005, 0), d(200005, 0), l(200005, 0), r(200005, -1); n map<pair<long long int, long long int>, long long int> mp; n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int bpow(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % 1000000007; n     a = (a * a) % 1000000007; n     b >>= 1; n   } n   return res % 1000000007; n } n void fact(long long int i) { n   f[0] = 1; n   for (long long int k = 1; k <= i; k++) { n     (f[k] = f[k - 1] * k) %= 1000000007; n   } n } n long long int isprime(long long int n) { n   if (n == 1) return 0; n   for (long long int i = 2; i <= sqrt(n); i++) n     if (n % i == 0) return 0; n   return 1; n } n long long int find(long long int x) { n   if (f[x] == x) n     return x; n   else n     return f[x] = find(f[x]); n } n bool cmp(long long int x, long long int y) { return x < y; } n long long int comb(long long int i, long long int j) { n   long long int k = f[i]; n   long long int g = (f[j] * (f[i - j])) % 1000000007; n   long long int h = bpow(g, 1000000007 - 2); n   return (k * h) % 1000000007; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   vector<long long int> a(n); n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   long long int mx = 0; n   for (long long int i = 0; i < n; i++) { n     mx = max(mx, a[i]); n   } n   for (long long int i = 0; i < n; i++) { n     long long int k = a[i], c = 0; n     while (k > 0) { n       f[k]++; n       r[k] = i; n       l[k] += (c); n       long long int h = k, j = c; n       while (h <= mx) { n         h *= 2; n         j++; n         if (r[h] != i) { n           f[h]++; n           r[h] = i; n           l[h] += j; n         } else n           break; n       } n       k /= 2; n       c++; n     } n   } n   long long int ans = 1e18; n   for (long long int i = 1; i <= 100000; i++) { n     if (f[i] == n) { n       ans = min(ans, l[i]); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> out[1000]; n int main() { n   int n; n   scanf( %d , &n); n   int ans; n   for (int i = 1; i * (i - 1) / 2 <= n; i++) { n     ans = i; n   } n   int id = 1; n   for (int i = 0; i < ans; i++) { n     for (int j = i + 1; j < ans; j++) { n       out[i].push_back(id); n       out[j].push_back(id); n       id++; n     } n   } n   printf( %d n , ans); n   for (int i = 0; i < ans; i++, puts(  )) n     for (int j = 0; j < out[i].size(); j++) printf( %d  , out[i][j]); n   return 0; n } n


#include <bits/stdc++.h> n namespace IO { n const long long IN_LEN = 1 << 18 | 1; n static char buf[IN_LEN], *s, *t; n inline long long Getchar(void) { n   return s == t && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)), n          s == t ? -1 : *s++; n } n template <class T> n inline void read(T& x) { n   static long long c, f; n   c = Getchar(), x = f = 0; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = 1; n     c = Getchar(); n   } n   while (c <=  9  && c >=  0 ) x = x * 10 + c - 48, c = Getchar(); n   x = f ? -x : x; n } n }  // namespace IO n using IO::read; n using namespace std; n const long long N = 1e5 + 5; n const long long INF = 0x3f3f3f3f3f3f3f3fLL; n long long head[N], eidx, dis[N], n, m, f[N]; n struct Edge { n   long long nxt, to, val; n } edge[N]; n queue<long long> q[N]; n priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, n                greater<pair<long long, long long> > > n     Q; n void dij(void) { n   static long long u, w; n   memset(dis, 0x3f, sizeof dis); n   Q.push(pair<long long, long long>(dis[1] = 0, 1)); n   while (!Q.empty()) { n     u = Q.top().second, w = Q.top().first; n     Q.pop(); n     if (dis[u] != w) continue; n     for (long long i = head[u], v; i; i = edge[i].nxt) n       if (dis[v = edge[i].to] > dis[u] + edge[i].val) n         Q.push(pair<long long, long long>(dis[v] = dis[u] + edge[i].val, v)); n   } n } n void bfs(const long long& lim) { n   static long long u, mx; n   mx = 0; n   memset(f, 0x3f, sizeof f); n   q[0].push(1), f[1] = 0; n   for (long long c = 0; c <= mx; ++c) { n     while (!q[c].empty()) { n       u = q[c].front(); n       q[c].pop(); n       if (f[u] < c) continue; n       for (long long i = head[u], v; i; i = edge[i].nxt) n         if (f[(v = edge[i].to)] > dis[u] - dis[v] + edge[i].val + f[u]) { n           f[v] = dis[u] - dis[v] + edge[i].val + f[u]; n           if (f[v] <= lim && f[v] < n - 1) q[f[v]].push(v), mx = max(mx, f[v]); n         } n     } n   } n } n signed main(void) { n   long long q; n   read(n), read(m), read(q); n   for (long long i = 1, u, v, w; i <= m; ++i) { n     read(u), read(v), read(w); n     edge[++eidx] = (Edge){head[u], v, w}; n     head[u] = eidx; n   } n   dij(); n   long long opt, x, y; n   while (q--) { n     read(opt), read(x); n     if (opt == 1) n       printf(dis[x] == INF ?  -1 n  :  %lld n , dis[x]); n     else { n       for (long long i = 1; i <= x; ++i) { n         read(y); n         ++edge[y].val; n       } n       bfs(x); n       for (long long i = 1; i <= n; ++i) dis[i] = min(INF, dis[i] + f[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n, j, temp, num; n   stringstream s, t; n   cin >> a >> b >> n; n   string out; n   s << a; n   num = a; n   for (j = 0; j < 10; j++) { n     s << j; n     s >> temp; n     if (temp % b == 0) { n       num = temp; n       s.clear(); n       s << num; n       break; n     } else { n       s.clear(); n       s << num; n     } n   } n   if (j == 10) n     cout << -1; n   else { n     for (int i = 0; i < n - 1; i++) s <<  0 ; n     s >> out; n     cout << out; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[1000001]; n int main() { n   int n, ind = 0, w, input; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> input; n     p[input]++; n     if (ind < p[input]) { n       ind = p[input]; n       w = input; n     } n   } n   cout << w << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long calc_gcd(long long a, long long b) { n   while (true) n     if (a) n       b %= a, swap(a, b); n     else n       return b; n } n void foo() { n   long long A, M; n   cin >> A >> M; n   long long gcd = calc_gcd(A, M); n   A /= gcd; n   M /= gcd; n   set<long long> yakusuu; n   long long tmp = M; n   while (tmp % 2 == 0) { n     yakusuu.insert(2); n     tmp /= 2; n   } n   for (long long i = 3; i * i <= M; i += 2) { n     while (tmp % i == 0) { n       yakusuu.insert(i); n       tmp /= i; n     } n   } n   if (tmp > 1) { n     yakusuu.insert(tmp); n     tmp = 1; n   } n   vector<long long> yakusuu_vec; n   for (auto it : yakusuu) yakusuu_vec.push_back(it); n   long long limit = 1; n   limit <<= yakusuu_vec.size(); n   long long foo = 0; n   long long bar = 0; n   for (long long i = 0; i < limit; i++) { n     long long tmp = 1; n     long long count = 0; n     for (long long k = 0; k < (yakusuu_vec.size()); k++) { n       if (((i >> k) & 1) == 1) { n         tmp *= yakusuu_vec[k]; n         count++; n       } n     } n     if (count % 2) { n       foo -= (A + M - 1) / tmp; n       bar -= (A - 1) / tmp; n     } else { n       foo += (A + M - 1) / tmp; n       bar += (A - 1) / tmp; n     } n   } n   cout << (foo - bar) << endl; n } n void solve() { n   long long T; n   cin >> T; n   for (long long t = 0; t < (T); t++) foo(); n } n int main(void) { n   cin.tie(0); n   ios::sync_with_stdio(false); n   cout.precision(12); n   cout << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int fib[51]; n vector<long long int> calc(long long int n, long long int k) { n   vector<long long int> res; n   if (!n) return res; n   if (n == 1) { n     res.push_back(1); n     return res; n   } n   if (k <= fib[n - 1]) { n     res.push_back(1); n     vector<long long int> v = calc(n - 1, k); n     for (auto i : v) res.push_back(i + 1); n   } else { n     res.push_back(2); n     res.push_back(1); n     vector<long long int> v = calc(n - 2, k - fib[n - 1]); n     for (auto i : v) res.push_back(i + 2); n   } n   return res; n } n void solve() { n   fib[1] = 1, fib[2] = 2; n   for (long long int i = 3; i <= 50; i++) fib[i] = fib[i - 1] + fib[i - 2]; n   long long int n, k; n   cin >> n >> k; n   vector<long long int> ans = calc(n, k); n   for (auto i : ans) cout << i <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cout.precision(20); n   long long int t = 1; n   for (long long int i = 1; i <= t; i++) { n     if (0) cout <<  Case #  << i <<  :  ; n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void pv(T a, T b) { n   for (T i = a; i != b; ++i) cout << *i <<    ; n   cout << endl; n } n template <class T> n void chmin(T &t, T f) { n   if (t > f) t = f; n } n template <class T> n void chmax(T &t, T f) { n   if (t < f) t = f; n } n int in() { n   int x; n   scanf( %d , &x); n   return x; n } n int N; n long long T[10010], C[10010]; n int main() { n   int i; n   for (; ~scanf( %d , &N);) { n     for (i = 0; i < N; ++i) { n       T[i] = in(); n       C[i] = in(); n     } n     long long ans = 0; n     long long t = 0; n     for (i = 0; i < N; ++i) { n       if (t <= T[i]) { n         chmax(ans, C[i]); n         t = T[i] + C[i]; n       } else { n         chmax(ans, (t - T[i]) + C[i]); n         t += C[i]; n       } n     } n     cout << t <<     << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a[100009], dau, cuoi, d[100009], c[100009], Res; n string st; n void Input() { n   cin >> n >> k >> st; n   for (int i = 0; i < n; ++i) { n     a[i + 1] = st[i] -  a ; n   } n } n void Solve() { n   dau = 1; n   cuoi = 1; n   d[0] = 0; n   c[0] = 0; n   while (cuoi <= n) { n     if (a[cuoi] == 0) { n       d[cuoi] = d[cuoi - 1] + 1; n       c[cuoi] = c[cuoi - 1]; n     } else { n       if (c[cuoi - 1] + 1 <= k) { n         d[cuoi] = d[cuoi - 1] + 1; n         c[cuoi] = c[cuoi - 1] + 1; n       } else { n         c[cuoi] = c[cuoi - 1] + 1; n         d[cuoi] = d[cuoi - 1] + 1; n         while (dau <= cuoi) { n           if (c[cuoi] > k) { n             if (a[dau] == 1) { n               c[cuoi]--; n             } n             dau++; n             d[cuoi]--; n           } else n             break; n         } n       } n     } n     Res = max(Res, d[cuoi]); n     cuoi++; n   } n   dau = 1; n   cuoi = 1; n   d[0] = 0; n   c[0] = 0; n   while (cuoi <= n) { n     if (a[cuoi] == 1) { n       d[cuoi] = d[cuoi - 1] + 1; n       c[cuoi] = c[cuoi - 1]; n     } else { n       if (c[cuoi - 1] + 1 <= k) { n         d[cuoi] = d[cuoi - 1] + 1; n         c[cuoi] = c[cuoi - 1] + 1; n       } else { n         c[cuoi] = c[cuoi - 1] + 1; n         d[cuoi] = d[cuoi - 1] + 1; n         while (dau <= cuoi) { n           if (c[cuoi] > k) { n             if (a[dau] == 0) { n               c[cuoi]--; n             } n             dau++; n             d[cuoi]--; n           } else n             break; n         } n       } n     } n     Res = max(Res, d[cuoi]); n     cuoi++; n   } n   cout << Res; n } n int main() { n   Input(); n   Solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   int c[n], w[m]; n   for (int i = 0; i < n; i++) cin >> c[i]; n   for (int i = 0; i < m; i++) cin >> w[i]; n   int res = 0; n   int j = 0; n   for (int i = 0; i < n; i++) { n     if (j > m - 1) { n       break; n     } n     if (w[j] >= c[i]) { n       res++; n       j++; n     } n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1}; n const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1}; n const double eps = 1e-9; n template <class T> n void print(const vector<T> &v) { n   ostringstream os; n   for (int i = 0; i < (int)v.size(); ++i) { n     if (i) os <<    ; n     os << v[i]; n   } n   cout << os.str() << endl; n } n template <class T> n int sz(const T &c) { n   return (int)c.size(); n } n template <class T> n void srt(T &c) { n   sort(c.begin(), c.end()); n } n template <class T> n void checkmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n void checkmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n T sqr(T x) { n   return x * x; n } n template <class T, class U> n T cast(U x) { n   ostringstream os; n   os << x; n   T res; n   istringstream is(os.str()); n   is >> res; n   return res; n } n template <class T> n vector<T> split(string s, string x =    ) { n   vector<T> res; n   for (int i = 0; i < s.size(); i++) { n     string a; n     while (i < (int)s.size() && x.find(s[i]) == string::npos) a += s[i++]; n     if (!a.empty()) res.push_back(cast<T>(a)); n   } n   return res; n } n template <class T> n bool inside(T r, T c, T R, T C) { n   return r >= 0 && r < R && c >= 0 && c < C; n } n struct item { n   int prio; n   int pos; n   bool operator<(const item &o) const { return prio > o.prio; } n }; n void dfs(vector<vector<pair<int, int> > > &g, int u, int p, n          vector<priority_queue<item> > &h) { n   for (int i(0), _b(sz(g[u]) - 1); i <= _b; ++i) { n     int v = g[u][i].first; n     if (v == p) continue; n     int c = g[u][i].second; n     while (c > 0 && !h[v].empty()) { n       h[u].push(h[v].top()); n       h[v].pop(); n       --c; n     } n     dfs(g, v, u, h); n   } n } n int main(int argc, char *argv[]) { n   int n; n   cin >> n; n   vector<priority_queue<item> > h(n); n   vector<int> a(n); n   for (int i(0), _n(n); i < _n; ++i) { n     cin >> a[i]; n     item e = {a[i], i}; n     h[i].push(e); n   } n   vector<vector<pair<int, int> > > g(n); n   for (int i(0), _n(n - 1); i < _n; ++i) { n     int u, v, c; n     cin >> u >> v >> c; n     --u; n     --v; n     g[u].push_back(make_pair(v, c)); n     g[v].push_back(make_pair(u, c)); n   } n   vector<int> res(n); n   int t = 0; n   int cnt = 0; n   while (1) { n     while (!h[0].empty()) { n       item e = h[0].top(); n       h[0].pop(); n       res[e.pos] = t; n       ++cnt; n       if (cnt == n) goto m1; n     } n     dfs(g, 0, -1, h); n     ++t; n   } n m1: n   print(res); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n using ll = long long; n using db = long double; n using str = string; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using pd = pair<db, db>; n using vi = vector<int>; n using vb = vector<bool>; n using vl = vector<ll>; n using vd = vector<db>; n using vs = vector<str>; n using vpi = vector<pi>; n using vpl = vector<pl>; n using vpd = vector<pd>; n template <class T> n using V = vector<T>; n template <class T> n using PR = pair<T, T>; n template <class T, size_t SZ> n using AR = array<T, SZ>; n template <class T> n using pqg = priority_queue<T, vector<T>, greater<T>>; n const int MX = 2e5 + 5; n const int MOD = 1e9 + 7; n const ll INF = 1e18; n const db PI = acos((db)-1); n const int xdir[4] = {1, 0, -1, 0}, ydir[4] = {0, 1, 0, -1}; n mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); n constexpr int pct(int x) { return __builtin_popcount(x); } n constexpr int bits(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); } n ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } n ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n template <class T, class U> n T fstTrue(T lo, T hi, U first) { n   hi++; n   assert(lo <= hi); n   while (lo < hi) { n     T mid = lo + (hi - lo) / 2; n     first(mid) ? hi = mid : lo = mid + 1; n   } n   return lo; n } n template <class T, class U> n T lstTrue(T lo, T hi, U first) { n   lo--; n   assert(lo <= hi); n   while (lo < hi) { n     T mid = lo + (hi - lo + 1) / 2; n     first(mid) ? lo = mid : hi = mid - 1; n   } n   return lo; n } n template <class T> n void remDup(V<T>& v) { n   sort(begin(v), end(v)); n   v.erase(unique(begin(v), end(v)), end(v)); n } n template <typename T1, typename T2> n str to_string(pair<T1, T2> p); n template <typename T1, typename T2, typename T3> n str to_string(tuple<T1, T2, T3> p); n template <typename T1, typename T2, typename T3, typename T4> n str to_string(tuple<T1, T2, T3, T4> p); n str to_string(const str& S) { return     + S +    ; } n str to_string(const char* S) { return to_string((str)S); } n str to_string(bool b) { return b ?  true  :  false ; } n template <class T> n str to_string(complex<T> c) { n   stringstream ss; n   ss << c; n   return ss.str(); n } n template <size_t SZ> n str to_string(bitset<SZ> v) { n   str res =   ; n   for (int i = (0); i < (SZ); ++i) res += char(v[i] +  0 ); n   return res; n } n template <typename T> n str to_string(T v) { n   bool fst = 1; n   str res =   ; n   for (const auto& x : v) { n     if (!fst) res +=    ; n     fst = 0; n     res += to_string(x); n   } n   return res; n } n template <typename T1, typename T2> n str to_string(pair<T1, T2> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n void DBG() { cerr << endl; } n template <typename Head, typename... Tail> n void DBG(Head H, Tail... T) { n   cerr <<     << to_string(H); n   DBG(T...); n } n void setPrec() { cout << fixed << setprecision(15); } n void unsyncIO() { cin.tie(0)->sync_with_stdio(0); } n void setIn(str name) { freopen(name.c_str(),  r , stdin); } n void setOut(str name) { freopen(name.c_str(),  w , stdout); } n void setIO(str name =   ) { n   unsyncIO(); n   setPrec(); n   if ((int)((name).size())) setIn(name +  .in ), setOut(name +  .out ); n } n struct node { n   ll prefix, suffix, sum, msum; n   node() { prefix = suffix = sum = msum = 0LL; } n   node(ll value) { n     sum = value; n     prefix = suffix = sum = msum = max(0LL, value); n   } n }; n node operator+(node a, node b) { n   node res; n   res.sum = a.sum + b.sum; n   res.prefix = max(a.prefix, a.sum + b.prefix); n   res.suffix = max(b.suffix, a.suffix + b.sum); n   res.msum = max({a.msum, b.msum, a.suffix + b.prefix}); n   return res; n } n template <class T> n struct Seg { n   const T ID = T(); n   T comb(T a, T b) { return a + b; } n   int N; n   vector<T> seg; n   void init(int _N) { n     N = _N; n     seg.assign(2 * N, ID); n   } n   void pull(int p) { seg[p] = comb(seg[2 * p], seg[2 * p + 1]); } n   void upd(int p, T val) { n     seg[p += N] = val; n     for (p /= 2; p; p /= 2) pull(p); n   } n   T query(int l, int r) { n     T ra = ID, rb = ID; n     for (l += N, r += N + 1; l < r; l /= 2, r /= 2) { n       if (l & 1) ra = comb(ra, seg[l++]); n       if (r & 1) rb = comb(seg[--r], rb); n     } n     return comb(ra, rb); n   } n }; n Seg<node> ST; n int SZ(int n) { n   int sz = 0; n   while ((1 << sz) < n) sz++; n   return 1 << sz; n } n int32_t main() { n   setIO(); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vi arr(n); n     for (auto& x : arr) cin >> x, --x; n     vi p(n); n     for (int i = (0); i < (n); ++i) p[arr[i]] = i; n     ST.init(SZ(n)); n     vb marked(n, false); n     bool res = true; n     int lst = n - 1, fst = 0; n     for (int i = (0); i < (n); ++i) { n       while (marked[lst]) --lst; n       ll csc = ST.query(fst, lst).msum + 1; n       auto can = [&](int x) { return ST.query(x, p[i]).sum == p[i] - x; }; n       ll sum = p[i] - fstTrue(0, p[i], can) + 1; n       if (sum != csc) { n         res = false; n         break; n       } n       ST.upd(p[i], 1); n       marked[p[i]] = 1; n     } n     cout << (res ?  Yes n  :  No n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5000; n const int MOD = 1000000007; n string mx[MAXN]; n int dp[MAXN][MAXN]; n int m, n; n void mainp() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> mx[i]; n   for (int i = 0; i < n; i++) n     for (int j = m - 1; j >= 0; j--) { n       if (j == m - 1) n         dp[i][j] = mx[i][j] ==  1  ? 1 : 0; n       else { n         if (mx[i][j] ==  1 ) n           dp[i][j] = 1 + dp[i][j + 1]; n         else n           dp[i][j] = 0; n       } n     } n   int ans = 0; n   for (int j = 0; j < m; j++) { n     int temp[MAXN]; n     for (int i = 0; i < n; i++) temp[i] = dp[i][j]; n     sort(temp, temp + n); n     for (int i = 0; i < n; i++) n       if (temp[i] * (n - i) > ans) ans = temp[i] * (n - i); n   } n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   mainp(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n vector<long long>::iterator ptr; n long long count = 0; n long long cache[10004]; n long long dp[100005] = {0}; n long long cnt[200005] = {0}; n long long a[200005] = {0}; n long long b[200005] = {0}; n long long r[200005] = {0}; n long long pr(long long n) { n   if (n % 2 == 0) { n     return 2; n   } n   for (long long i = 3; i <= sqrt(n); i = i + 2) { n     if (n % i == 0) return i; n   } n   if (n > 2) return n; n } n long long power(long long x, unsigned long long y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) n     return power(x, y / 2) * power(x, y / 2); n   else n     return x * power(x, y / 2) * power(x, y / 2); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n = 0, p, q = 0, k, x = 0, y, m; n   cin >> n >> m; n   char s[1005][1005]; n   long long v[1005][5] = {0}; n   for (long long i = 0; i < m; ++i) { n     for (long long j = 0; j < 5; ++j) { n       v[i][j] = 0; n     } n   } n   for (long long i = 0; i < n; ++i) { n     for (long long j = 0; j < m; ++j) { n       cin >> s[i][j]; n       if (s[i][j] ==  A ) n         v[j][0]++; n       else if (s[i][j] ==  B ) n         v[j][1]++; n       else if (s[i][j] ==  C ) n         v[j][2]++; n       else if (s[i][j] ==  D ) n         v[j][3]++; n       else if (s[i][j] ==  E ) n         v[j][4]++; n     } n   } n   for (long long i = 0; i < m; ++i) { n     cin >> a[i]; n   } n   for (long long i = 0; i < m; ++i) { n     p = 0; n     for (long long j = 0; j < 5; ++j) { n       p = max(p, v[i][j]); n     } n     x += (a[i] * p); n   } n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[105], b[105], t, i, k; n   cin >> t; n   for (i = 1; i < t + 1; i++) { n     scanf( %d , &a[i]); n   } n   for (i = 1; i < t + 1; i++) { n     k = a[i]; n     b[k] = i; n   } n   for (i = 1; i < t + 1; i++) { n     printf( %d  , b[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MAX = 100000; n vector<long long int> great[MAX + 1]; n vector<long long int> small[MAX + 1]; n vector<long long int> v[MAX + 1]; n bool gactive[MAX + 1] = {false}; n set<long long int> sactive; n long long int sz[MAX + 1] = {0}; n struct moves { n   long long int from, to, kind; n }; n bool in(long long int x, vector<long long int>& p) { n   if (lower_bound(p.begin(), p.end(), x) != p.end()) { n     return (*lower_bound(p.begin(), p.end(), x) == x); n   } n   return false; n } n void solve() { n   long long int n, m; n   cin >> n >> m; n   long long int tot = 0; n   vector<pair<long long int, long long int>> szv(n + 1); n   szv[0] = {0, 0}; n   for (long long int j = 1; j <= n; j++) { n     long long int s; n     cin >> s; n     tot += s; n     sz[j] = s; n     szv[j] = {s, j}; n     for (long long int i = 0; i < s; i++) { n       long long int c; n       cin >> c; n       v[j].push_back(c); n     } n   } n   sort(szv.begin(), szv.end()); n   vector<long long int> gf(n + 1); n   long long int sum = 0; n   for (long long int j = 1; j <= n; j++) { n     if ((tot / n) * (n - j + 1) == tot - sum) { n       gf[j] = tot / n; n     } else { n       gf[j] = (tot + n - 1) / n; n     } n     sum += gf[j]; n   } n   vector<long long int> should(n + 1); n   for (long long int j = 1; j <= n; j++) { n     should[szv[j].second] = gf[n - j + 1]; n   } n   for (long long int j = 1; j <= n; j++) { n     if (sz[j] > should[j]) { n       gactive[j] = true; n       for (auto i : v[j]) { n         great[i].push_back(j); n       } n     } else if (sz[j] < should[j]) { n       sactive.insert(j); n       for (auto i : v[j]) { n         small[i].push_back(j); n       } n     } n   } n   vector<moves> out; n   for (long long int j = 1; j <= m; j++) { n     if (((long long int)great[j].size()) == 0) continue; n     long long int m1 = great[j].size(), m2 = small[j].size(); n     long long int ptr1 = 0, ptr2 = 0; n     while (true) { n       if (ptr1 == m1) break; n       if (gactive[great[j][ptr1]]) break; n       ptr1++; n     } n     if (ptr1 == m1) continue; n     set<long long int> todel; n     for (auto it : sactive) { n       if (in(it, small[j])) n         continue; n       else { n         sz[great[j][ptr1]]--; n         sz[it]++; n         { n           struct moves q; n           q.from = great[j][ptr1]; n           q.to = it; n           q.kind = j; n           out.push_back(q); n         } n         if (sz[great[j][ptr1]] <= should[great[j][ptr1]]) n           gactive[great[j][ptr1]] = false; n         if (sz[it] >= should[it]) todel.insert(it); n         ptr1++; n         while (true) { n           if (ptr1 == m1) break; n           if (gactive[great[j][ptr1]]) break; n           ptr1++; n         } n         if (ptr1 == m1) break; n       } n     } n     for (auto it : todel) sactive.erase(it); n   } n   cout << (long long int)out.size() <<   n ; n   for (auto q : out) { n     cout << q.from <<     << q.to <<     << q.kind <<   n ; n   } n   return; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n void dv(vector<int> v) { n   for (int i = 0; i < v.size(); i++) cout << v[i] <<    ; n } n bool check_prime(int a) { n   for (int i = sqrt(a); i > 1; i--) { n     if (a % i == 0) return false; n   } n   return true; n } n int ctoil(char c) { return (int)c - 97; } n int ctoiu(char c) { return (int)c - 65; } n void dv_2d(vector<vector<int>> v) { n   for (int i = 0; i < v.size(); i++) { n     for (int j = 0; j < v[i].size(); j++) { n       cout << v[i][j] <<    ; n     } n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m; n   cin >> n >> m; n   long long a, b; n   if (n <= 2 * m) { n     a = 0; n   } else { n     a = n - 2 * m; n   } n   if (m == 0) { n     b = n; n   } else { n     b = n - ceil((sqrt(1 + 8 * m) + 1) / 2); n   } n   cout << a <<     << b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c = 0; n   cin >> n; n   int r = n; n   int arr[n]; n   deque<int> d; n   for (int i = 0; i < n; i++) { n     scanf( %d , &arr[i]); n     d.push_back(arr[i]); n   } n   sort(arr, arr + n); n   for (int i = 0; i < n; i++) { n     if (d[i] == arr[i]) { n       c++; n     } n   } n   int mid = (n + 1) / 2 - 1; n   if (c == n) { n     printf( %d n , 0); n     ; n     return 0; n   } else { n     c = 0; n     while (r--) { n       int t = 0; n       d.push_front(d.back()); n       d.pop_back(); n       c++; n       if (arr[0] == d.front() && arr[n - 1] == d.back() && arr[mid] == d[mid]) { n         if (mid + 1 < n) { n           if (d[mid + 1] >= d[mid] && d[mid - 1] <= d[mid]) { n             printf( %d n , c); n             ; n             return 0; n           } n         } else { n           printf( %d n , c); n           ; n           return 0; n         } n       } n     } n   } n   printf( %d n , -1); n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   long long x, y; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     cin >> x >> y; n     if ((x - y) >= 2) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n int size(const T &x) { n   return x.size(); n } n const int INF = ~(1 << 31); n const double EPS = 1e-9; n const double pi = acos(-1); n template <class T> n T smod(T a, T b) { n   return (a % b + b) % b; n } n int f(char c) { return c -  a ; } n char g(int i) { return (char)(i +  a ); } n int main() { n   int n; n   cin >> n; n   char c; n   vector<bool> A(26, true); n   int left = 26, cnt = 0; n   for (decltype(0) i = (0); i < (n); ++i) { n     cin >> c; n     if (c ==  . ) { n       vector<bool> B(26, true); n       string s; n       cin >> s; n       for (decltype(0) j = (0); j < (size(s)); ++j) { n         B[f(s[j])] = false; n       } n       for (decltype(0) j = (0); j < (26); ++j) { n         A[j] = A[j] && B[j]; n       } n     } else if (c ==  ! ) { n       if (left == 1) cnt++; n       vector<bool> B(26, false); n       string s; n       cin >> s; n       for (decltype(0) j = (0); j < (size(s)); ++j) { n         B[f(s[j])] = true; n       } n       for (decltype(0) j = (0); j < (26); ++j) { n         A[j] = A[j] && B[j]; n       } n     } else { n       char s; n       cin >> s; n       if (left == 1 && i != n - 1) cnt++; n       A[f(s)] = false; n     } n     left = 0; n     for (decltype(0) j = (0); j < (26); ++j) { n       left += A[j]; n     } n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n), b(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < n; ++i) cin >> b[i]; n   long long ans = 0; n   for (int i = 0; i < n; ++i) n     if (b[i] == 1) { n       ans += a[i]; n       a[i] = 0; n     } n   long long temp = 0, max = 0; n   for (int i = 0; i < k; ++i) { n     temp += a[i]; n   } n   ans += temp; n   max = temp; n   for (int i = 1; i <= n - k; ++i) { n     temp += (a[i + k - 1] - a[i - 1]); n     if (max < temp) { n       ans -= max; n       max = temp; n       ans += max; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   for (int i = 1; i <= t; ++i) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n long long z = 1000000007; n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) { n       res = (res * a) % z; n       b--; n     } else { n       a = (a * a) % z; n       b = b >> 1; n     } n   } n   return res; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   t = 1; n   while (t--) { n     long long s, x; n     cin >> s >> x; n     long long k = s - x; n     if (k & 1) n       cout <<  0 n ; n     else { n       long long ans = 1, c = 0; n       set<long long> s; n       k /= 2; n       for (long long i = 0; i < 64; i++) n         if (k & ((long long)1 << i)) s.insert(i); n       for (long long i = 0; i < 64; i++) { n         if (x & ((long long)1 << i)) { n           ans *= 2; n           if (s.find(i) != s.end()) { n             c++; n             break; n           } n         } n       } n       if (c) n         cout <<  0 n ; n       else { n         if (k == 0) n           cout << ans - 2 <<   n ; n         else n           cout << ans <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n const int maxn = 150010; n const int INF = 0x3f3f3f3f; n using namespace std; n vector<int> V; n int a[maxn]; n long long ans = 0; n int ok(int i) { n   if (i & 1) return a[i] < a[i - 1] && a[i] < a[i + 1]; n   return a[i] > a[i + 1] && a[i] > a[i - 1]; n } n int ok2(int i, int j) { n   int f = 1; n   swap(a[i], a[j]); n   if (!ok(i)) f = 0; n   if (!ok(j)) f = 0; n   for (int k = 0; k < V.size(); k++) { n     if (!ok(V[k])) f = 0; n   } n   swap(a[i], a[j]); n   return f; n } n void fun(int idx, int n) { n   for (int i = 1; i <= n; i++) { n     if (ok2(idx, i)) { n       ++ans; n     } n   } n } n int main() { n   int n, i; n   while (~scanf( %d , &n)) { n     for (i = 1; i <= n; i++) { n       scanf( %d , &a[i]); n     } n     a[0] = INF; n     a[n + 1] = (n + 1) % 2 ? -INF : INF; n     V.empty(); n     for (i = 1; i <= n; i++) { n       if (!ok(i)) { n         V.push_back(i); n       } n     } n     if (V.size() > 6) { n       printf( 0 n ); n       continue; n     } n     ans = 0; n     for (i = 0; i < V.size(); i++) { n       fun(V[i], n); n       for (int j = i + 1; j < V.size(); j++) { n         if (ok2(V[i], V[j])) { n           --ans; n         } n       } n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = acosl(-1.0); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m; n   cin >> n >> m; n   int a[n][m], ans[n][m]; n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < m; j++) cin >> a[i][j]; n   vector<map<int, int> > vc1, vc2; n   map<int, int> mymap; n   vector<int> v1, v11, v22; n   for (int i = 0; i < n; i++) { n     mymap.clear(); n     v1.clear(); n     for (int j = 0; j < m; j++) v1.push_back(a[i][j]); n     sort(v1.begin(), v1.end()); n     int k = 1; n     for (int j = 0; j < m; j++) { n       if (mymap.find(v1[j]) == mymap.end()) mymap[v1[j]] = k++; n     } n     v11.push_back(k - 1); n     vc1.push_back(mymap); n   } n   for (int i = 0; i < m; i++) { n     mymap.clear(); n     v1.clear(); n     for (int j = 0; j < n; j++) v1.push_back(a[j][i]); n     sort(v1.begin(), v1.end()); n     int k = 1; n     for (int j = 0; j < n; j++) { n       if (mymap.find(v1[j]) == mymap.end()) mymap[v1[j]] = k++; n     } n     v22.push_back(k - 1); n     vc2.push_back(mymap); n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int x = vc1[i][a[i][j]]; n       int y = vc2[j][a[i][j]]; n       if (x < y) n         ans[i][j] = max(v11[i] + y - x, v22[j]); n       else if (y < x) n         ans[i][j] = max(v11[i], v22[j] + x - y); n       else n         ans[i][j] = max(v11[i], v22[j]); n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) cout << ans[i][j] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long u, v, p; n map<long long, int> M; n map<long long, int> pre, pre2; n queue<int> x, y; n bool in(int val, int rn) { n   return ((M.find(val) != M.end()) & (((M[val] >> rn) & 1))); n } n long long modpow(long long x, long long n) { n   long long res = 1; n   while (n > 0) { n     if (n & 1) res = res * x % p; n     x = x * x % p; n     n >>= 1; n   } n   return res; n } n int main() { n   cin >> u >> v >> p; n   x.push(u); n   y.push(v); n   for (int i = 0;; i++) { n     int sz = x.size(); n     bool en = false; n     int goal = -1; n     while (sz--) { n       int q = x.front(); n       x.pop(); n       if (in(q, 0)) continue; n       M[q] |= 1; n       if (M[q] == 3) { n         en = true; n         goal = q; n         break; n       } n       if (!in((q + p - 1) % p, 0)) { n         x.push((q + p - 1) % p); n         pre[(q + p - 1) % p] = q; n       } n       if (!in((q + 1) % p, 0)) { n         x.push((q + 1) % p); n         pre[(q + 1) % p] = q; n       } n       long long rev = modpow(q, p - 2); n       if (!in(rev, 0)) { n         x.push(rev); n         pre[rev] = q; n       } n     } n     sz = y.size(); n     while (sz--) { n       int q = y.front(); n       y.pop(); n       if (in(q, 1)) continue; n       M[q] |= 2; n       if (M[q] == 3) { n         en = true; n         goal = q; n         break; n       } n       if (!in((q + p - 1) % p, 1)) { n         y.push((q + p - 1) % p); n         pre2[(q + p - 1) % p] = q; n       } n       if (!in((q + 1) % p, 1)) { n         y.push((q + 1) % p); n         pre2[(q + 1) % p] = q; n       } n       long long rev = modpow(q, p - 2); n       if (!in(rev, 1)) { n         y.push(rev); n         pre2[rev] = q; n       } n     } n     if (en) { n       vector<int> num; n       int cur = goal; n       num.push_back(cur); n       while (cur != u) { n         cur = pre[cur]; n         num.push_back(cur); n       } n       reverse(num.begin(), num.end()); n       cur = goal; n       while (cur != v) { n         cur = pre2[cur]; n         num.push_back(cur); n       } n       cout << num.size() - 1 << endl; n       for (int i = 1; i < num.size(); i++) { n         long long a = num[i - 1]; n         long long b = num[i]; n         if ((a + 1) % p == b) { n           printf( 1  ); n         } else if ((a + p - 1) % p == b) { n           printf( 2  ); n         } else n           printf( 3  ); n       } n       puts(  ); n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int dp[505][505]; n int a[505][505]; n int main() { n   int n; n   int i, j, k; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i][i]; n     for (j = i; j <= n; j++) dp[i][j] = j - i + 1; n   } n   for (int len = 2; len <= n; len++) { n     for (i = 1; i + len - 1 <= n; i++) { n       j = i + len - 1; n       for (k = i; k < j; k++) { n         dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]); n         if (dp[i][k] == 1 && dp[k + 1][j] == 1 && a[i][k] == a[k + 1][j]) { n           dp[i][j] = 1; n           a[i][j] = a[i][k] + 1; n         } n       } n     } n   } n   cout << dp[1][n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n int main() { n   string a, v[6]; n   cin >> a; n   for (int i = 1; i <= 5; ++i) { n     cin >> v[i]; n     if (v[i][0] == a[0] || v[i][1] == a[1]) { n       cout <<  YES n ; n       return 0; n     } n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   vector<pair<int, int> > v; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     v.push_back(make_pair(x, i)); n   } n   sort(v.begin(), v.end(), greater<pair<int, int> >()); n   long long ans = 0; n   vector<int> pos; n   for (int i = 0; i < (m * k); i++) { n     ans += v[i].first; n     pos.push_back(v[i].second); n   } n   sort(pos.begin(), pos.end()); n   vector<int> div; n   for (int i = 0; i < k - 1; i++) { n     div.push_back(pos[(i + 1) * m - 1]); n   } n   cout << ans << endl; n   for (int i = 0; i < div.size(); i++) { n     cout << div[i] + 1 <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double EPS = 1e-9; n long long dis(pair<long long, long long> a, pair<long long, long long> b) { n   return (a.first - b.first) * (a.first - b.first) + n          (a.second - b.second) * (a.second - b.second); n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long T, v; n   pair<long long, long long> C; n   cin >> C.first >> C.second >> v >> T; n   long long R = 1.00 * v * T; n   long long n; n   cin >> n; n   vector<pair<double, long long> > cut; n   pair<long long, long long> center; n   long long radi; n   for (long long i = 0; i < n; i++) { n     cin >> center.first >> center.second >> radi; n     double distance = dis(C, center); n     if (distance < 1.0 * radi * radi + EPS) { n       cout <<  1.00000 ; n       return 0; n     } n     distance = sqrt(distance); n     if (1.00 * radi + R * 1.00 < distance - EPS) continue; n     double left, right, ang; n     double angM = atan2(center.second - C.second, center.first - C.first); n     if (angM < 0) { n       angM += 2 * PI; n     } n     double tLen = sqrt(distance * distance - 1.0 * radi * radi); n     if (tLen < R + EPS) { n       ang = asin(radi / distance); n     } else { n       ang = acos((distance * distance + 1.00 * R * R - 1.0 * radi * radi) / n                  (2 * distance * 1.00 * R)); n     } n     left = angM - ang; n     right = angM + ang; n     if (left < 0) { n       cut.push_back({left + 2 * PI, 1}); n       cut.push_back({2 * PI, -1}); n       cut.push_back({0.00, 1}); n       cut.push_back({right, -1}); n     } else if (right > 2 * PI) { n       cut.push_back({left, 1}); n       cut.push_back({2 * PI, -1}); n       cut.push_back({0.00, 1}); n       cut.push_back({right - 2 * PI, -1}); n     } else n       cut.push_back({left, 1}), cut.push_back({right, -1}); n   } n   double ans = 0.00; n   long long count = 0; n   double last = 0; n   sort(cut.begin(), cut.end()); n   for (auto &x : cut) { n     if (count > 0) ans += (x.first - last); n     last = x.first; n     count += (x.second); n   } n   cout << fixed << setprecision(6) << (ans / (2 * PI)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, a, moves = 0; n   cin >> n; n   while (n--) { n     cin >> a; n     moves += a - 1; n     moves %= 2; n     cout << 2 - moves <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {-1, 0, 1, 0}; n const int dy[] = {0, -1, 0, 1}; n inline int read() { n   int ans = 0; n   bool f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) f ^= ch ==  - , ch = getchar(); n   while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = getchar(); n   return f ? ans : -ans; n } n int n, m; n long long b[100010], g[100010]; n long long ans; n int main(int argc, char const *argv[]) { n   ios::sync_with_stdio(false); n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]); n   for (int i = 1; i <= m; i++) scanf( %I64d , &g[i]); n   sort(b + 1, b + n + 1); n   sort(g + 1, g + m + 1); n   if (b[n] > g[1]) n     cout << -1; n   else if (b[n] == g[1]) { n     for (int i = 1; i < n; i++) ans += b[i] * m; n     for (int i = 1; i <= m; i++) ans += g[i]; n     cout << ans; n   } else { n     ans += b[n] + g[1] + b[n - 1] * (m - 1); n     for (int i = n - 2; i >= 1; i--) ans += b[i] * m; n     for (int i = 2; i <= m; i++) ans += g[i]; n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll llinf = (1ll << 61) - 1; n const int inf = 1000000007; n int TC = 1, CN, n, r, c[1 << 18 | 5]; n signed main() { n   cin.tie(0)->sync_with_stdio(0); n   cin.exceptions(cin.failbit); n   cout.precision(11), cout.setf(ios::fixed); n   auto kase = [&]() -> void { n     cin >> n >> r; n     double sum = 0; n     for (int i = 0; i < 1 << n; i++) { n       cin >> c[i], sum += c[i]; n     } n     for (int i = 0; i < r; i++) { n       cout << sum / (1 << n) <<   n ; n       int z, g; n       cin >> z >> g; n       sum -= c[z], c[z] = g, sum += c[z]; n     } n     cout << sum / (1 << n) <<   n ; n   }; n   while (CN++ != TC) kase(); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const long long INF = 0x3f3f3f3f; n const double eps = 1e-9; n struct P { n   long double x, y; n   P() : x(0), y(0) {} n   P(long double _x, long double _y) : x(_x), y(_y) {} n   P operator+(P& p) { return P(x + p.x, y + p.y); } n   P operator-(P& p) { return P(x - p.x, y - p.y); } n   P operator*(long double d) { return P(x * d, y * d); } n   P operator/(long double d) { return P(x / d, y / d); } n   long double abs() { return sqrtl(x * x + y * y); } n   long double dot(P p) { return x * p.x + y * p.y; } n   long double det(P p) { return x * p.y - y * p.x; } n }; n P p[maxn]; n long double tg[maxn], d[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cout.setf(ios::fixed); n   int n, q; n   cin >> n >> q; n   for (int i = 1; i <= n; i++) { n     cin >> p[i].x >> p[i].y; n   } n   P g; n   long double fzx = 0, fzy = 0, fm = 0; n   for (int i = 2; i <= n - 1; i++) { n     fzx += (p[1].x + p[i].x + p[i + 1].x) * n            ((p[i].x - p[1].x) * (p[i + 1].y - p[1].y) - n             (p[i + 1].x - p[1].x) * (p[i].y - p[1].y)); n     fzy += (p[1].y + p[i].y + p[i + 1].y) * n            ((p[i].x - p[1].x) * (p[i + 1].y - p[1].y) - n             (p[i + 1].x - p[1].x) * (p[i].y - p[1].y)); n   } n   for (int i = 2; i <= n - 1; i++) { n     fm += 3.0 * ((p[i].x - p[1].x) * (p[i + 1].y - p[1].y) - n                  (p[i + 1].x - p[1].x) * (p[i].y - p[1].y)); n   } n   g.x = fzx / fm; n   g.y = fzy / fm; n   for (int i = 1; i <= n; i++) { n     P l(p[i] - g); n     tg[i] = atan2l(l.y, l.x); n     if (tg[i] < 0) tg[i] += 2 * acosl(-1); n     d[i] = l.abs(); n   } n   int s1 = 1, s2 = 2; n   int flag = 0; n   for (int i = 1; i <= q; i++) { n     int op; n     cin >> op; n     if (op == 1) { n       int f, t; n       cin >> f >> t; n       if (f == s1) swap(s1, s2); n       s2 = t; n       flag = 1; n       g.x = p[s1].x; n       g.y = p[s1].y - d[s1]; n       long double _tg = tg[s1] - tg[s2]; n       p[s2].x = g.x + d[s2] * sinl(_tg); n       p[s2].y = g.y + d[s2] * cosl(_tg); n     } else { n       int v; n       cin >> v; n       if (!flag) { n         cout << fixed << setprecision(6) << p[v].x <<     << p[v].y << endl; n       } else { n         long double _tg = tg[s1] - tg[v]; n         P ans; n         ans.x = g.x + d[v] * sinl(_tg); n         ans.y = g.y + d[v] * cosl(_tg); n         cout << fixed << setprecision(6) << ans.x <<     << ans.y << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  RDLU ; n long long ln, lk, lm; n void etp(bool f = 0) { n   puts(f ?  YES  :  NO ); n   exit(0); n } n void addmod(int &x, int y, int mod = 1000000007) { n   assert(y >= 0); n   x += y; n   if (x >= mod) x -= mod; n   assert(x >= 0 && x < mod); n } n void et() { n   puts( -1 ); n   exit(0); n } n long long fastPow(long long x, long long y, int mod = 1000000007) { n   long long ans = 1; n   while (y > 0) { n     if (y & 1) ans = (x * ans) % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n long long gcd1(long long x, long long y) { n   long long z = y; n   while (x % y != 0) { n     z = x % y; n     x = y; n     y = z; n   } n   return z; n } n int a[33]; n int dp[(1 << 22) + 5], mn[(1 << 22) + 5], bs; n void fmain(int ID) { n   scanf( %d%d , &n, &m); n   for (int(i) = 1; (i) <= (int)(m); (i)++) { n     int u, v; n     scanf( %d%d , &u, &v); n     u--; n     v--; n     a[u] |= 1 << v; n     a[v] |= 1 << u; n   } n   bs = (1 << n) - 1; n   for (int(i) = 0; (i) < (int)(n); (i)++) dp[1 << i] = 1; n   for (int(i) = 0; (i) < (int)(n); (i)++) a[i] |= 1 << i; n   int cc = 0; n   for (int(i) = 0; (i) < (int)(n); (i)++) n     if (a[i] == (1 << n) - 1) { n       cc++; n     } n   if (cc == n) { n     puts( 0 ); n     return; n   } n   for (int s = 0; s < (1 << n); s++) n     if (dp[s]) { n       int tmp = 0; n       for (int(j) = 0; (j) < (int)(n); (j)++) n         if (s & (1 << j)) { n           tmp |= a[j]; n         } n       for (int(j) = 0; (j) < (int)(n); (j)++) n         if (tmp & (1 << j)) { n           dp[s | (1 << j)] = 1; n         } n       if (tmp == (1 << n) - 1) { n         if (__builtin_popcount(s) < __builtin_popcount(bs)) { n           bs = s; n         } n       } n     } n   printf( %d n , __builtin_popcount(bs)); n   for (int(j) = 0; (j) < (int)(n); (j)++) n     if (bs & (1 << j)) printf( %d  , j + 1); n } n int main() { n   int t = 1; n   for (int(i) = 1; (i) <= (int)(t); (i)++) { n     fmain(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n int n; n struct vec { n   long long x, y, idx; n } a, b; n long double pos_ang_with_x_axis(vec a) { n   long double res = atan2(a.y, a.x) * 180 / acos(-1); n   if (res < 0) res += 360; n   return res; n } n int dot(vec a, vec b) { return a.x * b.x + a.y * b.y; } n long double norm(vec a) { return (long double)sqrt(a.x * a.x + a.y * a.y); } n long double angle(vec a, vec b) { n   long double ang1 = pos_ang_with_x_axis(a); n   long double ang2 = pos_ang_with_x_axis(b); n   return fabs(ang1 - ang2); n } n vector<vec> v; n bool cmp(vec a, vec b) { n   vec c; n   c.x = c.y = 0; n   long double ang1 = pos_ang_with_x_axis(a); n   long double ang2 = pos_ang_with_x_axis(b); n   return ang1 < ang2; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a.x >> a.y; n     a.idx = i + 1; n     v.push_back(a); n   } n   sort(v.begin(), v.end(), cmp); n   int idx1, idx2; n   long double mn = 1e18; n   v.push_back(v[0]); n   for (int i = 1; i <= n; i++) { n     long double d = angle(v[i], v[i - 1]); n     d = min(d, (long double)360 - d); n     if (d < mn) mn = d, idx1 = v[i - 1].idx, idx2 = v[i].idx; n   } n   cout << idx1 <<     << idx2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long last = -1; n void dfs(long long s, vector<vector<pair<long long, long long>>> grf, n          vector<long long> &vis, long long &cost) { n   vis[s] = 1; n   last = s; n   for (auto x : grf[s]) { n     long long v = x.first, d = x.second; n     if (vis[v] == 0) { n       cost += d; n       dfs(v, grf, vis, cost); n     } n   } n } n signed main() { n   long long n; n   cin >> n; n   vector<vector<pair<long long, long long>>> grf(n + 1); n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     long long u, v, w; n     cin >> u >> v >> w; n     grf[u].push_back({v, w}); n     grf[v].push_back({u, 0}); n     sum += w; n   } n   long long cost = 0; n   vector<long long> vis(n + 1, 0); n   dfs(1, grf, vis, cost); n   if (last != 1) { n     for (auto x : grf[last]) { n       if (x.first == 1) cost += x.second; n     } n   } n   cout << min(cost, sum - cost); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> primes = {2,  4,  3,  9,  5,  25, 7,  49, 11, 13, n                         17, 19, 23, 29, 31, 37, 41, 43, 47}; n   int n = 0; n   for (int i = 0; i < primes.size(); i++) { n     cout << primes[i] << endl; n     string s; n     cin >> s; n     if (s ==  yes ) n++; n     if (n > 1) return cout <<  composite , 0; n   } n   cout <<  prime ; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, k, nb, a[1005], b[2005], t = -10000, pos = 0, p, d; n long long int save[1005][2005]; n long long int time(int i, int j) { n   if (save[i][j] != -1) return save[i][j]; n   if (i == n) return 0; n   if (j == k) return 3e9; n   return (save[i][j] = min(time(i, j + 1), max(abs(a[i] - b[j]) + abs(p - b[j]), n                                                time(i + 1, j + 1)))); n } n int main() { n   long long int i, j; n   cin >> n >> k >> p; n   vector<long long int> v; n   v.clear(); n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (i = 0; i < k; i++) cin >> b[i]; n   sort(b, b + k); n   memset(save, -1, sizeof save); n   t = time(0, 0); n   cout << t; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, m, t; n vector<int> e[maxn]; n int ecnt[maxn]; n queue<int> q; n bool vis[maxn]; n int dep[maxn]; n int ec[maxn]; n bool flag; n int f[maxn]; n int g[maxn]; n int cnt[maxn]; n int read() { n   int x; n   scanf( %d , &x); n   return x; n } n int dfs(int x, int fa) { n   int y; n   if (!ec[dep[x]]) { n     ec[dep[x]] = e[x].size(); n   } else { n     if (ec[dep[x]] != e[x].size()) { n       flag = false; n       return 0; n     } n   } n   for (auto y : e[x]) { n     if (y == fa) continue; n     dep[y] = dep[x] + 1; n     dfs(y, x); n     if (!flag) { n       return 0; n     } n   } n   return 0; n } n bool check(int x) { n   memset(ec, 0, sizeof(ec)); n   memset(dep, 0, sizeof(dep)); n   flag = true; n   dep[x] = 1; n   dfs(x, -1); n   return flag; n } n int solve() { n   int i, j; n   int x, y; n   vector<int> ans; n   memset(vis, 0, sizeof(vis)); n   for (i = 1; i <= n; i++) { n     ecnt[i] = e[i].size(); n     if (e[i].size() == 1) { n       vis[i] = true; n       q.push(i); n       f[i] = 1; n       g[i] = i; n       cnt[i] = 1; n     } n   } n   while (!q.empty()) { n     x = q.front(); n     q.pop(); n     for (auto y : e[x]) { n       if (vis[y]) continue; n       ecnt[y]--; n       if (ecnt[y] == 1) { n         q.push(y); n         vis[y] = true; n       } n     } n     for (auto y : e[x]) { n       if (!vis[y]) continue; n       if (!f[y]) continue; n       if (f[x]) { n         if (f[y] + 1 != f[x]) { n           if (cnt[x] < cnt[y]) { n             ans.push_back(g[x]); n           } else if (cnt[x] > cnt[y]) { n             ans.push_back(g[y]); n           } else { n             ans.push_back(g[x]); n             ans.push_back(g[y]); n           } n           break; n         } else { n           cnt[x] += cnt[y]; n         } n       } else { n         f[x] = f[y] + 1; n         g[x] = g[y]; n         cnt[x] += cnt[y]; n       } n     } n     if (q.empty() and ans.size() == 0) { n       for (auto y : e[x]) { n         if (!vis[y]) continue; n         if (!f[y]) continue; n         if (cnt[y] == 1) { n           ans.push_back(g[y]); n         } n       } n     } n     if (ans.size()) break; n   } n   for (auto x : ans) { n     if (check(x)) { n       printf( %d n , x); n       return 0; n     } n   } n   printf( -1 n ); n   return 0; n } n int main() { n   int i, j; n   int x = 1, y; n   n = read(); n   for (i = 1; i < n; i++) { n     x = read(); n     y = read(); n     e[x].push_back(y); n     e[y].push_back(x); n     ecnt[x]++; n     ecnt[y]++; n   } n   for (i = 1; i <= n; i++) { n     if (e[i].size() == 1) { n       vis[i] = true; n       q.push(i); n     } n   } n   while (!q.empty()) { n     x = q.front(); n     q.pop(); n     for (auto y : e[x]) { n       if (vis[y]) continue; n       ecnt[y]--; n       if (ecnt[y] == 1) { n         q.push(y); n         vis[y] = true; n       } n     } n   } n   if (check(x)) { n     printf( %d n , x); n   } else { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 200001; n const long long K = 5; n const long long INF = 1e16 + 7; n long long n, k, q; n long long a[MAXN][K]; n long long tree[MAXN << 2][1 << K]; n void upd(long long v, long long tl, long long tr, long long p) { n   if (tl == tr) { n     for (long long i = 0; i < k; ++i) { n       cin >> a[tl][i]; n     } n     for (long long mask = 0; mask < (1 << k); ++mask) { n       long long cost = 0; n       for (long long i = 0; i < k; ++i) { n         if ((mask >> i) & 1) { n           cost += a[tl][i]; n         } else { n           cost -= a[tl][i]; n         } n       } n       tree[v][mask] = cost; n     } n     return; n   } n   long long tm = (tl + tr) >> 1; n   if (p <= tm) { n     upd(v * 2 + 1, tl, tm, p); n   } else { n     upd(v * 2 + 2, tm + 1, tr, p); n   } n   for (long long mask = 0; mask < (1 << k); ++mask) { n     tree[v][mask] = max(tree[v * 2 + 1][mask], tree[v * 2 + 2][mask]); n   } n } n long long getmax(long long v, long long tl, long long tr, long long l, n                  long long r, long long mask) { n   if (tr < l || r < tl) { n     return -INF; n   } n   if (l <= tl && tr <= r) { n     return tree[v][mask]; n   } n   long long tm = (tl + tr) >> 1; n   return max(getmax(v * 2 + 1, tl, tm, l, r, mask), n              getmax(v * 2 + 2, tm + 1, tr, l, r, mask)); n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   for (long long i = 0; i < (MAXN << 2); ++i) { n     for (long long mask = 0; mask < (1 << K); ++mask) { n       tree[i][mask] = -INF; n     } n   } n   cin >> n >> k; n   for (long long i = 0; i < n; ++i) { n     upd(0, 0, n - 1, i); n   } n   cin >> q; n   for (long long i = 0; i < q; ++i) { n     long long t; n     cin >> t; n     if (t == 1) { n       long long p; n       cin >> p; n       --p; n       upd(0, 0, n - 1, p); n     } else { n       long long l, r; n       cin >> l >> r; n       --l; n       --r; n       long long ans = -INF; n       for (long long mask = 0; mask < (1 << (k - 1)); ++mask) { n         ans = max(ans, getmax(0, 0, n - 1, l, r, mask) + n                            getmax(0, 0, n - 1, l, r, mask ^ ((1 << k) - 1))); n       } n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int up, down; n   int people = 0; n   int max = 0; n   cin >> n; n   while (n--) { n     cin >> up >> down; n     people = people - up + down; n     if (people > max) max = people; n   } n   cout << max << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(pair<long long, long long> a, pair<long long, long long> b) { n   return (a.first - a.second) > (b.first - b.second); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<long long> hand(n); n   vector<long long> pile(n); n   unordered_map<long long, long long> hand_map(n); n   unordered_map<long long, long long> pile_map(n); n   for (long long i = 0; i < n; i++) { n     cin >> hand[i]; n     hand_map[hand[i]]++; n   } n   for (long long i = 0; i < n; i++) { n     cin >> pile[i]; n     pile_map[pile[i]]++; n   } n   long long flag = 0; n   long long last = pile[n - 1]; n   long long index; n   for (long long i = n - 1; i > 0; i--) { n     if (pile[i] == 1) { n       index = i; n       break; n     } n     if (pile[i] - 1 == pile[i - 1] && pile[i] != 0) { n     } else { n       flag = 1; n       break; n     } n   } n   long long shift = 0; n   if (flag == 1) { n     for (long long i = 0; i < n; i++) { n       if (pile[i] != 0) shift = max(shift, i + 2 - pile[i]); n     } n     cout << shift + n; n   } else { n     long long last = pile[n - 1]; n     for (long long i = 0; i < n; i++) { n       if (pile[i] == 1) { n         break; n       } n       if (pile[i] != 0) { n         shift = max(shift, i + 2 - (pile[i] - pile[n - 1])); n       } n     } n     if (shift == 0) { n       cout << shift + n - pile[n - 1]; n     } else { n       cout << index + 1 + n; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   if (0) return; n   cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   if (0) return; n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n void get_it_done() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n const long long N = 1e5 + 5; n long long n, m, k, s; n vector<long long> adjList[N], goods[N], cost[N]; n long long arr[N], dp[105][N]; n bool visited[N]; n int32_t main() { n   get_it_done(); n   long long t = 1; n   while (t--) { n     cin >> n >> m >> k >> s; n     for (long long i = 1; i < n + 1; ++i) n       cin >> arr[i], goods[arr[i]].push_back(i); n     for (long long i = 0; i < m; ++i) { n       long long u, v; n       cin >> u >> v; n       adjList[u].push_back(v); n       adjList[v].push_back(u); n     } n     if (s == 1) { n       for (long long i = 0; i < n; ++i) { n         cout << 0 <<    ; n       } n       cout <<   n ; n       continue; n     } n     for (long long i = 1; i < k + 1; ++i) { n       memset(visited, 0, sizeof(visited)); n       queue<long long> q; n       for (auto x : goods[i]) { n         visited[x] = 1; n         q.push(x); n       } n       while (!q.empty()) { n         long long node = q.front(); n         q.pop(); n         for (auto x : adjList[node]) { n           if (!visited[x]) { n             dp[i][x] = dp[i][node] + 1; n             visited[x] = 1; n             q.push(x); n           } n         } n       } n       for (long long j = 1; j < n + 1; ++j) { n         cost[j].push_back(dp[i][j]); n       } n     } n     for (long long i = 1; i < n + 1; ++i) { n       sort(cost[i].begin(), cost[i].end()); n       long long ans = 0; n       for (long long j = 0; j < s; ++j) { n         ans += cost[i][j]; n       } n       cout << ans <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, dd[270000]; n int main() { n   cin >> n >> x; n   int limit = (1 << n) - 1; n   vector<int> Q; n   Q.push_back(0); n   for (int i = 1; i <= limit; i++) { n     if (i == x) continue; n     if (dd[i]) continue; n     Q.push_back(i); n     dd[(i ^ x)] = 1; n   } n   cout << Q.size() - 1 << endl; n   for (int i = 1; i < Q.size(); i++) { n     cout << (Q[i] ^ Q[i - 1]) <<    ; n   } n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   int r = n + n - 1; n   int a = 0; n   int b = 0; n   int i; n   for (i = 0; i < n; i++) { n     scanf( %d , &a); n     if (a >= b) { n       r = r + (a - b); n     } else { n       r = r + (b - a); n     } n     b = a; n   } n   printf( %d , r); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, p, len; n int pos[500020]; n int Left[500020]; n int Right[500020]; n string str; n void Work() { n   int t = p; n   char op; n   int rt; n   for (int i = 0; i < m; i++) { n     cin >> op; n     if (op ==  L ) n       p = Left[p]; n     else if (op ==  R ) n       p = Right[p]; n     else { n       rt = pos[p]; n       if (rt > p) swap(rt, p); n       Right[Left[rt]] = Right[p]; n       Left[Right[p]] = Left[rt]; n       if (Right[p] > len) n         p = Left[rt]; n       else n         p = Right[p]; n     } n   } n   for (int i = 0; i <= len;) { n     if (i) cout << str[i - 1]; n     i = Right[i]; n   } n   cout << endl; n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   while (cin >> n >> m >> p) { n     stack<int> s; n     cin >> str; n     len = str.size(); n     Right[0] = 1; n     Left[1] = 0; n     Right[len] = len + 1; n     Left[len + 1] = len; n     for (int i = 1; i <= len; i++) { n       Right[i] = i + 1; n       Left[i] = i - 1; n       if (str[i - 1] ==  ( ) n         s.push(i); n       else { n         pos[i] = s.top(); n         pos[s.top()] = i; n         s.pop(); n       } n     } n     Work(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long F(unsigned long long n) { n   if (n < 10) return n; n   unsigned long long nn = n; n   int firstDig = 0; n   while (n) { n     firstDig = n % 10; n     n /= 10; n   } n   return (nn / 10) + 9 - (firstDig > (nn % 10)); n } n int main() { n   unsigned long long x, y; n   while (cin >> x >> y) cout << F(y) - F(x - 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char p[2010], tp[2010]; n char q[2010]; n vector<int> Res; n void Rev(int L) { n   int i; n   Res.push_back(L); n   for (i = n - L; i < n; i++) { n     tp[n - 1 - i] = p[i]; n   } n   for (i = 0; i < n - L; i++) { n     tp[i + L] = p[i]; n   } n   for (i = 0; i < n; i++) p[i] = tp[i]; n } n int C[30]; n int main() { n   int i, j; n   scanf( %d , &n); n   scanf( %s , p); n   scanf( %s , q); n   for (i = 0; q[i]; i++) { n     C[p[i] -  a ]++; n     C[q[i] -  a ]--; n   } n   for (i = 0; i < 26; i++) { n     if (C[i] != 0) { n       printf( -1 n ); n       return 0; n     } n   } n   for (i = 0; i < n - 1; i += 2) { n     int p1 = -1, p2 = -1; n     for (j = i; j < n; j++) { n       if (p[j] == q[i]) p1 = j; n     } n     for (j = i; j < n; j++) { n       if (p[j] == q[i + 1] && j != p1) p2 = j; n     } n     int L1 = i, L2, L3 = 1, L4, L5 = 1, L6; n     if (p1 < p2) { n       L2 = p1 - i; n       L4 = p2 - p1 - 1; n       L6 = n - p2 - 1; n       Rev(L6); n       Rev(L4 + L5); n       Rev(L3); n       Rev(L1 + L2 + L4 + L5 + L6); n       Rev(L3 + L4 + L5 + L6); n       Rev(L1); n     } else { n       L2 = p2 - i; n       L4 = p1 - p2 - 1; n       L6 = n - p1 - 1; n       Rev(L6); n       Rev(L5); n       Rev(L3 + L4); n       Rev(L1 + L2 + L6); n       Rev(L3 + L4 + L5 + L6); n       Rev(L1); n     } n   } n   printf( %d n , Res.size()); n   for (i = 0; i < Res.size(); i++) printf( %d  , Res[i]); n } n


#include <bits/stdc++.h> n using namespace std; n void strange(int t) { n   while (t--) { n     int n; n     cin >> n; n     vector<int> p(n); n     for (int i = 0; i < n; i++) { n       cin >> p[i]; n       p[i]--; n     } n     bool g = 1; n     int MIN = n; n     for (int i = 0; i < n; i++) { n       if (p[i] < MIN) n         MIN = p[i]; n       else if (p[i] == p[i - 1] + 1) { n       } else { n         g = false; n         break; n       } n     } n     cout << (g ?  Yes  :  No ) << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   strange(t); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, a, t; n   while (cin >> n >> m >> a) { n     if (m < n) { n       t = m; n       m = n; n       n = t; n     } n     if (a >= m) cout << 1 << endl; n     if ((a < m) && (a >= n)) { n       if (m % a == 0) n         cout << m / a << endl; n       else n         cout << m / a + 1 << endl; n     } n     if ((a < n) && (m % a != 0) && (n % a != 0)) n       cout << (m / a + 1) * (n / a + 1) << endl; n     if ((a < n) && (m % a != 0) && (n % a == 0)) n       cout << (m / a + 1) * (n / a) << endl; n     if ((a < n) && (m % a == 0) && (n % a != 0)) n       cout << (m / a) * (n / a + 1) << endl; n     if ((a < n) && (m % a == 0) && (n % a == 0)) n       cout << (m / a) * (n / a) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[1003]; n int main() { n   int n, x, ans, sum, t, ck; n   cin >> t; n   while (t--) { n     cin >> n >> x; n     for (int i = 1; i <= n; i++) cin >> arr[i]; n     sort(arr + 1, arr + n + 1); n     ck = 0; n     for (int i = 1; i <= n; i++) { n       if (arr[i] == x) ck = 1; n     } n     sum = 0; n     for (int i = 1; i <= n; i++) sum += (arr[i] - x); n     if (arr[1] == arr[n] && arr[n] == x) n       ans = 0; n     else if (sum == 0 || ck) n       ans = 1; n     else n       ans = 2; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class T> n int ge(const vector<T>& v, T val) { n   return distance(v.begin(), lower_bound(v.begin(), v.end(), val)); n } n template <class T> n int gt(const vector<T>& v, T val) { n   return distance(v.begin(), upper_bound(v.begin(), v.end(), val)); n } n template <class T> n int le(const vector<T>& v, T val) { n   auto itr = upper_bound(v.begin(), v.end(), val); n   if (itr == v.begin()) return v.size(); n   return distance(v.begin(), --itr); n } n template <class T> n int lt(const vector<T>& v, T val) { n   auto itr = lower_bound(v.begin(), v.end(), val); n   if (itr == v.begin()) return v.size(); n   return distance(v.begin(), --itr); n } n template <class T> n struct BIT { n   int size; n   vector<T> data; n   function<T(T, T)> f = [](T a, T b) { return a + b; }; n   BIT() {} n   BIT(int n) { init(n); } n   void init(int n) { n     size = n; n     data.assign(size + 1, 0); n   } n   T sum(int x) { n     T res = 0; n     while (x > 0) { n       res = f(res, data[x]); n       x -= (x & -x); n     } n     return res; n   } n   T sum(int lft, int rit) { n     if (lft == 0) return sum(rit); n     return sum(rit) - sum(lft - 1); n   } n   void add(int x, T y) { n     while (x <= size) { n       data[x] = f(data[x], y); n       x += (x & -x); n     } n   } n }; n int main(void) { n   int n; n   ll t; n   cin >> n >> t; n   vector<ll> a(n + 1, 0), sum(n + 1, 0), v; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     sum[i] = sum[i - 1] + a[i]; n   } n   v.assign(sum.begin(), sum.end()); n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   int vs = v.size(); n   BIT<int> bit(vs + 1); n   ll ans = 0; n   for (int l = n; l >= 0; l--) { n     int i = lt(v, sum[l] + t); n     if (i < vs) { n       ans += bit.sum(i + 1); n     } n     i = ge(v, sum[l]); n     bit.add(i + 1, 1); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 2 * 1e5 + 2; n int t, n, valeurs[NMAX]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> t; n   for (int test = 1; test <= t; test++) { n     cin >> n; n     if (n % 4 != 0) { n       cout <<  NO n ; n     } else { n       int moitie = n / 2, somme = 0, cur = 0; n       for (int i = 0; i < moitie; i++) { n         valeurs[i] = 2 * (i + 1); n         somme += valeurs[i]; n       } n       for (int i = 0; i < moitie - 1; i++) { n         valeurs[i + moitie] = 2 * i + 1; n         cur += valeurs[i + moitie]; n       } n       valeurs[n - 1] = somme - cur; n       cout <<  YES n ; n       for (int i = 0; i < n; i++) cout << valeurs[i] <<    ; n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, m; n vector<pair<int, int> > v, u; n int a, b, c; n int main() { n   cin >> n >> k >> m; n   a = n; n   for (int i = 0; i < n; i++) { n     int w; n     cin >> w; n     if (v.size() > 0 && v.back().first == w) { n       v.back().second++; n       if (v.back().second == k) { n         v.pop_back(); n         a -= k; n       } n     } else n       v.push_back({w, 1}); n   } n   u = v; n   int b = a; n   int x = 0, y = u.size() - 1; n   while (x < y) { n     if (u[x].first == u[y].first) { n       if (u[x].second + u[y].second == k) { n         x++; n         y--; n         b -= k; n       } else { n         if (u[x].second + u[y].second > k) b -= k; n         break; n       } n     } else { n       break; n     } n   } n   long long r = m * b; n   a -= b; n   if (x == y) { n     r = r % k; n     if (r == 0) a = 0; n   } n   cout << a + r << endl; n   return 0; n } n


#include<iostream> n using namespace std; n  n int query(int a, int b) { n  cout <<  ?   << a <<     << b << endl; n  cout.flush(); n  int ret; n  cin >> ret; n  return ret; n } n  n int main() { n  int n; n  cin >> n; n  int lt = 1, rt = n; n  int sec = query(1, n); n  while (rt - lt > 0) { n   int mid; n   if (rt + lt <= 2 * sec) { n    mid = (rt + lt + 1) / 2; n    if (mid == n) { n     rt = n - 1; n     break; n    } n    if (query(mid, n) == sec) lt = mid; n    else rt = mid - 1; n   } n   if (rt+lt > 2*sec) { n    mid = (rt + lt) / 2; n    if (mid == 1) { n     lt = 2; n     break; n    } n    if (query(1, mid) == sec) rt = mid; n    else lt = mid + 1; n   } n  } n  cout <<  !   << lt << endl; n  cout.flush(); n }


#include <bits/stdc++.h> n using namespace std; n long long int fast_expo(long long int x, long long int p) { n   if (p == 0) n     return 1; n   else if (p % 2 == 0) { n     long long int t = fast_expo(x, p / 2) % 1000000007; n     return (t * t) % 1000000007; n   } else n     return (x * (fast_expo(x, p - 1)) % 1000000007) % 1000000007; n } n long long int aft_bunk[501][501]; n long long int dp[501][501]; n vector<long long int> vect[501]; n long long int solve(long long int day, long long int bunk) { n   if (day == -1 && bunk >= 0) return 0; n   if (day < 0 || bunk < 0) return INT_MAX; n   if (dp[day][bunk] != -1) return dp[day][bunk]; n   long long int ans = INT_MAX; n   for (long long int i = 0; i <= vect[day].size(); ++i) { n     long long int temp = solve(day - 1, bunk - i) + aft_bunk[day][i]; n     if (ans > temp) ans = temp; n   } n   return dp[day][bunk] = ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long int n, m, k; n   cin >> n >> m >> k; n   char tempo; n   for (long long int i = 0; i < n; ++i) { n     for (long long int j = 1; j <= m; ++j) { n       cin >> tempo; n       if (tempo ==  1 ) { n         vect[i].push_back(j); n       } n     } n   } n   for (long long int i = 0; i < n; ++i) { n     for (long long int j = 0; j < 501; ++j) { n       aft_bunk[i][j] = INT_MAX; n     } n   } n   long long int temp; n   for (long long int i = 0; i < n; ++i) { n     for (long long int j = 0; j < vect[i].size(); ++j) { n       long long int ptr1 = 0, ptr2 = vect[i].size() - 1 - j; n       for (long long int ptr1 = 0; ptr1 <= j; ptr1++, ptr2++) { n         temp = vect[i][ptr2] - vect[i][ptr1] + 1; n         if (temp < aft_bunk[i][j]) aft_bunk[i][j] = temp; n       } n     } n     aft_bunk[i][vect[i].size()] = 0; n   } n   for (long long int i = 0; i < 501; ++i) { n     for (long long int j = 0; j < 501; ++j) dp[i][j] = -1; n   } n   cout << solve(n - 1, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n const int maxn = 5e5 + 5; n struct Point { n   char ty; n   int x, y; n   Point(char ch =  0 , int x = 0, int y = 0) : ty(ch), x(x), y(y) {} n } chess[maxn]; n int X0, Y0, n; n bool solve1() { n   vector<pair<int, char> > v; n   for (int i = 1; i <= n; i++) { n     if (chess[i].x == X0) v.push_back(make_pair(chess[i].y, chess[i].ty)); n   } n   if (v.size() == 0) return false; n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size() - 1; i++) { n     if (v[i].first < Y0 && v[i + 1].first > Y0) { n       if (v[i].second ==  R  || v[i].second ==  Q  || v[i + 1].second ==  R  || n           v[i + 1].second ==  Q ) n         return true; n       return false; n     } n   } n   int len = v.size(); n   if (v[len - 1].first < Y0 && n       (v[len - 1].second ==  R  || v[len - 1].second ==  Q )) n     return true; n   if (v[0].first > Y0 && (v[0].second ==  R  || v[0].second ==  Q )) n     return true; n   return false; n } n bool solve2() { n   vector<pair<int, char> > v; n   for (int i = 1; i <= n; i++) { n     if (chess[i].y == Y0) v.push_back(make_pair(chess[i].x, chess[i].ty)); n   } n   if (v.size() == 0) return false; n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size() - 1; i++) { n     if (v[i].first < X0 && v[i + 1].first > X0) { n       if (v[i].second ==  R  || v[i].second ==  Q  || v[i + 1].second ==  R  || n           v[i + 1].second ==  Q ) n         return true; n       return false; n     } n   } n   int len = v.size(); n   if (v[len - 1].first < X0 && n       (v[len - 1].second ==  R  || v[len - 1].second ==  Q )) n     return true; n   if (v[0].first > X0 && (v[0].second ==  R  || v[0].second ==  Q )) n     return true; n   return false; n } n bool solve3() { n   vector<pair<int, char> > v; n   for (int i = 1; i <= n; i++) { n     if (chess[i].x == chess[i].y) n       v.push_back(make_pair(chess[i].x, chess[i].ty)); n   } n   if (v.size() == 0) return false; n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size() - 1; i++) { n     if (v[i].first < X0 && v[i + 1].first > X0) { n       if (v[i].second ==  B  || v[i].second ==  Q  || v[i + 1].second ==  B  || n           v[i + 1].second ==  Q ) n         return true; n       return false; n     } n   } n   int len = v.size(); n   if (v[len - 1].first < X0 && n       (v[len - 1].second ==  B  || v[len - 1].second ==  Q )) n     return true; n   if (v[0].first > X0 && (v[0].second ==  B  || v[0].second ==  Q )) n     return true; n   return false; n } n bool solve4() { n   vector<pair<int, char> > v; n   for (int i = 1; i <= n; i++) { n     if (chess[i].x == -chess[i].y) n       v.push_back(make_pair(chess[i].x, chess[i].ty)); n   } n   if (v.size() == 0) return false; n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size() - 1; i++) { n     if (v[i].first < X0 && v[i + 1].first > X0) { n       if (v[i].second ==  B  || v[i].second ==  Q  || v[i + 1].second ==  B  || n           v[i + 1].second ==  Q ) n         return true; n       return false; n     } n   } n   int len = v.size(); n   if (v[len - 1].first < X0 && n       (v[len - 1].second ==  B  || v[len - 1].second ==  Q )) n     return true; n   if (v[0].first > X0 && (v[0].second ==  B  || v[0].second ==  Q )) n     return true; n   return false; n } n int main() { n   cin >> n >> X0 >> Y0; n   for (int i = 1; i <= n; i++) { n     char ch; n     int a, b; n     scanf( %s%d%d , &ch, &a, &b); n     chess[i] = Point(ch, a - X0, b - Y0); n   } n   X0 = Y0 = 0; n   if (solve1() || solve2() || solve3() || solve4()) n     printf( YES n ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using ii = pair<ll, ll>; n using vi = vector<ll>; n using vb = vector<bool>; n using vvi = vector<vi>; n using vii = vector<ii>; n using vvii = vector<vii>; n const int INF = 2000000000; n const ll LLINF = 9000000000000000000; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int N; n   ll M, T; n   cin >> N >> M >> T; n   vi S(N, 0LL); n   vi D(N, 0LL); n   vii Si(N, {0LL, 0LL}); n   bool lf = false, rf = false; n   int dsum = 0; n   for (int i = 0; i < N; ++i) { n     char c; n     cin >> S[i] >> c; n     D[i] = (c ==  L  ? -1 : 1); n     if (D[i] == -1) n       lf = true; n     else n       rf = true; n     dsum += D[i]; n     Si[i] = {S[i], i}; n   } n   vi pos(N, 0LL); n   for (int i = 0; i < N; ++i) { n     pos[i] = (S[i] + D[i] * (T % M)) + M; n     pos[i] %= M; n     if (pos[i] == 0) pos[i] = M; n   } n   if (!lf || !rf) { n     for (int i = 0; i < N; ++i) cout << pos[i] <<    n [i + 1 == N]; n     return 0; n   } n   vii crossdir; n   for (int i = 0; i < N; ++i) { n     ll k = -D[i] * (D[i] == 1 ? (S[i] - 1) : S[i]); n     while (k <= 0) k += M; n     k %= M; n     if (k == 0) k += M; n     crossdir.push_back({k, D[i]}); n   } n   sort(crossdir.begin(), crossdir.end()); n   ll shift = -(T / M) * dsum; n   for (size_t j = 0; j < crossdir.size() && crossdir[j].first <= (T % M); ++j) { n     shift -= crossdir[j].second; n   } n   shift = ((shift % N) + N) % N; n   sort(pos.begin(), pos.end()); n   sort(Si.begin(), Si.end()); n   vi ans(N, 0); n   for (int i = 0; i < N; ++i) { n     ans[Si[i].second] = pos[(i + N - shift) % N]; n   } n   for (int i = 0; i < N; ++i) cout << ans[i] <<    n [i + 1 == N]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n long long power(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret *= a; n     a *= a; n     if (ret >= MOD) ret %= MOD; n     if (a >= MOD) a %= MOD; n     b >>= 1; n   } n   return ret; n } n long long invmod(long long x) { return power(x, MOD - 2); } n vector<long long> vp[100005]; n int vis[100005] = {0}; n int dfs(int n) { n   if (vp[n].size() < 2) return 10001; n   int a[4005] = {0}; n   vector<long long> vp1; n   for (int i = 0; i < vp[n].size(); i++) { n     vp1.push_back(vp[n][i]); n     a[vp[n][i]] = 1; n   } n   int min = 10001; n   for (int i = 0; i < vp1.size(); i++) { n     for (int j = 0; j < vp[vp1[i]].size(); j++) { n       if (a[vp[vp1[i]][j]] == 1) { n         if (min > n             vp[vp[vp1[i]][j]].size() + vp[n].size() + vp[vp1[i]].size() - 6) { n           min = vp[vp[vp1[i]][j]].size() + vp[n].size() + vp[vp1[i]].size() - 6; n           break; n         } n       } n     } n   } n   return min; n } n int main() { n   int n, m; n   cin >> m >> n; n   int x, y; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     vp[x].push_back(y); n     vp[y].push_back(x); n   } n   int min1 = 10000; n   for (int i = 1; i <= m; i++) { n     min1 = min(dfs(i), min1); n   } n   if (min1 == 10000) { n     cout <<  -1  << endl; n     return 0; n   } n   cout << min1 << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int a, b, c, d; n   cin >> a >> b >> c >> d; n   long double t = n       (a * 1.0 / b) * (1.0 / (1 - (1 - a * 1.0 / b) * (1 - c * 1.0 / d))); n   cout << t << fixed << setprecision(6); n } n


#include <bits/stdc++.h> n using namespace std; n int const MAX_N = 600100; n int const INT_INF = 1000000000; n int my_rank[MAX_N], my_parent[MAX_N], diam_ancestor[MAX_N]; n int d[MAX_N], och[MAX_N], nnew[MAX_N]; n void make_set(int v) { n   my_parent[v] = v; n   diam_ancestor[v] = 0; n   my_rank[v] = 0; n } n int find_set(int v) { n   if (v != my_parent[v]) my_parent[v] = find_set(my_parent[v]); n   return my_parent[v]; n } n void my_Link(int x, int y, int flag) { n   if (my_rank[x] > my_rank[y]) n     my_parent[y] = x; n   else n     my_parent[x] = y; n   my_rank[y] += my_rank[x] == my_rank[y]; n   if (flag) { n     int D1 = diam_ancestor[x]; n     int D2 = diam_ancestor[y]; n     int new_VVV = find_set(x); n     int val = (D1 + 1) / 2 + (D2 + 1) / 2 + 1; n     diam_ancestor[new_VVV] = max(D1, max(D2, val)); n   } n } n void my_Union(int x, int y, int flag) { n   int V1 = find_set(x); n   int V2 = find_set(y); n   if (V1 == V2) return; n   my_Link(V1, V2, flag); n } n vector<int> e[MAX_N]; n int main() { n   int n, m, q; n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 0; i < n; i++) make_set(i); n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--; n     b--; n     my_Union(a, b, 0); n     e[a].push_back(b); n     e[b].push_back(a); n   } n   for (int i = 0; i < n; i++) d[i] = INT_INF; n   for (int i = 0; i < n; i++) n     if (!nnew[i]) { n       int p_read = 0, p_write = 1; n       och[p_read] = i; n       nnew[i] = 1; n       d[i] = 0; n       while (p_read < p_write) { n         int v = och[p_read]; n         p_read++; n         for (int j = 0; j < (int)e[v].size(); j++) { n           int new_v = e[v][j]; n           if (d[new_v] > d[v] + 1) { n             d[new_v] = d[v] + 1; n             och[p_write] = new_v; n             p_write++; n             nnew[new_v] = 1; n           } n         } n       } n       int mx_dist = -1, ans_vertex = -1; n       for (int j = 0; j < p_write; j++) n         if (d[och[j]] > mx_dist) { n           mx_dist = d[och[j]]; n           ans_vertex = och[j]; n         } n       for (int j = 0; j < p_write; j++) d[och[j]] = INT_INF; n       p_read = 0, p_write = 1; n       och[p_read] = ans_vertex; n       d[ans_vertex] = 0; n       while (p_read < p_write) { n         int v = och[p_read]; n         p_read++; n         for (int j = 0; j < (int)e[v].size(); j++) { n           int new_v = e[v][j]; n           if (d[new_v] > d[v] + 1) { n             d[new_v] = d[v] + 1; n             och[p_write] = new_v; n             p_write++; n           } n         } n       } n       mx_dist = -1; n       for (int j = 0; j < p_write; j++) mx_dist = max(mx_dist, d[och[j]]); n       diam_ancestor[find_set(i)] = mx_dist; n     } n   for (int i = 0; i < q; i++) { n     int tp; n     scanf( %d , &tp); n     if (tp == 2) { n       int a, b; n       scanf( %d%d , &a, &b); n       a--; n       b--; n       my_Union(a, b, 1); n     } else if (tp == 1) { n       int v; n       scanf( %d , &v); n       v--; n       int VVV = find_set(v); n       printf( %d n , diam_ancestor[VVV]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char arr[300]; n int main() { n   ios::sync_with_stdio(false); n   string s, t; n   cin >> s >> t; n   int n = s.size(); n   memset(arr,  A , sizeof(arr)); n   if (n != t.size()) { n     cout << -1; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     if (arr[t[i]] !=  A ) { n       if (arr[t[i]] != s[i]) { n         cout << -1; n         return 0; n       } n       continue; n     } n     if (arr[s[i]] ==  A ) { n       arr[s[i]] = t[i]; n       arr[t[i]] = s[i]; n     } n     if (arr[s[i]] != t[i]) { n       cout << -1; n       return 0; n     } n   } n   vector<pair<char, char> > v; n   for (int i = 0; i < 300; i++) { n     if (arr[i] !=  A ) { n       if (i == arr[i]) continue; n       v.push_back(make_pair((char)i, arr[i])); n       arr[arr[i]] =  A ; n       arr[i] =  A ; n     } n   } n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) n     cout << v[i].first <<     << v[i].second << endl; n   return 0; n } n