#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int M = 10000005;   const int mo = 1000000007;   int pri[M / 10], mn[M], id[M];   vector<int> e[N];   int n, T, Q, dfn[N], ed[N];   int fa[N][20], dep[N];   int qx[N], qy[N], qL[N], qv[N];   int t[N * 2], vis[N], A[N], ans[N];   vector<int> vec[M / 10];   pair<int, int> q1[N], q2[N];   int power(int x, int y) {     int s = 1;     for (; y; y /= 2, x = 1ll * x * x % mo)       if (y & 1) s = 1ll * s * x % mo;     return s;   }   void change(int x, int v) {     for (; x <= 2 * n; x += x & (-x)) t[x] += v;   }   int ask(int x) {     int ans = 0;     for (; x; x -= x & (-x)) ans += t[x];     return ans;   }   void init() {     for (int i = (int)(2); i <= (int)(M - 1); i++) {       if (!mn[i]) mn[i] = i, pri[++*pri] = i;       for (int j = 1; j <= *pri && i * pri[j] < M; ++j) {         mn[i * pri[j]] = pri[j];         if (i % pri[j] == 0) break;       }     }     for (int i = (int)(1); i <= (int)(*pri); i++) id[pri[i]] = i;   }   void insert(int x, int id) {     for (; x != 1;) {       int v = mn[x];       for (; x % v == 0; x /= v)         ;       vec[::id[v]].push_back(id);     }   }   void dfs(int x) {     dfn[x] = ++*dfn;     for (auto i : e[x])       if (i != fa[x][0]) {         fa[i][0] = x;         dep[i] = dep[x] + 1;         dfs(i);       }     ed[x] = ++*dfn;   }   int LCA(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int tmp = dep[x] - dep[y];     for (int i = (int)(0); i <= (int)(18); i++)       if (tmp & (1 << i)) x = fa[x][i];     for (int i = (int)(18); i >= (int)(0); i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return x == y ? x : fa[x][0];   }   void solve(int id) {     int top1 = 0, top2 = 0;     for (auto i : vec[id])       if (i < 0)         q2[++top2] = pair<int, int>(-i, qv[-i]);       else         q1[++top1] = pair<int, int>(i, A[i]);     for (; top1 && top2;) {       int tmp1 = 0, tmp2 = 0;       for (int i = (int)(1); i <= (int)(top1); i++) {         change(dfn[q1[i].first], -1);         change(ed[q1[i].first], 1);       }       for (int i = (int)(1); i <= (int)(top2); i++) {         int at = q2[i].first;         int val1 = ask(ed[qL[at]] - 1) - ask(ed[qx[at]] - 1);         int val2 = ask(ed[qL[at]]) - ask(ed[qy[at]] - 1);         ans[at] = 1ll * ans[at] * power(pri[id], val1 + val2) % mo;       }       for (int i = (int)(1); i <= (int)(top1); i++) {         change(dfn[q1[i].first], 1);         change(ed[q1[i].first], -1);       }       for (int i = (int)(1); i <= (int)(top1); i++) q1[i].second /= pri[id];       for (int i = (int)(1); i <= (int)(top2); i++) q2[i].second /= pri[id];       for (int i = (int)(1); i <= (int)(top1); i++)         if (q1[i].second % pri[id] == 0) q1[++tmp1] = q1[i];       for (int i = (int)(1); i <= (int)(top2); i++)         if (q2[i].second % pri[id] == 0) q2[++tmp2] = q2[i];       top1 = tmp1;       top2 = tmp2;     }   }   int main() {     init();     scanf( %d , &n);     for (int i = (int)(1); i <= (int)(n - 1); i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     dfs(1);     for (int i = (int)(1); i <= (int)(18); i++)       for (int j = (int)(1); j <= (int)(n); j++)         fa[j][i] = fa[fa[j][i - 1]][i - 1];     for (int i = (int)(1); i <= (int)(n); i++) {       scanf( %d , &A[i]);       insert(A[i], i);     }     scanf( %d , &Q);     for (int i = (int)(1); i <= (int)(Q); i++) {       scanf( %d%d%d , &qx[i], &qy[i], &qv[i]);       qL[i] = LCA(qx[i], qy[i]);       insert(qv[i], -i);       ans[i] = 1;     }     for (int i = (int)(1); i <= (int)(*pri); i++) solve(i);     for (int i = (int)(1); i <= (int)(Q); i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long int dp[100000 + 5] = {0};   void fun(long long int *A, long long int N) {     dp[0] = 0;     long long int a = 0;     for (long long int i = 1; i <= 100000; ++i) {       while (a < N and A[a] <= i) ++a;       dp[i] = a;     }   }   void solve() {     long long int N;     cin >> N;     long long int A[N];     for (long long int i = 0; i < N; ++i) cin >> A[i];     sort(A, A + N);     fun(A, N);     long long int Q;     cin >> Q;     while (Q--) {       long long int M;       cin >> M;       if (M > 100000)         cout << N <<   n ;       else         cout << dp[M] <<   n ;     }   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T = 1;     while (T--) {       solve();     }     exit(0);   }


#include <bits/stdc++.h>   const int maxn = 105;   int a[maxn];   inline int max(int a, int b) { return a > b ? a : b; }   int main() {     int n, ans = 0, temp;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (n < 3 || n % 2 == 0)       puts( -1 );     else {       for (int i = (n - 1); i >= 1; i -= 2) {         temp = max(a[i], a[i + 1]);         ans += temp;         a[i / 2] -= temp;         if (a[i / 2] < 0) a[i / 2] = 0;       }       ans += a[1];       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool a[200087];   int main(void) {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       a[temp + 100000] = true;     }     int ans = 0;     for (int i = 0; i <= 200000; i++) {       if (i != 100000 && a[i] == true) {         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void Fail() {     printf( 0 );     exit(0);   }   const int maxn = 100005;   int n, l, r, mn, id, ans, from, to, cnt, clen, mxdep, mid;   vector<pair<int, int> > edge[maxn];   pair<int, pair<int, int> > cur[maxn];   vector<int> beauty;   int sz[maxn], u[maxn], v[maxn], c[maxn], cen[maxn][25], total[maxn][25];   bool centroid[maxn], debug;   class segtree {    public:     pair<int, int> tree[maxn * 4];     int sz;     void _init(int tot) {       for (sz = 1; sz < tot; sz <<= 1)         ;       for (int(i) = 0; (i) < sz << 1; i++) tree[i] = make_pair(-1e9, -1);     }     void upd(int pos, int val, int id) {       pos += sz - 1;       tree[pos] = max(tree[pos], make_pair(val, id));       while (pos) {         pos >>= 1;         if (!pos) break;         tree[pos] = max(tree[pos << 1], tree[pos << 1 | 1]);       }     }     void clr(int pos) {       pos += sz - 1;       tree[pos] = make_pair(-1e9, -1);       while (pos) {         pos >>= 1;         if (!pos) break;         tree[pos] = max(tree[pos << 1], tree[pos << 1 | 1]);       }     }     pair<int, int> qry(int l, int r) {       if (r < 1) return make_pair(-1e9, -1);       l = max(l, 1);       r = min(r, sz);       l += sz - 1;       r += sz - 1;       pair<int, int> res = make_pair(-1e9, -1);       for (; l <= r; l >>= 1, r >>= 1) {         if (l & 1) res = max(res, tree[l++]);         if ((r - 1) & 1) res = max(res, tree[r--]);       }       return res;     }   } T;   void get_sz(int x, int p) {     sz[x] = 1;     for (int(i) = 0; (i) < edge[x].size(); i++) {       pair<int, int> y = edge[x][i];       if (centroid[y.first] || y.first == p) continue;       get_sz(y.first, x);       sz[x] += sz[y.first];     }   }   void get_centroid(int x, int p, int tot) {     int mx = tot - sz[x];     for (int(i) = 0; (i) < edge[x].size(); i++) {       pair<int, int> y = edge[x][i];       if (centroid[y.first] || y.first == p) continue;       get_centroid(y.first, x, tot);       mx = max(mx, sz[y.first]);     }     if (mx < mn) {       mn = mx;       id = x;     }   }   void get_dis(int x, int p, int dep, int dis, int s) {     mxdep = max(mxdep, dep);     cur[clen++] = make_pair(dep, make_pair(dis, x));     pair<int, int> mx = T.qry(l - dep + 1, r - dep + 1);     if (dis + mx.first > ans) {       ans = dis + mx.first;       from = x;       to = mx.second;     }     for (int(i) = 0; (i) < edge[x].size(); i++) {       pair<int, int> y = edge[x][i];       if (centroid[y.first] || y.first == p) continue;       get_dis(y.first, x, dep + 1, dis + (y.second >= mid ? 1 : -1), s);     }   }   void solve(int t, int dep) {     int s = cen[t][dep];     if (s < 0) {       mn = 1e9;       get_sz(t, -1);       get_centroid(t, -1, sz[t]);       s = id;       cen[t][dep] = s;       total[t][dep] = sz[t];     }     centroid[s] = true;     T._init(total[t][dep] + 1);     T.upd(1, 0, s);     for (int(i) = 0; (i) < edge[s].size(); i++) {       if (centroid[edge[s][i].first]) continue;       clen = 0;       get_dis(edge[s][i].first, s, 1, edge[s][i].second >= mid ? 1 : -1, s);       for (int(j) = 0; (j) < clen; j++) {         T.upd(cur[j].first + 1, cur[j].second.first, cur[j].second.second);       }     }     for (int(i) = 0; (i) < edge[s].size(); i++)       if (!centroid[edge[s][i].first]) solve(edge[s][i].first, dep + 1);     centroid[s] = false;   }   void add_edge(int x, int y, int z) {     edge[x].push_back(make_pair(y, z));     edge[y].push_back(make_pair(x, z));   }   bool check() {     ans = -1e9;     solve(0, 0);     return ans >= 0;   }   int main() {     memset(cen, -1, sizeof(cen));     scanf( %d%d%d , &n, &l, &r);     for (int(i) = 0; (i) < n - 1; i++) {       scanf( %d%d%d , &u[i], &v[i], &c[i]);       u[i]--, v[i]--;       add_edge(u[i], v[i], c[i]);       beauty.push_back(c[i]);     }     sort(beauty.begin(), beauty.end());     beauty.resize(unique(beauty.begin(), beauty.end()) - beauty.begin());     int L = 0, R = beauty.size();     while (R - L > 1) {       int Mid = (L + R) >> 1;       mid = beauty[Mid];       if (check())         L = Mid;       else         R = Mid;     }     debug = true;     mid = beauty[L];     check();     printf( %d %d , from + 1, to + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, l, r;   int ans[1000000 + 5];   long long mmod = 2333, mod = 1e9 + 7;   long long shash[1000000 + 5], base[1000000 + 5];   char s[1000000 + 5];   int main() {     scanf( %d%s , &n, s + 1);     base[0] = 1;     for (int i = 1; i <= n; i++) {       shash[i] = (shash[i - 1] * mmod + s[i] -  a  + 1) % mod;       base[i] = base[i - 1] * mmod % mod;     }     if (n % 2 == 1) {       ans[(n + 1) / 2] = -1;       l = r = (n + 1) / 2;     } else {       l = n / 2;       r = n / 2 + 1;       if (s[l] == s[r])         ans[n / 2] = 1;       else         ans[n / 2] = -1;     }     for (int i = (n + 1) / 2 - 1; i >= 1; i--) {       l--;       r++;       for (int j = ans[i + 1] + 2; j >= 1; j -= 2) {         long long a =             (shash[l + j - 1] - shash[l - 1] * base[j] % mod + mod) % mod;         long long b = (shash[r] - shash[r - j] * base[j] % mod + mod) % mod;         if (a == b) {           ans[i] = j;           break;         }       }       if (ans[i] == 0) ans[i] = -1;     }     for (int i = 1; i < (n + 1) / 2; i++) printf( %d  , ans[i]);     printf( %d , ans[(n + 1) / 2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 150004;   const long long mod = 998244353;   struct edge {     long long next, to;   } h[MAX << 1];   long long head[MAX], cnt, cnt_dfsn;   long long n, q, ans, inv;   inline void add(long long x, long long y) {     h[++cnt] = edge{head[x], y};     head[x] = cnt;     h[++cnt] = edge{head[y], x};     head[y] = cnt;   }   long long dfsn[MAX], size[MAX], son[MAX], fa[MAX], top[MAX], w[MAX];   long long tree[MAX];   inline long long lowbit(long long x) { return x & (-x); }   inline void ad(long long x, long long y) {     y %= mod;     for (long long i = x; i <= n; i += lowbit(i)) tree[i] = (tree[i] + y) % mod;   }   inline long long sum(long long x) {     long long ret = 0;     for (long long i = x; i; i -= lowbit(i)) ret = (ret + tree[i]) % mod;     return ret;   }   inline long long quick(long long x, long long y) {     long long ret = 1ll;     while (y) {       if (y & 1) ret = (ret * x) % mod;       y >>= 1;       x = (x * x) % mod;     }     return ret;   }   void dfs1(long long now, long long father) {     fa[now] = father;     size[now] = 1;     for (long long i = head[now]; i; i = h[i].next) {       long long aim = h[i].to;       if (aim != father) {         dfs1(aim, now);         size[now] += size[aim];         if (size[aim] > size[son[now]]) son[now] = aim;       }     }   }   void dfs2(long long now, long long start) {     top[now] = start;     dfsn[now] = ++cnt_dfsn;     if (son[now]) dfs2(son[now], start);     for (long long i = head[now]; i; i = h[i].next) {       long long aim = h[i].to;       if (aim != fa[now] && aim != son[now]) {         dfs2(aim, aim);       }     }   }   signed main() {     scanf( %lld %lld , &n, &q);     inv = quick(n, mod - 2);     for (long long x, y, i = 1; i < n; i++) scanf( %lld %lld , &x, &y), add(x, y);     dfs1(1, 1), dfs2(1, 1);     fa[1] = 0;     for (long long op, x, y, i = 1; i <= q; i++) {       scanf( %lld , &op);       if (op == 1) {         scanf( %lld %lld , &x, &y);         w[x] = (w[x] + y) % mod;         ad(1, size[x] * y % mod);         ad(dfsn[x], (mod - size[x] * y % mod) % mod),             ad(dfsn[x] + size[x], size[x] * y % mod);         if (son[x])           ad(dfsn[son[x]], (n - size[son[x]]) * y % mod),               ad(dfsn[son[x]] + size[son[x]], mod - (n - size[son[x]]) * y % mod);       } else {         scanf( %lld , &x);         ans = (sum(dfsn[x]) + n * w[x] % mod) % mod;         for (long long j = top[x]; fa[j]; j = top[fa[j]])           ans = (ans + (n - size[j]) * w[fa[j]] % mod) % mod;         printf( %lld n , (ans * inv) % mod);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int limit = 1000005;   void die() {     cout <<  NO  << endl;     exit(0);   }   void computereachable(int u, int code, vector<int> g[limit],                         int reachable[limit]) {     if (reachable[u] & code) return;     reachable[u] |= code;     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++)       computereachable(ar[i], code, g, reachable);   }   int n, m;   vector<int> g[limit], ginv[limit];   int reachdir[limit];   int reachinv[limit];   int nsink;   int nsour;   int listsour[limit];   int norder;   int order[limit];   int seen[limit];   void generatepostorder(int u) {     if (seen[u]) return;     seen[u] = 1;     vector<int> &ar = ginv[u];     for (int i = 0; i < int(ar.size()); i++) generatepostorder(ar[i]);     order[norder++] = u;   }   void traverse(int u) {     if (seen[u]) return;     seen[u] = 1;     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++) traverse(ar[i]);   }   void checkalreadystrong() {     for (int u = 1; u <= n; u++) generatepostorder(u);     reverse(order, order + norder);     for (int u = 1; u <= n; u++) seen[u] = 0;     traverse(order[0]);     for (int u = 1; u <= n; u++)       if (not seen[u]) die();     cout <<  YES  << endl;     exit(0);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       ginv[v].push_back(u);     }     for (int u = 1; u <= n; u++) {       if (int(g[u].size()) == 0) {         computereachable(u, 1 << (nsink++), ginv, reachinv);       }       if (int(ginv[u].size()) == 0) {         computereachable(u, 1, g, reachdir);         listsour[nsour++] = u;       }     }     if (nsour == 0) checkalreadystrong();     for (int u = 1; u <= n; u++)       if (not reachdir[u] or not reachinv[u]) die();     for (int c = 1; c < (1 << nsour) - 1; c++) {       int creach = 0;       for (int b = 0; b < nsour; b++)         if (c & (1 << b)) creach |= reachinv[listsour[b]];       if (__builtin_popcount(creach) <= __builtin_popcount(c)) die();     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, len, wmax, ans;   vector<long long> vec[2];   inline void _read(long long &x) {     long long f = 1;     x = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - )         f = -1;       else         f = 1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;     return;   }   inline void _print(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x >= 10) _print(x / 10);     putchar(x % 10 +  0 );     return;   }   inline long long chk(long long x1, long long x2) {     long long x = x1 + x2, y = x2 - x1;     return y * wmax > x && y * wmax > -x;   }   int main() {     _read(n);     _read(len);     _read(wmax);     long long x, v;     for (long long i = 1; i <= n; i++) {       _read(x);       _read(v);       if (v == -1)         vec[0].push_back(x);       else         vec[1].push_back(x);     }     sort(vec[0].begin(), vec[0].end());     if (!vec[0].size()) {       _print(0);       return 0;     }     long long l, r, mid;     for (long long i = 0; i < vec[1].size(); i++) {       l = 0;       r = vec[0].size();       while (l < r) {         mid = (l + r) >> 1;         if (chk(vec[1][i], vec[0][mid] + len))           r = mid;         else           l = mid + 1;       }       ans += (vec[0].size() - r);     }     _print(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3010;   bool visit[maxn];   int n, m, ans, f[maxn];   vector<int> ve;   vector<pair<int, int> > maps[maxn];   void first_dfs(const int u) {     visit[u] = 1;     for (int i = 0; i < ((int)(maps[u]).size()); ++i) {       int v = maps[u][i].first;       int w = maps[u][i].second;       if (!visit[v]) {         first_dfs(v);         f[u] += f[v] + w;       }     }   }   void second_dfs(const int u) {     visit[u] = 1;     for (int i = 0; i < ((int)(maps[u]).size()); ++i) {       int v = maps[u][i].first;       int w = maps[u][i].second;       if (!visit[v]) {         f[v] = f[u] + (w ? -1 : 1);         m = min(m, f[v]);         second_dfs(v);       }     }   }   void solve(const int u) {     first_dfs(u);     ans = min(ans, f[u]);     if (((int)(maps[u]).size()) >= 2) {       ve.clear();       memset(visit, 0, sizeof(visit));       visit[u] = 1;       for (int i = 0; i < ((int)(maps[u]).size()); ++i) {         int v = maps[u][i].first;         int w = maps[u][i].second;         m = f[v];         second_dfs(v);         ve.push_back(m + (w ? -1 : 1) - f[v]);       }       sort(ve.begin(), ve.end());       ans = min(ans, f[u] + ve[0] + ve[1]);     }   }   int main() {     scanf( %d , &n);     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       maps[u].push_back(make_pair(v, 0));       maps[v].push_back(make_pair(u, 1));     }     ans = maxn;     for (int i = 1; i <= n; ++i) {       memset(f, 0, sizeof(f));       memset(visit, 0, sizeof(visit));       solve(i);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int check(int m, int k, string s) {     int i;     for (i = m + 1; i <= m + k && i < s.size(); i++) {       if (s[i] ==  1 ) return i;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t > 0) {       int i = 0, n, k, m, s = 0;       string a;       cin >> n >> k >> a;       for (i = 0; i < n;) {         int temp = check(i, k, a);         if (temp == -1) {           if (a[i] ==  0 ) {             s++;           }           i += (k + 1);         } else           i = temp;       }       cout << s << endl;       t--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   bool ans[50000][4];   int main() {     cin >> t;     for (int i = 0; i < t; i++) {       int toys[4];       for (int j = 0; j < 4; j++) {         cin >> toys[j];       }       bool neg = (toys[0] + toys[1]) % 2 == 1;       bool small = toys[1] >= 1 || toys[2] >= 1;       bool big = toys[0] >= 1 || toys[3] >= 1;       if (neg) {         if (small) {           ans[i][1] = true;         }         if (big) {           ans[i][0] = true;         }       } else {         if (small) {           ans[i][2] = true;         }         if (big) {           ans[i][3] = true;         }       }     }     for (int i = 0; i < t; i++) {       for (int j = 0; j < 4; j++) {         if (j != 0) {           cout <<    ;         }         if (ans[i][j]) {           cout <<  Ya ;         } else {           cout <<  Tidak ;         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using u32 = unsigned int;   using db = double;   using ld = long double;   using pii = std::array<int, 2>;   using pll = std::array<ll, 2>;   const int INF = 0x3f3f3f3f;   const long long INFll = 0x3f3f3f3f3f3f3f3f;   namespace Fast_in {   template <typename T>   void in(T &x) {     x = 0;     bool f = false;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = true;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     if (f) x = -x;   }   template <typename T>   T in() {     T x = 0;     bool f = false;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = true;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f ? -x : x;   }   template <typename T, typename... Tp>   void in(T &x, Tp &...a) {     in(x);     in(a...);   }   template <typename T>   void in(T *l, T *r) {     for (; l != r; ++l) in(*l);   }   }  // namespace Fast_in   using namespace Fast_in;   namespace Fast_out {   template <typename T>   void out_sub(T x, char ch =   n ) {     static int tp, sk[30];     if (x < 0) {       putchar( - );       x = -x;     }     do {       sk[++tp] = x % 10;       x /= 10;     } while (x);     while (tp) {       putchar(sk[tp--] +  0 );     }     putchar(ch);   }   void out(int x, char ch =   n ) { out_sub(x, ch); }   void out(ll x, char ch =   n ) { out_sub(x, ch); }   void out(u32 x, char ch =   n ) { out_sub(x, ch); }   void out(ull x, char ch =   n ) { out_sub(x, ch); }   void out(db x, char ch =   n ) { printf( %.12f%c , x, ch); }   void out(ld x, char ch =   n ) { printf( %.12Lf%c , x, ch); }   void out(char x, char ch =   n ) { printf( %d%c , x, ch); }   void out(char *x, char ch =   n ) { printf( %s%c , x, ch); }   void out(string x, char ch =   n ) { printf( %s%c , x.c_str(), ch); }   void out(pii x) { out_sub(x[0],    ), out_sub(x[1]); }   void out(pll x) { out_sub(x[0],    ), out_sub(x[1]); }   template <typename T>   void out(vector<T> x, char ch =    ) {     if (x.empty()) {       puts(  );       return;     }     T val = x.back();     x.pop_back();     for (auto i : x) out(i, ch);     out(val);   }   template <typename T>   void out(set<T> x, char ch =    ) {     if (x.empty()) {       puts(  );       return;     }     T val = *x.rbegin();     x.erase(--x.end());     for (auto i : x) out(i, ch);     out(val);   }   template <typename T>   void out(T *l, T *r, char ch =    ) {     if (l == r) {       puts(  );       return;     }     --r;     for (; l != r; ++l) out(*l, ch);     if (l == r) out(*l);   }   template <typename T, typename... Tp>   void out(T x, Tp... a) {     out(x,    );     out(a...);   }   }  // namespace Fast_out   using namespace Fast_out;   namespace Bin {   template <int len = 0, typename T>   void out_bin(T x, char ch =   n ) {     if (len) {       cout << bitset<len>(x).to_string() << ch;       return;     }     long long val = 1ll << 32;     bool flg = false;     if (x > val) {       for (int i = 63; ~i; --i)         if (flg)           printf( %d , (x >> i) & 1);         else if ((x >> i) & 1) {           flg = true;           printf( 1 );         }     } else {       for (int i = 31; ~i; --i)         if (flg)           printf( %d , (x >> i) & 1);         else if ((x >> i) & 1) {           flg = true;           printf( 1 );         }     }     putchar(ch);   }   template <typename T>   void in_bin(T &x) {     x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) {       x <<= 1;       x |= ch & 1;       ch = getchar();     }   }   }  // namespace Bin   using namespace Bin;   struct Timer {     int val, pre;     Timer() {       pre = clock();       val = clock();     }     void operator()(int flg = 2) {       if (flg == 2) val = pre;       int now = clock();       if (flg != 0) std::cerr << now - val <<  ms n ;       if (flg != 1) val = now;       pre = now;     }   };   Timer Time;   struct Random {     mt19937 my_rand;     Random() {       srand((long long)new char);       my_rand.seed(rand());     }   };   Random __Rd;   template <typename T>   T rnd(T _l, T _r) {     T len = _r - _l + 1;     return __Rd.my_rand() % len + _l;   }   template <typename T>   void Max(T &x, T y) {     x < y && (x = y);   }   template <typename T>   void Min(T &x, T y) {     x > y && (x = y);   }   template <typename T, class Func>   void Max(T &x, T y, Func F) {     if (x < y) {       x = y;       F();     }   }   template <typename T, class Func>   void Min(T &x, T y, Func F) {     if (x > y) {       x = y;       F();     }   }   template <typename T>   T abss(T x) {     return x < 0 ? -x : x;   }   void File(string In, string Out) {     if (!In.empty()) freopen(In.c_str(),  r , stdin);     if (!Out.empty()) freopen(Out.c_str(),  w , stdout);   }   namespace Mod {   const int md = 998244353;   inline int add(const int &a, const int &b) {     int p = a + b;     if (p >= md) p -= md;     return p;   }   inline int sub(const int &a, const int &b) {     int p = a - b;     if (p < 0) p += md;     return p;   }   inline void add_(int &a, int b) {     a += b;     if (a >= md) a -= md;   }   inline void sub_(int &a, int b) {     a -= b;     if (a < 0) a += md;   }   inline int __mul(const int &a, const int &b) { return 1ll * a * b % md; }   inline int mul(const int &a, const int &b) {     int p = __mul(a, b);     if (p < 0) p += md;     return p;   }   template <typename T>   int qpow(int a, T b) {     int ret = 1;     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) ret = mul(ret, a);     return ret;   }   inline int inv(int x) { return qpow(x, md - 2); }   inline void inv(int *F, int len, int *G = NULL, bool flg = false) {     if (G == NULL) G = F;     if (flg) {       F[0] = G[0] = 1;       for (int i = 1; i <= len; ++i) F[i] = __mul(F[i - 1], i);     }     std::vector<int> S(len + 1), iS(len + 1);     S[0] = 1;     for (int i = 1; i <= len; ++i) S[i] = mul(S[i - 1], F[i]);     iS[len] = inv(S[len]);     for (int i = len; i >= 1; --i) {       iS[i - 1] = mul(iS[i], F[i]);       G[i] = mul(S[i - 1], iS[i]);     }   }   }  // namespace Mod   using namespace Mod;   namespace gvihvo {   const int N = 5010;   int n, k;   char s[N];   int C[N][N];   int sum[N];   int top;   pii stk[N];   void main() {     in(n, k);     if (k == 0) {       out(1);       return;     }     scanf( %s , s + 1);     int ans = 0;     for (int i = (0); i <= (n); ++i) {       C[i][0] = 1;       for (int j = (1); j <= (i); ++j)         C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);     }     for (int i = (1); i <= (n); ++i) sum[i] = sum[i - 1] + (s[i] ==  1 );     for (int i = 1, j = 1; i <= n; ++i) {       if (s[i - 1] ==  0 ) continue;       while (j + 1 <= n && sum[j + 1] - sum[i - 1] <= k) ++j;       if (sum[j] - sum[i - 1] != k) break;       stk[++top] = {i, j};     }     if (!top) {       out(1);       return;     }     for (int i = (1); i <= (top - 1); ++i) {       ans = add(ans, C[stk[i][1] - stk[i][0] + 1][k]);       if (stk[i][1] >= stk[i + 1][0]) {         ans = sub(ans, C[stk[i][1] - stk[i + 1][0] + 1]                         [sum[stk[i][1]] - sum[stk[i + 1][0] - 1]]);       } else         ans = sub(ans, 1);     }     ans = add(ans, C[stk[top][1] - stk[top][0] + 1][k]);     out(ans);   }   void init() { ; }   }  // namespace gvihvo   int main() {     gvihvo::init();     gvihvo::main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v[100005];   bool visit[100005];   int n;   vector<int> ans;   bool dfs(int i, int last) {     visit[i] = true;     bool flag = false;     for (int j = 0; j < v[i].size(); j++) {       if (!visit[v[i][j].first]) {         if (v[i][j].second == 2)           flag = flag | dfs(v[i][j].first, v[i][j].first);         else           flag = flag | dfs(v[i][j].first, 0);       }     }     if (flag == false && last != 0) {       flag = true;       ans.push_back(i);     }     return flag;   }   void Readinput() {     int i, x, y, t;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d , &x);       scanf( %d , &y);       scanf( %d , &t);       v[x].push_back(pair<int, int>(y, t));       v[y].push_back(pair<int, int>(x, t));     }   }   void solve() {     int i, j;     dfs(1, 0);     cout << ans.size() << endl;     for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     memset(visit, false, sizeof(visit));     Readinput();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int shuruHoJaa(long long int test) {     while (test--) {       long long int a, b, c, d;       cin >> a >> b >> c >> d;       long long int time = 0;       if (b >= a) {         cout << b;       } else if (c <= d) {         cout << -1;       } else {         time += b;         long long int tmp =             ((a - b) % (c - d) == 0 ? (a - b) / (c - d) : (a - b) / (c - d) + 1);         time += (tmp * (c));         cout << time;       }       cout <<   n ;     }     return 0;   }   int main(int argc, char const *argv[]) {     int t;     cin >> t;     shuruHoJaa(t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1010];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     int a0 = 0;     int a1 = 0;     int b0 = 0;     int b1 = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) {         if (i % 2)           b0++;         else           a0++;       } else {         if (i % 2)           b1++;         else           a1++;       }     }     int ans = min(a0 + b1, a1 + b0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, pl = 4, otv = 1;     cin >> n;     if (n > 1) {       for (long long i = 1; i < n; i++) {         otv = otv + pl;         pl += 4;       }     } else if (n == 1) {       otv = 1;     }     cout << otv;   }


#include <bits/stdc++.h>   using namespace std;   struct _ {     ios_base::Init i;     _() {       cin.sync_with_stdio(0);       cin.tie(0);     }   } _;   struct House {     int height;     int initial_position;   };   int main() {     int n;     cin >> n;     vector<House> houses;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       House h{x, i};       houses.push_back(h);     }     stable_sort(houses.begin(), houses.end(),                 [&](House h1, House h2) { return h1.height < h2.height; });     int up_to = 0;     int number_of_blocks = 0;     for (int i = 0; i < n; i++) {       int initial_position = houses[i].initial_position;       up_to = max(up_to, initial_position);       if (up_to == i) {         up_to++;         number_of_blocks++;       }     }     cout << number_of_blocks << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, freq[100123], pairs = 0;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> x;     long long v[n];     for (long long i = 0; i < n; i++) {       cin >> v[i];       freq[v[i]]++;     }     for (long long i = 0; i < 100123; i++)       if (freq[i] > 0)         if ((x ^ i) < 100123) pairs += freq[i] * (freq[(x ^ i)] - ((x ^ i) == i));     pairs /= 2;     cout << pairs << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Buffer_Size = 1 << 10;   char buffer[Buffer_Size], *ihead = buffer + Buffer_Size, *itail = ihead;   char Next_Char() {     if (ihead == itail) fread(buffer, 1, Buffer_Size, stdin), ihead = buffer;     return *ihead++;   }   template <typename T>   void read(T &n) {     n = 0;     char ch = Next_Char();     while (!isdigit(ch)) ch = Next_Char();     while (isdigit(ch)) {       n = (n << 3) + (n << 1) + (ch & 15);       ch = Next_Char();     }   }   long long r, c, n, k, tp, sum;   long long a[3002], cnt[3002], L[3002], R[3002];   vector<long long> v[3002];   struct Position {     long long x, y;   } p[3002];   bool Cmp(long long x, long long y) { return p[x].y < p[y].y; }   bool DFS(long long x, long long step) {     if (!step || !x) return 1;     if (!DFS(L[x], step - 1))       cnt[L[x]] = cnt[x];     else       cnt[L[x]] += cnt[x];     return 0;   }   int main() {     read(r), read(c), read(n), read(k);     for (long long i = 1; i <= n; ++i) {       read(p[i].x), read(p[i].y);       v[p[i].x].push_back(i);     }     long long ans = 0;     for (long long i = 1; i <= r; ++i) {       tp = sum = 0;       for (long long j = 1; j <= n; ++j)         if (p[j].x >= i) a[++tp] = j;       sort(a + 1, a + tp + 1, Cmp);       a[tp + 1] = n + 1;       memset(cnt, 0, sizeof(cnt));       memset(L, 0, sizeof(L));       memset(R, 0, sizeof(R));       long long now = 0;       for (long long j = 1; j <= c; ++j) {         while (p[a[now + 1]].y == j && now < tp) {           ++now;           L[a[now]] = a[now - 1], R[a[now]] = a[now + 1];         }         long long tmp = a[now];         for (long long l = 1; l < k; ++l) tmp = L[tmp];         ++cnt[tmp];       }       for (long long j = 1; j <= tp; ++j) sum += p[a[j]].y * cnt[a[j]];       ans += sum;       for (long long j = r; j >= i + 1; --j) {         long long sz = (long long)v[j].size();         for (long long l = 0; l < sz; ++l) {           long long x = v[j][l], q = x;           for (long long o = 1; o <= k; ++o) {             sum -= (p[x].y - p[L[x]].y) * cnt[x];             x = L[x];             if (!x) break;           }           x = q;           DFS(x, k);           x = q;           L[R[x]] = L[x], R[L[x]] = R[x];         }         ans += sum;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[200020], b[200020];   int x, y, c, d;   int n;   int mx[200020];   int calc(pair<int, int> a[], int len, int val) {     for (int i = 1; i <= len; ++i) {       mx[i] = max(mx[i - 1], a[i].second);     }     int ret = 0;     for (int i = len, j = 1; i >= 1; --i) {       while (j <= len && a[j].first + a[i].first <= val) {         ++j;       }       if (j > 1 && i > 1) ret = max(ret, a[i].second + mx[min(j - 1, i - 1)]);     }     return ret;   }   int main() {     scanf( %d%d%d , &n, &c, &d);     for (int i = 1; i <= n; ++i) {       int u, v;       char op[5];       scanf( %d%d%s , &u, &v, op);       if (op[0] ==  C )         a[++x] = make_pair(v, u);       else         b[++y] = make_pair(v, u);     }     sort(a + 1, a + x + 1);     sort(b + 1, b + y + 1);     int ans = calc(a, x, c);     ans = max(ans, calc(b, y, d));     int mx1 = -1, mx2 = -1;     for (int i = 1; i <= x; ++i)       if (a[i].first <= c) mx1 = max(mx1, a[i].second);     for (int i = 1; i <= y; ++i)       if (b[i].first <= d) mx2 = max(mx2, b[i].second);     if (mx1 != -1 && mx2 != -1) ans = max(ans, mx1 + mx2);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 2;   long long int i, j, n, m, s, ans = 0, cnt = 0;   vector<pair<long long int, long long int> > nf;   vector<long long int> graph[maxn];   bool foundd[maxn];   void dfs(long long int u, bool found[]) {     if (!foundd[u]) ++ans;     found[u] = true;     vector<long long int>::iterator it;     for (it = graph[u].begin(); it != graph[u].end(); ++it) {       if (!found[*it]) dfs(*it, found);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> s;     bool found[5200], isreachable[5200];     for (i = 0; i < m; ++i) {       long long int u, v;       cin >> u >> v;       graph[u].push_back(v);     }     memset(found, false, sizeof(found));     dfs(s, found);     for (i = 1; i <= n; ++i) foundd[i] = found[i];     for (i = 1; i <= n; ++i) {       if (!foundd[i]) {         bool found1[5001];         memset(found1, false, sizeof(found1));         ans = 0;         dfs(i, found1);         nf.push_back(make_pair(ans, i));       }     }     sort(nf.begin(), nf.end(), greater<pair<long long int, long long int> >());     for (i = 0; i < nf.size(); ++i) {       if (!foundd[nf[i].second]) {         bool found1[5001];         memset(found1, false, sizeof(found1));         dfs(nf[i].second, found1);         ++cnt;         for (j = 1; j <= n; ++j)           if (found1[j]) foundd[j] = true;       }     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   void read(int &a) {     a = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       c = getchar();     }     while (c >=  0  && c <=  9 ) {       a = (a << 1) + (a << 3) + c -  0 ;       c = getchar();     }   }   int Set(int n, int pos) { return n = n | (1LL << pos); }   int reset(int n, int pos) { return n = n & ~(1LL << pos); }   bool check(int n, int pos) { return (bool)(n & (1LL << pos)); }   int mul(int a, int b) {     int c;     c = (a % 1000000007 * b % 1000000007) % 1000000007;     return c;   }   int add(int a, int b) {     int c;     c = (a % 1000000007 + b % 1000000007) % 1000000007;     return c;   }   int sub(int a, int b) {     int c;     c = ((a % 1000000007 - b % 1000000007) % 1000000007 + 1000000007) %         1000000007;     return c;   }   int power(int x, int y) {     int res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long exgcd(long long x, long long y, long long &a, long long &b) {     int flag = 0;     long long t, la = 1, lb = 0, ra = 0, rb = 1;     while (x % y) {       if (flag == 0)         la -= x / y * ra, lb -= x / y * rb;       else         ra -= x / y * la, rb -= x / y * lb;       t = x, x = y, y = t % y;       flag = 1 - flag;     }     if (flag == 0)       a = ra, b = rb;     else       a = la, b = lb;     return y;   }   int n, m, k, r;   vector<int> rooms[200005];   vector<pair<int, int> > graph[200005];   int st[200005];   int col[200005];   deque<int> q;   bool bfs(int ma_src) {     q.clear();     col[ma_src] = 0;     q.push_back(ma_src);     while (!q.empty()) {       int u = q.front();       q.pop_front();       for (int i = 0; i < graph[u].size(); i++) {         int v = graph[u][i].first;         int _v = graph[u][i].second;         if (col[v] == -1) {           if (_v == 1)             col[v] = col[u];           else             col[v] = col[u] ^ 1;           q.push_back(v);         } else {           if (_v == 1) {             if (col[v] != col[u]) return 0;           } else {             if (col[v] == col[u]) return 0;           }         }       }     }     return 1;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &st[i]);     for (int i = 1; i <= m; i++) {       scanf( %d , &k);       for (int j = 1; j <= k; j++) {         scanf( %d , &r);         rooms[r].push_back(i);       }     }     for (int i = 1; i <= n; i++) {       int u = rooms[i][0];       int v = rooms[i][1];       graph[u].push_back(pair<int, int>(v, st[i]));       graph[v].push_back(pair<int, int>(u, st[i]));     }     memset((col), (-1), sizeof(col));     int ans = 1;     for (int i = 1; i <= m; i++) {       if (col[i] == -1) ans = ans & bfs(i);     }     if (!ans)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, sum = 0, i, j, n, cnt = 0;     int a[20] = {0}, value;     string s;     cin >> k;     cin >> s;     for (i = 0; i < ((int)s.size()); ++i) {       n = s[i] -  0 ;       sum += n;       a[n]++;     }     if (sum >= k) {       cout << cnt << endl;       return 0;     }     for (i = 0; i < 10; ++i) {       value = 9 - i;       for (j = 1; j <= a[i]; ++j) {         sum += value;         cnt++;         if (sum >= k) {           cout << cnt << endl;           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long x, y;   int main() {     ios_base::sync_with_stdio(0);     ;     cin >> x >> y;     if ((long long)sqrt(x * x + y * y + 0.5) == sqrt(x * x + y * y)) {       cout <<  black             <<   n ;       return 0;     }     long long d = sqrt(x * x + y * y);     if ((x > 0 && y > 0) || (x < 0 && y < 0)) {       if (d % 2 == 0)         cout <<  black               <<   n ;       else         cout <<  white               <<   n ;     } else {       if (d % 2 == 0)         cout <<  white               <<   n ;       else         cout <<  black               <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef pair<int,int> pii;   typedef vector<int> vi;   typedef vector<vi> vvi;   typedef vector<ll> vl;   typedef vector<vl> vvl;   typedef vector<string> vs;   typedef vector<vs> vvs;   typedef vector<pii> vpii;   typedef set<int> si;   typedef unordered_set<int> usi;   typedef multiset<int> msi;   typedef map<int,int> mi;   typedef unordered_map<int,int> umi;   typedef multimap<int,int> mmi;      #define f1(a,b,c) for(int(a)=(b);(a)<(c);(a)++)   #define f2(a,b,c) for(int(a)=(b);(a)<=(c);(a)++)   #define f3(a,b,c) for(int(a)=(b);(a)>(c);(a)--)   #define f4(a,b,c) for(int(a)=(b);(a)>=(c);(a)--)   #define fi(a,b) for(auto(a)=b.begin();(a)!=b.end();(a)++)   #define pb push_back   #define all(v) v.begin(),v.end()   #define nper next_permutation   #define pper prev_permutation   #define mp make_pair   #define F first   #define S second      int main()   {    ios_base::sync_with_stdio(false);    cin.tie(NULL);    int t;    cin>>t;    f1(i,0,t)    {     int n,k,x=1;     cin>>n>>k;     f1(j,0,(2*k)-n-1)     {      cout<<x<<   ;x++;     }     x=k;     f1(j,0,n-k+1)     {      cout<<x<<   ;x--;     }     cout<<  n ;    }    /*f1(i,0,t)    {     cout<<v[i]<<  n ;    }*/    return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return x * f;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     putchar(  n );   }   inline void wri(long long x) {     write(x);     putchar(   );   }   const int maxn = 1e5 + 233;   const int mod = 1e9 + 7;   int f[maxn];   int main() {     int n = read(), m = read();     f[0] = 1;     f[1] = 1;     for (register int i = (2); i <= int(maxn - 1); ++i)       f[i] = (f[i - 1] + f[i - 2]) % mod;     writeln(2ll * (f[n] + f[m] - 1) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   int vis1[MAXN], vis2[MAXN], dis[MAXN];   int st, ed, n, ans;   queue<int> q;   vector<int> G[MAXN];   void Bfs1() {     for (; !q.empty();) q.pop();     q.push(1);     vis1[1] = 1;     for (; !q.empty();) {       int u = q.front();       q.pop();       for (auto v : G[u]) {         if (vis1[v]) continue;         q.push(v);         vis1[v] = u;       }       st = u;     }   }   void Bfs2() {     for (; !q.empty();) q.pop();     q.push(st);     vis2[st] = st;     for (; !q.empty();) {       int u = q.front();       q.pop();       for (auto v : G[u]) {         if (vis2[v]) continue;         q.push(v);         vis2[v] = u;       }       ed = u;     }   }   int degree(int x) { return (int)G[x].size(); }   bool check(int root) {     int Tim = 0;     for (int i = 1; i <= n; i++) vis1[i] = dis[i] = 0;     for (; !q.empty();) q.pop();     q.push(root);     vis1[root] = 1;     for (; !q.empty();) {       int u = q.front();       q.pop();       for (auto v : G[u]) {         if (vis1[v]) continue;         if (++Tim == n) {         }         q.push(v);         vis1[v] = vis1[u] + 1;         if (!dis[vis1[v]]) dis[vis1[v]] = v;         if (degree(v) != degree(dis[vis1[v]])) return false;       }     }     ans = root;     return true;   }   bool checkCenter() {     int Tim = 0;     int D = 0;     for (int u = ed; u != st; u = vis2[u]) D++;     if (D & 1) return false;     int center = ed;     for (int i = 0; i != D / 2; i++, center = vis2[center])       ;     if (check(center)) return true;     for (int i = 1; i <= n; i++) vis1[i] = dis[i] = 0;     for (; !q.empty();) q.pop();     q.push(center);     vis1[center] = 1;     for (; !q.empty();) {       int u = q.front();       q.pop();       for (auto v : G[u]) {         if (vis1[v]) continue;         if (++Tim == n) {         }         q.push(v);         vis1[v] = vis1[u] + 1;         if (!dis[vis1[v]]) dis[vis1[v]] = v;         if (degree(v) != degree(dis[vis1[v]])) {           for (int x = v, tim = 0;;) {             if (++tim == n) break;             if (G[x].size() == 1) {               if (check(x))                 return true;               else                 break;             } else               x = (vis1[G[x][0]] == 0) ? G[x][0] : G[x][1];           }           for (int x = dis[vis1[v]], tim = 0;;) {             if (++tim == n) break;             if (G[x].size() == 1) {               if (check(x))                 return true;               else                 break;             } else               x = (vis1[G[x][0]] == 0) ? G[x][0] : G[x][1];           }           return false;         }       }     }     ans = center;     return true;   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     Bfs1();     Bfs2();     if (check(st) || check(ed))       cout << ans;     else if (checkCenter())       cout << ans;     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   long long K[5], T[5];   int main() {     queue<pair<long long, long long> > Q[5][2];     string ln;     int n;     getline(cin, ln);     istringstream(ln) >> K[1] >> K[2] >> K[3];     getline(cin, ln);     istringstream(ln) >> T[1] >> T[2] >> T[3];     getline(cin, ln);     istringstream(ln) >> n;     getline(cin, ln);     istringstream in(ln);     long long t0;     for (int i = 0; i < n; i++) {       in >> t0;       Q[1][0].push(pair<long long, long long>(t0, t0));     }     long long t = 0;     for (int i = 1; i <= 3; i++) {       while (Q[i][0].size()) {         t = Q[i][0].front().first;         t = max(t, Q[i][0].front().first);         t0 = Q[i][0].front().second;         Q[i][0].pop();         if (Q[i][1].size() < K[i]) {           Q[i][1].push(pair<long long, long long>(t + T[i], t0));         } else {           t = max(Q[i][1].front().first, t);           Q[i + 1][0].push(Q[i][1].front());           Q[i][1].pop();           Q[i][1].push(pair<long long, long long>(t + T[i], t0));         }       }       while (Q[i][1].size()) {         Q[i + 1][0].push(Q[i][1].front());         Q[i][1].pop();       }     }     long long res = 0;     while (Q[4][0].size()) {       res = max(res, Q[4][0].front().first - Q[4][0].front().second);       Q[4][0].pop();     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     while ((c <  0  || c >  9 ) && c -  - ) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c - 48;       c = getchar();     }     return x * f;   }   const int N = 3e5 + 10;   int n, rev[N];   long long f[N], g[N], jc[N], inv[N], z[N];   const long long mo = 998244353, Gi = 3;   inline long long qp(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mo;       a = (a * a) % mo;       b >>= 1;     }     return ans;   }   int lim = 1, l = 0;   inline void ntt(long long a[], int pan) {     for (int i = 0; i < lim; i++)       if (i > rev[i]) swap(a[i], a[rev[i]]);     for (int bj = 1; bj < lim; bj <<= 1) {       long long wn = qp(Gi, (mo - 1) / (bj << 1));       if (pan) wn = qp(wn, mo - 2);       for (int ks = 0; ks < lim; ks += (bj << 1)) {         long long w = 1;         for (int i = 0; i < bj; i++, w = (w * wn) % mo) {           long long x = a[ks + i], y = w * a[ks + i + bj] % mo;           a[ks + i] = (x + y) % mo;           a[ks + i + bj] = ((x - y) % mo + mo) % mo;         }       }     }     if (pan) {       long long ni = qp(lim, mo - 2);       for (int i = 0; i < lim; i++) a[i] = (a[i] * ni) % mo;     }   }   void gao(int t) {     if (t == 1) {       f[1] = 1;       return;     }     int mi = t / 2;     gao(mi);     for (int i = 0; i <= mi; i++) z[i] = f[i], f[i] = f[i] * jc[i] % mo;     long long c = mi, gu = 1;     g[mi] = inv[0];     for (int i = mi - 1; i >= 0; i--) {       gu = (gu * c) % mo;       g[i] = gu * inv[mi - i] % mo;     }     lim = 1, l = 0;     while (lim <= (mi << 1)) lim <<= 1, l++;     for (int i = 0; i < lim; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1);     ntt(f, 0);     ntt(g, 0);     for (int i = 0; i < lim; i++) f[i] = (f[i] * g[i]) % mo, g[i] = 0;     ntt(f, 1);     long long ji = f[mi];     for (int i = mi; i >= 1; i--) {       f[i] = f[i + mi];       f[i + mi] = 0;     }     f[0] = ji;     for (int i = 0; i <= mi; i++) f[i] = (f[i] * inv[i]) % mo;     lim = 1, l = 0;     while (lim <= (mi << 1)) lim <<= 1, l++;     for (int i = 0; i < lim; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1);     ntt(z, 0);     ntt(f, 0);     for (int i = 0; i < lim; i++) z[i] = (z[i] * f[i]) % mo;     ntt(z, 1);     for (int i = 0; i < lim; i++) f[i] = z[i], z[i] = 0;     if (t % 2) {       z[0] = (f[0] * (t - 1)) % mo;       for (int i = 1; i <= (mi << 1) + 1; i++)         z[i] = (f[i - 1] + (f[i] * (t - 1))) % mo;       for (int i = 1; i <= (mi << 1) + 1; i++) f[i] = z[i], z[i] = 0;     }   }   int A, B;   int main() {     jc[0] = inv[0] = 1;     for (int i = 1; i <= N - 10; i++) jc[i] = (jc[i - 1] * i) % mo;     inv[N - 10] = qp(jc[N - 10], mo - 2);     for (int i = N - 11; i >= 1; i--) inv[i] = (inv[i + 1] * (i + 1)) % mo;     n = read();     A = read();     B = read();     if (n == 1) {       if (A + B == 2)         cout <<  1 n ;       else         cout <<  0 n ;       return 0;     }     if (!A || !B || A + B > n + 1) {       cout <<  0 n ;       return 0;     }     gao(n - 1);     cout << f[A + B - 2] * jc[A + B - 2] % mo * inv[A - 1] % mo * inv[B - 1] % mo          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double PI = acos(-1.);   const int MXN = 200005;   const int MOD = 1000000000;   int a[MXN], n, m;   long long fib[MXN];   long long prefib[MXN];   struct SEG {     int l, r;     long long lazy;     long long g[2];     SEG() {}     SEG(int _l, int _r) { l = _l, r = _r; }   } SGT[MXN << 2];   void create(SEG &T, int t) {     T.lazy = 0;     T.g[0] = T.g[1] = a[t];   }   void fresh(SEG &T, SEG &L, SEG &R) {     int left = L.r - L.l + 1;     T.lazy = 0;     if (left == 1) {       T.g[0] = (L.g[0] + R.g[1]) % MOD;       T.g[1] = (L.g[0] + R.g[0] + R.g[1]) % MOD;       return;     }     T.g[0] =         (L.g[0] + fib[left - 2] * R.g[0] % MOD + fib[left - 1] * R.g[1] % MOD) %         MOD;     T.g[1] =         (L.g[1] + fib[left - 1] * R.g[0] % MOD + fib[left] * R.g[1] % MOD) % MOD;   }   void build(int id, int l, int r) {     SGT[id] = SEG(l, r);     int mid = (l + r) / 2;     if (l != r) {       build(id * 2, l, mid);       build(id * 2 + 1, mid + 1, r);       fresh(SGT[id], SGT[id << 1], SGT[id << 1 | 1]);     } else       create(SGT[id], l);   }   void update(int id, int l, int r, long long w) {     SEG &T = SGT[id];     int mid = (T.l + T.r) / 2;     if (T.l == l && T.r == r) {       T.lazy = (T.lazy + w) % MOD;       T.g[0] = (T.g[0] + w * prefib[T.r - T.l] % MOD) % MOD;       T.g[1] = (T.g[1] + w * (prefib[T.r - T.l + 1] - 1) % MOD) % MOD;       return;     }     if (T.lazy) {       update(id << 1, T.l, mid, T.lazy);       update(id << 1 | 1, mid + 1, T.r, T.lazy);       T.lazy = 0;     }     if (r <= mid)       update(id << 1, l, r, w);     else if (l > mid)       update(id << 1 | 1, l, r, w);     else {       update(id << 1, l, mid, w);       update(id << 1 | 1, mid + 1, r, w);     }     fresh(T, SGT[id << 1], SGT[id << 1 | 1]);   }   long long single(int id, int t) {     SEG &T = SGT[id];     int mid = (T.l + T.r) / 2;     if (T.l == T.r) return T.g[0];     if (t <= mid)       return T.lazy + single(id << 1, t);     else       return T.lazy + single(id << 1 | 1, t);   }   void query(int id, SEG &A) {     SEG &T = SGT[id];     int mid = (T.l + T.r) / 2;     if (A.l == T.l && A.r == T.r) {       A = T;       return;     }     if (T.lazy && T.l != T.r) {       update(id << 1, T.l, mid, T.lazy);       update(id << 1 | 1, mid + 1, T.r, T.lazy);       T.lazy = 0;     }     if (A.r <= mid)       query(id << 1, A);     else if (A.l > mid)       query(id << 1 | 1, A);     else {       SEG L(A.l, mid), R(mid + 1, A.r);       query(id << 1, L);       query(id << 1 | 1, R);       fresh(A, L, R);     }   }   int main() {     int i, j;     fib[0] = 1;     fib[1] = 1;     for (i = 2; i < MXN; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;     prefib[0] = 1;     for (i = 1; i < MXN; i++) prefib[i] = (prefib[i - 1] + fib[i]) % MOD;     while (~scanf( %d%d , &n, &m)) {       for (i = 1; i <= n; i++) scanf( %d , &a[i]);       build(1, 1, n);       while (m--) {         int q;         scanf( %d , &q);         if (q == 1) {           int x, v;           scanf( %d%d , &x, &v);           long long tp = single(1, x);           update(1, x, x, v - tp);         }         if (q == 2) {           int l, r;           scanf( %d%d , &l, &r);           SEG A(l, r);           query(1, A);           printf( %I64d n , ((A.g[0] % MOD) + MOD) % MOD);         }         if (q == 3) {           int l, r, d;           scanf( %d%d%d , &l, &r, &d);           update(1, l, r, d);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   const char vow[] = { a ,  e ,  i ,  o ,  u ,  y };   char str[maxn];   bool check(char ch) {     for (int i = 0; i < 6; ++i) {       if (ch == vow[i]) return true;     }     return false;   }   int main() {     int n;     while (~scanf( %d , &n)) {       scanf( %s , str);       for (int i = 0; i < n; ++i) {         if (check(str[i])) {           for (int j = i + 1; j < n; ++j) {             if (str[i] == 0) continue;             if (check(str[j]))               str[j] = 0;             else               break;           }         }       }       for (int i = 0; i < n; ++i) {         if (str[i]) putchar(str[i]);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-11;   void fast() { std::ios_base::sync_with_stdio(0); }   vector<vector<int>> seq(1e5 + 9);   int main() {     int n, x;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       seq[x].push_back(i);     }     bool flag = true;     vector<pair<int, int>> ans;     for (int i = 0; i <= 1e5; i++) {       flag = true;       if (seq[i].size() == 0)         continue;       else if (seq[i].size() == 1)         ans.push_back({i, 0});       else if (seq[i].size() == 2)         ans.push_back({i, seq[i][1] - seq[i][0]});       else {         for (int j = 2; j < seq[i].size() && flag; j++) {           if (seq[i][j] - seq[i][j - 1] != seq[i][j - 1] - seq[i][j - 2])             flag = false;         }         if (flag) {           ans.push_back({i, seq[i][1] - seq[i][0]});         }       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   typedef long long LL;   const double INF = 1e100;   const int oo = ~0u >> 2;   const double pi = acos(-1.0);   const double EPS = 1e-8;   const int MAXN = 100033;   double a, b, c;   double x11, x2;   int main() {     scanf( %lf%lf%lf , &a, &b, &c);     x11 = sqrt(b * b - 4.0 * a * c);     if (a > 0) {       x2 = (-b - x11) / 2.0 / a;       x11 = (-b + x11) / 2.0 / a;     } else {       x2 = (-b + x11) / 2.0 / a;       x11 = (-b - x11) / 2.0 / a;     }     printf( %.012lf n%.012lf n , x11, x2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long t;     cin >> t;     while (t--) {       vector<long long> A(3);       for (auto &a : A) cin >> a;       sort((A).begin(), (A).end(), greater<long long>());       long long a, b, c;       a = A[0];       b = A[1];       c = A[2];       long long ans = 0;       if (a > 0) {         a--;         ans++;       }       if (b > 0) {         b--;         ans++;       }       if (c > 0) {         c--;         ans++;       }       if (a > 0 && b > 0) {         a--;         b--;         ans++;       }       if (c > 0 && b > 0) {         c--;         b--;         ans++;       }       if (a > 0 && c > 0) {         a--;         c--;         ans++;       }       if (a > 0 && b > 0 && c > 0) {         a--;         b--;         c--;         ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       long long int r, n, c, m, i, j, count = 0, x, a, b, y, sum = 0;       long long int mn = 1e18, mx = 0, ans = 0, k, ind;       long long int br = 0, T, rz = 0;       string s =   ;       cin >> n;       long long int a1, a2, a3, b1, b2, b3;       cin >> a1 >> a2 >> a3;       cin >> b1 >> b2 >> b3;       mx = max(mx, a1 - b1 - b3);       mx = max(mx, a2 - b1 - b2);       mx = max(mx, a3 - b2 - b3);       mn = 0;       mn += min(a1, b2);       mn += min(a2, b3);       mn += min(a3, b1);       cout << mx <<     << mn << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void open(const char *s) {}   inline int rd() {     static int x, f;     x = 0;     f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return f > 0 ? x : -x;   }   const int N = 1000010;   int R, C, n, rt = 0, Lr;   vector<int> a[N];   pair<int, int> b[N];   namespace LCT {   struct tree {     int ch[2], fa, rev;     tree() { ch[0] = ch[1] = fa = rev = 0; }   } tr[N];   int cnt = 0;   inline bool isrt(int x) {     return tr[tr[x].fa].ch[0] != x && tr[tr[x].fa].ch[1] != x;   }   inline void pushdown(int x) {     if (!tr[x].rev) return;     swap(tr[x].ch[0], tr[x].ch[1]);     if (tr[x].ch[0]) tr[tr[x].ch[0]].rev ^= 1;     if (tr[x].ch[1]) tr[tr[x].ch[1]].rev ^= 1;     tr[x].rev = 0;   }   inline void clr(int x) {     static int st[N], tt;     for (st[tt = 1] = x; !isrt(x); x = tr[x].fa) st[++tt] = tr[x].fa;     while (tt) pushdown(st[tt--]);   }   inline void rotate(int x) {     static int y, z, t1, t2;     y = tr[x].fa;     z = tr[y].fa;     t1 = tr[y].ch[1] == x;     t2 = t1 ^ 1;     if (!isrt(y)) tr[z].ch[tr[z].ch[1] == y] = x;     tr[x].fa = z;     tr[y].fa = x;     if (tr[x].ch[t2]) tr[tr[x].ch[t2]].fa = y;     tr[y].ch[t1] = tr[x].ch[t2];     tr[x].ch[t2] = y;   }   inline void splay(int x) {     for (clr(x); !isrt(x); rotate(x)) {       int y = tr[x].fa, z = tr[y].fa;       if (isrt(y)) continue;       if ((tr[y].ch[0] == x) ^ (tr[z].ch[0] == y))         rotate(x);       else         rotate(y);     }   }   inline void access(int x) {     for (int s = 0; x; s = x, x = tr[x].fa) {       splay(x);       tr[x].ch[1] = s;     }   }   inline void makert(int x) {     access(x);     splay(x);     tr[x].rev ^= 1;   }   inline int findrt(int x) {     access(x);     splay(x);     pushdown(x);     while (tr[x].ch[0]) x = tr[x].ch[0], pushdown(x);     return x;   }   inline void link(int x, int y) {     makert(x);     access(y);     splay(y);     tr[x].fa = y;   }   inline void cut(int x, int y) {     makert(y);     access(x);     splay(x);     tr[tr[x].ch[0]].fa = 0;     tr[x].ch[0] = 0;   }   }  // namespace LCT   namespace Seg {   struct tree {     int ls, rs, mx, cmx, tag;     tree() { ls = rs = mx = cmx = tag = 0; }   } tr[N << 1];   int cnt = 0;   inline void pushup(int o) {     tr[o].mx = max(tr[tr[o].ls].mx, tr[tr[o].rs].mx);     tr[o].cmx = 0;     if (tr[o].mx == tr[tr[o].ls].mx) tr[o].cmx += tr[tr[o].ls].cmx;     if (tr[o].mx == tr[tr[o].rs].mx) tr[o].cmx += tr[tr[o].rs].cmx;   }   inline void pushdown(int o) {     if (!tr[o].tag) return;     static int ls, rs;     ls = tr[o].ls, rs = tr[o].rs;     tr[ls].mx += tr[o].tag;     tr[ls].tag += tr[o].tag;     tr[rs].mx += tr[o].tag;     tr[rs].tag += tr[o].tag;     tr[o].tag = 0;   }   void build(int &o, int l, int r) {     o = ++cnt;     if (l == r) return tr[o].mx = l, tr[o].cmx = 1, void();     int mid = (l + r) >> 1;     build(tr[o].ls, l, mid);     build(tr[o].rs, mid + 1, r);     pushup(o);   }   void modify(int o, int l, int r, int L, int R, int d) {     if (l == L && r == R) return tr[o].mx += d, tr[o].tag += d, void();     pushdown(o);     int mid = (l + r) >> 1;     if (L <= mid) modify(tr[o].ls, l, mid, L, min(mid, R), d);     if (R > mid) modify(tr[o].rs, mid + 1, r, max(mid + 1, L), R, d);     pushup(o);   }   pair<int, int> query(int o, int l, int r, int L, int R) {     if (l == L && r == R) return pair<int, int>(tr[o].mx, tr[o].cmx);     pushdown(o);     int mid = (l + r) >> 1;     pair<int, int> res = pair<int, int>(0, 0), tmp;     if (L <= mid) res = query(tr[o].ls, l, mid, L, min(mid, R));     if (R > mid) {       tmp = query(tr[o].rs, mid + 1, r, max(mid + 1, L), R);       if (res.first == tmp.first)         res.second += tmp.second;       else         res = max(res, tmp);     }     return res;   }   }  // namespace Seg   inline bool check(int p) {     static int d[5], tt, x, y;     tt = 0;     x = b[p].first, y = b[p].second;     if (x > 1 && a[x - 1][y] >= Lr && a[x - 1][y] < p)       d[++tt] = LCT::findrt(a[x - 1][y]);     if (y > 1 && a[x][y - 1] >= Lr && a[x][y - 1] < p)       d[++tt] = LCT::findrt(a[x][y - 1]);     if (x < R && a[x + 1][y] >= Lr && a[x + 1][y] < p)       d[++tt] = LCT::findrt(a[x + 1][y]);     if (y < C && a[x][y + 1] >= Lr && a[x][y + 1] < p)       d[++tt] = LCT::findrt(a[x][y + 1]);     sort(d + 1, d + tt + 1);     for (int i = 1; i <= tt - 1; i++)       if (d[i] == d[i + 1]) return 0;     return 1;   }   inline void del(int p) {     static int x, y;     x = b[p].first, y = b[p].second;     if (x > 1 && a[x - 1][y] >= p) LCT::cut(a[x - 1][y], p);     if (y > 1 && a[x][y - 1] >= p) LCT::cut(a[x][y - 1], p);     if (x < R && a[x + 1][y] >= p) LCT::cut(a[x + 1][y], p);     if (y < C && a[x][y + 1] >= p) LCT::cut(a[x][y + 1], p);   }   inline void gao(int p) {     static int x, y;     for (; !check(p); ++Lr) del(Lr);     x = b[p].first, y = b[p].second;     if (x > 1 && a[x - 1][y] >= Lr && a[x - 1][y] < p) {       LCT::link(a[x - 1][y], p);       Seg::modify(rt, 1, n, 1, a[x - 1][y], 1);     }     if (y > 1 && a[x][y - 1] >= Lr && a[x][y - 1] < p) {       LCT::link(a[x][y - 1], p);       Seg::modify(rt, 1, n, 1, a[x][y - 1], 1);     }     if (x < R && a[x + 1][y] >= Lr && a[x + 1][y] < p) {       LCT::link(a[x + 1][y], p);       Seg::modify(rt, 1, n, 1, a[x + 1][y], 1);     }     if (y < C && a[x][y + 1] >= Lr && a[x][y + 1] < p) {       LCT::link(a[x][y + 1], p);       Seg::modify(rt, 1, n, 1, a[x][y + 1], 1);     }   }   int main() {     open( hh );     R = rd();     C = rd();     for (int i = 1; i <= R; i++) {       a[i].resize(C + 1);       for (int j = 1; j <= C; j++) b[a[i][j] = rd()] = pair<int, int>(i, j);     }     n = R * C;     Seg::build(rt, 1, n);     Lr = 1;     long long ans = 1;     for (int i = 2; i <= n; i++) {       gao(i);       pair<int, int> res = Seg::query(rt, 1, n, Lr, i);       ans += res.first == i ? res.second : 0;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ntest = 0, test = 0;   inline void init();   inline void run();   inline void stop() { ntest = test - 1; }   int main() {     init();     while (++test <= ntest) {       run();     }     return 0;   }   const int INF = (int)1E9 + 5;   const double EPS = 1E-11;   const long long MOD = (long long)1E9 + 7;   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   inline void init() { ntest = 1; }   long long mu(long long a, long long n) {     long long rs = 1;     for (; n; n >>= 1) {       if (n & 1) rs = (rs * a) % MOD;       a = (a * a) % MOD;     }     return rs;   }   vector<int> a;   inline void run() {     int n, k;     cin >> n >> k;     a.resize(n);     for (int i = 0; i < (n); i++) cin >> a[i];     if (k == 0) {       for (int i = 0; i < (n); i++) cout << a[i] <<    ;       return;     }     for (int i = 0; i < (n); i++) {       long long total = a[i];       long long cur = 1;       for (int j = (1); j <= (i); j++) {         cur = (cur * (k + j - 1)) % MOD;         cur = (cur * mu(j, MOD - 2)) % MOD;         total = (total + (cur * a[i - j]) % MOD) % MOD;       }       cout << total <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long LL_INF = (long long)9.22e18;   string s;   int main() {     cin >> s;     bool isFirst = true;     int cnt = 0;     for (char ch : s) {       if (ch ==  1  && isFirst) {         isFirst = false;         continue;       }       if (ch ==  0  && !isFirst) {         cnt++;       }     }     if (cnt >= 6 && !isFirst) {       cout <<  yes  << endl;     } else {       cout <<  no  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int ans, pre, cnt;   int main() {     cin >> s;     for (int i = 0; i < s.size(); i++) {       pre += s[i] -  0 ;       cnt++;       if (cnt == 3 || (s[i] -  0 ) % 3 == 0 || pre % 3 == 0)         ans++, pre = 0, cnt = 0;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using pii = pair<int, int>;   using UI = unsigned int;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const double EPS = 1e-8;   const double PI = acos(-1.0);   const int N = 5e5 + 10;   const int M = N + (1 << 20);   int n, a[N][2];   int deg[1 << 20];   bool vis[N << 1];   vector<pii> G[M];   vector<int> ans;   void dfs(int x, int idx) {     pii p;     while (G[x].size()) {       p = G[x].back();       G[x].pop_back();       if (!vis[p.second]) {         vis[p.second] = 1;         dfs(p.first, p.second);       }     }     if (idx != -1) {       ans.emplace_back(idx);     }   }   void add_edge(int x, int y, int idx) {     G[x].emplace_back(y, idx);     G[y].emplace_back(x, idx);   }   bool ok(int k) {     int mask = (1 << k) - 1;     for (int i = (0); i < ((1 << k)); ++i) {       deg[i] = 0;     }     for (int i = (0); i < ((1 << k) + n); ++i) {       G[i].clear();     }     int x, y, z;     int offset = 1 << k;     for (int i = (0); i < (n); ++i) {       x = a[i][0] & mask;       y = a[i][1] & mask;       deg[x] += 1;       deg[y] += 1;       add_edge(x, i + offset, i << 1);       add_edge(y, i + offset, i << 1 | 1);     }     for (int i = (0); i < (1 << k); ++i) {       if (deg[i] & 1) return 0;     }     for (int i = (0); i < (n << 1); ++i) {       vis[i] = 0;     }     ans.clear();     for (int i = (0); i < (n + (1 << k)); ++i) {       if (G[i].size()) {         dfs(i, -1);         break;       }     }     if (ans.size() < n * 2) {       return 0;     }     printf( %d n , k);     for (int i = (0); i < (ans.size()); ++i) {       printf( %d  , ans[i] + 1);     }     puts(  );     return 1;   }   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) {       scanf( %d %d , &a[i][0], &a[i][1]);     }     for (int i = (20); i > (0); --i) {       if (ok(i)) {         return 0;       }     }     puts( 0 );     for (int i = (1); i < (n + 1); ++i) {       printf( %d %d  , i * 2 - 1, i * 2);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int tinf = (int)1e9 + 7;   const long long inf = (long long)1e18 + 7;   const int N = 1e5 + 5;   long long n, x[10000], y[10000], ans;   int main() {     {       ios ::sync_with_stdio(false);       cin.tie(0);     }     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     for (int i = 1; i < n - 1; i++)       if (y[i] > y[i - 1] && x[i + 1] < x[i])         ans++;       else if (y[i] < y[i - 1] && x[i + 1] > x[i])         ans++;       else if (x[i] > x[i - 1] && y[i + 1] > y[i])         ans++;       else if (x[i] < x[i - 1] && y[i + 1] < y[i])         ans++;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long second = 0;     int r, m;     cin >> m >> r;     long long koef = 0, koef2 = 0;     for (int i = 1; i <= m; ++i) {       long long lef = i - 2, rig = m - i - 1;       if (lef < 0) lef = 0;       if (rig < 0) rig = 0;       koef2 += i != 1;       koef2 += i != m;       koef += lef + rig;       second += 2;       if (i != 1) second += 2;       if (i != m) second += 2;       second += (lef + 1) * lef;       second += (rig + 1) * rig;     }     long double ans = second + (2 * koef + koef2) * sqrt(2.0);     printf( %.10f n , double(ans / (1LL * m * m) * r));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long spf[100001];   long long fac[100001];   void sieve() {     spf[1] = 1;     for (long long i = 2; i < 100001; i++) spf[i] = i;     for (long long i = 4; i < 100001; i += 2) spf[i] = 2;     for (long long i = 3; i * i < 100001; i++) {       if (spf[i] == i) {         for (long long j = i * i; j < 100001; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   map<long long, long long> getfactor(long long a) {     map<long long, long long> m;     while (a > 1) {       m[spf[a]]++;       a /= spf[a];     }     return m;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long inverse(long long a, long long p) { return power(a, p - 2, p); }   long long ncr(long long n, long long r, long long p) {     if (r == 0) return 1;     return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;   }   void solve() {     long long n;     cin >> n;     long long a[n];     long long hah[100001] = {0}, ans[100001] = {0};     for (long long i = 0; i < n; i++) {       cin >> a[i];       hah[a[i]]++;     }     for (long long i = 100000; i >= 1; i--) {       long long sum = 0;       for (long long j = i; j <= 100000; j += i) {         sum += hah[j];         ans[i] = (ans[i] - ans[j] + 1000000007) % 1000000007;         if (ans[i] < 0) ans[i] = (ans[i] + 1000000007) % 1000000007;       }       ans[i] = (ans[i] % 1000000007 + power(2, sum, 1000000007) - 1 + 1000000007 +                 1000000007) %                1000000007;     }     cout << ans[1] <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 100;   const long long INF = 9 * (long long)(1e18);   const long double PI = 3.14159265358979323846;   long long int modexp(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (y == 0)       return 1;     else if (x == 0)       return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res % p;   }   vector<long long int> is_prime(N + 1, 1);   void sieve(long long int n) {     for (long long int i = 1; i <= n; i++) is_prime[i] = i;     for (long long int i = 2; i * i <= n; i++) {       if (is_prime[i] == i) {         for (long long int j = i * i; j <= n; j += i)           is_prime[j] = min(i, is_prime[j]);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int foo;     cin >> foo;     while (foo--) {       long long int n;       cin >> n;       long long int x = (n + 3) / 4;       string s = string(x,  8 );       n -= x;       string s2 = string(n,  9 );       cout << s2 + s <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50 + 10, dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};   int main() {     int n, m, x, y;     while (~scanf( %d%d , &n, &m)) {       getchar();       char a[N][N];       for (int i = 0; i < n; i++) {         scanf( %s , a[i]);         for (int j = 0; j < m; j++) {           if (a[i][j] ==  S ) {             x = i;             y = j;           }         }       }       string str;       cin >> str;       int sum = 0, mmp[5], sz[5];       memset(sz, 0, sizeof(sz));       for (int i = 0; i < 4; i++) {         mmp[0] = i;         sz[i] = 1;         for (int j = 0; j < 4; j++) {           if (!sz[j]) {             sz[j] = 1;             mmp[1] = j;             for (int k = 0; k < 4; k++) {               if (!sz[k]) {                 mmp[2] = k;                 sz[k] = 1;                 for (int l = 0; l < 4; l++) {                   if (!sz[l]) {                     mmp[3] = l;                     int nx = x, ny = y;                     for (int zz = 0; zz < str.size(); zz++) {                       nx += dx[mmp[str[zz] -  0 ]];                       ny += dy[mmp[str[zz] -  0 ]];                       if (a[nx][ny] ==  #  ||                           !(nx >= 0 && nx < n && ny >= 0 && ny < m))                         break;                       if (a[nx][ny] ==  E ) {                         sum++;                         break;                       }                     }                   }                 }                 sz[k] = 0;               }             }             sz[j] = 0;           }         }         sz[i] = 0;       }       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct MyStruct {     long long val;     long long under;     long long scorev;     long long scoreu;     MyStruct(long long v, long long u, long long sv, long long su)         : val(v), under(u), scorev(sv), scoreu(su) {}     bool operator<(const MyStruct& m) const { return val < m.val; }   };   int main() {     ios_base::sync_with_stdio(false);     long long n;     cin >> n;     long long a1[n], a2[n], b1[n], b2[n];     for (long long i = 0; i < n; ++i) cin >> a1[i] >> b1[i] >> a2[i] >> b2[i];     long long ans = 0;     priority_queue<MyStruct> pq;     for (long long i = 0; i < n; ++i) {       long long cnum = a1[i] + b1[i], dnum = a2[i] + b2[i];       if (cnum < dnum) {         if (a1[i] > b2[i]) {           ans += a1[i] - b2[i];         } else if (b1[i] > a2[i]) {           ans -= b1[i] - a2[i];         }         continue;       }       if (cnum == dnum) {         ans += (a1[i] - b2[i]);         continue;       }       pq.push(MyStruct(cnum, dnum, a1[i], a2[i]));     }     bool first = true;     while (!pq.empty()) {       MyStruct top = pq.top();       pq.pop();       if (first)         ans += top.scorev;       else         ans += (top.scorev - top.val);       if (top.under != -1) pq.push(MyStruct(top.under, -1, top.scoreu, -1));       first = !first;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18;   const int mod = 4e4 + 7;   vector<int> prime;   bool p[100005];   void init() {     p[1] = true;     for (int i = 2; i <= 100005; i++) {       if (!p[i]) {         prime.push_back(i);         for (int j = i + i; j < 100005; j += i) p[j] = true;       }     }   }   bool isp(int n) {     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   int main() {     init();     int n;     cin >> n;     int s[100005];     int mx = 0;     for (int i = 0; i < n; i++) scanf( %d , &s[i]), mx = max(mx, s[i]);     sort(s, s + n);     int ans = 1;     int num[100005];     for (int i = 2; i <= mx; i++)       num[i] = upper_bound(s, s + n, i) - lower_bound(s, s + n, i);     for (int i = 0; i < prime.size(); i++) {       int sum = 0;       int x = prime[i];       for (int j = x; j <= mx; j++) {         if (j % x == 0) sum += num[j];       }       ans = max(ans, sum);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> v[i];       sum += v[i];     }     int req = sum / 2 - v[0] + 1;     vector<pair<int, int> > v1;     for (int i = 1; i < n; i++) {       if (v[i] <= v[0] / 2) v1.push_back(make_pair(v[i], i));     }     vector<int> v2;     if (req > 0)       for (int j = 0; j < v1.size(); j++) {         req -= v1[j].first;         v2.push_back(v1[j].second + 1);         if (req <= 0) break;       }     if (req > 0)       cout << 0 << endl;     else {       cout << v2.size() + 1 << endl;       cout <<  1  ;       for (int i = 0; i < v2.size(); i++) cout << v2[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int t, n, i, j, k, sum = 0, res = 0, maxi = -1, mini = 1000000100;     cin >> n;     long long int a[n + 1];     for (i = 0; i < n; i++) cin >> a[i];     long long int idx = 0;     for (i = 31; i >= 0; i--) {       long long int cnt = 0;       for (j = 0; j < n; j++) {         if ((a[j] >> i) & 1) {           cnt++;           idx = j;         }         if (cnt == 2) break;       }       if (cnt == 1) break;     }     swap(a[idx], a[0]);     for (i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   const int MOD = 1E9 + 7;   const int N = 150000 + 5;   const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};   const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};   using namespace std;   struct Edge {     int nex, to;     int w;     Edge() {}     Edge(int nex, int to, int w) : nex(nex), to(to), w(w) {}   } edge[5151111];   int head[N];   int cnt;   void addEdge(int from, int to, int w) {     edge[++cnt].nex = head[from];     edge[cnt].to = to;     edge[cnt].w = w;     head[from] = cnt++;   }   vector<int> G[N];   vector<int> nex[N];   int dis[N];   bool vis[N];   int Find(int y, int w) {     int left = 0, right = G[y].size() - 1;     while (left <= right) {       int mid = (left + right) / 2;       if (G[y][mid] > w)         right = mid - 1;       else if (G[y][mid] < w)         left = mid + 1;       else         return nex[y][mid];     }     return w;   }   int SPFA(int s, int n) {     memset(dis, 0x3f3f3f3f, sizeof(dis));     memset(vis, false, sizeof(vis));     vis[s] = true;     dis[s] = Find(1, 0);     queue<int> Q;     Q.push(s);     while (!Q.empty()) {       int x = Q.front();       Q.pop();       vis[x] = false;       for (int i = head[x]; i != -1; i = edge[i].nex) {         int y = edge[i].to;         int w = edge[i].w;         int times = dis[x] + w;         if (y != n) times = Find(y, times);         if (dis[y] > times) {           dis[y] = times;           if (!vis[y]) {             vis[y] = true;             Q.push(y);           }         }       }     }     return dis[n];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     memset(head, -1, sizeof(head));     for (int i = 1; i <= m; i++) {       int x, y, w;       scanf( %d%d%d , &x, &y, &w);       addEdge(x, y, w);       addEdge(y, x, w);     }     for (int i = 1; i <= n; i++) {       int t;       scanf( %d , &t);       while (t--) {         int x;         scanf( %d , &x);         G[i].push_back(x);       }     }     for (int i = 1; i <= n; i++) {       for (int j = G[i].size() - 1; j >= 0; j--) {         int before;         if (j == G[i].size() - 1 || G[i][j] != G[i][j + 1] - 1)           before = G[i][j] + 1;         nex[i].push_back(before);       }       reverse(nex[i].begin(), nex[i].end());     }     int res = SPFA(1, n);     if (res == 0x3f3f3f3f) res = -1;     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   const int INF = 0x3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-9;   int a[maxn];   int n;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     int now = 10;     int ans = 0;     int anscnt = 0;     bool flag = true;     for (int i = 0; i < n; ++i) {       if (flag) {         now += a[i];         if (now == 360) {           anscnt += i + 1;           flag = false;         } else if (now > 360) {           anscnt += i;           if (now <= 720) {             flag = false;             anscnt++;             ans += now - 360;           } else             break;         }       } else {         now += a[i];         if (now <= 720) {           anscnt++;           ans += now - 360;         } else           break;       }     }     if (now <= 360) {       anscnt = n;       ans = 0;     }     cout << anscnt <<     << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, r, r1, s, s1, pos, pos1, nx = 0;     int digits[19], index = 0;     cin >> x;     pos = 1;     do {       pos1 = pos;       pos *= 10;       r = x % pos;       s = (x - r) / pos;       r1 = r % pos1;       s1 = (r - r1) / pos1;       digits[index] = s1;       index++;     } while (s != 0);     for (int i = index - 1; i >= 0; i--) {       if (!(i == index - 1) || !(digits[i] == 9)) {         if (digits[i] > 4) digits[i] = 9 - digits[i];         nx = nx + digits[i] * pos1;       } else {         nx = nx + digits[i] * pos1;       }       pos1 /= 10;     }     cout << nx << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int val[105];     memset(val, 0, sizeof val);     char arr[105];     scanf( %s , arr);     int n = strlen(arr);     for (int i = 0; i < n; i++) {       if (arr[i] ==  A ) {         if (i > 0) {           val[i - 1] |= 1;         }         val[i] |= 1;         if (i < n - 1) {           val[i + 1] |= 1;         }       } else if (arr[i] ==  B ) {         if (i > 0) {           val[i - 1] |= (1 << 1);         }         val[i] |= (1 << 1);         if (i < n - 1) {           val[i + 1] |= (1 << 1);         }       } else if (arr[i] ==  C ) {         if (i > 0) {           val[i - 1] |= (1 << 2);         }         val[i] |= (1 << 2);         if (i < n - 1) {           val[i + 1] |= (1 << 2);         }       }     }     bool flag = false;     for (int i = 0; i < n; i++) {       if (val[i] == 7) {         flag = true;         break;       }     }     if (flag) {       printf( Yes n );     } else {       printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) {     long long g = gcd(a, b);     long long ans = (a * b) / g;     return ans;   }   vector<long long> primes;   bool prime[10005];   void seive() {     memset(prime, 1, sizeof(prime));     prime[0] = 0;     prime[1] = 0;     for (long long i = 2; i <= 10000; i++) {       if (prime[i] == 1) {         for (long long j = i * i; j <= 10000; j += i) prime[j] = 0;       }     }   }   long long power(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans % 1000000007 * a % 1000000007) % 1000000007;       a = (a * a) % 1000000007;       b = b / 2;     }     return ans;   }   template <typename T>   std::string NumberToString(T Number) {     std::ostringstream ss;     ss << Number;     return ss.str();   }   long long gcdExtended(long long a, long long b, long long *x, long long *y);   long long modInverse(long long b, long long m) {     long long x, y;     long long g = gcdExtended(b, m, &x, &y);     if (g != 1) return -1;     return (x % m + m) % m;   }   long long modDivide(long long a, long long b, long long m) {     a = a % m;     long long inv = modInverse(b, m);     return (inv * a) % m;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long n;   vector<long long> v[100005];   vector<long long> ans;   void dfs(long long u, long long p) {     if (v[u].size() == 1 and p != 0) {       ans.push_back(u);       return;     }     for (auto x : v[u]) {       if (x != p) {         dfs(x, u);       }     }   }   void solve() {     cin >> n;     long long i, j;     for (i = 0; i < n - 1; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     long long ct = 0, root = 1;     for (long long i = 1; i <= n; i++) {       if (v[i].size() > 2) {         root = i;         ct++;       }     }     if (ct > 1) {       cout <<  No ;       return;     }     cout <<  Yes  <<   n ;     dfs(root, 0);     cout << ans.size() <<   n ;     for (i = 0; i < ans.size(); i++) {       cout << root <<     << ans[i] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     bool codechef = 0;     long long t = 1;     if (codechef) {       cin >> t;     }     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   template <typename T>   inline bool smin(T &a, const T &b) {     return a > b ? a = b : a;   }   template <typename T>   inline bool smax(T &a, const T &b) {     return a < b ? a = b : a;   }   const int N = (int)1 << 15, mod = (int)998244353;   int a[N], b[N], dp[N];   int pw(int a, int b) {     return b != 0 ? (long long)pw((long long)a * a % mod, b >> 1) *                         (b & 1 ? a : 1) % mod                   : 1;   }   void NTT(int a[], int lg, bool inverse) {     int N = 1 << lg;     for (int i = 0; i < N; ++i) {       int rev = 0;       for (int j = 0; j < lg; ++j)         if (i >> j & 1) rev |= 1 << (lg - j - 1);       if (rev > i) swap(a[rev], a[i]);     }     for (int len = 2; len <= N; len <<= 1) {       int wn = pw(3, (mod - 1) / len);       if (inverse) wn = pw(wn, mod - 2);       for (int j = 0; j < N; j += len) {         int w = 1;         for (int first = j, second = j + len / 2; second < j + len;              ++first, ++second) {           int u = a[first], v = (long long)a[second] * w % mod;           a[first] = u + v;           a[second] = u - v + mod;           while (a[first] >= mod) a[first] -= mod;           while (a[second] >= mod) a[second] -= mod;           w = (long long)w * wn % mod;         }       }     }     if (inverse) {       int div = pw(N, mod - 2);       for (int i = 0; i < N; ++i) a[i] = (long long)a[i] * div % mod;     }   }   int res[17][N], tmpa[17][N], tmpb[17][N];   void solve(int b, int e, int a[N], int d = 0) {     if (b + 1 == e) {       res[d][0] = 1;       res[d][1] = a[b];       return;     }     int m = b + e >> 1;     solve(b, m, a, d + 1);     for (int j = 0; j <= (m - b); ++j)       tmpa[d][j] = res[d + 1][j], res[d + 1][j] = 0;     solve(m, e, a, d + 1);     for (int j = 0; j <= (e - m); ++j)       tmpb[d][j] = res[d + 1][j], res[d + 1][j] = 0;     int lg = 0;     while ((1 << lg) <= e - b) ++lg;     NTT(tmpa[d], lg, false);     NTT(tmpb[d], lg, false);     for (int j = 0; j < (1 << lg); ++j)       res[d][j] = (long long)tmpa[d][j] * tmpb[d][j] % mod,       tmpa[d][j] = tmpb[d][j] = 0;     NTT(res[d], lg, true);   }   int32_t main() {     int n, k;     cin >> n >> k;     for (int j = 0; j < n; ++j) cin >> a[j];     int qm;     cin >> qm;     while (qm--) {       int c;       cin >> c;       if (c == 1) {         int q, p, d;         cin >> q >> p >> d;         --p;         for (int j = 0; j < n; ++j) b[j] = q - a[j];         b[p] = q - d;       } else {         int q, l, r, d;         cin >> q >> l >> r >> d;         --l;         for (int j = 0; j < n; ++j) b[j] = q - a[j];         for (int j = l; j < r; ++j) b[j] -= d;       }       for (int j = 0; j < n; ++j) b[j] = (b[j] % mod + mod) % mod;       memset(res, 0, sizeof res);       solve(0, n, b);       cout << res[0][k] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 25;   int main() {     int n, m, l, r, t, c;     cin >> n >> m;     pair<int, int> s[n + 1];     for (int i = (1), _b = (n + 1); i < (_b); ++i) s[i] = make_pair(0, 0);     for (int i = (0), _b = (m); i < (_b); ++i) {       cin >> l >> r >> t >> c;       for (int j = (l), _b = (r + 1); j < (_b); ++j) {         if (!s[j].second)           s[j] = make_pair(t, c);         else {           if (t < s[j].first) {             s[j] = make_pair(t, c);           }         }       }     }     int ret = 0;     for (int i = (1), _b = (n + 1); i < (_b); ++i) {       ret += s[i].second;     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, A, B, scc[75], tot[75], fa[75], ans[75], f[75][1 << 16];   int c, To[405], nxt[405], cst[405], Head[75];   bool vis[75][1 << 16];   inline int Read() {     int x = 0, f = 1;     char ch = getchar();     while (ch < 48 || ch > 57) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch > 47 && ch < 58) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   inline void Write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) Write(x / 10);     putchar(48 + x % 10);   }   void ad_ed(int u, int v, int ct) {     nxt[++c] = Head[u];     To[c] = v;     cst[c] = ct;     Head[u] = c;   }   int Find(int x) {     if (fa[x] != x) fa[x] = Find(fa[x]);     return fa[x];   }   void Merge(int x, int y) {     int rx = Find(x), ry = Find(y);     if (rx != ry) fa[ry] = rx, tot[rx] += tot[ry];   }   struct info {     int id, dis, st;     friend bool operator<(info a, info b) { return a.dis > b.dis; }   };   priority_queue<info> q;   int main() {     n = Read();     m = Read();     A = Read();     B = Read();     if (A > B) swap(A, B);     for (int i = 1; i <= n; i++) fa[i] = i, tot[i] = 1, ans[i] = 0x3f3f3f3f;     memset(f, 0x3f, sizeof(f));     for (int i = 1; i <= m; i++) {       int u = Read(), v = Read(), ct = Read();       ad_ed(u, v, ct);       ad_ed(v, u, ct);       if (ct == A) Merge(u, v);     }     int idx = 0;     for (int i = 1; i <= n; i++)       if (!scc[i] && tot[Find(i)] > 3) {         idx++;         for (int j = 1; j <= n; j++)           if (Find(j) == Find(i)) scc[j] = idx;       }     int beg_st = (!scc[1] ? 0 : 1 << scc[1]);     f[1][beg_st] = 0;     q.push(info{1, 0, beg_st});     while (!q.empty()) {       info x = q.top();       q.pop();       if (vis[x.id][x.st]) continue;       vis[x.id][x.st] = 1;       ans[x.id] = min(ans[x.id], x.dis);       for (int i = Head[x.id]; i; i = nxt[i]) {         int v = To[i], ct = cst[i];         if (ct == A) {           if (f[x.id][x.st] + ct < f[v][x.st]) {             f[v][x.st] = f[x.id][x.st] + ct;             q.push(info{v, f[v][x.st], x.st});           }         } else if (ct == B) {           if (Find(x.id) == Find(v)) continue;           if (scc[v] && ((x.st >> scc[v]) & 1)) continue;           int net = x.st | (1 << scc[v]);           if (f[x.id][x.st] + ct < f[v][net]) {             f[v][net] = f[x.id][x.st] + ct;             q.push(info{v, f[v][net], net});           }         }       }     }     for (int i = 1; i <= n; i++) Write(ans[i]), putchar(   );     return 0;   }


#include <bits/stdc++.h>   const long long INF = (1 << 30) - 1;   const int MAXN = 100001;   struct Node {     int l, r;     long long num;     long long num2;     long long delta;   };   int n, m;   long long t[MAXN];   int l[MAXN], r[MAXN];   long long q[MAXN];   Node tree[MAXN << 2];   void build(int cur, int l, int r) {     tree[cur].l = l;     tree[cur].r = r;     tree[cur].delta = tree[cur].num = tree[cur].num2 = 0;     if (l + 1 != r) {       tree[cur].delta = 0;       build((cur << 1) + 1, l, (l + r) >> 1);       build((cur << 1) + 2, (l + r) >> 1, r);     }   }   void update(int cur) {     tree[(cur << 1) + 1].delta |= tree[cur].delta;     tree[(cur << 1) + 2].delta |= tree[cur].delta;     tree[(cur << 1) + 1].num |= tree[cur].delta;     tree[(cur << 1) + 2].num |= tree[cur].delta;     tree[(cur << 1) + 1].num2 |= tree[cur].delta;     tree[(cur << 1) + 2].num2 |= tree[cur].delta;     tree[cur].delta = 0;   }   void change(int cur, int l, int r, int delta) {     if (l <= tree[cur].l && tree[cur].r <= r) {       tree[cur].delta |= delta;       tree[cur].num |= delta;       tree[cur].num2 |= delta;     } else {       if (tree[cur].delta != 0) update(cur);       int mid = (tree[cur].l + tree[cur].r) >> 1;       if (l < mid) change((cur << 1) + 1, l, r, delta);       if (r > mid) change((cur << 1) + 2, l, r, delta);       tree[cur].num = tree[(cur << 1) + 1].num | tree[(cur << 1) + 2].num;       tree[cur].num = tree[(cur << 1) + 1].num & tree[(cur << 1) + 2].num;     }   }   long long query(int cur, int l, int r) {     if (l <= tree[cur].l && tree[cur].r <= r) {       return tree[cur].num2;     } else {       if (tree[cur].delta != 0) update(cur);       int mid = (tree[cur].l + tree[cur].r) >> 1;       long long ans = INF;       if (l < mid) ans &= query((cur << 1) + 1, l, r);       if (r > mid) ans &= query((cur << 1) + 2, l, r);       return ans;     }   }   int main() {     scanf( %d%d , &n, &m);     memset(t, 0LL, sizeof(t));     build(0, 1, n + 1);     for (int i = 1; i <= m; i++) {       scanf( %d%d%I64d , &l[i], &r[i], &q[i]);       change(0, l[i], r[i] + 1, q[i]);     }     bool ok = true;     for (int i = 1; i <= m; i++) {       long long te = query(0, l[i], r[i] + 1);       if (te != q[i]) {         ok = false;         break;       }     }     if (ok) {       printf( YES n );       for (int i = 1; i <= n; i++) {         printf( %I64d  , query(0, i, i + 1));       }       printf(  n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   struct Node {     Node(int v = 1, int pos = 1e9) { min = (v == 1 ? int(1e9) : pos); }     Node(Node l, Node r) { min = std::min(l.min, r.min); }     int min;   };   template <class i_t, class e_t>   class SegmentTree {    public:     void init(std::vector<e_t> base) {       n = base.size();       tree.resize(2 * n);       for (int i = 0; i < n; i++) {         tree[i + n] = i_t(base[i], i);       }       for (int i = n - 1; i > 0; i--) {         tree[i] = i_t(tree[i + i], tree[i + i + 1]);       }     }     i_t qry(int l, int r) {       i_t lp, rp;       for (l += n, r += n; l < r; l /= 2, r /= 2) {         if (l & 1) lp = i_t(lp, tree[l++]);         if (r & 1) rp = i_t(tree[--r], rp);       }       return i_t(lp, rp);     }     void upd(int x, e_t v) {       x += n;       tree[x] = i_t(v, x - n);       build(x);     }       private:     int n;     std::vector<i_t> tree;     void build(int x) {       for (x /= 2; x > 0; x /= 2) {         tree[x] = i_t(tree[x + x + 1], tree[x + x]);       }     }   };   struct Bucket {     int n;     SegmentTree<Node, int> tree;     void init(int n) {       this->n = n;       tree.init(std::vector<int>(n, 0));     }     void erase(int pos) { tree.upd(pos, 0); }     int insert(int pos) {       int x = tree.qry(pos, n).min;       int ans = 0;       if (x >= n) {         x = tree.qry(0, pos).min;         ans += n - pos + x;       } else {         ans += x - pos;       }       tree.upd(x, 1);       return ans;     }   };   int main() {     int h, m, n;     std::cin >> h >> m >> n;     int size = 1;     for (int i = 2; i <= h; i++) {       if (h % i == 0 && m % i == 0) {         size = i;       }     }     std::vector<Bucket> buckets(size);     std::vector<int> hashBucket(h, 0);     std::vector<int> posBucket(h, 0);     std::map<int, std::pair<int, int> > idBucket;     for (int i = 0; i < size; i++) {       for (int j = 0, pos = i; j < h / size; j++, pos = (pos + m) % h) {         posBucket[pos] = j;         hashBucket[pos] = i;       }       buckets[i].init(h / size);     }     long long ans = 0;     for (int i = 0; i < n; i++) {       char t;       int id;       scanf(  %c %d , &t, &id);       if (t ==  + ) {         int hash;         scanf( %d , &hash);         int got = buckets[hashBucket[hash]].insert(posBucket[hash]);         idBucket[id] = std::pair<int, int>(hashBucket[hash],                                            (posBucket[hash] + got) % (h / size));         ans += got;       } else {         auto it = idBucket.find(id);         buckets[it->second.first].erase(it->second.second);         idBucket.erase(it);       }     }     std::cout << ans << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   vector<long long> fact(10005);   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long power(long long x, long long y) {     long long temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInv(long long n, long long p) { return power(n, p - 2, p); }   long long ncr(long long n, long long r) {     return (n >= r ? (fact[n] * modInv(fact[r], mod)) % mod *                          modInv(fact[n - r], mod) % mod                    : 0);   }   long long add(long long a, long long b) {     long long z = a + b;     if (z >= mod) z -= mod;     return z;   }   long long mul(long long a, long long b) { return (a * b) % mod; }   long long sub(long long a, long long b) { return (a - b + mod) % mod; }   int main() {     long long t = 1, n, i, j, m, cnt, f, ff;     cin >> t;     while (t--) {       cin >> n >> mod;       long long z = log2(n) - 1;       long long ans = (n - (1 << (z + 1)) + 2) % mod;       for (i = 0; i <= z; i++) {         ans = mul(ans, (1 << i) + 1);       }       if (ans == 0)         cout << mod - 1 <<   n ;       else         cout << ans - 1 <<   n ;     }   }