#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 0x3f3f3f3f;   long long dp[maxn];   int n, m;   struct node {     int lb, lu;     long long w;   };   vector<node> ve[maxn];   int lb, lu;   long long w, cost[maxn];   struct seg {     long long ma, lazy;   } tr[maxn << 2];   void build(int o, int l, int r) {     tr[o].ma = 0;     tr[o].lazy = 0;     if (l == r) {       return;     }     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);   }   void pushup(int o) { tr[o].ma = max(tr[o << 1].ma, tr[o << 1 | 1].ma); }   void pushdown(int o) {     if (tr[o].lazy) {       tr[o << 1].ma += tr[o].lazy;       tr[o << 1 | 1].ma += tr[o].lazy;       tr[o << 1].lazy += tr[o].lazy;       tr[o << 1 | 1].lazy += tr[o].lazy;       tr[o].lazy = 0;     }   }   void update(int o, int l, int r, int ql, int qr, long long val) {     if (ql <= l && qr >= r) {       tr[o].ma += val;       tr[o].lazy += val;       return;     }     pushdown(o);     int mid = (l + r) >> 1;     if (ql <= mid) update(o << 1, l, mid, ql, qr, val);     if (qr > mid) update(o << 1 | 1, mid + 1, r, ql, qr, val);     pushup(o);   }   long long query(int o, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) {       return tr[o].ma;     }     pushdown(o);     int mid = (l + r) >> 1;     long long maxx = 0;     if (ql <= mid) maxx = max(maxx, query(o << 1, l, mid, ql, qr));     if (qr > mid) maxx = max(maxx, query(o << 1 | 1, mid + 1, r, ql, qr));     return maxx;   }   int main() {     while (cin >> n >> m) {       for (int i = 1; i <= n; i++) {         scanf( %lld , &cost[i]);         ve[i].clear();       }       for (int i = 1; i <= m; i++) {         scanf( %d%d%lld , &lb, &lu, &w);         ve[lu].push_back({lb, lu, w});       }       build(1, 0, n);       long long maxx = 0;       for (int i = 1; i <= n; i++) {         dp[i] = dp[i - 1];         update(1, 0, n, 0, i - 1, -cost[i]);         for (int j = 0; j < ve[i].size(); j++) {           lb = ve[i][j].lb, w = ve[i][j].w;           update(1, 0, n, 0, lb - 1, w);         }         dp[i] = max(dp[i], query(1, 0, n, 0, i - 1));         update(1, 0, n, i, i, dp[i]);         maxx = max(maxx, dp[i]);       }       printf( %lld n , maxx);     }   }


#include <bits/stdc++.h>   using namespace std;   int read_number(int i) {     cout <<  ?   << i <<   n ;     fflush(stdout);     int number;     cin >> number;     return number;   }   bool intersects(int l1, int l2, int r1, int r2) {     if (l1 >= l2) swap(l1, l2);     if (r1 >= r2) swap(r2, r1);     return max(l1, r1) <= min(l2, r2);   }   bool contains(int l1, int l2, int r1, int r2) {     if (l1 >= l2) swap(l1, l2);     if (r1 >= r2) swap(r1, r2);     return (l1 <= r1 && l2 >= r2) || (r1 <= l1 && l2 <= r2);   }   bool dif(int l1, int l2, int r1, int r2) { return (l2 - l1) * (r2 - r1) <= 0; }   bool solution(int l1, int l2, int r1, int r2) {     return (dif(l1, l2, r1, r2) && intersects(l1, l2, r1, r2)) ||            contains(l1, l2, r1, r2);   }   int main() {     int n;     cin >> n;     if ((n / 2) % 2 == 1) {       cout <<  ! -1 n ;       return 0;     }     int l1 = read_number(1);     int r1 = read_number(n / 2 + 1);     int l2 = r1;     int r2 = l1;     int min_l1 = 1;     int max_l1 = n / 2 + 1;     int min_r1 = n / 2 + 1;     int max_r2 = n + 1;     if (l1 == r1) {       cout <<  !   << l1 <<   n ;       return 0;     }     while (true) {       int med_l1 = (1 + min_l1 + max_l1) / 2;       int med_r2 = (1 + min_r1 + max_r2) / 2;       int temp_l1 = read_number(med_l1);       int temp_r1 = read_number(med_r2);       if (temp_l1 == temp_r1) {         cout <<  !   << med_l1 <<   n ;         return 0;       }       if (solution(l1, temp_l1, r1, temp_r1)) {         l2 = temp_l1;         r2 = temp_r1;         max_l1 = med_l1;         max_r2 = med_r2;       } else {         l1 = temp_l1;         r1 = temp_r1;         min_l1 = med_l1;         min_r1 = med_r2;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t, k;   vector<int> g[200010];   int par[200010];   int nodeId;   int leaf;   vector<int> deep[200010];   int a[200010];   void createGraph(int x, int level) {     if (level > t) return;     for (int i = 1; i <= a[level]; i++) {       g[x].push_back(++nodeId);       par[nodeId] = x;       deep[level].push_back(nodeId);     }     leaf += a[level];     if (level != t) leaf--;     createGraph(nodeId, level + 1);   }   void adjust(int dp) {     queue<int> Q;     for (int i : deep[dp]) {       if (g[i].size() == 0) {         Q.push(i);       }     }     int size = deep[dp + 1].size();     for (int i = 0; i < size - 1; i++) {       if (Q.empty()) break;       if (leaf <= k) break;       int node = deep[dp + 1][i];       par[node] = Q.front();       Q.pop();       --leaf;     }   }   int main(int argc, char const *argv[]) {     nodeId = 1;     scanf( %d %d %d , &n, &t, &k);     for (int i = 1; i <= t; i++) {       scanf( %d , a + i);     }     createGraph(1, 1);     if (leaf < k) {       printf( -1 n );       exit(0);     }     for (int i = 1; i < t; i++) {       adjust(i);     }     if (leaf != k) {       printf( -1 n );       exit(0);     }     printf( %d n , n);     for (int i = 2; i <= n; i++) {       printf( %d %d n , par[i], i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long m, k;     cin >> n >> m >> k;     vector<long long> arr(n);     long long max1 = -1;     long long max2 = -2;     long long temp;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > max2) {         max2 = arr[i];       }       if (max2 > max1) {         temp = max2;         max2 = max1;         max1 = temp;       }     }     long long cycle = (max1 * k) + max2;     long long period = k + 1;     long long ans = (m / period) * cycle;     ans += (m % period) * max1;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main()   {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin>>t;     while(t--)     {       int n;       cin>>n;       vector<long long int>a(n);       for(int i=0;i<n;i++)         cin>>a[i];       sort(a.begin(),a.end());       long long int as=0,bs=0,turn=0;       for(int i=n-1;i>=0;i--)       {         if(turn==0)         {           if(a[i]%2==0)           {             as+=a[i];           }         }         else          {           if(a[i]&1)           {             bs+=a[i];           }         }         turn=1-turn;       }       if(as>bs)         cout<< Alice <<endl;       else if(bs>as)         cout<< Bob <<endl;       else         cout<< Tie <<endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   int n, num, h[N], siz[N], e[N << 1], pre[N << 1];   double g[N], C[N][N], f[N][N];   inline void add(int x, int y) { e[++num] = y, pre[num] = h[x], h[x] = num; }   void dfs(int u, int fa = 0) {     memset(f[u], 0, sizeof f[u]), f[u][0] = siz[u] = 1;     for (int i = h[u]; i; i = pre[i])       if (e[i] != fa) {         dfs(e[i], u), siz[u] += siz[e[i]];         memset(g, 0, sizeof g);         for (int j = 0; j < siz[e[i]]; ++j) g[j] = f[e[i]][j] * (siz[e[i]] - j);         for (int j = 1; j <= siz[e[i]]; ++j)           for (int k = 0; k < j; ++k) g[j] += f[e[i]][k] / 2;         for (int j = siz[u]; j--;) {           f[u][j] = f[u][j] * g[0] * C[siz[u] - 1 - j][siz[e[i]]];           for (int k = 1; k <= siz[e[i]]; ++k)             f[u][j] +=                 f[u][j - k] * g[k] * C[siz[u] - 1 - j][siz[e[i]] - k] * C[j][k];         }       }   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; ++i) scanf( %d%d , &x, &y), add(x, y), add(y, x);     C[0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= i; ++j)         C[i][j] = (j ? C[i - 1][j - 1] : 0) + C[i - 1][j];     double k = 1;     for (int i = 1; i < n; ++i) k /= i;     for (int i = 1; i <= n; ++i) dfs(i), printf( %.10lf n , f[i][n - 1] * k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (1e6) + 5;   const int M = (60) + 5;   int memo[M][M];   int n, a[N];   int grundy(int n, int last) {     if (n == 0) {       return 0;     }     int &ret = memo[n][last];     if (ret != -1) return ret;     set<int> S;     for (int i = last + 1; i <= n; i += 1) {       S.insert(grundy(n - i, i));     }     ret = 0;     while (S.count(ret)) ret++;     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     memset(memo, -1, sizeof memo);     int g = 0;     for (int i = 0; i < n; i += 1) {       g ^= grundy(a[i], 0);     }     cout << (g == 0 ?  YES  :  NO ) <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse4 )   using namespace std;   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-6;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char nl =   n ;   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   void ckmin(T& a, T b) {     a = min(a, b);   }   template <class T>   void ckmax(T& a, T b) {     a = max(a, b);   }   int pct(int x) { return __builtin_popcount(x); }   int pct(long long x) { return __builtin_popcountll(x); }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << h;     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   void setIn(string s) { freopen(s.c_str(),  r , stdin); }   void setOut(string s) { freopen(s.c_str(),  w , stdout); }   void unsyncIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   void setIO(string s =   ) {     unsyncIO();     if ((int)s.size()) {       setIn(s +  .in ), setOut(s +  .out );     }   }   long long pow(long long b, long long e, long long m = 0LL,                 long long ans = 1LL) {     while (e) {       if (e & 1LL) {         ans *= b;         if (m) ans %= m;       }       b *= b, e >>= 1LL;       if (m) b %= m;     }     return ans;   }   void solve(int tcn) {     int n, m;     cin >> n >> m;     vector<vector<int> > l(n + 1, vector<int>(m + 1)),         r(n + 1, vector<int>(m + 1));     for (int i = (0); i < (n); ++i) {       int k;       cin >> k;       for (int j = (0); j < (k); ++j) {         int lll, rrr;         cin >> lll >> rrr;         for (int x = (lll); x < (rrr + 1); ++x) {           l[i + 1][x] = lll;           r[i + 1][x] = rrr;         }       }     }     vector<vector<long long> > dp(m + 2, vector<long long>(m + 2, 0LL));     for (int lll = m; lll >= 1; --lll) {       for (int rrr = (lll); rrr < (m + 1); ++rrr) {         for (int x = (lll); x < (rrr + 1); ++x) {           long long cnt = 0LL;           for (int k = (1); k < (n + 1); ++k)             if (l[k][x] >= lll && r[k][x] <= rrr) ++cnt;           ckmax(dp[lll][rrr], dp[lll][x - 1] + cnt * cnt + dp[x + 1][rrr]);         }       }     }     cout << dp[1][m] << nl;   }   int main() {     setIO();     int t = 1;     for (int i = 1; i <= t; ++i) {       solve(i);     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int main(){       int t;       cin>>t;              while(t--){       string s;       cin>>s;              int n = s.length();              int i=0,j = n-1,k = n-1;       char z =  a ;              while(k>=0){           if(s[i] == z+k)           i++;           else if(s[j] == z+k)           j--;           else           break;                      k--;       }              if(k == -1)       cout<< YES <<endl;       else       cout<< NO <<endl;              }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long N = 1000L + 10;   const long long modulo = 1000000007L;   vector<pair<long, long> > interv;   bool memo[N][N];   bool visited[N];   void divideByZero(const char *error) {     printf(error);     fclose(stdout);     int a = 234;     a = a / (a - a);   }   bool canDirectly(long a, long b, long c, long d) {     return (c < a && a < d) || (c < b && b < d);   }   void addInterval(long x, long y) {     long n = interv.size();     interv.push_back(make_pair(x, y));     for (long i = 0; i < n; i++) {       if (canDirectly(interv[i].first, interv[i].second, x, y)) {         memo[i][n] = true;       }       if (canDirectly(x, y, interv[i].first, interv[i].second)) {         memo[n][i] = true;       }     }   }   bool pathExists(long from, long to) {     for (long i = 0; i < N; i++) visited[i] = false;     long n = interv.size();     queue<long> q;     visited[from] = true;     q.push(from);     while (!q.empty()) {       long v = q.front();       if (v == to) return true;       q.pop();       for (long nb = 0; nb < n; nb++)         if (memo[v][nb]) {           if (visited[nb]) continue;           visited[nb] = true;           q.push(nb);         }     }     return false;   }   int main() {     long n;     scanf( %ld  , &n);     for (long i = 0; i < n; i++)       for (long j = 0; j < n; j++) memo[i][j] = false;     for (long i = 0; i < n; i++) {       long mode, x, y;       scanf( %ld %ld %ld , &mode, &x, &y);       if (mode == 1)         addInterval(x, y);       else {         if (pathExists(x - 1, y - 1))           printf( YES n );         else           printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   constexpr int Maxn = 2e5 + 7;   constexpr int Maxm = 1e6 + 7;   constexpr int Mod = 1e9 + 7;   int n, k, sum, root;   void add(int bit[], int p, int v) {     for (; p < Maxn; p += p & -p) bit[p] = (bit[p] + v) % Mod;   }   int query(int bit[], int p) {     int res = 0;     for (; p; p -= p & -p) res = (res + bit[p]) % Mod;     return res;   }   struct Edge {     int nxt, to, w;   } e[Maxn << 1];   int head[Maxn], edge_cnt, res;   inline void add_edge(int u, int v, int w) {     e[++edge_cnt].to = v;     e[edge_cnt].nxt = head[u];     e[edge_cnt].w = w;     head[u] = edge_cnt;   }   int a[Maxn], siz[Maxn], f[Maxn];   int del[Maxn];   void getroot(int u, int fa) {     siz[u] = 1;     f[u] = 0;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (!del[v] && v != fa) {         getroot(v, u);         siz[u] += siz[v];         f[u] = std::max(f[u], siz[v]);       }     }     f[u] = std::max(f[u], sum - siz[u]);     if (f[u] < f[root]) root = u;   }   int val[2][Maxn], num[2][Maxn];   void DFS(int u, int fa, int rcol, int col, int nxt, int tot, int opt) {     tot = (tot + a[u]) % Mod;     if (opt == 0) {       if (k >= nxt) {         int cnt = query(num[rcol], k - nxt + 1);         int cur = query(val[rcol], k - nxt + 1);         res = (res + 1LL * cnt * tot % Mod) % Mod;         res = (res + cur) % Mod;       }       if (k >= nxt + 1) {         int cnt = query(num[rcol ^ 1], k - nxt);         int cur = query(val[rcol ^ 1], k - nxt);         res = (res + 1LL * cnt * tot % Mod) % Mod;         res = (res + cur) % Mod;       }       if (k >= nxt) res = (res + tot) % Mod;     } else if (opt == 1) {       add(num[rcol], nxt + 1, 1);       add(val[rcol], nxt + 1, tot);     } else {       add(num[rcol], nxt + 1, Mod - 1);       add(val[rcol], nxt + 1, Mod - tot);     }     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to, w = e[i].w;       if (del[v] || v == fa) continue;       int nxtstp = nxt;       if (w != col) ++nxtstp;       DFS(v, u, rcol, w, nxtstp, tot, opt);     }   }   void solve(int u) {     del[u] = 1;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to, w = e[i].w;       if (!del[v]) {         DFS(v, u, w, w, 0, a[u], 0);         DFS(v, u, w, w, 0, 0, 1);       }     }     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to, w = e[i].w;       if (!del[v]) DFS(v, u, w, w, 0, 0, -1);     }     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (!del[v]) {         root = 0, sum = siz[v];         getroot(v, 0);         solve(root);       }     }   }   int main() {     scanf( %d%d , &n, &k);     f[0] = sum = n;     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1, u, v, w; i <= n - 1; ++i) {       scanf( %d%d%d , &u, &v, &w);       add_edge(u, v, w), add_edge(v, u, w);     }     getroot(1, 0);     solve(root);     for (int i = 1; i <= n; ++i) res = (res + a[i]) % Mod;     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   void rwFile() {     freopen( INP.inp ,  r , stdin);     freopen( OUT.out ,  w , stdout);   }   void solveC_VanyaAndScales() {     long long w, m;     cin >> w >> m;     if (w == 2) {       cout <<  YES ;       return;     }     int able = 1;     while (m) {       long long tmp = m % w;       m /= w;       if (tmp == w - 1) {         m++;         continue;       }       if (tmp == 1 || tmp == 0) continue;       able = 0;       break;     }     if (able == 1)       cout <<  YES ;     else       cout <<  NO ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     solveC_VanyaAndScales();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n);     vector<int> update(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       update[i] = 0;     }     int accumalated = 0;     for (int i = 0; i < m; i++) {       int t;       cin >> t;       if (t == 1) {         int v, x;         cin >> v >> x;         a[v - 1] = x;         update[v - 1] = accumalated;       } else if (t == 2) {         int y;         cin >> y;         accumalated += y;       } else {         int q;         cin >> q;         cout << a[q - 1] + accumalated - update[q - 1] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   inline int read() {     int 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;   }   int n, m, K;   int a[N], b[N], c[N], dp[N][N];   struct Node {     int x, w;   } g[N];   inline bool cp(Node x, Node y) { return x.w < y.w; }   signed main() {     n = read(), m = read(), K = read();     for (register int i = 1; i <= n; i++)       a[i] = read(), b[i] = read(), c[i] = read(), g[i].x = g[i].w = i;     for (register int i = 1; i <= m; i++) {       int u, v;       u = read(), v = read();       g[v].w = max(g[v].w, u);     }     sort(g + 1, g + 1 + n, cp);     int now = 1;     while (!g[now].w) now++;     memset(dp, -0x3f, sizeof(dp));     for (register int i = 0; i <= K; i++) dp[0][i] = 0;     int qwq = K;     for (register int i = 1; i <= n; i++) {       if (qwq < a[i]) {         puts( -1 );         return 0;       }       qwq += b[i];       for (register int j = a[i]; j <= 5000 - b[i]; j++)         dp[i][j + b[i]] = max(dp[i][j + b[i]], dp[i - 1][j]);       while (now <= n && g[now].w == i) {         for (register int j = 1; j <= 5000; j++)           dp[i][j - 1] = max(dp[i][j - 1], dp[i][j] + c[g[now].x]);         now++;       }     }     int res = 0;     for (register int i = 0; i <= 5000; i++) res = max(res, dp[n][i]);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0U >> 1;   const long long linf = (long long)1e18;   const double eps = 1e-6;   template <class T>   string tostr(T a) {     ostringstream out;     out << a;     return out.str();   }   struct debugger {     template <typename T>     debugger &operator,(const T &x) {       cerr << x << endl;       return *this;     }   } dbg;   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;   }   inline void read(long long &x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;   }   inline void read(bool &x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;   }   inline void read(double &x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (ch ==  . ) {       double tmp = 1;       ch = nc();       for (; ch >=  0  && ch <=  9 ; ch = nc())         tmp /= 10.0, x += tmp * (ch -  0 );     }     if (sign) x = -x;   }   inline void read(char *s) {     char ch = nc();     for (; blank(ch); ch = nc())       ;     if (IOerror) return;     for (; !blank(ch) && !IOerror; ch = nc()) *s++ = ch;     *s = 0;   }   inline void read(char &c) {     for (c = nc(); blank(c); c = nc())       ;     if (IOerror) {       c = -1;       return;     }   }   inline void read1(int &x) {     char ch;     int bo = 0;     x = 0;     for (ch = getchar(); ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) bo = 1;     for (; ch >=  0  && ch <=  9 ; x = x * 10 + ch -  0 , ch = getchar())       ;     if (bo) x = -x;   }   inline void read1(long long &x) {     char ch;     int bo = 0;     x = 0;     for (ch = getchar(); ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) bo = 1;     for (; ch >=  0  && ch <=  9 ; x = x * 10 + ch -  0 , ch = getchar())       ;     if (bo) x = -x;   }   inline void read1(double &x) {     char ch;     int bo = 0;     x = 0;     for (ch = getchar(); ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) bo = 1;     for (; ch >=  0  && ch <=  9 ; x = x * 10 + ch -  0 , ch = getchar())       ;     if (ch ==  . ) {       double tmp = 1;       for (ch = getchar(); ch >=  0  && ch <=  9 ;            tmp /= 10.0, x += tmp * (ch -  0 ), ch = getchar())         ;     }     if (bo) x = -x;   }   inline void read1(char *s) {     char ch = getchar();     for (; blank(ch); ch = getchar())       ;     for (; !blank(ch); ch = getchar()) *s++ = ch;     *s = 0;   }   inline void read1(char &c) {     for (c = getchar(); blank(c); c = getchar())       ;   }   inline void read2(int &x) { scanf( %d , &x); }   inline void read2(long long &x) { scanf( %lld , &x); }   inline void read2(double &x) { scanf( %lf , &x); }   inline void read2(char *s) { scanf( %s , s); }   inline void read2(char &c) { scanf(  %c , &c); }   inline void readln2(char *s) { gets(s); }   struct Ostream_fwrite {     char *buf, *p1, *pend;     Ostream_fwrite() {       buf = new char[100000];       p1 = buf;       pend = buf + 100000;     }     void out(char ch) {       if (p1 == pend) {         fwrite(buf, 1, 100000, stdout);         p1 = buf;       }       *p1++ = ch;     }     void print(int x) {       static char s[15], *s1;       s1 = s;       if (!x) *s1++ =  0 ;       if (x < 0) out( - ), x = -x;       while (x) *s1++ = x % 10 +  0 , x /= 10;       while (s1-- != s) out(*s1);     }     void println(int x) {       static char s[15], *s1;       s1 = s;       if (!x) *s1++ =  0 ;       if (x < 0) out( - ), x = -x;       while (x) *s1++ = x % 10 +  0 , x /= 10;       while (s1-- != s) out(*s1);       out(  n );     }     void print(long long x) {       static char s[25], *s1;       s1 = s;       if (!x) *s1++ =  0 ;       if (x < 0) out( - ), x = -x;       while (x) *s1++ = x % 10 +  0 , x /= 10;       while (s1-- != s) out(*s1);     }     void println(long long x) {       static char s[25], *s1;       s1 = s;       if (!x) *s1++ =  0 ;       if (x < 0) out( - ), x = -x;       while (x) *s1++ = x % 10 +  0 , x /= 10;       while (s1-- != s) out(*s1);       out(  n );     }     void print(double x, int y) {       static long long mul[] = {1,                                 10,                                 100,                                 1000,                                 10000,                                 100000,                                 1000000,                                 10000000,                                 100000000,                                 1000000000,                                 10000000000LL,                                 100000000000LL,                                 1000000000000LL,                                 10000000000000LL,                                 100000000000000LL,                                 1000000000000000LL,                                 10000000000000000LL,                                 100000000000000000LL};       if (x < -1e-7) out( - ), x = -x;       x *= mul[y];       long long x1 = (long long)floor(x);       if (x - floor(x) >= 0.5) ++x1;       long long x2 = x1 / mul[y];       print(x2);       if (y > 0) {         out( . );         print(x1 - x2 * mul[y]);       }     }     void println(double x, int y) {       print(x, y);       out(  n );     }     void print(char *s) {       while (*s) out(*s++);     }     void println(char *s) {       while (*s) out(*s++);       out(  n );     }     void flush() {       if (p1 != buf) {         fwrite(buf, 1, p1 - buf, stdout);         p1 = buf;       }     }     ~Ostream_fwrite() { flush(); }   } Ostream;   inline void print(int x) { Ostream.print(x); }   inline void println(int x) { Ostream.println(x); }   inline void print(char x) { Ostream.out(x); }   inline void println(char x) {     Ostream.out(x);     Ostream.out(  n );   }   inline void print(long long x) { Ostream.print(x); }   inline void println(long long x) { Ostream.println(x); }   inline void print(double x, int y) { Ostream.print(x, y); }   inline void println(double x, int y) { Ostream.println(x, y); }   inline void print(char *s) { Ostream.print(s); }   inline void println(char *s) { Ostream.println(s); }   inline void println() { Ostream.out(  n ); }   inline void flush() { Ostream.flush(); }   char Out[100000], *o = Out;   inline void print1(int x) {     static char buf[15];     char *p1 = buf;     if (!x) *p1++ =  0 ;     if (x < 0) *o++ =  - , x = -x;     while (x) *p1++ = x % 10 +  0 , x /= 10;     while (p1-- != buf) *o++ = *p1;   }   inline void println1(int x) {     print1(x);     *o++ =   n ;   }   inline void print1(long long x) {     static char buf[25];     char *p1 = buf;     if (!x) *p1++ =  0 ;     if (x < 0) *o++ =  - , x = -x;     while (x) *p1++ = x % 10 +  0 , x /= 10;     while (p1-- != buf) *o++ = *p1;   }   inline void println1(long long x) {     print1(x);     *o++ =   n ;   }   inline void print1(char c) { *o++ = c; }   inline void println1(char c) {     *o++ = c;     *o++ =   n ;   }   inline void print1(char *s) {     while (*s) *o++ = *s++;   }   inline void println1(char *s) {     print(s);     *o++ =   n ;   }   inline void println1() { *o++ =   n ; }   inline void flush1() {     if (o != Out && *(o - 1) ==   n ) *--o = 0;     puts(Out);   }   struct puts_write {     ~puts_write() { flush1(); }   };   inline void print2(int x) { printf( %d , x); }   inline void println2(int x) { printf( %d n , x); }   inline void print2(char x) { printf( %c , x); }   inline void println2(char x) { printf( %c n , x); }   inline void print2(long long x) { printf( %lld , x); }   inline void println2(long long x) {     print2(x);     printf(  n );   }   inline void println2() { printf(  n ); }   };  // namespace fastIO   using namespace fastIO;   string name =   , in =  .in , out =  .out ;   bool a[2005][2005], visit[2005][2005];   int cx[700005], cy[700005], c1, n, cnt, cntC, cntS;   double dist[700005], Ox, Oy;   void dfs(int x, int y) {     if (visit[x][y]) return;     visit[x][y] = 1;     ++cnt;     bool bo = 0;     Ox += x;     Oy += y;     for (int dx = -1; dx <= 1; ++dx)       for (int dy = -1; dy <= 1; ++dy) {         int x1 = x + dx, y1 = y + dy;         if (!a[x1][y1])           ++bo;         else           dfs(x1, y1);       }     if (bo) ++c1, cx[c1] = x, cy[c1] = y;   }   void genMap() {     static bool tmp[2005][2005];     memcpy(tmp, a, sizeof(a));     memset(a, 0, sizeof(a));     for (int i = 4; i + 3 <= n; ++i)       for (int j = 4; j + 3 <= n; ++j) {         int cnt = 0;         for (int dx = -3; dx <= 3; ++dx)           for (int dy = -3; dy <= 3; ++dy) cnt += tmp[i + dx][j + dy];         if (cnt >= 24)           a[i][j] = 1;         else           a[i][j] = 0;       }   }   int main() {     read(n);     memset(visit, 1, sizeof(visit));     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) read(a[i][j]), visit[i][j] = 0;     genMap();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (!visit[i][j] && a[i][j]) {           c1 = 0;           cnt = 0;           Ox = 0;           Oy = 0;           dfs(i, j);           if (cnt < 130) continue;           double max_d = 0;           int c1_pre = c1;           Ox /= cnt;           Oy /= cnt;           for (int k = 1; k <= c1; ++k)             dist[k] =                 sqrt((Ox - cx[k]) * (Ox - cx[k]) + (Oy - cy[k]) * (Oy - cy[k]));           for (int k = 1; k <= c1; ++k) max_d = max(max_d, dist[k]);           for (int k = 1; k <= c1; ++k) dist[k] /= max_d;           double ave = accumulate(dist + 1, dist + c1 + 1, 0.0) / c1, sum = 0;           for (int k = 1; k <= c1; ++k) sum += (dist[k] - ave) * (dist[k] - ave);           sum /= c1;           sum = sqrt(sum);           double div = sum / ave;           if (div > 0.045 && div < 0.055) {             printf( div=%.5lf cnt=%d n , div, cnt);             while (1)               ;           }           if (div < 0.060)             ++cntC;           else             ++cntS;         }   end:;     printf( %d %d n , cntC, cntS);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 5;   const int MOD = 998244353;   long long p[MAX];   long long mpow[MAX];   int main(int argc, char* argv[]) {     if (argc == 2 or argc == 3) freopen(argv[1],  r , stdin);     if (argc == 3) freopen(argv[2],  w , stdout);     int n, m;     string a, b;     cin >> n >> m >> a >> b;     while (n < m) a =  0  + a, n++;     while (m < n) b =  0  + b, m++;     mpow[0] = 1;     for (int i = 1; i < MAX; i++) {       mpow[i] = (mpow[i - 1] * 2) % MOD;     }     for (int i = n - 1; i >= 0; i--) {       p[i] = p[i + 1] + (a[i] ==  1 ) * mpow[n - i - 1];       p[i] %= MOD;     }     long long ans = 0;     for (int i = 0; i < m; i++) {       if (b[i] ==  1 ) {         ans = (ans + p[i]) % MOD;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool reverse(long long a, long long b) { return a > b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, i;     cin >> n;     if (n % 2 != 0)       cout <<  -1             <<   n ;     else {       for (long long i = 1; i <= n; i++) {         if (i % 2 == 0)           cout << i - 1 <<    ;         else           cout << i + 1 <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long int n;       cin >> n;       long long int a[n + 1], b[n + 1];       for (long long int i = 1; i <= n; i++) cin >> a[i];       for (long long int i = 1; i <= n; i++) cin >> b[i];       multiset<long long int> s;       for (long long int i = 1; i <= n; i++) s.insert(b[i]);       for (long long int i = 1; i <= n; i++) {         long long int opt1 = *s.begin();         if (s.lower_bound(n - a[i]) == s.end()) {           cout << (a[i] + opt1) % n <<    ;           s.erase(s.find(opt1));           continue;         }         long long int opt2 = *s.lower_bound(n - a[i]);         if ((a[i] + opt1) % n < (a[i] + opt2) % n) {           cout << (a[i] + opt1) % n <<    ;           s.erase(s.find(opt1));         } else {           cout << (a[i] + opt2) % n <<    ;           s.erase(s.find(opt2));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long head[200010], cnt;   class littlestar {    public:     long long to, nxt;     void add(long long u, long long v) {       to = v;       nxt = head[u];       head[u] = cnt;     }   } star[400010];   long long n, f[200010], g[200010], h[200010];   void dfs(long long u, long long fa) {     for (long long i = head[u]; i; i = star[i].nxt) {       long long v = star[i].to;       if (v == fa) continue;       dfs(v, u);       f[fa] = f[fa] + f[v] + 1;       g[u] = g[u] + f[v] + 1;     }   }   void dp(long long u, long long fa) {     for (long long i = head[u]; i; i = star[i].nxt) {       long long v = star[i].to;       if (v == fa) continue;       h[v] = g[u] - 1;       if (fa) h[v] = h[fa];       dp(v, u);     }   }   signed main() {     cin >> n;     for (register long long i = 1; i <= n - 1; i++) {       long long x, y;       scanf( %lld%lld , &x, &y);       star[++cnt].add(x, y);       star[++cnt].add(y, x);     }     dfs(1, 0);     h[1] = f[1];     dp(1, 0);     long long ans = LLONG_MAX;     for (register long long i = 1; i <= n; i++) ans = min(ans, h[i]);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   bool comparator(string a, string b) {     if (a.size() == b.size()) {       return a > b;     }     return a.size() > b.size();   }   int main() {     int n, m;     cin >> n >> m;     string mat[n];     for (int i = 0; i < n; i++) {       cin >> mat[i];     }     vector<pair<int, int> > enemy;     vector<int> adj[n * m];     int jugador;     int end;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int pos = i * m + j;         if (mat[i][j] ==  T ) continue;         if (mat[i][j] ==  E ) {           end = pos;         }         if (mat[i][j] -  0  >= 0 && mat[i][j] -  0  <= 9) {           enemy.emplace_back(pair<int, int>(pos, mat[i][j] -  0 ));         }         if (mat[i][j] ==  S ) {           jugador = pos;         }         if (i > 0 && mat[i - 1][j] !=  T ) {           adj[pos].emplace_back(pos - m);           adj[pos - m].emplace_back(pos);         }         if (i < n - 1 && mat[i + 1][j] !=  T ) {           adj[pos].emplace_back(pos + m);           adj[pos + m].emplace_back(pos);         }         if (j < m - 1 && mat[i][j + 1] !=  T ) {           adj[pos].emplace_back(pos + 1);           adj[pos + 1].emplace_back(pos);         }         if (j > 0 && mat[i][j - 1] !=  T ) {           adj[pos].emplace_back(pos - 1);           adj[pos - 1].emplace_back(pos);         }       }     }     queue<int> qu;     int dist[n * m];     for (int i = 0; i < n * m; i++) {       dist[i] = 1000000000;     }     dist[end] = 0;     qu.push(end);     while (!qu.empty()) {       int u = qu.front();       qu.pop();       for (auto v : adj[u]) {         if (dist[u] + 1 < dist[v]) {           dist[v] = dist[u] + 1;           qu.push(v);         }       }     }     long long ans = 0;     for (auto ene : enemy) {       if (dist[ene.first] <= dist[jugador]) {         ans += ene.second;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using ld = long double;   const ld EPS = 1e-12;   const ld PI = acos((ld)-1);   inline bool equ(const ld& a, const ld& b) { return std::abs(a - b) < EPS; }   struct vec {    public:     ld x, y;     bool operator==(const vec& o) const { return equ(x, o.x) && equ(y, o.y); }     vec& operator+=(const vec& o) { return x += o.x, y += o.y, *this; }     vec& operator-=(const vec& o) { return x -= o.x, y -= o.y, *this; }     ld ang() { return atan2(y, x); }     friend vec operator+(vec a, const vec& b) { return a += b; }     friend vec operator-(vec a, const vec& b) { return a -= b; }     ld operator*(const vec& o) const { return x * o.x + y * o.y; }     ld mag() const { return hypot(x, y); }   };   const int MN = 1e5 + 10;   int N, S, P, G, s, p, g, ctr, op;   char t;   vec m, a[MN];   std::multiset<ld> set, val;   std::map<ld, int> map;   int main() {     scanf( %d%d%d%d , &S, &P, &G, &N);     m = vec{(ld)P / (S + P + G), (ld)G / (S + P + G)};     for (int i = 0, x = 0, y; i < N; ++i) {       scanf(  %c , &t);       if (t ==  A ) {         scanf( %d%d%d , &s, &p, &g);         ++x;         a[x] = {(ld)p / (s + p + g), (ld)g / (s + p + g)};         a[x] -= m;         if (a[x].mag() < EPS)           ++ctr;         else {           {             ld v = a[x].ang();             auto it = map.lower_bound(v - EPS);             if (it == map.end() || !equ(it->first, v))               it = map.insert({v, 0}).first;             if (!it->second++) {               v += PI;               if (v > PI) v -= 2 * PI;               it = map.lower_bound(v - EPS);               if (it != map.end() && equ(it->first, v) && it->second) ++op;             }           }           {             ld v = a[x].ang();             auto it = set.insert(v);             auto nx = std::next(it);             if (it != set.begin()) {               auto pr = std::prev(it);               val.insert(*it - *pr);               if (nx != set.end()) val.erase(val.lower_bound(*nx - *pr - EPS));             }             if (nx != set.end()) val.insert(*nx - *it);           }         }       } else {         scanf( %d , &y);         if (a[y].mag() < EPS)           --ctr;         else {           {             ld v = a[y].ang();             auto it = map.lower_bound(v - EPS);             assert(it != map.end() && equ(it->first, v));             if (!--it->second) {               v += PI;               if (v > PI) v -= 2 * PI;               it = map.lower_bound(v - EPS);               if (it != map.end() && equ(it->first, v) && it->second) --op;             }           }           {             ld v = a[y].ang();             auto it = set.lower_bound(v - EPS);             auto nx = std::next(it);             if (it != set.begin()) {               auto pr = std::prev(it);               val.erase(val.lower_bound(*it - *pr - EPS));               if (nx != set.end()) val.insert(*nx - *pr);             }             if (nx != set.end()) val.erase(val.lower_bound(*nx - *it - EPS));             set.erase(it);           }         }       }       if (ctr)         printf( 1 n );       else if (op)         printf( 2 n );       else if (set.size() >= 3 && *val.rbegin() < PI &&                (2 * PI + *set.begin() - *set.rbegin()) < PI)         printf( 3 n );       else         printf( 0 n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX_N = 3e5 + 10, MAX_LOG_N = 20;   const long long MOD1 = 1e9 + 7, BASE1 = 29, MOD2 = 1e9 + 9, BASE2 = 37;   long long sq(long long a, long long p) { return a * a % p; }   long long qpow(long long a, long long b, long long p) {     return b ? sq(qpow(a, b / 2, p), p) * (b & 1 ? a : 1) % p : 1;   }   long long inv(long long a, long long p) { return qpow(a, p - 2, p); }   int N, M, logN, log_table[MAX_N], pa[MAX_N], jmp[MAX_N][MAX_LOG_N],       depth[MAX_N], down_len[MAX_N], chain_content[MAX_N * 2],       *chain_content_alloc = chain_content, *pos[MAX_N];   char S[MAX_N];   long long pow_base1[MAX_N], pow_base1i[MAX_N], pow_base2[MAX_N],       pow_base2i[MAX_N];   long long pref_hash1_up[MAX_N], pref_hash1_down[MAX_N], pref_hash2_up[MAX_N],       pref_hash2_down[MAX_N];   vector<int> edge[MAX_N], child[MAX_N];   void construct_dfs1(int x) {     pref_hash1_down[x] =         (pref_hash1_down[pa[x]] + (S[x] -  a ) * pow_base1[depth[x]]) % MOD1;     pref_hash1_up[x] =         (pref_hash1_up[pa[x]] + (S[x] -  a ) * pow_base1i[depth[x]]) % MOD1;     pref_hash2_down[x] =         (pref_hash2_down[pa[x]] + (S[x] -  a ) * pow_base2[depth[x]]) % MOD2;     pref_hash2_up[x] =         (pref_hash2_up[pa[x]] + (S[x] -  a ) * pow_base2i[depth[x]]) % MOD2;     for (int i : edge[x]) {       if (i == pa[x]) continue;       child[x].push_back(i);       pa[i] = x;       depth[i] = depth[x] + 1;       construct_dfs1(i);       down_len[x] = max(down_len[x], down_len[i]);     }     down_len[x]++;     sort(child[x].begin(), child[x].end(),          [](int a, int b) { return down_len[a] > down_len[b]; });   }   void construct_dfs2(int x) {     vector<int> light;     int y = x;     while (!child[y].empty()) {       for (int i = 1; i < child[y].size(); i++) light.push_back(child[y][i]);       y = child[y][0];     }     chain_content_alloc += 2 * down_len[x];     int *t = chain_content_alloc;     for (int i = 1; i <= 2 * down_len[x]; i++) {       *--t = y;       if (i <= down_len[x]) {         pos[y] = t;       }       y = pa[y];     }     for (int i : light) {       construct_dfs2(i);     }   }   void init() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       log_table[i] = log_table[i - 1];       if (1 << log_table[i] + 1 < i) log_table[i]++;     }     logN = log_table[N];     pow_base1[0] = pow_base1i[0] = pow_base2[0] = pow_base2i[0] = 1;     pow_base1[1] = BASE1;     pow_base1i[1] = inv(BASE1, MOD1);     pow_base2[1] = BASE2;     pow_base2i[1] = inv(BASE2, MOD2);     for (long long *arr : {pow_base1, pow_base1i}) {       for (int i = 2; i <= N; i++) arr[i] = arr[1] * arr[i - 1] % MOD1;     }     for (long long *arr : {pow_base2, pow_base2i}) {       for (int i = 2; i <= N; i++) arr[i] = arr[1] * arr[i - 1] % MOD2;     }     scanf( %s , S + 1);     for (int i = 1; i < N; i++) {       int a, b;       scanf( %d%d , &a, &b);       edge[a].push_back(b);       edge[b].push_back(a);     }     construct_dfs1(1);     for (int i = 1; i <= N; i++) jmp[i][0] = pa[i];     for (int i = 1; i <= logN; i++) {       for (int j = 1; j <= N; j++) {         jmp[j][i] = jmp[jmp[j][i - 1]][i - 1];       }     }     construct_dfs2(1);   }   int kth_ancestor(int x, int k) {     if (k) {       int t = log_table[k];       x = jmp[x][t];       k -= 1 << t;     }     return pos[x][-k];   }   int LCA(int a, int b) {     if (depth[a] > depth[b]) swap(a, b);     b = kth_ancestor(b, depth[b] - depth[a]);     if (a == b) return a;     for (int i = logN; i >= 0; i--) {       if (jmp[a][i] != jmp[b][i]) {         a = jmp[a][i];         b = jmp[b][i];       }     }     return pa[a];   }   long long hash1_up(int a, int b) {     return (pref_hash1_up[a] - pref_hash1_up[pa[b]] + MOD1) *            pow_base1[depth[a]] % MOD1;   }   long long hash1_down(int a, int b) {     return (pref_hash1_down[a] - pref_hash1_down[pa[b]] + MOD1) *            pow_base1i[depth[b]] % MOD1;   }   long long hash1(int a, int b, int c, int len) {     if (len <= depth[a] - depth[b] + 1) {       return hash1_up(a, kth_ancestor(a, len - 1));     } else {       int dis = depth[a] + depth[c] - 2 * depth[b] + 1;       long long res =           hash1_up(a, b) + hash1_down(kth_ancestor(c, dis - len),                                       kth_ancestor(c, depth[c] - depth[b] - 1)) *                                pow_base1[depth[a] - depth[b] + 1];       return res % MOD1;     }   }   long long hash2_up(int a, int b) {     return (pref_hash2_up[a] - pref_hash2_up[pa[b]] + MOD2) *            pow_base2[depth[a]] % MOD2;   }   long long hash2_down(int a, int b) {     return (pref_hash2_down[a] - pref_hash2_down[pa[b]] + MOD2) *            pow_base2i[depth[b]] % MOD2;   }   long long hash2(int a, int b, int c, int len) {     if (len <= depth[a] - depth[b] + 1) {       return hash2_up(a, kth_ancestor(a, len - 1));     } else {       int dis = depth[a] + depth[c] - 2 * depth[b] + 1;       long long res =           hash2_up(a, b) + hash2_down(kth_ancestor(c, dis - len),                                       kth_ancestor(c, depth[c] - depth[b] - 1)) *                                pow_base2[depth[a] - depth[b] + 1];       return res % MOD2;     }   }   void solve() {     int s1, t1, s2, t2;     scanf( %d%d%d%d , &s1, &t1, &s2, &t2);     int c1 = LCA(s1, t1), c2 = LCA(s2, t2);     int l = 0, r = min(depth[s1] + depth[t1] - 2 * depth[c1] + 1,                        depth[s2] + depth[t2] - 2 * depth[c2] + 1);     while (l != r) {       int m = (l + r + 1) / 2;       if (hash1(s1, c1, t1, m) == hash1(s2, c2, t2, m) &&           hash2(s1, c1, t1, m) == hash2(s2, c2, t2, m)) {         l = m;       } else {         r = m - 1;       }     }     printf( %d n , l);   }   int main() {     init();     scanf( %d , &M);     for (int i = 1; i <= M; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   long long nexta, nextb;   long long d, m;   int main() {     cin >> a >> b;     nexta = a;     nextb = b;     long long cur = 0;     while (nexta != nextb)       if (nexta < nextb) {         d += nexta - cur;         cur = nexta;         nexta += a;       } else {         m += nextb - cur;         cur = nextb;         nextb += b;       }     if (a > b)       d += nexta - cur;     else       m += nextb - cur;     if (d > m)       cout <<  Dasha n ;     else if (d < m)       cout <<  Masha n ;     else       cout <<  Equal n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %  PRId64, &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <typename T, typename... X>   void R(T &head, X &...tail) {     _R(head);     R(tail...);   }   const int N = 7005;   int stat[2][N], n, t[2], arr[2][N], cnt[2][N];   char str[3][10] = { Loop ,  Win ,  Lose };   void dfs(int who, int pos, int st) {     if (stat[who][pos]) return;     stat[who][pos] = st;     ;     if (st == 1)       for (int i = 0; i < t[1 - who]; i++) {         int pre = (pos - arr[1 - who][i] + n) % n;         if (--cnt[1 - who][pre] == 0) dfs(1 - who, pre, 2);       }     else       for (int i = 0; i < t[1 - who]; i++) {         int pre = (pos - arr[1 - who][i] + n) % n;         dfs(1 - who, pre, 1);       }   }   void print() {     for (int i = 0; i < 2; i++)       for (int j = 1; j < n; j++)         printf( %s%c , str[stat[i][j]],    n [j == n - 1]);   }   int main() {     R(n);     for (int i = 0; i < 2; i++) {       R(t[i]);       for (int j = 0; j < t[i]; j++) R(arr[i][j]);     }     for (int i = 0; i < 2; i++)       for (int j = 0; j < n; j++) cnt[i][j] = t[i];     stat[0][0] = stat[1][0] = 2;     for (int i = 0; i < 2; i++)       for (int j = 0; j < t[i]; j++) dfs(i, n - arr[i][j], 1);     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int kk[7];   int main() {     string s;     cin >> s;     int n = s.length();     sort(s.begin(), s.end());     for (int i = 0, j; i < n; i = j) {       j = i + 1;       while (j < n && s[j] == s[i]) j++;       kk[j - i]++;     }     int ans;     if (kk[6] == 1 || kk[5] == 1 && kk[1] == 1)       ans = 1;     else if (kk[4] == 1 || kk[3] == 2)       ans = 2;     else if (kk[3] == 1 && kk[2] == 1 && kk[1] == 1)       ans = 3;     else if (kk[3] == 1 && kk[1] == 3)       ans = 5;     else if (kk[2] == 3)       ans = 6;     else if (kk[2] == 2 && kk[1] == 2)       ans = 8;     else if (kk[2] == 1 && kk[1] == 4)       ans = 15;     else       ans = 30;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int a, b, x, y, n;       cin >> a >> b >> x >> y >> n;       cout << min(max(x, a - n) * max(y, b - n + min(n, a - x)),                   max(y, b - n) * max(x, a - n + min(n, b - y)))            << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     string s;     cin >> s;     if (n % 4 != 0) {       cout <<  === ;       return 0;     }     vector<long long> v(5, 0);     for (long long i = 0; i < n; i++) {       if (s[i] ==  A ) {         v[0]++;       }       if (s[i] ==  C ) {         v[1]++;       }       if (s[i] ==  G ) {         v[2]++;       }       if (s[i] ==  T ) {         v[3]++;       }       if (s[i] ==  ? ) {         v[4]++;       }     }     long long max1 = max(v[0], max(v[1], v[2]));     long long maxov = max(max1, v[3]);     long long reqd = 4 * maxov - v[0] - v[1] - v[2] - v[3];     bool check = false;     if (v[4] >= reqd && (v[4] - reqd) % 4 == 0) {       check = true;     }     if (check == false) {       cout <<  === ;     } else {       long long reqda = maxov - v[0] + ((v[4] - reqd) / 4);       long long reqdc = maxov - v[1] + ((v[4] - reqd) / 4);       long long reqdg = maxov - v[2] + ((v[4] - reqd) / 4);       long long reqdt = maxov - v[3] + ((v[4] - reqd) / 4);       for (long long i = 0; i < n; i++) {         if (s[i] !=  ? ) {           cout << s[i];         } else {           if (reqda > 0) {             cout <<  A ;             reqda--;             continue;           }           if (reqdc > 0) {             cout <<  C ;             reqdc--;             continue;           }           if (reqdg > 0) {             cout <<  G ;             reqdg--;             continue;           }           if (reqdt > 0) {             cout <<  T ;             reqdt--;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t v[200005] = {0};   int64_t fnc(int64_t h, int n) {     int64_t mn = v[0];     for (int i = 1; i < n; i++) {       v[i] += v[i - 1];       mn = min(mn, v[i]);     }     if (v[n - 1] >= 0 && h + mn > 0) return -1;     int64_t ans = 0;     if (h + mn <= 0) {       for (int i = 0; i < n; i++)         if (h + v[i] <= 0) return i + 1;     }     int64_t t = ceil(((-mn - h) * 1.0) / v[n - 1]);     if (t < 0) t = 0;     ans += n * t;     h = h + t * v[n - 1];     for (int i = 0; i < n; i++) {       if (h + v[i] <= 0) {         ans += i + 1;         break;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int m;     int64_t h;     cin >> h >> m;     for (int i = 0; i < m; i++) cin >> v[i];     cout << fnc(h, m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, k, ans = 1e11;     string s;     cin >> n;     if (n == 1 || n == 2) {       cout <<  No  << endl;       return 0;     }     cout <<  Yes  << endl;     set<long long> s1, s2;     for (long long i = 1; i < n + 1; i++) {       i % 2 ? s1.insert(i) : s2.insert(i);     }     cout << s2.size() <<    ;     for (auto i : s2) cout << i <<    ;     cout << endl;     cout << s1.size() <<    ;     for (auto i : s1) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int64_t> v[3001];   int64_t calc(int64_t taken, int64_t n, int64_t m) {     int64_t req = taken - v[0].size();     int64_t t = v[0].size();     int64_t ans = 0;     vector<int64_t> rem;     for (int64_t i = 1; i < m; i++) {       if (v[i].size() == 0) continue;       for (int64_t j = 0; j < v[i].size(); j++) {         if (j + taken <= v[i].size()) {           ans += v[i][j];           req--;         } else           rem.push_back(v[i][j]);       }     }     if (req > 0) {       sort(rem.begin(), rem.end());       int64_t i = 0;       while (req > 0 and i < rem.size()) {         ans += rem[i];         i++;         req--;       }     }     return ans;   }   void solve() {     int64_t n, m, i, ans;     cin >> n >> m;     for (int64_t i = 0; i < n; i++) {       int64_t p, c;       cin >> p >> c;       p--;       v[p].push_back(c);     }     for (int64_t i = 0; i < m; i++) {       sort(v[i].begin(), v[i].end());     }     ans = LLONG_MAX;     for (int64_t i = 1; i <= n; i++) {       int64_t curr_cost = calc(i, n, m);       ans = min(ans, curr_cost);     }     cout << ans <<   n ;   }   signed main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     cerr <<   Execution :   << (1.0 * clock()) / CLOCKS_PER_SEC <<  s  n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   long long n, m, b, ans;   long long a[1005];   int l, r, mid;   long long dp[1005][1005];   struct Node {     long long w, id;   } f[1005];   bool cmp(Node a, Node b) {     if (a.w != b.w) return a.w < b.w;     return a.id > b.id;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n + 1; ++i)       for (int j = 0; j <= n + 1; ++j) dp[i][j] = 1e18;     dp[n + 1][0] = 0;     for (int i = n; i >= 1; --i) {       for (int j = 0; j <= n; ++j)         dp[i][j] = min(dp[i][j], max(0LL, dp[i + 1][j] - a[i]));       for (int j = 1; j <= n; ++j) dp[i][j] = min(dp[i][j], dp[i + 1][j - 1]);     }     for (int i = 0; i <= n; ++i) {       f[i].w = dp[1][i];       f[i].id = i;     }     sort(f, f + n + 1, cmp);     for (int i = 1; i <= m; ++i) {       cin >> b;       l = 0;       r = n;       ans = -1;       while (l <= r) {         mid = (l + r) / 2;         if (f[mid].w <= b) {           ans = f[mid].id;           l = mid + 1;         } else           r = mid - 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     double y1, y2, yw, xb, yb, r, A, B, C;     scanf( %lf%lf%lf%lf%lf%lf , &y1, &y2, &yw, &xb, &yb, &r);     yw -= r;     y1 += r;     yb = 2 * yw - yb;     A = y1 - yb;     B = xb;     C = -B * y1 + B * y2;     if ((C / sqrt(A * A + B * B)) <= r) {       printf( -1 );       return 0;     }     C = -B * y1;     printf( %.10lf , (-C - B * yw) / A);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[200010], t[200010], pos[200010], ans[200010];   struct point {     int pos, v, f;     point(int pos, int v, int f) : pos(pos), v(v), f(f) {}   };   vector<point> v[200010];   inline void insert(int x) {     for (register int i = x; i <= n; i += i & -i) t[i]++;   }   inline int find(int x) {     register int ans = 0;     for (register int i = x; i; i -= i & -i) ans += t[i];     return ans;   }   inline void add(int x, int y, int f, int i) { v[x].push_back(point(i, y, f)); }   inline int read() {     register int x = 0, ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   int main() {     n = read(), m = read();     for (register int i = 1; i <= n; i++) pos[a[i] = read()] = i;     for (register int i = 1; i <= m; i++) {       int l = read(), r = read();       add(r, r, 1, i), add(l - 1, r, -1, i), add(r, l - 1, -1, i),           add(l - 1, l - 1, 1, i);     }     for (register int i = 1; i <= n; i++) {       for (register int j = a[i]; j <= n; j += a[i]) insert(pos[j]);       for (register int j = 0; j < v[i].size(); j++)         ans[v[i][j].pos] += find(v[i][j].v) * v[i][j].f;     }     for (register int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     vector<pair<int, int> > v(n), ans;     for (int i = 0; i < n; ++i) cin >> v[i].first, v[i].second = i;     while (k--) {       sort(v.begin(), v.end());       if (v.back().first - v[0].first > 1)         --v.back().first, ++v[0].first,             ans.push_back({v.back().second, v[0].second});     }     sort(v.begin(), v.end());     cout << v.back().first - v[0].first <<     << ans.size() <<   n ;     for (auto it : ans) cout << it.first + 1 <<     << it.second + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, x;     cin >> n >> x;     x--;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     long long mn = a[x];     for (long long i = 0; i < n; i++) {       if (a[i] < mn) {         mn = a[i];       }     }     long long ans = mn * n;     while (a[x] != mn) {       a[x]--;       ans++;       x--;       if (x < 0) x = n - 1;     }     for (long long i = 0; i < n; i++) cout << (i == x ? ans : a[i] - mn) <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 10;   int n, k, m, kk, x, b[M];   int main() {     int T;     cin >> T;     while (T--) {       cin >> n >> k;       kk = 1;       m = 0;       for (int i = 1; i <= n; i++) {         cin >> x;         if (x % 2) {           m++;           if (kk < k) {             b[kk] = i;             kk++;           }         }       }       if ((m - k + 1) % 2 == 1 && kk == k) {         cout <<  YES  << endl;         for (int i = 1; i < kk; i++) cout << b[i] <<    ;         cout << n << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, 1, 0, -1};   bool myComparison1(const pair<long long, long long> &a,                      const pair<long long, long long> &b) {     return a.second < b.second;   }   bool myComparison2(const pair<long long, long long> &a,                      const pair<long long, long long> &b) {     if (a.first == b.first) {       return (a.second < b.second);     }     return (a.first < b.first);   }   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long expo(long long n, long long m, long long p) {     long long r = 1;     n = n % p;     while (m > 0) {       if (m % 2) r = (r * n) % p;       n = (n * n) % p;       m = m / 2;     }     return r % p;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<long long> z_function(string s) {     long long n = (long long)s.length();     vector<long long> z(n);     for (long long i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   long long distance(long long x, long long y) { return (sqrt(x * 2 + y * 2)); }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     vector<long long> x, y;     for (long long i = 0; i < n; i++) {       long long c, d;       cin >> c >> d;       x.push_back(c);       y.push_back(d);     }     long long max = -1;     long long X = 0, Y = 0;     for (long long i = 0; i < n; i++) {       if (x[i] + y[i] > max) {         X = x[i];         Y = y[i];         max = X + Y;       }     }     cout << max;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     srand(time(NULL));     ;     int T = 1;     while (T--) {       int a[3];       for (int i = 0; i < int(3); i++) cin >> a[i];       sort(a, a + 3);       cout << a[2] - a[0];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[5];   int c[100];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> a[0] >> a[1];     for (int i = 1; i <= n; i++) cin >> c[i];     int m = min(a[0], a[1]);     int ans = 0;     for (int i = 1; i <= n / 2 + n % 2; i++) {       if (c[i] == 2 && c[n - i + 1] == 2) {         if (i != n / 2 + n % 2)           ans += 2 * m;         else if (n % 2 == 0)           ans += 2 * m;         else           ans += m;       } else if (c[i] == 2)         ans += a[c[n - i + 1]];       else if (c[n - i + 1] == 2)         ans += a[c[i]];       else if (c[i] != c[n - i + 1]) {         cout << -1;         return 0;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 510;   bitset<510> can[maxn][2][64];   int N, M;   long long ans, best[maxn][2];   inline long long dfs(int now, int last) {     if (best[now][last ^ 1] != -1)       return best[now][last ^ 1];     else       best[now][last ^ 1] = 0;     for (int i = 59; i >= 0; --i)       if (can[now][last ^ 1][i].any()) {         for (int j = 1; j <= N; ++j)           if (can[now][last ^ 1][i][j])             best[now][last ^ 1] =                 max(dfs(j, last ^ 1) + (1LL << i), best[now][last ^ 1]);         break;       }     return best[now][last ^ 1];   }   int main() {     scanf( %d %d , &N, &M);     while (M--) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       can[a][c][0][b] = 1;     }     for (int i = 1; i <= 62; ++i)       for (int j = 1; j <= N; ++j)         for (int k = 0; k < 2; ++k)           for (int l = 1; l <= N; ++l) {             if (!can[j][k][i - 1][l]) continue;             can[j][k][i] |= can[l][k ^ 1][i - 1];           }     for (int i = 1; i <= N; ++i)       if (can[i][0][60].any()) puts( -1 ), exit(0);     memset(best, -1, sizeof(best));     for (int i = 1; i <= N; ++i) ans = max(ans, dfs(i, 1));     if (ans > 1000000000000000000LL) ans = -1;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int vis[maxn], p[maxn];   int plen;   void prime() {     memset(vis, 0, sizeof(vis));     plen = 0;     for (int i = 2, k = 4; i < maxn; ++i, k += i + i - 1) {       if (!vis[i]) {         p[plen++] = i;         if (k < maxn) {           for (int j = k; j < maxn; j += i) {             vis[j] = 1;           }         }       }     }   }   struct node {     int id;     int cnt;     int color;   } need[maxn];   bool cmp(const node &a, const node &b) { return a.cnt > b.cnt; }   bool cmp1(const node &a, const node &b) { return a.id < b.id; }   char buf[maxn], out[maxn];   int cnt[maxn];   int main(int argc, char *argv[]) {     prime();     while (scanf( %s , buf) != EOF) {       memset(vis, -1, sizeof(vis));       memset(cnt, 0, sizeof(cnt));       int len = strlen(buf);       for (int i = 0; i < len; i++) {         cnt[buf[i] -  a ]++;       }       int colornum = 0;       for (int i = 0; i < plen && p[i] <= len; i++) {         int color = -1;         for (int j = 1; j <= len / p[i]; j++) {           if (vis[j * p[i]] != -1) {             color = vis[j];             break;           }         }         if (color == -1) {           color = colornum++;         }         for (int j = 1; j <= len / p[i]; j++) {           vis[j * p[i]] = color;         }       }       for (int i = 0; i < maxn; i++) {         need[i].id = i;         need[i].cnt = 0;       }       for (int i = 2; i <= len; i++) {         need[vis[i]].cnt++;       }       sort(need, need + colornum, cmp);       int flag = 0;       for (int i = 0; i < colornum; i++) {         int maxcolor = 0, k = -1;         for (int j = 0; j < 26; j++) {           if (cnt[j] > maxcolor) {             maxcolor = cnt[j];             k = j;           }         }         if (k == -1 || maxcolor < need[i].cnt) {           flag = 1;           break;         } else {           need[i].color = k;           cnt[k] -= need[i].cnt;         }       }       if (!flag) {         printf( YES n );         for (int i = 0; i < 26; i++) {           if (cnt[i]) {             out[1] = i +  a ;             break;           }         }         sort(need, need + colornum, cmp1);         for (int i = 2; i <= len; i++) {           out[i] = need[vis[i]].color +  a ;         }         out[len + 1] = 0;         printf( %s n , out + 1);       } else {         printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int readInt() {     bool minus = false;     int result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       minus = true;     else       result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = result * 10 + (ch -  0 );     }     if (minus)       return -result;     else       return result;   }   template <class T>   T mulmod(T a, T b) {     if (b == 0) return 0;     if (b == 1) return a;     T x = mulmod(a, b >> 1);     x = (x + x) % 1000000007;     if (b & 1) x = (x + a) % 1000000007;     return x;   }   template <class T>   T larger(T a, T b) {     return (a > b ? a : b);   }   template <class T>   T smaller(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   template <class T>   string converter(T n) {     stringstream x;     x << n;     return x.str();   }   template <class T>   T pw(T a, T b) {     if (b == 0) return 1;     T x = pw(a, b >> 1);     x = (x * x) % 1000000007;     if (b & 1) x = (x * a) % 1000000007;     return x;   }   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   char totalDiff(char a, char b) {     for (char c =  a ; c <=  z ; c++)       if (c != a && c != b) return c;   }   void letsgo() {     int n, t;     cin >> n >> t;     string a, b, c;     cin >> a >> b;     int i, same = 0;     for (i = 0; i < n; i++) {       same += (a[i] == b[i]);     }     c =   ;     if (same >= n - t) {       int j = n - t;       for (i = 0; i < n; i++) {         if (a[i] == b[i] && j)           c.push_back(a[i]), j--;         else           c.push_back(totalDiff(a[i], b[i]));       }       cout << c;       return;     }     int j = n - t - same;     int l = j;     int k = same;     if (2 * j > n - same) {       cout << -1;       return;     }     for (i = 0; i < n; i++) {       if (a[i] == b[i] && k) {         c.push_back(a[i]);         k--;       } else if (j) {         c.push_back(a[i]);         j--;       } else if (l) {         c.push_back(b[i]);         l--;       } else {         c.push_back(totalDiff(a[i], b[i]));       }     }     cout << c;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     letsgo();     int t;     cin >> t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       long long int i, j, k, y, n, x, m, a, b, ans = 0, sum = 0, cnt = 0;       long long int c, mx = 0;       string s, z, taj =  YES ;       cin >> s;       map<char, long long int> mp;       n = s.size();       for (i = 0; i < n; i++) mp[s[i]]++;       if (!mp[ 4 ] and !mp[ 7 ])         cout << -1;       else if (mp[ 4 ] >= mp[ 7 ])         cout << 4;       else         cout << 7;       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[11][100010];   int vmap[11][100010];   int pointer[11];   int main() {     int n, m;     scanf( %d %d , &n, &m);     long long ans = 0;     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) {         scanf( %d , &v[j][i]);         v[j][i]--;         vmap[j][v[j][i]] = i;       }     }     bool isNew = true;     long long sz;     for (int i = 0; i < n; i++) {       if (isNew) {         for (int j = 1; j < m; j++) pointer[j] = vmap[j][v[0][i]];         sz = 1;         ans += 1;         isNew = false;       } else {         bool check = true;         sz++;         for (int j = 1; j < m && check; j++) {           pointer[j]++;           if (pointer[j] >= n || v[j][pointer[j]] != v[0][i]) check = false;         }         if (check)           ans += sz;         else {           isNew = true;           i--;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int n, s;   int a[N];   int vis[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> s;     for (int i = 0; i < n; ++i) cin >> a[i];     int cnt = 0;     if (a[s - 1]) {       cnt++;       a[s - 1] = 0;     }     sort(a, a + n);     memset(vis, false, sizeof false);     vis[0] = true;     for (int i = 1; i < n; ++i) vis[a[i]] = true;     int cmax = 0;     for (int i = 1; i < n; ++i) {       if (!a[i]) {         while (cmax < n && vis[cmax]) cmax++;         if (cmax < n) {           vis[cmax] = true;         }         cnt++;       } else {         int pos = n - 1;         for (int j = i; j <= pos; ++j) {           if (!vis[a[j] - 1]) {             while (pos > j && cmax < a[j] - 1) {               while (cmax < a[j] - 1 && vis[cmax]) cmax++;               vis[cmax] = true;               pos--;               cnt++;               if (cmax == a[j] - 1) break;             }             if (!vis[a[j] - 1]) {               while (cmax < a[j] - 1 && vis[cmax]) cmax++;               vis[cmax] = true;               cnt++;             }           }         }         break;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n], i;     for (i = 0; i < n; i++) cin >> arr[i];     int ind = 0, price;     int max = arr[0];     for (i = 1; i < n; i++) {       if (arr[i] > max) {         max = arr[i];         ind = i;       }     }     sort(arr, arr + n);     price = arr[n - 2];     cout << ind + 1 <<     << price;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   template <typename T>   static inline void sd(vector<T> &x) {     sort((x).begin(), (x).end(), greater<T>());   }   long long n, m;   const long long N = 3e5 + 5;   vector<long long> g[N];   vector<long long> dep(N), parent(N), vis(N);   void dfs(long long v, long long par = -1) {     vis[v] = 1;     for (long long ch : g[v]) {       if (ch != par and !vis[ch]) {         dep[ch] = dep[v] + 1;         parent[ch] = v;         dfs(ch, v);       }     }   }   void solve() {     cin >> n >> m;     for (long long i = 0; i < n + 1; ++i) {       g[i].clear();       vis[i] = 0;     }     auto path = [&](long long a, long long b) {       bool flag = false;       if (dep[a] < dep[b]) {         swap(a, b);         flag = true;       }       vector<long long> v[2];       while (dep[a] > dep[b]) {         v[0].push_back(a);         a = parent[a];       }       while (a != b) {         v[0].push_back(a);         v[1].push_back(b);         a = parent[a];         b = parent[b];       }       v[0].push_back(a);       while (!v[1].empty()) {         v[0].push_back(v[1].back());         v[1].pop_back();       }       if (flag) {         reverse(v[0].begin(), v[0].end());       }       return v[0];     };     vector<long long> cnt(n + 1);     for (long long i = 0; i < m; ++i) {       long long e, f;       cin >> e >> f;       g[e].push_back(f);       g[f].push_back(e);     }     dfs(1);     vector<vector<long long> > output;     long long q;     cin >> q;     for (long long j = 0; j < q; ++j) {       long long a, b;       cin >> a >> b;       cnt[a]++;       cnt[b]++;       output.push_back(path(a, b));     }     long long k = 0;     for (long long i = 1; i < n + 1; ++i) {       if ((cnt[i] & 1) == 1) {         k++;       }     }     if (k == 0) {       cout <<  YES n ;       for (auto &i : output) {         cout << i.size() <<   n ;         for (long long j : i) {           cout << j <<    ;         }         cout <<   n ;       }     } else {       cout <<  NO n ;       cout << k / 2 <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long testcases = 1;     while (testcases--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3f;   template <typename T>   inline void read(T& X) {     X = 0;     int w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     if (w) X = -X;   }   long long a[20], p[20];   int main() {     int t;     for (int i = 0; i <= 9; i++) p[i] = pow(10, i);     scanf( %d , &t);     while (t--) {       long long k, n;       long long ans = 0;       scanf( %lld %lld , &n, &k);       for (int i = 1; i <= n; i++) {         scanf( %lld , &a[i]);         a[i] = p[a[i]];       }       for (int i = 1; i <= n; i++) {         if (i == n) {           ans = ans + (k + 1) * a[i];           break;         }         long long now = (a[i + 1] - a[i]) / a[i];         if (now <= k) {           ans = ans + a[i + 1] - a[i];           k = k - now;         } else {           ans = ans + a[i] * (k + 1);           break;         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   long long n, a[N], dp[2][N], mini[2][N];   vector<long long> v;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back(x);       a[i] = x;     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= v.size(); j++) {         int r = i % 2;         dp[r][j] = mini[1 - r][j] + abs(a[i - 1] - v[j - 1]);         if (j == 1) {           mini[r][j] = dp[r][j];         } else           mini[r][j] = min(dp[r][j], mini[r][j - 1]);       }     }     cout << mini[n % 2][v.size()];     cin.get();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int p;     cin >> p;     while (p--) {       int y = 0, n, z = 0, x = 0;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] == 0) z++;       }       for (int i = 0; i < n; i++) {         if (a[i] == 1)           break;         else           x++;       }       for (int i = n - 1; i >= 0; i--) {         if (a[i] == 1)           break;         else           x++;       }       cout << z - x - y <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[210000];   long long dp[210000][2];   const long long INF = 1LL << 60;   int N;   void init() {     for (int i = 0; i < 210000; i++)       for (int j = 0; j < 2; j++) dp[i][j] = INF;   }   long long solve(int x, bool t) {     if (x <= 0 || x > N) return 0;     if (x == 1) return -1;     if (dp[x][t] == -INF) return dp[x][t] = -1;     if (dp[x][t] != INF) return dp[x][t];     dp[x][t] = -INF;     int i2 = x;     if (t)       i2 += a[x];     else       i2 -= a[x];     long long r = solve(i2, !t);     long long res;     if (r == -1)       res = -1;     else       res = a[x] + r;     return dp[x][t] = res;   }   int main() {     cin >> N;     for (int i = 0; i < N - 1; i++) cin >> a[i + 2];     init();     for (int i = 1; i < N; i++) {       long long r = solve(1 + i, 0);       if (r != -1) r += i;       cout << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, x, y, z;     scanf( %d%d%d%d%d%d , &a, &b, &c, &x, &y, &z);     bool can = true;     int more = 0;     int less = 0;     if (a > x)       more += (a - x) / 2;     else       less += x - a;     if (b > y)       more += (b - y) / 2;     else       less += y - b;     if (c > z)       more += (c - z) / 2;     else       less += z - c;     if (more >= less)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long N, T;     cin >> N;     list<long long> L;     for (int i = 0; i < N; i++) {       cin >> T;       L.push_back(T);     }     long long K, possible = 1, curr = -1, orig = 0;     cin >> K;     vector<pair<long long, long long> > operations;     long long sum = *L.begin();     list<long long>::iterator it = L.begin();     for (int i = 0; i < K && possible; i++) {       cin >> T;       ++curr;       list<long long> L2;       if (it == L.end())         possible = 0;       else {         sum = *it;         if (T != sum) {           if (T < sum)             possible = 0;           else {             sum = 0;             long long maz = *it;             while (it != L.end() && T > sum) {               sum += *it;               L2.push_back(*it);               maz = max(maz, *it);               it++;             }             if (T != sum)               possible = 0;             else {               list<long long>::iterator it2 = L2.begin();               while (it2 != L2.end() && *it2 != maz) ++it2, ++curr;               if (it2 == L2.begin()) {                 if (it2 != L2.end()) ++it2;                 ++curr;                 while (it2 != L2.end() && *it2 == maz) ++it2, ++curr;                 if (it2 == L2.end())                   possible = 0;                 else {                   list<long long>::iterator it3 = it2;                   --it2;                   --curr;                   do {                     operations.push_back(make_pair(curr, 1));                     ++it3;                   } while (it3 != L2.end());                   while (it2 != L2.begin()) {                     --it2;                     operations.push_back(make_pair(curr, 0));                     --curr;                   }                 }               } else if (it2 == L2.end())                 possible = 0;               else {                 list<long long>::iterator it3 = it2;                 do {                   --it3;                   operations.push_back(make_pair(curr, 0));                   --curr;                 } while (it3 != L2.begin());                 ++it2;                 while (it2 != L2.end()) {                   operations.push_back(make_pair(curr, 1));                   ++it2;                 }               }             }           }         } else           ++it;       }     }     if (it != L.end() || operations.size() != N - K) possible = 0;     if (possible) {       cout <<  YES  << endl;       for (int i = 0; i < operations.size(); i++) {         cout << operations[i].first + 1 <<                  << (operations[i].second == 0 ?  L  :  R ) << endl;       }     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4;   vector<int> e[N];   int n, siz[N];   long long ans;   int sn = 0, sx = 0;   int en[N], ex[N];   void dfs(int u, int fa) {     siz[u] = 1;     for (auto v : e[u]) {       if (v == fa) continue;       dfs(v, u);       siz[u] += siz[v];       en[u] += en[v];       ans += 1ll * ex[u] * en[v] * siz[v];     }     ans += 1ll * ex[u] * (sn - en[u]) * (n - siz[u]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       e[u].push_back(v);       e[v].push_back(u);     }     for (int i = 1; i <= n; i++)       scanf( %d %d , &en[i], &ex[i]), sn += en[i], sx += ex[i];     dfs(1, 0);     printf( %.10f n , (double)(ans / (1.0 * sx * sn)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   string S, P;   int dp[2001][2002], dp1[2001][2011], len[2001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long a, b, c, d = 0, e, f = 0, g, h = 0, x, y, z = 0;     cin >> S >> P;     a = S.size(), b = P.size();     for (int i = (0); i < (b); ++i) dp1[a][i] = 1000000;     for (int i = a - 1; i >= 0; i--) {       for (int j = 0; j < b; j++) {         if (S[i] == P[j]) {           dp1[i][j] = dp1[i + 1][j + 1];         } else           dp1[i][j] = 1 + dp1[i + 1][j];       }       len[i] = dp1[i][0];     }     for (int i = 1; i <= a; i++) dp[a][i] = -100000;     for (int i = a - 1; i >= 0; i--) {       for (int j = 0; j <= a; j++) {         dp[i][j] = -100000;         if (j > (a - i)) {           continue;         }         dp[i][j] = max(dp[i][j], dp[i + 1][j]);         if (j > 0) dp[i][j] = max(dp[i][j], dp[i + 1][j - 1]);         if (len[i] <= j && (i + len[i] + b) <= a)           dp[i][j] = max(dp[i][j], 1 + dp[i + len[i] + b][j - len[i]]);       }     }     for (int i = 0; i <= a; i++) cout << dp[0][i] <<    ;     cout << endl;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   ll n,m,pos,qwq,delta,a[1009],b[1009],p[1009][1009];   inline ll read(){    ll s = 0,w = 1;    char ch = getchar();    while (ch >  9  || ch <  0 ){ if (ch ==  - ) w = -1; ch = getchar();}    while (ch <=  9  && ch >=  0 ) s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar();    return s * w;   }   int main(){    m = read(),n = read();    for (ll i = 1;i <= n;i += 1) for (ll j = 1;j <= m;j += 1) p[i][j] = read(),a[i] += p[i][j],b[i] += p[i][j] * p[i][j];    for (ll i = 2;i < n;i += 1) if (a[i] - a[i - 1] != (a[n] - a[1]) / (n - 1)){pos = i,delta = a[i] - a[i - 1] - (a[n] - a[1]) / (n - 1); break;}    if (pos <= 3) qwq = b[n - 2] + b[n] - 2 * b[n - 1];    else qwq = b[1] + b[3] - 2 * b[2];    for (ll i = 1;i <= m;i += 1) if (b[pos - 1] + b[pos + 1] - 2 * (b[pos] - p[pos][i] * p[pos][i] + (p[pos][i] - delta) * (p[pos][i] - delta)) == qwq){printf( %lld %lld ,pos - 1,p[pos][i] - delta); return 0;}    return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(long long &x) {     char ch = getchar();     x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();   }   const long long N = 2e5 + 10;   long long n, mx, rt, tmp, sum, f[N], fr[N], tot, st[N], fl[N], p[N];   long long cnt, h[N], to[N << 1], nxt[N << 1], len[N << 1], d[N], vis[N];   void add(long long u, long long v, long long l) {     to[++cnt] = v, len[cnt] = l, nxt[cnt] = h[u], h[u] = cnt;     to[++cnt] = u, len[cnt] = l, nxt[cnt] = h[v], h[v] = cnt;   }   void dfs(long long u, long long la) {     if (d[u] > d[mx]) mx = u;     fr[u] = la;     for (long long i = h[u], v; i; i = nxt[i]) {       if ((v = to[i]) == la) continue;       fl[v] = len[i], d[v] = d[u] + len[i], dfs(v, u);     }   }   void get_dis(long long u, long long deep) {     f[u] = deep;     vis[u] = 1;     for (long long i = h[u]; i; i = nxt[i])       if (!vis[to[i]]) get_dis(to[i], deep + len[i]);   }   long long ff[N], dp[N];   void get_fa(long long u, long long deep) {     dp[u] = deep;     for (long long i = h[u], v; i; i = nxt[i])       if ((v = to[i]) != ff[u]) ff[v] = u, get_fa(v, deep + 1);   }   bool cmp(long long x, long long y) {     return f[x] == f[y] ? dp[x] < dp[y] : f[x] < f[y];   }   long long fa[N], sz[N];   long long find(long long x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); }   void work(long long l) {     long long res = 0;     for (long long i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;     for (long long i = n, j = n; i >= 1; --i) {       while (f[p[j]] > f[p[i]] + l) --sz[find(p[j--])];       res = max(res, sz[p[i]]);       fa[p[i]] = find(ff[p[i]]);       sz[find(ff[p[i]])] += sz[p[i]];     }     printf( %lld n , res);   }   signed main() {     read(n);     for (long long i = 1, u, v, l; i < n; ++i)       read(u), read(v), read(l), add(u, v, l);     dfs(1, 0);     d[mx] = fl[mx] = 0, dfs(mx, 0);     while (mx) sum += fl[mx], st[++tot] = mx, vis[mx] = 1, mx = fr[mx];     long long now = 0, mn = 1e15;     for (long long i = 1; i <= tot; ++i) {       get_dis(st[i], max(now, sum - now));       if (max(now, sum - now) < mn) mn = max(now, sum - now), rt = st[i];       now += fl[st[i]];     }     get_fa(rt, 0);     for (long long i = 1; i <= n; ++i) p[i] = i;     sort(p + 1, p + n + 1, cmp);     long long m, x;     read(m);     while (m--) read(x), work(x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct E {     int x, y;   };   E map1[1010], map2[1010], map3[1010];   int vis[1010];   int n, flag;   void dfs(int k) {     if (k == n + 1) {       cout << map3[n].x <<     << map3[n].y;       flag = 1;       return;     } else {       for (int i = 1; i <= n; i++) {         if (!vis[i]) {           if (map1[k].x + map2[i].x == map3[k - 1].x &&               map1[k].y + map2[i].y == map3[k - 1].y) {             vis[i] = 1;             map3[k].x = map1[k].x + map2[i].x;             map3[k].y = map1[k].y + map2[i].y;             dfs(k + 1);             if (flag) {               break;             }             vis[i] = 0;           }         }       }     }   }   int main(int argc, char *argv[]) {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> map1[i].x >> map1[i].y;     }     for (int i = 1; i <= n; i++) {       cin >> map2[i].x >> map2[i].y;     }     for (int i = 1; i <= n; i++) {       map3[1].x = map1[1].x + map2[i].x;       map3[1].y = map1[1].y + map2[i].y;       vis[i] = 1;       dfs(2);       vis[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char arr[205];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     for (int i = (0); i < (n); i++) cin >> arr[i];     long long res = 0;     pair<int, int> udlr;     for (int i = (0); i < (n); i++) {       udlr.first = 0;       udlr.second = 0;       for (int j = (i); j < (n); j++) {         if (arr[j] ==  U ) udlr.first += 1;         if (arr[j] ==  D ) udlr.first -= 1;         if (arr[j] ==  L ) udlr.second += 1;         if (arr[j] ==  R ) udlr.second -= 1;         if (udlr.second == 0 && udlr.first == 0) res++;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long double pi = acos(-1.0);   const long double log23 = 1.58496250072115618145373894394781;   const long double eps = 1e-8;   const long long INF = 1e18 + 239;   const long long prost = 239;   const int two = 2;   const int th = 3;   const long long MOD = 998244353;   const long long MOD2 = MOD * MOD;   const int BIG = 1e9 + 239;   const int alf = 26;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   const int dxb[4] = {-1, 1, 1, -1};   const int dyb[4] = {-1, 1, -1, 1};   const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   const int dig = 10;   const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};   const long long bt = 62;   template <typename T>   inline T gcd(T a, T b) {     while (a) {       b %= a;       swap(a, b);     }     return b;   }   template <typename T>   inline T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   inline bool is_down(char x) { return ( a  <= x && x <=  z ); }   inline bool is_upper(char x) { return ( A  <= x && x <=  Z ); }   inline bool is_digit(char x) { return ( 0  <= x && x <=  9 ); }   mt19937_64 rnd(239);   const int M = 3e5 + 239;   const int N = 2e3 + 239;   const int L = 103;   const int T = (1 << 18);   const int B = trunc(sqrt(M)) + 1;   const int X = 1e4 + 239;   long long dp[two][M];   int n, kol;   vector<int> v[M];   long long pref[M], suf[M], now, fl[M];   void dfs(int p, int pr) {     for (int i : v[p])       if (i != pr) dfs(i, p);     dp[0][p] = 1;     for (int i : v[p])       if (i != pr) dp[0][p] = (dp[0][p] * (dp[0][i] + dp[1][i])) % MOD;     dp[1][p] = 0;     kol = 0;     pref[0] = 1;     for (int i : v[p])       if (i != pr) {         kol++;         pref[kol] = (pref[kol - 1] * (2LL * dp[1][i] + dp[0][i])) % MOD;       }     reverse(v[p].begin(), v[p].end());     suf[kol] = 1;     for (int i : v[p])       if (i != pr) {         kol--;         suf[kol] = (suf[kol + 1] * (2LL * dp[1][i] + dp[0][i])) % MOD;       }     reverse(v[p].begin(), v[p].end());     for (int i : v[p])       if (i != pr) {         now = (pref[kol] * suf[kol + 1]) % MOD;         kol++;         now = (now * fl[i]) % MOD;         dp[1][p] = (dp[1][p] + now) % MOD;       }     fl[p] = pref[kol];   }   int main() {     ios::sync_with_stdio(0);     cin.tie();     cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int s, f;       cin >> s >> f;       s--, f--;       v[s].push_back(f);       v[f].push_back(s);     }     dfs(0, -1);     cout << (dp[0][0] + dp[1][0]) % MOD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [ ;     for (auto u : v) {       os << u;       os <<  , ;     }     os <<  ]         <<   n ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& s) {     os <<  { ;     for (auto u : s) {       os << u;       if (u != *s.rbegin()) os <<  , ;     }     os <<  }         <<   n ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     os <<  { ;     os << p.first <<  ,  << p.second;     os <<  }         <<   n ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& mp) {     for (auto p : mp) os << p.first <<   :   << p.second <<   n ;     return os;   }   void boost() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed << setprecision(3);   }   int32_t main() {     boost();     long long t = 1;     while (t--) {       long long a[3], d;       cin >> a[0] >> a[1] >> a[2] >> d;       sort(a, a + 3);       if (a[1] >= a[0] + d && a[2] >= a[1] + d)         cout << 0 <<   n ;       else {         if (a[1] >= a[0] + d) {           if (a[2] >= a[0] + 2 * d) {             long long get = a[2] - d;             long long ans = a[1] - get;             cout << ans <<   n ;           } else {             long long have = (a[1] + d) - a[2];             cout << have <<   n ;           }         } else if (a[2] >= a[1] + d) {           if (a[2] >= a[0] + 2 * d) {             long long get = a[0] + d;             long long ans = get - a[1];             cout << ans <<   n ;           } else {             long long have = abs((a[1] - d) - a[0]);             cout << have <<   n ;           }         } else {           long long ans = abs(d - (a[1] - a[0]));           ans = ans + abs(d - (a[2] - a[1]));           cout << ans <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string tostring(const T &x) {     ostringstream os;     os << x;     return os.str();   }   inline int toint(const string &s) {     istringstream is(s);     int x;     is >> x;     return x;   }   inline int todecimal(string s) {     int a = 0;     for (int i = 0; i < s.size(); i++) a = 2 * a + (s[i] -  0 );     return a;   }   inline string tobinary(int a) {     string s;     while (a != 0) {       s = (char)(a % 2 +  0 ) + s;       a >>= 1;     }     return s;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? abs(a) : gcd(b, a % b);   }   inline int isvowel(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ) return 1;     return 0;   }   inline int isprime(int a) {     for (int i = 2; i * i <= a; i++)       if (!(a % i)) return 0;     return 1;   }   inline void inp(int &n) {     n = 0;     int ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     n = n * sign;   }   const int dx4[4] = {0, 0, 1, -1};   const int dy4[4] = {1, -1, 0, 0};   const int dx8[8] = {0, 0, 1, 1, 1, -1, -1, -1};   const int dy8[8] = {1, -1, 0, 1, -1, 1, 0, -1};   class node {    public:     int x, y, z;     node(int a, int b, int c) {       x = a;       y = b;       z = c;     }   };   bool operator<(const node &a, const node &b) { return a.x > b.x; }   bool compare(const node &a, const node &b) { return a.x < b.x; }   void solve() {}   void input() {     int n, k;     cin >> n >> k;     int ans = INT_MIN;     int f, t;     for (int i = 0; i < n; i++) {       cin >> f >> t;       if (t > k)         ans = max(ans, f - t + k);       else         ans = max(ans, f);     }     cout << ans << endl;   }   int main() {     int testcase = 1;     for (int i = 0; i < testcase; i++) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[300], book[300], n, a, b, flag = 0, tun = 0;   int main() {     cin >> n >> a >> b;     arr[a] = arr[b] = 2;     while (!flag) {       tun++;       memset(book, 0, sizeof(book));       for (int i = 1; i <= n; i++) {         if (!book[i] && (arr[i] == 0 || arr[i] == 2)) {           for (int j = i + 1; j <= n; j++) {             if (!book[j] && (arr[j] == 0 || arr[j] == 2)) {               if (arr[i] == 2 && arr[j] == 2) {                 flag = 1;               } else if (arr[i] == 0 && arr[j] == 2) {                 arr[i] = 1;               } else if (arr[i] == 2 && arr[j] == 0)                 arr[j] = 1;               else                 arr[i] = 1;               book[i] = book[j] = 1;               break;             }           }         }       }       if (flag) break;     }     int ans = (int)pow(2, tun);     if (ans == n)       cout <<  Final!  << endl;     else       cout << tun << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, t[1000 * 1000], a[1000 * 1000], b[1000 * 1000], v, ans;   map<long long, long long> w;   long long get(int v, int tl, int tr, int l, int r) {     if (r < tl || tr < l) return 0;     if (l <= tl && tr <= r) return t[v];     int m = (tl + tr) >> 1;     return max(get(v + v, tl, m, l, min(r, m)),                get(v + v + 1, m + 1, tr, max(l, m + 1), r));   }   void upd(int v, int l, int r, int p, long long x) {     if (l == r)       t[v] = x;     else {       int m = (l + r) >> 1;       if (p <= m)         upd(v + v, l, m, p, x);       else         upd(v + v + 1, m + 1, r, p, x);       t[v] = max(t[v + v], t[v + v + 1]);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       long long r, h;       cin >> r >> h;       b[i] = a[i] = ((r) * (r)) * h;     }     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; i++) w[b[i]] = i;     for (int i = 1; i <= n; i++) {       v = get(1, 1, n, 1, w[a[i]] - 1) + a[i];       upd(1, 1, n, w[a[i]], v);       ans = max(ans, v);     }     printf( %.7f , ans * acos(-1));   }


#include <bits/stdc++.h>   using namespace std;   constexpr int inf = 1e9;   int main() {     int n, q;     cin >> n >> q;     vector<int> t(q), l(q), r(q), v(q);     vector<int> added(n), ub(n, inf);     for (int j = 0; j < q; ++j) {       cin >> t[j] >> l[j] >> r[j] >> v[j];       l[j]--;       if (t[j] == 1) {         for (int i = l[j]; i < r[j]; ++i) {           added[i] += v[j];         }       } else {         for (int i = l[j]; i < r[j]; ++i) {           ub[i] = min(ub[i], v[j] - added[i]);         }       }     }     vector<int> ans = ub;     for (int i = 0; i < q; ++i) {       if (t[i] == 1) {         for (int j = l[i]; j < r[i]; ++j) {           ans[j] += v[i];         }       } else {         int maxi = -inf;         for (int j = l[i]; j < r[i]; ++j) {           maxi = max(maxi, ans[j]);         }         if (maxi != v[i]) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; ++i) {       cout << ub[i] <<    n [i + 1 == n];     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 5;   vector<long long> g[N];   map<long long, long long> cnt;   long long n, c, a[N], pref[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> c;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       cnt[a[i]]++;       g[a[i]].push_back(i);       pref[i] = pref[i - 1] + (a[i] == c);     }     long long ans = cnt[c];     for (long long i = 1; i < N; i++) {       if (!g[i].size() || i == c) continue;       long long prev = g[i][0];       long long cur = 0, max_so_far = 0;       for (auto it : g[i]) {         cur = cur + 1 - (pref[it] - pref[prev]);         prev = it;         if (cur <= 0) cur = 1;         max_so_far = max(max_so_far, cur);       }       ans = max(ans, pref[n] + max_so_far);     }     cout << ans << endl;     return 0;   }