#include <bits/stdc++.h>   using namespace std;   const int64_t LINF = 1LL << 62;   struct Point {     int x, y;     bool operator<(const Point& o) const {       return x < o.x || (x == o.x && y < o.y);     }   };   inline int64_t cross(const Point& o, const Point& a, const Point& b) {     return (a.x - o.x) * (int64_t)(b.y - o.y) -            (a.y - o.y) * (int64_t)(b.x - o.x);   }   int64_t solve(vector<Point> a, int m) {     int n = ((int)(a).size());     Point o = a[0];     sort(a.begin() + 1, a.end(),          [o](const Point& a, const Point& b) { return cross(o, a, b) > 0; });     vector<vector<int>> works(n);     vector<vector<vector<int64_t>>> dp(n);     works[0] = {0};     dp[0] = vector<vector<int64_t>>(1, vector<int64_t>(m + 1, -LINF));     dp[0][0][1] = 0;     int64_t ans = 0;     for (int i = 1; i < n; ++i) {       for (int j = i - 1; j > 0; --j) {         if (works[i].empty() || cross(a[i], a[works[i].back()], a[j]) < 0) {           works[i].push_back(j);         }       }       works[i].push_back(0);       reverse(works[i].begin(), works[i].end());       dp[i] = vector<vector<int64_t>>(((int)(works[i]).size()),                                       vector<int64_t>(m + 1, -LINF));       for (int j = 0; j < ((int)(works[i]).size()); ++j) {         int prev = works[i][j];         int pos = 0, step = 1;         while (step < ((int)(works[prev]).size())) {           step *= 2;         }         for (; step > 0; step /= 2) {           if (pos + step < ((int)(works[prev]).size()) &&               cross(a[i], a[prev], a[works[prev][pos + step]]) <= 0) {             pos += step;           }         }         for (int k = 2; k <= m; ++k) {           dp[i][j][k] = max(j == 0 ? -LINF : dp[i][j - 1][k],                             dp[prev][pos][k - 1] + cross(o, a[prev], a[i]));         }       }       ans = max(ans, dp[i].back().back());     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<Point> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].x >> a[i].y;     }     sort(a.begin(), a.end());     int64_t ans = 0;     for (int i = 0; i < n; ++i) {       ans = max(ans, solve(vector<Point>(a.begin() + i, a.end()), m));     }     cout << ans / 2;     if (ans % 2 == 0) {       cout <<  .00 n ;     } else {       cout <<  .50 n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, start, x;     cin >> n >> start >> x;     int ans = x;     int val, nt;     cout <<  ?   << start << endl;     cin >> val >> nt;     if (val >= x) {       cout <<  !   << val << endl;       return 0;     }     int best = start;     long long diff = x - val;     int step = sqrt(n);     start = ((rand() << 4 + rand()) % n + n) % n + 1;     bool was[n + 1];     fill(was, was + n + 1, 0);     for (int i = 0; i < min(1000, n / 2); i++) {       while (was[start]) {         start = ((rand() << 4 + rand()) % n + n) % n + 1;       }       was[start] = 1;       cout <<  ?   << start << endl;       cin >> val >> nt;       if (val < x and nt == -1) {         cout <<  !   << -1 << endl;         return 0;       }       if (val < x and x - val < diff) diff = x - val, best = start;     }     while (1) {       cout <<  ?   << best << endl;       cin >> val >> nt;       if (val < x and nt == -1) {         cout <<  !   << -1 << endl;         return 0;       }       if (val >= x) {         cout <<  !   << val << endl;         return 0;       }       best = nt;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   template <typename T>   inline T Abs(T x) {     return (x >= 0) ? x : -x;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   inline string toStr(T x) {     stringstream st;     st << x;     string s;     st >> s;     return s;   }   template <typename T>   inline int bit(T mask, int b) {     return (b >= 0 && (mask & (T(1) << b)) != 0) ? 1 : 0;   }   inline int nextInt() {     int x;     if (scanf( %d , &x) != 1) throw;     return x;   }   inline long long nextInt64() {     long long x;     if (scanf( %lld , &x) != 1) throw;     return x;   }   inline double nextDouble() {     double x;     if (scanf( %lf , &x) != 1) throw;     return x;   }   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   const int MAXN = 500100;   const int OSN = (1 << 19) - 1;   int n, lst[MAXN], rst[MAXN], tree[2 * OSN + 10], tree0[2 * OSN + 10];   vector<int> g[MAXN], st;   void DFS(int v, int prev) {     lst[v] = int(st.size());     st.push_back(v);     for (int i = 0; i < (int)(g[v].size()); i++) {       int u = g[v][i];       if (u != prev) DFS(u, v);     }     rst[v] = int(st.size() - 1);   }   void update(int v, int value) {     v += OSN;     tree[v] = value;     while (v > 0) {       v = (v - 1) >> 1;       tree[v] = max(tree[v], value);     }   }   void update(int v, int l, int r, int ll, int rr, int value) {     if (l > rr || ll > r || ll > rr) return;     if (ll <= l && r <= rr) {       tree0[v] = value;       return;     }     int mid = (l + r) >> 1;     update(2 * v + 1, l, mid, ll, rr, value);     update(2 * v + 2, mid + 1, r, ll, rr, value);   }   int getMax(int v, int l, int r, int ll, int rr) {     if (l > rr || ll > r || ll > rr) return 0;     if (ll <= l && r <= rr) return tree[v];     int mid = (l + r) >> 1;     return max(getMax(2 * v + 1, l, mid, ll, rr),                getMax(2 * v + 2, mid + 1, r, ll, rr));   }   int getMax(int v, int l, int r, int x) {     if (l > x || x > r) return 0;     if (l == r) return tree0[v];     int mid = (l + r) >> 1;     int ans = tree0[v];     ans = max(ans, getMax(2 * v + 1, l, mid, x));     ans = max(ans, getMax(2 * v + 2, mid + 1, r, x));     return ans;   }   int check(int v) {     int t0 = getMax(0, 0, OSN, lst[v], rst[v]);     int t1 = getMax(0, 0, OSN, lst[v]);     return int(t0 < t1);   }   int main() {     n = nextInt();     for (int i = 0; i < (int)(n - 1); i++) {       int v = nextInt() - 1;       int u = nextInt() - 1;       g[v].push_back(u);       g[u].push_back(v);     }     DFS(0, 0);     int q = nextInt();     for (int i = 0; i < (int)(q); i++) {       int type = nextInt();       int v = nextInt() - 1;       if (type == 1) update(0, 0, OSN, lst[v], rst[v], i + 1);       if (type == 2) update(lst[v], i + 1);       if (type == 3) printf( %d n , check(v));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long inf = (1ll << 60);   int n, m, k, cnt, a, b, v[N], p[N], ta[N], tb[N], td[N], ca[N << 2], cb[N << 2],       cd[N << 2], flag[N], pa, pb, pc, pd;   long long A[N], B[N], C[N], D[N], co[N], sum, ans = inf;   int read() {     int x = 0, f = 1;     char s;     while ((s = getchar()) >  9  || s <  0 )       if (s ==  - ) f = -1;     while (s <=  9  && s >=  0 )       x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();     return x * f;   }   bool cmp(const int a, const int b) { return v[a] < v[b]; }   void build(const int o, const int l, const int r) {     if (l == r) {       ca[o] = ta[l], cb[o] = tb[l], cd[o] = td[l];       return;     }     int mid = l + r >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);     ca[o] = ca[o << 1 | 1];     cb[o] = cb[o << 1 | 1];     cd[o] = cd[o << 1 | 1];   }   long long query(const int o, const int l, const int r, const int need) {     if (l == r)       return A[max(need, ca[o])] + B[max(need, cb[o])] + D[cd[o]] -              co[l] * (max(need, ca[o]) + max(need, cb[o]) + cd[o] + k - need - m);     int mid = l + r >> 1;     long long t =         max(need, ca[o << 1]) + max(need, cb[o << 1]) + cd[o << 1] + k - need;     if (t >= m)       return query(o << 1, l, mid, need);     else       return query(o << 1 | 1, mid + 1, r, need);   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= n; ++i) v[i] = read(), p[i] = i;     sort(p + 1, p + n + 1, cmp);     for (int i = 1; i <= n; ++i) {       if (i == 1 || co[cnt] < v[p[i]]) co[++cnt] = v[p[i]];       v[p[i]] = cnt;     }     a = read();     for (int i = 1; i <= a; ++i) b = read(), flag[b] |= 1;     a = read();     for (int i = 1; i <= a; ++i) b = read(), flag[b] |= 2;     for (int i = 1; i <= n; ++i) {       if (flag[i] == 0) D[++pd] = co[v[i]], ++td[v[i]];       if (flag[i] == 1) A[++pa] = co[v[i]], ++ta[v[i]];       if (flag[i] == 2) B[++pb] = co[v[i]], ++tb[v[i]];       if (flag[i] == 3) C[++pc] = co[v[i]];     }     sort(A + 1, A + pa + 1);     sort(B + 1, B + pb + 1);     sort(C + 1, C + pc + 1);     sort(D + 1, D + pd + 1);     for (int i = 1; i <= cnt; ++i)       ta[i] += ta[i - 1], tb[i] += tb[i - 1], td[i] += td[i - 1];     for (int i = 1; i <= pa; ++i) A[i] += A[i - 1];     for (int i = 1; i <= pb; ++i) B[i] += B[i - 1];     for (int i = 1; i <= pd; ++i) D[i] += D[i - 1];     build(1, 0, cnt);     for (int i = 0; i <= min(m, pc); ++i) {       sum += C[i];       if (min(pa, pb) >= k - i && 2 * k - 2 * i <= m - i && i + pa + pb + pd >= m)         ans = min(ans, sum + query(1, 0, cnt, k - i));     }     printf( %lld n , ans == inf ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int len, i;     bool chk = true;     string str;     cin >> str;     char ch =  a ;     len = str.size();     for (i = 0; i < len; i++) {       if (str[i] > ch) {         chk = false;         break;       } else if (str[i] == ch)         ch++;     }     chk ? printf( YES n ) : printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   long long gi() {     long long x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   int n, tt;   long long m, k, d[N];   pair<long long, long long> p[N];   int main() {     int T = gi();     while (T--) {       m = gi();       n = gi();       k = gi();       for (int i = 1; i <= n; i++) d[i] = gi();       d[++n] = m;       for (int i = n; i; i--) d[i] -= d[i - 1];       if (!k) {         cout << *max_element(d + 1, d + n + 1) - *min_element(d + 1, d + n + 1)              <<   n ;         continue;       }       long long l = 1, r = 1e15;       while (l < r) {         long long mid = (l + r + 1) >> 1, sum = 0;         for (int i = 1; i <= n; i++) {           sum += d[i] / mid - 1;           if (sum >= k) break;         }         if (sum >= k)           l = mid;         else           r = mid - 1;       }       long long mx = l;       l = 1, r = 1e15;       while (l < r) {         long long mid = (l + r) >> 1, sum = 0;         for (int i = 1; i <= n; i++) {           sum += (d[i] + mid - 1) / mid - 1;           if (sum > k) break;         }         if (sum <= k)           r = mid;         else           l = mid + 1;       }       long long mn = l;       tt = 0;       for (int i = 1; i <= n; i++) {         if ((d[i] + mn - 1) / mn > d[i] / mx) {           long long t = d[i] / mx;           p[++tt].first = d[i] / (t + 1);           t = (d[i] + mn - 1) / mn;           if (t == 1)             p[tt].second = 1e18;           else             p[tt].second = (d[i] + t - 2) / (t - 1);         }       }       sort(p + 1, p + tt + 1);       long long low = mn, ans = 1e18;       for (int i = 1, j; i <= tt; i = j + 1) {         j = i;         while (j < tt && p[j + 1].first == p[i].first) ++j;         ans = min(ans, low - p[i].first);         for (int k = i; k <= j; k++) low = max(low, p[k].second);       }       ans = min(ans, low - mx);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.141592653589793238;   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   char str[200005];   int lps[200005];   int kmp() {     int i = 0, j = 1, m = strlen(str);     lps[0] = 0;     while (j < m) {       while (i && str[i] != str[j]) {         i = lps[i - 1];       }       if (str[i] == str[j]) ++i;       lps[j++] = i;     }     if (m % (m - i) == 0) return (m - i);     return m;   }   int main() {     scanf( %s , str);     cout << kmp() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int INF = 1e9;   int n, m;   char mt[1505][1505];   const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};   bool flag = false;   pair<int, int> vis[1505][1505];   void dfs(int x, int y) {     int ax = (x % n + n) % n, ay = (y % m + m) % m;     if (mt[ax][ay] ==  # ) return;     if (vis[ax][ay] != make_pair(INF, INF) && vis[ax][ay] != make_pair(x, y)) {       flag = true;       return;     }     if (vis[ax][ay] != make_pair(INF, INF)) return;     vis[ax][ay] = make_pair(x, y);     for (int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     int sx, sy;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) vis[i][j] = make_pair(INF, INF);     for (int i = 0; i < n; i++) {       cin >> mt[i];       for (int j = 0; j < m; j++)         if (mt[i][j] ==  S ) sx = i, sy = j;     }     dfs(sx, sy), cout << (flag == true ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct bian {     int next, point, w;   } b[10000];   int d[2100][2100], n, x[2100], f[2100], pd[2100], pre[2100], p[2100], len;   long long e[2100][2100];   int getmin() {     int num = 2e9, where = 0;     for (int i = 1; i <= n; i++)       if (pd[i] == 0 && f[i] < num) {         num = f[i];         where = i;       }     return where;   }   void ade(int k1, int k2, int k3) {     b[++len] = (bian){p[k1], k2, k3};     p[k1] = len;   }   void add(int k1, int k2, int k3) {     ade(k1, k2, k3);     ade(k2, k1, k3);   }   void dfs(int k1, int k2, long long k3, int k4) {     e[k4][k1] = k3;     for (int i = p[k1]; i; i = b[i].next) {       int j = b[i].point;       if (j != k2) dfs(j, k1, k3 + b[i].w, k4);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &d[i][j]);     for (int i = 1; i <= n; i++)       if (d[i][i] != 0) {         cout <<  NO  << endl;         return 0;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (d[i][j] != d[j][i]) {           cout <<  NO  << endl;           return 0;         }     memset(f, 0x3f, sizeof f);     f[1] = 0;     memset(pd, 0x00, sizeof pd);     for (int i = 1; i <= n; i++) {       int k1 = getmin();       if (k1 != 1 && f[k1] == 0) {         cout <<  NO  << endl;         return 0;       }       if (pre[k1]) add(pre[k1], k1, f[k1]);       pd[k1] = 1;       for (int j = 1; j <= n; j++)         if (pd[j] == 0 && d[k1][j] < f[j]) {           pre[j] = k1;           f[j] = d[k1][j];         }     }     for (int i = 1; i <= n; i++) dfs(i, 0, 0, i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (e[i][j] != d[i][j]) {           cout <<  NO  << endl;           return 0;         }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, mn, mx, l, t, mn2 = INT_MAX, mx2 = INT_MIN;   set<long long> q;   int main() {     cin >> n >> m >> mn >> mx;     long long a[m];     for (int i = 0; i < m; i++) {       cin >> a[i];       if (a[i] < mn2) mn2 = a[i];       if (a[i] > mx2) mx2 = a[i];       if (a[i] >= mn && a[i] <= mx) t++;     }     if (t == m && m <= n) {       if (mn2 != mn && mx2 != mx && t + 2 <= n)         cout <<  Correct ;       else if ((mn2 == mn && t + 1 <= n) || (mx2 == mx && t + 1 <= n))         cout <<  Correct ;       else if (mn2 == mn && mx2 == mx && t <= n)         cout <<  Correct ;       else         cout <<  Incorrect ;     } else       cout <<  Incorrect ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);     };     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<int> matching;       vector<int> vis(3 * n + 1, 0);       for (int i = 1; i <= m; i++) {         int u, v;         cin >> u >> v;         if (!vis[u] and !vis[v]) {           matching.push_back(i);           vis[u] = vis[v] = 1;         }       }       if (matching.size() >= n) {         cout <<  Matching  << endl;         for (int i = 0; i < n; i++) cout << matching[i] <<    ;         cout << endl;       } else {         cout <<  IndSet  << endl;         int seen = 0;         for (int i = 1; i <= 3 * n and seen < n; i++) {           if (!vis[i]) {             cout << i <<    ;             seen++;           }         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   char x[200005];   int dp[200005], maxdp[26];   int main() {     int n;     scanf( %d , &n);     scanf( %s , x + 1);     for (int i = 1; i <= n; i++) {       x[i] = x[i] -  a ;       dp[i] = 1;     }     maxdp[x[1]] = 1;     for (int i = 2; i <= n; i++) {       for (int j = x[i] + 1; j < 26; j++) {         dp[i] = dp[i] < maxdp[j] + 1 ? maxdp[j] + 1 : dp[i];       }       if (dp[i] > maxdp[x[i]]) maxdp[x[i]] = dp[i];     }     int ans = -1;     for (int i = 1; i <= n; i++) {       if (dp[i] > ans) ans = dp[i];     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d  , dp[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, m;     cin >> t >> m;     vector<int> A;     A.resize(m);     int c = 0;     for (int i = 0; i < m; ++i) A[i] = 0;     for (int i = 0; i < t; ++i) {       string z;       int tmp;       cin >> z;       if (z[0] ==  d ) {         for (int j = 0; j < m - 1; ++j) {           for (int k = m - 1; k > j; k--) {             if (A[k] != 0 && 0 == A[k - 1]) {               int tmp2 = A[k];               A[k] = A[k - 1];               A[k - 1] = tmp2;             }           }         }       } else if (z[0] ==  e ) {         cin >> tmp;         int j = 0;         while (j < m && A[j] != tmp) j++;         if (j == m || tmp == 0) cout <<  ILLEGAL_ERASE_ARGUMENT  << endl;         while (j < m && A[j] == tmp) {           A[j] = 0;           j++;         }       } else {         cin >> tmp;         int empty = 0;         int j = 0;         while (j < m && empty < tmp) {           if (A[j] == 0)             empty++;           else             empty = 0;           j++;         }         if (j == m && empty < tmp)           cout <<  NULL  << endl;         else {           c++;           for (int k = j - 1; k > j - 1 - empty; --k) {             A[k] = c;           }           cout << c << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline int Rint() {     int x;     scanf( %d , &x);     return x;   }   const int MOD = 1e9 + 7;   const int MAXN = 1e5 + 10;   int alll(char* str_a, char* str_b, int n) {     int ret = 1;     for (int i = 0; i < n; ++i) {       if (str_a[i] ==  ? ) ret = ret * 10ll % MOD;       if (str_b[i] ==  ? ) ret = ret * 10ll % MOD;     }     return ret;   }   int upp(char* str_a, char* str_b, int n) {     int ans = 1;     for (int i = 0; i < n; ++i) {       if (str_a[i] == str_b[i]) {         if (str_a[i] !=  ? )           ;         else           ans = ans * 55ll % MOD;       } else if (str_a[i] ==  ? ) {         ans = ans * (long long)( 9  - str_b[i] + 1) % MOD;       } else if (str_b[i] ==  ? ) {         ans = ans * (long long)(str_a[i] -  0  + 1) % MOD;       } else if (str_a[i] >= str_b[i]) {       } else         return 0;     }     return ans;   }   int equ(char* str_a, char* str_b, int n) {     int ret = 1;     for (int i = 0; i < n; ++i)       if (str_a[i] ==  ?  || str_b[i] ==  ? ) {         if (str_a[i] ==  ?  && str_b[i] ==  ? ) ret = ret * 10ll % MOD;       } else if (str_a[i] != str_b[i])         return 0;     return ret;   }   int n;   char str_a[MAXN], str_b[MAXN];   int main() {     while (cin >> n) {       scanf( %s , str_a);       scanf( %s , str_b);       int all = alll(str_a, str_b, n);       int mod1 = upp(str_a, str_b, n);       int mod2 = upp(str_b, str_a, n);       int mod3 = equ(str_a, str_b, n);       int ans = ((mod1 + mod2 - mod3) % MOD + MOD) % MOD;       ans = (all - ans + MOD) % MOD;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ip {     long long a, b, c, d, m;   };   ip getip(long long num, int mm) {     return {(num & (255 << 24)) >> 24, (num & (255 << 16)) >> 16,             (num & (255 << 8)) >> 8, num & 255, mm};   }   vector<ip> numtoip(pair<long long, long long> p) {     long long s = p.first, e = p.second;     vector<ip> ans;     while (s < e) {       int k = (!s) ? 32 : __builtin_ctzll(s);       while (s + (1ll << k) - 1 >= e) k--;       ans.push_back(getip(s, 32 - k));       s += 1ll << k;     }     return ans;   }   pair<long long, long long> iptonum(ip x) {     long long n =         x.a * (1 << 24) + x.b * (1 << 16) + x.c * (1 << 8) + x.d * (1 << 0);     bitset<32> low(n), high(n);     for (int i = 0, ThxDem = 32 - x.m; i < ThxDem; ++i) low[i] = 0, high[i] = 1;     return {low.to_ullong(), high.to_ullong() + 1};   }   struct disjoint_intervals {     set<pair<long long, long long> > s;     void insert(pair<long long, long long> v) {       if (v.first >= v.second) return;       auto at = s.lower_bound(v);       auto it = at;       if (at != s.begin() && (--at)->second >= v.first) v.first = at->first, --it;       for (; it != s.end() && it->first <= v.second; s.erase(it++))         v.second = max(v.second, it->second);       s.insert(v);     }     bool intersect(pair<long long, long long> v) {       auto it = s.upper_bound({v.first, -2});       return (it != s.end() && it->first < v.second) ||              (it != s.begin() && prev(it)->second > v.first);     }   };   disjoint_intervals w, b;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0, ThxDem = n; i < ThxDem; ++i) {       string s;       cin >> s;       s +=  . ;       int now = 0, white = s[0] ==  + ;       vector<int> v;       for (int i = 1, ThxDem = ((int)(s).size()); i < ThxDem; ++i) {         if (s[i] >=  0  && s[i] <=  9 )           now = 10 * now + s[i] -  0 ;         else           v.push_back(now), now = 0;       }       if (v.size() < 5) v.push_back(32);       auto ran = iptonum({v[0], v[1], v[2], v[3], v[4]});       if (white)         w.insert(ran);       else         b.insert(ran);     }     for (auto x : w.s) {       if (b.intersect(x)) {         cout << -1 << endl;         return 0;       }     }     vector<pair<long long, long long> > good = {{-1, 0}}, ans;     for (auto x : w.s) good.push_back(x);     good.push_back({1ll << 32, (1ll << 32) + 1ll});     for (int i = 1, ThxDem = ((int)(good).size()); i < ThxDem; ++i)       ans.push_back({good[i - 1].second, good[i].first});     vector<ip> res;     for (auto xx : ans) {       vector<ip> x = numtoip(xx);       for (auto aux : x) {         auto rr = iptonum(aux);         if (b.intersect(rr)) res.push_back(aux);       }     }     cout << res.size() << endl;     for (auto x : res)       cout << x.a <<  .  << x.b <<  .  << x.c <<  .  << x.d <<  /  << x.m << endl;   }


#include <bits/stdc++.h>   using namespace std;   string imp =  Impossible n ;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   clock_t startTime;   double getCurrentTime() {     return (double)(clock() - startTime) / CLOCKS_PER_SEC;   }   const int N = 1e5 + 1e3;   long long MOD = 1e9 + 7;   vector<int> aa[N];   int a[N], b[N], c[N];   int n, m, k, i, j;   bool d[N];   string s;   bool iscons(char c) {     if (c !=  a  && c !=  e  && c !=  i  && c !=  o  && c !=  u ) return true;     return false;   }   int main() {     startTime = clock();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tests = 1;     while (tests--) {       cin >> s;       int ns = s.size();       if (ns < 3) {         cout << s;         return 0;       }       int cons = 0;       if (iscons(s[1])) {         if (iscons(s[0]))           cons += 2;         else           cons++;       }       cout << s[0] << s[1];       for (int i = 2; i < ns; i++) {         if (iscons(s[i])) {           cons++;           if (cons == 3) {             if (s[i] == s[i - 1] && s[i - 1] == s[i - 2]) cons = 2;           }         } else           cons = 0;         if (cons == 3) {           cout <<    ;           cons = 1;         }         cout << s[i];       }     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;   void mex(string &s)   {       s.back()++;       for(int i=s.length()-1;i>=1;i--)       {           if(s[i]> z )           {               s[i]= a ;               s[i-1]++;           }                  }       if(s[0]> z )           {               s.push_back( a );               s[0]= a ;           }   }      int main()   {       int t;cin>>t;       while(t--)       {           int n;cin>>n;           string s;cin>>s;           string k= a ;           while(s.find(k,0)!=string::npos)           {               mex(k);           }           cout<<k<<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   int b[105];   int main() {     int n, m, i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d%d , &a[i], &b[i]);     int con = 0;     for (i = 1; i <= 10000; i++) {       int s = 0;       for (j = 1; j <= n; j++) s += (i * a[j] / b[j] + 1);       if (s == m) con++;     }     printf( %d n , con);   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   int n, m, k, second;   int a[500005];   int b[500005];   int cnt[500005];   int rbd[500005];   int stat[500005];   int app[500005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> m >> k >> n >> second;     for (int i = (1); i <= (signed)(m); i++) {       cin >> a[i];     }     for (int i = (1); i <= (signed)(second); i++) {       int x;       cin >> x;       b[x]++;     }     int rb = 0;     int sat = 0;     for (int i = (1); i <= (signed)(m); i++) {       while (rb <= m && sat < second) {         rb++;         int c = a[rb];         if (b[c] > cnt[c]) {           sat++;         }         cnt[c]++;       }       rbd[i] = max(rb, i + k - 1);       int c = a[i];       if (b[c] >= cnt[c]) sat--;       cnt[c]--;     }     int dc = 0;     for (int i = (1); i <= (signed)(m); i++) {       if (rbd[i] == m + 1) break;       int bef = (i - 1) / k;       int aft = (m - rbd[i]) / k;       if (bef + aft + 1 >= n) {         for (int j = (i); j <= (signed)(rbd[i]); j++) {           int c = a[j];           if (b[c] > app[c]) {             stat[j] = 1;           }           app[c]++;         }         int added = second;         for (int j = (i); j <= (signed)(rbd[i]); j++) {           if (added < k && stat[j] == 0) {             added++;             stat[j] = 1;           } else if (added == k && stat[j] == 0) {             stat[j] = -1;             dc++;           }         }         int td = (i - 1) % k;         if (bef >= n) {           td += (bef + 1 - n) * k;         }         for (int i = (1); i <= (signed)(td); i++) {           stat[i] = -1;           dc++;         }         cout << dc <<   n ;         for (int i = (1); i <= (signed)(m); i++) {           if (stat[i] == -1) cout << i <<    ;         }         return 0;       }     }     cout <<  -1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     string t, s;     cin >> s >> t;     n = t.size();     vector<long long> pi(n + 1, 0);     for (long long i = (long long)1; i != (long long)n; i = i + 1) {       long long j = pi[i - 1];       while (j >= 0 && t[i] != t[j]) {         j = j > 0 ? pi[j - 1] : -1;       }       pi[i] = j + 1;     }     vector<long long> dp1(s.size() + 1, 0), dp2(s.size() + 1, 0),         dp3(s.size() + 1, 0);     vector<long long> pos;     long long curpi = 0;     for (long long i = (long long)0; i != (long long)s.size(); i = i + 1) {       long long j = curpi < n ? curpi : pi[curpi - 1];       while (j >= 0 && s[i] != t[j]) {         j = j > 0 ? pi[j - 1] : -1;       }       curpi = j + 1;       if (curpi == n) {         pos.push_back(i);       }     }     if (pos.size() == 0) {       cout << 0 <<   n ;       return 0;     }     long long j = 0;     for (long long i = (long long)0; i != (long long)s.size(); i = i + 1) {       if (j < pos.size() && i == pos[j]) {         j++;         dp1[i + 1] = (dp3[i + 1 - n] + i + 2 - n) % mod;         dp2[i + 1] = (dp1[i + 1] + dp2[i]) % mod;       } else {         dp1[i + 1] = dp1[i];         dp2[i + 1] = (dp2[i] + dp1[i + 1]) % mod;       }       dp3[i + 1] = (dp3[i] + dp2[i + 1]) % mod;     }     cout << dp2[s.size()] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a[101], b[101];   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     cin >> m;     for (int i = 0; i < m; ++i) cin >> b[i];     sort(b, b + m);     cout << a[n - 1] <<     << b[m - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char name[105][20];   long long type[105], w[105], h[105], border[105], space[105];   int link[105][105];   bool caled[105];   int n, m;   void cal(int x) {     if (caled[x]) return;     caled[x] = true;     if (link[x][0] == 0) return;     int i, k;     if (type[x] == 2) {       for (i = 1; i <= link[x][0]; i++) {         k = link[x][i];         cal(k);         w[x] += w[k];         if (h[k] > h[x]) h[x] = h[k];       }       w[x] += border[x] * 2;       h[x] += border[x] * 2;       w[x] += space[x] * (link[x][0] - 1);       return;     }     for (i = 1; i <= link[x][0]; i++) {       k = link[x][i];       cal(k);       h[x] += h[k];       if (w[k] > w[x]) w[x] = w[k];     }     w[x] += border[x] * 2;     h[x] += border[x] * 2;     h[x] += space[x] * (link[x][0] - 1);   }   void exchange(int x, int y) {     int i, k;     char c;     k = max(strlen(name[x]), strlen(name[y]));     for (i = 0; i <= k; i++) {       c = name[x][i];       name[x][i] = name[y][i];       name[y][i] = c;     }   }   int main() {     int i, j, k, l, t;     char s[1000], tmp[1000];     scanf( %d , &m);     n = 0;     for (i = 1; i <= m; i++) {       scanf( %s , s);       if (!strcmp(s,  Widget )) {         scanf( %s , s);         n++;         type[n] = 1;         caled[n] = true;         j = 0;         while (s[j] !=  ( ) {           name[n][j] = s[j];           j++;         }         name[n][j] =   0 ;         j++;         w[n] = 0;         h[n] = 0;         while (s[j] !=  , ) {           w[n] = w[n] * 10 + (s[j] -  0 );           j++;         }         j++;         while (s[j] !=  ) ) {           h[n] = h[n] * 10 + (s[j] -  0 );           j++;         }         continue;       }       if ((!strcmp(s,  HBox )) || (!strcmp(s,  VBox ))) {         n++;         caled[n] = false;         w[n] = 0;         h[n] = 0;         border[n] = 0;         space[n] = 0;         link[n][0] = 0;         if (!strcmp(s,  HBox ))           type[n] = 2;         else           type[n] = 3;         scanf( %s , s);         strcpy(name[n], s);         continue;       }       j = 0;       while (s[j] !=  . ) {         tmp[j] = s[j];         j++;       }       tmp[j] =   0 ;       j++;       k = 1;       while (strcmp(tmp, name[k]) != 0) k++;       t = 0;       while (s[j] !=  ( ) {         tmp[t] = s[j];         j++;         t++;       }       j++;       tmp[t] =   0 ;       if (!strcmp(tmp,  pack )) {         t = 0;         while (s[j] !=  ) ) {           tmp[t] = s[j];           t++;           j++;         }         tmp[t] =   0 ;         l = 1;         while (strcmp(tmp, name[l]) != 0) l++;         if (k == l) continue;         link[k][0]++;         link[k][link[k][0]] = l;         continue;       }       if (!strcmp(tmp,  set_border )) {         border[k] = 0;         while (s[j] !=  ) ) {           border[k] = border[k] * 10 + (s[j] -  0 );           j++;         }         continue;       }       if (!strcmp(tmp,  set_spacing )) {         space[k] = 0;         while (s[j] !=  ) ) {           space[k] = space[k] * 10 + (s[j] -  0 );           j++;         }         continue;       }     }     for (i = 1; i <= n; i++) cal(i);     for (i = 1; i <= n - 1; i++)       for (j = i + 1; j <= n; j++)         if (strcmp(name[i], name[j]) > 0) {           swap(w[i], w[j]);           swap(h[i], h[j]);           exchange(i, j);         }     for (i = 1; i <= n; i++) printf( %s %I64d %I64d n , name[i], w[i], h[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 505;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   char dc[] = { R ,  L ,  D ,  U };   string ans;   int n;   bool grid[MAX][MAX], vis[MAX][MAX];   int dp[MAX][MAX][4];   bool valid(int x, int y, int dir) {     return dp[x][y][dir] = ~dp[x][y][dir]                 ? dp[x][y][dir]                            : (!x || !y || x > n || y > n) ? 0                            : grid[x][y]                   ? 1                                         : valid(x + dx[dir], y + dy[dir], dir);   }   void dfs1(int x, int y) {     vis[x][y] = 1;     if (!grid[x][y]) ans +=  1 , grid[x][y] = 1;     for (int i = 0; i < 4; ++i) {       int nx = x + dx[i], ny = y + dy[i];       if (vis[nx][ny] || !valid(nx, ny, i)) continue;       ans += dc[i];       dfs1(nx, ny);       ans += dc[i ^ 1];     }   }   void dfs0(int x, int y) {     grid[x][y] = 0;     for (int i = 0; i < 4; ++i) {       int nx = x + dx[i], ny = y + dy[i];       if (!grid[nx][ny]) continue;       ans += dc[i];       dfs0(nx, ny);       ans += dc[i ^ 1];     }     ans +=  2 ;   }   int main() {     int sx, sy;     memset(dp, -1, sizeof dp);     cin >> n >> sx >> sy;     for (int i = 1; i <= n; ++i) {       vis[0][i] = vis[i][0] = vis[0][n + 1] = vis[n + 1][0] = 1;       for (int j = 1; j <= n; ++j) scanf( %d , grid[i] + j);     }     dfs1(sx, sy);     dfs0(sx, sy);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (grid[i][j]) return puts( NO ), 0;     puts( YES );     puts(ans.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Grass {     int sizee;     char dir;   } a[100005];   int n;   bool flag[100005];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].dir;     }     for (int i = 1; i <= n; i++) {       cin >> a[i].sizee;     }     int nowx = 1;     flag[nowx] = 1;     while (true) {       if (a[nowx].dir ==  > ) {         nowx += a[nowx].sizee;       } else {         nowx -= a[nowx].sizee;       }       if (nowx > n || nowx < 1) {         cout <<  FINITE ;         break;       }       if (flag[nowx] == 1) {         cout <<  INFINITE ;         break;       }       flag[nowx] = 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200000], x, y, ans;   multimap<int, int> M;   pair<int, int> P;   int main() {     scanf( %d , &n);     for (int i = 1; i <= (n); ++i) scanf( %d , &a[i]);     scanf( %d%d , &x, &y);     sort(a + 1, a + n + 1);     n = unique(a + 1, a + n + 1) - a - 1;     for (int i = 1; i <= (n); ++i)       if (x - x % a[i] >= y) M.insert(make_pair(x - x % a[i], a[i]));     while (x > y) {       if (M.empty()) {         ans += x - y;         break;       }       multimap<int, int>::iterator it = M.begin();       if (it->first < x)         x = it->first;       else         --x;       ++ans;       for (it = M.end(); !M.empty() && (--it)->first > x; it = M.end()) {         P.first = x - x % it->second;         P.second = it->second;         M.erase(it);         if (P.first >= y) M.insert(P);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int>>> adj[(long)(1e5)];   int sub[(long)(1e5)];   int w[(long)(1e5)];   int c[(long)(1e5)];   int dfs(int r, int p) {     int cnt = 0;     for (int i = 0; i < adj[r].size(); i++) {       if (adj[r][i].first != p) {         w[adj[r][i].first] = adj[r][i].second.first;         c[adj[r][i].first] = adj[r][i].second.second;         cnt += dfs(adj[r][i].first, r);       }     }     if (!cnt) cnt = 1;     sub[r] = cnt;     return cnt;   }   void solve() {     int n;     long long s;     scanf( %d%lld , &n, &s);     for (int i = 0; i < n; i++) adj[i].clear();     for (int i = 0; i < n - 1; i++) {       int u, v, ww, cc;       scanf( %d%d%d%d , &u, &v, &ww, &cc);       adj[u - 1].push_back({v - 1, {ww, cc}});       adj[v - 1].push_back({u - 1, {ww, cc}});     }     for (int i = 0; i < n; i++) sub[i] = 0;     dfs(0, -1);     vector<long long> vs[2];     for (int k = 0; k < 2; k++) {       long long sum = 0;       set<pair<long long, int>> di;       for (int i = 1; i < n; i++) {         if (c[i] == k + 1) {           di.insert({(1ll * sub[i] * w[i] - 1ll * sub[i] * (w[i] / 2)), i});           sum += 1ll * sub[i] * w[i];         }       }       vs[k].push_back(sum);       while (sum > 0) {         int i = di.rbegin()->second;         long long decr = di.rbegin()->first;         di.erase(prev(di.end()));         sum -= decr;         w[i] = w[i] / 2;         di.insert({(1ll * sub[i] * w[i] - 1ll * sub[i] * (w[i] / 2)), i});         vs[k].push_back(sum);       }     }     int flip = 0;     if (vs[0].size() > vs[1].size()) {       swap(vs[1], vs[0]);       flip = 1;     }     int ans = 1e9;     for (int i = 0; i < vs[0].size(); i++) {       int lo = 0, hi = vs[1].size() - 1;       while (lo <= hi) {         int mid = (lo + hi) / 2;         if (vs[0][i] + vs[1][mid] <= s)           hi = mid - 1;         else           lo = mid + 1;       }       if (vs[0][i] + vs[1][lo] <= s)         ans = min(ans, i * (1 + flip) + lo * (2 - flip));     }     printf( %d n , ans);   }   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   struct Edge {     int to, nxt;   } e[N << 1];   int h[N], idx, a[N];   void Ins(int a, int b) {     e[++idx].to = b;     e[idx].nxt = h[a];     h[a] = idx;   }   long long dis[N], siz[N];   void dfs(int u, int fa) {     siz[u] = a[u];     for (int i = h[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       dfs(v, u);       siz[u] += siz[v];       dis[1] += siz[v];     }   }   long long sum;   void dfs1(int u, int fa) {     for (int i = h[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       dis[v] = dis[u] + sum - 2ll * siz[v];       dfs1(v, u);     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum += a[i];     for (int i = 2; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       Ins(x, y);       Ins(y, x);     }     dfs(1, 0);     dfs1(1, 0);     long long res = 0;     for (int i = 1; i <= n; i++) res = max(res, dis[i]);     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, i, j;     int l = 0, t = 0, m = 0, max = 0;     cin >> n;     cin >> i >> j;     l = j;     while (t < n) {       t++;       cin >> x >> y;       m = j - x + y;       if (m > max) {         max = m;       }       j = m;     }     if (max == 0 && l > 0 || l > max)       cout << l;     else       cout << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, t, a, x, cur = 0, sum = 0, sz = 1;     cin >> n;     vector<long long> arr(n + 20), ch(n + 20);     for (int i = 0; i < n; i++) {       cin >> t;       if (t == 1) {         cin >> a >> x;         ch[a - 1] += x;         sum += a * x;       } else if (t == 2) {         cin >> x;         sum += x;         arr[++cur] = x;       } else {         sum -= (arr[cur] + ch[cur]);         ch[cur - 1] += ch[cur];         ch[cur] = 0;         arr[cur] = 0;         cur--;       }       cout << (sum * 1.0) / (1.0 * (cur + 1)) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(12);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9 + 1;   const int MAXN = (int)5001;   int solve(vector<pair<int, int> > sg, int pos) {     sg.erase(sg.begin() + pos);     int mx = sg[0].first, mn = sg[0].second;     for (int i = (1); i < (int)(sg.size()); i++) {       if (sg[i].first > mn || sg[i].second < mx) return 0;       mx = max(mx, sg[i].first);       mn = min(mn, sg[i].second);     }     return abs(mx - mn);   }   bool comp1(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first == b.first) ? (a.second - a.first > b.second - b.first)                                 : (a.first < b.first);   }   bool comp2(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second == b.second) ? (a.second - a.first < b.second - b.first)                                   : (a.second < b.second);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, y;     cin >> n;     vector<pair<int, int> > sgm;     for (int i = (0); i < (int)(n); i++) {       cin >> x >> y;       sgm.push_back(make_pair(x, y));     }     sort((sgm).begin(), (sgm).end(), comp1);     x = solve(sgm, n - 1);     sort((sgm).begin(), (sgm).end(), comp2);     cout << max(x, solve(sgm, 0));   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string s;   set<string> st;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     while (cin >> s) {       st.clear();       for (int i = 0; i < s.size(); i++) {         string s1 =   ;         for (int j = 0; j < s.size(); j++) s1 += s[(i + j) % s.size()];         st.insert(s1);       }       cout << st.size() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> moves = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};   bool isValid(int a, int b, int x, int y) {     return (a >= 0 && a < x) && (b >= 0 && b < y);   }   bool isPath(int n, int m, vector<string>& mat) {     bool isPossible = false;     int cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mat[i][j] ==  G ) cnt++;       }     }     if (mat[n - 1][m - 1] ==  #  && cnt > 0) return isPossible;     vector<vector<bool>> vis(n, vector<bool>(m));     queue<pair<int, int>> q;     q.push({n - 1, m - 1});     vis[n - 1][m - 1] = true;     while (!q.empty()) {       pair<int, int> curr = q.front();       q.pop();       if (mat[curr.first][curr.second] ==  G ) {         cnt--;       }       for (int i = 0; i < 4; i++) {         int nx = curr.first + moves[i][0];         int ny = curr.second + moves[i][1];         if (isValid(nx, ny, n, m) && mat[nx][ny] !=  #  && !vis[nx][ny]) {           q.push({nx, ny});           vis[nx][ny] = true;         }       }     }     isPossible = cnt <= 0 ? true : false;     return isPossible;   }   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> mat(n);       for (int i = 0; i < n; i++) {         cin >> mat[i];       }       bool isPossible = true;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (mat[i][j] ==  B ) {             for (int k = 0; k < 4; k++) {               int nx = i + moves[k][0];               int ny = j + moves[k][1];               if (isValid(nx, ny, n, m)) {                 if (mat[nx][ny] ==  G ) {                   isPossible = false;                   break;                 } else if (mat[nx][ny] ==  . ) {                   mat[nx][ny] =  # ;                 }               }             }           }           if (!isPossible) break;         }         if (!isPossible) break;       }       if (!isPossible) {         cout <<  No  << endl;       } else {         isPossible = isPath(n, m, mat);         if (!isPossible)           cout <<  No  << endl;         else           cout <<  Yes  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int t = 0;   int d[300000];   int par[300000];   int t1[300000];   int t2[300000];   void dfs(int s, vector<vector<int> > &ed, int y) {     d[s] = y;     t1[s] = t++;     for (int i = 0; i < ed[s].size(); i++) {       if (ed[s][i] != par[s]) {         par[ed[s][i]] = s;         dfs(ed[s][i], ed, y + 1);       }     }     t2[s] = t++;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<vector<int> > v(n);     int f, s;     for (int i = 1; i < n; i++) {       cin >> f >> s;       f--;       s--;       v[f].push_back(s);       v[s].push_back(f);     }     for (int i = 0; i < n; i++) {       sort(v[i].begin(), v[i].end());     }     par[0] = -1;     dfs(0, v, 0);     for (int i = 0; i < m; i++) {       cin >> f;       vector<int> h(f);       for (int j = 0; j < f; j++) {         cin >> h[j];         h[j]--;       }       int u = 0;       for (int j = 0; j < f; j++) {         if (d[h[j]] > d[u]) {           u = h[j];         }       }       int flag = 1;       for (int j = 0; j < f; j++) {         if (!((t1[h[j]] <= t1[u] && t2[h[j]] >= t2[u]) ||               (t1[par[h[j]]] <= t1[u] && t2[par[h[j]]] >= t2[u]))) {           flag = 0;           break;         }       }       if (flag == 0) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;      typedef long long ll;      int q(int l, int r){       cout <<  ?   << l <<     << r << endl;       int idx; cin >> idx;       return idx;   }   void solve(){       int n;       cin >> n;       int idx = q(1, n);       int L = -1, R = -1;       if(1 < idx) L = q(1, idx);       if(n > idx) R = q(idx, n);       if(R == idx){ // 最大值在右           int ans = n, l = idx + 1, r = n, mid;           while(l <= r){               mid = l + r >> 1;               int t = q(idx, mid);               if(t == idx){                   ans = min(ans, mid);                   r = mid - 1;               }else{                   l = mid + 1;               }           }           cout <<  !   << ans << endl;       }else{           int ans = 1, l = 1, r = idx - 1, mid;           while(l <= r){               mid = l + r >> 1;               int t = q(mid, idx);               if(t == idx){                   ans = max(ans, mid);                   l = mid + 1;               }else{                   r = mid - 1;               }           }           cout <<  !   << ans << endl;       }   }   // 5 1 2 3 4   int main(){       // #define LOCAL   #ifdef LOCAL       freopen( in.in ,  r , stdin);       freopen( out.out ,  w , stdout);   #endif         int _ = 1;       // cin >> _;       for(int i = 1; i <= _; ++i) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long int a[10000010];   int main() {     long long int n;     long long ans = 0;     cin >> n;     for (long long int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     ans = a[n - 1] * n;     long long int c = n;     for (long long int i = n - 2; i >= 0; i--) {       ans += (c * a[i]);       c--;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   int a[1100][1100], pt[1100], b[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}, ef, n;   map<string, int> m;   string st[1100];   int f(int aa, int bb) {     if (pt[aa] != pt[bb])       return pt[aa] > pt[bb];     else {       for (int i = 0; i < 60; i++)         if (a[aa][i] != a[bb][i]) return a[aa][i] > a[bb][i];       return 0;     }   }   int f2(int aa, int bb) {     if (a[aa][0] != a[bb][0])       return a[aa][0] > a[bb][0];     else       return f(aa, bb);   }   int main() {     int t;     cin >> t;     for (int ii = 0; ii < t; ii++) {       cin >> n;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         if (m.find(s) == m.end()) {           m[s] = ef++;           st[ef - 1] = s;         }         a[m[s]][i]++;         if (i <= 9) pt[m[s]] += b[i];       }     }     int r[1100];     for (int i = 0; i < m.size(); i++) r[i] = i;     sort(r, r + m.size(), f);     cout << st[r[0]] << endl;     sort(r, r + m.size(), f2);     cout << st[r[0]] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char st[500];     cin >> st;     int n = strlen(st);     int left = 0, right = 0, i = 0;     for (; i < n; ++i) {       if (st[i] ==  | )         break;       else         left++;     }     right = n - 1 - i;     char a[500];     cin >> a;     int x = strlen(a), av = x;     int he, ch = 0;     if (left > right) {       int diff = left - right;       if (diff <= x) {         right = left;         av = av - diff;         if (av % 2 == 0) {           for (int j = 0; j < av / 2; ++j) cout << a[j];           cout << st;           for (int j = av / 2; j < x; ++j) cout << a[j];         } else {           cout <<  Impossible n ;         }       } else {         cout <<  Impossible ;       }     } else if (right > left) {       int diff = right - left;       if (diff <= x) {         left = right;         av = av - diff;         if (av % 2 == 0) {           for (int j = 0; j < x - av / 2; ++j) cout << a[j];           cout << st;           for (int j = x - av / 2; j < x; ++j) cout << a[j];         } else {           cout <<  Impossible n ;         }       } else {         cout <<  Impossible ;       }     } else {       if (x % 2 == 0) {         for (int j = 0; j < x / 2; ++j) cout << a[j];         cout << st;         for (int j = x / 2; j < x; ++j) cout << a[j];       } else         cout <<  Impossible n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mo(const long long input, const long long ceil) {     return input >= ceil ? input % ceil : input;   }   const long long maxn = 5e5 + 10;   long long cnt, cnta, cntb;   long long vis[maxn];   vector<long long> e[maxn];   void dfs(long long k, long long t) {     vis[k] = t;     cnt++;     for (auto i : e[k])       if (vis[i] != t) dfs(i, t);   }   void solve(long long t) {     long long n, m, a, b;     cin >> n >> m >> a >> b;     for (long long i = 1; i <= n; i++) e[i].clear();     for (long long i = 1; i <= m; i++) {       long long x, y;       cin >> x >> y;       e[x].push_back(y);       e[y].push_back(x);     }     vis[a] = t * 2 - 1;     cnt = 1;     dfs(b, t * 2 - 1);     cnta = n - cnt;     vis[b] = t * 2;     cnt = 1;     dfs(a, t * 2);     cntb = n - cnt;     cout << cnta * cntb <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long tt = 1;     cin >> tt;     for (long long i = 1; i <= tt; i++) solve(i);     cerr <<   n n nTime :            << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC <<  ms n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long int __gcd(long long int a, long long int b);   void pdash(int n = 1);   int bitcount(long long int u);   long long int power(long long int x, long long int y);   long long int power(long long int x, long long int y, long long int z);   long long int modInverse(long long int n, long long int p);   long long int nCrF(long long int n, long long int r, long long int p);   void cordinate_compression(vector<int>& v);   void make_unique(vector<int>& vec);   const long long int mod = 1e9 + 7;   void solve() {     int n, q;     cin >> n >> q;     string str;     cin >> str;     vector<int> vec(n);     for (int i = 0; i < n; i++) {       vec[i] = (str[i] -  0 );     }     for (int i = 1; i < n; i++) {       vec[i] += vec[i - 1];     }     while (q--) {       int zero, one;       int a, b;       cin >> a >> b;       a--;       b--;       one = vec[b] - (((a - 1) >= 0) ? vec[a - 1] : 0);       zero = (b - a) + 1 - one;       cout << ((power(2, zero, mod) * ((power(2, one, mod) - 1 + mod) % mod)) %                mod)            <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }   inline long long int __gcd(long long int a, long long int b) {     if (a == 0 || b == 0) {       return max(a, b);     }     long long int tempa, tempb;     while (1) {       if (a % b == 0)         return b;       else {         tempa = a;         tempb = b;         a = tempb;         b = tempa % tempb;       }     }   }   void pdash(int n) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < 30; j++) {         cout <<  - ;       }       cout <<   n ;     }   }   long long int power(long long int x, long long int y) {     long long int result = 1;     while (y > 0) {       if (y & 1) {         result = (result * x);       }       y = y >> 1;       x = (x * x);     }     return result;   }   long long int power(long long int x, long long int y, long long int z) {     long long int result = 1;     x = x % z;     while (y > 0) {       if (y & 1) {         result = (result * x) % z;       }       y = y >> 1;       x = (x * x) % z;     }     return result;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p);   }   long long int nCrF(long long int n, long long int r, long long int p) {     if (r == 0) return 1;     long long int f[n + 1];     f[0] = 1;     for (long long int i = 1; i <= n; i++) f[i] = f[i - 1] * i % p;     return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p) % p;   }   void cordinate_compression(vector<int>& v) {     vector<int> p = v;     make_unique(p);     for (int i = 0; i < (int)((v).size()); i++)       v[i] = (int)(lower_bound(p.begin(), p.end(), v[i]) - p.begin());   }   void make_unique(vector<int>& vec) {     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());   }   int bitcount(long long int u) {     int cnt = 0;     while (u) {       u = u & (u - 1);       cnt++;     }     return cnt;   }


#include <bits/stdc++.h>   using namespace std;   const double INF = 1000000000;   struct point {     long long x, y;     point() {}     point(long long x, long long y) : x(x), y(y) {}     point operator-(point P) { return point(x - P.x, y - P.y); }   };   double abs(point P) { return sqrt(P.x * P.x + P.y * P.y); }   double dist(point P, point Q) { return abs(Q - P); }   long long dot(point P, point Q) { return P.x * Q.x + P.y * Q.y; }   long long cross(point P, point Q) { return P.x * Q.y - P.y * Q.x; }   int main() {     cout << fixed << setprecision(20);     int N, K;     cin >> N >> K;     K--;     vector<point> P(N);     for (int i = 0; i < N; i++) {       cin >> P[i].x >> P[i].y;     }     if (N == 3) {       int a = (K + 1) % 3;       int b = (K + 2) % 3;       cout << min(dist(P[K], P[a]), dist(P[K], P[b])) + dist(P[a], P[b]) << endl;     } else {       mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());       int p;       int x;       point D;       while (true) {         int a = mt() % N;         int b = mt() % N;         int c = mt() % N;         if (a != b && b != c && c != a) {           if (cross(P[b] - P[a], P[c] - P[a]) == 0) {             x = a;             D = P[b] - P[a];             for (int i = 0; i < N; i++) {               if (cross(P[i] - P[a], D) != 0) {                 p = i;               }             }             break;           }         }       }       vector<pair<long long, int>> L;       for (int i = 0; i < N; i++) {         if (i != p) {           L.push_back(make_pair(dot(P[i] - P[x], D), i));         }       }       sort(L.begin(), L.end());       vector<point> Q(N - 1);       for (int i = 0; i < N - 1; i++) {         Q[i] = P[L[i].second];       }       if (p == K) {         cout << min(dist(P[K], Q[0]), dist(P[K], Q[N - 2])) + dist(Q[0], Q[N - 2])              << endl;       } else {         int s;         for (int i = 0; i < N - 1; i++) {           if (L[i].second == K) {             s = i;           }         }         double ans = INF;         ans = min(ans,                   dist(Q[s], Q[0]) + dist(Q[0], Q[N - 2]) + dist(Q[N - 2], P[p]));         ans = min(ans,                   dist(Q[s], Q[N - 2]) + dist(Q[N - 2], Q[0]) + dist(Q[0], P[p]));         for (int i = s; i < N - 2; i++) {           double d11 = dist(Q[s], Q[i]) + dist(Q[i], Q[0]) + dist(Q[0], P[p]);           double d12 = dist(Q[s], Q[0]) + dist(Q[0], Q[i]) + dist(Q[i], P[p]);           double d1 = min(d11, d12);           double d2 = min(dist(P[p], Q[i + 1]), dist(P[p], Q[N - 2])) +                       dist(Q[i + 1], Q[N - 2]);           ans = min(ans, d1 + d2);         }         for (int i = 1; i <= s; i++) {           double d11 =               dist(Q[s], Q[i]) + dist(Q[i], Q[N - 2]) + dist(Q[N - 2], P[p]);           double d12 =               dist(Q[s], Q[N - 2]) + dist(Q[N - 2], Q[i]) + dist(Q[i], P[p]);           double d1 = min(d11, d12);           double d2 =               min(dist(P[p], Q[i - 1]), dist(P[p], Q[0])) + dist(Q[i - 1], Q[0]);           ans = min(ans, d1 + d2);         }         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   const int Z = 100;   const int N = Z * Z;   const int M = Z * Z * Z;   int px[N], py[N];   int head[N], to[M], ct[M], w[M], nt[M];   int d[N], vis[N];   int pre[N], id[N];   int s, t, tot;   void add(int u, int v, int flow, int cost) {     to[tot] = v;     ct[tot] = cost;     w[tot] = flow;     nt[tot] = head[u];     head[u] = tot++;     to[tot] = u;     ct[tot] = -cost;     w[tot] = 0;     nt[tot] = head[v];     head[v] = tot++;   }   void init() {     memset(head, -1, sizeof(head));     tot = 0;   }   int spfa(int s, int t) {     queue<int> q;     memset(d, inf, sizeof(d));     memset(vis, 0, sizeof(vis));     memset(pre, -1, sizeof(pre));     d[s] = 0;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       vis[u] = 0;       for (int i = head[u]; ~i; i = nt[i]) {         if (w[i] > 0 && d[to[i]] > d[u] + ct[i]) {           d[to[i]] = d[u] + ct[i];           pre[to[i]] = u;           id[to[i]] = i;           if (!vis[to[i]]) {             vis[to[i]] = 1;             q.push(to[i]);           }         }       }     }     return d[t] < inf;   }   int MaxFlow(int s, int t) {     int Mi = inf;     int sum = 0;     int tt = 0;     while (spfa(s, t)) {       Mi = inf;       for (int i = t; i != s; i = pre[i]) Mi = min(Mi, w[id[i]]);       for (int i = t; i != s; i = pre[i]) {         w[id[i]] -= Mi;         w[id[i] ^ 1] += Mi;       }       tt += Mi;       sum += d[t] * Mi;     }     return sum;   }   int main() {     init();     int n, m, k, c, d;     scanf( %d%d%d%d%d , &n, &m, &k, &c, &d);     int s = 0, t = n * 100 + 1;     for (int i = 1; i <= 100; ++i) add(i, t, 100, 0);     for (int i = 1, v; i <= k; ++i) {       scanf( %d , &v);       add(s, (v - 1) * 100 + 1, 1, 0);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j < 100; ++j) {         add((i - 1) * 100 + j, (i - 1) * 100 + j + 1, 100, c);       }     }     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       for (int j = 1; j < 100; ++j) {         int idx = (u - 1) * 100 + j;         int idy = (v - 1) * 100 + j + 1;         for (int k = 1; k <= 20; ++k) {           add(idx, idy, 1, c + (k * k - (k - 1) * (k - 1)) * d);         }       }       for (int j = 1; j < 100; ++j) {         int idx = (v - 1) * 100 + j;         int idy = (u - 1) * 100 + j + 1;         for (int k = 1; k <= 20; ++k) {           add(idx, idy, 1, c + (k * k - (k - 1) * (k - 1)) * d);         }       }     }     printf( %d n , MaxFlow(s, t));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int odd_a = 0, odd_b = 0, even_a = 0, even_b = 0;     int a, b, c;     cin >> a >> b;     for (int i = 0; i < a; i++) {       cin >> c;       c % 2 ? odd_a++ : even_a++;     }     for (int i = 0; i < b; i++) {       cin >> c;       c % 2 ? odd_b++ : even_b++;     }     int ans = 0;     ans += min(odd_a, even_b);     ans += min(even_a, odd_b);     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int const N = 1e5 + 86;   int const M = 1e9 + 7;   int a[N], f[111][N];   ll ext_gcd(ll a, ll b, ll &x, ll &y) {     if (!b) {       x = 1, y = 0;       return a;     }     ll ret = ext_gcd(b, a % b, x, y);     ll t = x;     x = y, y = t - a / b * y;     return ret;   }   ll mod_inv(ll a, ll n) {     ll x, y;     ext_gcd(a, n, x, y);     x %= n;     if (x < 0) x += n;     return x;   }   void add(int &x, int y) {     x += y;     if (x >= M) x -= M;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     for (int l, r, k; m--;) {       scanf( %d%d%d , &l, &r, &k), --l, --r;       add(f[k][l], 1), add(f[k][r + 1], M - 1);       ll c = 1, m = r - l + 1;       for (int i = 1; i <= k; ++i, ++m) {         c = c * m % M;         c = c * mod_inv(i, M) % M;         add(f[k - i][r + 1], M - c);       }     }     for (int i = 100; i >= 0; --i) {       for (int j = 1; j < n; ++j) add(f[i][j], f[i][j - 1]);       for (int j = 0; i && j < n; ++j) add(f[i - 1][j], f[i][j]);     }     for (int i = 0; i < n; ++i) add(a[i], f[0][i]);     for (int i = 0; i < n; ++i) printf( %d%s , a[i], i == n - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a1[200005];   long long int a2[29];   vector<long long int> v, v1;   bool p[100000008];   void seive() {     long long int i, j;     for (i = 1; i * i <= 100; i++) {       if (p[i] == false) {         for (j = i * i; j <= 100; j += i) {           p[j] = true;         }       }     }     v.push_back(2);     for (i = 3; i <= 100; i += 2) {       if (p[i] == false) {         v.push_back(i);         cout << i << endl;       }     }   }   int main() {     long long int n, d = 0, k = 0, c = 0, x = 0, i = 0, m, f = 0, j = 0, j1,                      sum = 0, s = 0, mx = 100000000000000000;     cin >> n;     while (n--) {       cin >> m;       k = 1;       sum = 0;       for (i = 3; i <= m; i += 2) {         d = (i * 2) + (i - 2) * 2;         sum += (d * k);         k++;       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long r = 0, t = 1, c = getchar();     while (c <  0  || c >  9 ) {       t = c ==  -  ? -1 : 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       r = r * 10 + c - 48;       c = getchar();     }     return r * t;   }   const int N = 6010, mod = 998244353;   long long n, m, ans, r;   vector<pair<long long, long long> > c, a[N], b[N];   set<pair<long long, long long> > s;   void insert(set<pair<long long, long long> > &s, pair<long long, long long> a) {     auto it = s.upper_bound(pair<long long, long long>(a.first, (~0ull) >> 1));     if (it != s.begin()) {       it--;       if (it->first <= a.first && it->second >= a.second) return;     }     it = s.lower_bound(pair<long long, long long>(a.first, 0));     while (it != s.end() && a.first <= it->first && a.second >= it->second)       it = s.erase(it);     s.insert(a);     assert(s.size() <= 200000);   }   int main() {     n = read();     for (int i = (1), end_i = (n); i <= end_i; i++) {       long long l = read(), r = read();       while (r - l >= (l & (-l)) - 1) {         a[i].push_back(pair<long long, long long>(l, l + (l & (-l)) - 1));         l += l & (-l);       }       for (int j = (60), end_j = (0); j >= end_j; j--)         if (r - l + 1 >= (1ll << j)) {           a[i].push_back(pair<long long, long long>(l, l + (1ll << j) - 1));           l += (1ll << j);         }     }     m = read();     for (int i = (1), end_i = (m); i <= end_i; i++) {       long long l = read(), r = read();       while (l + (l & (-l)) - 1 <= r) {         b[i].push_back(pair<long long, long long>(l, l + (l & (-l)) - 1));         l += l & (-l);       }       for (int j = (60), end_j = (0); j >= end_j; j--)         if (r - l + 1 >= (1ll << j)) {           b[i].push_back(pair<long long, long long>(l, l + (1ll << j) - 1));           l += (1ll << j);         }     }     for (int i = (1), end_i = (n); i <= end_i; i++)       for (int j = (1), end_j = (m); j <= end_j; j++) {         s.clear();         for (auto A : a[i])           for (auto B : b[j]) {             long long w = max(A.second - A.first, B.second - B.first);             insert(s, pair<long long, long long>((A.first ^ B.first) & (~w),                                                  (A.first ^ B.first) | w));           }         for (auto S : s) c.push_back(S);       }     sort(c.begin(), c.end(),          [](pair<long long, long long> a, pair<long long, long long> b) {            return a.first == b.first ? a.second > b.second : a.first < b.first;          });     for (auto C : c)       if (C.second > r) {         ans = (ans + ((C.second - C.first + 1) % mod) *                          ((C.first + C.second) % mod) % mod * ((mod + 1) / 2)) %               mod;         r = C.second;       }     printf( %d n , (int)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int mod = 1e9 + 7;   const long long inf = 1e18;   const double PI = acos(-1);   const double eps = 1e-8;   long long qkmod(long long base, long long cnt) {     long long res = 1;     while (cnt) {       if (cnt & 1) res = res * base % mod;       base = base * base % mod;       cnt >>= 1;     }     return res;   }   int a[maxn];   int main() {     int T;     scanf( %d , &T);     int n, p;     while (T--) {       scanf( %d %d , &n, &p);       for (int i = 0; i < n; i++) cin >> a[i];       if (p == 1) {         printf(n & 1 ?  1 n  :  0 n );         continue;       }       sort(a, a + n);       long long res = 0, sum = 0, pre = 1e6 + 7;       bool flag = false;       int i = n - 1, j = n - 1;       while (~i) {         int k = a[i--];         int d = pre - k;         pre = k;         res = res * qkmod(p, d) % mod;         for (int i = 0; i < min(20, d); i++) {           sum *= p;           if (sum > maxn) flag = true;         }         while (~j && a[j] == k) {           j--;           if (flag || sum > 0) {             sum--;             res += mod - 1;           } else {             sum++;             res++;           }         }         res %= mod;       }       printf( %d n , (res * qkmod(p, pre)) % mod);     }   }


#include <bits/stdc++.h>   int main() {     int t = 0, i, n;     char str[60];     scanf( %d , &n);     scanf( %s , &str);     for (i = 1; t < n; i = i + 1) {       printf( %c , str[t]);       t += i;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   vector<int> edge[1005];   pair<int, int> ans[1005];   set<int> eQQ;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, a, b;     cin >> n;     for (int i = 1; i < n; ++i) {       cin >> a >> b;       if (b != n) return cout <<  NO n , 0;       edge[a].push_back(i);     }     for (int i = n - 1; i > 0; --i)       if (edge[i].empty()) eQQ.insert(i);     for (int i = n - 1, l; i >= 0; --i) {       l = n;       for (auto x : edge[i])         if (x == edge[i].back())           ans[x] = make_pair(l, i);         else {           auto p = eQQ.lower_bound(i);           if (p == eQQ.begin())             return cout <<  NO n , 0;           else             --p, ans[x] = make_pair(l, *p), l = *p, eQQ.erase(p);         }     }     cout <<  YES n ;     for (int i = 1; i < n; ++i)       cout << ans[i].first <<     << ans[i].second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100 * 100 + 5];   pair<int, int> as[100 * 10000 + 5];   pair<int, int> ass[100 * 1000 * 7 + 5];   int p = 0;   int badbakhti(int l, int r) {     if (r - l < 2) {       return 1;     }     int h = -10000 * 100000, e = (r + l) / 2;     h = a[e].first;     for (int i = l; i < r; i++) {       if (i != e) {         as[p].first = a[e].first;         as[p].second = a[i].second;         p++;       }     }     badbakhti(l, e);     badbakhti(e, r);     return 1;   }   int main() {     int n;     cin >> n;     int d, q;     for (int i = 0; i < n; i++) {       cin >> d >> q;       a[i] = make_pair(d, q);       as[p] = make_pair(d, q);       p++;     }     sort(a, a + n);     badbakhti(0, n);     sort(as, as + p);     int u = 0, er = 0;     for (int i = 0; i < p; i++) {       u = i;       while (as[i].first == as[u].first && as[i].second == as[u].second) u++;       ass[er].first = as[i].first;       ass[er].second = as[i].second;       er++;       i = u - 1;     }     cout << er << endl;     for (int i = 0; i < er; i++) {       cout << ass[i].first <<     << ass[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   const int M = 1001000;   const int P = 1000000007;   int fac[M], phi[M];   vector<int> prime;   long long val[M], sum[M], res[M];   long long ans[M], vec[M], rec[M];   void init_() {     fac[1] = 1;     for (int i = 2; i <= N; i++) {       if (!fac[i]) {         fac[i] = i;         prime.push_back(i);       }       for (int j = 0; j <= (int)prime.size() - 1; j++) {         int p = prime[j];         if (p * i > N) break;         fac[p * i] = p;         if (fac[i] == p) break;       }     }     phi[1] = 1;     for (int i = 2; i <= N; i++) {       int p = fac[i];       int j = i / p;       int p_ = fac[j];       if (p == p_)         phi[i] = phi[j] * p;       else         phi[i] = phi[j] * (p - 1);     }     for (int i = 1; i <= N; i++) val[i] = (val[i - 1] + i) % P;     for (int i = 1; i <= N; i++) sum[i] = (sum[i - 1] + (long long)i * i) % P;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N / i; j++) (res[i * j] += (long long)i * phi[j]) %= P;     for (int i = 1; i <= N; i++)       ans[i] =           (sum[i] + sum[i - 1] + 2 * (2 * P - val[i] - val[i - 1] + res[i])) % P;     for (int i = 1; i <= N; i++) vec[i] = (vec[i - 1] + ans[i] * i) % P;     for (int i = 1; i <= N; i++) rec[i] = (rec[i - 1] + ans[i] * i % P * i) % P;     for (int i = 1; i <= N; i++) ans[i] = (ans[i - 1] + ans[i]) % P;   }   int main() {     init_();     int _;     cin >> _;     while (_--) {       int n, m;       scanf( %d%d , &n, &m);       if (n > m) swap(n, m);       n++, m++;       int o = (ans[n] * n % P * m % P - (n + m) * vec[n] % P + rec[n] + P) % P;       printf( %d n , o);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e6 + 3;   int nxt[mxN], vis[mxN];   void get(string s) {     nxt[0] = -1;     int i = 0, k = -1, len = s.size();     while (i < len) {       if (k == -1 or s[i] == s[k])         nxt[++i] = ++k;       else         k = nxt[k];     }   }   int main() {     int t;     int n, m, i, j, c, a, b, k, cn = 0, sm = 0, mx = INT_MIN, mn = INT_MAX;     string s, ss, sr;     bool f = false, ff = true;     cin >> s;     get(s);     nxt[0] = 0;     n = nxt[s.size()];     for (i = 0; i < s.size(); i++) vis[nxt[i]] = 1;     while (n) {       if (vis[n]) break;       n = nxt[n];     }     if (!n)       return cout <<  Just a legend                    <<   n ,              0;     for (i = 0; i < n; i++) cout << s[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[10] = {};   int fac[13] = {1};   inline void p(vector<int> q, vector<int> w, int cnt, long long pr) {     if (q.size() == 0) {       a[cnt] += pr;       return;     }     int qq = q[q.size() - 1], ww = w[w.size() - 1];     q.pop_back();     w.pop_back();     p(q, w, cnt, pr * qq);     p(q, w, cnt + 1, pr * ww);   }   inline int c(int a, int b) { return fac[a] / fac[b] / fac[a - b]; }   inline int cal(int r, int n) {     if (r <= 0) return 0;     if (n == 6) return 1;     long long ret = 0;     for (int i = 0; i < r; ++i) {       if (a[i] <= 0) continue;       --a[i];       ret = (ret + cal(r - i, n + 1) * (a[i] + 1)) % 1000000007;       ++a[i];     }     return ret;   }   int main() {     char m[11];     int cnt = 0, t = 1;     long long ans = 0, tmp = 1;     vector<int> q, w;     for (int i = 1; i < 13; ++i) fac[i] = fac[i - 1] * i;     scanf( %s , m);     for (int i = 0; i < strlen(m); ++i) {       if (m[i] ==  0 ) continue;       q.clear();       w.clear();       t = 1;       if (m[i] <=  4 )         t = m[i] -  0 ;       else if (m[i] <=  7 ) {         q.push_back(m[i] -  0  - 1);         w.push_back(1);       } else {         q.push_back(m[i] -  0  - 2);         w.push_back(2);       }       for (int j = i + 1; j < strlen(m); ++j) {         q.push_back(8);         w.push_back(2);       }       p(q, w, cnt, t);       if (m[i] ==  4  || m[i] ==  7 ) ++cnt;     }     ++a[cnt];     --a[0];     for (int i = 1; i < 10 && a[i] > 0; ++i) {       --a[i];       ans = (ans + (long long)cal(i, 0) * (a[i] + 1)) % 1000000007;       ++a[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     string s;     cin >> s;     long long n = s.length();     map<char, long long> m;     m[ B ] = 1;     m[ u ] = 1;     m[ l ] = 1;     m[ b ] = 1;     m[ a ] = 1;     m[ s ] = 1;     m[ r ] = 1;     for (long long i = 0; i < n; i++) {       if (m[s[i]] > 0) {         m[s[i]]++;       }     }     long long c1 = min(m[ u ] - 1, m[ a ] - 1);     long long c11 = min(m[ B ] - 1, m[ b ] - 1);     long long c22 = min(m[ l ] - 1, m[ r ] - 1);     c22 = min(m[ s ] - 1, c22);     long long c3 = min(c11, c22);     long long num1 = c1 / 2;     long long num2 = c3;     cout << min(num1, num2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int a[N];   struct Block {     int len, st, ed, num;     Block(const int len = 0, const int st = 0, const int ed = 0,           const int num = 0)         : len(len), st(st), ed(ed), num(num){};   };   vector<Block> v;   bool islucky(int a) {     bool ret = true;     while (a && ret) {       ret = a % 10 == 4 || a % 10 == 7;       a /= 10;     }     return ret;   }   struct Node {     int l, r;     Node *left, *right;     Node(const int l = 0, const int r = 0)         : l(l), r(r), left(NULL), right(NULL) {}   };   unsigned long long cal(const unsigned long long l, const unsigned long long r) {     return (r - l) * (r - l + 1) / 2;   }   unsigned long long cal3(const unsigned long long n) {     return n * (n + 1) / 2 * n * (n + 1) / 2;   }   unsigned long long cal3(const unsigned long long l,                           const unsigned long long r) {     return (r * (r + 1) / 2 + (l - 1) * l / 2) *            (r * (r + 1) / 2 - (l - 1) * l / 2);   }   unsigned long long cal2(const unsigned long long n) {     return n * (2 * n + 1) * (n + 1) / 6;   }   unsigned long long cal2(const unsigned long long l,                           const unsigned long long r) {     return cal2(r) - cal2(l - 1);   }   unsigned long long cal1(const unsigned long long l,                           const unsigned long long r) {     return (r + l) * (r - l + 1) / 2;   }   unsigned long long cal0(const unsigned long long l,                           const unsigned long long r) {     return r - l + 1;   }   int main() {     unsigned long long n;     cin >> n;     int last = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       if (islucky(a[i])) {         v.push_back(Block(i - last + 1, last, i, a[i]));         last = i + 1;       }     }     a[n] = -1;     if (last != n) {       v.push_back(Block(n - last, last, n, -1));     }     map<int, vector<int> > tr;     for (int i = 0; i < (int)v.size(); ++i) {       tr[v[i].num].push_back(v[i].ed);     }     unsigned long long ans = 0;     for (int i = 0; i < v.size(); ++i) {       unsigned long long bpSum = 0;       set<int> bp;       set<int> contain;       unsigned long long tmp = 0;       tmp = 1 * cal3(v[i].st, v[i].ed - 1);       tmp += (n * (n - 1) + n * (v[i].st - 1) + (n - 1) * (v[i].st - 1)) *              cal1(v[i].st, v[i].ed - 1);       tmp -= (n + n - 1 + (v[i].st - 1)) * cal2(v[i].st, v[i].ed - 1);       tmp -= (v[i].st - 1) * n * (n - 1) * cal0(v[i].st, v[i].ed - 1);       ans += tmp / 2;       bp.insert(n);       bp.insert(v[i].ed - 1);       bpSum = cal(v[i].ed, n);       for (int j = i; j + 1 < (int)v.size(); ++j) {         int bar = v[j + 1].ed;         while (*bp.begin() < bar) {           bpSum -= cal(*bp.begin() + 1, *(++bp.begin()));           bp.erase(bp.begin());         }         bp.insert(bar - 1);         bpSum += cal(*bp.begin() + 1, *(++bp.begin()));         if (!contain.count(v[j].num)) {           contain.insert(v[j].num);           vector<int> breaks = tr[v[j].num];           for (int k = 0; k < breaks.size(); ++k) {             if (breaks[k] >= v[j + 1].ed) {               int cut = breaks[k];               set<int>::iterator it = bp.upper_bound(cut);               int right = *it, left = *(--it);               bpSum -= cal(left + 1, right);               bp.insert(cut);               bpSum += cal(left + 1, cut) + cal(cut + 1, right);             }           }         }         unsigned long long k, tmp1, rem = bpSum;         k = *(++bp.begin());         rem *= (v[j + 1].ed - v[j].ed);         tmp1 = 1 * cal2(v[j].ed, v[j + 1].ed - 1) +                (2 * k - v[j + 1].ed) * (v[j + 1].ed - 1) *                    cal0(v[j].ed, v[j + 1].ed - 1) -                (2 * k - v[j + 1].ed + v[j + 1].ed - 1) *                    cal1(v[j].ed, v[j + 1].ed - 1);         ans += v[i].len * (rem + tmp1 / 2);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, pair<long long, long long>>> v;   long long a, b, w, cnt;   long long parent[100005], sz[100005];   void init(long long n) {     for (long long i = 1; i <= n; i++) parent[i] = i, sz[i] = 1;   }   long long root(long long x) {     if (parent[x] == x) return x;     return parent[x] = root(parent[x]);   }   long long mst(long long n, long long k) {     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long x = v[i].second.first, y = v[i].second.second, z = v[i].first;       if (x == a && y == b) continue;       long long px = root(x), py = root(y);       if (px != py) {         if (sz[px] < sz[py]) swap(px, py);         ans += z;         sz[px] += sz[py];         parent[py] = px;         cnt++;       }     }     if (cnt != k) return -1;     return ans;   }   int main() {     long long t, n, i, j, m, ans = 0;     cin >> n >> m;     for (i = 1; i <= m; i++) {       long long x, y, z;       cin >> x >> y >> z;       if (x > y) swap(x, y);       v.push_back({z, {x, y}});     }     a = v[0].second.first, b = v[0].second.second, w = v[0].first;     sort(v.begin(), v.end());     init(n);     cnt = 2;     sz[a] = 2;     parent[b] = a;     long long ans1 = w + mst(m, n);     init(n);     cnt = 1;     long long ans2 = mst(m, n);     if (ans2 >= 0)       cout << w - (ans1 - ans2);     else       cout << 1000000000;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000001;   int n;   int l[MAXN];   int r[MAXN];   int num[MAXN];   int izq[MAXN];   int der[MAXN];   long long int ans[MAXN];   long long int bit[2][MAXN];   vector<pair<int, int> > L[MAXN];   vector<pair<int, int> > R[MAXN];   void update(int id, int a, int v) {     while (a <= n) {       bit[id][a] += v;       a += a & -a;     }   }   void update_range(int a, int b, int v) {     a++, b++;     update(0, a, v);     update(0, b + 1, -v);     update(1, a, v * (a - 1));     update(1, b + 1, -v * b);   }   long long int query(int id, int a) {     long long int ans = 0;     while (a > 0) {       ans += bit[id][a];       a -= a & -a;     }     return ans;   }   long long int query(int b) { return query(0, b) * b - query(1, b); }   long long int query_range(int a, int b) {     if (a > b) return 0ll;     a++, b++;     return query(b) - query(a - 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> n >> q;     vector<pair<int, int> > A;     for (int i = 0; i < n; ++i) {       cin >> num[i];       A.emplace_back(num[i], i);     }     sort(A.begin(), A.end());     reverse(A.begin(), A.end());     set<int> s;     s.insert(-1);     s.insert(n);     for (int i = 0; i < n; ++i) {       auto it = s.lower_bound(A[i].second);       der[A[i].second] = *it;       it--;       izq[A[i].second] = *it;       s.insert(A[i].second);     }     for (int i = 0; i < q; ++i) cin >> l[i];     for (int i = 0; i < q; ++i) cin >> r[i];     for (int i = 0; i < q; ++i) {       l[i]--, r[i]--;       L[l[i]].emplace_back(r[i], i);       R[r[i] + 1].emplace_back(l[i], i);     }     for (int i = n - 1; i >= 0; i--) {       update_range(izq[i] + 1, der[i] - 1, 1);       for (int j = 0; j < R[i].size(); ++j)         ans[R[i][j].second] -= query_range(R[i][j].first, i - 1);       for (int j = 0; j < L[i].size(); ++j)         ans[L[i][j].second] += query_range(i, L[i][j].first);     }     for (int i = 0; i < q; ++i) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include<bits/stdc++.h>   #define LL long long   #define SZ(x) (int)x.size()-1   #define F(i,a,b) for (int i=a;i<=b;++i)   #define DF(i,a,b) for (int i=a;i>=b;--i)   #define pb push_back   #define ms(a,b) memset(a,b,sizeof a)   using namespace std;   int read(){       char ch=getchar(); int w=1,c=0;       for (;!isdigit(ch);ch=getchar()) if (ch== - ) w=-1;       for (;isdigit(ch);ch=getchar()) c=(c<<3)+(c<<1)+(ch^48);       return w*c;   }   const int M=2e4+10;   int n,a[M],m;   #define lowbit(x) (x&-x)   #define pii pair<int,int>   #define mp make_pair   pii d[M];   void add(int x,pii y){    for (;x<=n;x+=lowbit(x)) d[x]=max(d[x],y);   }   pii qry(int x){    pii ret=mp(0,0);    for (;x;x-=lowbit(x)) ret=max(ret,d[x]);    return ret;   }   pii f[15][M][33];   int g[15][M][33],b[M],tw[33],ted[33];   pii nw[33];   int main(){    n=read(); m=read();    F(i,1,n) a[i]=read(),b[i]=min(a[i]+i,n);    DF(i,n,1){     F(j,0,30) g[0][i][j]=min(n,b[i]+j);      add(i,mp(b[i],i));     f[0][i][0]=qry(b[i]);     int tmp=f[0][i][0].second;     F(j,1,30){      f[0][i][j]=max(f[0][i][j-1],mp(b[min(b[i]+j,n)],min(b[i]+j,n)));     }    }    F(t,1,14){     F(i,1,n){      F(j,0,30){       F(jj,0,j){        int ps=f[t-1][i][jj].second;        f[t][i][j]=max(f[t][i][j],f[t-1][ps][j-jj]);        g[t][i][j]=max(g[t][i][j],g[t-1][ps][j-jj]);       }      }     }    }    F(T,1,m){     int l=read(),r=read(),k=read();     if (l==r){      cout<<0<<  n ;      continue;     }     F(i,0,k) nw[i]=mp(b[l],l);     int ans=1e9,cur=0;     DF(i,14,0){      F(j,0,k) tw[j]=nw[j].second,ted[j]=0;      F(j,0,k){       F(jj,0,j){        ted[j]=max(ted[j],g[i][tw[jj]][j-jj]);        }       }      int mx=0;      F(j,0,k) mx=max(mx,ted[j]);      if (mx>=r){       ans=min(ans,cur|(1<<i));      }      else{       F(j,0,k){        F(jj,0,j){         nw[j]=max(nw[j],f[i][tw[jj]][j-jj]);         }        }       cur|=(1<<i);      }     }     cout<<ans<<  n ;    }       return 0;   }   /*   100 1   4 6 5 1 6 6 6 5 3 6 4 4 2 1 6 4 2 1 2 1 4 6 6 5 4 5 5 4 4 5 5 4 1 2 3 1 3 5 4 4 5 3 6 5 5 1 4 4 1 5 5 4 5 1 1 5 3 4 4 2 6 6 4 4 5 2 6 6 2 3 1 6 3 4 4 1 2 1 2 2 3 4 1 3 3 4 6 3 2 5 6 6 6 6 4 6 3 2 1 5   19 84 14   */


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e8 + 5e4 + 1;   const double error = 1e-7;   const double PI = acos(-1);   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   inline long long int MOD(long long int x, long long int m = mod) {     long long int y = x % m;     return (y >= 0) ? y : y + m;   }   const int inf = 0x3f3f3f3f;   const unsigned long long int infl = 1e18 + 1;   const int nmax = 2e3 + 5;   typedef long long int T;   bool lexcomp(const complex<T> &p, const complex<T> &q) {     return make_pair(p.real(), p.imag()) < make_pair(q.real(), q.imag());   }   complex<T> origin, ray;   inline bool half(complex<T> p) {     return ((conj(ray) * (p)).imag()) < 0 ||            (((conj(ray) * (p)).imag()) == 0 && ((conj(ray) * (p)).real()) > 0);   }   bool polarComp(complex<T> p, complex<T> q) {     p -= origin;     q -= origin;     return make_tuple(half(p), 0) < make_tuple(half(q), ((conj(p) * (q)).imag()));   }   vector<complex<T> > points;   vector<int> ans;   vector<int> input;   char str[nmax];   int main() {     int n;     cin >> n;     points.resize(n + 1);     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       points[i] = complex<T>(x, y);       input.push_back(i);     }     cin >> str;     int pid =         min_element(input.begin(), input.end(),                     [&](int i, int j) { return lexcomp(points[i], points[j]); }) -         input.begin();     ans.push_back(input[pid]);     origin = points[input[pid]];     ray = complex<T>(0, -1);     input.erase(input.begin() + pid);     for (int i = 0; i < n - 2; i++) {       if (str[i] ==  L )         pid = min_element(                   input.begin(), input.end(),                   [&](int i, int j) { return polarComp(points[i], points[j]); }) -               input.begin();       else         pid = max_element(                   input.begin(), input.end(),                   [&](int i, int j) { return polarComp(points[i], points[j]); }) -               input.begin();       ray = -points[ans.back()] + points[input[pid]];       ans.push_back(input[pid]);       origin = points[input[pid]];       input.erase(input.begin() + pid);     }     ans.push_back(input[0]);     for (int x : ans) cout << x <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> arr;   int main() {     cin >> N;     for (int i = 0; i < N; i++) {       int num;       cin >> num;       arr.push_back(num);     }     vector<int> cur(1000, 0);     int toto = 0;     for (int i = 0; i < N; i++) {       int zoto = toto;       for (int k = 0; k < cur.size(); k++) {         zoto -= cur[k];         int remo = (arr[i] - zoto) / 9 + ((arr[i] - zoto) % 9 ? 1 : 0);         if (arr[i] - zoto < 0) {           continue;         }         if (k < remo - 1 || cur[k] == 9)           continue;         else if (k == remo - 1) {           int montar = (arr[i] - zoto) % 9;           if (montar == 0) montar = 9;           if (zoto + montar + 9 * k > arr[i]) continue;           montar = max(montar, cur[k] + 1);           if (zoto + montar > arr[i]) continue;           toto -= cur[k];           cur[k] = montar;           toto += cur[k];         } else {           if (zoto + cur[k] + 1 > arr[i]) continue;           cur[k]++;           toto++;         }         int remy = arr[i] - (zoto + cur[k]);         for (int hu = 0; hu < k; hu++) {           if (remy >= 9) {             toto -= cur[hu];             cur[hu] = 9;             toto += cur[hu];             remy -= cur[hu];           } else if (remy >= 0) {             toto -= cur[hu];             cur[hu] = remy;             toto += cur[hu];             remy -= cur[hu];           } else             break;         }         break;       }       int maxx = 0;       for (int x = 0; x < cur.size(); x++) {         if (cur[x] != 0) maxx = x;       }       for (int x = maxx; x >= 0; x--) {         cout << cur[x];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int he[100005], np;   int n;   long long v[100005], f2[100005], fl[100005], ms[100005];   long long h[100005], g[100005];   int read() {     int x = 0;     char ch;     ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   struct edg {     int to, nxt;   } e[200005];   void ad(int x, int y) {     np++;     e[np].to = y;     e[np].nxt = he[x];     he[x] = np;   }   void dfs(int x, int fa) {     f2[x] = fl[x] = ms[x] = g[x] = v[x];     for (int i = he[x]; i; i = e[i].nxt) {       int y = e[i].to;       if (y == fa) continue;       dfs(y, x);       f2[x] = max(f2[x], f2[y]);       f2[x] = max(f2[x], g[x] + ms[y]);       f2[x] = max(f2[x], ms[x] + g[y]);       f2[x] = max(f2[x], fl[x] + fl[y]);       fl[x] = max(fl[x], ms[x] + ms[y]);       fl[x] = max(fl[x], fl[y]);       g[x] = max(g[x], v[x] + g[y]);       g[x] = max(g[x], ms[y] + v[x] + h[x]);       g[x] = max(g[x], ms[x] + fl[y]);       h[x] = max(h[x], fl[y]);       ms[x] = max(ms[x], v[x] + ms[y]);     }   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       v[i] = read();     }     for (int i = 1; i <= n - 1; i++) {       int x = read(), y = read();       ad(x, y);       ad(y, x);     }     dfs(1, 0);     cout << f2[1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 400010;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   void print(long long x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   long long n, k;   long long a[N];   void MS(long long l, long long r) {     if (!k || r - l <= 1) return;     long long mid = (l + r >> 1);     k -= 2, swap(a[mid - 1], a[mid]);     MS(l, mid), MS(mid, r);   }   signed main() {     n = read(), k = read();     for (register long long i = 0; i < n; i++) a[i] = i;     if (!(k & 1ll)) {       puts( -1 );       return 0;     }     if (k == 1) {       for (register long long i = 1; i <= n; i++) printf( %lld  , i);       puts(  );       return 0;     }     k--;     MS(0, n);     if (!k) {       for (register long long i = 0; i < n; i++) printf( %lld  , a[i] + 1);       puts(  );     } else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long b, d, s, x, y, z, m, t;     x = y = z = 0;     cin >> b >> d >> s;     long long a[3] = {b, d, s};     sort(a, a + 3);     if (a[0] == a[2]) {       cout << 0;     } else if (a[1] == a[2]) {       cout << a[2] - a[0] - 1;     } else {       cout << 2 * a[2] - a[0] - a[1] - 2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l, r;     cin >> l >> r;     while (l % 2) l++;     if (l + 2 > r)       cout << -1 << endl;     else       cout << l <<     << l + 1 <<     << l + 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   int n, k;   vector<vector<long long> > mul(vector<vector<long long> > &A,                                  vector<vector<long long> > &B) {     vector<vector<long long> > C(1, vector<long long>(n));     for (int i = 0; i < n; ++i) {       for (int k = 0; k <= i; ++k) {         C[0][i] = (C[0][i] + A[0][k] * B[0][i - k]) % M;       }     }     return C;   }   vector<vector<long long> > pow(vector<vector<long long> > A, int k) {     vector<vector<long long> > B(1, vector<long long>(n));     B[0][0] = 1;     while (k > 0) {       if (k & 1) B = mul(B, A);       A = mul(A, A);       k >>= 1;     }     return B;   }   void solve() {     vector<vector<long long> > f(1, vector<long long>(n));     for (int i = 0; i < n; ++i) {       f[0][i] = 1;     }     f = pow(f, k);     vector<vector<long long> > A(1, vector<long long>(n));     for (int i = 0; i < n; ++i) cin >> A[0][i];     cout << A[0][0];     for (int i = 1; i < n; ++i) {       long long tmp = 0;       for (int j = 0; j <= i; ++j) {         tmp = (tmp + A[0][j] * f[0][i - j]) % M;       }       cout <<     << tmp;     }   }   int main() {     scanf( %d%d , &n, &k);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   int n, m, u, f[3100][3100], sum[3100][3100], C[3100][3100], inv[3100], g[3100];   int edgenum, vet[210000], Next[210000], Head[110000];   void addedge(int u, int v) {     vet[++edgenum] = v;     Next[edgenum] = Head[u];     Head[u] = edgenum;   }   void dfs(int u) {     for (int i = Head[u]; i; i = Next[i]) {       dfs(vet[i]);       for (int j = 1; j <= n; j++) f[u][j] = 1ll * f[u][j] * sum[vet[i]][j] % Mod;     }     for (int i = 1; i <= n; i++) sum[u][i] = (sum[u][i - 1] + f[u][i]) % Mod;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       scanf( %d , &u);       addedge(u, i);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) f[i][j] = 1;     dfs(1);     C[0][0] = 1;     for (int i = 1; i <= n; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;     }     inv[0] = 1;     inv[1] = 1;     for (int i = 2; i <= n; i++)       inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;     for (int i = 2; i <= n; i++) inv[i] = 1ll * inv[i - 1] * inv[i] % Mod;     for (int i = 1; i <= n; i++) {       g[i] = f[1][i];       for (int j = 1; j < i; j++)         g[i] = (g[i] - 1ll * C[i - 1][j - 1] * g[j] % Mod + Mod) % Mod;     }     int ans = 0;     for (int i = 1; i <= n && i <= m; i++) {       int mul = inv[i];       for (int j = m - i + 1; j <= m; j++) mul = 1ll * mul * j % Mod;       ans = (ans + 1ll * mul * g[i] % Mod) % Mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long N = mod;   long long quick_mod(long long a, long long b) {     long long ans = 1;     a %= N;     while (b) {       if (b % 2 != 0) {         ans = ans * a % N;         b--;       }       b /= 2;       a = a * a % N;     }     return ans % N;   }   int main() {     long long m, n, i, j, k;     while (cin >> m) {       if (m == 0) {         cout << 1 << endl;         continue;       }       cout << (quick_mod(2, m - 1) * (1 + quick_mod(2, m))) % N << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <int modd>   struct modint {     static const int mod = modd;     int v;     explicit operator int() const { return v; }     modint() : v(0) {}     modint(long long x) : v(int(x % mod)) {       if (v < 0) v += mod;     }     friend bool operator==(const modint& a, const modint& b) {       return a.v == b.v;     }     friend bool operator!=(const modint& a, const modint& b) {       return a.v != b.v;     }     friend bool operator<(const modint& a, const modint& b) { return a.v < b.v; }     modint& operator+=(const modint& a) {       if ((v += a.v) >= mod) v -= mod;       return *this;     }     modint& operator-=(const modint& a) {       if ((v -= a.v) < 0) v += mod;       return *this;     }     modint& operator*=(const modint& a) {       v = int((long long)v * a.v % mod);       return *this;     }     modint& operator/=(const modint& a) { return (*this) *= inv(a); }     friend modint pow(modint a, long long p) {       modint ret = 1;       for (; p; p /= 2, a *= a) {         if (p & 1) ret *= a;       }       return ret;     }     friend modint inv(const modint& a) { return pow(a, mod - 2); }     modint operator-() const { return modint(-v); }     modint& operator++() { return *this += 1; }     modint& operator--() { return *this -= 1; }     friend modint operator+(modint a, const modint& b) { return a += b; }     friend modint operator-(modint a, const modint& b) { return a -= b; }     friend modint operator*(modint a, const modint& b) { return a *= b; }     friend modint operator/(modint a, const modint& b) { return a /= b; }     friend ostream& operator<<(ostream& out, modint a) { return out << a.v; }     friend istream& operator>>(istream& in, modint& a) {       long long b;       in >> b;       a.v = b;       return in;     }   };   using mint = modint<1000000007>;   struct change {     int* ptr;     int val, t;     change(int* p, int v, int tin) : ptr(p), val(v), t(tin) {}     void undo() { *ptr = val; }   };   struct dsu {     vector<int> v, len;     stack<change> st;     int ttime, ct;     dsu(int n) : v(n), len(n, 1), ttime(0), ct(n) { iota(v.begin(), v.end(), 0); }     void make_change(int* p, int val) {       change ch(p, *p, ttime);       st.push(ch);       *p = val;     }     void batch_undo() {       assert(!st.empty());       int tt = st.top().t;       while (((int)((st).size())) && st.top().t == tt) {         st.top().undo();         st.pop();       }     }     int root(int a) { return (v[a] == a ? a : root(v[a])); }     bool unite(int a, int b) {       ttime++;       int a1 = root(a), b1 = root(b);       if (a1 == b1) {         make_change(&v[0], v[0]);         return false;       }       make_change(&ct, ct - 1);       if (len[a1] < len[b1]) swap(a1, b1);       make_change(&len[a1], len[a1] + len[b1]);       make_change(&v[b1], a1);       return true;     }   };   const int mx = 5e5 + 5;   int n, m, k;   long long a[mx];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int q = 1; q <= n; q++) cin >> a[q];     vector<array<long long, 3>> v(m);     for (int q = 0; q < m; q++) {       cin >> v[q][1] >> v[q][2];       v[q][0] = a[v[q][1]] ^ a[v[q][2]];     }     sort(v.begin(), v.end());     int q = 0, tot = 0;     dsu d(n + 1);     mint ans = 0;     while (q < m) {       tot++;       int w = q;       while (w < m && v[w][0] == v[q][0]) {         d.unite(v[w][1], v[w][2]);         w++;       }       ans += pow(mint(2), d.ct - 1);       w = q;       while (w < m && v[w][0] == v[q][0]) {         d.batch_undo();         w++;       }       q = w;     }     ans += (pow(mint(2), k) - tot) * pow(mint(2), n);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     vector<int> v;     int temp = 0;     for (int i = 0; i < n; i++) {       cin >> temp;       v.push_back(temp);     }     int dem0 = 0;     if (n == 1) {       if (v[0] == 1)         cout <<  YES ;       else         cout <<  NO ;     } else {       for (int i = 0; i < n; i++) {         if (v[i] == 0) dem0++;       }       if (dem0 == 0 || dem0 > 1)         cout <<  NO ;       else         cout <<  YES ;     }     return 0;   }