#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   void qr(int &x) { scanf( %d , &x); }   int n, sz[N], f[N], root, c[N];   long long k, mn, mx;   struct edge {     int y, next;   } a[N * 2];   int len, last[N];   void ins(int x, int y) {     a[++len] = (edge){y, last[x]};     last[x] = len;   }   void dfs1(int x, int fa) {     sz[x] = f[x] = 1;     for (int k = last[x], y; k; k = a[k].next) {       y = a[k].y;       if (y ^ fa) {         dfs1(y, x);         sz[x] += sz[y];         mn += sz[y] & 1;         mx += min(sz[y], n - sz[y]);         f[x] = max(f[x], sz[y]);       }     }     f[x] = max(f[x], n - sz[x]);   }   void dfs2(int x, int fa) {     sz[x] = 1;     for (int k = last[x], y; k; k = a[k].next) {       y = a[k].y;       if (y ^ fa) {         dfs2(y, x);         sz[x] += sz[y];       }     }     c[sz[x]]++;   }   vector<int> d[N];   int son[N], tot, A[N], B[N];   void dfs3(int x, int fa) {     sz[x] = 1;     for (int k = last[x], y; k; k = a[k].next)       if ((y = a[k].y) ^ fa) dfs3(y, x), sz[x] += c[y];     int C = (sz[x] - c[x]) >> 1, st = 1, ed;     son[tot = 1] = x;     d[x].push_back(x);     for (int k = last[x], y; k; k = a[k].next)       if ((y = a[k].y) ^ fa) son[++tot] = y;     ed = tot;     for (int i = 1; i <= C; i++) {       while (d[son[st]].empty()) st++;       A[i] = d[son[st]].back();       d[son[st]].pop_back();       while (d[son[ed]].empty()) ed--;       B[i] = d[son[ed]].back();       d[son[ed]].pop_back();     }     for (int i = 1; i <= C; i++) printf( %d %d n , A[i], B[C - i + 1]);     for (int i = 2; i <= tot; i++) {       if (d[son[i]].size() > d[x].size()) swap(d[x], d[son[i]]);       for (int j : d[son[i]]) d[x].push_back(j);     }   }   int main() {     qr(n);     scanf( %lld , &k);     for (int i = 1, x, y; i < n; i++) qr(x), qr(y), ins(x, y), ins(y, x);     dfs1(1, 0);     if (!(mn <= k && k <= mx) || (k - mn) % 2 == 1) puts( NO ), exit(0);     root = 1;     for (int i = 2; i <= n; i++)       if (f[i] < f[root]) root = i;     dfs2(root, 0);     int p = n - 1;     for (; p > 1; p--)       if (mx - c[p] * 2 >= k) {         mx -= c[p] * 2;         c[p - 2] += c[p];       } else         break;     for (int i = 1; i <= n; i++) c[i] = min(sz[i], p - (p + sz[i]) % 2);     c[root] = 0;     for (int i = 1; i <= n; i++)       if (c[i] == p && mx > k) {         mx -= 2;         c[i] -= 2;       }     puts( YES );     dfs3(root, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 111111;   const int INF = 0x3f3f3f3f;   int vis[maxn];   bool selected[maxn];   int n, m;   vector<int> adj[maxn];   bool test[maxn];   double elapsed() { return clock() / (double)CLOCKS_PER_SEC; }   bool dfs(int v) {     if (selected[v] == true) return false;     vis[v] = -1;     for (auto w : adj[v]) {       if (vis[w] == 0) {         if (dfs(w)) return true;       } else if (vis[w] == -1) {         for (int i = 1; i <= n; i++) {           if (vis[i] != -1) test[i] = true;         }         return true;       }     }     vis[v] = 1;     return false;   }   bool check() {     memset(vis, 0, sizeof vis);     for (int i = 1; i <= n; i++) {       if (!vis[i] && dfs(i)) return false;     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);     }     vector<int> emp;     for (int i = 0; i < n; ++i) emp.push_back(i + 1);     random_shuffle(emp.begin(), emp.end());     for (int i = 0; elapsed() <= 0.95 and i < emp.size(); i++) {       selected[emp[i]] = true;       if (!test[emp[i]] && check()) {         printf( %d n , emp[i]);         return 0;       }       selected[emp[i]] = false;     }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   inline int gi() {     char c;     int num = 0, flg = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flg = -1;     while (c >=  0  && c <=  9 ) {       num = num * 10 + c - 48;       c = getchar();     }     return num * flg;   }   int n, m;   int fir[200005], cur[200005], to[5000005], nxt[5000005], cap[5000005],       id[2 * 200005], cnt;   void adde(int a, int b, int c, int d = 0) {     to[++cnt] = b;     nxt[cnt] = fir[a];     fir[a] = cnt;     cap[cnt] = c;     if (d) id[cnt] = d;     to[++cnt] = a;     nxt[cnt] = fir[b];     fir[b] = cnt;     cap[cnt] = 0;     if (d) id[cnt] = d;   }   int fa[200005], son[200005], sonp[200005], siz[200005], top[200005],       dep[200005];   void dfs1(int u) {     dep[u] = dep[fa[u]] + 1;     siz[u] = 1;     for (int v, p = fir[u]; p; p = nxt[p]) {       if ((v = to[p]) != fa[u]) {         fa[v] = u;         dfs1(v);         siz[u] += siz[v];         if (siz[son[u]] < siz[v]) son[u] = v, sonp[u] = p;       }     }   }   int pos[200005], dc, dfn[200005];   void dfs2(int u, int fro) {     pos[u] = ++dc;     dfn[dc] = id[fro];     if (son[u]) top[son[u]] = top[u], dfs2(son[u], sonp[u]);     for (int v, p = fir[u]; p; p = nxt[p])       if ((v = to[p]) != fa[u] && v != son[u]) top[v] = v, dfs2(v, p);   }   int S, T, sz;   const int INF = 0x3f3f3f3f;   struct node {     int l, r;   } a[200005];   int rt;   void build(int &i, int l, int r) {     if (l == r) {       i = dfn[l];       return;     }     i = ++sz;     int mid = (l + r) >> 1;     build(a[i].l, l, mid);     build(a[i].r, mid + 1, r);     adde(i, a[i].l, INF);     adde(i, a[i].r, INF);   }   void insert(int i, int l, int r, int ql, int qr, int p) {     if (l > qr || r < ql) return;     if (ql <= l && r <= qr) {       adde(p, i, INF);       return;     }     int mid = (l + r) >> 1;     insert(a[i].l, l, mid, ql, qr, p);     insert(a[i].r, mid + 1, r, ql, qr, p);   }   void QP(int x, int y, int p) {     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       insert(rt, 1, n, pos[top[x]], pos[x], p);       x = fa[top[x]];     }     if (dep[x] > dep[y]) swap(x, y);     insert(rt, 1, n, pos[x] + 1, pos[y], p);   }   queue<int> q;   int dis[200005];   bool bfs() {     for (int i = 1; i <= sz; i++) dis[i] = -1;     q.push(T);     dis[T] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v, p = fir[u]; p; p = nxt[p]) {         v = to[p];         if (cap[p ^ 1] > 0 && dis[v] == -1) {           dis[v] = dis[u] + 1;           q.push(v);         }       }     }     return dis[S] != -1;   }   int sap(int u, int aug) {     if (u == T) return aug;     int tmp, ret = 0;     for (int v, &p = cur[u]; p; p = nxt[p]) {       v = to[p];       if (cap[p] > 0 && dis[u] == dis[v] + 1) {         tmp = sap(v, min(cap[p], aug));         cap[p] -= tmp;         aug -= tmp;         cap[p ^ 1] += tmp;         ret += tmp;         if (!aug) break;       }     }     return ret;   }   int flow;   void maxflow() {     flow = 0;     while (bfs()) {       for (int i = 1; i <= sz; i++) cur[i] = fir[i];       flow += sap(S, INF);     }   }   int main() {     int i, u, v;     n = gi();     m = gi();     for (i = 1; i < n; i++) {       u = gi();       v = gi();       adde(u, v, 0, i);     }     dfs1(1);     top[1] = 1;     dfs2(1, 0);     memset(fir, 0, sizeof(fir));     cnt = 1;     sz = n;     build(rt, 1, n);     for (i = 1; i <= m; i++) {       u = gi();       v = gi();       QP(u, v, sz + i);     }     S = sz + m + 1;     T = sz + m + 2;     int tot = sz;     for (i = 1; i < n; i++) adde(i, T, 1);     for (i = 1; i <= m; i++) adde(S, sz + i, 1);     sz = T;     maxflow();     printf( %d n , flow);     int cnt1 = 0, cnt2 = 0;     for (i = 1; i <= m; i++)       if (dis[tot + i] != -1) cnt1++;     for (i = 1; i < n; i++)       if (dis[i] == -1) cnt2++;     printf( %d , cnt1);     for (i = 1; i <= m; i++)       if (dis[tot + i] != -1) printf(  %d , i);     printf(  n );     printf( %d , cnt2);     for (i = 1; i < n; i++)       if (dis[i] == -1) printf(  %d , i);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   long long a[212345], sumi, wow, i;   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       sumi += a[i];     }     wow = 0;     for (i = 0; i < n; i++) {       wow += a[i];       if (2 * wow >= sumi) break;     }     cout << i + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9, maxn = (int)1e5 + 1;   const double eps = (double)1e-8;   const int mod = (int)1000000009;   int n, a[1001], x, y, xx, yy, z, my, mx;   vector<pair<int, bool> > b[3000];   string c, st;   int main() {     my = 1500;     z = 1500;     cin >> n;     x = 0;     y = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       xx = x;       yy = y;       x += a[i];       if (i & 1) {         y += a[i];         for (int j = yy; j < y; j++)           b[z + j].push_back(make_pair(xx + j - yy, 1));       } else {         y -= a[i];         for (int j = yy - 1; j >= y; j--)           b[z + j].push_back(make_pair(xx + (yy - j - 1), 0));       }       my = max(my, y + z);     }     st =   ;     for (int i = 0; i < x; i++) st +=    ;     mx = x;     for (int i = my - 1;; i--) {       c = st;       if (b[i].size() == 0) break;       for (int j = 0; j < b[i].size(); j++) {         if (b[i][j].second)           c[b[i][j].first] =  / ;         else           c[b[i][j].first] = char(92);       }       cout << c << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int H, M, N;   set<int> a[200005];   int p[200005], seq[200005], r = 0;   int u[200005];   map<int, pair<int, int> > history;   void release(pair<int, int> P) { a[P.first].insert(P.second); }   int main(void) {     scanf( %d%d%d , &H, &M, &N);     for (int i = 0; i < H; i++) {       if (!u[i]) {         for (int c = 0, j = i; !u[j]; j = (j + M) % H, ++c) {           p[j] = r;           seq[j] = c;           a[r].insert(c);           u[j] = 1;         }         ++r;       }     }     long long ans = 0;     while (N--) {       char x[10];       int id, hash;       scanf( %s%d , x, &id);       if (x[0] ==  - )         release(history[id]);       else {         scanf( %d , &hash);         hash %= H;         int A = p[hash], B = seq[hash];         set<int>::iterator it = a[A].lower_bound(B);         if (it == a[A].end()) {           it = a[A].begin();           ans += *it + H / r - B;         } else {           ans += *it - B;         }         history[id] = make_pair(A, *it);         a[A].erase(it);       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     int n;     cin >> n;     int graph[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         graph[i][j] = INF;       }     }     for (int i = 0; i < n - 1; i++) {       int a, b, c;       cin >> a >> b >> c;       graph[a][b] = graph[b][a] = c;     }     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (graph[i][j] >= graph[i][k] + graph[k][j]) {             graph[i][j] = graph[i][k] + graph[k][j];           }         }       }     }     int ans = 0;     for (int i = 1; i < n; i++) {       if (graph[0][i] != INF) ans = max(ans, graph[0][i]);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 300333, inf = 1011111111;   int n, m, a[max_n], used[max_n], pos, lb[max_n];   vector<int> g2[max_n], num2[max_n], g[max_n], num[max_n], k, ans;   void dfs(int v) {     used[v] = 1;     for (int i = 0; i < g2[v].size(); ++i) {       if (used[g2[v][i]] == 0) {         g[v].push_back(g2[v][i]);         num[v].push_back(num2[v][i]);         dfs(g2[v][i]);       }     }   }   void dfs2(int v) {     for (int i = 0; i < g[v].size(); ++i) {       dfs2(g[v][i]);       lb[v] ^= lb[g[v][i]];       if (lb[g[v][i]]) {         ans.push_back(num[v][i]);       }     }   }   int main() {     scanf( %d%d , &n, &m);     pos = -1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i] == -1) {         pos = i;       }       if (a[i] == 1) {         k.push_back(i);       }     }     if (pos == -1 && k.size() % 2 != 0) {       printf( -1 n );       return 0;     }     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       g2[u].push_back(v);       g2[v].push_back(u);       num2[u].push_back(i);       num2[v].push_back(i);     }     dfs(1);     for (int i = 0; i + 1 < k.size(); i += 2) {       lb[k[i]] = 1;       lb[k[i + 1]] = 1;     }     if (k.size() % 2) {       lb[pos] = 1;       lb[k.back()] = 1;     }     dfs2(1);     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       printf( %d n , ans[i] + 1);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005, INF = 1e18;   void solve() {     long long n, ans = 0, max = 0;     cin >> n;     ans = n / 2;     cout << ans <<   n ;     for (long long i = (long long)0; i < ans - 1; i++) {       cout <<  2  ;     }     if (n % 2 == 0)       cout << 2 <<   n ;     else       cout << 3 <<   n ;   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010, maxp = 1000010;   int x[maxn], dp[maxp][20], can[maxp], f[maxp];   int n, a, b;   inline void chkmax(int& a, int b) {     if (a < b) a = b;   }   inline void chkmin(int& a, int b) {     if (a > b) a = b;   }   int getmin(int l, int r) {     int b;     for (b = 0; l + (1 << b) < r - (1 << b) + 1; b++)       ;     return min(dp[l][b], dp[r - (1 << b) + 1][b]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &x[i]);     sort(x, x + n);     n = unique(x, x + n) - x;     scanf( %d %d , &a, &b);     swap(a, b);     for (int i = 0; i < n; i++) {       int st = a - a % x[i];       if (st != a) st += x[i];       while (st <= b) {         chkmax(can[st - a], x[i]);         st += x[i];       }     }     int length = b - a + 1;     memset(f, 0x3f, sizeof f);     dp[length - 1][0] = 0;     f[length - 1] = 0;     for (int i = length - 2; i >= 0; i--) {       int pos = min(length - 1, i + can[i] - 1);       if (can[i] > 1) chkmin(f[i], getmin(i + 1, pos) + 1);       chkmin(f[i], f[i + 1] + 1);       dp[i][0] = f[i];       for (int j = 1; i + (1 << j) <= length; j++)         dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);     }     printf( %d n , f[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[100000];   vector<int> rev_g[100000];   vector<int> post_order;   vector<bool> visited;   vector<int> scc;   void dfs1(int x) {     if (visited[x]) return;     visited[x] = true;     for (auto y : g[x]) dfs1(y);     post_order.push_back(x);   }   void dfs2(int x, int cc) {     if (visited[x]) return;     visited[x] = true;     scc[x] = cc;     for (auto y : rev_g[x]) dfs2(y, cc);   }   int Kosaraju() {     visited = vector<bool>(n, false);     for (int i = 0; i < n; i++) dfs1(i);     scc = vector<int>(n, -1);     visited = vector<bool>(n, false);     int cc = 0;     assert(post_order.size() == n);     reverse(post_order.begin(), post_order.end());     for (auto x : post_order)       if (scc[x] == -1) dfs2(x, cc++);     return cc;   }   set<int> par_scc[100000];   set<int> chi_scc[100000];   vector<int> scc_list[100000];   stack<int> source_scc;   int q = 0;   int pos = 0;   bool get_dir(int a, int b) {     q++;     printf( ? %d %d n , a + 1, b + 1);     fflush(stdout);     int res;     scanf( %d , &res);     if (res == 1) pos++;     return (res == 1);   }   int main() {     scanf( %d%d , &n, &m);     int v = -1, w;     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       g[a].push_back(b);       rev_g[b].push_back(a);     }     int ncc = Kosaraju();     for (int i = 0; i < n; i++)       for (auto j : g[i])         if (scc[i] != scc[j]) {           assert(scc[i] >= 0 && scc[j] >= 0 && scc[i] < n && scc[j] < n);           par_scc[scc[j]].insert(scc[i]);           chi_scc[scc[i]].insert(scc[j]);         }     for (int i = 0; i < n; i++) scc_list[scc[i]].push_back(i);     for (int i = 0; i < ncc; i++)       if (par_scc[i].empty()) source_scc.push(i);     int cur_scc = source_scc.top();     int cur_i = 0;     int cur_size = scc_list[cur_scc].size();     source_scc.pop();     int nxt_scc, nxt_i, nxt_size;     while (!source_scc.empty()) {       nxt_scc = source_scc.top();       nxt_i = 0;       nxt_size = scc_list[nxt_scc].size();       source_scc.pop();       while (cur_i < cur_size && nxt_i < nxt_size) {         if (!get_dir(scc_list[cur_scc][cur_i], scc_list[nxt_scc][nxt_i])) {           swap(cur_scc, nxt_scc);           swap(cur_i, nxt_i);           swap(cur_size, nxt_size);         }         nxt_i++;       }       assert(nxt_i == nxt_size);       for (auto x : chi_scc[nxt_scc]) {         par_scc[x].erase(nxt_scc);         if (par_scc[x].empty()) source_scc.push(x);       }     }     printf( ! %d n , scc_list[cur_scc][cur_i] + 1);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int query(int x, int y) {     cout <<  1   << x <<     << y << endl;     string ans;     cin >> ans;     if (ans ==  TAK ) return 1;     return 0;   }   int find(int l, int r) {     if (l > r) return -1;     int L = l;     int R = r;     while (L < R) {       int mid = (L + R) / 2;       if (query(mid, mid + 1))         R = mid;       else         L = mid + 1;     }     return L;   }   int main() {     cin >> n >> k;     int x = find(1, n);     int y = find(1, x - 1);     if (x == 1 || !query(y, x)) y = find(x + 1, n);     cout <<  2   << x <<     << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, s, t;   int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   int n1, n2, n3, p1, p2, p3, m1, m2, m3, st;   long long m, n, ans;   int st2[1010000], sta[1010000];   struct data {     int p, q;   };   bool cmp(const data &a, const data &b) { return a.p < b.p; }   struct da {     data a[50];     int n;   } a, b;   long long qpow(long long x, int y) {     long long ans = 1;     while (y) {       if (y & 1) ans *= x;       x *= x;       y >>= 1;     }     return ans;   }   void solve1(int x, long long y) {     if (y > n) return;     if (x == b.n + 1) {       ans++;       return;     }     solve1(x + 1, y);     for (int i = 1; i <= b.a[x].q; i++) y *= b.a[x].p, solve1(x + 1, y);   }   void solve2(int x, long long y, int f) {     if (!y) return;     if (x == st + 1) {       ans += y * f;       return;     }     solve2(x + 1, y, f);     for (int i = 1; i <= st2[x]; i++) y /= sta[x];     solve2(x + 1, y, -f);   }   void pre(da &a, int x) {     int i, j, k;     for (i = 1; i <= a.n; i++)       while (x % a.a[i].p == 0) x /= a.a[i].p, a.a[i].q++;     for (i = 2; i * i <= x; i++)       if (x % i == 0) {         a.n++;         a.a[a.n].p = i;         a.a[a.n].q = 0;         while (x % i == 0) x /= i, a.a[a.n].q++;       }     if (x > 1) {       a.n++;       a.a[a.n].p = x;       a.a[a.n].q = 1;     }   }   int main() {     int T = read();     while (T--) {       n1 = read();       n2 = read();       n3 = read();       n = (long long)n1 * n2 * n3;       m1 = read();       m2 = read();       m3 = read();       m = (long long)m1 * m2 * m3;       p1 = read();       p2 = read();       p3 = read();       a.n = 0;       b.n = 0;       ans = 0;       pre(a, n1);       pre(a, n2);       pre(a, n3);       pre(b, p1);       pre(b, p2);       pre(b, p3);       pre(b, 2);       sort(a.a + 1, a.a + a.n + 1, cmp);       sort(b.a + 1, b.a + b.n + 1, cmp);       solve1(1, 1);       j = 1;       st = 0;       for (i = 1; i <= a.n; i++) {         while (b.a[j].p < a.a[i].p && j <= b.n) j++;         if (j == b.n + 1) break;         if (b.a[j].p == a.a[i].p && a.a[i].q > b.a[j].q) {           sta[++st] = a.a[i].p;           st2[st] = b.a[j].q + 1;         }         if (b.a[j].p > a.a[i].p) {           sta[++st] = a.a[i].p;           st2[st] = 1;         }       }       for (; i <= a.n; i++) {         sta[++st] = a.a[i].p;         st2[st] = 1;       }       solve2(1, m, 1);       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int mod = 1e9 + 7;   struct edge {     int u, v, t, c, id;   } e[N];   int n, m;   vector<edge> s[N];   bool cmp(edge a, edge b) { return a.c < b.c; }   struct TwoSat {     static const int N = ::N << 1;     int dfn[N], low[N], id[N], st[N], _st, _, cc;     vector<int> g[N];     int mark[N], n;     void init(int _n) {       for (int i = ((n = _n << 1)) - 1; i >= (0); --i) g[i].clear();     }     int new_node() {       for (int i = (0); i < (2); i++) g[n++].clear();       return n / 2 - 1;     }     void addedge(int a, int va, int b, int vb) {       a = a << 1 | va;       b = b << 1 | vb;       g[a].push_back(b);       g[b ^ 1].push_back(a ^ 1);     }     void add_set(int a, int va) {       a = a << 1 | va;       g[a ^ 1].push_back(a);     }     void add_then(int a, int va, int b, int vb) { addedge(a, va, b, vb ^ 1); }     void add_or(int a, int va, int b, int vb) { addedge(a, va ^ 1, b, vb); }     void add_xor(int a, int va, int b, int vb) {       addedge(a, va, b, vb);       addedge(b, vb, a, va);     }     void dfs(int c, vector<int> g[]) {       dfn[c] = low[c] = ++cc;       st[_st++] = c;       for (auto t : g[c])         if (!dfn[t])           dfs(t, g), low[c] = min(low[c], low[t]);         else if (!id[t])           low[c] = min(low[c], dfn[t]);       if (low[c] == dfn[c]) {         ++_;         do {           id[st[--_st]] = _;         } while (st[_st] != c);       }     }     void find() {       fill_n(dfn, n, cc = 0);       fill_n(low, n, _st = 0);       fill_n(id, n, _ = 0);       for (int i = (0); i < (n); i++)         if (!dfn[i]) dfs(i, g);       for (int i = (0); i < (n); i++) --id[i];       return;     }     bool solve() {       find();       for (int i = 0; i < n; i += 2) {         if (id[i] == id[i + 1]) return 0;         mark[i >> 1] = (id[i] > id[i + 1]);       }       return 1;     }   } ts;   int p = 0;   void solve(int u) {     sort(s[u].begin(), s[u].end(), cmp);     for (int i = 0, j; i < (int)s[u].size();) {       j = i;       while (j < (int)s[u].size() && s[u][j].c == s[u][i].c) j++;       if (j - i >= 3) {         cout <<  No n ;         exit(0);       }       if (j - i == 2) {         int x = s[u][i].id, y = s[u][i + 1].id;         ts.add_or(x, 0, y, 0);       }       i = j;     }     for (int i = (0); i < ((int)s[u].size() - 1); i++) {       ts.addedge(p + i + 1, 0, p + i, 0);     }     for (int i = (0); i < ((int)s[u].size()); i++) {       int x = s[u][i].id;       ts.addedge(x, 0, p + i, 0);       if (i != (int)s[u].size() - 1) ts.addedge(x, 0, p + i + 1, 1);     }   }   void link() {     p = m;     for (int i = (1); i < (n + 1); i++) {       solve(i);       p += (int)s[i].size();     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int L = 0, R = 0;     for (int i = (1); i < (m + 1); i++) {       cin >> e[i].u >> e[i].v >> e[i].c >> e[i].t;       e[i].id = i - 1;       R = max(R, e[i].t);       s[e[i].u].push_back(e[i]);       s[e[i].v].push_back(e[i]);     }     int ans = -1;     while (L <= R) {       int mid = (L + R) / 2;       ts.init(3 * m);       link();       for (int i = (1); i < (m + 1); i++)         if (e[i].t > mid) {           ts.add_set(e[i].id, 1);         }       if (ts.solve()) {         ans = mid;         R = mid - 1;       } else         L = mid + 1;     }     if (ans == -1)       cout <<  No ;     else {       ts.init(3 * m);       link();       for (int i = (1); i < (m + 1); i++)         if (e[i].t > ans) ts.add_set(e[i].id, 1);       ts.solve();       cout <<  Yes n ;       vector<int> task;       for (int i = 0; i < m; ++i)         if (!ts.mark[i]) task.push_back(i + 1);       cout << ans <<     << (int)task.size() <<   n ;       for (auto v : task) cout << v <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   const long long MOD = 1000000007;   long long n, k;   long long pre[MAXN], suf[MAXN], fac[MAXN], ifac[MAXN];   inline long long quick_pow(long long x, long long k) {     long long res = 1;     while (k) {       if (k & 1) (res *= x) %= MOD;       (x *= x) %= MOD;       k >>= 1;     }     return res;   }   inline void init() {     pre[0] = suf[k + 3] = fac[0] = 1;     for (int i = 1; i <= k + 2; i++) pre[i] = pre[i - 1] * (n - i) % MOD;     for (int i = k + 2; i >= 1; i--) suf[i] = suf[i + 1] * (n - i) % MOD;     for (int i = 1; i <= k + 2; i++) fac[i] = fac[i - 1] * i % MOD;     ifac[k + 2] = quick_pow(fac[k + 2], MOD - 2);     for (int i = k + 2 - 1; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1) % MOD;   }   inline long long calc(int i, long long tmp) {     return ((k - i) & 1 ? -1 : 1) * pre[i - 1] * suf[i + 1] % MOD * ifac[i - 1] %            MOD * ifac[k + 2 - i] % MOD * tmp % MOD;   }   int main() {     cin >> n >> k;     init();     long long ans = 0, tmp = 0;     for (int i = 1; i <= k + 2; i++) {       (tmp += quick_pow(i, k)) %= MOD;       (ans += calc(i, tmp) % MOD) %= MOD;     }     cout << (ans + MOD) % MOD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string st;   double ans = 0.0, curr = 0.0;   int flag = 0;   int main() {     cin >> st;     for (int i = 0; i < st.size(); i++) {       if ( a  <= st[i] && st[i] <=  z ) {         ans += curr;         curr = 0.0;         continue;       }       if (st[i] ==  . ) {         if (i + 3 < st.size() &&  0  <= st[i + 3] && st[i + 3] <=  9 ) {           curr = curr * 1000 + st[i + 1] * 100 + st[i + 2] * 10 + st[i + 3] -                  48 * 111;           i += 3;           continue;         }         curr += (st[i + 1] * 10 + st[i + 2] - 48 * 11) / 100.0;         i += 2;         continue;       }       curr = curr * 10 + st[i] - 48;     }     ans += curr;     string s = to_string(ans);     s.erase(s.end() - 4, s.end());     int n = s.size();     stack<char> S;     if (s[n - 1] !=  0  || s[n - 2] !=  0 )       S.push(s[n - 1]), S.push(s[n - 2]), S.push( . );     for (int i = n - 4, j = 1; i >= 0; i--, j++) {       S.push(s[i]);       if (j % 3 == 0 && i) S.push( . );     }     while (!S.empty()) cout << S.top(), S.pop();     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10, MAXM = 1e6 + 10;   const int INF = INT_MAX, SINF = 0x3f3f3f3f;   const long long llINF = LLONG_MAX;   const int MOD = 1e9 + 7, mod = 998244353;   const int inv2 = 5e8 + 4;   long double x, y, z;   long double a[MAXN];   string s[MAXN];   int main() {     cin >> x >> y >> z;     a[1] = powl(y, z) * log(x);     a[2] = powl(z, y) * log(x);     a[3] = z * y * log(x);     a[4] = z * y * log(x);     a[5] = powl(x, z) * log(y);     a[6] = powl(z, x) * log(y);     a[7] = z * x * log(y);     a[8] = z * x * log(y);     a[9] = powl(x, y) * log(z);     a[10] = powl(y, x) * log(z);     a[11] = x * y * log(z);     a[12] = x * y * log(z);     int cnt = max_element(a + 1, a + 13) - a;     s[1] =  x^y^z ;     s[2] =  x^z^y ;     s[3] =  (x^y)^z ;     s[4] =  (x^z)^y ;     s[5] =  y^x^z ;     s[6] =  y^z^x ;     s[7] =  (y^x)^z ;     s[8] =  (y^z)^x ;     s[9] =  z^x^y ;     s[10] =  z^y^x ;     s[11] =  (z^x)^y ;     s[12] =  (z^y)^x ;     cout << s[cnt];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int sum(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }   int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }   int mul(int a, int b) { return (1LL * a * b) % MOD; }   const int MAXN = 1e6 + 7;   int shuru[MAXN], shesh[MAXN];   int zero[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.size();     int zerosum = 1;     int sheshsum = 0;     int z = 0;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  0 ) {         z++;         if (i + z == n) zerosum = sum(zerosum, 1);         zerosum = sub(zerosum, zero[z]);         zero[z] = shuru[i + z];         zerosum = sum(zerosum, zero[z]);       } else {         z = 0;         shesh[i] = zerosum;         sheshsum = sum(sheshsum, shesh[i]);         shuru[i] = sheshsum;       }     }     if (z == n) {       cout << n <<   n ;     } else {       cout << mul(z + 1, shuru[z]) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5E4 + 5;   const int M = N * 17 * 17;   int n, m, q, x, y, son[N], dep[N], fa[N], g[N], l[N], tot, f[N], mark[M], to[N],       ch[M][2], sum, c[N], a[N], k, b[N];   long long ans[N], tr[M], C;   vector<int> G[N];   int dfs(int x) {     int y;     son[x] = 1;     dep[x] = dep[fa[x]] + 1;     for (int i = 0; i < G[x].size(); i++) {       son[x] += dfs(y = G[x][i]);       if (son[y] > son[g[x]]) g[x] = y;     }     return son[x];   }   void dfs2(int x, int pre) {     l[x] = ++tot;     b[tot] = x;     f[x] = pre + 1;     if (g[x]) dfs2(g[x], pre);     for (int i = 0; i < G[x].size(); i++)       if (G[x][i] != g[x]) dfs2(G[x][i], tot);   }   void push_down(int p, int l, int mid, int r, int &lc, int &rc) {     if (!mark[p]) return;     if (!lc) lc = ++sum;     if (!rc) rc = ++sum;     tr[lc] += (long long)mark[p] * (mid - l + 1), mark[lc] += mark[p];     tr[rc] += (long long)mark[p] * (r - mid), mark[rc] += mark[p];     mark[p] = 0;   }   long long get(int &p, int l, int r, int x, int y, int k) {     if (x > r || y < l) return 0;     if (!p) p = ++sum;     if (x <= l && y >= r) {       int len = r - l + 1;       tr[p] += k * len;       mark[p] += k;       return tr[p] - k * len;     }     int mid = (l + r) / 2;     push_down(p, l, mid, r, ch[p][0], ch[p][1]);     long long ans =         get(ch[p][0], l, mid, x, y, k) + get(ch[p][1], mid + 1, r, x, y, k);     tr[p] = tr[ch[p][0]] + tr[ch[p][1]];     return ans;   }   void work(int x, int v, int k) {     ans[v] += (long long)c[v] * c[v] * dep[x];     for (; x;) {       ans[v] += 2ll * k *                 (get(to[v], 1, n, f[x], l[x], k) * c[v] -                  C * (dep[x] - dep[fa[b[f[x]]]])) *                 c[v];       x = fa[b[f[x]]];     }   }   int main() {     cin >> n >> m >> q >> C;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) ans[i] = C * C * n;     for (int i = 2; i <= n; i++) {       scanf( %d , &fa[i]);       G[fa[i]].push_back(i);     }     for (int i = 1; i <= m; i++) scanf( %d , &c[i]);     dfs(1);     dfs2(1, 0);     for (int i = 1; i <= n; i++) work(i, a[i], 1);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &k, &x);       if (k == 1) {         scanf( %d , &y);         work(x, a[x], -1);         work(x, y, 1);         a[x] = y;       } else         printf( %.6f n , (double)ans[x] / n);     }   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 50010;   const int INF = 0x3f3f3f3f;   const int MOD = 100000, STA = 8000010;   const long long LNF = 1LL << 60;   const double EPS = 1e-8;   const double OO = 1e15;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   const int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   inline int sign(double x) { return (x > EPS) - (x < -EPS); }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   inline T lcm(T a, T b, T d) {     return a / d * b;   }   template <class T>   inline T Min(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T Max(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T Min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T Max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T Min(T a, T b, T c, T d) {     return min(min(a, b), min(c, d));   }   template <class T>   inline T Max(T a, T b, T c, T d) {     return max(max(a, b), max(c, d));   }   int N, M, T;   int n, m, x, t, w, h;   map<int, deque<int> > Q;   struct TT {     int g, p, t, id;   } E[101111];   int tp[101111], a[101111], b[101111];   bool cp(TT a, TT b) { return a.p < b.p; }   void init(int x, int now) {     for (int i = 1; i <= n; i++) {       if (E[i].g == x) Q[E[i].t - E[i].p].push_back(i);     }     for (int i = 1; i <= n; i++)       if (E[i].g != x) {         auto p = Q.find(E[i].t - E[i].p);         if (p == Q.end() || p->second.empty()) {           tp[i] = i;         } else {           tp[i] = p->second.back();           p->second.pop_back();           p->second.push_front(i);         }       }     Q.clear();   }   int main() {     scanf( %d%d%d , &n, &w, &h);     int g, p, t;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &E[i].g, &E[i].p, &E[i].t);       E[i].id = i;     }     sort(E + 1, E + n + 1, cp);     init(1, 2);     init(2, 1);     for (int i = 1; i <= n; i++) {       if (E[i].g == 1) {         a[E[tp[i]].id] = E[i].p;         b[E[tp[i]].id] = h;       } else {         a[E[tp[i]].id] = w;         b[E[tp[i]].id] = E[i].p;       }     }     for (int i = 1; i <= n; i++) {       printf( %d %d n , a[i], b[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     ;     int n, k;     cin >> n >> k;     while (n > 0 && k > 0) {       k--;       if (n % 10 == 0)         n = n / 10;       else         n--;     }     cout << n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[200005], tree[200005];   void update(int pos, long long v) {     for (; pos < 200005; pos += pos & -pos) tree[pos] += v;   }   long long read(int pos) {     long long ret = 0;     for (; pos; pos -= pos & -pos) ret += tree[pos];     return ret;   }   int main() {     ios::sync_with_stdio(false);     cout.setf(ios::fixed);     cout.precision(10);     int i, size = 1, t, n, lo, hi;     long long x, sum = 0, a;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> t;       if (t == 1) {         cin >> a >> x;         lo = 1, hi = min((long long)size, a);         update(lo, x);         update(hi + 1, -x);         sum += hi * x;       } else {         if (t == 2) {           cin >> x;           update(size + 1, x);           update(size + 2, -x);           size++;           sum += x;         } else {           if (size >= 2) {             long long val = read(size);             update(size, -val);             update(size + 1, val);             size--;             sum -= val;           }         }       }       cout << (sum * 1.0 / size) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> sg;   map<int, bool> us;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x, d;       cin >> x >> d;       sg[x] = x + d;       us[x] = true;       if (us[x + d] && sg[x + d] == x && sg[x] == x + d) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int v = 0;     map<int, int> s;     for (int i = 19; s.size() < 10010; i += 9) {       int kk = i;       int c = 0;       while (kk > 0) {         c += kk % 10;         kk /= 10;       }       if (c == 10) s[v++] = i;     }     cout << s[n - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int le, ri, cnt;     data(int le_ = 0, int ri_ = 0, int cnt_ = 0) {       le = le_;       ri = ri_;       cnt = cnt_;     }   };   const int N = 1e6 + 10;   int seg[4 * N + 10];   int brk[5][4 * N + 10];   int n;   void add(int idx, bool b, int L = 0, int R = n, int id = 1) {     if (L == R - 1) {       brk[b][id]++;       return;     }     int mid = (L + R) / 2;     if (idx < mid)       add(idx, b, L, mid, 2 * id + 0);     else       add(idx, b, mid, R, 2 * id + 1);     seg[id] = seg[2 * id + 0] + seg[2 * id + 1] +               min(brk[0][2 * id + 0], brk[1][2 * id + 1]);     brk[0][id] =         brk[0][2 * id + 1] + max(0, brk[0][2 * id + 0] - brk[1][2 * id + 1]);     brk[1][id] =         brk[1][2 * id + 0] + max(0, brk[1][2 * id + 1] - brk[0][2 * id + 0]);     return;   }   data get(int l, int r, int L = 0, int R = n, int id = 1) {     if (L == l && R == r) return data(brk[0][id], brk[1][id], seg[id]);     int mid = (L + R) / 2;     data le, ri;     if (l < mid) le = get(l, min(r, mid), L, mid, 2 * id + 0);     if (r > mid) ri = get(max(l, mid), r, mid, R, 2 * id + 1);     data ret;     ret.cnt = le.cnt + ri.cnt + min(le.le, ri.ri);     ret.le = ri.le + max(0, le.le - ri.ri);     ret.ri = le.ri + max(0, ri.ri - le.le);     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     string s;     cin >> s, n = s.size();     for (int i = 0; i < s.size(); i++)       if (s[i] ==  ( )         add(i, 0);       else         add(i, 1);     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r, l--;       cout << 2 * get(l, r).cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[1 << 10], M = 1000000;   long long l, r, k;   class Matrix {    public:     long long a[3][3];     Matrix(int fib = 0) {       memset(a, 0, sizeof(a));       if (fib) a[1][2] = a[2][1] = a[2][2] = 1;     }     Matrix operator*(const Matrix &v) {       Matrix ret;       for (int i = 1; i <= 2; ++i)         for (int j = 1; j <= 2; ++j)           for (int k = 1; k <= 2; ++k)             ret.a[i][k] = (ret.a[i][k] + a[i][j] * v.a[j][k]) % M;       return ret;     }     void print() { cout << a[1][2] % M << endl; }   };   Matrix one(1);   long long solve(long long l, long long r, long long v) {     l = (l - 1) / v + 1;     r = r / v;     return r - l + 1;   }   Matrix fib(long long u) {     if (u == 1) return one;     Matrix cache = fib(u / 2);     cache = cache * cache;     if (u % 2) cache = cache * one;     return cache;   }   int main() {     cin >> M >> l >> r >> k;     long long ans = 1;     if (k >= 1000000) {       ans = (r - l + 1) / (k - 1) + 2;       while (solve(l, r, ans) < k) --ans;     } else {       for (int i = 1; i + k - 1 <= 1000000; ++i) {         long long tl = (l - 1) / i + 1, tr = r / (i + k - 1);         if (tl <= tr) ans = max(ans, tr);       }     }     fib(ans).print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return (a > b ? a : b); }   long long min(long long a, long long b) { return (a < b ? a : b); }   void algo() {     string s1, s2;     char c;     cin >> s1 >> s2;     long long j = 0, len = s1.size();     for (long long i = 0; i < len; i++) {       c = s1[i];       long long k = j;       if (s1[i + 1] == c && i != len - 1) {         if (c == s2[j])           j++;         else {           cout <<  NO ;           return;         }       } else {         while (c == s2[j]) {           j++;         }       }       if (k == j) {         cout <<  NO ;         return;       }     }     if (j != s2.size())       cout <<  NO ;     else       cout <<  YES ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       algo();       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double const EPS = 1.0E-9;   int const MOD = (int)1e9 + 7;   inline void read(char* s) { scanf( %s , s); }   inline void read(int& x) { scanf( %d , &(x)); }   inline void read(long long& x) { scanf( %lld , &x); }   inline void read(double& x) { scanf( %lf , &x); }   inline void writeln(int x) { printf( %d n , x); }   inline void writeln(long long x) { printf( %lld n , x); }   inline void writeln(double x) { printf( %.12f n , x); }   template <typename... T>   void read(T&... args) {     using swallow = int[];     swallow w = {0, (read(args), 0)...};   }   inline long long gcd(long long x, long long y) {     return y == 0 ? x : gcd(y, x % y);   }   inline long long lcm(long long x, long long y) {     return x == 0 && y == 0 ? 0 : x / gcd(x, y) * y;   }   inline long long powmod(long long x, long long n, long long m = MOD) {     long long r = 1;     while (n) {       if (n & 1) r = (r * x) % m;       x = (x * x) % m;       n /= 2;     }     return r;   }   static int leap(int y) { return y % 4 == 0 && y % 100 != 0 || y % 400 == 0; }   static int const month[2][12] = {       {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},       {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};   static const int N = 1 << 18;   static const int M = 1 << 20;   int freq[N];   int n, k;   int f[N];   int h[12];   int hw[5012][512];   static int solve() {     read(n, k);     for (int i = 1; i <= n * k; ++i) {       int a;       read(a);       freq[a]++;     }     for (int i = 1; i <= n; ++i) {       int x;       read(x);       f[x]++;     }     for (int i = 1; i <= k; ++i) {       read(h[i]);     }     for (int i = 0; i < 5012; ++i) {       for (int j = 0; j < 512; ++j) {         if (i == 0 || j == 0) {           hw[i][j] = 0;         } else {           hw[i][j] = 0;           for (int l = 0; l <= k && l <= i; ++l) {             hw[i][j] = std::max(hw[i][j], hw[i - l][j - 1] + h[l]);           }         }       }     }     long long ans = 0;     for (int i = (0), vzq_b = (N); i < vzq_b; ++i) {       int fa = f[i];       ans += hw[freq[i]][fa];     }     writeln(ans);     return 0;   }   int main(int argc, char* argv[]) {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   const int MAX_LENGTH = 100000 + 8;   const ull B = 100000007ULL;   char s[3][MAX_LENGTH];   ull H[3][MAX_LENGTH], B_to[MAX_LENGTH] = {1ULL};   int id[3] = {0, 1, 2}, len[3];   void init_hash() {     for (int i = 0; i < 3; ++i) {       for (int j = 1; j < len[i] + 1; ++j) {         H[i][j] = H[i][j - 1] * B + s[i][j];       }     }     int n = max(max(len[0], len[1]), len[2]);     for (int i = 1; i < n + 1; ++i) {       B_to[i] = B_to[i - 1] * B;     }   }   inline ull hash_of(ull *h, int b, int l) {     return h[b + l - 1] - h[b - 1] * B_to[l];   }   bool contain(int a, int b) {     if (len[a] < len[b]) return false;     ull bh = H[b][len[b]];     for (int i = 1; i + len[b] <= len[a]; ++i)       if (hash_of(H[a], i, len[b]) == bh) return true;     return false;   }   int overlap(int a, int b) {     int ans = 0;     for (int i = 1; i <= min(len[a], len[b]); ++i) {       if (hash_of(H[a], len[a] - i + 1, i) == hash_of(H[b], 1, i)) ans = i;     }     return ans;   }   int solve() {     int ans = MAX_LENGTH * 3;     for (int i = 0; i < 2; ++i) {       for (int j = i + 1; j < 3; ++j) {         if (contain(i, j) || contain(j, i)) {           int x = len[i] > len[j] ? i : j;           int y = 3 - i - j;           if (contain(x, y) || contain(y, x)) return max(len[x], len[y]);           return len[x] + len[y] - max(overlap(x, y), overlap(y, x));         }       }     }     do       ans = min(ans, len[0] + len[1] + len[2] - overlap(id[0], id[1]) -                          overlap(id[1], id[2]));     while (next_permutation(id, id + 3));     return ans;   }   int main() {     for (int i = 0; i < 3; ++i) {       gets(s[i] + 1);       len[i] = strlen(s[i] + 1);     }     init_hash();     printf( %d n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a < b) swap(a, b);     if (b == 0) return a;     while (b) {       long long int re = a % b;       a = b;       b = re;     }     return a;   }   vector<int> a[1000 + 10], b[1000 + 10];   vector<int> c1(1000 + 10, 0), c2(1000 + 10, 0);   void dfs(int i, int k, int p) {     if (p)       c1[i] = k;     else       c2[i] = k;     if (p) {       for (int j : a[i]) {         if (c1[j] == 0) dfs(j, k, p);       }     } else {       for (int j : b[i]) {         if (c2[j] == 0) dfs(j, k, p);       }     }   }   int main() {     int n, m1, m2;     cin >> n >> m1 >> m2;     for (int i = 0; i < m1; i++) {       int u, v;       cin >> u >> v;       a[u].push_back(v);       a[v].push_back(u);     }     for (int i = 0; i < m2; i++) {       int u, v;       cin >> u >> v;       b[u].push_back(v);       b[v].push_back(u);     }     int k = 1;     for (int i = 1; i < n + 1; i++) {       if (c1[i] == 0) {         dfs(i, k, 1);         k++;       }     }     k = 1;     vector<pair<long long int, long long int> > ans;     for (int i = 1; i < n + 1; i++) {       if (c2[i] == 0) {         dfs(i, k, 0);         k++;       }     }     map<int, int> mp1, mp2;     for (int i = 0; i < n + 1; i++) {       mp1[i] = i;       mp2[i] = i;     }     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < n + 1; j++) {         int cai = mp1[c1[i]], caj = mp1[c1[j]], cbi = mp2[c2[i]],             cbj = mp2[c2[j]];         if (cai != caj && cbi != cbj) {           ans.push_back({i, j});           mp1[c1[j]] = mp1[c1[i]] = -1;           mp2[c2[j]] = mp2[c2[i]] = -1;         }       }     }     cout << ans.size() << endl;     for (auto it : ans) cout << it.first <<     << it.second << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int val[maxn];   int sito[maxn];   int main() {     ios::sync_with_stdio(false);     for (int i = 0; i < maxn; i++) {       sito[i] = true;     }     vector<int> v;     sito[0] = sito[1] = false;     for (int i = 2; i < maxn; i++) {       if (sito[i]) {         v.push_back(i);         if (i < 1000) {           for (int j = i * i; j < maxn; j += i) {             sito[j] = false;           }         }       }     }     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> val[i];       val[i]--;     }     vector<pair<int, int> > ss;     for (int i = 0; i < n;) {       int pos = i;       if (pos == val[pos]) {         i++;         continue;       }       while (pos != val[pos]) {         int l = 0, r = v.size() - 1;         int best = 0;         while (l <= r) {           int mid = (l + r) / 2;           if (pos + v[mid] - 1 <= val[pos]) {             l = mid + 1;             best = max(best, v[mid] - 1);           } else {             r = mid - 1;           }         }         ss.push_back(make_pair(pos + 1, pos + best + 1));         swap(val[pos], val[pos + best]);         pos += best;       }     }     cout << ss.size() << endl;     for (int i = 0; i < ss.size(); i++) {       cout << ss[i].first <<     << ss[i].second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long sqr(long long x) { return x * x; }   bool done = false;   int p[8][3];   bool same(double x, double y) { return abs(x - y) < 1e-9; }   int cnt = 0;   void backtr(int idx) {     if (done) return;     if (idx == 7) {       cnt++;       map<long long, int> ck;       vector<long long> t(28), v(3, 1);       int idx = 0, idx2 = 0;       long long l1 = -1, l2 = -1, l3 = -1;       for (int i = 0; i < 8; ++i)         for (int j = i + 1; j < 8; ++j) {           t[idx++] = sqr(p[i][0] - p[j][0]) + sqr(p[i][1] - p[j][1]) +                      sqr(p[i][2] - p[j][2]);           if (!ck.count(t[idx - 1])) {             if (idx2 == 3) return;             v[idx2++] = t[idx - 1], ck[t[idx - 1]] = 1;           } else             ck[t[idx - 1]]++;         }       sort(v.begin(), v.end());       if (ck[v[0]] == 12 && ck[v[1]] == 12 && ck[v[2]] == 4 && 2 * v[0] == v[1] &&           v[0] + v[1] == v[2]) {         done = true;         printf( YES n );         for (int i = 0; i < 8; ++i)           printf( %d %d %d n , p[i][0], p[i][1], p[i][2]);       }     } else {       do {         backtr(idx + 1);         if (done) return;       } while (next_permutation(p[idx], p[idx] + 3));       sort(p[idx], p[idx] + 3);     }   }   int main() {     clock_t start_time, end_time;     start_time = clock();     for (int i = 0; i < 8; ++i)       scanf( %d%d%d , &p[i][0], &p[i][1], &p[i][2]), sort(p[i], p[i] + 3);     backtr(0);     if (!done) printf( NO );     end_time = clock();   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 30;   bool vis[N];   int id1 = -1, id2 = -1;   char ch;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     int n = 27;     for (int i = 0; i < 27; i++) {       if (vis[s[i] -  A ]) {         id2 = i;         ch = s[i];       } else {         vis[s[i] -  A ] = true;       }     }     for (int i = 0; i < 27; i++) {       if (s[i] == ch) {         id1 = i;         break;       }     }     if (id2 == id1 + 1) {       cout <<  Impossible n ;       return 0;     }     if ((id2 - id1 - 1) % 2 == 1) {       int cnt = id2 - id1 - 1;       int rast = cnt / 2, chap = n - id2 - 1;       if (rast + chap + 1 <= 13) {         int rem = 13 - rast - chap - 1;         for (int i = rem; i < id1; i++) cout << s[i];         for (int i = id1 + 1; i <= id1 + cnt / 2 + 1; i++) cout << s[i];         cout <<   n ;         for (int i = rem - 1; i >= 0; i--) cout << s[i];         for (int i = n - 1; i > id2; i--) cout << s[i];         cout << ch;         for (int i = id2 - 1; i >= id2 - cnt / 2; i--) cout << s[i];         cout <<   n ;       } else {         int rem = rast + chap + 1 - 13;         for (int i = 0; i < rem; i++) cout << s[n - rem + i];         for (int i = 0; i < id1; i++) cout << s[i];         for (int i = id1 + 1; i <= id1 + cnt / 2 + 1; i++) cout << s[i];         cout <<   n ;         for (int i = n - rem - 1; i > id2; i--) cout << s[i];         cout << ch;         for (int i = id2 - 1; i >= id2 - cnt / 2; i--) cout << s[i];       }     } else {       int cnt = id2 - id1 - 1;       int rast = cnt / 2, chap = n - id2 - 1;       if (rast + chap + 1 <= 13) {         int rem = 13 - rast - chap - 1;         for (int i = rem; i < id1; i++) cout << s[i];         for (int i = id1 + 1; i <= id1 + cnt / 2; i++) cout << s[i];         cout <<   n ;         for (int i = rem - 1; i >= 0; i--) cout << s[i];         for (int i = n - 1; i > id2; i--) cout << s[i];         cout << ch;         for (int i = id2 - 1; i >= id2 - cnt / 2; i--) cout << s[i];         cout <<   n ;       } else {         int rem = rast + chap + 1 - 13;         for (int i = 0; i < rem; i++) cout << s[n - rem + i];         for (int i = 0; i < id1; i++) cout << s[i];         for (int i = id1 + 1; i <= id1 + cnt / 2; i++) cout << s[i];         cout <<   n ;         for (int i = n - rem - 1; i > id2; i--) cout << s[i];         cout << ch;         for (int i = id2 - 1; i >= id2 - cnt / 2; i--) cout << s[i];       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4;   void solve() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     float min = 4.5 * n;     int mn = (int)min;     if (min - mn > 0) mn++;     int sum = 0;     for (int i = 0; i < n; i++) sum += arr[i];     int req = mn - sum;     if (req <= 0) {       cout << 0 << endl;       return;     }     sort(arr, arr + n);     int ans = 0, i = 0;     while (req > 0) {       req -= 5 - arr[i];       i++;       ans++;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i;     scanf( %d%d , &n, &k);     char s[n];     scanf( %s , s);     for (i = 0; i < n; ++i) {       if (s[i] ==  G ) {         for (int j = i + k; j < n; j += k) {           if (s[j] ==  # ) {             printf( NO n );             return 0;           } else if (s[j] ==  T ) {             printf( YES n );             return 0;           }         }         printf( NO n );         return 0;       } else if (s[i] ==  T ) {         for (int j = i + k; j < n; j += k) {           if (s[j] ==  # ) {             printf( NO n );             return 0;           } else if (s[j] ==  G ) {             printf( YES n );             return 0;           }         }         printf( NO n );         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int S = 550;   int n, q, a[N];   struct Block {     int lid, rid;     deque<int> que;     int mp[N];     Block() {}     void init() {       lid = rid = 0;       que.clear();       memset(mp, 0, sizeof mp);     }     void addf(int x) {       que.push_front(x);       mp[x]++;     }     void addb(int x) {       que.push_back(x);       mp[x]++;     }     void delf() {       if (que.empty()) return;       int x = que.front();       que.pop_front();       mp[x]--;     }     void delb() {       if (que.empty()) return;       int x = que.back();       que.pop_back();       mp[x]--;     }   } all[S];   int tot;   void init() {     for (int i = 0; i < S; ++i) all[i].init();     int id = 1;     tot = 0;     for (int i = 0; id <= n; ++i) {       tot++;       all[i].lid = all[i].rid = id;       for (int j = 1; j <= S && id <= n; ++j) {         all[i].addb(a[id]);         all[i].rid++;         id++;       }     }     for (int i = 0; i < tot; ++i) all[i].rid--;   }   int st[N], top;   void mov(int l, int r) {     int sx = 0, tx = 0;     for (int i = 0; i < tot; ++i) {       if (all[i].lid <= l && l <= all[i].rid) {         sx = i;       }       if (all[i].lid <= r && r <= all[i].rid) {         tx = i;       }     }     for (int i = sx + 1; i <= tx; ++i) {       all[i].addf(all[i - 1].que.back());       all[i - 1].delb();     }     int val = 0;     top = 0;     for (int i = all[tx].rid; i > r; --i) {       st[top++] = all[tx].que.back();       all[tx].delb();     }     val = all[tx].que.back();     all[tx].delb();     while (top > 0) all[tx].addb(st[--top]);     for (int i = all[sx].lid; i < l; ++i) {       st[top++] = all[sx].que.front();       all[sx].delf();     }     all[sx].addf(val);     while (top > 0) all[sx].addf(st[--top]);   }   int cal(int ip, int l, int r, int k) {     int res = 0;     top = 0;     for (int i = 1; i <= l - 1; ++i) {       st[top++] = all[ip].que.front();       all[ip].delf();     }     int alx = all[ip].rid - all[ip].lid + 1;     for (int i = 1; i <= alx - r; ++i) {       st[top++] = all[ip].que.back();       all[ip].delb();     }     res = all[ip].mp[k];     for (int i = 1; i <= alx - r; ++i) {       all[ip].addb(st[--top]);     }     for (int i = 1; i <= l - 1; ++i) {       all[ip].addf(st[--top]);     }     return res;   }   int qry(int l, int r, int k) {     int res = 0;     for (int i = 0; i < tot; ++i) {       if (all[i].lid <= l && r <= all[i].rid)         return cal(i, l - all[i].lid + 1, r - all[i].lid + 1, k);       if (l <= all[i].lid && all[i].rid <= r) res += all[i].mp[k];       if (all[i].lid < l && l <= all[i].rid) {         res += cal(i, l - all[i].lid + 1, all[i].rid - all[i].lid + 1, k);       }       if (all[i].lid <= r && all[i].rid > r) {         res += cal(i, 1, r - all[i].lid + 1, k);       }     }     return res;   }   int scan() {     int res = 0;     char ch;     while ((ch = getchar()) && (ch !=     && ch !=   n ))       res = res * 10 + ch -  0 ;     return res;   }   int Run() {     n = scan();     for (int i = 1; i <= n; ++i) a[i] = scan();     init();     int lans = 0;     q = scan();     while (q--) {       int op, l, r;       op = scan(), l = scan(), r = scan();       l = (l + lans - 1) % n + 1;       r = (r + lans - 1) % n + 1;       if (l > r) swap(l, r);       if (op == 1) {         mov(l, r);       } else {         int k;         k = scan();         k = (k + lans - 1) % n + 1;         lans = qry(l, r, k);         printf( %d n , lans);       }     }     return 0;   }   int main() { return Run(); }


#include <bits/stdc++.h>   using namespace std;   int n, f, r[4];   char names[4][16] = { Gryffindor ,  Hufflepuff ,  Ravenclaw ,  Slytherin };   int main() {     scanf( %d , &n);     vector<vector<int> > v;     v.push_back(vector<int>(4));     for (int k = 0; k < (int)(n); k++) {       char op;       scanf(  %c , &op);       ((void)0);       if (op !=  ? ) {         for (int i = 0; i < (int)(4); i++)           if (op == names[i][0]) {             for (int j = 0; j < (int)(v.size()); j++) v[j][i]++;           }       } else {         vector<vector<int> > nv;         for (int j = 0; j < (int)(v.size()); j++) {           int mx = 1 << 30;           for (int i = 0; i < (int)(4); i++) mx = min(mx, v[j][i]);           for (int i = 0; i < (int)(4); i++)             if (v[j][i] == mx) {               nv.push_back(v[j]);               nv.back()[i]++;             }         }         sort(nv.begin(), nv.end());         nv.erase(unique(nv.begin(), nv.end()), nv.end());         v = nv;       }     }     for (int i = 0; i < (int)(v.size()); i++) {       int mx = 1 << 30;       for (int j = 0; j < (int)(4); j++) mx = min(mx, v[i][j]);       for (int j = 0; j < (int)(4); j++)         if (v[i][j] == mx) r[j] = 1;     }     for (int i = 0; i < (int)(4); i++)       if (r[i]) puts(names[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, L;   char s[100005];   int main() {     scanf( %s , &s);     L = strlen(s);     for (i = 0; i < L; i++) printf( %c , s[i]);     for (i = L - 1; i >= 0; i--) printf( %c , s[i]);   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> adj[200005];   int dfs(int cur, int prv, bool valid) {     int cnt = valid;     for (int nxt : adj[cur])       if (nxt != prv) cnt += dfs(nxt, cur, !valid);     return cnt;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 0, a, b; i < N - 1; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     int cnt = dfs(1, 0, true);     cout << min(cnt, N - cnt) - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> m;   int main() {     long long int n, mm, i;     string s, b, s1, b1;     cin >> n >> mm;     for (i = 0; i < n; i++) {       cin >> s >> b;       m[b] = s;     }     char c;     for (i = 0; i < mm; i++) {       cin >> s1 >> b1;       int l = b1.length();       cout << s1 <<     << b1.substr(0, l - 1) <<  ; #  << m[b1.substr(0, l - 1)]            <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000010;   long long n, m, s, l;   vector<pair<long long, long long> > Adj[N];   long long Dis[N], Ans;   set<pair<long long, long long> > Res;   vector<pair<long long, pair<long long, long long> > > Edges;   void Dik() {     for (int i = 0; i <= n; i++) Dis[i] = 1e18;     Dis[s] = 0;     set<pair<long long, long long> > S;     S.insert({0, s});     while (!S.empty()) {       auto Cur = *S.begin();       S.erase(S.begin());       for (int i = 0; i < Adj[Cur.second].size(); i++) {         int to = Adj[Cur.second][i].first;         long long w = Adj[Cur.second][i].second;         if (Dis[to] > Cur.first + w) {           Dis[to] = Cur.first + w;           S.insert({Dis[to], to});         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> s;     for (int i = 0; i < m; i++) {       int a, b, w;       cin >> a >> b >> w;       Edges.push_back({w, {a, b}});       Adj[a].push_back({b, w});       Adj[b].push_back({a, w});     }     cin >> l;     if (l == 0) {       cout << 1 << endl;       return 0;     }     Dik();     for (int i = 1; i <= n; i++)       if (Dis[i] == l) Ans++;     for (int i = 0; i < Edges.size(); i++) {       int a = Edges[i].second.first;       int b = Edges[i].second.second;       long long w = Edges[i].first;       if (Dis[a] < l && Dis[a] + w > l && (w - (l - Dis[a])) + Dis[b] >= l) {         Ans++;       }       if (Dis[b] < l && Dis[b] + w > l && (w - (l - Dis[b])) + Dis[a] >= l) {         Ans++;       }       if (Dis[a] < l && Dis[a] + w > l && (w - (l - Dis[a])) + Dis[b] >= l) {         if (Dis[b] < l && Dis[b] + w > l && (w - (l - Dis[b])) + Dis[a] >= l) {           if (w - (l - Dis[a]) == (l - Dis[b])) Ans--;         }       }     }     cout << Ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, k, x, y;       cin >> n >> k;       if (n > k) {         x = k * (k + 1);         x = x / 2;         cout << x << endl;       } else {         y = n - 1;         x = y * (y + 1);         x = x / 2;         cout << x + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPSILON = 1e-9;   const double PI = acos(0.0) * 2;   const int MOD = 1000000007;   const int INF = 0x3c3c3c3c;   const long long INFL = 0x3c3c3c3c3c3c3c3c;   const int MAX_N = 102;   long long S, X;   long long solve(long long sum, int pos) {     if (sum > S) return 0;     if (pos < 0) return sum == S;     long long ret = 0;     if (X & (1ll << pos)) {       if ((1ll << pos) + sum <= S) ret += 2 * solve(sum + (1ll << pos), pos - 1);     } else {       if ((1ll << (pos + 1)) + sum <= S)         ret += solve(sum + 2 * (1ll << pos), pos - 1);       if (S - sum <= 2 * ((1ll << pos) - 1)) ret += solve(sum, pos - 1);     }     return ret;   }   int main() {     scanf( %lld%lld , &S, &X);     cout << solve(0, 60) - (X == S ? 2 : 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0;     long long q, p = 1;     cin >> q;     for (int i = 0; i < 2; i++) {       for (long long s = 2; s * s <= q; s++) {         if (q % s == 0) {           n++;           p *= s;           q /= s;           break;         }       }     }     if (n == 2 && q > 1 || n == 0) {       cout << 1 << endl;       cout << (n == 0 ? 0 : p) << endl;     } else {       cout << 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 212345;   int seg[4 * N], v[N], tin[N], tout[N], ans[N];   int a, b, n, q;   void init(int r, int i, int j) {     if (i == j) {       seg[r] = v[i];     } else {       init(2 * r, i, (i + j) / 2);       init(2 * r + 1, (i + j) / 2 + 1, j);       seg[r] = min(seg[2 * r], seg[2 * r + 1]);     }   }   int query(int r, int i, int j) {     if (b < i || a > j) return 0x3f3f3f3f;     if (i >= a && j <= b) {       return seg[r];     } else {       int L = query(2 * r, i, (i + j) / 2);       int R = query(2 * r + 1, (i + j) / 2 + 1, j);       return min(L, R);     }   }   void update(int r, int i, int j, int pos, int val) {     if (pos < i || pos > j) return;     if (i == j) {       seg[r] = val;     } else {       update(2 * r, i, (i + j) / 2, pos, val);       update(2 * r + 1, (i + j) / 2 + 1, j, pos, val);       seg[r] = min(seg[2 * r], seg[2 * r + 1]);     }   }   set<int> zeros;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> q;     int mx = 0;     for (int i = 1; i <= n; i++) {       cin >> v[i];       if (v[i] == 0) {         zeros.emplace(i);         v[i] = 0x3f3f3f3f;       } else {         if (tin[v[i]] == 0) tin[v[i]] = i;         tout[v[i]] = i;         mx = max(mx, v[i]);       }     }     if (zeros.size() == n) {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) cout << q <<    ;       cout << endl;       return 0;     }     if (mx != q and zeros.size() == 0) {       cout <<  NO  << endl;       return 0;     }     init(1, 1, n);     if (mx != q and zeros.size()) {       auto it = zeros.begin();       update(1, 1, n, *it, q);       zeros.erase(it);     }     for (int i = q; i >= 1; i--) {       if (tin[i] == 0) continue;       a = tin[i];       b = tout[i];       if (query(1, 1, n) < i) {         cout <<  NO  << endl;         return 0;       }       auto it = zeros.lower_bound(tin[i]);       while (it != zeros.end() and *it <= tout[i]) {         update(1, 1, n, *it, i);         it = zeros.erase(it);       }     }     for (int i = 1; i <= n; i++) {       a = i;       b = i;       ans[i] = query(1, 1, n);     }     for (int i = 2; i <= n; i++) {       if (ans[i] == 0x3f3f3f3f and ans[i - 1] != 0x3f3f3f3f) ans[i] = ans[i - 1];     }     for (int i = n - 1; i >= 1; i--) {       if (ans[i] == 0x3f3f3f3f and ans[i + 1] != 0x3f3f3f3f) ans[i] = ans[i + 1];     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) {       assert(ans[i] != 0x3f3f3f3f);       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int th = 0;     for (int i = 1; i < n; i++) {       th += i;       th %= n;       cout << (th + 1) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e6 + 7;   const long long mod = 1e9 + 7;   const long long INF = 3e18 + 315;   vector<pair<long long, long long> > va, vb;   long long n, s, ans, na, nb, ta, tb;   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> s;     for (long long i = 0; i < n; i++) {       long long num, a, b;       cin >> num >> a >> b;       if (a > b) {         ans += num * a;         na += num;         va.push_back({a - b, num});       } else {         ans += num * b;         nb += num;         vb.push_back({b - a, num});       }     }     na %= s;     nb %= s;     sort(va.begin(), va.end());     sort(vb.begin(), vb.end());     if (na + nb > s) return cout << ans << endl, 0;     for (long long i = 0; i < ((long long)(va).size()); i++) {       ta += min(na, va[i].second) * va[i].first;       na -= min(na, va[i].second);     }     for (long long i = 0; i < ((long long)(vb).size()); i++) {       tb += min(nb, vb[i].second) * vb[i].first;       nb -= min(nb, vb[i].second);     }     ans -= min(ta, tb);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 10001;   void solve() {}   int main() {     int a, b, c;     while (cin >> a >> b >> c) {       int t = a * c;       for (int i = 0; i <= 1005 * 1005; i++) {         if (b * i + c * b >= a * c) {           cout << i << endl;           break;         }       }     }     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int arr[200007];     map<int, bool> vis;     queue<int> q;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       if (vis[arr[i]]) continue;       vis[arr[i]] = true;       if (q.size() == k) {         vis[q.front()] = false;         q.pop();       }       q.push(arr[i]);     }     vector<int> v;     while (!q.empty()) {       v.push_back(q.front());       q.pop();     }     cout << (int)v.size() << endl;     for (int i = (int)v.size() - 1; i >= 0; i--) {       cout << v[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   int n, m, Q, a[300006][2], fa[300006], dep[300006], siz[300006], b[300006], D;   bool vis[300006];   map<int, int> mp[300006];   vector<int> v[300006], s[300006];   const double pi = acos(-1.0);   void df5(int te, int la) {     vis[te] = 1;     siz[te] = 1;     for (int i = 0; i < v[te].size(); i++) {       int j = v[te][i];       if (j == la) continue;       if (vis[j]) continue;       dep[j] = dep[te] + 1;       fa[j] = te;       df5(j, te);       siz[te] += siz[j];     }   }   inline double getde(int x, int y) {     double ret = atan2(1.0 * a[y][1] - a[x][1], 1.0 * a[y][0] - a[x][0]);     if (ret < 0) ret += 2.0 * pi;     return ret;   }   inline bool cmp(int x, int y) { return getde(D, x) < getde(D, y); }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y), v[y].push_back(x);     }     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i][0], &a[i][1]);     df5(1, 1);     for (int i = 1; i <= n; i++) {       D = i;       sort(v[i].begin(), v[i].end(), cmp);       for (int j = 0; j < v[i].size(); j++) mp[i][v[i][j]] = j;       if (!v[i].empty()) {         if (v[i][0] == fa[i])           s[i].push_back(-siz[i]);         else if (fa[v[i][0]] == i)           s[i].push_back(siz[v[i][0]]);         else           s[i].push_back(0);       }       for (int j = 1; j < v[i].size(); j++) {         int x = v[i][j], la = s[i][j - 1];         if (x == fa[i])           s[i].push_back(la - siz[i]);         else if (fa[x] == i)           s[i].push_back(la + siz[x]);         else           s[i].push_back(la);       }     }     scanf( %d , &Q);     while (Q--) {       int k;       scanf( %d , &k);       bool hv1 = false;       for (int i = 1; i <= k; i++) scanf( %d , &b[i]);       for (int i = 1; i <= k; i++)         if (b[i] == 1) {           hv1 = true;           break;         }       long long sum = 0;       bool flag = false;       for (int i = 1; i <= k; i++) {         int ii = i % k + 1;         sum += (1ll * (a[b[i]][0] - a[b[ii]][0]) * a[b[i]][1] -                 1ll * a[b[i]][0] * (a[b[i]][1] - a[b[ii]][1]));       }       if (sum > 0) flag = true;       long long ans = 0;       if (!flag) {         for (int i = 2, j = k; i < j; i++, j--) swap(b[i], b[j]);       }       for (int i = 1; i <= k; i++) {         int la = i - 1;         if (!la) la = k;         int nx = i % k + 1;         int ts1 = mp[b[i]][b[la]], ts2 = mp[b[i]][b[nx]],             tt = ((int)v[b[i]].size()) - 1;         if (ts1 >= ts2) {           if (ts1) ans += s[b[i]][ts1];           if (ts2) ans -= s[b[i]][ts2 - 1];         } else {           ans += s[b[i]][ts1];           if (ts2) ans += s[b[i]][tt] - s[b[i]][ts2 - 1];         }       }       ans += k;       if (ans <= 0) ans += n;       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   int main() {     using namespace std;     int c, m, i;     cin >> c >> m;     int a = 0;     for (i = 1; i <= 9; i++) {       if (i * c % 10 == 0) {         cout << i;         break;       }       if (c == m) {         cout << i;         break;       }       if (i * c % 10 == m) {         cout << i;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = 105;   const long long mod = 998244353;   vector<vector<int>> adj;   void solve() {     long long n, i, j, k;     cin >> n;     long long a[n];     for (i = 0; i < n; i++) cin >> a[i];     long long res = 0, su = 0;     for (i = 0; i < n; i++) {       su += a[i];     }     long long mm = su / n;     for (i = 0; i < n; i++) {       res += abs(a[i] - mm);       a[i + 1] += a[i] - mm;     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     scanf( %I64d %I64d , &a, &b);     long long t = 0;     while (b) {       t *= 10;       t += b % 10;       b /= 10;     }     printf( %I64d n , a + t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long int mod = 1000000007;   const double epsilon = 1e-9;   template <class T>   ostream &operator<<(ostream &out, vector<T> &A) {     for (auto x : A) out << x <<    ;     return out;   }   template <class T>   ostream &operator<<(ostream &out, set<T> &A) {     for (auto x : A) out << x <<    ;     return out;   }   template <class T>   ostream &operator<<(ostream &out, unordered_set<T> &A) {     for (auto x : A) out << x <<    ;     return out;   }   template <class T1, class T2>   T1 powr(T1 a, T2 b) {     T1 res = 1;     for (long long int i = 1; i < b + 1; i++) res = res * a;     return res;   }   long long int binpow(long long int a, long long int b) {     a = a % mod;     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return (res + mod) % mod;   }   const long long int N = 10000025;   long long int prime[10000000];   void SieveOfEratosthenes() {     for (long long int i = 0; i < N; i++) prime[i] = 1;     prime[0] = 0;     prime[1] = 0;     for (long long int p = 2; p * p <= 10000000; p++) {       if (prime[p] == 1) {         for (long long int i = p * p; i <= 10000000; i += p) prime[i] = 0;       }     }   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int sum = 0, cnt = 0;       for (long long int i = 1; i < 100000; i++) {         long long int x = pow(2, i) - 1;         if (n - (x * (x + 1)) / 2 >= 0) {           n -= (x * (x + 1) / 2);           cnt++;         } else {           break;         }       }       cout << cnt <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int d, n, m, b[200005];   int mn[200005 << 2];   long long ans;   struct node {     int x;     long long p;     bool operator<(const node &a) const { return x < a.x; }   } a[200005];   int check(int x, int y) { return a[x].p < a[y].p ? x : y; }   void build(int l, int r, int rt) {     if (l == r) {       mn[rt] = l;       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     mn[rt] = check(mn[rt << 1], mn[rt << 1 | 1]);   }   int get_mn(int l, int r, int rt, int L, int R) {     if (L == l && R == r) return mn[rt];     int mid = (l + r) >> 1;     if (R <= mid)       return get_mn(l, mid, rt << 1, L, R);     else if (L > mid)       return get_mn(mid + 1, r, rt << 1 | 1, L, R);     else       return check(get_mn(l, mid, rt << 1, L, mid),                    get_mn(mid + 1, r, rt << 1 | 1, mid + 1, R));   }   int main() {     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) scanf( %d%I64d , &a[i].x, &a[i].p);     sort(a + 1, a + m + 1);     a[++m].x = d;     a[0].p = 0x3f3f3f3f;     build(1, m, 1);     for (int i = 1; i <= m; i++) b[i] = a[i].x;     int now = n, i = 0, j = 1, t, k;     while (i < m) {       t = upper_bound(b + 1, b + m + 1, a[i].x + n) - b - 1;       if (t == i) {         puts( -1 );         return 0;       }       t = upper_bound(b + 1, b + m + 1, a[i].x + now) - b - 1;       k = (t > i ? get_mn(1, m, 1, i + 1, t) : 0);       if (a[k].p <= a[i].p) {         now -= (a[k].x - a[i].x);         i = k;       } else {         t++;         while (t <= m && a[t].x - a[i].x <= n) {           if (a[t].p <= a[i].p) {             ans = (ans + (a[t].x - a[i].x - now) * a[i].p);             now = 0;             i = t;             break;           }           t++;         }         if (a[t].x - a[i].x > n) {           t = upper_bound(b + 1, b + m + 1, a[i].x + n) - b - 1;           k = get_mn(1, m, 1, i + 1, t);           ans = (ans + (n - now) * a[i].p);           now = (n - (a[k].x - a[i].x));           i = k;         }       }     }     cout << ans << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 1;   const long long INF = -1e17;   long long n;   long long ans, cnt, mx = 0;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     getline(cin, s);     getline(cin, s);     for (long long i = 0; i < s.size(); i++) {       if (s[i] > 64 and s[i] < 95) {         ans++;         mx = max(ans, mx);       } else if (s[i] ==    ) {         mx = max(ans, mx);         ans = 0;       }     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000010;   vector<int> freqs;   int t, n, k, a[N], f[N], vis[N];   int main() {     cin >> t;     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         f[i] = 0, vis[i] = 0;       }       for (int i = 1; i <= n; ++i) {         scanf( %d , a + i);         ++f[a[i]];       }       int minFreq = n + n;       for (int i = 1; i <= n; ++i) {         if (f[i]) ++vis[f[i]], minFreq = min(minFreq, f[i]);       }       freqs.clear();       for (int i = 1; i <= n; ++i)         if (vis[i]) {           freqs.emplace_back(i);         }       int ans = n;       for (int s = 1; s <= minFreq; ++s) {         int bad = 0, m = 0;         for (int it : freqs) {           int x = (it + s) / (s + 1);           if (x * s > it) {             bad = 1;             break;           }           m += vis[it] * x;         }         if (bad) continue;         ans = min(ans, m);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double e = 1e-6;   int main() {     int T;     double n;     scanf( %d , &T);     while (T--) {       scanf( %lf , &n);       double a = 0, b = n;       bool flag = false;       for (int i = 0; i < 10000; i++) {         double m = (a + b) / 2, d = n - m;         if (m * d - m - d > 1e-9)           b = m;         else if (m + d - d * m > 1e-9)           a = m;       }       double m = (a + b) / 2, d = n - m;       if (m + d - n <= e && m + d - n >= -e && (m + d) - m * d <= e &&           (m + d) - m * d >= -e && m * d - n <= e && m * d - n >= -e)         printf( Y %.9lf %.9lf n , d, m);       else         puts( N );     }     return 0;   }


#include <bits/stdc++.h>   int n, a[444], s, p, q, ans;   int main() {     scanf( %d , &n);     ans = -1;     for (int i = 0; i < n; ++i) scanf( %d , a + i);     for (int i = 1; i < n; ++i)       for (int j = 0; j < n; ++j) {         p = a[i - 1] - 1;         for (int k = q = s = 0; k <= j;)           q += p / a[k], s += p / a[k] * a[k], p %= a[k++];         ++q, p = s += a[j];         for (int k = 0; k < n; ++k) q -= p / a[k], p %= a[k];         if (q < 0) ans = (unsigned)ans < s ? ans : s;       }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, m, k;   set<int> a[maxn], b[maxn];   set<int, greater<int> > c[maxn], d[maxn];   int main() {     scanf( %d%d%d , &n, &m, &k);     int x, y, nx, ny, lx = 0, ly = 0, rx = n + 1, ry = m + 1, dir = 1;     long long ans = 1;     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x, &y);       a[x].insert(y), c[x].insert(y);       b[y].insert(x), d[y].insert(x);     }     x = 1, y = 1;     for (int i = 1;; i++) {       nx = x, ny = y;       if (dir == 1) {         auto t = a[x].lower_bound(y);         ny = ((t == a[x].end()) ? ry : min(*t, ry)) - 1, lx = x;       }       if (dir == 2) {         auto t = b[y].lower_bound(x);         nx = ((t == b[y].end()) ? rx : min(*t, rx)) - 1, ry = y;       }       if (dir == 3) {         auto t = c[x].lower_bound(y);         ny = ((t == c[x].end()) ? ly : max(*t, ly)) + 1, rx = x;       }       if (dir == 4) {         auto t = d[y].lower_bound(x);         nx = ((t == d[y].end()) ? lx : max(*t, lx)) + 1, ly = y;       }       if (x == nx && y == ny && i > 1) break;       ans += abs(nx - x) + abs(ny - y), x = nx, y = ny,                                         dir = (dir < 4) ? dir + 1 : 1;     }     if (ans == (long long)n * m - k)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int cnt, n, res;   int tin[maxn], tout[maxn], a[maxn + maxn], dp[maxn], f[maxn][17], st[maxn],       h[maxn], b[maxn];   bool need[maxn];   vector<int> adj[maxn];   void Input() {     int x, y;     cin >> n;     for (int i = (2); i <= (n); ++i) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }   }   void DFS(int u) {     tin[u] = ++cnt;     for (int v : adj[u]) {       if (h[v] != 0) continue;       h[v] = h[u] + 1;       f[v][0] = u;       for (int i = (1); i <= (16); ++i) f[v][i] = f[f[v][i - 1]][i - 1];       DFS(v);     }     tout[u] = cnt;   }   int LCA(int u, int v) {     if (h[u] < h[v]) swap(u, v);     for (int i = (16); i >= (0); --i)       if (h[u] - (1 << i) >= h[v]) u = f[u][i];     if (u == v) return u;     for (int i = (16); i >= (0); --i)       if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];     return f[u][0];   }   bool cmp(int u, int v) { return tin[u] < tin[v]; }   bool IsAnc(int u, int v) { return tin[u] < tin[v] && tout[v] <= tout[u]; }   bool canbuild(int k) {     sort(a + 1, a + 1 + k, cmp);     for (int i = (1); i <= (k - 1); ++i) a[k + i] = LCA(a[i], a[i + 1]);     k = k + k - 1;     sort(a + 1, a + 1 + k, cmp);     k = unique(a + 1, a + 1 + k) - a - 1;     for (int i = (1); i <= (k); ++i) adj[a[i]].clear();     int top = 1, u;     st[1] = a[1];     for (int i = (2); i <= (k); ++i) {       while (top >= 1 && !IsAnc(st[top], a[i])) --top;       if (top == 0) {         st[++top] = a[i];         continue;       }       u = st[top];       if (need[u] && need[a[i]] && f[a[i]][0] == u) return false;       adj[u].push_back(a[i]);       st[++top] = a[i];     }     return true;   }   void Calc(int u) {     int tmp = 0;     for (int v : adj[u]) {       Calc(v);       tmp += dp[v];     }     if (need[u]) {       res += tmp;       dp[u] = 1;     } else {       if (tmp >= 2)         dp[u] = 0, ++res;       else         dp[u] = tmp;     }   }   void Solve() {     h[1] = 1;     DFS(1);     int q, k;     cin >> q;     for (int i = (1); i <= (q); ++i) {       cin >> k;       for (int j = (1); j <= (k); ++j) {         cin >> a[j];         b[j] = a[j];         need[a[j]] = true;       }       if (!canbuild(k)) {         cout << -1 <<   n ;         for (int j = (1); j <= (k); ++j) need[b[j]] = false;         continue;       }       res = 0;       Calc(st[1]);       cout << res <<   n ;       for (int j = (1); j <= (k); ++j) need[b[j]] = false;     }   }   int main() {     iostream::sync_with_stdio(false);     cin.tie(0);     Input();     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using maxpq = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using minpq = priority_queue<T>;   int n, TOT;   string a[305];   int HASH[305], len[305], p[100005];   inline int add(int a, int b) {     long long c = a + b;     if (c >= 1000000007) c -= 1000000007;     return c;   }   inline int sub(int a, int b) {     int c = a - b;     if (c < 0) c += 1000000007;     return c;   }   inline int mul(int a, int b) { return (a * 1ll * b) % 1000000007; }   int power(int a, int b, int m = 1000000007) {     int res = 1;     while (b > 0) {       if (b & 1) res = mul(res, a);       a = mul(a, a);       b >>= 1;     }     return res;   }   inline int Fermat(int a, int p = 1000000007) { return power(a, p - 2, p); }   inline int Div(int a, int b) { return mul(a, Fermat(b)); }   int base = 128;   inline int h(char c) { return c; }   inline int hsh(string s) {     int t = 0;     for (int i = (0); i < (s.size()); i++) {       t = mul(t, base);       t = add(t, h(s[i]));     }     return t;   }   int ans = 0;   vector<pair<int, int>> adj[305];   void pre() {     p[0] = 1;     for (int i = (1); i < (100005); i++) {       p[i] = mul(p[i - 1], base);     }   }   void solve() {     for (int l = (1); l < (n + 1); l++) {       for (int i = (0); i < (n - l + 1); i++) {         int j = i + l - 1;         int t = HASH[i], tot = len[i];         for (int k = (i + 1); k < (j + 1); k++) {           t = mul(t, p[len[k] + 1]);           t = add(t, mul(h(   ), p[len[k]]));           t = add(t, HASH[k]);           tot = tot + len[k] + 1;         }         adj[l].push_back({t, tot});       }     }     for (int l = (1); l < (n); l++) {       for (int i = (0); i < (n - l + 1); i++) {         bool b = 0;         int tmp = TOT;         for (int j = (i + l); j < (n - l + 1); j++) {           if (adj[l][i].first != adj[l][j].first ||               adj[l][j].second != adj[l][j].second)             continue;           tmp += -adj[l][i].second + l;           if (b == 0) b = 1, tmp += -adj[l][i].second + l;           j += l - 1;         }         ans = min(ans, tmp);       }     }   }   int main() {     clock_t clk = clock();     cerr <<  I will return... n ;     cin >> n;     for (int i = (0); i < (n); i++)       cin >> a[i], len[i] = a[i].size(), TOT += len[i], HASH[i] = hsh(a[i]);     TOT += n - 1;     ans = TOT;     pre();     solve();     cout << ans <<   n ;     cerr <<  ...don t you ever hang your head. n ;     cerr <<  Time (in ms):   << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC          <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void __read(T& a) {     cin >> a;   }   template <typename T, typename... Args>   void __read(T& a, Args&... args) {     cin >> a;     __read(args...);   }   constexpr long long M7 = 1000000007ll;   constexpr long long M9 = 1000000009ll;   constexpr long long MFFT = 998244353ll;   template <class T>   void outv(T& a) {     for (auto& x : a) cout << x <<    ;   }   mt19937 rnd(static_cast<unsigned>(       chrono::steady_clock::now().time_since_epoch().count()));   template <class T>   void random_shuffle(T s, T e) {     shuffle(s, e, rnd);   };   static auto __super_speed__ = (ios_base::sync_with_stdio(0), cin.tie(0));   signed dp[30 + 1][30 + 1][51];   signed calc(signed n, signed m, signed k) {     signed& v = dp[n][m][k];     if (v != -1) return v;     if (n * m == k || k == 0) return v = 0;     v = M7;     for (signed i = 1; i < n; ++i)       for (signed nk = 0; nk < k; ++nk)         v = min(v, calc(i, m, nk) + calc(n - i, m, k - nk) + m * m);     for (signed i = 1; i < m; ++i)       for (signed nk = 0; nk < k; ++nk)         v = min(v, calc(n, i, nk) + calc(n, m - i, k - nk) + n * n);     return v;   }   int32_t main() {     memset(dp, -1, sizeof(dp));     signed t;     __read(t);     while (t--) {       signed n, m, k;       __read(n, m, k);       cout << calc(n, m, k) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, test =  hello ;     int c = 0;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] == test[c]) {         c++;       }       if (c == 5) {         break;       }     }     if (c == 5) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class TAT>   void read(TAT &a) {     static char cc;     static bool fff;     while (((cc = getchar()) <  0  || cc >  9 ) && cc !=  - )       ;     if (cc ==  - )       fff = 1, a = 0;     else       fff = 0, a = cc - 48;     while ((cc = getchar()) >=  0  && cc <=  9 ) a = a * 10 + cc - 48;     if (fff) a = -a;   }   template <class TAT>   void write(TAT a) {     static char cc[25];     static int ct;     if (a == 0) {       putchar( 0 );       return;     }     if (a < 0) {       putchar( - );       a = -a;     }     ct = 0;     while (a) {       cc[++ct] = a % 10 + 48;       a /= 10;     }     while (ct) {       putchar(cc[ct--]);     }   }   void begin() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void end() {     fclose(stdin);     fclose(stdout);   }   template <class TAT>   void Ckmin(TAT &a, const TAT &b) {     if (a > b) a = b;   }   template <class TAT>   void Ckmax(TAT &a, const TAT &b) {     if (a < b) a = b;   }   const int mod = 1000000007;   const int maxn = 105;   const int maxm = 10005;   long long n, m, K;   long long C[maxn][maxn] = {0};   long long F[maxn][maxm] = {0};   long long P[maxn] = {0};   void Init() { read(n), read(m), read(K); }   int Pow(long long x, long long y) {     long long S = 1;     while (y) {       if (y & 1) S = (S * x) % mod;       x = (x * x) % mod;       y >>= 1;     }     return S;   }   void Prepare() {     const int N = 101;     register int i, j, k;     C[0][0] = 1;     for (i = 1; i <= N; ++i) {       C[i][0] = 1;       for (j = 1; j <= i; ++j) {         C[i][j] =             ((C[i][j - 1] * Pow(j, mod - 2)) % mod * (long long)(i - j + 1)) %             mod;       }     }   }   void Solve() {     register int i, j, k;     memset(F, 0, sizeof(F));     F[0][0] = 1;     for (i = 1; i <= n; ++i) {       for (j = 0; j <= n; ++j) P[j] = Pow(C[n][j], (m + n - i) / n) % mod;       for (j = 0; j <= K; ++j) {         for (k = j; k <= K && k <= j + n; ++k) {           F[i][k] = (F[i][k] + F[i - 1][j] * P[k - j]) % mod;         }       }     }     write(F[n][K]);     putchar(  n );   }   int main() {     Init();     Prepare();     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100009;   int main() {     string s;     cin >> s;     int l = s.size();     for (int i = 0; i < l; i++) s += s[i];     int ans = 1;     for (int i = 0; i < l;) {       int j = i;       for (; j < l + i - 1; j++) {         if (s[j] == s[j + 1])           break;         else           ans = max(ans, j - i + 2);       }       i = j + 1;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     long long cnt = 0;     for (long long i = 0; i < s.length(); i++) {       if (s[i] >= 97) cnt++;     }     if (cnt >= s.length() - cnt) {       transform(s.begin(), s.end(), s.begin(), ::tolower);     } else       transform(s.begin(), s.end(), s.begin(), ::toupper);     cout << s << endl;   }   int main() {     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, s, l, r, res, cur, maxx = -9999999999;   int main() {     cin >> n >> s;     for (long long i = 1; i <= n; i++) {       cin >> l >> r;       maxx = max(maxx, l + r);     }     cout << max(maxx, s);     return 0;   }


#include <bits/stdc++.h>   struct MI {    private:     char bb[1 << 14];     FILE *f;     char *bs, *be;     char e;     bool o, l;       public:     MI() : f(stdin), bs(0), be(0) {}     inline char get() {       if (o) {         o = 0;         return e;       }       if (bs == be) be = (bs = bb) + fread(bb, 1, sizeof(bb), f);       if (bs == be) {         l = 1;         return -1;       };       return *bs++;     }     inline void unget(char c) {       o = 1;       e = c;     }     template <class T>     inline T read() {       T r;       *this > r;       return r;     }     template <class T>     inline MI &operator>(T &);   };   template <class T>   struct Q {     const static bool U = T(-1) >= T(0);     inline void operator()(MI &t, T &r) const {       r = 0;       char c;       bool y = 0;       if (U)         for (;;) {           c = t.get();           if (c == -1) goto E;           if (isdigit(c)) break;         }       else         for (;;) {           c = t.get();           if (c == -1) goto E;           if (c ==  - ) {             c = t.get();             if (isdigit(c)) {               y = 1;               break;             };           } else if (isdigit(c))             break;           ;         };       for (;;) {         if (c == -1) goto E;         if (isdigit(c))           r = r * 10 + (c ^ 48);         else           break;         c = t.get();       }       t.unget(c);     E:;       if (y) r = -r;     }   };   template <>   struct Q<char> {};   template <class T>   inline MI &MI::operator>(T &t) {     Q<T>()(*this, t);     return *this;   }   template <class T>   std::ostream &operator<(std::ostream &out, const T &t) {     return out << t;   }   using std::cout;   MI cin;   const int $n = 500005;   const int $t = 1048600;   template <typename T>   inline bool gmax(T &a, const T &b) {     return a < b && (a = b, true);   }   int n, fa[$n], mx[$n], se[$n], dep[$n], es[$n][2], t1, t2, dia;   std::vector<std::pair<int, bool>> outs[$n];   bool val[$n];   void dfs(int x) {     mx[x] = x;     dep[x] = dep[fa[x]] + 1;     for (auto [v, w] : outs[x]) {       if (v == fa[x]) continue;       fa[v] = x;       val[v] = val[x] ^ w;       dfs(v);       if (dep[mx[v]] >= dep[mx[x]]) {         se[x] = mx[x];         mx[x] = mx[v];       } else if (dep[mx[v]] > dep[se[x]])         se[x] = mx[v];     }     if (se[x] && gmax(dia, dep[mx[x]] + dep[se[x]] - dep[x] * 2)) {       t1 = mx[x];       t2 = se[x];     }   }   struct {     int rt, fa[$n], dfn[$n], dt, siz[$n], dep[$n], seq[$n];     int mx[$t][2], ll, rr;     bool rv[$t];     inline void upd(int x) {       std::swap(mx[x][0], mx[x][1]);       rv[x] ^= 1;     }     inline void pd(int x) {       if (!rv[x]) return;       upd((x << 1));       upd(((x << 1) | 1));       rv[x] = 0;     }     inline void pu(int x) {       mx[x][0] = std::max(mx[(x << 1)][0], mx[((x << 1) | 1)][0]);       mx[x][1] = std::max(mx[(x << 1)][1], mx[((x << 1) | 1)][1]);     }     void build(int x = 1, int l = 1, int r = n) {       if (l == r) return (void)(mx[x][val[seq[l]]] = dep[seq[l]] - 1);       const int mid = (l + r) >> 1;       build((x << 1), l, mid);       build(((x << 1) | 1), mid + 1, r);       pu(x);     }     void $update(int x, int l, int r) {       if (ll <= l && r <= rr) return upd(x);       const int mid = (l + r) >> 1;       pd(x);       if (ll <= mid) $update((x << 1), l, mid);       if (mid < rr) $update(((x << 1) | 1), mid + 1, r);       pu(x);     }     inline void update(int l, int r) {       ll = l;       rr = r;       $update(1, 1, n);     }     void dfs(int x) {       seq[dfn[x] = ++dt] = x;       siz[x] = 1;       dep[x] = dep[fa[x]] + 1;       for (auto [v, w] : outs[x]) {         if (v == fa[x]) continue;         fa[v] = x;         dfs(v);         siz[x] += siz[v];       }     }     inline void init(int rt) {       this->rt = rt;       dfs(rt);       build();     }     inline int flip(int x, int y) {       if (fa[y] == x) std::swap(x, y);       assert(fa[x] == y);       update(dfn[x], dfn[x] + siz[x] - 1);       return mx[1][val[rt]];     }   } A, B;   int main() {     cin > n;     for (int i = 1; i < n; ++i) {       const int x = es[i][0] = (cin.read<int>()),                 y = es[i][1] = (cin.read<int>()), w = (cin.read<int>());       outs[x].emplace_back(y, w);       outs[y].emplace_back(x, w);     }     dfs(1);     A.init(t1);     B.init(t2);     for (int T = (cin.read<int>()); T; --T) {       const int id = (cin.read<int>()), x = es[id][0], y = es[id][1];       cout < std::max(A.flip(x, y), B.flip(x, y)) < (  n );     }   }


#include <bits/stdc++.h>   using namespace std;   char s[3009], t[3009];   long long dp[3009][3009];   int n, m;   long long bigmod(long long a, long long p) {     long long r = 1ll;     while (p) {       if ((p & 1ll)) {         r = (a * r) % 998244353ll;       }       a = (a * a) % 998244353ll;       p >>= 1;     }     return r;   }   long long func(int i, int j) {     if (i < 0) {       return 1ll;     }     if (j >= m) {       return bigmod(2, i + 1);     }     long long &ret = dp[i][j];     if (~ret) return ret;     ret = 0;     if (s[i] == t[j]) ret = func(i - 1, j + 1);     if (j + i >= m || (s[i] == t[i + j])) ret += func(i - 1, j);     if (ret >= 998244353ll) ret -= 998244353ll;     return ret;   }   int main() {     scanf( %s , s);     scanf( %s , t);     n = strlen(s);     m = strlen(t);     memset(dp, -1, sizeof(dp));     long long ans = 0;     for (int i = n; i >= m; i--) {       ans += func(i - 1, 0);       if (ans >= 998244353ll) ans -= 998244353ll;     }     if (ans >= 998244353ll) ans -= 998244353ll;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int a, b, c, d, i, j, n, m, k, ans;   int cs[100001], mas[100001], dp[100001];   inline int sum(int a, int b) {     if (!a)       return cs[b];     else       return cs[b] - cs[a - 1];   }   int main() {     scanf( %d , &n);     for (int _n((n)-1), i(0); i <= _n; i++) {       scanf( %d , &mas[i]);       if (!i)         cs[i] = mas[i];       else         cs[i] = cs[i - 1] + mas[i];     }     ans = -1000000000 - 1;     for (int _n((n)-1), i(0); i <= _n; i++) {       if (!i)         dp[i] = max(cs[i], -cs[i]);       else         dp[i] = max(dp[i - 1] + mas[i], max(cs[i], -cs[i]));       ans = max(ans, dp[i]);     }     a = 0;     for (int i = (n - 2), _b = (0); i >= _b; i--) {       a += mas[i + 1];       ans = max(ans, max(a, -a) + dp[i]);     }     ans = max(ans, cs[n - 1]);     ans = max(ans, -cs[n - 1]);     ans = max(ans, dp[n - 1]);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005];   long long b[200005];   void solve() {     long long n;     cin >> n;     long long c = 0, t, c1 = 0;     cin >> t;     for (long long i = 0; i < t; i++) {       cin >> a[i];     }     for (long long i = 1; i < t; i++) {       if (n - a[i - 1] > 0) c += n - a[i - 1];     }     cout << c;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k;     cin >> n >> k;     m = (3 * n <= k) ? 0 : 3 * n - k;     cout << m << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie();     long long a, b, c, n, x;     cin >> a >> b >> c >> n;     x = a + b - c;     x = n - x;     if (x < 1 || c > a || c > b || c > (a + b))       cout << -1 << endl;     else       cout << x << endl;     return 0;   }