#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, M = 1e6 + 10;   struct node {     int a, b, w;   } e[M];   int fa[N];   bool cmp(node a, node b) { return a.w < b.w; }   int find(int x) {     if (fa[x] != x) fa[x] = find(fa[x]);     return fa[x];   }   int du[N];   int main() {     int n, m;     cin >> n >> m;     int a1, b1, w1;     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &e[i].a, &e[i].b, &e[i].w);       if (i == 1) {         a1 = e[i].a;         b1 = e[i].b;       }     }     for (int i = 1; i <= n; ++i) fa[i] = i;     sort(e + 2, e + 1 + m, cmp);     for (int i = 2; i <= m; ++i) {       int f1 = find(e[i].a);       int f2 = find(e[i].b);       if (f1 == f2) continue;       fa[f1] = f2;       if (find(a1) == find(b1)) {         printf( %d n , e[i].w);         return 0;       }     }     printf( 1000000000 n );   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a[600000], L, R, r, t, l, f;   long long s;   bool ok(long long x) {     long long r = 0;     for (long long i = 0; i < n; i++)       if (a[i] > x) r += (a[i] - x);     if (r <= t) return 1;     return 0;   }   bool ok1(long long x) {     long long r = 0;     for (long long i = 0; i < n; i++)       if (a[i] < x) r += (x - a[i]);     if (r <= t) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> t;     L = 2e9;     for (long long i = 0; i < n; i++) {       cin >> a[i];       s += a[i];       L = min(L, a[i]);       R = max(R, a[i]);     }     long long d1 = R, d2 = L;     l = L;     r = R;     while (r - l > 10) {       long long mid = (r + l) / 2;       if (ok(mid))         r = mid;       else         l = mid + 1;     }     for (long long i = l; i <= r; i++)       if (ok(i)) d1 = min(d1, i);     l = L;     r = R;     while (r - l > 10) {       long long mid = (r + l) / 2;       if (ok1(mid))         l = mid;       else         r = mid - 1;     }     for (long long i = l; i <= r; i++)       if (ok1(i)) d2 = max(d2, i);     if (s % n == 0)       f = 0;     else       f = 1;     cout << max(f, d1 - d2);   }


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


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   inline int comp(double A, double B = 0) {     return (A <= B + EPS) ? (A + EPS < B) ? -1 : 0 : 1;   }   struct point {     double x, y;     point(double x = 0, double y = 0) : x(x), y(y) {}     bool operator<(const point &other) const {       if (!comp(x, other.x)) return comp(y, other.y) < 0;       return comp(x, other.x) < 0;     }     point operator+(const point &other) const {       return point(x + other.x, y + other.y);     }     point operator-(const point &other) const {       return point(x - other.x, y - other.y);     }   };   double inner(const point &A, const point &B) { return A.x * B.x + A.y * B.y; }   double outer(const point &A, const point &B) { return A.x * B.y - A.y * B.x; }   double dist(const point &A, const point &B) {     return sqrt(inner(A - B, A - B));   }   double angle(const point &A, const point &O, const point &B) {     return acos(inner(A - O, B - O) / (dist(A, O) * dist(B, O)));   }   int side(const point &A, const point &O, const point &B) {     return comp(outer(A - O, B - O));   }   vector<point> convex_hull(vector<point> &points) {     int size = (int)points.size();     if (size < 3) return points;     point O = *min_element(points.begin(), points.end());     sort(points.begin(), points.end(), [O](const point &A, const point &B) {       double foo = outer(A - O, B - O);       return comp(foo) > 0 or (!comp(foo) and comp(dist(A, O), dist(B, O)) < 0);     });     vector<point> polygon = {points.back(), points[0], points[1]};     for (int i = 2; i < size;)       if (polygon.size() <= 2 or           side(polygon.rbegin()[0], polygon.rbegin()[1], points[i]) > 0)         polygon.push_back(points[i++]);       else         polygon.pop_back();     polygon.pop_back();     return polygon;   }   vector<int> pre_kmp(const vector<double> &A) {     int i = 0, j, size = (int)A.size();     vector<int> back(size + 1);     back[0] = j = -1;     while (i < size) {       while (j >= 0 and comp(A[i], A[j])) j = back[j];       ++i;       ++j;       back[i] = j;     }     return back;   }   vector<int> kmp(const vector<double> &A, const vector<double> &B) {     int i = 0, j = 0, sizea = (int)A.size(), sizeb = (int)B.size();     vector<int> match, back = pre_kmp(B);     while (i < sizea) {       while (j >= 0 and comp(A[i], B[j])) j = back[j];       ++i;       ++j;       if (j == sizeb) {         match.push_back(i - j);         j = back[j];       }     }     return match;   }   vector<double> stringify(const vector<point> &P) {     vector<double> foo;     int size = (int)P.size();     for (int i = 0; i < size; ++i) {       foo.push_back(dist(P[i], P[(i + 1) % size]));       foo.push_back(angle(P[i], P[(i + 1) % size], P[(i + 2) % size]));     }     return foo;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<point> A(n), B(m);     for (int i = 0; i < n; ++i) scanf( %lf %lf , &A[i].x, &A[i].y);     for (int i = 0; i < m; ++i) scanf( %lf %lf , &B[i].x, &B[i].y);     vector<double> X = stringify(convex_hull(A)), Y = stringify(convex_hull(B));     X.insert(X.end(), X.begin(), X.end());     printf( %s n , kmp(X, Y).empty() ?  NO  :  YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fib[100005], mod = 1e9 + 7;   void pre() {     fib[0] = fib[1] = 1;     for (int i = 2; i < 100005; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % mod;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     pre();     long long m, n, x;     cin >> m >> n;     x = (fib[m] + fib[n] - 1) % mod;     cout << (2LL * x) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e2 + 7;   long long p[MAXN], dp[MAXN];   pair<long long, long long> fig[MAXN];   int32_t main() {     long long n;     cin >> n;     for (long long i = 0; i < n; ++i) cin >> fig[i].second >> fig[i].first;     sort(fig, fig + n);     long long t;     cin >> t;     for (long long i = 1; i <= t; ++i) cin >> p[i];     p[t + 1] = (1LL << 60);     long long pos = 1, ans = 0, sum = 0;     for (long long i = 0; i < n; ++i) {       while (fig[i].second) {         if (p[pos] - sum > fig[i].second) {           sum += fig[i].second;           ans += fig[i].second * pos * fig[i].first;           fig[i].second = 0;         } else {           ans += fig[i].first * (p[pos] - sum) * pos;           fig[i].second -= p[pos] - sum;           sum = p[pos];           pos++;         }       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   int btf(int n) {     static int num[10];     memset(num, 0, sizeof(num));     for (int i = 0; i < 4; i++) {       num[n % 10]++;       n /= 10;     }     for (int i = 0; i < 10; i++)       if (num[i] > 1) return 0;     return 1;   }   void solve(int n) {     for (int i = n + 1; 1; i++)       if (btf(i)) {         printf( %d n , i);         return;       }   }   int main() {     int n;     while (scanf( %d , &n) != EOF) solve(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, m;   void deal() {     for (int i = 0; i <= a && i < m; i++) {       if ((m - (long long int)i * 1000000000 % m) % m > b) {         printf( 1 %.9d n , i);         return;       }     }     printf( 2 n );   }   int main() {     while (scanf( %d%d%d , &a, &b, &m) != EOF) {       deal();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long ans[2200], MOD = 1000003;   long long dp[2200][2200], inv[2200], fac[2200], ifac[2200];   void init_math(int N) {     inv[1] = 1LL;     for (int i = 2; i <= N; i++)       inv[i] = (MOD - ((MOD / i) * inv[MOD % i]) % MOD);     fac[0] = 1LL;     ifac[0] = 1LL;     for (int i = 1; i <= N; i++) {       fac[i] = (fac[i - 1] * (long long)(i)) % MOD;       ifac[i] = (ifac[i - 1] * inv[i]) % MOD;     }   }   int st[2200], stc, r, len, ms, t[2200], tc;   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     init_math(2000);     cin >> s;     len = s.size();     ans[1] = 1;     for (int i = 1; i <= 2000; i++)       ans[i + 1] = inv[i + 1] * fac[i * 2] % MOD * ifac[i] % MOD * ifac[i] % MOD;     tc = 0;     bool isn = 0, ist;     for (int i = 0; i < len; i++) {       ist = 0;       if (s[i] <=  9  && s[i] >=  0 )         isn = 1;       else {         if (isn) {           t[tc++] = 0;           isn = 0;         }         if (i == 0 || !(s[i - 1] <=  9  && s[i - 1] >=  0 )) {           if (s[i] ==  *  || s[i] ==  / ) {             cout << 0 << endl;             return 0;           }           t[tc++] = 1;         } else           ist = 1;       }     }     if (isn) t[tc++] = 0;     if (t[tc - 1] == 1 || ist) {       cout << 0 << endl;       return 0;     }     stc = 0;     for (int i = 0; i < tc; i++) {       if (t[i] == 0)         st[stc]++;       else         stc++;     }     if (stc == 0) {       cout << ans[tc] << endl;       return 0;     }     dp[stc + 1][0] = 1;     for (int i = stc; i >= 0; i--) {       r = st[i];       if (i) {         ms += r;         for (int j = 1; j <= ms; j++)           for (int k = max(r - j, 0); k <= ms - j; k++) {             dp[i][k + 1] += (dp[i + 1][k + j - r] * ans[j]) % MOD;             if (dp[i][k + 1] >= MOD) dp[i][k + 1] -= MOD;           }       } else {         for (int j = 0; j <= ms; j++) {           dp[i][j + r] += dp[i + 1][j];           if (dp[i][j + r] >= MOD) dp[i][j + r] -= MOD;         }       }     }     long long res = 0;     for (int i = 1; i <= tc; i++) {       res += (dp[0][i] * ans[i]) % MOD;       if (res >= MOD) res -= MOD;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int two(int x) { return 1 << x; }   inline long long TWO(int x) { return (long long)1 << x; }   template <class T>   void Min(T &x, T y) {     if (y < x) x = y;   }   template <class T>   void Max(T &x, T y) {     if (y > x) x = y;   }   template <class T>   T _abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   const int maxn = 200010;   const int mod = 1000000007;   int get_val() {     int ret(0);     char c;     while ((c = getchar()) ==     || c ==   n  || c ==   r )       ;     ret = c -  0 ;     while ((c = getchar()) !=     && c !=   n  && c !=   r )       ret = ret * 10 + c -  0 ;     return ret;   }   int n, m, k;   int a[maxn], b[maxn];   int num[maxn];   int main() {     cin >> n >> m >> k;     map<int, int> mpa, mpb, mp;     for (int i = 0; i < n; i++) a[i] = get_val(), mpa[a[i]]++, mp[a[i]]++;     for (int i = 0; i < m; i++) b[i] = get_val(), mpb[b[i]]++, mp[b[i]]--;     int tot = 0;     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       if (it->second) num[tot++] = it->second;     }     long long s1 = 0, s2 = 0;     for (int i = tot; i >= 0; i--) {       s1 += num[i];       if (s1 > 0) {         return puts( YES ), 0;       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, k, a;     cin >> n1 >> n2;     vector<int> arr1, arr2;     for (int l = 0; l < n1; l++) {       cin >> a;       arr1.push_back(a);     }     for (int l = 0; l < n2; l++) {       cin >> a;       arr2.push_back(a);     }     sort(arr1.begin(), arr1.end());     sort(arr2.begin(), arr2.end());     for (int k = 0; k < arr1.size(); k++) {       for (int l = 0; l < arr2.size(); l++) {         if (arr1[k] == arr2[l]) {           cout << arr1[k] <<   n ;           return 0;         }       }     }     if (arr1[0] < arr2[0]) {       k = 10 * arr1[0] + arr2[0];       cout << k <<   n ;     } else {       k = 10 * arr2[0] + arr1[0];       cout << k <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] !=  a  && s[i] !=  e  && s[i] !=  i  && s[i] !=  o  &&           s[i] !=  u  && s[i] !=  n ) {         if (i != s.length() - 1) {           if (s[i + 1] !=  a  && s[i + 1] !=  e  && s[i + 1] !=  i  &&               s[i + 1] !=  o  && s[i + 1] !=  u ) {             cout <<  NO  << endl;             return 0;           }         } else {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long long linf = 1000000000000000000LL;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T k) {     return k >= 0 ? k : -k;   }   template <class T>   T sqr(T n) {     return n * n;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   template <class T>   T addmod(T a, T b, T c) {     return (T)((long long)(a + b) % c);   }   template <class T>   T mulmod(T a, T b, T c) {     return (T)((long long)a * b % c);   }   template <class T>   T powmod(T a, T b, T c) {     return (T)(b ? sqr((long long)powmod(a, b >> 1, c)) % c * (b & 1 ? a : 1) % c                  : 1);   }   template <class T>   void maxe(T &a, T b) {     a = max(a, b);   }   template <class T>   void mine(T &a, T b) {     a = min(a, b);   }   template <class T>   void mode(T &a, T b) {     a = mod(a, b);   }   template <class T>   void addmode(T &a, T b, T c) {     a = addmod(a, b, c);   }   template <class T>   void mulmode(T &a, T b, T c) {     a = mulmod(a, b, c);   }   template <class T>   void powmode(T &a, T b, T c) {     a = powmod(a, b, c);   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 111111;   int test;   int n, m, k;   long long ans;   long long d[N], h[N], t[N], s[N], st[N];   long long dp[111][N];   int q[N], head, tail;   long long f1(int i, int j, int k) { return dp[i][k] + st[k] - t[j] * k; }   long long f2(int i, int j, int k) {     return ((dp[i][j] + st[j]) - (dp[i][k] + st[k])) / (j - k);   }   long long getans() {     sort(t + 1, t + 1 + m);     for (int i = 1; i <= m; i++) {       st[i] = st[i - 1] + t[i];       dp[1][i] = t[i] * i - st[i];     }     for (int i = 2; i <= k; i++) {       head = tail = 0;       for (int j = 1; j <= m; j++) {         while (head < tail && f1(i - 1, j, q[head]) >= f1(i - 1, j, q[head + 1]))           head++;         while (head < tail &&                f2(i - 1, q[tail - 1], q[tail]) >= f2(i - 1, q[tail], j))           tail--;         dp[i][j] = t[j] * j - st[j] + f1(i - 1, j, q[head]);         q[++tail] = j;       }     }     return dp[k][m];   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 2; i <= n; i++) {       scanf( %I64d , &d[i]);       s[i] = s[i - 1] + d[i];     }     for (int i = 1; i <= m; i++) {       scanf( %I64d%I64d , &h[i], &t[i]);       t[i] -= s[h[i]];     }     ans = getans();     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, vmx;   long long seed;   struct node {     int l, r;     mutable long long val;     bool operator<(const node &x) const { return l < x.l; }   };   set<node> tr;   set<node>::iterator split(int pos) {     set<node>::iterator iter = tr.lower_bound((node){pos});     if (iter != tr.end() && iter->l == pos) return iter;     iter--;     int L = iter->l, R = iter->r;     long long Val = iter->val;     tr.erase(iter);     tr.insert((node){L, pos - 1, Val});     return tr.insert((node){pos, R, Val}).first;   }   void assign(int l, int r, long long val) {     set<node>::iterator R = split(r + 1), L = split(l);     tr.erase(L, R);     tr.insert((node){l, r, val});     return;   }   void add(int l, int r, long long val) {     set<node>::iterator R = split(r + 1), L = split(l);     for (; L != R; ++L) L->val = L->val + val;     return;   }   struct Lsh {     long long val;     int sum;   } ls[N];   inline bool Lscmp(Lsh a, Lsh b) { return a.val < b.val; }   inline long long rnk(int l, int r, int x) {     set<node>::iterator R = split(r + 1), L = split(l);     int tot = 0;     for (; L != R; ++L) ls[++tot].val = L->val, ls[tot].sum = (L->r - L->l + 1);     sort(ls + 1, ls + tot + 1, Lscmp);     for (int i = 1; i <= tot; i++) {       x -= ls[i].sum;       if (x <= 0) return ls[i].val;     }   }   inline long long ksm(long long a, long long b, long long mod) {     a %= mod;     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   inline long long calc(int l, int r, int x, int y) {     set<node>::iterator R = split(r + 1), L = split(l);     long long ans = 0;     for (; L != R; ++L)       ans = (ans + ksm(L->val, x, y) * (L->r - L->l + 1) % y) % y;     return ans;   }   inline int rnd() {     int ret = seed;     seed = (seed * 7 + 13) % 1000000007;     return ret;   }   int op, l, r, x, y;   int tot;   int main() {     scanf( %d%d%lld%d , &n, &m, &seed, &vmx);     for (int i = 1; i <= n; i++) tr.insert((node){i, i, rnd() % vmx + 1});     tr.insert((node){n + 1, n + 1, 0});     for (int i = 1; i <= m; i++) {       op = rnd() % 4 + 1;       l = rnd() % n + 1;       r = rnd() % n + 1;       if (l > r) swap(l, r);       if (op == 3)         x = rnd() % (r - l + 1) + 1;       else         x = rnd() % vmx + 1;       if (op == 4) y = rnd() % vmx + 1;       if (op == 1)         add(l, r, x);       else if (op == 2)         assign(l, r, x);       else if (op == 3)         printf( %lld n , rnk(l, r, x));       else         printf( %lld n , calc(l, r, x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double a[200005], b[200005];   double l = -10001, r = 10001;   const double eps = 2e-12;   double solve(double x) {     for (int i = 1; i <= n; ++i) b[i] = a[i] - x;     double res = 0, tmp = 0;     for (int i = 1; i <= n; ++i) {       if (tmp < 0) tmp = 0;       tmp += b[i];       res = max(res, tmp);     }     tmp = 0;     for (int i = 1; i <= n; ++i) {       if (tmp < 0) tmp = 0;       tmp -= b[i];       res = max(res, tmp);     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lf , &a[i]);     }     while (r > eps + l) {       double ll = (2 * l + r) / 3, rr = (l + 2 * r) / 3;       double lll = solve(ll);       double rrr = solve(rr);       if (lll < rrr)         r = rr;       else         l = ll;     }     cout << fixed << setprecision(12) << solve((l + r) / 2) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c, i;     cin >> n >> m;     c = 2 * n;     i = 1;     while (i <= 2 * n) {       if (m > c) {         c++;         cout << c <<    ;       }       cout << i <<    ;       i++;       if (m < i) break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, sx, sy, ex, ey;   int e, s, n, w;   string ch;   int main() {     cin >> t >> sx >> sy >> ex >> ey;     if (sx < ex)       e = ex - sx;     else       w = sx - ex;     if (sy < ey)       n = ey - sy;     else       s = sy - ey;     cin >> ch;     long long d = 1;     for (long long i = 0; i < t; i++) {       if (ch[i] ==  S )         s--;       else if (ch[i] ==  N )         n--;       else if (ch[i] ==  E )         e--;       else         w--;       if ((s <= 0 && n <= 0) && (e <= 0 && w <= 0)) {         d = 0;         cout << i + 1 << endl;         break;       }     }     if (d == 1) cout << -1 << endl;   }


#include<bits/stdc++.h>   using namespace std;   #define read(x) scanf( %d ,&x)   const int N=1e5+10;   string s;   int main()   {        int t; read(t);    while(t--)    {     cin>>s;     for(int i=0;i<s.size();i++)     {      if(i%2==0)      {       if(s[i]!= a ) s[i]= a ;       else s[i]= b ;      }      else      {       if(s[i]!= z ) s[i]= z ;       else s[i]= y ;      }     }     cout<<s<<endl;    }       return 0;    }


#include <bits/stdc++.h>   using namespace std;   const int N = 123456;   void solve() {     long long n;     cin >> n;     if (n % 2 == 0) {       cout << (10 + n) <<   10 ;     } else {       cout << (9 + n) <<   9 ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  inline ,  -ffast-math )   #pragma GCC target( avx,sse2,sse3,sse4,mmx )   inline long long read() {     long long s(0);     bool w(1);     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   long long l, r, n, m, x, y, num;   int main() {     n = read(), x = read();     for (int i = 1; i <= n; i++) {       num = read();       l = l * x + num;     }     scanf( %lld%lld , &m, &y);     for (int i = 1; i <= m; i++) {       num = read();       r = r * y + num;     }     puts(l == r ?  =  : (l > r ?  >  :  < ));   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 4e3 + 5;   const int mod = 1e9 + 7;   const double eps = 1e-8;   const double pi = asin(1.0) * 2;   const double e = 2.718281828459;   bool Finish_read;   template <class T>   inline void read(T &x) {     Finish_read = 0;     x = 0;     int f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) {         f = -1;       }       if (ch == EOF) {         return;       }       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;     Finish_read = 1;   };   int main(int argc, char *argv[]) {     int n, m;     read(n);     read(m);     vector<int> a;     a.push_back(0);     for (int i = 1, x; i <= n; ++i) {       read(x);       a.push_back(x);     }     a.push_back(m);     vector<int> f[2];     f[0].assign(a.size(), 0);     f[1].assign(a.size(), 0);     for (int i = int(a.size()) - 2; i >= 0; --i) {       f[0][i] = f[1][i + 1];       f[1][i] = (a[i + 1] - a[i]) + f[0][i + 1];     }     int ans = f[1][0];     for (int i = 0; i + 1 < int(a.size()); ++i) {       if (a[i + 1] - a[i] < 2) {         continue;       }       int tp = (i & 1) ^ 1;       int pSum = f[1][0] - f[tp][i];       ans = max(ans, pSum + (a[i + 1] - a[i] - 1) + f[tp][i + 1]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> Q[123];   int stk[123];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       for (int j = 0; j < x; j++) {         int u;         scanf( %d , &u);         Q[i].push_back(u);       }     }     int cnt = 0;     int A = 0, B = 0;     for (int i = 0; i < n; i++) {       if (Q[i].size() % 2 == 1) {         stk[cnt++] = Q[i][Q[i].size() / 2];       }       for (int j = 0; j < Q[i].size() / 2; j++) A += Q[i][j];       for (int j = 0; j < Q[i].size() / 2; j++) B += Q[i][Q[i].size() - 1 - j];     }     sort(stk, stk + cnt);     for (int i = cnt - 2; i > -1; i -= 2) B += stk[i];     for (int i = cnt - 1; i > -1; i -= 2) A += stk[i];     cout << A <<     << B <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     void solve(std::istream& in, std::ostream& out) {       int T;       in >> T;       for (int _t = 0; _t < (int)(T); ++_t) {         int n, s, t;         in >> n >> s >> t;         int res = n - min(s, t) + 1;         out << res << endl;       }     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2001];   int ou, ji;   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       ans += a[i];       if (a[i] % 2 == 0)         ou++;       else         ji++;     }     if (ou > ji)       ou = ji + 1;     else if (ji > ou)       ji = ou + 1;     sort(a + 1, a + 1 + n);     for (int i = n; i >= 1; i--) {       if (a[i] % 2 == 0 && ou) {         ans -= a[i];         ou--;       } else if (a[i] % 2 != 0 && ji) {         ans -= a[i];         ji--;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace FGF {   const int N = 2e5 + 5;   int n, m;   long long read() {     long long s = 0, w = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) w = -w;       ch = getchar();     }     while (isdigit(ch)) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * w;   }   struct Node {     long long a, b, tim;     Node(){};     Node(long long _a, long long _b, long long _t) : a(_a), b(_b), tim(_t){};   } c[N];   bool operator<(Node x, Node y) { return x.tim > y.tim; }   bool check(long long x) {     priority_queue<Node> q;     while (q.size()) q.pop();     for (int i = 1; i <= n; i++)       if (c[i].tim < m) q.push(c[i]);     if (q.empty()) return 1;     for (int i = 0; i < m; i++) {       Node u = q.top();       q.pop();       if (u.tim < i) return 0;       u.a += x;       u.tim = u.a / u.b;       if (u.tim < m) q.push(u);       if (q.empty()) return 1;     }     return 1;   }   void work() {     n = read(), m = read();     for (int i = 1; i <= n; i++) c[i].a = read();     for (int i = 1; i <= n; i++) c[i].b = read(), c[i].tim = c[i].a / c[i].b;     long long l = 0, r = 5e12, ans = -1;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %lld n , ans);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 0x3f3f3f3f;   const long long SEED = 19260817;   const long long MOD = 1e9 + 9;   const int maxn = 2e5 + 11;   int N, M, T;   char a[maxn];   long long cnt[maxn][26], dif[maxn], cx[maxn], cy[maxn];   void solve(int x, int y, int l) {     for (int i = 0; i < 26; i++) {       cx[i] = (cnt[x + l - 1][i] - cnt[x - 1][i] * dif[l] % MOD + MOD) % MOD;       cy[i] = (cnt[y + l - 1][i] - cnt[y - 1][i] * dif[l] % MOD + MOD) % MOD;     }     sort(cx, cx + 26);     sort(cy, cy + 26);     for (int i = 0; i < 26; i++)       if (cx[i] != cy[i]) {         puts( NO );         return;       }     puts( YES );     return;   }   int main() {     cin >> N >> M;     scanf( %s , a + 1);     dif[0] = 1;     for (int i = 1; i <= N; i++) {       dif[i] = (dif[i - 1] * SEED) % MOD;       for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j] * SEED % MOD;       cnt[i][a[i] -  a ] = (cnt[i][a[i] -  a ] + 1) % MOD;     }     while (M--) {       int x, y, l;       scanf( %d%d%d , &x, &y, &l);       solve(x, y, l);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 10;   long long tree[MAXN * 4][7][11], s[6][MAXN], a[MAXN];   void Pushup(long long u, long long len) {     long long z, i, j;     for (z = 2; z <= 6; z++)       for (i = 0; i < 2 * (z - 1); i++)         tree[u][z][i] =             tree[u * 2][z][i] + tree[u * 2 + 1][z][(i + len) % (2 * (z - 1))];     return;   }   void Build(long long u, long long l, long long r) {     long long z, i;     if (l == r) {       for (z = 2; z <= 6; z++)         for (i = 0; i < (z - 1) * 2; i++) tree[u][z][i] = a[l] * s[z][i];       return;     }     long long mid = (l + r) >> 1;     Build(u * 2, l, mid);     Build(u * 2 + 1, mid + 1, r);     Pushup(u, mid - l + 1);   }   void Update(long long u, long long l, long long r, long long pos,               long long val) {     long long z, i;     if (l == r) {       for (z = 2; z <= 6; z++)         for (i = 0; i < 2 * (z - 1); i++) tree[u][z][i] = val * s[z][i];       return;     }     long long mid = (l + r) >> 1;     if (pos <= mid)       Update(u * 2, l, mid, pos, val);     else       Update(u * 2 + 1, mid + 1, r, pos, val);     Pushup(u, mid - l + 1);   }   long long Query(long long u, long long L, long long R, long long l, long long r,                   long long z, long long i) {     if (L == l && R == r) return tree[u][z][i];     long long mid = (L + R) >> 1;     if (r <= mid) return Query(u * 2, L, mid, l, r, z, i);     if (l > mid) return Query(u * 2 + 1, mid + 1, R, l, r, z, i);     return Query(u * 2, L, mid, l, mid, z, i) +            Query(u * 2 + 1, mid + 1, R, mid + 1, r, z,                  (i + mid - l + 1) % (2 * (z - 1)));   }   int main() {     long long n, m, z, i, j;     scanf( %lld , &n);     for (i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (z = 2; z <= 6; z++) {       long long mod = 2 * (z - 1);       for (i = 1; i <= 100000; i++) {         if (i % mod == 0)           s[z][i - 1] = 2;         else if (i % mod <= z)           s[z][i - 1] = i % mod;         else           s[z][i - 1] = (z * 2) - (i % mod);       }     }     Build(1, 1, n);     scanf( %lld , &m);     for (i = 1; i <= m; i++) {       long long op;       scanf( %lld , &op);       if (op == 1) {         long long pos, val;         scanf( %lld %lld , &pos, &val);         Update(1, 1, n, pos, val);       } else {         long long l, r, z;         scanf( %lld %lld %lld , &l, &r, &z);         printf( %lld n , Query(1, 1, n, l, r, z, 0));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void miz(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void maz(T &a, T b) {     if (b > a) a = b;   }   template <class T>   void clear(T &x) {     T t;     x.swap(t);   }   template <class T>   T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   T sqr(T x) {     return x * x;   }   unsigned HASH(const char *p) {     unsigned r = 0;     while (*p) r = r * 257 + 1 + *p++;     return r;   }   int ROUND(double x) { return x >= 0 ? x + 0.5 : x - 0.5; }   int cnt[1000005];   int main() {     int k, c, i, now = 0;     long long ans = 0;     scanf( %d  , &k);     cnt[0] = 1;     for (i = 1; (c = getchar()) !=   n ; i++) {       if (c ==  1 ) now++;       if (now >= k) ans += cnt[now - k];       cnt[now]++;     }     cout << ans << endl;     return 0;   }


/*   西江月·证明   即得易见平凡，仿照上例显然；留作习题答案略，读者自证不难。   反之亦然同理，推论自然成立；略去过程Q.E.D.，由上可知证毕。      result of thinking: Pure.    主要是非内、外向树的情形容易遗漏.       AC:   */   #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef long double ldouble;   template<class T> bool chmin(T &x, const T &y) {     return x > y ? (x = y, true) : false;   }   template<class T> bool chmax(T &x, const T &y) {     return x < y ? (x = y, true) : false;   }      #define maxn 1000005   const ll mod = 998244353;   const ll inv2 = 499122177;   const ll inv6 = 166374059;   int n;   ll f[maxn], r[maxn], df[maxn];      int main() {     scanf( %d , &n);     f[0] = r[0] = 1;     for (int i = 1; i <= n; i++) {       f[i] = (f[i - 1] * f[i - 1] % mod * inv2 + 3 * f[i - 1] * inv2 + 1) % mod;       r[i] = (f[i] + (f[i - 1] * f[i - 1] % mod * f[i - 1]                       + f[i - 1] * f[i - 1] * 3                       + f[i - 1] * 2) % mod * inv6) % mod;     }     ll ans = ((r[n] - r[n - 1]) * 2 - 1) % mod;     df[0] = f[0];     for (int i = 1; i <= n; i++)       df[i] = f[i] - f[i - 1];     for (int i = 1; i <= n - 2; i++) {       (ans += (df[i] - df[i - 1]) * (df[n - 1 - i] - 1)) %= mod;     }     printf( %lld n , (ans + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 201;   set<int> graph[N];   map<pair<int, int>, int> edges;   pair<int, int> bfs(int node) {     int dist[N] = {0};     int vis[N] = {0};     queue<pair<int, int> > q;     q.push({0, node});     while (!q.empty()) {       int top = q.front().second;       q.pop();       if (vis[top]) continue;       vis[top] = true;       for (set<int>::iterator it = graph[top].begin(); it != graph[top].end();            it++) {         int to = *it;         if (vis[to]) continue;         dist[to] = dist[top] + 1;         q.push({dist[to], to});       }     }     pair<int, int> temp = {node, 0};     for (int i = 1; i <= N; i++) {       if (dist[i] > temp.second) {         temp.second = dist[i];         temp.first = i;       }     }     return temp;   }   int find_dia(int node) {     pair<int, int> temp = bfs(node);     temp = bfs(temp.first);     return temp.second;   }   int main(void) {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       graph[u].insert(v);       graph[v].insert(u);       edges[{u, v}] = 1;     }     int ans = 0;     for (map<pair<int, int>, int>::iterator it = edges.begin(); it != edges.end();          it++) {       int u = (*it).first.first;       int v = (*it).first.second;       graph[u].erase(v);       graph[v].erase(u);       ans = max(ans, find_dia(v) * find_dia(u));       graph[u].insert(v);       graph[v].insert(u);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, n1, n2;     scanf( %d%d%d , &n, &n1, &n2);     if (n1 > n2) swap(n1, n2);     vector<double> X;     double x;     for (int i = 0; i < n; i++) {       scanf( %lf , &x);       X.push_back(x);     }     sort(X.begin(), X.end());     double sum1 = 0, sum2 = 0;     for (int i = n - n1 - n2; i < n; i++) {       if (i < n - n1)         sum2 += X[i];       else         sum1 += X[i];     }     sum1 /= n1;     sum2 /= n2;     printf( %.8lf , sum1 + sum2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100100, mod = 1e9 + 7, mod2 = 1e9 + 9, mod3 = 998244353,                   sq = 450, base = 727, lg = 30;   long long n, m, x, y, z, w, ans, t, l[N], r[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];       if (i == 0) {         x = l[i];         y = r[i];         continue;       }       x = min(x, l[i]);       y = max(y, r[i]);     }     for (int i = 0; i < n; i++) {       if (l[i] == x && r[i] == y) return cout << i + 1, 0;     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (m == 0) {       cout << n <<   n ;       return 0;     }     string hint[m];     getline(cin, hint[0]);     vector<vector<string> > h(m);     for (int i = 0; i < m; i++) {       getline(cin, hint[i]);       stringstream ss(hint[i]);       string w;       while (ss >> w) h[i].push_back(w);     }     int i;     int ans = 0;     for (i = 0; i < n; i++) {       bool yes = true;       for (int j = 0; j < m; j++) {         if (h[j][2] ==  left ) {           int k = atoi(h[j][4].c_str()) - 1;           if (i >= k) {             yes = false;             break;           }         } else if (h[j][2] ==  right ) {           int k = atoi(h[j][4].c_str()) - 1;           if (i <= k) {             yes = false;             break;           }         }       }       if (yes) ans++;     }     if (ans == 0) ans = -1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[300005];   int n, cnt, p[300005], to[600005], nexti[600005];   int fa[300005], son[300005], dep[300005], len[300005], top[300005],       dfsx[300005], st[300005];   void dfs(int x, int lasti) {     son[x] = 0;     len[x] = 1;     for (int i = p[x]; i != -1; i = nexti[i])       if (to[i] != lasti) {         fa[to[i]] = x;         dep[to[i]] = dep[x] + 1;         dfs(to[i], x);         len[x] += len[to[i]];         if (!son[x] || len[to[i]] > len[son[x]]) son[x] = to[i];       }   }   void DFS(int x, int lasti) {     st[x] = ++cnt;     dfsx[cnt] = x;     if (son[x]) top[son[x]] = top[x], DFS(son[x], x);     for (int i = p[x]; ~i; i = nexti[i])       if (to[i] != lasti && to[i] != son[x]) top[to[i]] = to[i], DFS(to[i], x);   }   int pw[300005], pre[300005], suf[300005];   inline int gethash(int l, int r) {     if (l < r)       return (pre[r] - 1LL * pre[l - 1] * pw[r - l + 1] % 998244353 + 998244353) %              998244353;     else       return (suf[r] - 1LL * suf[l + 1] * pw[l - r + 1] % 998244353 + 998244353) %              998244353;   }   struct Path {     int l, r;     int len() { return abs(r - l) + 1; }     Path(int l = 0, int r = 0) : l(l), r(r) {}   } x[305], y[305];   int getpath(int u, int v, Path *path) {     static Path l[305], r[305];     int totl = 0, totr = 0;     while (top[u] != top[v]) {       if (dep[top[u]] > dep[top[v]]) {         l[++totl] = Path(st[u], st[top[u]]);         u = fa[top[u]];       } else {         r[++totr] = Path(st[top[v]], st[v]);         v = fa[top[v]];       }     }     if (dep[u] > dep[v])       l[++totl] = Path(st[u], st[v]);     else       r[++totr] = Path(st[u], st[v]);     int tot = 0;     for (int i = 1; i <= totl; i++) path[++tot] = l[i];     for (int i = totr; i >= 1; i--) path[++tot] = r[i];     return tot;   }   inline void getlr(Path pa, int len, int &l, int &r) {     if (pa.l < pa.r)       l = pa.l, r = l + len - 1;     else       l = pa.l, r = l - len + 1;   }   inline void update(Path *pa, int &x, int len) {     if (pa[x].len() == len)       pa[x++] = Path();     else if (pa[x].l < pa[x].r)       pa[x].l += len;     else       pa[x].l -= len;   }   bool ck(int cntx, int cnty, int len) {     if (len == 0) return true;     int l, r;     getlr(x[cntx], len, l, r);     int hx = gethash(l, r);     getlr(y[cnty], len, l, r);     int hy = gethash(l, r);     if (hx == hy)       return true;     else       return false;   }   int query(int a, int b, int c, int d) {     int xn = getpath(a, b, x), yn = getpath(c, d, y);     int cntx = 1, cnty = 1, ret = 0;     while (cntx <= xn && cnty <= yn) {       int len = min(x[cntx].len(), y[cnty].len());       if (ck(cntx, cnty, len)) {         update(x, cntx, len);         update(y, cnty, len);         ret += len;       } else {         int ans = 0, L = 0, R = len - 1;         while (L < R) {           len = (L + R + 1) >> 1;           if (ck(cntx, cnty, len))             L = len;           else             R = len - 1;         }         return ret + L;       }     }     return ret;   }   int main() {     scanf( %d%s , &n, s + 1);     memset(p, -1, sizeof p);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       cnt++, to[cnt] = v, nexti[cnt] = p[u], p[u] = cnt;       cnt++, to[cnt] = u, nexti[cnt] = p[v], p[v] = cnt;     }     dep[1] = 1;     dfs(1, -1);     cnt = 0;     DFS(1, 1);     pw[0] = 1;     for (int i = 1; i <= n; i++) pw[i] = 1LL * pw[i - 1] * 29 % 998244353;     for (int i = 1; i <= n; i++)       pre[i] = (1LL * pre[i - 1] * 29 + s[dfsx[i]] -  a  + 1) % 998244353;     for (int i = n; i >= 1; i--)       suf[i] = (1LL * suf[i + 1] * 29 + s[dfsx[i]] -  a  + 1) % 998244353;     int q;     scanf( %d , &q);     while (q--) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       printf( %d n , query(a, b, c, d));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200005], b[200005], c[200005];   int num = 0;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[a[i]]++;     }     for (int i = 1; i <= n; i++) {       if (b[i] == 0) c[++num] = i;     }     cout << num << endl;     sort(c + 1, c + 1 + num);     int tot = 0;     int hson[200005];     memset(hson, 0, sizeof(hson));     for (int i = 1; i <= n; i++) {       if (b[a[i]] > 1) {         if (c[tot + 1] > a[i] && hson[a[i]] == 0) {           hson[a[i]]++;           continue;         }         tot++;         b[a[i]]--;         a[i] = c[tot];       }     }     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b;   stack<long long int> st;   bool dfs(long long int n) {     if (n > b) {       return false;     }     if (n == b) {       return true;     }     bool a1, a2;     a1 = dfs(n * 2);     if (a1) {       st.push(n * 2);       return true;     }     a2 = dfs((n * 10) + 1);     if (a2) {       st.push((n * 10) + 1);       return true;     }     return false;   }   int main() {     cin >> a >> b;     if (dfs(a)) {       cout <<  YES n ;       cout << st.size() + 1 <<   n ;       cout << a <<    ;       while (!st.empty()) {         cout << st.top() <<    ;         st.pop();       }     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   void printV(vector<int> &S) {     for (int s : S) {       cout << s;     }     cout << endl;   }   void solve() {     int x;     cin >> x;     string T;     cin >> T;     vector<int> S;     for (int i = 0; i < (int)T.size(); i++) {       S.push_back(T[i] -  0 );     }     int l = 0;     while (x > (int)S.size()) {       int end = (int)S.size();       for (int rp = 0; rp < S[l] - 1; rp++) {         for (int i = l + 1; i < end; i++) {           S.push_back(S[i]);         }       }       l++;     }     long long len = (long long)S.size() - l - 1;     for (int i = l; i < x; i++) {       len *= S[i];       len--;       len %= MOD;     }     cout << (len + x + 1 + MOD) % MOD << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) solve();   }


#include <bits/stdc++.h>   using namespace std;   int a[10010];   int n, cnt;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++)       if (a[a[i]] == i && a[i] <= i) cnt++;     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1E-8;   const int FFTSZ = 1 << 20;   const double pi = acos(-1.);   struct cp {     double real, img;     cp(double _r = 0.0, double _i = 0.0) : real(_r), img(_i) {}     cp operator+(const cp &c) const { return cp(real + c.real, img + c.img); }     cp operator-(const cp &c) const { return cp(real - c.real, img - c.img); }     cp operator*(const cp &c) const {       return cp(real * c.real - img * c.img, real * c.img + img * c.real);     }   };   void fft(cp x[], int n, int op) {     for (int i = 1, j = 0; i < n; i++) {       for (int l = n >> 1; (j ^= l) < l; l >>= 1)         ;       if (i < j) swap(x[i], x[j]);     }     for (int h = 2; h <= n; h <<= 1) {       cp wn(cos(-op * 2 * pi / h), sin(-op * 2 * pi / h));       for (int j = 0; j < n; j += h) {         cp w(1, 0);         for (int k = j; k < j + h / 2; k++) {           cp u = x[k], v = w * x[k + h / 2];           x[k] = u + v, x[k + h / 2] = u - v;           w = w * wn;         }       }     }     if (op == -1)       for (int i = 0; i < n; i++) x[i].real /= n, x[i].img /= n;   }   cp x[FFTSZ], y[FFTSZ];   int convolution(int a[], int lena, int b[], int lenb, int c[]) {     int len = 1;     while (len < lena + lenb - 1) len <<= 1;     for (int i = 0; i < len; i++) {       if (i < lena)         x[i] = cp(a[i] * 1.0, 0.0);       else         x[i] = cp(0.0, 0.0);     }     for (int i = 0; i < len; i++) {       if (i < lenb)         y[i] = cp(b[i] * 1.0, 0.0);       else         y[i] = cp(0.0, 0.0);     }     fft(x, len, 1), fft(y, len, 1);     for (int i = 0; i < len; i++) x[i] = x[i] * y[i];     fft(x, len, -1);     c[len] = 0;     for (int i = 0; i < len; i++) c[i] = int(x[i].real + 0.5);     return lena + lenb - 1;   }   const int N = (1 << 20) + 1;   int a[N], p[N];   int n, k;   int main() {     while (~scanf( %d%d , &n, &k)) {       (memset(a, 0, sizeof(a))), (memset(p, 0, sizeof(p)));       a[0] = 1;       int mx = 0;       for (int i = 1; i <= n; i++) {         int v;         scanf( %d , &v);         p[v] = 1;         mx = max(mx, v);       }       mx++;       while (k) {         if (k & 1) convolution(a, mx, p, mx, a);         mx = convolution(p, mx, p, mx, p);         k >>= 1;         for (int i = 0; i < mx; i++) {           a[i] = !!a[i];           p[i] = !!p[i];         }       }       for (int i = 0; i < mx; i++)         if (a[i] != 0) printf( %d  , i);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int powOfPositive(long long int n) {     long long int pos = floor(log2(n));     return pos;   }   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       vector<long long int> arr(n);       for (long long int i = 0; i < n; i++) {         cin >> arr[i];       }       vector<long long int> dp(30, 0);       long long int ans = 0;       for (long long int i = 0; i < n; i++) {         if (arr[i] == 1) {           dp[0]++;           continue;         }         long long int x = powOfPositive(arr[i]);         dp[x]++;       }       for (long long int i = 0; i < 30; i++) {         if (dp[i] > 0) {           ans += ((dp[i]) * (dp[i] - 1)) / 2;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace zyt {   const int N = 1e6 + 10, CH = 20;   int f[1 << CH], n;   char s[N];   bool check(const int a, const int p) { return a & (1 << p); }   int ctoi(const char c) { return c -  a ; }   void get_max(int &a, const int b) { a = max(a, b); }   int work() {     scanf( %s , s);     n = strlen(s);     for (int i = 0; i < n; i++) {       int tmp = 0;       for (int j = i; j < n; j++)         if (check(tmp, ctoi(s[j])))           break;         else           get_max(f[tmp |= (1 << ctoi(s[j]))], j - i + 1);     }     for (int i = 0; i < (1 << CH); i++)       for (int j = 0; j < CH; j++)         if (check(i, j)) get_max(f[i], f[i ^ (1 << j)]);     int ans = 0;     for (int i = 1; i < (1 << CH); i++)       get_max(ans, f[i] + f[~i & ((1 << CH) - 1)]);     printf( %d , ans);     return 0;   }   }  // namespace zyt   int main() { return zyt::work(); }


#include <bits/stdc++.h>   using namespace std;   const int nax = 2 * (int)1e5 + 10;   const int INF = (int)1e9 + 47;   vector<int> g[nax];   int n, k;   int lvl[nax], tin[nax], tout[nax];   int cnt = 0;   int timer = 0;   int ver[nax];   int seen[nax];   int par[nax];   int vr[nax];   vector<pair<int, int>> vec;   void dfs(int v, int p = -1) {     if (p != -1) lvl[v] = lvl[p] + 1;     vec.push_back({lvl[v], v});     par[v] = p;     if (g[v].size() == 1 && p != -1) cnt++;     if (p != -1) lvl[v] = lvl[p] + 1;     for (auto to : g[v]) {       if (to == p) continue;       dfs(to, v);     }   }   long long f(int red, int blue) {     int w = n - red - blue;     return w * 1ll * (red - blue);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       --a, --b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(0);     sort(vec.begin(), vec.end(), greater<pair<int, int>>());     vector<int> vv;     for (int i = 0; i < n; i++) {       int cur = vec[i].second;       int cc = 0;       while (cur != -1 && !seen[cur]) {         cc++;         seen[cur] = 1;         cur = par[cur];       }       vv.push_back(cc);     }     sort(vv.begin(), vv.end(), greater<int>());     int blue = n;     long long best_ans = -(long long)1e18;     for (int i = 0; i < min(k, cnt); i++) {       blue -= vv[i];       int l = 0, r = blue;       for (int it = 0; it < 40; it++) {         int mid = (l + r) / 2;         if (f(i + 1, mid + 1) <= f(i + 1, mid))           l = mid;         else           r = mid;       }       if ((f(i + 1, r) > f(i + 1, r + 1) && r + 1 < blue) ||           (f(i + 1, r - 1) < f(i + 1, r) && r - 1 >= 0))         throw 47;       best_ans = max(best_ans, f(i + 1, r));     }     while (cnt <= k) {       best_ans = max(best_ans, (n - cnt) * 1ll * cnt);       cnt++;     }     cout << best_ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       vector<long long> v;       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         v.push_back(x);       }       sort(v.begin(), v.end());       long long ans = v[0] * v[v.size() - 1];       int sum = 0, flag = 1;       for (long long i = 2; i * i <= ans; i++) {         if (ans % i == 0) {           if (find(v.begin(), v.end(), i) == v.end() ||               find(v.begin(), v.end(), ans / i) == v.end()) {             flag = 0;             break;           }           sum += 2;           if (i * i == ans) sum--;         }       }       if (sum == n && flag == 1)         cout << ans << endl;       else         cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 + 10;   const int INF = 99999999;   const double eps = 1e-4;   int dp[MAXN];   int main() {     int n, m, c0, d0;     cin >> n >> m >> c0 >> d0;     memset(dp, 0, sizeof(dp));     for (int i = c0; i <= n; i++) dp[i] = i / c0 * d0;     for (int i = 1; i <= m; i++) {       int a, b, c, d;       cin >> a >> b >> c >> d;       for (int j = 1; j <= a / b; j++) {         for (int k = n; k >= c; k--) dp[k] = max(dp[k - c] + d, dp[k]);       }     }     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nod(long long a, long long b) {     while (a != 0 && b != 0) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   int main() {     long long n, a[100];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long p = nod(a[0], a[1]);     for (int i = 1; i < n; i++) p = nod(p, a[i]);     long long max = a[n - 1], s;     s = ((max - p) / p) + 1;     if ((s - n) % 2 == 0)       cout <<  Bob ;     else       cout <<  Alice ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long M = (long long)1e9 + 7;   int Int() {     int x;     scanf( %d , &x);     return x;   }   long long Long() {     long long x;     scanf( %lld , &x);     return x;   }   void Char(char *ch) { scanf( %s , ch); }   template <typename t>   inline t abs(t a) {     if (a >= 0) return a;     return -a;   }   template <typename T>   inline T modpow(T b, T p, T Mod) {     T res = 1;     while (p) {       if (p & 1) {         res *= b;         res %= Mod;       }       b *= b;       b %= Mod;       p >>= 1;     }     return res;   }   template <typename T>   inline T ModInv(T b, T Mod) {     return modpow(b, Mod - 2, Mod);   }   long long pwr(long long b, long long p) {     long long res = 1LL;     while (p) {       if (p & 1) {         res *= b;       }       b *= b;       p >>= 1LL;     }     return res;   }   template <typename T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename T>   inline void Int(T &n) {     n = 0;     int f = 1;     register int ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch -  0 ;     n = n * f;   }   template <typename T, typename U>   inline void Int(T &a, U &b) {     Int(a);     Int(b);   }   template <typename T, typename U, typename W>   inline void Int(T &a, U &b, W &c) {     Int(a, b);     Int(c);   }   template <typename T, typename U, typename W, typename X>   inline void Int(T &a, U &b, W &c, X &d) {     Int(a, b, c);     Int(d);   }   vector<int> Unique(vector<int> v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     return v;   }   vector<string> split(const string &s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cout << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<    ;     err(++it, args...);   }   int digit(long long n) {     int s = 0;     while (n) {       n /= 10;       s++;     }     return s;   }   long long F(long long n) {     int len = digit(n);     if (len <= 1) return n;     long long res = 0, add = 9;     for (int i = 1; i < len; i++) {       if (i == 1) {         res += 9;       } else {         res += add;         add *= 10;       }     }     long long k = pwr(10, len - 1);     long long x = n / k;     long long y = n % 10LL;     long long p = (n % k) / 10LL;     if (y >= x) {       res += (p + 1) + ((x - 1) * (k / 10LL));     } else {       res += p + ((x - 1) * (k / 10LL));     }     return res;   }   int main() {     long long a = Long(), b = Long();     printf( %lld n , F(b) - F(a - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     std::cin >> n >> m;     getchar();     int a[n][m], nums[m];     for (int i = 0; i < m; i++) {       nums[i] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         a[i][j] = getchar() -  0 ;         nums[j] += a[i][j];       }       getchar();     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j]) {           if (nums[j] == 1) goto A;         }       }       std::cout <<  YES ;       return 0;     A:;     }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long double x, y, s;     point() {}     point(int xx, int yy, point o) {       x = (long double)xx, y = (long double)yy;       s = atan2(y - o.y, x - o.x);     }   } o, p;   bool operator<(point _1, point _2) {     if (_1.s == _2.s) {       return _1.x < _2.x;     }     return _1.s < _2.s;   }   point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y, o); }   long double Cro(point a, point b) { return a.x * b.y - a.y * b.x; }   int px[5], py[5], n;   set<point> s;   set<point>::iterator getpre(set<point>::iterator it) {     if (it == s.begin()) {       return --s.end();     }     return --it;   }   set<point>::iterator getnxt(set<point>::iterator it) {     if ((++it) == s.end()) {       return s.begin();     }     return it;   }   void Insert(point p) {     s.insert(p);     set<point>::iterator tmp = s.find(p);     set<point>::iterator i = getpre(tmp), j = getpre(i);     while (Cro(p - (*j), (*i) - (*j)) >= 0) {       s.erase(i);       i = j, j = getpre(j);     }     i = getnxt(tmp), j = getnxt(i);     while (Cro(p - (*j), (*i) - (*j)) <= 0) {       s.erase(i);       i = j, j = getnxt(j);     }     return;   }   int main() {     {       n = 0;       char ch;       int f = 0;       do {         ch = getchar();         if (ch ==  - ) {           f = 1;         }       } while (ch <  0  || ch >  9 );       while ( 0  <= ch && ch <=  9 ) {         n = (n << 1) + (n << 3) + ch - 48;         ch = getchar();       }       if (f) n = -n;     }     int op, x, y;     for (int i = 1; i <= 3; i++) {       {         op = 0;         char ch;         int f = 0;         do {           ch = getchar();           if (ch ==  - ) {             f = 1;           }         } while (ch <  0  || ch >  9 );         while ( 0  <= ch && ch <=  9 ) {           op = (op << 1) + (op << 3) + ch - 48;           ch = getchar();         }         if (f) op = -op;       }       {         px[i] = 0;         char ch;         int f = 0;         do {           ch = getchar();           if (ch ==  - ) {             f = 1;           }         } while (ch <  0  || ch >  9 );         while ( 0  <= ch && ch <=  9 ) {           px[i] = (px[i] << 1) + (px[i] << 3) + ch - 48;           ch = getchar();         }         if (f) px[i] = -px[i];       }       {         py[i] = 0;         char ch;         int f = 0;         do {           ch = getchar();           if (ch ==  - ) {             f = 1;           }         } while (ch <  0  || ch >  9 );         while ( 0  <= ch && ch <=  9 ) {           py[i] = (py[i] << 1) + (py[i] << 3) + ch - 48;           ch = getchar();         }         if (f) py[i] = -py[i];       }       o.x += (long double)px[i], o.y += (long double)py[i];     }     o.x /= 3.0, o.y /= 3.0;     for (int i = 1; i <= 3; i++) {       s.insert(point(px[i], py[i], o));     }     for (int i = 4; i <= n; i++) {       {         op = 0;         char ch;         int f = 0;         do {           ch = getchar();           if (ch ==  - ) {             f = 1;           }         } while (ch <  0  || ch >  9 );         while ( 0  <= ch && ch <=  9 ) {           op = (op << 1) + (op << 3) + ch - 48;           ch = getchar();         }         if (f) op = -op;       }       {         x = 0;         char ch;         int f = 0;         do {           ch = getchar();           if (ch ==  - ) {             f = 1;           }         } while (ch <  0  || ch >  9 );         while ( 0  <= ch && ch <=  9 ) {           x = (x << 1) + (x << 3) + ch - 48;           ch = getchar();         }         if (f) x = -x;       }       {         y = 0;         char ch;         int f = 0;         do {           ch = getchar();           if (ch ==  - ) {             f = 1;           }         } while (ch <  0  || ch >  9 );         while ( 0  <= ch && ch <=  9 ) {           y = (y << 1) + (y << 3) + ch - 48;           ch = getchar();         }         if (f) y = -y;       }       p = point(x, y, o);       set<point>::iterator nxt = s.lower_bound(p);       if (nxt == s.end()) {         nxt = s.begin();       }       set<point>::iterator pre = getpre(nxt);       if (op == 1) {         if (Cro(p - (*pre), (*nxt) - p) > 0) {           Insert(p);         }       } else {         if (Cro(p - (*pre), (*nxt) - p) > 0) {           puts( NO );         } else {           puts( YES );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double n, l, v1, v2, k;     cin >> n >> l >> v1 >> v2 >> k;     double m = ceil(n / k);     double ans =         l * v2 / (v1 * v2 - v2 * (v1 * v1 - v2 * v2) / (v1 + (2 * m - 1) * v2));     cout << fixed << setprecision(10) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ar[5000009];   long long j;   int finder(vector<pair<long long, long long> > v, long long jump) {     for (int i = 0; i < v.size(); i++) {       if (v[i].first > jump) {         return i;       }     }     return v.size();   }   long long count = 0;   vector<pair<long long, long long> > v[4];   void dfs1(long long b, long long p, long long jump) {     if (v[b].size() == 0) {       ::count = max(::count, p);       return;     } else {       long long low = finder(v[b], jump);       if (v[b][0].first > jump) {         ::count = max(::count, p);         return;       } else {         low--;         long long u = 0, maxi = v[b][0].second;         for (int k = 1; k <= low; k++) {           if (maxi < v[b][k].second) {             maxi = v[b][k].second;             u = k;           }         }         jump += v[b][u].second;         v[b].erase(v[b].begin() + u);         dfs1((b == 1) ? 0 : ((b == 0) ? 1 : ((b == 2) ? 3 : 2)), p + 1, jump);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n, jump, a, s, d;     cin >> n >> jump;     for (int i = 0; i < n; ++i) {       cin >> a >> s >> d;       if (a == 0) {         v[0].push_back(make_pair(s, d));         v[2].push_back(make_pair(s, d));       } else {         v[3].push_back(make_pair(s, d));         v[1].push_back(make_pair(s, d));       }     }     sort(v[0].begin(), v[0].end());     sort(v[1].begin(), v[1].end());     sort(v[2].begin(), v[2].end());     sort(v[3].begin(), v[3].end());     dfs1(0, 0, jump);     dfs1(3, 0, jump);     cout << ::count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     long long int res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int logtwo(long long int n) {     if (n == 1) return 0;     return logtwo(n / 2) + 1;   }   vector<long long int> adj[105][105];   long long int vis[105][105];   void dfs(int par, long long int col) {     for (auto child : adj[par][col]) {       if (vis[child][col]) continue;       vis[child][col] = vis[par][col];       dfs(child, col);     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       long long int N, M;       cin >> N >> M;       for (long long int i = 0; i < M; i++) {         long long int a, b, c;         cin >> a >> b >> c;         a--;         b--;         adj[a][c].push_back(b);         adj[b][c].push_back(a);       }       for (long long int i = 0; i < 105; i++) {         long long int c = 1;         for (long long int j = 0; j < N; j++) {           if (vis[j][i]) continue;           vis[j][i] = c++;           dfs(j, i);         }       }       long long int Q;       cin >> Q;       while (Q--) {         long long int x, y;         cin >> x >> y;         long long int ans = 0;         x--;         y--;         for (long long int i = 0; i < 105; i++) {           if (vis[x][i] && vis[x][i] == vis[y][i]) ans++;         }         cout << ans <<   n ;       }     }     cerr <<  Time :   << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC          <<  ms n ;     ;   }


#include <bits/stdc++.h>   using namespace std;   int st[200011], disc = 0, mod, en[200011];   vector<int> adj[200011];   bitset<1003> m[1000011];   int flag[1000011], a[200011];   int p[2011], arr[200011];   vector<int> pr;   bitset<1003> def;   void dfs(int u, int p) {     st[u] = disc;     arr[disc] = u;     disc++;     for (int i = 0; i < adj[u].size(); i++) {       int k = adj[u][i];       if (k == p) continue;       dfs(k, u);     }     en[u] = disc - 1;   }   void rotate(std::bitset<1003>& b, unsigned m) {     b = (((b << m) & def) | (b >> (mod - m)));   }   void build(int n, int b, int e) {     if (b == e) {       m[n].set(a[arr[b]]);       return;     }     int l = 2 * n, mid = (b + e) / 2;     build(l, b, mid);     build(l + 1, mid + 1, e);     m[n] = m[l] | m[l + 1];   }   void update(int n, int b, int e, int x, int y, int v) {     if (flag[n] != 0) {       rotate(m[n], flag[n]);       if (b != e) {         flag[2 * n] = (flag[2 * n] + flag[n]) % mod;         flag[2 * n + 1] = (flag[2 * n + 1] + flag[n]) % mod;       }       flag[n] = 0;     }     if (b > y || e < x) return;     if (b >= x && e <= y) {       rotate(m[n], v);       if (b != e) {         flag[2 * n] = (flag[2 * n] + v) % mod;         flag[2 * n + 1] = (flag[2 * n + 1] + v) % mod;       }       return;     }     int l = 2 * n, mid = (b + e) / 2;     update(l, b, mid, x, y, v);     update(l + 1, mid + 1, e, x, y, v);     m[n] = m[l] | m[l + 1];   }   bitset<1003> query(int n, int b, int e, int x, int y) {     if (flag[n] != 0) {       rotate(m[n], flag[n]);       if (b != e) {         flag[2 * n] = (flag[2 * n] + flag[n]) % mod;         flag[2 * n + 1] = (flag[2 * n + 1] + flag[n]) % mod;       }       flag[n] = 0;     }     if (b > y || e < x) return 0;     if (b >= x && e <= y) return m[n];     int l = 2 * n, mid = (b + e) / 2;     return (query(l, b, mid, x, y) | query(l + 1, mid + 1, e, x, y));   }   int main() {     int n, i, j, k;     scanf( %d %d , &n, &mod);     for (i = 2; i < mod; i++)       if (p[i] == 0) {         pr.push_back(i);         for (j = i + i; j < mod; j += i) p[j] = 1;       }     for (i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] %= mod;     for (i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     build(1, 0, n - 1);     int q;     scanf( %d , &q);     for (i = 0; i < mod; i++) def.set(i);     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int x, v;         scanf( %d %d , &v, &x);         x %= mod;         update(1, 0, n - 1, st[v], en[v], x);       } else {         int v, ans = 0;         scanf( %d , &v);         bitset<1003> b = query(1, 0, n - 1, st[v], en[v]);         for (int i = 0; i < pr.size(); i++)           if (b.test(pr[i])) ans++;         printf( %d n , ans);       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); }   char s[100100];   long long res[2][2];   int main() {     cin >> s;     int len = strlen(s);     memset(res, 0, sizeof(res));     long long a = 0, b = 0;     for (int i = 0; i < len; i++) {       int temp = i & 1;       res[s[i] -  a ][temp]++;       a += res[s[i] -  a ][1 - temp];       b += res[s[i] -  a ][temp];     }     cout << a <<     << b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     long long int a[m];     for (int i = 0; i < m; i++) {       cin >> a[i];     }     sort(a, a + m);     int i = 0;     while (i < m - 2) {       if (a[i] + 1 == a[i + 1] && a[i + 1] + 1 == a[i + 2]) {         cout <<  NO n ;         return 0;       }       i++;     }     if (a[0] == 1 || a[m - 1] == n) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double lim = 1e99;   template <typename T>   inline T read() {     register T sum = 0;     register char cc = getchar();     int sym = 1;     while (cc !=  -  && (cc >  9  || cc <  0 )) cc = getchar();     if (cc ==  - ) sym = -1, cc = getchar();     sum = sum * 10 + cc -  0 ;     cc = getchar();     while (cc >=  0  && cc <=  9 ) sum = sum * 10 + cc -  0 , cc = getchar();     return sym * sum;   }   template <typename T>   inline T read(T& a) {     a = read<T>();     return a;   }   template <typename T, typename... Others>   inline void read(T& a, Others&... b) {     a = read(a);     read(b...);   }   int n, m, K;   long double ans, fac[100010];   long double C(int n, int m) { return fac[n] - fac[m] - fac[n - m]; }   int main() {     read(n, m, K);     for (int i = 1; i <= m; i++) fac[i] = fac[i - 1] + log(1. * i);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) {         int num = (i + j) * n - i * j;         if (num <= K) {           long double p = C(n, i) + C(n, j) + C(m - num, K - num) - C(m, K);           ans = min(ans + exp(p), lim);         }       }     printf( %.15Lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int MAX_N = 200000;   int N, M, S, D;   int X[MAX_N + 10];   int DP[MAX_N + 1] = {0};   stack<string> OPS;   void run(int x) {     if (x == 0) return;     std::ostringstream os;     os <<  RUN   << x;     OPS.push(os.str());   }   void jump(int x) {     assert(x > 0);     std::ostringstream os;     os <<  JUMP   << x;     OPS.push(os.str());   }   bool dfs(int p) {     assert(p >= 0 && p <= N);     if (DP[p] != 0) {       assert(DP[p] == 2);       return false;     }     if (M < X[p]) {       DP[p] = 2;       return false;     }     if (p == N || M < X[p + 1]) {       run(M - X[p] - 1);       DP[p] = 1;     } else {       DP[p] = 2;       int space = X[p + 1] - X[p] - 2;       if (space < S) {         return false;       }       int i = p + 1;       while (DP[p] != 1 && i <= N && X[i] + 1 <= X[p + 1] - 1 + D) {         if (dfs(i)) {           DP[p] = 1;           jump(X[i] + 1 - X[p + 1] + 1);           run(space);         }         i++;       }     }     return DP[p] == 1;   }   int main() {     cin >> N >> M >> S >> D;     X[0] = -1;     for (int i = 0; i < N; i++) {       cin >> X[i + 1];     }     sort(&X[0], &X[N + 1]);     if (!dfs(0)) {       printf( IMPOSSIBLE n );     } else {       while (!OPS.empty()) {         cout << OPS.top() << endl;         OPS.pop();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long mpow(long long x, long long y) {     if (y == 0) return 1;     if (y % 2) return x * mpow(x, y - 1) % MOD;     long long h = mpow(x, y / 2);     return h * h % MOD;   }   long long arr[111111];   int main() {     int k;     scanf( %d , &k);     for (int i = 0; i < k; i++) scanf( %lld , arr + i);     long long p = 2;     for (int i = 0; i < k; i++) p = mpow(p, arr[i]);     p = p * mpow(2, MOD - 2) % MOD;     long long q = p;     if (all_of(arr, arr + k, [&](long long i) { return i % 2; }))       p = (p - 1 + MOD) % MOD;     else       p = (p + 1) % MOD;     p = p * mpow(3, MOD - 2) % MOD;     printf( %lld/%lld , p, q);   }


#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long m, n, i, j;     string a, b;     cin >> m >> n >> a >> b;     long long t[m + 1][n + 1];     memset(t, 0, sizeof(t));     long long sol = 0;     for (i = 1; i <= m; i++)       for (j = 1; j <= n; j++) {         if (a[i - 1] == b[j - 1])           t[i][j] = 2 + t[i - 1][j - 1];         else           t[i][j] = max(t[i - 1][j], t[i][j - 1]) - 1;         t[i][j] = max((long long)0, t[i][j]);         sol = max(sol, t[i][j]);       }     return sol;   }   int32_t main() {     long long t = 1;     while (t--) cout << solve() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int nm = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) nm = nm * 10 + c -  0 ;     return nm * f;   }   long long cup[10001], flow[10001], to[10001], head[10001], nxt[10001],       deep[10001];   bool vis[10001];   int n, m, s, t, cnt = 1;   long long ans = 0;   void push(int vi, int vj, long long v) {     cnt++, to[cnt] = vj, nxt[cnt] = head[vi], head[vi] = cnt, cup[cnt] = v;     cnt++, to[cnt] = vi, nxt[cnt] = head[vj], head[vj] = cnt;   }   bool bfs(int be, int ed) {     memset(deep, 0, sizeof(deep));     deep[be] = 1;     queue<int> q;     q.push(be);     while (!q.empty()) {       int now = q.front();       q.pop();       for (int i = head[now]; i; i = nxt[i]) {         int vj = to[i];         if (flow[i] >= cup[i] || deep[vj]) continue;         deep[vj] = deep[now] + 1;         q.push(vj);         if (vj == ed) return true;       }     }     return false;   }   long long dfs(int now, int ed, long long f) {     if (f == 0 || now == ed) return f;     long long tot = 0, x;     for (int i = head[now]; i; i = nxt[i]) {       int vj = to[i];       if (deep[vj] != deep[now] + 1) continue;       if (x = dfs(vj, ed, min(f, cup[i] - flow[i]))) {         flow[i] += x;         flow[i ^ 1] -= x;         tot += x;         f -= x;       }       if (f == 0) break;     }     if (tot == 0) deep[now] = -1;     return tot;   }   void Dinic(int be, int ed) {     while (bfs(be, ed)) ans -= dfs(be, ed, 1ll << 50);   }   int main() {     n = read(), m = read();     s = n + m + 1, t = s + 1;     for (int i = 1; i <= n; i++) {       push(i, t, read());     }     for (int i = 1; i <= m; i++) {       int vi = read(), vj = read(), v = read();       ans += v;       push(s, n + i, v);       push(n + i, vi, 1ll << 50);       push(n + i, vj, 1ll << 50);     }     Dinic(s, t);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2036000;   const long long INF = 199999999999LL;   int n, m;   long long a[N], b[N];   long long first, second, mod;   long long w[N], t[N];   int nn;   void AddA(int &i) {     w[nn] = a[i++];     t[nn++] = 1;   }   void AddB(int &j) {     w[nn] = b[j++];     t[nn++] = 2;   }   int main() {     cin >> n;     cin >> n >> a[0] >> first >> second >> mod;     for (int i = (1); i < (int)(n); i++) a[i] = (a[i - 1] * first + second) % mod;     cin >> m >> b[0] >> first >> second >> mod;     for (int j = (1); j < (int)(m); j++) b[j] = (b[j - 1] * first + second) % mod;     int i = 0, j = 0;     nn = 0;     long long lt = -INF;     while (i < n || j < m) {       if (i == n) {         AddB(j);       } else if (j == m) {         AddA(i);       } else {         bool ga = a[i] >= lt;         bool gb = b[j] >= lt;         if (ga ^ gb) {           if (ga) {             AddA(i);           } else {             AddB(j);           }         } else {           if (a[i] < b[j]) {             AddA(i);           } else {             AddB(j);           }         }       }       lt = w[nn - 1];     }     int bad = 0;     for (int k = (1); k < (int)(nn); k++) bad += (w[k] < w[k - 1]);     cout << bad << endl;     if (n + m <= 200000) {       for (int k = (0); k < (int)(nn); k++) cout << w[k] <<     << t[k] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   const int inf = 1e9 + 1;   const long long OO = 1e18;   long long p1, p2, c1, c2, w1, w2;   long long solve() {     long long a2, b1, b3, ans = 0;     for (int i = 0; i <= min(p1 / w1, c1); i++) {       long long a2 = min((p1 - i * w1) / w2, c2);       long long b1 = min(p2 / w1, c1 - i);       long long b2 = min((p2 - b1 * w1) / w2, c2 - a2);       ans = max(ans, i + a2 + b1 + b2);     }     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> p1 >> p2 >> c1 >> c2 >> w1 >> w2;       if (w1 > w2) {         swap(w1, w2);         swap(c1, c2);       }       cout << solve() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, lam, mx = 0, c = 0;     cin >> n;     vector<int> cand(n);     for (int i = 0; i < n; i++) {       cin >> cand[i];       if (mx < cand[i]) mx = cand[i];     }     for (int i = 0; i < n; i++)       if (mx == cand[i]) c++;     int x = lam = cand[0];     if (lam == mx && c > 1) return cout <<  1 , 0;     if (lam == mx && c == 1) return cout <<  0 , 0;     sort(cand.begin(), cand.end());     while (lam <= cand[n - 1]) {       lam += 1;       cand[n - 1] -= 1;       sort(cand.begin(), cand.end());     }     cout << lam - x;   }


#include <bits/stdc++.h>   using namespace std;   int64_t *arry[3];   int main(void) {     int64_t n, p, q, r;     cin >> n >> p >> q >> r;     for (int i = 0; i < 3; i++) {       arry[i] = (int64_t *)malloc(sizeof(int64_t) * n);     }     for (int i = 0; i < n; i++) {       int buf;       cin >> buf;       arry[0][i] = buf * p;       arry[1][i] = buf * q;       arry[2][i] = buf * r;     }     {       int64_t *pt = (int64_t *)malloc(sizeof(int64_t) * n);       pt[n - 1] = arry[2][n - 1];       for (int i = n - 1; i > 0; i--) {         pt[i - 1] = max(pt[i], arry[2][i - 1]);       }       free(arry[2]);       arry[2] = pt;     }     {       int64_t *pt = (int64_t *)malloc(sizeof(int64_t) * n);       for (int i = 0; i < n; i++) {         pt[i] = arry[1][i] + arry[2][i];       }       free(arry[1]);       arry[1] = pt;     }     {       int64_t *pt = (int64_t *)malloc(sizeof(int64_t) * n);       pt[0] = *arry[0];       for (int i = 1; i < n; i++) {         pt[i] = max(pt[i - 1], arry[0][i]);       }       free(arry[0]);       arry[0] = pt;     }     int64_t max = arry[0][0] + arry[1][0];     for (int i = 1; i < n; i++) {       int64_t buf = arry[0][i] + arry[1][i];       if (buf > max) max = buf;     }     cout << max << endl;     for (int i = 0; i < 3; i++) {       free(arry[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   long long int func(long long int n) {     long long int res = 0;     while (n != 0) {       n /= 10;       res++;     }     return res;   }   int main() {     long long int w, m, k;     cin >> w >> m >> k;     long long int n = func(m), tr = w / k, res = 0;     while (tr > 0) {       long long int dum = pow(10, n) - m;       res += fmin(tr / n, dum);       tr -= dum * n;       m += dum;       n++;     }     cout << res;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   int main() {     long double r, x1, y1, x2, y2;     cin >> r >> x1 >> y1 >> x2 >> y2;     long double x = sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));     if (x - r >= 0)       cout << fixed << setprecision(10) << x1 <<     << y1 <<     << r;     else {       if (x == 0) {         cout << x1 - r / 2 <<     << y1 <<     << r / 2;         return 0;       }       x1 = x1 + ((x - r) / 2) * (x2 - x1) / x;       y1 = y1 + ((x - r) / 2) * (y2 - y1) / x;       cout << fixed << setprecision(10) << x1 <<     << y1 <<                << r - (r - x) / 2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Rd(int &x) {     static char c;     x = 0;     while ((c = getchar()) < 48)       ;     do x = (x << 3) + (x << 1) + (c ^ 48);     while ((c = getchar()) > 47);   }   int n;   int Next[200004 << 1], V[200004 << 1], W[200004], Head[200004], tot;   void Add_Edge(int u, int v) { Next[++tot] = Head[u], V[Head[u] = tot] = v; }   int Sz[200004], G, Mn, Nowsz;   bool Mark[200004];   long long Ans, Dis[200004];   void GetG(int x, int f) {     int y, mx = 0;     Sz[x] = 1;     for (int i = Head[x]; i; i = Next[i])       if (!Mark[y = V[i]] && y != f) {         GetG(y, x);         Sz[x] += Sz[y];         mx = max(mx, Sz[y]);       }     mx = max(mx, Nowsz - Sz[x]);     if (mx < Mn) Mn = mx, G = x;   }   int m;   struct Node {     int l;     long long d;   } D[200004];   long long Calc(int x) {     long long Tmp[2] = {0, 0}, Cnt[2] = {0, 0}, Res = 0;     for (int i = (0), i_end_ = (m); i < i_end_; ++i)       (Tmp[D[i].l & 1] += D[i].d) %= 1000000007, Cnt[D[i].l & 1]++;     Res -= 2 * Cnt[1] * Tmp[1] + Cnt[1] * Cnt[1] % 1000000007 * W[x];     Res += 2 * Cnt[0] * Tmp[0] + Cnt[0] * Cnt[0] % 1000000007 * W[x];     return Res % 1000000007;   }   void Gets(int x, int f, int d) {     D[m++] = (Node){d, Dis[x]};     int y;     Sz[x] = 1;     for (int i = Head[x]; i; i = Next[i])       if (!Mark[y = V[i]] && y != f) {         Dis[y] = Dis[x] + ((d & 1) ? W[y] : -W[y]);         Gets(y, x, d + 1);         Sz[x] += Sz[y];       }   }   void Work(int x, int sz) {     Mn = 200004, Nowsz = sz;     GetG(x, 0);     Mark[x = G] = 1;     m = Dis[x] = 0;     Gets(x, 0, 0);     Ans += Calc(x);     if (sz == 1) return;     int y;     for (int i = Head[x]; i; i = Next[i])       if (!Mark[y = V[i]]) {         m = 0;         Gets(y, x, 1);         Ans -= Calc(x);         Work(y, Sz[y]);       }   }   int main() {     Rd(n);     for (int i = (1), i_end_ = (n + 1); i < i_end_; ++i) scanf( %d , &W[i]);     for (int i = (1), i_end_ = (n); i < i_end_; ++i) {       int u, v, w;       Rd(u), Rd(v);       Add_Edge(u, v);       Add_Edge(v, u);     }     Work(1, n);     printf( %I64d n , (Ans % 1000000007 + 1000000007) % 1000000007);     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const ll MOD =  998244353;   #define rep(i,a,b) for(ll i=a;i<b;++i)    #define pii pair<int,int>      int main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       int tt=1;       cin>>tt;       while(tt--)       {           int n;           cin>>n;           int a[n];           rep(i,0,n)           cin>>a[i];           vector<int> v;           rep(i,0,n)           {               v.push_back(a[i]);               int p = i+1;               rep(j,i+1,n)               {                   p = j;                   if(a[j]>a[i]) break;                   v.push_back(a[j]);               }               reverse(v.begin()+i,v.end());               i = p-1;               if(p==n-1 && v.size()==n) i=n;           }           for(int i=v.size()-1;i>=0;--i)           cout<<v[i]<<   ;           cout<<  n ;       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a[120], i, j, res;     while (scanf( %d %d , &n, &m) == 2) {       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       bool flag = true;       int k = 0;       while (flag) {         for (i = 1; i <= n; i++) {           if (a[i]) {             if (a[i] <= m) {               a[i] = 0;               k++;               if (k == n) {                 flag = false;                 res = i;               }             } else if (a[i] > m) {               a[i] -= m;             }           }         }       }       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     double r, v, si, fi;     cin >> n >> r >> v;     for (int i = 0; i < n; i++) {       cin >> si >> fi;       double dist = fi - si;       double cir = 2 * 3.14159265358979323846 * r;       double rev = dist / cir;       rev = floor(rev);       double time = rev * (cir / v);       dist -= time * v;       double left = 0;       double right = cir / v;       double x;       while (right - left > 1e-12) {         double mid = (left + right) / 2;         double temp =             2 * r * sin((mid * 3.14159265358979323846) / (cir / v)) + mid * v;         if (temp >= dist) {           right = mid;         } else           left = mid;       }       time += left;       printf( %.12f n , time);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n, Q, x;   int fa[N], fv[N];   vector<int> c[N];   struct nod {     int i, l, r;   } b;   vector<nod> a[N];   int pl, pr;   long long px;   long long t[N * 4], lz[N * 4];   void down(int i) {     if (lz[i]) {       t[i + i] += lz[i];       lz[i + i] += lz[i];       t[i + i + 1] += lz[i];       lz[i + i + 1] += lz[i];       lz[i] = 0;     }   }   void add(int i, int x, int y) {     if (y < pl || x > pr) return;     if (x >= pl && y <= pr) {       t[i] += px;       lz[i] += px;       return;     }     int m = x + y >> 1;     down(i);     add(i + i, x, m);     add(i + i + 1, m + 1, y);     t[i] = min(t[i + i], t[i + i + 1]);   }   void ft(int i, int x, int y) {     if (y < pl || x > pr) return;     if (x >= pl && y <= pr) {       px = min(px, t[i]);       return;     }     int m = x + y >> 1;     down(i);     ft(i + i, x, m);     ft(i + i + 1, m + 1, y);   }   int p[N], q[N], tp;   long long s[N];   const long long M = 1e18;   void dg(int x) {     p[x] = ++tp;     for (int j = 0, B = c[x].size() - 1; j <= B; j++) {       int y = c[x][j];       s[y] = s[x] + fv[y], dg(y);     }     q[x] = tp;     if (p[x] == q[x]) {       pl = pr = p[x];       px = s[x] - M;       add(1, 1, n);     }   }   long long ans[N];   void dfs(int x) {     for (int j = 0, B = a[x].size() - 1; j <= B; j++) {       pl = a[x][j].l, pr = a[x][j].r;       px = 1e18;       ft(1, 1, n);       ans[a[x][j].i] = px;     }     for (int j = 0, B = c[x].size() - 1; j <= B; j++) {       int y = c[x][j];       px = -fv[y];       pl = p[y];       pr = q[y];       add(1, 1, n);       px = fv[y];       pl = 1;       pr = p[y] - 1;       add(1, 1, n);       pl = q[y] + 1;       pr = n;       add(1, 1, n);       dfs(y);       px = -fv[y];       pl = q[y] + 1;       pr = n;       add(1, 1, n);       pl = 1;       pr = p[y] - 1;       add(1, 1, n);       px = fv[y];       pl = p[y];       pr = q[y];       add(1, 1, n);     }   }   int main() {     scanf( %d %d , &n, &Q);     for (int i = 1, B = n * 4; i <= B; i++) t[i] = 1e18;     for (int i = 2, B = n; i <= B; i++) {       scanf( %d %d , &fa[i], &fv[i]);       c[fa[i]].push_back(i);     }     for (int i = 1, B = Q; i <= B; i++) {       scanf( %d , &x);       scanf( %d %d , &b.l, &b.r);       b.i = i;       a[x].push_back(b);     }     dg(1);     dfs(1);     for (int i = 1, B = Q; i <= B; i++) printf( %I64d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int NWarm, NChip;     cin >> NWarm >> NChip;     int temp = NWarm * (NWarm + 1) / 2;     int ans = NChip % temp;     int i;     for (i = 1; i <= temp; i++) {       ans = ans - i;       if (ans < 0) break;     }     int ans1 = ans + i;     cout << ans1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> start(m);     vector<int> ending(m);     vector<int> time(m);     vector<int> prize(m);     int money = 0;     for (int i = 0; i < m; i++) {       cin >> start[i] >> ending[i] >> time[i] >> prize[i];     }     int mn = 9000;     int currprize;     for (int j = 1; j <= n; j++) {       mn = 9000;       currprize = 0;       for (int i = 0; i < m; i++) {         if (start[i] <= j && ending[i] >= j && time[i] < mn) {           mn = time[i];           currprize = prize[i];         }       }       money += currprize;     }     cout << money << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200005;   const int Maxd = 10;   int bits[1 << Maxd];   int t;   char str[Maxn];   int slen;   int main() {     for (int i = 1; i < 1 << Maxd; i++) bits[i] = 1 + bits[i - (i & -i)];     scanf( %d , &t);     while (t--) {       scanf( %s , str);       slen = strlen(str);       int cur = 0;       for (int i = 0; i < slen; i++) cur ^= 1 << int(str[i] -  0 );       bool solved = false;       for (int i = slen - 1; i >= 0 && !solved; i--) {         int my = str[i] -  0 ;         cur ^= 1 << my;         for (int j = my - 1; j >= 0 && !solved; j--) {           cur ^= 1 << j;           if (i + 1 + bits[cur] <= slen) {             solved = true;             str[i] = j +  0 ;             int pnt = i + 1;             int lft = slen - (i + 1 + bits[cur]);             while (lft--) str[pnt++] =  9 ;             for (int l = Maxd - 1; l >= 0; l--)               if (cur & 1 << l) str[pnt++] =  0  + l;           }           cur ^= 1 << j;         }       }       int pnt = 0;       while (str[pnt] ==  0 ) pnt++;       for (int i = pnt; i < slen - pnt; i++) printf( %c , str[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n;   vector<int> v, lm, rm;   class SegmentTreeMax {    public:     int n;     vector<long long> vect;     SegmentTreeMax(int _n) : n(_n) {       vect.resize(2 * n);       fill(vect.begin(), vect.end(), 0);     }     void modify(int p, long long value) {       for (vect[p += n] = value; p > 1; p >>= 1) {         int val = rm[vect[p]] > rm[vect[p ^ 1]] ? vect[p] : vect[p ^ 1];         vect[p >> 1] = val;       }     }     long long query(int l, int r) {       long long res = 0;       for (l += n, r += n; l < r; l >>= 1, r >>= 1) {         if (l & 1) {           if (rm[res] < rm[vect[l]]) res = vect[l];           l++;         }         if (r & 1) {           if (rm[res] < rm[vect[r - 1]]) res = vect[r - 1];           r--;         }       }       return res;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     v.resize(n + 1);     lm.resize(n + 1);     rm.resize(n + 1);     vector<int> v2;     for (int i = 1; i <= n; i++) {       cin >> v[i];       v2.push_back(v[i]);     }     v2.push_back(0);     sort(v2.begin(), v2.end());     auto it = unique(v2.begin(), v2.end());     v2.resize(it - v2.begin());     int l = 1, r = 1;     vector<int> ans;     SegmentTreeMax stm(n + 1);     vector<int> visited, ct(n + 1);     vector<vector<int>> updates(n + 1);     while (r <= n) {       int id = lower_bound(v2.begin(), v2.end(), v[r]) - v2.begin();       if (!lm[id]) lm[id] = r;       int val = stm.query(l, lm[id]);       updates[id].push_back(r);       rm[id] = r;       ct[id]++;       visited.push_back(id);       if (rm[val] > lm[id] || ct[id] == 4) {         if (ct[id] == 4) {           for (int i = 0; i < 4; i++) ans.push_back(v[r]);         } else {           ans.push_back(v2[val]);           ans.push_back(v[r]);           ans.push_back(v2[val]);           ans.push_back(v[r]);         }         for (int i : visited) {           lm[i] = 0;           rm[i] = 0;           ct[i] = 0;           updates[i].clear();         }         visited.clear();         l = r + 1;         r = l;       } else {         for (int i : updates[id]) {           stm.modify(i, id);         }         r++;       }     }     cout << ans.size() <<   n ;     for (int i : ans) {       cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool get_int(T &x) {     char t = getchar();     bool neg = false;     x = 0;     for (; (t >  9  || t <  0 ) && t !=  -  && t != EOF; t = getchar())       ;     if (t ==  - ) neg = true, t = getchar();     if (t == EOF) return false;     for (; t <=  9  && t >=  0 ; t = getchar()) x = x * 10 + t -  0 ;     if (neg) x = -x;     return true;   }   template <typename T>   void print_int(T x) {     if (x < 0) putchar( - ), x = -x;     short a[20] = {}, sz = 0;     while (x > 0) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   const int inf = 0x3f3f3f3f;   const long long Linf = 1ll << 61;   const double pi = acos(-1.0);   const int mod = 1e9 + 7;   const int maxn = 100111;   int qpow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = (long long)ret * x % mod;       x = (long long)x * x % mod;       y >>= 1;     }     return ret;   }   int n, k, p[maxn];   long long cnt[maxn];   vector<int> divs[maxn * 2];   int main() {     (get_int(n) && get_int(k));     k = qpow(k, mod - 2);     p[0] = 1;     for (int i = 1; i <= n; i++) p[i] = (long long)p[i - 1] * k % mod;     for (int i = 1; i < n; i++)       for (int j = i; j < n * 2; j += i) divs[j].push_back(i);     for (int s = 1; s < n + n; s++) {       reverse(divs[s].begin(), divs[s].end());       vector<int> ansv;       for (auto g : divs[s]) {         int lb = g, rb = (n - 1) / g * g;         lb = max(lb, s - rb);         rb = min(rb, s - lb);         if (lb > rb)           ansv.push_back(0);         else           ansv.push_back((rb - lb) / g + 1);       }       for (int i = 0; i < (int)divs[s].size(); i++) {         for (int j = 0; j < i; j++)           if (divs[s][j] % divs[s][i] == 0) ansv[i] -= ansv[j];         int g = divs[s][i];         if (s - g <= n)           cnt[n - g] += ansv[i];         else           cnt[n + n - s] += ansv[i];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) ans = (ans + cnt[i] % mod * p[i]) % mod;     printf( %d n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     scanf( %d%d , &a, &b);     if (b > a)       printf( -1 n );     else {       double ans, a1, a2;       a1 = (a + b) / (2.0 * ((a + b) / (2 * b)));       a2 = (a - b) / (2.0 * ((a - b) / (2 * b)));       printf( %.12lf n , min(a1, a2));     }   }


#include <bits/stdc++.h>   using namespace std;   double esp = 1e-11;   const double PI = acos(-1.0);   const long long int INF = 0x3f3f3f3f;   const long long int MOD = 1e9 + 7;   const int maxn = 200010;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     long double x = (-b + sqrt((long double)b * b - 4 * a * c)) / (2 * a);     long double y = (-b - sqrt((long double)b * b - 4 * a * c)) / (2 * a);     if (x < y) swap(x, y);     printf( %.6f n%.6f n , (double)x, (double)y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int NMAX = 300010;   const double E = 1e-8;   const double PI = acos(-1);   int n, m, stest;   int d;   set<long long> St;   long long st[NMAX], h[NMAX];   pair<int, int> Tree[4 * NMAX];   int dp[NMAX], trace[NMAX];   pair<int, int> cmp(pair<int, int> a, pair<int, int> b) {     if (a.first > b.first)       return a;     else       return b;   }   void update(int i, int lo, int hi, int u, int x, int vt) {     if (lo == hi) {       Tree[i] = cmp(Tree[i], pair<int, int>(x, vt));       return;     }     int mid = (lo + hi) >> 1;     if (u <= mid)       update(2 * i, lo, mid, u, x, vt);     else       update(2 * i + 1, mid + 1, hi, u, x, vt);     Tree[i] = cmp(Tree[2 * i], Tree[2 * i + 1]);   }   pair<int, int> query(int i, int lo, int hi, int u, int v) {     if (v < lo || hi < u) return pair<int, int>(0, 0);     if (u <= lo && hi <= v) return Tree[i];     int mid = (lo + hi) >> 1;     return cmp(query(2 * i, lo, mid, u, v), query(2 * i + 1, mid + 1, hi, u, v));   }   void truy(int x) {     if (x == 0) return;     truy(trace[x]);     cout << x <<    ;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> d;     for (int i = 1; i <= n; i++) {       cin >> h[i];       St.insert(h[i]);       St.insert(h[i] - d);       St.insert(h[i] + d);     }     for (set<long long>::iterator it = St.begin(); it != St.end(); it++)       st[++m] = *it;     int ans = 0, vt = 0;     for (int i = 1; i <= n; i++) {       int pos = lower_bound(st + 1, st + m + 1, h[i]) - st;       int u = lower_bound(st + 1, st + m + 1, h[i] - d) - st;       int v = lower_bound(st + 1, st + m + 1, h[i] + d) - st;       pair<int, int> res = cmp(query(1, 1, m, 1, u), query(1, 1, m, v, m));       dp[i] = res.first + 1;       trace[i] = res.second;       update(1, 1, m, pos, dp[i], i);       if (dp[i] > ans) {         ans = dp[i];         vt = i;       }     }     cout << ans << endl;     truy(vt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MXN = 3e5 + 5;   const int MOD = 998244353;   const int LOG = 19;   int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; }   int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; }   int mul(int x, int y) { return (ll)x * y % MOD; }   int pwr(int x, int p) {     if (p == 0) return 1;     if (p % 2) return mul(x, pwr(x, p - 1));     return pwr(mul(x, x), p / 2);   }   int inv(int x) { return pwr(x, MOD - 2); }   int sol = 1;   int ok[MXN];   int val[MXN];   int dep[MXN];   int lca[MXN];   int nxt[MXN];   int dp[MXN][2];   int anc[MXN][LOG];   vector<int> adj[MXN];   int getlca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int diff = dep[x] - dep[y];     for (int i = 0; i < LOG; ++i) {       if (diff >> i & 1) x = anc[x][i];     }     if (x == y) return x;     for (int i = LOG - 1; i >= 0; --i) {       if (anc[x][i] != anc[y][i]) {         x = anc[x][i];         y = anc[y][i];       }     }     return anc[x][0];   }   void dfs1(int x, int p) {     if (val[x]) {       if (lca[val[x]]) {         lca[val[x]] = getlca(lca[val[x]], x);       } else {         lca[val[x]] = x;       }     }     for (int y : adj[x]) {       if (y == p) continue;       anc[y][0] = x;       dep[y] = dep[x] + 1;       for (int i = 0; i < LOG - 1; ++i) {         anc[y][i + 1] = anc[anc[y][i]][i];       }       dfs1(y, x);     }   }   void dfs2(int x, int p) {     vector<int> vec;     for (int y : adj[x]) {       if (y == p) continue;       dfs2(y, x);       if (ok[y]) {         ok[x] = 1;         vec.push_back(y);       }       if (val[y] && y != lca[val[y]]) {         if (val[x] && val[x] != val[y]) {           cout <<  0 n ;           exit(0);         }         val[x] = val[y];       }     }     if (val[x]) {       dp[x][0] = ok[x] = 1;       for (int y : vec) {         sol = mul(sol, add(mul(dp[y][0], nxt[y] + 1), dp[y][1]));       }     } else if (vec.size() > 1) {       dp[x][1] = 1;       for (int y : vec) {         int tmp = add(dp[y][1], mul(dp[y][0], nxt[y] + 1));         dp[x][1] = mul(dp[x][1], tmp);       }       for (int y : vec) {         int tmp = add(dp[y][1], mul(dp[y][0], nxt[y] + 1));         dp[x][0] = add(dp[x][0], mul(mul(dp[x][1], inv(tmp)), dp[y][0]));       }     } else if (vec.size() == 1) {       dp[x][0] = dp[vec[0]][0];       dp[x][1] = dp[vec[0]][1];       nxt[x] = nxt[vec[0]] + 1;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> val[i];     }     for (int i = 2; i <= n; ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs1(1, 0);     dfs2(1, 0);     if (dp[1][0]) sol = mul(sol, dp[1][0]);     cout << sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int l[100000 + 9], r[100000 + 9];   int n, p;   int main() {     cin >> n >> p;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     double ans = 0;     for (int i = 0; i < n; i++) {       int j = (i + 1) % n;       int div1 = r[i] / p - (l[i] - 1) / p;       int nondiv1 = r[i] - l[i] + 1 - div1;       int div2 = r[j] / p - (l[j] - 1) / p;       int nondiv2 = r[j] - l[j] + 1 - div2;       double nondivs = 1.0 - ((double)nondiv1 / double(r[i] - l[i] + 1)) *                                  ((double)nondiv2 / double(r[j] - l[j] + 1));       ans += nondivs * 2000.0;     }     cout << fixed << setprecision(15) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s, t;     cin >> s >> t;     int ns = s.size() - 1;     int nt = t.size() - 1;     bool stop = true;     while (stop && (ns >= 0 && nt >= 0)) {       if (s[ns] != t[nt]) {         stop = false;       }       if (stop) {         ns--;         nt--;       }     }     int r = ns + nt + 2;     cout << r;     return 0;   }