#include <iostream>   #include <cstdio>   #include <cmath>   #include <ctime>   #include <cstdlib>   #include <cassert>   #include <vector>   #include <list>   #include <stack>   #include <queue>   #include <deque>   #include <map>   #include <set>   #include <bitset>   #include <string>   #include <algorithm>   #include <utility>   #include <complex>   #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)   #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++)   #define chmin(x, y) (x) = min((x), (y))   #define chmax(x, y) (x) = max((x), (y))   #define sz(x) ((ll)(x).size())   #define ceil(x, y) (((x)+(y)-1) / (y))   #define all(x) (x).begin(),(x).end()   #define outl(...) dump_func(__VA_ARGS__)   #define inf 1e18      using namespace std;      typedef long long llint;   typedef long long ll;   typedef pair<ll, ll> P;      struct edge{    ll to, cost;    edge(){}    edge(ll a, ll b){ to = a, cost = b;}   };   const ll dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};      const ll mod = 1000000007;   //const ll mod = 998244353;      struct mint{    ll x = 0;    mint(ll y = 0){x = y; if(x < 0 || x >= mod) x = (x%mod+mod)%mod;}    mint(const mint &ope) {x = ope.x;}        mint operator-(){return mint(-x);}    mint operator+(const mint &ope){return mint(x) += ope;}    mint operator-(const mint &ope){return mint(x) -= ope;}    mint operator*(const mint &ope){return mint(x) *= ope;}    mint operator/(const mint &ope){return mint(x) /= ope;}    mint& operator+=(const mint &ope){     x += ope.x;     if(x >= mod) x -= mod;     return *this;    }    mint& operator-=(const mint &ope){     x += mod - ope.x;     if(x >= mod) x -= mod;     return *this;    }    mint& operator*=(const mint &ope){     x *= ope.x, x %= mod;     return *this;    }    mint& operator/=(const mint &ope){     ll n = mod-2; mint mul = ope;     while(n){      if(n & 1) *this *= mul;      mul *= mul;      n >>= 1;     }     return *this;    }    mint inverse(){return mint(1) / *this;}    bool operator ==(const mint &ope){return x == ope.x;}    bool operator !=(const mint &ope){return x != ope.x;}   };   mint modpow(mint a, ll n){    if(n == 0) return mint(1);    if(n % 2) return a * modpow(a, n-1);    else return modpow(a*a, n/2);   }   istream& operator >>(istream &is, mint &ope){    ll t; is >> t, ope.x = t;    return is;   }   ostream& operator <<(ostream &os, mint &ope){return os << ope.x;}   ostream& operator <<(ostream &os, const mint &ope){return os << ope.x;}      bool exceed(ll x, ll y, ll m){return x >= m / y + 1;}   void mark(){ cout <<  *  << endl; }   void yes(){ cout <<  Yes  << endl; }   void no(){ cout <<  No  << endl; }   ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a%b);}   ll digitnum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret++; return ret;}   ll digitsum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret += x % b; return ret;}      template<typename T>   ostream& operator << (ostream& os, vector<T>& vec) {    for(int i = 0; i < vec.size(); i++) {     os << vec[i] << (i + 1 == vec.size() ?    :    );    }    return os;   }   template<typename T>   ostream& operator << (ostream& os, deque<T>& deq) {    for(int i = 0; i < deq.size(); i++) {     os << deq[i] << (i + 1 == deq.size() ?    :    );    }    return os;   }   template<typename T, typename U>   ostream& operator << (ostream& os, pair<T, U>& pair_var) {    os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ;    return os;   }   template<typename T, typename U>   ostream& operator << (ostream& os, const pair<T, U>& pair_var) {    os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ;    return os;   }   template<typename T, typename U>   ostream& operator << (ostream& os, map<T, U>& map_var) {    for(typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); itr++) {     os <<  (  << itr->first <<  ,   << itr->second <<  ) ;     itr++;     if(itr != map_var.end()) os <<  , ;     itr--;    }    return os;   }   template<typename T>   ostream& operator << (ostream& os, set<T>& set_var) {    for(typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) {     os << *itr;     ++itr;     if(itr != set_var.end()) os <<    ;     itr--;    }    return os;   }   template<typename T>   ostream& operator << (ostream& os, multiset<T>& set_var) {    for(typename multiset<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) {     os << *itr;     ++itr;     if(itr != set_var.end()) os <<    ;     itr--;    }    return os;   }   template<typename T>   void outa(T a[], ll s, ll t)   {    for(ll i = s; i <= t; i++){ cout << a[i]; if(i < t) cout <<    ;}    cout << endl;   }   void dump_func() {cout << endl;}   template <class Head, class... Tail>   void dump_func(Head &&head, Tail &&... tail) {    cout << head;    if(sizeof...(Tail) > 0) cout <<    ;    dump_func(std::move(tail)...);   }      struct SegTree{    typedef ll SEG;        int size;    vector<SEG> seg;        SegTree(){}    SegTree(int size){     this->size = size;     seg.resize(1<<(size+1));    }        SEG Ident(){  //identity element     return inf;    }    SEG ope(SEG a, SEG b){ //operator     return min(a, b);    }        void init()    {     for(int i = 0; i < (1<<(size+1)); i++) seg[i] = Ident();    }        void update(int i, SEG val)    {     i += (1 << size);     seg[i] = val;     while(i > 1){      i /= 2;      seg[i] = ope(seg[i*2], seg[i*2+1]);     }    }       SEG query(int a, int b, int k, int l, int r)    {     if(b < l || r < a) return Ident();     if(a <= l && r <= b) return seg[k];     SEG lval = query(a, b, k*2, l, (l+r)/2);     SEG rval = query(a, b, k*2+1, (l+r)/2+1, r);     return ope(lval, rval);    }    SEG query(int a, int b)    {     if(a > b) return Ident();     return query(a, b, 1, 0, (1<<size)-1);    }   };      ll n, m;   ll a[200005], b[200005];   vector<ll> comp;   vector<P> vec[400005], qvec[400005];   SegTree seg(19);      int main(void)   {    ios::sync_with_stdio(0);    cin.tie(0);        cin >> n;    rep(i, 1, n) cin >> a[i];    rep(i, 1, n) cin >> b[i];        rep(i, 1, n) comp.push_back(a[i]), comp.push_back(b[i]);    sort(all(comp));    comp.erase(unique(all(comp)), comp.end());    rep(i, 1, n){     a[i] = lower_bound(all(comp), a[i]) - comp.begin();     b[i] = lower_bound(all(comp), b[i]) - comp.begin();    }    m = sz(comp);        ll ans = 0;        rep(i, 0, m) vec[i].clear(), qvec[i].clear(); //++    rep(i, 1, n){     ll A = comp[a[i]], B = comp[b[i]];     vec[a[i]].push_back(P(b[i], A - B - abs(A-B)));     qvec[b[i]].push_back(P(a[i], A - B - abs(A-B)));    }    seg.init();    for(int i = m; i >= 0; i--){     for(auto p : vec[i]){      ll x = seg.query(p.first, p.first);      chmin(x, p.second);      seg.update(p.first, x);     }     for(auto p : qvec[i]){      chmin(ans, seg.query(0, p.first) + p.second);     }    }        rep(i, 0, m) vec[i].clear(), qvec[i].clear(); //+-    rep(i, 1, n){     ll A = comp[a[i]], B = comp[b[i]];     vec[a[i]].push_back(P(b[i], - A - B - abs(A-B)));     qvec[b[i]].push_back(P(a[i], A + B - abs(A-B)));    }    seg.init();    for(int i = 0; i <= m; i++){     for(auto p : vec[i]){      ll x = seg.query(p.first, p.first);      chmin(x, p.second);      seg.update(p.first, x);     }     for(auto p : qvec[i]){      chmin(ans, seg.query(0, p.first) + p.second);     }    }        rep(i, 0, m) vec[i].clear(), qvec[i].clear(); //--    rep(i, 1, n){     ll A = comp[a[i]], B = comp[b[i]];     vec[a[i]].push_back(P(b[i], - A + B - abs(A-B)));     qvec[b[i]].push_back(P(a[i], - A + B - abs(A-B)));    }    seg.init();    for(int i = 0; i <= m; i++){     for(auto p : vec[i]){      ll x = seg.query(p.first, p.first);      chmin(x, p.second);      seg.update(p.first, x);     }     for(auto p : qvec[i]){      chmin(ans, seg.query(p.first, m) + p.second);     }    }        rep(i, 1, n) ans += abs(comp[a[i]]-comp[b[i]]);    outl(ans);        return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, k, ans = 0, fa = 0, c = 0;     cin >> n >> k;     c = (n * (n + 1)) / 2;     c -= k;     c -= n;     while (c > 0) {       fa++;       c -= n;       n--;     }     cout << fa;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int x[105], y[105];   int ans;   bool judge(int x1, int x2, int y1, int y2) {     if (x1 + x2 <= a && max(y1, y2) <= b) {       return 1;     }     if (x1 + x2 <= b && max(y1, y2) <= a) {       return 1;     }     if (x1 + y2 <= a && max(y1, x2) <= b) {       return 1;     }     if (x1 + y2 <= b && max(y1, x2) <= a) {       return 1;     }     if (y1 + x2 <= a && max(x1, y2) <= b) {       return 1;     }     if (y1 + x2 <= b && max(x1, y2) <= a) {       return 1;     }     if (y1 + y2 <= a && max(x1, x2) <= b) {       return 1;     }     if (y1 + y2 <= b && max(x1, x2) <= a) {       return 1;     }     return 0;   }   int main() {     int i, j;     cin >> n >> a >> b;     for (i = 1; i <= n; i++) {       cin >> x[i] >> y[i];     }     for (i = 1; i <= n; i++) {       for (j = 1; j < i; j++) {         if (judge(x[i], x[j], y[i], y[j]) == 1) {           ans = max(ans, x[i] * y[i] + x[j] * y[j]);         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char i = getchar();     long long f = 1, res = 0;     while (i <  0  || i >  9 ) {       if (i ==  - ) f = -1;       i = getchar();     }     while (i >=  0  && i <=  9 ) {       res = res * 10 + i -  0 ;       i = getchar();     }     return f * res;   }   const int N = 50005;   int dp[N];   int n, K;   int a[N], pre[N], pos[N];   int maxn[N << 2], lazy[N << 2];   inline void pushup(int rt) { maxn[rt] = max(maxn[rt << 1], maxn[rt << 1 | 1]); }   inline void pushdown(int rt) {     if (lazy[rt]) {       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       maxn[rt << 1] += lazy[rt];       maxn[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }   }   inline void update(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       maxn[rt] += 1;       lazy[rt] += 1;       return;     }     int mid = (l + r) >> 1;     pushdown(rt);     if (L <= mid) update(L, R, l, mid, rt << 1);     if (R > mid) update(L, R, mid + 1, r, rt << 1 | 1);     pushup(rt);   }   inline int query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       return maxn[rt];     }     int mid = (l + r) >> 1;     int res = 0;     pushdown(rt);     if (L <= mid) res = max(res, query(L, R, l, mid, rt << 1));     if (R > mid) res = max(res, query(L, R, mid + 1, r, rt << 1 | 1));     return res;   }   inline void build(int l, int r, int rt) {     lazy[rt] = 0;     if (l == r) {       maxn[rt] = dp[l - 1];       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushup(rt);   }   int main() {     n = read(), K = read();     for (int i = 1; i <= n; ++i) {       a[i] = read();       pos[i] = pre[a[i]] + 1;       pre[a[i]] = i;     }     memset(pre, -1, sizeof pre);     for (int i = 1; i <= K; ++i) {       build(1, n, 1);       for (int j = 1; j <= n; ++j) {         update(pos[j], j, 1, n, 1);         dp[j] = query(1, j, 1, n, 1);       }     }     cout << dp[n] << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmin(T &first, T second) {     return second < first ? first = second, 1 : 0;   }   template <typename T>   bool chkmax(T &first, T second) {     return first < second ? first = second, 1 : 0;   }   template <typename T>   void readint(T &first) {     first = 0;     int f = 1;     char c;     for (c = getchar(); !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) first = first * 10 + (c -  0 );     first *= f;   }   const int MOD = 1000000007, INV3 = (MOD + 1) / 3;   inline int dmy(int first) { return first >= MOD ? first - MOD : first; }   inline void inc(int &first, int second) { first = dmy(first + second); }   int qmi(int first, int second) {     int ans = 1;     for (; second; second >>= 1, first = 1ll * first * first % MOD)       if (second & 1) ans = 1ll * ans * first % MOD;     return ans;   }   const int MAXN = 6005;   int n;   int cnt[4][4];   int main() {     readint(n);     for (int i = 1, first, second; i <= n; ++i)       readint(first), readint(second), ++cnt[first & 3][second & 3];     long long res = 0;     for (int i = 0; i <= 3; ++i)       for (int j = 0; j <= 3; ++j)         res += 1ll * cnt[i][j] * (cnt[i][j] - 1) / 2 * (n - cnt[i][j]) +                1ll * cnt[i][j] * (cnt[i][j] - 1) * (cnt[i][j] - 2) / 6;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, head[100000 + 5], sz[100000 + 5], cnt = 1;   double ans[100000 + 5];   struct edges {     int to, next;   } e[2 * 100000 + 5];   inline void insert(int x) {     int u = x, v;     scanf( %d , &v);     e[++cnt] = (edges){u, head[v]};     head[v] = cnt;     e[++cnt] = (edges){v, head[u]};     head[u] = cnt;   }   void dfs(int x, int fa) {     sz[x] = 1;     for (int i = head[x]; i; i = e[i].next) {       if (e[i].to == fa) continue;       dfs(e[i].to, x);       sz[x] += sz[e[i].to];     }   }   void dfs1(int x, int fa) {     for (int i = head[x]; i; i = e[i].next) {       if (e[i].to == fa) continue;       ans[e[i].to] = 1.0 * (sz[x] - 1 - sz[e[i].to]) / 2.0 + 1.0 + ans[x];       dfs1(e[i].to, x);     }   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) insert(i);     dfs(1, 0);     ans[1] = 1;     dfs1(1, 0);     for (int i = 1; i <= n; i++) printf( %.7lf n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c, b;     long ans = 0;     cin >> n >> m;     long a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> c >> b;       ans += min(a[c], a[b]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct segment {     int l, r, fu;     bool operator<(const segment &temp) const { return l < temp.l; }   };   segment sg[5000];   int cnt_sg;   const int inf = 1e9;   int xx[400], yy[400];   int cnt_x, cnt_y;   struct rectangle {     int lx, ly, rx, ry;   };   rectangle rec[99];   int n, m, k, cnt, mc[1111][1111], nc[1111][11111], list[99], cnt_list, ls[99],       cnt_ls;   long long ans, now;   char str[1111][1111];   bool vsx[400], vsy[400];   int main() {     int i, j, s, p, q, id, dx1, dx2, dy1, dy2, lx, ly, rx, ry, pn;     scanf( %d%d%d , &n, &m, &k);     for (i = 0; i < n; i++) scanf( %s , str[i]);     cnt = 0;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         if (str[i][j] ==  *  && !(i > 0 && str[i - 1][j] ==  * ) &&             !(j > 0 && str[i][j - 1] ==  * )) {           rec[cnt].lx = i;           rec[cnt].ly = j;           for (s = i; s < n; s++) {             for (p = j; p < m; p++) {               if (str[s][p] !=  * ) break;             }             if (p == j) break;             rec[cnt].ry = p - 1;           }           rec[cnt++].rx = s - 1;         }       }     memset(mc, 0, sizeof(mc));     memset(nc, 0, sizeof(nc));     for (i = 0; i < k; i++) mc[rec[i].lx][rec[i].ly]++;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         mc[i + 1][j] += mc[i][j];         mc[i][j + 1] += mc[i][j];         mc[i + 1][j + 1] -= mc[i][j];       }     cnt_x = cnt_y = 0;     for (i = 0; i < k; i++) {       xx[cnt_x++] = rec[i].lx;       xx[cnt_x++] = rec[i].rx;       if (rec[i].lx - 1 >= 0) xx[cnt_x++] = rec[i].lx - 1;       if (rec[i].rx + 1 < n) xx[cnt_x++] = rec[i].rx + 1;       yy[cnt_y++] = rec[i].ly;       yy[cnt_y++] = rec[i].ry;       if (rec[i].ly - 1 >= 0) yy[cnt_y++] = rec[i].ly - 1;       if (rec[i].ry + 1 < m) yy[cnt_y++] = rec[i].ry + 1;     }     sort(xx, xx + cnt_x);     sort(yy, yy + cnt_y);     int nn = 0;     for (i = 0; i < cnt_x; i++) {       if (nn == 0 || xx[nn - 1] < xx[i]) xx[nn++] = xx[i];     }     cnt_x = nn;     nn = 0;     for (i = 0; i < cnt_y; i++) {       if (nn == 0 || yy[nn - 1] < yy[i]) yy[nn++] = yy[i];     }     cnt_y = nn;     ans = 0;     for (i = 0; i < cnt_x; i++) {       if (i == 0)         dx1 = xx[i] + 1;       else         dx1 = xx[i] - xx[i - 1];       for (j = i + 1; j <= cnt_x; j++) {         if (j == cnt_x)           dx2 = n - xx[j - 1];         else           dx2 = xx[j] - xx[j - 1];         cnt_sg = 0;         for (s = 0; s < k; s++) {           if (rec[s].rx < xx[i] || rec[s].lx > xx[j - 1]) continue;           if ((rec[s].rx >= xx[i] && rec[s].lx < xx[i]) ||               (rec[s].rx > xx[j - 1] && rec[s].lx <= xx[j - 1]))             sg[cnt_sg].fu = 1;           else             sg[cnt_sg].fu = 0;           sg[cnt_sg].l = rec[s].ly;           sg[cnt_sg++].r = rec[s].ry;         }         sort(sg, sg + cnt_sg);         nn = 0;         for (s = 0; s < cnt_sg; s++) {           if (nn == 0 || sg[nn - 1].r < sg[s].l)             sg[nn++] = sg[s];           else if (sg[nn - 1].r < sg[s].r) {             sg[nn - 1].r = sg[s].r;             sg[nn - 1].fu = max(sg[nn - 1].fu, sg[s].fu);           }         }         cnt_sg = nn;         for (s = 1; s <= cnt_sg; s++) {           if (s < cnt_sg)             dy2 = sg[s].l - sg[s - 1].r;           else             dy2 = m - sg[s - 1].r;           pn = 0;           for (p = s - 1; p >= 0; p--) {             lx = xx[i];             ly = sg[p].l;             rx = xx[j - 1];             ry = sg[s - 1].r;             int rs = mc[rx][ry];             if (lx > 0) rs -= mc[lx - 1][ry];             if (ly > 0) rs -= mc[rx][ly - 1];             if (lx > 0 && ly > 0) rs += mc[lx - 1][ly - 1];             if (rs > 3 || sg[p].fu == 1) break;             if (rs == 0) continue;             if (p == 0)               dy1 = sg[p].l + 1;             else               dy1 = sg[p].l - sg[p - 1].r;             for (q = 0; q < k; q++) {               if (rec[q].lx >= lx && rec[q].rx <= rx && rec[q].ly >= ly &&                   rec[q].ry <= ry)                 continue;               if (rec[q].lx <= rx && rec[q].rx >= xx[i] && rec[q].ly <= ry &&                   rec[q].ry >= ly)                 break;             }             if (q >= k) pn += dy1;           }           ans += (long long)pn * (long long)dy2 * (long long)dx1 * (long long)dx2;         }       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double num, a, b, c, d, e, f, r1, r2;     double m1, m2, m3;     while (cin >> a >> b >> c >> d >> e >> f) {       if (d == 0) {         cout <<  Hermione  << endl;         continue;       }       if (c == 0) {         cout <<  Ron  << endl;         continue;       }       if (b == 0) {         cout <<  Hermione  << endl;         continue;       }       if (a == 0) {         cout <<  Ron  << endl;         continue;       }       if (f != 0 && e == 0) {         cout <<  Ron  << endl;         continue;       }       num = 500;       r1 = 0;       r2 = 0;       m1 = b / a;       m2 = d / c;       m3 = e / f;       r1 = num * m1 * m2;       r2 = num * m3;       if (r1 > r2) {         cout <<  Ron  << endl;       } else {         cout <<  Hermione  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vii = vector<ii>;   double x;   int main() {     cin >> x;     for (double a = 1; a <= 10; a++) {       for (double h = 1; h <= 10; h++) {         double cr = -h * a / 2;         double r = -cr / sqrt(a * a / 4 + h * h);         if (fabs(r - x) < 1e-5) {           cout << a <<     << h << endl;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int f[n], b[m], a[m];     map<int, int> x;     for (int i = 0; i < n; i++) {       scanf( %d , &f[i]);       if (x.find(f[i]) != x.end())         x[f[i]] = -1;       else         x[f[i]] = i;     }     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     sort(f, f + n);     bool y = 0, z = 0;     for (int i = 0; i < m; i++) {       if (x.find(b[i]) != x.end()) {         if (x[b[i]] == -1) {           z = 1;         } else {           a[i] = x[b[i]];         }       } else {         printf( Impossible );         y = 1;         break;       }     }     if (!y) {       if (z) {         printf( Ambiguity );       } else {         printf( Possible n );         for (int i = 0; i < m; i++) {           printf( %d , a[i] + 1);           printf(   );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MXN = 1e5 + 20;   int n, a[MXN], b[MXN], c[MXN];   vector<int> ans;   void IN() {     int tmp;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tmp;       a[i] = tmp;     }     for (int i = 0; i < n - 1; i++) {       cin >> tmp;       b[i] = tmp;     }     for (int i = 0; i < n - 2; i++) {       cin >> tmp;       c[i] = tmp;     }   }   void SLV() {     sort(a, a + n);     sort(b, b + n - 1);     sort(c, c + n - 2);     for (int i = 0; i < n; i++)       if (b[i] != a[i]) {         ans.push_back(a[i]);         break;       }     for (int i = 0; i < n; i++)       if (c[i] != b[i]) {         ans.push_back(b[i]);         break;       }   }   void OUT() {     for (auto i : ans) cout << i << endl;   }   int main() {     IN();     SLV();     OUT();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using matrix = vector<vector<long long>>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int x, l, n, q;     cin >> x >> l >> n >> q;     int log_n = 0;     while ((1 << log_n) <= n) {       ++log_n;     }     vector<int> c(l + 1);     for (int i = 1; i <= l; ++i) {       cin >> c[i];     }     map<int, int> stones;     vector<int> stops = {n - x};     for (int i = 0; i < q; ++i) {       int p, w;       cin >> p >> w;       stones[p] = w;       for (int j = 1; j <= l; ++j) {         stops.push_back(p - j);       }     }     sort(stops.begin(), stops.end());     while (stops.back() > n - x) {       stops.pop_back();     }     vector<matrix> pow_matrix(log_n);     pow_matrix[0].assign(1 << l, vector<long long>(1 << l, LLONG_MAX / 2));     for (int i = 0; i < (1 << l); ++i) {       if ((i & 1) == 0) {         pow_matrix[0][i][i >> 1] = 0;       } else {         for (int j = 1; j <= l; ++j) {           if ((i & (1 << j)) == 0) {             pow_matrix[0][i][(i ^ (1 << j)) >> 1] = c[j];           }         }       }     }     auto mul = [](const matrix& a, const matrix& b) -> matrix {       int n = a.size();       matrix c(n, vector<long long>(n, LLONG_MAX / 2));       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           for (int k = 0; k < n; ++k) {             c[i][k] = min(c[i][k], a[i][j] + b[j][k]);           }         }       }       return c;     };     for (int i = 1; i < log_n; ++i) {       pow_matrix[i] = mul(pow_matrix[i - 1], pow_matrix[i - 1]);     }     auto mul_vector = [](const matrix& a,                          const vector<long long>& b) -> vector<long long> {       int n = a.size();       vector<long long> c(n, LLONG_MAX / 2);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           c[j] = min(c[j], a[i][j] + b[i]);         }       }       return c;     };     vector<long long> dp(1 << l, LLONG_MAX / 2);     dp[(1 << x) - 1] = 0;     int pos = 1;     for (auto i : stops) {       if (i < pos) {         continue;       }       for (int j = log_n - 1; j >= 0; --j) {         if (pos + (1 << j) <= i) {           dp = mul_vector(pow_matrix[j], dp);           pos += 1 << j;         }       }       vector<long long> dp_new(1 << l, LLONG_MAX / 2);       for (int j = 0; j < (1 << l); ++j) {         if ((j & 1) == 0) {           dp_new[j >> 1] = min(dp_new[j >> 1], dp[j]);         } else {           for (int k = 1; k <= l; ++k) {             if ((j & (1 << k)) == 0) {               long long cost = dp[j] + c[k];               if (stones.count(pos + k)) {                 cost += stones[pos + k];               }               int mask = (j ^ (1 << k)) >> 1;               dp_new[mask] = min(dp_new[mask], cost);             }           }         }       }       dp = dp_new;       ++pos;     }     cout << dp[(1 << x) - 1] <<   n ;   }


#include <bits/stdc++.h>   double eps = 1e-6;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     long long p, a[100010], b[100010];     long long sum = 0;     cin >> n >> p;     for (int i = 0; i < n; ++i) {       cin >> a[i] >> b[i];       sum += a[i];     }     if (p >= sum) {       cout << -1 << endl;       return 0;     }     double lo = 0;     double hi = 1e17;     double mx = 0;     for (int var = 0; var < 100; ++var) {       mx = lo + (hi - lo) / 2;       double need = 0;       for (int i = 0; i < n; ++i) {         need += max(mx * a[i] - b[i], 0 * 1.0);       }       if (p * mx >= need) {         lo = mx + eps;       } else {         hi = mx - eps;       }     }     printf( %.9f n , lo);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, f[1050000], a[1050000], b[1050000], mp[21][100005], ans;   void fwt(long long a[], long long n, long long f) {     for (long long i = 1; i < 1 << n; i <<= 1) {       for (long long t = 0; t < 1 << n; t++) {         if (i & t) {           long long x = a[t - i], y = a[t];           a[t - i] = x + y;           a[t] = x - y;         }       }     }     if (f == -1) {       for (long long i = 0; i < 1 << n; i++) a[i] = a[i] / (1 << n);     }   }   long long get(long long x) {     long long num = 0;     while (x) {       if (x % 2 == 1) num++;       x /= 2;     }     return num;   }   int main() {     scanf( %lld%lld , &n, &m);     ans = n * m;     f[1] = 1;     for (long long i = 2; i <= n; i++) {       f[i] = f[i - 1] * 2;     }     for (long long i = 1; i <= n; i++) {       for (long long t = 1; t <= m; t++) {         char s;         cin >> s;         if (s ==  1 )           mp[i][t] = 1;         else           mp[i][t] = 0;       }     }     for (long long i = 1; i <= m; i++) {       long long x = 0;       for (long long t = 1; t <= n; t++) {         if (mp[t][i] == 1) x += f[t];       }       a[x]++;     }     for (long long i = 0; i < 1 << n; i++) {       long long x = get(i);       b[i] = min(x, n - x);     }     fwt(a, n, 1);     fwt(b, n, 1);     for (long long i = 0; i < 1 << n; i++) {       a[i] = a[i] * b[i];     }     fwt(a, n, -1);     for (long long i = 0; i < 1 << n; i++) {       ans = min(ans, a[i]);     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, sum = 0;     while (cin >> n) {       for (int i = 0; i < (n); ++i) {         int x;         cin >> x;         sum += x;       }       if (sum % n)         cout << n - 1 <<   n ;       else         cout << n <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, t, n;     cin >> t;     while (t--) {       cin >> n;       long long arr[n];       for (i = 0; i < n; i++) {         cin >> arr[i];       }       reverse(arr, arr + n);       for (i = 0; i < n - 1; i++) {         cout << arr[i] <<    ;       }       cout << arr[n - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int mxm = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n], i;       set<long long int> x;       for (i = 0; i < n; i++) {         cin >> a[i];         x.insert(i + 1);       }       sort(a, a + n);       for (i = 0; i < n; i++) {         if (x.count(a[i])) {           x.erase(a[i]);           a[i] = 0;         }       }       long long int ans = 0;       sort(a, a + n);       for (i = 0; i < n; i++) {         if (a[i] > 0) {           if (2 * (*x.begin()) < a[i]) {             x.erase(x.begin());             ans++;           } else {             ans = -1;             break;           }         }       }       cout << (ans) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     while (cin >> n >> d) {       int A[n], ans = 0;       for (int i = 0; i < n; i++) cin >> A[i];       for (int i = 1; i < n; i++) {         if (A[i] <= A[i - 1]) {           int rest = A[i - 1] - A[i], cnt = (rest / d) + 1;           A[i] += cnt * d;           ans += cnt;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long INF = (long long)5e18;   const int MOD = 998244353;   int add(int x, int y) {     x += y;     return x >= MOD ? x - MOD : x;   }   int sub(int x, int y) {     x -= y;     return x < 0 ? x + MOD : x;   }   int qpow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = (long long)(ret) * (x) % MOD;       x = (long long)(x) * (x) % MOD;       y >>= 1;     }     return ret;   }   void checkmin(int &x, int y) {     if (x > y) x = y;   }   void checkmax(int &x, int y) {     if (x < y) x = y;   }   void checkmin(long long &x, long long y) {     if (x > y) x = y;   }   void checkmax(long long &x, long long y) {     if (x < y) x = y;   }   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   const int N = 5005;   int n, a[N], dp[N];   int fac[N], ifac[N], lim[N];   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (long long)(fac[i - 1]) * (i) % MOD;     ifac[n] = qpow(fac[n], MOD - 2);     for (int i = n - 1; i >= 0; i--)       ifac[i] = (long long)(ifac[i + 1]) * (i + 1) % MOD;     for (int i = 1; i <= n; i++) {       for (int j = i - 1; j >= 1; j--) {         if (a[j] * 2 <= a[i]) {           lim[i] = j;           break;         }       }     }   }   void solve() {     dp[0] = 1;     if (a[n] < a[n - 1] * 2) {       puts( 0 );       return;     }     for (int i = 1; i <= n; i++) {       for (int j = lim[i]; j >= 0; j--) {         int delta = lim[i] - lim[j] - 1, rest = n - lim[j] - 2;         if (j == 0) delta++, rest++;         dp[i] =             add(dp[i], (long long)(dp[j]) *                            ((long long)(fac[rest]) * (ifac[rest - delta]) % MOD) %                            MOD);       }     }     cout << dp[n] << endl;   }   int main() {     init();     solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long fpow(long long b, long long p) {     if (b == 0) return 0;     long long ans = 1;     while (p) {       if (p & 1) ans = ans * b % (998244353);       b = b * b % (998244353);       p /= 2;     }     return ans;   }   struct BIT {     long long n;     long long a[150050];     void init(long long _n) {       n = _n;       memset(a, 0, sizeof(a));     }     void add(long long i, long long x) {       while (i <= n) {         a[i] += x;         if (a[i] >= (998244353)) a[i] -= (998244353);         i += (i & (-i));       }     }     long long ask(long long l, long long r) {       long long ans = 0;       while (r > 0) {         ans += a[r];         r -= (r & (-r));       }       l--;       while (l > 0) {         ans -= a[l];         l -= (l & (-l));       }       return ans % (998244353);     }   } bit;   long long N, N1;   long long addall = 0;   vector<long long> adj[150010];   long long sz[150010];   long long p[150010];   long long nxt[150010];   long long id[150010];   long long head[150010];   long long add[150010];   long long info(long long n, long long par) {     sz[n] = 1;     p[n] = par;     pair<long long, long long> mx(0, 0);     for (auto &i : adj[n])       if (i != par) {         mx = max(mx, make_pair(info(i, n), i));         sz[n] += sz[i];       }     nxt[n] = mx.second;     return sz[n];   }   void hld(long long n, long long h) {     static long long nowid = 1;     id[n] = nowid;     nowid++;     head[n] = h;     if (nxt[n] != 0) hld(nxt[n], h);     for (auto &i : adj[n])       if (i != p[n] && i != nxt[n]) {         hld(i, i);       }   }   long long ask(long long n) {     long long ans = addall + add[n];     while (n != 0) {       ans += bit.ask(id[head[n]], id[n]);       n = head[n];       ans = (ans + add[p[n]] * (N - sz[n]) % (998244353) * N1) % (998244353);       n = p[n];     }     return ans;   }   signed main() {     {       ;       ;       ;       ios::sync_with_stdio(false);       cin.tie(0);       ;       ;       ;     }     cin >> N;     long long q;     cin >> q;     N1 = fpow(N, (998244353) - 2);     for (long long i = 1; i <= N - 1; i++) {       long long a, b;       cin >> a >> b;       adj[a].emplace_back(b);       adj[b].emplace_back(a);     }     bit.init(N);     info(1, 0);     hld(1, 1);     while (q--) {       long long op;       cin >> op;       if (op == 1) {         long long v, x;         cin >> v >> x;         addall = (addall + x * sz[v] % (998244353) * N1) % (998244353);         add[v] = (add[v] + x) % (998244353);         bit.add(id[v], -x * sz[v] % (998244353) * N1 % (998244353));         if (nxt[v] != 0) {           bit.add(id[nxt[v]],                   x * (N - sz[nxt[v]]) % (998244353) * N1 % (998244353));         }       } else {         long long v;         cin >> v;         long long ans = addall + add[v];         while (v != 0) {           ans += bit.ask(id[head[v]], id[v]);           v = head[v];           ans = (ans + add[p[v]] * (N - sz[v]) % (998244353) * N1) % (998244353);           v = p[v];         }         cout << (ans + (998244353)) % (998244353) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 210000;   vector<int> p[N];   bool vis[N], inq[N];   int fa[N], froot[N], troot[N], size[N], q[N], powk[N], val[N], in0[N], out0[N],       in1[N], out1[N], n, jsb, goal, k, dep[N], inv[N];   inline int Pow(int a, int b) {     int c = 1;     for (; b; b >>= 1, a = a * 1ll * a % jsb)       if (b & 1) c = c * 1ll * a % jsb;     return c;   }   const int mo = 100007;   struct state {     int head[N], np[N], p[N], cnt[N];     int tot;     inline void clear() {       for (int i = (1); i <= (int)tot; i++) {         int x = p[i];         np[i] = cnt[i] = p[i] = 0;         x %= mo;         head[x] = 0;       }       tot = 0;     }     inline void add(int x) {       int pos = x % mo;       for (int u = head[pos]; u; u = np[u])         if (p[u] == x) {           cnt[u]++;           return;         }       tot++;       p[tot] = x;       cnt[tot] = 1;       np[tot] = head[pos];       head[pos] = tot;     }     inline int ask(int x) {       int pos = x % mo;       for (int u = head[pos]; u; u = np[u])         if (p[u] == x) {           return cnt[u];         }       return 0;     }   } cnt;   inline int getroot(int y) {     q[q[0] = 1] = y;     inq[y] = 1;     fa[y] = 0;     for (int i = (1); i <= (int)q[0]; i++) {       int x = q[i];       for (int j = (0); j <= (int)p[x].size() - 1; j++)         if (!inq[p[x][j]] && !vis[p[x][j]]) {           q[++q[0]] = p[x][j];           inq[p[x][j]] = 1;           fa[p[x][j]] = x;         }     }     int a, b;     b = 210000;     a = 0;     for (int i = (q[0]); i >= (int)1; i--) {       int x = q[i];       size[x] = 1;       int MA = -1;       for (int j = (0); j <= (int)p[x].size() - 1; j++)         if (inq[p[x][j]] && fa[x] != p[x][j] && !vis[p[x][j]]) {           size[x] += size[p[x][j]];           if (size[p[x][j]] > MA) MA = size[p[x][j]];         }       if (q[0] - size[x] > MA) MA = q[0] - size[x];       if (MA < b) {         b = MA;         a = x;       }     }     for (int i = (1); i <= (int)q[0]; i++) {       int x = q[i];       inq[x] = 0;     }     return a;   }   inline void Bfs1(int y) {     q[q[0] = 1] = y;     inq[y] = 1;     froot[y] = val[y];     troot[y] = val[y];     dep[y] = 0;     for (int i = (1); i <= (int)q[0]; i++) {       int x = q[i];       for (int j = (0); j <= (int)p[x].size() - 1; j++)         if (!inq[p[x][j]] && !vis[p[x][j]]) {           int d = p[x][j];           troot[d] = (troot[x] * 1ll * k + val[d]) % jsb;           dep[d] = dep[x] + 1;           froot[d] = (froot[x] + 1ll * powk[dep[d]] * val[d]) % jsb;           q[++q[0]] = d;           inq[d] = 1;         }     }     for (int i = (1); i <= (int)q[0]; i++) inq[q[i]] = 0;   }   inline void work(int rt, int y, int v) {     q[q[0] = 1] = y;     inq[y] = 1;     for (int i = (1); i <= (int)q[0]; i++) {       int x = q[i];       for (int j = (0); j <= (int)p[x].size() - 1; j++)         if (!inq[p[x][j]] && !vis[p[x][j]]) {           inq[p[x][j]] = 1;           q[++q[0]] = p[x][j];         }     }     for (int i = (1); i <= (int)q[0]; i++) cnt.add((froot[q[i]] + jsb) % jsb);     for (int i = (1); i <= (int)q[0]; i++) {       int x = q[i];       int key = powk[dep[x]] * 1ll * val[rt] % jsb;       key = (key + goal) % jsb;       key = (key - troot[x]) % jsb;       key = key * 1ll * inv[dep[x]] % jsb;       if (key < 0) key += jsb;       out1[x] += cnt.ask(key) * v;     }     cnt.clear();     for (int i = (1); i <= (int)q[0]; i++) {       int x = q[i];       int key = (goal - troot[x]) % jsb;       key = key * 1ll * inv[dep[x]] % jsb;       if (key < 0) key += jsb;       cnt.add(key);     }     for (int i = (1); i <= (int)q[0]; i++) {       int x = q[i];       int key = froot[x];       key = (key - val[rt]) % jsb;       if (key < 0) key += jsb;       in1[x] += cnt.ask(key) * v;     }     cnt.clear();     for (int i = (1); i <= (int)q[0]; i++) inq[q[i]] = 0;   }   void fenzhi(int y, int depp) {     int x = getroot(y);     Bfs1(x);     vis[x] = 1;     work(x, x, 1);     for (int i = (0); i <= (int)p[x].size() - 1; i++)       if (!vis[p[x][i]]) work(x, p[x][i], -1);     for (int i = (0); i <= (int)p[x].size() - 1; i++)       if (!vis[p[x][i]]) fenzhi(p[x][i], depp + 1);   }   int main() {     scanf( %d%d%d%d , &n, &jsb, &k, &goal);     powk[0] = 1;     for (int i = (1); i <= (int)n; i++) powk[i] = powk[i - 1] * 1ll * k % jsb;     for (int i = (0); i <= (int)n; i++) inv[i] = Pow(powk[i], jsb - 2);     for (int i = (1); i <= (int)n; i++) scanf( %d , &val[i]);     for (int i = (1); i <= (int)n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       p[u].push_back(v);       p[v].push_back(u);     }     fenzhi(1, 0);     long long ans = 0;     for (int i = (1); i <= (int)n; i++) {       in0[i] = n - in1[i];       out0[i] = n - out1[i];       ans = (ans + 2ll * out1[i] * out0[i]);       ans = (ans + 2ll * in1[i] * in0[i]);       ans = (ans + 1ll * in1[i] * out0[i]);       ans = (ans + 1ll * in0[i] * out1[i]);     }     long long pa = n * 1ll * n;     pa = pa * 1ll * n;     ans /= 2;     printf( %I64d n , pa - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int dp[N];   int pdp[2 * N];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int c, n;     cin >> c >> n;     ++n;     pair<pair<int, int>, int> a[n];     a[0] = {{1, 1}, 0};     for (int i = 1; i < n; i++)       cin >> a[i].second >> a[i].first.first >> a[i].first.second;     memset(dp, 0, sizeof dp);     memset(pdp, 0, sizeof pdp);     dp[n - 1] = 1;     pdp[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       dp[i] = i != 0;       for (int j = i + 1; j < min(n, i + 1005); j++) {         int taken = abs(a[i].first.first - a[j].first.first) +                     abs(a[i].first.second - a[j].first.second);         int can = a[j].second - a[i].second;         if (taken <= can) {           dp[i] = max(dp[i], dp[j] + (i != 0));         }       }       dp[i] = max(dp[i], pdp[i + 1004] + (i != 0));       pdp[i] = max(dp[i], pdp[i + 1]);     }     cout << dp[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const int N = 3e5 + 10;   int a[N];   int b[N];   long long solve(long long x, int n) {     long long tmp = 0;     for (int i = 1; i <= n; i++) {       tmp += a[i] * x / b[i];     }     return tmp + n;   }   int main() {     int n, c;     cin >> n >> c;     for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];     int l = 1, r = inf;     int lans = inf, rans = 0;     while (l <= r) {       int mid = (l + r) / 2;       if (solve(mid, n) >= c)         lans = mid, r = mid - 1;       else         l = mid + 1;     }     l = 1, r = inf;     while (l <= r) {       int mid = (l + r) / 2;       if (solve(mid, n) <= c)         rans = mid, l = mid + 1;       else         r = mid - 1;     }     if (solve(lans, n) != c || solve(rans, n) != c)       cout << 0 << endl;     else       cout << max(0, rans - lans + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read(register T& t) {     register T f = 1;     register char ch = getchar();     t = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) t = t * 10 + ch -  0 , ch = getchar();     t *= f;     return t;   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   const long long p = 998244353;   inline long long power(register long long x, register long long k = p - 2) {     register long long re = 1;     for (; k; k >>= 1, x = x * x % p)       if (k & 1) re = re * x % p;     return re;   }   long long n, m;   long long a[300005];   long long g[300005], f[300005];   long long ans;   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]), m += a[i];     g[0] = n - 1;     for (int i = 1; i < m; i++)       g[i] =           (m * (n - 1) % p + g[i - 1] * (n - 1) % p * i % p) * power(m - i) % p;     f[m] = 0;     for (int i = m - 1; i >= 0; i--) f[i] = (f[i + 1] + g[i]) % p;     ans = (p - f[0] * (n - 1) % p) % p;     for (int i = 1; i <= n; i++) ans = (ans + f[a[i]]) % p;     printf( %lld n , ans * power(n) % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     std::vector<int> v;     for (int i = 0; i < n / 2; i++) {       v.push_back(2);     }     if (n % 2 != 0) {       v.pop_back();       v.push_back(3);     }     cout << v.size() << endl;     for (auto a : v) cout << a <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vi[200200];   int dp[200200];   int dfs(int now, int prev) {     dp[now] = 1;     for (auto x : vi[now]) {       if (x == prev) continue;       dp[now] += dfs(x, now);     }     return dp[now];   }   long long int rose = 0;   int n;   void rec(int now, int prev, long long int sum) {     rose = max(rose, sum);     for (auto x : vi[now]) {       if (x == prev) continue;       rec(x, now, sum - dp[x] + (n - dp[x]));     }   }   int main() {     int i, j, k, x, y, ans, curr, temp, m;     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d %d , &x, &y);       vi[x].push_back(y);       vi[y].push_back(x);     }     dfs(1, 0);     for (i = 1; i <= n; i++) rose += dp[i];     rec(1, 0, rose);     printf( %lld n , rose);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, k, ans = 0, flag = -1, p = 0, sum = 0;     cin >> n >> k;     long long a[n], i, b[n];     map<long long, long long> m;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + n);     reverse(a, a + n);     for (i = 0; i < k; i++) {       ans += a[i];       m[a[i]]++;     }     cout << ans << endl;     sum = n;     flag = 0;     for (i = 0; i < n; i++) {       p++;       if (k == 1) break;       if (m[b[i]] > 0) {         cout << p <<    ;         sum -= p;         k--;         p = 0;         m[b[i]]--;       }     }     if (sum) cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, d, m;   long long lin;   long long a[100007], b[100007], la, lb;   long long pa[100007], pb[100007];   long long ans;   void go(long long l, long long r, long long k) {     if (l > r) return;     long long mid = (l + r) / 2;     long long yu = min(n - ((mid - 1) * (d + 1) + 1), la);     long long now = pa[yu] + pb[mid];     if (now > ans) {       ans = now;       go(l, mid - 1, 2);       go(mid + 1, r, 1);     } else {       if (k == 1) {         go(l, mid - 1, 1);       } else {         go(mid + 1, r, 2);       }     }   }   int main() {     la = 0, lb = 0;     scanf( %lld%lld%lld , &n, &d, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &lin);       if (lin <= m) {         a[++la] = lin;       } else {         b[++lb] = lin;       }     }     sort(a + 1, a + 1 + la, greater<int>());     sort(b + 1, b + 1 + lb, greater<int>());     for (int i = 1; i <= la; i++) {       pa[i] = pa[i - 1] + a[i];     }     for (int i = 1; i <= lb; i++) {       pb[i] = pb[i - 1] + b[i];     }     long long l = 0, r = min((n - 1) / (d + 1) + 1, lb);     ans = 0;     go(l, r, 0);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   map<long long int, long long int> m;   map<long long int, long long int> m1, m2;   int main() {     ios_base::sync_with_stdio(0);     ;     long long int n, k;     cin >> n >> k;     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       if ((x / k) * k == x) {         ans += m2[x / k];         m2[x] += m1[x / k];       }       m1[x]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define pb push_back   #define mp make_pair   #define mt make_tuple   #define ff first   #define ss second   #define pii pair <int,int>   #define pll pair <ll,ll>   #define testcase() int t; cin>>t; while(t--)   #define forn(i,n) for(int i=0;i<n;i++)   #define forn1(i,n) for(int i=1;i<=n;i++)   #define vll vector <ll>   #define vi vector <int>   #define all(v) v.begin(),v.end()      ll M = 1e9 + 7;   double pi = acos(-1.0);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }   ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }   ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}      int main() {        //ifstream cin( input.txt );    //ofstream cout( output.txt );    ios_base::sync_with_stdio(false);        cin.tie(NULL);         ll n,k,x; cin >> n >> k >> x;       vll a(n);       forn(i,n) cin >> a[i];       sort(all(a));       ll grp = 1;       vll diffs;       for(int i=1;i<n;i++)       {           if( a[i] - a[i-1] <= x ) continue;           grp++;           diffs.pb( (a[i]-a[i-1]-1)/x );       }       sort(all(diffs));       int id = 0;       // cout << grp << endl;       while(id<diffs.size())       {           if( diffs[id] > k ) break;           k -= diffs[id];           grp--;           id++;       }       cout << grp <<   n ;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007ll;   const int INTMAX = numeric_limits<int>::max();   const long long LLMAX = numeric_limits<long long>::max();   void writeln() { cout <<   n ; }   template <class T>   inline void print(T&& a);   template <class T>   inline void priws(T&& a);   template <class T>   inline void read(T& a);   template <class... Args>   inline void readln(Args&... args) {     (read(args), ...);   }   template <class H, class... T>   inline void writeln(H&& h, T&&... t) {     priws(h);     (print(t), ...);     writeln();   }   template <class T>   inline void writeln_range(T f, T s) {     if (f != s)       for (auto i = f; i != s; ++i) writeln(*i);   }   vector<string> split(string& s, string d) {     vector<string> v;     size_t p = 0;     while ((p = s.find(d)) != string::npos)       v.push_back(s.substr(0, p)), s.erase(0, p + d.length());     v.push_back(s);     return v;   }   template <class... Args>   inline void err(string v, Args... args) {     auto vv = split(v,  ,  );     auto it = vv.begin();     (writeln(*it++,  = , args), ...);   }   template <typename T>   T binpowmod(T a, long long n, T mod) {     assert(n > 0);     T res = a;     --n;     while (n > 0) {       if (n & 1) res = (res * a) % mod;       a = (a * a) % mod;       n >>= 1;     }     return res;   }   void run() {     int n, k;     readln(n, k);     vector<vector<pair<int, int>>> g(n);     int u, v, x;     for (int i = 0; i < (int)(n - 1); ++i)       readln(u, v, x), --u, --v, g[u].push_back({v, x}), g[v].push_back({u, x});     vector<long long> degs(n + 1, 0);     for (int i = 1; i < (int)(n + 1); ++i) degs[i] = binpowmod(i * 1ll, k, MOD);     vector<bool> used(n, false);     function<int(int)> dfs = [&](int u) {       used[u] = true;       int cnt = 1;       for (auto& [v, x] : g[u])         if (!x && !used[v]) cnt += dfs(v);       return cnt;     };     long long ans = degs[n];     for (int i = 0; i < (int)(n); ++i)       if (!used[i]) {         int cnt = dfs(i);         ans -= degs[cnt];         if (ans < 0) ans += MOD;       }     writeln(ans);   }   int main() {     ios_base::sync_with_stdio(false);     run();     return 0;   }   template <class T>   inline ostream& operator<<(ostream& os, vector<T> const& _a);   template <class T1, class T2>   inline istream& operator>>(istream& is, pair<T1, T2>& _a) {     return is >> _a.first >> _a.second;   }   template <class T1, class T2>   inline ostream& operator<<(ostream& os, pair<T1, T2> const& _a) {     return os << _a.first <<     << _a.second;   }   template <class T>   inline ostream& operator<<(ostream& os, vector<T> const& _a) {     if (_a.size())       os << _a[0];     else       os <<   n ;     for (int i = 1; i < (int)(_a.size()); ++i)       os <<   n  [is_fundamental<T>::value] << _a[i];     return os;   }   template <class T>   inline ostream& operator<<(ostream& os, valarray<T> const& _a) {     if (_a.size())       os << _a[0];     else       os <<   n ;     for (int i = 1; i < (int)(_a.size()); ++i)       os <<   n  [is_fundamental<T>::value] << _a[i];     return os;   }   template <class T>   inline istream& operator>>(istream& is, vector<T>& _a) {     for (int i = 0; i < (int)(_a.size()); ++i) is >> _a[i];     return is;   }   template <class T>   inline istream& operator>>(istream& is, valarray<T>& _a) {     for (int i = 0; i < (int)(_a.size()); ++i) is >> _a[i];     return is;   }   template <class T>   inline void print(T&& _a) {     cout <<     << _a;   }   template <class T>   inline void priws(T&& _a) {     cout << _a;   }   template <class T>   inline void read(T& _a) {     cin >> _a;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, t, min = -1, flag = 0;     cin >> n;     string s;     cin >> s;     long long int a[n];     for (int i = 0; i < n; i++) {       cin >> t;       a[i] = t;     }     for (int i = 1; i < n; i++) {       if ((s[i] ==  L  && s[i - 1] ==  R )) {         t = (a[i] - a[i - 1]) / 2;         if (t < min || min == -1) min = t;         flag = 1;       }     }     if (flag == 0)       cout << -1;     else       cout << min;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int C = 26;   void add(int &x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int fix(int x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int pw(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       b >>= 1;       a = 1ll * a * a % MOD;     }     return ret;   }   const int MAXN = 2e5 + 10;   const int INF = 2e9 + 5;   int n, m, vec[MAXN], ans[MAXN], qu[MAXN], sz;   vector<array<int, 4>> g[MAXN];   void solve() {     cin >> n >> m;     memset(ans, -1, 4 * m);     for (int i = 0, u, v, w; i < m; i++) {       cin >> u >> v >> w;       --u, --v;       g[u].push_back({v, w, i, 0});       g[v].push_back({u, w, i, 1});       vec[u] += w;       vec[v] += w;     }     for (int i = 1; i < n - 1; i++) {       vec[i] /= 2;     }     vec[0] = 0;     vec[n - 1] = INF;     qu[sz++] = 0;     for (int i = 0; i < sz; i++) {       int u = qu[i];       for (auto [v, w, j, dir] : g[u]) {         if (~ans[j]) continue;         vec[v] -= w;         ans[j] = dir;         if (vec[v] == 0 && v != n - 1) qu[sz++] = v;       }     }     for (int i = 0; i < m; i++) {       assert(~ans[i]);       cout << ans[i] <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int SZ = 2000 + 10;   LL g_n, g_k, g_p;   LL a[SZ], b[SZ];   void prete() {}   void input() {     for (int i = 0; i < g_n; ++i) {       scanf(  %I64d , a + i);     }     for (int i = 0; i < g_k; ++i) {       scanf(  %I64d , b + i);     }   }   void solve() {     LL ans = LLONG_MAX;     sort(a, a + g_n);     sort(b, b + g_k);     for (int i = 0; i <= g_k - g_n; ++i) {       LL t = LLONG_MIN;       for (int j = 0; j < g_n; ++j) {         t = max(t, abs(a[j] - b[i + j]) + abs(b[i + j] - g_p));       }       ans = min(ans, t);     }     cout << ans << endl;   }   int main() {     prete();     while (cin >> g_n >> g_k >> g_p) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<string, int> mapp;     int mina = 10000000, minb = 10000000, minc = 10000000, minab = 10000000,         minac = 10000000, minbc = 10000000, min3 = 10000000;     int x;     string na;     for (int i = 0; i < n; i++) {       cin >> x >> na;       sort(na.begin(), na.end());       if (na.length() == 3) {         min3 = min(x, min3);       } else if (na ==  A ) {         mina = min(x, mina);       } else if (na ==  B ) {         minb = min(x, minb);       } else if (na ==  C ) {         minc = min(x, minc);       } else if (na ==  AB ) {         minab = min(x, minab);       } else if (na ==  AC ) {         minac = min(x, minac);       } else if (na ==  BC ) {         minbc = min(x, minbc);       }     }     min3 = min(min3, minab + minc);     min3 = min(min3, minac + minb);     min3 = min(min3, minbc + mina);     min3 = min(min3, mina + minb + minc);     min3 = min(min3, minab + minbc);     min3 = min(min3, minab + minac);     min3 = min(min3, minac + minbc);     if (min3 > 1000000) {       cout <<  -1  << endl;     } else {       cout << min3 << endl;     }     return 0;   }


#include <bits/stdc++.h>   bool visited[200010] = {0};   int first[200010], second[200010], thrid[200010], count = 0;   std::set<long long int> happened;   long long int f(int one, int two) {     return (1LL * 1e6 * std::min(one, two) + std::max(one, two));   }   int dfs(int current, std::vector<std::vector<int> > &g, int parent = -1) {     if (visited[current]) return current;     visited[current] = 1;     std::vector<int> s;     for (int i = 0; i < g[current].size(); ++i) {       if (g[current][i] != parent) {         int value = dfs(g[current][i], g, current);         if (value != -1 &&             happened.find(f(g[current][i], current)) == happened.end()) {           s.push_back(value);         }       }     }     int ffirst = 0, ssecond = 1;     while (ssecond < s.size()) {       happened.insert(f(s[ffirst], current));       happened.insert(f(s[ssecond], current));       first[count] = s[ffirst];       second[count] = current;       thrid[count] = s[ssecond];       ++count;       ffirst += 2;       ssecond += 2;     }     if (ffirst == s.size()) return current;     if (parent != -1) {       first[count] = s[ffirst];       second[count] = current;       thrid[count] = parent;       ++count;       happened.insert(f(s[ffirst], current));       happened.insert(f(current, parent));     }     return -1;   }   int main() {     int n, m;     std::cin >> n >> m;     std::vector<std::vector<int> > g(n);     for (int i = 0; i < m; ++i) {       int x, y;       std::cin >> x >> y;       --x;       --y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 0; i < n; ++i) {       if (!visited[i]) {         dfs(i, g);       }     }     std::cout << count <<   n ;     for (int i = 0; i < count; ++i) {       std::cout << first[i] + 1 <<     << second[i] + 1 <<     << thrid[i] + 1                 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> s;   vector<pair<int, int> > v;   vector<vector<int> > g;   vector<bool> used;   map<int, int> mp;   int c[1005];   int cl[1005];   int cr[1005];   int main() {     ios_base::sync_with_stdio(0);     int n, m, k;     cin >> n >> m >> k;     g.resize(n);     for (int i = 0; i < k; i++) {       int x;       cin >> x;       x--;       s.push_back(x);     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       v.push_back({a, b});       g[a].push_back(b);       g[b].push_back(a);     }     int ck = 0;     queue<int> q;     used.resize(n + 5, 0);     mp[0] = n;     for (int i = 0; i < k; i++) {       q.push(s[i]);       ck++;       while (!q.empty()) {         int vc = q.front();         c[vc] = ck;         used[vc] = 1;         for (int i = 0; i < g[vc].size(); i++) {           if (!used[g[vc][i]]) q.push(g[vc][i]);         }         q.pop();       }     }     for (int i = 0; i < n; i++) {       cl[c[i]]++;     }     for (int i = 0; i < m; i++) {       int x = v[i].first;       cr[c[x]]++;     }     long long mx = 0;     int num = -1;     for (int i = 1; i <= ck; i++) {       long long cur = (cl[i] + cl[0]) * (cl[i] + cl[0] - 1) - cr[i] - cr[0];       if (cur > mx) {         mx = cur;         num = i;       }     }     cl[num] += cl[0];     cr[num] += cr[0];     long long ans = 0;     for (int i = 1; i <= ck; i++) {       ans += cl[i] * (cl[i] - 1) / 2 - cr[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int gcd(int a, int b, int &counter) {     if (b == 0) return a;     counter += a / b;     return gcd(b, a % b, counter);   }   int main() {     int n;     int minn = 1000000;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int tempCounter = 0;       if (gcd(n, i, tempCounter) == 1 && tempCounter < minn) minn = tempCounter;     }     if (n == 1)       minn = 0;     else       minn--;     printf( %d n , minn);     return 0;   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();     if (flag) x = -x;   }   using namespace std;   const int P = 1e9 + 7;   const int inv2 = (P + 1) / 2;   inline long long quickpow(long long x, long long k) {     long long res = 1;     x %= P;     while (k) {       if (k & 1) res = res * x % P;       x = x * x % P;       k >>= 1;     }     return res;   }   int k;   long long s[230][230], tri[230][230], jie[230], jieni[230];   inline void init() {     s[0][0] = 1;     for (int i = 1; i <= k; ++i)       for (int j = 1; j <= i; ++j)         s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * (i - 1)) % P;     tri[1][1] = 1;     for (int i = 2; i <= k + 1; ++i)       for (int j = 1; j <= i; ++j)         tri[i][j] = (tri[i - 1][j - 1] + tri[i - 1][j]) % P;     jie[0] = jieni[0] = 1;     for (int i = 1; i <= k; ++i) jie[i] = jie[i - 1] * i % P;     jieni[k] = quickpow(jie[k], P - 2);     for (int i = k - 1; i; --i) jieni[i] = jieni[i + 1] * (i + 1) % P;   }   inline long long get_c(int n, int m) {     if (n < 0 || m < 0 || n - m < 0) return 0;     return tri[n + 1][m + 1];   }   struct Complex {     long long a, b;     Complex() { a = 0, b = 0; }     Complex(long long jzp, long long zzz) { a = jzp, b = zzz; }   } phi, phihat;   inline Complex operator+(const Complex &a, const Complex &b) {     return Complex((a.a + b.a) % P, (a.b + b.b) % P);   }   inline Complex operator-(const Complex &a, const Complex &b) {     return Complex((a.a - b.a) % P, (a.b - b.b) % P);   }   inline Complex operator*(const Complex &a, const Complex &b) {     return Complex((a.a * b.a + 5 * a.b * b.b) % P, (a.a * b.b + a.b * b.a) % P);   }   inline Complex get_inv(Complex x) {     long long a = x.a, b = x.b;     if (!b) return Complex(quickpow(a, P - 2), 0);     long long d = b * quickpow((5ll * b * b - a * a) % P, P - 2) % P;     long long c = -a * quickpow(b, P - 2) % P * d % P;     Complex res = Complex(c, d);     return res;   }   inline Complex Pow(Complex x, long long k) {     Complex res(1, 0);     while (k) {       if (k & 1) res = res * x;       x = x * x;       k >>= 1;     }     return res;   }   inline long long work(long long n) {     Complex ans;     for (int j = 0; j <= k; ++j) {       Complex res;       for (int d = 0; d <= j; ++d) {         Complex A = Pow(phi, d) * Pow(phihat, j - d);         if (A.a == 1 && A.b == 0) {           if ((j - d) & 1)             res = res - Complex(n % P * get_c(j, d) % P, 0);           else             res = res + Complex(n % P * get_c(j, d) % P, 0);         }         A = A * (Complex(1, 0) - Pow(A, n)) * get_inv(Complex(1, 0) - A);         if ((j - d) & 1)           res = res - Complex(get_c(j, d), 0) * A;         else           res = res + Complex(get_c(j, d), 0) * A;       }       if ((k - j) & 1)         ans = ans - Complex(s[k][j], 0) * Pow(get_inv(Complex(0, 1)), j) * res;       else         ans = ans + Complex(s[k][j], 0) * Pow(get_inv(Complex(0, 1)), j) * res;     }     ans = ans * Complex(jieni[k], 0);     return ans.a;   }   int main() {     phi = Complex(inv2, inv2);     phihat = Complex(inv2, P - inv2);     read(k);     init();     long long l, r;     read(l), read(r);     l += 2;     r += 2;     long long ans = work(r) - work(l - 1);     printf( %lld n , (ans % P + P) % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, inf = 15e8;   int A[maxn], B[maxn], C[maxn], ANSA, ANSB, n, l, r;   vector<int> ed;   vector<pair<int, int> > v[maxn];   int SZ[maxn], MX;   bool mark[maxn];   pair<int, int> val[2 * maxn];   void dfsS(int u, int par = -1) {     SZ[u] = 1;     for (pair<int, int> p : v[u]) {       if (p.first != par && !mark[p.first])         dfsS(p.first, u), SZ[u] += SZ[p.first];     }   }   int dfsC(int u, int ss, int par = -1) {     for (pair<int, int> p : v[u]) {       if (p.first != par && !mark[p.first] && SZ[p.first] >= ss)         return dfsC(p.first, ss, u);     }     return u;   }   void prep() {     for (int i = 0; i < 2 * MX; i++) {       val[i] = {-inf, -inf};     }   }   pair<int, int> ask(int f, int s) {     s = min(s, MX - 1);     f += MX;     s += MX;     pair<int, int> ans = {-inf, -inf};     while (f < s) {       if (f & 1) ans = max(ans, val[f++]);       if (s & 1) ans = max(ans, val[--s]);       f >>= 1;       s >>= 1;     }     return ans;   }   void add(int pos, pair<int, int> p) {     pos += MX;     while (pos > 0) {       val[pos] = max(val[pos], p);       pos >>= 1;     }   }   void dfsadd(int u, int ln, int sm, int par) {     add(ln, {sm, u});     for (pair<int, int> p : v[u]) {       if (p.first != par && !mark[p.first])         dfsadd(p.first, ln + 1, sm + p.second, u);     }   }   void dfsask(int u, int ln, int sm, int par) {     pair<int, int> X = ask(max(0, l - ln), max(0, r - ln + 1));     if (X.first + sm >= 0) ANSA = X.second, ANSB = u;     for (pair<int, int> p : v[u]) {       if (p.first != par && !mark[p.first])         dfsask(p.first, ln + 1, sm + p.second, u);     }   }   void solve(int u) {     dfsS(u);     MX = SZ[u] + 5;     prep();     u = dfsC(u, SZ[u] / 2);     add(0, {0, u});     mark[u] = 1;     for (pair<int, int> p : v[u]) {       if (!mark[p.first])         dfsask(p.first, 1, p.second, u), dfsadd(p.first, 1, p.second, u);     }     for (pair<int, int> p : v[u]) {       if (!mark[p.first]) solve(p.first);     }   }   bool okay(int num) {     memset(mark, 0, sizeof mark);     for (int i = 1; i <= n; i++) {       v[i].clear();     }     for (int i = 0; i < n - 1; i++) {       v[A[i]].push_back({B[i], C[i] >= ed[num] ? 1 : -1});       v[B[i]].push_back({A[i], C[i] >= ed[num] ? 1 : -1});     }     ANSA = ANSB = -1;     solve(1);     return ANSA != -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> l >> r;     for (int i = 0; i < n - 1; i++) {       cin >> A[i] >> B[i] >> C[i];       ed.push_back(C[i]);     }     sort(ed.begin(), ed.end());     int l = 0, r = n - 2, ansa = -1, ansb = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (okay(mid))         ansa = ANSA, ansb = ANSB, l = mid + 1;       else         r = mid - 1;     }     cout << ansa <<     << ansb << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   int main() {     int a, b;     cin >> a >> b;     long long S = 0;     for (int e = 1; e < b; e++) {       long long s1 = ((long long)a * (a + 1) / 2) % INF;       long long s2 = (s1 * b) % INF;       s2 = (s2 + a) % INF;       S = (S + ((s2 * e) % INF)) % INF;     }     cout << S;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int main(){       int t;       cin>>t;       while(t--){           int n;           cin>>n;           int a[n];           int mini;           int c=0;           for(int i=0;i<n;i++){               cin>>a[i];           }           // for(int i=0;i<n;i++){           //     if(a[i]<mini){           //         mini=a[i];           //     }          mini=*min_element(a,a+n);                      for(int i=0;i<n;i++){               if(a[i]!=mini ){                   c++;               }           }           cout << c << endl;       }         }


#include <bits/stdc++.h>      using namespace std;   #define int long long   bool local=false;   int z1;   int n;   vector <int> a;   mt19937 rnd;   int med(int x,int y,int z)   {       vector <int> h={x,y,z};       sort(h.begin(),h.end());       return h[1];   }   int query(int u,int v,int w)   {       cout<< ?  <<u+1<<   <<v+1<<   <<w+1<<endl;       if(!local)       {           int ans;           cin>>ans;           return ans;       }       else       {           return med(abs(a[u]-a[v]),abs(a[v]-a[w]),abs(a[w]-a[u]));       }   }   bool check(int x)   {       //cout<<n<<  n  <<endl;       if(x==z1) return false;       int sum=0;       for(int i=0;i<18;++i)       {           int u=rnd()%n;           int v=rnd()%n;           if(u==v || u==z1 || u==x || v==z1 || v==x) {i--;continue;}           int res1=query(u,v,z1);int res2=query(u,v,x);           if(res1==(res2+1) || res1==res2)           {               ++sum;           }       }       //cout<<  trfe  <<endl;       return (sum==18);   }   int32_t main()   {       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);       int t;       cin>>t;       while(t--)       {           cin>>n;           a.clear();           rnd.seed(4824948+rnd());           if(local)           {               for(int i=0;i<n;++i) a.push_back(i+1);               shuffle(a.begin(),a.end(),default_random_engine(rand()+rnd()+6432));               if(a[0]>a[1])               {                   for(int i=0;i<n;++i) a[i]=(n+1-a[i]);               }           }           int ans1=1e9;           vector <int> z;           for(int i=0;i<200;++i)           {               int u=rnd()%n;int v=rnd()%n;int w=rnd()%n;               if(u!=v && v!=w && w!=u)               {                   int r=query(u,v,w);                   if(r<ans1)                   {                       ans1=r;                       z={u,v,w};                   }               }           }           vector <pair<int,int> > v;           for(int x=0;x<n;++x)           {               if(x!=z[1] && x!=z[2])               {                   int res1=query(x,z[1],z[2]);                   v.push_back({res1,x});               }           }           sort(v.begin(),v.end());reverse(v.begin(),v.end());           int pos1=v[0].second;           z1=pos1;int z2=(-1);           int pos2=v[1].second;           int pos3=v[2].second;           int pos4=v[3].second;           //cout<<z[0]<<   <<z[1]<<   <<z[2]<<endl;           //cout<<pos1<<   <<pos2<<   <<pos3<<   <<pos4<<endl;           {               if(check(pos2)) {z2=pos2;}               else if(check(pos3)) {z2=pos3;}               else if(check(pos4)) {z2=pos4;}               else if(check(z[1])) {z2=z[1];}               else if(check(z[2])) {z2=z[2];}           }           if(z2==(-1)) assert(false);           vector <int> ans(n);           ans[z1]=1;           ans[z2]=2;           for(int i=0;i<n;++i)           {               if(i!=z1 && i!=z2)               {                   ans[i]=query(z1,z2,i)+2;               }           }           if(ans[0]>ans[1]) for(int i=0;i<n;++i) ans[i]=(n+1-ans[i]);           if(local) {for(int i=0;i<n;++i) cout<<a[i]<<   ;           cout<<endl;}           cout<< !  ;           for(int i=0;i<n;++i) cout<<ans[i]<<   ;           cout<<endl;           int res;           cin>>res;           if(res==(-1))           {               exit(0);           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 20222, mod = 998244353;   int n, k, q, A[max_n], a[max_n];   int dp[max_n];   int solve() {     int q1 = 0, q2 = 1;     memset(dp, 0, sizeof(dp));     dp[0] = 1;     for (int i = 0; i < n; ++i) {       for (int j = min(i + 1, k); j >= max(1, k - (n - i - 1)); --j) {         dp[j] = (dp[j] + 1LL * dp[j - 1] * a[i]) % mod;       }     }     return dp[k];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) {       scanf( %d , &A[i]);     }     scanf( %d , &q);     while (q--) {       copy(A, A + n, a);       int tp, x;       scanf( %d%d , &tp, &x);       if (tp == 1) {         int pos, d;         scanf( %d%d , &pos, &d);         --pos;         a[pos] = d;       } else {         int l, r, d;         scanf( %d%d%d , &l, &r, &d);         --l;         for (int i = l; i < r; ++i) {           a[i] += d;         }       }       for (int i = 0; i < n; ++i) {         a[i] = ((x - a[i]) % mod + mod) % mod;       }       printf( %d n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct TP {};   int ar[5][5];   int ans = 0;   int nums[5];   bool used[10];   void cal(int pos) {     if (pos == 5) {       int tmp = 0;       for (int x = 0; x < 5; x++) {         for (int y = x; y < 4; y += 2) {           tmp += ar[nums[y]][nums[y + 1]];           tmp += ar[nums[y + 1]][nums[y]];         }       }       ans = max(ans, tmp);       return;     }     for (int i = 0; i < 5; i++) {       if (!used[i]) {         nums[pos] = i;         used[i] = 1;         cal(pos + 1);         used[i] = 0;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     for (int i = 0; i < 5; i++)       for (int j = 0; j < 5; j++) scanf( %d , &ar[i][j]);     cal(0);     printf( %d , ans);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int x1, y1, x2, y2, res = 0;     scanf( %d%d%d%d , &x1, &y1, &x2, &y2);     int n;     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) {       long long a, b, c;       scanf( %lld%lld%lld , &a, &b, &c);       long long t1 = a * x1 + b * y1 + c;       long long t2 = a * x2 + b * y2 + c;       t1 = t1 > 0, t2 = t2 > 0;       res += t1 != t2;     }     printf( %d n , res);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, d;     cin >> n >> d;     int a[n], sum = 0;     for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];     if (sum + 10 * (n - 1) <= d)       cout << (d - sum) / 5;     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   inline long long getnum() {     register long long r = 0;     register bool ng = 0;     register char c;     c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) ng = 1, c = getchar();     while (c !=     && c !=   n ) r = r * 10 + c -  0 , c = getchar();     if (ng) r = -r;     return r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x > 0) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline void putsp() { putchar(   ); }   inline void putendl() { putchar(  n ); }   inline char mygetchar() {     register char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   int n, k;   int a[511];   bool dp[511][511];   vector<int> v;   int main() {     n = getnum(), k = getnum();     for (int i = 1; i <= n; i++) a[i] = getnum();     dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int t1 = 500; t1 >= 0; t1--) {         for (int t2 = 500; t2 >= 0; t2--) {           if (t1 + a[i] <= 500) dp[t1 + a[i]][t2] |= dp[t1][t2];           if (t2 + a[i] <= 500) dp[t1][t2 + a[i]] |= dp[t1][t2];         }       }     }     for (int i = 0; i <= k; i++)       if (dp[i][k - i]) v.push_back(i);     putnum(v.size()), putendl();     for (int i = 0; i < v.size(); i++) putnum(v[i]), putsp();     return 0;   }


#include <bits/stdc++.h>   const double pi = 3.1415926535;   using namespace std;   int main() {     double n, r;     cin >> n >> r;     r = sin(pi / n) * r / (1 - sin(pi / n));     cout << fixed << setprecision(7) << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class SegmentTree {    private:     int n;     vector<int> st;     int left(int p) { return (p << 1); }     int right(int p) { return (p << 1) + 1; }     int parent(int p) { return (p >> 1); }     void build(int p, int L, int R) {       if (L == R)         st[p] = A[L];       else {         build(left(p), L, (L + R) / 2);         build(right(p), (L + R) / 2 + 1, R);         int p1 = st[left(p)], p2 = st[right(p)];         st[p] = p1 + p2;       }     }     int rsq(int p, int L, int R, int i, int j) {       if (i > R || j < L) return 0;       if (i <= L && R <= j) return st[p];       int p1 = rsq(left(p), L, (L + R) / 2, i, j);       int p2 = rsq(right(p), (L + R) / 2 + 1, R, i, j);       return p1 + p2;     }       public:     vector<int> A;     SegmentTree() {}     SegmentTree(const vector<int> &v) {       A = v;       n = (int)A.size();       st.assign(4 * n, 0);       build(1, 0, n - 1);     }     int query(int i, int j) { return rsq(1, 0, n - 1, i, j); }     void update(int i, int j, int a) {       A[i] = a;       int L = 0, R = n - 1, p = 1;       while (L < R) {         int mid = (L + R) / 2;         if (i <= mid) {           R = mid;           p = left(p);         } else {           L = mid + 1;           p = right(p);         }       }       st[p] = a;       while (p = parent(p)) {         int p1 = st[left(p)], p2 = st[right(p)];         st[p] = p1 + p2;       }     }   };   int a[123456];   int L[123456];   int R[123456];   vector<int> isOn(123456, 1);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     SegmentTree st(isOn);     vector<int> v;     for (int i = 1; i < n; i++) {       L[i] = i - 1;       R[i] = i + 1;       if (a[i] < a[i - 1]) v.push_back(i);     }     int cnt = 0;     while (v.size() > 0) {       for (int ID : v) {         st.update(ID, ID, 0);       }       vector<int> _new;       for (int ID : v) {         int isOk1 = st.query(R[ID], R[ID]);         int isOk2 = st.query(L[ID], L[ID]);         if (isOk1 && isOk2) {           R[L[ID]] = R[ID];           L[R[ID]] = L[ID];           if (R[ID] < n && a[R[ID]] < a[L[ID]]) {             _new.push_back(R[ID]);           }           continue;         }         if (R[ID] < n) {           int I = R[ID];           if (isOk1) {             int lo = 0, hi = I - 1, mid;             while (hi - lo > 5) {               mid = (lo + hi) / 2;               int foo = st.query(mid, I - 1);               if (foo > 1) {                 lo = mid + 1;               } else if (foo == 0) {                 hi = mid - 1;               } else {                 assert(foo == 1);                 lo = mid;               }             }             int idx = 0;             for (int i = hi; i >= lo; i--) {               if (st.query(i, I - 1) == 1) {                 idx = i;                 break;               }             }             L[I] = idx;             if (a[idx] > a[I]) _new.push_back(I);           }         }         int I = L[ID];         if (isOk2) {           int lo = I + 1, hi = n, mid;           while (hi - lo > 5) {             mid = (lo + hi) / 2;             int foo = st.query(I + 1, mid);             if (foo > 1) {               hi = mid - 1;             } else if (foo == 0) {               lo = mid + 1;             } else {               assert(foo == 1);               hi = mid;             }           }           int idx = n;           for (int i = lo; i <= hi; i++) {             if (st.query(I + 1, i) == 1) {               idx = i;               break;             }           }           R[I] = idx;           if (idx < n && a[idx] < a[I]) _new.push_back(idx);         }       }       v.clear();       v = _new;       assert(is_sorted(v.begin(), v.end()));       auto it = unique(v.begin(), v.end());       v.resize(distance(v.begin(), it));       cnt++;     }     cout << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     long long res = 0;     cin >> n >> m;     int v[n];     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       res += min(v[x - 1], v[y - 1]);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n), b(n);     pair<int, int> p;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     iota(b.begin(), b.end(), 0);     sort(b.begin(), b.end(), [&](int x, int y) {       if (a[x] != a[y]) {         return a[x] < a[y];       }       return x < y;     });     for (int i = n - 1; i >= 0; i--) {       int it = 0;       for (auto j = b.begin(); j != b.end(); j++) {         if (*j == i) {           b.erase(j);           break;         }         it++;       }       for (int j = it; j < b.size(); j++) {         p.first = b[j];         p.second = i;         v.emplace_back(p);       }     }     cout << v.size() <<   n ;     for (auto i : v) {       cout << i.first + 1 <<     << i.second + 1 <<   n ;     }   }   int main() {     solve();     return 0;   }


#include  bits/stdc++.h    using namespace std;      #define ll long long   #define Rip_classic_loki_for_glorious_purpose ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)      #pragma GCC target ( avx2 )   #pragma GCC optimization ( O3 )   #pragma GCC optimization ( unroll-loops )      // need for speed      int main()   {       Rip_classic_loki_for_glorious_purpose;         int t;       cin >> t;          while(t--){           int n,k,check;        cin >> n >> k;        int w = 0;     for(int i = 0;i < n;i++){      cout << (i ^ w) << endl;      cin >> check;      if(check == 1){       break;      }      w = i;     }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(vector<long long> &A, vector<long long> &B) {     if (A[0] - A[1] > B[0] - B[1]) return true;     return false;   }   int main() {     long long(n), (a), (b);     scanf( %lld%lld%lld , &(n), &(a), &(b));     ;     vector<vector<long long>> A, B;     long long sum = 0;     for (long long i = 0; i < (n); i++) {       long long(a), (b);       scanf( %lld%lld , &(a), &(b));       ;       if (a > b)         B.push_back(vector<long long>{a, b});       else         A.push_back(vector<long long>{a, b});       sum += b;     }     if (b == 0) {       printf( %lld n , sum);       return 0;     }     long long val = 1;     while (a--) val *= 2;     sort((B).begin(), (B).end(), compare);     while (B.size() > b) {       A.push_back(B[B.size() - 1]);       B.pop_back();     }     long long store = 0;     for (long long i = 0; i < (B.size()); i++) {       sum += B[i][0] - B[i][1];       if (B.size() == b && i == b - 1) store = B[i][1] - B[i][0];     }     long long ans = sum;     for (long long i = 0; i < (B.size()); i++) {       long long temp = sum;       temp -= B[i][0];       temp += B[i][0] * val;       ans = max(ans, temp);     }     for (long long i = 0; i < (A.size()); i++) {       long long temp = sum + store;       temp -= A[i][1];       temp += A[i][0] * val;       ans = max(ans, temp);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using std::list;   const int N = 128;   struct car {     int coord, length, req;   };   list<car> cars;   int InsertCar(int length, int req, int b, int f) {     list<car>::iterator i = cars.begin(), j = ++cars.begin();     int from, to;     while (j != cars.end()) {       from = i->coord + i->length + b;       to = j->coord - f;       if (to - from >= length) {         cars.insert(j, (car){from, length, req});         return from;       }       ++i, ++j;     }     return -1;   }   void DeleteCar(int req) {     list<car>::iterator i = cars.begin();     while (i != cars.end()) {       if (i->req == req) {         cars.erase(i);         break;       }       ++i;     }   }   int main() {     int l, b, f, n;     scanf( %d%d%d%d , &l, &b, &f, &n);     cars.push_back((car){-b, 0, -1});     cars.push_back((car){l + f, 0, -1});     int type, req;     for (int i = 0; i < n; ++i) {       scanf( %d%d , &type, &req);       if (type == 1)         printf( %d n , InsertCar(req, i, b, f));       else         DeleteCar(req - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   int n, k;   int a[MAXN];   stack<pair<int, int> > s;   int l[MAXN], r[MAXN];   long long cal(int l, int r) {     if (l > r || r - l + 1 - k < 0) return 0;     int m = (r - l + 1 - (k - 1)) / (k - 1);     long long res = 1LL * (m + 1) * (r - l - k + 2) % mod -                     1LL * (1 + m) * m / 2 % mod * (k - 1) % mod;     return res;   }   int main(int argc, char* argv[]) {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) {       if (i == 1)         s.push(make_pair(a[i], l[i] = 1));       else {         l[i] = i;         while (!s.empty() && s.top().first < a[i]) {           l[i] = s.top().second;           s.pop();         }         s.push(make_pair(a[i], l[i]));       }     }     while (!s.empty()) s.pop();     for (int i = n; i >= 1; i--) {       if (i == n)         s.push(make_pair(a[i], r[i] = n));       else {         r[i] = i;         while (!s.empty() && s.top().first <= a[i]) {           r[i] = s.top().second;           s.pop();         }         s.push(make_pair(a[i], r[i]));       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long res = cal(l[i], r[i]) - cal(l[i], i - 1) - cal(i + 1, r[i]);       res = res % mod * a[i] % mod;       ans = (ans + res) % mod;     }     if (ans < 0) ans += mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 10;   int n;   long long x[N], y[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &x[i], &y[i]);     }     while (1) {       vector<int> r;       for (int i = 1; i <= n; i++) {         if ((x[i] + y[i]) % 2 == 0) r.push_back(i);       }       if (r.size() == 0 || r.size() == n) {         for (int i = 1; i <= n; i++) {           long long tx = x[i];           long long ty = y[i];           x[i] = tx - ty;           y[i] = tx + ty;         }         if (x[1] % 2 != 0) {           for (int i = 1; i <= n; i++) {             x[i]++, y[i]++;             x[i] /= 2, y[i] /= 2;           }         }         while (1) {           bool ok = 1;           for (int i = 1; i <= n; i++) {             if (x[i] % 2 || y[i] % 2) ok = 0;           }           if (ok) {             for (int i = 1; i <= n; i++) {               x[i] /= 2, y[i] /= 2;             }           } else {             break;           }         }         continue;       }       printf( %d n , r.size());       for (auto x : r) {         printf( %d  , x);       }       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 2147483647;   const long long ll = 9223372036854775807, ninf = 1000000000;   const double eps = 1e-6;   const long long nll = 1000000000000000000;   class CircleOrder {    public:     string firstOrder(string s) {}   };   long long C[1005][1005] = {};   long long dp[1005] = {};   const int MOD = 998244353;   int main() {     for (int i = 0; i < 1005; i++) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; j++) {         C[i][j] = C[i - 1][j] + C[i - 1][j - 1];         C[i][j] %= MOD;       }     }     int a;     while (cin >> a) {       int A[1005] = {};       for (int i = 0; i < a; i++) cin >> A[i];       dp[a] = 1;       for (int i = a - 1; i >= 0; i--) {         if (A[i] <= 0) continue;         for (int j = i + A[i] + 1; j <= a; j++) {           dp[i] += (dp[j]) * (C[j - i - 1][A[i]]);           dp[i] %= MOD;         }       }       long long ans = 0;       for (int i = 0; i < a; i++) {         ans += dp[i];         ans %= MOD;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   inline int add(int a, int b);   inline int mult(int a, int b);   inline int sub(int a, int b);   inline int divv(int a, int b);   int p1[300500];   int p2[300500];   int pow1 = 37;   int pow2 = 41;   int mod1 = 1000000007;   int mod2 = 1000000009;   int32_t main() {     std::iostream::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     string s;     cin >> s;     int half = s.size() / 2;     set<char> st;     for (int i = 0; i < half; i++) st.insert(s[i]);     if (st.size() <= 1) {       cout <<  Impossible n ;       return 0;     }     for (int i = 1; i < s.size(); i++) {       string s1 = s.substr(0, i);       string s2 = s.substr(i, s.size());       string t = s2 + s1;       string rt = t;       reverse(rt.begin(), rt.end());       if (t != s && t == rt) {         cout <<  1 n ;         return 0;       }     }     cout <<  2 n ;     return 0;   }   int add(int a, int b) {     int result = a + b;     if (result >= mod) result -= mod;     return result;   }   int sub(int a, int b) {     int result = a - b;     if (result < 0) result += mod;     return result;   }   int mult(int a, int b) { return (a * 1ll * b) % mod; }   int bin(int a, int n) {     int res = 1;     while (n) {       if (n & 1) res = mult(res, a);       a = mult(a, a);       n /= 2;     }     return res;   }   int divv(int a, int b) { return mult(a, bin(b, mod - 2)); }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 3e3 + 4;   long long dp[N];   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int>> v(n);     for (int i = 0; i < n; i++)       scanf( %d , &v[i].first), scanf( %d , &v[i].second);     sort(v.begin(), v.end());     dp[n - 1] = v[n - 1].second;     for (int i = n - 2; i >= 0; i--) {       dp[i] = v[i].second + dp[i + 1];       long long sum = 0;       for (int j = i; j < n; j++) {         sum += (v[j].first - v[i].first);         dp[i] = min(dp[i], sum + dp[j + 1] + v[i].second);       }     }     cout << dp[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[n - 1] >= a[n - 2] + a[n - 3]) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (long long i = 0; i < n; i += 2) cout << a[i] <<    ;     for (long long i = n - n % 2 - 1; i >= 0; i -= 2) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int k, d, t;     cin >> k >> d >> t;     long long int k1, k2;     k1 = k;     k2 = (k / d) * d + (int)(k % d != 0) * d - k;     t *= 2;     long long int bal = 2 * k1 + k2;     long long int n = t / bal;     double time = n * (k1 + k2);     double extra = 1 - ((double)n / (double)t) * (double)bal;     double work_done_by_k1 = 2 * (double)k1 / (double)t;     double work_done_by_k2 = (double)k2 / (double)t;     if (extra > work_done_by_k1) {       time += (k1 + (double)(extra - work_done_by_k1) * (double)t);     } else {       time += (double)extra * (double)t / 2;     }     printf( %f n , time);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, d;       cin >> a >> b >> d;       if (d < a)         cout << d << endl;       else {         cout << b + d - (b % d) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int x1, yy1, r1, R1;   int x2, y2, r2, R2;   int dis;   inline bool inside(int r, int R) {     double dist = sqrt((double)dis);     if (dist <= double(R - r)) return true;     return false;   }   inline bool outside(int r, int R) {     double dist = sqrt((double)dis);     if (dist >= double(R + r)) return true;     return false;   }   int main() {     scanf( %d%d%d%d , &x1, &yy1, &r1, &R1);     scanf( %d%d%d%d , &x2, &y2, &r2, &R2);     dis = (x1 - x2) * (x1 - x2) + (yy1 - y2) * (yy1 - y2);     if (R1 > R2) {       swap(x1, x2);       swap(yy1, y2);       swap(r1, r2);       swap(R1, R2);     }     int ans = 0;     if (inside(r1, r2) || outside(r1, R2)) ans++;     if (inside(R1, r2) || outside(R1, R2)) ans++;     if (inside(R1, r2) || inside(r2, r1) || outside(r2, R1)) ans++;     if (inside(R1, R2) || outside(R1, R2)) ans++;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, x;     bool tt = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> x;       v.push_back(x);     }     for (int i = 1; i < n; ++i) {       if (v[i] <= v[i - 1])         tt = true;       else if (tt && v[i] > v[i - 1])         return cout <<  NO n , 0;     }     reverse(v.begin(), v.end());     tt = 0;     for (int i = 1; i < n; ++i) {       if (v[i] <= v[i - 1])         tt = true;       else if (tt && v[i] > v[i - 1])         return cout <<  NO n , 0;     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   const int inf = 1e6;   int n, m;   int a[maxn + 5], b[maxn + 5];   int tag[maxn << 2], mx[maxn << 2];   void seta(int p, int d) {     tag[p] += d;     mx[p] += d;   }   void push(int p) {     seta(p + p, tag[p]);     seta(p + p + 1, tag[p]);     tag[p] = 0;   }   void modify(int p, int l, int r, int ql, int qr, int d) {     if (l == ql && r == qr) {       seta(p, d);       return;     }     push(p);     int mid = (l + r) >> 1;     if (qr <= mid)       modify(p + p, l, mid, ql, qr, d);     else if (mid < ql)       modify(p + p + 1, mid + 1, r, ql, qr, d);     else       modify(p + p, l, mid, ql, mid, d),           modify(p + p + 1, mid + 1, r, mid + 1, qr, d);     mx[p] = max(mx[p + p], mx[p + p + 1]);   }   int query(int p, int l, int r) {     if (l == r) return l;     push(p);     int mid = (l + r) >> 1;     if (mx[p + p + 1] > 0)       return query(p + p + 1, mid + 1, r);     else       return query(p + p, l, mid);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       modify(1, 1, inf, 1, a[i], 1);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);       modify(1, 1, inf, 1, b[i], -1);     }     int q;     scanf( %d , &q);     while (q--) {       int op, i, x;       scanf( %d %d %d , &op, &i, &x);       if (op == 1) {         modify(1, 1, inf, 1, a[i], -1);         a[i] = x;         modify(1, 1, inf, 1, a[i], 1);       } else {         modify(1, 1, inf, 1, b[i], 1);         b[i] = x;         modify(1, 1, inf, 1, b[i], -1);       }       if (mx[1] <= 0)         printf( %d n , -1);       else         printf( %d n , query(1, 1, inf));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 5;   struct node {     long long x, y;     int id;     bool operator<(const node &ope) const { return y < ope.y; }   } a[maxn];   bool vis[maxn][maxn];   long long dp[maxn][maxn];   bool vis2[maxn];   inline void init() {     memset(dp, -1, sizeof(dp));     memset(vis, false, sizeof(vis));     memset(vis2, false, sizeof(vis2));   }   void solve(int n, int k) {     init();     dp[0][0] = 0;     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; ++i) {       int t = ((i) < (k) ? (i) : (k));       for (int j = 0; j <= t; ++j) {         if (dp[i - 1][j] >= 0) dp[i][j] = dp[i - 1][j] + (k - 1) * 1ll * a[i].y;         if (j > 0 && dp[i - 1][j - 1] >= 0) {           if (dp[i][j] >= dp[i - 1][j - 1] + a[i].x + (j - 1) * 1ll * a[i].y)             continue;           dp[i][j] = dp[i - 1][j - 1] + a[i].x + (j - 1) * 1ll * a[i].y;           vis[i][j] = true;         }       }     }   }   void print(int n, int k) {     printf( %d n , k + (n - k) * 2);     for (int i = n, j = k; i > 0 && j >= 0; --i) {       if (vis[i][j]) vis2[i] = true, --j;     }     int t = 0;     for (int i = 1; i <= n; ++i) {       if (!vis2[i]) continue;       if (++t == k) {         t = a[i].id;         break;       }       printf( %d  , a[i].id);     }     for (int i = 1; i <= n; ++i) {       if (!vis2[i]) printf( %d %d  , a[i].id, -a[i].id);     }     printf( %d n , t);   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; ++i) {         scanf( %lld%lld , &a[i].x, &a[i].y);         a[i].id = i;       }       solve(n, k);       print(n, k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, a[105], S;   int main() {     cin >> t;     while (t--) {       cin >> n >> m;       S = 0;       for (int i = 1; i <= n; ++i) {         cin >> a[i];         S = S + a[i];       }       if (S == m)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   using ll = long long int;   using ld = long double;   template <typename T, typename V>   using P = pair<T, V>;   template <typename T>   using V = vector<T>;   constexpr ll MOD = 1e9 + 7;   constexpr ll INF = 0x3f3f3f3f;   constexpr ld PI = 3.1415926535897932384626;   constexpr ld EPS = 1e-9;   constexpr ll MAX = 1e5 + 5;   void solve() {     ll n;     cin >> n;     V<ll> a(n + 1);     for (ll i = (ll)(1); i < (ll)(n + 1); i++) cin >> a[i];     if (a[1]) {       cout << n + 1 <<    ;       for (ll i = (ll)(1); i < (ll)(n + 1); i++) cout << i <<    n [i == n];       return;     } else if (!a[n]) {       for (ll i = (ll)(1); i < (ll)(n + 1); i++) cout << i <<    ;       cout << n + 1 <<   n ;       return;     }     for (ll i = (ll)(1); i < (ll)(n); i++)       if (!a[i] && a[i + 1]) {         for (ll j = (ll)(1); j < (ll)(i + 1); j++) cout << j <<    ;         cout << n + 1 <<    ;         for (ll j = (ll)(i + 1); j < (ll)(n + 1); j++) cout << j <<    n [j == n];         return;       }     cout <<  -1 n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ll t = 1;     cin >> t;     for (ll i = (ll)(1); i < (ll)(t + 1); i++) solve();   }