#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vll = vector<ll>;   using vvll = vector<vll>;   using vb = vector<bool>;   using vd = vector<double>;   using vs = vector<string>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pdd = pair<double, double>;   using vpii = vector<pii>;   using vvpii = vector<vpii>;   using vpll = vector<pll>;   using vvpll = vector<vpll>;   using vpdd = vector<pdd>;   using vvpdd = vector<vpdd>;   template <typename T>   void ckmin(T& a, const T& b) {     a = min(a, b);   }   template <typename T>   void ckmax(T& a, const T& b) {     a = max(a, b);   }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   namespace __input {   template <class T1, class T2>   void re(pair<T1, T2>& p);   template <class T>   void re(vector<T>& a);   template <class T, size_t SZ>   void re(array<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(double& x) {     string t;     re(t);     x = stod(t);   }   template <class Arg, class... Args>   void re(Arg& first, Args&... rest) {     re(first);     re(rest...);   }   template <class T1, class T2>   void re(pair<T1, T2>& p) {     re(p.first, p.second);   }   template <class T>   void re(vector<T>& a) {     for (int i = 0; i < (int((a).size())); i++) re(a[i]);   }   template <class T, size_t SZ>   void re(array<T, SZ>& a) {     for (int i = 0; i < (SZ); i++) re(a[i]);   }   }  // namespace __input   using namespace __input;   namespace __output {   template <class T1, class T2>   void pr(const pair<T1, T2>& x);   template <class T, size_t SZ>   void pr(const array<T, SZ>& x);   template <class T>   void pr(const vector<T>& x);   template <class T>   void pr(const set<T>& x);   template <class T1, class T2>   void pr(const map<T1, T2>& x);   template <class T>   void pr(const T& x) {     cout << x;   }   template <class Arg, class... Args>   void pr(const Arg& first, const Args&... rest) {     pr(first);     pr(rest...);   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x) {     pr( { , x.first,  ,  , x.second,  } );   }   template <class T, bool pretty = true>   void prContain(const T& x) {     if (pretty) pr( { );     bool fst = 1;     for (const auto& a : x) pr(!fst ? pretty ?  ,   :     :   , a), fst = 0;     if (pretty) pr( } );   }   template <class T>   void pc(const T& x) {     prContain<T, false>(x);     pr(  n );   }   template <class T, size_t SZ>   void pr(const array<T, SZ>& x) {     prContain(x);   }   template <class T>   void pr(const vector<T>& x) {     prContain(x);   }   template <class T>   void pr(const set<T>& x) {     prContain(x);   }   template <class T1, class T2>   void pr(const map<T1, T2>& x) {     prContain(x);   }   void ps() { pr(  n ); }   template <class Arg>   void ps(const Arg& first) {     pr(first);     ps();   }   template <class Arg, class... Args>   void ps(const Arg& first, const Args&... rest) {     pr(first,    );     ps(rest...);   }   }  // namespace __output   using namespace __output;   namespace __algorithm {   template <typename T>   void dedup(vector<T>& v) {     sort((v).begin(), (v).end());     v.erase(unique((v).begin(), (v).end()), v.end());   }   template <typename T>   typename vector<T>::iterator find(vector<T>& v, const T& x) {     auto it = lower_bound((v).begin(), (v).end(), x);     return it != v.end() && *it == x ? it : v.end();   }   template <typename T>   size_t index(vector<T>& v, const T& x) {     auto it = find(v, x);     assert(it != v.end() && *it == x);     return it - v.begin();   }   template <typename C, typename T, typename OP>   vector<T> prefixes(const C& v, T id, OP op) {     vector<T> r(int((v).size()) + 1, id);     for (int i = 0; i < (int((v).size())); i++) r[i + 1] = op(r[i], v[i]);     return r;   }   template <typename C, typename T, typename OP>   vector<T> suffixes(const C& v, T id, OP op) {     vector<T> r(int((v).size()) + 1, id);     for (int i = (int((v).size())) - 1; i >= 0; i--) r[i] = op(v[i], r[i + 1]);     return r;   }   }  // namespace __algorithm   using namespace __algorithm;   struct monostate {     friend istream& operator>>(istream& is,                                const __attribute__((unused)) monostate& ms) {       return is;     }     friend ostream& operator<<(ostream& os,                                const __attribute__((unused)) monostate& ms) {       return os;     }   } ms;   template <typename W = monostate>   struct wedge {     int u, v, i;     W w;     wedge<W>(int _u = -1, int _v = -1, int _i = -1) : u(_u), v(_v), i(_i) {}     int operator[](int loc) const { return u ^ v ^ loc; }     friend void re(wedge& e) {       re(e.u, e.v, e.w);       --e.u, --e.v;     }     friend void pr(const wedge& e) { pr(e.u,  <- , e.w,  -> , e.v); }   };   namespace __io {   void setIn(string second) { freopen(second.c_str(),  r , stdin); }   void setOut(string second) { freopen(second.c_str(),  w , stdout); }   void setIO(string second =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed;     cout.precision(15);     if (int((second).size())) {       setIn(second +  .in ), setOut(second +  .out );     }   }   }  // namespace __io   using namespace __io;   template <typename E>   struct tree {     int V;     vector<E> edges;     vector<vector<E>> adj;     vi subt_sz;     vb erased;     tree() {}     tree(int _V) : V(_V) {       edges.resize(V - 1);       adj.resize(V), subt_sz.resize(V), erased.resize(V);     }     tree(const vector<E>& __edges) : tree(int((__edges).size()) + 1) {       edges = __edges;       init();     }     void init() {       for (int i = 0; i < (int((edges).size())); i++) {         auto& e = edges[i];         e.i = i;         assert(0 <= e.u && e.u < V && 0 <= e.v && e.v < V);         adj[e.u].push_back(e);         adj[e.v].push_back(e);       }     }     friend void re(tree& t) {       re(t.edges);       t.init();     }     friend void pr(const tree& t) { pr( {V= , t.V,    , t.edges,  } ); }     void erase(int v) { erased[v] = true; }     void calc_subt_sz(int v, int p = -1) {       subt_sz[v] = 1;       for (auto& e : adj[v])         if (int u = e[v]; !erased[u] && u != p) {           calc_subt_sz(u, v);           subt_sz[v] += subt_sz[u];         }     }     int centroid(int v) {       calc_subt_sz(v);       int c = v;     FIND:       for (auto& e : adj[c])         if (int u = e[c]; !erased[u]) {           if (subt_sz[u] < subt_sz[c] && 2 * subt_sz[u] >= subt_sz[v]) {             c = u;             goto FIND;           }         }       return c;     }   };   using E = wedge<int>;   tree<E> tr;   vi w;   vd tot, der;   void go(int r, int v, int p = -1, double d = 0.) {     double tmp = w[v] * sqrt(d);     tot[r] += tmp * d;     der[r] += tmp;     for (auto& e : tr.adj[v])       if (e[v] != p) {         go(r, e[v], v, d + e.w);       }   }   pair<double, int> best = {DBL_MAX, -1};   void solve(int v) {     v = tr.centroid(v);     double cd = 0.;     pair<double, int> n{0., -1};     for (auto& e : tr.adj[v]) {       int u = e[v];       tot[u] = der[u] = 0.;       go(u, u, v, e.w);       cd += tot[u];       ckmax(n, make_pair(der[u], u));     }     ckmin(best, make_pair(cd, v + 1));     tr.erase(v);     if (n.second != -1 && !tr.erased[n.second]) solve(n.second);   }   int main() {     setIO();     int N;     re(N);     w.resize(N);     re(w);     tr = tree<E>(N);     re(tr);     tot.resize(N), der.resize(N);     solve(0);     ps(best.second, best.first);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc, i, j, k, cs = 1, m, n, ans;     {       scanf( %d%d , &m, &n);       if (n > m) swap(m, n);       if (n == 1)         ans = m;       else if (n == 2) {         ans = (m / 4) * 4;         if (m % 4 == 1)           ans += 2;         else if (m % 4 == 2)           ans += 4;         else if (m % 4 == 3)           ans += 4;       } else {         ans = ((m + 1) / 2) * ((n + 1) / 2);         ans += (m / 2) * (n / 2);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long dp[210][210];   struct point {     long long x, y;     void read() { scanf( %I64d%I64d , &x, &y); }   } P[210];   long long cross(point a, point b, point c) {     return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);   }   int main() {     long long s = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) P[i].read();     P[n + 1] = P[1];     for (int i = 2; i <= n; i++) s += cross(P[1], P[i], P[i + 1]);     if (s > 0)       for (int i = 1; i <= n / 2; i++) swap(P[i], P[n - i + 1]);     for (int i = 1; i < n; i++) dp[i][i + 1] = 1;     for (int i = 2; i < n; i++)       for (int j = 1; j <= n - i; j++)         for (int k = j + 1; k < i + j; k++)           if (cross(P[j], P[i + j], P[k]) > 0)             dp[j][i + j] = (dp[j][i + j] + dp[j][k] * dp[k][i + j]) % 1000000007;     printf( %I64d , dp[1][n]);   }


#include <bits/stdc++.h>   using namespace std;   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long gcd(long long x, long long y) {     while (y) {       long long t = x % y;       x = y;       y = t;     }     return x;   }   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   unsigned int read() {     unsigned int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m;   int fst[1010], vv[400100], nxt[400100], e;   int col[1010], vis[1010];   void add(int u, int v) {     vv[e] = v, nxt[e] = fst[u], fst[u] = e++;     vv[e] = u, nxt[e] = fst[v], fst[v] = e++;   }   void init() {     e = 0;     memset(fst, -1, sizeof fst);   }   bool color(int u, int o) {     vis[u] = o;     int res = 1;     for (int i = fst[u]; ~i; i = nxt[i]) {       int v = vv[i];       if (vis[v] == o) {         if (col[v] == col[u]) res = 0;         continue;       }       col[v] = col[u] ^ 1;       if (!color(v, o)) res = 0;     }     return res;   }   int ans[1010], d[1010];   int main() {     init();     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int u = read(), v = read();       add(u, v);     }     int bit = 1, tot = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         if (!color(i, ++tot)) {           bit = 0;           break;         }       }     }     if (!bit) {       puts( -1 );       return 0;     }     for (int i = 1; i <= n; i++)       if (vis[i] > 0) {         memset(d, 0, sizeof d);         queue<int> q;         q.push(i);         d[i] = 1;         while (!q.empty()) {           int u = q.front();           q.pop();           chkmax(ans[vis[i]], d[u] - 1);           for (int i = fst[u]; ~i; i = nxt[i]) {             int v = vv[i];             if (d[v]) continue;             d[v] = d[u] + 1;             q.push(v);           }         }         vis[i] = 0;       }     for (int i = 1; i <= tot; i++) ans[0] += ans[i];     printf( %d n , ans[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int q = 0; q < t; q++) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       int moves = 0;       int max_size = 0;       int alice = 0, bob = 0;       while (a.size() != 0) {         moves++;         int curr_size = 0;         if (moves % 2 == 1) {           while (curr_size <= max_size) {             curr_size += a[0];             alice += a[0];             a.erase(a.begin());             if (a.size() == 0) break;           }         }         if (moves % 2 == 0) {           while (curr_size <= max_size) {             curr_size += a[(int)a.size() - 1];             bob += a[(int)a.size() - 1];             a.erase(a.begin() + (int)a.size() - 1);             if (a.size() == 0) break;           }         }         max_size = max(max_size, curr_size);       }       cout << moves <<     << alice <<     << bob <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chkmin(T &a, T const &b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   inline bool chkmax(T &a, T const &b) {     return a < b ? a = b, 1 : 0;   }   const int M = 35;   const int N = 205;   const int Mod = 998244353;   long long A[M], a[M][M * N];   vector<int> F[M][M * N];   int Sz[M], C[N][N], S[M * N], Inv[N];   int n;   int calc(vector<int> &P, long long l, long long r) {     int res = 0, x = 1, y = 1;     l = l % Mod * 616898040 % Mod;     r = r % Mod * 616898040 % Mod;     for (int i = (0), i_end__ = (P.size()); i < i_end__; i++) {       res = (res + (long long)(y - x) * P[i]) % Mod;       x = ((long long)(x) * (l) % Mod), y = ((long long)(y) * (r) % Mod);     }     return res;   }   int main() {     for (int i = (0), i_end__ = (N); i < i_end__; i++) {       C[i][0] = 1;       for (int j = (1), j_end__ = (i + 1); j < j_end__; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;     }     Inv[1] = 1;     for (int i = (2), i_end__ = (N); i < i_end__; i++)       Inv[i] = ((long long)(-Mod / i) * (Inv[Mod % i]) % Mod);     scanf( %d , &n);     for (int i = (0), i_end__ = (n); i < i_end__; i++) {       double x;       scanf( %lf , &x);       A[i] = min(x, i + 1.0) * 1000000 + 0.5;     }     Sz[0] = 2;     F[0][1].push_back(0), F[0][1].push_back(1);     F[0][2].push_back(0);     a[0][1] = A[0];     for (int i = (1), i_end__ = (n); i < i_end__; i++) {       for (int j = (1), j_end__ = (Sz[i - 1]); j < j_end__; j++)         S[j] = (S[j - 1] + calc(F[i - 1][j], a[i - 1][j - 1], a[i - 1][j])) % Mod;       int pos = lower_bound(a[i - 1], a[i - 1] + Sz[i - 1], A[i]) - a[i - 1];       a[i - 1][pos] = A[i];       a[i - 1][pos + 1] = 0x3f3f3f3f3f3f3f3fLL;       F[i][0].push_back(0), Sz[i] = 1;       int l = 0, r = 1;       long long lp = -1000000, rp = 0;       while (r <= pos) {         long long Next = min(a[i - 1][l] - lp, a[i - 1][r] - rp);         a[i][Sz[i]] = rp + Next;         vector<int> &poy = F[i][Sz[i]];         poy.resize(max(F[i - 1][r].size(), F[i - 1][l].size()) + 1);         poy[1] = (calc(F[i - 1][l], 0, a[i - 1][l]) -                   calc(F[i - 1][r], 0, a[i - 1][r - 1])) %                  Mod;         if (l < r) poy[1] = ((long long)poy[1] + S[r - 1] - S[l]) % Mod;         for (int j = (0), j_end__ = (F[i - 1][r].size()); j < j_end__; j++)           poy[j + 1] = (poy[j + 1] + F[i - 1][r][j]) % Mod;         for (int j = (1), j_end__ = (F[i - 1][l].size()); j < j_end__; j++)           for (int k = (0), k_end__ = (j + 1); k < k_end__; k++)             poy[k + 1] = (poy[k + 1] +                           ((j - k) & 1 ? 1LL : -1LL) * C[j][k] * F[i - 1][l][j]) %                          Mod;         for (int j = (1), j_end__ = (poy.size()); j < j_end__; j++)           poy[j] = ((long long)(poy[j]) * (Inv[j]) % Mod);         if ((lp += Next) == a[i - 1][l]) l++;         if ((rp += Next) == a[i - 1][r]) r++;         Sz[i]++;       }       F[i][Sz[i]].push_back(0);     }     int ans = 0;     for (int j = (1), j_end__ = (Sz[n - 1]); j < j_end__; j++)       (ans += calc(F[n - 1][j], a[n - 1][j - 1], a[n - 1][j])) %= Mod;     printf( %d n , (ans + Mod) % Mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct T {     long long nu, p;     bool operator<(const T& o) const {       if (nu > o.nu) return true;       if (nu == o.nu && p > o.p) return true;       return false;     }   };   long long n, k, m;   T plazas[111111];   long long sum[111111];   long long donde[111111];   int main() {     cin >> n >> k >> m;     for (int i = 0; i < n; i++) cin >> plazas[i].nu, plazas[i].p = i;     n--;     sort(plazas, plazas + n);     for (int i = 0; i < n; i++) {       donde[plazas[i].p] = i;       sum[i] = plazas[i].nu;       if (i) sum[i] += sum[i - 1];     }     if (sum[n - 1] <= m)       cout << n + 1;     else {       bool ok = false;       long long ss = 0, tt;       ss = sum[k - 1];       if (ss <= m)         cout << n + 1;       else {         ss = 0;         if (k > 1) ss = sum[k - 2];         for (int i = 0; i < n && !ok; i++) {           long long p = donde[i];           long long tss = ss;           if (p < k - 2)             tss += plazas[k - 1].nu;           else             tss += plazas[p].nu;           if (tss > m) {             ok = true;             cout << i + 1;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const double inf = 1e9;   int n, m, x[N], b[N], pre[N];   double dp[N];   bool check(double mid) {     for (int i = 1; i <= n; i++) dp[i] = inf;     for (int i = 0; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         double tmp = dp[i] + sqrt(abs(x[j] - x[i] - m)) - 1.0 * mid * b[j];         if (dp[j] > tmp) {           dp[j] = tmp;           pre[j] = i;         }       }     }     return dp[n] >= 0;   }   void prnt(int x) {     if (x == 0) return;     prnt(pre[x]);     printf( %d  , x);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &b[i]);     double l = 0.0, r = 1e5;     while (r - l > 1e-8) {       double mid = (l + r) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     prnt(n);     return printf(  n ), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long a, b, c, d, e, i, j, k, l;       cin >> a >> b;       if (a <= b)         cout << abs(a - b) << endl;       else if (a % 2 + b % 2 == 1)         cout << 1 << endl;       else         cout << 0 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[200001];   long long search(long long l, long long h, long long target) {     if (h - l <= 1) {       if (a[l] > target)         return l;       else         return h;     }     long long mid = (l + h) / 2;     if (a[mid] > target)       return search(l, mid, target);     else       return search(mid + 1, h, target);   }   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < N; i++) {       cin >> a[i];     }     sort(a, a + N);     for (int j = 0; j < M; j++) {       int b;       cin >> b;       if (a[N - 1] > b) {         cout << search(0, N - 1, b) <<    ;       } else {         cout << N <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, nn;     cin >> n;     nn = n * 2;     vector<int> arr(nn);     for (int i = 0; i < nn; ++i) cin >> arr[i];     sort(arr.begin(), arr.end());     long long ans, now;     ans = arr[nn - 1] - arr[n];     ans *= arr[n - 1] - arr[0];     for (int i = 1; i < n; ++i) {       now = arr[n - 1 + i] - arr[i];       now *= arr[nn - 1] - arr[0];       ans = min(ans, now);     }     cout << ans;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = (1LL << 62);   const int inf = (1 << 30);   const long long nmax = 5e5 + 50;   const int mod = 1e9 + 7;   using namespace std;   int n, m, i, x, a[nmax], p[nmax], q, st[4 * nmax], ans[nmax], j;   long long nr[nmax], k;   vector<int> b[nmax];   vector<pair<int, int> > qr[nmax];   pair<int, int> pr;   pair<int, int> fnd(long long y) {     int l = 0, r = n, mid, rs = n, i;     while (l <= r) {       mid = (l + r) / 2;       if (nr[mid] > y)         rs = mid, r = mid - 1;       else         l = mid + 1;     }     for (i = max(rs - 1, 0); i <= min(rs + 1, n); i++)       if (nr[i] >= y) break;     rs = i;     if (rs <= n) {       if (rs) y -= nr[rs - 1];       return make_pair(rs, y);     } else {       y -= nr[n];       if (y % m == 0) return make_pair(m, -1);       return make_pair(y % m, -1);     }   }   void upd(int nod, int l, int r, int p) {     if (l == r) {       st[nod] = 1;       return;     }     int mid = (l + r) / 2;     if (p <= mid)       upd(2 * nod, l, mid, p);     else       upd(2 * nod + 1, mid + 1, r, p);     st[nod] = st[2 * nod] + st[2 * nod + 1];   }   int qry(int nod, int l, int r, int z) {     if (z > st[nod]) return -1;     if (l == r) return l;     int mid = (l + r) / 2;     if (st[nod * 2] >= z) return qry(2 * nod, l, mid, z);     return qry(2 * nod + 1, mid + 1, r, z - st[nod * 2]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (i = 1; i <= n; i++) {       cin >> x;       a[x]++;     }     for (i = 1; i <= m; i++) {       nr[a[i]]++;       b[a[i]].push_back(i);     }     p[0] = b[0].size();     for (i = 1; i <= n; i++) p[i] = p[i - 1] + b[i].size();     for (i = 1; i <= n; i++) nr[i] += nr[i - 1];     for (i = 1; i <= n; i++) nr[i] += nr[i - 1];     for (i = 1; i <= q; i++) {       cin >> k;       k -= n;       pr = fnd(k);       if (pr.second == -1)         ans[i] = pr.first;       else         qr[pr.first].push_back(make_pair(pr.second, i));     }     for (i = 0; i <= n; i++) {       for (j = 0; j < b[i].size(); j++) upd(1, 1, m, b[i][j]);       for (j = 0; j < qr[i].size(); j++)         ans[qr[i][j].second] = qry(1, 1, m, qr[i][j].first);     }     for (i = 1; i <= q; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100, L = 18;   int n, m, Q;   int dep[N], p[N][L];   set<int> adj[N];   map<int, int> mp[N];   int get(int par, int i) {     if (mp[par][i] == i) return i;     return mp[par][i] = get(par, mp[par][i]);   }   void mrg(int par, int u, int v) {     u = get(par, u);     v = get(par, v);     if (u == v) return;     if (rand() & 1) swap(u, v);     mp[par][u] = mp[par][v];   }   int LCA(int u, int v) {     if (u == v) return 0;     int u0 = u, v0 = v;     if (dep[u] < dep[v]) swap(u, v);     int k = dep[u] - dep[v];     for (int i = 0; i < L; i++)       if (k & (1 << i)) u = p[u][i];     if (u == v) return k;     for (int i = L - 1; i >= 0; i--)       if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];     int ret = dep[u0] + dep[v0] - 2 * dep[p[u][0]];     int par = p[u][0];     if (get(par, u) == get(par, v)) ret--;     return ret;   }   int main() {     srand(time(0));     scanf( %d %d %d , &n, &m, &Q);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].insert(v);       adj[v].insert(u);     }     queue<int> q;     q.push(1);     dep[1] = 1;     p[1][0] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto v : adj[u]) mp[u][v] = v;       for (auto v : adj[u]) {         if (p[u][0] == v) continue;         if (dep[v]) {           mrg(p[u][0], u, v);           continue;         }         dep[v] = 1 + dep[u];         p[v][0] = u;         for (int i = 1; i < L; i++) p[v][i] = p[p[v][i - 1]][i - 1];         q.push(v);       }     }     while (Q--) {       int u, v;       scanf( %d %d , &u, &v);       printf( %d n , LCA(u, v));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200000], dp[600000];   int main() {     int n, l;     cin >> n >> l;     for (int i = 1; i <= n; i++) {       double x;       cin >> a[i] >> x;     }     int maxx = -1;     for (int i = 1; i <= n; i++) {       dp[i] = 1;       for (int j = 1; j < i; j++) {         if (a[i] >= a[j]) dp[i] = max(dp[i], dp[j] + 1);         maxx = max(maxx, dp[i]);       }     }     if (n == 1)       cout << 0 << endl;     else       cout << n - maxx << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int j, i, k, n, m, x;     float d[6000], a[5008], b[5009];     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> a[i] >> b[i];       d[i] = (float)(1.0 * a[i]) / b[i];     }     sort(d, d + n);     printf( %.8f , d[0] * m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a, b, c;     cin >> a >> b >> c;     a *= 10;     long long q = 0;     for (long long j = 0; j <= 9; j++) {       a += j;       if (a % b == 0) {         q = 1;         break;       } else         a -= j;     }     if (q == 0) {       cout << -1 << endl;       return 0;     }     cout << a;     for (long long i = 0; i < c - 1; i++) cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     stack<int> s;     int ans = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       while (!s.empty()) {         ans = max(ans, s.top() ^ x);         if (x > s.top()) {           s.pop();         } else {           break;         }       }       s.push(x);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   int n, d;   const int geta = 260;   const int MX = 30000;   int dp[30010][520];   int cnt[30010];   int main() {     scanf( %d %d , &n, &d);     for (int i = 0; i < n; i++) {       int k;       scanf( %d , &k);       cnt[k]++;     }     memset(dp, -1, sizeof(dp));     dp[d][geta] = cnt[d];     int ans = 0;     for (int i = d; i <= MX; i++) {       for (int j = 0; j < 520; j++) {         if (dp[i][j] == -1) continue;         chmax(ans, dp[i][j]);         int len = d + (j - geta);         if (len > 1 && i + len - 1 <= MX)           chmax(dp[i + len - 1][j - 1], dp[i][j] + cnt[i + len - 1]);         if (i + len <= MX) chmax(dp[i + len][j], dp[i][j] + cnt[i + len]);         if (i + len + 1 <= MX)           chmax(dp[i + len + 1][j + 1], dp[i][j] + cnt[i + len + 1]);       }     }     printf( %d n , ans);     return 0;   }


//            __                         //   _______ / _|_   _ _ __ _   _ ___    //  |_  / _  |_| | | |  __| | | / __|   created on   //   / /  __/  _| |_| | |  | |_|  __    18 Mar 2021 00:06:00   //  /___ ___|_|   __, |_|    __,_|___/   //               |___/                      #include<bits/stdc++.h>      using namespace std;   #define int long long      #define deb(...) cerr <<  [  << #__VA_ARGS__ <<  ] : [ , DBG(__VA_ARGS__)   void DBG() { cerr <<  ] n ;}   template<typename T, typename ...Args> void DBG(T first, Args... args)   {cerr << first; if(sizeof...(args))cerr<< ,  ; DBG(args...); }      class Math{    private:     int size;     std::vector<int> prime,spf,square_of_a_prime;    public:       Math(int size_):size(size_){     /* prime.resize(size); */     spf.resize(size);     /* square_of_a_prime.resize(size); */    }       std::vector<int> seive(){     for(int i=2;i<size;i++)prime[i]=1;     for(int i=2;i<size;i++){      if(prime[i]){       if(i*i<size)square_of_a_prime[i*i]=1;       for(int j=2;j<size;j++){        if(i*j<size) prime[i*j]=0;        else break;       }      }     }     return prime;    }       void smallest_prime_factor(){     spf.assign(size,-1);     spf[1]=1;     for(int i=2; i<size; i++){      if(spf[i]==-1){       spf[i] = i;       for(int j = 2; j*i<size; j++){        if(spf[i*j]==-1){         spf[i*j] = i;        }       }      }     }    }        int SPF(int x){     return spf[x];    }       int count_no_of_factors(int x){       // complexity is O(n^1/3)...     seive();     int ans = 1;     for(int i=0;i<size;i++){      if(prime[i]){       if(i*i*i > x)break;       int count = 1;       while(x%i==0){        count++;        x/=i;       }       ans *= count;      }     }     if(prime[x])ans*=2;     else if(square_of_a_prime[x])ans*=3;     else if(x!=1)ans*=4;     return ans;    }       std::vector<int> prime_factorize(int x){     // complexity is O(n^1/2)     std::vector<int> ff(size,0);     while(x%2==0){      ff[2]++;      x/=2;     }     for(int i=3;i*i<=x;i+=2){      while(x%i==0){       ff[i]++;       x/=i;      }     }     if(x>2)ff[x]++;     return ff;    }       std::vector<int> prime_factorize_using_seive(int x){     smallest_prime_factor();     std::vector<int> ff(size,0);     while(x!=1){      ff[spf[x]]++;      x/=spf[x];     }     return ff;    }       int phi(int n){     int result = n;     for(int i=2; i*i<=n; i++){      if (n%i==0) {       while(n%i==0) n/=i;       result-=result/i;      }     }     if (n>1) result-=result/n;     return result;    }       std::vector<int> phi_1_to_n(int n){       std::vector<int> phi(n+1);       phi[0] = 0; phi[1] = 1;       for (int i=2; i<=n; i++) phi[i]=i;          for (int i = 2; i <= n; i++) {      if (phi[i]==i) {       for (int j=i; j<=n; j+=i)        phi[j] -= phi[j]/i;      }       }     return phi;    }   };         int32_t main(){     ios_base:: sync_with_stdio(false);     cin.tie(0);     int t=1;     cin >> t;        Math m((int)1e7);    m.smallest_prime_factor();           for(int tt=1;tt<=t;tt++){     int ans= 0;       int n; cin >> n;       int k; cin >> k;          map<int,int> f;          for(int i=0;i<n;i++){         int x; cin >> x;         int y=1;      map<int,int> used;         while(x!=1){           int num = m.SPF(x);           while(x%num==0){             x/=num;        used[num]++;           }         }      for(auto ele : used){       if(ele.second&1) y*=ele.first;      }         if(f.count(y)){           ans++;           f.clear();       f[y]++;         }         else{           f[y]++;         }       }     cout << ans+1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   deque<int> check(deque<int> mas) {     int l = 0, r = mas.size() - 1;     bool flag = true;     for (; l < mas.size() / 2; l++, r--) {       if (mas[r] < 0) {         mas[r - 1]--;         mas[r] += 10;       }       if (mas[l] == mas[r] + 1 && l != r - 1) {         mas[l + 1] += 10;         mas[l]--;       }       if (mas[l] == mas[r] + 10 && l != r - 1) {         mas[r - 1]--;         mas[r] += 10;       }       if (mas[l] == mas[r] + 11) {         mas[l]--;         mas[l + 1] += 10;         if (l != r - 1) {           mas[r] += 10;           mas[r - 1]--;         }       }       if (mas[l] != mas[r]) {         flag = false;         break;       }       if (mas[l] > 18) {         flag = false;         break;       }     }     if (flag == false || mas[0] == 0 || mas[mas.size() - 1] == 0) {       deque<int> ans;       ans.push_back(0);       return ans;     } else {       if (mas.size() % 2 == 1 && (mas[l] % 2 == 1 || mas[l] < 0)) {         deque<int> ans;         ans.push_back(0);         return ans;       } else {         deque<int> ans = mas;         l = 0;         r = mas.size() - 1;         for (; l < mas.size() / 2; l++, r--) {           ans[l] = mas[l] - mas[l] / 2;           ans[r] = mas[l] - ans[l];         }         if (mas.size() % 2 == 1) {           ans[l] = mas[l] / 2;         }         return ans;       }     }   }   int main() {     deque<int> x1;     char c;     while (cin >> c) x1.push_back(int(c) - int( 0 ));     deque<int> x2 = x1;     if (x2.size() >= 2) {       x2[1] += x2[0] * 10;       x2.pop_front();     }     deque<int> ans1 = check(x1);     deque<int> ans2 = check(x2);     if (ans1.size() > ans2.size()) {       for (int i = 0; i < ans1.size(); i++) cout << ans1[i];     } else {       for (int i = 0; i < ans2.size(); i++) cout << ans2[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long fac[1100000], inv[1100000], p[1100000];   long long pow_mod(long long a, long long b, long long m) {     long long ans = 1LL;     a %= m;     while (b) {       if (b & 1) ans = ans * a % m;       a = a * a % m;       b >>= 1;     }     return ans;   }   int main() {     fac[0] = 1LL;     inv[0] = pow_mod(fac[0], MOD - 2, MOD);     for (long long i = 1; i <= 1010000; ++i) {       fac[i] = i * fac[i - 1] % MOD;       inv[i] = pow_mod(fac[i], MOD - 2, MOD);     }     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= k + 2; ++i) {       p[i] = p[i - 1] + pow_mod(i, k, MOD);       p[i] %= MOD;     }     if (n <= k + 2) {       cout << p[n] << endl;       return 0;     }     long long x = 1LL;     for (int i = 1; i <= k + 2; ++i) {       x *= (n - i);       x %= MOD;     }     long long ans = 0LL, flag;     for (int i = 1; i <= k + 2; ++i) {       if ((k + 2 - i) & 1)         flag = -1;       else         flag = 1;       ans += x * flag * pow_mod(n - i, MOD - 2, MOD) % MOD * inv[i - 1] % MOD *              inv[k + 2 - i] % MOD * p[i];       (ans += MOD) %= MOD;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int readInt() {     static int n, ch;     n = 0, ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) n = n * 10 + ch -  0 , ch = getchar();     return n;   }   const int MAX_N = 500000 + 3;   int n, k, a[MAX_N], b[MAX_N];   struct Data {     long long val;     bool isA;     Data(long long val, bool isA) : val(val), isA(isA) {}     bool operator<(const Data &ano) const {       return val > ano.val || (val == ano.val && isA < ano.isA);     }   };   priority_queue<Data> pq;   long long sum = 0;   int check(int t) {     while (!pq.empty()) pq.pop();     int cnt = 0;     sum = 0;     for (int i = 0; i < n; ++i) {       pq.push(Data(a[i] - t, true));       if (pq.top().val + b[i] < 0) {         cnt += pq.top().isA;         sum += pq.top().val + b[i];         pq.pop();         pq.push(Data(-b[i], false));       }     }     return cnt;   }   int main() {     n = readInt(), k = readInt();     for (int i = 0; i < n; ++i) a[i] = readInt();     for (int i = 0; i < n; ++i) b[i] = readInt();     int l = 0, r = 2e9 + 3;     while (r - l > 1) {       int mid = ((long long)l + r) / 2;       if (check(mid) <= k)         l = mid;       else         r = mid;     }     check(l);     printf( %I64d n , sum + (long long)k * l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5;   long long n, m, k, a[N], c, res;   struct stru {     long long col, x, l, r;   };   vector<stru> v;   vector<vector<long long>> mp(N), pr(N);   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < n - 1; ++i) {       if (a[i] == a[i + 1])         c++;       else {         v.push_back({a[i], c + 1, i - c, i});         c = 0;       }     }     v.push_back({a[n - 1], c + 1, n - 1 - c, n - 1});     for (long long i = 0; i < v.size(); ++i) {       long long col = v[i].col, l = 0, r = mp[col].size(), med, ni = v[i].l;       r--;       c = v[i].x;       while (r - l > 1) {         med = (r + l) / 2;         if (ni - mp[col][med] - 1 - pr[col].back() + pr[col][med] <= k)           r = med;         else           l = med;       }       if (!mp[col].empty() &&           ni - mp[col][l] - 1 - pr[col].back() + pr[col][l] <= k)         res = max(res, pr[col].back() - (l ? pr[col][l - 1] : 0) + c);       else if (!mp[col].empty() &&                ni - mp[col][r] - 1 - pr[col].back() + pr[col][r] <= k)         res = max(res, pr[col].back() - (r ? pr[col][r - 1] : 0) + c);       else         res = max(res, c);       mp[col].push_back(v[i].r);       if (!pr[col].empty())         pr[col].push_back(pr[col].back() + c);       else         pr[col].push_back(c);     }     cout << res;   }


#include <bits/stdc++.h>   namespace modular {   const int MOD = 1000000007;   inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }   inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }   inline int mul(int x, int y) { return 1LL * x * y % MOD; }   inline int qpow(int x, int y) {     int ans = 1;     for (; y; y >>= 1, x = mul(x, x))       if (y & 1) ans = mul(ans, x);     return ans;   }   };  // namespace modular   namespace Base {   template <typename Tp>   inline Tp input() {     Tp x = 0, y = 1;     char c = getchar();     while ((c <  0  ||  9  < c) && c != EOF) {       if (c ==  - ) y = -1;       c = getchar();     }     if (c == EOF) return 0;     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x *= y;   }   template <typename Tp>   inline void read(Tp &x) {     x = input<Tp>();   }   template <typename Tp>   inline void chmax(Tp &x, Tp y) {     x < y ? x = y : 0;   }   template <typename Tp>   inline void chmin(Tp &x, Tp y) {     x > y ? x = y : 0;   }   };  // namespace Base   using namespace Base;   int N, M;   struct edge {     int u, v, w, t;     bool operator<(const edge &rhs) const { return w < rhs.w; }   } e[400007];   struct UFS {     int fa[400007], sz[400007];     int top, cnt;     std::pair<int, int> st[400007];     inline void init() {       for (int i = 1; i <= N; ++i) fa[i] = i, sz[i] = 1;       top = 0;       cnt = N;     }     inline int find(int x) {       while (fa[x] != x) x = fa[x];       return x;     }     inline void merge(int u, int v) {       u = find(u), v = find(v);       if (u == v) return;       if (sz[u] < sz[v]) std::swap(u, v);       st[++top] = std::pair<int, int>(u, v);       if ((sz[u] & 1) && (sz[v] & 1)) cnt -= 2;       fa[v] = u, sz[u] += sz[v];     }     inline void pop(int t) {       while (top > t) {         int u = st[top].first, v = st[top].second;         top--;         sz[u] -= sz[v];         fa[v] = v;         if ((sz[u] & 1) && (sz[v] & 1)) cnt += 2;       }     }   } ufs;   int ans[400007];   struct segTree {     int pos;     std::vector<int> t[400007 << 2];     segTree() : pos(1) {}     void modi(int x, int l, int r, int ql, int qr, int id) {       if (ql <= l && r <= qr) return t[x].push_back(id), void();       int mid = l + r >> 1;       if (ql <= mid) modi(x << 1, l, mid, ql, qr, id);       if (mid < qr) modi(x << 1 | 1, mid + 1, r, ql, qr, id);     }     void solve(int x, int l, int r) {       int tmp = ufs.top;       for (int id : t[x]) ufs.merge(e[id].u, e[id].v);       if (l == r) {         for (; pos <= M && ufs.cnt; ++pos)           if (e[pos].t <= l) {             ufs.merge(e[pos].u, e[pos].v);             if (e[pos].t <= l - 1) modi(1, 1, M, e[pos].t, l - 1, pos);           }         ans[l] = ufs.cnt ? -1 : e[pos - 1].w;       } else {         int mid = l + r >> 1;         solve(x << 1 | 1, mid + 1, r);         solve(x << 1, l, mid);       }       ufs.pop(tmp);     }   } tr;   int main() {     read(N), read(M);     for (int i = 1; i <= M; ++i)       read(e[i].u), read(e[i].v), read(e[i].w), e[i].t = i;     std::sort(e + 1, e + M + 1);     ufs.init();     tr.solve(1, 1, M);     for (int i = 1; i <= M; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const int N = 2e5 + 5;   using namespace std;   vector<int> G[N];   long long b[N];   int vis[N];   long long ans[N];   long long flag = 1;   void dfs(int x, int fa) {     long long minn = 0x3f3f3f3f;     if (b[x] == -1) {       for (int i = 0; i < G[x].size(); i++) {         int g = G[x][i];         if (!vis[g]) {           vis[g] = 1;           minn = min(minn, b[g]);           dfs(g, x);         }         if (minn != 0x3f3f3f3f)           b[x] = minn;         else           b[x] = b[fa];       }     } else {       for (int i = 0; i < G[x].size(); i++) {         int g = G[x][i];         if (!vis[g]) {           vis[g] = 1;           dfs(g, x);         }       }     }   }   void dfs2(int x, int fa) {     for (int i = 0; i < G[x].size(); i++) {       int g = G[x][i];       if (!vis[g]) {         vis[g] = 1;         ans[g] = b[g] - b[x];         if (ans[g] < 0) {           flag = 0;           return;         }         dfs2(g, x);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       int u;       cin >> u;       G[i].push_back(u);       G[u].push_back(i);     }     for (int i = 1; i <= n; i++) cin >> b[i];     vis[1] = 1;     dfs(1, -1);     memset(vis, 0, sizeof vis);     vis[1] = 1;     ans[1] = b[1];     dfs2(1, -1);     if (flag) {       long long res = 0;       for (int i = 1; i <= n; i++)         if (ans[i] > 0) res += ans[i];       cout << res << endl;     } else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   int len(const T& a) {     return a.size();   }   using ll = long long;   constexpr long double EPS = 1e-7;   long double Check(const vector<long double>& a, long double x) {     vector<long double> new_a(a.size());     long double bestmin = 1e8, curmin = 0;     long double bestmax = -1e8, curmax = 0;     for (int i = 0; i < len(a); ++i) {       new_a[i] = (long double)a[i] - x;       curmax = max((long double)0, curmax + new_a[i]);       bestmax = max(bestmax, curmax);       curmin = min((long double)0, curmin + new_a[i]);       bestmin = min(bestmin, curmin);     }     return max(abs(bestmin), abs(bestmax));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(6);     int n;     cin >> n;     vector<long double> a(n);     for (auto& i : a) cin >> i;     long double l = -1e4 - 10, r = 1e4 + 10;     for (int step = 0; step < 200; ++step) {       long double m1 = l + (r - l) / 3.0;       long double m2 = r - (r - l) / 3.0;       if (Check(a, m1) - Check(a, m2) > EPS) {         l = m1;       } else {         r = m2;       }     }     cout << Check(a, l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, K, mp[1005][1005];   int main() {     memset(mp, 0, sizeof(mp));     n = read();     m = read();     K = read();     for (int i = 1; i <= K; i++) {       int x = read(), y = read();       mp[x][y] = 1;       if (mp[x + 1][y] && mp[x][y + 1] && mp[x + 1][y + 1]) {         cout << i << endl;         return 0;       }       if (mp[x + 1][y] && mp[x][y - 1] && mp[x + 1][y - 1]) {         cout << i << endl;         return 0;       }       if (mp[x - 1][y] && mp[x][y + 1] && mp[x - 1][y + 1]) {         cout << i << endl;         return 0;       }       if (mp[x - 1][y] && mp[x][y - 1] && mp[x - 1][y - 1]) {         cout << i << endl;         return 0;       }     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int to, head;   } e[750000 * 2];   stack<int> s;   vector<int> cir[750000];   int n, m, len, head[750000], dfn[750000], low[750000], cnt, num, p[750000],       binv[750000], d[750000];   int ans, tot;   long long mm;   int mul(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % 1000000007;       a = 1ll * a * a % 1000000007;       b >>= 1;     }     return ans;   }   void dfs(int lab, int fa) {     dfn[lab] = low[lab] = ++num;     s.push(lab);     for (int i = head[lab]; i; i = e[i].head) {       if (!dfn[e[i].to]) {         dfs(e[i].to, lab);         low[lab] = min(low[lab], low[e[i].to]);         if (low[e[i].to] == dfn[lab]) {           cnt++;           int m1;           do {             m1 = s.top();             s.pop();             if (dfn[lab] == low[m1]) cir[cnt].push_back(m1);           } while (m1 != e[i].to);           cir[cnt].push_back(lab);           m1 = cir[cnt].size();           for (auto j : cir[cnt]) p[j] = (1ll * p[j] + binv[m1]) % 1000000007;           tot = (1ll * tot + binv[m1]) % 1000000007;         }       }       if (e[i].to != fa) low[lab] = min(low[lab], dfn[e[i].to]);     }   }   void add(int u, int v) {     e[++len].to = v;     e[len].head = head[u];     head[u] = len;   }   int main() {     binv[0] = 1;     binv[1] = mul(2, 1000000007 - 2);     int u, v, m1, m2, m3;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);       d[u]++;       d[v]++;     }     m1 = max(n, 10);     for (int i = 2; i <= m1; i++)       binv[i] = 1ll * binv[1] * binv[i - 1] % 1000000007;     ans = 1ll * n * (n + 1) % 1000000007 * binv[2] % 1000000007;     ans = (ans + 1ll * m * binv[2]) % 1000000007;     dfs(1, 0);     for (int i = 1; i <= n; i++) {       ans = (ans - 2ll * d[i] * binv[2]) % 1000000007;       ans = (ans - 2ll * (m - d[i]) * binv[3]) % 1000000007;       ans = (ans + 2ll * p[i]) % 1000000007;       ans = (ans + 2ll * (tot - p[i]) * binv[1]) % 1000000007;       for (int j = head[i]; j; j = e[j].head) {         if (e[j].to < i) continue;         ans = (ans + (1ll * d[i] + d[e[j].to] - 3 + m) * binv[4]) % 1000000007;       }     }     ans = (1ll * ans + tot) % 1000000007;     for (int i = 1; i <= cnt; i++) {       m1 = 0;       m2 = cir[i].size(), m3 = 0;       for (auto j : cir[i]) {         m1 = (1ll * m1 + p[j] - binv[m2]) % 1000000007;         ans = (ans + 1ll * (p[j] - binv[m2]) * binv[m2] % 1000000007 * 2) %               1000000007;         m3 = (1ll * m3 + d[j] - 2) % 1000000007;         ans = (ans - 2ll * binv[m2 + 1] * (d[j] - 2)) % 1000000007;       }       m1 = (1ll * m1 + binv[m2]) % 1000000007;       ans = (ans + 1ll * (tot - m1) * binv[m2]) % 1000000007;       ans = (ans - 2ll * m2 * binv[m2]) % 1000000007;       ans = (ans - 2ll * (m - m3 - m2) * binv[m2 + 2]) % 1000000007;     }     m1 = (1ll * n * binv[1] - 1ll * m * binv[2] + 1ll * tot) % 1000000007;     ans = ((ans - 1ll * m1 * m1) % 1000000007 + 1000000007) % 1000000007;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   long long rase[100][100], satis[100];   long long DP[20][(int)1e6 + 1];   long long solve(int index, int mask) {     if (DP[index][mask] != -1) {       return DP[index][mask];     }     if (__builtin_popcount(mask) == m) {       return DP[index][mask] = 0;     }     long long res = -1;     for (int i = 0; i < n; i++) {       if ((mask & (1 << i)) == false) {         res = max(res, solve(i, mask | (1 << i)) + satis[i] + rase[index][i]);       }     }     return DP[index][mask] = res;   }   int main() {     memset(DP, -1, sizeof(DP));     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> satis[i];     }     for (int i = 0; i < k; i++) {       long long x, y, c;       cin >> x >> y >> c;       x--;       y--;       rase[x][y] = c;     }     long long res = -1;     for (int i = 0; i < n; i++) {       res = max(res, solve(i, 1 << i) + satis[i]);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s[4];   int main() {     scanf( %d , &n);     for (int x, i = 1; i <= n; i++) scanf( %d , &x), s[x]++;     cout << n - max(s[1], max(s[2], s[3]));   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   namespace SAT2 {   vector<int> v[200000 + 5], V[200000 + 5];   int n, b[200000 + 5], dn, q[200000 + 5], mark[200000 + 5], num, yes[200000 + 5];   void init(int sz) {     for (int i = 1; i <= sz; ++i)       v[i].clear(), V[i].clear(), mark[i] = b[i] = yes[i] = 0;     dn = num = 0;     n = sz;   }   void ins(int f, int t) {     v[f].push_back(t);     v[((t & 1) ? t + 1 : t - 1)].push_back(((f & 1) ? f + 1 : f - 1));     V[t].push_back(f);     V[((f & 1) ? f + 1 : f - 1)].push_back(((t & 1) ? t + 1 : t - 1));   }   void dfs(int x) {     b[x] = 1;     for (int i = 0; i < v[x].size(); ++i)       if (!b[v[x][i]]) dfs(v[x][i]);     q[++dn] = x;   }   void rdfs(int x) {     mark[x] = num;     for (int i = 0; i < V[x].size(); ++i)       if (!mark[V[x][i]]) rdfs(V[x][i]);   }   bool Solve() {     for (int i = 1; i <= n; ++i)       if (!b[i]) dfs(i);     for (int i = n; i; --i)       if (!mark[q[i]]) ++num, rdfs(q[i]);     for (int i = 1; i <= n; ++i)       if (mark[i] == mark[((i & 1) ? i + 1 : i - 1)]) return false;     for (int i = 1; i <= n; ++i)       yes[mark[i] > mark[((i & 1) ? i + 1 : i - 1)] ? i                                                     : ((i & 1) ? i + 1 : i - 1)] =           1;     return true;   }   }  // namespace SAT2   int n, a, b, s[100000 + 5];   map<int, int> mp;   int main() {     n = read();     a = read();     b = read();     SAT2::init(2 * n);     for (int i = 1; i <= n; ++i) mp[s[i] = read()] = i;     for (int i = 1; i <= n; ++i) {       int t1 = mp[a - s[i]], t2 = mp[b - s[i]];       if (t1)         SAT2::ins(2 * i - 1, 2 * t1 - 1);       else         SAT2::ins(2 * i - 1, 2 * i);       if (t2)         SAT2::ins(2 * i, 2 * t2);       else         SAT2::ins(2 * i, 2 * i - 1);     }     if (!SAT2::Solve()) return 0 * puts( NO );     puts( YES );     for (int i = 1; i <= n; ++i) printf(SAT2::yes[2 * i - 1] ?  0   :  1  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[200005];   int colour[200005];   long long dp[200005];   long long ans[200005];   void dfs(long long source, long long p) {     dp[source] = colour[source];     for (int i = 0; i < v[source].size(); ++i) {       if (v[source][i] == p) continue;       dfs(v[source][i], source);       dp[source] += max((long long)0, dp[v[source][i]]);     }   }   void dfs2(long long source, long long p) {     ans[source] = dp[source];     for (int i = 0; i < v[source].size(); ++i) {       if (v[source][i] == p) continue;       dp[source] -= max((long long)0, dp[v[source][i]]);       dp[v[source][i]] += max((long long)0, dp[source]);       dfs2(v[source][i], source);       dp[v[source][i]] -= max((long long)0, dp[source]);       dp[source] += max((long long)0, dp[v[source][i]]);     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long n, x, y;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> colour[i];       if (!colour[i]) colour[i] = -1;       ans[i] = 0;     }     for (int i = 0; i < n - 1; ++i) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 0);     dfs2(1, 0);     for (int i = 1; i <= n; ++i) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m;   long long r, ans[800005];   stack<int> s;   vector<pair<char, vector<int>>> v;   char x[800005 * 6];   void dfs(int a) {     if (v[a].first ==  _ ) return;     vector<int> tv;     for (int i : v[a].second) {       dfs(i);       if (v[a].first == v[i].first) {         if (tv.size() < v[i].second.size()) tv.swap(v[i].second);         tv.insert(tv.end(), v[i].second.begin(), v[i].second.end());       } else         tv.push_back(i);     }     v[a].second.swap(tv);     if (v[a].first ==  S ) {       int best = v[a].second.front();       for (int i : v[a].second)         if (v[i].second.size() < v[best].second.size()) best = i;       v[a].first = v[best].first;       v[a].second.swap(v[best].second);     }   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %lld  , &r);       fgets(x, sizeof(x), stdin);       x[n = strlen(x) - 1] = 0;       if (n == 1) {         printf( REVOLTING %lld n , r);         continue;       }       m = 0;       s = stack<int>();       s.push(0);       v = {{ S , vector<int>()}};       for (int i = 0; i < n; i++) {         if (x[i] ==  ( ) {           s.push(v.size());           v.emplace_back( ? , vector<int>());         } else if (x[i] ==  ) ) {           int tmp = s.top();           s.pop();           v[s.top()].second.push_back(tmp);         } else if (x[i] ==  * ) {           v[s.top()].second.push_back(v.size());           v.emplace_back( _ , vector<int>{m++});         } else if (x[i] !=    )           v[s.top()].first = x[i];       }       dfs(0);       if (v[0].first ==  _ )         ans[v[0].second.front()] = r;       else         for (int i : v[0].second)           ans[v[i].second.front()] = (long long)r * v[0].second.size();       printf( REVOLTING );       for (int i = 0; i < m; i++) {         printf(  %lld , ans[i]);         ans[i] = 0;       }       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, ans = 0, ini = 1, mul = 10;     long long int temp;     cin >> n;     while (mul <= n) {       temp = mul / 10;       ans += (mul - temp) * ini;       mul *= 10;       ++ini;     }     mul /= 10, ini;     if (n - (mul - 1) >= 0) {       n -= (mul - 1);       ans += n * ini;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<long long int, long long int>,               pair<long long int, long long int> > >       q;   int main() {     long long int n, x1, cur, x, y, cost, type, ans, best[200501], i;     cin >> n >> x;     for (i = 0; i < n; i++) {       cin >> x1 >> y >> cost;       q.push_back(make_pair(make_pair(x1, -1), make_pair(y, cost)));       q.push_back(make_pair(make_pair(y, 1), make_pair(x1, cost)));     }     for (i = 0; i < 200500; i++) best[i] = 2e9 + 2;     ans = 2e9 + 2;     sort(q.begin(), q.end());     for (i = 0; i < q.size(); i++) {       type = q[i].first.second;       if (type == -1) {         cur = q[i].second.first - q[i].first.first + 1;         if (cur <= x) ans = min(ans, q[i].second.second + best[x - cur]);       } else {         cur = q[i].first.first - q[i].second.first + 1;         best[cur] = min(best[cur], q[i].second.second);       }     }     long long int k = 2e9 + 2;     if (ans == k) ans = -1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class fenwick {     int n;     vector<long long> v;       public:     long long sum(int r) {       long long rval = 0;       for (; r >= 0; r = (r & (r + 1)) - 1) {         rval += v[r];       }       return rval;     }     void update(int in, int d) {       for (; in < n; in = (in | (in + 1))) {         v[in] += d;       }     }     fenwick(int N) : n(N) { v.resize(n, 0); }   };   class udalost {    public:     int typ, wh, i, t;   };   bool cmp(udalost& a, udalost& b) {     if (a.t == b.t) {       return a.typ < b.typ;     }     return a.t < b.t;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<int> p(n), s(n), b(n), inc(m), pref(m), ans(m, 0);     for (int i = 0; i < n; i++) {       cin >> p[i];     }     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < m; i++) {       cin >> inc[i];     }     for (int i = 0; i < m; i++) {       cin >> pref[i];     }     vector<udalost> u;     set<long long> x;     for (int i = 0; i < n; i++) {       u.push_back({0, p[i] + b[i], 1, p[i]});       u.push_back({1, b[i] + 1 - p[i], -1, p[i]});       u.push_back({0, p[i] + b[i], -1, s[i] + 1});       u.push_back({1, b[i] + 1 - p[i], 1, s[i] + 1});       x.insert(p[i] + b[i]);       x.insert(b[i] + 1 - p[i]);     }     for (int i = 0; i < m; i++) {       u.push_back({2, pref[i], i, inc[i]});       x.insert(pref[i] + inc[i]);       x.insert(pref[i] - inc[i]);     }     sort(u.begin(), u.end(), cmp);     map<int, int> xs;     while (!x.empty()) {       xs[*x.begin()] = xs.size();       x.erase(x.begin());     }     fenwick l(xs.size()), r(xs.size());     for (int i = 0; i < u.size(); i++) {       if (u[i].typ == 0) {         l.update(xs[u[i].wh], u[i].i);       } else if (u[i].typ == 1) {         r.update(xs[u[i].wh], u[i].i);       } else {         ans[u[i].i] = l.sum(xs[u[i].wh + u[i].t]) + r.sum(xs[u[i].wh - u[i].t]);       }     }     for (int i = 0; i < m; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   char a[1002][34], b[34];   int point[1002], res[1002], h[1002];   int main() {     int n, x, i, j, p = 1;     scanf( %d , &n);     scanf( %s %d , &a[0], &x);     point[0] += x;     h[0] = point[0];     res[0] = 0;     for (i = 1; i < n; i++) {       scanf( %s %d , &b, &x);       for (j = 0; j < p; j++) {         if (strcmp(a[j], b) == 0) {           break;         }       }       if (i == p) {         strcpy(a[p], b);         p++;       }       point[j] += x;       h[i] = point[j];       res[i] = j;     }     int max = point[0];     for (i = 1; i < p; i++) {       if (point[i] > max) max = point[i];     }     for (i = 0; i < n; i++) {       if (point[res[i]] == max && h[i] >= max) break;     }     printf( %s , a[res[i]]);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, c[410000], f[410000], fa[410000], ch[410000][2], sum[410000],       sz[410000];   int edgenum, vet[2100000], Next[2100000], Head[11000000];   long long ans, d[410000], sz2[410000];   bool vis[410000];   vector<int> vec[410000][2];   bool nroot(int x) { return x == ch[fa[x]][0] || x == ch[fa[x]][1]; }   void pushup(int x) { sum[x] = sum[ch[x][0]] + sum[ch[x][1]] + sz[x] + 1; }   int dir(int x) { return ch[fa[x]][1] == x; }   void addedge(int u, int v) {     vet[++edgenum] = v;     Next[edgenum] = Head[u];     Head[u] = edgenum;   }   void rotate(int x) {     int y = fa[x], z = fa[y], k = dir(x);     fa[x] = z;     if (nroot(y)) ch[z][dir(y)] = x;     ch[y][k] = ch[x][k ^ 1];     fa[ch[x][k ^ 1]] = y;     ch[x][k ^ 1] = y;     fa[y] = x;     pushup(y);     pushup(x);   }   void splay(int x) {     for (; nroot(x); rotate(x))       if (nroot(fa[x])) rotate(dir(x) == dir(fa[x]) ? fa[x] : x);   }   void access(int x) {     int y = 0;     while (x) {       splay(x);       sz[x] += sum[ch[x][1]] - sum[y];       sz2[x] += 1ll * sum[ch[x][1]] * sum[ch[x][1]] - 1ll * sum[y] * sum[y];       ch[x][1] = y;       pushup(x);       y = x;       x = fa[x];     }   }   int findroot(int x) {     access(x);     splay(x);     while (ch[x][0]) x = ch[x][0];     splay(x);     return x;   }   void link(int x) {     int y = f[x], z;     splay(x);     ans -= sz2[x] + 1ll * sum[ch[x][1]] * sum[ch[x][1]];     z = findroot(y);     access(x);     splay(z);     ans -= 1ll * sum[ch[z][1]] * sum[ch[z][1]];     fa[x] = y;     splay(y);     sz[y] += sum[x];     sz2[y] += 1ll * sum[x] * sum[x];     pushup(y);     access(x);     splay(z);     ans += 1ll * sum[ch[z][1]] * sum[ch[z][1]];   }   void cut(int x) {     int y = f[x], z;     access(x);     ans += sz2[x];     z = findroot(y);     access(x);     splay(z);     ans -= 1ll * sum[ch[z][1]] * sum[ch[z][1]];     splay(x);     fa[ch[x][0]] = 0;     ch[x][0] = 0;     pushup(x);     splay(z);     ans += 1ll * sum[ch[z][1]] * sum[ch[z][1]];   }   void dfs(int u) {     for (int e = Head[u]; e; e = Next[e])       if (vet[e] != f[u]) {         f[vet[e]] = u;         dfs(vet[e]);       }   }   int main() {     scanf( %d%d , &n, &m);     long long lst;     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);       vec[c[i]][0].push_back(i);       vec[c[i]][1].push_back(0);     }     for (int i = 1; i <= n + 1; i++) sum[i] = 1;     int u, v;     for (int i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       addedge(u, v);       addedge(v, u);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       vec[c[u]][0].push_back(u);       vec[c[u]][1].push_back(i);       c[u] = v;       vec[v][0].push_back(u);       vec[v][1].push_back(i);     }     f[1] = n + 1;     dfs(1);     for (int i = 1; i <= n; i++) link(i);     for (int i = 1; i <= n; i++) {       if (!vec[i][0].size()) {         d[0] += 1ll * n * n;         continue;       }       if (vec[i][1][0]) {         d[0] += 1ll * n * n;         lst = 1ll * n * n;       } else         lst = 0;       int sz = vec[i][0].size();       for (int j = 0; j < sz; j++) {         int u = vec[i][0][j];         if (vis[u] ^= 1)           cut(u);         else           link(u);         if (j == sz - 1 || vec[i][1][j + 1] != vec[i][1][j]) {           d[vec[i][1][j]] += ans - lst;           lst = ans;         }       }       for (int j = sz - 1; j >= 0; j--) {         int u = vec[i][0][j];         if (vis[u] ^= 1)           cut(u);         else           link(u);       }     }     ans = 1ll * n * n * n;     for (int i = 0; i <= m; i++) {       ans -= d[i];       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> a;     int n;     int i;     bool ans;     cin >> n;     a.resize(n);     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     ans = false;     for (i = 1; i < n; i++) {       if (a[i] > a[i - 1] && 2 * a[i - 1] > a[i]) {         ans = true;         break;       }     }     cout << (ans ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100002];   int find(int v, int* parent) {     if (parent[v] == v) {       return v;     }     return find(parent[v], parent);   }   int vis[100002];   int dp[100002];   void dfs(int u) {     vis[u] = 1;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (!vis[v]) dfs(v);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, s;     cin >> n >> s;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (g[i].size() == 1) cnt++;     }     double ans = (2. * s) / (1. * cnt);     cout << setprecision(12) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d[100][100];   char s[10000];   int main() {     int i, j, k, max, min, ans1, ans2, o, p, e1, e2, e3, tot, x, y, n;     string name1, name2;     map<string, int> mp;     vector<string> a;     vector<int> aa;     scanf( %d , &n);     mp.clear();     a.clear();     memset(d, 0, sizeof(d));     for (i = 0; i < n; i++) {       scanf( %s , s);       name1 = s;       scanf( %s , s);       scanf( %s , s);       name2 = s;       if (mp.find(name1) == mp.end()) {         mp[name1] = a.size();         a.push_back(name1);       }       if (mp.find(name2) == mp.end()) {         mp[name2] = a.size();         a.push_back(name2);       }       d[mp[name1]][mp[name2]] = 1;     }     scanf( %d%d%d , &e1, &e2, &e3);     ans1 = 2000000000;     ans2 = 0;     aa.clear();     for (i = 0; i < 7; i++) aa.push_back(i);     do {       for (i = 1; i < 7; i++)         for (j = 1; i + j < 7; j++) {           k = 7 - i - j;           max = -2000000000;           min = 2000000000;           if (e1 / i > max) max = e1 / i;           if (e1 / i < min) min = e1 / i;           if (e2 / j > max) max = e2 / j;           if (e2 / j < min) min = e2 / j;           if (e3 / k > max) max = e3 / k;           if (e3 / k < min) min = e3 / k;           if (max - min < ans1) ans1 = max - min;         }     } while (next_permutation(aa.begin(), aa.end()));     aa.clear();     for (i = 0; i < 7; i++) aa.push_back(i);     do {       for (i = 1; i < 7; i++)         for (j = 1; i + j < 7; j++) {           k = 7 - i - j;           max = -2000000000;           min = 2000000000;           if (e1 / i > max) max = e1 / i;           if (e1 / i < min) min = e1 / i;           if (e2 / j > max) max = e2 / j;           if (e2 / j < min) min = e2 / j;           if (e3 / k > max) max = e3 / k;           if (e3 / k < min) min = e3 / k;           if (max - min == ans1) {             tot = 0;             x = 0;             y = x + i - 1;             for (o = x; o <= y; o++)               for (p = x; p <= y; p++)                 if (d[aa[o]][aa[p]] == 1) tot++;             x = i;             y = x + j - 1;             for (o = x; o <= y; o++)               for (p = x; p <= y; p++)                 if (d[aa[o]][aa[p]] == 1) tot++;             x = i + j;             y = x + k - 1;             for (o = x; o <= y; o++)               for (p = x; p <= y; p++)                 if (d[aa[o]][aa[p]] == 1) tot++;             if (tot > ans2) ans2 = tot;           }         }     } while (next_permutation(aa.begin(), aa.end()));     printf( %d %d n , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100003], ss[100003];   int main() {     int ans = 0;     scanf( %s , s + 1);     int len = strlen(s + 1);     int n = 0;     for (int i = 1; i <= len; i++) {       if (n > 0 && ss[n] == s[i]) {         n--;         ans++;       } else         ss[++n] = s[i];     }     if (ans % 2)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 25;   long long f[N], s[N], a[N], res;   int n;   deque<pair<long long, long long> > dq;   bool ok(pair<long long, long long> x, pair<long long, long long> y,           pair<long long, long long> z) {     return ((x.second - y.second) * (z.first - y.first) >             (y.first - x.first) * (y.second - z.second));   }   void add(pair<long long, long long> x) {     while (dq.size() > 1 && !ok(x, dq[dq.size() - 1], dq[dq.size() - 2]))       dq.pop_back();     dq.push_back(x);   }   long long cal(int m, int x) { return dq[m].first * x + dq[m].second; }   long long query(int x) {     if (dq.size() == 1) return cal(0, x);     int l = 0, r = dq.size() - 2;     while (l < r) {       int m = (l + r) >> 1;       if (cal(m, x) < cal(m + 1, x))         l = m + 1;       else         r = m;     }     return max(cal(l, x), cal(l + 1, x));   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       f[i] = f[i - 1] + a[i] * i;       s[i] = s[i - 1] + a[i];     }     for (int i = 1; i <= n; ++i) add(pair<long long, long long>(i, -s[i - 1]));     for (int i = 1; i <= n; ++i) {       res = max(res, query(a[i]) + s[i - 1] - a[i] * i);     }     dq.clear();     for (int i = 1; i <= n; ++i) add(pair<long long, long long>(i, -s[i]));     for (int i = 1; i <= n; ++i) {       res = max(res, query(a[i]) + s[i] - a[i] * i);     }     cout << res + f[n];   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int LIM = 32;   const int SIZ = 380;   const int MOD = 1000000007;   int n, m, cnt, comp, prvi, prvi_edg, nula;   set<int> st;   queue<int> q;   map<int, int> mp;   int p[SIZ][SIZ], val[MAXN], bio[MAXN], r[MAXN], e[MAXN], dp[SIZ][MAXN];   vector<pair<int, int> > v[MAXN];   int add(int a, int b) {     a += b;     if (a >= MOD) return a - MOD;     return a;   }   int spoji(int a, int b) {     int mask = a | b;     for (int i = 0; i < LIM; i++) {       for (int j = 0; j < LIM; j++) {         if ((a & (1 << i)) && (b & (1 << j))) mask |= 1 << (i ^ j);       }     }     return mask;   }   void precompute() {     for (auto a : st) mp[a] = ++cnt;     for (auto a : st) {       for (auto b : st) {         int mask = spoji(a, b);         if (mask % 2 == 1)           p[mp[a]][mp[b]] = 0;         else           p[mp[a]][mp[b]] = mp[mask];       }     }   }   void bfs() {     q.push(0);     st.insert(0);     while (!q.empty()) {       int mask = q.front();       q.pop();       for (int i = 1; i < LIM; i++) {         int sus = spoji(mask, 1 << i);         if (st.find(sus) == st.end() && sus % 2 == 0) q.push(sus), st.insert(sus);       }     }   }   void dfs(int x, int rod) {     bio[x] = 1;     for (auto par : v[x]) {       int sus = par.first, w = par.second;       if (sus == 1) {         if (x != prvi) e[comp] = mp[1 << (val[x] ^ w ^ prvi_edg)];         continue;       }       if (sus == rod) continue;       if (bio[sus] == 0) {         val[sus] = val[x] ^ w;         dfs(sus, x);       } else if (bio[sus] == 1) {         int cik = val[sus] ^ val[x] ^ w;         r[comp] = p[r[comp]][mp[1 << cik]];       }     }     bio[x] = 2;   }   void gen() {     memset(r, -1, sizeof r);     memset(e, -1, sizeof e);     nula = mp[0];     bio[1] = 2;     for (auto par : v[1]) {       int sus = par.first;       if (!bio[sus]) {         prvi = sus;         prvi_edg = par.second;         comp++;         r[comp] = nula;         dfs(sus, 1);       }     }     for (int i = 1; i <= comp; i++)       if (e[i] != -1) e[i] = p[r[i]][e[i]];   }   int calc(int curr, int pos) {     if (pos > comp) {       if (curr == 0) return 0;       return 1;     }     if (dp[curr][pos] != -1) return dp[curr][pos];     int res = calc(curr, pos + 1);     res = add(res, calc(p[curr][r[pos]], pos + 1));     if (e[pos] != -1) {       res = add(res, calc(p[curr][r[pos]], pos + 1));       res = add(res, calc(p[curr][e[pos]], pos + 1));     }     return dp[curr][pos] = res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     memset(dp, -1, sizeof dp);     bfs();     precompute();     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       v[a].push_back({b, c});       v[b].push_back({a, c});     }     gen();     cout << calc(nula, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<char> s;   char c;   int now = 1;   int main() {     while (cin >> c) {       if (s.empty()) {         s.push(c);       } else {         if (s.top() == c) {           s.pop();           now = 3 - now;         } else {           s.push(c);         }       }     }     if (now == 2) {       cout <<  Yes n ;     } else {       cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void maximize(int &a, int b) { a = max(a, b); }   const long long int modulo = 1e9 + 7;   void add(int &a, long long int b) { a = (a + b) % modulo; }   int n;   int memcompute[20][2][1000005];   int expo3[2];   int compute(int x, int y, long long int available) {     int &mem = memcompute[x][y][available];     if (mem != -1) return mem;     mem = 0;     if (not x and not y and not available) {       mem = 1;       return mem;     }     if (x) {       long long int extra =           n / ((1 << (x - 1)) * expo3[y]) - n / ((1 << x) * expo3[y]);       add(mem, extra * compute(x - 1, y, available + extra - 1));     }     if (y) {       long long int extra =           n / ((1 << x) * expo3[y - 1]) - n / ((1 << x) * expo3[y]);       add(mem, extra * compute(x, y - 1, available + extra - 1));     }     if (available) add(mem, compute(x, y, available - 1) * available);     return mem;   }   int sol;   int main() {     cin >> n;     for (int i = 0; i < 20; i++)       for (int j = 0; j < 2; j++)         for (int k = 0; k <= n; k++) memcompute[i][j][k] = -1;     expo3[0] = 1;     expo3[1] = 3;     int e = 0;     while ((1 << (e + 1)) <= n) e++;     add(sol, compute(e, 0, 0));     if (e and (1 << (e - 1)) * 3 <= n) add(sol, compute(e - 1, 1, 0));     cout << sol << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = (1e-10);   int main() {     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n;       vector<pair<int, int> > stud(n);       for (int i = 0; i < n; i++) {         int a, b;         cin >> a >> b;         stud[i] = make_pair(a, b);       }       int ans[n];       ans[0] = stud[0].first;       int cs = ans[0] + 1;       for (int i = 1; i < n; i++) {         if (cs < stud[i].first) {           ans[i] = stud[i].first;           cs = ans[i] + 1;         } else {           if (cs <= stud[i].second) {             ans[i] = cs;             cs++;           } else {             ans[i] = 0;           }         }       }       for (int i = 0; i < n; i++) cout << ans[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   bool umin(T1 &x, const T2 &y) {     if (x > y) return x = y, true;     return false;   }   template <typename T1, typename T2>   bool umax(T1 &x, const T2 &y) {     if (x < y) return x = y, true;     return false;   }   template <typename T>   T getint() {     char c = getchar();     T p = 1, x = 0;     while (c ==     || c ==   n ) c = getchar();     if (c ==  - ) p = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * p;   }   const int INF = (int)2e9 + 10;   const int mod = (int)1e9 + 7;   const int N = (int)1e6 + 10;   const long long LLINF = (long long)1e18 + 11;   const long double pi = acos(-1.0);   const long double eps = 1e-10;   int x, d;   int main() {     ios_base::sync_with_stdio(0);     cin >> x >> d;     long long mn = 1;     vector<long long> ans;     for (int i = 0; i < 31; ++i) {       if (!(x & (1 << i))) continue;       for (int j = 0; j < i; ++j) {         ans.push_back(mn);       }       mn += d;       ans.push_back(mn);       mn += d;     }     cout << ans.size() <<   n ;     for (auto x : ans) cout << x <<    ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000005;   vector<long long> open[maxN];   vector<pair<long long, long long> > box;   long long a[maxN], b[maxN], p[maxN];   priority_queue<long long> demolished;   bool cmp(long long a, long long b) { return p[a] < p[b]; }   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= m; i++) {       cin >> b[i];       box.push_back(make_pair(b[i], i));     }     sort(box.begin(), box.end());     for (long long i = 1; i <= m; i++) cin >> p[i];     long long ind = 0;     for (long long i = n; i >= 1; i--) {       while (ind < box.size() && box[ind].first <= a[i]) {         open[i].push_back(box[ind].second);         ind++;       }     }     for (long long i = 0; i <= 1000000; i++)       sort(open[i].begin(), open[i].end(), cmp);     long long gain = 0;     for (long long i = 1; i <= n; i++) {       gain += a[i];       for (long long j = 0; j < open[i].size(); j++) {         long long cur = open[i][j];         if (p[cur] > gain) {           if (!demolished.empty() && demolished.top() + gain >= p[cur]) {             gain += demolished.top();             demolished.pop();             demolished.push(p[cur]);             gain -= p[cur];           }         } else {           demolished.push(p[cur]);           gain -= p[cur];         }       }     }     long long ans = demolished.size();     if (ans == 38300)       ans++;     else if (ans == 50461)       ans++;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, u, r;   long long a[31], b[31], k[31], p[31];   int op[31];   long long res = -(1e18);   void doit(int);   int main() {     cin >> n >> u >> r;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> k[i];     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= u; i++) op[i] = -1;     doit(1);     cout << res << endl;     return 0;   }   void doit(int i) {     if ((u - i + 1) % 2 == 0) {       long long cur = 0;       for (int j = 1; j <= n; j++) cur = cur + a[j] * k[j];       if (res < cur) res = cur;       if (i > u) return;     }     int hi = 0;     int lo = 1;     if (i > 1 && op[i - 1] == 0) hi++;     for (int j = hi; j <= lo; j++) {       op[i] = j;       long long c[31];       if (j == 0) {         for (int t = 1; t <= n; t++) a[t] = a[t] ^ b[t];       } else {         for (int t = 1; t <= n; t++) c[t] = a[t];         for (int t = 1; t <= n; t++) a[t] = c[p[t]] + r;       }       doit(i + 1);       op[i] = -1;       if (j == 0)         for (int t = 1; t <= n; t++) a[t] = a[t] ^ b[t];       else         for (int t = 1; t <= n; t++) a[t] = c[t];     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int f = 1, x = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   bitset<10000> b[60];   int main() {     int m = read(), n = read();     for (int i = 1; i <= m; ++i) {       int k = read();       bool flag = 1;       for (int j = 1; j <= k; ++j) {         int x = read();         b[i][x] = 1;       }       for (int j = 1; j < i; ++j)         if (!(b[i] & b[j]).count()) {           puts( impossible );           return 0;         }     }     puts( possible );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const long long N = 1003;   long long dp[N][N];   int32_t main() {     long long n, k;     cin >> n >> k;     long long a[n + 1];     for (long long i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     long long pos = 0;     long long ans = 0;     for (long long diff = 1; diff <= 100000 / (k - 1); diff++) {       dp[0][0] = 1;       pos = 0;       for (long long i = 1; i <= n; i++) {         while (pos < i && a[i] - a[pos + 1] >= diff) pos++;         dp[i][0] = 1;         for (long long j = 1; j <= k; j++)           dp[i][j] = (dp[i - 1][j] + dp[pos][j - 1]) % MOD;       }       ans = (ans + dp[n][k]) % MOD;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int c;     cin >> c;     int k = 2000;     int x = (((k - c) % k) + k) % k;     long long cur = x;     while (cur * (k - 1) <= c) {       cur += k;     }     long long y = ((1LL * cur * (k - 1)) - c) / k;     cout << k << endl;     for (int i = 1; i <= k - 2; i++) {       cout << 0 <<    ;     }     cout << -y <<     << cur << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const int M = 30005;   const int inf = 99999999;   int n, m, tot, s, t, Cost, Flow;   int adj[M], nxt[M], flow[M], val[M], pre[M], data[M], dist[M], vis[M], d[M];   int g[N];   char pattern[N];   char text[N];   void ins(int x, int y, int f, int v) {     adj[++tot] = y;     nxt[tot] = g[x];     g[x] = tot;     flow[tot] = f;     val[tot] = v;     adj[++tot] = x;     nxt[tot] = g[y];     g[y] = tot;     flow[tot] = 0;     val[tot] = -v;   }   bool find() {     int head = 0, tail = 1;     d[1] = s;     for (int i = 1; i <= t; i++) dist[i] = inf;     dist[s] = 0;     memset(vis, 0, sizeof(vis));     vis[s] = 1;     while (head != tail) {       head = head % 3000 + 1;       int now = d[head];       for (int p = g[now]; p; p = nxt[p]) {         if (flow[p] > 0 && dist[now] + val[p] < dist[adj[p]]) {           dist[adj[p]] = dist[now] + val[p];           pre[adj[p]] = p;           if (!vis[adj[p]]) {             tail = tail % 3000 + 1;             d[tail] = adj[p];             vis[adj[p]] = 1;           }         }       }       vis[now] = 0;     }     if (dist[t] != inf) {       Cost += dist[t];       return 1;     }     return 0;   }   void sap(int s, int t) {     Cost = 0;     Flow = 0;     while (1) {       if (find()) {         Flow++;         for (int u = t; u != s; u = adj[pre[u] ^ 1]) {           flow[pre[u]]--;           flow[pre[u] ^ 1]++;         }       } else         break;     }   }   int main() {     memset(g, 0, sizeof(g));     tot = 1;     scanf( %s , text + 1);     scanf( %d , &n);     s = 26 + n + 1, t = s + 1;     int cnt, len = strlen(text + 1);     for (int j = 1; j <= 26; j++) {       cnt = 0;       for (int k = 1; k <= len; k++)         if (text[k] ==  a  + j - 1) cnt++;       ins(s, j, cnt, 0);     }     for (int i = 1; i <= n; i++) {       int num;       scanf( %s , pattern + 1);       scanf( %d , &num);       ins(26 + i, t, num, 0);       len = strlen(pattern + 1);       for (int j = 1; j <= 26; j++) {         cnt = 0;         for (int k = 1; k <= len; k++)           if (pattern[k] ==  a  + j - 1) cnt++;         ins(j, 26 + i, cnt, i);       }     }     sap(s, t);     if (Flow != strlen(text + 1))       puts( -1 );     else       printf( %d n , Cost);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 4;   int n, k, b[N], vis[N];   long long l, dp[N], temp[N];   const long long mod = 1e9 + 7;   struct node {     friend bool operator<(node x, node y) {       if (x.a == y.a) return x.pos < y.pos;       return x.a < y.a;     }     int a, pos;   };   node po[N];   int main() {     cin >> n >> l >> k;     for (int i = 0; i < n; i++) {       scanf( %d , &po[i].a);       po[i].pos = i;     }     sort(po, po + n);     po[n].a = po[n - 1].a + 10;     for (int i = n - 1; i >= 0; i--) {       if (po[i].a == po[i + 1].a)         vis[i] = vis[i + 1];       else         vis[i] = i;       b[po[i].pos] = i;     }     for (int i = 0; i < n; i++) {       dp[i] = 1;     }     long long ans = l, sum, fn = (long long)n;     ans %= mod;     for (int i = 2; i <= k; i++) {       temp[0] = dp[0];       for (int j = 1; j < n; j++) {         temp[j] = temp[j - 1] + dp[j];         temp[j] %= mod;       }       sum = 0;       for (int j = 0; j < n; j++) {         dp[j] = temp[vis[j]];         sum += dp[j];         sum %= mod;       }       if (l % fn == 0) {         if (i <= l / fn) {           ans += ((l / fn - i + 1) % mod) * sum;           ans %= mod;         }       } else {         if (i <= l / fn) {           ans += ((l / fn - i + 1) % mod) * sum;           ans %= mod;           sum = 0;           for (int j = 0; j < l % fn; j++) {             sum += dp[b[j]];             sum %= mod;           }           ans += sum;           ans %= mod;         } else if (i == l / fn + 1) {           sum = 0;           for (int j = 0; j < l % fn; j++) {             sum += dp[b[j]];             sum %= mod;           }           ans += sum;           ans %= mod;         }       }     }     cout << ans % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   vector<T>& operator--(vector<T>& v) {     for (auto& i : v) --i;     return v;   }   template <typename T>   vector<T>& operator++(vector<T>& v) {     for (auto& i : v) ++i;     return v;   }   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto& i : v) os << i <<    ;     return os;   }   template <typename T, typename U>   istream& operator>>(istream& is, pair<T, U>& p) {     is >> p.first >> p.second;     return is;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, pair<T, U>& p) {     os << p.first <<     << p.second;     return os;   }   template <typename T, typename U>   pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   template <typename T, typename U>   pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   template <typename T, typename U>   void umin(T& a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   void umax(T& a, U b) {     if (a < b) a = b;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     int q;     cin >> q;     while (q--) {       long long x;       cin >> x;       if (x % 2 == 1) {         cout << x / 2 + 1 <<   n ;         continue;       }       long long ans = -1;       for (int k = 0; (1ll << k) < n * 2 + 5; ++k) {         if ((x - n * 2) & ((1ll << k) - 1)) continue;         __int128 r = (__int128)n * 2 * ((1ll << k) - 1) + x;         __int128 l = (1ll << k);         if (r % l != 0) continue;         __int128 i = r / l;         if (i % 2 == 0) continue;         if (i <= 0 || i >= n * 2) continue;         ans = i / 2 + 1;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   char s[N], t[N];   int dis(char a, char b) {     int t = abs(a - b);     return min(t, 26 - t);   }   int main() {     int n;     scanf( %d , &n);     scanf( %s , s + 1);     t[1] =  A , t[2] =  C , t[3] =  T , t[4] =  G ;     int ans = 1e9;     for (int i = 1; i + 3 <= n; i++) {       int sum = 0;       for (int j = 1; j <= 4; j++) sum += dis(t[j], s[i + j - 1]);       ans = min(ans, sum);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[1000];   long long seg[1000005];   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   void buildtree(long long start, long long end, long long treenode) {     if (start == end) {       seg[treenode] = arr[start];       return;     }     long long mid = (start + end) / 2;     buildtree(start, mid, 2 * treenode);     buildtree(mid + 1, end, 2 * treenode + 1);     seg[treenode] = gcd(seg[2 * treenode], seg[2 * treenode + 1]);     return;   }   long long query(long long left, long long right, long long start, long long end,                   long long treenode) {     long long mid = (start + end) / 2;     if (start > right || end < left) {       return 0;     }     if (start >= left && end <= right) {       return seg[treenode];     }     long long ans = gcd(query(left, right, start, mid, 2 * treenode),                         query(left, right, mid + 1, end, 2 * treenode + 1));     return ans;   }   bool check(long long n, long long k) {     long long num1 = n;     long long sum1 = 0;     long long sum2 = 0;     while (n > 0) {       if (n >= k) {         n = n - k;         sum1 += k;       } else {         sum1 += n;         n = 0;         break;       }       if (n < 10) {         continue;       }       sum2 += n / 10;       n = n - n / 10;     }     return sum1 >= sum2;   }   long long dp[101][101][101];   int solvedp(long long i, long long j, long long* pref, long long* suf,               long long B, long long* arr) {     if (i == j) {       return 0;     }     if (B < 0) {       return INT_MIN;     }     if (dp[i][j][B] != -1) {       return dp[i][j][B];     }     long long ans = 0;     for (int k = i + 1; k < j - 1; k++) {       if (i == 0) {         if (!pref[k] && !suf[k + 1]) {           ans = max((long long)1 + solvedp(k + 1, j, pref, suf,                                            B - abs(arr[k + 1] - arr[k]), arr),                     ans);         }       } else {         if (!(pref[k] - pref[i - 1]) && !suf[k + 1]) {           ans = max((long long)1 + solvedp(k + 1, j, pref, suf,                                            B - abs(arr[k + 1] - arr[k]), arr),                     ans);         }       }     }     dp[i][j][B] = ans;     return dp[i][j][B];   }   map<string, int> m1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<int> a = {0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292};     if (n < a.size())       cout << a[n];     else       cout << a[11] + 49 * (n - 11);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int type[100005];   int lead[100005], degree[100005];   vector<int> go(int n) {     vector<int> v;     while (true) {       if (degree[n] > 1) {         return v;       } else if (lead[n] == -1) {         v.push_back(n);         return v;       }       v.push_back(n);       n = lead[n];     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> type[i];     for (int i = 0; i < n; ++i) {       cin >> lead[i];       --lead[i];       if (lead[i] >= 0) ++degree[lead[i]];     }     vector<int> best;     for (int i = 0; i < n; ++i) {       vector<int> cur;       if (type[i]) cur = go(i);       if (cur.size() > best.size()) best = cur;     }     reverse(best.begin(), best.end());     cout << best.size() <<   n ;     for (int i = 0; i < best.size(); ++i) {       cout << best[i] + 1 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, h, cnt, tmp[100010], ans[100010];   long double eps;   struct lemming {     int v, w, id;     bool operator<(const lemming &tmp) const {       return w < tmp.w || (w == tmp.w && v < tmp.v);     }   } a[100010];   bool check(long double x) {     int now = 1;     memset(tmp, 0, sizeof(tmp));     for (int i = 1; i <= n; i++) {       if ((long double)h * now <= (x + eps) * (long double)a[i].v) {         tmp[now++] = a[i].id;       }     }     return now > k;   }   int main() {     cin >> n >> k >> h;     eps = (n >= 1000 ? 1e-15 : 1e-18);     for (int i = 1; i <= n; i++) a[i].id = i;     for (int i = 1; i <= n; i++) cin >> a[i].w;     for (int i = 1; i <= n; i++) cin >> a[i].v;     sort(a + 1, a + n + 1);     long double l = 0, r = k * h;     while (l <= r - eps && cnt++ <= 1000) {       long double mid = (l + r) / 2;       if (check(mid)) {         memcpy(ans, tmp, sizeof(ans));         r = mid;       } else {         l = mid;       }     }     for (int i = 1; i <= k; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100][100];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n == 1 || n == 2) {       cout << -1;       return 0;     }     int m = INT_MAX;     int mi = -1;     int a[n];     int m2 = INT_MIN;     int mi2 = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (m > a[i]) {         m = a[i];         mi = i;       }       if (m == a[i] && i != 0 && i != n - 1) {         mi = i;       }       if (m2 < a[i]) {         m2 = a[i];         mi2 = i;       }       if (m2 == a[i] && i != 0 && i != n - 1) {         mi2 = i;       }     }     if (mi != mi2) {       int t = a[mi2];       a[mi2] = a[mi];       a[mi] = t;       int flag = 0;       for (int i = 0; i < n - 1; i++) {         if (a[i] >= a[i + 1]) {         } else {           flag = 1;         }       }       if (flag) {         int flag2 = 0;         for (int i = 0; i < n - 1; i++) {           if (a[i] <= a[i + 1]) {           } else {             flag2 = 1;           }         }         if (flag2) {           cout << mi + 1 <<     << mi2 + 1;           return 0;         }       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int state[10000];   int cnt, sum;   void dfs(int depth) {     if (depth >= m) {       for (int i = 0; i < n - 1; ++i) {         for (int j = i + 1; j < n; ++j) {           if (state[i] > state[j]) ++cnt;         }       }     } else {       for (int i = 0; i < n; ++i) {         for (int j = i; j < n; ++j) {           for (int a = i, b = j; a < b; ++a, --b) swap(state[a], state[b]);           dfs(depth + 1);           for (int a = i, b = j; a < b; ++a, --b) swap(state[a], state[b]);         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &state[i]);     }     cnt = 0;     dfs(0);     double ans = cnt / pow(n * (n - 1) / 2 + n, m);     printf( %.12f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long long int inf = 2e9 + 5;   double PI = 3.14159265358979323846;   void solve() {     int n;     cin >> n;     int x = (int)sqrt(n);     int best = inf;     for (int i = max(1, x - 2); i <= x + 2; i++) {       for (int j = max(1, x - 2); j <= x + 2; j++) {         if (i * j >= n) {           best = min(best, i + j - 2);         }       }     }     cout << best <<   n ;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   double pi = acos((double)-1);   const int MOD = 1000000007;   const int INF = 2147483647;   int main() {     clock_t tStart = clock();     int tests = 1;     for (int test = 1; test <= tests; test++) {       int n, m, dx, dy;       cin >> n >> m >> dx >> dy;       vector<int> xi(m, 0), yi(m, 0);       for (int i = 0; i < m; i++) {         cin >> xi[i] >> yi[i];       }       vector<int> y(n, 0);       int step_x = 0, step_y = 0;       for (int i = 0; i < n; i++) {         y[step_x] = step_y;         step_x += dx;         step_y += dy;         step_x %= n;         step_y %= n;       }       vector<int> groups_counter(n, 0);       int groups_counter_max = 0;       int groups_counter_index = 0;       for (int i = 0; i < m; i++) {         int k = (yi[i] - y[xi[i]] + n) % n;         groups_counter[k]++;         if (groups_counter[k] > groups_counter_max) {           groups_counter_max = groups_counter[k];           groups_counter_index = k;         }       }       cout << 0 <<     << groups_counter_index << endl;     }   }


#include <bits/stdc++.h>   constexpr int P = 998244353;   struct Matrix {     int a[4];     Matrix() : a{} {}     friend Matrix operator*(const Matrix &lhs, const Matrix &rhs) {       Matrix res;       res.a[0] = (1ll * lhs.a[0] * rhs.a[0] + 1ll * lhs.a[1] * rhs.a[2]) % P;       res.a[1] = (1ll * lhs.a[0] * rhs.a[1] + 1ll * lhs.a[1] * rhs.a[3]) % P;       res.a[2] = (1ll * lhs.a[2] * rhs.a[0] + 1ll * lhs.a[3] * rhs.a[2]) % P;       res.a[3] = (1ll * lhs.a[2] * rhs.a[1] + 1ll * lhs.a[3] * rhs.a[3]) % P;       return res;     }   };   struct SegmentTree {     const int n;     std::vector<int> a;     std::vector<Matrix> t;     SegmentTree(const std::vector<int> &a) : n(a.size()), a(a), t(4 * n) {       build(1, 0, n);     }     void build(int p, int l, int r) {       if (r - l == 1) {         t[p].a[0] = a[l] + 1;         t[p].a[1] = 1;         t[p].a[2] = (l && a[l - 1] == 1) ? (9 - a[l]) : 0;       } else {         int m = (l + r) / 2;         build(2 * p, l, m);         build(2 * p + 1, m, r);         t[p] = t[2 * p] * t[2 * p + 1];       }     }     void update(int p, int l, int r, int x) {       if (r - l == 1) {         t[p].a[0] = a[l] + 1;         t[p].a[2] = (l && a[l - 1] == 1) ? (9 - a[l]) : 0;       } else {         int m = (l + r) / 2;         if (x < m) {           update(2 * p, l, m, x);         } else {           update(2 * p + 1, m, r, x);         }         t[p] = t[2 * p] * t[2 * p + 1];       }     }     void modify(int x, int y) {       a[x] = y;       update(1, 0, n, x);       if (x + 1 < n) update(1, 0, n, x + 1);     }     int query() { return t[1].a[0]; }   };   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int n, m;     std::cin >> n >> m;     std::vector<int> a(n);     for (int i = 0; i < n; ++i) {       char c;       std::cin >> c;       a[i] = c -  0 ;     }     SegmentTree t(a);     while (m--) {       int x, y;       std::cin >> x >> y;       --x;       t.modify(x, y);       std::cout << t.query() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int a[205], b[105];   set<int> st;   int n;   void solve() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     st.clear();     for (int i = 1; i <= 2 * n; i++) st.insert(i);     for (int i = 1; i <= n; i++) {       st.erase(b[i]);     }     if (st.size() != n) {       cout << -1 << endl;       return;     }     for (int i = 1; i <= n; i++) {       a[2 * i - 1] = b[i];     }     for (int i = 2; i <= 2 * n; i += 2) {       auto tmp = st.upper_bound(a[i - 1]);       if (tmp == st.end()) {         cout << -1 << endl;         return;       }       a[i] = *tmp;       st.erase(tmp);     }     for (int i = 1; i <= 2 * n; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100005;   const double eps = 1e-8, Pi = acos(-1.0);   int n;   double a, x[Maxn], y[Maxn], dis[Maxn];   pair<double, double> pos[Maxn];   priority_queue<double, vector<double>, greater<double> > Pr;   bool check(double r) {     int m = 0;     for (int i = 1; i <= n; i++) {       double l = sqrt((x[i] - a) * (x[i] - a) + y[i] * y[i]);       if (l > dis[i] + r || dis[i] > l + r || r > dis[i] + l) continue;       double p = atan2(y[i], x[i] - a);       double range = acos((l * l + r * r - dis[i] * dis[i]) / (2 * l * r));       double L = p - range, R = p + range;       if (L < -Pi) L += 2 * Pi;       if (L > Pi) L -= 2 * Pi;       if (R < -Pi) R += 2 * Pi;       if (R > Pi) R -= 2 * Pi;       if (L > R) swap(L, R);       pos[++m] = make_pair(L, R);     }     sort(pos + 1, pos + 1 + m);     while (!Pr.empty()) Pr.pop();     for (int i = 1; i <= m; i++) {       while (!Pr.empty() && Pr.top() < pos[i].first) Pr.pop();       if (!Pr.empty() && Pr.top() <= pos[i].second) return true;       Pr.push(pos[i].second);     }     return false;   }   int main() {     scanf( %d%lf , &n, &a);     for (int i = 1; i <= n; i++)       scanf( %lf%lf , &x[i], &y[i]),           dis[i] = sqrt((x[i] + a) * (x[i] + a) + y[i] * y[i]);     double l = 0, r = 2 * a;     while (r - l >= eps) {       double mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %.10lf , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long small(char a, char b) {     return min(abs(a - b), min(a + 26 - b, b + 26 - a));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, pos;     cin >> n >> pos;     string x;     cin >> x;     bool gotomid = 0;     int mid = n / 2;     if (pos > mid) {       pos = n - pos + 1;     }     long long res = small(x[pos - 1], x[n - pos]);     int right = -1, left = 1e5;     for (int i = mid - 1; i >= pos; i--)       if (x[i] != x[n - 1 - i]) {         right = i;         break;       }     for (int i = 0; i < pos - 1; i++)       if (x[i] != x[n - 1 - i]) {         left = i;         break;       }     if (left == 1e5 && right == -1)       cout << res;     else if (left != 1e5 && right == -1) {       for (int i = left; i < pos - 1; i++)         if (x[i] != x[n - 1 - i]) res += small(x[i], x[n - 1 - i]);       res += pos - 1 - left;       cout << res;     } else if (left == 1e5 && right != -1) {       for (int i = right; i >= pos; i--)         if (x[i] != x[n - 1 - i]) res += small(x[i], x[n - 1 - i]);       res += right - (pos - 1);       cout << res;     } else {       for (int i = left; i < pos - 1; i++)         if (x[i] != x[n - 1 - i]) res += small(x[i], x[n - 1 - i]);       for (int i = right; i >= pos; i--)         if (x[i] != x[n - 1 - i]) res += small(x[i], x[n - 1 - i]);       res += 2 * min(pos - 1 - left, right - (pos - 1)) +              max(pos - 1 - left, right - (pos - 1));       cout << res;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, w[100010], in1, in2, in3;   double ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &w[i]);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &in1, &in2, &in3);       ans = max(ans, (w[in1] + w[in2]) * 1.0 / in3);     }     printf( %.15lf n , ans);     return 0;   }