#include <bits/stdc++.h> n using namespace std; n static const int INF = 500000000; n template <class T> n void debug(T a, T b) { n   for (; a != b; ++a) cerr << *a <<    ; n   cerr << endl; n } n int h, w, q; n char buf[505][505]; n int ans[1000005]; n struct query_ { n   int y1, x1, y2, x2; n   int id; n }; n bitset<505> able[2][505][505]; n void rec(int l, int r, vector<query_>& query) { n   vector<query_> left, right; n   int md = (l + r) >> 1; n   for (int i = 0; i < h; ++i) n     for (int j = l; j < r; ++j) able[0][i][j].reset(), able[1][i][j].reset(); n   for (int i = 0; i < h; ++i) n     if (buf[i][md] ==  . ) able[0][i][md].set(i), able[1][i][md].set(i); n   for (int i = h - 1; i >= 0; --i) n     for (int j = md; j >= l; --j) n       if (buf[i][j] ==  . ) { n         able[0][i][j] |= able[0][i + 1][j]; n         if (j < md) able[0][i][j] |= able[0][i][j + 1]; n       } n   for (int i = 0; i < h; ++i) n     for (int j = md; j < r; ++j) n       if (buf[i][j] ==  . ) { n         if (buf[i][j + 1] ==  . ) able[1][i][j + 1] |= able[1][i][j]; n         if (buf[i + 1][j] ==  . ) able[1][i + 1][j] |= able[1][i][j]; n       } n   for (int i = 0; i < query.size(); ++i) { n     if (query[i].x1 <= md && md <= query[i].x2) { n       if ((able[0][query[i].y1][query[i].x1] & n            able[1][query[i].y2][query[i].x2]) n               .any()) { n         ans[query[i].id] = 1; n       } n     } else if (query[i].x2 < md) n       left.push_back(query[i]); n     else n       right.push_back(query[i]); n   } n   if (!left.empty()) rec(l, md, left); n   if (!right.empty()) rec(md, r, right); n   query.clear(); n } n int main() { n   for (int i = 0; i < h; ++i) n     for (int j = 0; j < w; ++j) buf[i][j] =  # ; n   scanf( %d%d , &h, &w); n   for (int i = 0; i < h; ++i) scanf( %s , buf[i]); n   scanf( %d , &q); n   vector<query_> query; n   for (int i = 0; i < q; ++i) { n     int a, b, c, d; n     scanf( %d%d%d%d , &a, &b, &c, &d); n     --a; n     --b; n     --c; n     --d; n     if (a > c || b > d) continue; n     query.push_back((query_){a, b, c, d, i}); n   } n   rec(0, w, query); n   for (int i = 0; i < q; ++i) { n     if (ans[i]) n       puts( Yes ); n     else n       puts( No ); n   } 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   int t = 1; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> v(n); n     for (int i = 0; i < n; i++) cin >> v[i]; n     vector<int> ans(n); n     for (int i = 0; i < n / 2; i++) { n       ans[i] = v[n - 1 - i]; n       ans[n - 1 - i] = -1 * v[i]; n     } n     for (int ele : ans) cout << ele <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using cd = complex<double>; n const int Inf = 1000000007; n const long long mod = 1000000007; n const double Pi = acos(-1); n void Fastio() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n int n, t, ans = 0; n long long res = 0; n int Co[4], Color[100005], a[100005]; n vector<int> Adj[100005]; n map<int, long long> C; n int main() { n   Fastio(); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int j = 2; j <= n; j++) { n     int temp; n     cin >> temp; n     Adj[temp].emplace_back(j); n     Adj[j].emplace_back(temp); n   } n   queue<int> BFS; n   BFS.push(1); n   Co[1] = 1; n   Color[1] = 1; n   while (BFS.empty() == false) { n     int node = BFS.front(); n     for (auto x : Adj[node]) { n       if (!Color[x]) { n         Color[x] = 3 - Color[node]; n         Co[Color[x]]++; n         BFS.push(x); n       } n     } n     BFS.pop(); n   } n   for (int i = 1; i <= n; i++) { n     if (Adj[i].size() == 1 and i != 1) { n       t = Color[i]; n       break; n     } n   } n   t = 3 - t; n   for (int i = 1; i <= n; i++) { n     if (Color[i] == 3 - t) { n       ans ^= a[i]; n       C[a[i]]++; n     } n   } n   if (ans == 0) { n     res += 1ll * Co[3 - t] * (Co[3 - t] - 1) / 2; n     res += 1ll * Co[t] * (Co[t] - 1) / 2; n   } n   for (int i = 1; i <= n; i++) { n     if (Color[i] == t) { n       res += C[a[i] ^ ans]; n     } n   } n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 5, inf = 1e9 + 5; n char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc; n int ny; n inline char gc() { n   return pp1 == pp2 && n                  (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) n              ? EOF n              : *pp1++; n } n inline int read() { n   int x = 0; n   for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;) n     if (nc == 45) ny = -1; n   if (nc < 0) return nc; n   for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF; n        x = (x << 3) + (x << 1) + (nc ^ 48)) n     ; n   return x * ny; n } n int n, p[MAXN], tot; n struct Node { n   int x, y, c; n } a[MAXN]; n vector<int> s[MAXN]; n pair<long long, int> Mn[MAXN << 2]; n long long t[MAXN << 2]; n inline void pushup(int x) { Mn[x] = min(Mn[x << 1], Mn[x << 1 | 1]); } n inline void pushr(int x, long long v) { Mn[x].first += v, t[x] += v; } n inline void pushdown(int x) { n   if (t[x]) pushr(x << 1, t[x]), pushr(x << 1 | 1, t[x]), t[x] = 0; n } n inline void insert(int x, int l, int r, int p, long long v) { n   if (l == r) { n     Mn[x].first += v; n     return; n   } n   int mid = l + r >> 1; n   pushdown(x); n   (p <= mid ? insert(x << 1, l, mid, p, v) n             : insert(x << 1 | 1, mid + 1, r, p, v)), n       pushup(x); n } n inline void add(int x, int l, int r, int ql, int qr, int v) { n   if (ql > qr) return; n   if (ql <= l && r <= qr) return pushr(x, v); n   int mid = l + r >> 1; n   pushdown(x); n   if (ql <= mid) add(x << 1, l, mid, ql, qr, v); n   if (qr > mid) add(x << 1 | 1, mid + 1, r, ql, qr, v); n   pushup(x); n } n inline pair<long long, int> ask(int x, int l, int r, int ql, int qr) { n   if (ql <= l && r <= qr) return Mn[x]; n   int mid = l + r >> 1; n   pair<long long, int> res = make_pair((long long)1e18, 0); n   pushdown(x); n   if (ql <= mid) res = min(res, ask(x << 1, l, mid, ql, qr)); n   if (qr > mid) res = min(res, ask(x << 1 | 1, mid + 1, r, ql, qr)); n   return res; n } n inline void build(int x, int l, int r) { n   if (l == r) { n     Mn[x] = make_pair(-p[l], l); n     return; n   } n   int mid = l + r >> 1; n   build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r), pushup(x); n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     int x = read(), y = read(), w = read(); n     p[++tot] = x, p[++tot] = y, a[i] = (Node){x, y, w}; n   } n   sort(p + 1, p + tot + 1), tot = unique(p + 1, p + tot + 1) - p - 1, n                             build(1, 1, tot); n   for (int i = 1; i <= n; i++) n     a[i].x = lower_bound(p + 1, p + tot + 1, a[i].x) - p, n     a[i].y = lower_bound(p + 1, p + tot + 1, a[i].y) - p; n   for (int i = 1; i <= n; i++) s[max(a[i].x, a[i].y)].push_back(i); n   long long sum = 0, ans = 0, px, py; n   int flg = 0; n   for (int i = 1; i <= tot; i++) { n     insert(1, 1, tot, i, sum); n     for (auto o : s[i]) n       sum += a[o].c, add(1, 1, tot, min(a[o].x, a[o].y) + 1, i, a[o].c); n     pair<long long, int> t = ask(1, 1, tot, 1, i); n     if (sum - p[i] - t.first > ans) n       ans = sum - p[i] - t.first, px = p[i], py = p[t.second], flg = 1; n   } n   if (flg) n     cout << ans <<   n  << py <<     << py <<     << px <<     << px <<   n ; n   else n     cout << 0 <<   n  << inf <<     << inf <<     << inf <<     << inf <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void no(int ex = -1) { cout << ex <<   n ; } n void bl(bool win) { n   if (win) n     cout <<  YES ; n   else n     cout <<  NO ; n   cout <<   n ; n } n const int N = 2 * 10e5; n const int mod = 998244353; n vector<bool> pr; n void prime() { n   int EDGE = 1000; n   pr = vector<bool>(EDGE); n   for (int i = 0; i < EDGE; i++) pr[i] = true; n   pr[0] = false; n   pr[1] = false; n   for (int i = 2; i < EDGE; i++) { n     if (pr[i]) { n       if (i * i < EDGE) { n         for (int j = i * i; j < EDGE; j += i) pr[j] = false; n       } n     } n   } n } n long long nod(long long a1, long long b1) { n   if (b1 == 0) n     return a1; n   else n     return nod(b1, a1 % b1); n } n long long T; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   vector<int> mn(n); n   for (int i = 0; i < int(n); i++) { n     cin >> mn[i]; n   } n   vector<int> res(k); n   for (int i = 0; i < int(k); i++) { n     cin >> res[i]; n   } n   vector<int> ab = {0, 0, 0, 1}; n   vector<int>::iterator hig; n   hig = lower_bound(ab.begin(), ab.end(), 1); n   vector<vector<int>> ans(n, {0}); n   sort(mn.begin(), mn.end()); n   vector<int> us(n, 0); n   int cnt = 0; n   for (int z = n - 1; z >= 0; z--) { n     vector<int>::iterator low; n     low = lower_bound(us.begin(), us.end(), res[mn[z] - 1]); n     int y = low - us.begin(); n     y = min(n - 1, y); n     if (us[y] == res[mn[z] - 1]) y--; n     ans[n - y - 1][0]++; n     us[y]++; n     ans[n - y - 1].push_back(mn[z]); n   } n   int cur = 0; n   while (cur < n && ans[cur][0] != 0) { n     cur++; n   } n   cout << cur <<   n ; n   for (int i = 0; i < cur; i++) { n     for (int j = 0; j <= ans[i][0]; j++) cout << ans[i][j] <<    ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans = 1e5, freq[125]; n bool exst[125]; n string s; n int main() { n   scanf( %d , &n); n   cin >> s; n   for (int i = 0; i < n; i++) { n     exst[s[i]] = true; n   } n   freq[s[0]] = 1; n   for (int i = 0, j = 0; j < n;) { n     bool valid = 1; n     for (int k = 0; k <=  z ; k++) { n       if (exst[k] && !freq[k]) { n         j++; n         freq[s[j]]++; n         valid = 0; n         break; n       } n     } n     if (valid) { n       ans = min(ans, j - i + 1); n       freq[s[i]]--; n       i++; n     } n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int n, x, y, i, j; n   long double sum1 = 0, sum2 = 0, mini, maxi, p, z; n   cin >> n >> x >> y; n   long int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   mini = min(x, y); n   maxi = max(x, y); n   p = mini; n   j = 0; n   while (mini--) { n     sum1 = sum1 + a[n - 1 - j]; n     j++; n   } n   z = maxi; n   while (maxi--) { n     sum2 = sum2 + a[n - 1 - j]; n     j++; n   } n   cout << fixed << setprecision(12) << sum1 / p + sum2 / z; n } n


#include <bits/stdc++.h> n long long int oddsum[100020], evensum[100020]; n int main() { n   memset(oddsum, 0, sizeof(oddsum)); n   memset(evensum, 0, sizeof(evensum)); n   int n, i; n   long long int x, ans = 0, sum; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %lld , &x); n     if (i & 1) n       oddsum[(i >> 1) + 1] = oddsum[i >> 1] + x; n     else n       evensum[(i >> 1) + 1] = evensum[i >> 1] + x; n   } n   for (i = 0; i < n; i++) { n     if (i & 1) n       sum = n           oddsum[(i >> 1) + 1] + evensum[(n >> 1) + 1] - evensum[(i >> 1) + 1]; n     else n       sum = evensum[(i >> 1) + 1] + oddsum[n >> 1] - oddsum[i >> 1]; n     if (ans < sum) ans = sum; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s[222], str; n int res[1000000] = {0}; n bool hh(int n, int x) { n   for (int i = 0; i < (1 << x); i++) { n     str =   ; n     for (int k = 0; k < x; k++) (i & (1 << k)) ? str +=  1  : str +=  0 ; n     if (s[n].find(str) == -1) return false; n   } n   return true; n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> s[i]; n     int ii = 0, jj = 10; n     while (ii < jj && hh(i, ii + 1)) ii++; n     res[i] = ii; n   } n   int t, m; n   cin >> t; n   while (t--) { n     int i, j, mid, ii, jj; n     cin >> i >> j; n     ii = i; n     jj = j; n     n++; n     s[n] = s[i] + s[j]; n     if (s[n].size() > 1000) n       s[n] = s[n].substr(0, 500) + s[n].substr(s[n].size() - 500, 500); n     i = 0; n     j = 10; n     while (i < j && hh(n, i + 1)) i++; n     res[n] = max(i, max(res[ii], res[jj])); n     cout << res[n] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   static int f[10000]; n   int n, ok = false; n   scanf( %d , &n); n   for (register int i = 1; i <= n; ++i) scanf( %d , f + i); n   for (int i = 1; i <= n; ++i) n     if (f[f[f[i]]] == i) ok = true; n   puts(ok ?  YES  :  NO ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n const long long mod = 1e9 + 7; n inline long long gcd(long long a, long long b) { n   return !b ? a : gcd(b, a % b); n } n inline long long q_pow(long long a, long long x) { n   long long ans = 1, tmp = a; n   while (x) { n     if (x & 1) (ans *= tmp) %= mod; n     (tmp *= tmp) %= mod; n     x >>= 1; n   } n   return ans; n } n template <typename T> n inline void re(T &N) { n   int f = 1; n   char c; n   while ((c = getchar()) <  0  || c >  9 ) n     if (c ==  - ) f = -1; n   N = c -  0 ; n   while ((c = getchar()) >=  0  && c <=  9 ) N = N * 10 + c -  0 ; n   N *= f; n } n int m, n, t = 1, st, en; n struct Trie { n   struct node { n     int a[2]; n     int ans, len; n     int ma, mi; n     node() { n       a[0] = a[1] = 0; n       ans = 1e9; n       len = 1; n       ma = -1e9; n       mi = 1e9; n     } n     node(int x) { n       a[0] = a[1] = 0; n       ans = 1e9; n       len = 1; n       ma = mi = 0; n     } n   } nul; n   vector<node> v; n   Trie() { v.assign(1, nul); } n   inline void push_up(int p) { n     v[p].mi = min(v[(v[p].a[0])].mi, v[(v[p].a[1])].mi + v[(v[p].a[0])].len); n     v[p].ma = max(v[(v[p].a[0])].ma, v[(v[p].a[1])].ma + v[(v[p].a[0])].len); n     v[p].ans = n         min({v[(v[p].a[0])].ans, v[(v[p].a[1])].ans, n              v[(v[p].a[1])].mi - v[(v[p].a[0])].ma + v[(v[p].a[0])].len}); n     v[p].len = v[(v[p].a[0])].len + v[(v[p].a[1])].len; n   } n   int build(int p, int l, int r) { n     if (!p) v.push_back(nul), p = (int)v.size() - 1; n     if (l == r) return p; n     int mid = (l + r) >> 1; n     (v[p].a[0]) = build((v[p].a[0]), l, mid); n     (v[p].a[1]) = build((v[p].a[1]), mid + 1, r); n     push_up(p); n     return p; n   } n   void insert(int p, int dep, int val) { n     if (!(~dep)) return v[p] = node(1), void(); n     insert(v[p].a[val >> dep & 1], dep - 1, val); n     push_up(p); n   } n   void rotate(int p, int dep, int lim) { n     if (dep == lim) { n       swap((v[p].a[0]), (v[p].a[1])); n       push_up(p); n       return; n     } n     rotate((v[p].a[0]), dep - 1, lim); n     rotate((v[p].a[1]), dep - 1, lim); n     push_up(p); n   } n } tr; n int main() { n   ios::sync_with_stdio(0); n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   tr.build(0, 0, (1 << k) - 1); n   for (int i = 0; i < n; i++) tr.insert(1, k - 1, a[i]); n   vector<int> ans(1 << k), gray(1 << k); n   for (int i = 0; i < 1 << k; i++) { n     gray[i] = (i >> 1) ^ i; n     vector<int> tmp; n     for (int j = 0; j < k; j++, gray[i] >>= 1) tmp.push_back(gray[i] & 1); n     for (int j = 0; j < k; j++) gray[i] = gray[i] << 1 | tmp[j]; n   } n   for (int i = 0; i < 1 << k; i++) { n     ans[gray[i]] = tr.v[1].ans; n     if ((i + 1) < 1 << k) { n       int pos = 31 - __builtin_clz(gray[i] ^ gray[i + 1]); n       tr.rotate(1, k - 1, pos); n     } n   } n   for (int i = 0; i < 1 << k; i++) cout << ans[i] <<    n [i + 1 == 1 << k]; n } n


#include <bits/stdc++.h> n using namespace std; n static const int INF = 0x3f3f3f3f; n static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; n template <typename T, typename U> n static void amin(T &x, U y) { n   if (y < x) x = y; n } n template <typename T, typename U> n static void amax(T &x, U y) { n   if (x < y) x = y; n } n struct MaximumFlow { n   static const int InfCapacity = INF; n   struct Edge { n     int to; n     int capacity; n     int rev; n   }; n   vector<vector<Edge>> g; n   void init(int n) { g.assign(n, vector<Edge>()); } n   void add(int i, int j, int capacity) { n     Edge e, f; n     e.to = j, f.to = i; n     e.capacity = capacity, f.capacity = 0; n     g[i].push_back(e); n     g[j].push_back(f); n     g[i].back().rev = (int)g[j].size() - 1; n     g[j].back().rev = (int)g[i].size() - 1; n   } n   void addB(int i, int j, int capacity) { n     Edge e, f; n     e.to = j, f.to = i; n     e.capacity = capacity, f.capacity = capacity; n     g[i].push_back(e); n     g[j].push_back(f); n     g[i].back().rev = (int)g[j].size() - 1; n     g[j].back().rev = (int)g[i].size() - 1; n   } n   int maximumFlow(int s, int t) { n     int n = g.size(); n     vector<int> level(n); n     int total = 0; n     bool update; n     do { n       update = false; n       fill(level.begin(), level.end(), -1); n       level[s] = 0; n       queue<int> q; n       q.push(s); n       for (int d = n; !q.empty() && level[q.front()] < d;) { n         int u = q.front(); n         q.pop(); n         if (u == t) d = level[u]; n         for (auto e = (g[u]).begin(); e != (g[u]).end(); ++e) n           if (e->capacity > 0 && level[e->to] == -1) n             q.push(e->to), level[e->to] = level[u] + 1; n       } n       vector<int> iter(n); n       for (int i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1; n       while (1) { n         int f = augment(level, iter, s, t, InfCapacity); n         if (f == 0) break; n         total += f; n         update = true; n       } n     } while (update); n     return total; n   } n   int augment(vector<int> &level, vector<int> &iter, int u, int t, int f) { n     if (u == t || f == 0) return f; n     int lv = level[u]; n     if (lv == -1) return 0; n     level[u] = -1; n     for (; iter[u] >= 0; --iter[u]) { n       Edge &e = g[u][iter[u]]; n       if (level[e.to] <= lv) continue; n       int l = augment(level, iter, e.to, t, min(f, e.capacity)); n       if (l == 0) continue; n       e.capacity -= l; n       g[e.to][e.rev].capacity += l; n       level[u] = lv; n       return l; n     } n     return 0; n   } n }; n int main() { n   int n; n   int m; n   while (~scanf( %d%d , &n, &m)) { n     vector<array<int, 2>> edges(m); n     for (int(i) = 0; (i) < (int)(m); ++(i)) { n       int x; n       int y; n       scanf( %d%d , &x, &y), --x, --y; n       edges[i] = {x, y}; n     } n     vector<pair<int, int>> ans(m); n     int lo = 0, up = m + 1; n     while (up - lo > 0) { n       int mid = (lo + up) / 2; n       MaximumFlow mf; n       int src = m + n, dst = src + 1; n       mf.init(dst + 1); n       for (int(i) = 0; (i) < (int)(m); ++(i)) mf.add(src, i, 1); n       for (int(i) = 0; (i) < (int)(m); ++(i)) n         for (int j : edges[i]) mf.add(i, m + j, 1); n       for (int(j) = 0; (j) < (int)(n); ++(j)) mf.add(m + j, dst, mid); n       int f = mf.maximumFlow(src, dst); n       if (f == m) { n         up = mid; n         for (int(i) = 0; (i) < (int)(m); ++(i)) { n           for (auto e : mf.g[i]) n             if (e.capacity == 0 && m <= e.to && e.to < m + n) { n               int x = e.to - m; n               auto p = make_pair(edges[i][0], edges[i][1]); n               if (p.first != x) swap(p.first, p.second); n               ans[i] = p; n             } n         } n       } else { n         lo = mid + 1; n       } n     } n     printf( %d n , up); n     for (int i = 0; i < (int)ans.size(); ++i) n       printf( %d %d n , ans[i].first + 1, ans[i].second + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[100010], ans; n bool vis[100010]; n bool c[100010]; n void find(int v) { n   vis[v] = true; n   bool del = true; n   for (int u : adj[v]) { n     del &= c[u]; n     if (!vis[u]) find(u); n   } n   if (c[v] && del) ans.push_back(v); n } n int main() { n   int n; n   cin >> n; n   int root; n   for (int i = 1; i <= n; i++) { n     int p; n     cin >> p >> c[i]; n     if (p != -1) n       adj[p].push_back(i); n     else n       root = i; n   } n   find(root); n   sort(ans.begin(), ans.end()); n   if (ans.empty()) cout <<  -1 ; n   for (int v : ans) cout << v <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 111; n int N; n long long A[maxn]; n map<long long, long long> f; n void rl(long long &x) { n   char ch = (getchar()); n   x = 0; n   while ((ch <  0  || ch >  9 )) ch = (getchar()); n   while (!(ch <  0  || ch >  9 )) x = x * 10 + ch -  0 , ch = (getchar()); n } n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N; ++i) rl(A[i]); n   f[A[1] - 1] = 0; n   for (int i = 2; i <= N; ++i) n     for (map<long long, long long>::iterator j = f.lower_bound(A[i]); n          j != f.end(); f.erase(j++)) { n       long long x = j->first, y = j->second; n       f[x % A[i]] = max(f[x % A[i]], y + 1ll * (i - 1) * (x - x % A[i])); n       f[A[i] - 1] = n           max(f[A[i] - 1], y + 1ll * (i - 1) * A[i] * ((x - A[i] + 1) / A[i])); n     } n   long long ans = 0; n   for (map<long long, long long>::iterator i = f.begin(); i != f.end(); ++i) n     ans = max(ans, i->first * N + i->second); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int MN = 1e5 + 4, INF = 0x3f3f3f3f; n int N, R, M, ans, D, A[MN], depth[MN], ord[MN], ecnt, ein[MN], eout[MN], st[MN]; n std::vector<int> adj[MN]; n struct nd { n   int l, r, val; n   nd *ch[2]; n   nd() : l(0), r(0), val(INF), ch{0} {} n } * sgt[MN]; n void dfs(int src, int p, int d) { n   depth[src] = d; n   ein[src] = ++ecnt; n   for (int i : adj[src]) { n     if (i == p) continue; n     dfs(i, src, d + 1); n   } n   eout[src] = ecnt; n } n inline void upd(nd *n) { n->val = std::min(n->ch[0]->val, n->ch[1]->val); } n void build(nd *&n, int l, int r) { n   n = new nd(); n   n->l = l, n->r = r; n   if (l == r) return; n   int mid = l + r >> 1; n   build(n->ch[0], l, mid); n   build(n->ch[1], mid + 1, r); n } n void mod(nd *&n, nd *o, int p, int v) { n   n = new nd(); n   n->l = o->l, n->r = o->r; n   if (n->l == n->r) { n     n->val = v; n     return; n   } n   int mid = n->l + n->r >> 1; n   bool b = p > mid; n   n->ch[!b] = o->ch[!b]; n   mod(n->ch[b], o->ch[b], p, v); n   upd(n); n } n int qry(nd *n, int l, int r) { n   if (l > n->r || r < n->l) return INF; n   if (l <= n->l && n->r <= r) return n->val; n   return std::min(qry(n->ch[0], l, r), qry(n->ch[1], l, r)); n } n int main() { n   scanf( %d%d , &N, &R); n   for (int i = 1; i <= N; scanf( %d , A + i++)) n     ; n   for (int i = 1, a, b; i < N; ++i) { n     scanf( %d%d , &a, &b); n     adj[a].emplace_back(b); n     adj[b].emplace_back(a); n   } n   dfs(R, -1, 1); n   for (int i = 0; i < N; ++i) ord[i] = i + 1; n   std::stable_sort(ord, ord + N, [=](const int &a, const int &b) { n     return depth[a] < depth[b]; n   }); n   build(sgt[0], 1, N); n   for (int i = 0; i < N; ++i) { n     if (depth[ord[i]] != D) st[D++] = i; n     mod(sgt[i + 1], sgt[i], ein[ord[i]], A[ord[i]]); n   } n   st[D] = N; n   scanf( %d , &M); n   for (int i = 0, a, b; i < M; ++i) { n     scanf( %d%d , &a, &b); n     a = ((a + ans) % N) + 1, b = (b + ans) % N; n     printf( %d n , n            ans = qry(sgt[st[std::min(depth[a] + b, D)]], ein[a], eout[a])); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int L = 0, R = 1, U = 2, D = 3; n const int maxn = 5005; n class Node { n  public: n   int dir, l, r, u, d; n } a[maxn], b[maxn]; n int n, m; n char s[maxn]; n inline int id(int x, int y) { return x * m + y; } n inline void build(int x, int y) { n   Node &u = a[id(x, y)]; n   int nx, ny; n   for (nx = x, ny = y - 1; ny >= 0 && s[id(nx, ny)] ==  . ; --ny) n     ; n   if (ny < 0) n     u.l = -1; n   else n     u.l = id(nx, ny); n   for (nx = x, ny = y + 1; ny < m && s[id(nx, ny)] ==  . ; ++ny) n     ; n   if (ny >= m) n     u.r = -1; n   else n     u.r = id(nx, ny); n   for (nx = x - 1, ny = y; nx >= 0 && s[id(nx, ny)] ==  . ; --nx) n     ; n   if (nx < 0) n     u.u = -1; n   else n     u.u = id(nx, ny); n   for (nx = x + 1, ny = y; nx < n && s[id(nx, ny)] ==  . ; ++nx) n     ; n   if (nx >= n) n     u.d = -1; n   else n     u.d = id(nx, ny); n   return; n } n inline void connectX(int u, int v) { n   if (~u) b[u].r = v; n   if (~v) b[v].l = u; n } n inline void connectY(int u, int v) { n   if (~u) b[u].d = v; n   if (~v) b[v].u = u; n   return; n } n inline void erase(int u) { n   connectX(b[u].l, b[u].r); n   connectY(b[u].u, b[u].d); n   return; n } n inline void dfs(int x, int &res) { n   Node &u = b[x]; n   ++res; n   if (u.dir == L) { n     if (!~u.l) return; n     erase(x); n     dfs(u.l, res); n   } else if (u.dir == R) { n     if (!~u.r) return; n     erase(x); n     dfs(u.r, res); n   } else if (u.dir == U) { n     if (!~u.u) return; n     erase(x); n     dfs(u.u, res); n   } else { n     if (!~u.d) return; n     erase(x); n     dfs(u.d, res); n   } n   return; n } n int main() { n   cin >> n >> m; n   for (int i = (0); i < (n); ++i) { n     string buf; n     cin >> buf; n     for (int j = (0); j < (m); ++j) { n       s[id(i, j)] = buf[j]; n       if (buf[j] ==  L ) n         a[id(i, j)].dir = L; n       else if (buf[j] ==  R ) n         a[id(i, j)].dir = R; n       else if (buf[j] ==  U ) n         a[id(i, j)].dir = U; n       else if (buf[j] ==  D ) n         a[id(i, j)].dir = D; n     } n   } n   for (int x = (0); x < (n); ++x) n     for (int y = (0); y < (m); ++y) n       a[id(x, y)].l = a[id(x, y)].r = a[id(x, y)].u = a[id(x, y)].d = -1; n   for (int x = (0); x < (n); ++x) n     for (int y = (0); y < (m); ++y) build(x, y); n   int ans = 0, cnt = 0; n   for (int i = (0); i < (n); ++i) n     for (int j = (0); j < (m); ++j) n       if (s[id(i, j)] !=  . ) { n         for (int x = (0); x < (n); ++x) n           for (int y = (0); y < (m); ++y) b[id(x, y)] = a[id(x, y)]; n         int res = 0; n         dfs(id(i, j), res); n         if (res > ans) n           ans = res, cnt = 1; n         else if (res == ans) n           ++cnt; n       } n   printf( %d %d n , ans, cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[500010]; n int num[500010]; n int cnt; n long long t, mid; n int n; n int skip[500010]; n long long minn(long long a, long long b) { return a < b ? a : b; } n stack<int> sta; n int ok(long long k) { n   int i, j, end = -1, last, type = -1, cnt = 0; n   long long time = 0, min; n   for (i = 0; i < n; ++i) { n     ++time; n     if (s[i] ==  H ) { n       if (k) { n         --k; n         last = i; n         type = 0; n         continue; n       } n       type = 1; n       if (skip[i] == -1) { n         return 0; n       } n       time += (skip[i] - i) * 3; n       if (end != -1) { n         num[cnt++] = i - end; n       } n       num[cnt++] = skip[i] - i; n       end = skip[i]; n       last = skip[i]; n       i = skip[i]; n     } else if (s[i] ==  S ) { n       ++k; n     } n   } n   if (type == 0 && end != -1) { n     num[cnt++] = last - end; n   } n   time -= (n - 1 - last); n   min = time; n   for (i = cnt - 1; i >= 0; --i) { n     if (i & 1) { n       time += num[i]; n     } else { n       time -= num[i]; n       min = minn(min, time); n     } n   } n   return min <= t; n } n int main() { n   long long left, right; n   int i; n   cin >> n >> t >> s; n   memset(skip, -1, sizeof(skip)); n   for (i = 0; i < n; ++i) { n     if (s[i] ==  H ) { n       sta.push(i); n     } else if (s[i] ==  S ) { n       if (!sta.empty()) { n         skip[sta.top()] = i; n         sta.pop(); n       } n     } n   } n   left = 0; n   right = n + 1; n   while (left < right) { n     mid = (left + right) >> 1; n     if (ok(mid)) n       right = mid; n     else { n       left = mid + 1; n     } n   } n   if (right == n + 1) n     printf( -1 n ); n   else n     cout << left << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f, maxn = 200007; n const long long MOD = 998244353; n const long long LINF = 0x3f3f3f3f3f3f3f3fLL; n const long long P = 19260817; n char nc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n inline 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 << 3) + (x << 1) + ch -  0 , ch = getchar(); n   return x * f; n } n inline long long readll() { n   long long 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 << 3) + (x << 1) + ch -  0 , ch = getchar(); n   return x * f; n } n void write(int x) { n   if (!x) putchar( 0 ); n   if (x < 0) x = -x, putchar( - ); n   static int sta[20]; n   register int tot = 0; n   while (x) sta[tot++] = x % 10, x /= 10; n   while (tot) putchar(sta[--tot] + 48); n } n int mod1(int x) { n   if (x >= MOD) x -= MOD; n   return x; n } n int n, k; n int a[maxn], c[maxn]; n int lst[maxn]; n struct mcmf { n   struct edge { n     int to, nxt, c, val; n   } e[maxn << 1]; n   int tot = 1, head[maxn]; n   void addedge(int u, int v, int val, int cost) { n     e[++tot] = (edge){v, head[u], cost, val}; n     head[u] = tot; n     e[++tot] = (edge){u, head[v], -cost, 0}; n     head[v] = tot; n   } n   int s, t; n   int dis[maxn], pre[maxn], vis[maxn]; n   bool spfa() { n     queue<int> q; n     while (!q.empty()) q.pop(); n     memset(dis, 0x3f, sizeof(dis)); n     memset(vis, 0, sizeof(vis)); n     memset(pre, 0, sizeof(pre)); n     q.push(s); n     dis[s] = 0; n     vis[s] = 1; n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       vis[u] = 0; n       for (int i = head[u]; i; i = e[i].nxt) { n         int v = e[i].to; n         if (e[i].val && dis[v] > dis[u] + e[i].c) { n           dis[v] = dis[u] + e[i].c, pre[v] = i; n           if (!vis[v]) { n             vis[v] = true; n             q.push(v); n           } n         } n       } n     } n     return (pre[t] != 0); n   } n   int query() { n     int mc = 0, mf = 0; n     while (spfa()) { n       int flow = INF; n       for (int i = pre[t]; i; i = pre[e[i ^ 1].to]) flow = min(flow, e[i].val); n       mf += flow; n       for (int i = pre[t]; i; i = pre[e[i ^ 1].to]) { n         e[i].val -= flow, e[i ^ 1].val += flow, mc += flow * e[i].c; n       } n     } n     return mc; n   } n } F; n vector<int> v; n int main() { n   scanf( %d%d , &n, &k); 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   int sum = 0; n   v.push_back(0); n   for (int i = 1; i <= n; i++) n     if (a[i] != a[i - 1]) v.push_back(a[i]); n   n = v.size() - 1; n   for (int i = 1; i <= n; i++) { n     sum += c[v[i]]; n     if (lst[v[i]]) F.addedge(lst[v[i]] + 1, i, 1, -c[v[i]]); n     lst[v[i]] = i; n     if (i != n) F.addedge(i, i + 1, k - 1, 0); n   } n   F.s = n + 1, F.t = n + 2; n   F.addedge(F.s, 1, k - 1, 0); n   F.addedge(n, F.t, k - 1, 0); n   printf( %d , sum + F.query()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, flag = 1, num = 0; n   cin >> n; n   string st; n   cin >> st; n   for (int i = 0; i < n && flag; i++) { n     if (i < n - 1) { n       if (st[i] == st[i + 1]) { n         if (st[i] !=  ? ) { n           flag = 0; n         } else { n           num = 1; n         } n       } n     } n     if (st[i] ==  ? ) { n       if (i == 0 || i == n - 1) n         num += 1; n       else { n         if (st[i - 1] == st[i + 1]) num += 1; n       } n     } n   } n   if (flag == 0) n     cout <<  No ; n   else { n     if (num >= 1) n       cout <<  Yes ; n     else n       cout <<  No ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int k, t; n char n1[10005]; n char n2[10005]; n int swapindex[2]; n bool same(char x[], char y[], int n) { n   for (int i = 0; i < n; i++) { n     if (x[i] != y[i]) { n       return false; n     } n   } n   return true; n } n int ham(char x[], char y[], int n) { n   int temp = 0; n   for (int i = 0; i < n; i++) { n     if (x[i] != y[i]) { n       temp++; n     } n   } n   return temp; n } n int main() { n   cin >> k; n   for (int i = 0; i < k; i++) { n     cin >> t; n     for (int l = 0; l < t; l++) { n       cin >> n1[l]; n     } n     for (int l = 0; l < t; l++) { n       cin >> n2[l]; n     } n     if (ham(n1, n2, t) == 2) { n       int temp = 0; n       for (int i = 0; i < t; i++) { n         if (n1[i] != n2[i]) { n           swapindex[temp] = i; n           temp++; n         } n       } n       swap(n1[swapindex[0]], n2[swapindex[1]]); n       if (same(n1, n2, t)) { n         cout <<  Yes  << endl; n       } else { n         cout <<  No  << endl; n       } n     } else { n       cout <<  No  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100005]; n long long k; n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   long long sum = accumulate(a, a + n, 0LL); n   if (sum < k) n     cout << -1 << endl; n   else { n     long long L = 0, R = 1 << 30; n     while (L < R) { n       long long mid = (L + R + 1) / 2, cur = 0; n       for (int i = 0; i < n; i++) cur += min(mid, (long long)a[i]); n       if (cur > k) n         R = mid - 1; n       else n         L = mid; n     } n     long long cur = k; n     for (int i = 0; i < n; i++) cur -= min((long long)a[i], L); n     queue<pair<int, int> > q; n     for (int i = 0; i < n; i++) n       if (a[i] - L > 0) q.push(make_pair(i, a[i] - L)); n     while (cur--) { n       pair<int, int> p = q.front(); n       q.pop(); n       if (p.second - 1 > 0) q.push(make_pair(p.first, p.second - 1)); n     } n     while (!q.empty()) { n       pair<int, int> p = q.front(); n       q.pop(); n       cout << p.first + 1 <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long long sum = 0, sum_mas; n   cin >> n; n   vector<int> mas; n   for (int i = 0, temp = 0; i < n; i++) { n     cin >> temp; n     sum += temp; n     mas.push_back(temp); n   } n   sum_mas = sum; n   sort(mas.begin(), mas.end()); n   for (int i = 0; i < n; i++) { n     sum += sum_mas; n     sum_mas -= mas[i]; n   } n   cout << sum - mas[mas.size() - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class A, class B> n ostream& operator<<(ostream& os, const pair<A, B>& p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <class T> n auto operator<<(ostream& os, T&& x) -> decltype(x.begin(), os) { n   os <<  { ; n   for (auto it = x.begin(); it != x.end(); ++it) n     os << *it << (it == prev(x.end()) ?    :  ,  ); n   return os <<  } ; n } n void dump() {} n template <class T, class... Args> n void dump(T&& x, Args... args) { n   cerr << x <<  ;   ; n   dump(args...); n } n int t, n, m; n void solve() { n   cin >> n >> m; n   bool ans = false; n   for (int i = 0; i < n; ++i) { n     int x, y, z, w; n     cin >> x >> y >> z >> w; n     if (y == z) ans = true; n   } n   if (m % 2 == 0 && ans) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n int main() { n   ios::sync_with_stdio(false); n   for (cin >> t; t--;) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, yu, one, sum, cnt = 3; n long long ans[4]; n long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } n int main() { n   scanf( %I64d , &n); n   if (!(n % 3)) n     printf( 1 1 %I64d , n - 2); n   else n     printf( 1 2 %I64d , n - 3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct tree { n   int lf; n   int rt; n   int we; n } a[2000010]; n int v[2000010]; n int main() { n   int n; n   scanf( %d , &n); n   for (int j = 0; j < n - 1; j++) { n     scanf( %d%d , &a[j].lf, &a[j].rt); n     a[j].we = -1; n     v[a[j].lf]++; n     v[a[j].rt]++; n   } n   int maxi = 0, ans = -1, p = 0; n   for (int j = 0; j < 2000010; j++) { n     if (maxi < v[j]) { n       maxi = v[j]; n       ans = j; n     } n   } n   for (int j = 0; j < n - 1; j++) n     if ((a[j].lf == ans || a[j].rt == ans) && a[j].we == -1) a[j].we = p++; n   for (int j = 0; j < n - 1; j++) n     if (a[j].we == -1) a[j].we = p++; n   for (int j = 0; j < n - 1; j++) printf( %d n , a[j].we); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.size(); n   n = (s[n - 2] - 48) * 10 + (s[n - 1] - 48); n   if (n % 4) n     cout <<  0 ; n   else n     cout <<  4 ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 121; n int a[N], b[N], last[N], kol, ans, v, u, i, n; n inline void add(int v, int u) { n   a[++kol] = u; n   b[kol] = last[v]; n   last[v] = kol; n } n void dfs(int v, int p, int len) { n   if (len == 2) { n     ++ans; n     return; n   } n   int x = last[v]; n   while (x) { n     if (a[x] != p) dfs(a[x], v, len + 1); n     x = b[x]; n   } n } n int main() { n   cin >> n; n   for (i = 1; i < n; ++i) { n     cin >> v >> u; n     add(v, u); n     add(u, v); n   } n   for (i = 1; i <= n; ++i) dfs(i, 0, 0); n   cout << ans / 2 << endl; 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     int v[1000]; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> v[i]; n       v[i] = abs(v[i]); n     } n     int signo = 1; n     for (int i = 0; i < n - 1; i++) { n       cout << v[i] * signo <<    ; n       signo *= -1; n     } n     cout << v[n - 1] * signo << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline long long lin() { n   long long x; n   scanf( %lld , &x); n   return x; n } n const long long maxn = 200 + 10; n const long long inf = 1e18 + 1; n long long a[maxn][maxn], mini[maxn], res[maxn], dp[maxn][maxn], id[maxn], n     what[maxn]; n long long N; n inline void calcDp() { n   memset(dp, 0, sizeof dp); n   dp[N][0] = 1; n   for (long long i = N - 1; i >= 0; i--) { n     for (long long j = 0; j <= i; j++) { n       dp[i][j] = min(dp[i + 1][j + 1] * bool(what[i] != 1) + n                          (j && what[i] != 0 ? dp[i + 1][j - 1] : 0), n                      inf); n     } n   } n } n int32_t main() { n   long long n = in(), m = in(), k = lin(); n   N = n + m - 1; n   memset(mini, 63, sizeof mini); n   memset(res, -1, sizeof res); n   memset(what, -1, sizeof what); n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < m; j++) a[i][j] = in(); n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) mini[i + j] = min(mini[i + j], a[i][j]); n   } n   iota(id, id + n + m - 1, 0); n   sort(id, id + n + m - 1, [](const long long &a, const long long &b) { n     return mini[a] < mini[b]; n   }); n   for (long long _ = 0; _ < n + m - 1; _++) { n     long long i = id[_]; n     what[i] = 0; n     calcDp(); n     if (dp[0][0] >= k) continue; n     k -= dp[0][0]; n     what[i] = 1; n   } n   for (long long i = 0; i < n; i++, cout <<   n ) { n     for (long long j = 0; j < m; j++) { n       cout << (what[i + j] == 0 ?  (  :  ) ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> cnt(n); n   for (int i = 0; i < n; ++i) cin >> cnt[i]; n   sort(cnt.begin(), cnt.end(), greater<int>()); n   long long ans = 0; n   int prev = 1000000001; n   for (int i = 0; i < n; ++i) { n     if (cnt[i] >= prev) cnt[i] = prev - 1; n     prev = max(cnt[i], 0); n     ans += prev; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void parseArray(long long* A, long long n) { n   for (long long K = 0; K < n; K++) { n     cin >> A[K]; n   } n } n long long modInverse(long long a, long long b) { n   return 1 < a ? b - modInverse(b % a, a) * b / a : 1; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long double dist(long long x, long long y, long long a, long long b) { n   return sqrt((x - a) * (x - a) + (y - b) * (y - b)); n } n void debug(long long* a, long long n) { n   for (int k = 0; k < n; k++) { n     cout << a[k] <<    ; n   } n   cerr <<   n ; n } n long long mod = 1000000007; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   long long n; n   cin >> n; n   long long ans[n + 1]; n   memset(ans, 0, sizeof ans); n   long long id = 1; n   for (int k = 2; k <= n; k++) { n     if (ans[k] == 0) { n       for (int j = k; j <= n; j += k) { n         ans[j] = id; n       } n       id++; n     } n   } n   for (int k = 2; k <= n; k++) { n     cout << ans[k] <<    ; n   } n   cout << 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   cout.tie(0); n   int n; n   int sum, c = 0; n   cin >> n; n   int arr[3]; n   for (int i = 0; i < n; i++) { n     for (int i = 0; i < 3; i++) { n       cin >> arr[i]; n     } n     sum = arr[0] + arr[1] + arr[2]; n     if (sum > 1) c++; n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n inline void read(T &x) { n   x = 0; n   char c = getchar(); n   bool flag = false; n   while (!isdigit(c)) { n     if (c ==  - ) flag = true; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); n   if (flag) x = -x; n } n using namespace std; n const int P = 1e9 + 7; n const int inv2 = (P + 1) / 2; n inline long long quickpow(long long x, long long k) { n   long long res = 1; n   x %= P; n   while (k) { n     if (k & 1) res = res * x % P; n     x = x * x % P; n     k >>= 1; n   } n   return res; n } n int k; n long long s[230][230], tri[230][230], jie[230], jieni[230]; n inline void init() { n   s[0][0] = 1; n   for (int i = 1; i <= k; ++i) n     for (int j = 1; j <= i; ++j) n       s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * (i - 1)) % P; n   tri[1][1] = 1; n   for (int i = 2; i <= k + 1; ++i) n     for (int j = 1; j <= i; ++j) n       tri[i][j] = (tri[i - 1][j - 1] + tri[i - 1][j]) % P; n   jie[0] = jieni[0] = 1; n   for (int i = 1; i <= k; ++i) jie[i] = jie[i - 1] * i % P; n   jieni[k] = quickpow(jie[k], P - 2); n   for (int i = k - 1; i; --i) jieni[i] = jieni[i + 1] * (i + 1) % P; n } n inline long long get_c(int n, int m) { n   if (n < 0 || m < 0 || n - m < 0) return 0; n   return tri[n + 1][m + 1]; n } n struct Complex { n   long long a, b; n   Complex() { a = 0, b = 0; } n   Complex(long long jzp, long long zzz) { a = jzp, b = zzz; } n } phi, phihat; n inline Complex operator+(const Complex &a, const Complex &b) { n   return Complex((a.a + b.a) % P, (a.b + b.b) % P); n } n inline Complex operator-(const Complex &a, const Complex &b) { n   return Complex((a.a - b.a) % P, (a.b - b.b) % P); n } n inline Complex operator*(const Complex &a, const Complex &b) { n   return Complex((a.a * b.a + 5 * a.b * b.b) % P, (a.a * b.b + a.b * b.a) % P); n } n inline Complex get_inv(Complex x) { n   long long a = x.a, b = x.b; n   if (!b) return Complex(quickpow(a, P - 2), 0); n   long long d = b * quickpow((5ll * b * b - a * a) % P, P - 2) % P; n   long long c = -a * quickpow(b, P - 2) % P * d % P; n   Complex res = Complex(c, d); n   return res; n } n inline Complex Pow(Complex x, long long k) { n   Complex res(1, 0); n   while (k) { n     if (k & 1) res = res * x; n     x = x * x; n     k >>= 1; n   } n   return res; n } n inline long long work(long long n) { n   Complex ans; n   for (int j = 0; j <= k; ++j) { n     Complex res; n     for (int d = 0; d <= j; ++d) { n       Complex A = Pow(phi, d) * Pow(phihat, j - d); n       if (A.a == 1 && A.b == 0) { n         if ((j - d) & 1) n           res = res - Complex(n % P * get_c(j, d) % P, 0); n         else n           res = res + Complex(n % P * get_c(j, d) % P, 0); n       } n       A = A * (Complex(1, 0) - Pow(A, n)) * get_inv(Complex(1, 0) - A); n       if ((j - d) & 1) n         res = res - Complex(get_c(j, d), 0) * A; n       else n         res = res + Complex(get_c(j, d), 0) * A; n     } n     if ((k - j) & 1) n       ans = ans - Complex(s[k][j], 0) * Pow(get_inv(Complex(0, 1)), j) * res; n     else n       ans = ans + Complex(s[k][j], 0) * Pow(get_inv(Complex(0, 1)), j) * res; n   } n   ans = ans * Complex(jieni[k], 0); n   if (ans.b) puts( wawa ); n   return ans.a; n } n int main() { n   phi = Complex(inv2, inv2); n   phihat = Complex(inv2, P - inv2); n   read(k); n   init(); n   long long l, r; n   read(l), read(r); n   l += 2; n   r += 2; n   long long ans = work(r) - work(l - 1); n   printf( %lld n , (ans % P + P) % P); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t0, t1, t2, x1, x2; n long long count(long long y1, long long y2) { n   return t1 * y1 + t2 * y2 - t0 * (y1 + y2); n } n int main() { n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   if (t1 == t2) { n     cout << x1 <<     << x2; n     return 0; n   } n   long long by1 = 0, by2 = x2; n   for (long long y1 = 0; y1 <= x1; y1++) { n     long long l = (y1 == 0 ? 1 : 0), r = x2; n     while (l <= r) { n       long long m = (l + r) / 2; n       long long c = count(y1, m); n       if (c < 0) n         l = m + 1; n       else { n         if ((t1 * y1 + t2 * m) * (by1 + by2) < n                 (t1 * by1 + t2 * by2) * (y1 + m) || n             ((t1 * y1 + t2 * m) * (by1 + by2) == n                  (t1 * by1 + t2 * by2) * (y1 + m) && n              (by1 + by2) < (y1 + m))) { n           by1 = y1; n           by2 = m; n         } n         r = m - (r == m ? 1 : 0); n       } n     } n   } n   cout << by1 <<     << by2; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   cout <<  0  <<     <<  0  <<     << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, b, a[22222], mx = 0; n   cin >> n >> b; n   mx = b; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) { n     int k = b / a[i]; n     int s = b % a[i]; n     for (int j = i + 1; j < n; j++) { n       int p = a[j] * k + s; n       mx = max(mx, p); n     } n   } n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int i, j, n, max = -1, count, a; n   char c1, c2; n   scanf( %d , &n); n   char s[n]; n   scanf( %s , s); n   for (i = 0; i < n - 1; i++) { n     count = 0; n     for (j = i + 1; j < n - 1; j++) { n       if (s[j] == s[i]) { n         if (s[j + 1] == s[i + 1]) count++; n       } n     } n     if (count > max) { n       max = count; n       c1 = s[i]; n       c2 = s[i + 1]; n     } n   } n   printf( %c%c n , c1, c2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   set<long long> a = {1, n}; n   for (long long d = 2; d <= min((long long)sqrt(n) + 10, n - 1); d++) { n     if (n % d == 0) { n       a.insert(d); n       a.insert(n / d); n     } n   } n   long long ans = -1; n   if (a.size() >= k) { n     auto it = next(a.begin(), k - 1); n     ans = *it; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const int N = 405; n int x, y, n, d, a[25][2], memo[N][N]; n bool check(int i, int j) { return i * i + j * j <= d * d; } n int solve(int i, int j) { n   int &ans = memo[i + 200][j + 200]; n   if (~ans) return ans; n   set<int> st; n   for (int k = 0; k < n; k++) n     if (check(i + a[k][0], j + a[k][1])) n       st.insert(solve(i + a[k][0], j + a[k][1])); n   int mex = 0; n   while (st.count(mex)) mex++; n   return ans = mex; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> x >> y >> n >> d; n   for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; n   memset(memo, -1, sizeof memo); n   cout << (solve(x, y) ?  Anton  :  Dasha ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v, vv, vv2; n int main() { n   long long t, n, a[1000], k, f = 0; n   cin >> n; n   string s; n   cin >> s; n   int cnt = 0; n   for (int i = 0; i < s.size() && cnt >= -1; i++) { n     if (s[i] ==  ( ) n       cnt++; n     else n       cnt--; n   } n   if (!cnt) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int a[n]; n   for (int i = 0; i < n; i++) a[i] = s[i] - 48; n   int c1 = 0; n   for (int i = 0; i < n; i++) { n     if (n % 2 && i == n - 1) { n       if (!a[i]) c1 += 1; n     } else { n       if (a[i] == a[i + 1]) n         c1 += 1; n       else if (a[i] == 0 && a[i + 1] == 1) n         c1 += 2; n       i++; n     } n   } n   int c2 = 0; n   for (int i = 0; i < n; i++) { n     if (n % 2 && i == n - 1) { n       if (a[i]) c2 += 1; n     } else { n       if (a[i] == a[i + 1]) n         c2 += 1; n       else if (a[i] == 1 && a[i + 1] == 0) n         c2 += 2; n       i++; n     } n   } n   cout << min(c1, c2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int> > a(n); n   for (int i = (0); i < ((n)); ++i) cin >> a[i].first >> a[i].second; n   sort(a.begin(), a.end()); n   long long best = -1; n   vector<long long> dp(n, 0); n   for (int i = n - 1; i >= 0; --i) { n     dp[i] = -1; n     long long prev = 0; n     for (int j = i; j < n; ++j) { n       prev += a[j].first - a[i].first; n       long long cost = a[i].second + prev + (j == n - 1 ? 0 : dp[j + 1]); n       if (dp[i] == -1 || dp[i] > cost) { n         dp[i] = cost; n       } n     } n     if (dp[i] == -1) dp[i] = a[i].second; n   } n   cout << dp[0] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long re = 0, flag = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) flag = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) re = (re << 1) + (re << 3) + ch -  0 , ch = getchar(); n   return re * flag; n } n long long n, mx, m, ans; n namespace seg { n long long seg[1000010]; n inline void update(long long num) { n   seg[num] = seg[num << 1] + seg[num << 1 | 1]; n } n inline void add(long long l, long long r, long long num, long long pos) { n   if (l == r) { n     seg[num] = 1; n     return; n   } n   long long mid = (l + r) >> 1; n   if (mid >= pos) n     add(l, mid, num << 1, pos); n   else n     add(mid + 1, r, num << 1 | 1, pos); n   update(num); n } n inline long long query(long long l, long long r, long long ql, long long qr, n                        long long num) { n   if (l >= ql && r <= qr) return seg[num]; n   long long mid = (l + r) >> 1, re = 0; n   if (mid >= ql) re += query(l, mid, ql, qr, num << 1); n   if (mid < qr) re += query(mid + 1, r, ql, qr, num << 1 | 1); n   return re; n } n }  // namespace seg n struct node { n   long long x, y; n } a[200010]; n inline bool cmp1(const node &a, const node &b) { return a.x < b.x; } n inline bool cmp2(const node &a, const node &b) { n   if (a.y != b.y) return a.y < b.y; n   return a.x > b.x; n } n int main() { n   n = read(); n   long long i, j, k; n   for (i = 1; i <= n; i++) a[i].x = read(), a[i].y = read(); n   sort(a + 1, a + n + 1, cmp1); n   for (i = 1; i <= n; i = j + 1) { n     m++; n     j = i; n     while (j < n && a[j + 1].x == a[i].x) a[++j].x = m; n     a[i].x = m; n   } n   sort(a + 1, a + n + 1, cmp2); n   for (i = 1; i <= n; i = j + 1) { n     mx++; n     j = i; n     while (j < n && a[j + 1].y == a[i].y) a[++j].y = mx; n     a[i].y = mx; n   } n   reverse(a + 1, a + n + 1); n   for (i = 1; i <= n; i = j + 1) { n     j = i; n     while (j < n && a[j + 1].y == a[i].y) j++; n     for (k = i; k <= j; k++) { n       seg::add(1, m, 1, a[k].x); n     } n     for (k = i; k <= j; k++) { n       ans += seg::query(1, m, ((k == i) ? 1 : a[k - 1].x + 1), a[k].x, 1) * n              seg::query(1, m, a[k].x, m, 1); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n void solve() { n   cin >> n >> k; n   if (n < k) { n     cout << k - n <<   n ; n     return; n   } n   if ((n % 2 == 0 and k % 2 == 0) or (n % 2 == 1 and k % 2 == 1)) n     cout << 0 <<   n ; n   else n     cout << 1 <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long t; n   cin >> t; n   for (long long i = 1; i <= t; i++) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, i; n   int rs = 1; n   int temp_rs = 1; n   cin >> n >> k; n   int mang[n]; n   for (i = 0; i < n; i++) { n     cin >> mang[i]; n     if (i > 0) { n       if (mang[i] != mang[i - 1]) { n         rs += 1; n       } else { n         rs = 1; n       } n       if (rs > temp_rs) { n         temp_rs = rs; n       } n     } n   } n   cout << temp_rs; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s, t; n int l[200005], r[200005], last[200005]; n int main() { n   cin >> s >> t; n   memset(last, -1, sizeof(last)); n   int j = 0, slen = s.size(), tlen = t.size(); n   for (int i = 0; i < slen; i++) { n     l[i] = last[s[i] -  a ]; n     if (j < tlen && s[i] == t[j]) { n       l[i] = j; n       j++; n     } n     last[s[i] -  a ] = l[i]; n   } n   memset(last, -1, sizeof(last)); n   j = tlen - 1; n   for (int i = slen - 1; i >= 0; i--) { n     r[i] = last[s[i] -  a ]; n     if (j >= 0 && s[i] == t[j]) { n       r[i] = j; n       j--; n     } n     last[s[i] -  a ] = r[i]; n   } n   bool ok = true; n   for (int i = 0; i < slen; i++) { n     if (l[i] == -1 || r[i] == -1 || l[i] < r[i]) { n       ok = false; n       break; n     } n   } n   if (ok) n     cout <<  yes  << endl; n   else n     cout <<  no  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long mod1 = 998244353; n const double pie = 3.1415926535; n long long power(long long x, long long y) { n   if (y == 0) n     return 1; n   else { n     if (y % 2 == 0) n       return power(x * x, y / 2); n     else n       return x * power(x * x, (y - 1) / 2); n   } n } n long long mod_power(long long x, long long y, long long m) { n   long long r = 1; n   x = x % m; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) r = (r * x) % m; n     y = y / 2; n     x = (x * x) % m; n   } n   return r; n } n unsigned long long gcd(unsigned long long x, unsigned long long y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n vector<long long> extended_Euclid(long long a, long long b) { n   vector<long long> v(3); n   if (b == 0) { n     v[0] = a; n     v[1] = 1; n     v[2] = 0; n     return v; n   } else { n     vector<long long> v1 = extended_Euclid(b, a % b); n     v[0] = v1[0]; n     v[1] = v1[2]; n     v[2] = v1[1] - (a / b) * v1[2]; n     return v; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int TESTS = 1; n   while (TESTS--) { n     int n, k; n     cin >> n >> k; n     vector<vector<int> > adj; n     long long t = 0; n     int flag = 0; n     for (int i = 0; i < k; i++) { n       int m; n       cin >> m; n       vector<int> v(m); n       for (int i = 0; i < m; i++) cin >> v[i]; n       if (v[0] == 1) { n         for (int i = 1; i < m; i++) { n           if (v[i] == (v[i - 1] + 1)) n             flag++; n           else n             break; n         } n         t += m - 1 - flag; n       } else n         t += m - 1; n     } n     long long ans = t + n - flag - 1; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-5; n const long double PI = acos(-1); n const int INF = (int)1e9; n const long long INFF = (long long)1e18; n const int mod = (int)1e9 + 7; n const int MXN = (int)3e5 + 7; n int main(void) { n   int n; n   cin >> n; n   puts(n == 2 ?  2  :  1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[5]; n   int dp[350][350]; n   int n; n   int i, j, k; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   if (n == 1) { n     if (a[0] != 0) n       printf( BitLGM n ); n     else n       printf( BitAryo n ); n   } n   if (n == 2) { n     int mx = max(a[0], a[1]); n     for (i = 1; i <= mx; i++) { n       dp[i][0] = 1; n       dp[0][i] = 1; n     } n     for (i = 1; i <= a[0]; i++) { n       for (j = 1; j <= a[1]; j++) { n         for (k = 1; k < i; k++) { n           if (dp[i - k][j] == 0) { n             dp[i][j] = 1; n             break; n           } n         } n         for (k = 1; k < j; k++) { n           if (dp[i][j - k] == 0) { n             dp[i][j] = 1; n             break; n           } n         } n         for (k = 1; k <= min(i, j); k++) { n           if (dp[i - k][j - k] == 0) { n             dp[i][j] = 1; n             break; n           } n         } n       } n     } n     if (dp[a[0]][a[1]] == 1) n       printf( BitLGM n ); n     else n       printf( BitAryo n ); n   } n   if (n == 3) { n     int g = 0; n     g = g ^ a[0]; n     g = g ^ a[1]; n     g = g ^ a[2]; n     if (g != 0) n       printf( BitLGM n ); n     else n       printf( BitAryo n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, r1, r2, t1, t2, f1 = 1, f2 = 1, col[100010]; n vector<vector<int>> graph; n bool dfs(const int &v, const int &from, const int &color) { n   if (col[v] != color) return 0; n   for (auto &i : graph[v]) n     if (i != from) n       if (!dfs(i, v, color)) return 0; n   return 1; n } n int main() { n   scanf( %d , &n); n   graph.resize(n + 1); n   for (int i = 1; i < n; ++i) { n     scanf( %d%d , &r1, &r2); n     graph[r1].push_back(r2); n     graph[r2].push_back(r1); n   } n   for (int i = 1; i <= n; ++i) scanf( %d , &col[i]); n   for (int i = 1; i <= n; ++i) n     for (auto &j : graph[i]) n       if (col[i] != col[j]) { n         t1 = i; n         t2 = j; n         break; n       } n   if (!t1) { n     printf( YES n1 ); n     return 0; n   } n   for (auto &i : graph[t1]) f1 &= dfs(i, t1, col[i]); n   for (auto &i : graph[t2]) f2 &= dfs(i, t2, col[i]); n   if (f1) n     printf( YES n%d , t1); n   else if (f2) n     printf( YES n%d , t2); n   else n     printf( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n int convexP = 0; n const int SQ = 1075; n const long long mini = -8e18; n bool isErased[300001]; n long long type[300001], a[300001], b[300001]; n long long out[300001]; n long long la[300001], lb[300001]; n int convexSz, p; n double cross(int x, int y) { return (double)(lb[y] - lb[x]) / (la[x] - la[y]); } n void insert(long long m, long long b) { n   if (convexSz > 0) { n     if (la[convexSz - 1] == m) { n       lb[convexSz - 1] = min(lb[convexSz - 1], b); n     } else { n       la[convexSz] = m; n       lb[convexSz++] = b; n     } n   } else { n     la[convexSz] = m; n     lb[convexSz++] = b; n   } n   while (convexSz >= 3 && cross(convexSz - 3, convexSz - 2) > n                               cross(convexSz - 2, convexSz - 1)) { n     swap(la[convexSz - 2], la[convexSz - 1]); n     swap(lb[convexSz - 2], lb[convexSz - 1]); n     --convexSz; n   } n } n long long query(long long x) { n   if (convexSz == 0) { n     return mini; n   } n   while (p + 1 < convexSz && cross(p, p + 1) <= x) p++; n   return -(lb[p] + la[p] * x); n } n pair<pair<long long, long long>, int> ret[300001]; n pair<pair<long long, long long>, int> v[300001]; n pair<pair<long long, long long>, int> u[300001]; n pair<pair<long long, long long>, int> g[300001]; n void merge(int &arSize, int st, int ed) { n   int usz = 0; n   for (int i = st; i <= ed; ++i) { n     if (!isErased[i] && type[i] == 1) { n       u[usz++] = {{-a[i], -b[i]}, i}; n     } n   } n   sort(u, u + usz, greater<pair<pair<int, int>, int> >()); n   int sz0 = 0, sz1 = 0, rpos = 0; n   while (sz0 < arSize && sz1 < usz) { n     if (v[sz0].first.first > u[sz1].first.first) { n       ret[rpos++] = (v[sz0++]); n     } else { n       ret[rpos++] = (u[sz1++]); n     } n   } n   while (sz0 < arSize) { n     ret[rpos++] = (v[sz0++]); n   } n   while (sz1 < usz) { n     ret[rpos++] = (u[sz1++]); n   } n   arSize = rpos; n   for (int i = 0; i < arSize; ++i) { n     v[i] = ret[i]; n   } n } n pair<long long, long long> q[300001]; n int ttt[300001]; n void solve() { n   int n; n   scanf( %d  , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld %lld , &type[i], &a[i]); n     if (type[i] == 1) { n       scanf( %lld  , &b[i]); n     } n     out[i] = mini; n   } n   int pos = 0; n   int vsz = 0; n   for (int i = 1; i <= n; i += SQ) { n     int ed = min(n, i + SQ - 1); n     int sz = 0; n     int gsz = 0; n     for (int j = i; j <= ed; ++j) { n       if (type[j] == 2 && a[j] < i) { n         isErased[a[j]] = true; n         int id = a[j]; n         g[gsz++] = {{a[id], b[id]}, j}; n       } n     } n     int tsz = 0; n     for (int j = 0; j < vsz; ++j) { n       if (!isErased[v[j].second]) { n         v[sz++] = v[j]; n       } n     } n     vsz = sz; n     convexSz = 0; n     p = 0; n     for (int j = 0; j < vsz; ++j) { n       insert(v[j].first.first, v[j].first.second); n     } n     int qsz = 0; n     for (int j = i; j <= ed; ++j) { n       q[qsz++] = {a[j], j}; n     } n     sort(q, q + qsz); n     if (convexSz > 0) n       for (int j = 0; j < qsz; ++j) { n         out[q[j].second] = query(q[j].first); n       } n     int tttsz = 0; n     for (int j = i; j <= ed; ++j) { n       if (type[j] == 3) { n         for (int k = 0; k < tttsz; ++k) { n           int tid = ttt[k]; n           if (!isErased[tid]) out[j] = max(out[j], a[tid] * a[j] + b[tid]); n         } n         for (int k = gsz - 1; k >= 0; --k) { n           if (g[k].second < j) { n             break; n           } n           out[j] = max(out[j], g[k].first.first * a[j] + g[k].first.second); n         } n       } else if (type[j] == 2) { n         isErased[a[j]] = true; n       } else { n         ttt[tttsz++] = j; n       } n     } n     merge(vsz, i, ed); n   } n   for (int i = 1; i <= n; ++i) { n     if (type[i] == 3) { n       if (out[i] != mini) n         printf( %lld n , out[i]); n       else n         printf( EMPTY SET n ); n     } n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXK = 3000; n struct Update { n   int cost; n   long long profit; n }; n struct CommutativeUndoableDS { n   vector<array<long long, MAXK + 1> > dp; n   CommutativeUndoableDS() { n     dp.emplace_back(); n     fill(dp.back().begin(), dp.back().end(), 0); n   } n   void addUpdate(Update u) { n     int sz = dp.size(); n     dp.push_back(dp.back()); n     for (int i = MAXK; i >= u.cost; i--) { n       dp[sz][i] = max(dp[sz][i], dp[sz - 1][i - u.cost] + u.profit); n     } n   } n   void undoLastUpdate() { n     dp.pop_back(); n     assert(!dp.empty()); n   } n   long long operator[](int i) { return dp.back()[i]; } n }; n struct QueueUndoDS { n   vector<pair<Update, int> > qyu; n   CommutativeUndoableDS ds; n   int rem_a; n   QueueUndoDS() { rem_a = 0; } n   void pushBack(pair<Update, int> u) { n     ds.addUpdate(u.first); n     qyu.emplace_back(u); n   } n   void pushBack(Update u) { pushBack(pair<Update, int>(u, 1)); } n   void popFront() { n     assert(!qyu.empty()); n     if (rem_a == 0) { n       rem_a = qyu.size(); n       for (int i = 0; i < rem_a; i++) ds.undoLastUpdate(); n       reverse(qyu.begin(), qyu.end()); n       for (pair<Update, int> &u : qyu) { n         u.second = 0; n         ds.addUpdate(u.first); n       } n     } n     vector<pair<Update, int> > popped[2]; n     while (qyu.back().second == 1) { n       popped[1].push_back(qyu.back()); n       qyu.pop_back(); n       ds.undoLastUpdate(); n     } n     int sz = rem_a & (-rem_a); n     for (int i = 0; i < sz; i++) { n       assert(qyu.back().second == 0); n       popped[0].push_back(qyu.back()); n       qyu.pop_back(); n       ds.undoLastUpdate(); n     } n     for (int z : {1, 0}) { n       reverse(popped[z].begin(), popped[z].end()); n       for (pair<Update, int> &u : popped[z]) pushBack(u); n     } n     assert(qyu.back().second == 0); n     ds.undoLastUpdate(); n     qyu.pop_back(); n     rem_a--; n   } n }; n vector<long long> a[MAXK]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   QueueUndoDS qds; n   for (int i = 1; i <= n; i++) { n     int sz; n     cin >> sz; n     a[i].resize(sz + 1); n     for (int j = 1; j <= sz; j++) { n       cin >> a[i][j]; n       a[i][j] += a[i][j - 1]; n     } n     if (sz > k) a[i].resize(k + 1); n     qds.pushBack({(int)a[i].size() - 1, a[i].back()}); n   } n   long long ans = -1; n   for (int i = 1; i <= n; i++) { n     qds.popFront(); n     for (int j = 0; j < a[i].size(); j++) { n       ans = max(ans, a[i][j] + qds.ds[k - j]); n     } n     qds.pushBack({(int)a[i].size() - 1, a[i].back()}); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n constexpr int maxn = 1e6 + 7; n struct DSU { n   vector<int> f; n   void init(int n) { n     f.resize(n + 1); n     iota(f.begin(), f.end(), 0); n   } n   int seek(int x) { return x == f[x] ? x : (f[x] = seek(f[x])); } n   bool same(int u, int v) { return seek(u) == seek(v); } n   void Merge(int u, int v) { f[seek(u)] = seek(v); } n } dsu; n vector<int> prime[maxn]; n set<pair<int, int> > onepath; n void solve() { n   dsu.init(maxn); n   int n, m, mx = 0; n   scanf( %d %d , &n, &m); n   vector<int> vec(n + 1, 0); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &vec[i]); n     mx = max(mx, vec[i]); n   } n   for (int i = 2; i <= mx + 1; ++i) { n     if (!prime[i].size()) { n       for (int j = i; j <= mx + 1; j += i) { n         prime[j].push_back(i); n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (auto fac : prime[vec[i]]) { n       dsu.Merge(vec[i], fac); n     } n   } n   for (int i = 1; i <= n; ++i) { n     vector<int> has = prime[vec[i] + 1]; n     has.push_back(vec[i]); n     for (int i = 0; i < has.size(); ++i) { n       for (int j = i + 1; j < has.size(); ++j) { n         int u = has[i], v = has[j]; n         u = dsu.seek(u), v = dsu.seek(v); n         if (!dsu.same(u, v)) { n           if (u > v) swap(u, v); n           onepath.insert({u, v}); n         } n       } n     } n   } n   while (m--) { n     int u, v; n     scanf( %d %d , &u, &v); n     u = vec[u], v = vec[v]; n     u = dsu.seek(u), v = dsu.seek(v); n     if (u > v) swap(u, v); n     if (u == v) n       puts( 0 ); n     else if (onepath.count({u, v})) n       puts( 1 ); n     else n       puts( 2 ); n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int maxx = -1; n   set<int> s; n   map<int, int> m; n   vector<int> l(n); n   for (int i = 0; i < n; i++) { n     cin >> l[i]; n     m[l[i]]++; n     if (m[l[i]] > maxx) maxx = m[l[i]]; n     s.insert(l[i]); n   } n   cout << maxx <<     << s.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   long long int n, m, k; n   vector<long long int> a, b; n   while (t--) { n     cin >> n >> m; n     cout << n <<     << n * 2 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300005; n int n, m; n char s[MAXN]; n int g[22][22]; n int dp[1 << 21]; n int sol(int msk) { n   if (1 << m == msk + 1) return 0; n   if (dp[msk] != -1) return dp[msk]; n   int tk[20] = {0}; n   int ntk[20] = {0}; n   int tksz = 0; n   int ntksz = 0; n   for (int i = 0; i < m; i++) { n     if (msk & (1 << i)) n       tk[tksz++] = i; n     else n       ntk[ntksz++] = i; n   } n   int all = 0; n   int save = 0; n   int best = 10000000; n   for (int i = 0; i < ntksz; i++) { n     save = 0; n     int x = ntk[i]; n     for (int j = 0; j < tksz; j++) { n       int y = tk[j]; n       save += g[x][y] + g[y][x]; n     } n     best = min(best, -save + sol(msk | (1 << ntk[i]))); n     all += save; n   } n   return dp[msk] = best + all; n } n int main() { n   memset(dp, -1, sizeof(dp)); n   scanf( %d %d , &n, &m); n   scanf( %s , s); n   for (int i = 1; i < n; i++) { n     g[s[i - 1] -  a ][s[i] -  a ]++; n   } n   for (int i = 0; i < m; i++) g[i][i] = 0; n   int ans = sol(0); n   for (int i = 0; i < m; i++) n     for (int j = 0; j < m; j++) ans += g[i][j]; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n struct Student { n   int number; n   int cost; n   int com; n }; n bool comp1(Student a, Student b) { n   if (a.cost < b.cost) return true; n   return false; n } n bool comp2(Student a, Student b) { n   if (a.number < b.number) return true; n   return false; n } n int main() { n   long n, t, k, res, q; n   cin >> n; n   Student* A = new Student[n]; n   int* K = new int[n]; n   for (int i = 0; i < n; i++) { n     A[i].number = i; n     A[i].com = 0; n     cin >> A[i].cost; n   } n   sort(A, A + n, comp1); n   int* D = new int[n]; n   int* C = new int[n]; n   D[2] = -1; n   C[2] = A[2].cost - A[0].cost; n   K[2] = 1; n   for (int i = 3; i < n; i++) { n     D[i] = -1; n     C[i] = A[i].cost - A[0].cost; n     K[i] = 1; n     if (i >= 5) { n       if (i - 3 >= 2 && (C[i - 3] + A[i].cost - A[i - 2].cost) < C[i]) { n         C[i] = C[i - 3] + A[i].cost - A[i - 2].cost; n         D[i] = i - 3; n         K[i] = K[i - 3] + 1; n       } n       if (i - 4 >= 2 && (C[i - 4] + A[i].cost - A[i - 3].cost) < C[i]) { n         C[i] = C[i - 4] + A[i].cost - A[i - 3].cost; n         D[i] = i - 4; n         K[i] = K[i - 4] + 1; n       } n       if (i - 5 >= 2 && (C[i - 5] + A[i].cost - A[i - 4].cost) < C[i]) { n         C[i] = C[i - 5] + A[i].cost - A[i - 4].cost; n         D[i] = i - 5; n         K[i] = K[i - 5] + 1; n       } n     } n   } n   q = n - 1; n   while (q != -1) { n     A[q].com = K[q]; n     t = q - 1; n     while (t != D[q]) { n       A[t].com = K[q]; n       t--; n     } n     q = D[q]; n   } n   res = C[n - 1]; n   cout << res <<     << K[n - 1] << endl; n   sort(A, A + n, comp2); n   for (int i = 0; i < n; i++) cout << A[i].com <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct x { n   int a, id, gp; n   bool operator<(const x& xx) const { return a < xx.a; } n } s[100005]; n bool cmp(x p, x q) { return p.id < q.id; } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %d , &s[i].a); n     s[i].id = i; n     s[i].gp = 1; n   } n   if (n == 2) { n     printf( 0 n1 1 n ); n     return 0; n   } n   sort(s, s + n); n   int a1 = s[n - 1].a + s[n - 2].a - s[0].a - s[1].a; n   int a2 = max(s[n - 1].a + s[n - 2].a, s[n - 1].a + s[0].a + m) - n            min(s[0].a + s[1].a + m, s[1].a + s[2].a); n   if (a1 > a2) { n     s[0].gp = 2; n     sort(s, s + n, cmp); n     printf( %d n , a2); n     for (int i = 0; i < n; i++) printf( %d  , s[i].gp); n   } else { n     printf( %d n , a1); n     for (int i = 0; i < n; i++) printf( 1  ); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 1000005; n int sp[maxN]; n void seive() { n   for (int i = 2; i <= 1000000; ++i) { n     if (sp[i] != 0) continue; n     for (int j = i; j <= 1000000; j += i) { n       if (sp[j] == 0) sp[j] = i; n     } n   } n } n int nxtpow(int x) { n   int p = 1; n   while (p < x) p <<= 1; n   return p; n } n int main() { n   seive(); n   int n; n   scanf( %d , &n); n   int pow = 0; n   int x = n; n   int val = 1; n   vector<int> pows; n   while (x > 1) { n     int p = sp[x]; n     int cnt = 1; n     while (x > 1 && sp[x / p] == p) { n       x /= p; n       ++cnt; n     } n     x /= p; n     pow = max(pow, nxtpow(cnt)); n     val *= p; n     pows.push_back(cnt); n   } n   int ans = 0; n   for (int x : pows) { n     if (x != pow) { n       ++ans; n       break; n     } n   } n   while (pow > 1) { n     pow >>= 1; n     ++ans; n   } n   printf( %d %d n , val, ans); 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   cout.tie(NULL); n   map<string, long long> m; n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     long long x; n     string y; n     cin >> x >> y; n     sort(y.begin(), y.end()); n     if (m[y] == 0) n       m[y] = x; n     else n       m[y] = min(m[y], x); n   } n   long long ans = INT_MAX; n   for (auto it = m.begin(); it != m.end(); it++) { n     for (auto i = m.begin(); i != m.end(); i++) { n       if (i == it) continue; n       string s1 = it->first; n       string s2 = i->first; n       set<char> s; n       for (long long p = 0; p < s1.size(); p++) s.insert(s1[p]); n       for (long long q = 0; q < s2.size(); q++) s.insert(s2[q]); n       if (s.size() == 3) ans = min(ans, m[s1] + m[s2]); n     } n   } n   if (m[ ABC ] > 0) ans = min(ans, m[ ABC ]); n   if (m[ A ] > 0 && m[ B ] > 0 && m[ C ] > 0) n     ans = min(ans, m[ A ] + m[ B ] + m[ C ]); n   if (ans != INT_MAX) n     cout << ans << endl; n   else n     cout << -1 << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 1000001; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int ans = 0, i, j, dp[N], half, n, a[N]; n   cin >> n; n   for (i = 0; i < n; ++i) cin >> a[i]; n   for (i = n - 1; i >= 0; --i) { n     dp[a[i]] = 1; n     for (j = 2 * a[i]; j < N; j += a[i]) { n       dp[a[i]] = max(dp[a[i]], dp[j] + 1); n     } n     ans = max(ans, dp[a[i]]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n using vc = vector<T>; n template <class T> n using vvc = vc<vc<T>>; n template <class T> n void mkuni(vector<T>& v) { n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n } n long long rand_int(long long l, long long r) { n   static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); n   return uniform_int_distribution<long long>(l, r)(gen); n } n template <class T> n void print(T x, int suc = 1) { n   cout << x; n   if (suc == 1) n     cout <<   n ; n   else n     cout <<    ; n } n template <class T> n void print(const vector<T>& v, int suc = 1) { n   for (int i = 0; i < v.size(); i++) n     print(v[i], i == (int)(v.size()) - 1 ? suc : 2); n } n const int INF = 0x3f3f3f; n const int maxn = 5e3 + 7; n const int mod = 998244353; n const int N = 1e7 + 7; n int n; n int dp[maxn][maxn]; n int pre[maxn]; n int sum[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   sort(a.begin(), a.end()); n   for (int i = 0; i < n; ++i) { n     pre[i + 1] = upper_bound(a.begin(), a.end(), (a[i]) / 2) - a.begin(); n   } n   dp[0][n + 1] = 1; n   for (int i = 0; i < n; ++i) { n     sum[n + 1] = dp[i][n + 1]; n     for (int k = n; k >= 1; --k) sum[k] = (sum[k + 1] + dp[i][k]) % mod; n     for (int j = 1; j <= n; ++j) { n       if (pre[n - j + 1] - i + 1 >= 0) n         dp[i + 1][j] = n             (dp[i + 1][j] + 1ll * dp[i][j] * (pre[n - j + 1] - i + 1) % mod) % n             mod; n       dp[i + 1][j] = (dp[i + 1][j] + sum[n - pre[n - j + 1] + 1]) % mod; n     } n   } n   cout << dp[n][1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 998244353; n const int N = 200005, E = 524288; n int R[N * 4]; n long long qpow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % M; n     a = a * a % M; n     b >>= 1; n   } n   return ans; n } n long long wn[N * 4], iwn[N * 4]; n void init() { n   int i; n   iwn[E / 2] = wn[E / 2] = 1; n   long long s1 = qpow(3, (M - 1) / E); n   long long s2 = qpow(s1, M - 2); n   for (i = E / 2 + 1; i < E; ++i) { n     wn[i] = wn[i - 1] * s1 % M; n     iwn[i] = iwn[i - 1] * s2 % M; n   } n   for (i = E / 2 - 1; i; --i) { n     wn[i] = wn[i << 1]; n     iwn[i] = iwn[i << 1]; n   } n } n void NTT(long long *f, int lim, int op) { n   int i, j, k; n   for (i = 0; i < lim; ++i) { n     R[i] = (R[i >> 1] >> 1) | (i & 1 ? lim >> 1 : 0); n     if (R[i] < i) swap(f[R[i]], f[i]); n   } n   for (i = 1; i < lim; i <<= 1) n     for (j = 0; j < lim; j += (i << 1)) n       for (k = j; k < j + i; ++k) { n         long long a = f[k], b = f[k + i]; n         long long w = (op == 1 ? wn[k - j + i] : iwn[k - j + i]); n         f[k] = (a + b * w) % M; n         f[k + i] = (a - b * w) % M; n       } n   if (op == -1) { n     long long inv = qpow(lim, M - 2); n     for (i = 0; i < lim; ++i) f[i] = f[i] * inv % M; n   } n } n void mult(long long *a, int n, long long *b, int m) { n   int lim = 1; n   while (lim < n + m) lim <<= 1; n   for (int i = n; i < lim; ++i) a[i] = 0; n   for (int i = m; i < lim; ++i) b[i] = 0; n   NTT(a, lim, 1); n   NTT(b, lim, 1); n   for (int i = 0; i < lim; ++i) a[i] = a[i] * b[i] % M; n   NTT(a, lim, -1); n } n int p[66], k, i, n, m; n char s[N], t[N]; n long long a[N * 4], b[N * 4], sum, vis[66], pre[N]; n int main() { n   init(); n   for (i = 0; i < 26; ++i) { n     scanf( %d , &p[i]); n     --p[i]; n   } n   mt19937 rnd(time(0)); n   for (i = 0; i < 26; ++i) n     for (int j = i; !vis[j]; j = p[j]) vis[j] = rnd() % M; n   scanf( %s , s); n   scanf( %s , t); n   n = strlen(s); n   m = strlen(t); n   reverse(s, s + n); n   for (i = 0; i < n; ++i) { n     a[i] = (-vis[s[i] -  a ] - vis[p[s[i] -  a ]]) % M; n     sum = (sum + vis[s[i] -  a ] * vis[p[s[i] -  a ]]) % M; n   } n   for (i = 0; i < m; ++i) { n     b[i] = vis[t[i] -  a ]; n     pre[i] = vis[t[i] -  a ] * vis[t[i] -  a ] % M; n   } n   for (i = 1; i < m; ++i) pre[i] = (pre[i - 1] + pre[i]) % M; n   mult(a, n, b, m); n   for (i = n - 1; i < m; ++i) n     if ((a[i] + pre[i] - (i - n >= 0 ? pre[i - n] : 0) + sum) % M == 0) n       putchar( 1 ); n     else n       putchar( 0 ); n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const int maxn = 2e5 + 5; n const double PI = 3.14159265358979323846; n void solve() { n   long long n; n   cin >> n; n   vector<long long> v(n); n   set<long long> s1; n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n     if (s1.find(v[i]) != s1.end() && s1.size() > 1) { n       cout << 0 <<   n ; n       return; n     } n     s1.insert(v[i]); n   } n   if (n == 1) { n     cout << -1 <<   n ; n     return; n   } n   if (s1.size() == 1) { n     cout << 1 <<   n ; n     cout << v[0] <<   n ; n     return; n   } n   sort(v.begin(), v.end()); n   set<long long> s2; n   unordered_map<long long, long long> amp; n   long long d = 0; n   long long d2 = INT_MAX; n   for (long long i = 1; i < n; i++) { n     s2.insert(v[i] - v[i - 1]); n     amp[v[i] - v[i - 1]]++; n     ; n     d = ((d) > (v[i] - v[i - 1]) ? (d) : (v[i] - v[i - 1])); n     d2 = ((d2) < (v[i] - v[i - 1]) ? (d2) : (v[i] - v[i - 1])); n   } n   if (s2.size() > 2) { n     cout << 0; n     return; n   } n   if (s2.size() == 1) { n     if (n == 2 && d / 2 == double(d) / 2) { n       vector<long long> ans; n       ans.push_back(v[0] - d); n       ans.push_back(v[n - 1] + d); n       ans.push_back(v[0] + d / 2); n       sort(ans.begin(), ans.end()); n       cout << ans.size() <<   n ; n       cout << ans[0] <<     << ans[1] <<     << ans[2]; n       return; n     } n     cout << 2 <<   n ; n     cout << v[0] - d <<     << v[n - 1] + d; n     return; n   } n   if (amp[d] > 1) { n     cout << 0 <<   n ; n     return; n   } n   for (long long i = 1; i < n; i++) { n     if (v[i] - v[i - 1] == d && (double)d / 2 == d2) { n       cout << 1 <<   n ; n       cout << v[i - 1] + d2 <<   n ; n       return; n     } n   } n   cout << 0 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long l = 1; n   while (l--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void speed() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n const long long N = 1e5 + 5; n const long long NN = 105; n const long long MAX = 2e5 + 123; n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n map<long long, long long> m; n long long ans = 1, cnt; n vector<pair<long long, pair<long long, long long> > > v; n void hajime() { n   long long n, a[N * 2]; n   scanf( %I64d , &n); n   for (long long i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   a[n + 1] = -INF; n   long long l = 1; n   long long mx = 0; n   for (long long i = 1; i <= n; i++) { n     if (a[i] < a[i + 1]) { n       ans++; n     } else { n       mx = max(mx, ans); n       v.push_back({ans, {l, i}}); n       ans = 1; n       l = i + 1; n     } n   } n   for (int i = 0; i < v.size(); i++) { n     if (i) { n       if (a[v[i].second.first + 1] > a[v[i - 1].second.second]) { n         mx = max(mx, v[i].first + v[i - 1].first - 1); n       } n     } n     if (i != v.size() - 1) { n       if (a[v[i].second.second - 1] < a[v[i + 1].second.first]) { n         mx = max(mx, v[i].first + v[i + 1].first - 1); n       } n     } n   } n   cout << mx; n } n int main() { n   long long miyagi = 1; n   while (miyagi--) hajime(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 5; n long long n; n long long nim[N], prefnim[N]; n vector<pair<long long, long long> > sum[N]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     long long cur = i; n     for (long long j = i + 1; j <= n; j++) { n       cur += j; n       if (cur > n) break; n       sum[cur].push_back({i, j}); n     } n   } n   for (long long i = 1; i <= n; i++) { n     unordered_set<long long> s; n     for (auto &it : sum[i]) n       s.insert(prefnim[it.second] ^ prefnim[it.first - 1]); n     long long val = 0; n     while (s.find(val) != s.end()) val++; n     nim[i] = val; n     prefnim[i] = prefnim[i - 1] ^ nim[i]; n   } n   if (nim[n] == 0) n     cout <<  -1 ; n   else { n     long long ans = 1e9; n     for (auto &it : sum[n]) { n       if ((prefnim[it.second] ^ prefnim[it.first - 1]) == 0) n         ans = min(ans, it.second - it.first + 1); n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dem[100001]; n long long f[100002]; n int main() { n   int n; n   long long x; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     dem[x]++; n   } n   f[1] = dem[1]; n   for (int i = 2; i < 100002; i++) f[i] = max(f[i - 2] + dem[i] * i, f[i - 1]); n   cout << f[100001]; n } n


#include <bits/stdc++.h> n using namespace std; n long long dpf[110][100][60]; n long long dpg[110][100][60]; n int diff; n int likes_init = 0; n const long long mod = 998244353; n long long fast_exp(long long b, int e) { n   b = b % mod; n   if (e == 0) return 1; n   if (e == 1) return b; n   if (e % 2 == 1) return (b * fast_exp(b, e - 1)) % mod; n   return fast_exp((b * b) % mod, e / 2); n } n long long modinv(long long x) { n   assert(x % mod != 0); n   return fast_exp(x, mod - 2); n } n long long f(int curr, int likes, int runs) { n   if (dpf[curr][likes - likes_init][runs] == 1LL << 40) { n     int dislike = likes + runs - diff; n     if (curr == 0) return 0; n     if (runs == 0) { n       return curr; n     } n     if (dislike < 0) return 0; n     long long tmp1, tmp2, tmp3; n     tmp1 = (curr == 0 ? 0 : curr * f(curr + 1, likes + 1, runs - 1)); n     tmp2 = n         (likes - curr == 0 ? 0 : (likes - curr) * f(curr, likes + 1, runs - 1)); n     tmp3 = (dislike == 0 ? 0 : dislike * f(curr, likes, runs - 1)); n     long long tmp = (tmp1 + tmp2 + tmp3) % mod; n     long long ans = (tmp * modinv(likes + dislike)) % mod; n     return dpf[curr][likes - likes_init][runs] = ans; n   } else { n     return dpf[curr][likes - likes_init][runs]; n   } n } n long long g(int curr, int likes, int runs) { n   if (dpg[curr][likes - likes_init][runs] == 1LL << 40) { n     int dislike = likes + runs - diff; n     if (curr == 0) return 0; n     if (runs == 0) { n       return curr; n     } n     if (dislike < 0) return 0; n     long long tmp1 = (curr == 0 ? 0 : curr * g(curr - 1, likes, runs - 1)); n     long long tmp2 = (likes == 0 ? 0 : likes * g(curr, likes + 1, runs - 1)); n     long long tmp3 = n         (dislike - curr == 0 ? 0 : (dislike - curr) * g(curr, likes, runs - 1)); n     long long tmp = (tmp1 + tmp2 + tmp3) % mod; n     long long ans = (tmp * modinv(likes + dislike)) % mod; n     return dpg[curr][likes - likes_init][runs] = ans; n   } else { n     return dpg[curr][likes - likes_init][runs]; n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   diff = m; n   int a[n]; n   for (int i = 0; i < 110; i++) { n     for (int j = 0; j < 100; j++) { n       for (int k = 0; k < 60; k++) { n         dpf[i][j][k] = 1LL << 40; n         dpg[i][j][k] = 1LL << 40; n       } n     } n   } n   bool good[n]; n   int tl = 0; n   for (int i = 0; i < n; i++) { n     cin >> good[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (good[i]) { n       diff += a[i]; n       tl += a[i]; n     } else n       diff -= a[i]; n   } n   likes_init = tl; n   for (int i = 0; i < n; i++) { n     if (good[i]) { n       cout << (f(a[i], tl, m) % mod + mod) % mod <<   n ; n     } else { n       cout << (g(a[i], tl, m) % mod + mod) % mod <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, j, k, m = 0, n, cnt = 0, x = 0, ans = 0, y, sum = 0, l = 0, n                          r = 0; n   cin >> n >> m; n   string a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (a[i][j] ==  B ) { n         for (k = j; k < m; k++) { n           if (a[i][k] ==  B ) { n             cnt++; n           } else { n             break; n           } n         } n         cnt = cnt / 2; n         i += cnt; n         j += cnt; n         i++; n         j++; n         cout << i <<     << j; n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1010; n int n, m, a[MAXN]; n int main() { n   cin.tie(0); n   int T; n   cin >> T; n   while (T--) { n     int ans = 0; n     cin >> n >> m; n     for (register int i = 1; i <= n; ++i) cin >> a[i]; n     if (n > m || n == 2) { n       puts( -1 ); n       continue; n     } n     for (register int i = 1; i <= n; ++i) ans += a[i] + a[i]; n     m -= n; n     int minn1 = 0x3f3f3f3f, minn2 = 0x3f3f3f3f, p1, p2; n     for (register int i = 1; i <= n; ++i) { n       if (a[i] < minn1) n         p2 = p1, p1 = i, minn2 = minn1, minn1 = a[i]; n       else if (a[i] < minn2) n         minn2 = a[i], p2 = i; n     } n     ans += m * (minn1 + minn2); n     printf( %d n , ans); n     for (register int i = 1; i <= m; ++i) printf( %d %d n , p1, p2); n     for (register int i = 2; i <= n; ++i) printf( %d %d n , i, i - 1); n     printf( 1 %d n , n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n struct Data { n   int u, v, w; n   Data() {} n   Data(int x, int y, int z) : u(x), v(y), w(z) {} n }; n int n; n vector<Data> edge, ans; n vector<int> neighbor[N]; n void dfs(int u, int par, vector<int> &leaf) { n   if (neighbor[u].size() == 1) { n     leaf.push_back(u); n     return; n   } n   for (auto v : neighbor[u]) n     if (v != par) dfs(v, u, leaf); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i < n; i++) { n     int x, y, w; n     cin >> x >> y >> w; n     edge.push_back(Data(x, y, w)); n     neighbor[x].push_back(y); n     neighbor[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) n     if (neighbor[i].size() == 2) return cout <<  NO , 0; n   cout <<  YES n ; n   for (auto Q : edge) { n     int u = Q.u, v = Q.v, w = Q.w; n     vector<int> Uleaf, Vleaf; n     dfs(u, v, Uleaf); n     dfs(v, u, Vleaf); n     int u1 = Uleaf.front(), u2 = Uleaf.back(); n     int v1 = Vleaf.front(), v2 = Vleaf.back(); n     ans.push_back(Data(u1, v1, w / 2)); n     ans.push_back(Data(u2, v2, w / 2)); n     if (u1 != u2) ans.push_back(Data(u1, u2, -w / 2)); n     if (v1 != v2) ans.push_back(Data(v1, v2, -w / 2)); n   } n   cout << ans.size() <<   n ; n   for (auto Q : ans) { n     int u = Q.u, v = Q.v, w = Q.w; n     cout << u <<     << v <<     << w <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[200003], b[200003], ch[200003]; n void Do() { n   int n, f = 0; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   for (int i = 0; i < n - 1; i++) { n     if (a[i] == 0) f = 1; n     if (f) a[i] = a[i + 1]; n   } n   f = 0; n   for (int i = 0; i < n - 1; i++) { n     if (b[i] == 0) f = 1; n     if (f) b[i] = b[i + 1]; n   } n   int beg = a[0], desire; n   ch[0] = a[0]; n   for (int i = 0; i < n - 1; i++) n     if (b[i] == beg) desire = i; n   int ind = 1; n   for (int i = desire + 1; i < n - 1; i++) { n     ch[ind++] = b[i]; n     if (ind == n - 1) break; n   } n   if (ind != n - 1) { n     for (int i = 0;; i++) { n       ch[ind++] = b[i]; n       if (ind == n - 1) break; n     } n   } n   bool flag = true; n   for (int i = 0; i < n - 1; i++) n     if (a[i] != ch[i]) flag = false; n   if (flag) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n int main() { n   Do(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long a, long long n) { n   if (a == 0) return 0; n   if (a == 1 || n == 0) return 1; n   if (n == 1) return a % 1000000007; n   long long t = power(a, n / 2); n   t = t * t % 1000000007; n   if (n & 1) return t * a % 1000000007; n   return t; n } n int popcount(long long a) { n   int c = 0; n   while (a) { n     c++; n     a -= a & -a; n   } n   return c; n } n void factorize(int a) {} n void update(int tree[], int idx, int val, int maxval) { n   for (; idx <= maxval; idx += idx & -idx) { n     tree[idx] += val; n   } n } n int read(int tree[], int idx) { n   long long sum = 0; n   for (; idx > 0; idx -= idx & -idx) { n     sum += tree[idx]; n   } n   return sum; n } n struct node2 { n   int id, val; n   node2() { n     static int ctx = 1; n     id = ctx++; n   }; n   node2(int a, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) { n     val = a; n   } n }; n struct comp2 { n   bool operator()(int a, int b) { return b < a; } n }; n bool cmp2(int a, int b) { return b < a; } n struct node { n   long long x, y; n }; n struct comp { n   bool operator()(int a, int b) { return b < a; } n }; n bool cmp(int a, int b) { return b < a; } n int n, m, a, b, c, d, k, h, w, x, y, p, q, t, res, ma, mi, T, act = 0, pas = 1, n                                                               cur, flag, now; n int deg[100009]; n char s[1]; n double e, f, z; n vector<int> v[100009], vec; n node ans[100009]; n set<int> sett; n map<int, int> mapp; n void print() {} n void print2() {} n void input() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n     deg[x]++; n     deg[y]++; n   } n } n int Y[] = {0, 1, 0, -1, 0}; n int X[] = {0, 0, 1, 0, -1}; n int bgfjsvf[] = {0, 3, 4, 1, 2}; n void calc(int id, int par, long long y, long long x, long long dist, int dir) { n   ans[id].x = x; n   ans[id].y = y; n   int block = 1; n   for (auto u : v[id]) { n     if (u == par) continue; n     if (block == dir) block++; n     calc(u, id, y + Y[block] * dist, x + X[block] * dist, dist / 2, n          bgfjsvf[block]); n     block++; n   } n } n void solve() { n   for (int i = 1; i < n + 1; i++) n     if (deg[i] > 4) { n       flag = 1; n       return; n     } n   calc(1, 0, 0, 0, 1e9, 0); n } n void output() { n   if (flag == 1) n     cout <<  NO ; n   else { n     cout <<  YES  << endl; n     for (int i = 1; i < n + 1; i++) cout << ans[i].x <<     << ans[i].y << endl; n   } n } n int main() { n   input(); n   solve(); n   output(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int LEN = 100009; n int n; n int a[LEN]; n int ch = 0, nech = 0; n int ans = 0; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) { n     if (a[i] % 2 == 0) n       ch++; n     else n       nech++; n   } n   ans = min(ch, nech); n   while (nech > 1) { n     nech -= 2; n     ch++; n     ans = max(ans, min(ch, nech)); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<long long, long long> > st; n const long long INF = 1 << 30; n const long long N = 100005; n long long p[N], n, m; n long long nxt[N], pre[N]; n long long a[N], x[N]; n inline long long read() { n   long long 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 << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n bool cmp(long long x, long long y) { return p[x] < p[y]; } n long long calc(long long x, long long y) { n   if (x == y) return INF; n   long long d = (p[y] - p[x] + m) % m; n   if (x > y) d = (d + a[y]) % m; n   if (d <= a[x]) return 1; n   if (a[x] <= a[y]) return INF; n   long long dis = a[x] - a[y]; n   return (d - a[y] - 1) / dis + 1; n } n signed main() { n   n = read(); n   m = read(); n   for (long long i = 1; i <= n; i++) { n     p[i] = read(); n     a[i] = read(); n     x[i] = i; n   } n   sort(x + 1, x + n + 1, cmp); n   for (long long i = 1; i <= n; i++) { n     if (i < n) n       nxt[x[i]] = x[i + 1]; n     else n       nxt[x[i]] = x[1]; n     pre[nxt[x[i]]] = x[i]; n   } n   for (long long i = 1; i <= n; i++) { n     st.insert(make_pair(calc(i, nxt[i]), i)); n   } n   while (!st.empty()) { n     set<pair<long long, long long> >::iterator it = st.begin(); n     if ((*it).first == INF) break; n     long long i = (*it).second; n     st.erase(it); n     st.erase(make_pair(calc(nxt[i], nxt[nxt[i]]), nxt[i])); n     st.erase(make_pair(calc(pre[i], i), pre[i])); n     p[i] += calc(i, nxt[i]); n     --a[i]; n     nxt[i] = nxt[nxt[i]]; n     pre[nxt[i]] = i; n     st.insert(make_pair(calc(pre[i], i), pre[i])); n     st.insert(make_pair(calc(i, nxt[i]), i)); n   } n   printf( %d n , st.size()); n   for (set<pair<long long, long long> >::iterator it = st.begin(); n        it != st.end(); it++) n     printf( %lld  , (*it).second); n } n


#include <bits/stdc++.h> n using namespace std; n int h, t, R; n int n, m; n vector<pair<int, int> > H, T; n int D[201][201]; n int shortestWin() { n   memset(D, -1, sizeof(D)); n   queue<pair<int, int> > q; n   for (int i = 1; i <= n; i++) { n     pair<int, int> s; n     s.first = i; n     s.second = 0; n     if (i <= R && H[i - 1].first == 0 && H[i - 1].second == 0) { n       q.push(s); n       D[i][0] = 1; n     } n   } n   for (int i = 1; i <= m; i++) { n     pair<int, int> s; n     s.first = 0; n     s.second = i; n     if (i <= R && T[i - 1].first == 0 && T[i - 1].second == 0) { n       q.push(s); n       D[0][i] = 1; n     } n   } n   while (!q.empty()) { n     pair<int, int> u = q.front(); n     q.pop(); n     for (int i = 0; i < n; i++) { n       pair<int, int> v; n       v.first = u.first + (i + 1) - (H[i].first); n       v.second = u.second - (H[i].second); n       if (v.first + v.second <= R) { n         if (v.first >= 0 && v.second >= 0 && v.first >= (i + 1)) { n           if (D[v.first][v.second] == -1) { n             D[v.first][v.second] = D[u.first][u.second] + 1; n             q.push(v); n           } n         } n       } n     } n     for (int i = 0; i < m; i++) { n       pair<int, int> v; n       v.first = u.first - (T[i].first); n       v.second = u.second + (i + 1) - (T[i].second); n       if (v.first + v.second <= R) { n         if (v.first >= 0 && v.second >= 0 && v.second >= (i + 1)) { n           if (D[v.first][v.second] == -1) { n             D[v.first][v.second] = D[u.first][u.second] + 1; n             q.push(v); n           } n         } n       } n     } n   } n   return D[h][t]; n } n int V[201][201]; n int dp(int h, int t) { n   if (h + t > R || h < 0 || t < 0) { n     return 0; n   } n   if (V[h][t] == 1) { n     return 1000000000; n   } n   if (D[h][t] != -1) { n     return D[h][t]; n   } n   V[h][t] = 1; n   int best = 0; n   for (int i = 0; i < n; i++) { n     if (i + 1 > h) break; n     int vh = h - (i + 1) + H[i].first; n     int vt = t + H[i].second; n     best = max(best, dp(vh, vt) + 1); n   } n   for (int i = 0; i < m; i++) { n     if (i + 1 > t) break; n     int vh = h + T[i].first; n     int vt = t - (i + 1) + T[i].second; n     best = max(best, dp(vh, vt) + 1); n   } n   D[h][t] = best; n   V[h][t] = 2; n   return D[h][t]; n } n int main() { n   cin >> h >> t >> R; n   cin >> n; n   H.resize(n); n   for (int i = 0; i < n; i++) { n     cin >> H[i].first >> H[i].second; n   } n   cin >> m; n   T.resize(m); n   for (int i = 0; i < m; i++) { n     cin >> T[i].first >> T[i].second; n   } n   int winningPath = shortestWin(); n   if (winningPath != -1) { n     cout <<  Ivan n  << winningPath <<   n ; n   } else { n     memset(D, -1, sizeof(D)); n     memset(V, 0, sizeof(V)); n     int losingPath = dp(h, t); n     if (losingPath >= 1000000000) { n       cout <<  Draw n ; n     } else { n       cout <<  Zmey n  << losingPath <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n const int MAXN = 300011; n int N; n struct Pair { n   int Val; n   long long Mask; n } P[MAXN]; n long long Sum; n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N; ++i) { n     scanf( %d%I64d , &P[i].Val, &P[i].Mask); n     Sum += P[i].Val; n   } n   if (Sum < 0LL) { n     for (int i = 1; i <= N; ++i) P[i].Val = -P[i].Val; n   } n   long long Ans = 0LL, Tmp; n   for (int i = 61; i >= 0; --i) { n     Tmp = 0LL; n     for (int j = 1; j <= N; ++j) n       if ((P[j].Mask >> i) & 1 && ((P[j].Mask & ((1LL << i) - 1)) == 0)) n         Tmp += P[j].Val; n     if (Tmp > 0LL) { n       Ans ^= (1LL << i); n       for (int j = 1; j <= N; ++j) n         if ((P[j].Mask >> i) & 1) P[j].Val = -P[j].Val; n     } n   } n   printf( %I64d n , Ans); n   return 0; n } n