#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1); n const int dx[4] = {0, 0, 1, -1}; n const int dy[4] = {1, -1, 0, 0}; n int n, a, b, c; n string s; n map<pair<int, pair<int, int> >, int> dic; n bool bo1 = false, bo2 = false, bo3 = false; n void dfs(int a, int b, int c) { n   pair<int, pair<int, int> > temp = make_pair(a, make_pair(b, c)); n   if (dic[temp]) return; n   dic[temp] = 1; n   if (a + b + c == 1) { n     if (a == 1) bo1 = true; n     if (b == 1) bo2 = true; n     if (c == 1) bo3 = true; n     return; n   } n   if (a > 0 && b > 0) dfs(a - 1, b - 1, c + 1); n   if (a > 0 && c > 0) dfs(a - 1, b + 1, c - 1); n   if (b > 0 && c > 0) dfs(a + 1, b - 1, c - 1); n   if (a > 1) dfs(a - 1, b, c); n   if (b > 1) dfs(a, b - 1, c); n   if (c > 1) dfs(a, b, c - 1); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   cin >> n; n   cin >> s; n   for (int i = 0; i < (int)s.size(); i++) { n     if (s[i] ==  B ) a++; n     if (s[i] ==  G ) b++; n     if (s[i] ==  R ) c++; n   } n   dfs(a, b, c); n   if (bo1) cout <<  B ; n   if (bo2) cout <<  G ; n   if (bo3) cout <<  R ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const int MX = 3003; n const int M = 998244353; n char s[MX], t[MX]; n int n, m, ans, dp[MX][MX]; n int f(int i, int j) { n   if (i < 1 && j > n) return 1; n   if (dp[i][j] == -1) { n     int p = 0, q = 0, r = (i == j); n     int k = j - i + r, x = (i < 1 && j > m); n     if (i) { n       if (i <= m) n         p = (s[k] == t[i]) ? f(i - 1, j + r) : 0; n       else n         p = f(i - 1, j + r); n     } n     if (j <= n) { n       if (j <= m) n         q = (s[k] == t[j]) ? f(i - r, j + 1) : 0; n       else n         q = f(i - r, j + 1); n     } n     int y = (p + q < M) ? (p + q) : (p + q - M); n     dp[i][j] = (x + y < M) ? (x + y) : (x + y - M); n   } n   return dp[i][j]; n } n int main() { n   scanf( %s %s , s + 1, t + 1); n   n = strlen(s + 1), m = strlen(t + 1); n   memset(dp, -1, sizeof(dp)); n   for (int i = 1; i <= n; i++) ans = (ans + f(i, i)) % M; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int day[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}; n int sec, n, k, dd, mm, h, s, m, now; n string str; n queue<int> q; n int main() { n   cin >> sec >> k; n   getline(cin, str); n   while (scanf( 2012-%d-%d %d:%d:%d: , &mm, &dd, &h, &m, &s) != EOF) { n     getline(cin, str); n     now = (day[mm - 1] + dd - 1) * 24 * 60 * 60 + h * 60 * 60 + m * 60 + s; n     q.push(now); n     while (q.front() + sec <= now) q.pop(); n     if (q.size() >= k) { n       printf( 2012-%02d-%02d %02d:%02d:%02d , mm, dd, h, m, s); n       return 0; n     } n   } n   cout << -1 << endl; n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:128000000 ) n using namespace std; n map<string, int> a; n map<string, int>::iterator ii, jj; n string s; n int main() { n   int k, i, v, u, j, n, m, d, d2, y, r, p, t1, t2, x, l, t, z, fl, to; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> s >> p; n     if (a[s] <= p) a[s] = p; n   } n   k = 0; n   for (ii = a.begin(); ii != a.end(); ii++) k++; n   cout << k << endl; n   for (ii = a.begin(); ii != a.end(); ii++) { n     t = 0; n     p = 0; n     for (jj = a.begin(); jj != a.end(); jj++) { n       if ((*ii).second >= (*jj).second) t++; n       if ((*ii).second < (*jj).second) p++; n     } n     if ((double)p / (double)k > 0.5) { n       cout << (*ii).first <<     n            <<  noob  << endl; n       continue; n     } n     if ((double)t / (double)k >= 0.5 && (double)p / (double)k > 0.2) { n       cout << (*ii).first <<     n            <<  random  << endl; n       continue; n     } n     if ((double)t / (double)k >= 0.8 && (double)p / (double)k > 0.1) { n       cout << (*ii).first <<     n            <<  average  << endl; n       continue; n     } n     if ((double)t / (double)k >= 0.9 && (double)p / (double)k > 0.01) { n       cout << (*ii).first <<     n            <<  hardcore  << endl; n       continue; n     } n     if ((double)t / (double)k >= 0.99) { n       cout << (*ii).first <<     n            <<  pro  << endl; n       continue; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   priority_queue<int> pq{}; n   for (int i{1}; i <= n; ++i) pq.push(i); n   vector<pair<int, int>> ans{}; n   for (int i{0}; i < n - 1; ++i) { n     int mx1{pq.top()}; n     pq.pop(); n     int mx2{pq.top()}; n     pq.pop(); n     ans.push_back({mx1, mx2}); n     pq.push((mx1 + mx2 + 1) / 2); n   } n   cout << pq.top() <<   n ; n   for (auto& x : ans) cout << x.first <<     << x.second <<   n ; n } n void solve2() { n   int n; n   cin >> n; n   cout <<  2 n ; n   cout << n <<     << n - 1 <<   n ; n   for (int i{n}; i >= 3; --i) cout << i <<     << i - 2 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int t; n   cin >> t; n   while (t--) solve2(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[200] = {0}; n int main() { n   string a; n   int m; n   cin >> m; n   cin >> a; n   int n = a.length(); n   for (int i = 0; i < n; i++) { n     if (a[i] !=  ? ) p[a[i] -  a ] = 1; n     if (a[i] !=  ?  && a[i] -  a  >= m) { n       cout <<  IMPOSSIBLE  << endl; n       return 0; n     } n   } n   for (int i = 0; i < n; i++) { n     if (a[i] ==  ?  && a[n - i - 1] !=  ? ) a[i] = a[n - i - 1]; n   } n   for (int i = n / 2; i >= 0; i--) { n     if (a[i] ==  ?  && a[n - i - 1] ==  ? ) { n       for (int j = m - 1; j >= 0; j--) { n         if (!p[j]) { n           a[i] = j +  a ; n           a[n - i - 1] = j +  a ; n           p[j] = 1; n           break; n         } n       } n       if (a[i] ==  ? ) a[i] =  a , a[n - i - 1] =  a ; n     } n   } n   for (int i = 0; i < n; i++) { n     if (a[i] != a[n - i - 1]) { n       cout <<  IMPOSSIBLE  << endl; n       return 0; n     } n   } n   for (int i = 0; i < m; i++) n     if (!p[i]) { n       cout <<  IMPOSSIBLE  << endl; n       return 0; n     } n   cout << a << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200005; n int v[MAXN], l[MAXN], r[MAXN]; n int ST[4 * MAXN]; n int L[4 * MAXN]; n int n; n void _update(int node, int lo, int hi, int i, int j, int val) { n   if (L[node]) { n     ST[node] = max(ST[node], L[node]); n     if (hi != lo) { n       L[2 * node] = max(L[node], L[2 * node]); n       L[2 * node + 1] = max(L[node], L[2 * node + 1]); n     } n     L[node] = 0; n   } n   if (lo > j || hi < i) return; n   if (lo >= i && hi <= j) { n     ST[node] = max(ST[node], val); n     if (hi != lo) { n       L[2 * node] = max(val, L[2 * node]); n       L[2 * node + 1] = max(val, L[2 * node + 1]); n     } n     return; n   } n   int mid = (lo + hi) / 2; n   _update(2 * node, lo, mid, i, j, val); n   _update(2 * node + 1, mid + 1, hi, i, j, val); n   ST[node] = max(ST[2 * node], ST[2 * node + 1]); n } n int _query(int node, int l, int r, int i, int j) { n   if (L[node]) { n     ST[node] = max(ST[node], L[node]); n     L[2 * node] = max(L[2 * node], L[node]); n     L[2 * node + 1] = max(L[2 * node + 1], L[node]); n     L[node] = 0; n   } n   if (r < i || l > j) return -1; n   if (l >= i && r <= j) return ST[node]; n   int mid = (l + r) / 2; n   int p1 = _query(2 * node, l, mid, i, j); n   int p2 = _query(2 * node + 1, mid + 1, r, i, j); n   return max(p1, p2); n } n int query(int i, int j) { return _query(1, 0, n, i, j); } n void update(int i, int j, int val) { _update(1, 0, n, i, j, val); } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &v[i]); n   l[0] = -1; n   for (int i = 1; i < n; i++) { n     l[i] = i - 1; n     while (v[l[i]] >= v[i] && l[i] != -1) l[i] = l[l[i]]; n   } n   r[n - 1] = -1; n   for (int i = n - 2; i >= 0; i--) { n     r[i] = i + 1; n     while (v[r[i]] >= v[i] && r[i] != -1) { n       r[i] = r[r[i]]; n     } n   } n   for (int i = 0; i < n; i++) { n     int ri = r[i], li = l[i]; n     if (ri == -1) ri = n; n     if (li == -1) li = -1; n     int segment_length = (ri - 1) - (li + 1) + 1; n     update(1, segment_length, v[i]); n   } n   bool first = true; n   for (int i = 1; i <= n; i++) { n     if (first) n       first = false; n     else n       printf(   ); n     printf( %d , query(i, i)); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[4]; n int main() { n   cin >> a[0] >> a[1] >> a[2] >> a[3]; n   sort(a, a + 4); n   if (a[0] + a[1] > a[2] || a[1] + a[2] > a[3]) { n     cout <<  TRIANGLE ; n     return 0; n   } else if (a[0] + a[1] == a[2] || a[1] + a[2] == a[3]) { n     cout <<  SEGMENT ; n     return 0; n   } else n     cout <<  IMPOSSIBLE ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n bool isin( n     const pair<long long, tuple<long long, long long, long long> >& elem) { n   return get<1>(elem.second) == 0; n } n bool isout( n     const pair<long long, tuple<long long, long long, long long> >& elem) { n   return get<0>(elem.second) == 0; n } n long long INF = 1e18; n int main() { n   long long n, m, k; n   cin >> n >> m >> k; n   if (m == 0) { n     cout << -1; n     return 0; n   } n   vector<pair<long long, tuple<long long, long long, long long> > > flights; n   long long d, f, t, c; n   for (long long i = 0; i < m; i++) { n     cin >> d >> f >> t >> c; n     flights.push_back( n         make_pair(d, tuple<long long, long long, long long>(f, t, c))); n   } n   sort(flights.begin(), flights.end()); n   long long days_cnt = flights.back().first + 2; n   vector<bool> in(n + 1, false); n   vector<bool> out(n + 1, false); n   vector<long long> totalin(days_cnt, 0); n   vector<long long> totalout(days_cnt, 0); n   vector<long long> pre_min(days_cnt, INF); n   vector<long long> suf_min(days_cnt, INF); n   vector<long long> p_min(n + 1, INF); n   vector<long long> p_min_rev(n + 1, INF); n   long long cur = 0; n   for (long long i = 0; i < flights.size(); i++) { n     auto elem = flights[i]; n     long long d = elem.first; n     long long f = get<0>(elem.second); n     long long t = get<1>(elem.second); n     long long c = get<2>(elem.second); n     long long p = f; n     if (p == 0) { n       continue; n     } n     while (cur < d) { n       cur++; n       totalin[cur] = totalin[cur - 1]; n       pre_min[cur] = pre_min[cur - 1]; n     } n     if (!in[p]) { n       totalin[d]++; n       in[p] = true; n       p_min[p] = c; n       pre_min[d] = (pre_min[d] == INF ? 0 : pre_min[d]) + p_min[p]; n     } else { n       long long old_min = p_min[p]; n       p_min[p] = min(p_min[p], c); n       if (old_min > p_min[p]) { n         pre_min[d] -= old_min; n         pre_min[d] += p_min[p]; n       } n     } n   } n   while (cur < days_cnt) { n     cur++; n     if (cur == days_cnt) continue; n     pre_min[cur] = pre_min[cur - 1]; n     totalin[cur] = totalin[cur - 1]; n   } n   cur = days_cnt - 1; n   for (long long i = flights.size() - 1; i >= 0; i--) { n     auto elem = flights[i]; n     long long d = elem.first; n     long long f = get<0>(elem.second); n     long long t = get<1>(elem.second); n     long long c = get<2>(elem.second); n     long long p = t; n     if (p == 0) { n       continue; n     } n     while (cur > d) { n       cur--; n       totalout[cur] = totalout[cur + 1]; n       suf_min[cur] = suf_min[cur + 1]; n     } n     if (!out[p]) { n       totalout[d]++; n       out[p] = true; n       p_min_rev[p] = c; n       suf_min[d] = (suf_min[d] == INF ? 0 : suf_min[d]) + p_min_rev[p]; n     } else { n       long long old_min = p_min_rev[p]; n       p_min_rev[p] = min(p_min_rev[p], c); n       if (old_min > p_min_rev[p]) { n         suf_min[d] -= old_min; n         suf_min[d] += p_min_rev[p]; n       } n     } n   } n   while (cur >= 0) { n     cur--; n     if (cur < 0) continue; n     suf_min[cur] = suf_min[cur + 1]; n     totalout[cur] = totalout[cur + 1]; n   } n   long long ans = INF; n   for (long long i = 0; i < suf_min.size(); i++) { n     if (i + k + 1 >= totalout.size()) continue; n     if (totalin[i] >= n && totalout[i + k + 1] >= n) { n       ans = min(ans, pre_min[i] + suf_min[i + k + 1]); n     } n   } n   cout << (ans >= INF ? -1 : ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 400010; n inline int max(int a, int b) { return a > b ? a : b; } n int head[maxn], cnt, sz[maxn], n, mx_sz, top[maxn], ans[maxn]; n vector<int> vt; n struct ed { n   int to, next; n } e[maxn * 2]; n void ad(int x, int y) { n   e[cnt] = (ed){y, head[x]}; n   head[x] = cnt++; n   e[cnt] = (ed){x, head[y]}; n   head[y] = cnt++; n } n void get_vt(int u, int last) { n   sz[u] = 1; n   int mx = 0; n   for (int k = head[u]; ~k; k = e[k].next) { n     int v = e[k].to; n     if (v != last) { n       get_vt(v, u); n       sz[u] += sz[v]; n       mx = max(mx, sz[v]); n     } n   } n   mx = max(mx, n - sz[u]); n   if (mx <= mx_sz) vt.push_back(u); n } n void dfs(int u, int last, int tp) { n   sz[u] = 1, top[u] = tp; n   for (int k = head[u]; ~k; k = e[k].next) { n     int v = e[k].to; n     if (v != last) { n       dfs(v, u, tp); n       sz[u] += sz[v]; n     } n   } n } n void work(int u) { n   ans[u] = 1; n   memset(sz, 0, sizeof(sz)); n   int mx = 0, _mx = 0; n   for (int k = head[u]; ~k; k = e[k].next) { n     int v = e[k].to; n     dfs(v, u, v); n     if (sz[v] >= sz[mx]) n       _mx = mx, mx = v; n     else if (sz[v] > sz[_mx]) n       _mx = v; n   } n   for (int i = 1; i <= n; i++) { n     if (top[i] == mx) n       ans[i] |= (n - sz[i] - sz[_mx] <= mx_sz); n     else n       ans[i] |= (n - sz[i] - sz[mx] <= mx_sz); n   } n } n int main() { n   while (~scanf( %d , &n)) { n     cnt = 0; n     mx_sz = n / 2; n     vt.clear(); n     memset(sz, 0, sizeof(sz)); n     memset(ans, 0, sizeof(ans)); n     memset(head, -1, sizeof(head)); n     int u, v; n     for (int i = 1; i < n; i++) { n       scanf( %d%d , &u, &v); n       ad(u, v); n     } n     get_vt(1, 0); n     for (int i = 0; i < vt.size(); i++) work(vt[i]); n     for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[3010], y[3010]; n vector<int> py[3010]; n int L[3010], R[3010], q, k; n void nxt(int &u, int k = 1) { n   while (k-- > 0) u = R[u]; n } n void pre(int &u, int k = 1) { n   while (k-- > 0) u = L[u]; n } n long long res = 0; n struct node { n   int x, y; n   bool operator<(const node a) const { return x < a.x; } n } p[3010]; n int n, m; n void solve() { n   res = 0; n   int l = 0, r = 0; n   nxt(r, k); n   if (r == q + 1) return; n   for (; r != q + 1; nxt(r)) { n     nxt(l); n     res += 1ll * p[l].x * (p[R[r]].x - p[r].x); n   } n } n void del(int u) { R[L[u]] = R[u], L[R[u]] = L[u]; } n void erase(int u) { n   int l = u; n   pre(l, k + 1); n   int l0 = l; n   int r = l; n   nxt(r, k); n   for (; l < u && r < q + 1; nxt(r)) { n     nxt(l); n     res -= 1ll * p[l].x * (p[R[r]].x - p[r].x); n   } n   del(u); n   l = r = l0; n   nxt(r, k); n   for (; R[l] < u && r < q + 1; nxt(r)) { n     nxt(l); n     res += 1ll * p[l].x * (p[R[r]].x - p[r].x); n   } n } n int main() { n   scanf( %d%d%d%d , &n, &m, &q, &k); n   for (int i = 1; i <= q; i++) scanf( %d%d , &p[i].x, &p[i].y); n   sort(p + 1, p + q + 1); n   p[q + 1] = (node){n + 1, m + 1}; n   for (int i = 1; i <= q; i++) py[p[i].y].push_back(i); n   long long ans = 0; n   R[q + 1] = q + 1; n   for (int y0 = 1; y0 <= m; y0++) { n     int pr = 0; n     for (int i = 1; i <= q; i++) n       if (p[i].y <= y0) n         L[i] = pr, pr = i; n       else n         L[i] = 0; n     L[q + 1] = pr; n     pr = q + 1; n     for (int i = q; i >= 1; i--) n       if (p[i].y <= y0) n         R[i] = pr, pr = i; n       else n         R[i] = 0; n     R[0] = pr; n     solve(); n     ans += res; n     for (int y = 1; y <= y0; y++) { n       for (int u : py[y]) erase(u); n       ans += res; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct flight { n   int d, f, t, c; n }; n int main() { n   int n, m, k; n   scanf( %d %d %d , &n, &m, &k); n   vector<flight> flights(m); n   for (int i = 0; i < m; i++) { n     scanf( %d %d %d %d , &flights[i].d, &flights[i].f, &flights[i].t, n           &flights[i].c); n   } n   sort(flights.begin(), flights.end(), n        [](const flight &a, const flight &b) { return a.d < b.d; }); n   vector<long long> miniCostTo(n + 1, (1LL << 50)); n   vector<long long> totalTo(1000001, (1LL << 50)); n   vector<bool> haveTo(n + 1); n   int toCounter = 0; n   long long costTo = 0; n   int toIndex = 0; n   for (int i = 0; i <= 1000000; i++) { n     if (toCounter == n) { n       totalTo[i] = costTo; n     } n     while (toIndex < m && flights[toIndex].d == i) { n       flight f = flights[toIndex]; n       if (!f.t) { n         if (miniCostTo[f.f] > f.c) { n           if (miniCostTo[f.f] != (1LL << 50)) costTo -= miniCostTo[f.f] - f.c; n           miniCostTo[f.f] = f.c; n         } n         if (!haveTo[f.f]) { n           haveTo[f.f] = true; n           costTo += f.c; n           toCounter++; n         } n       } n       toIndex++; n     } n   } n   vector<long long> miniCostFrom(n + 1, (1LL << 50)); n   vector<long long> totalFrom(1000001, (1LL << 50)); n   vector<bool> haveFrom(n + 1); n   int fromCounter = 0; n   long long costFrom = 0; n   int fromIndex = m - 1; n   for (int i = 1000000; i >= 0; i--) { n     if (fromCounter == n) { n       totalFrom[i] = costFrom; n     } n     while (fromIndex >= 0 && flights[fromIndex].d == i) { n       flight f = flights[fromIndex]; n       if (!f.f) { n         if (miniCostFrom[f.t] > f.c) { n           if (miniCostFrom[f.t] != (1LL << 50)) n             costFrom -= miniCostFrom[f.t] - f.c; n           miniCostFrom[f.t] = f.c; n         } n         if (!haveFrom[f.t]) { n           haveFrom[f.t] = true; n           costFrom += f.c; n           fromCounter++; n         } n       } n       fromIndex--; n     } n   } n   long long cheapest = (1LL << 50); n   for (int i = 0; i + k - 1 <= 1000000; i++) { n     cheapest = min(cheapest, totalTo[i] + totalFrom[i + k - 1]); n   } n   if (cheapest == (1LL << 50)) n     printf( -1 n ); n   else n     printf( %I64d n , cheapest); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class classcomp { n  public: n   bool operator()(const int &l, const int &r) const { return l < r; } n }; n long long mod = 1000000007; n void matrixmul(int p, int q, int r, long long *a, long long *b, long long *c) { n   int i, j, k; n   for (i = 0; i < p; i++) { n     for (j = 0; j < r; j++) { n       c[i * r + j] = 0; n       for (k = 0; k < q; k++) n         c[i * r + j] = (c[i * r + j] + a[i * q + k] * b[k * r + j]) % mod; n     } n   } n } n void exp(int q, long long *a, long long *c, long long n) { n   int i, j; n   if (n == 0) { n     for (i = 0; i < q; i++) { n       for (j = 0; j < q; j++) c[i * q + j] = 0; n       c[i * q + i] = 1; n     } n     return; n   } n   long long x[q * q]; n   exp(q, a, x, n / 2); n   matrixmul(q, q, q, x, x, c); n   if (n % 2 == 1) { n     memcpy(x, c, sizeof(x)); n     matrixmul(q, q, q, a, x, c); n   } n   return; n } n int main() { n   long long n, m, k; n   cin >> n >> m >> k; n   long long a[m * m]; n   int i, j, l; n   char s[10]; n   for (i = 0; i < m; i++) n     for (j = 0; j < m; j++) a[i * m + j] = 1; n   for (i = 0; i < k; i++) { n     scanf( %s , s); n     if ( a  <= s[0] && s[0] <=  z ) n       j = s[0] -  a ; n     else n       j = s[0] -  A  + 26; n     if ( a  <= s[1] && s[1] <=  z ) n       l = s[1] -  a ; n     else n       l = s[1] -  A  + 26; n     a[l * m + j] = 0; n   } n   long long ans[m * m]; n   exp(m, a, ans, n - 1); n   long long ret = 0; n   for (i = 0; i < m; i++) n     for (j = 0; j < m; j++) { n       ret = (ret + ans[i * m + j]) % mod; n     } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[1010][10], rez[1010]; n int main() { n   int n, nr = 0, l = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int p = 0; n     for (int j = 1; j <= 5; j++) scanf( %d , &v[i][j]); n   } n   if (n > 200) { n     printf( 0 ); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     int p = 0; n     for (int j = 1; j <= n; j++) n       if (i != j) { n         for (int k = 1; k <= n; k++) n           if (j != k && i != k) { n             int c = 0; n             for (int m = 1; m <= 5; m++) n               c += (v[j][m] - v[i][m]) * (v[k][m] - v[i][m]); n             if (c > 0) { n               p = 1; n               break; n             } n           } n         if (p == 1) break; n       } n     if (p == 0) rez[++l] = i; n   } n   printf( %d n , l); n   for (int i = 1; i <= l; i++) printf( %d n , rez[i]); n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 1e5 + 1; n int n, m, l = 1; n long long a; n char s[maxn]; n int main() { n   scanf( %d%d%s , &n, &m, s + 1); n   for (int i = 1; i <= n; i++) n     if (s[i] != s[i - 1]) a += n * (m - 1); n   for (int i = 2; i <= n; i++) n     if (l == 1 && s[i] != s[i - 1] || l > 1 && s[i] == s[i - 2]) n       ++l; n     else if (a -= 1ll * l * (l - 1) >> 1) n       l = 1 + (s[i] != s[i - 1]); n   printf( %lld n , a -= 1ll * l * (l - 1) >> 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using vi = vector<int>; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   cin >> t; n   vi v(t); n   for (int i = 0; i < t; i++) { n     cin >> v[i]; n   } n   int m = t; n   priority_queue<int> qi; n   for (int i = 0; i < t; i++) { n     if (v[i] == m) { n       m--; n       cout << v[i] <<    ; n       while (!qi.empty() && (qi.top() == m)) { n         m--; n         cout << qi.top() <<    ; n         qi.pop(); n       } n     } else n       qi.push(v[i]); n     cout <<   n ; n   } n   cerr <<   ntime taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int s, v1, v2, p1, p2; n   scanf( %d%d%d%d%d , &s, &v1, &v2, &p1, &p2); n   if (v1 * s + p1 * 2 < v2 * s + p2 * 2) printf( First n ); n   if (v1 * s + p1 * 2 > v2 * s + p2 * 2) printf( Second n ); n   if (v1 * s + p1 * 2 == v2 * s + p2 * 2) printf( Friendship n ); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int N = 10; n int n, k; n int a[1005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   int nn = n; n   for (int i = 0; i < k; i++) { n     cin >> a[i]; n     while (a[i] >= 4 && nn > 0) { n       a[i] -= 4; n       nn--; n     } n   } n   int n2 = n * 2 + nn; n   for (int i = 0; i < k; i++) { n     while (a[i] >= 2 && n2 > 0) { n       a[i] -= 2; n       n2--; n     } n   } n   int sum = 0; n   for (int i = 0; i < k; i++) { n     sum += a[i]; n   } n   if (sum > nn + n2) { n     cout <<  NO  << endl; n   } else { n     cout <<  YES  << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<long long int> v(n); n     for (long long int &x : v) cin >> x; n     for (int i = 0; i < n; i++) { n       if (i % 2) n         v[i] = -abs(v[i]); n       else n         v[i] = abs(v[i]); n       cout << v[i] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char c[100005]; n   scanf( %s , c); n   vector<char> v; n   int count[26]; n   int instk[26]; n   memset(count, 0, sizeof(count)); n   memset(instk, 0, sizeof(instk)); n   int find = 0; n   for (int i = 0; c[i] != 0; i++) count[c[i] -  a ]++; n   while (count[find] == 0) find++; n   for (int i = 0; c[i] != 0; i++) { n     v.push_back(c[i]); n     count[c[i] -  a ]--; n     while (count[find] == 0) find++; n     while (!v.empty() && v.back() -  a  <= find) { n       printf( %c , v.back()); n       v.pop_back(); n     } n   } n   while (!v.empty()) { n     printf( %c , v.back()); n     v.pop_back(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     long long a, b, x, y; n     cin >> a >> b >> x >> y; n     long long distX = x - a, distY = y - b; n     cout << distX * distY + 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n int n, m; n int id[N * 2][N * 2]; n map<int, int> mp; n vector<int> l[N * 2], e[N * 2]; n vector<int> ord; n pair<int, int> a[N]; n int dp[N * 2][N * 2]; n pair<int, int> DP[N * 2][N * 2]; n void type(int i, int j) { n   if (DP[i][j].second == 0) { n     if (i != 0) printf( %d  , i); n     return; n   } n   if (DP[i][j].first) { n     type(i, a[DP[i][j].second].first); n     type(DP[i][j].second, a[DP[i][j].second].second); n   } else n     type(i, DP[i][j].second); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     a[i] = make_pair(x - y, x + y); n     mp[x - y] = 1; n     mp[x + y] = 1; n   } n   for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) n     it->second = ++m; n   for (int i = 1; i <= n; i++) { n     a[i] = make_pair(mp[a[i].first], mp[a[i].second]); n     id[a[i].first][a[i].second] = i; n     e[a[i].second].push_back(i); n     l[a[i].second - a[i].first + 1].push_back(i); n   } n   a[0] = make_pair(1, m); n   l[m].push_back(0); n   for (int _ = 1; _ <= m; _++) n     for (int __ = 0; __ < l[_].size(); __++) { n       int i = l[_][__]; n       for (int j = a[i].first; j <= a[i].second; j++) { n         dp[i][j] = dp[i][j - 1]; n         DP[i][j] = make_pair(0, j - 1); n         for (int k = 0; k < e[j].size(); k++) { n           int p = e[j][k]; n           if (a[p].first >= a[i].first && n               dp[i][j] < dp[i][a[p].first] + dp[p][a[p].second]) { n             dp[i][j] = dp[i][a[p].first] + dp[p][a[p].second]; n             DP[i][j] = make_pair(1, p); n           } n         } n       } n       for (int j = a[i].first; j <= a[i].second; j++) dp[i][j]++; n     } n   printf( %d n , dp[0][m] - 1); n   type(0, m); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n const long long mod = 998244353; n long long ksm(long long a, long long b) { n   long long ans = 1LL; n   while (b) { n     if (b & 1) ans = ans * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return ans; n } n int a[N], c[N], tmp[N], ans, tot; n bool vis[N]; n bool judge(int x, int y) { n   for (int i = 1; i <= x; i++) { n     int t = i; n     bool flag = 0; n     for (int j = 1; j <= y; j++) { n       if (c[tmp[t]] != c[tmp[i]]) { n         flag = 1; n         break; n       } n       t = (t + x - 1) % tot + 1; n     } n     if (!flag) return 1; n   } n   return 0; n } n void dfs(int x) { n   tot = 0; n   tmp[++tot] = x; n   vis[x] = 1; n   for (int i = a[x]; i != x; i = a[i]) tmp[++tot] = i, vis[i] = 1; n   for (int i = 1; i * i <= tot; i++) { n     if (tot % i == 0) { n       if (judge(i, tot / i)) { n         ans = min(ans, i); n         return; n       } n       if (judge(tot / i, i)) ans = min(ans, tot / i); n     } n   } n } n void solve() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &c[i]); n   ans = INT_MAX; n   for (int i = 1; i <= n; i++) n     if (!vis[i]) dfs(i); n   for (int i = 1; i <= n; i++) vis[i] = 0; n   printf( %d n , ans); n } n int main() { n   int _; n   scanf( %d , &_); n   while (_--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> dvsr; n void get(long long n) { n   for (int i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       dvsr.push_back(i); n       if (i != n / i) dvsr.push_back(n / i); n     } n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long a, b; n   cin >> a >> b; n   if (a == b) { n     cout << 0; n     return 0; n   } n   if (a > b) swap(a, b); n   long long df = b - a; n   get(df); n   set<pair<long long, long long> > s; n   for (auto it : dvsr) { n     if (a % it == 0 and b % it == 0) { n       s.insert({(a * b) / it, 0}); n     } else { n       long long dif = it * (b / it + 1) - b; n       long long x = a + dif, y = b + dif; n       s.insert({(x * y) / it, dif}); n     } n   } n   long long ans = b; n   auto i1 = s.begin(); n   cout << i1->second; n } n


#include<bits/stdc++.h> n using namespace std; n #define int long long n #define fast_io ios_base::sync_with_stdio(0);cin.tie(0)  n #define mod 1e9 + 7 n #define pb push_back n #define vi vector<int> n  n int32_t main(){ n     fast_io; n     int t;cin>>t; n     while(t--){ n         int n;cin>>n; n         set<int> s; n         vi arr(n); n         for(int i=0;i<n;i++){ n             int x;cin>>x; n             arr[i] = x; n             s.insert(x); n         } n         sort(arr.rbegin(),arr.rend()); n         int z = arr[n-1]; n         int ans = 0; n         for(int i=0;i<n;i++){ n             if(arr[i]!=z){ n                 ans++; n             } n         } n         cout<<ans<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string str; n   cin >> str; n   set<char> a; n   for (int i = 0; i < n; i++) { n     a.insert(tolower(str[i])); n   } n   if (a.size() == 26) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int h, m; n   cin >> h >> m; n   long long int t = h * 60 + m; n   long long int a = 1440 - t; n   cout << a << endl; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   long long int t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2010; n int T, n, m, vis[maxn], cnt[maxn]; n char s[maxn]; n bitset<maxn> b[maxn]; n queue<pair<int, int>> Q; n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d %d , &n, &m); n     for (int i = 1; i <= n; i++) { n       b[i].reset(), vis[i] = 0; n     } n     for (int i = 1; i <= m; i++) { n       scanf( %s , s + 1), cnt[i] = 0; n       for (int j = 1; j <= n; j++) { n         if (s[j] ==  1 ) cnt[i]++; n       } n       if (cnt[i] == 1) continue; n       for (int j = 1; j <= n; j++) { n         if (s[j] ==  1 ) b[j].set(i); n       } n     } n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) n         if (i ^ j) { n           if ((b[i] & b[j]) == b[i]) Q.emplace(i, j); n         } n     } n     vector<pair<int, int>> E; n     while (!Q.empty()) { n       int u = Q.front().first, v = Q.front().second; n       Q.pop(); n       if (vis[u] || vis[v]) continue; n       vis[u] = 1, E.emplace_back(u, v); n       for (int i = 1; i <= m; i++) { n         if (b[u][i]) cnt[i]--; n       } n       for (int i = 1; i <= m; i++) n         if (cnt[i] == 1) { n           cnt[i] = 0; n           for (int j = 1; j <= n; j++) n             if (b[j][i] && !vis[j]) { n               b[j][i] = 0; n               for (int k = 1; k <= n; k++) n                 if (j ^ k && !vis[k]) { n                   if ((b[j] & b[k]) == b[j]) Q.emplace(j, k); n                 } n             } n         } n     } n     if (E.size() < n - 1) { n       puts( NO ); n       continue; n     } n     puts( YES ); n     for (auto p : E) { n       printf( %d %d n , p.first, p.second); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = (int)1e9 + 9; n bool cmp(const pair<int, int> &a, const pair<int, int> &b) { n   return a.first < b.first; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<pair<int, int> > k(n); n   for (int(i) = (0); (i) < (n); ++(i)) { n     cin >> k[i].first >> k[i].second; n   } n   sort(((k).begin()), ((k).end()), cmp); n   double ans = oo; n   for (int(i) = (0); (i) < (n); ++(i)) { n     ans = min(ans, (double)k[i].first / (double)k[i].second); n   } n   ans *= (double)m; n   cout << fixed << setprecision(8) << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1000 * 1000 * 1000; n const long long inf64 = 1ll * inf * inf; n const long long mod = 1e9 + 7; n mt19937 rng(0); n long long binpow(long long a, long long p, long long mod = 998244353) { n   if (p == 0) return 1; n   if (p % 2 == 0) { n     long long t = binpow(a, p / 2); n     return t * t % mod; n   } else { n     return binpow(a, p - 1) * a % mod; n   } n } n long long invert(long long x) { return binpow(x, 998244351); } n pair<long long, long long> add(pair<long long, long long> a, n                                pair<long long, long long> b) { n   pair<long long, long long> ans; n   ans.first = a.first * b.second + b.first * a.second; n   ans.second = a.second * b.second; n   ans.first %= 998244353; n   ans.second %= 998244353; n   return ans; n } n pair<long long, long long> multi(pair<long long, long long> a, n                                  pair<long long, long long> b) { n   return {a.first * b.first % 998244353, a.second * b.second % 998244353}; n } n void run() { n   long long n; n   cin >> n; n   vector<vector<long long>> a(n); n   vector<vector<long long>> poses(1e6 + 10); n   for (long long i = 0; i < n; i++) { n     long long k; n     cin >> k; n     a[i].resize(k); n     for (long long j = 0; j < k; j++) { n       cin >> a[i][j]; n       poses[a[i][j]].push_back(i); n     } n   } n   pair<long long, long long> ans = {0, 1}; n   for (long long i = 0; i < n; ++i) { n     pair<long long, long long> t = {1, n}; n     for (long long k = 0; k < a[i].size(); ++k) { n       pair<long long, long long> r = {1, a[i].size()}; n       pair<long long, long long> e = {poses[a[i][k]].size(), n}; n       ans = add(ans, multi(multi(t, r), e)); n     } n   } n   cout << ans.first * invert(ans.second) % 998244353; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   for (long long i = 0; i < t; i++) { n     run(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> X; n map<long long, pair<int, long long> > M; n pair<int, long long> go(long long x) { n   if (x <= 1) return {x, x}; n   if (M.find(x) != M.end()) return M[x]; n   int i = upper_bound(X.begin(), X.end(), x) - X.begin() - 1; n   int p1, p2; n   long long q1, q2; n   pair<int, long long> P1; n   P1 = go(x - X[i]); n   p1 = P1.first; n   q1 = P1.second; n   P1 = go(X[i] - 1); n   p2 = P1.first; n   q2 = P1.second; n   return M[x] = max(make_pair(p1 + 1, q1 + X[i]), {p2, q2}); n } n int main() { n   for (int i = 0; i <= 1e5 + 7; ++i) X.push_back(1LL * i * i * i); n   long long x; n   cin >> x; n   pair<int, long long> Ans; n   Ans = go(x); n   cout << Ans.first <<     << Ans.second <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1000000007; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n; n   cin >> n; n   if (n == 1) { n     cout << 2; n     return 0; n   } n   if (n == 2) { n     cout << 3; n     return 0; n   } n   long long int curr = 2, line = 3, to = 2; n   while (to < n) { n     line++; n     to += curr; n     if (to >= n) { n       cout << line; n       return 0; n     } n     line++; n     to += (curr); n     curr++; n     if (to >= n) { n       cout << line; n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x1, y1, z, x, y; n   cin >> x1 >> y1 >> z; n   x = x1 - y1 + z; n   y = x1 - y1 - z; n   if (x > 0 && y > 0) n     cout <<  +  n          <<   n ; n   else if (x < 0 && y < 0) n     cout <<  -  n          <<   n ; n   else if (x == 0 && y == 0) n     cout <<  0  n          <<   n ; n   else n     cout <<  ?  n          <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10, lgN = 29, INF = 2e9; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n struct segTree { n   struct node { n     int l, r, w, flg; n   } sgt[N * lgN]; n   int p = 0, rt[N] = {0}; n   void insert(int &i, int b, int e, int k, int x) { n     sgt[++p] = sgt[i]; n     i = p; n     if (b == e) { n       sgt[i].w = sgt[i].w ? min(sgt[i].w, x) : x; n       return; n     } n     int mid = (b + e) >> 1; n     if (k <= mid) n       insert(sgt[i].l, b, mid, k, x); n     else n       insert(sgt[i].r, mid + 1, e, k, x); n     sgt[i].w = max(sgt[sgt[i].l].w, sgt[sgt[i].r].w); n   } n   int query(int i, int b, int e, int l, int r) { n     if (e < l || r < b) return 0; n     if (i == 0) return INF; n     if (l <= b && e <= r) return sgt[i].w; n     int mid = (b + e) >> 1, lc = sgt[i].l, rc = sgt[i].r; n     return max(query(lc, b, mid, l, r), query(rc, mid + 1, e, l, r)); n   } n   void walk(int i, int b, int e, int dep) { n     if (!i) return; n     int mid = (b + e) >> 1, lc = sgt[i].l, rc = sgt[i].r; n     if (b != e) walk(lc, b, mid, dep + 1); n     for (int i = 0; i < dep; i++) printf(    ); n     printf( %d[%d,%d]w=%d n , i, b, e, sgt[i].w); n     if (b != e) walk(rc, mid + 1, e, dep + 1); n   } n } t; n struct seg { n   int l, r, p; n } a[N]; n bool comp(seg a, seg b) { return a.l < b.l; } n int n, m, k, rt[N]; n int bin(int x) { n   int l = 1, r = k, ret = -1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (a[mid].l >= x) n       ret = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   return ret; n } n int main() { n   n = read(); n   m = read(); n   k = read(); n   for (int i = 1; i <= k; i++) { n     a[i].l = read(); n     a[i].r = read(); n     a[i].p = read(); n   } n   sort(a + 1, a + k + 1, comp); n   t.sgt[0].w = INF; n   for (int i = k; i; i--) { n     rt[i] = rt[i + 1]; n     t.insert(rt[i], 1, n, a[i].p, a[i].r); n   } n   for (int i = 1; i <= m; i++) { n     int a = read(), b = read(), x = read(), y = read(); n     int lb = bin(x); n     if (lb == -1 || t.query(rt[lb], 1, n, a, b) > y) n       printf( no n ); n     else n       printf( yes n ); n     fflush(stdout); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long N, K; n long long Top, Bot, H[200005], cnt[200005]; n long long hcnt[200005]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> N >> K; n   Top = 0, Bot = 2e5; n   for (int i = 0; i <= N - 1; i++) { n     cin >> H[i]; n     cnt[H[i]]++; n     Top = max(Top, H[i]); n     Bot = min(Bot, H[i]); n   } n   long long curc = 0; n   for (int i = Top; i >= 1; i--) { n     curc += cnt[i]; n     hcnt[i] += curc; n   } n   long long cutt = 0; n   int ans = 0; n   for (int i = Top; i >= Bot + 1; i--) { n     if (cutt + hcnt[i] > K) { n       ans++; n       cutt = hcnt[i]; n     } else n       cutt += hcnt[i]; n   } n   if (cutt) ans++; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long n, l, r; n   cin >> n; n   while (n-- && cin >> l >> r) { n     if (l * 2 > r) n       cout <<  YES ; n     else n       cout <<  NO ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   cin >> n; n   long long a = (n + 2) * (n + 1) * n / 6, n             b = (n + 4) * (n + 3) * (n + 2) * (n + 1) * n / 120; n   cout << a * b; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1005, maxk = 12; n string s, t; n long long d[maxn][maxn][maxk][2]; n long long n, m, k; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m >> k >> s >> t; n   for (long long i = 0; i <= n; i++) { n     for (long long j = 0; j <= m; j++) { n       for (long long z = 0; z <= k; z++) { n         long long temp = max(d[i][j][z][0], d[i][j][z][1]); n         d[i + 1][j][z][0] = max(d[i + 1][j][z][0], temp); n         d[i][j + 1][z][0] = max(d[i][j + 1][z][0], temp); n         if (s[i] == t[j]) { n           d[i + 1][j + 1][z + 1][1] = n               max(d[i + 1][j + 1][z + 1][1], d[i][j][z][0] + 1); n           if (z > 0) { n             d[i + 1][j + 1][z][1] = n                 max(d[i + 1][j + 1][z][1], d[i][j][z][1] + 1); n           } n         } n       } n     } n   } n   cout << *max_element(d[n][m][0], d[n][m][k] + 2) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long int n, i, m, k, x, pc = 0, c = 0; n   cin >> n >> m >> k; n   long long int p, f; n   queue<long long int> q; n   for (i = 0; i < m; i++) { n     cin >> x; n     q.push(x - 1); n   } n   x = 0; n   while (!q.empty()) { n     f = q.front(); n     p = (f - c) / k; n     while (!q.empty() && ((q.front() - c) / k) == p) { n       pc++; n       q.pop(); n     } n     c = pc; n     x++; n   } n   cout << x; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b, ed; n double p, M; n long long T; n vector<pair<double, double> > v; n pair<double, double> sta[100004]; n double cros(pair<double, double> a, pair<double, double> b) { n   return (b.second - a.second) / (a.first - b.first); n } n double r[100004], ret; n double mat[35][3][3], cur[3]; n int main() { n   scanf( %d%I64d , &n, &T); n   for (int i = 0; i < n; i++) { n     scanf( %d%d%lf , &a, &b, &p); n     M = max(M, p * b); n     v.push_back(make_pair(p, -p * a)); n   } n   sort(v.begin(), v.end()); n   for (int i = 0; i < n; i++) { n     if (i > 0 && v[i].first == v[i - 1].first) continue; n     v[i].second *= -1; n     while (ed > 1 && cros(sta[ed - 1], sta[ed]) > cros(sta[ed], v[i])) ed--; n     sta[++ed] = v[i]; n   } n   for (int i = 1; i < ed; i++) r[i] = cros(sta[i], sta[i + 1]); n   r[ed] = 1e18 + 114; n   double lst = 0; n   long long t1 = 0; n   for (int i = 1; i <= ed; i++) { n     if (t1 == T || (t1 * M - lst) >= r[i]) continue; n     mat[0][0][0] = 1 - sta[i].first, mat[0][0][1] = 0, mat[0][0][2] = 0; n     mat[0][1][0] = sta[i].first * M, mat[0][1][1] = 1, mat[0][1][2] = 0; n     mat[0][2][0] = sta[i].second, mat[0][2][1] = 1, mat[0][2][2] = 1; n     for (int j = 1; j <= 33; j++) { n       for (int i1 = 0; i1 < 3; i1++) n         for (int j1 = 0; j1 < 3; j1++) { n           mat[j][i1][j1] = 0; n           for (int k = 0; k < 3; k++) n             mat[j][i1][j1] += mat[j - 1][i1][k] * mat[j - 1][k][j1]; n         } n     } n     for (int j = 33; j >= 0; j--) { n       if (t1 + (1ll << j) >= T) continue; n       cur[0] = lst, cur[1] = t1, cur[2] = 1; n       ret = 0; n       for (int k = 0; k < 3; k++) ret += cur[k] * mat[j][k][0]; n       if (M * (t1 + (1ll << j)) - ret < r[i]) lst = ret, t1 += (1ll << j); n     } n     cur[0] = lst, cur[1] = t1, cur[2] = 1; n     lst = 0; n     for (int j = 0; j < 3; j++) lst += cur[j] * mat[0][j][0]; n     t1++; n   } n   printf( %.6lf , lst); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string s; n   cin >> s; n   string ans; n   ans += s[0]; n   for (int i = 1; i <= s.length() - 2; i = i + 2) { n     ans += s[i]; n   } n   ans += s[s.length() - 1]; n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long test; n   cin >> test; n   while (test--) { n     solve(); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[101], t = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     t += a[i]; n   } n   int ans = 0; n   for (int j = 1; j <= 5; j++) { n     int k = t + j, i = 0; n     while (k) { n       k--; n       if (!k) break; n       i = ((i + 1) % (n + 1)); n     } n     if (i != 0) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   map<int, vector<int>> frec; n   for (int i = 0; i < n; i++) { n     int val; n     cin >> val; n     frec[val].push_back(i); n   } n   int x = 0; n   vector<int> ans(n); n   for (int i = 0; i < n; i++) { n     while (frec[x].empty() && x >= 3) x -= 3; n     if (frec[x].empty()) { n       cout <<  Impossible n ; n       return 0; n     } n     ans[i] = frec[x].back() + 1; n     frec[x].pop_back(); n     x++; n   } n   cout <<  Possible n ; n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MM = 2e5 + 5; n int n, k, a, b, q, pref[MM], suff[MM], cnt[MM]; n void upd(int bit[], int x, int v) { n   for (; x < MM; x += x & -x) { n     bit[x] += v; n   } n } n int get(int bit[], int x) { n   int res = 0; n   for (; x > 0; x -= x & -x) res += bit[x]; n   return res; n } n int get(int bit[], int l, int r) { return get(bit, r) - get(bit, l - 1); } n int main() { n   cin.tie(0)->sync_with_stdio(0); n   cin >> n >> k >> a >> b >> q; n   while (q--) { n     int t; n     cin >> t; n     if (t == 1) { n       int x, v; n       cin >> x >> v; n       int val = min(b, v + cnt[x]); n       int diff = val - get(pref, x, x); n       upd(pref, x, diff); n       val = min(a, v + cnt[x]); n       diff = val - get(suff, x, x); n       upd(suff, x, diff); n       cnt[x] += v; n     } else { n       int p; n       cin >> p; n       int ans = get(pref, p - 1); n       ans += get(suff, p + k, MM - 1); n       cout << ans <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e+5 + 10; n long long b[MAXN], l[MAXN], r[MAXN], o[MAXN], dp[MAXN]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     cin >> b[i]; n   } n   for (int i = 1; i < n; i++) { n     l[i] = b[i - 1] - (b[i - 1] % 2) + l[i - 1]; n     if (b[i - 1] == 1) l[i] = 0; n   } n   for (int i = n - 2; i > -1; i--) { n     r[i] = b[i] - (b[i] % 2) + r[i + 1]; n     if (b[i] == 1) r[i] = 0; n   } n   for (int i = 1; i < n; i++) { n     o[i] = o[i - 1] + b[i - 1] - (b[i - 1] % 2 == 0); n   } n   long long ans = 0, m = 0; n   for (int i = 0; i < n; i++) { n     m = max(m, l[i] - o[i]); n     ans = max(ans, r[i] + o[i] + m); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int64_t t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n vector<vector<int64_t>> to; n vector<bool> bobCan, parcouru; n vector<int64_t> pId; n int64_t nbPar; n int64_t da, db, goal; n void dfsBob(int64_t n, int64_t dist) { n   if (bobCan[n]) return; n   bobCan[n] = true; n   goal++; n   if (dist == 0) return; n   for (int64_t &i : to[n]) dfsBob(i, dist - 1); n } n int64_t dfs2(int64_t n, int64_t dist, int64_t id) { n   if (pId[n] == id) return 0; n   pId[n] = id; n   int64_t score = 0; n   if (bobCan[n]) score = 1; n   if (dist == 0) return score; n   for (int64_t &i : to[n]) score += dfs2(i, dist - 1, id); n   return score; n } n bool dfs1(int64_t n, int64_t dist) { n   if (parcouru[n]) return false; n   parcouru[n] = true; n   if (dfs2(n, da, nbPar++) == goal) return true; n   if (dist == 0) return false; n   for (int64_t &i : to[n]) n     if (dfs1(i, dist - 1)) return true; n   return false; n } n bool recherche(int64_t n, int64_t dist, int64_t m) { n   if (parcouru[n]) return false; n   parcouru[n] = true; n   if (n == m) return true; n   if (dist == 0) return false; n   for (int64_t &i : to[n]) n     if (recherche(i, dist - 1, m)) return true; n   return false; n } n void solve() { n   int64_t n, a, b; n   cin >> n >> a >> b >> da >> db; n   to = vector<vector<int64_t>>(n + 1); n   bobCan = parcouru = vector<bool>(n + 1); n   for (int64_t i = 0; i < n - 1; i++) { n     pair<int64_t, int64_t> input; n     cin >> input.first >> input.second; n     to[input.first].push_back(input.second); n     to[input.second].push_back(input.first); n   } n   if (db <= 2 * da) { n     cout <<  Alice n ; n     return; n   } n   if (recherche(a, da, b)) { n     cout <<  Alice n ; n     return; n   } n   parcouru = vector<bool>(n + 1); n   goal = 0; n   dfsBob(b, db); n   parcouru = vector<bool>(n + 1); n   pId = vector<int64_t>(n + 1); n   nbPar = 1; n   if (dfs1(n, da)) { n     cout <<  Alice n ; n     return; n   } n   { n     cout <<  Bob n ; n     return; n   } n   return; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1e9 + 7; n long long int mul(long long int x, long long int y) { n   return (x * 1ll * y) % mod; n } n long long int add(long long int x, long long int y) { n   x += y; n   while (x >= mod) x -= mod; n   while (x < 0) x += mod; n   return x; n } n long long int dp[200005][3]; n long long int a, b, c; n long long int n, l, r; n long long int fun(int i, int j) { n   if (i == n) { n     if (j == 0) n       return 1; n     else n       return 0; n   } n   if (dp[i][j] != -1) return dp[i][j]; n   dp[i][j] = add( n       mul(a, fun(i + 1, (j) % 3)), n       add(mul(b, fun(i + 1, (j + 1) % 3)), mul(c, fun(i + 1, (j + 2) % 3)))); n   return dp[i][j]; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n >> l >> r; n   long long int x = (l - 1 + 2) / 3; n   long long int y = (r - 1) / 3; n   b = y - x + 1; n   x = (l - 2 + 2) / 3; n   y = (r - 2) / 3; n   c = y - x + 1; n   x = (l + 2) / 3; n   y = (r) / 3; n   a = y - x + 1; n   if (l == 1 && r == 1) { n     a = 0, b = 1, c = 0; n   } n   memset(dp, -1, sizeof(dp)); n   long long int ans = 0; n   ans = add(ans, mul(a, fun(1, 0))); n   ans = add(ans, mul(b, fun(1, 1))); n   ans = add(ans, mul(c, fun(1, 2))); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   char c =  a ; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  z  + 1) n       continue; n     else if (s[i] != c) { n       cout <<  NO n ; n       return 0; n     } else { n       for (int j = i; j < s.size(); j++) { n         if (s[j] == c) s[j] =  z  + 1; n       } n       c++; n     } n   } n   cout <<  YES n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long max_n = 1e6 + 20; n long long n, m, k, ans, sum; n long long a[max_n]; n long long mark[max_n]; n vector<long long> v, adj[max_n], jda[max_n]; n void dfs(long long v) { n   mark[v] = 1; n   if (adj[v].size() == 2) ans = -1; n   for (auto i : adj[v]) { n     if (!mark[i]) { n       dfs(i); n     } n   } n } n int32_t main() { n   cin >> n; n   for (long long i = 1; i < n; i++) { n     long long u, v; n     cin >> u >> v; n     u--, v--; n     adj[v].push_back(u); n     adj[u].push_back(v); n   } n   if (n == 2) { n     cout <<  YES ; n     return 0; n   } n   for (long long i = 0; i < n; i++) { n     if (adj[i].size() == 1 && !mark[i]) dfs(i); n   } n   if (ans == -1) { n     cout <<  NO ; n   } else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[111111], ans[111111]; n int n, kk; n int main() { n   scanf( %d , &n); n   for (int i = (1); i <= (n); ++i) scanf( %I64d , &a[i]); n   sort(a + 1, a + n + 1); n   reverse(a + 1, a + n + 1); n   for (int i = (1); i <= (n); ++i) a[i] += a[i - 1]; n   scanf( %d , &kk); n   for (int t = (0); t < (kk); ++t) { n     int k; n     scanf( %d , &k); n     k = (k > n - 1) ? n - 1 : k; n     if (!ans[k]) { n       long long l, r, st, tmp; n       l = r = tmp = 1; n       st = 0; n       while (l <= n) { n         ans[k] += (a[r] - a[l - 1]) * st; n         tmp *= k; n         ++st; n         l = r + 1; n         r += tmp; n         r = (r > n) ? n : r; n       } n     } n     printf( %I64d  , ans[k]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   unsigned long long no_of_paths; n   unsigned long long no_of_arrangements; n   scanf( %I64u , &no_of_paths); n   no_of_arrangements = (no_of_paths) * (no_of_paths - 1) / 2 * n                        (no_of_paths - 2) / 3 * (no_of_paths - 3) / 4 * n                        (no_of_paths - 4) / 5; n   no_of_arrangements *= (no_of_paths) * (no_of_paths - 1) * (no_of_paths - 2) * n                         (no_of_paths - 3) * (no_of_paths - 4); n   printf( %I64u n , no_of_arrangements); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, mod = 1, cnt = 0, i, min; n   cin >> n; n   vector<int> v{1, 5, 10, 20, 100}; n   while (n) { n     min = INT_MAX; n     for (i = 0; i < 5; ++i) { n       if (n / v[i] >= 1) { n         if (min > n / v[i]) { n           min = n / v[i]; n           mod = n % v[i]; n         } n       } n     } n     cnt += min; n     n = mod; n   } n   cout << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n int t = 1000001; n class myData { n  public: n   int t; n   int x; n   int y; n   int d; n   myData(int t, int x, int y, int d) : t(t), x(x), y(y), d(d) {} n   bool operator<(const myData &a) const { return (this->t < a.t); } n }; n long long exponentMod(long long A, long long B, long long C) { n   if (A == 0) return 0; n   if (B == 0) return 1; n   long long y; n   if (B % 2 == 0) { n     y = exponentMod(A, B / 2, C); n     y = (y * y) % C; n   } else { n     y = A % C; n     y = (y * exponentMod(A, B - 1, C) % C) % C; n   } n   return (long long)((y + C) % C); n } n pair<int, int> factorize(long long n) { n   int ans = 1; n   int c = 0; n   for (long long i = 2; i * i <= n; ++i) { n     while (n % i == 0) { n       if (i != 2) ans *= i, c++; n       n /= i; n     } n   } n   if (n != 1) { n     if (n != 2) ans *= n, c++; n   } n   return {ans, c}; n } n map<long long, long long> bit; n int N1 = 2e5; n void update(long long i) { n   for (; i <= N1; i += i & (-i)) bit[i]++; n } n long long get(long long i) { n   long long ans = 0; n   for (; i > 0; i -= i & (-i)) ans += bit[i]; n   return ans; n } n int now; n bool sortByVal(const myData &a, const myData &b) { return (a.t < b.t); } n long long ans1 = 0; n int spf[1000003]; n long long calc[1000003 + 1]; n long long nCk(long long n, long long k, long long mod) { n   return ((((calc[n] % mod) * exponentMod(calc[k], mod - 2, mod)) % mod) * n           exponentMod(calc[n - k], mod - 2, mod)) % n          mod; n } n void sieve() { n   spf[1] = 1; n   for (int i = 2; i < 1000003; i++) spf[i] = i; n   for (int i = 4; i < 1000003; i += 2) spf[i] = 2; n   for (int i = 3; i * i < 1000003; i++) { n     if (spf[i] == i) { n       for (int j = i * i; j < 1000003; j += i) n         if (spf[j] == j) spf[j] = i; n     } n   } n } n set<int> getFactorization(int x) { n   set<int> ret; n   while (x != 1) { n     ret.insert(spf[x]); n     x = x / spf[x]; n   } n   return ret; n } n bool prime[1000003 + 1]; n void sieve2() { n   memset(prime, true, sizeof(prime)); n   for (int p = 2; p * p <= 1000003; p++) { n     if (prime[p] == true) { n       for (int i = p * p; i <= 1000003; i += p) prime[i] = false; n     } n   } n } n int MEX(int a[], int n) { n   set<int> s; n   for (int i = 0; i < n; i++) { n     s.insert(a[i]); n   } n   int c = 0; n   for (auto i = s.begin(); i != s.end(); i++) { n     if (*i == c) { n       c++; n     } else n       break; n   } n   return c; n } n int smallestDivisor(int n) { n   if (n % 2 == 0) return 2; n   for (int i = 3; i * i <= n; i += 2) { n     if (n % i == 0) return i; n   } n   return n; n } n map<int, pair<int, int>> m; n const int maxn = 3e3 + 110; n const int mod = 1e9 + 7; n int dp[maxn][310]; n int a[310], b[310]; n int main() { n   int l, n, x, y, ans = 0; n   cin >> n >> l; n   for (int i = 1; i <= n; i++) { n     cin >> a[i] >> b[i]; n     dp[a[i]][i]++; n     if (a[i] != b[i]) { n       a[i + n] = b[i]; n       b[i + n] = a[i]; n       dp[a[i + n]][i + n]++; n     } n   } n   for (int i = 1; i <= l; i++) { n     for (int j = 1; j <= n * 2; j++) { n       if (!dp[i][j]) continue; n       for (int k = 1; k <= n * 2; k++) { n         if ((j % n) != (k % n) && b[j] == a[k]) n           dp[i + a[k]][k] = (dp[i + a[k]][k] + dp[i][j]) % mod; n       } n     } n   } n   for (int i = 1; i <= 2 * n; i++) ans = (ans + dp[l][i]) % mod; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long T, m, n, q, w, mi, ma, cnt, s, t, fi, cc, e, r, z, x, an, anx, any, n     cx, cy; n long long d[5][2]; n int main() { n   scanf( %I64d%I64d , &m, &n); n   scanf( %I64d%I64d , &e, &r); n   scanf( %I64d%I64d , &cx, &cy); n   for (int i = 0; i < 4; i++) { n     q = e; n     w = r; n     d[i][0] = e - m; n     d[i][1] = r - n; n     e = -w; n     r = q; n   } n   fi = 0; n   for (int i = 0; i < 4; i++) { n     if (d[i][0] == 0 && d[i][1] == 0) { n       fi = 1; n       break; n     } n     if (cx == 0 && cy == 0) continue; n     if ((d[i][1] * cx - d[i][0] * cy) % (cx * cx + cy * cy) == 0) n       if ((d[i][0] * cx + d[i][1] * cy) % (cx * cx + cy * cy) == 0) { n         fi = 1; n         break; n       } n   } n   if (fi == 1) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class sparse_table { n   vector<int> values; n   vector<int> maxk; n   vector<vector<int> > st; n   void build(const vector<int>& a) { n     values = a; n     int n = a.size(); n     st.resize(maxk[n] + 1); n     st[0].resize(n); n     for (int i = 0; i < n; i++) st[0][i] = i; n     for (int i = 1; i <= maxk[n]; i++) { n       st[i].resize(n - (1 << i) + 1); n       for (int j = 0; j < (int)st[i].size(); j++) { n         if (values[st[i - 1][j]] < values[st[i - 1][j + (1 << (i - 1))]]) n           st[i][j] = st[i - 1][j]; n         else n           st[i][j] = st[i - 1][j + (1 << (i - 1))]; n       } n     } n   } n  n  public: n   sparse_table(const vector<int>& vec) { n     int n = vec.size(); n     maxk.resize(n + 1, 0); n     for (int i = 2; i < n + 1; i++) maxk[i] = maxk[i / 2] + 1; n     build(vec); n   } n   sparse_table() {} n   int get(int l, int r) { n     if (values[st[maxk[r - l]][l]] < n         values[st[maxk[r - l]][r - (1 << maxk[r - l])]]) n       return st[maxk[r - l]][l]; n     else n       return st[maxk[r - l]][r - (1 << maxk[r - l])]; n   } n }; n int n; n vector<vector<int> > graph; n vector<int> vec; n vector<int> height; n vector<int> first; n vector<int> tin, tout, parent; n int cur_time = 0; n void dfs(int u, int par, int hg) { n   height[u] = hg; n   vec.push_back(u); n   first[u] = vec.size() - 1; n   tin[u] = cur_time++; n   parent[u] = par; n   for (int v : graph[u]) n     if (v != par) { n       vec.push_back(u); n       dfs(v, u, hg + 1); n     } n   tout[u] = cur_time++; n } n sparse_table st; n void precalc_lca() { n   vec.clear(); n   height.clear(); n   first.clear(); n   height.resize(n); n   first.resize(n); n   tin.resize(n); n   tout.resize(n); n   parent.resize(n); n   dfs(0, -1, 0); n   vector<int> to_st(vec.size()); n   for (int i = 0; i < (int)vec.size(); i++) to_st[i] = height[vec[i]]; n   st = sparse_table(to_st); n } n int lca(int u, int v) { n   int a = min(first[u], first[v]); n   int b = max(first[u], first[v]); n   return vec[st.get(a, b + 1)]; n } n int dist(int u, int v) { return height[u] + height[v] - 2 * height[lca(u, v)]; } n bool is_child(int u, int v) { return tin[u] <= tin[v] && tout[v] <= tout[u]; } n int c1 = 0, c2 = 0, x = 0; n int add_vertex(int v) { n   if (c1 == c2) { n     if (dist(c1, v) == x + 1) { n       x++; n       if (is_child(c1, v)) { n         auto it = upper_bound( n             graph[c1].begin(), graph[c1].end(), v, n             [](const int& i, const int& j) -> bool { return tin[i] < tin[j]; }); n         assert(it != graph[c1].begin()); n         it--; n         c2 = *it; n       } else { n         c2 = parent[c1]; n       } n     } n   } else { n     if (dist(c1, v) == x + 1) { n       c1 = c2; n     } else if (dist(c2, v) == x + 1) { n       c2 = c1; n     } n   } n   if (c1 == c2) { n     return 2 * x; n   } else { n     return 2 * x - 1; n   } n } n int main() { n   cin >> n; n   graph.resize(n); n   for (int i = 1; i < n; i++) { n     int a; n     cin >> a; n     a--; n     graph[a].push_back(i); n     graph[i].push_back(a); n   } n   precalc_lca(); n   for (int i = 1; i < n; i++) { n     cout << add_vertex(i) <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long B = 360; n const long long N = 100005; n long long block(long long x) { return x / B; } n long long offset(long long x) { return x % B; } n deque<long long> a[B]; n signed c[B][N]; n long long n, q; n signed main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (long long i = 0; i < n; i++) { n     long long x; n     cin >> x; n     a[block(i)].push_back(x); n     c[block(i)][x]++; n   } n   cin >> q; n   long long lastans = 0; n   for (long long i = 0; i < q; i++) { n     long long op, l, r, k; n     cin >> op >> l >> r; n     l = (l + lastans - 1) % n; n     r = (r + lastans - 1) % n; n     if (l > r) swap(l, r); n     if (op == 2) cin >> k; n     k = (k + lastans - 1) % n + 1; n     long long L = block(l); n     long long R = block(r); n     l = offset(l); n     r = offset(r); n     if (op == 1) { n       if (L == R) { n         long long x = a[R][r]; n         a[R].erase(a[R].begin() + r); n         a[L].insert(a[L].begin() + l, x); n       } else { n         for (long long i = L; i < R; i++) { n           long long x = a[i].back(); n           a[i].pop_back(); n           c[i][x]--; n           c[i + 1][x]++; n           a[i + 1].push_front(x); n         } n         long long x = a[R][r + 1]; n         a[R].erase(a[R].begin() + r + 1); n         a[L].insert(a[L].begin() + l, x); n         c[R][x]--; n         c[L][x]++; n       } n     } else { n       long long ans = 0; n       if (L == R) { n         for (long long i = l; i <= r; i++) ans += a[L][i] == k; n       } else { n         for (long long i = l; i < a[L].size(); i++) ans += a[L][i] == k; n         for (long long i = 0; i <= r; i++) ans += a[R][i] == k; n         for (long long i = L + 1; i <= R - 1; i++) ans += c[i][k]; n       } n       cout << (lastans = ans) << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   int x; n   int y; n }; n int main() { n   int n; n   cin >> n; n   Point P[n]; n   for (int i = 0; i < n; i++) { n     cin >> P[i].x >> P[i].y; n   } n   int val; n   if (n < 2) n     val = -1; n   else if (n == 2) { n     if (P[0].x != P[1].x && P[0].y != P[1].y) n       val = abs(P[0].x - P[1].x) * abs(P[0].y - P[1].y); n     else n       val = -1; n   } else { n     int alt, larg; n     if ((P[0].x - P[1].x) != 0) n       alt = P[0].x - P[1].x; n     else { n       alt = P[0].x - P[2].x; n     } n     if ((P[0].y - P[1].y) != 0) n       larg = P[0].y - P[1].y; n     else { n       larg = P[0].y - P[2].y; n     } n     val = abs(alt * larg); n   } n   cout << val << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int q, n; n int par[1 << 20][32], dep[1 << 20]; n int da[500000]; n void add(int v) { n   par[n][0] = par[n + 1][0] = v; n   dep[n] = dep[n + 1] = dep[v] + 1; n   for (int i = (int)(0); i < (int)(20); i++) n     par[n][i + 1] = par[n + 1][i + 1] = par[par[n][i]][i]; n } n int lca(int u, int v) { n   if (dep[u] > dep[v]) swap(u, v); n   int dif = dep[v] - dep[u]; n   for (int i = (int)(0); i < (int)(21); i++) n     if (dif & (1 << i)) v = par[v][i]; n   if (u == v) return u; n   for (int i = 20; i >= 0; i--) n     if (par[u][i] != par[v][i]) { n       u = par[u][i]; n       v = par[v][i]; n     } n   return par[u][0]; n } n int dist(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; } n void solve() { n   int u = 2, v = 3, d = 2, x, i = 0, jos = q; n   ; n   dep[2] = dep[3] = dep[4] = 1; n   par[2][0] = par[3][0] = par[4][0] = 1; n   n = 5; n   while (q--) { n     scanf( %d , &x); n     add(x); n     int du = dist(n, u), dv = dist(n, v); n     if (du > d) n       v = n, d = du; n     else if (dv > d) n       u = n, d = dv; n     n += 2; n     da[i] = d; n     i++; n   } n   int j; n   for (j = 0; j < jos; j++) { n     printf( %d n , da[j]); n   } n } n int main() { n   scanf( %d , &q); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mat[1005][1005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = (0); i < (n); i++) { n     for (int j = (0); j < (n); j++) { n       scanf( %d , &mat[i][j]); n     } n   } n   int akt = 0; n   for (int i = (0); i < (n); i++) akt = (akt + mat[i][i]) % 2; n   int q; n   scanf( %d , &q); n   for (int i = (0); i < (q); i++) { n     int nr; n     scanf( %d , &nr); n     if (nr == 1 || nr == 2) { n       akt = 1 - akt; n       int x; n       scanf( %d , &x); n     } else n       printf( %d , akt); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 3.14159265358979323846; n void rw() {} n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   vector<long long> s; n   long long n, c, f, se; n   cin >> n; n   s.push_back(4); n   s.push_back(7); n   for (int i = 0; i < s.size(); i++) { n     f = 0, se = 0; n     c = s[i]; n     while (c) { n       if (c % 10 == 4) n         f++; n       else n         se++; n       c /= 10; n     } n     if (s[i] >= n && f == se) { n       cout << s[i] <<   n ; n       break; n     } else { n       s.push_back(s[i] * 10 + 4); n       s.push_back(s[i] * 10 + 7); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, k = 0; n   long long x, y, z = 0; n   long long hsl[1002]; n   cin >> a; n   for (int i = 1; i <= a; i++) { n     y = 0; n     z = 0; n     cin >> b >> k >> x; n     if (x % 2 == 0) { n       y = x / 2; n       z = x / 2; n     } else { n       z = x / 2 + 1; n       y = x / 2; n     } n     z = z * b; n     y = y * k; n     z = z - y; n     hsl[i] = z; n   } n   for (int i = 1; i <= a; i++) { n     cout << hsl[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n pair<long long int, long long int> a[500001]; n int main() { n   ios::sync_with_stdio(false); n   cout << fixed << setprecision(10); n   long long int i, j, n, f; n   double lo, mid, hi, ans = -1, last; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; n   lo = 0; n   hi = 1e10; n   for (i = 0; i < 100; i++) { n     mid = (lo + hi) / 2.0; n     f = 0; n     last = -1e100; n     for (j = 1; j <= n; j++) { n       if (a[j].second > 0) n         last = max(last, 1.0 * (a[j].first + 1.0 * a[j].second * mid)); n       else { n         if (1.0 * (a[j].first + 1.0 * a[j].second * mid) < last) { n           f = 1; n           break; n         } n       } n     } n     if (f) { n       hi = mid; n       ans = mid; n     } else n       lo = mid; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct st { n   int t, l, r, p; n   bool operator<(const st& B) const { return t < B.t; } n } a[100005]; n int N, M, K, s[100005]; n vector<st> u[100005], v[100005]; n long long b[100005], ans[100005]; n int sum(int x) { n   int d = 0; n   for (int i = x; i; i -= i & -i) d += s[i]; n   return d; n } n void ins(int x, int d) { n   for (int i = x; i <= M; i += i & -i) s[i] += d; n } n int find(int k) { n   int p = 0; n   for (int i = 20; i >= 0; i--) n     if (p + (1 << i) <= M && s[p + (1 << i)] < k) k -= s[p += 1 << i]; n   return p + 1; n } n void init() { n   scanf( %d%d , &N, &M); n   for (int i = 1; i <= N; i++) n     scanf( %d%d%d , &a[i].t, &a[i].l, &a[i].r), b[i] = a[i].t, a[i].p = i; n   sort(a + 1, a + N + 1), sort(b + 1, b + N + 1), n       K = unique(b + 1, b + N + 1) - b - 1; n } n void work(long long t, int p) { n   for (auto i : u[p]) v[i.r].push_back(i), ins(i.r, 1); n   for (auto i : v[p]) ans[i.p] = t; n   ins(p, -u[p].size() - v[p].size()); n   u[p].clear(), v[p].clear(); n } n void doit() { n   b[++K] = 1e18; n   long long t = 0; n   for (int i = 1, j = 1, p = 1; i <= K; i++) { n     for (; t < b[i];) { n       int n = sum(M), d = sum(p), u = n - sum(p - 1), q; n       if (!n) { n         t = b[i]; n         continue; n       } n       if (u >= d) { n         q = find(n - u + 1); n         if (t + q - p <= b[i]) n           t += q - p, p = q, work(t, p); n         else n           p += b[i] - t, t = b[i]; n       } else { n         q = find(d); n         if (t + p - q <= b[i]) n           t += p - q, p = q, work(t, p); n         else n           p -= b[i] - t, t = b[i]; n       } n     } n     for (; j <= N && a[j].t == b[i]; j++) n       ins(a[j].l, 1), u[a[j].l].push_back(a[j]); n   } n   for (int i = 1; i <= N; i++) printf( %I64d n , ans[i]); n } n int main() { n   init(); n   doit(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, x, n, k, m = 0, f = 0, j = 1; n   int a[26]; n   string s; n   cin >> s; n   n = s.length(); n   cin >> k; n   k = k + n; n   for (i = 0; i < 26; i++) { n     cin >> a[i]; n     m = max(m, a[i]); n   } n   for (i = 0; i < n; i++) { n     f = f + a[s[i] -  a ] * j; n     j++; n   } n   f = f + ((k * (k + 1)) / 2 - (n * (n + 1)) / 2) * m; n   cout << f << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long modInverse(long long a, long long m) { n   long long m0 = m; n   long long y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     long long q = a / m; n     long long t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n long long nCmmod(long long n, long long m, long long mod) { n   vector<long long> a(200001, 1); n   for (__typeof(1) i = 1; i < 200001; i += 1) { n     a[i] = (a[i - 1] * i) % mod; n   } n   long long p = 1; n   p = (p * a[n]) % mod; n   p = (p * modInverse(a[m], mod)) % mod; n   p = (p * modInverse(a[n - m], mod)) % mod; n   return p; n } n vector<long long> p(long long n) { n   long long x = 0; n   vector<long long> v; n   for (long long i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (n / i == i) { n         v.push_back(i); n       } else { n         v.push_back(i); n         v.push_back(n / i); n       } n     } n   } n   sort(v.begin(), v.end()); n   return v; n } n long long bsearch(vector<long long> arr, long long l, long long r, int x) { n   if (r >= l) { n     long long mid = l + (r - l) / 2; n     if (arr[mid] == x) return mid; n     if (arr[mid] > x) return bsearch(arr, l, mid - 1, x); n     return bsearch(arr, mid + 1, r, x); n   } n   return l + (r - l) / 2; n } n string decToBinary(long long n) { n   string s =   ; n   long long f = 0; n   for (int i = 31; i >= 0; i--) { n     int k = n >> i; n     if (k & 1) n       s +=  1 ; n     else n       s +=  0 ; n   } n   return s; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int power(long long int x, long long int y) { n   long long int temp; n   if (y == 0) return 1; n   temp = power(x, y / 2); n   if (y % 2 == 0) n     return (temp % 1000000007 * temp % 1000000007) % 1000000007; n   else { n     if (y > 0) n       return (x % 1000000007 * temp % 1000000007 * temp % 1000000007) % n              1000000007; n     else n       return (temp % 1000000007 * temp % 1000000007) % 1000000007 / x; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     string s; n     cin >> s; n     long long m = n / k; n     long long cn = (k + 1) / 2; n     long long r = 0; n     for (__typeof(cn) i = 0; i < cn; i += 1) { n       vector<long long> A(26, 0); n       char c = s[i]; n       for (__typeof(m) j = 0; j < m; j += 1) { n         A[s[j * k + i] -  a ] += 1; n       } n       for (__typeof(m) j = 0; j < m; j += 1) { n         A[s[j * k + k - 1 - i] -  a ] += 1; n       } n       long long ma = -1; n       for (__typeof(26) j = 0; j < 26; j += 1) { n         if (A[j] > ma) { n           ma = A[j]; n         } n       } n       if (k % 2 == 1 && i == cn - 1) n         r += m - ma / 2; n       else n         r += 2 * m - ma; n     } n     cout << r << endl; n   } n } n


#include <bits/stdc++.h> n const double pi = 3.1415926535897932384626433832795; n int gcd(int a, int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n using namespace std; n void ifd() {} n void tme() {} n int main() { n   ifd(); n   string s, t, tmp; n   getline(cin, s); n   vector<string> d; n   vector<int> check; n   vector<int> r; n   stringstream p; n   p.clear(); n   p << s; n   while (p >> t) d.push_back(t); n   bool f = true; n   for (int i = (0); i < (d.size()); ++i) { n     tmp = d[i]; n     while (tmp.size() < 6) tmp =  ?  + tmp; n     tmp = tmp.substr(tmp.size() - 6, 6); n     if (tmp[2] ==  l  && tmp[3] ==  i  && tmp[4] ==  o  && tmp[5] ==  s ) { n       check.push_back(1); n       r.push_back(0); n     } else if (tmp[2] ==  e  && tmp[3] ==  t  && tmp[4] ==  r  && n                tmp[5] ==  a ) { n       check.push_back(2); n       r.push_back(1); n     } else if (tmp[3] ==  e  && tmp[4] ==  t  && tmp[5] ==  r ) { n       check.push_back(2); n       r.push_back(0); n     } else if (tmp[1] ==  l  && tmp[2] ==  i  && tmp[3] ==  a  && n                tmp[4] ==  l  && tmp[5] ==  a ) { n       check.push_back(1); n       r.push_back(1); n     } else if (tmp ==  initis ) { n       check.push_back(3); n       r.push_back(0); n     } else if (tmp ==  inites ) { n       check.push_back(3); n       r.push_back(1); n     } else { n       cout <<  NO  << endl; n       return 0; n     } n   } n   int te = r[0]; n   for (int i = (0); i < (r.size()); ++i) n     if (r[i] != te) f = false; n   if (!f) { n     cout <<  NO  << endl; n     return 0; n   } n   if (check.size() == 1) { n     cout <<  YES  << endl; n     return 0; n   } n   int n1 = 0, n2 = 0, n3 = 0; n   for (int i = (0); i < (check.size()); ++i) { n     if (check[i] == 1) n1++; n     if (check[i] == 2) n2++; n     if (check[i] == 3) n3++; n     if (i > 0 && check[i] < check[i - 1]) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   if (n1 >= 0 && n2 == 1 && n3 >= 0) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   tme(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 1; n int n, m, tin[N], up[N], dw[N]; n bool ans[N]; n vector<int> edge[N], redge[N]; n void topo() { n   queue<int> q; n   for (int i = 1; i <= n; i++) n     if (!tin[i]) q.push(i); n   while (q.size()) { n     int at = q.front(); n     q.pop(); n     for (auto to : edge[at]) n       if (!--tin[to]) q.push(to); n   } n } n void dfs2(int at, int rt, int rev) { n   if (!rev) { n     up[at] = rt; n     for (auto to : edge[at]) n       if (!up[to]) dfs2(to, rt, rev); n   } else { n     dw[at] = rt; n     for (auto to : redge[at]) n       if (!dw[to]) dfs2(to, rt, rev); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     edge[x].push_back(y); n     redge[y].push_back(x); n     tin[y]++; n   } n   topo(); n   int ok = 1; n   for (int i = 1; i <= n; i++) n     if (tin[i]) ok = 0; n   if (!ok) n     cout << -1 <<   n ; n   else { n     for (int i = 1; i <= n; i++) { n       if (!up[i]) dfs2(i, i, 0); n       if (!dw[i]) dfs2(i, i, 1); n     } n     int cnt = 0; n     for (int i = 1; i <= n; i++) n       if (up[i] == i and dw[i] == i) ans[i] = 1, cnt++; n     cout << cnt <<   n ; n     for (int i = 1; i <= n; i++) cout << (ans[i] ?  A  :  E ); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n const long long inf = 1e18; n using namespace std; n int n; n long long x[100005]; n long long lb, ub, mid; n long long sum, S; n long long cnt[3]; n int main(void) { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> x[i]; n   lb = inf, ub = -inf; n   for (int i = 1; i <= n; i++) { n     lb = min(lb, x[i]); n     ub = max(ub, x[i]); n   } n   if (ub - lb <= 1) { n     cout << n << endl; n     for (int i = 1; i <= n; i++) { n       cout << x[i]; n       if (i != n) cout <<    ; n     } n     cout << endl; n     return 0; n   } n   mid = lb + 1; n   for (int i = 1; i <= n; i++) { n     sum += x[i]; n     if (x[i] == lb) cnt[0]++; n     if (x[i] == ub) cnt[2]++; n     if (x[i] == mid) cnt[1]++; n   } n   S = sum - mid * n; n   bool flag = false; n   long long tmp, ans = n, ans_p; n   if (S < 0) S *= -1, flag = true; n   for (long long p = S; 2 * p <= n + S; p++) { n     long long m = p - S; n     if (flag) n       tmp = min(ans, min(p, cnt[0]) + min(m, cnt[2]) + min(n - p - m, cnt[1])); n     else n       tmp = min(ans, min(p, cnt[2]) + min(m, cnt[0]) + min(n - p - m, cnt[1])); n     if (ans > tmp) { n       ans = tmp; n       ans_p = p; n     } n   } n   long long ans_m = ans_p - S; n   if (flag) { n     long long t = ans_m; n     ans_m = ans_p; n     ans_p = t; n   } n   cout << ans << endl; n   for (int i = 1; i <= ans_p; i++) cout << ub <<    ; n   for (int i = 1; i <= ans_m; i++) cout << lb <<    ; n   for (int i = 1; i <= n - ans_p - ans_m; i++) cout << mid <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a = 0; n   int d = 0; n   string s; n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  A ) n       a++; n     else n       d++; n   } n   cout << (a == d ?  Friendship  : (a > d ?  Anton  :  Danik )); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long N; n   cin >> N; n   vector<long long> V; n   long long Sum = N; n   for (long long i = 0; i < N; i++) { n     long long X; n     cin >> X; n     V.push_back(X); n   } n   long long L = 0; n   long long Cnt = 0; n   for (long long i = 0; i < N; i++) { n     if (V[i] == V[L]) n       Cnt++; n     else { n       if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2; n       while (V[L] != V[i]) { n         L++; n         Cnt--; n       } n       Cnt++; n     } n   } n   if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2; n   cout << Sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n long long s, total, ans, leaves[maxn]; n int n; n vector<pair<long long, long long>> tree[maxn]; n void dfs(int u, int prev, n          priority_queue<pair<long long, pair<long long, long long>>>& pq) { n   leaves[u] = (long long)(tree[u].size() == 1); n   for (auto e : tree[u]) { n     long long v = e.second, w = e.first; n     if (v == prev) continue; n     dfs(v, u, pq); n     leaves[u] += leaves[v]; n     pq.push({w * leaves[v] - w / 2ll * leaves[v], {w, leaves[v]}}); n     total += w * leaves[v]; n   } n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int T; n   cin >> T; n   while (T--) { n     cin >> n >> s; n     for (int i = 0; i < n; ++i) { n       leaves[i] = 0; n       tree[i].clear(); n     } n     for (int i = 0; i < n - 1; ++i) { n       long long u, v, w; n       cin >> u >> v >> w; n       u--, v--; n       tree[u].push_back({w, v}); n       tree[v].push_back({w, u}); n     } n     priority_queue<pair<long long, pair<long long, long long>>> pq; n     total = ans = 0; n     dfs(0, -1, pq); n     while (total > s) { n       auto cur = pq.top(); n       pq.pop(); n       long long w = cur.second.first, cnt = cur.second.second; n       total -= w * cnt; n       w /= 2ll; n       total += w * cnt; n       if (w > 0ll) pq.push({w * cnt - w / 2ll * cnt, {w, cnt}}); n       ans++; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = (int)1e9 + 1; n const int MAX = 1e5 + 1; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, x, arr[3] = {}; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     arr[x]++; n   } n   if (!arr[1]) n     cout << 0 << endl; n   else if (arr[1] > arr[2]) n     cout << arr[2] + (arr[1] - arr[2]) / 3 << endl; n   else if (arr[2] >= arr[1]) n     cout << arr[1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans, reg[26] = {1}; n char s[100][100]; n bool dfs(int dep) { n   if (reg[dep] == n) return true; n   if (dep >= ans || reg[dep] > n) return false; n   ++dep; n   for (int i = -1; i < (dep); ++i) n     for (int j = 0; j < (dep); ++j) { n       int ii = i; n       if (ii == -1) ii = 25; n       for (int k = 1; k <= 8; k <<= 1) { n         reg[dep] = reg[ii] + k * reg[j]; n         if (dfs(dep)) { n           sprintf(s[dep],  lea e%cx, [e%cx + %d*e%cx] , dep +  a , ii +  a , k, n                   j +  a ); n           return true; n         } n       } n     } n   return false; n } n int main() { n   scanf( %d , &n); n   for (ans = 0; !dfs(0); ++ans) n     ; n   printf( %d n , ans); n   for (int i = 1; i < (ans + 1); ++i) printf( %s n , s[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string tostring(int x) { n   ostringstream o; n   o << x; n   return o.str(); n } n int toint(string s) { n   istringstream st(s); n   int i; n   st >> i; n   return i; n } n const int mod = 1e9 + 7; n const int N = 1e6 + 10; n const int inf = 2e9; n const double eps = 1e-7; n const long long INF = (long long)1e18; n int n; n long long h, k; n long long a[N]; n int main() { n   cin >> n >> h >> k; n   for (int i = 0; i < (n); ++i) cin >> a[i]; n   int i = 0, j = 0; n   long long sum = 0; n   long long left = 0; n   long long ans = 0; n   while (i < n) { n     j = i; n     sum = left; n     while (j < n && sum + a[j] <= h) { n       sum += a[j]; n       j++; n     } n     ans += sum / k; n     left = sum % k; n     if (j < n && left + a[j] > h) { n       ans++; n       left = 0; n     } n     i = j; n   } n   if (left) ans++; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n long long gi() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) f ^= ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return f ? x : -x; n } n std::mt19937 rnd(time(NULL)); n template <class T> n void cxk(T& a, T b) { n   a = a > b ? a : b; n } n template <class T> n void cnk(T& a, T b) { n   a = a < b ? a : b; n } n int a[100010]; n int main() { n   int qwq = gi(), n, k; n   while (qwq--) { n     n = gi(), k = gi(); n     for (int i = 1; i <= n; ++i) a[i] = gi(); n     bool s1 = 0, s2 = n == 1; n     for (int i = 1; i <= n; ++i) s1 |= a[i] == k; n     for (int i = 1; i < n; ++i) s2 |= a[i] >= k && a[i + 1] >= k; n     for (int i = 1; i + 1 < n; ++i) s2 |= a[i] >= k && a[i + 2] >= k; n     puts((s1 & s2) ?  yes  :  no ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int n; n vector<set<int> > g(200000); n vector<int> used(200000); n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   vector<int> x(m); n   vector<int> y(m); n   for (int i = 0; i < m; i++) { n     cin >> x[i] >> y[i]; n     x[i]--; n     y[i]--; n     g[x[i]].insert(y[i]); n     g[y[i]].insert(x[i]); n   } n   set<pair<int, int> > s; n   vector<int> v(n); n   for (int i = 0; i < n; i++) { n     s.insert(make_pair(g[i].size(), i)); n     v[i] = g[i].size(); n   } n   while (s.size()) { n     int a = s.begin()->first; n     int b = s.begin()->second; n     if (a < k) { n       s.erase(make_pair(a, b)); n       v[b] = 0; n       for (auto i = g[b].begin(); i != g[b].end(); i++) n         if (v[*i] >= k) { n           s.erase(make_pair(v[*i], *i)); n           v[*i]--; n           s.insert(make_pair(v[*i], *i)); n         } n     } else n       break; n   } n   vector<int> ans(m); n   ans[m - 1] = s.size(); n   for (int i = m - 1; i >= 1; i--) { n     int fl = 0; n     if (s.find(make_pair(v[x[i]], x[i])) != s.end()) fl++; n     if (s.find(make_pair(v[y[i]], y[i])) != s.end()) fl++; n     if (fl != 2) n       ans[i - 1] = ans[i]; n     else { n       s.erase(make_pair(v[x[i]], x[i])); n       s.erase(make_pair(v[y[i]], y[i])); n       v[x[i]]--; n       v[y[i]]--; n       s.insert(make_pair(v[x[i]], x[i])); n       s.insert(make_pair(v[y[i]], y[i])); n       g[x[i]].erase(y[i]); n       g[y[i]].erase(x[i]); n       while (s.size()) { n         int a = s.begin()->first; n         int b = s.begin()->second; n         if (a < k) { n           s.erase(make_pair(a, b)); n           v[b] = 0; n           for (auto i = g[b].begin(); i != g[b].end(); i++) n             if (v[*i] >= k) { n               s.erase(make_pair(v[*i], *i)); n               v[*i]--; n               s.insert(make_pair(v[*i], *i)); n             } n         } else n           break; n       } n       ans[i - 1] = s.size(); n     } n   } n   for (int i = 0; i < m; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n, val; n   cin >> n; n   vector<int> vet; n   for (int i = 0; i < n; i++) { n     cin >> val; n     vet.push_back(val); n   } n   sort(vet.begin(), vet.end()); n   vector<int> ans; n   while (ans.size() < n) { n     set<int> opa; n     for (int i = 0; i < n; i++) { n       if (vet[i] != -1) opa.insert(vet[i]); n     } n     set<int>::iterator it = opa.begin(); n     while (it != opa.end()) { n       ans.push_back(*it); n       it++; n     } n     for (int i = 0; i < n; i++) { n       if (opa.count(vet[i])) { n         opa.erase(vet[i]); n         vet[i] = -1; n       } n     } n   } n   int resp = 0; n   for (int i = 0; i < n - 1; i++) { n     if (ans[i + 1] > ans[i]) resp++; n   } n   cout << resp <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Max(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ b; } n int Min(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ a; } n long long GCD(long long a, long long b) { return b != 0 ? GCD(b, a % b) : a; } n long long LCM(long long a, long long b) { return a * (b / GCD(a, b)); } n long long Pow(long long n, long long e) { n   if (e == 0) return 1; n   if (e == 1) n     return n; n   else if (e & 1) { n     long long t = Pow(n, e / 2); n     return n * t * t; n   } else { n     long long t = Pow(n, e / 2); n     return t * t; n   } n } n const long long MOD = 1000000007; n long long PowMod(long long n, long long e, long long m) { n   if (e == 0) return 1; n   if (e == 1) n     return n % m; n   else if (e & 1) { n     long long t = PowMod(n, e / 2, m) % m; n     return (((t * t) % m) * (n % m)) % m; n   } else { n     long long t = PowMod(n, e / 2, m) % m; n     return (t * t) % m; n   } n } n long long C(long long n, long long k) { n   if (n == k || k == 0) return 1; n   if (k > n / 2) k = n - k; n   long long a = 1; n   for (int i = (1), max_ = (k + 1); i < max_; ++i) { n     a = (a * (n - i + 1)) % MOD; n   } n   long long b = 1; n   for (int i = (1), max_ = (k + 1); i < max_; ++i) { n     b = (b * i) % MOD; n   } n   a = (a * PowMod(b, MOD - 2, MOD)) % MOD; n   return a; n } n long long a[2005], r[2005], inv[2005]; n int main() { n   int N, K; n   scanf( %d %d , &N, &K); n   for (int i = 0, max_ = (N); i < max_; ++i) scanf( %d , &a[i]); n   if (K == 0) { n     for (int i = 0, max_ = (N); i < max_; ++i) r[i] = a[i]; n   } else { n     for (int i = (1), max_ = (2005); i < max_; ++i) n       inv[i] = PowMod(i, MOD - 2, MOD); n     r[0] = a[0]; n     for (int i = (1), max_ = (N); i < max_; ++i) { n       r[i] = a[i]; n       long long curr = K; n       int n = K; n       int k = 1; n       int j = i - 1; n       while (j >= 0) { n         long long tmp = (a[j] * curr) % MOD; n         r[i] = (r[i] + tmp) % MOD; n         ++n; n         ++k; n         curr = (curr * n) % MOD; n         curr = (curr * inv[k]) % MOD; n         --j; n       } n     } n   } n   for (int i = 0, max_ = (N); i < max_; ++i) printf( %I64d  , r[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int stack[90], n, k, ans, bag, a[90], tim[90]; n int vec[90][90], zoom[90]; n bool vis[90]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     vec[a[i]][0]++; n     vec[a[i]][vec[a[i]][0]] = i; n   } n   for (int i = 1; i <= n; i++) n     tim[i] = vec[i][1], vec[i][vec[i][0] + 1] = n + 1, zoom[i] = 1; n   for (int i = 1; i <= n; i++) { n     if (!vis[a[i]]) { n       if (bag < k) n         bag++; n       else { n         int now, ref = 0; n         for (int i = 1; i <= n; i++) n           if (vis[i] && ref <= tim[i]) { n             now = i; n             ref = tim[i]; n           } n         vis[now] = false; n       } n       ans++; n       zoom[a[i]]++; n       tim[a[i]] = vec[a[i]][zoom[a[i]]]; n       vis[a[i]] = true; n     } else { n       zoom[a[i]]++; n       tim[a[i]] = vec[a[i]][zoom[a[i]]]; n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, k; n   cin >> n >> k; n   long long r = (n * (n - 1)); n   r = (r >> 1); n   if (r > k) { n     for (long long i = 0; i < n; i++) { n       cout << 0 <<     << i <<   n ; n     } n     return 0; n   } n   cout <<  no solution n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5001; n long long x11[10]; n long long y11[10]; n long long x22[10]; n long long y22[10]; n long long deltax[10]; n long long deltay[10]; n int main() { n   bool flag1 = 0; n   bool flag2 = 0; n   bool flag3 = 0; n   for (int i = 0; i < 4; i++) { n     scanf( %lld %lld %lld %lld , &x11[i], &y11[i], &x22[i], &y22[i]); n     if (x11[i] == x22[i] && y11[i] == y22[i]) flag3 = 1; n     deltax[i] = x11[i] - x22[i]; n     deltay[i] = y11[i] - y22[i]; n     if (deltax[i] == 0) flag1 = 1; n     if (deltay[i] == 0) flag2 = 1; n   } n   if (!flag1 || !flag2 || flag3) { n     printf( NO n ); n     return 0; n   } n   for (int i = 0; i < 4; i++) { n     if (deltax[i] != 0 && deltay[i] != 0) { n       printf( NO n ); n       return 0; n     } n   } n   vector<long long> vx; n   vector<long long> vy; n   map<long long, int> mp1; n   map<long long, int> mp2; n   for (int i = 0; i < 4; i++) { n     vx.push_back(x11[i]); n     vx.push_back(x22[i]); n     vy.push_back(y11[i]); n     vy.push_back(y22[i]); n     mp1[x11[i]]++; n     mp1[x22[i]]++; n     mp2[y11[i]]++; n     mp2[y22[i]]++; n   } n   if (mp1.size() != 2 || mp2.size() != 2) { n     printf( NO n ); n   } else { n     bool tempflag = 0; n     for (auto it : mp1) { n       if (it.second != 4) tempflag = 1; n     } n     for (auto it : mp2) { n       if (it.second != 4) tempflag = 1; n     } n     if (!tempflag) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n int main() { n   ll n; n   cin >> n; n   vector<ll> a(n + 1); n   ll curr = 0; n   vector<ll> iseven(2); n   ll ans = 0; n   for (int i = 1; i <= n; i++) { n     ll x; n     cin >> x; n     x = __builtin_popcountll(x); n     a[i] = x; n     curr = (curr + x) % 2; n     ans += iseven[curr]; n     if (i > 1) { n       if (curr == 0) ans++; n       if (x % 2 == 0) ans--; n     } n     iseven[curr]++; n   } n   for (ll i = 1; i <= n; i++) { n     ll maxi = a[i]; n     ll sum = a[i]; n     for (ll j = i - 1; j >= max(1ll, i - 62); j--) { n       sum += a[j]; n       maxi = max(maxi, a[j]); n       if (sum % 2 == 0 && 2 * maxi > sum) { n         ans--; n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct Seg { n   int sa, ea, sb, eb; n } p[200005]; n int cmp(Seg &a, Seg &b) { n   if (a.ea != b.ea) n     return a.ea < b.ea; n   else n     return a.sa < b.sa; n } n int n, mx[4 * 200005], mi[4 * 200005]; n void creat(int l, int r, int k) { n   if (l == r) { n     mx[k] = p[l].sb, mi[k] = p[l].eb; n     return; n   } n   int mid = (l + r) / 2; n   creat(l, mid, 2 * k); n   creat(mid + 1, r, 2 * k + 1); n   mx[k] = max(mx[2 * k], mx[2 * k + 1]); n   mi[k] = min(mi[2 * k], mi[2 * k + 1]); n } n int querymin(int l, int r, int al, int ar, int k) { n   if (l == al && r == ar) return mi[k]; n   int mid = (l + r) / 2; n   if (ar <= mid) n     return querymin(l, mid, al, ar, 2 * k); n   else if (al > mid) n     return querymin(mid + 1, r, al, ar, 2 * k + 1); n   else n     return min(querymin(l, mid, al, mid, 2 * k), n                querymin(mid + 1, r, mid + 1, ar, 2 * k + 1)); n } n int querymax(int l, int r, int al, int ar, int k) { n   if (l == al && r == ar) return mx[k]; n   int mid = (l + r) / 2; n   if (ar <= mid) n     return querymax(l, mid, al, ar, 2 * k); n   else if (al > mid) n     return querymax(mid + 1, r, al, ar, 2 * k + 1); n   else n     return max(querymax(l, mid, al, mid, 2 * k), n                querymax(mid + 1, r, mid + 1, ar, 2 * k + 1)); n } n int ea[200005]; n int solve() { n   std::sort(p + 1, p + 1 + n, cmp); n   creat(1, n, 1); n   for (int i = 1; i <= n; i++) ea[i] = p[i].ea; n   for (int i = 1; i <= n; i++) { n     if (i == 1) continue; n     int left = p[i].sa; n     int ans = lower_bound(ea + 1, ea + i, left) - ea; n     if (ans > i - 1) continue; n     int maxL = querymax(1, n, ans, i - 1, 1); n     int minR = querymin(1, n, ans, i - 1, 1); n     if (minR < p[i].sb || maxL > p[i].eb) return 0; n   } n   return 1; n } n int main() { n   int i, j, k, sig = 1; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) n     scanf( %d %d %d %d , &p[i].sa, &p[i].ea, &p[i].sb, &p[i].eb); n   sig &= solve(); n   for (i = 1; i <= n; i++) swap(p[i].sa, p[i].sb), swap(p[i].ea, p[i].eb); n   sig &= solve(); n   if (sig) n     printf( YES n ); n   else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int tem; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int arr[n]; n     for (int i = 0; i < n; i++) scanf( %d , &arr[i]); n     int flag = 1; n     for (int i = 0; i < n - 1; i++) { n       if (abs(arr[i] - arr[i + 1]) > 1) { n         printf( YES n%d %d n , i + 1, i + 2); n         flag = 0; n         break; n       } n     } n     if (flag) printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n void lire_input() { freopen( input.txt ,  r , stdin); } n void ecrire_output() { freopen( output.txt ,  w , stdout); } n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n % 2 == 1) { n     for (int i = 0; i < n; i++) { n       printf( %d  , i); n     } n     printf(  n ); n     for (int i = 1; i <= n; i++) { n       if (i != n) n         printf( %d  , i); n       else n         printf( %d  , 0); n     } n     printf(  n ); n     for (int i = 0; i < n; i++) { n       if (i != n) n         printf( %d  , (2 * i + 1) % n); n       else n         printf( %d  , i % n); n     } n   } else n     cout <<  -1 ; n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool posible(int a, int b, int a2, int b2) { n   if ((a + a2 == b && b == b2) || (a + b2 == b && b == a2) || n       (b + b2 == a && a == a2) || (b + a2 == a && a == b2)) { n     return true; n   } n   return false; n } n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int a, b, a2, b2; n     cin >> a >> b >> a2 >> b2; n     if (posible(a, b, a2, b2)) { n       cout <<  YES n ; n     } else { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, p, last[10]; n struct node { n   int x, y; n }; n int s[10]; n char a[1005][1005]; n int vis[1005][1005], ans[10], can[10]; n queue<node> que[10]; n int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; n void bfs() { n   for (int i = 1; i <= p; i++) { n     while (!que[i].empty()) que[i].pop(); n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] !=  .  && a[i][j] !=  # ) { n         que[a[i][j] -  0 ].push({i, j}); n         vis[i][j] = a[i][j] -  0 ; n         last[a[i][j] -  0 ]++; n       } n     } n   } n   bool flag = true; n   while (flag) { n     flag = false; n     for (int idx = 1; idx <= p; idx++) { n       for (int ss = 1; ss <= s[idx] && can[idx] == 0; ss++) { n         int num = last[idx]; n         last[idx] = 0; n         for (int t = 1; t <= num; t++) { n           node now = que[idx].front(); n           que[idx].pop(); n           ans[idx]++; n           for (int i = 0; i < 4; i++) { n             int xx = now.x + d[i][0], yy = now.y + d[i][1]; n             if (xx >= 0 && xx < n && yy >= 0 && yy < m && vis[xx][yy] == 0 && n                 a[xx][yy] ==  . ) { n               que[idx].push({xx, yy}); n               vis[xx][yy] = idx; n               last[idx]++; n             } n           } n         } n         if (que[idx].empty()) can[idx] = idx; n       } n     } n     for (int i = 1; i <= p; i++) n       if (!que[i].empty()) flag = true; n   } n   for (int i = 1; i <= p; i++) printf( %d  , ans[i]); n   printf(  n ); n } n int main() { n   while (scanf( %d %d %d , &n, &m, &p) != EOF) { n     memset(a, 0, sizeof(a)); n     memset(s, 0, sizeof(s)); n     memset(ans, 0, sizeof(ans)); n     memset(vis, 0, sizeof(vis)); n     memset(last, 0, sizeof(last)); n     memset(can, 0, sizeof(can)); n     for (int i = 1; i <= p; i++) scanf( %d , &s[i]); n     getchar(); n     for (int i = 0; i < n; i++) scanf( %s , a[i]); n     bfs(); n   } n   return 0; n } n