#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)3e3 + 5;   const long long INF = (long long)1e15;   pair<int, long long> dp[MAXN][MAXN];   vector<int> adj[MAXN];   int arr[MAXN];   int sub[MAXN];   int n, m;   void dfs(int v, int pr = -1) {     fill(dp[v], dp[v] + n + 1, make_pair(-n, -INF));     dp[v][0] = make_pair(0, 0);     sub[v] = 1;     for (int to : adj[v]) {       if (to == pr) {         continue;       }       dfs(to, v);     }     vector<pair<int, long long> > ndp(n + 5, make_pair(-n, -INF));     for (int to : adj[v]) {       if (to == pr) {         continue;       }       for (int i = 0; i <= sub[v] + sub[to] + 3; ++i) {         ndp[i] = make_pair(-n, -INF);       }       for (int i = sub[v]; i >= 0; --i) {         for (int j = sub[to]; j >= 0; --j) {           if (dp[v][i].second == -INF || dp[to][j].second == -INF ||               dp[v][i].first < 0 || dp[to][j].first < 0) {             continue;           }           if (dp[to][j].second > 0) {             ndp[i + j + 1] = max(                 ndp[i + j + 1],                 make_pair(dp[v][i].first + dp[to][j].first + 1, dp[v][i].second));           } else {             ndp[i + j + 1] =                 max(ndp[i + j + 1],                     make_pair(dp[v][i].first + dp[to][j].first, dp[v][i].second));           }           ndp[i + j] =               max(ndp[i + j], make_pair(dp[v][i].first + dp[to][j].first,                                         dp[v][i].second + dp[to][j].second));         }       }       for (int j = 0; j < n; ++j) {         dp[v][j] = ndp[j];       }       sub[v] += sub[to];     }     for (int i = 0; i < n; ++i) {       if (dp[v][i].second != -INF) {         dp[v][i].second += arr[v];       }     }   }   void solve() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) {       adj[i].clear();       arr[i] = 0;     }     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       arr[i] = -x;     }     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       arr[i] += x;     }     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     printf( %d n , dp[1][m - 1].first + (dp[1][m - 1].second > 0));   }   int main() {     int tt;     scanf( %d , &tt);     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf( %d , &n);     if (n & 1)       printf( %d n , (n - 1) / 2);     else {       int w = 1;       while (w <= n) w *= 2;       w /= 2;       printf( %d n , (n - w) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve(vector<int> a, int bit) {     if (bit == 0) {       return a.size();     }     if (a.size() <= 1) {       return a.size();     }     vector<int> v0, v1;     for (int x : a) {       if (1 & (x >> bit)) {         v0.push_back(x);       } else {         v1.push_back(x);       }     }     return max(solve(v0, bit - 1) + (v1.size() ? 1 : 0),                solve(v1, bit - 1) + (v0.size() ? 1 : 0));   }   int main() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int ans = solve(arr, 30);     cout << n - ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T x, T y) {     if (x < y) swap(x, y);     while (y > 0) {       T f = x % y;       x = y;       y = f;     }     return x;   }   const int maxn = 100007;   int BLOCKSIZE = 350;   set<int> s[maxn];   int a[maxn];   int nxt[maxn];   int n, m;   long long b[maxn];   int d[maxn];   long long query(int block, int R) {     int iBlockStart = block * BLOCKSIZE;     int iBlockEnd = min((block + 1) * BLOCKSIZE, n);     int idx = upper_bound(d + iBlockStart, d + iBlockEnd, R,                           [](int i, int j) { return i < nxt[j]; }) -               d;     if (idx == iBlockStart) return 0;     return b[idx - 1];   }   void updateBlock(int block) {     int iBlockStart = block * BLOCKSIZE;     int iBlockEnd = min((block + 1) * BLOCKSIZE, n);     sort(d + iBlockStart, d + iBlockEnd,          [](int i, int j) { return nxt[i] < nxt[j]; });     b[iBlockStart] = nxt[d[iBlockStart]] - d[iBlockStart];     for (int i = iBlockStart + 1; i < iBlockEnd; i++)       b[i] = b[i - 1] + nxt[d[i]] - d[i];   }   int main(int argc, char *argv[]) {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n >> m;     {       BLOCKSIZE = 1;       while (BLOCKSIZE * BLOCKSIZE < n) BLOCKSIZE++;       BLOCKSIZE = max(BLOCKSIZE, 10);       for (int i = 0; i < n; i++) nxt[i] = n + 1, d[i] = i;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (!s[a[i]].empty()) nxt[*s[a[i]].rbegin()] = i;         s[a[i]].insert(i);       }       for (int i = 0; i * BLOCKSIZE < n; i++) updateBlock(i);       for (int i = 0; i < m; i++) {         int op;         cin >> op;         if (op == 1) {           int p, x;           cin >> p >> x;           p--;           if (a[p] == x) continue;           {             auto it = s[a[p]].find(p);             if (it != s[a[p]].begin()) {               int pr = *prev(it);               auto nxt_it = it == s[a[p]].end() ? it : next(it);               nxt[pr] = nxt_it == s[a[p]].end() ? (n + 1) : *nxt_it;               updateBlock(pr / BLOCKSIZE);             }           }           s[a[p]].erase(p);           a[p] = x;           nxt[p] = n + 1;           if (!s[x].empty()) {             auto it = s[x].upper_bound(p);             if (it != s[x].begin()) {               int pr = *prev(it);               nxt[pr] = p;               updateBlock(pr / BLOCKSIZE);             }             if (it != s[x].end()) {               nxt[p] = (it == s[x].end()) ? (n + 1) : *it;             }           }           s[a[p]].insert(p);           updateBlock(p / BLOCKSIZE);         } else {           int l, r, R;           cin >> l >> r;           l--;           r--;           R = r;           long long res = 0;           for (; l <= r && l % BLOCKSIZE; l++)             if (nxt[l] <= R) res += nxt[l] - l;           for (; l <= r && (r + 1) % BLOCKSIZE; r--)             if (nxt[r] <= R) res += nxt[r] - r;           if (l <= r) {             for (int i = l / BLOCKSIZE, j = r / BLOCKSIZE; i <= j; i++) {               res += query(i, R);             }           }           cout << res << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long int, long long int> &a,             pair<long long int, long long int> &b) {     if (a.first == b.first) return a.second < b.second;     return a.first > b.first;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, d;     cin >> n >> m >> d;     pair<long long int, long long int> py[n], in[m];     for (int i = 0; i < n; i++) cin >> py[i].first >> py[i].second;     for (int i = 0; i < m; i++) cin >> in[i].first >> in[i].second;     sort(py, py + n, comp);     sort(in, in + m, comp);     int p1 = 0, p2 = 1;     long long int sm = py[0].first + in[0].first;     long long int w = py[0].second + in[0].second;     if (w > d) {       cout <<  0 n ;       return 0;     }     long long int ans = sm;     while (p2 < m) {       sm += in[p2].first;       w += in[p2].second;       if (w <= d) ans = sm;       p2++;     }     p2 = m - 1;     while (p1 != n - 1) {       p1++;       sm += py[p1].first;       w += py[p1].second;       while (w > d and p2 > 0) {         sm -= in[p2].first;         w -= in[p2].second;         p2--;       }       if (w <= d) ans = max(ans, sm);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, h, n, i;   long long x, ans;   pair<pair<int, int>, int> p[100005];   map<long long, long long> f;   void update(int index, long long value) {     while (index < 1e9) {       f[index] = max(f[index], value);       index += (-index & index);     }   }   long long read(int index) {     long long ans = 0;     while (index > 0) {       ans = max(ans, f[index]);       index -= (-index & index);     }     return ans;   }   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++)       scanf( %d%d%d , &p[i].first.second, &p[i].first.first, &p[i].second);     sort(p, p + n);     reverse(p, p + n);     for (i = 0; i < n; i++) {       x = read(p[i].first.first) + p[i].second;       update(p[i].first.second + 1, x);       ans = max(ans, x);     }     printf( %lld , ans);   }


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


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using vi = vector<int>;   const ld EPS = 1E-9;   struct pt {     ld x, y;   };   struct seg {     pt p, q;     int id;     ld get_y(ld x) const {       if (abs(p.x - q.x) < EPS) return p.y;       return p.y + (q.y - p.y) * (x - p.x) / (q.x - p.x);     }   };   inline bool intersect1d(ld l1, ld r1, ld l2, ld r2) {     if (l1 > r1) swap(l1, r1);     if (l2 > r2) swap(l2, r2);     return max(l1, l2) <= min(r1, r2) + EPS;   }   inline int vec(const pt& a, const pt& b, const pt& c) {     ld s = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);     return abs(s) < EPS ? 0 : s > 0 ? +1 : -1;   }   bool intersect(const seg& a, const seg& b) {     return intersect1d(a.p.x, a.q.x, b.p.x, b.q.x) &&            intersect1d(a.p.y, a.q.y, b.p.y, b.q.y) &&            vec(a.p, a.q, b.p) * vec(a.p, a.q, b.q) <= 0 &&            vec(b.p, b.q, a.p) * vec(b.p, b.q, a.q) <= 0;   }   bool operator<(const seg& a, const seg& b) {     ld x = max(min(a.p.x, a.q.x), min(b.p.x, b.q.x));     return a.get_y(x) < b.get_y(x) - EPS;   }   struct event {     ld x;     int tp, id;     event() {}     event(ld x, int tp, int id) : x(x), tp(tp), id(id) {}     bool operator<(const event& e) const {       if (abs(x - e.x) > EPS) return x < e.x;       return tp > e.tp;     }   };   set<seg> s;   vector<set<seg>::iterator> where;   inline set<seg>::iterator prev(set<seg>::iterator it) {     return it == s.begin() ? s.end() : --it;   }   inline set<seg>::iterator next(set<seg>::iterator it) { return ++it; }   pair<int, int> solve(const vector<seg>& a) {     int n = (int)a.size();     vector<event> e;     for (int i = 0; i < n; ++i) {       e.push_back(event(min(a[i].p.x, a[i].q.x), +1, i));       e.push_back(event(max(a[i].p.x, a[i].q.x), -1, i));     }     sort(e.begin(), e.end());     s.clear();     where.resize(a.size());     for (size_t i = 0; i < e.size(); ++i) {       int id = e[i].id;       if (e[i].tp == +1) {         set<seg>::iterator nxt = s.lower_bound(a[id]), prv = prev(nxt);         if (nxt != s.end() && intersect(*nxt, a[id]))           return make_pair(nxt->id, id);         if (prv != s.end() && intersect(*prv, a[id]))           return make_pair(prv->id, id);         where[id] = s.insert(nxt, a[id]);       } else {         set<seg>::iterator nxt = next(where[id]), prv = prev(where[id]);         if (nxt != s.end() && prv != s.end() && intersect(*nxt, *prv))           return make_pair(prv->id, nxt->id);         s.erase(where[id]);       }     }     return make_pair(-1, -1);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<pt> S(n), V(n);     vi U(n);     for (int i = 0; i < n; i++) {       cin >> S[i].x >> S[i].y >> V[i].x >> V[i].y >> U[i];       ld len = sqrt(V[i].x * V[i].x + V[i].y * V[i].y);       V[i].x /= len;       V[i].y /= len;       V[i].x *= U[i];       V[i].y *= U[i];     }     ld lf = 0, rg = 1e12;     {       ld md = rg;       vector<seg> a(n);       for (int i = 0; i < n; i++) {         a[i].id = i;         a[i].p = S[i];         ld X = S[i].x + V[i].x * md;         ld Y = S[i].y + V[i].y * md;         a[i].q = {X, Y};       }       if (solve(a) == make_pair(-1, -1)) {         cout <<  No show :( ;         return 0;       }     }     const ld _eps = 1e-8;     while ((rg - lf) > _eps) {       ld md = (lf + rg) / 2;       vector<seg> a(n);       for (int i = 0; i < n; i++) {         a[i].id = i;         a[i].p = S[i];         ld X = S[i].x + V[i].x * md;         ld Y = S[i].y + V[i].y * md;         a[i].q = {X, Y};       }       if (solve(a) != make_pair(-1, -1)) {         rg = md;       } else {         lf = md;       }     }     cout.precision(10);     cout << fixed << (lf + rg) / 2;   }


#include <bits/stdc++.h>   using namespace std;   char str[200005];   int main() {     int ts;     scanf( %d , &ts);     while (ts--) {       int n;       scanf( %d %s , &n, str);       vector<int> vec;       for (int i = 0; i < n; i++) {         int j = i, c = 0;         while (i < n && str[i] == str[j]) i++, c++;         i--;         vec.push_back(c);       }       if (vec.size() == 1 && vec[0] > 2) vec[0] += 2;       if (vec.size() != 1 && str[0] == str[n - 1])         vec[0] += vec.back(), vec.pop_back();       int res = 0;       for (int i = 0; i < vec.size(); i++) res += vec[i] / 3;       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   int main() {     int n;     long long k;     scanf( %d%I64d , &n, &k);     long long ans = 1;     bool ok = false;     for (int i = 0; i < n; ++i) {       long long x;       scanf( %I64d , &x);       if (ans) ans = lcm(ans, x) % k;       if (ans == 0) ok = true;     }     if (ok)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mr[] = {0, 1, 0, -1};   int mc[] = {1, 0, -1, 0};   char a[52][52];   int id[52][52];   int ar[2500], br[2500], ac[2500], bc[2500];   void flood(int r, int c, char color, int tag) {     ar[tag] = min(ar[tag], r);     br[tag] = max(br[tag], r);     ac[tag] = min(ac[tag], c);     bc[tag] = max(bc[tag], c);     id[r][c] = tag;     for (int o = 0; o < 4; o++) {       int dr = r + mr[o];       int dc = c + mc[o];       if (a[dr][dc] == color && id[dr][dc] < 0) flood(dr, dc, color, tag);     }   }   int main() {     int n, m, s, cnt = 0;     scanf( %d%d , &n, &s);     for (int i = 1; i <= n; i++) scanf( %s , a[i] + 1);     m = strlen(a[1] + 1);     memset(id, 255, sizeof(id));     memset(ar, 127, sizeof(ar));     memset(br, 128, sizeof(br));     memset(ac, 127, sizeof(ac));     memset(bc, 128, sizeof(bc));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (id[i][j] < 0) flood(i, j, a[i][j], cnt++);     int r = 1, c = 1, dp = 0, cp = 0;     while (s--) {       int tr = r, tc = c, tag = id[r][c];       if (dp == 0 && cp == 0) tr = ar[tag], tc = bc[tag] + 1;       if (dp == 0 && cp == 1) tr = br[tag], tc = bc[tag] + 1;       if (dp == 1 && cp == 0) tr = br[tag] + 1, tc = bc[tag];       if (dp == 1 && cp == 1) tr = br[tag] + 1, tc = ac[tag];       if (dp == 2 && cp == 0) tr = br[tag], tc = ac[tag] - 1;       if (dp == 2 && cp == 1) tr = ar[tag], tc = ac[tag] - 1;       if (dp == 3 && cp == 0) tr = ar[tag] - 1, tc = ac[tag];       if (dp == 3 && cp == 1) tr = ar[tag] - 1, tc = bc[tag];       if (!a[tr][tc] || a[tr][tc] ==  0 ) {         cp ^= 1;         if (!cp) dp = (dp + 1) & 3;       } else {         r = tr;         c = tc;       }     }     printf( %c n , a[r][c]);   }


#include <bits/stdc++.h>   using namespace std;   int N, K, T, to[25];   long double prob[25], dp[2000100], val[25], ans[25];   bool v[2000100];   long double calc(int mask) {     if (v[mask]) return dp[mask];     v[mask] = 1;     int i;     long double tot = 0;     for (i = 0; i < N; i++)       if (mask & (1 << i)) tot += prob[i];     for (i = 0; i < N; i++)       if (mask & (1 << i)) {         tot -= prob[i];         dp[mask] = dp[mask] + (prob[i] * calc(mask - (1 << i))) / (1 - tot);         tot += prob[i];       }     return dp[mask];   }   void get_masks(int mask, int cnt, int p) {     if (p == N || cnt == K) {       if (cnt != K) return;       calc(mask);       int i;       for (i = 0; i < N; i++)         if (mask & (1 << i)) val[i] += dp[mask];       return;     }     get_masks(mask, cnt, p + 1);     get_masks(mask + (1 << p), cnt + 1, p + 1);   }   int main() {     cin >> N >> K;     int i;     for (i = 0; i < N; i++) {       cin >> prob[i];       if (prob[i] != 0) {         T++;         prob[T - 1] = prob[i];         to[T - 1] = i;       }     }     swap(T, N);     if (K > N) K = N;     dp[0] = 1, v[0] = 1;     get_masks(0, 0, 0);     for (i = 0; i < N; i++) ans[to[i]] = val[i];     for (i = 0; i < T; i++) cout << fixed << setprecision(9) << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> graph[200010];   long long v[200010], new_visit[200010], MAX_node, mx, cnt;   void dfs(long long node) {     v[node] = 1;     if ((long long)graph[node].size() > mx) {       mx = (long long)graph[node].size();       MAX_node = node;     }     for (auto &x : graph[node])       if (!v[x]) dfs(x);   }   void bfs(long long node) {     queue<long long> q;     q.push(node);     while (!q.empty()) {       long long frt = q.front();       new_visit[frt] = 1;       q.pop();       for (auto &x : graph[frt]) {         if (!new_visit[x]) {           new_visit[x] = 1;           cout << frt <<     << x << endl;           q.push(x);           cnt--;           if (cnt == 0) return;         }       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m;     cin >> n >> m;     cnt = n - 1;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       graph[x].push_back(y);       graph[y].push_back(x);     }     dfs(1);     bfs(MAX_node);   }


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


#include <bits/stdc++.h>   using namespace std;   long long n, m, budget;   long long price[100005], perMoney[100005];   bool can(int k) {     long long curBudget = 0;     int j = 0;     for (int i = k - 1; i >= 0; i--, j++) {       curBudget += max(0ll, price[j] - perMoney[i]);     }     return curBudget <= budget;   }   int main() {     cin >> n >> m >> budget;     for (int i = 0; i < n; i++) cin >> perMoney[i];     for (int i = 0; i < m; i++) cin >> price[i];     sort(price, price + m);     sort(perMoney, perMoney + n);     reverse(perMoney, perMoney + n);     long long lo = 0, hi = min(m, n);     while (lo < hi) {       long long mid = (lo + hi + 1) / 2;       if (can(mid))         lo = mid;       else         hi = mid - 1;     }     long long spent = 0;     for (int i = 0; i < lo; i++) {       spent += price[i];     }     cout << lo <<     << max(0ll, spent - budget) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int loc;     int s;     int v;     Node(int ll, int ss, int vv) : loc(ll), s(ss), v(vv) {}     bool operator<(const Node& other) const { return v > other.v; }   };   vector<pair<int, int> > adj[32];   int main() {     priority_queue<Node> que;     int N, K, T;     scanf( %d%d%d , &N, &K, &T);     while (K--) {       int h, w, r;       scanf( %d%d%d , &h, &w, &r);       h--;       w--;       adj[h].push_back(pair<int, int>(w, r));     }     que.push(Node(0, 0, 0));     int now = 0;     while (now + 1 < T) {       Node p = que.top();       que.pop();       now++;       for (int h = p.loc; h < N; h++) {         for (int i = 0; i < adj[h].size(); i++) {           pair<int, int> w = adj[h][i];           if (!(p.s & (1 << w.first)))             que.push(Node(h + 1, p.s | (1 << w.first), p.v + w.second));         }       }     }     printf( %d n , que.top().v);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, i, j, k, b[200005], a[200005], x, m, l, r, mid, ans, s;   vector<long long> u, v;   int main() {     ios::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       if (x % 2)         v.push_back(x);       else         u.push_back(x);       s += x;     }     sort(u.begin(), u.end(), greater<long long>());     sort(v.begin(), v.end(), greater<long long>());     n = v.size();     m = u.size();     n = min(n, m);     for (i = 0; i < n; i++) s -= u[i] + v[i];     if (u.size() > v.size()) s -= u[i];     if (u.size() < v.size()) s -= v[i];     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int visit[111111];   vector<int> v[111111], mark[111111];   int dfs(int t) {     vector<int> v1;     int i;     for (i = 0; i < v[t].size(); i++) {       int u = v[t][i];       if (visit[mark[t][i]] == 0) {         visit[mark[t][i]] = 1;         int w = dfs(u);         if (w == 0)           v1.push_back(u);         else           printf( %d %d %d n , t, u, w);       }     }     while (v1.size() > 1) {       printf( %d %d %d n , v1[v1.size() - 1], t, v1[v1.size() - 2]);       v1.pop_back();       v1.pop_back();     }     if (v1.size() == 1)       return v1[0];     else       return 0;   }   int main() {     memset(visit, 0, sizeof(visit));     scanf( %d%d , &n, &m);     int i;     for (i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);       mark[a].push_back(i);       mark[b].push_back(i);     }     if (m % 2)       printf( No solution n );     else {       for (i = 1; i <= n; i++) dfs(i);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> vi1, vi2;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       vi1.push_back(x);     }     sort(vi1.begin(), vi1.end());     vi1.push_back(1e9);     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       if (a == 1) vi2.push_back(b);     }     sort(vi2.begin(), vi2.end());     int j = 0, mini = vi2.size();     for (int i = 0; i <= n; i++) {       int hi = vi1[i];       while (j < vi2.size() && vi2[j] < hi) {         j++;       }       int asdf = vi2.size();       mini = min(mini, i + asdf - j);     }     cout << mini;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int t, h, g;     cin >> t;     while (t--) {       scanf( %d %d , &h, &g);       int n = (1 << h) - 1, m = (1 << g) - 1;       std::vector<pair<int, int> > a(1 << h);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i].first);         a[i].second = i + 1;       }       sort(a.begin(), a.end());       std::vector<int> notFree(n + 1, 0), taken(n + 1, 0);       ll ans = 0LL;       for (int i = 0; i < n; i++) {         int where = a[i].second;         while (where > m or notFree[where]) where = where >> 1;         if (!where) continue;         if (notFree[where << 1] == notFree[where << 1 | 1]) {           notFree[where] = 1;           ans += a[i].first;           taken[a[i].second] = 1;         }       }       printf( %lld n , ans);       for (int i = n; i >= 1; i--) {         if (!taken[i]) printf( %d  , i);         ;       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, cnt = 0;     cin >> n;     vector<vector<int>> adj(n);     vector<int> deg(n);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--, y--;       adj[x].push_back(y);       adj[y].push_back(x);       deg[x]++, deg[y]++;     }     for (int i = 0; i < n; i++)       if (deg[i] == 1)         cnt++;       else if (deg[i] == 2) {         cnt = 0;         break;       }     if ((long long)cnt * (cnt - 1) >= 2 * (n - 1))       cout <<  YES  <<   n ;     else       cout <<  NO  <<   n ;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   struct node {     int x, l;   } a[200005];   int skip[200005][25];   int mx[200005];   long long f[200005][25];   inline int read() {     register int x = 0, f = 1;     register char s = getchar();     while (s >  9  || s <  0 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   inline int max(const int &x, const int &y) { return x > y ? x : y; }   int main() {     int n = read();     for (register int i = 1; i <= n; ++i) {       a[i].x = read();       a[i].l = read();     }     for (register int i = n - 1; i >= 1; --i) {       int cur = i + 1;       mx[i] = a[i].x + a[i].l;       while (cur && a[i].x + a[i].l >= a[cur].x) {         mx[i] = max(mx[i], mx[cur]);         cur = skip[cur][0];       }       skip[i][0] = cur;       f[i][0] = a[cur].x - mx[i];     }     for (register int i = 1; i <= 20; ++i) {       for (register int x = 1; x <= n; ++x) {         f[x][i] = f[x][i - 1] + f[skip[x][i - 1]][i - 1];         skip[x][i] = skip[skip[x][i - 1]][i - 1];       }     }     int Q = read();     while (Q--) {       int l = read(), r = read();       if (skip[l][0] > r) {         printf( 0 n );       } else {         long long ans = 0;         for (register int i = 20; i >= 0; --i) {           if (skip[l][i] && skip[l][i] <= r) {             ans += f[l][i];             l = skip[l][i];           }         }         printf( %lld n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<int> v(n);       set<int> st;       for (int i = 0; i < n; i++) {         cin >> v[i];         st.insert(v[i]);       }       sort(v.begin(), v.end());       int mx = v.back();       int ans = mx;       if (mx % 2 == 0 && mx % 3 == 0 && mx % 5 == 0) {         if (st.find(mx / 2) != st.end() && st.find(mx / 3) != st.end() &&             st.find(mx / 5) != st.end()) {           ans = max(ans, mx / 2 + mx / 3 + mx / 5);         }       }       vector<int> tmp;       while (!st.empty() && tmp.size() < 3) {         int x = *st.rbegin();         st.erase(prev(st.end()));         bool f = 1;         for (auto it : tmp) {           if (it % x == 0 || x % it == 0) f = 0;         }         if (f) tmp.push_back(x);       }       int sum = 0;       for (auto it : tmp) sum += it;       ans = max(ans, sum);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> arr(78498);   vector<vector<int>> in(505, vector<int>(505));   vector<vector<int>> out(505, vector<int>(505));   void SieveOfEratosthenes(int n) {     vector<bool> prime(n + 1, true);     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     int i = 0;     for (int p = 2; p <= n; p++)       if (prime[p]) arr[i++] = p;   }   int f(int val) {     int l = 0, u = arr.size() - 1, res = -1;     while (l <= u) {       int mid = (l + u) / 2;       if (val == arr[mid])         return -2;       else if (val < arr[mid]) {         res = mid;         u = mid - 1;       } else         l = mid + 1;     }     return res;   }   int main() {     SieveOfEratosthenes(1000000);     sort(arr.begin(), arr.end());     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> in[i][j];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int res = f(in[i][j]);         if (res == -2)           out[i][j] = 0;         else if (res == -1)           cout <<  error  << endl;         else {           out[i][j] = arr[res] - in[i][j];         }       }     }     long long mini = pow(10, 18);     for (int i = 0; i < n; i++) {       long long tot = 0;       for (int j = 0; j < m; j++) tot += (long long)out[i][j];       mini = min(mini, tot);     }     for (int j = 0; j < m; j++) {       long long tot = 0;       for (int i = 0; i < n; i++) tot += (long long)out[i][j];       mini = min(mini, tot);     }     cout << mini << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[103], c;     int length, i, m;     gets(a);     length = strlen(a);     for (i = length - 2; i >= 0; --i) {       if (a[i] !=    ) {         c = a[i];         break;       }     }     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  ||         c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y ) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int vp, vd, t, f, c, ans;     double cc, d;     scanf( %d%d%d%d%d , &vp, &vd, &t, &f, &c);     if (vd <= vp) {       printf( 0 n );       return 0;     }     d = vp * t;     cc = c;     ans = 0;     while (1) {       if (d + d / (vd - vp) * vp >= cc - 1e-9) break;       ans++;       d = d + (2 * d / (vd - vp) + f) * vp;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int n, x, now;   long long ans;   char a[3];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a[0] ==  a ) {         cin >> x;         v.insert(lower_bound(v.begin(), v.end(), x), x);       }       if (a[0] ==  d ) {         cin >> x;         v.erase(lower_bound(v.begin(), v.end(), x));       }       if (a[0] ==  s ) {         ans = 0;         for (int i = 2; i < v.size(); i += 5) ans += v[i];         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   inline void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   inline void writes(string s) { puts(s.c_str()); }   inline void writeln() { writes(  ); }   inline void writei(int x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline void writell(long long x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   int n, h, m, i, j, dis[3005], cnt, ans, s = 0, t = 3001;   vector<int> e[3005];   struct edg {     int y, z;   } a[1111111];   void add(int x, int y, int z) {     cnt++;     e[x].push_back(cnt * 2 - 2);     e[y].push_back(cnt * 2 - 1);     a[cnt * 2 - 2] = (edg){y, z};     a[cnt * 2 - 1] = (edg){x, 0};   }   int id(int x, int y) { return (x - 1) * h + y; }   bool bfs(int s, int t) {     queue<int> q;     memset((dis), (0x16), (sizeof((dis))));     dis[s] = 0;     q.push(s);     while (!q.empty()) {       int x = q.front();       q.pop();       for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)         if (a[*it].z) {           if (dis[a[*it].y] > dis[x] + 1) {             dis[a[*it].y] = dis[x] + 1;             q.push(a[*it].y);           }         }     }     return dis[t] < dis[t + 1];   }   int dfs(int x, int tt, int flw) {     if (x == tt || !flw) return flw;     int ans = 0;     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {       if (a[*it].z && dis[x] + 1 == dis[a[*it].y]) {         int t = dfs(a[*it].y, tt, min(flw, a[*it].z));         ans += t;         flw -= t;         a[*it].z -= t;         a[(*it) ^ 1].z += t;       }       if (!flw) break;     }     if (flw) dis[x] = -1;     return ans;   }   int dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       ans += dfs(s, t, 0x3bbbbbbb);     }     return ans;   }   int main() {     read(n);     read(h);     read(m);     for (((i)) = (1); ((i)) <= ((n)); ((i))++) {       for (((j)) = (1); ((j)) <= ((h)); ((j))++) {         if (j < h) add(id(i, j + 1), id(i, j), 0x3bbbbbbb);         add(s, id(i, j), j * 2 - 1);         ans += j * 2 - 1;       }     }     for (((i)) = (1); ((i)) <= ((m)); ((i))++) {       int l, r, ys, c;       read(l);       read(r);       read(ys);       read(c);       if (ys < h)         for ((j) = (l); (j) <= (r); (j)++) {           add(id(j, ys + 1), i + 2500, 0x3bbbbbbb);         }       add(i + 2500, t, c);     }     cout << ans - dinic(s, t) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Jora {    public:     int a;     int b;   };   int myfunc(Jora A, Jora B) {     if (A.a < B.a) return 1;     if (A.a > B.a) return 0;     return A.b < B.b;   }   Jora jrr[200200];   int n;   vector<int> ser;   map<int, int> taken;   map<int, vector<int> > mp;   int sss;   int cal() {     map<int, int> val, ans;     for (int i = 0; i < ser.size(); i++) {       val[ser[i]] = 2000000000;       ans[ser[i]] = 0;     }     int sum = 0;     int cur = 0;     int tim = 1;     for (int i = 0; i < ser.size(); i++) {       int to = ser[i];       int uu = ((to - cur) + sum) % 1000000007;       if (val[to] > uu) {         val[to] = uu;         ans[to] = tim;       } else if (val[to] == uu) {         ans[to] = (ans[to] + tim) % 1000000007;       }       int aa = val[to];       int bb = ans[to];       vector<int> &vvv = mp[to];       for (int j : vvv) {         if (val[j] > aa) {           val[j] = aa;           ans[j] = bb;         } else if (val[j] == aa) {           ans[j] = (ans[j] + bb) % 1000000007;         }       }       sum = aa;       cur = to;       tim = bb;     }     int tot = 0;     int value = 2000000000;     map<int, int> mrk;     for (int i = 1; i <= n; i++) {       int u = jrr[i].a;       if (mrk[u] != 1 && u > sss) {         if (val[u] < value) {           value = val[u];           tot = ans[u];         } else if (val[u] == value)           tot = (tot + ans[u]) % 1000000007;       }       mrk[u] = 1;     }     return tot;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &jrr[i].a, &jrr[i].b);       mp[jrr[i].b].push_back(jrr[i].a);       if (taken[jrr[i].a] != 1) ser.push_back(jrr[i].a);       if (taken[jrr[i].b] != 1) ser.push_back(jrr[i].b);       taken[jrr[i].a] = 1;       taken[jrr[i].b] = 1;       sss = max(sss, jrr[i].b);     }     sort(ser.begin(), ser.end());     printf( %d n , cal());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f(long long l) {     if (l < 10ll) return l;     long long L = l, t = 1ll, ans = 0ll;     int x = 0, last;     while (L) {       x++;       last = L % 10;       L /= 10;     }     for (int i = 1; i < x; i++) {       ans += 9ll * t;       if (i >= 2) t *= 10ll;     }     ans += (last - 1ll) * t;     if (x >= 2) t *= 10ll;     l -= t * 1ll * last;     ans += l / 10ll;     if (l % 10 >= last) ans++;     return ans;   }   int main() {     long long l, r;     cin >> l >> r;     cout << f(r) - f(l - 1);     return 0;   }


#include <bits/stdc++.h>   int main() {     long long k, l, c = 0;     scanf( %I64d , &k);     scanf( %I64d , &l);     while (l % k == 0) {       l /= k;       c++;     }     if (c >= 0 && l == 1)       printf( YES n%I64d , c - 1);     else       printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int id, fail, next[26];     void init() {       id = -1;       fail = -1;       memset(next, 0, sizeof(int) * 26);     }   } node[2000050];   int e;   void insert(char *str, int id) {     int len = strlen(str);     int pos = 0;     for (int i = 0; i < len; i++) {       int tmp = str[i] -  a ;       if (node[pos].next[tmp] == 0) {         node[++e].init();         node[pos].next[tmp] = e;       }       pos = node[pos].next[tmp];     }     node[pos].id = id;   }   int head, tail, q[2000050];   void bfs() {     head = tail = 0;     q[tail++] = 0;     while (head < tail) {       int u = q[head++];       for (int i = 0; i < 26; i++) {         if (node[u].next[i]) {           int tmp = node[u].fail;           while (tmp != -1 && node[tmp].next[i] == 0) tmp = node[tmp].fail;           if (tmp == -1)             tmp = 0;           else             tmp = node[tmp].next[i];           node[node[u].next[i]].fail = tmp;           q[tail++] = node[u].next[i];         }       }     }   }   int n, k, g;   char record[2000050];   char word[2000050];   int dp[2000050];   int ans[2000050];   int cnt[2000050];   void solve() {     memcpy(record + k * n, record, k * n);     memset(dp, -1, sizeof(int) * (n * k));     int pos = 0;     for (int i = 0; i < k * n * 2; i++) {       while (pos != 0 && node[pos].next[record[i] -  a ] == 0)         pos = node[pos].fail;       pos = node[pos].next[record[i] -  a ];       if (node[pos].id != -1) dp[i % (n * k)] = node[pos].id;     }     memset(cnt, 0, sizeof(int) * g);     for (int st = 0; st < k; st++) {       bool flag = true;       pos = st;       for (int i = 0; i < n; i++) {         if (dp[pos] == -1 || cnt[dp[pos]] > 0) {           flag = false;           while (pos >= 0) {             cnt[dp[pos]] = 0;             pos -= k;           }           break;         }         cnt[dp[pos]] = 1;         ans[i] = dp[pos] + 1;         pos += k;       }       if (flag) {         printf( YES n );         for (int i = 0; i < n; i++) printf( %d  , ans[i]);         printf(  n );         return;       }     }     printf( NO n );   }   int main() {     while (scanf( %d%d , &n, &k) == 2) {       scanf( %s , record);       scanf( %d , &g);       e = 0;       node[0].init();       for (int i = 0; i < g; i++) {         scanf( %s , word);         insert(word, i);       }       bfs();       solve();     }   }


#include <bits/stdc++.h>   const int xn = 200001, xe = 399999;   int head[xn], next[xe], to[xe], N, E, fa[xn], q[xn], ue[xn], O[xn * 5], L,       col[xn], D;   int main() {     scanf( %d , &N);     bool allblack = 1;     for (int i = 1; i <= N; i++) {       scanf( %d , col + i);       if (col[i] == -1) allblack = 0;     }     if (allblack) {       puts( 1 );       return 0;     }     for (int i = 1, u, v; i < N; i++) {       scanf( %d%d , &u, &v);       next[++E] = head[u], to[E] = v, head[u] = E;       next[++E] = head[v], to[E] = u, head[v] = E;     }     q[1] = 1;     ue[1] = head[1];     D = 1;     O[L = 1] = 1;     while (D) {       if (to[ue[D]] == fa[q[D]]) ue[D] = next[ue[D]];       if (ue[D]) {         int To = to[ue[D]];         ue[D] = next[ue[D]];         O[++L] = To;         fa[To] = q[D];         q[++D] = To;         ue[D] = head[To];       } else {         if (D > 1) {           O[++L] = q[D - 1];           col[q[D - 1]] *= col[q[D]];         }         D--;       }     }     printf( 1 );     for (int i = 1; i < L - 1; i++)       if (O[i] == fa[O[i + 1]] && col[O[i + 1]] == 1)         printf(  %d %d %d , O[i + 1], O[i], O[i + 1]);       else         printf(  %d , O[i + 1]);     if (col[1] == 1) printf(  1 );     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, cntu[1000006], cntd[1000006], preu[1000006], pred[1000006];   string s;   vector<long long> lisu, lisd;   int main() {     ios::sync_with_stdio(0);     cin >> n >> s;     lisd.push_back(0);     lisu.push_back(0);     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  D )         cntd[i]++;       else         cntu[i]++;       cntd[i] += cntd[i - 1];       cntu[i] += cntu[i - 1];       if (s[i - 1] ==  D )         pred[i] += i;       else         preu[i] += i;       pred[i] += pred[i - 1];       preu[i] += preu[i - 1];       if (s[i - 1] ==  D ) {         lisd.push_back(lisd.back() + i);       } else {         lisu.push_back(lisu.back() + i);       }     }     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  U ) {         long long down_after = cntd[n] - cntd[i];         long long up_before = cntu[i - 1];         if (down_after <= up_before)           cout << 2 * (pred[n] - pred[i]) +                       2 * (-lisu[cntu[i - 1]] + lisu[cntu[i - 1] - down_after]) +                       n - i + 1                <<    ;         else           cout << 2 * (lisd[cntd[i] + up_before + 1] - i - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - up_before]) +                       i                <<    ;       } else {         long long down_after = cntd[n] - cntd[i];         long long up_before = cntu[i - 1];         if (up_before <= down_after)           cout << 2 * (lisd[cntd[i] + up_before] - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - up_before]) +                       i                <<    ;         else           cout << 2 * (lisd[cntd[i] + down_after] - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - down_after - 1] +                        i) +                       n - i + 1                <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long a;       cin >> a;       long long b;       cin >> b;       if (b >= a) {         if (b % a == 0 && pow(2, (long long)log2(b / a)) == b / a) {           if ((long long)(log2(b / a)) % 3 == 0) {             cout << (long long)log2(b / a) / 3 << endl;           } else {             cout << (long long)(1 + (log2(b / a) / 3)) << endl;           }         } else {           cout << -1 << endl;         }       } else {         if (a % b == 0 && pow(2, (long long)log2(a / b)) == a / b) {           if ((long long)(log2(a / b)) % 3 == 0) {             cout << (long long)log2(a / b) / 3 << endl;           } else {             cout << (long long)(1 + (log2(a / b) / 3)) << endl;           }         } else {           cout << -1 << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         cin >> n;         if (n == 1) {           count = abs(2 - i) + abs(2 - j);           cout << count << endl;           return 0;         }       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, v;     int sum = 0;     int cnt[10];     memset(cnt, 0, sizeof cnt);     cin >> n;     while (n--) {       cin >> v;       cnt[v]++;       sum += v;     }     if (cnt[0] == 0) {       cout <<  -1 ;       return 0;     }     int mod = sum % 3;     if (mod != 0) {       bool deleted = 0;       for (int i = mod; i < 9; i += 3) {         if (cnt[i] > 0) {           deleted = 1;           cnt[i]--;           break;         }       }       if (!deleted) {         int left = 2;         for (int i = mod == 1 ? 2 : 1; i < 9 && left; i += 3) {           int take = min(left, cnt[i]);           left -= take;           cnt[i] -= take;         }       }     }     string res;     for (int i = 9; i >= 0; i--) {       if (i == 0 && res.empty()) cnt[0] = 1;       res += string(cnt[i],  0  + i);     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, string> > v[10020];   int main() {     long long n, m;     pair<long long, string> p;     long long temp;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> p.second;       cin >> temp;       cin >> p.first;       v[temp].push_back(p);     }     for (int i = 1; i <= m; i++) {       sort(v[i].begin(), v[i].end());     }     for (int i = 1; i <= m; i++) {       int k = v[i].size();       if (k < 2 || (k > 2 && v[i][k - 2].first == v[i][k - 3].first)) {         cout <<  ?  << endl;       } else {         cout << v[i][k - 1].second <<     << v[i][k - 2].second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const double EPS = 1e-9;   const double PI = acos(-1.);   const int INF = 1e8;   const int MAXN = 505;   const long long MOD = 1e9 + 7;   int v[MAXN];   int dp[MAXN][MAXN];   void solve() {     int n, i, j, k, lim, fl;     scanf( %d , &n);     for ((i) = (0); (i) < (int)(n); (i)++) {       scanf( %d , &v[i]);     }     for ((i) = (0); (i) < (int)(n); (i)++) {       for ((j) = (0); (j) < (int)(n); (j)++) {         dp[i][j] = INF;       }     }     for (i = n - 1; i >= 0; i--) {       dp[i][i] = 1;       if (i < n - 1) {         dp[i][i + 1] = 2;         if (v[i] == v[i + 1]) {           dp[i][i + 1] = 1;         }       }       for (j = i + 2; j < n; j++) {         for (k = i; k < j; k++) {           dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);         }         if (v[i] == v[j]) {           dp[i][j] = min(dp[i][j], dp[i + 1][j - 1]);         }       }     }     printf( %d n , dp[0][n - 1]);   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[110], suml[110], sumr[110], ans = 0;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) suml[i] = suml[i - 1] + (a[i] == 0);     for (int i = n; i >= 1; i--) sumr[i] = sumr[i + 1] + (a[i] == 1);     for (int i = 1; i <= n; i++) ans = max(ans, suml[i] + sumr[i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     vector<vector<long double> > dist(n + 1, vector<long double>(n + 1));     vector<long double> x(n + 1), y(n + 1), z(n + 1);     vector<long long int> vis(n + 1, 0);     for (long long int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= n; j++) {         dist[i][j] = (x[i] - x[j]) * (x[i] - x[j]) +                      (y[i] - y[j]) * (y[i] - y[j]) +                      (z[i] - z[j]) * (z[i] - z[j]);         dist[i][j] = sqrt(dist[i][j]);       }     }     for (long long int i = 1; i <= n; i++) {       if (vis[i] == 0) {         long double big = 1e18 * 1.0;         long long int ans;         for (long long int j = i + 1; j <= n; j++) {           if (vis[j] == 0) {             if (dist[i][j] < big) {               big = dist[i][j];               ans = j;             }           }         }         vis[ans] = 1;         vis[i] = 1;         cout << i <<     << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int getint() {     static char c;     while ((c = getchar()) <  0  || c >  9 )       ;     int res = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) res = res * 10 + c -  0 ;     return res;   }   const int MaxN = 200005;   const int M = 1000000007;   inline int add(int a, const int &b) {     a += b;     return a >= M ? a - M : a;   }   inline int dec(int a, const int &b) {     a -= b;     return a < 0 ? a + M : a;   }   int n;   int key[MaxN];   vector<int> adj[MaxN];   int inv[MaxN];   int phi[MaxN];   vector<int> divs[MaxN];   vector<int> coe[MaxN];   int prod[MaxN];   inline void init_math() {     inv[1] = phi[1] = 1;     for (int i = 2; i <= n; ++i) {       phi[i] = i;       inv[i] = (long long)(M - M / i) * inv[M % i] % M;     }     for (int i = 1; i <= n; ++i) {       divs[i].push_back(i);       for (int j = i << 1; j <= n; j += i) {         divs[j].push_back(i);         phi[j] -= phi[i];       }     }     for (int i = 1; i <= n; ++i) coe[i].resize(divs[i].size());     coe[1][0] = 1;     for (int i = 2; i <= n; ++i) {       int p = divs[i][1];       if (p == i) {         coe[i][0] = 1;         coe[i][1] = inv[p - 1];         continue;       }       int q = i;       while (q % p == 0) q /= p;       for (int d : divs[i]) prod[d] = 0;       for (int i = 0; i < divs[p].size(); ++i)         for (int j = 0; j < divs[q].size(); ++j) {           int u = divs[p][i], a = coe[p][i];           int v = divs[q][j], b = coe[q][j];           int x = u * v, y = (long long)a * b % M;           prod[x] = add(prod[x], y);         }       for (int j = 0; j < divs[i].size(); ++j) coe[i][j] = prod[divs[i][j]];     }   }   bool book[MaxN];   int q_n, q[MaxN];   int fa[MaxN];   int dep[MaxN];   int size[MaxN];   inline void bfs(const int &sv, const int &prev) {     q[q_n = 1] = sv;     fa[sv] = prev, dep[sv] = 1;     for (int i = 1; i <= q_n; ++i) {       int u = q[i];       for (int v : adj[u])         if (!book[v] && v != fa[u]) {           fa[v] = u;           dep[v] = dep[u] + 1;           q[++q_n] = v;         }     }   }   inline int centroid(int root) {     bfs(root, 0);     int vC = 0, wC = q_n;     for (int i = 1; i <= q_n; ++i) size[q[i]] = 1;     for (int i = q_n; i >= 1; --i) {       int u = q[i];       size[fa[u]] += size[u];       int vW = q_n - size[u];       for (int v : adj[u])         if (!book[v] && v != fa[u]) vW = max(vW, size[v]);       if (vW < wC) wC = vW, vC = u;     }     return vC;   }   int nVer = 0;   int ver[MaxN];   int sum = 0;   int sum_phi[MaxN];   inline int calc(int v) {     int sum = 0;     for (int i = 0; i < divs[v].size(); ++i) {       int d = divs[v][i];       sum = add(sum, (long long)coe[v][i] * sum_phi[d] % M);     }     return (long long)sum * phi[v] % M;   }   inline void work(int vC) {     nVer = q_n;     for (int i = 1; i <= q_n; ++i) ver[i] = q[i];     for (int i = 1; i <= nVer; ++i) {       int v = key[ver[i]];       for (int d : divs[v]) sum_phi[d] = add(sum_phi[d], phi[v]);     }     for (int u : adj[vC])       if (!book[u]) {         bfs(u, vC);         for (int i = 1; i <= q_n; ++i) {           int v = key[q[i]];           for (int d : divs[v]) sum_phi[d] = dec(sum_phi[d], phi[v]);         }         for (int i = 1; i <= q_n; ++i) {           int v = q[i];           int w = key[v];           sum = add(sum, (long long)dep[v] * calc(w) % M);         }         for (int i = 1; i <= q_n; ++i) {           int v = key[q[i]];           for (int d : divs[v]) sum_phi[d] = add(sum_phi[d], phi[v]);         }       }     for (int i = 1; i <= nVer; ++i) {       int v = key[ver[i]];       for (int d : divs[v]) sum_phi[d] = 0;     }   }   void solve(int root) {     int vC = centroid(root);     book[vC] = true;     work(vC);     for (int v : adj[vC])       if (!book[v]) solve(v);   }   int main() {     n = getint();     for (int u = 1; u <= n; ++u) key[u] = getint();     for (int i = 1; i < n; ++i) {       int u = getint(), v = getint();       adj[u].push_back(v);       adj[v].push_back(u);     }     init_math();     solve(1);     sum = (long long)sum * inv[n] % M;     sum = (long long)sum * inv[n - 1] % M;     sum = (long long)sum * 2 % M;     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int xx[4] = {0, 0, 1, -1};   int yy[4] = {1, -1, 0, 0};   int n, m, b, s;   int x[int(1e5)], y[int(1e5)];   int main() {     scanf( %d%d , &n, &m);     scanf( %d , &b);     for (int i = (1), _b = (b); i <= _b; i++) {       scanf( %d , &s);       x[s] = true;     }     scanf( %d , &b);     for (int i = (1), _b = (b); i <= _b; i++) {       scanf( %d , &s);       y[s] = true;     }     for (int i = (0), _b = (2 * n * m); i <= _b; i++) {       int u = i % n;       int v = i % m;       if (x[u] || y[v]) {         x[u] = true;         y[v] = true;       }     }     for (int i = (0), _b = (n - 1); i <= _b; i++)       if (!x[i]) {         cout <<  No  << endl;         return 0;       }     for (int i = (0), _b = (m - 1); i <= _b; i++)       if (!y[i]) {         cout <<  No  << endl;         return 0;       }     cout <<  Yes  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 10;   int ad[N][N];   long long n;   pair<int, int> t[N];   bool ok;   int c[N];   void connect(int k) {     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (abs(t[i].first - t[j].first) + abs(t[i].second - t[j].second) > k)           ad[i][j] = ad[j][i] = 1;         else           ad[i][j] = ad[j][i] = 0;       }     }   }   void dfs(int v, int col) {     c[v] = col;     for (int i = 0; i < n; i++) {       if (ad[v][i] && c[i] == 0)         dfs(i, 3 - col);       else if (ad[v][i] && c[i] == col) {         ok = 0;         return;       }     }   }   int tt = 10000;   int bs() {     long long top = 10100, low = 0;     while (top > low + 1) {       int md = (low + top) / 2;       connect(md);       ok = true;       for (int i = 0; i < n; i++) c[i] = 0;       for (int i = 0; i < n; i++) {         if (!c[i]) {           dfs(i, 1);         }       }       if (ok)         top = md;       else         low = md;       tt = top;     }     return top;   }   bool mark[N] = {0};   void dfsp(int v) {     mark[v] = 1;     for (int i = 0; i < n; i++) {       if (ad[v][i] && mark[i] == 0) dfsp(i);     }   }   const int M = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n == 2) {       cout << 0 << endl << 2;       return 0;     }     for (int i = 0; i < n; i++) cin >> t[i].first >> t[i].second;     cout << bs() << endl;     connect(tt);     long long x = 1;     for (int i = 0; i < n; i++) {       if (mark[i] == 0) {         x *= 2;         x %= M;         dfsp(i);       }     }     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n, u, r;   vector<int> b, k;   vector<int> p;   void exec(vector<int> a, int type, int count) {     if (count < u) {       if (type == 0) {         for (int i = 0; i < n; ++i) a[i] = a[i] ^ b[i];         exec(a, 1, count + 1);       } else {         vector<int> aa(n);         for (int i = 0; i < n; ++i) aa[i] = a[p[i]] + r;         int rest = u - count - 1;         long long cur_cand = 0;         if (rest & 1) {           vector<int> aaa(n);           for (int i = 0; i < n; ++i) aaa[i] = aa[i] ^ b[i];           cur_cand = inner_product(aaa.begin(), aaa.end(), k.begin(), 0LL);         } else {           cur_cand = inner_product(aa.begin(), aa.end(), k.begin(), 0LL);         }         ans = max(cur_cand, ans);         exec(aa, 0, count + 1);         exec(aa, 1, count + 1);       }     } else {       long long cand = inner_product(a.begin(), a.end(), k.begin(), 0LL);       ans = max(cand, ans);     }   }   int main() {     cin >> n >> u >> r;     vector<int> a(n);     b.resize(n);     k.resize(n);     p.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) cin >> k[i];     for (int i = 0; i < n; ++i) {       cin >> p[i];       --p[i];     }     for (int i = 0; i < n; ++i) {       ans += k[i] * (u & 1 ? a[i] ^ b[i] : a[i]);     }     exec(a, 1, 0);     exec(a, 0, 0);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int book[100010];   vector<pair<int, int>> v;   deque<int> high, low;   int main() {     int n, k, ans = 0, num = 0, r, l;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> book[i];     for (r = 1, l = 1; r <= n; r++) {       while (!high.empty() && high.back() < book[r]) high.pop_back();       high.push_back(book[r]);       while (!low.empty() && low.back() > book[r]) low.pop_back();       low.push_back(book[r]);       while (!high.empty() && !low.empty() && high.front() - low.front() > k) {         if (v.empty()) {           num = 1;           ans = r - l;           v.push_back(make_pair(l, r - 1));         } else if (r - l > ans) {           v.clear();           num = 1;           ans = r - l;           v.push_back(make_pair(l, r - 1));         } else if (!v.empty() && r - l == ans) {           num++;           v.push_back(make_pair(l, r - 1));         }         if (high.front() == book[l]) high.pop_front();         if (low.front() == book[l]) low.pop_front();         l++;       }     }     while (l <= n) {       if (v.empty()) {         num = 1;         ans = r - l;         v.push_back(make_pair(l, r - 1));       } else if (r - l > ans) {         v.clear();         num = 1;         ans = r - l;         v.push_back(make_pair(l, r - 1));       } else if (!v.empty() && r - l == ans) {         num++;         v.push_back(make_pair(l, r - 1));       }       if (high.front() == book[l]) high.pop_front();       if (low.front() == book[l]) low.pop_front();       l++;     }     cout << ans <<     << num << endl;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > Dates;   int n, x, y, ans, cur;   int main() {     std::ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       Dates.push_back(make_pair(x, y));     }     sort(Dates.begin(), Dates.end());     for (int i = 0; i < Dates.size(); i++) {       if (Dates[i].second > cur)         cur = Dates[i].second;       else if (Dates[i].second < cur) {         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   string a[] = { zero ,  one ,  two ,    three ,  four ,                  five ,  six ,  seven ,  eight ,  nine };   string b[] = { ten ,    twenty ,   thirty ,  forty ,  fifty ,                  sixty ,  seventy ,  eighty ,  ninety };   string c[] = { eleven ,   twelve ,     thirteen ,  fourteen ,  fifteen ,                  sixteen ,  seventeen ,  eighteen ,  nineteen };   int main() {     int n;     cin >> n;     if (n < 10) {       cout << a[n] << endl;       return 0;     } else {       if (n % 10 == 0) {         cout << b[(n / 10) - 1] << endl;         return 0;       } else if (n > 10 && n < 20) {         cout << c[(n % 10) - 1] << endl;         return 0;       } else {         cout << b[(n / 10) - 1] <<  -  << a[n % 10] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long int INF = 3e16;   const int N = 200010;   int n;   int ask(vector<int> v) {     printf( ? );     for (int i = 0; i < n; i++) printf(  %d , v[i]);     printf(  n );     fflush(stdout);     int ans;     scanf( %d , &ans);     return ans;   }   int main() {     scanf( %d , &n);     int pivo = -1;     for (int i = 1; i < n; i++) {       vector<int> tmp(n);       tmp[n - 1] = 1;       for (int j = 0; j < n - 1; j++) {         tmp[j] = 1 + i;       }       int k = ask(tmp);       if (k == 0) {         pivo = i;         break;       }     }     if (pivo == -1) pivo = n;     vector<int> ans(n + 1);     ans[n] = pivo;     for (int i = 1; i <= n; i++) {       if (i == pivo) continue;       vector<int> tmp(n);       tmp[n - 1] = (n + 1) - pivo;       for (int j = 0; j < n - 1; j++) {         tmp[j] = (n + 1) - i;       }       int k = ask(tmp);       ans[k] = i;     }     printf( ! );     for (int i = 1; i <= n; i++) printf(  %d , ans[i]);     printf(  n );     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[300000 + 13];   int n;   void erf() {     for (int i = 1; i < n; i++) {       if (a[i - 1].first + 1 >= a[i].first) a[i].first = a[i - 1].first + 1;     }   }   int main() {     int cur, ebte;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     erf();     pair<int, int> b;     for (int i = 0; i < n; i++) {       b = make_pair(a[i].second, a[i].first);       swap(a[i], b);     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       cout << a[i].second <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e6;   long long a[100000 + 5];   bool vis[100000 + 5];   char c[] = { 6 ,  7 ,  8 ,  9 ,  T ,  J ,  Q ,  K ,  A };   int main() {     long long n;     string s, s1, s2;     cin >> s >> s1 >> s2;     if (s1[1] == s[0]) {       if (s2[1] != s[0])         cout <<  YES  << endl;       else {         int i = 0;         for (i = 0; i < 9; i++) {           if (s1[0] == c[i]) break;         }         int j = 0;         for (j = 0; j < 9; j++) {           if (s2[0] == c[j]) break;         }         if (i > j)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     } else {       if (s2[1] == s[0])         cout <<  NO  << endl;       else if (s1[1] == s2[1]) {         int i = 0;         for (i = 0; i < 9; i++) {           if (s1[0] == c[i]) break;         }         int j = 0;         for (j = 0; j < 9; j++) {           if (s2[0] == c[j]) break;         }         if (i > j)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getID(char nms[202][30], char s[30], int &len) {     for (int i = 0; i < 30; ++i) {       if (s[i] >=  a  && s[i] <=  z ) s[i] +=  A  -  a ;     }     for (int i = 0; i < len; ++i) {       if (strcmp(nms[i], s) == 0) return i;     }     strcpy(nms[len], s);     len++;     return len - 1;   }   int search(int mailFrom[202], int mailTo[202], int p, int n, int h) {     int max = 0;     for (int i = 0; i < n; ++i) {       if (mailFrom[i] == p) {         int ans = search(mailFrom, mailTo, mailTo[i], n, h + 1);         if (max < ans) max = ans;       }     }     if (max == 0) return h;     return max;   }   int main() {     int n;     while (cin >> n) {       char nms[202][30] = {0};       int len = 0;       int mailFrom[202] = {0};       int mailTo[202] = {0};       bool notHead[202] = {0};       for (int i = 0; i < n; ++i) {         char n1[30], n2[30], t[30];         cin >> n1;         cin >> t;         cin >> n2;         mailFrom[i] = getID(nms, n2, len);         mailTo[i] = getID(nms, n1, len);         notHead[mailTo[i]] = 1;       }       int max = 0;       for (int i = 0; i < n; ++i) {         if (!notHead[i]) {           int ans = search(mailFrom, mailTo, i, n, 1);           if (ans > max) max = ans;         }       }       cout << max << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ;   const long long N = 5e3 + 10;   vector<bitset<N> > v;   vector<pair<long long, pair<long long, long long> > > hor, ver;   long long n, cnt, y11, y2, x1, x2;   long long ans;   bool check(long long x, pair<long long, long long> a) {     return a.first <= x && x <= a.second;   }   void solve() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> x1 >> y11 >> x2 >> y2;       if (x1 > x2) swap(x1, x2);       if (y11 > y2) swap(y11, y2);       if (x1 == x2)         ver.push_back({x1, {y11, y2}});       else         hor.push_back({y11, {x1, x2}});     }     if ((long long)((hor).size()) > (long long)((ver).size())) swap(hor, ver);     v.resize((long long)((hor).size()));     for (long long i = 0; i < (long long)((hor).size()); i++) {       for (long long j = 0; j < (long long)((ver).size()); j++) {         v[i][j] = check(hor[i].first, ver[j].second) &&                   check(ver[j].first, hor[i].second);       }     }     for (long long i = 0; i < (long long)((v).size()); i++) {       for (long long j = i + 1; j < (long long)((v).size()); j++) {         cnt = (v[i] & v[j]).count();         ans += cnt * (cnt - 1) / 2;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     clock_t start, end;     start = clock();     cout << fixed << setprecision(15);     while (t--) {       solve();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);   }


#include <bits/stdc++.h>   const double PI = 3.141592653589793238460;   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n], i, sum = 0, maxi = -1000000000, mini = 1000000000;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > maxi)           maxi = a[i];         else if (a[i] < mini)           mini = a[i];       }       for (i = 0; i < n - 1; i++) {         long long int pro = a[i] * a[i + 1];         if (pro > sum) {           sum = pro;         }       }       cout << sum <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1760777216 )   using namespace std;   const double Pi = 3.14159265358979323846;   int main() {     int T;     scanf( %d , &T);     while (T--) {       double R, r, k;       scanf( %lf%lf%lf , &R, &r, &k);       double x1 = 0.5 / R, x2 = 0.5 / r, rr = fabs(x1 - x2) / 2;       double x = (x1 + x2) / 2, y = 2 * k * rr, a = x / sqrt(x * x + y * y);       double dx = rr * a, dy = rr * sqrt(1 - a * a);       double res = sqrt(x * x + y * y);       printf( %.9lf n , (1 / (res - rr) - 1 / (res + rr)) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool arr[100100];   int dp[100100];   int pref[100100];   int pref2[100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     char a;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a ==  G ) arr[i] = true;     }     for (int i = 1; i <= n; i++) {       if (arr[i]) pref[i] = pref[i - 1] + 1;     }     for (int i = 1; i <= n; i++) {       pref2[i] = pref2[i - 1] + arr[i];     }     if (pref2[n] == n) {       cout << n << endl;       return 0;     }     if (pref2[n] == 0) {       cout << 0 << endl;       return 0;     }     for (int i = n; i >= 1; i--) {       if (pref[i - 1] > 0 && pref[i] > 0) pref[i - 1] = pref[i];     }     int ma = -1e9;     for (int i = 1; i <= n; i++) {       if (!arr[i]) {         if (pref[i - 1] + pref[i + 1] < pref2[n])           ma = max(ma, pref[i - 1] + pref[i + 1] + 1);         else           ma = max(ma, pref[i - 1] + pref[i + 1]);       }     }     cout << ma << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream f( test.in );   ofstream g( test.out );   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, ans = 0;       cin >> n;       stack<int> s;       int x;       cin >> x;       s.push(x);       for (int i = 2; i <= n; i++) {         cin >> x;         while (!s.empty() and s.top() > x) {           ans++;           s.pop();         }         s.push(x);       }       while (!s.empty()) s.pop();       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int main() {     cin >> a >> b;     if (a == b)       cout << a;     else       cout << 1;   }


#include <bits/stdc++.h>   using namespace std;   vector<set<int> > newadj(212345);   int visit[212345];   vector<vector<int> > adj(212345);   vector<int> vec, vecans;   set<int> seti;   int cnt = 0;   int pos[212345];   int dfs(int cur) {     cnt++;     visit[cur] = 1;     set<int>::iterator it;     for (it = newadj[cur].begin(); it != newadj[cur].end(); it++) {       if (!visit[*it]) {         dfs(*it);       }     }     return 0;   }   int main() {     std::ios::sync_with_stdio(false);     int n, m;     int i, j, u, v;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     int mini = (1000 * 1000 * 1000 + 5), vert;     for (i = 0; i < n; i++) {       if (mini > adj[i].size()) {         mini = adj[i].size();         vert = i;       }     }     int sumi = 0;     for (i = 0; i < n; i++) {       sumi++;       pos[i] = vert;     }     vec.push_back(vert);     for (i = 0; i < adj[vert].size(); i++) {       sumi--;       pos[adj[vert][i]] = adj[vert][i];       vec.push_back(adj[vert][i]);       seti.insert(adj[vert][i]);     }     seti.insert(vert);     set<int>::iterator it;     for (i = 1; i < vec.size(); i++) {       for (it = seti.begin(); it != seti.end(); it++) {         newadj[vec[i]].insert(*it);       }       cnt = 0;       for (j = 0; j < adj[vec[i]].size(); j++) {         if (pos[adj[vec[i]][j]] == vert) {           cnt++;           continue;         }         newadj[vec[i]].erase(pos[adj[vec[i]][j]]);       }       if (cnt == sumi) {         newadj[vec[i]].erase(vert);       } else {         newadj[vert].insert(vec[i]);       }     }     for (i = 0; i < vec.size(); i++) {       if (!visit[vec[i]]) {         cnt = 0;         dfs(vec[i]);         if (i == 0) {           cnt += sumi - 1;         }         vecans.push_back(cnt);       }     }     sort(vecans.begin(), vecans.end());     cout << vecans.size() << endl;     for (i = 0; i < vecans.size(); i++) {       cout << vecans[i] <<    ;     }     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int b = -1, n = 0, limit = 10;     string pass, box =  0000000000 , zero, one, two, three, four, five, six,                  seven, eight, nine;     cin >> pass;     cin >> zero;     cin >> one;     cin >> two;     cin >> three;     cin >> four;     cin >> five;     cin >> six;     cin >> seven;     cin >> eight;     cin >> nine;     while (n < 8) {       for (int i = b + 1, i2 = 0; i < limit; i++, i2++) {         box[i2] = pass[i];         b = i;       }       if (box == zero)         cout <<  0 ;       else if (box == one)         cout <<  1 ;       else if (box == two)         cout <<  2 ;       else if (box == three)         cout <<  3 ;       else if (box == four)         cout <<  4 ;       else if (box == five)         cout <<  5 ;       else if (box == six)         cout <<  6 ;       else if (box == seven)         cout <<  7 ;       else if (box == eight)         cout <<  8 ;       else if (box == nine)         cout <<  9 ;       n++;       limit += 10;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 20;   const int MAXS = (1 << 16) + 10;   long long dp[MAXS];   int ans[MAXN], req[MAXN];   bool vis[MAXN];   int main() {     long long n, y, m;     cin >> n >> y >> m;     y -= 2001;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       req[b - 1] |= (1 << (a - 1));     }     memset(ans, -1, sizeof ans);     for (int i = 0; i < n; i++) {       for (ans[i] = 0; ans[i] < n; ans[i]++) {         if (!vis[ans[i]]) {           memset(dp, 0, sizeof dp);           dp[0] = 1;           for (int s = 0; s < (1 << n); s++) {             if (dp[s] > 0) {               for (int j = 0; j < n; j++) {                 if (!(s & (1 << j))) {                   if ((ans[j] == -1 || ans[j] == __builtin_popcount(s)) &&                       ((s & req[j]) == req[j])) {                     dp[s | (1 << j)] += dp[s];                   }                 }               }             }           }           if (y >= dp[(1 << n) - 1]) {             y -= dp[(1 << n) - 1];           } else {             vis[ans[i]] = true;             break;           }         }       }       if (ans[i] >= n) {         cout <<  The times have changed  << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       cout << ans[i] + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   const long long N = 2e5 + 100;   vector<long long> v[N];   long long dfn[N], num[N], val[N], sz[N], hs[N], tp[N], dep[N], f[N];   inline void dfs(long long x, long long fa) {     sz[x] = 1;     long long num = 0;     dep[x] = dep[fa] + 1;     f[x] = fa;     for (auto y : v[x]) {       if (y == fa) continue;       dfs(y, x);       sz[x] += sz[y];       if (num < sz[y]) hs[x] = y, num = sz[y];     }   }   long long cnt;   inline void redfs(long long x, long long fa, long long top) {     tp[x] = top;     dfn[x] = ++cnt;     num[cnt] = x;     if (hs[x]) redfs(hs[x], x, top);     for (auto y : v[x]) {       if (y == fa || y == hs[x]) continue;       redfs(y, x, y);     }   }   struct seg {     long long l, r, v;   } t[N << 2];   long long a[N];   inline void build(long long p, long long l, long long r) {     t[p].l = l, t[p].r = r;     if (l == r) {       t[p].v = abs(val[num[l]]);       return;     }     long long mid = l + r >> 1;     build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);     t[p].v = t[p << 1].v + t[p << 1 | 1].v;   }   inline void modify(long long p, long long x, long long v) {     if (t[p].l == t[p].r) {       t[p].v = v;       return;     }     long long mid = t[p].l + t[p].r >> 1;     if (x <= mid)       modify(p << 1, x, v);     else       modify(p << 1 | 1, x, v);     t[p].v = t[p << 1].v + t[p << 1 | 1].v;   }   inline long long query(long long p, long long x, long long y) {     if (x <= t[p].l && t[p].r <= y) {       return t[p].v;     }     long long mid = t[p].l + t[p].r >> 1;     if (y <= mid) return query(p << 1, x, y);     if (x > mid) return query(p << 1 | 1, x, y);     return query(p << 1, x, y) + query(p << 1 | 1, x, y);   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> q;     for (long long i = 1; i <= n; i++) cin >> val[i], val[i] = abs(val[i]);     for (long long i = 1; i <= n - 1; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y), v[y].push_back(x);     }     dfs(1, 0);     redfs(1, 0, 1);     build(1, 1, n);     for (long long i = 1; i <= q; i++) {       long long opt, x, y;       cin >> opt >> x >> y;       if (opt == 1) {         modify(1, dfn[x], abs(y));         val[x] = abs(y);       } else {         long long ans = 0, X = x, Y = y;         ;         while (tp[x] != tp[y]) {           if (dep[tp[x]] < dep[tp[y]]) swap(x, y);           ans += query(1, dfn[tp[x]], dfn[x]);           x = f[tp[x]];         }         if (dep[x] < dep[y]) swap(x, y);         ans += query(1, dfn[y], dfn[x]);         cout << ans * 2 - val[X] - val[Y] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   const int N = 200;   const int M = 1e9 + 7;   const long long M2 = 1ll * M * M;   int n;   long long a[N];   int mat[N][N];   int result[N][N];   void multiply(int a[N][N], int b[N][N]) {     static int c[N][N];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         long long result = 0;         for (int z = 0; z < n; z++) {           result += 1ll * a[i][z] * b[z][j];           if (result >= M2) {             result -= M2;           }         }         c[i][j] = result % M;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         a[i][j] = c[i][j];       }     }   }   void power(long long n) {     for (int i = 0; i < ::n; i++) {       result[i][i] = 1;     }     for (; n > 0; n >>= 1) {       if (n & 1) {         multiply(result, mat);       }       multiply(mat, mat);     }   }   int main() {     long long k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         long long x = a[i] ^ a[j];         int cnt = 0;         while (x > 0) {           cnt += x & 1;           x /= 2;         }         if (cnt % 3 == 0) {           mat[i][j]++;         }       }     }     power(k - 1);     int answer = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         answer += result[i][j];         if (answer >= M) {           answer -= M;         }       }     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   inline long long int max(long long int a, long long int b) {     return a > b ? a : b;   }   inline long long int min(long long int a, long long int b) {     return a > b ? b : a;   }   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x;   }   long long int sum[maxn * 4], mq[maxn * 4], dl[maxn * 4], dr[maxn * 4];   int lb[maxn * 4], rb[maxn * 4];   int N, M;   int a[maxn];   inline void update(int i) {     if (lb[i] == rb[i]) {       sum[i] = fabs(dr[i]);       mq[i] = max(dl[i], 0) + max(dr[i], 0);       return;     }     sum[i] = sum[i << 1] + sum[(i << 1) + 1];     mq[i] = min(mq[i << 1], mq[(i << 1) + 1]);   }   inline void updateall(int i) {     while (i > 1) {       update(i);       i = i >> 1;     }     update(1);   }   void build(int i, int l, int r) {     lb[i] = l;     rb[i] = r;     if (l == r) {       dl[i] = a[l - 1] - a[l];       dr[i] = a[l + 1] - a[l];       sum[i] = fabs(dr[i]);       mq[i] = max(dl[i], 0) + max(dr[i], 0);     } else {       int m = (l + r) >> 1;       build(i << 1, l, m);       build((i << 1) + 1, m + 1, r);       update(i);     }   }   long long int getmq(int i, int l, int r) {     if (l == lb[i] && r == rb[i]) return mq[i];     int m = (lb[i] + rb[i]) >> 1;     long long int re = 1e9 + 10;     if (l <= m) re = min(re, getmq(i << 1, l, min(m, r)));     if (r > m) re = min(re, getmq((i << 1) + 1, max(m + 1, l), r));     return re;   }   int find(int x, int i) {     if (lb[i] == rb[i] && lb[i] == x)       return i;     else if (x <= ((lb[i] + rb[i]) >> 1))       return find(x, i << 1);     else       return find(x, (i << 1) + 1);   }   inline long long int solve1(int l, int r, int x) {     if (l == r) {       int p = find(l, 1);       return fabs(dl[p] - x) + fabs(dr[p] - x) - fabs(dl[p]) - fabs(dr[p]) +              sum[1];     } else {       return max(0, 2 * x - 2 * getmq(1, l, r)) + sum[1];     }   }   inline void solve2(int l, int r, int x) {     int p = find(l, 1);     dl[p] -= x;     updateall(p);     p = find(l - 1, 1);     dr[p] += x;     updateall(p);     p = find(r, 1);     dr[p] -= x;     updateall(p);     p = find(r + 1, 1);     dl[p] += x;     updateall(p);   }   int main() {     int i, j, k, x, y;     N = read();     for (i = 1; i <= N; i++) a[i] = read();     a[N + 1] = a[N];     a[0] = a[1];     build(1, 1, N);     M = read();     for (i = 1; i <= M; i++) {       j = read();       k = read();       x = read();       y = read();       if (j == 1) {         printf( %I64d n , solve1(k, x, y));       } else {         solve2(k, x, y);       }     }   }


#include <bits/stdc++.h>   long long T, n, k;   long long a, sum, num;   int main() {     scanf( %I64d%I64d , &n, &k);     for (long long i = 1; i <= n; i++) {       scanf( %I64d , &a);       if (sum - (i - 1 - num) * (n - i) * a >= k)         sum += a * (i - 1 - num);       else {         printf( %I64d n , i);         num++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MOD = 1e9 + 7,             around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};   const long long LINF = 1e18;   const long double PI = abs(acos(-1));   int a, b, c;   int main() {     cin >> a >> b >> c;     for (int x1 = (0); x1 < (3); x1++) {       for (int x2 = (0); x2 < (3); x2++) {         for (int x3 = (0); x3 < (3); x3++) {           bool li[1500 * 1510 + 1] = {};           int ma = 0;           for (int i = (0); i < (max(a, max(b, c))); i++) {             li[x1 + a * i] = li[x2 + b * i] = li[x3 + c * i] = true;             ma = max(x1 + a * i, max(x2 + b * i, x3 + c * i));           }           for (int i = 0; x1 + a * i < ma; i++) li[x1 + a * i] = true;           for (int i = 0; x2 + b * i < ma; i++) li[x2 + b * i] = true;           for (int i = 0; x3 + c * i < ma; i++) li[x3 + c * i] = true;           bool f = true;           for (int i = (0); i < (ma + 1); i++) f = f & li[i];           if (f) {             cout <<  YES  << endl;             return 0;           }         }       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[3001];   int n;   struct node {     int pos, val;     bool operator<(const node& a) const { return val < a.val; }   } nodes[3001];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int ans = 0;       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %d , &nodes[i].val);         nodes[i].pos = i;       }       sort(nodes, nodes + n);       dp[0] = 1;       for (int i = 1; i < n; i++) {         if (nodes[i - 1].pos < nodes[i].pos)           dp[i] = dp[i - 1] + 1;         else           dp[i] = 1;         ans = max(ans, dp[i]);       }       ans = max(ans, dp[0]);       printf( %d n , n - ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0u >> 1, MOD = 1e9 + 7;   inline int rd() {     int first = 0, c = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar()) f = c !=  - ;     for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ;     return f ? first : -first;   }   const int N = 2e5 + 11;   struct Edge {     int v, id;     Edge *nex;   } pl[N << 1], *cur = pl, *G[N];   void ins(int u, int v, int id) {     cur->v = v, cur->id = id;     cur->nex = G[u], G[u] = cur++;   }   int wx[N], wy[N], n, m;   int f[N], vis[N], g[N];   void dfs(int first) {     vis[first] = 1;     for (Edge *i = G[first]; i; i = i->nex)       if (!vis[i->v]) {         dfs(i->v);         if (f[i->v]) {           f[i->v] = 0;           f[first] ^= 1;           g[i->id] ^= 1;         }       }   }   int q[N];   int main() {     n = rd(), m = rd();     for (int i = (1), i_end = (m); i <= i_end; i++) {       wx[i] = rd(), wy[i] = rd();       ins(wx[i], wy[i], i), ins(wy[i], wx[i], i);       f[wx[i]] ^= 1;     }     for (int i = (1), i_end = (n); i <= i_end; i++)       if (!vis[i]) dfs(i);     int ans = m;     for (int i = (1), i_end = (n); i <= i_end; i++)       if (f[i]) ans--;     printf( %d n , ans >> 1);     for (int first = (1), x_end = (n); first <= x_end; first++) {       int cnt = 0;       for (Edge *i = G[first]; i; i = i->nex)         if ((wy[i->id] != first) ^ g[i->id]) {           q[++cnt] = (wx[i->id] ^ wy[i->id] ^ first);         }       for (int i = 1; i < cnt; i += 2) {         printf( %d %d %d n , q[i], first, q[i + 1]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int lsb(int val) { return val & ((val ^ (val - 1))); }   pair<int, pair<int, int> > a[600666];   int Arb[600666], SEG[600666], result[600666];   bool comp(pair<int, pair<int, int> > i1, pair<int, pair<int, int> > i2) {     return i1.second.second < i2.second.second;   }   int query(int pos) {     if (pos) return Arb[pos] + query(pos - lsb(pos));     return 0;   }   void update(int pos, int n) {     if (pos > n) return;     Arb[pos]++;     update(pos + lsb(pos), n);   }   int bs(int value, int n, int A[]) {     int left = 1, right = n + 1;     while (left < right - 1) {       int mid = (right + left) / 2;       if (A[mid] <= value)         left = mid;       else         right = mid;     }     return left;   }   int main() {     cin.sync_with_stdio(false);     int n, i, nr_seg = 0;     cin >> n;     for (i = 1; i <= n; ++i) {       cin >> a[i].second.first >> a[i].second.second;       a[i].first = i;       SEG[++nr_seg] = a[i].second.first;       SEG[++nr_seg] = a[i].second.second;     }     sort(SEG + 1, SEG + nr_seg + 1);     sort(a + 1, a + n + 1, comp);     for (i = 1; i <= n; ++i) {       a[i].second.first = bs(a[i].second.first, nr_seg, SEG);       a[i].second.second = bs(a[i].second.second, nr_seg, SEG);     }     for (i = 1; i <= n; ++i) {       result[a[i].first] = query(a[i].second.second) - query(a[i].second.first);       update(a[i].second.first, n * 2);     }     for (i = 1; i <= n; ++i) cout << result[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b != 0) {       int r = a % b;       a = b;       b = r;     }     return a;   }   void FindMinimum(int a[], int &n) {     int g = gcd(a[0], a[1]);     for (int i = 2; i < n; ++i) g = gcd(a[i], g);     cout << g * n;   }   int main() {     int n, a[100];     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     FindMinimum(a, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int expo(int base, int exponent, int mod) {     int ans = 1;     while (exponent != 0) {       if (exponent & 1) ans = (1LL * ans * base) % mod;       base = (1LL * base * base) % mod;       exponent >>= 1;     }     return ans % mod;   }   int n, a[5005], ans[10005], pre[5005], inv[5005];   int up[5005][10005];   int get_down(int l, int r) {     if (l <= 0 or r < 0) return 0;     if (r == 0) return 1;     r = l + r - 1;     if (r >= n) return 0;     return 1LL * pre[r] * inv[l - 1] % 1000000007;   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     a[0] = pre[0] = inv[0] = 1;     for (int i = 1; i < n + 1; i++)       pre[i] = 1LL * a[i] * pre[i - 1] % 1000000007,       inv[i] = expo(pre[i], 1000000007 - 2, 1000000007);     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < 2 * n - 1; j++) {         if (i >= 2)           up[i][j] = (0LL + up[i - 1][j - 1] + get_down(i - 1, j - 1) -                       get_down(i, j - 2) + 1000000007) %                      1000000007;         ans[j] = (ans[j] + 1LL * pre[i - 1] * (up[i][j] + get_down(i, j))) %                  1000000007;       }     }     for (int i = 1; i < 2 * n - 1; i++)       cout << 1LL * ans[i] * (1000000007 + 1) / 2 % 1000000007 <<    ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long lim = 100000000000ll;   long long qv[61], dis[100010], ma, nw, dep[100010];   int n, Q, ans[61], x, y, v, hd[100010], cnt, q[100010], l, r, maa, la[100010],       rt[100010];   struct node {     int to, next, val;   } e[200010];   struct seg {     int ls, rs, val;   } t[6000010];   void addedge(int x, int y, int v) {     e[++cnt] = (node){y, hd[x], v}, hd[x] = cnt;     e[++cnt] = (node){x, hd[y], v}, hd[y] = cnt;   }   void add(int i, long long l, long long r, long long x) {     t[i].val++;     if (l == r) return;     long long mid = (l + r) >> 1;     if (x <= mid)       add(t[i].ls ? t[i].ls : (t[i].ls = (++cnt)), l, mid, x);     else       add(t[i].rs ? t[i].rs : (t[i].rs = (++cnt)), mid + 1, r, x);   }   int query(int i, long long l, long long r, long long ql, long long qr) {     if (l == ql && r == qr) return t[i].val;     long long mid = (l + r) >> 1;     if (qr <= mid) return t[i].ls ? query(t[i].ls, l, mid, ql, qr) : 0;     if (ql > mid) return t[i].rs ? query(t[i].rs, mid + 1, r, ql, qr) : 0;     return (t[i].ls ? query(t[i].ls, l, mid, ql, mid) : 0) +            (t[i].rs ? query(t[i].rs, mid + 1, r, mid + 1, qr) : 0);   }   void merge(int i, int I, long long l, long long r) {     t[i].val += t[I].val;     if (l == r) return;     long long mid = (l + r) >> 1;     if (t[i].ls) {       if (t[I].ls) merge(t[i].ls, t[I].ls, l, mid);     } else       t[i].ls = t[I].ls;     if (t[i].rs) {       if (t[I].rs) merge(t[i].rs, t[I].rs, mid + 1, r);     } else       t[i].rs = t[I].rs;   }   void dfs(int x, int fa) {     rt[x] = (++cnt), add(rt[x], 0, lim, dep[x]);     for (int i = hd[x]; i; i = e[i].next)       if (e[i].to != fa) {         if (dep[e[i].to] == -1) dep[e[i].to] = dep[x] + e[i].val;         dfs(e[i].to, x), merge(rt[x], rt[e[i].to], 0, lim);       }     for (int i = 1; i <= Q; i++)       ans[i] = max(ans[i], query(rt[x], 0, lim, dep[x], dep[x] + qv[i]));   }   int main() {     scanf( %d , &n), cnt = 0;     memset(hd, 0, sizeof(hd));     for (int i = 1; i < n; i++) {       scanf( %d%d%d , &x, &y, &v);       addedge(x, y, v);     }     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) scanf( %I64d , &qv[i]), ans[i] = 0;     for (int i = 2; i <= n; i++) dis[i] = -1;     dis[1] = 0, q[l = r = 1] = 1;     while (l <= r) {       x = q[l++];       for (int i = hd[x]; i; i = e[i].next)         if (dis[e[i].to] == -1)           dis[e[i].to] = dis[x] + e[i].val, q[++r] = e[i].to;     }     ma = 0, maa = 0;     for (int i = 1; i <= n; i++)       if (dis[i] > ma) ma = dis[i], maa = i;     for (int i = 1; i <= n; i++) dis[i] = -1;     dis[maa] = 0, q[l = r = 1] = maa;     while (l <= r) {       x = q[l++];       for (int i = hd[x]; i; i = e[i].next)         if (dis[e[i].to] == -1)           dis[e[i].to] = dis[x] + e[i].val, q[++r] = e[i].to,           la[e[i].to] = ((i & 1) ? (i + 1) : (i - 1));     }     ma = 0, maa = 0, nw = 0;     for (int i = 1; i <= n; i++)       if (dis[i] > ma) ma = dis[i], maa = i;     for (int i = 1; i <= n; i++) dep[i] = -1;     while (1) {       nw += e[la[maa]].val;       if ((nw << 1) > ma) {         x = maa, y = e[la[maa]].to;         dep[x] = ma - (nw - e[la[maa]].val);         dep[y] = nw;         break;       }       if ((nw << 1) == ma) {         x = y = e[la[maa]].to;         dep[x] = nw;         break;       }       maa = e[la[maa]].to;     }     cnt = 0;     if (dep[x] < dep[y])       dfs(x, 0);     else       dfs(y, 0);     for (int i = 1; i <= Q; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int nax = 2e5 + 10;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, f;     cin >> n >> f;     vector<int> k(n), l(n);     vector<pair<int, int> > a;     for (int i = 0; i < n; i++) {       cin >> k[i] >> l[i];       a.push_back({min(2 * k[i], l[i]) - min(k[i], l[i]), i});     }     sort(a.rbegin(), a.rend());     ll ans = 0;     for (int i = 0; i < f; i++) {       ans += min(2 * k[a[i].second], l[a[i].second]);     }     for (int i = f; i < n; i++) {       ans += min(k[a[i].second], l[a[i].second]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 987654321;   bool adj[4010][4010];   int n, m, u, v, cnt[4010];   vector<vector<int> > node;   int main() {     scanf( %d%d , &n, &m);     node.resize(n + 1);     while (m--) {       scanf( %d%d , &u, &v);       node[u].push_back(v);       node[v].push_back(u);       adj[u][v] = adj[v][u] = true;     }     for (int i = 1; i <= n; ++i) cnt[i] = node[i].size();     int sol = INF;     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         if (!adj[i][j]) continue;         for (int a = 0; a < node[i].size(); ++a) {           int k = node[i][a];           if (!adj[k][j]) continue;           sol = min(sol, cnt[i] + cnt[j] + cnt[k] - 6);         }       }     }     printf( %d n , sol == INF ? -1 : sol);   }


#include <bits/stdc++.h>   using namespace std;   struct wall {     double x, y;     wall() {}     wall(double x, double y) : x(x), y(y) {}   };   struct tx {     double d;     int v;     tx() {}     tx(double d, int v) : d(d), v(v) {}   };   bool cmp2(const tx& p1, const tx& p2) { return p1.d < p2.d; }   bool cmp(const wall& p1, const wall& p2) { return p1.x < p2.x; }   int dcmp(double x) { return fabs(x) < 1e-8 ? 0 : (x > 0 ? 1 : -1); }   wall w[2000001];   wall ans[2000001];   int n, m;   int f[2000001];   double V;   tx ang[2000001];   int main() {     scanf( %d %lf , &n, &V);     for (int i = 1; i <= n; i++) {       scanf( %lf , &ang[i].d);       ang[i].v = i;     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %lf %lf , &w[i].x, &w[i].y);     sort(w + 1, w + 1 + m, cmp);     sort(ang + 1, ang + 1 + n, cmp2);     int tp = 1;     for (int i = 1; i <= n; i++) {       int flag = 0;       if (tp > m) ans[i] = wall(V * V * sin(2 * ang[i].d) / 9.8, 0.0);       while (tp <= m) {         double tmpx = (w[tp].x * sin(2 * ang[i].d) / 2.0) -                       (9.8 * w[tp].x * w[tp].x / (2.0 * V * V));         tmpx /= cos(ang[i].d) * cos(ang[i].d);         if (tmpx <= 0.0) {           ans[i] = wall(V * V * sin(2 * ang[i].d) / 9.8, 0.0), flag = 1;           break;         } else if (!dcmp(tmpx - w[tp].y) || tmpx < w[tp].y) {           ans[i] = wall(w[tp].x, tmpx);           flag = 1;           break;         } else           tp++;       }       if (!flag) ans[i] = wall(V * V * sin(2 * ang[i].d) / 9.8, 0.0);     }     for (int i = 1; i <= n; i++) f[ang[i].v] = i;     for (int i = 1; i <= n; i++)       printf( %.9lf %.9lf n , ans[f[i]].x, ans[f[i]].y);     return 0;   }


#include <bits/stdc++.h>   #define mset(arr, val) memset(arr, val, sizeof(arr))   #define all(v) v.begin(), v.end()   #define F first   #define S second   #define endl   n    using namespace std;   // const double PI = acos(-1.0);   // const double E = exp(1.0);   // const double EPS = 1e-9;   const int MOD = (int)1e9 + 7;   const int N = (int)2e5;      int main() {   #ifdef MY_LOCAL       freopen( in.txt ,  r , stdin);       freopen( out.txt ,  w , stdout);   #endif       ios_base::sync_with_stdio(false);       cin.tie(0);          int T;       cin >> T;       for (int tc = 1; tc <= T; tc++) {           int n;           cin >> n;           vector<int> a(n);           map<int, int> mp;           cin >> a[0];           mp[a[0]] = 0;           for (int i = 1; i < n; i++) {               cin >> a[i];               if (a[i] != a[i - 1]) {                   mp[a[i]]++;               }           }                      int ans = INT32_MAX;           for (auto x : mp) {               if (x.first != a[n - 1]) {                   x.second++;               }               ans = min(ans, x.second);           }           if (ans == INT32_MAX) {               ans = 0;           }           cout << ans << endl;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   vector<int> mp[maxn];   vector<int> R[maxn];   vector<int> L[maxn];   int ans = 0;   bool vis[maxn];   int n, m;   struct node {     int last_L;     int last_R;   } last[maxn];   void dfs(int now, int l, int r) {     if (now == n) {       ans = max(ans, r - l + 1);       return;     }     for (int i = 0; i < mp[now].size(); i++) {       if (vis[mp[now][i]]) continue;       int nl = max(l, L[now][i]);       int nr = min(r, R[now][i]);       vis[mp[now][i]] = 1;       if (nl <= nr && nr - nl + 1 > ans &&           !(last[mp[now][i]].last_L <= nl && last[mp[now][i]].last_R >= nr))         last[mp[now][i]].last_L = nl, last[mp[now][i]].last_R = nr,         dfs(mp[now][i], nl, nr);       vis[mp[now][i]] = 0;     }     return;   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b, l, r;       cin >> a >> b >> l >> r;       mp[a].push_back(b);       mp[b].push_back(a);       L[a].push_back(l);       L[b].push_back(l);       R[a].push_back(r);       R[b].push_back(r);     }     vis[1] = 1;     last[1].last_L = 1;     last[1].last_R = INT_MAX;     dfs(1, 1, INT_MAX);     if (!ans)       cout <<  Nice work, Dima!  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Data {     int Value, Number;   };   bool operator<(Data A, Data B) { return A.Value < B.Value; }   int Get() {     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     int X = 0;     while (c >=  0  && c <=  9 ) {       X = X * 10 + c - 48;       c = getchar();     }     return X;   }   void Output(int X) {     int Len = 0, Data[10];     while (X) {       Data[Len++] = X % 10;       X /= 10;     }     if (!Len) Data[Len++] = 0;     while (Len--) putchar(Data[Len] + 48);   }   int main() {     int N = Get();     static Data A[100000];     for (int i = 0; i < N; i++) {       A[i].Value = Get();       A[i].Number = i;     }     sort(A, A + N);     static int X[100000], Y[100000];     memset(X, 0, sizeof(X));     memset(Y, 0, sizeof(Y));     int K = (N - 1) / 3 + 1, T = N - K * 2;     for (int i = 0; i < K; i++) {       X[A[i].Number] = A[i].Value;       Y[A[i + K].Number] = A[i + K].Value;     }     for (int i = K * 2; i < N; i++) {       X[A[i].Number] = A[i].Value - N + i;       Y[A[i].Number] = N - i;     }     printf( YES n );     for (int i = 0; i < N; i++) {       Output(X[i]);       putchar((i + 1 == N) ?   n  :    );     }     for (int i = 0; i < N; i++) {       Output(Y[i]);       putchar((i + 1 == N) ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   int64_t a[400005], b[200005];   int64_t len;   int n;   bool check(int64_t value) {     std::vector<std::pair<int64_t, int64_t>> v;     for (int i = 0; i < n; ++i) {       auto rg = std::make_pair(b[i] - value, b[i] + value);       if (rg.first < 0) {         rg.first += len;         rg.second += len;       }       v.push_back(rg);       if (rg.second < len) v.emplace_back(rg.first + len, rg.second + len);     }     std::sort(v.begin(), v.end());     int pa = 0, pr = 0;     while (pr < (int)v.size()) {       while (pa < n * 2 && (a[pa] < v[pr].first || a[pa] > v[pr].second)) ++pa;       if (pa >= n * 2)         return false;       else {         ++pa;         ++pr;       }     }     return true;   }   int main(int argc, char* argv[]) {     scanf( %d%lld , &n, &len);     for (int i = 0; i < n; ++i) scanf( %lld , &a[i]);     for (int i = 0; i < n; ++i) scanf( %lld , &b[i]);     std::sort(a, a + n);     for (int i = 0; i < n; ++i) a[n + i] = a[i] + len;     int64_t left = 0, right = len;     int64_t ans = 0;     while (right >= left) {       int64_t mid = (left + right) / 2;       if (check(mid)) {         ans = mid;         right = mid - 1;       } else         left = mid + 1;     }     printf( %lld n , ans);     return 0;   }