#include <bits/stdc++.h> n using namespace std; n struct node; n typedef node *Node; n const int inf = 1000000; n bool fl = 0; n struct node { n   Node left, right, link, parent; n   int size, prior, sum, number; n   set<int> all; n   pair<int, int> mmin; n   node(int number) : number(number) { n     left = right = link = parent = NULL; n     prior = rand() + (rand() << 16); n     update(); n   } n   int key() { n     int ans = 1; n     if (left) ans += left->size; n     return ans; n   } n   void update() { n     size = 1; n     sum = all.size(); n     if (sum == 0) n       mmin = make_pair(inf, inf); n     else n       mmin = make_pair(*all.begin(), number); n     if (left) { n       size += left->size; n       sum += left->sum; n       mmin = min(mmin, left->mmin); n       left->parent = this; n     } n     if (right) { n       size += right->size; n       sum += right->sum; n       mmin = min(mmin, right->mmin); n       right->parent = this; n     } n   } n }; n void upd_min(Node t) { n   while (t) { n     t->update(); n     t = t->parent; n   } n } n void add_ppl(Node &t, int ppl) { n   t->all.insert(ppl); n   t->sum++; n   upd_min(t); n } n void del_ppl(Node &t, int ppl) { n   t->all.erase(ppl); n   t->sum--; n   upd_min(t); n } n Node merge(Node l, Node r) { n   if (!l) return r; n   if (!r) return l; n   if (l->prior > r->prior) { n     l->right = merge(l->right, r); n     l->update(); n     return l; n   } else { n     r->left = merge(l, r->left); n     r->update(); n     return r; n   } n } n void split(Node t, int key, Node &l, Node &r) { n   if (!t) return void(l = r = NULL); n   if (t->key() <= key) { n     split(t->right, key - t->key(), t->right, r); n     l = t; n   } else { n     split(t->left, key, l, t->left); n     r = t; n   } n   t->update(); n   t->parent = NULL; n } n int get_pos(Node t) { n   vector<char> vc; n   Node v = t; n   while (v->parent) { n     if (v->parent->left == v) n       vc.push_back(0); n     else n       vc.push_back(1); n     v = v->parent; n   } n   reverse(vc.begin(), vc.end()); n   int pos = 0; n   for (int i = 0; i < vc.size(); ++i) { n     if (vc[i] == 0) n       v = v->left; n     else n       pos += v->key(), v = v->right; n   } n   pos += v->key(); n   return pos; n } n Node get_root(Node t) { n   Node ans = NULL; n   while (t) { n     ans = t; n     t = t->parent; n   } n   return ans; n } n Node leftmost(Node t) { n   Node ans = NULL; n   while (t) { n     ans = t; n     t = t->left; n   } n   return ans; n } n Node rightmost(Node t) { n   Node ans = NULL; n   while (t) { n     ans = t; n     t = t->right; n   } n   return ans; n } n void set_link(Node t, Node v) { n   if (!t) return; n   t->link = v; n } n void cut_out(Node t) { n   int pos = get_pos(t); n   Node l, r; n   split(get_root(t), pos, l, r); n   set_link(leftmost(r), t); n } n void cut_out1(Node t) { n   int pos = get_pos(t); n   Node l, r; n   split(get_root(t), pos - 1, l, r); n   set_link(leftmost(r), rightmost(l)); n } n void expose(Node v) { n   cut_out(v); n   v = leftmost(get_root(v)); n   while (v->link) { n     cut_out(v->link); n     merge(get_root(v->link), get_root(v)); n     set_link(v, NULL); n     v = leftmost(get_root(v)); n   } n } n void link(Node u, Node v) { n   set_link(u, v); n   expose(u); n } n void cut(Node u, Node v) { n   expose(v); n   set_link(u, NULL); n } n Node lca(Node v, Node u, bool &one_tree) { n   expose(u); n   if (get_root(u) == get_root(v)) { n     one_tree = 1; n     return v; n   } n   expose(v); n   expose(u); n   return leftmost(get_root(v))->link; n } n vector<Node> nodes; n const int maxn = 100000; n vector<pair<int, int> > add; n vector<int> g[maxn + 1]; n vector<int> deep; n void dfs(int v, int p = -1) { n   for (int i = 0; i < g[v].size(); ++i) { n     int tv = g[v][i]; n     if (tv == p) continue; n     deep[tv] = deep[v] + 1; n     dfs(tv, v); n   } n } n void print_(Node v) { n   if (!v) return; n   print_(v->left); n   cout <<   t  << v->number <<     << (v->link ? v->link->number : -1) << endl; n   print_(v->right); n } n void print(Node v) { print_(get_root(v)); } n void print_all(int n) { n   for (int i = 1; i <= n; ++i) { n     cout << i <<  : n ; n     print(nodes[i]); n     cout << endl; n   } n } n void do_the_thing(Node v, int x) { n   Node t = get_root(v); n   int k = min(x, t->sum); n   cout << k <<    ; n   vector<pair<int, int> > add_after; n   for (int i = 0; i < k; ++i) { n     pair<int, int> cmin = t->mmin; n     cout << cmin.first <<    ; n     del_ppl(nodes[cmin.second], cmin.first); n     add_after.push_back(cmin); n   } n   cout << endl; n   for (int i = 0; i < add_after.size(); ++i) { n     pair<int, int> ct = add_after[i]; n     add_ppl(nodes[ct.second], ct.first); n   } n } n int main() { n   srand(time(NULL)); n   ios_base::sync_with_stdio(0); n   int n, m, q; n   cin >> n >> m >> q; n   nodes.resize(n + 1); n   deep.assign(n + 1, 0); n   for (int i = 1; i <= n; ++i) nodes[i] = new node(i); n   for (int i = 0; i < n - 1; ++i) { n     int a, b; n     cin >> a >> b; n     add.push_back(make_pair(a, b)); n     g[a].push_back(b); n     g[b].push_back(a); n   } n   dfs(1); n   for (int i = 0; i < add.size(); ++i) { n     int a = add[i].first; n     int b = add[i].second; n     if (deep[a] < deep[b]) swap(a, b); n     link(nodes[a], nodes[b]); n   } n   for (int i = 1; i <= m; ++i) { n     int city; n     cin >> city; n     add_ppl(nodes[city], i); n   } n   for (int i = 0; i < q; ++i) { n     int v, u, x; n     cin >> v >> u >> x; n     bool one_tree = 0; n     Node t = lca(nodes[v], nodes[u], one_tree); n     if (one_tree) { n       cut_out1(nodes[v]); n       do_the_thing(nodes[v], x); n     } else { n       int split_key = get_root(nodes[v])->size; n       cut_out1(t); n       merge(get_root(nodes[v]), get_root(t)); n       do_the_thing(nodes[v], x); n       Node l, r; n       split(get_root(nodes[v]), split_key, l, r); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000000000 ) n using namespace std; n const long long int INF = 2e18; n int nex[20000][35]; n int at[35]; n int main() { n   string f, s; n   cin >> f >> s; n   memset(nex, -1, sizeof nex); n   memset(at, -1, sizeof at); n   for (int i = 0; i < f.size(); i++) { n     int he = f[i] -  a ; n     if (at[he] == -1) { n       at[he] = i; n     } n   } n   for (int i = f.size() - 1; i >= 0; i--) { n     for (int j = 0; j < 35; j++) { n       nex[i][j] = at[j]; n     } n     at[f[i] -  a ] = i; n   } n   int now = (f[0] == s[0] ? 0 : nex[0][s[0] -  a ]); n   int cur = 0; n   int cnt = 1; n   while (cur < s.size()) { n     if (now == -1) { n       cout << -1; n       return 0; n     } n     cur++; n     if (cur == s.size()) break; n     int gogo = nex[now][s[cur] -  a ]; n     if (gogo == -1) { n       cout << -1; n       return 0; n     } n     if (gogo <= now) { n       cnt++; n     } n     now = gogo; n   } n   cout << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> dis(n + 1, n), cnt(n + 1, -1); n   while (m--) { n     int a, b; n     cin >> a >> b; n     ++cnt[a]; n     dis[a] = min(dis[a], a > b ? b - a + n : b - a); n   } n   for (int i = 1; i <= n; ++i) { n     int res = 0; n     for (int j = 1; j <= n; ++j) n       if (~cnt[j]) n         res = max(res, (i > j ? j - i + n : j - i) + cnt[j] * n + dis[j]); n     cout << res <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(); n   string s, mx; n   cin >> s; n   int len = s.length(); n   for (int i = 1; i < 1 << len; i++) { n     string foo; n     for (int j = 0; j < len; j++) n       if (i & (1 << j)) foo += s[j]; n     bool flag = 1; n     for (int k = 0; k <= foo.length() / 2; k++) n       if (foo[k] != foo[foo.length() - k - 1]) flag = 0; n     if (flag && foo > mx) mx = foo; n   } n   cout << mx; n } n


#include <bits/stdc++.h> n using namespace std; n const int size = 300000001; n bitset<size> gut; n int main() { n   int l, r; n   cin >> l >> r; n   gut.set(); n   for (int i = 3; i * i <= r; i += 2) { n     if (gut[i]) n       for (int j = i * i; j <= r; j += (i << 1)) { n         gut[j] = false; n       } n   } n   int rez = 0; n   rez = (l <= 2 && r >= 2); n   for (int i = 5; i <= r; i += 4) { n     if (i >= l && gut[i]) rez++; n   } n   cout << rez << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3010; n struct edge { n   int v, next, flag; n } e[N << 2]; n int head[N], cnt; n void addedge(int u, int v, int flag) { n   e[cnt].v = v; n   e[cnt].flag = flag; n   e[cnt].next = head[u]; n   head[u] = cnt++; n } n int sum[N], dp[N]; n void dfs(int u, int pre) { n   sum[u] = 0; n   for (int i = head[u]; i != -1; i = e[i].next) { n     if (e[i].v == pre) continue; n     dfs(e[i].v, u); n     int v = e[i].v; n     sum[u] += sum[v] + e[i].flag; n   } n   dp[u] = sum[u]; n   for (int i = head[u]; i != -1; i = e[i].next) { n     if (e[i].v == pre) continue; n     int v = e[i].v; n     dp[u] = min(dp[u], sum[u] - sum[v] + 1 - e[i].flag + dp[v] - e[i].flag); n   } n } n int main() { n   memset(head, -1, sizeof(head)); n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int x, y, z; n     scanf( %d%d , &x, &y); n     addedge(x, y, 0); n     addedge(y, x, 1); n   } n   int ans = 0x7fffffff; n   for (int i = 1; i <= n; i++) { n     dfs(i, -1); n     for (int j = 1; j <= n; j++) { n       ans = min(ans, sum[i] - sum[j] + dp[j]); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e3 + 100; n int N; n int p[MAXN], rp[MAXN]; n char ans[MAXN][MAXN]; n bool v[MAXN]; n int lvl, C; n bool pd; n bool id(int* a, int as) { n   for (int i = 1; i <= as; i++) n     if (a[i] != i) return false; n   return true; n } n char get_dir(bool d) { return d ?  /  :     ; } n char get_dir(int a, int b) { n   assert(a != b); n   return get_dir(a < b); n } n bool addE(int a, int b) { n   assert(a != b); n   if (a < b) { n     ans[lvl][a] = ans[lvl][b] =  / ; n     return true; n   } n   if (a > b) { n     ans[lvl][a] = ans[lvl][b] =     ; n     return false; n   } n   assert(false); n   return false; n } n void init(int n) { n   assert(p[n] != n); n   v[n] = true; n   C = n; n   for (int i = p[n]; i != n; i = p[i]) { n     v[i] = true; n     pd = addE(p[i], i); n     lvl--; n   } n } n int addFE(int n, int lf) { n   if ((pd) xor (n > C)) { n     ans[lvl][n] = get_dir(p[n], C); n     ans[lf][C] = get_dir(C, n); n     pd = C < n; n     ans[lf][n] = get_dir(C, n); n     return -1; n   } n   if ((p[n] < n) xor (n < C)) { n     ans[lvl - 1][C] = get_dir(p[n], C); n     ans[lf][C] = get_dir(C, n); n     ans[lf][n] = get_dir(C, n); n     return -1; n   } n   assert(false); n   return -1; n } n void fill(int n) { n   v[n] = true; n   int l = 1, s = -1; n   for (int i = p[n]; i != n; i = p[i]) { n     v[i] = true, l++; n     if (((p[n] < n) xor (C < n)) or (pd xor (n > C))) s = i; n   } n   lvl += addFE(s, lvl - l); n   for (int i = p[s]; i != s; i = p[i]) { n     addE(p[i], i), lvl--; n   } n } n int main() { n   scanf( %d , &N); n   lvl = N; n   pd = false; n   for (int i = 0; i <= N; i++) v[i] = false, p[i] = rp[i] = -1; n   for (int i = 1; i <= N; i++) scanf( %d , rp + i); n   for (int i = 1; i <= N; i++) p[rp[i]] = i; n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) ans[i][j] =  . ; n   if (id(p, N)) { n     printf( %d n , N); n     for (int i = 1; i <= N; i++, printf(  n )) n       for (int j = 1; j <= N; j++) printf( %c , ans[i][j]); n     return 0; n   } n   for (int i = 1; i <= N; i++) n     if (p[i] == i) v[i] = true; n   for (int i = 1, c = 1; c and i <= N; i++) n     if (!v[i]) init(i), c = 0; n   lvl++; n   for (int i = 1; i <= N; i++) n     if (!v[i]) fill(i); n   printf( %d n , N - 1); n   for (int i = 1; i <= N; i++, printf(  n )) n     for (int j = 1; j <= N; j++) printf( %c , ans[i][j]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t[35], mp[400][400], n; n void dfs(int step, int x, int y, int dir) { n   if (step > n) return; n   if (dir == 0) { n     dfs(step + 1, x, y + t[step], 1 - dir); n     for (int i = 0; i < 400; i++) n       for (int j = 0; j < 400; j++) n         if (mp[i][j]) { n           mp[i][j] = mp[x * 2 - i][j] = 1; n         } n     for (int i = 1; i <= t[step]; i++) mp[x][y + i] = 1; n   } else { n     dfs(step + 1, x + t[step], y + t[step], 1 - dir); n     int b = y - x; n     for (int i = 0; i < 400; i++) n       for (int j = 0; j < 400; j++) n         if (mp[i][j]) { n           mp[i][j] = mp[j - b][i + b] = 1; n         } n     for (int i = 1; i <= t[step]; i++) { n       mp[x + i][y + i] = 1; n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , t + i); n   memset(mp, 0, sizeof(mp)); n   dfs(1, 200, 199, 0); n   int ans = 0; n   for (int i = 0; i < 400; i++) n     for (int j = 0; j < 400; j++) n       if (mp[i][j]) ans++; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2000000; n char a[MAXN + 10], b[MAXN + 10]; n int main(void) { n   int n; n   scanf( %d%s%s , &n, a, b); n   int cnt[2][2]; n   for (int i = 0; i < (2); ++i) { n     for (int j = 0; j < (2); ++j) { n       cnt[i][j] = 0; n     } n   } n   n *= 2; n   for (int i = 0; i < (n); ++i) { n     ++cnt[a[i] -  0 ][b[i] -  0 ]; n   } n   int sA = 0, sB = 0; n   for (int i = 0; i < (n); ++i) { n     if (cnt[1][1] > 0) { n       --cnt[1][1]; n       ++sA; n     } else if (cnt[1][0] > 0) { n       --cnt[1][0]; n       ++sA; n     } else if (cnt[0][1] > 0) { n       --cnt[0][1]; n     } else { n       --cnt[0][0]; n     } n     if (cnt[1][1] > 0) { n       --cnt[1][1]; n       ++sB; n     } else if (cnt[0][1] > 0) { n       --cnt[0][1]; n       ++sB; n     } else if (cnt[1][0] > 0) { n       --cnt[1][0]; n     } else { n       --cnt[0][0]; n     } n   } n   if (sA > sB) { n     puts( First ); n   } else if (sA < sB) { n     puts( Second ); n   } else { n     puts( Draw ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, X, Y, Z, p; n   int x, y; n   while (scanf( %d%d%d%d%d%d , &n, &m, &X, &Y, &Z, &p) != EOF) { n     X %= 4; n     Y %= 2; n     Z %= 4; n     int tn = n; n     int tm = m; n     for (int i = 1; i <= p; i++) { n       n = tn; n       m = tm; n       scanf( %d%d , &x, &y); n       if (X == 1) { n         int xx = x; n         x = y; n         y = n + 1 - xx; n         int nn = n; n         n = m; n         m = nn; n       } else if (X == 2) { n         x = n + 1 - x; n         y = m + 1 - y; n       } else if (X == 3) { n         int xx = x; n         x = m + 1 - y; n         y = xx; n         int nn = n; n         n = m; n         m = nn; n       } n       if (Y == 1) { n         y = m + 1 - y; n       } n       if (Z == 1) { n         int xx = x; n         x = m + 1 - y; n         y = xx; n         int nn = n; n         n = m; n         m = nn; n       } else if (Z == 2) { n         x = n + 1 - x; n         y = m + 1 - y; n       } else if (Z == 3) { n         int xx = x; n         x = y; n         y = n + 1 - xx; n         int nn = n; n         n = m; n         m = nn; n       } n       printf( %d %d n , x, y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n const int INF = 1e9 + 7; n const int N = 4e5 + 7; n const int M = 5e6 + 7; n int vis[M]; n int p[N]; n int qt[N]; n signed main() { n   ios::sync_with_stdio(false); n   int q, x, y; n   cin >> q >> x; n   set<pair<int, int>> vals; n   for (int i = 0; i < x; i++) vals.insert({qt[i], i}); n   while (q--) { n     int y; n     cin >> y; n     y %= x; n     vals.erase({qt[y], y}); n     vals.insert({++qt[y], y}); n     auto k = *vals.begin(); n     int nVal = k.first * x + k.second; n     cout << nVal << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double n, m; n   cin >> n >> m; n   printf( %.10lf n , n * pow(1.000000011, m)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, l[60], r[60], ans; n int main() { n   scanf( %d %d , &n, &x); n   for (int i = 1; i <= n; ++i) { n     scanf( %d %d , &l[i], &r[i]); n   } n   for (int i = 1; i <= n; ++i) { n     ans += (l[i] - r[i - 1] - 1) % x; n     ans += r[i] - l[i] + 1; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000 + 7, Mod = 1000000000 + 7; n inline int Inc(int A, int B) { n   A += B; n   return A >= Mod ? A - Mod : A; n } n inline int Dec(int A, int B) { n   A -= B; n   return A < 0 ? A + Mod : A; n } n int n, m, A, B, Dpd[N][N], Dpr[N][N], Sumd[N][N], Sumr[N][N], d[N][N], r[N][N]; n char Map[N][N]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = (1), iLimit = (n); i <= iLimit; (++(i))) n     for (int j = (1), jLimit = (m); j <= jLimit; (++(j))) cin >> Map[i][j]; n   if (n == 1 && m == 1) { n     if (Map[1][1] ==  R ) n       puts( 0 ); n     else n       puts( 1 ); n     return 0; n   } n   for (int i = (n), iLimit = (1); i >= iLimit; (--(i))) n     for (int j = (m), jLimit = (1); j >= jLimit; (--(j))) { n       d[i][j] = d[i + 1][j] + (Map[i + 1][j] ==  R ); n       r[i][j] = r[i][j + 1] + (Map[i][j + 1] ==  R ); n     } n   Dpd[n][m] = Dpr[n][m] = Sumd[n][m] = Sumr[n][m] = (Map[n][m] !=  R ); n   for (int i = (n), iLimit = (1); i >= iLimit; (--(i))) n     for (int j = (m), jLimit = (1); j >= jLimit; (--(j))) n       if (i != n || j != m) { n         Dpr[i][j] = Dec(Sumd[i][j + 1], Sumd[i][m - r[i][j] + 1]); n         Dpd[i][j] = Dec(Sumr[i + 1][j], Sumr[n - d[i][j] + 1][j]); n         Sumr[i][j] = Inc(Sumr[i + 1][j], Dpr[i][j]); n         Sumd[i][j] = Inc(Sumd[i][j + 1], Dpd[i][j]); n       } n   printf( %d , Inc(Dpr[1][1], Dpd[1][1])); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n const long long INF = 1e9; n const long long mod = 1e9 + 7; n const long long LINF = 1e14; n using namespace std; n long long n, l; n vector<long long> c; n vector<int> b; n int main() { n   std::ios::sync_with_stdio(false); n   cin >> n >> l; n   c.resize(n); n   cin >> c[0]; n   for (long long i = (1); i < (n); i++) { n     cin >> c[i]; n     c[i] = min(c[i - 1] * 2, c[i]); n   } n   while (l > 0) b.push_back(l % 2), l /= 2; n   while (c.size() < b.size()) c.push_back(c.back() * 2); n   while (b.size() < c.size()) b.push_back(0); n   c.push_back(c.back() * 2); n   n = b.size(); n   vector<long long> d(n + 1, LINF); n   d[0] = 0; n   for (long long i = (1); i < (n + 1); i++) { n     d[i] = min(d[i - 1], c[i - 1]); n     if (b[i - 1] == 1) d[i] += c[i - 1]; n   } n   cout << min(d[n], c.back()) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x; n   cin >> x; n   int k = x % 4; n   if (k == 1) { n     cout << 0 <<   A  << endl; n   } else if (k == 0) { n     cout << 1 <<   A  << endl; n   } else if (k == 2) { n     cout << 1 <<   B  << endl; n   } else { n     cout << 2 <<   A  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char arr[50][50]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if ((i % 2 == 0 || n            ((i % 4 == 1 && j == m - 1) || (i % 4 == 3 && j == 0)))) n         arr[i][j] =  # ; n       else n         arr[i][j] =  . ; n     } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) cout << arr[i][j]; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n inline void chmin(A &a, B b) { n   if (a > b) a = b; n } n template <typename A, typename B> n inline void chmax(A &a, B b) { n   if (a < b) a = b; n } n struct UnionFindTree { n   vector<long long> par, sz; n   UnionFindTree(long long n) { n     par.resize(n); n     sz.resize(n); n     for (long long i = 0; i < n; i++) { n       par[i] = i; n       sz[i] = 1; n     } n   } n   long long find(long long x) { n     return x == par[x] ? x : par[x] = find(par[x]); n   } n   void unite(long long x, long long y) { n     x = find(x); n     y = find(y); n     if (x == y) return; n     if (sz[x] < sz[y]) swap(x, y); n     sz[x] += sz[y]; n     par[y] = x; n   } n   bool areSame(long long x, long long y) { return find(x) == find(y); } n   long long size(long long x) { return sz[find(x)]; } n }; n const long long SIZE = 1000000; n long long N, M; n long long A[SIZE], B[SIZE]; n long long cnt[SIZE]; n signed main() { n   scanf( %lld%lld , &N, &M); n   for (long long i = 0; i < (M); i++) scanf( %lld%lld , &A[i], &B[i]); n   vector<long long> vs; n   for (long long i = 0; i < (M); i++) { n     vs.push_back(A[i]); n     vs.push_back(B[i]); n   } n   sort((vs).begin(), (vs).end()); n   vs.erase(unique((vs).begin(), (vs).end()), vs.end()); n   for (long long i = 0; i < (M); i++) { n     A[i] = lower_bound((vs).begin(), (vs).end(), A[i]) - vs.begin(); n     B[i] = lower_bound((vs).begin(), (vs).end(), B[i]) - vs.begin(); n   } n   N = vs.size(); n   UnionFindTree uf(N); n   for (long long i = 0; i < (M); i++) uf.unite(A[i], B[i]); n   if (uf.size(0) != N) { n     puts( 0 ); n     return 0; n   } n   long long luz = 0; n   for (long long i = 0; i < (M); i++) { n     if (A[i] == B[i]) n       luz++; n     else { n       cnt[A[i]]++; n       cnt[B[i]]++; n     } n   } n   long long ans = 0; n   ans += luz * (M - luz); n   ans += luz * (luz - 1) / 2; n   for (long long i = 0; i < N; i++) ans += cnt[i] * (cnt[i] - 1) / 2; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int N = 100000, M = 100000; n long long int MOD = 1000000007; n void solve() { n   long long int n; n   cin >> n; n   long long int a[n + 1], b[n + 1]; n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   for (long long int i = 0; i < n; i++) { n     b[i] = a[i] - i; n     if (b[i] < 0) n       b[i] = 0; n     else if (b[i] % n == 0) n       b[i] = b[i] / n; n     else n       b[i] = (b[i] / n) + 1; n   } n   for (long long int i = 0; i < n; i++) b[i] = i + (n * b[i]); n   long long int min1 = b[0]; n   long long int ans = 0; n   for (long long int i = 0; i < n; i++) { n     if (min1 > b[i]) { n       min1 = b[i]; n       ans = i; n     } n   } n   cout << ans + 1; n } n int main() { n   long long int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int k, m; n set<int> S; n int pw[10]; n void rec(int ind, int number, int value) { n   if (ind == 4) { n     if (value > k && value - k < 10000) { n       S.insert(number * 10000 + (value - k)); n     } n     if (k >= value && k - value < 10000) { n       S.insert(number * 10000 + (k - value)); n     } n     return; n   } n   for (int i = 1; i + ind < 5; i++) { n     for (int j = 0; j < pw[i]; j++) { n       if (ind == 0) { n         rec(ind + i, j, j); n       } else { n         rec(ind + i, number * pw[i] + j, value + j); n         rec(ind + i, number * pw[i] + j, value - j); n         rec(ind + i, number * pw[i] + j, value * j); n       } n     } n   } n } n int main() { n   scanf( %d , &k); n   scanf( %d , &m); n   pw[0] = 1; n   for (int i = 1; i <= 6; i++) pw[i] = pw[i - 1] * 10; n   rec(0, 0, 0); n   for (set<int>::iterator it = S.begin(); (it != S.end()) && m; it++, m--) { n     cout << setw(8) << setfill( 0 ) << (*it) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n int main() { n   int cases; n   scanf( %d , &cases); n   while (cases--) { n     char str[1009]; n     int ret[9]; n     scanf( %s , str); n     int num = 0; n     int i; n     int cnt = 0; n     int flag = -1; n     for (i = 0; str[i]; i++) { n       if (str[i] >=  A  && str[i] <=  Z ) { n         str[i] = str[i] -  A  +  a ; n       } n       if (str[i] ==  : ) { n         if (str[i + 1] ==  : ) { n           flag = cnt; n           i++; n         } n         ret[cnt] = num; n         cnt++; n         num = 0; n       } else if (str[i] >=  0  && str[i] <=  9 ) { n         num = num * 16 + str[i] -  0 ; n       } else { n         num = num * 16 + str[i] -  a  + 10; n       } n     } n     ret[cnt++] = num; n     int k = 0; n     for (int j = 0; j < cnt; j++) { n       printf( %04x , ret[j]); n       k++; n       if (k != 8) { n         putchar( : ); n       } n       if (flag == j) { n         for (i = 0; i < 8 - cnt; i++) { n           printf( 0000 ); n           k++; n           if (k != 8) { n             putchar( : ); n           } n         } n       } n     } n     putchar(10); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, j, r, mn, mx, x, cnt = 0, a = 1, b = 1; n   string s; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> s; n     if (s ==  UR  || s ==  DL ) n       a++; n     else if (s ==  UL  || s ==  DR ) n       b++; n     else { n       a++, b++; n     } n   } n   cout << a * b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2e9; n int n; n pair<int, int> p[25]; n int dis[25][25]; n int dp[1 << 24 | 1]; n int pre[1 << 24 | 1]; n int main() { n   scanf( %d%d%d , &p[0].first, &p[0].second, &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d , &p[i].first, &p[i].second); n   } n   for (int i = 0; i <= n; ++i) n     for (int j = i; j <= n; ++j) { n       dis[i][j] = dis[j][i] = n           pow(p[i].first - p[j].first, 2) + pow(p[i].second - p[j].second, 2); n     } n   for (int m = 1; m < (1 << n); ++m) { n     dp[m] = INF; n   } n   dp[0] = 0; n   for (int m = 0; m < (1 << n); ++m) { n     if (dp[m] == INF) continue; n     for (int i = 1; i <= n; ++i) { n       if (m & 1 << (i - 1)) continue; n       for (int j = 1; j <= n; ++j) { n         if (m & 1 << (j - 1)) continue; n         if (dp[m | (1 << i - 1) | (1 << j - 1)] > n             dp[m] + dis[0][i] + dis[i][j] + dis[j][0]) { n           dp[m | (1 << i - 1) | (1 << j - 1)] = n               dp[m] + dis[0][i] + dis[i][j] + dis[j][0]; n           pre[m | (1 << i - 1) | (1 << j - 1)] = m; n         } n       } n       break; n     } n   } n   printf( %d n , dp[(1 << n) - 1]); n   int num = (1 << n) - 1; n   while (num) { n     printf( 0  ); n     int t = pre[num] ^ num; n     for (int i = 0; i < n; ++i) { n       if (t & (1 << i)) { n         printf( %d  , i + 1); n       } n     } n     num = pre[num]; n   } n   printf( 0 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1000001; n long long n, l[MAXN], r[MAXN], id[MAXN], K; n bool cmp(long long i, long long j) { n   return (l[i] / K == l[j] / K) n              ? ((l[i] / K & 1) ? (r[i] < r[j]) : (r[i] > r[j])) n              : (l[i] < l[j]); n } n int main() { n   scanf( %lld , &n); n   K = 1000; n   for (long long i = 1; i <= n; i++) scanf( %lld%lld , &l[i], &r[i]), id[i] = i; n   sort(id + 1, id + 1 + n, cmp); n   for (int i = 1; i <= n; i++) printf( %lld  , id[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const long long neutral = 0; n class SegmentTree { n   vector<long long> a; n   int n; n  n  public: n   SegmentTree(long long* st, long long* en) { n     int sz = int(en - st); n     for (n = 1; n < sz; n <<= 1) n       ; n     a.assign(n << 1, neutral); n     for (int i = 0; i < sz; i++) a[i + n] = st[i]; n     for (int i = n + sz - 1; i > 1; i--) a[i >> 1] = ((a[i >> 1]) | (a[i])); n   } n   void update(int i, long long x) { n     a[i += n] = x; n     for (i >>= 1; i; i >>= 1) a[i] = ((a[i << 1]) | (a[1 + (i << 1)])); n   } n   long long query(int l, int r) { n     long long ans = neutral; n     for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) { n       if (l & 1) ans = ((ans) | (a[l++])); n       if (r & 1) ans = ((ans) | (a[--r])); n     } n     return ans; n   } n }; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin.exceptions(cin.failbit); n   int n, q, m; n   string s; n   cin >> s; n   n = (int)(s).size(); n   long long v[n]; n   for (int i = 0; i < (n); ++i) { n     v[i] = 1LL << (s[i] -  a ); n   } n   cin >> q; n   SegmentTree st(v, v + n); n   while (q--) { n     int t; n     cin >> t; n     if (t == 2) { n       int a, b; n       cin >> a >> b; n       long long res = st.query(a - 1, b - 1), c = 0; n       while (res > 0) c++, res -= (res & -res); n       cout << c << endl; n     } else { n       int a; n       char c; n       cin >> a >> c; n       int b = c -  a ; n       st.update(a - 1, 1LL << b); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9; n const long long INF = 1e15; n template <class o> n void qr(o& x) { n   char c = getchar(); n   x = 0; n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n   x *= f; n } n template <class o> n void qw(o x) { n   if (x / 10) qw(x / 10); n   putchar(x % 10 +  0 ); n } n template <class o> n void pr1(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   putchar(   ); n } n template <class o> n void pr2(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   putchar(10); n } n template <class o> n void cmax(o& x, o y) { n   if (x < y) x = y; n } n void cmax(int& x, int y) { x = x - y >> 31 ? y : x; } n template <class o> n void cmin(o& x, o y) { n   if (x > y) x = y; n } n void cmin(int& x, int y) { x = x - y >> 31 ? x : y; } n int n, m, a[N], p[N], b[N]; n struct BIT { n   int c[N]; n   void clear() { memset(c + 1, 0, n * sizeof(int)); } n   void clear(int x) { n     for (; x <= n; x += x & -x) c[x] = 0; n   } n   int ask(int x) { n     int y = 0; n     for (; x; x -= x & -x) y += c[x]; n     return y; n   } n   int ask(int l, int r) { return ask(r) - ask(l - 1); } n   void add(int x, int y) { n     for (; x <= n; x += x & -x) c[x] += y; n   } n } tr; n struct Q { n   int l, r, y, v, id; n   Q(int _l, int _r, int _y, int _v, int _id = 0) n       : l(_l), r(_r), y(_y), v(_v), id(_id){}; n   Q(){}; n   bool operator<(Q b) const { return y < b.y; } n } q[N * 5], t[N * 5]; n int tot, ans[N], id; n void cdq(int l, int r) { n   if (r - l < 100) { n     int j = 0; n     for (auto i = l; i <= r; i++) { n       if (!q[i].id) n         t[++j] = q[i]; n       else n         for (auto k = 1; k <= j; k++) { n           if (q[i].l <= t[k].l && t[k].l <= q[i].r && t[k].y <= q[i].y) n             ans[q[i].id] += q[i].v * t[k].v; n         } n     } n     sort(q + l, q + r + 1); n     return; n   } n   int mid = (l + r) / 2; n   cdq(l, mid); n   cdq(mid + 1, r); n   Q* p = t; n   for (int i = l, j = mid + 1; i <= mid || j <= r;) { n     if (j > r || (i <= mid && q[i].y <= q[j].y)) { n       if (!q[i].id) tr.add(q[i].l, q[i].v); n       *p++ = q[i++]; n     } else { n       if (q[j].id) ans[q[j].id] += q[j].v * tr.ask(q[j].l, q[j].r); n       *p++ = q[j++]; n     } n   } n   if (r - l > 2333) n     tr.clear(); n   else n     for (auto i = l; i <= mid; i++) n       if (!q[i].id) tr.clear(q[i].l); n   for (auto i = r; i >= l; i--) q[i] = *--p; n } n void solve() { n   qr(n); n   qr(m); n   for (auto i = 1; i <= n; i++) qr(a[i]), p[a[i]] = i; n   for (auto i = 1; i <= n; i++) n     qr(b[i]), b[i] = p[b[i]], q[++tot] = Q(i, i, b[i], 1); n   int op, x, y, l, r; n   while (m--) { n     qr(op); n     qr(x); n     qr(y); n     if (op == 1) { n       qr(l); n       qr(r); n       ++id; n       q[++tot] = Q(l, r, y, 1, id); n       q[++tot] = Q(l, r, x - 1, -1, id); n     } else { n       q[++tot] = Q(x, x, b[x], -1); n       q[++tot] = Q(y, y, b[y], -1); n       swap(b[x], b[y]); n       q[++tot] = Q(x, x, b[x], 1); n       q[++tot] = Q(y, y, b[y], 1); n     } n   } n   cdq(1, tot); n   for (auto i = 1; i <= id; i++) pr2(ans[i]); n } n int main() { n   int T = 1; n   while (T--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n class _Fenwick { n  private: n   std::vector<T> sum; n   int _size; n  n  public: n   _Fenwick() { _size = 0; } n   void reset(int n) { n     _size = n; n     sum.clear(); n     sum.resize(n + 1); n   } n   void add(int x, T y) { n     while (x <= _size) { n       sum[x] += y; n       x += x & -x; n     } n   } n   T query(int x, T y) { n     T ans = y; n     while (x) { n       ans += sum[x]; n       x -= x & -x; n     }; n     return ans; n   } n   void build(T *a, int n) { n     reset(n); n     for (int i = 1; i <= n; ++i) add(i, a[i]); n   } n }; n template <typename T> n void read(T &x); n template <typename T> n void read(T &x, T &y); n template <typename T> n void read(T &x, T &y, T &z); n template <typename T> n void write(T x); n template <typename T> n void writeC(T x); n template <typename T> n void writeN(T x); n template <typename T> n void _binary(T x, int len); n long long _qpow(long long a, long long b, long long M); n long long _inv(long long x, long long M); n long long ans; n int n, a[200005], b[200005][31], R[200005][31], L[200005][31], pre[35]; n signed main() { n   read(n); n   for (int i = 1; i <= (n); ++i) read(a[i]); n   ; n   long long ans = (long long)n * (n + 1) / 2; n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j <= 30; ++j) b[i][j] = (a[i] >> j) & 1; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= 30; ++j) { n       L[i][j] = pre[j]; n       if (b[i][j]) pre[j] = i; n     } n   } n   for (int i = 0; i <= 30; ++i) pre[i] = n + 1; n   for (int i = n; i >= 1; i--) { n     for (int j = 0; j <= 30; ++j) { n       R[i][j] = pre[j]; n       if (b[i][j]) pre[j] = i; n     } n   } n   std::map<int, int> last; n   for (int i = 1; i <= n; ++i) { n     int l = last[a[i]] + 1, r = n; n     for (int j = 0; j <= 30; ++j) n       if (!b[i][j]) { n         l = std::max(l, L[i][j] + 1); n         r = std::min(r, R[i][j] - 1); n       } n     ans -= (long long)(i - l + 1) * (r - i + 1); n     last[a[i]] = i; n   } n   printf( %lld , ans); n } n template <typename T> n void read(T &x) { n   x = 0; n   char c = getchar(); n   T flag = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) flag = -flag; n     c = getchar(); n   } n   while ( 0  <= c && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x *= flag; n } n template <typename T> n void read(T &x, T &y) { n   read(x); n   read(y); n } n template <typename T> n void read(T &x, T &y, T &z) { n   read(x); n   read(y); n   read(z); n } n template <typename T> n void writeC(T x) { n   if (x < 0) x = ~x + 1, putchar( - ); n   if (x > 9) writeC(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T> n void write(T x) { n   writeC(x); n   putchar(   ); n } n template <typename T> n void writeN(T x) { n   writeC(x); n   puts(  ); n } n template <typename T> n void _binary(T x, int len) { n   for (int i = len - 1; i >= 0; --i) writeC((x >> i) & 1); n } n long long _inv(long long x, long long M) { n   assert(x != 0); n   return x == 1 ? 1 : (M - M / x) * _inv(M % x, M) % M; n } n long long _qpow(long long a, long long b, long long M) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % M; n     a = a * a % M; n     b >>= 1; n   } n   return res; n } n


#include <bits/stdc++.h> n using namespace std; n int num[400005]; n int tot = 0; n set<int> st; n int mp[20]; n int freq[20]; n long long push[20][20]; n long long addp[20][1048576]; n vector<int> pos[20]; n long long sum[20]; n int cnt[20]; n long long memo[1048576]; n long long cost(int mask, int ofst, int id) { n   return sum[id] + addp[id][mask] - n          1LL * (ofst + 1 + ofst + cnt[id]) * cnt[id] / 2; n   ; n } n long long dp(int i, int mask, int ofst) { n   if (i == tot) return 0; n   if (memo[mask] != -1) return memo[mask]; n   long long mn = 1000000000000000000; n   int id; n   for (int j = (0); j <= (tot - 1); j++) { n     if ((mask >> j) & 1) continue; n     long long v = n         dp(i + 1, mask | (1 << j), ofst + cnt[j]) + cost(mask, ofst, j); n     if (v < mn) { n       mn = v; n       id = j; n     } n   } n   return memo[mask] = mn; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = (1); i <= (n); i++) { n     scanf( %d , &num[i]); n     --num[i]; n     st.insert(num[i]); n   } n   for (auto u : st) { n     mp[u] = tot++; n   } n   for (int i = (0); i <= (tot - 1); i++) pos[i].push_back(0); n   for (int i = (1); i <= (n); i++) { n     num[i] = mp[num[i]]; n     int t = num[i]; n     pos[t].push_back(i); n     cnt[t]++; n     sum[t] += i; n   } n   memset(push, 0, sizeof(push)); n   for (int i = (1); i <= (n); i++) { n     freq[num[i]]++; n     for (int j = (0); j <= (tot - 1); j++) { n       push[num[i]][j] += cnt[j] - freq[j]; n     } n   } n   memset(addp, 0, sizeof(addp)); n   for (int i = (0); i <= (tot - 1); i++) { n     for (int j = (0); j <= ((1 << tot) - 1); j++) { n       if ((j >> i) & 1) continue; n       for (int k = (0); k <= (tot - 1); k++) { n         if (~(j >> k) & 1) continue; n         addp[i][j] += push[i][k]; n       } n     } n   } n   memset(memo, -1, sizeof(memo)); n   printf( %lld n , dp(0, 0, 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[200010]; n long long int ans = 0LL; n int odd = 0, sz[200010] = {}; n void dfs(int cur, int par = -1, int ht = 0) { n   sz[cur]++; n   for (int u : adj[cur]) { n     if (u == par) continue; n     dfs(u, cur, ht ^ 1); n     sz[cur] += sz[u]; n   } n   if (ht) odd++; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs(1); n   for (int i = 1; i <= n; i++) ans += (1LL) * sz[i] * (n - sz[i]); n   ans += (1LL) * odd * (n - odd); n   printf( %lld n , ans / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[300003]; n vector<int> adje[300003]; n int d[300003]; n int pickd[300003]; n bool vis[300003]; n int n, m; n int x; n int dfs1(int u) { n   int ans = 0; n   if (d[u] == -1) n     x = u; n   else if (d[u] == 1) n     ++ans; n   vis[u] = true; n   for (int v : adj[u]) { n     if (!vis[v]) { n       ans += dfs1(v); n     } n   } n   return ans; n } n int dfs2(int u) { n   int ans = 0; n   if (d[u] == 1) ++ans; n   vis[u] = true; n   for (int i = 0; i < ((int)(adj[u].size())); ++i) { n     int v = adj[u][i]; n     if (!vis[v]) { n       int c = dfs2(v); n       if (c % 2) pickd[adje[u][i]] = 1; n       ans += c; n     } n   } n   return ans; n } n bool solve() { n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= n; ++i) { n     if (!vis[i]) { n       x = -1; n       int c = dfs1(i); n       if (c % 2) { n         if (x == -1) n           return false; n         else { n           d[x] = 1; n         } n       } n     } n   } n   memset(vis, 0, sizeof(vis)); n   memset(pickd, 0, sizeof(pickd)); n   for (int i = 1; i <= n; ++i) { n     if (!vis[i]) { n       dfs2(i); n     } n   } n   int k = accumulate(pickd + 1, pickd + m + 1, 0); n   cout << k <<   n ; n   for (int i = 1; i <= m; ++i) { n     if (pickd[i]) { n       cout << i <<    n [(--k) == 0]; n     } n   } n   return true; n } n int main() { n   ios ::sync_with_stdio(0); n   while (cin >> n >> m) { n     for (int i = 1; i <= n; ++i) { n       cin >> d[i]; n     } n     for (int i = 1; i <= m; ++i) { n       int u, v; n       cin >> u >> v; n       adj[u].push_back(v); n       adj[v].push_back(u); n       adje[u].push_back(i); n       adje[v].push_back(i); n     } n     if (!solve()) cout <<  -1 n ; n     for (int i = 1; i <= n; ++i) { n       adj[i].clear(); n       adje[i].clear(); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   char ch = getchar(); n   x = 0; n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); n } n int n, m, mx, now, a[5200]; n signed main() { n   read(n), read(m); n   int tmp = 0; n   for (int i = 3; i <= n; ++i) { n     if (i & 1) ++tmp; n     mx += tmp; n   } n   if (m > mx) return puts( -1 ), 0; n   a[1] = 1, a[2] = 2; n   int p = n + 1; n   tmp = 0; n   for (int i = 3; i <= n; ++i) { n     if (i & 1) ++tmp; n     if (now + tmp > m) { n       p = i - 1; n       break; n     } n     now += tmp, a[i] = i; n   } n   m -= now; n   if (m) n     a[p + 1] = p - m * 2 + 1 + p, p += 2; n   else n     ++p; n   for (int i = p; i <= n; ++i) a[i] = 200000000 + i * n; n   for (int i = 1; i <= n; ++i) printf( %d  , a[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n const int N = 5e3 + 10; n vector<double> vd; n int flag = 0; n vector<int> check(double x, int sz) { n   vector<int> v; n   int cur = 0; n   double tot = x; n   while (v.size() < sz) { n     int o = tot / 10; n     cur += o; n     v.push_back(cur); n     tot -= o * 10; n     if (v.size() == sz) break; n     tot += x; n   } n   if (flag) vd.push_back(tot); n   return v; n } n double solve(vector<int>& v1, int o = 0) { n   double l = 10 + 1e-10; n   double r = INF; n   int cnt = 200; n   while (cnt--) { n     double mid = (l + r) / 2; n     auto v2 = check(mid, v1.size()); n     for (int i = 0; i < v1.size(); i++) { n       if (v1[i] < v2[i]) { n         r = mid; n         break; n       } n       if (v1[i] > v2[i]) { n         l = mid; n         break; n       } n     } n     if (v1 != v2) continue; n     if (o == 0) n       l = mid; n     else n       r = mid; n   } n   return l; n } n int main() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (auto& x : v) cin >> x; n   double key1 = solve(v, 0); n   double key2 = solve(v, 1); n   flag = 1; n   if (key1 > key2) swap(key1, key2); n   int ans1 = check(key1, n + 1).back(); n   int ans2 = check(key2, n + 1).back(); n   if (abs(vd[0] - 10) <= 1e-8) ans1++; n   if (ans1 == ans2) n     puts( unique ), printf( %d n , ans1), exit(0); n   else n     puts( not unique ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long p[11]; n int main() { n   string s; n   cin >> s; n   int n = s.size(); n   p[0] = 1; n   for (int i = 1; i < n; i++) p[i] = p[i - 1] * 9ll; n   long long ans = 1ll; n   for (char c : s) ans *= (long long)(c -  0 ); n   ans = max(ans, p[n - 1]); n   long long pre = 1; n   for (int i = 1; i <= n; i++) { n     for (long long j = 1; j < s[i - 1] -  0 ; j++) { n       ans = max(ans, pre * j * p[n - i]); n     } n     pre *= (long long)(s[i - 1] -  0 ); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string a; n   cin >> a; n   int sum = 0; n   char b[3] = { R ,  G ,  B }; n   for (int i = 1; i < n; i++) { n     if (a[i - 1] == a[i] && a[i] == a[i + 1]) { n       for (int j = 0; j < 3; j++) { n         if (b[j] != a[i]) { n           a[i] = b[j]; n           break; n         } n       } n       sum++; n     } else if (a[i - 1] == a[i]) { n       for (int j = 0; j < 3; j++) { n         if (b[j] != a[i] && b[j] != a[i + 1]) { n           a[i] = b[j]; n           break; n         } n       } n       sum++; n     } n   } n   printf( %d n , sum); n   for (int i = 0; i < n; i++) { n     printf( %c , a[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long r, i; n   int flag = 1; n   cin >> r; n   for (i = 1; i <= 1000000; i++) { n     if ((r - i * i - i - 1) > 0 && (r - i * i - i - 1) % (2 * i) == 0) { n       flag = 0; n       break; n     } n   } n   if (flag == 0) n     printf( %lld %lld n , i, (r - i * i - i - 1) / 2 * i); n   else n     puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n int distance(int x1, int y1, int x2, int y2) { n   return (int)ceil(sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, x, q, cnt = 0; n   string t; n   char ch; n   map<char, vector<pair<int, int>>> keys; n   int freq[26] = {0}; n   cin >> n >> m >> x; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> ch; n       if (!freq[ch -  a ]) freq[ch -  a ]++; n       keys[ch].push_back(make_pair(i, j)); n     } n   } n   if (keys.count( S )) { n     vector<pair<int, int>> shiftCords = keys[ S ]; n     vector<pair<int, int>> chCords; n     for (int i =  a ; i <=  z ; i++) { n       if (keys.count(i)) { n         chCords = keys[i]; n         bool validDistance = 0; n         for (int j = 0; j < (int)chCords.size(); j++) { n           for (int k = 0; k < (int)shiftCords.size(); k++) { n             if (distance(chCords[j].first, chCords[j].second, n                          shiftCords[k].first, shiftCords[k].second) <= x) { n               freq[i -  a ]++; n               validDistance = 1; n               break; n             } n           } n           if (validDistance) break; n         } n       } n     } n   } n   cin >> q; n   cin >> t; n   for (int i = 0; i < q; i++) { n     char c = t[i]; n     if (islower(c)) { n       if (!freq[c -  a ]) { n         cout << -1 << endl; n         return 0; n       } n     } else { n       c = tolower(c); n       if (!keys.count( S ) || !freq[c -  a ]) { n         cout << -1 << endl; n         return 0; n       } else { n         if (freq[c -  a ] == 1) cnt++; n       } n     } n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   int maxP = 0; n   int maxQ = 0; n   for (int i = 0; i < k; i++) { n     int p = 0; n     int q = 0; n     cin >> p; n     cin >> q; n     if (p < q) { n       cout <<  Happy Alex  << endl; n       return 0; n     } n   } n   cout <<  Poor Alex  << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 4e5 + 10; n const int maxm = 2e5 + 10; n const int inf = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n const double eps = 1e-7; n using namespace std; n long long cnt[25][25], dp[1 << 21]; n int n; n vector<int> col[25]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     col[x].push_back(i); n   } n   for (int i = 1; i <= 20; ++i) n     for (int j = 1; j <= 20; ++j) n       if (i != j) { n         if (!col[i].size() || !col[j].size()) continue; n         int l = 0; n         for (int k = 0; k < col[i].size(); ++k) { n           while (true) { n             if (l == col[j].size() - 1 || col[j][l + 1] > col[i][k]) break; n             l++; n           } n           if (col[j][l] < col[i][k]) cnt[i][j] += l + 1; n         } n       } n   memset(dp, 0x3f, sizeof dp); n   dp[0] = 0; n   for (int S = 0; S < 1 << 20; ++S) { n     for (int i = 0; i < 20; ++i) n       if (!(S >> i & 1)) { n         long long sum(0); n         for (int j = 0; j < 20; ++j) n           if (S >> j & 1) sum += cnt[j + 1][i + 1]; n         dp[S | (1 << i)] = min(dp[S | (1 << i)], dp[S] + sum); n       } n   } n   cout << dp[(1 << 20) - 1] << endl; n   return ~~(0 - 0); n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long v; n   cin >> v; n   for (long long i = 0; i < v; i++) { n     vector<long double> arr(250); n     for (long long j = 0; j < 250; j++) cin >> arr[j]; n     long double avg1 = 0; n     for (long long j = 0; j < 250; j++) avg1 += arr[j]; n     avg1 /= 250.0; n     sort(arr.begin(), arr.end()); n     long double v1 = ((arr[249] - arr[0]) * (arr[249] - arr[0])) / 12.0; n     long double v2 = 0; n     for (long long j = 0; j < 250; j++) n       v2 += ((avg1 - arr[j]) * (avg1 - arr[j])); n     v2 /= 250.0; n     long double avg2 = 0; n     if (abs(v2 - avg1) > abs(v1 - v2)) n       cout <<  uniform n ; n     else n       cout <<  poisson n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(string new_l, string old_l) { n   int len_1; n   int col_izm; n   col_izm = 0; n   len_1 = new_l.length(); n   if (len_1 == old_l.length()) { n     for (int i = 0; i < len_1; i++) { n       if (new_l[i] == old_l[i]) { n         col_izm++; n       } else if (((new_l[i] ==  1 ) || (new_l[i] ==  i ) || (new_l[i] ==  l ) || n                   (new_l[i] ==  I ) || (new_l[i] ==  L )) && n                  ((old_l[i] ==  1 ) || (old_l[i] ==  i ) || (old_l[i] ==  l ) || n                   (old_l[i] ==  I ) || (old_l[i] ==  L ))) { n         col_izm++; n       } else if (((new_l[i] ==  0 ) || (new_l[i] ==  o ) || n                   (new_l[i] ==  O )) && n                  ((old_l[i] ==  0 ) || (old_l[i] ==  o ) || n                   (old_l[i] ==  O ))) { n         col_izm++; n       } else if (((new_l[i] - old_l[i]) == 32) || n                  ((new_l[i] - old_l[i]) == -32)) { n         col_izm++; n       } else n         return true; n     } n     if (col_izm == len_1) n       return false; n     else n       return true; n   } else n     return true; n } n int main() { n   string n_login, login; n   int col; n   cin >> n_login; n   cin >> col; n   for (int i = 0; i < col; i++) { n     cin >> login; n     if (!check(n_login, login)) { n       cout <<  No  << endl; n       return 0; n     } n   } n   cout <<  Yes  << endl; n   return 0; n } n


#include <bits/stdc++.h> n int cmp(const void *a, const void *b) { return *((int *)a) - *((int *)b); } n int maximum(int a, int b) { n   if (a > b) { n     return a; n   } else { n     return b; n   } n } n int minimum(int a, int b) { n   if (a < b) { n     return a; n   } else { n     return b; n   } n } n int main() { n   int a[2000]; n   int p = 0, q = 1, x = 1, i, j; n   int pl, pr, vl, vr, k; n   long long c = 0, d; n   a[0] = 0; n   for (i = 0; i < 9; i++) { n     for (j = p; j < q; j++) { n       a[x++] = a[j] * 10 + 4; n       a[x++] = a[j] * 10 + 7; n     } n     p = q; n     q = x; n   } n   qsort(a, x, sizeof(int), cmp); n   a[x] = 1000000001; n   scanf( %d %d %d %d %d , &pl, &pr, &vl, &vr, &k); n   d = (long long)(pr - pl + 1) * (vr - vl + 1); n   for (i = 1; i <= x - k; i++) { n     if (pl <= a[i] && vr >= a[i + k - 1]) { n       int s1 = minimum(a[i], pr); n       int s2 = maximum(a[i - 1] + 1, pl); n       int t1 = maximum(a[i + k - 1], vl); n       int t2 = minimum(a[i + k] - 1, vr); n       if (s1 - s2 >= 0 && t2 - t1 >= 0) { n         c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1); n       } n     } n     if (vl <= a[i] && pr >= a[i + k - 1]) { n       int s1 = minimum(a[i], vr); n       int s2 = maximum(a[i - 1] + 1, vl); n       int t1 = maximum(a[i + k - 1], pl); n       int t2 = minimum(a[i + k] - 1, pr); n       if (s1 - s2 >= 0 && t2 - t1 >= 0) { n         c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1); n       } n     } n   } n   if (k == 1) { n     for (i = 1; i < x; i++) { n       if (pl <= a[i] && pr >= a[i] && vl <= a[i] && vr >= a[i]) c--; n     } n   } n   printf( %.20lf n , (double)c / d); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5100; n char Map[N][N]; n int dp[N][N]; n int main() { n   int i, j; n   int line, row; n   scanf( %d%d , &line, &row); n   for (i = 0; i < line; i++) scanf( %s , Map[i]); n   for (i = 0; i < line; i++) { n     for (j = row - 1; j >= 0; j--) { n       if (Map[i][j] ==  1 ) n         dp[j][i] = dp[j + 1][i] + 1; n       else n         dp[j][i] = 0; n     } n   } n   int ret = 0; n   for (i = 0; i < row; i++) { n     sort(dp[i], dp[i] + line); n     for (j = 0; j < line; j++) { n       ret = max(ret, (line - j) * dp[i][j]); n     } n   } n   printf( %d n , ret); n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx ) n using namespace std; n const double eps = 0.000001; n const long double pi = acos(-1); n const int maxn = 1e7 + 9; n const int mod = 1e9 + 7; n const long long MOD = 1e18 + 9; n const long long INF = 1e18 + 123; n const int inf = 2e9 + 11; n const int mxn = 1e6 + 9; n const int N = 3e5 + 123; n const int PRI = 555557; n const int pri = 997; n int tests = 1; n int n, m, q; n int sz[N], pr[N], ans[N]; n bool u[N]; n vector<int> g[N]; n void dfs(int v, int p = 1) { n   sz[v] = 1; n   pr[v] = p; n   for (int to : g[v]) { n     if (to == p) continue; n     dfs(to, v); n     sz[v] += sz[to]; n   } n } n void dfs_center(int v) { n   u[v] = 1; n   if (sz[v] == 1) { n     ans[v] = v; n     return; n   } n   int mx = g[v].back(); n   for (int to : g[v]) { n     if (u[to]) continue; n     dfs_center(to); n     if (sz[mx] < sz[to]) { n       mx = to; n     } n   } n   int c = ans[mx]; n   while (sz[v] > sz[c] * 2) { n     c = pr[c]; n   } n   ans[v] = c; n } n inline void Solve() { n   cin >> n >> q; n   for (int i = 2; i <= n; i++) { n     int x; n     cin >> x; n     g[x].push_back(i); n   } n   dfs(1); n   dfs_center(1); n   while (q--) { n     int x; n     cin >> x; n     cout << ans[x] <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   while (tests--) { n     Solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   regex w( WUB ); n   cout << regex_replace(s, w,    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = int(1e9) + 7; n int debug = 0; n const int N = int(2e3) + 5; n using namespace std; n int a[N], b[N], p[N]; n int main() { n   int i, j, n, t; n   ios::sync_with_stdio(false); n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) cin >> b[i]; n   int ans = 0; n   vector<pair<int, int> > moves; n   for (i = 0; i < n; i++) p[a[i]] = i; n   for (i = 0; i < n; i++) { n     int pos = -1; n     for (j = 0; j < n; j++) n       if (debug) n         cerr <<  j  n              <<  :   << j <<   |   n              <<  b[j]  n              <<  :   << b[j] << endl; n     ; n     for (j = 0; j < n; j++) n       if (p[b[j]] == i) pos = j; n     if (j == i) continue; n     if (debug) n       cerr <<  pos  n            <<  :   << pos <<   |   n            <<  i  n            <<  :   << i << endl; n     ; n     int cur = pos; n     for (j = pos - 1; j >= i; j--) { n       if (p[b[j]] >= cur) { n         ans += cur - j; n         moves.push_back(make_pair(j, cur)); n         b[cur] = b[j]; n         b[j] = i; n         cur = j; n       } n     } n   } n   cout << ans <<   n ; n   reverse(moves.begin(), moves.end()); n   cout << moves.size() <<   n ; n   for (i = 0; i < moves.size(); i++) n     cout << moves[i].second + 1 <<     << moves[i].first + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3079; n int r, c, n, k; n vector<int> nx(maxn, -1), pv(maxn, -1), kth(maxn, -1); n vector<vector<int> > my(maxn); n class point { n  public: n   int x, y; n }; n bool cmp(point& a, point& b) { return (a.y == b.y ? a.x < b.x : a.y < b.y); } n vector<point> v(maxn); n long long sum(int i) { return (v[i].y - v[pv[i]].y) * (c + 1 - v[kth[i]].y); } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> r >> c >> n >> k; n   long long ans = 0; n   int m = n + k + 1; n   for (int i = 1; i <= n; i++) cin >> v[i].x >> v[i].y; n   v[0] = {r + 1, 0}; n   for (int i = n + 1; i < m; i++) v[i] = {r + 1, c + 1}; n   sort(v.begin(), v.begin() + m, cmp); n   for (int i = n + 1; i < m; i++) n     kth[i] = m - 1, pv[i] = i - 1, nx[i] = min(m - 1, i + 1); n   for (int i = m - 1; i >= 0; i--) my[v[i].x].push_back(i); n   for (int x1 = 1; x1 <= r; x1++) { n     int p = 0; n     for (int i = 1; i <= n; i++) { n       if (v[i].x < x1) continue; n       nx[p] = i, pv[i] = p; n       p = i; n     } n     nx[p] = n + 1, pv[n + 1] = p; n     kth[p] = (k == 1 ? p : pv[m - 1]); n     for (int i = p; i >= 0; i = pv[i]) kth[i] = pv[kth[nx[i]]]; n     long long cur = 0; n     for (int i = nx[0]; i <= n; i = nx[i]) cur += sum(i); n     for (int x2 = r; x2 >= x1; x2--) { n       ans += cur; n       for (int i : my[x2]) { n         cur -= sum(i); n         for (int j = pv[i], cnt = 0; cnt < k - 1 && j; cnt++, j = pv[j]) { n           cur -= sum(j); n           if (j < i) kth[j] = nx[kth[j]]; n           cur += sum(j); n         } n         cur -= sum(nx[i]); n         nx[pv[i]] = nx[i], pv[nx[i]] = pv[i]; n         cur += sum(nx[i]); n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 233; n const int INF = numeric_limits<int>::max(); n void read(int &x) { n   x = 0; n   char ch = getchar(); n   int f = 1; n   while (!isdigit(ch)) (ch ==  -  ? f = -1 : 0), ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   x *= f; n } n int f[N][105], g[105]; n int n, K, p, a[N], nw, s[N]; n int x, sum, st[N], tp; n signed main() { n   memset(g, 0x7f, sizeof(g)); n   memset(f, 0x7f, sizeof(f)); n   read(n); n   read(K); n   read(p); n   if (p * K > n) { n     for (int i = 1; i <= n; ++i) { n       read(x); n       x %= p; n       a[i] = x; n       sum = (sum + a[i]) % p; n       f[i][1] = sum; n       g[1] = sum; n       for (int j = min(K, i); j >= 2; --j) n         if (i == j) { n           f[i][j] = f[i - 1][j - 1] + x; n           g[j] = x; n         } else { n           int l = f[i - 1][j - 1] + x; n           int r = f[i - 1][j] + x; n           if (g[j] + x >= p) r -= p; n           if (l < r) n             f[i][j] = l, g[j] = x; n           else if (l > r) n             f[i][j] = r, g[j] = (g[j] + x) % p; n           else n             f[i][j] = l, g[j] = max(x, (g[j] + x) % p); n         } n     } n     return printf( %d , f[n][K]), 0; n   } n   for (int i = 1; i <= n; ++i) n     read(a[i]), a[i] %= p, sum += a[i], s[i] = (s[i - 1] + a[i]) % p; n   for (int i = 1; i <= n - 1; ++i) { n     int pos = upper_bound(st + 1, st + 1 + tp, s[i]) - st; n     if (pos > tp) ++tp; n     st[pos] = s[i]; n   } n   int pos = upper_bound(st + 1, st + 1 + tp, s[n]) - st; n   if (pos >= K) n     printf( %d , s[n]); n   else n     printf( %d , s[n] + p); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int y; n vector<pair<int, int> > p[3]; n int dp[111][111][3]; n bool check(int x, int t, int y) { n   for (int i = 0; i < p[y].size(); i++) { n     if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t) return false; n   } n   return true; n } n int go(int x, int t, int y) { n   if (x == n - 1) return true; n   int& res = dp[x][t][y]; n   if (res != -1) return res; n   res = 0; n   for (int i = 0; i < p[y].size(); i++) { n     if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t || n         x + 1 >= p[y][i].first - 2 * t && x + 1 <= p[y][i].second - 2 * t) n       return res = false; n   } n   if (check(x + 1, t, y)) res |= go(x + 1, t + 1, y); n   if (check(x + 1, t, min(2, y + 1))) res |= go(x + 1, t + 1, min(2, y + 1)); n   if (check(x + 1, t, max(y - 1, 0))) res |= go(x + 1, t + 1, max(y - 1, 0)); n   return res; n } n void R(string s, int v) { n   int i = 0; n   if (s[0] ==  s ) { n     y = v; n     s[0] =  . ; n   } n   while (i < s.size()) { n     if (s[i] !=  . ) { n       int l = i; n       int r = l; n       while (i < s.size() && s[i] == s[l]) i++; n       r = i - 1; n       i--; n       p[v].push_back(make_pair(l, r)); n       if (i == s.size() - 1) return; n     } n     i++; n   } n } n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     p[0].clear(); n     p[1].clear(); n     p[2].clear(); n     memset(dp, -1, sizeof(dp)); n     cin >> n >> k; n     string s1, s2, s3; n     cin >> s1 >> s2 >> s3; n     R(s1, 0); n     R(s2, 1); n     R(s3, 2); n     if (go(0, 0, y)) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n const int sz = 1 << 15; n char inbuf[sz], outbuf[sz]; n char *pinbuf = inbuf + sz; n char *poutbuf = outbuf; n inline char _getchar() { n   if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf; n   return *(pinbuf++); n } n inline void _putchar(char x) { n   if (poutbuf == outbuf + sz) fwrite(outbuf, 1, sz, stdout), poutbuf = outbuf; n   *(poutbuf++) = x; n } n inline void flush() { n   if (poutbuf != outbuf) n     fwrite(outbuf, 1, poutbuf - outbuf, stdout), poutbuf = outbuf; n } n }  // namespace IO n inline int read() { n   int x = 0, p = 1; n   char c = IO::_getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) p = -1; n     c = IO::_getchar(); n   } n   while (c >=  0  && c <=  9 ) x = x * 10 + c - 48, c = IO::_getchar(); n   return x * p; n } n namespace Mymath { n long long qp(long long x, long long p, long long mod) { n   long long ans = 1; n   while (p) { n     if (p & 1) ans = ans * x % mod; n     x = x * x % mod; n     p >>= 1; n   } n   return ans; n } n long long inv(long long x, long long mod) { return qp(x, mod - 2, mod); } n long long C(long long N, long long K, long long fact[], long long mod) { n   return fact[N] * inv(fact[K], mod) % mod * inv(fact[N - K], mod) % mod; n } n template <typename Tp> n Tp gcd(Tp A, Tp B) { n   if (B == 0) return A; n   return gcd(B, A % B); n } n template <typename Tp> n Tp lcm(Tp A, Tp B) { n   return A * B / gcd(A, B); n } n };  // namespace Mymath n const int Maxn = 705; n const long long mod = 1e9 + 7; n int dp[Maxn][3][Maxn][11]; n int tot[11][Maxn]; n char c[Maxn]; n int n; n void Add(int &x, int y) { n   x += y; n   if (x >= mod) x -= mod; n } n int main() { n   scanf( %s , c); n   n = strlen(c); n   for (int i = 0; i <= 9; i++) dp[0][1][0][i] = 1; n   for (int i = 0; i < n; i++) { n     int curv = c[i] -  0 ; n     for (int j = 0; j <= i; j++) { n       for (int k = 0; k <= 9; k++) { n         if (i) n           for (int l = 0; l < 3; l++) Add(tot[k][j], dp[i][l][j][k]); n         Add(dp[i + 1][1][j + (curv >= k)][k], dp[i][1][j][k]); n         for (int l = 0; l <= 9; l++) { n           if (!i && !l) continue; n           if (l == curv) continue; n           Add(dp[i + 1][(l < curv) ? 0 : 2][j + (l >= k)][k], dp[i][1][j][k]); n         } n         for (int l = 0; l <= 9; l++) { n           if (!i && !l) continue; n           Add(dp[i + 1][0][j + (l >= k)][k], dp[i][0][j][k]); n           Add(dp[i + 1][2][j + (l >= k)][k], dp[i][2][j][k]); n         } n       } n     } n   } n   for (int j = 0; j <= n; j++) { n     for (int k = 0; k <= 9; k++) { n       for (int l = 0; l < 2; l++) Add(tot[k][j], dp[n][l][j][k]); n     } n   } n   for (int i = 0; i <= 9; i++) { n     for (int j = n; j >= 0; j--) { n       Add(tot[i][j], tot[i][j + 1]); n     } n   } n   long long ans = 0; n   int w = 1; n   for (int i = 0; i < n; i++) { n     for (int j = 1; j <= 9; j++) { n       int cnt = tot[j][i + 1] - tot[j + 1][i + 1]; n       if (cnt < 0) cnt += mod; n       ans += 1ll * cnt * w % mod * j; n       ans %= mod; n     } n     w = 1ll * w * 10 % mod; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n std::ostream &operator<<(std::ostream &out, vector<T> &v) { n   for (typename vector<T>::size_type i = 0; i < v.size(); ++i) n     out << v[i] <<    ; n   out <<   n ; n   return out; n } n template <typename T> n std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) { n   for (size_t i = 0; i < v.size(); ++i) { n     for (size_t j = 0; j < v[i].size(); ++j) { n       out << v[i][j] <<    ; n     } n     out <<   n ; n   } n   return out; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, k; n   cin >> n >> k; n   vector<long long> divisors; n   for (long long i = 1; i * i <= n; ++i) { n     if (n % i == 0) { n       divisors.push_back(i); n       if (n / i != i) { n         divisors.push_back(n / i); n       } n     } n   } n   if (k > divisors.size()) { n     cout <<  -1 n ; n     return 0; n   } n   sort(divisors.begin(), divisors.end()); n   cout << divisors[k - 1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000; n struct node { n   int n; n   int i; n   node(int n, int i) : n(n), i(i) {} n   node() {} n   bool operator<(const node& n1) const { return n < n1.n; } n   bool is_happy() const { n     int a = n; n     while (a) { n       if (a % 10 != 7 && a % 10 != 4) return false; n       a /= 10; n     } n     return true; n   } n }; n node nodes[maxn]; n int rev[maxn]; n inline void sw(int i, int j, vector<pair<int, int> >& ans) { n   ans.push_back(pair<int, int>(nodes[i].i, nodes[j].i)); n   swap(nodes[i].i, nodes[j].i); n   rev[nodes[i].i] = i; n   rev[nodes[j].i] = j; n } n int main() { n   int n; n   scanf( %d , &n); n   bool sorted = true; n   int x = -1, prev; n   for (int i = 0; i < n; i++) { n     prev = x; n     scanf( %d , &x); n     if (prev > x) sorted = false; n     nodes[i] = node(x, i); n   } n   if (sorted) { n     printf( 0 n ); n     return 0; n   } n   sort(nodes, nodes + n); n   for (int i = 0; i < n; i++) { n     rev[nodes[i].i] = i; n   } n   int happy = -1; n   for (int i = 0; i < n; i++) { n     if (nodes[i].is_happy()) { n       happy = i; n       break; n     } n   } n   if (happy == -1) { n     printf( -1 n ); n     return 0; n   } n   vector<pair<int, int> > ans; n   for (int i = 0; i < n; i++) n     if (i != happy && nodes[i].i != i) { n       if (rev[i] != happy) sw(rev[i], happy, ans); n       sw(happy, i, ans); n     } n   printf( %d n , ans.size()); n   for (int i = 0; i < 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 const int Mod = 1e9 + 7; n int qpow(long long a, long long b) { n   long long c = 1; n   while (b) { n     if (b & 1) c = c * a % Mod; n     if (b >>= 1) a = a * a % Mod; n   } n   return c; n } n int n; n long long a; n int p, q; n int main() { n   scanf( %d , &n); n   bool minus = 1; n   q = 2; n   for (int i = 1; i <= n; i++) { n     scanf( %I64d , &a); n     if (!(a & 1)) minus = 0; n     q = qpow(q, a); n   } n   q = q * 500000004ll % Mod; n   if (minus) { n     p = q - 1; n     if (p < 0) p += Mod; n   } else n     p = q + 1; n   p = p * 333333336ll % Mod; n   printf( %d/%d n , p, q); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int dx[4] = {-1, 0, 0, +1}; n long long int dy[4] = {0, -1, +1, 0}; n const long long int LINF = 1e18; n const long long int INF = 1e9; n const long long int mod = 1e9 + 7; n long long int power(long long int a, long long int b, long long int m) { n   if (b == 0) return 1; n   if (b == 1) return a % m; n   long long int t = power(a, b / 2, m); n   t = (t * t) % m; n   if (b & 1) t = (t * a) % m; n   return t; n } n long long int modInverse(long long int a, long long int m) { n   return power(a, m - 2, m); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, ans = 0, i, j; n     string ip; n     cin >> ip; n     long long int sz = ip.size(); n     if (ip[0] ==  ? ) { n       if (sz >= 2 && ip[1] ==  a ) n         ip[0] =  b ; n       else n         ip[0] =  a ; n     } n     for (long long int i = 1; i <= -1 + ip.size(); i++) { n       if (ip[i] ==  ? ) { n         if (ip[i - 1] ==  a ) { n           if ((i + 1) < sz && ip[i + 1] ==  b ) n             ip[i] =  c ; n           else n             ip[i] =  b ; n         } else if (ip[i - 1] ==  b ) { n           if ((i + 1) < sz && ip[i + 1] ==  a ) n             ip[i] =  c ; n           else n             ip[i] =  a ; n         } else if (ip[i - 1] ==  c ) { n           if ((i + 1) < sz && ip[i + 1] ==  a ) n             ip[i] =  b ; n           else n             ip[i] =  a ; n         } else n           ip[i] =  a ; n       } n     } n     bool poss = true; n     for (long long int i = 1; i <= sz - 1; i++) { n       if (ip[i] == ip[i - 1]) { n         cout << -1 << endl; n         poss = false; n         break; n       } n     } n     if (poss) cout << ip << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[105], b[105], c[105], tot, ans; n char s[105]; n int main() { n   scanf( %d , &n); n   scanf( %s , s + 1); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &a[i], &b[i]); n     c[i] = s[i] -  0 ; n     if (c[i] == 1) tot++; n   } n   ans = tot; n   for (int i = 1; i <= 125; i++) { n     for (int j = 1; j <= n; j++) { n       if (i < b[j]) continue; n       int k = i - b[j]; n       if (k % a[j] != 0) continue; n       tot -= c[j]; n       c[j] ^= 1; n       tot += c[j]; n     } n     ans = max(ans, tot); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x7fffffff; n const int oo = 0x3f3f3f3f; n template <typename T> n inline void rd(T &x) { n   x = 0; n   int f = 1; n   char CH = getchar(); n   while (!isdigit(CH)) { n     if (CH ==  - ) f = 0; n     CH = getchar(); n   } n   while (isdigit(CH)) { n     x = ((x + (x << 2)) << 1) + (CH - 48); n     CH = getchar(); n   } n   x = (f == 1) ? x : -x; n   return; n } n const int MXN = 2e6; n int a[MXN], n; n inline void solve() { n   long long fuck; n   rd(fuck); n   if (fuck > 36) { n     cout << -1; n     return; n   } n   if (fuck == 1) n     cout << 6; n   else if (fuck == 2) n     cout << 8; n   else if (fuck > 2) { n     while (fuck > 2) fuck -= 2, cout << 8; n     if (fuck == 1) cout << 0; n     if (fuck == 2) cout << 8; n   } n } n int main() { solve(); } n


#include <bits/stdc++.h> n const int MAXN = 100; n char s[MAXN + 5]; n int main() { n   int n, p, q; n   scanf( %d%d%d , &n, &p, &q); n   scanf( %s , s); n   for (int i = 0; p * i <= n; i++) { n     if ((n - p * i) % q == 0) { n       int j = (n - p * i) / q; n       printf( %d n , i + j); n       int pos = 0; n       for (int k = 1; k <= i; k++) { n         for (int l = 1; l <= p; l++) { n           printf( %c , s[pos]); n           pos++; n         } n         puts(  ); n       } n       for (int k = 1; k <= j; k++) { n         for (int l = 1; l <= q; l++) { n           printf( %c , s[pos]); n           pos++; n         } n         puts(  ); n       } n       return 0; n     } n   } n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &x) { n   x = 0; n   bool f = 0; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = 1; n   for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); n   if (f) x = -x; n } n long long T, n, m, k; n int main() { n   read(T); n   while (T--) { n     read(n), read(k); n     k = k * k; n     if ((n & 1) != (k & 1) || k > n) n       puts( NO ); n     else n       puts( YES ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxn(3e5 + 10), mxm(4e5 + 10); n const long long modl(998244353); n int nm, n, m, p, t, k; n int ans; n int a[mxn], b[mxn], c[mxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> nm; n   while (cin >> n >> m) { n     ans = max(0, n + m - 3) / m + 1; n     cout << ans; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 27; n vector<vector<int>> g; n int t, tin[N], tout[N], up[N][20], sz[N], d[N]; n void dfs(int v, int p = 0, int dp = 0) { n   tin[v] = t++; n   d[v] = dp; n   sz[v] = 1; n   up[v][0] = p; n   for (int i = 1; i < 20; i++) up[v][i] = up[up[v][i - 1]][i - 1]; n   for (int u : g[v]) { n     if (u != p) { n       dfs(u, v, dp + 1); n       sz[v] += sz[u]; n     } n   } n   tout[v] = t++; n } n bool is(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; } n int get_up(int a, int b) { n   for (int i = 18; i >= 0; i--) { n     if (!is(up[a][i], b)) a = up[a][i]; n   } n   return a; n } n int lca(int a, int b) { n   if (is(a, b)) return a; n   if (is(b, a)) return b; n   return up[get_up(a, b)][0]; n } n int main() { n   int n; n   cin >> n; n   g.resize(n + 1); n   for (int i = 1; i < n; i++) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   tin[0] = -1; n   tout[0] = 3 * N; n   dfs(1); n   int q; n   cin >> q; n   for (int o = 0; o < q; o++) { n     int a, b; n     cin >> a >> b; n     int l = lca(a, b); n     if (a == b) n       cout << n <<   n ; n     else if (d[b] - d[l] == d[a] - d[l]) { n       a = get_up(a, l); n       b = get_up(b, l); n       cout << n - sz[a] - sz[b] <<   n ; n     } else { n       if (d[a] < d[b]) swap(a, b); n       int dist = d[a] + d[b] - 2 * d[l]; n       if (dist % 2) { n         puts( 0 ); n         continue; n       } n       dist /= 2; n       int u = a; n       for (int i = 18; i >= 0; i--) { n         if (d[a] - d[up[u][i]] < dist) u = up[u][i]; n       } n       int m = up[u][0]; n       cout << sz[m] - sz[u] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int l, t, c, a; n bool vis[26]; n bool ok = false; n int main() { n   cin >> s; n   l = s.size(); n   if (l < 26) { n     cout << -1 << endl; n     return 0; n   } n   for (int i = 0; i < l; ++i) { n     memset(vis, 0, sizeof vis); n     t = c = 0; n     for (int j = i; j < i + 26 && j < l; ++j) { n       if (vis[s[j] -  A ]) break; n       if (s[j] ==  ? ) { n         c++; n         continue; n       } n       vis[s[j] -  A ]++; n       t++; n     } n     if (c + t == 26) { n       a = i; n       ok = true; n       break; n     } n   } n   if (!ok) { n     cout << -1 << endl; n     return 0; n   } n   queue<char> q; n   for (int j = 0; j < 26; ++j) { n     if (!vis[j]) q.push((char)j +  A ); n   } n   for (int i = 0; i < a; ++i) n     if (s[i] !=  ? ) n       cout << s[i]; n     else n       cout <<  A ; n   for (int i = a; i < 26 + a; ++i) n     if (s[i] !=  ? ) n       cout << s[i]; n     else { n       cout << q.front(); n       q.pop(); n     } n   for (int i = 26 + a; i < l; ++i) n     if (s[i] !=  ? ) n       cout << s[i]; n     else n       cout <<  A ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long k; n   cin >> k; n   long long second = 2000 + k; n   long long ar[2000]; n   ar[0] = -1; n   for (long long int i = 1; i < 2000; i++) { n     if (second <= 1000000) { n       ar[i] = second; n       second = 0; n     } else { n       ar[i] = 1000000; n       second -= 1000000; n     } n   } n   cout << 2000 <<   n ; n   for (long long int i = 0; i < 2000; i++) n     cout << ar[i] << ((i == (2000 - 1)) ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> blame(1002, 0); n vector<bool> visited(1002, false); n long long dfs(long long u) { n   if (visited[u]) return u; n   visited[u] = true; n   return dfs(blame[u]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> blame[i]; n   } n   for (long long i = 1; i <= n; i++) { n     cout << dfs(i) <<    ; n     fill(visited.begin(), visited.end(), false); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long g; n void ex_gcd(long long a, long long b, long long& x, long long& y) { n   if (!b) { n     g = a; n     x = 1, y = 0; n   } else { n     ex_gcd(b, a % b, y, x); n     y = y - a / b * x; n   } n } n int main() { n   long long a, b, c; n   scanf( %lld%lld%lld , &a, &b, &c); n   long long x, y; n   ex_gcd(a, b, x, y); n   if (c % g != 0) return 0 * printf( -1 n ); n   return 0 * printf( %lld %lld n , x * (-c / g), y * (-c / g)); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x[300300], y[300300]; n vector<int> graph[300300]; n int counter, dfs_num[300300], dfs_low[300300], dfs_parent[300300]; n vector<pair<int, int> > bs; n void bridges(int u) { n   dfs_low[u] = dfs_num[u] = counter++; n   for (int v : graph[u]) { n     if (!dfs_num[v]) { n       dfs_parent[v] = u; n       bridges(v); n       if (dfs_low[v] > dfs_num[u]) bs.push_back(pair<int, int>(u, v)); n       dfs_low[u] = min(dfs_low[u], dfs_low[v]); n     } else if (v != dfs_parent[u]) { n       dfs_low[u] = min(dfs_low[u], dfs_num[v]); n     } n   } n } n vector<pair<int, int> > ng[300300]; n struct subset { n   int parent, _rank; n } subsets[300300]; n int Find(int i) { n   if (subsets[i].parent != i) subsets[i].parent = Find(subsets[i].parent); n   return subsets[i].parent; n } n void Union(int x, int y) { n   int xroot = Find(x), yroot = Find(y); n   if (subsets[xroot]._rank < subsets[yroot]._rank) n     subsets[xroot].parent = yroot; n   else if (subsets[xroot]._rank > subsets[yroot]._rank) n     subsets[yroot].parent = xroot; n   else { n     subsets[yroot].parent = xroot; n     subsets[xroot]._rank++; n   } n } n int maxi = 1, dist[300300]; n void dfs(int u, int p, int d) { n   if (d > dist[maxi]) maxi = u; n   dist[u] = d; n   for (pair<int, int> v : ng[u]) { n     if (v.first != p) { n       dfs(v.first, u, d + v.second); n     } n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d %d , &x[i], &y[i]); n     graph[x[i]].push_back(y[i]); n     graph[y[i]].push_back(x[i]); n   } n   counter = 1; n   for (int i = 1; i <= n; i++) n     if (!dfs_num[i]) bridges(i); n   for (int i = 1; i <= n; i++) { n     subsets[i].parent = i; n     subsets[i]._rank = 1; n   } n   for (int i = 0; i < bs.size(); i++) { n     Union(bs[i].first, bs[i].second); n     ng[bs[i].first].push_back(pair<int, int>(bs[i].second, 1)); n     ng[bs[i].second].push_back(pair<int, int>(bs[i].first, 1)); n   } n   for (int i = 0; i < m; i++) { n     if (Find(x[i]) == Find(y[i])) continue; n     Union(x[i], y[i]); n     ng[x[i]].push_back(pair<int, int>(y[i], 0)); n     ng[y[i]].push_back(pair<int, int>(x[i], 0)); n   } n   dfs(1, 0, 0); n   memset(dist, 0, sizeof dist); n   dfs(maxi, 0, 0); n   printf( %d n , dist[maxi]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[100005], D[100005], n, m, w, L[100005]; n bool go(int h) { n   fill(L, L + n, 0); n   for (int i = 0; i < n; ++i) D[i] = max(h - A[i], 0); n   int pow = 0, cap = m, d; n   for (int i = 0; i < n; ++i) { n     pow -= L[i]; n     d = max(D[i] - pow, 0); n     if (d > cap) return false; n     pow += d; n     cap -= d; n     if (i + w < n) L[i + w] += d; n   } n   return true; n } n int main() { n   std::ios::sync_with_stdio(false); n   int mini = 2e9; n   cin >> n >> m >> w; n   for (int i = 0; i < n; ++i) { n     cin >> A[i]; n     mini = min(mini, A[i]); n   } n   int lo = mini, hi = mini + m + 1, mid; n   while (hi - lo > 1) { n     mid = (hi + lo) >> 1; n     if (go(mid)) n       lo = mid; n     else n       hi = mid; n   } n   cout << lo << endl; n } n


#include <bits/stdc++.h> n int main(void) { n   int t, n, d; n   scanf( %d , &t); n   while (t--) { n     scanf( %d %d , &n, &d); n     int i = 0; n     int flag = 1; n     while (i < n) { n       int te = d / (i + 1); n       te = te * (i + 1) == d ? te : te + 1; n       if (i + te <= n) { n         printf( YES n ); n         flag = 0; n         break; n       } n       i++; n     } n     if (flag) printf( NO n ); n   } n   return 0; 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   int n, m1 = 0, m2 = 0; n   cin >> n; n   vector<vector<long long> > m(n, vector<long long>(n)); n   vector<int> a(n); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) cin >> m[i][j]; n   for (int i = 1; i < n - 1; i++) n     a[i] = sqrt(m[i][i + 1] * m[i - 1][i] / m[i - 1][i + 1]); n   a[0] = m[0][1] / a[1]; n   a[n - 1] = m[0][n - 1] / a[0]; n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n const long long maxm = 1e5 + 100; n long long n, m; n struct node { n   long long col[maxm * 4], tag[maxm * 4], sum[maxm * 4], siz[maxm * 4]; n   inline void pushup(long long o) { n     sum[o] = sum[(o << 1)] + sum[(o << 1) | 1]; n     col[o] = col[(o << 1)] == col[(o << 1) | 1] ? col[(o << 1)] : 0; n   } n   inline void pushdown(long long o) { n     if (tag[o]) { n       tag[(o << 1)] += tag[o]; n       tag[(o << 1) | 1] += tag[o]; n       sum[(o << 1)] += siz[(o << 1)] * tag[o]; n       sum[(o << 1) | 1] += siz[(o << 1) | 1] * tag[o]; n       col[(o << 1)] = col[(o << 1) | 1] = col[o]; n       tag[o] = 0; n     } n   } n   void build(long long o, long long l, long long r) { n     siz[o] = (r - l + 1); n     if (l >= r) { n       col[o] = l; n       return; n     } n     long long mid = (l + r) >> 1; n     build((o << 1), l, mid), build((o << 1) | 1, mid + 1, r); n     pushup(o); n   } n   void cover(long long o, long long l, long long r, long long ql, long long qr, n              long long c) { n     if (ql > r || qr < l) return; n     if ((ql <= l) && (r <= qr) && col[o]) { n       tag[o] += abs(col[o] - c); n       sum[o] += abs(col[o] - c) * siz[o]; n       col[o] = c; n       return; n     } n     pushdown(o); n     long long mid = (l + r) >> 1; n     cover((o << 1), l, mid, ql, qr, c), n         cover((o << 1) | 1, mid + 1, r, ql, qr, c); n     pushup(o); n   } n   long long ask(long long o, long long l, long long r, long long ql, n                 long long qr) { n     if (ql > r || qr < l) return 0; n     if ((ql <= l) && (r <= qr)) return sum[o]; n     pushdown(o); n     long long mid = (l + r) >> 1; n     return ask((o << 1), l, mid, ql, qr) + n            ask((o << 1) | 1, mid + 1, r, ql, qr); n   } n } st; n signed main() { n   scanf( %I64d%I64d , &n, &m); n   st.build(1, 1, n); n   for (long long i = 1; i <= m; i++) { n     long long opt, l, r, x; n     scanf( %I64d%I64d%I64d , &opt, &l, &r); n     if (opt == 1) n       scanf( %I64d , &x), st.cover(1, 1, n, l, r, x); n     else n       printf( %I64d n , st.ask(1, 1, n, l, r)); n   } n   return 0; n } n


#include <bits/stdc++.h> n template <typename Arg1> n void ZZ(const char* name, Arg1&& arg1) { n   std::cout << name <<   =   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void ZZ(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   std::cout.write(names, comma - names) <<   =   << arg1; n   ZZ(comma, args...); n } n using namespace std; n long long int to_ll(string& s) { n   long long int i, ret = 0, p = 1; n   for (i = (long long int)s.length() - 1; i >= 0; i--) n     ret += (s[i] -  0 ) * p, p *= 10LL; n   return ret; n } n long long int gcd(long long int x, long long int y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n long long int pwr(long long int base, long long int expo, long long int m) { n   if (base == 0) return 0LL; n   if (expo == 0) return (1LL % m); n   if ((expo & 1) == 0) { n     long long int temp = pwr(base, expo >> 1, m); n     return (temp * temp) % m; n   } n   return ((base % m) * pwr(base, expo - 1, m)) % 1000000007; n } n vector<long long int> adj[200009]; n long long int dp_down[200009][5], dp_up[200009][5], sz_down[200009][5], n     sz_up[200009][5], p[200009], dp[200009][5], dp_sz[200009][5]; n bool v_dp_down[200009][5], v_dp_up[200009][5], v_sz_down[200009][5], n     v_sz_up[200009][5]; n long long int n, k; n void dfs(long long int node, long long int parent) { n   long long int i; n   p[node] = parent; n   for (i = 0; i < adj[node].size(); i++) { n     long long int nxt = adj[node][i]; n     if (nxt == parent) continue; n     dfs(nxt, node); n   } n } n void dfs_sz_down(long long int node, long long int parent, long long int m) { n   long long int i; n   if (v_sz_down[node][m] == 1) return; n   v_sz_down[node][m] = 1; n   for (i = 0; i < adj[node].size(); i++) { n     long long int nxt = adj[node][i]; n     long long int nxt_m = ((m - 1) % k + k) % k; n     if (nxt == parent) continue; n     dfs_sz_down(nxt, node, nxt_m); n     sz_down[node][m] += sz_down[nxt][nxt_m]; n     dp_sz[node][nxt_m] += sz_down[nxt][nxt_m]; n   } n   if (m == 0) sz_down[node][m]++; n } n void dfs_sz_up(long long int node, long long int parent, long long int m) { n   if (v_sz_up[node][m] == 1) return; n   v_sz_up[node][m] = 1; n   if (m == 0) sz_up[node][m]++; n   if (parent == -1) return; n   long long int nxt_m = ((m - 1) % k + k) % k, i; n   dfs_sz_up(parent, p[parent], nxt_m); n   sz_up[node][m] += sz_up[parent][nxt_m]; n   sz_up[node][m] += dp_sz[parent][((m - 2) % k + k) % k]; n   sz_up[node][m] -= sz_down[node][((m - 2) % k + k) % k]; n } n void dfs_up(long long int node, long long int parent, long long int m) { n   if (v_dp_up[node][m] == 1) return; n   v_dp_up[node][m] = 1; n   if (parent == -1) return; n   long long int nxt_m = ((m - 1) % k + k) % k, i; n   dfs_up(parent, p[parent], nxt_m); n   dp_up[node][m] += sz_up[parent][nxt_m] + dp_up[parent][nxt_m]; n   dp_up[node][m] += dp[parent][((m - 2) % k + k) % k]; n   dp_up[node][m] -= (2 * sz_down[node][((m - 2) % k + k) % k] + n                      dp_down[node][((m - 2) % k + k) % k]); n } n void dfs_down(long long int node, long long int parent, long long int m) { n   if (v_dp_down[node][m] == 1) return; n   v_dp_down[node][m] = 1; n   long long int i; n   for (i = 0; i < adj[node].size(); i++) { n     long long int nxt = adj[node][i]; n     long long int nxt_m = ((m - 1) % k + k) % k; n     if (nxt == parent) continue; n     dfs_down(nxt, node, nxt_m); n     dp_down[node][m] += sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m]; n     dp[node][nxt_m] += (2 * sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m]); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int i, j, x, y, ans = 0; n   cin >> n >> k; n   for (i = 0; i < n - 1; i++) { n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs(1, -1); n   for (i = 1; i <= n; i++) n     for (j = 0; j < k; j++) dfs_sz_down(i, p[i], j); n   for (i = 1; i <= n; i++) n     for (j = 0; j < k; j++) dfs_sz_up(i, p[i], j); n   for (i = 1; i <= n; i++) n     for (j = 0; j < k; j++) dfs_down(i, p[i], j); n   for (i = 1; i <= n; i++) n     for (j = 0; j < k; j++) dfs_up(i, p[i], j); n   for (j = 0; j < k; j++) { n     for (i = 1; i <= n; i++) { n       long long int total = dp_up[i][j] + dp_down[i][j]; n       long long int total_sz = sz_down[i][j] + sz_up[i][j]; n       if (j == 0) total_sz--; n       long long int val = ((total - total_sz * j) / k); n       if (j != 0) val += total_sz; n       ans += val; n     } n   } n   cout << ans / 2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 4; n int n, m, a, b, ay[N], by[N], l[N], linkY[N << 1]; n void read() { n   cin >> n >> m >> a >> b; n   for (int i = 1; i <= n; ++i) { n     cin >> ay[i]; n   } n   for (int i = 1; i <= m; ++i) { n     cin >> by[i]; n   } n   for (int i = 1; i <= m; ++i) { n     cin >> l[i]; n   } n } n long double dist = 1e18; n int ida, idb, idTmp; n long double sqr(long double x) { return x * x; } n long double euc(long double xa, long double ya, long double xb, n                 long double yb) { n   return sqrt(sqr(xa - xb) + sqr(ya - yb)); n } n long double f(int ni, int mi) { n   return euc(0, 0, a, ay[ni]) + euc(a, ay[ni], b, by[mi]); n } n long double ternarySearch(int num) { n   int l = 1, r = n; n   while (l + 2 < r) { n     int dm = (r - l) / 3; n     int m1 = l + dm; n     int m2 = r - dm; n     long double d1 = f(m1, num); n     long double d2 = f(m2, num); n     if (fabs(d1 - d2) < 1e-9) { n       l = m1; n       r = m2; n     } else if (d1 < d2) { n       r = m2; n     } else { n       l = m1; n     } n   } n   idTmp = l; n   for (int i = l + 1; i <= r; ++i) { n     if (f(i, num) < f(idTmp, num)) { n       idTmp = i; n     } n   } n   return f(idTmp, num); n } n void calc() { n   for (int i = 1; i <= m; ++i) { n     long double distTmp = ternarySearch(i) + l[i]; n     if (distTmp < dist) { n       dist = distTmp; n       ida = idTmp; n       idb = i; n     } n   } n } n void sovle() { n   read(); n   calc(); n   cout << ida <<     << idb; n } n int main() { n   ios_base::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n   sovle(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops ) n #pragma GCC target( avx,avx2,sse,sse2 ) n using namespace std; n using vi = vector<long long>; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n long long powmod(long long a, long long b, long long mod) { n   if (b == 0 || a == 1) { n     if (mod == 1) n       return 0; n     else n       return 1; n   } n   if (b % 2 == 0) { n     long long k = powmod(a, b / 2, mod); n     return (k * k) % mod; n   } else { n     long long k = powmod(a, b / 2, mod); n     return ((k * k) % mod * a) % mod; n   } n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   if (b == 0) return a; n   if (a > b) n     return gcd(a % b, b); n   else n     return gcd(b % a, a); n } n long long prime(long long p) { n   if (p == 1) return 0; n   for (long long i = 2; i * i <= p; i++) { n     if (p % i == 0 && i < p) return i; n   } n   return 1; n } n long long inv(long long a, long long mod) { return powmod(a, mod - 2, mod); } n long long random_modul() { n   uniform_int_distribution<long long> u1(1e9, 2e9); n   long long pepega = u1(rnd); n   while (prime(pepega) != 1) pepega = u1(rnd); n   return pepega; n } n template <typename T1> n void ifmax(T1& max, T1 kek) { n   if (kek > max) max = kek; n   return; n } n template <typename T1> n void ifmin(T1& min, T1 kek) { n   if (kek < min) min = kek; n   return; n } n template <typename T1> n istream& operator>>(std::istream& in, pair<T1, T1>& a) { n   in >> a.first >> a.second; n   return in; n } n template <typename T1> n istream& operator>>(std::istream& in, vector<T1>& a) { n   for (long long i = 0; i < a.size(); i++) in >> a[i]; n   return in; n } n template <typename T1> n ostream& operator<<(std::ostream& out, vector<T1>& b) { n   for (long long i = 0; i < b.size(); i++) out << b[i]; n   return out; n } n template <typename T1> n void sort(vector<T1>& m) { n   sort(m.begin(), m.end()); n } n template <typename T1> n void reverse(vector<T1>& m) { n   reverse(m.begin(), m.end()); n } n long long mod = 1000000007; n long long fac[200005]; n long long inv_fac[200005]; n long long co(long long a, long long b) { n   long long ans = 1; n   ans *= fac[b]; n   ans *= inv_fac[b - a]; n   ans %= mod; n   ans *= inv_fac[a]; n   return ans % mod; n } n void solve() { n   string a, b; n   cin >> a >> b; n   long long s1 = a.size(); n   long long s2 = b.size(); n   string ans; n   for (long long i = 1; i <= s1; i++) { n     for (long long j = 1; j <= s2; j++) { n       string cur =   ; n       for (long long k = 0; k < i; k++) cur += a[k]; n       for (long long k = 0; k < j; k++) cur += b[k]; n       if (i == 1 && i == j) n         ans = cur; n       else n         ans = min(ans, cur); n     } n   } n   cout << ans; n   return; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << fixed << setprecision(10); n   long long multitest = 0; n   long long tututu; n   tututu = 1; n   long long combinatorics = 0; n   if (combinatorics) { n     fac[1] = 1; n     fac[0] = 1; n     for (long long i = 2; i < 200005; i++) { n       fac[i] = fac[i - 1] * i; n       fac[i] %= mod; n     } n     for (long long i = 0; i < 200005; i++) { n       inv_fac[i] = inv(fac[i], mod); n     } n   } n   if (multitest) cin >> tututu; n   for (long long qwerty = 0; qwerty < tututu; qwerty++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long double n; n   cin >> n; n   long long m = sqrt(n); n   if (m * m == n) { n     cout << 2 * m; n   } else if ((long long)m * (long long)(m + 1) >= n) { n     cout << (long long)m + (long long)(m + 1); n   } else n     cout << (long long)2 * (long long)(m + 1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t, i, oo = 0, oz = 0, zo = 0, zz = 0; n   char s1[2000005], s2[2000005]; n   cin >> t; n   cin >> s1; n   cin >> s2; n   t = 2 * t; n   for (i = 0; i < t; i++) { n     if (s1[i] ==  1  && s2[i] ==  1 ) n       oo++; n     else if (s1[i] ==  1  && s2[i] ==  0 ) n       oz++; n     else if (s1[i] ==  0  && s2[i] ==  1 ) n       zo++; n     else n       zz++; n   } n   if (oo % 2 == 0) { n     if (oz > zo) n       cout <<  First ; n     else if (oz + 1 == zo || oz == zo) n       cout <<  Draw ; n     else n       cout <<  Second ; n   } else { n     if (oz >= zo) n       cout <<  First ; n     else if (oz + 1 == zo || oz + 2 == zo) n       cout <<  Draw ; n     else n       cout <<  Second ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, l, r, q; n map<pair<int, int>, int> vi; n int V[100005 << 2], ly[100005 << 2]; n void push_down(int o) { n   if (ly[o]) { n     ly[o << 1] |= ly[o]; n     ly[o << 1 | 1] |= ly[o]; n     V[o << 1] |= ly[o]; n     V[o << 1 | 1] |= ly[o]; n     ly[o] = 0; n   } n } n void push_up(int o) { V[o] = V[o << 1] & V[o << 1 | 1]; } n void ud(int o, int l, int r, int L, int R, int x) { n   int mid = (l + r) / 2; n   if (L <= l && r <= R) { n     V[o] |= x; n     ly[o] |= x; n     return; n   } n   push_down(o); n   if (L <= mid) ud(o << 1, l, mid, L, R, x); n   if (R > mid) ud(o << 1 | 1, mid + 1, r, L, R, x); n   push_up(o); n } n int qy(int o, int l, int r, int L, int R) { n   int mid = (l + r) / 2; n   if (L <= l && r <= R) return V[o]; n   push_down(o); n   int ans = (1 << 30) - 1; n   if (L <= mid) ans &= qy(o << 1, l, mid, L, R); n   if (R > mid) ans &= qy(o << 1 | 1, mid + 1, r, L, R); n   push_up(o); n   return ans; n } n int main() { n   cin >> n >> m; n   int ok = 1; n   for (int i = 0; i < m; i++) { n     scanf( %d%d%d , &l, &r, &q); n     int tp = qy(1, 1, n, l, r); n     if (vi[make_pair(l, r)]) { n       if (tp != q) { n         ok = 0; n       } n     } n     if (!ok) continue; n     vi[make_pair(l, r)] = 1; n     if ((tp & q) == tp) n       ud(1, 1, n, l, r, q); n     else n       ok = 0; n   } n   if (!ok) { n     puts( NO ); n     return 0; n   } n   printf( YES n ); n   for (int i = 1; i <= n; i++) printf( %d  , qy(1, 1, n, i, i)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   if (n == 1) n     cout << m; n   else if (n - m > m - 1 && n - m != 0) n     cout << m + 1; n   else n     cout << m - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int main() { n   list<int> a; n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     a.push_back(x); n   } n   for (auto t = a.begin(); t != a.end(); t++) { n     auto s = t; n     s--; n     if (t == a.begin()) continue; n     while (true) { n       if (*t == *s) { n         *t = *t + 1; n         t = a.erase(s); n         if (t == a.begin()) break; n         s = t, s--; n       } else n         break; n     } n   } n   printf( %d n , a.size()); n   for (auto t : a) printf( %d  , t); n   return 0; n } n