#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 1e6 + 6;   int a[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int pt = 0;     if (n & 1) {       for (int i = 2; i <= n; i += 2) {         a[pt++] = i;       }       for (int i = n - 1; i >= 2; i -= 2) {         a[pt++] = i;       }       for (int i = 1; i <= n; i += 2) {         a[pt++] = i;       }       for (int i = n - 2; i >= 1; i -= 2) {         a[pt++] = i;       }       a[pt++] = n;     } else {       for (int i = 1; i <= n; i += 2) {         a[pt++] = i;       }       for (int i = n - 1; i >= 1; i -= 2) {         a[pt++] = i;       }       for (int i = 2; i <= n; i += 2) {         a[pt++] = i;       }       for (int i = n - 2; i >= 2; i -= 2) {         a[pt++] = i;       }       a[pt++] = n;     }     for (int i = 0; i < pt; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   struct Frac {     long long a, b;     Frac(long long aa = 0, long long bb = 1) {       if (bb < 0) {         aa = -aa;         bb = -bb;       }       long long g = gcd(abs(aa), bb);       a = aa / g;       b = bb / g;     }     Frac& operator=(const Frac& f) {       a = f.a;       b = f.b;       return *this;     }     Frac& operator+=(const Frac& f) {       return *this = Frac(a * f.b + b * f.a, b * f.b);     }     Frac& operator-=(const Frac& f) {       return *this = Frac(a * f.b - b * f.a, b * f.b);     }     Frac& operator*=(const Frac& f) { return *this = Frac(a * f.a, b * f.b); }     Frac& operator/=(const Frac& f) { return *this = Frac(a * f.b, b * f.a); }     Frac operator-() const { return Frac(-a, b); }     Frac operator+(const Frac& f) const { return Frac(*this) += f; }     Frac operator-(const Frac& f) const { return Frac(*this) -= f; }     Frac operator*(const Frac& f) const { return Frac(*this) *= f; }     Frac operator/(const Frac& f) const { return Frac(*this) /= f; }     bool operator<(const Frac& f) const { return a * f.b < b * f.a; }     bool operator>(const Frac& f) const { return f < *this; }     bool operator<=(const Frac& f) const { return !(f < *this); }     bool operator>=(const Frac& f) const { return !(*this < f); }     bool operator==(const Frac& f) const { return !(*this < f) && !(f < *this); }     bool operator!=(const Frac& f) const { return !(*this == f); }   };   std::ostream& operator<<(std::ostream& os, const Frac& f) {     return os << f.a <<  /  << f.b;   }   Frac MAX_T = Frac(200000);   struct Event {     int from, to;     Frac time_from, time_to;     long long V;     Event(int from, int to, Frac time_from, Frac time_to, long long V)         : from(from), to(to), time_from(time_from), time_to(time_to), V(V) {       if (this->time_from > this->time_to) {         swap(this->from, this->to);         swap(this->time_from, this->time_to);       }       if ((this->from < this->to) ^ (this->V > 0)) this->V *= -1;       assert(this->time_from <= this->time_to);     }     ostream& output_me(ostream& os) const {       return os << from <<   ->   << to <<   t0=  << time_from                 <<   t1=  << time_to <<   V=  << V;     }     Frac getPoint(Frac c_time) const {       Frac dif = c_time - time_from;       Frac pos = Frac(from) + Frac(V) * dif;       return pos;     }   };   std::ostream& operator<<(std::ostream& os, const Event& e) {     return e.output_me(os);   }   const int MAXN = 100100;   vector<int> adj[MAXN];   int depth[MAXN];   int parent[MAXN];   int subsize[MAXN];   int largest[MAXN];   int leader[MAXN];   vector<int> decomposition[MAXN];   vector<Event> events[MAXN];   int lca(int a, int b) {     while (true) {       if (leader[a] == leader[b]) return ((depth[a] < depth[b]) ? a : b);       if (depth[leader[a]] > depth[leader[b]]) swap(a, b);       b = parent[leader[b]];     }   }   void init1(int n, int p, int d) {     depth[n] = d;     parent[n] = p;     subsize[n] = 1;     largest[n] = -1;     for (auto to : adj[n])       if (to != p) {         init1(to, n, d + 1);         subsize[n] += subsize[to];         if (largest[n] == -1 || subsize[to] > subsize[largest[n]]) {           largest[n] = to;         }       }   }   void init2(int n, int l) {     leader[n] = l;     decomposition[l].push_back(n);     if (largest[n] != -1) init2(largest[n], l);     for (auto to : adj[n])       if (to != parent[n] && to != largest[n]) {         decomposition[to].push_back(n);         init2(to, to);       }   }   bool insert(Frac start_t, int f, int r, int V) {     if (f == r) return false;     if (leader[f] == leader[r]) {       events[leader[f]].push_back(Event(depth[f], depth[r], start_t,                                         start_t + Frac(depth[f] - depth[r], V),                                         (V)));       return true;     }     assert(decomposition[leader[f]][0] != leader[f]);     int m = decomposition[leader[f]][0];     Frac t_m = Frac(depth[f] - depth[m], V) + start_t;     events[leader[f]].push_back(Event(depth[f], depth[m], start_t, t_m, (V)));     return insert(t_m, m, r, V);   }   Frac cur_time;   bool operator<(const Event& a, const Event& b) {     assert(a.time_from <= cur_time);     assert(a.time_to >= cur_time);     assert(b.time_from <= cur_time);     assert(b.time_to >= cur_time);     return a.getPoint(cur_time) < b.getPoint(cur_time);   }   bool operator==(const Event& a, const Event& b) {     assert(a.time_from <= cur_time);     assert(a.time_to >= cur_time);     assert(b.time_from <= cur_time);     assert(b.time_to >= cur_time);     return a.getPoint(cur_time) == b.getPoint(cur_time);   }   Frac split_(const Event& a, const Event& b) {     Frac T1 = a.time_from;     if (T1 < b.time_from) T1 = b.time_from;     Frac T2 = a.time_to;     if (T2 > b.time_to) T2 = b.time_to;     Frac sa = a.getPoint(T1), sb = b.getPoint(T1);     Frac ea = a.getPoint(T2), eb = b.getPoint(T2);     if (sa == sb) return T1;     if (ea == eb) return T2;     if ((sa < sb) ^ (ea < eb)) {       Frac d1 = sa - sb;       Frac d2 = eb - ea;       d2 = (d2 / d1);       d1 = Frac(1);       Frac rel = d1 / (d1 + d2);       Frac res = (T2 - T1) * rel + T1;       return res;     }     return MAX_T;   }   int main() {     int N, Q;     scanf( %d%d , &N, &Q);     for (int i = (0); i < (N); i++) adj[i].clear();     for (int i = (0); i < (N); i++) decomposition[i].clear();     for (int i = (1); i < (N); i++) {       int a, b;       scanf( %d%d , &a, &b);       adj[--a].push_back(--b);       adj[b].push_back(a);     }     memset(leader, -1, sizeof(leader));     init1(0, 0, 0);     init2(0, 0);     for (int q = (0); q < (Q); q++) {       int T, V, a, b;       scanf( %d%d%d%d , &T, &V, &a, &b);       --a;       --b;       int r = lca(a, b);       Frac t_start(T);       Frac t_end = t_start + Frac(depth[a] + depth[b] - 2 * depth[r], V);       bool lca_done = insert(t_start, a, r, V);       lca_done |= insert(t_end, b, r, -V);       if (!lca_done) {         Frac t_mid = t_start + Frac(depth[a] - depth[r], V);         events[leader[r]].push_back(Event(depth[r], depth[r], t_mid, t_mid, 1));       }     }     Frac split = MAX_T;     for (int ii = (0); ii < (N); ii++) {       vector<Event>& ev = events[ii];       if (int((ev).size()) == 0) continue;       set<Event> active;       set<tuple<Frac, bool, int> > change;       for (int i = (0); i < (int((ev).size())); i++) {         change.insert(make_tuple(ev[i].time_from, 0, i));         change.insert(make_tuple(ev[i].time_to, 1, i));       }       for (auto tpl : change) {         int id;         bool remove;         tie(cur_time, remove, id) = tpl;         if (split <= cur_time) break;         if (remove) {           auto it = active.find(ev[id]);           if (it != active.begin()) {             auto it1 = it;             it1--;             auto it2 = it;             it2++;             if (it2 != active.end()) {               Frac sp = split_(*it1, *it2);               if (sp < split) split = sp;             }           }           active.erase(it);         } else {           auto it = active.find(ev[id]);           if (it != active.end()) {             split = cur_time;             break;           }           active.insert(ev[id]);           it = active.find(ev[id]);           if (it != active.begin()) {             auto pr = it;             pr--;             Frac sp = split_(*pr, *it);             if (sp < split) split = sp;           }           auto ne = it;           ne++;           if (ne != active.end()) {             Frac sp = split_(*ne, *it);             if (sp < split) split = sp;           }         }       }     }     if (MAX_T == split)       printf( -1 n );     else       printf( %.10lf n , split.a / (double)split.b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   inline double nf() {     double a;     scanf( %lf , &a);     return a;   }   template <class T>   void out(T a, T b) {     bool first = true;     for (T i = a; i != b; i++) {       if (!first) printf(   );       first = false;       cout << *i;     }     puts(  );   }   template <class T>   void outl(T a, T b) {     for (T i = a; i != b; i++) cout << *i <<   n ;   }   const int MAXN = 5010;   int gcd(int x, int y) {     while (x) {       y %= x;       swap(x, y);     }     return y;   }   int n, m;   int a[MAXN], b[MAXN], g[MAXN];   long long d[MAXN];   long long balance[MAXN], gb[MAXN];   int main() {     n = ni();     m = ni();     for (int i = 0; i < (int)(n); i++) a[i] = ni();     for (int i = 0; i < (int)(m); i++) b[i] = ni();     sort(b, b + m);     g[0] = a[0];     for (int i = 1; i < n; i++) g[i] = gcd(g[i - 1], a[i]);     for (int i = 0; i < (int)(n); i++) {       int c = a[i];       for (int j = 2; j * j <= c; j++) {         if (c % j) continue;         bool flag = binary_search(b, b + m, j);         while (c % j == 0) {           if (flag)             balance[i]--;           else             balance[i]++;           c /= j;         }       }       if (c != 1) {         bool flag = binary_search(b, b + m, c);         if (flag)           balance[i]--;         else           balance[i]++;       }     }     for (int i = 0; i < (int)(n); i++) {       int c = g[i];       for (int j = 2; j * j <= c; j++) {         if (c % j) continue;         bool flag = binary_search(b, b + m, j);         while (c % j == 0) {           if (flag)             gb[i]--;           else             gb[i]++;           c /= j;         }       }       if (c != 1) {         bool flag = binary_search(b, b + m, c);         if (flag)           gb[i]--;         else           gb[i]++;       }     }     for (int i = n - 1; i >= 0; i--) {       d[i] = -(1LL << 60);       long long sum = 0;       for (int j = i; j < n; j++) {         sum += balance[j];         d[i] = max(d[i], d[j + 1] + sum - ((j - i + 1) * 1LL) * gb[j]);       }       d[i] = max(d[i], sum);     }     cout << d[0] << endl;   }


#include <bits/stdc++.h>   const int INF_INT = 0x3f3f3f3f;   const long long INF_LL = 0x7f7f7f7f;   const int MOD = 1e9 + 7;   const double eps = 1e-10;   const double pi = acos(-1);   using namespace std;   int n;   int a[30];   int vis[30];   bool dfs(int root, int cnt, int son) {     if (root == n + 1) return true;     if (cnt + 1 == a[root]) {       if (son != 1 && dfs(root + 1, 0, 0)) return true;       return false;     }     int same = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i] && cnt + a[i] < a[root] && a[i] != same) {         same = a[i];         vis[i] = 1;         if (dfs(root, cnt + a[i], son + 1)) return true;         vis[i] = 0;       }     }     return false;   }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     memset(vis, 0, sizeof(vis));     if (a[n] != n)       puts( NO );     else {       if (dfs(1, 0, 0))         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int arrx[100];   long long int arry[100];   long long int arr[10000];   map<long long int, bool> M;   void parr(long long int a[], long long int n);   int main() {     long long int x, y, l, r, ss, siz, sizx, sizy, mulx, muly, start, ans, fin,         ran, tempx, tempy, i, j, temp;     bool fx, fy;     scanf( %lld , &x);     scanf( %lld , &y);     scanf( %lld , &l);     scanf( %lld , &r);     sizx = 0;     sizy = 0;     mulx = 1;     muly = 1;     tempx = r / x;     tempy = r / y;     fx = 1;     fy = 1;     while (1) {       if (fx) {         arrx[sizx] = mulx;         sizx++;       }       if (fy) {         arry[sizy] = muly;         sizy++;       }       if (mulx > tempx && muly > tempy) break;       if (mulx <= tempx) {         mulx = mulx * x;       } else         fx = 0;       if (muly <= tempy) {         muly = muly * y;       } else         fy = 0;     }     siz = 0;     for (i = 0; i < sizx; i = i + 1) {       temp = r - arrx[i];       for (j = 0; j < sizy; j = j + 1) {         if (arry[j] > temp) break;         ss = arrx[i] + arry[j];         if (ss < l) continue;         if (M[ss]) continue;         arr[siz] = ss;         M[ss] = 1;         siz++;       }     }     sort(arr, arr + siz);     start = l;     ans = 0;     for (i = 0; i < siz; i = i + 1) {       fin = arr[i] - 1;       ran = fin - start + 1;       ans = max(ans, ran);       start = arr[i] + 1;     }     ran = r - start + 1;     ans = max(ans, ran);     printf( %lld n , ans);     return 0;   }   void parr(long long int a[], long long int n) {     long long int i;     for (i = 0; i < n; i = i + 1) {       printf( %lld  , a[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[300010];   bool vst[300010];   int dp[300010][2];   int root[300010];   int cnt[300010];   int dst[300010];   int find_root(int u) {     if (root[u] == u) return u;     return root[u] = find_root(root[u]);   }   void reunion(int u, int v) {     u = find_root(u);     v = find_root(v);     if (u == v) return;     if (cnt[u] < cnt[v]) swap(u, v);     cnt[u] += cnt[v];     root[v] = u;     dst[u] = max(dst[u], (dst[u] + 1) / 2 + (dst[v] + 1) / 2 + 1);     dst[u] = max(dst[u], dst[v]);   }   int val;   void dfs(int u, int fa = 0) {     vst[u] = 1;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == fa) continue;       dfs(v, u);     }     vector<int> vt;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == fa) continue;       vt.push_back(dp[v][0]);     }     sort(vt.begin(), vt.end());     reverse(vt.begin(), vt.end());     if (vt.size()) dp[u][0] = vt[0] + 1;     if (vt.size() > 1) dp[u][1] = vt[1] + 1;     val = max(val, dp[u][0] + dp[u][1]);   }   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) root[i] = i;     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);       reunion(u, v);     }     for (int i = 1; i <= n; i++) {       if (!vst[i]) {         val = 0;         dfs(i);         int fa = find_root(i);         dst[fa] = val;       }     }     while (q--) {       int ok;       scanf( %d , &ok);       if (ok == 2) {         int u, v;         scanf( %d%d , &u, &v);         reunion(u, v);       } else {         int u;         scanf( %d , &u);         u = find_root(u);         printf( %d n , dst[u]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a, d;   double pre(double v) {     if (d >= (v * v) / (2.0 * a)) {       double x = v / a;       double y = d - ((v * v) / (2.0 * a));       double out = x + (y / (v));       return out;     } else {       double out = sqrt((2.0 * d) / a);       return out;     }   }   int main() {     int n;     cin >> n >> a >> d;     double arr[n][2];     double time[n];     for (int i = 0; i < n; i++) {       scanf( %lf%lf , &arr[i][0], &arr[i][1]);       double x = pre(arr[i][1]);       time[i] = x + arr[i][0];       if (i != 0 && time[i] < time[i - 1]) {         time[i] = time[i - 1];       }       printf( %.6f n , time[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sushu(long long n) {     long long t = sqrt(n);     for (long long i = 2; i <= t; i++) {       if (n % i == 0) return false;     }     return true;   }   long long ret(long long n) {     long long ne = 0;     while (n != 0) {       ne = ne * 10 + n % 10;       n = n / 10;     }     return ne;   }   int main() {     long long n, ans;     long long a[11190];     long long i, num = 0;     for (i = 13;; i++) {       if (sushu(i) && sushu(ret(i)) && i != ret(i)) {         a[num++] = i;         if (num == 11184) break;       }     }     while (cin >> n) {       cout << a[n - 1] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void ckmx(int &x, int y) { x = max(x, y); }   const int N = 100050;   const int L = 17;   const int M = 2 * N;   int root, ls[M], rs[M], tsz, mx[M], lzy[M];   void Build(int &c, int ss, int se, int a[]) {     c = ++tsz;     lzy[c] = 0;     if (ss == se) {       mx[c] = a[ss];       return;     }     int mid = ss + se >> 1;     Build(ls[c], ss, mid, a);     Build(rs[c], mid + 1, se, a);     mx[c] = max(mx[ls[c]], mx[rs[c]]);   }   void Add(int c, int ss, int se, int qs, int qe, int f) {     if (qs > qe || qs > se || ss > qe) return;     if (qs <= ss && qe >= se) {       lzy[c] += f;       mx[c] += f;       return;     }     int mid = ss + se >> 1;     Add(ls[c], ss, mid, qs, qe, f);     Add(rs[c], mid + 1, se, qs, qe, f);     mx[c] = max(mx[ls[c]], mx[rs[c]]) + lzy[c];   }   int Get(int c, int ss, int se, int qs, int qe) {     if (qs > qe || qs > se || ss > qe) return -1e9;     if (qs <= ss && qe >= se) return mx[c];     int mid = ss + se >> 1;     return max(Get(ls[c], ss, mid, qs, qe), Get(rs[c], mid + 1, se, qs, qe)) +            lzy[c];   }   vector<int> E[N];   int dep[N], par[N][L], lid[N], rid[N], tid, h[N], ans[N];   void DFS(int u, int p) {     par[u][0] = p;     dep[u] = dep[p] + 1;     lid[u] = ++tid;     h[lid[u]] = dep[u];     for (int i = 1; i < L; i++) par[u][i] = par[par[u][i - 1]][i - 1];     for (int v : E[u])       if (v != p) DFS(v, u);     rid[u] = tid;   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int i = L - 1; ~i; i--)       if (dep[par[u][i]] >= dep[v]) u = par[u][i];     for (int i = L - 1; ~i; i--)       if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];     return u == v ? v : par[v][0];   }   int Dist(int u, int v) { return dep[u] + dep[v] - 2 * dep[LCA(u, v)]; }   int Up(int u, int k) {     for (int i = 0; i < L; i++)       if (k >> i & 1) u = par[u][i];     return u;   }   struct Query {     int id, l, r;   };   vector<Query> Qs[N];   void Solve(int u, int p) {     Add(root, 1, tid, lid[u], rid[u], -2);     for (Query Q : Qs[u]) ckmx(ans[Q.id], Get(root, 1, tid, Q.l, Q.r) + dep[u]);     for (int v : E[u])       if (v != p) Solve(v, u);     Add(root, 1, tid, lid[u], rid[u], 2);   }   int main() {     int n, m;     scanf( %i , &n);     for (int i = 1, u, v; i < n; i++)       scanf( %i %i , &u, &v), E[u].push_back(v), E[v].push_back(u);     DFS(1, 0);     Build(root, 1, n, h);     scanf( %i , &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %i %i , &u, &v);       if (dep[u] < dep[v]) swap(u, v);       int w = Up(u, (Dist(u, v) - 1) / 2);       Qs[u].push_back((Query){i, lid[w], rid[w]});       Qs[v].push_back((Query){i, 1, lid[w] - 1});       Qs[v].push_back((Query){i, rid[w] + 1, n});     }     Solve(1, 0);     for (int i = 1; i <= m; i++) printf( %i n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h, t;   vector<vector<int> > graph;   vector<int> lvl;   int edges[100005][2];   int stat[100005];   int check(int u, int v) {     int len = h + t;     int ht = 0;     int tt = 0;     stat[u] = -1;     stat[v] = -1;     int i = 0;     while (ht < len) {       int a = graph[u][i++];       if (a == -1) break;       if (stat[a] == -1) continue;       stat[a] = 1;       ht++;     }     i = 0;     while (tt < t) {       int a = graph[v][i++];       if (a == -1) break;       if (stat[a] == -1) continue;       if (stat[a] == 1) {         if (ht > h)           ht--;         else           continue;       }       stat[a] = 2;       tt++;     }     if (ht >= h && tt >= t) return 1;     stat[u] = 0;     stat[v] = 0;     i = 0;     while (ht > 0) {       int a = graph[u][i++];       if (stat[a] == 1) {         ht--;         stat[a] = 0;       }     }     i = 0;     while (tt > 0) {       int a = graph[v][i++];       if (stat[a] == 2) tt--;       stat[a] = 0;     }     return 0;   }   void print(int n) {     for (int i = 0; i <= n && h > 0; i++) {       if (stat[i] == 1) {         cout << i <<    ;         h--;       }     }     cout << endl;     for (int i = 0; i <= n && t > 0; i++) {       if (stat[i] == 2) {         cout << i <<    ;         t--;       }     }   }   int main() {     int n, m;     cin >> n >> m >> h >> t;     for (int i = 0; i <= n; i++) {       lvl.push_back(0);       graph.push_back(vector<int>());     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);       edges[i][0] = a;       edges[i][1] = b;     }     for (int i = 0; i <= n; i++) {       graph[i].push_back(-1);     }     for (int i = 0; i < m; i++) {       if (check(edges[i][0], edges[i][1])) {         cout <<  YES  << endl;         cout << edges[i][0] <<     << edges[i][1] << endl;         print(n);         return 0;       }       if (check(edges[i][1], edges[i][0])) {         cout <<  YES  << endl;         cout << edges[i][1] <<     << edges[i][0] << endl;         print(n);         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[3010];   pair<int, long long> dp[3010][3010], tmp[3010];   int v[3010], sz[3010];   void merge(int x, int y) {     for (int i = 0; i < sz[x] + sz[y]; i++) tmp[i] = pair<int, long long>(-1, 0);     for (int i = 0; i < sz[x]; i++)       for (int j = 0; j < sz[y]; j++) {         tmp[i + j] = max(tmp[i + j],                          pair<int, long long>(dp[x][i].first + dp[y][j].first,                                               dp[x][i].second + dp[y][j].second));         tmp[i + j + 1] = max(             tmp[i + j + 1], pair<int, long long>(dp[x][i].first + dp[y][j].first +                                                      (dp[y][j].second > 0),                                                  dp[x][i].second));       }     sz[x] += sz[y];     for (int i = 0; i < sz[x]; i++) dp[x][i] = tmp[i];   }   void dfs(int x, int p) {     sz[x] = 1;     dp[x][0] = pair<int, long long>(0, v[x]);     for (int i = 0; i < adj[x].size(); i++) {       int y = adj[x][i];       if (y == p) continue;       dfs(y, x);       merge(x, y);     }   }   void solve() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) v[i] = 0, adj[i].clear();     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       v[i] -= x;     }     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       v[i] += x;     }     for (int i = 1, x, y; i < n; i++) {       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(1, 0);     cout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << endl;   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int abc;   inline int rd(int l, int r) { return rand() % (r - l + 1) + l; }   const int mxn = 2e5 + 3, mod = 998244353;   long long por(long long x, int y = mod - 2) {     long long r = 1;     for (; y; y >>= 1) {       if (y & 1) r = r * x % mod;       x = x * x % mod;     }     return r;   }   int n, a[mxn], m, R[mxn], N;   long long w[2][mxn];   bool b[mxn];   bool chk() {     for (int i = 1; i <= n;) {       int x = a[i], y = x;       b[++m] = x > 1;       while (y--) {         if (a[i] != x) return 0;         ++i;       }     }     return 1;   }   struct VV {     vector<long long> a[2][2];     void ii(int s) {       a[0][0].resize(s), a[0][1].resize(s), a[1][0].resize(s), a[1][1].resize(s);     }   };   void ntt(vector<long long>& a, int n, bool tp = 0) {     for (int i = 1; i < n; ++i) R[i] = R[i >> 1] >> 1, R[i] |= (i & 1) * (n >> 1);     for (int i = 0; i < n; ++i) a[i] %= mod;     for (int i = 0; i < n; ++i)       if (i > R[i]) swap(a[i], a[R[i]]);     for (int d = 1, t = N >> 1; d < n; d *= 2, t >>= 1) {       for (int i = 0; i < n; i += d * 2)         for (int j = 0; j < d; ++j) {           long long x = a[i + j + d] * w[tp][t * j];           a[i + j + d] = (a[i + j] - x) % mod, a[i + j] = (a[i + j] + x) % mod;         }     }     if (tp) {       long long iv = por(n);       for (int i = 0; i < n; ++i) a[i] = a[i] * iv % mod;     }   }   vector<long long> d;   void NTT(vector<long long>& a, vector<long long>& b, vector<long long>& c,            int t1, int t2) {     for (int i = 0; i < n; ++i) d[i] = a[i] * b[i] % mod;     ntt(d, n, 1);     for (int i = 0; i < n; ++i)       if (d[i]) c[i] += d[i] * (t1 + 1) * (t2 + 1), c[i - 1] += d[i] * 2;     for (int i = 0; i < n; ++i) c[i] %= mod;   }   VV sol(int L, int R) {     if (L == R) {       VV r;       r.ii(2);       r.a[b[L]][b[L]][1] = 1;       return r;     }     int md = (L + R) >> 1;     VV v1 = sol(L, md), v2 = sol(md + 1, R), re;     n = 1;     while (n <= R - L + 1) n *= 2;     v1.ii(n), v2.ii(n), re.ii(n), d.resize(n);     for (int i1 = 0; i1 <= 1; ++i1)       for (int i2 = 0; i2 <= 1; ++i2)         for (int i3 = 0; i3 <= 1; ++i3)           for (int i4 = 0; i4 <= 1; ++i4) {             vector<long long>&h1 = v1.a[i1][i2], &h2 = v2.a[i3][i4];             h1[1] = (h1[1] + mod) % mod, h2[1] = (h2[1] + mod) % mod;             assert(h1[0] == 0 && h2[0] == 0);             assert(h1[1] >= 0 && h1[1] <= 1 && h2[1] >= 0 && h2[1] <= 1);             if (i1 == i2 && i3 == i4)               re.a[i1][i3][2] += h1[1] * h2[1], re.a[1][1][1] += h1[1] * h2[1];             if (i1 == i2) {               if (h1[1])                 for (int i = 2; i < n; ++i) {                   if (h2[i])                     assert(i + 1 < n), re.a[i1][i4][i + 1] += (i3 + 1) * h2[i],                         re.a[1][i4][i] += h2[i];                 }             }             if (i3 == i4) {               if (h2[1])                 for (int i = 2; i < n; ++i) {                   if (h1[i])                     assert(i + 1 < n), re.a[i1][i4][i + 1] += (i2 + 1) * h1[i],                         re.a[i1][1][i] += h1[i];                 }             }           }     for (int i = 0; i <= 1; ++i)       for (int j = 0; j <= 1; ++j) {         vector<long long>& v = v1.a[i][j];         v[1] = 0;         ntt(v, n);       }     for (int i = 0; i <= 1; ++i)       for (int j = 0; j <= 1; ++j) {         vector<long long>& v = v2.a[i][j];         v[1] = 0;         ntt(v, n);       }     for (int i1 = 0; i1 <= 1; ++i1)       for (int i2 = 0; i2 <= 1; ++i2)         for (int i3 = 0; i3 <= 1; ++i3)           for (int i4 = 0; i4 <= 1; ++i4)             NTT(v1.a[i1][i2], v2.a[i3][i4], re.a[i1][i4], i2, i3);     return re;   }   int main() {     abc = scanf( %d , &n);     for (int i = 1; i <= n; ++i) abc = scanf( %d , a + i);     if (!chk()) return puts( 0 ), 0;     N = 1;     while (N <= m) N *= 2;     assert(N < mxn && (mod - 1) % N == 0);     w[0][0] = w[1][0] = 1, w[0][1] = por(3, (mod - 1) / N),     w[1][1] = por(w[0][1]);     for (int i = 2; i < N; ++i)       w[0][i] = w[0][i - 1] * w[0][1] % mod,       w[1][i] = w[1][i - 1] * w[1][1] % mod;     VV re = sol(1, m);     long long ans = 0;     for (int i1 = 0; i1 <= 1; ++i1)       for (int i2 = 0; i2 <= 1; ++i2) {         vector<long long>& v = re.a[i1][i2];         long long jc = (m & 1) ? -1 : 1;         for (int i = 1; i <= m; ++i) {           jc *= -i, jc %= mod;           if (i == 1)             ans += v[i] * (i1 + 1) * jc % mod;           else             ans += v[i] * (i1 + 1) * (i2 + 1) * jc % mod;         }         ans %= mod;       }     printf( %lld n , (ans % mod + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x, y;     cin >> n >> m;     vector<pair<int, int>> v;     for (int i = 0; i < m; i++) {       cin >> x >> y;       v.push_back({y, x});     }     sort(v.begin(), v.end());     int ans = 0, counter = 0;     for (int i = m - 1; i >= 0; i--) {       if (counter + v[i].second <= n) {         ans += v[i].first * v[i].second;         counter += v[i].second;       } else {         ans += v[i].first * (n - counter);         break;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int val[300005];   long long num[300005];   int main() {     int n;     scanf( %d , &n);     long long s = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%lld , &val[i], &num[i]);       s += val[i];     }     long long ans = 0;     for (int i = 61; i >= 0; i--) {       long long s0 = 0, s1 = 0;       for (int j = 1; j <= n; j++)         if ((num[j] & (1LL << i)) && (num[j] >> i << i) == num[j]) {           bool v = (val[j] > 0) ^ (s > 0);           for (int k = 0; k < 62; k++)             if ((num[j] & ans) & (1LL << k)) v ^= 1;           if (v)             s0 += abs(val[j]);           else             s1 += abs(val[j]);         }       if (s1 > s0) ans ^= (1LL << i);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     while (n--) {       cout << 1 <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   const int N = 5054, mod = 1000000007;   int n, K;   int f[N];   long long PowerMod(long long a, int n, long long c = 1) {     for (; n; n >>= 1, a = a * a % mod)       if (n & 1) c = c * a % mod;     return c;   }   int main() {     int i, j, x, in, ans = 0;     std::ios::sync_with_stdio(false), cin.tie(NULL);     cin >> n >> K, *f = 1, in = PowerMod(n, mod - 2);     for (i = 0; i < n; ++i) {       cin >> x;       for (j = i + 1; j; --j) f[j] = ((long long)f[j] * x + mod - f[j - 1]) % mod;       *f = (long long)*f * x % mod;     }     for (x = mod - 1, i = 1; i <= n && i <= K; ++i)       x = x * (K - i + 1ll) % mod * in % mod,       ans = (ans + (long long)x * f[i]) % mod;     cout << ans <<   n ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int main()    {      long long t;      cin >> t;      while(t--){            string s;      cin >> s;      cout << s.size() << endl;          }    return 0;    }


#include <bits/stdc++.h>   using namespace std;   int seq[100050];   int n;   int l[40], r[40];   int dp[100050];   bool chk() {     for (int i = 1; i <= n; ++i)       if (seq[i] != i) return false;     return true;   }   void dfs(int dep) {     if (chk()) {       printf( %d n , dep);       for (int i = dep; i >= 1; --i) printf( %d %d n , l[i], r[i]);       exit(0);     }     if (dep == 3) return;     for (int i = 1; i <= n - 1; ++i) {       if (seq[i] != i &&           (abs(seq[i] - seq[i - 1]) != 1 || abs(seq[i] - seq[i + 1]) != 1)) {         for (int j = i + 1; j <= n; ++j)           if (seq[j] != j &&               (abs(seq[j] - seq[j + 1]) != 1 || abs(seq[j] - seq[j - 1]) != 1)) {             l[dep + 1] = i;             r[dep + 1] = j;             reverse(seq + i, seq + j + 1);             dfs(dep + 1);             reverse(seq + i, seq + j + 1);           }       }     }   }   int main() {     seq[0] = -1;     scanf( %d , &n);     seq[n + 1] = -1;     for (int i = 1; i <= n; ++i) scanf( %d , &seq[i]);     dfs(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> Height(n);     vector<int> count(n, 0);     for (int i = 0; i < n; i++) {       cin >> Height[i];     }     int x = 0, after = 1, befor = 0;     while (after < n && Height[x] >= Height[after]) {       count[0]++;       x++;       after++;     }     for (int i = 1; i < n - 1; i++) {       x = i, after = i + 1, befor = i - 1;       while (befor >= 0 && Height[x] >= Height[befor]) {         count[i]++;         x--;         befor--;       }       x = i;       while (after < n && Height[x] >= Height[after]) {         count[i]++;         x++;         after++;       }     }     x = n - 1;     befor = n - 2;     while (befor >= 0 && Height[x] >= Height[befor]) {       count[n - 1]++;       x--;       befor--;     }     sort(count.begin(), count.end());     cout << count[count.size() - 1] + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0, fl = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fl = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch -  0 );     return x * fl;   }   const int NN = 500000 + 17;   const int MM = 10000000 + 17;   void open() {     freopen( a.in ,  r , stdin);     freopen( a.out ,  w , stdout);   }   int n, maxx;   int pw[NN], miu[MM], pri[NN * 4], cnt;   int tax[MM], bs[MM], f[MM], has[MM];   bool notp[MM];   const int mod = 1e9 + 7;   int add(int x, int y) { return (x + y) % mod; }   int getmod(int x) { return (x + mod) % mod; }   void prework() {     pw[0] = 1;     for (int i = 1; i <= n; i++) pw[i] = add(pw[i - 1], pw[i - 1]);     miu[1] = 1;     for (int i = 2; i <= maxx; i++) {       if (!notp[i]) {         pri[++cnt] = i;         miu[i] = -1;       }       for (int j = 1; j <= cnt && i * pri[j] <= maxx; j++) {         notp[i * pri[j]] = true;         if (i % pri[j] == 0) {           miu[i * pri[j]] = 0;           break;         }         miu[i * pri[j]] = -miu[i];       }     }   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       int x = read();       maxx = max(maxx, x);       tax[x]++;     }     prework();     for (int i = maxx; i; i--)       for (int j = i; j <= maxx; j += i) {         bs[i] += tax[j];       }     for (int i = maxx; i; i--) {       f[i] = (pw[bs[i]] - 1 + mod) % mod;       for (int j = i + i; j <= maxx; j += i) {         f[i] = (f[i] - f[j] + mod) % mod;       }     }     for (int i = 1; i <= maxx; i++)       for (int j = i; j <= maxx; j += i) {         has[j] = add(has[j], 1LL * getmod(miu[i]) * bs[i] % mod);       }     int ans = 0;     for (int i = 2; i <= maxx; i++) {       ans = add(ans, 1LL * has[i] * f[i] % mod);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Segment {     int x1, y1, x2, y2;   };   struct Line {     long long a, b, c;   };   int n;   Segment seg[1005];   map<pair<int, int>, int> intersectCount;   unordered_map<int, int> toSubtract;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long det(long long a11, long long a12, long long a21, long long a22) {     return a11 * a22 - a12 * a21;   }   pair<int, int> intersectLines(const Line &l1, const Line &l2) {     long long detS = det(l1.a, l1.b, l2.a, l2.b);     if (detS == 0) return make_pair(0x3f3f3f3f, 0x3f3f3f3f);     long long detX = det(l1.c, l1.b, l2.c, l2.b);     long long detY = det(l1.a, l1.c, l2.a, l2.c);     if (detX % detS || detY % detS) return make_pair(0x3f3f3f3f, 0x3f3f3f3f);     return make_pair(detX / detS, detY / detS);   }   Line segmentToLine(const Segment &s) {     Line l;     l.a = s.y1 - s.y2;     l.b = s.x2 - s.x1;     l.c = l.a * s.x1 + l.b * s.y1;     return l;   }   pair<int, int> intersectSegments(const Segment &s1, const Segment &s2) {     return intersectLines(segmentToLine(s1), segmentToLine(s2));   }   bool pointInSegment(const pair<int, int> &A, const Segment &s) {     return min(s.x1, s.x2) <= A.first && A.first <= max(s.x1, s.x2) &&            min(s.y1, s.y2) <= A.second && A.second <= max(s.y1, s.y2);   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> seg[i].x1 >> seg[i].y1 >> seg[i].x2 >> seg[i].y2;     }     long long sol = 0;     for (int i = 1; i <= n; ++i) {       sol += gcd(abs(seg[i].x1 - seg[i].x2), abs(seg[i].y1 - seg[i].y2)) + 1;     }     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         pair<int, int> A = intersectSegments(seg[i], seg[j]);         if (A.first == 0x3f3f3f3f) continue;         if (pointInSegment(A, seg[i]) && pointInSegment(A, seg[j])) {           ++intersectCount[A];         }       }     }     int S = 0;     for (int i = 1; i <= n; ++i) {       S += i;       toSubtract[S] = i;     }     for (auto first : intersectCount) {       assert(toSubtract.count(first.second));       sol -= toSubtract[first.second];     }     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long C[1007][1007];   int main() {     long long n, m, k;     memset(C, 0, sizeof(C));     C[0][0] = 1;     for (long long i = 1; i <= 1000; i++) {       C[i][0] = 1;       for (long long j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;     }     while (cin >> n >> m >> k) {       long long a = n - 2 * k - 1;       long long b = m - 2 * k - 1;       if (a < 0 || b < 0)         cout << 0 << endl;       else         cout << (C[2 * k + a][a] * C[2 * k + b][b]) % 1000000007 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct _IO {     _IO() {       ios::sync_with_stdio(0);       cin.tie(0);     }   } _io;   using ll = long long;   using db = long double;   using pi = pair<int, int>;   using mi = map<int, int>;   const int N = 6e5 + 5, M = 1e9 + 7;   using vi = vector<int>;   ll ri() {     ll x;     cin >> x;     return x;   }   void prl() { cout <<   n ; }   template <class T, class... U>   void prl(T x, U... y) {     cout << x <<    , prl(y...);   }   template <class T, class U>   ostream &operator<<(ostream &out, pair<T, U> p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <class T>   ostream &operator<<(ostream &out, vector<T> &v) {     cout <<  { ;     for (int i = (0); i < (v.size()); ++i) {       if (i) cout <<  ,  ;       cout << v[i];     }     cout <<  } ;     return out;   }   struct cp {     db x, y;     cp(db a = 0, db b = 0) : x(a), y(b) {}     cp operator-(const cp &b) const { return cp(x - b.x, y - b.y); }     cp operator+(const cp &b) const { return cp(x + b.x, y + b.y); }     cp operator*(const cp &b) const {       return cp(x * b.x - y * b.y, x * b.y + y * b.x);     }     cp operator/(const int &b) const { return cp(x / b, y / b); }   };   const db PI = acos(-1);   int rev[N];   void init(int n) {     for (int i = 0, lim = __builtin_ctz(n); i < n; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (lim - 1));   }   void fft(cp *a, int n, int f) {     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int l = 2, m = 1; l <= n; m = l, l <<= 1)       for (cp *p = a, wn(cos(2 * PI / l), sin(f * 2 * PI / l)); p != a + n;            p += l)         for (cp *q = p, w(1, 0); q != p + m; q++, w = w * wn) {           cp t = *(q + m) * w;           *(q + m) = *q - t;           *q = *q + t;         }     if (f == -1)       for (int i = 0; i < n; i++) a[i] = a[i] / n;   }   cp a[N];   signed main() {     int n = ri(), m = ri(), k = ri();     string s, t, p =  ATCG ;     cin >> s >> t;     int len = 1;     while (len < n + m) len *= 2;     init(len);     vi ans(len), sum(n + 1);     for (int c = (0); c < (4); ++c) {       memset(a, 0, sizeof a);       for (int i = (0); i < (n); ++i) {         if (s[i] == p[c]) {           sum[i + 1] = 1;         } else {           sum[i + 1] = 0;         }         sum[i + 1] = sum[i] + sum[i + 1];       }       for (int i = (0); i < (n); ++i) {         if (sum[min(n, i + k + 1)] - sum[max(0, i - k)] >= 1) {           a[i].x = 1;         }       }       for (int i = (0); i < (m); ++i) {         if (t[i] == p[c]) {           a[m - i - 1].y = 1;         }       }       fft(a, len, 1);       for (int i = (0); i < (len); ++i) {         a[i] = a[i] * a[i];       }       fft(a, len, -1);       for (int i = (0); i < (len); ++i) {         ans[i] += (int)(a[i].y / 2 + 0.5);       }     }     int cnt = 0;     for (int i = (0); i < (n); ++i)       if (ans[i] == m) ++cnt;     prl(cnt);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200010, M = 2000010, INF = 0x3f3f3f3f;   inline long long max(long long x, long long y) { return x > y ? x : y; }   inline long long min(long long x, long long y) { return x < y ? x : y; }   inline void swap(long long &x, long long &y) { x ^= y ^= x ^= y; }   long long head[N], ver[M], Next[M], tot;   long long n, m, k, t, top, num, d[N], id[N], st[N], vis[N], size[N], f[N][20];   vector<long long> v[N];   bool cmp(long long x, long long y) { return id[x] < id[y]; }   void add(long long x, long long y) {     ver[++tot] = y, Next[tot] = head[x], head[x] = tot;   }   void dfs(long long x, long long fa) {     d[x] = d[fa] + 1;     id[x] = ++num;     for (long long i = head[x]; i; i = Next[i]) {       long long y = ver[i];       if (y == fa) continue;       f[y][0] = x;       for (long long j = 1; j <= t; j++) f[y][j] = f[f[y][j - 1]][j - 1];       dfs(y, x);     }   }   long long lca(long long x, long long y) {     if (d[x] > d[y]) swap(x, y);     for (long long i = t; i >= 0; i--)       if (d[f[y][i]] >= d[x]) y = f[y][i];     if (x == y) return x;     for (long long i = t; i >= 0; i--)       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     return f[x][0];   }   long long dp(long long x, long long fa) {     long long res = 0;     size[x] = vis[x];     for (long long i = 0; i < (long long)v[x].size(); i++)       if (v[x][i] != fa) res += dp(v[x][i], x);     if (size[x]) {       for (long long i = 0; i < (long long)v[x].size(); i++)         if (v[x][i] != fa) res += (size[v[x][i]]);     } else {       long long cnt = 0;       for (long long i = 0; i < (long long)v[x].size(); i++)         if (v[x][i] != fa) cnt += (size[v[x][i]]);       if (cnt == 1)         size[x] = 1;       else if (cnt > 1)         res++;     }     return res;   }   int main() {     scanf( %lld , &n);     t = (long long)(log(n) / log(2)) + 1;     for (long long i = 1; i < n; i++) {       long long x, y;       scanf( %lld%lld , &x, &y);       add(x, y), add(y, x);     }     dfs(1, 0);     scanf( %lld , &m);     while (m--) {       scanf( %lld , &k);       top = 0;       for (long long i = 1; i <= k; i++) {         long long x;         scanf( %lld , &x);         st[++top] = x;         vis[x] = 1;       }       long long flag = 0;       for (long long i = 1; i <= top; i++) flag |= vis[f[st[i]][0]];       sort(st + 1, st + top + 1, cmp);       for (long long i = 1; i < k; i++) {         long long l = lca(st[i], st[i + 1]);         if (l != st[i] && l != st[i + 1]) st[++top] = l;       }       st[++top] = 1;       sort(st + 1, st + top + 1);       top = unique(st + 1, st + top + 1) - st - 1;       sort(st + 1, st + top + 1, cmp);       for (long long i = 2; i <= top; i++) {         long long l = lca(st[i - 1], st[i]);         v[l].push_back(st[i]);       }       if (flag)         puts( -1 );       else         printf( %lld n , dp(st[1], 0));       for (long long i = 1; i <= top; i++) v[st[i]].clear();       for (long long i = 1; i <= top; i++) vis[st[i]] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tot[100100];   int maxd = 0;   vector<vector<int> > g;   void dfs(int v, int d, int p) {     maxd = ((maxd < d) ? (d) : (maxd));     tot[d]++;     for (int i = (0); i < (g[v].size()); ++i) {       int to = g[v][i];       if (to != p) {         dfs(to, d + 1, v);       }     }   }   int use[100100];   inline bool check(int k, int w) {     int l = 1, r = 1;     int sum = tot[l];     while (sum < k) {       r++;       sum += tot[r];     }     long long price = 0;     int need = k;     for (int i = r; i >= l; --i) {       int v = ((need < tot[i]) ? (need) : (tot[i]));       use[i] = v;       price += v * 1ll * (r - i);       need -= v;     }     if (price <= w) return true;     while (1) {       if (r == maxd) break;       sum += tot[r + 1];       while (1) {         if (l == r) break;         if (sum - tot[l] >= k) {           price -= (r - l) * 1ll * use[l];           sum -= tot[l];           l++;         } else {           int v = k - (sum - tot[l]);           price -= (r - l) * 1ll * (use[l] - v);           use[l] = v;           break;         }       }       r++;       use[r] = ((tot[r] < k) ? (tot[r]) : (k));       price += k - use[r];       if (price <= w) return true;     }     return false;   }   int main() {     int n, k, p;     scanf( %d%d%d , &n, &k, &p);     g.resize(n);     for (int i = (0); i < (n - 1); ++i) {       int v1, v2;       scanf( %d%d , &v1, &v2);       v1--;       v2--;       g[v1].push_back(v2);       g[v2].push_back(v1);     }     dfs(0, 0, -1);     int res = 0;     int le = 1, ri = ((n - 1 < k) ? (n - 1) : (k));     while (le <= ri) {       int m = (le + ri) / 2;       if (check(m, p)) {         res = m;         le = m + 1;       } else {         ri = m - 1;       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, e = 0, o = 0;       long long i, j;       long long ans = 0;       string str;       cin >> str;       for (i = 0; i < str.size(); i++) {         if (str[i] ==  0 )           e++;         else           o++;       }       ans = min(o, e);       if (ans % 2 == 1)         cout <<  DA  << endl;       else         cout <<  NET  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class B_808 {    public:     int main() {       int n, k, a[200005];       double ans = 0.0, sum = 0.0;       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < k; i++) sum += a[i];       ans += sum / ((double)n - k + 1);       for (int i = k; i < n; i++) {         sum += a[i] - a[i - k];         ans += sum / ((double)n - k + 1);       }       cout << std::fixed;       cout << std::setprecision(6) << ans << endl;       return 0;     }   };   class C_43 {    public:     int main() {       int n, a, ans = 0, m[3] = {0};       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a;         m[a % 3]++;       }       ans += m[0] / 2;       ans += min(m[1], m[2]);       cout << ans << endl;       return 0;     }   };   class B_814 {    private:     int n, a[1004], b[1004];     bool isValid() {       int d = 0;       for (int i = 0; i < n; i++) {         if (a[i] != b[i]) d++;       }       return d == 1;     }       public:     int main() {       int missing, rep = 0;       set<int> s;       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       for (int i = 1; i <= n; i++) s.insert(i);       for (int i = 0; i < n; i++) {         if (s.find(a[i]) != s.end()) {           s.erase(a[i]);         } else {           rep = a[i];         }       }       missing = *s.begin();       for (int i = 0; i < n; i++) {         if (a[i] == rep) {           a[i] = missing;           if (isValid()) {             break;           } else {             a[i] = rep;           }         }       }       for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ?   n  :    );       return 0;     }   };   class C_628 {    public:     int main() {       int n, k;       string s;       cin >> n >> k;       cin >> s;       string output = s;       for (int i = 0; i < n && k > 0; i++) {         if (abs( a  - s[i]) >= abs( z  - s[i])) {           if (abs( a  - s[i]) < k) {             output[i] =  a ;             k -= abs( a  - s[i]);           } else {             output[i] = s[i] - k;             k = 0;           }         } else {           if (abs( z  - s[i]) < k) {             output[i] =  z ;             k -= abs( z  - s[i]);           } else {             output[i] = s[i] + k;             k = 0;           }         }       }       if (k == 0) {         cout << output;       } else {         cout <<  -1 ;       }       return 0;     }   };   class D_182 {    private:     bool verify(string &d, string &s) {       int n = (int)d.length();       for (int i = 0; i < s.length(); i++) {         if (d[i % n] != s[i]) {           return false;         }       }       return true;     }       public:     int main() {       string s1, s2, d;       cin >> s1 >> s2;       set<string> divisors;       int ans = 0;       int n = (int)s1.size();       for (int i = 1; i * i <= n; i++) {         if (n % i == 0) {           d = s1.substr(0, i);           if (verify(d, s1)) {             divisors.insert(d);           }           d = s1.substr(0, n / i);           if (verify(d, s1)) {             divisors.insert(d);           }         }       }       n = (int)s2.size();       for (int i = 1; i * i <= n; i++) {         if (n % i == 0) {           d = s2.substr(0, i);           if (verify(d, s2) && divisors.find(d) != divisors.end()) {             ans++;           }           if (i * i == n) continue;           d = s2.substr(0, n / i);           if (verify(d, s2) && divisors.find(d) != divisors.end()) {             ans++;           }         }       }       cout << ans;       return 0;     }   };   int main(int argc, const char *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     D_182().main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int maxm = 1e5 + 5;   const long double eps = 1e-14;   const long double eps2 = 1e-9;   const long double INF = 1 << 30;   inline int dcmp(const long double& x) {     return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1);   }   pair<long double, long double> operator+(       const pair<long double, long double>& a,       const pair<long double, long double>& b) {     return {a.first + b.first, a.second + b.second};   }   pair<long double, long double> operator-(       const pair<long double, long double>& a,       const pair<long double, long double>& b) {     return {a.first - b.first, a.second - b.second};   }   pair<long double, long double> operator*(       const pair<long double, long double>& a, const long double& b) {     return {a.first * b, a.second * b};   }   long double dot(const pair<long double, long double>& a,                   const pair<long double, long double>& b) {     return a.first * b.first + a.second * b.second;   }   long double cross(const pair<long double, long double>& a,                     const pair<long double, long double>& b) {     return a.first * b.second - a.second * b.first;   }   long double abs(const pair<long double, long double>& a) {     return sqrt(dot(a, a));   }   long double interPnt(pair<long double, long double> p1,                        pair<long double, long double> p2,                        pair<long double, long double> q1,                        pair<long double, long double> q2) {     pair<long double, long double> d = p2 - p1, e = q2 - q1;     long double crs = cross(d, e);     if (abs(crs) < eps) {       long double c2 = cross(d, q1 - p1);       if (abs(c2) > eps) return INF;       long double da2 = dot(d, d);       long double f1 = dot(d, q1 - p1) / da2;       long double f2 = dot(d, q2 - p1) / da2;       if (f1 < -eps and f2 < -eps) return INF;       if (f1 > 1 + eps and f2 > 1 + eps) return INF;       long double f = max(0.l, min(f1, f2));       return (p1 + d * f).first;     }     assert(0);   }   template <typename T>   inline bool getmin(T& a, const T& b) {     return dcmp(b - a) < 0 ? (a = b, true) : false;   }   template <typename T>   inline bool getmax(T& a, const T& b) {     return dcmp(b - a) > 0 ? (a = b, true) : false;   }   struct Iron {     int show, speed, st, ed;     inline void read() {       scanf( %d%d%d%d , &show, &speed, &st, &ed);       st--, ed--;     }   } iron[maxm];   struct Iron2 {     long double from, fromt, to, tot;   };   struct Path {     int id, from, to;   };   struct Event {     long double t;     int segid;     bool operator<(const Event& rhs) const { return dcmp(t - rhs.t) < 0; }   };   int n, m;   vector<int> G[maxn], chain[maxn];   int fa[maxn], dep[maxn], chainid[maxn], size[maxn];   int pre[maxn], dfs_clock;   void dfs(int now) {     vector<int>& vec = chain[chainid[now]];     for (int i = ((int)(vec.size())) - 1; i >= 0; i--) pre[vec[i]] = dfs_clock++;     for (int i = 0; i < ((int)(vec.size())); i++) {       int now = vec[i];       for (const int& to : G[now])         if ((!i || to != vec[i - 1]) && to != fa[now]) dfs(to);     }   }   inline void make_HLD() {     int first = 0, last = 0;     int* q = new int[n];     q[last++] = 0;     fa[0] = -1;     dep[0] = 0;     while (last - first > 0) {       int now = q[first++];       for (const int& to : G[now])         if (to != fa[now]) {           fa[to] = now;           dep[to] = dep[now] + 1;           q[last++] = to;         }     }     for (int i = last - 1; i >= 0; i--) {       int now = q[i], hs = -1;       size[now] = 1;       for (const int& to : G[now])         if (to != fa[now]) {           size[now] += size[to];           if (hs < 0 || size[to] > size[hs]) hs = to;         }       if (hs < 0)         chainid[now] = now;       else         chainid[now] = chainid[hs];       chain[chainid[now]].push_back(now);     }     dfs_clock = 0;     delete[] q;     dfs(0);   }   inline bool inrange(const long double& x, const long double& L,                       const long double& R) {     return dcmp(x - L) >= 0 && dcmp(x - R) <= 0;   }   inline long double getIntersectime(const Iron2& A, const Iron2& B) {     const long double &x1 = A.from, &t1 = A.fromt, &x2 = A.to, &t2 = A.tot,                       &x3 = B.from, &t3 = B.fromt, &x4 = B.to, &t4 = B.tot;     long double deno = (x2 - x1) * (t4 - t3) - (t2 - t1) * (x4 - x3);     long double nume = (x3 - x1) * (t2 - t1) * (t4 - t3) -                        t3 * (t2 - t1) * (x4 - x3) + t1 * (t4 - t3) * (x2 - x1);     long double ans;     if (dcmp(deno) == 0) {       return interPnt(make_pair(t1, x1), make_pair(t2, x2), make_pair(t3, x3),                       make_pair(t4, x4));       if (dcmp((x4 - x3) / (t4 - t3) * (t1 - t3) + x3 - x1) == 0)         ans = max(t1, t3);       else         ans = INF;     } else       ans = nume / deno;     if (inrange(ans, max(t1, t3), min(t2, t4)))       return ans;     else       return INF;   }   long double curtime;   vector<Iron2> vec;   struct cmp {     inline long double getpos(const Iron2& I, const long double& t) const {       return I.from + ((I.to - I.from) / (I.tot - I.fromt)) * (t - I.fromt);     }     bool operator()(const int& a, const int& b) const {       long double d1 = dcmp(getpos(vec[a], curtime) - getpos(vec[b], curtime)),                   d2 = dcmp(getpos(vec[a], curtime + 1) -                             getpos(vec[b], curtime + 1));       return d1 < 0 || (d1 == 0 && d2 < 0) || (d1 == 0 && d2 == 0 && a < b);     }   };   vector<Iron2> Seg[maxn];   inline long double solve_path(const int& nowSeg) {     vec = Seg[nowSeg];     set<int, cmp> second;     vector<Event> eve;     for (int i = 0; i < ((int)(vec.size())); i++)       eve.push_back((Event){vec[i].fromt, i << 1}),           eve.push_back((Event){vec[i].tot, i << 1 | 1});     sort(eve.begin(), eve.end());     long double ans = INF;     for (const Event& e : eve) {       curtime = e.t;       if (dcmp(curtime - ans) >= 0) break;       int id = e.segid;       if (!(id & 1)) {         id /= 2;         set<int>::iterator it = second.lower_bound(id);         assert(second.find(id) == second.end());         if (it != second.end()) getmin(ans, getIntersectime(vec[id], vec[*it]));         if (it != second.begin())           it--, getmin(ans, getIntersectime(vec[id], vec[*it]));         second.insert(id);       } else {         id /= 2;         set<int>::iterator it = second.lower_bound(id), itL = it, itR = it;         assert((*it) == id);         itR++;         if (itL != second.begin() && itR != second.end()) {           itL--;           getmin(ans, getIntersectime(vec[*itL], vec[*itR]));         }         second.erase(it);       }     }     return ans;   }   vector<Path> path, L, R;   inline void getPath(int a, int b) {     L.clear();     R.clear();     while (chainid[a] != chainid[b]) {       int atop = chain[chainid[a]].back(), btop = chain[chainid[b]].back();       if (dep[atop] > dep[btop])         L.push_back((Path){chainid[a], a, fa[atop]}), a = fa[atop];       else         R.push_back((Path){chainid[b], fa[btop], b}), b = fa[btop];     }     L.push_back((Path){chainid[a], a, b});     path.clear();     for (int i = 0; i < ((int)(L.size())); i++) path.push_back(L[i]);     for (int i = ((int)(R.size())) - 1; i >= 0; i--) path.push_back(R[i]);   }   inline int PosOnPath(int id, int now) {     if (chainid[now] != id) return 0;     return pre[now] - pre[chain[id].back()] + 1;   }   inline long double solve_tree() {     make_HLD();     for (int i = 0; i < m; i++) {       getPath(iron[i].st, iron[i].ed);       long double curt = iron[i].show, v = iron[i].speed;       for (const Path& p : path) {         int from = PosOnPath(p.id, p.from), to = PosOnPath(p.id, p.to);         long double arrt = curt + abs(to - from) / v;         long double cc = dcmp(arrt - curt) == 0 ? 0 : (to - from) / (arrt - curt);         Seg[p.id].push_back(             (Iron2){from - eps2 * cc, curt - eps2, to + eps2 * cc, arrt + eps2});         curt = arrt;       }     }     long double res = INF;     for (int i = 0; i < n; i++) getmin(res, solve_path(i));     return res;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, a, b; i < n - 1; i++) {       scanf( %d%d , &a, &b);       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 0; i < m; i++) iron[i].read();     long double ans = solve_tree();     if (dcmp(ans - INF) >= 0)       printf( -1 n );     else       printf( %.13f n , (double)ans);   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int mod = 1e9 + 7;   const long long inf = 1e18;   int d, n, m, x[N], p[N], cur, r[N];   long long ans = inf, carry;   pair<int, int> a[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second;     vector<int> st;     sort(a + 1, a + m + 1);     for (int i = 1; i <= m; i++) x[i] = a[i].first, p[i] = a[i].second;     for (int i = m; i >= 0; i--) {       r[i] = i;       while (st.size() && p[st.back()] >= p[i]) {         r[i] = r[st.back()];         st.pop_back();       }       st.push_back(i);     }     for (int i = 0, j = 0; i <= m; i++) {       if (cur < 0) {         ans = inf;         break;       }       while (j + 1 <= m && x[j + 1] - x[i] <= n) j++;       if (n >= d - x[i]) {         long long dist = d - x[i];         long long cost = carry;         if (dist > cur) cost += 1ll * (dist - cur) * p[i];         ans = min(ans, cost);       }       if (j < r[i] + 1) {         carry += 1ll * (n - cur) * p[i];         cur = n;       } else {         long long dist = x[r[i] + 1] - x[i];         if (dist > n) dist = n;         if (dist > cur) {           carry += 1ll * (dist - cur) * p[i];           cur = dist;         }       }       cur -= (x[i + 1] - x[i]);     }     if (ans == inf) ans = -1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[1000010];   int n, k;   bool r[1000010];   int s[1000010];   int m[1000010];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < k; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(y);     }     int v = 0;     for (int i = 1; i <= n; i++) {       if (r[i]) continue;       s[v++] = i;       r[i] = true;       for (int j = 0; j < (int)g[i].size(); j++) r[g[i][j]] = true;     }     int sz = 0;     for (int i = 1; i <= n; i++) r[i] = false;     for (int i = v - 1; i >= 0; i--) {       if (!r[s[i]]) {         m[sz++] = s[i];         for (int j = 0; j < (int)g[s[i]].size(); j++) r[g[s[i]][j]] = true;       }     }     printf( %d n , sz);     for (int i = 0; i < sz; i++) printf( %d  , m[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 100;   int c[maxn], a[maxn];   int main() {     int n, m, l = 0, ans = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> c[i];     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 0; i < n; i++)       if (a[l] >= c[i]) {         ans++;         l++;       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     int x = 0, y = 0, pos = 0, coin = 0;     if (s[0] ==  R )       x++;     else       y++;     if (y > x) pos = 2;     if (x > y) pos = 1;     for (int i = 1; i < s.length(); i++) {       if (s[i] ==  R )         x++;       else         y++;       int npos = 0;       if (y > x) npos = 2;       if (x > y) npos = 1;       if (npos != 0 && npos != pos) {         coin++;         pos = npos;       }     }     cout << coin;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int r, x, y, x1, y1;     cin >> r >> x >> y >> x1 >> y1;     double d;     d = pow((((x - x1) * (x - x1)) + ((y - y1) * (y - y1))), 0.5);     cout << ceil(d / (2 * r)) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, min1, min2, a, b;     cin >> t;     while (t--) {       cin >> n;       long long arr1[n];       long long arr2[n];       for (long long c = 0; c < n; c++) {         cin >> arr1[c];       }       for (long long d = 0; d < n; d++) {         cin >> arr2[d];       }       min1 = arr1[0];       for (long long i = 0; i < n; i++) {         if (min1 > arr1[i]) {           min1 = arr1[i];         }       }       min2 = arr2[0];       for (long long j = 0; j < n; j++) {         if (min2 > arr2[j]) {           min2 = arr2[j];         }       }       long long count = 0;       for (long long k = 0; k < n; k++) {         a = arr1[k] - min1;         b = arr2[k] - min2;         if (a > b) {           count = count + a;         } else {           count = count + b;         }       }       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn];   long long s[maxn], ss[maxn];   pair<int, long long> que[maxn];   int tot;   pair<int, long long> operator-(pair<int, long long> b, pair<int, long long> a) {     pair<int, long long> c;     c.first = b.first - a.first;     c.second = b.second - a.second;     return c;   }   bool operator>(pair<int, long long> b, pair<int, long long> a) {     double x = 1.0 * a.second / a.first;     double y = 1.0 * b.second / b.first;     return x > y;   }   int main() {     int i, j, n;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[n - i + 1]);     }     for (i = 1; i <= n; i++) {       s[i] = s[i - 1] + a[i];       ss[i] = ss[i - 1] + s[i];     }     long long ans = 0;     for (i = n; i >= 1; i--) {       ans = max(ans, (long long)a[i]);       while (tot > 1 && (que[tot - 1] - make_pair(i, ss[i])) >                             (que[tot - 2] - que[tot - 1])) {         tot--;       }       que[tot++] = make_pair(i, ss[i]);       if (tot == 1) {         continue;       }       int le = 0, ri = tot - 2;       int mid;       while (le <= ri) {         mid = (le + ri) / 2;         double x = (que[mid].second - que[mid + 1].second) * 1.0 /                    (que[mid].first - que[mid + 1].first);         if (x >= s[i - 1]) {           ri = mid - 1;         } else           le = mid + 1;       }       ans = max(ans,                 que[le].second - ss[i - 1] - (que[le].first - i + 1) * s[i - 1]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int row[] = {0, 1, 0, -1, -1, -1, 1, 1};   int col[] = {1, 0, -1, 0, 1, -1, -1, 1};   const long long N = 2e5 + 10;   const long long M = 1e18 + 7;   const long long H = 1e9 + 7;   const long long base = 131;   long long logx(long long a, long long bs) { return log(a) / log(bs); }   long long Max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long Min(long long a, long long b) {     if (a > b) return b;     return a;   }   long long big_mul(long long a, long long b, long long m) {     long long x = 0, y = a % m;     while (b > 0) {       if (b & 1) x = (x + y) % m;       y = (2 * y) % m;       b >>= 1;     }     return x % m;   }   long long big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = (x * y) % m;       y = (y * y) % m;       b >>= 1;     }     return x % m;   }   long long Big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = big_mul(x, y, m);       y = big_mul(y, y, m);       b >>= 1;     }     return x % m;   }   long long mod_inverse(long long a, long long m) { return big_mod(a, m - 2, m); }   long long GCD(long long a, long long b) {     if (!a) return b;     return GCD(b % a, a);   }   double l, r;   vector<double> vec1;   vector<double> vec2;   double fnct(double total, double value) { return total / value; }   bool possible(double x, double m) {     double total = m + x;     double need = fnct(total, vec1[0]);     if (need > x) return false;     x -= need;     total = m + x;     for (int i = 1; i < vec1.size(); i++) {       need = fnct(total, vec2[i]);       if (need > x) return false;       x -= need;       total = m + x;       need = fnct(total, vec1[i]);       if (need > x) return false;       x -= need;       total = m + x;     }     need = fnct(total, vec2[0]);     if (need > x) return false;     return true;   }   void bs(double m) {     l = 0;     r = (double)H;     int cnt = 0;     while (cnt++ <= 100) {       double mid = (l + r) / 2.0;       if (possible(mid, m) == true)         r = mid;       else         l = mid;     }     if (l == H || r == H)       cout <<  -1  << endl;     else       printf( %0.10lf n , l);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     double m;     cin >> m;     for (int i = 0; i < n; i++) {       double a;       cin >> a;       vec1.push_back(a);     }     for (int i = 0; i < n; i++) {       double a;       cin >> a;       vec2.push_back(a);     }     bs(m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 11;   const long long MOD0 = 1e9 + 7;   const long long P0 = 37;   const long long MOD1 = 1e9 + 9;   const long long P1 = 49;   long long a[N], b[N];   long long h1[2][N], h2[2][N], s[2][N];   long long m, n;   map<int, bool> ans;   int getnext(int pos) {     if (pos > a[n]) return 1e9;     int l = 1, r = n;     while (r - l > 1) {       int mid = (l + r) / 2;       if (a[mid] >= pos)         r = mid;       else         l = mid;     }     if (a[l] >= pos) return l;     return r;   }   int getprev(int pos) {     if (pos < a[1]) return -1e9;     int l = 1, r = n;     while (r - l > 1) {       int mid = (l + r) / 2;       if (a[mid] <= pos)         l = mid;       else         r = mid;     }     if (a[r] <= pos) return r;     return l;   }   bool good0(int l, int r) {     long long hash1 = h1[0][r] - h1[0][l - 1] + MOD0;     hash1 *= s[0][n - r];     hash1 %= MOD0;     long long hash2 = h2[0][l] - h2[0][r + 1] + MOD0;     hash2 *= s[0][l];     hash2 %= MOD0;     if (hash1 == hash2) return true;     return false;   }   bool good1(int l, int r) {     long long hash1 = h1[1][r] - h1[1][l - 1] + MOD1;     hash1 *= s[1][n - r];     hash1 %= MOD1;     long long hash2 = h2[1][l] - h2[1][r + 1] + MOD1;     hash2 *= s[1][l];     hash2 %= MOD1;     if (hash1 == hash2) return true;     return false;   }   bool good(long long x, long long y) {     if (x > y) return true;     if (y < a[1]) return true;     int l = getnext(x), r = getprev(y);     if (l > r) return true;     if (a[l] - x != y - a[r]) return false;     if (l == r) return true;     if (good1(l, r - 1) && good0(l, r - 1)) return true;     return false;   }   bool good(long long p) {     if (ans[p]) return false;     ans[p] = 1;     if (good(0, p) && good(p + 1, m - 1)) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];     s[0][0] = 1;     s[1][0] = 1;     for (int i = 1; i <= n * 2; i++) {       s[0][i] = (s[0][i - 1] * P0) % MOD0;       s[1][i] = (s[1][i - 1] * P1) % MOD1;     }     for (int i = 1; i < n; i++) {       h1[0][i] = (h1[0][i - 1] + b[i] * s[0][i]) % MOD0;       h1[1][i] = (h1[1][i - 1] + b[i] * s[1][i]) % MOD1;     }     for (int i = n - 1; i >= 1; i--) {       h2[0][i] = (h2[0][i + 1] + b[i] * s[0][n - i]) % MOD0;       h2[1][i] = (h2[1][i + 1] + b[i] * s[1][n - i]) % MOD1;     }     vector<int> vv;     for (int i = 1; i <= n; i++) {       long long x = (a[1] + a[i]) % m;       if (good(x)) vv.push_back(x);     }     sort(vv.begin(), vv.end());     cout << vv.size() << endl;     for (int j = 0; j < vv.size(); j++) cout << vv[j] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       vector<int> v;       long long res, me = 0, mf = 0;       for (int i = 0; i < n; i++) {         int c;         cin >> c;         v.push_back(c);       }       long long res1 = 1000000 - v[0];       res = 1000007;       v.push_back(1000000);       for (int i = 0; i < v.size() - 1; i++) {         me = v[i] - 1;         mf = 1000000 - v[i + 1];         if (i == n - 1) {           res = min(res, me);           continue;         }         res = min(res, max(me, mf));       }       cout << min(res, res1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   int n, m, l, x, oo = 1000000007, c[100005], a[100005], b[100005];   long long res = 1, ans;   long long Exp(long long x, long long y) {     long long res = 1;     for (; y; y >>= 1, x = x * x % oo)       if (y & 1) res = res * x % oo;     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &x), c[x]++;     for (int i = 100005 - 5; i; i--) c[i - 1] += c[i];     for (int i = 1; c[i]; i++) {       m = l = 0, res = 1;       for (int j = 1; j * j <= i; j++)         if (i % j == 0) {           a[m++] = j;           if (j * j - i) b[l++] = i / j;         }       while (l--) a[m++] = b[l];       for (int j = 1; j < m; j++) res = res * Exp(j, c[a[j - 1]] - c[a[j]]) % oo;       ans = (ans + res * (Exp(m, c[i]) - Exp(m - 1, c[i]))) % oo;     }     printf( %d n , (ans + oo) % oo);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EXP = 1e-11;   const int maxn = 2e5 + 10;   int n;   double a[maxn];   double a2[maxn];   double Judge(double x) {     double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;     for (int i = 1; i <= n; i++) a2[i] = a[i] - x;     for (int i = 1; i <= n; i++) {       sum1 = max(sum1 + a2[i], a2[i]);       sum3 = max(sum3, sum1);     }     for (int i = 1; i <= n; i++) a2[i] = a2[i] * (-1.0);     for (int i = 1; i <= n; i++) {       sum2 = max(sum2 + a2[i], a2[i]);       sum3 = max(sum3, sum2);     }     return sum3;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i]);     double l = -40000.0, r = 40000.0;     while (r - l > EXP) {       double mid = (l + l + r) / 3.0;       double mmid = (l + r + r) / 3.0;       if (Judge(mid) >= Judge(mmid))         l = mid;       else         r = mmid;     }     printf( %.13lf n , min(Judge(l), Judge(r)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<bitset<7>> score;   vector<bitset<7>> bvec(10);   map<unsigned long, int> bmap;   bool flag = false;   long long ans = 0;   vector<string> anss;   int ccc = 0;   int ans_tab[2001][10][2001];   bool valid(vector<bitset<7>>& s, int cur, int dig, int cnt) {     if (ans_tab[cur][dig][cnt] != -1) return ans_tab[cur][dig][cnt];     ccc++;     bool vld = (score[cur] & bvec[dig]).to_ulong() == score[cur].to_ulong();     if (vld) {       int x = __builtin_popcount((char)(score[cur] ^ bvec[dig]).to_ulong());       if (cnt - x >= 0) {         if (cur == n - 1 && cnt - x == 0) {           flag = true;           return ans_tab[cur][dig][cnt] = true;         } else {           for (int j = 9; j >= 0; j--) {             if (ans_tab[cur][dig][cnt] = valid(s, cur + 1, j, cnt - x)) {               return true;             }           }         }       } else {         return ans_tab[cur][dig][cnt] = false;       }     }     return ans_tab[cur][dig][cnt] = false;   }   void solve() {     memset(ans_tab, -1, sizeof(ans_tab));     cin >> n >> k;     string in;     for (int i = 0; i < n; ++i) {       cin >> in;       score.emplace_back(in);     }     bvec = {bitset<7>( 1110111 ), bitset<7>( 0010010 ), bitset<7>( 1011101 ),             bitset<7>( 1011011 ), bitset<7>( 0111010 ), bitset<7>( 1101011 ),             bitset<7>( 1101111 ), bitset<7>( 1010010 ), bitset<7>( 1111111 ),             bitset<7>( 1111011 )};     for (int i = 0; i < (int)bvec.size(); ++i) {       bmap[bvec[i].to_ulong()] = i;     }     string test =   ;     test =   ;     int cc = k;     for (int j = 9; j >= 0; --j) {       valid(score, 0, j, cc);     }     if (flag) {       for (int i = 0; i < n; ++i) {         for (int j = 9; j >= 0; --j) {           bool vld = (score[i] & bvec[j]).to_ulong() >= score[i].to_ulong();           if (vld) {             int x = __builtin_popcount((char)(score[i] ^ bvec[j]).to_ulong());             if (cc - x >= 0) {               if (ans_tab[i][j][cc]) {                 test += to_string(j);                 cc -= x;                 break;               }             }           }         }       }       cout << test << endl;     } else       cout << -1 << endl;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   long long dp[N][N][N];   char s[N];   int a[N];   long long f[N];   void update(long long &x, long long y) {     if (y == -1) return;     if (x == -1 || x < y) x = y;   }   bool vis[N][N][N];   long long dfs(int l, int r, int p) {     if (l > r) return a[p];     if (vis[l][r][p]) return dp[l][r][p];     vis[l][r][p] = true;     if (l == r) {       return dp[l][r][p] = f[p + 1];     }     dp[l][r][p] = dfs(l, r - 1, 0) + f[p + 1];     for (int k = l; k < r; k++)       if (s[k] == s[r]) {         update(dp[l][r][p], dfs(l, k, p + 1) + dfs(k + 1, r - 1, 0));       }     return dp[l][r][p];   }   int main() {     int n;     cin >> n;     cin >> (s + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     f[0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++) f[i] = max(f[i], f[i - j] + a[j]);     memset(dp, -1, sizeof(dp));     cout << dfs(1, n, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   void test_case() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> l(n), r(n);     l[0] = 1;     for (int i = 1; i < n; i++) {       if (arr[i] > arr[i - 1])         l[i] = l[i - 1] + 1;       else         l[i] = 1;     }     r[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       if (arr[i] < arr[i + 1])         r[i] = r[i + 1] + 1;       else         r[i] = 1;     }     int ans = 1;     for (int i = 0; i < n; i++) {       if (i > 0 && i < n - 1 && arr[i + 1] >= arr[i - 1] + 2) {         ans = max(ans, l[i - 1] + r[i + 1] + 1);       }       if (i > 0 && arr[i] <= arr[i - 1]) {         ans = max(ans, 1 + l[i - 1]);       }       if (i < n - 1 && arr[i] >= arr[i + 1]) {         ans = max(ans, 1 + r[i + 1]);       }     }     ans = max(ans, l[n - 1]);     ans = max(ans, r[0]);     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t = 1;     while (t--) test_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     scanf( %lld , &n);     scanf( %lld , &k);     long long int i, j;     long long int val = 0, val1 = 0, val2 = 1;     for (i = 1; i < k; i++) {       val = (val * 10) + 9;       val2 = val2 * 10;     }     val1 = (val * 10) + 9;     long long int arr[n + 5];     long long int brr[n + 5];     long long int m = n / k;     for (i = 0; i < m; i++) {       scanf( %lld , &arr[i]);     }     for (i = 0; i < m; i++) {       scanf( %lld , &brr[i]);     }     long long int tot = 1;     long long int mod = 1e9 + 7;     for (i = 0; i < m; i++) {       long long int t1 = val1 / arr[i];       if (brr[i] != 0) t1++;       long long int t2 = (brr[i] * val2) + val;       long long int t3 = t2 / arr[i];       long long int t4 = (max(0LL, brr[i] * val2 - 1)) / arr[i];       t3 = t3 - t4;       long long int t5 = t1 - t3;       tot *= t5;       tot %= mod;     }     cout << tot <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _Tp, typename _Up>   bool maximize(_Tp &__a, _Up __b) {     if (__a < __b) {       __a = __b;       return true;     }     return false;   }   template <typename _Tp, typename _Up>   bool minimize(_Tp &__a, _Up __b) {     if (__a > __b) {       __a = __b;       return true;     }     return false;   }   const long long siz = 2e5 + 2;   const long long SIZ = 1e6 + 2;   const long long mod = 1e9 + 7;   const long long maxx = 2e9;   const long long MAXX = 1e18;   const string file =  3 ;   struct fenwick_tree {     long long n;     vector<long long> fwt;     fenwick_tree(long long n) : n(n) { fwt.assign(n + 1, 0); }     void pos_update(long long pos, long long val) {       assert(1 <= pos && pos <= n);       for (long long i = pos; i <= n; i += i & (-i)) {         fwt[i] += val;       }     }     long long pre_sum(long long pos) {       assert(0 <= pos && pos <= n + 1);       long long res = 0;       for (long long i = pos; i > 0; i -= i & (-i)) {         res += fwt[i];       }       return res;     }     long long suf_sum(long long pos) { return (pre_sum(n) - pre_sum(pos - 1)); }     long long range_sum(long long lt, long long rt) {       if (lt > rt) {         return 0;       }       return (pre_sum(rt) - pre_sum(lt - 1));     }   };   long long ans[siz];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<pair<pair<long long, long long>, long long> > hold;     for (long long i = 1; i <= n; i++) {       long long l, r;       cin >> l >> r;       hold.push_back(pair<pair<long long, long long>, long long>(           pair<long long, long long>(l, r), i));     }     vector<long long> rar;     for (auto x : hold) {       rar.push_back(x.first.first);       rar.push_back(x.first.second);     }     sort((rar).begin(), (rar).end());     rar.resize(unique((rar).begin(), (rar).end()) - rar.begin());     for (auto &x : hold) {       long long &l = x.first.first, &r = x.first.second;       l = lower_bound((rar).begin(), (rar).end(), l) - rar.begin() + 1;       r = lower_bound((rar).begin(), (rar).end(), r) - rar.begin() + 1;     }     sort((hold).begin(), (hold).end(),          [](const pair<pair<long long, long long>, long long> &x,             const pair<pair<long long, long long>, long long> &y) {            return (x.first.first > y.first.first);          });     fenwick_tree fen(2 * n);     for (auto x : hold) {       long long l = x.first.first, r = x.first.second, i = x.second;       ans[i] = fen.pre_sum(r);       fen.pos_update(r, 1);     }     for (long long i = 1; i <= n; i++) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long first, second, cycle_s, cycle_len, l;   int n, m, d, cnt[2][1000005][26];   string A, B;   int gcd(int first, int second) {     if (!second) return first;     return gcd(second, first % second);   }   int main() {     cin >> first >> second >> A >> B;     n = A.size();     m = B.size();     d = gcd(n, m);     int i, j;     for (i = 0; i < n; i += d)       for (j = 0; j < d; j++) cnt[0][j][A[i + j] -  a ]++;     for (i = 0; i < m; i += d)       for (j = 0; j < d; j++) cnt[1][j][B[i + j] -  a ]++;     for (j = 0; j < d; j++)       for (i = 0; i < 26; i++) cycle_s += (long long)cnt[0][j][i] * cnt[1][j][i];     cycle_len = (long long)m * n / d;     l = n * first;     cout << l - l / cycle_len * cycle_s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t MOD = 1e9 + 7;   void add(int64_t& a, int64_t b) { a = (a + b) % MOD; }   int nth_bit(int64_t num, int n) { return (num >> n) & 1; }   const int SZ = 14 * 16;   void matmul(int64_t A[SZ][SZ], int64_t B[SZ][SZ]) {     int64_t ret[SZ][SZ] = {0};     for (int i = 0; i < SZ; i++)       for (int j = 0; j < SZ; j++)         for (int k = 0; k < SZ; k++) add(ret[i][j], A[i][k] * B[k][j]);     for (int i = 0; i < SZ; i++)       for (int j = 0; j < SZ; j++) A[i][j] = ret[i][j];   }   int main() {     int N, K, M;     cin >> N >> K >> M;     static int64_t A[SZ][SZ];     for (int j = 0; j <= K; j++)       for (int bits = 0; bits < 16; bits++) {         int pos = 1;         for (int k = 0; k < M; k++)           if (nth_bit(bits, k)) pos++;         add(A[(j + 1) * 16 + (bits << 1) % 16 + 1][j * 16 + bits], pos);         add(A[j * 16 + (bits << 1) % 16][j * 16 + bits], 1);       }     static int64_t B[SZ][SZ];     for (int i = 0; i < SZ; i++) B[i][i] = 1;     while (N > 0) {       if (N % 2) matmul(B, A);       matmul(A, A);       N /= 2;     }     int64_t ans = 0;     for (int bits = 0; bits < 16; bits++) add(ans, B[K * 16 + bits][0]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double ans = 0.0000;   void bfs();   list<int> arr[100005];   int visited[100005], dep[100005];   int main() {     int n, i, start, end;     cin >> n;     n--;     while (n--) {       cin >> start;       cin >> end;       arr[start].push_back(end);       arr[end].push_back(start);     }     bfs();     cout.precision(7);     cout << fixed << ans;     return 0;   }   void bfs() {     int node;     dep[1] = 1;     queue<int> qu;     list<int>::iterator iter = arr[1].begin();     node = 1;     visited[1] = 1;     qu.push(1);     while (!qu.empty()) {       for (iter = arr[node].begin(); iter != arr[node].end(); ++iter) {         if (!visited[*iter]) {           qu.push(*iter);           visited[*iter] = 1;           dep[*iter] = dep[node] + 1;         }       }       int k = qu.front();       qu.pop();       node = qu.front();       ans += 1 / (double)dep[k];     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   map<pair<int, int>, int> weight;   vector<int> edges[MAXN];   bool visited[MAXN];   long long int maximum;   void dfs(int v, long long int sum) {     visited[v] = true;     maximum = max(maximum, sum);     for (int i : edges[v]) {       if (!visited[i]) dfs(i, sum + weight[make_pair(v, i)]);     }     return;   }   int main() {     long long int n, a, b, c, sum_of_edges = 0;     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> a >> b >> c;       sum_of_edges += c;       a--;       b--;       edges[a].push_back(b);       edges[b].push_back(a);       weight[make_pair(a, b)] = c;       weight[make_pair(b, a)] = c;     }     dfs(0, 0);     sum_of_edges *= 2;     sum_of_edges -= maximum;     cout << sum_of_edges << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int c[maxn];   int p[64], q[64];   int l[maxn];   int ans[maxn];   vector<int> g[maxn];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> c[i];     int Q;     cin >> Q;     for (int i = 1; i <= Q; i++) {       int r;       cin >> l[i] >> r;       g[r].push_back(i);     }     for (int i = 1; i <= n; i++) {       int r = i, x = c[i];       for (int j = 30; j >= 0; j--) {         if (x >> j & 1) {           if (!p[j]) {             p[j] = x;             q[j] = r;             break;           }           if (q[j] < r) {             swap(p[j], x);             swap(q[j], r);           }           x ^= p[j];         }       }       for (int k = 0; k < g[i].size(); k++) {         int now = g[i][k];         for (int j = 30; j >= 0; j--) {           if (q[j] >= l[now]) ans[now] = max(ans[now], ans[now] ^ p[j]);         }       }     }     for (int i = 1; i <= Q; i++) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char puzzel[600];     vector<string> Puz;     int m, n;     int stp;     int len = 0, judge = 0;     int prevstp;     int prevlen;     int minv = 1000;     int maxv = -9;     int flag = 0;     scanf( %d%d , &m, &n);     for (int i = 0; i < m; i++) {       scanf( %s , puzzel);       Puz.push_back(puzzel);     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         if (Puz[i][j] ==  X ) {           stp = j;           len++;           for (int k = j; k < n - 1; k++) {             if (Puz[i][k + 1] ==  X ) {               len++;             } else {               break;             }           }           if (flag == 0) {             flag = 1;             prevlen = len;             prevstp = stp;             len = 0;           } else {             if (prevstp == stp && prevlen == len) {               prevstp = stp;               prevlen = len;               len = 0;             } else {               judge = 1;             }           }           break;         }       }     }     if (judge == 1) {       printf( NO n );     } else if (flag == 1) {       printf( YES n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double const eps = 1e-6;   double const pi = 3.1415926535;   long long const mod = 1e9 + 7;   int a[20];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < (1 << n); i++) {       int x = 0;       for (int j = 0; j < n; j++) {         if (i & (1 << j))           x += a[j];         else           x -= a[j];       }       if (x % 360 == 0) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> res;   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(0);     long long n, f = 0, m;     cin >> n;     m = n;     for (int i = 2; i <= sqrt(m); i++) {       if (n % i == 0) {         while (n % i == 0) {           res.push_back(i);           n /= i;           if (res.size() == 3) {             f = 1;             break;           }         }       }     }     if (res.size() == 2) {       if (m == res[0] * res[1])         cout << 2;       else         cout << 1 << endl << res[0] * res[1];       return 0;     }     if (f) {       cout << 1 << endl << (res[0] * res[1]);       return 0;     }     if (res.empty())       cout << 1 << endl << 0;     else       cout << 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long ksm(long long a, long long b, long long mod) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }   void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, y, x, d);       y -= x * (a / b);     }   }   int arr[55], num[55];   int main() {     int n;     long long d, tmp = 0;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &arr[i]);       num[arr[i]]++;     }     sort(arr + 1, arr + 1 + n);     if (num[arr[1]] <= n / 2)       printf( Alice n );     else       printf( Bob n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   short k, r, m = 10;   int main() {     cin >> k >> r;     for (int i = 10; i > 0; --i) {       if ((i * k) % 10 == 0 || (i * k - r) % 10 == 0) {         m = i;       }     }     cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int num[10];   char s[100010];   int main() {     scanf( %d , &n);     scanf( %s , s);     for (int i = 0; i < n; i++) {       if (s[i] ==  L ) {         for (int j = 0; j < 10; j++) {           if (num[j] == 0) {             num[j] = 1;             break;           }         }       } else if (s[i] ==  R ) {         for (int j = 9; j >= 0; j--) {           if (num[j] == 0) {             num[j] = 1;             break;           }         }       } else if (s[i] >=  0  && s[i] <=  9 ) {         num[s[i] -  0 ] = 0;       }     }     for (int i = 0; i < 10; i++) {       printf( %d , num[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, n, s;       cin >> a >> b >> n >> s;       if ((min(s / n, a) * n + b) >= s) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void scanint(int &x) {     register int c = getchar();     x = 0;     int neg = 0;     for (; ((c < 48 || c > 57) && c !=  - ); c = getchar())       ;     if (c ==  - ) {       neg = 1;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x = -x;   }   int cmp(int a, int b) {     if (a > b)       return a;     else       return b;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m, i, j, k;     cin >> n >> m;     int a[n][3];     for (i = 0; i < n; i++) {       for (j = 0; j < 3; j++) {         a[i][j] = 55;       }     }     for (i = 0; i < n; i++) {       string s;       cin >> s;       for (j = 0; j < m; j++) {         int ctr = 2;         if (s[j] ==  #  || s[j] ==  *  || s[j] ==  & )           ctr = 0;         else if (s[j] >=  0  && s[j] <=  9 )           ctr = 1;         if (a[i][ctr] > min(j, m - j)) a[i][ctr] = min(j, m - j);       }     }     int ans = 200;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i == j) continue;         for (k = 0; k < n; k++) {           if (i == k || k == j) continue;           ans = min(ans, a[i][0] + a[j][1] + a[k][2]);         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);     putchar(   );   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   using namespace std;   int u, v, l, r;   vector<pair<int, int> > ans;   map<pair<int, int>, bool> dd;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     cin >> u >> v;     int up = 1, down = u;     l = 1, r = v;     while (up <= down) {       if (l == 1) {         for (int i = (1); i <= (v); ++i) {           ans.push_back(make_pair(up, l));           ++l;           ans.push_back(make_pair(down, r));           --r;         }         ++up;         --down;         --l;         ++r;       } else {         for (int i = (1); i <= (v); ++i) {           ans.push_back(make_pair(up, l));           --l;           ans.push_back(make_pair(down, r));           ++r;         }         ++up;         --down;         ++l;         --r;       }     }     for (auto v : ans) {       if (dd[v]) continue;       dd[v] = 1;       cout << v.first <<     << v.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modulo(long long base, long long exp, long long m);   int main() {     int x;     cin >> x;     if (x <= 1)       cout <<  -1 ;     else {       cout << x <<     << x;     }     return 0;   }   long long modulo(long long base, long long exp, long long m) {     long long answer = 1;     while (exp > 0) {       if (exp % 2 == 1) answer = (answer * base) % m;       exp = exp / 2;       base = (base * base) % m;     }     return answer;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, last[28], tmp[28];   long long ans[28];   char s[300005];   int main() {     scanf( %s , s);     for (i = 0; i <= 26; i++) last[i] = -1;     int length = strlen(s);     for (i = 0; i < length; i++) {       last[s[i] -  a ] = i;       for (int j = 0; j <= 26; j++) tmp[j] = last[j];       sort(tmp, tmp + 27);       for (int j = 26; j; j--) ans[26 - j + 1] += tmp[j] - tmp[j - 1];     }     for (i = 1; i <= 26; i++)       if (!ans[i]) break;     printf( %d n , i - 1);     for (int j = 1; j < i; j++) printf( %I64d n , ans[j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 5, sum = 0;     while (n--) {       int a;       cin >> a;       sum += a;     }     if (sum == 0) {       cout << -1 << endl;       return 0;     }     cout << (sum % 5 == 0 ? sum / 5 : -1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   char b[100][100];   int n;   bool in(int x) { return x >= 0 && x < n; }   bool in(int x, int y) { return in(x) && in(y); }   char a[200][200];   int main() {     scanf( %d , &n);     for (int i = 0; i < (n); i++) scanf( %s , b[i]);     vector<pair<int, int> > ans;     for (int dx = (-n + 1); dx <= (n - 1); dx++) {       for (int dy = (-n + 1); dy <= (n - 1); dy++) {         if (dx == 0 && dy == 0) {           continue;         }         bool fail = false;         for (int i = 0; i < (n); i++) {           for (int j = 0; j < (n); j++) {             if (b[i][j] ==  o  && in(i + dx, j + dy) &&                 b[i + dx][j + dy] ==  . ) {               fail = true;             }           }         }         if (!fail) {           ans.emplace_back(dx, dy);         }       }     }     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) {         if (b[i][j] ==  x ) {           bool success = false;           for (auto& p : ans) {             if (in(i - p.first, j - p.second) &&                 b[i - p.first][j - p.second] ==  o ) {               success = true;             }           }           if (!success) {             puts( NO );             return 0;           }         }       }     puts( YES );     for (int i = 0; i < (2 * n - 1); i++) {       for (int j = 0; j < (2 * n - 1); j++) {         a[i][j] =  . ;       }     }     a[n - 1][n - 1] =  o ;     for (auto& p : ans) {       a[n - 1 + p.first][n - 1 + p.second] =  x ;     }     for (int i = 0; i < (2 * n - 1); i++) {       puts(a[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10, maxm = 2e6 + 10;   const long long INF = 0x3f3f3f3f, mod = 1e9 + 7;   int casn, n, m, k;   namespace graph {   vector<int> g[maxn];   int all, sz[maxn], root, maxt;   bool vis[maxn];   int dfs_root(int now, int fa) {     int cnt = 1;     for (auto to : g[now]) {       if (to == fa || vis[to]) continue;       cnt += dfs_root(to, now);     }     int tmp = max(cnt - 1, all - cnt);     if (maxt > tmp) maxt = tmp, root = now;     return sz[now] = cnt;   }   int ans[maxn];   void dfs_col(int now, int fa, int c) {     ans[now] = c;     for (auto to : g[now])       if (to != fa && !vis[to]) dfs_col(to, now, c);   }   void dfs_dv(int now, int d = 0) {     vis[now] = 1;     dfs_col(now, now, d);     for (auto to : g[now]) {       if (vis[to]) continue;       maxt = root = n + 1;       all = sz[to];       dfs_root(to, now);       dfs_dv(root, d + 1);     }   }   void solve(int n) {     all = maxt = root = n + 1;     dfs_root(1, 1);     all -= maxt;     dfs_dv(root);   }   }  // namespace graph   using namespace graph;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     solve(n);     for (int i = 1; i <= n; ++i) cout << char(ans[i] +  A ) <<    ;   }