#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> a; n   int n, t; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> t; n     a.push_back(t); n   } n   sort(a.begin(), a.end()); n   for (int i = 0; i < n / 2; i++) cout << a[i] <<     << a[n - i - 1] <<    ; n   if (n % 2 == 1) cout << a[n / 2]; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1000000]; n int main() { n   long long i, num, res = 0, n, k, rem, fl = 0; n   cin >> n >> k; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   for (i = 1; i < n; i++) { n     if ((a[i] - a[0]) % k != 0) { n       fl = 1; n       break; n     } else { n       rem = (a[i] - a[0]) / k; n       res += rem; n     } n   } n   if (fl) { n     cout << -1 << endl; n   } else n     cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[101], piller; n int main() { n   cin >> n; n   for (auto i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (auto i = 0; i < n; i++) { n     if (piller * a[i] + piller <= i) piller++; n   } n   cout << piller; n } n


#include <bits/stdc++.h> n using namespace std; n int t[3000]; n int main() { n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   for (int i = 0; i < n; i++) { n     t[s[i]] += 1; n   } n   int lk = t[ A ]; n   for (char c =  A ; c <  A  + k; c++) { n     if (t[c] < lk) { n       lk = t[c]; n     } n   } n   cout << lk * k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const int mod = 1e9 + 7; n struct SAM { n   int n, tot, last; n   int ch[N][26], dep[N], fa[N]; n   int root[N], ls[N * 20], rs[N * 20], cnt; n   vector<int> G[N]; n   void init() { n     tot = last = 1; n     memset(ch[1], 0, sizeof(ch[1])); n   } n   inline int newnode(int _dep) { n     dep[++tot] = _dep; n     memset(ch[tot], 0, sizeof(ch[tot])); n     return tot; n   } n   void add(int alp) { n     ++n; n     alp -=  a ; n     int u, p = newnode(dep[last] + 1); n     for (u = last; u && !ch[u][alp]; u = fa[u]) ch[u][alp] = p; n     if (!u) n       fa[p] = 1; n     else { n       int v = ch[u][alp]; n       if (dep[v] == dep[u] + 1) n         fa[p] = v; n       else { n         int nv = newnode(dep[u] + 1); n         fa[nv] = fa[v]; n         fa[v] = fa[p] = nv; n         memcpy(ch[nv], ch[v], sizeof(ch[v])); n         for (; u && ch[u][alp] == v; u = fa[u]) ch[u][alp] = nv; n       } n     } n     last = p; n   } n   int build(int l, int r, int p) { n     if (l == r) return ++cnt; n     int mid = l + r >> 1; n     int now = ++cnt; n     if (p <= mid) n       ls[now] = build(l, mid, p); n     else n       rs[now] = build(mid + 1, r, p); n     return now; n   } n   int merge(int x, int y) { n     if (x == 0 || y == 0) return x + y; n     int now = ++cnt; n     ls[now] = merge(ls[x], ls[y]); n     rs[now] = merge(rs[x], rs[y]); n     return now; n   } n   void dfs(int x) { n     for (int i = 0; i < G[x].size(); ++i) { n       int u = G[x][i]; n       dfs(u); n       root[x] = merge(root[x], root[u]); n     } n   } n   void build_segtree(char* s) { n     int now = 1; n     int n = strlen(s + 1); n     for (int i = 1; i <= n; ++i) { n       now = ch[now][s[i] -  a ]; n       root[now] = build(1, n, i); n     } n     for (int i = 1; i <= tot; ++i) G[fa[i]].push_back(i); n     dfs(1); n   } n   string ans; n   bool chk(int k, int l, int r, int p, int q) { n     if (k == 0) return false; n     if (l >= p && r <= q) return true; n     if (l > q || r < p) return false; n     int mid = l + r >> 1; n     return chk(ls[k], l, mid, p, q) || chk(rs[k], mid + 1, r, p, q); n   } n   bool check(int l, int r, int p) { return chk(p, 1, n, l, r); } n   bool solve(int now, int l, int r, char* s) { n     if (l > r) return false; n     if (*s == 0) { n       for (int i = 0; i < 26; i++) { n         if (ch[now][i] && check(l, r, root[ch[now][i]])) { n           ans.push_back( a  + i); n           return true; n         } n       } n       return false; n     } else { n       int i = *s -  a ; n       if (ch[now][i] && check(l, r, root[ch[now][i]]) && n           solve(ch[now][i], l + 1, r, s + 1)) { n         ans.push_back( a  + i); n         return true; n       } n       for (i = i + 1; i < 26; ++i) { n         if (ch[now][i] && check(l, r, root[ch[now][i]])) { n           ans.push_back( a  + i); n           return true; n         } n       } n       return false; n     } n   } n } sam; n int n, m; n char s[N]; n int main() { n   sam.init(); n   scanf( %s , s + 1); n   n = strlen(s + 1); n   for (int i = 1; i <= n; i++) sam.add(s[i]); n   sam.build_segtree(s); n   scanf( %d , &m); n   while (m--) { n     int l, r; n     scanf( %d %d %s , &l, &r, s + 1); n     sam.ans.clear(); n     if (!sam.solve(1, l, r, s + 1)) n       printf( -1 n ); n     else { n       reverse(sam.ans.begin(), sam.ans.end()); n       printf( %s n , sam.ans.c_str()); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e5 + 5; n int n, q, l[N], r[N], level[N], p[N][20]; n pair<int, int> res[N]; n int import[N], numCity, numVirus, node[N], total_num; n vector<int> adj[N], newAdj[N]; n struct T { n   int city, speed; n }; n T virus[N]; n int cnt = 0; n void dfs(int x, int pa) { n   cnt++; n   l[x] = cnt; n   p[x][0] = pa; n   for (auto &u : adj[x]) { n     if (u == pa) continue; n     level[u] = level[x] + 1; n     dfs(u, x); n   } n   r[x] = cnt; n } n void init_lca() { n   for (int k = 1; k <= 18; k++) { n     for (int i = 1; i <= n; i++) p[i][k] = p[p[i][k - 1]][k - 1]; n   } n } n int lca(int x, int y) { n   if (x == 1 || y == 1) return 1; n   if (level[x] > level[y]) swap(x, y); n   int diff = level[y] - level[x]; n   for (int k = 18; k >= 0; k--) n     if (diff >> k & 1) y = p[y][k]; n   if (x == y) return x; n   for (int k = 18; k >= 0; k--) { n     if (p[x][k] != p[y][k]) { n       x = p[x][k]; n       y = p[y][k]; n     } n   } n   return p[x][0]; n } n bool isParent(int p, int u) { return (l[p] <= l[u] && l[u] <= r[p]); } n bool lf(const int &x, const int &y) { return l[x] < l[y]; } n int dist(int x, int y) { return level[x] + level[y] - 2 * level[lca(x, y)]; } n void compress_tree() { n   total_num = numCity + numVirus; n   for (int i = 1; i <= numVirus; i++) node[i] = virus[i].city; n   for (int i = numVirus + 1; i <= total_num; i++) n     node[i] = import[i - numVirus]; n   sort(node + 1, node + total_num + 1, lf); n   total_num = unique(node + 1, node + total_num + 1) - node - 1; n   int now = total_num; n   for (int i = 1; i < now; i++) { n     total_num++; n     node[total_num] = lca(node[i], node[i + 1]); n   } n   sort(node + 1, node + total_num + 1, lf); n   total_num = unique(node + 1, node + total_num + 1) - node - 1; n   for (int i = 1; i <= total_num; i++) newAdj[node[i]].clear(); n   stack<int> st; n   st.push(node[1]); n   for (int i = 2; i <= total_num; i++) { n     while (!st.empty() && !isParent(st.top(), node[i])) st.pop(); n     if (!st.empty()) { n       int par = st.top(); n       newAdj[par].push_back(node[i]); n       newAdj[node[i]].push_back(par); n     } n     st.push(node[i]); n   } n } n int calc(int dist, int s) { return (dist - 1 + s) / s; } n void solve() { n   for (int i = 1; i <= total_num; i++) res[node[i]] = make_pair(1e9, 0); n   priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, n                  greater<pair<pair<int, int>, int>>> n       pq; n   for (int i = 1; i <= numVirus; i++) { n     int id = virus[i].city; n     res[id] = make_pair(0, i); n     pq.push(make_pair(res[id], id)); n   } n   while (!pq.empty()) { n     auto now = pq.top(); n     pq.pop(); n     if (res[now.second] != now.first) continue; n     for (auto &u : newAdj[now.second]) { n       if (res[u] > make_pair(calc(dist(u, virus[now.first.second].city), n                                   virus[now.first.second].speed), n                              now.first.second)) { n         res[u] = make_pair(calc(dist(u, virus[now.first.second].city), n                                 virus[now.first.second].speed), n                            now.first.second); n         pq.push(make_pair(res[u], u)); n       } n     } n   } n   for (int i = 1; i <= numCity; i++) cout << res[import[i]].second <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1, 0); n   init_lca(); n   cin >> q; n   while (q--) { n     cin >> numVirus >> numCity; n     for (int i = 1; i <= numVirus; i++) cin >> virus[i].city >> virus[i].speed; n     for (int i = 1; i <= numCity; i++) cin >> import[i]; n     compress_tree(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, A[100005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> A[i]; n   sort(A, A + n); n   int mid = n / 2; n   long long res = 0; n   for (int i = 0; i < mid; i++) { n     res = (res + A[i] * A[n - 1 - i] * 2) % 10007; n   } n   if (n & 1) res = (res + A[mid] * A[mid]) % 10007; n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y, next; n } a[1010000]; n int len, last[510000]; n inline void ins(int x, int y) { n   len++; n   a[len].x = x; n   a[len].y = y; n   a[len].next = last[x]; n   last[x] = len; n } n int tt[510000]; n int col[510000]; n int cnt, belong[510000]; n bool dfs(int x, int c) { n   if (col[x] != -1) return col[x] == c; n   col[x] = c; n   belong[x] = cnt; n   for (int k = last[x]; k > 0; k = a[k].next) { n     int y = a[k].y; n     if (tt[x] != tt[y]) continue; n     if (!dfs(y, 1 - c)) return false; n   } n   return true; n } n bool b[510000]; n int tg[510000]; n struct edge { n   int x, y, c, next; n   bool bk; n } e[1010000]; n map<int, map<int, int>> east; n inline void ins(int x, int y, int c) { n   len++; n   e[len].x = x; n   e[len].y = y; n   e[len].c = c; n   e[len].next = east[x][tg[y]]; n   east[x][tg[y]] = len; n   e[len].bk = true; n } n int Al, Be, Ga; n bool De; n void color(int x, int c) { n   if (col[x] < Ga) { n     col[x] = c; n     int ty = tg[x] == Al ? Be : Al; n     for (int k = east[x][ty]; k > 0; k = e[k].next) { n       int y = e[k].y; n       e[k].bk = false; n       color(y, c ^ e[k].c); n     } n   } else if (col[x] == (c ^ 1)) n     De = false; n } n set<pair<int, int>> S; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &tt[i]); n   len = 0; n   memset(last, 0, sizeof(last)); n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     ins(x, y); n     ins(y, x); n   } n   memset(col, -1, sizeof(col)); n   memset(b, true, sizeof(b)); n   cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (col[i] == -1 && b[tt[i]]) { n       cnt++; n       if (!dfs(i, 0)) { n         k--; n         b[tt[i]] = false; n       } n     } n   } n   for (int i = 1; i <= n; i++) tg[belong[i]] = tt[i]; n   len = 0; n   for (int i = 1; i <= m; i++) { n     int x = a[i * 2].x, y = a[i * 2].y; n     if (b[tt[x]] && b[tt[y]] && tt[x] != tt[y]) { n       ins(belong[x], belong[y], col[x] ^ col[y]); n       ins(belong[y], belong[x], col[x] ^ col[y]); n     } n   } n   memset(col, -1, sizeof(col)); n   Ga = 0; n   for (int i = 1; i <= len; i += 2) { n     int x = e[i].x, y = e[i].y; n     if (tg[x] > tg[y]) x ^= y ^= x ^= y; n     if (e[i].bk) { n       Al = tg[x]; n       Be = tg[y]; n       De = true; n       color(x, Ga); n       if (!De) S.insert({tg[x], tg[y]}); n       Ga += 2; n     } n   } n   printf( %lld n , 1ll * k * (k - 1) / 2 - S.size()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double n, m; n   while (cin >> m >> n) { n     double res = 0; n     for (double i = 1; i <= m; i++) { n       res += i * (pow(i / m, n) - pow((i - 1) / m, n)); n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void print(T &x) { n   cout << x; n } n template <class T, class U> n void print(pair<T, U> &p) { n   cout <<  ( ; n   print(p.first); n   cout <<  ,  ; n   print(p.second); n   cout <<  ) ; n } n template <class T> n void print(vector<T> &v) { n   cout <<  { ; n   if (((int)(v).size())) print(v[0]); n   for (int i = 1; i < ((int)(v).size()); i++) cout <<  ,  , print(v[i]); n   cout <<  } n ; n } n const int n = 5e5 + 5; n int N, M, K, T; n vector<long long> A; n int cnt(vector<long long> A, int b) { n   if (((int)(A).size()) == 1) return 1; n   if (((int)(A).size()) == 0) return 0; n   vector<long long> B; n   while (!A.empty() && A[((int)(A).size()) - 1] >= 1LL << b) { n     long long v = A[((int)(A).size()) - 1]; n     A.pop_back(); n     B.push_back(v ^ (1LL << b)); n   } n   int szA = ((int)(A).size()); n   int t1 = cnt(A, b - 1) + (((int)(B).size()) > 0 ? 1 : 0); n   sort(B.begin(), B.end()); n   int t2 = cnt(B, b - 1) + (szA > 0 ? 1 : 0); n   return max(t1, t2); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> N; n   A.resize(N); n   for (long long &a : A) cin >> a; n   sort(A.begin(), A.end()); n   int c = cnt(A, 31); n   cout << N - c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 50; n const int inf = 0x3f3f3f3f; n int n, mod; n long long ans; n int head[maxn], nxt[maxn << 1], to[maxn << 1], cost[maxn << 1], edge_tot; n void add_edge(int u, int v, int c) { n   nxt[++edge_tot] = head[u]; n   head[u] = edge_tot; n   to[edge_tot] = v; n   cost[edge_tot] = c; n } n void change(long long &x, int mod) { x = (x % mod + mod) % mod; } n void ext_gcd(long long a, long long b, long long &d, long long &x, n              long long &y) { n   if (!b) { n     d = a; n     x = 1; n     y = 0; n   } else { n     ext_gcd(b, a % b, d, y, x); n     y -= x * (a / b); n   } n } n long long fac[maxn], inv[maxn]; n void pre() { n   fac[0] = 1; n   for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * 10 % mod; n   for (int i = 0; i < maxn; i++) { n     long long a = fac[i], b = mod; n     long long d, x, y; n     ext_gcd(a, b, d, x, y); n     change(x, mod); n     inv[i] = x; n   } n } n int root; n bool vis[maxn]; n int siz[maxn], mxson[maxn]; n void ndc_init() { mxson[0] = inf; } n void get_root(int u, int f, int sum) { n   siz[u] = 1; n   mxson[u] = 0; n   for (int i = head[u]; i; i = nxt[i]) { n     int v = to[i]; n     if (vis[v] || v == f) continue; n     get_root(v, u, sum); n     siz[u] += siz[v]; n     if (mxson[u] < siz[v]) mxson[u] = siz[v]; n   } n   if (mxson[u] < sum - siz[u]) mxson[u] = sum - siz[u]; n   if (mxson[u] < mxson[root]) root = u; n } n map<long long, int> mp; n void add1(int u, int f, register long long sum, int dep, int op) { n   mp[sum] += op; n   for (int i = head[u]; i; i = nxt[i]) { n     int v = to[i]; n     if (vis[v] || v == f) continue; n     add1(v, u, (sum + fac[dep] * cost[i] % mod) % mod, dep + 1, op); n   } n } n void calc(int u, int f, register long long sum, int dep) { n   if (!sum) ans++; n   long long fd = -inv[dep] * sum; n   change(fd, mod); n   if (mp.count(fd)) ans += mp[fd]; n   for (int i = head[u]; i; i = nxt[i]) { n     int v = to[i]; n     if (vis[v] || v == f) continue; n     calc(v, u, (sum * 10 + cost[i]) % mod, dep + 1); n   } n } n void solve(int u = 1, int sum = n) { n   root = 0; n   get_root(u, 0, sum); n   vis[root] = 1; n   for (int i = head[root]; i; i = nxt[i]) { n     int v = to[i]; n     if (vis[v]) continue; n     add1(v, root, cost[i] % mod, 1, 1); n   } n   if (mp.count(0)) ans += mp[0]; n   for (int i = head[root]; i; i = nxt[i]) { n     int v = to[i]; n     if (vis[v]) continue; n     add1(v, root, cost[i] % mod, 1, -1); n     calc(v, root, cost[i] % mod, 1); n     add1(v, root, cost[i] % mod, 1, 1); n   } n   mp.clear(); n   int root_sz = siz[root]; n   for (int i = head[root]; i; i = nxt[i]) { n     int v = to[i]; n     if (vis[v]) continue; n     solve(v, siz[v]); n   } n } n int main() { n   ans = 0; n   scanf( %d%d , &n, &mod); n   for (int i = 1; i < n; i++) { n     int u, v, c; n     scanf( %d%d%d , &u, &v, &c); n     u++, v++; n     add_edge(u, v, c); n     add_edge(v, u, c); n   } n   pre(); n   ndc_init(); n   solve(); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[41]; n void prec() { n   dp[0] = 0; n   long long x = 1; n   for (int i = int(1); i < int(41); i++) { n     dp[i] = 2 * dp[i - 1] + x; n     x = x << 1; n   } n } n int main(int argc, const char* argv[]) { n   long long n; n   cin >> n; n   prec(); n   n--; n   long long ans = 0; n   long long original = n; n   while (n) { n     long long r = n & (-n); n     ans += dp[(int)log2(r)]; n     n -= r; n   } n   long long i = 1; n   while (i <= original) { n     ans += i & original; n     i = i << 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[100001], i; n   set<int> mysetp, mysetn, left, right; n   set<int>::iterator l, r, p; n   scanf( %d , &n); n   scanf( %d , &a[1]); n   mysetn.insert(-a[1]); n   mysetp.insert(a[1]); n   for (i = 2; i <= n; i++) { n     scanf( %d , &a[i]); n     l = mysetn.lower_bound(-a[i]); n     r = mysetp.lower_bound(a[i]); n     if (*l > 0 || -(*l) > a[i]) { n       left.insert(*r); n       printf( %d n , *r); n     } else if (*r < a[i]) { n       printf( %d n , -(*l)); n     } else if (-(*l) == *r) { n       if (*r > a[i]) left.insert(*r); n       printf( %d n , *r); n     } else { n       p = left.lower_bound(*r); n       if (*p == *r) { n         printf( %d n , -(*l)); n       } else { n         left.insert(*r); n         printf( %d n , *r); n       } n     } n     mysetp.insert(a[i]); n     mysetn.insert(-a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using DB = double; n using LL = long long; n using PII = pair<int, int>; n void err() { puts(  ); } n template <template <typename...> class T, typename t, typename... Args> n void err(T<t> a, Args... args) { n   for (auto x : a) cout << x <<    ; n   err(args...); n } n template <typename T, typename... Args> n void err(T a, Args... args) { n   cout << a <<    ; n   err(args...); n } n const int N = 2e5 + 10; n char s[N], t[N]; n void work() { n   int n, m; n   scanf( %d%d%s%s , &n, &m, s, t); n   int id = -1; n   for (int i = 0; i < n; i++) n     if (s[i] ==  * ) id = i; n   if (id == -1) { n     printf( %s n , strcmp(s, t) == 0 ?  YES  :  NO ); n   } else { n     bool flag = 0; n     if (n - 1 <= m) { n       flag = 1; n       for (int i = 0; i < id; i++) { n         if (s[i] != t[i]) flag = 0; n       } n       for (int i = n - 1, j = m - 1; i > id; i--, j--) { n         if (s[i] != t[j]) flag = 0; n       } n     } n     printf( %s n , flag ?  YES  :  NO ); n   } n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n const long long inf = 1000000000000000000LL; n int a[N]; n long long prefix_cost[N], cost[N], suffix_cost[N]; n set<int> factors; n set<int>::iterator it; n void pf(int x) { n   for (int j = x - 1; j <= x + 1; j++) { n     int d = j; n     for (int i = 2; i * i <= j; i++) { n       if (d % i == 0) { n         factors.insert(i); n         while (d % i == 0) d /= i; n       } n     } n     if (d != 1) factors.insert(d); n   } n } n int main() { n   int n, p, A, B; n   scanf( %d %d %d , &n, &A, &B); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   if (n == 1) { n     printf( 0 n ); n     return 0; n   } n   pf(a[1]); n   pf(a[n]); n   long long ans = inf; n   for (it = factors.begin(); it != factors.end(); ++it) { n     prefix_cost[0] = 0LL; n     p = *it; n     for (int i = 1; i <= n; i++) { n       if (a[i] % p == 0) n         cost[i] = 0LL; n       else if ((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0) n         cost[i] = (long long)B; n       else n         cost[i] = inf; n       prefix_cost[i] = prefix_cost[i - 1] + cost[i]; n       if (prefix_cost[i] > inf) prefix_cost[i] = inf; n     } n     prefix_cost[0] = inf; n     suffix_cost[n + 1] = 0LL; n     long long suffix_sum = 0LL; n     for (int i = n; i > 0; i--) { n       suffix_sum += cost[i]; n       if (suffix_sum > inf) suffix_sum = inf; n       suffix_cost[i] = min(A + suffix_cost[i + 1], suffix_sum); n     } n     ans = min(ans, suffix_cost[1]); n     for (int i = 2; i <= n; i++) n       ans = min(ans, prefix_cost[i - 1] + suffix_cost[i]); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n vector<string> vec_splitter(string s) { n   s +=  , ; n   vector<string> res; n   while (!s.empty()) { n     res.push_back(s.substr(0, s.find( , ))); n     s = s.substr(s.find( , ) + 1); n   } n   return res; n } n void debug_out(vector<string> __attribute__((unused)) args, n                __attribute__((unused)) int idx, n                __attribute__((unused)) int LINE_NUM) { n   cerr << endl; n } n template <typename Head, typename... Tail> n void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { n   if (idx > 0) n     cerr <<  ,  ; n   else n     cerr <<  Line(  << LINE_NUM <<  )  ; n   stringstream ss; n   ss << H; n   cerr << args[idx] <<   =   << ss.str(); n   debug_out(args, idx + 1, LINE_NUM, T...); n } n const long long MOD = (int)1e9 + 7; n const long long INF = 2e18 + 5; n struct hashLL { n   size_t operator()(long long x) const { n     x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); n     x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb); n     x = x ^ (x >> 31); n     return x; n   } n }; n long long inv(long long a, long long b) { n   return 1 < a ? b - inv(b % a, a) * b / a : 1; n } n long long gcd(long long a, long long b, long long& x, long long& y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long d = gcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n long long distsq(long long x1, long long y1, long long x2, long long y2) { n   return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); n } n const int N = 200001; n long long n, m, k, t, u, v; n string s; n unordered_set<int> ks; n unordered_map<int, vector<int>> g; n int visited[N]; n long long tosink[N]; n long long tosource[N]; n void bfs(int start, long long arr[]) { n   for (int i = 0; i < n + 1; i++) arr[i] = -1; n   deque<int> q; n   q.push_back(start); n   arr[start] = 0; n   while (!q.empty()) { n     int n = q.size(); n     for (int i = 0; i < (n); i++) { n       int curr = q.front(); n       q.pop_front(); n       for (int c : g[curr]) { n         if (arr[c] == -1) { n           arr[c] = arr[curr] + 1; n           q.push_back(c); n         } n       } n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m >> k; n   for (int i = 0; i < (k); i++) { n     cin >> u; n     ks.emplace(u); n   } n   for (int i = 0; i < (m); i++) { n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   bfs(1, tosource); n   bfs(n, tosink); n   vector<pair<int, int>> tok; n   map<int, unordered_set<int>> towardssink; n   for (auto& p : ks) { n     tok.push_back(make_pair(tosource[p], p)); n     towardssink[-tosink[p]].emplace(p); n   } n   sort((tok).begin(), (tok).end()); n   long long best = 0; n   for (auto& p : tok) { n     long long mintosource = p.first; n     long long node = p.second; n     towardssink[-tosink[node]].erase(node); n     if (towardssink[-tosink[node]].empty()) { n       towardssink.erase(-tosink[node]); n     } n     if (towardssink.empty()) break; n     auto& pr = *towardssink.begin(); n     long long mxtosink = -pr.first; n     long long curr = 1; n     curr = curr + mintosource + min(tosink[node], mxtosink); n     best = max(best, curr); n   } n   long long normaldist = tosink[1]; n   if (best < normaldist) { n     cout << best << endl; n   } else { n     cout << normaldist << endl; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n template <class T> n T gcd(T a, T b) { n   return ((b == 0) ? a : gcd(b, a % b)); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, q; n   cin >> n >> q; n   vector<int> a(n); n   set<int> st; n   multiset<int> mlt; n   for (int i = 0; i < (int)(n); i++) cin >> a[i], st.insert(a[i]); n   sort(a.begin(), a.end()); n   for (int i = (int)(1); i < (int)(n); i++) mlt.insert(a[i] - a[i - 1]); n   int r = a[n - 1], l = a[0]; n   for (int i = 0; i < (int)(q + 1); i++) { n     if (mlt.size()) { n       auto it = --mlt.end(); n       int mx = *it; n       cout << r - l - mx <<   n ; n     } else n       cout << 0 <<   n ; n     if (i == q) continue; n     int t; n     cin >> t; n     if (t == 0) { n       int x; n       cin >> x; n       if (*st.begin() == x) { n         auto it = st.begin(); n         it++; n         if (it != st.end()) { n           auto it2 = mlt.find(*it - *st.begin()); n           if (it2 != mlt.end()) mlt.erase(it2); n         } n       } else { n         auto it = st.lower_bound(x); n         it--; n         if (mlt.find(x - *it) != mlt.end()) mlt.erase(mlt.find(x - *it)); n         auto it1 = it; n         it1++; n         it1++; n         if (it1 != st.end()) { n           auto it2 = mlt.find(*it1 - x); n           if (it2 != mlt.end()) mlt.erase(it2); n           mlt.insert(*it1 - *it); n         } n       } n       auto it = st.find(x); n       if (it != st.end()) st.erase(it); n     } else { n       int x; n       cin >> x; n       if (st.size()) { n         auto it = st.lower_bound(x); n         if (it != st.end()) { n           mlt.insert(*it - x); n           if (it != st.begin()) { n             auto it1 = it; n             it1--; n             mlt.insert(x - *it1); n             auto it2 = mlt.find(*it - *it1); n             if (it2 != mlt.end()) mlt.erase(it2); n           } n         } else { n           if (it != st.begin()) { n             it--; n             mlt.insert(x - *it); n           } n         } n       } n       st.insert(x); n     } n     if (st.size()) { n       l = *st.begin(); n       r = *(--st.end()); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m; n int k; n vector<int> a; n long long memo[66][2][66]; n long long dp(int id, int tight, int cnt) { n   long long &res = memo[id][tight][cnt]; n   if (res == -1) { n     res = 0; n     if (id == a.size()) { n       if (cnt == k) res = 1; n     } else { n       for (int i = 0; i < 2; i++) { n         if (tight && i > a[id]) continue; n         int new_tight = tight ? i == a[id] : false; n         int new_cnt = cnt + (i == 1 ? 1 : 0); n         res += dp(id + 1, new_tight, new_cnt); n       } n     } n   } n   return res; n } n long long solve(long long n) { n   a.clear(); n   while (n) { n     a.push_back(n % 2); n     n /= 2; n   } n   a.push_back(0); n   reverse(a.begin(), a.end()); n   memset(memo, -1, sizeof(memo)); n   return dp(0, 1, 0); n } n long long possible(long long n) { return solve(2 * n) - solve(n); } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> m >> k; n   long long lo = 1, hi = (long long)1e18 + 15; n   long long ans = -1; n   while (lo <= hi) { n     long long mid = (lo + hi) / 2; n     if (possible(mid) == m) { n       ans = mid; n       break; n     } n     if (possible(mid) < m) { n       lo = mid + 1; n     } else n       hi = mid - 1; n   } n   assert(ans != -1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(int a, int b) { return a > b; } n int main() { n   int n, a, index; n   cin >> n; n   vector<int> A; n   int temp; n   int count = 0; n   for (int i = 0; i < n; i++) { n     cin >> a; n     A.push_back(a); n   } n   for (int i = 0; i < n; i++) { n     if (A[i] == 1) { n       count++; n       index = i; n       break; n     } n   } n   for (int i = index + 1; i < n; i++) { n     if (A[i] == 1 && A[i - 1] == 1) n       count++; n     else if (A[i] == 1 && A[i - 1] == 0) n       count += 2; n     else n       continue; n   } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   vector<long long> v, ans; n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     long long q; n     cin >> q; n     v.push_back(q); n   } n   sort(v.begin(), v.end()); n   bool cur = 0; n   while (!v.empty()) { n     if (!cur) { n       cout << v.front(); n       v.erase(v.begin()); n     } else { n       cout << v.back(); n       v.erase(v.begin() + v.size() - 1); n     } n     cout <<    ; n     cur = 1 - cur; n   } n } n signed main() { n   long long t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF64 = (long long)(1e18) + 10; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int q = 1, i, j, test, k; n   for (test = 1; test < (q + 1); test++) { n     long long n, ans = 0, x = 0; n     cin >> n; n     vector<long long> v(n); n     for (i = 0; i < (n); i++) cin >> v[i]; n     map<long long, long long> prefodd, prefeven; n     prefodd[0]++; n     for (i = 0; i < (n); i++) { n       x = x ^ v[i]; n       if (i & 1) n         ans += prefodd[x], prefodd[x]++; n       else n         ans += prefeven[x], prefeven[x]++; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool isBeautiful(int n) { n   bool flag[10]; n   for (int i = 0; i < 10; i++) flag[i] = false; n   while (n > 0) { n     int digit = n % 10; n     if (flag[digit]) return false; n     flag[digit] = true; n     n = n / 10; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   if (isBeautiful(n)) n++; n   while (!isBeautiful(n)) { n     n++; n   } n   cout << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long INF = (1e15) + 1; n int n, dp[100004], par[100004]; n long long d, arr[100004]; n struct Node { n   Node *leftNode, *rightNode; n   long long leftBound, rightBound; n   pair<int, int> mx; n   Node() { n     leftNode = rightNode = NULL; n     leftBound = rightBound = 0LL; n     mx = {0, 0}; n   } n }; n void update(Node *par, long long pos, int dpMax, int ind) { n   if (par->leftBound == pos && par->rightBound == pos) { n     if ((par->mx).first < dpMax) { n       par->mx = {dpMax, ind}; n     } n     return; n   } n   long long mid = (par->leftBound + par->rightBound) >> 1; n   if (pos <= mid) { n     if (par->leftNode == NULL) par->leftNode = new Node(); n     par->leftNode->leftBound = par->leftBound; n     par->leftNode->rightBound = mid; n     update(par->leftNode, pos, dpMax, ind); n     if ((par->leftNode->mx).first > (par->mx).first) { n       par->mx = par->leftNode->mx; n     } n   } else { n     if (par->rightNode == NULL) par->rightNode = new Node(); n     par->rightNode->leftBound = mid + 1; n     par->rightNode->rightBound = par->rightBound; n     update(par->rightNode, pos, dpMax, ind); n     if ((par->rightNode->mx).first > (par->mx).first) { n       par->mx = par->rightNode->mx; n     } n   } n } n pair<int, int> query(Node *par, long long l, long long r) { n   if (par == NULL || par->leftBound > r || par->rightBound < l) { n     return {0, 0}; n   } n   if (par->leftBound >= l && par->rightBound <= r) { n     return par->mx; n   } n   long long mid = (par->leftBound + par->rightBound) >> 1; n   pair<int, int> p1 = query(par->leftNode, l, r); n   pair<int, int> p2 = query(par->rightNode, l, r); n   if (p1.first > p2.first) n     return p1; n   else n     return p2; n } n int main() { n   scanf( %d%lld , &n, &d); n   for (int i = 1; i <= n; i++) scanf( %lld , &arr[i]); n   Node *root = new Node(); n   root->leftBound = 0LL; n   root->rightBound = INF; n   int ans = 0, curInd = 0; n   for (int i = 1; i <= n; i++) { n     long long l = max(0LL, arr[i] - d); n     long long r = min(INF, arr[i] + d); n     pair<int, int> p1 = query(root, 1LL, l); n     pair<int, int> p2 = query(root, r, INF); n     pair<int, int> p = p1; n     if (p.first < p2.first) p = p2; n     dp[i] = p.first + 1; n     par[i] = p.second; n     update(root, arr[i], dp[i], i); n     if (dp[i] > ans) { n       ans = dp[i]; n       curInd = i; n     } n   } n   printf( %d n , ans); n   vector<int> inds; n   while (curInd != 0) { n     inds.push_back(curInd); n     curInd = par[curInd]; n   } n   reverse(inds.begin(), inds.end()); n   for (int i = 0; i <= inds.size() - 1; i++) { n     printf( %d  , inds[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void Read(T &x) { n   x = 0; n   char c; n   while (!isdigit(c = getchar())) n     ; n   do { n     x = x * 10 + c -  0 ; n   } while (isdigit(c = getchar())); n } n long long read() { n   long long tmp; n   cin >> tmp; n   return tmp; n } n void giuncute() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n void OF() { n   freopen( n        f  n        .inp , n        r , stdin); n   freopen( n        f  n        .out , n        w , stdout); n } n const long long MOD = 1e9 + 7, mxn = 5e3 + 2; n long long n, a[mxn] = {0}, numNode[mxn] = {0}, p[mxn]; n int down[mxn][mxn] = {{0}}, up[mxn][2] = {{0}}; n long long Pow(long long u, long long v) { n   if (!v) return 1; n   long long tmp = Pow(u, v >> 1); n   (tmp *= tmp) %= MOD; n   if (v & 1) return (tmp * u) % MOD; n   return tmp; n } n int main() { n   giuncute(); n   cin >> n; n   numNode[1] = 1; n   for (long long i = 1; i <= n - 1; ++i) { n     cin >> a[i]; n     numNode[i + 1] = (numNode[i] * a[i]) % MOD; n     p[i] = Pow(a[i], MOD - 2); n   } n   for (long long i = 1; i <= n; ++i) down[i][1] = a[i], up[i][1] = 1; n   up[1][1] = 0; n   for (long long i = n - 1; i >= 1; --i) n     for (long long j = 2; j <= n - i; ++j) n       down[i][j] = (a[i] * down[i + 1][j - 1]) % MOD; n   long long p2 = Pow(2, MOD - 2); n   for (long long j = 1; j <= n * 2 - 2; ++j) { n     long long cnt_up = 0, cnt_down = 0; n     if (j != 1) n       for (long long i = 2; i <= n; ++i) { n         if (j > n + i - 2) continue; n         (up[i][j & 1] += up[i - 1][~j & 1]) %= MOD; n         if (j <= n && down[i - 1][j - 1]) n           (up[i][j & 1] += n            (down[i - 1][j - 1] * (((a[i - 1] - 1) * p[i - 1]) % MOD)) % MOD) %= n               MOD; n       } n     for (long long i = 1; i <= n; ++i) { n       up[i][~j & 1] = 0; n       if (j > n + i - 2) continue; n       (cnt_up += (numNode[i] * up[i][j & 1]) % MOD) %= MOD; n       if (j < n) (cnt_down += (numNode[i] * down[i][j]) % MOD) %= MOD; n     } n     cout << (((cnt_up + cnt_down) % MOD) * p2) % MOD <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n ostream& operator<<(ostream& out, const pair<A, B>& p) { n   out <<  (  << p.first <<  ,  << p.second <<  )  ; n   return out; n } n template <typename A, typename B> n void printP(const pair<A, B>& p, const char* str = NULL) { n   if (!(1 && !1)) return; n   if (str != NULL) cout << str <<  : ; n   cout <<  (  << p.first <<  ,  << p.second <<  )  ; n } n template <typename T> n void printV(const vector<T>& v, const char* str = NULL) { n   if (!(1 && !1)) return; n   if (str != NULL) cout << str <<  :  ; n   for (int i = 0; i < (v.size()); ++i) cout << v[i] <<    ; n   cout << endl; n } n template <typename T> n void printC(T& container, const char* str = NULL) { n   if (!(1 && !1)) return; n   if (str != NULL) cout << str <<  : ; n   for (__typeof((container).begin()) it = ((container).begin()); n        it != (container).end(); ++it) { n     cout << (*it) <<    ; n   } n   cout << endl; n } n const int INF = 1000010111; n const int S_N = 152; n const int MOD = 1000000007; n int main() { n   int n; n   cin >> n; n   vector<int> t1, t2; n   for (int i = 0; i < n; i++) { n     int thick, width; n     cin >> thick >> width; n     ((thick == 1) ? t1 : t2).push_back(width); n   } n   sort(t1.begin(), t1.end(), greater<int>()); n   sort(t2.begin(), t2.end(), greater<int>()); n   int mini = INF; n   for (int c1 = 0; c1 <= t1.size(); c1++) { n     for (int c2 = 0; c2 <= t2.size(); c2++) { n       int tSum = 1 * c1 + 2 * c2; n       int wSum = 0; n       for (int i = c1; i < t1.size(); i++) wSum += t1[i]; n       for (int i = c2; i < t2.size(); i++) wSum += t2[i]; n       if (tSum >= wSum) mini = min(mini, tSum); n     } n   } n   cout << mini << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500010; n int n, a; n multiset<int> st; n int main() { n   cin >> n; n   st.insert(0); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a); n     if (st.find(a) != st.end()) { n       st.erase(st.find(a)); n       st.insert(i); n     } else { n       st.insert(i); n     } n   } n   cout << st.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[200005]; n long long n; n map<long long, long long> ans; n bool debug = false; n long long rec(long long node) { n   if (debug) cout <<  entering   << node << endl; n   if (node == 1) return 1000000000000; n   if (node <= 0 || node > n) return 0; n   if (ans.count(node) && ans[node] == -1000000000000) n     return ans[node] = 1000000000000; n   if (ans.count(node)) { n     if (debug) cout <<  already computed for   << node << endl; n     return ans[node]; n   } n   ans[node] = -1000000000000; n   long long val = 0; n   long long n1 = node + arr[node]; n   val += arr[node]; n   if (n1 <= 0 || n1 > n) return ans[node] = val; n   long long n2 = n1 - arr[n1]; n   val += arr[n1]; n   return ans[node] = val + rec(n2); n } n int main() { n   scanf( %lld , &n); n   for (__typeof(n - 1) i = 0; i < n - 1; i++) scanf( %lld , &arr[i + 2]); n   long long k; n   for (__typeof(n) i = 2; i <= n; i++) { n     long long val = i - 1; n     long long nex = i - arr[i]; n     val += arr[i]; n     k = rec(nex) + val; n     if (k >= 1000000000000) n       cout << -1 << endl; n     else n       cout << k << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e4 + 100; n int a[25]; n int ans[25]; n map<int, int> mp; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     ans[i] = a[i]; n   } n   sort(ans, ans + n); n   for (int i = 0; i < n; i++) { n     if (i == 0) n       mp[ans[i]] = ans[n - 1]; n     else n       mp[ans[i]] = ans[i - 1]; n   } n   for (int i = 0; i < n; i++) printf( %d  , mp[a[i]]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a; n   cin >> n >> a; n   vector<int> vi(n); n   for (int i = 0; i < n; ++i) cin >> vi[i]; n   sort((vi).begin(), (vi).end()); n   if (n == 1) n     cout << 0; n   else if (a <= vi[0]) n     cout << llabs(vi[n - 2] - a); n   else if (a >= vi[n - 1]) n     cout << llabs(vi[1] - a); n   else { n     long long ans1, ans2, ans3, ans4; n     ans1 = llabs(vi[0] - a) + llabs(vi[0] - vi[n - 2]); n     ans2 = llabs(vi[1] - a) + llabs(vi[1] - vi[n - 1]); n     ans3 = llabs(vi[n - 1] - a) + llabs(vi[n - 1] - vi[1]); n     ans4 = llabs(vi[n - 2] - a) + llabs(vi[n - 2] - vi[0]); n     cout << min(min(ans1, ans2), min(ans3, ans4)); n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int m[11]; n int dig(int i) { n   while (i) { n     if (m[i % 10]) return 1; n     i /= 10; n   } n   return 0; n } n int main() { n   int n, i, s(0); n   cin >> n; n   int temp = n; n   for (int i = 0; i < 11; i++) m[i] = 0; n   while (temp) { n     m[temp % 10] = 1; n     temp /= 10; n   } n   for (int i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       s += dig(i); n       if (i != sqrt(n)) s += dig(n / i); n     } n   } n   cout << s << 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   long long n, a, b, ans; n   cin >> n >> a >> b; n   if (b > 0) { n     ans = (a + b) % n; n     if (ans == 0) ans = n; n   } else if (b < 0) { n     if (a > abs(b)) { n       ans = a - abs(b); n     } else { n       ans = n - abs(a + b) % n; n     } n   } else n     ans = a; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<char, int> ma; n   int p; n   char a, k[1000]; n   cin >> p; n   for (int i = 0; i < p; i++) { n     cin >> k[i]; n     a = tolower(k[i]); n     ma[a]++; n   } n   if (ma.size() == 26) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long oo = 3e18, M = 54; n long long q, n, k; n string F = n      What are you doing at the end of the world? Are you busy? Will you save   n      us? ; n string X =  What are you doing while sending   ; n string Y =   ? Are you busy? Will you send   ; n string Z =   ? ; n long long length(int n) { n   if (n >= M) { n     return oo; n   } n   long long tot = X.size() + Y.size() + Z.size(); n   long long len = ((1LL << n) - 1) * tot + (1LL << n) * F.size(); n   return len; n } n char solve(long long i, long long k) { n   if (i == 0) { n     return k > F.size() ?  .  : F[k - 1]; n   } n   long long len = length(i - 1); n   if (X.size() + len + Y.size() + len + Z.size() < k) { n     return  . ; n   } else if (X.size() + len + Y.size() + len < k) { n     k -= X.size() + len + Y.size() + len; n     return Z[k - 1]; n   } else if (X.size() + len + Y.size() < k) { n     k -= X.size() + len + Y.size(); n     return solve(i - 1, k); n   } else if (X.size() + len < k) { n     k -= X.size() + len; n     return Y[k - 1]; n   } else if (X.size() < k) { n     k -= X.size(); n     return solve(i - 1, k); n   } else { n     return X[k - 1]; n   } n } n int main() { n   cin >> q; n   while (q--) { n     cin >> n >> k; n     cout << solve(n, k); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 7; n const double eps = 1e-9; n int a[maxn]; n int main() { n   std::ios::sync_with_stdio(false); n   int n, sum = 0; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i]; n   sort(a, a + n); n   int ans = 0; n   while (fabs(round(1.0 * sum / n) - 5.0) > eps) { n     sum += 5 - a[0]; n     ++ans; n     a[0] = 5; n     sort(a, a + n); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n, m, p; n   cin >> n >> m >> p; n   vector<long long> a(n); n   for (long long i = 0; i < n; ++i) cin >> a[i]; n   vector<long long> b(m); n   for (long long i = 0; i < m; ++i) cin >> b[i]; n   for (long long i = 0; i < n; ++i) { n     bool flag = false; n     if (a[i] % p != 0) { n       for (long long j = 0; j < m; ++j) { n         if (b[j] % p != 0) { n           flag = true; n           cout << i + j; n           break; n         } n       } n       if (flag) { n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using std::ios; n constexpr int MOD = 1e9 + 7; n constexpr int mod = 998244353; n template <typename T> n T power(T a, T b) { n   T r = 1; n   while (b) { n     if (b & 1) r *= a; n     b /= 2; n     a *= a; n   } n   return r; n } n int d[100005]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int tt = 1; n   while (tt--) { n     int n; n     cin >> n; n     vector<int> b(n), d(n); n     map<int, int> ans; n     for (int i = 0; i < n; i++) { n       cin >> b[i] >> d[i]; n       ans[b[i]]++; n       ans[d[i]]--; n     } n     int mx = 0, id = 0; n     int sum = 0; n     for (auto i : ans) { n       i.second += sum; n       sum = i.second; n       if (i.second > mx) { n         mx = i.second; n         id = i.first; n       } n     } n     cout << id <<     << mx; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int n; n     string s; n     cin >> n; n     cin >> s; n     int flag = 0; n     int p = n / 2; n     p = p - 1; n     for (int i = 0; i <= p; i++) { n       if ((abs(s[i] - s[n - 1 - i]) != 2) && (s[i] != s[n - 1 - i])) { n         cout <<  NO  << endl; n         flag = 1; n         break; n       } n     } n     if (flag == 1) { n       continue; n     } n     cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int o[100100]; n int ans[6000100]; n int main() { n   int i, j, n; n   int e = 0; n   long long x, y; n   long long m, tmp, st, ed, mid; n   scanf( %d %I64d , &n, &m); n   for (i = 1; i <= n; i++) scanf( %d , &o[i]); n   sort(o + 1, o + n + 1); n   o[0] = 0; n   o[n + 1] = 1000000001; n   for (i = 0; i <= n; i++) { n     x = o[i] + 1; n     y = o[i + 1] - 1; n     if (x <= y) { n       tmp = ((x + y) * (y - x + 1)) >> 1; n       if (m - tmp >= 0) { n         m -= tmp; n         for (j = x; j <= y; j++) ans[e++] = j; n       } else { n         st = x; n         ed = y; n         while (st < ed) { n           mid = (st + ed) >> 1; n           tmp = ((x + mid) * (mid - x + 1)) >> 1; n           if (tmp <= m) n             st = mid + 1; n           else n             ed = mid; n         } n         st--; n         tmp = 0; n         if (x <= st) { n           tmp = ((x + st) * (st - x + 1)) >> 1; n           m -= tmp; n           for (j = x; j <= st; j++) ans[e++] = j; n         } n       } n     } n   } n   printf( %d n , e); n   for (i = 0; i < e; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 110; n int n, m, x, y, c[maxn]; n int lowbit(int x) { return x & -x; } n void add(int x, int k) { n   for (; x <= n; x += lowbit(x)) { n     c[x] += k; n   } n } n int Query(int x) { n   int ans = 0; n   for (; x; x -= lowbit(x)) { n     ans += c[x]; n   } n   return ans; n } n int main() { n   scanf( %d%d , &n, &m); n   while (m--) { n     scanf( %d%d , &x, &y); n     add(x, 1), add(y + 1, -1); n   } n   for (int i = 1; i <= n; ++i) { n     if (Query(i) != 1) { n       printf( %d %d , i, Query(i)); n       return 0; n     } n   } n   puts( OK ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 10; n int n, m, q, v[maxn], lp[maxn]; n vector<int> e[maxn], t[maxn]; n vector<long long> ps[maxn]; n int mx, argmx; n void dfs(int id, int p, int d, int cpn) { n   if (cpn) v[id] = cpn; n   lp[id] = max(lp[id], d); n   if (d > mx) { n     mx = d; n     argmx = id; n   } n   if (cpn) t[cpn].push_back(lp[id]); n   for (int i = 0; i < e[id].size(); i++) n     if (e[id][i] != p) dfs(e[id][i], id, d + 1, cpn); n } n int main() { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   int cpn = 0; n   for (int i = 1; i <= n; i++) n     if (!v[i]) { n       mx = -1; n       dfs(i, 0, 0, 0); n       mx = -1; n       dfs(argmx, 0, 0, 0); n       mx = -1; n       dfs(argmx, 0, 0, ++cpn); n       sort(t[cpn].begin(), t[cpn].end()); n       ps[cpn].push_back(0); n       for (int j = 0; j < t[cpn].size(); j++) n         ps[cpn].push_back(ps[cpn].back() + t[cpn][j]); n     } n   map<pair<int, int>, double> res; n   for (int i = 0; i < q; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     x = v[x]; n     y = v[y]; n     if (x == y) n       printf( -1 n ); n     else { n       if (t[x].size() > t[y].size()) swap(x, y); n       if (!res.count({x, y})) { n         auto ans = 0LL; n         int mxd = max(t[x].back(), t[y].back()); n         for (int j = 0; j < t[x].size(); j++) { n           int l = lower_bound(t[y].begin(), t[y].end(), mxd - 1 - t[x][j]) - n                   t[y].begin(); n           ans += 1LL * l * mxd + 1LL * (t[y].size() - l) * (t[x][j] + 1) + n                  ps[y].back() - ps[y][l]; n         } n         res.insert({{x, y}, ans * 1.0 / t[x].size() / t[y].size()}); n       } n       printf( %.10lf n , res[{x, y}]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1, ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n inline void write(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x >= 10) write(x / 10); n   putchar(x % 10 +  0 ); n } n inline void writeln(long long x) { n   write(x); n   puts(  ); n } n const long long N = 5e5 + 5; n long long q, sum[N], a[N], cnt; n inline double f(long long x) { n   return (double)a[cnt] - (sum[x] + a[cnt]) / (double)(x + 1); n } n signed main() { n   q = read(); n   for (long long i = 1; i <= q; i++) { n     long long l, r, opt = read(); n     if (opt == 1) { n       a[++cnt] = read(); n       sum[cnt] = sum[cnt - 1] + a[cnt]; n     } else { n       l = 1, r = cnt - 1; n       while (l < r - 2) { n         long long k = (r - l) / 3; n         long long lmid = l + k, rmid = r - k; n         if (f(lmid) > f(rmid)) { n           r = rmid; n         } else { n           if (f(lmid) < f(rmid)) { n             l = lmid; n           } else { n             l = lmid; n             r = rmid; n           } n         } n       } n       double ans = 0; n       for (long long j = l; j <= r; j++) ans = max(ans, f(j)); n       printf( %.8lf n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n struct PP { n   int l, r, k; n   int rank, ans; n   bool operator<(const PP& b) const { n     if (r == b.r) return l < b.l; n     return r < b.r; n   } n } a[MAXN], b[MAXN]; n struct Point { n   int l, r, rank; n   bool operator<(const Point& b) const { n     if (l == b.l) { n       if (r == b.r) return rank < b.rank; n       return r < b.r; n     } n     return l < b.l; n   } n }; n int n, m; n int res[MAXN]; n void input() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i].l >> a[i].r; n     a[i].rank = i; n   } n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> b[i].l >> b[i].r >> b[i].k; n     b[i].rank = i; n   } n } n bool cmp(const PP& a, const PP& b) { return a.rank < b.rank; } n void solve() { n   sort(a, a + n); n   sort(b, b + m); n   set<Point> s; n   int cnt = n; n   for (int i = 0, j = 0; i < m; i++) { n     while (j < n && a[j].r <= b[i].r) { n       s.insert((Point){a[j].l, a[j].r, j}); n       j++; n     } n     for (int z = 0; z < b[i].k; z++) { n       auto it = s.lower_bound((Point){b[i].l, 0, 0}); n       if (it == s.end()) break; n       a[it->rank].ans = b[i].rank + 1; n       s.erase(it); n       cnt--; n     } n   } n   if (s.size() != 0 || cnt != 0) { n     cout <<  NO  << endl; n     return; n   } n   sort(a, a + n, cmp); n   cout <<  YES  << endl; n   cout << a[0].ans; n   for (int i = 1; i < n; i++) cout <<     << a[i].ans; n   cout << endl; n } n int main() { n   ios::sync_with_stdio(false); n   input(); n   solve(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   string s; n   cin >> s; n   int i, j, res = 0; n   for (i = 0; i < n; i++) { n     if (s[i] ==  . ) { n       res++; n     } else if (s[i] ==  L ) { n       res = 0; n     } else { n       for (j = i + 1; j < n; j++) { n         if (s[j] ==  L ) { n           break; n         } n       } n       if (j >= n) { n         break; n       } n       res += (j - i - 1) % 2; n       i = j; n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n int n, m, p; n int a[200004], b[200004]; n int sol[200004]; n int ns = 0; n int main() { n   scanf( %d%d%d , &n, &m, &p); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 1; i <= m; ++i) scanf( %d , &b[i]); n   int num = m; n   for (int i = 1; i <= p && i + (m - 1) * 1ll * p <= n; ++i) { n     mp.clear(); n     num = m; n     for (int j = 1; j <= m; ++j) mp[b[j]]++; n     for (int j = i, cc = 0; j <= n; j += p) { n       ++cc; n       mp[a[j]]--; n       if (mp[a[j]] == 0) mp.erase(a[j]); n       if (mp.empty()) sol[ns++] = j - (m - 1) * p; n       if (cc == m) { n         --cc; n         int x = a[j - cc * p]; n         mp[x]++; n         if (mp[x] == 0) mp.erase(x); n       } n     } n   } n   sort(sol, sol + ns); n   cout << ns << endl; n   for (int i = 0; i < ns; ++i) printf( %d  , sol[i]); n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 65 + 5, maxk = (1 << 15) + 5, mod = 1e9 + 7, n                 inf = 0x3f3f3f3f; n long long n, m, Q, K, T, S; n long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n long long a[maxn], jc[maxn], inv[maxn], du[maxn], ST[maxn]; n long long q[maxn], top, cont[maxk], val[maxn]; n long long cnt, tot, dp[maxn][maxk]; n long long ans = 1; n long long kpow(long long x, long long k) { n   long long ans = 1, now = x; n   while (k) { n     if (k & 1) ans = 1ll * ans * now % mod; n     now = 1ll * now * now % mod, k >>= 1; n   } n   return ans; n } n bool cmp(long long x, long long y) { return x > y; } n long long C(long long a, long long b) { n   if (a < b) return 0; n   return 1ll * jc[a] * inv[b] % mod * inv[a - b] % mod; n } n void dfs(long long x, long long st) { n   if (ST[x]) return; n   ++tot, ST[x] = st; n   for (long long i = (1); i <= (n); ++i) n     if ((a[i] % a[x] == 0) || (a[x] % a[i] == 0)) dfs(i, st); n } n void clear() { n   top = 0; n   tot = 0; n   memset(cont, 0, sizeof(cont)); n   memset(dp, 0, sizeof(dp)); n } n signed main() { n   n = read(); n   jc[0] = inv[0] = 1; n   for (long long i = (1); i <= (n); ++i) n     jc[i] = 1ll * jc[i - 1] * i % mod, inv[i] = kpow(jc[i], mod - 2); n   for (long long i = (1); i <= (n); ++i) a[i] = read(); n   sort(a + 1, a + 1 + n); n   for (long long i = (1); i <= (n); ++i) n     for (long long j = (i + 1); j <= (n); ++j) n       if (!(a[j] % a[i])) ++du[j]; n   for (long long T = (1); T <= (n); ++T) { n     if (ST[T]) continue; n     clear(); n     dfs(T, T); n     for (long long i = (1); i <= (n); ++i) n       if (!du[i] && ST[i] == T) q[++top] = a[i]; n     if (tot - top <= 1) continue; n     for (long long i = (1); i <= (n); ++i) { n       if (!du[i] || ST[i] != T) continue; n       for (long long j = (1); j <= (top); ++j) n         if (!(a[i] % q[j])) val[i] |= (1 << (j - 1)); n     } n     S = (1 << top) - 1; n     for (long long s = (0); s <= (S); ++s) n       for (long long j = (1); j <= (n); ++j) n         if (ST[j] == T && du[j] && ((s & val[j]) == val[j])) ++cont[s]; n     for (long long i = (1); i <= (n); ++i) n       if (ST[i] == T && du[i]) ++dp[1][val[i]]; n     for (long long i = (1); i <= (tot - top - 1); ++i) n       for (long long s = (0); s <= (S); ++s) { n         if (!dp[i][s]) continue; n         if (cont[s] > i) n           dp[i + 1][s] = n               (dp[i + 1][s] + 1ll * dp[i][s] * (cont[s] - i) % mod) % mod; n         for (long long j = (1); j <= (n); ++j) n           if (ST[j] == T && du[j] && (s & val[j]) && ((s & val[j]) != val[j])) n             dp[i + 1][s | val[j]] = (dp[i + 1][s | val[j]] + dp[i][s]) % mod; n       } n     long long res = 0; n     tot -= top; n     for (long long s = (0); s <= (S); ++s) res = (res + dp[tot][s]) % mod; n     ans = 1ll * ans * res % mod * C(cnt + tot - 1, tot - 1) % mod; n     cnt += tot - 1; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   while (cin >> n) { n     long long g[200000] = {0}; n     long long a[200000] = {0}, i; n     long long sum = 0; n     for (i = 1; i <= n; i++) cin >> a[i]; n     long long ans = 0; n     long long m1 = 0, m2 = 0; n     while (sum < n) { n       long long p = 0; n       for (int i = 1; i <= n; i++) { n         while (g[i] == 0) { n           g[i] = 1; n           i = a[i]; n           p++; n         } n         if (p) { n           sum += p; n           ans += p * p; n           if (p >= m1) { n             m2 = m1; n             m1 = p; n           } else if (p > m2) n             m2 = p; n           break; n         } n       } n     } n     ans += 2 * m1 * m2; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, t; n int a[25][25]; n int vis[25]; n int dfs(int x, int sum, int limit) { n   if (sum > limit) return 0; n   if (x == n + 1) return 1; n   int ans = dfs(x + 1, sum, limit); n   for (int i = 1; i <= n; i++) n     if (vis[i] == 0 && a[x][i]) n       vis[i] = 1, ans += dfs(x + 1, sum + a[x][i], limit), vis[i] = 0; n   return ans; n } n int check(int x) { return dfs(1, 0, x) >= t; } n int main() { n   scanf( %d%d%d , &n, &k, &t); n   for (int i = 1; i <= k; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     a[x][y] = z; n   } n   int l = 0, r = 2e5; n   int ans = -1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       r = mid - 1, ans = mid; n     else n       l = mid + 1; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c, a, b; n   scanf( %d %d %d %d , &n, &c, &a, &b); n   a--; n   b--; n   int ca = a % c, cb = b % c; n   if (ca == 0) { n     if ((cb == (c - 1)) or b == (n - 1)) n       printf( 1 n ); n     else if (b / c == a / c) n       printf( 1 n ); n     else n       printf( 2 n ); n   } else if (cb == (c - 1)) { n     if (b / c == a / c) n       printf( 1 n ); n     else n       printf( 2 n ); n   } else if (a / c == b / c) n     printf( 1 n ); n   else if (b / c == a / c + 1) n     printf( 2 n ); n   else if (b == (n - 1)) n     printf( 2 n ); n   else if (b % c == (a % c) - 1) n     printf( 2 n ); n   else n     printf( 3 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool checkThree(char cc, char lc, char nc) { return (cc != lc && cc != nc); } n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s, t; n     cin >> s >> t; n     for (int i = 0; i < s.length(); i++) { n       int x = t.find(s[i]); n       if (x < t.length()) { n         cout <<  YES  << endl; n         goto label; n       } n     } n     cout <<  NO  << endl; n   label:; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000000000 ) n using namespace std; n int n, m; n vector<pair<int, int> > ans; n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     ans.clear(); n     cin >> n >> m; n     int k = 0; n     for (int i = 0; i < n; i++) n       for (int j = i + 1; j < n; j++) { n         if (k == (2 * n + m)) { n           i = n; n           break; n         } n         k++; n         ans.push_back(make_pair(i + 1, j + 1)); n       } n     for (int i = 0; i < ans.size(); i++) n       cout << ans[i].first <<     << ans[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n signed main(void) { n   vector<long long> in(101, 0); n   long long sum = 0; n   for (long long i = 0; i < (5); i++) { n     long long a; n     cin >> a; n     in[a]++; n     sum += a; n   } n   long long ans = sum; n   for (long long i = 0; i < (101); i++) n     if (in[i] > 1) ans = min(ans, sum - min(in[i], 3LL) * i); n   cout << ans << 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 a1, a2, b1, b2; n     cin >> a1 >> a2; n     cin >> b1 >> b2; n     if ((a2 == b2 && (a1 + b1 == a2)) || (a1 == b1 && (a2 + b2 == a1)) || n         (a2 == b1 && (a1 + b2 == a2)) || (a1 == b2 && (a2 + b1 == a1))) { n       cout <<  Yes  << endl; n     } else { n       cout <<  No  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000 + 5], b[1000 + 5]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= m; i++) scanf( %d , &b[i]); n   int ans = 0; n   for (int i = 1, j = 1; i <= n; i++) { n     if (b[j] >= a[i]) { n       j++; n       ans++; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[300010], po[300010], ans; n int n, p = 1e9 + 7; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   sort(a + 1, a + n + 1); n   po[0] = 1; n   for (int i = 1; i <= n; i++) po[i] = po[i - 1] * 2 % p; n   for (int i = 1; i <= n; i++) n     (ans += a[i] * (p + po[i - 1] - po[n - i]) % p) %= p; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int matrix[101][101]; n struct HATE { n   int t, r, c, x; n   HATE(int t, int r, int c, int x) { n     this->t = t; n     this->r = r; n     this->c = c; n     this->x = x; n   } n }; n HATE* hates[10001]; n int main() { n   int n, m, q; n   cin >> n >> m >> q; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       matrix[i][j] = 1e9 + 1; n     } n   } n   for (int heh = 0; heh < q; heh++) { n     int t; n     cin >> t; n     if (t == 1) { n       int r; n       cin >> r; n       hates[heh] = new HATE(t, r, 0, 0); n     } else if (t == 2) { n       int c; n       cin >> c; n       hates[heh] = new HATE(t, 0, c, 0); n     } else { n       int r, c, x; n       cin >> r >> c >> x; n       hates[heh] = new HATE(t, r, c, x); n     } n   } n   for (int heh = q - 1; heh >= 0; heh--) { n     int t = hates[heh]->t; n     int r = hates[heh]->r; n     int c = hates[heh]->c; n     int x = hates[heh]->x; n     if (t == 1) { n       r--; n       int temp = matrix[r][m - 1]; n       for (int i = m - 1; i >= 1; i--) { n         matrix[r][i] = matrix[r][i - 1]; n       } n       matrix[r][0] = temp; n     } else if (t == 2) { n       c--; n       int temp = matrix[n - 1][c]; n       for (int i = n - 1; i >= 1; i--) { n         matrix[i][c] = matrix[i - 1][c]; n       } n       matrix[0][c] = temp; n     } else { n       r--; n       c--; n       matrix[r][c] = x; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (matrix[i][j] == 1e9 + 1) { n         cout << 1488 <<    ; n       } else { n         cout << matrix[i][j] <<    ; n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n pair<pair<int, int>, pair<int, int> > a[60000]; n int ans[60000], b[60000], n, m, maxx; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; i++) n     cin >> a[i].first.first >> a[i].first.second >> a[i].second.first >> n         a[i].second.second; n   for (int i = 1; i <= n; i++) ans[i] = (int)(1e9); n   for (int i = m; i >= 1; i--) { n     if (a[i].first.first == 1) { n       for (int j = a[i].first.second; j <= a[i].second.first; j++) n         if (ans[j] < (int)(1e9)) ans[j] -= a[i].second.second; n     } else { n       for (int j = a[i].first.second; j <= a[i].second.first; j++) n         if (ans[j] > a[i].second.second) ans[j] = a[i].second.second; n     } n   } n   for (int i = 1; i <= n; i++) b[i] = ans[i]; n   for (int i = 1; i <= m; i++) { n     if (a[i].first.first == 1) { n       for (int j = a[i].first.second; j <= a[i].second.first; j++) n         if (ans[j] < (int)(1e9)) ans[j] += a[i].second.second; n     } else { n       maxx = -(int)(1e9); n       for (int j = a[i].first.second; j <= a[i].second.first; j++) n         if (ans[j] > maxx) maxx = ans[j]; n       if (maxx != a[i].second.second) { n         cout <<  NO n ; n         return 0; n       } n     } n   } n   cout <<  YES n ; n   for (int i = 1; i <= n; i++) cout << b[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:64000000000 ) n using namespace std; n const double EPS = 1e-9; n const int INF = (int)(2e9 + 0.5); n const int MAXN = 201000; n int n, k, a; n vector<int> mass; n set<int> minima; n map<int, int> bad; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a); n     mass.push_back(-a); n   } n   for (int i = 0; i < k; ++i) { n     bad[mass[i]]++; n     if (bad[mass[i]] != 1) { n       if (minima.count(mass[i])) minima.erase(mass[i]); n     } else n       minima.insert(mass[i]); n   } n   for (int l = 0, r = k - 1; r < n; ++l, ++r) { n     if (!minima.size()) n       printf( Nothing n ); n     else n       printf( %d n , -(*minima.begin())); n     bad[mass[l]]--; n     if (bad[mass[l]] == 1) minima.insert(mass[l]); n     if (bad[mass[l]] != 1) n       if (minima.count(mass[l])) minima.erase(mass[l]); n     if (r + 1 < n) { n       bad[mass[r + 1]]++; n       if (bad[mass[r + 1]] != 1) { n         if (minima.count(mass[r + 1])) minima.erase(mass[r + 1]); n       } else n         minima.insert(mass[r + 1]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000; n const int delt = 255; n long long fa[N], fb[N], fc[N]; n int main() { n   ios::sync_with_stdio(false); n   string a, b, c; n   cin >> a; n   cin >> b; n   cin >> c; n   for (int i = 0; i < a.size(); i++) { n     fa[a[i] + delt]++; n   } n   for (int i = 0; i < b.size(); i++) { n     fb[b[i] + delt]++; n   } n   for (int i = 0; i < c.size(); i++) { n     fc[c[i] + delt]++; n   } n   pair<long long, pair<long long, long long> > ans = {0, {0, 0}}; n   for (int j = 0; j <= a.size(); j++) { n     long long kb = j; n     bool was = 0; n     for (char i =  a ; i <=  z ; i++) { n       if (fa[i + delt] < kb * fb[i + delt]) { n         was = 1; n         break; n       } n     } n     if (was) continue; n     long long kc = (long long)1e15; n     for (char i =  a ; i <=  z ; i++) { n       if (fc[i + delt] > 0) n         kc = min(kc, (fa[i + delt] - kb * fb[i + delt]) / fc[i + delt]); n     } n     ans = max(ans, make_pair(kb + kc, make_pair(kb, kc))); n   } n   for (char i =  a ; i <=  z ; i++) { n     fa[i + delt] -= ans.second.first * fb[i + delt]; n     fa[i + delt] -= ans.second.second * fc[i + delt]; n   } n   string str =   ; n   for (int i = 0; i < ans.second.first; i++) { n     str += b; n   } n   for (int i = 0; i < ans.second.second; i++) { n     str += c; n   } n   for (char i =  a ; i <=  z ; i++) { n     while (fa[i + delt] > 0) { n       str += i; n       fa[i + delt]--; n     } n   } n   cout << str <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c[26]; n int main() { n   string s; n   cin >> s; n   if (s.length() < 26) { n     cout << -1; n     return 0; n   } n   int f = 0, h = 0; n   for (int i = 0; i < 25; i++) { n     if (s[i] !=  ? ) { n       h += (c[s[i] -  A ] == 0); n       c[s[i] -  A ]++; n     } else { n       f++; n     } n   } n   for (int i = 25; i < s.length(); i++) { n     if (s[i] !=  ? ) { n       h += (c[s[i] -  A ] == 0); n       c[s[i] -  A ]++; n     } else { n       f++; n     } n     if (h + f == 26) { n       int o = i - 25; n       for (int j = 0; j < 26; j++) { n         if (c[j] == 0) { n           while (s[o] !=  ? ) o++; n           s[o] = j +  A ; n         } n       } n       for (int j = 0; j < s.length(); j++) { n         if (s[j] ==  ? ) { n           s[j] =  A ; n         } n       } n       cout << s; n       return 0; n     } n     if (s[i - 25] !=  ? ) { n       c[s[i - 25] -  A ]--; n       h -= (c[s[i - 25] -  A ] == 0); n     } else { n       f--; n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nos; n void split(int n) { n   if (nos == 0 || n == 1) n     cout << n <<    ; n   else { n     --nos; n     split(n / 2); n     split(n / 2); n   } n } n int main() { n   ios::sync_with_stdio(false); n   int n, k; n   cin >> k >> n; n   if (n > k) n     cout <<  NO  << endl; n   else { n     vector<int> nums; n     for (int i = 0; k; k /= 2, ++i) { n       if (k % 2) nums.push_back(pow(2, i)); n     } n     nos = n - nums.size(); n     if (nos < 0) n       cout <<  NO  << endl; n     else { n       cout <<  YES  << endl; n       for (auto &i : nums) split(i); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int iinf = 1e9 + 7; n const int oo = 0x3f3f3f3f; n const long long linf = 1ll << 60; n const double dinf = 1e60; n template <typename T> n inline void scf(T &x) { n   bool f = 0; n   x = 0; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) { n     f = 1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   if (f) x = -x; n   return; n } n template <typename T1, typename T2> n void scf(T1 &x, T2 &y) { n   scf(x); n   return scf(y); n } n template <typename T1, typename T2, typename T3> n void scf(T1 &x, T2 &y, T3 &z) { n   scf(x); n   scf(y); n   return scf(z); n } n template <typename T1, typename T2, typename T3, typename T4> n void scf(T1 &x, T2 &y, T3 &z, T4 &w) { n   scf(x); n   scf(y); n   scf(z); n   return scf(w); n } n inline char mygetchar() { n   char c = getchar(); n   while (c ==     || c ==   n ) c = getchar(); n   return c; n } n template <typename T> n inline bool chkmax(T &x, const T &y) { n   return y > x ? x = y, 1 : 0; n } n template <typename T> n inline bool chkmin(T &x, const T &y) { n   return y < x ? x = y, 1 : 0; n } n const int maxn = 1e6 + 10; n struct node { n   node *go[26], *par; n   int len, siz, tag; n   node() { n     memset(go, 0, sizeof go); n     par = 0; n     len = siz = tag = 0; n   } n   inline void cpy(node *u) { n     memcpy(go, u->go, sizeof go); n     par = u->par; n     return; n   } n } * root, *last; n vector<node *> lvl[maxn]; n char s[maxn]; n inline void expand(int id) { n   node *p = last, *np = new node; n   np->len = p->len + 1; n   np->siz = 1; n   while (p && !p->go[id]) p->go[id] = np, p = p->par; n   if (!p) n     np->par = root; n   else { n     node *q = p->go[id]; n     if (q->len == p->len + 1) n       np->par = q; n     else { n       node *nq = new node; n       nq->cpy(q); n       q->par = np->par = nq; n       nq->len = p->len + 1; n       while (p && p->go[id] == q) p->go[id] = nq, p = p->par; n     } n   } n   last = np; n   return; n } n inline void dfs(node *u) { n   if (!~u->tag) return; n   u->tag = -1; n   lvl[u->len].push_back(u); n   for (int i = 0, _end_ = (26); i < _end_; ++i) n     if (u->go[i]) dfs(u->go[i]); n   return; n } n int main() { n   root = new node; n   last = root; n   char c = getchar(); n   while (c <  a  || c >  z ) c = getchar(); n   while (c >=  a  && c <=  z ) expand(c -  a ), c = getchar(); n   dfs(root); n   for (int i = last->len; i; --i) n     for (int j = 0, _end_ = ((int)lvl[i].size()); j < _end_; ++j) n       if (lvl[i][j]->par) lvl[i][j]->par->siz += lvl[i][j]->siz; n   int q; n   scf(q); n   while (q--) { n     scanf( %s , s); n     int n = strlen(s), matched = 0, ans = 0; n     node *u = root; n     for (int i = 0, _end_ = (n << 1); i < _end_; ++i) { n       int id = s[i % n] -  a ; n       while (u && !u->go[id]) u = u->par, matched = u ? u->len : 0; n       if (!u) n         u = root; n       else { n         u = u->go[id]; n         ++matched; n         while (u->par && u->par->len >= n) u = u->par, matched = u->len; n         if (matched >= n && u->tag != q) u->tag = q, ans += u->siz; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e3 + 7; n const int mod = 998244353; n int col[maxn]; n namespace DSU { n int far[maxn]; n void init() { n   for (int i = 0; i < maxn; i++) far[i] = i; n } n int Find(int x) { return x == far[x] ? x : far[x] = Find(far[x]); } n void Union(int x, int y) { n   x = Find(x), y = Find(y); n   if (x < y) swap(x, y); n   far[y] = x; n } n };  // namespace DSU n string s; n int var, w, b; n bool isp[maxn]; n vector<int> G[maxn]; n bool dfs(int u) { n   for (auto &v : G[u]) { n     if (col[v] == -1) { n       col[v] = col[u] ^ 1; n       if (!dfs(v)) return false; n     } else { n       if (col[v] == col[u]) return false; n     } n   } n   return true; n } n long long solve(int len) { n   for (int i = 0; i <= b; i++) G[i].clear(); n   memset(isp, 0, sizeof(isp)); n   DSU::init(); n   for (int i = 0; i < s.length() / 2; i++) DSU::Union(i, s.length() - i - 1); n   for (int i = 0; i < len / 2; i++) DSU::Union(var + i, var + len - 1 - i); n   isp[w] = isp[b] = 1; n   DSU::Union(var + len - 1, b); n   for (int i = 0; i < s.length(); i++) isp[i] = 1; n   for (int i = 0; i < len; i++) isp[i + var] = 1; n   for (int i = 0; i < len; i++) n     if (s[i] ==  0 ) DSU::Union(i, var + i); n   for (int i = len; i < s.length(); i++) { n     if (s[i] ==  1 ) n       DSU::Union(i, b); n     else if (s[i] ==  0 ) n       DSU::Union(i, w); n   } n   DSU::Union(s.length() - 1, b); n   if (DSU::Find(b) == DSU::Find(w)) return 0; n   for (int i = 0; i < len; i++) { n     if (s[i] ==  1 ) { n       G[DSU::Find(i)].push_back(DSU::Find(var + i)); n       G[DSU::Find(var + i)].push_back(DSU::Find(i)); n     } n   } n   G[DSU::Find(w)].push_back(DSU::Find(b)); n   G[DSU::Find(b)].push_back(DSU::Find(w)); n   long long ret = 1; n   memset(col, -1, sizeof(col)); n   for (int i = b; i >= 0; i--) { n     if (isp[i]) { n       int cur = DSU::Find(i); n       if (col[cur] == -1) { n         if (cur == b) n           col[cur] = 1; n         else n           col[cur] = 0; n         if (!dfs(cur)) n           return 0; n         else { n           if (cur != b && cur != w) ret = ret * 2 % mod; n         } n       } n     } n   } n   return ret; n } n int main() { n   cin >> s; n   var = s.length(); n   reverse(s.begin(), s.end()); n   w = var * 2 + 1, b = var * 2 + 2; n   long long ans = 0; n   for (int i = 1; i < s.length(); i++) ans = (ans + solve(i)) % mod; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   string a; n   string b; n   cin >> a >> b; n   int order = 0; n   while (a[order] ==  0 ) { n     order++; n   } n   a = a.substr(order); n   order = 0; n   while (b[order] ==  0 ) { n     order++; n   } n   b = b.substr(order); n   if (a.size() > b.size()) { n     cout <<  > ; n   } else if (a.size() < b.size()) { n     cout <<  < ; n   } else { n     for (int i = 0; i < a.size(); i++) { n       if (a[i] > b[i]) { n         cout <<  > ; n         return 0; n       } else if (a[i] < b[i]) { n         cout <<  < ; n         return 0; n       } n     } n     cout <<  = ; n   } n } n