#include <bits/stdc++.h>   using namespace std;   struct event {     int x, size, val, ent;     bool operator<(const event& rhs) const {       if (x == rhs.x) return ent < rhs.ent;       return x < rhs.x;     }   };   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n, x;     cin >> n >> x;     vector<event> v;     for (int i = 0; i < n; i++) {       int l, r, cost;       cin >> l >> r >> cost;       v.push_back({l, r - l + 1, cost, 0});       v.push_back({r, r - l + 1, cost, 1});     }     sort(v.begin(), v.end());     int ans = 0x7fffffff;     map<int, int> mp;     for (const event& eve : v) {       if (eve.ent == 0) {         auto it = mp.find(x - eve.size);         if (it == mp.end())           continue;         else           ans = min(ans, it->second + eve.val);       } else {         if (mp[eve.size] == 0)           mp[eve.size] = eve.val;         else           mp[eve.size] = min(eve.val, mp[eve.size]);       }     }     if (ans == 0x7fffffff) ans = -1;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007, con = 2500000;   long long n, k, a, ans;   int main() {     iostream::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> k;       ans += abs(a - k);       a = k;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 7;   int n;   int a[maxn], b[maxn];   long long solve() {     long long res = 0;     for (int i = 0; i < int(n); i++) {       long long sa = 0, sb = 0;       for (int j = i; j < int(n); j++) {         sa |= a[j];         sb |= b[j];         res = max(res, sa + sb);       }     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < int(n); i++) scanf( %d , &a[i]);     for (int i = 0; i < int(n); i++) scanf( %d , &b[i]);     printf( %lld n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define ull unsigned long long   #define uint unsigned int   #define loop(n) for(int i=1;i<=n;i++)         int main()   {    ios_base::sync_with_stdio(false);    cout.tie(NULL);    cin.tie(NULL);       uint t;    cin>>t;    while(t--)    {     int n,temp,tem;     ll min=INT_MAX;     cin>>n;     map<int,int> a;     vector<int> s;     set<int> st;     loop(n)     {      cin>>temp;      tem=a[temp];      a[temp]=tem+1;     }     for(auto i:a)     {      //cout<<i.second<<   ;      s.push_back(i.second);      st.insert(i.second);     }     for(auto mid:st)       {      ll sum=0;      for(auto i:s)       if(i<mid)        sum+=i;       else        sum+=i-mid;      if(min>sum)       min=sum;     }     cout<<min<<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s[2001][2002];   int wu[2][2001];   int ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 1; i <= n; i++) {       int rxor = 0, lxor = 0, d;       for (int j = n; j > i; j--) {         d = wu[0][j] ^ (s[i][j] -  0 ) ^ rxor;         if (d) ans++, rxor ^= 1, wu[0][j] ^= 1;         d = wu[1][j] ^ (s[j][i] -  0 ) ^ lxor;         if (d) ans++, lxor ^= 1, wu[1][j] ^= 1;       }       if ((s[i][i] -  0 ) ^ rxor ^ lxor ^ wu[0][i] ^ wu[1][i]) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct team {     int prob;     int time;   };   bool comp(team a, team b) {     return (a.prob > b.prob) || ((a.prob == b.prob) && (a.time < b.time));   }   int main(int argc, char const *argv[]) {     int n, k;     cin >> n >> k;     team t[n];     for (int i = 0; i < n; ++i) {       cin >> t[i].prob >> t[i].time;     }     sort(t, t + n, comp);     team tk;     tk = t[k - 1];     int count = 1;     int i = k - 2;     int j = k;     while ((tk.time == t[i].time) && (tk.prob == t[i].prob) && (i >= 0)) {       count++;       i--;     }     while ((tk.time == t[j].time) && (tk.prob == t[j].prob) && (j < n)) {       count++;       j++;     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize  trapv    long long int power(long long int x, long long int b) {     long long int p = 1;     while (b > 0) {       if (b & 1) {         p = p * x;         p %= 1000000007;       }       b >>= 1;       x *= x;       x %= 1000000007;     }     return p % 1000000007;   }   using namespace std;   struct ppp {     char a;     long long int b, c, d;   };   long long int N;   struct lex_compare {     bool operator()(ppp p1, ppp p2) {       if (p1.a == p2.a) {         if (p1.b == p2.b)           return p1.c < p2.c;         else           return p1.b < p2.b;       } else {         return p1.a < p2.a;       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n;     cin >> n;     long long int arr[n];     for (long long int i = 0; i < n; i++) cin >> arr[i];     long long int maxt = n;     vector<vector<long long int> > ans;     while (maxt--) {       vector<vector<long long int> > blocks;       int i = 0;       while (i < n) {         long long int s = arr[i];         vector<long long int> temp;         temp.push_back(s);         i++;         while (i < n && arr[i] == s + 1) {           s = arr[i];           i++;           temp.push_back(s);         }         blocks.push_back(temp);       }       if (blocks.size() == 1) break;       long long int minele = blocks[blocks.size() - 1].back();       long long int next = minele + 1;       if (next == n + 1) {         vector<long long int> tempans;         long long int ind = 0;         for (int j = blocks.size() - 1; j >= 0; j--) {           tempans.push_back(blocks[j].size());           for (auto k : blocks[j]) {             arr[ind++] = k;           }         }         reverse(tempans.begin(), tempans.end());         ans.push_back(tempans);         continue;       }       long long int ind2nd = 0;       while (ind2nd < blocks.size() && blocks[ind2nd][0] != next) {         ind2nd++;       }       vector<long long int> tempans;       long long int size1 = 0;       i = 0;       while (i < ind2nd) {         size1 += blocks[i].size();         i++;       }       if (size1 != 0) tempans.push_back(size1);       size1 = 0;       i = ind2nd;       while (i < blocks.size() - 1) {         size1 += blocks[i].size();         i++;       }       if (size1 != 0) tempans.push_back(size1);       tempans.push_back(blocks.back().size());       ans.push_back(tempans);       int ind = 0;       for (auto j : blocks.back()) {         arr[ind++] = j;       }       for (int j = ind2nd; j < blocks.size() - 1; j++) {         for (auto k : blocks[j]) {           arr[ind++] = k;         }       }       for (int j = 0; j < ind2nd; j++) {         for (auto k : blocks[j]) {           arr[ind++] = k;         }       }     }     cout << ans.size() <<   n ;     for (auto i : ans) {       cout << i.size() <<    ;       for (auto j : i) cout << j <<    ;       cout <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int n, a, b;   long long int S(long long int x) {     int ret = 0;     long long int y = n - x;     while (x > 0) {       ret += x % 10;       x /= 10;     }     while (y > 0) {       ret += y % 10;       y /= 10;     }     return ret;   }   long long int solve(long long int x) {     long long int b = 1, ans = x;     while (x) {       long long int cur = (x - 1) * b + (b - 1);       if (S(cur) > S(ans)) {         ans = cur;       }       x /= 10;       b *= 10;     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     cout << S(solve(n));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize(2)   using namespace std;   int n, r;   bool dp[666][666];   int fang[666][666];   pair<int, int> ku[666];   void dfs(int x, int y) {     if (x == y)       cout <<  () ;     else if (fang[x][y] == -1) {       cout <<  ( ;       dfs(x + 1, y);       cout <<  ) ;     } else {       dfs(x, fang[x][y]);       dfs(fang[x][y] + 1, y);     }   }   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     memset(dp, 0, sizeof dp);     cin >> n;     for (register int i = 1; (1 < n) ? (i <= n) : (i >= n);          i += (1 < n) ? 1 : (-1))       cin >> ku[i].first >> ku[i].second;     for (register int i = 1; (1 < n) ? (i <= n) : (i >= n);          i += (1 < n) ? 1 : (-1))       dp[i][i] = (bool)(ku[i].first == 1);     for (register int i = 2; (2 < n) ? (i <= n) : (i >= n);          i += (2 < n) ? 1 : (-1)) {       for (register int l = 1;            (1 < n - i + 1) ? (l <= n - i + 1) : (l >= n - i + 1);            l += (1 < n - i + 1) ? 1 : (-1)) {         r = l + i - 1;         if (dp[l + 1][r] && ku[l].first - 1 <= (r - l) * 2 &&             (r - l) * 2 <= ku[l].second - 1) {           dp[l][r] = 1;           fang[l][r] = -1;         } else {           for (register int k = l; (l < r - 1) ? (k <= r - 1) : (k >= r - 1);                k += (l < r - 1) ? 1 : (-1)) {             if (dp[l][k] && dp[k + 1][r]) {               dp[l][r] = 1;               fang[l][r] = k;               break;             }           }         }       }     }     if (dp[1][n]) {       dfs(1, n);       cout << endl;     } else       cout <<  IMPOSSIBLE  << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 5000 + 10;   struct node {     int l, r, id;   };   node a[N];   bool pre[N], suf[N];   std::vector<node> vector;   bool cmp(const node& i, const node& j) {     if (i.r ^ j.r)       return i.r < j.r;     else       return i.l < j.l;   }   bool cc(const node& i, const node& j) { return i.id < j.id; }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       a[i].id = i;       scanf( %d%d , &a[i].l, &a[i].r);     }     std::sort(a + 1, a + 1 + n, cmp);     pre[0] = pre[1] = true;     for (int i = 2; i <= n; ++i)       if (pre[i - 1] && a[i].l >= a[i - 1].r)         pre[i] = true;       else         break;     suf[n + 1] = suf[n] = true;     for (int i = n - 1; i >= 1; --i)       if (suf[i + 1] && a[i].r <= a[i + 1].l)         suf[i] = true;       else         break;     for (int i = 1; i <= n; ++i)       if (pre[i - 1] && suf[i + 1]) {         if (i == 1 || i == n || a[i - 1].r <= a[i + 1].l) vector.push_back(a[i]);       }     std::sort(vector.begin(), vector.end(), cc);     printf( %d n , vector.size());     for (int i = 0; i < vector.size(); ++i) {       if (i) putchar(   );       printf( %d , vector[i].id);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     double f, s, v, l, omega, r;     const double tol = 1.0e-7;     scanf( %d %lf %lf , &n, &r, &v);     omega = v / r;     double xt, xb, a, b;     for (int i = 0; i < n; i++) {       scanf( %lf %lf , &s, &f);       l = (f - s) / 2.;       a = (l + r + 0.1) / v;       b = -0.1;       xt = (a + b) / 2.;       while (abs((b - a) / xt) > tol) {         if ((v * xt + r * sin(xt * omega) - l) *                 (v * a + r * sin(a * omega) - l) <             0.)           b = xt;         else           a = xt;         xt = (a + b) / 2.;       }       a = (l + r + 0.1) / v;       b = -0.1;       do {         xb = (a + b) / 2.;         if ((v * xb - r * sin(xb * omega) - l) *                 (v * a - r * sin(a * omega) - l) <             0.)           b = xb;         else           a = xb;       } while (abs((b - a) / xb) > tol);       printf( %.10lf n , 2. * min(xb, xt));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   map<string, long long> mm;   string a[100005];   long long c[100005];   long long min(long long a, long long b) { return a < b ? a : b; }   int main() {     cin >> n >> k >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       mm[a[i]] = x;     }     for (int i = 0; i < k; i++) {       long long x;       cin >> x;       long long minn = 0x3f3f3f3f;       for (int j = 0; j < x; j++) {         cin >> c[j];         minn = min(minn, mm[a[c[j]]]);       }       for (int j = 0; j < x; j++) {         mm[a[c[j]]] = minn;       }     }     string b;     long long s = 0;     for (int i = 0; i < m; i++) {       cin >> b;       s += mm[b];     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 10;   struct node {     int l, r, sum, mus;   } tr[M];   int n, a[M], now[M], sz[M], place[M], q, p;   vector<int> g[M];   void maket(int l, int r, int t) {     tr[t].l = l;     tr[t].r = r;     if (l == r) {       tr[t].sum += now[a[l]];       return;     }     maket(l, (l + r) / 2, 2 * t);     maket((l + r) / 2 + 1, r, 2 * t + 1);     tr[t].sum = tr[2 * t].sum + tr[2 * t + 1].sum;   }   void change(int l, int r, int t) {     if (tr[t].l == l && tr[t].r == r) {       tr[t].sum = r - l + 1 - tr[t].sum;       tr[t].mus ^= 1;       return;     }     if (tr[t].mus) {       change(tr[2 * t].l, tr[2 * t].r, 2 * t);       change(tr[2 * t + 1].l, tr[2 * t + 1].r, 2 * t + 1);       tr[t].mus = 0;     }     if (r <= tr[2 * t].r)       change(l, r, 2 * t);     else if (l >= tr[2 * t + 1].l)       change(l, r, 2 * t + 1);     else {       change(l, tr[2 * t].r, 2 * t);       change(tr[2 * t + 1].l, r, 2 * t + 1);     }     tr[t].sum = tr[2 * t].sum + tr[2 * t + 1].sum;   }   int query(int l, int r, int t) {     if (tr[t].l == l && tr[t].r == r) return tr[t].sum;     if (tr[t].mus) {       change(tr[2 * t].l, tr[2 * t].r, 2 * t);       change(tr[2 * t + 1].l, tr[2 * t + 1].r, 2 * t + 1);       tr[t].mus = 0;     }     if (r <= tr[2 * t].r)       return query(l, r, 2 * t);     else if (l >= tr[2 * t + 1].l)       return query(l, r, 2 * t + 1);     else       return query(l, tr[2 * t].r, 2 * t) + query(tr[2 * t + 1].l, r, 2 * t + 1);     tr[t].sum = tr[2 * t].sum + tr[2 * t + 1].sum;   }   void dfs(int v) {     a[++p] = v;     place[v] = p;     sz[v] = 1;     for (int i = 0; i < g[v].size(); i++) {       dfs(g[v][i]);       sz[v] += sz[g[v][i]];     }   }   int main() {     cin >> n;     for (int i = 2; i <= n; i++) {       int x;       scanf( %d , &x);       g[x].push_back(i);     }     for (int i = 1; i <= n; i++) scanf( %d , now + i);     dfs(1);     maket(1, n, 1);     cin >> q;     while (q--) {       string s;       cin >> s;       int v;       scanf( %d , &v);       if (s ==  get )         printf( %d n , query(place[v], place[v] + sz[v] - 1, 1));       else         change(place[v], place[v] + sz[v] - 1, 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     string s;     cin >> s;     string ans =  0 ;     int curr = 0;     for (int i = 1; i < n; i++) {       if (s[i] ==  ( ) curr = curr ^ 1;       ans += (char)(curr +  0 );       if (s[i] ==  ) ) curr = curr ^ 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long c[200005];   int b[200005];   int a[100005];   void up(int n, int k) {     if (!n) return;     while (n <= 200000) {       b[n]++;       c[n] += k;       k++;       n <<= 1;     }   }   void solve(int n) {     int cur = 0;     long long num = n * 2;     up(num, 1);     num = n;     cur = 0;     while (num) {       if (num & 1) {         up(num / 2 * 2, cur + 2);       }       b[num]++;       c[num] += cur;       num >>= 1;       cur++;     }   }   int main() {     scanf( %d , &n);     memset(c, 0, sizeof(c));     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       solve(a[i]);     }     long long res = 1000000000;     for (int i = 0; i <= 200000; i++) {       if (b[i] == n) {         res = min(res, c[i]);       }     }     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 10, mod = 1e9 + 7;   long long n, x;   long long f[N];   void solve() {     scanf( %lld , &n);     long long s1 = 0, s2 = 0, ans = 0;     for (long long i = 1; i <= n; i++) {       scanf( %lld , &x);       if (x == 1)         s1++;       else         s2++;     }     f[0] = 1, f[1] = 1;     for (long long i = 2; i <= s1; i++)       f[i] = (f[i - 1] + (i - 1) * f[i - 2]) % mod;     ans = f[s1];     for (long long i = s1 + 1; i <= n; i++) ans = ans * i % mod;     printf( %lld , ans);   }   signed main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000 + 10;   int n, tmp, ans, p[N], q[N], pos[N];   vector<pair<int, int> > vec;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int i, j;     cin >> n;     for (i = 1; i <= n; ++i) cin >> p[i];     for (i = 1; i <= n; ++i) cin >> q[i];     for (i = 1; i <= n; ++i) pos[p[i]] = i;     for (i = 1; i <= n; ++i) p[pos[q[i]]] = i;     for (i = 1; i <= n; ++i) pos[p[i]] = i;     for (i = n; i >= 1; --i) {       while (pos[i] != i) {         for (j = pos[i] + 1; j <= i; ++j) {           if (p[j] <= pos[i]) {             tmp = pos[i];             ans += j - pos[i];             vec.push_back({pos[i], j});             swap(pos[i], pos[p[j]]);             swap(p[tmp], p[j]);             break;           }         }       }     }     cout << ans <<   n ;     cout << vec.size() <<   n ;     for (auto x : vec) cout << x.first <<     << x.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   const int N = 1e7 + 100;   bool a[N];   int main() {     cin >> n >> k;     vector<long long> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];       a[v[i]] = 1;     }     int q;     cin >> q;     for (int test = 0; test < q; test++) {       long long w;       int ans = 1000;       cin >> w;       for (int t = 1; t <= k; t++) {         for (int i = 0; i < n; i++) {           long long rem = w - t * v[i];           if (rem < 0) continue;           if (rem == 0) ans = min(ans, t);           for (int e = 1; t + e <= k; e++) {             if (rem % e != 0) continue;             long long x = rem / e;             if (x >= N) continue;             if (a[x]) ans = min(e + t, ans);           }         }       }       if (ans != 1000)         cout << ans;       else         cout << -1;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n;     int i, i2;     int a[100000] = {0};     int flag = 0;     int max = -1000001;     int min = 1000001;     int sum = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] > 0) {         if (a[i] < min && a[i] % 2 != 0) {           min = a[i];         }         sum += a[i];       } else {         if (a[i] > max && a[i] % 2 != 0) {           max = a[i];         }       }     }     if (min == 1000001) {       printf( %d , sum + max);       return 0;     }     if (sum % 2 == 0) {       if (min > (-max)) {         printf( %d , sum + max);       } else {         printf( %d , sum - min);       }     } else {       printf( %d , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     int sum = 0;     sum += 2 * n / k;     if (2 * n % k != 0) sum++;     sum += 5 * n / k;     if (5 * n % k != 0) sum++;     sum += 8 * n / k;     if (8 * n % k != 0) sum++;     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 1000000007;   const int inv2 = (mo + 1) / 2;   const int inv4 = (mo + 1) / 4;   const int N = 500005;   int dep[N], fa[N], deg[N];   int sz[N], p[N], cnt[N], n, m, nd;   vector<int> e[N], vec[N];   int power(int x, int y) {     int s = 1;     for (; y; y /= 2, x = 1ll * x * x % mo)       if (y & 1) s = 1ll * s * x % mo;     return s;   }   void dfs(int x) {     dep[x] = dep[fa[x]] + 1;     for (auto i : e[x])       if (i != fa[x])         if (!dep[i]) {           fa[i] = x;           dfs(i);         } else if (dep[x] > dep[i]) {           ++nd;           for (int y = x;; y = fa[y]) {             vec[nd].push_back(y);             if (y == i) break;           }           sz[nd] = vec[nd].size();           p[nd] = power(inv2, sz[nd]);         }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (int)(1); i <= (int)(m); i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     for (int i = (int)(1); i <= (int)(n); i++) deg[i] = e[i].size();     dfs(1);     int E1 = 0, E2 = 0, E3 = 0;     E1 = 1ll * n * inv2 % mo;     E2 = 1ll * m * inv4 % mo;     for (int i = (int)(1); i <= (int)(nd); i++) E3 = (E3 + p[i]) % mo;     int E = (E1 + mo - E2 + 1ll * E3) % mo;     int E11 = 0, E12 = 0, E13 = 0, E22 = 0, E23 = 0, E33 = 0;     E11 = (1ll * n * (n - 1) % mo * inv4 % mo + E1) % mo;     for (int i = (int)(1); i <= (int)(n); i++)       E12 = (E12 + 1ll * (m - deg[i]) * inv4 % mo * inv2 + 1ll * deg[i] * inv4) %             mo;     for (int i = (int)(1); i <= (int)(nd); i++)       E13 =           (E13 + 1ll * p[i] * (1ll * inv2 * (n - sz[i]) % mo + sz[i]) % mo) % mo;     E22 = (1ll * m * (m - 1) % mo * inv4 % mo * inv4 % mo + E2) % mo;     for (int i = (int)(1); i <= (int)(n); i++)       E22 = (E22 + 1ll * deg[i] * (deg[i] - 1) % mo * inv4 % mo * inv4) % mo;     for (int i = (int)(1); i <= (int)(nd); i++)       E23 = (E23 + 1ll * p[i] * (1ll * inv4 * (m - sz[i]) % mo + sz[i])) % mo;     for (int i = (int)(1); i <= (int)(nd); i++)       for (auto j : vec[i])         E23 = (E23 + 1ll * p[i] * inv4 % mo * (deg[j] - 2) % mo) % mo;     for (int i = (int)(1); i <= (int)(nd); i++)       E33 = (E33 + 1ll * p[i] * (E3 + mo - p[i] + 1)) % mo;     for (int i = (int)(1); i <= (int)(nd); i++)       for (auto j : vec[i]) cnt[j] = (cnt[j] + p[i]) % mo;     for (int i = (int)(1); i <= (int)(nd); i++)       for (auto j : vec[i]) E33 = (E33 + 1ll * p[i] * (cnt[j] + mo - p[i])) % mo;     int EF =         (1ll * E11 + E22 + E33 + 2 * E13 + 4ll * mo - 2 * E12 - 2 * E23) % mo;     printf( %lld n , (EF + mo - 1ll * E * E % mo) % mo);   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100100;   const int maxM = maxN << 1;   const int maxB = 17;   int n, Q, Log[maxN];   int edgecnt = -1, Head[maxN], Next[maxM], V[maxM], W[maxM], Dst[maxN];   class Tree {    public:     int root, Dep[maxN], Fa[maxN], Dst[maxN], Mx[maxN], ST[maxB][maxN],         Mxd[maxB][maxN], dfncnt, dfn[maxN], lst[maxN];     int lcnt, Mark[maxN];     pair<int, int> Leaf[maxN];     void dfs_init(int u, int fa) {       Dep[u] = 0;       ST[0][u] = fa;       for (int i = Head[u]; i != -1; i = Next[i])         if (V[i] != fa) {           dfs_init(V[i], u);           if (Dep[V[i]] + W[i] > Dep[u]) Mx[u] = V[i], Dep[u] = Dep[V[i]] + W[i];         }       return;     }     void dfs_push(int u, int fa, int w) {       Dep[u] = Dep[fa] + 1;       dfn[u] = ++dfncnt;       Mxd[0][dfncnt] = Dst[u];       if (Mx[u] == 0)         Leaf[++lcnt] = make_pair(w, u);       else {         Fa[Mx[u]] = u;         for (int i = Head[u]; i != -1; i = Next[i])           if (V[i] != fa)             Dst[V[i]] = Dst[u] + W[i],             dfs_push(V[i], u, (V[i] == Mx[u]) ? w + W[i] : W[i]);       }       lst[u] = dfncnt;       return;     }     void Init(int r) {       root = r;       dfs_init(root, 0);       Dep[root] = 1;       Dst[root] = 0;       dfs_push(root, 0, 0);       for (int i = 1; i < maxB; i++)         for (int j = 1; j <= n; j++) ST[i][j] = ST[i - 1][ST[i - 1][j]];       sort(&Leaf[1], &Leaf[lcnt + 1]);       reverse(&Leaf[1], &Leaf[lcnt + 1]);       for (int i = 1; i <= lcnt; i++) Leaf[i].first += Leaf[i - 1].first;       for (int i = 1; i <= lcnt; i++) {         int now = Leaf[i].second;         while (now) Mark[now] = i, now = Fa[now];       }       for (int i = 1; i < maxB; i++)         for (int j = 1; j + (1 << (i)) - 1 <= n; j++)           Mxd[i][j] = max(Mxd[i - 1][j], Mxd[i - 1][j + (1 << (i - 1))]);       return;     }     int LCA(int u, int v) {       if (Dep[u] < Dep[v]) swap(u, v);       for (int i = maxB - 1; i >= 0; i--)         if (ST[i][u] && Dep[ST[i][u]] >= Dep[v]) u = ST[i][u];       if (u == v) return u;       for (int i = maxB - 1; i >= 0; i--)         if (ST[i][u] && ST[i][v] && ST[i][u] != ST[i][v])           u = ST[i][u], v = ST[i][v];       return ST[0][u];     }     int GET(int u, int cnt) {       cnt = min(cnt * 2 - 1, lcnt);       if (Mark[u] <= cnt) return Leaf[cnt].first;       int ret = Leaf[cnt - 1].first;       int now = u;       for (int i = maxB - 1; i >= 0; i--)         if (ST[i][now] && Mark[ST[i][now]] > cnt) now = ST[i][now];       now = ST[0][now];       int l = dfn[u], r = lst[u], lg = Log[r - l + 1];       int mxd = max(Mxd[lg][l], Mxd[lg][r - (1 << (lg)) + 1]);       ret = ret + mxd - Dst[now];       return max(ret, Leaf[cnt].first + mxd - Dst[Leaf[Mark[now]].second]);     }   };   Tree T1, T2;   void Add_Edge(int u, int v, int w);   void Bfs(int S);   int main() {     for (int i = 2; i < maxN; i++) Log[i] = Log[i >> 1] + 1;     scanf( %d%d , &n, &Q);     memset(Head, -1, sizeof(Head));     for (int i = 1; i < n; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       Add_Edge(u, v, w);       Add_Edge(v, u, w);     }     int S, T;     Bfs(1);     S = 1;     for (int i = 1; i <= n; i++)       if (Dst[S] < Dst[i]) S = i;     Bfs(S);     T = 1;     for (int i = 1; i <= n; i++)       if (Dst[T] < Dst[i]) T = i;     T1.Init(S);     T2.Init(T);     int lstans = 0;     while (Q--) {       int x, y;       scanf( %d%d , &x, &y);       x = (x + lstans - 1) % n + 1;       y = (y + lstans - 1) % n + 1;       printf( %d n , lstans = max(T1.GET(x, y), T2.GET(x, y)));     }     return 0;   }   void Add_Edge(int u, int v, int w) {     Next[++edgecnt] = Head[u];     Head[u] = edgecnt;     V[edgecnt] = v;     W[edgecnt] = w;     return;   }   void Bfs(int S) {     static int vis[maxN], Qu[maxN];     memset(vis, 0, sizeof(vis));     int l = 1, r = 1;     Qu[1] = S;     Dst[S] = 0;     vis[S] = 1;     while (l <= r)       for (int u = Qu[l++], i = Head[u]; i != -1; i = Next[i])         if (vis[V[i]] == 0) Dst[Qu[++r] = V[i]] = Dst[u] + W[i], vis[V[i]] = 1;     return;   }


#include <bits/stdc++.h>   using namespace std;   long long N;   pair<long long, long long> arr[6005];   long long cnt[20][20];   bool good(int x1, int y1, int x2, int y2, int x3, int y3) {}   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> arr[i].first >> arr[i].second;       cnt[arr[i].first % 4][arr[i].second % 4]++;     }     vector<pair<long long, long long>> vec;     for (int i = 0; i < 16; i += 2) {       for (int j = 0; j < 16; j += 2) {         vec.emplace_back(i, j);       }     }     long long ans = N * (N - 1) * (N - 2) / 6;     ans -= cnt[0][0] * cnt[0][2] * cnt[2][0];     ans -= cnt[0][0] * cnt[0][2] * cnt[2][2];     ans -= cnt[0][0] * cnt[2][0] * cnt[2][2];     ans -= cnt[0][2] * cnt[2][0] * cnt[2][2];     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   string direc =  URDL ;   const long long MOD2 = (long long)1000000007 * (long long)1000000007;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   int a[500135], cnt[500135], M, ps[500135], pre[500135];   long long ans;   pair<int, int> b1, b2;   void upt(pair<int, int> z) {     if (z > b1) {       b2 = b1;       b1 = z;     } else       maxtt(b2, z);   }   void uptAns(long long x, long long y) {     if (x >= 2) maxtt(ans, x * y);   }   void fmain(int tid) {     scanf( %d , &n);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       scanf( %d , a + i);       cnt[a[i]]++;       maxtt(M, a[i]);     }     for (int(i) = 1; (i) <= (int)(M); (i)++) {       ps[i] = ps[i - 1] + cnt[i];       pre[i] = pre[i - 1];       if (cnt[i]) pre[i] = i;     }     for (int y = 2; y <= M; y++) {       long long cntY = 0;       for (int i = y; i <= M; i += y) {         cntY += (long long)(ps[min(i + y - 1, M)] - ps[i - 1]) * (i / y);       }       b1 = {-1, -1};       b2 = {-1, -1};       for (int k = M / y, R = M + 1; k >= 0; R = k * y, k--) {         int ky = k * y, ss = (b1.first >= 0) + (b2.first >= 0);         if (pre[R - 1] >= ky) {           pair<int, int> key = {pre[R - 1] % y, pre[R - 1]};           upt(key);           if (cnt[pre[R - 1]] > 1)             upt(key);           else {             int tmp = pre[pre[R - 1] - 1];             if (tmp >= ky) upt({tmp % y, tmp});           }         }         if (b1.first >= 0) {           uptAns(min((long long)(b1.first + ky) / 2, cntY - k), y);         }         if (b2.second >= 0) {           uptAns(min((long long)(b2.first + ky), cntY - k - k), y);           if ((b1.second < R) + ss >= 2) {             uptAns(min((long long)(b1.first + ky), cntY - k - k - 1), y);           }         }       }     }     printf( %lld n , ans);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const int N = 100000 + 10;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int n, a[N], b[N];   vector<int> E[N];   int rt[N], tot = 0;   struct line {     int k;     long long b;   } s[N];   struct node {     int ls, rs, id;   } t[N * 30];   long long f(int i, int x) { return 1ll * s[i].k * x + s[i].b; }   void modify(int& o, int l, int r, int x) {     if (!o) {       o = ++tot, t[o].id = x;       return;     }     if (l == r) {       if (f(x, l) < f(t[o].id, l)) t[o].id = x;       return;     }     int mid = (l + r) >> 1;     if (s[x].k < s[t[o].id].k) {       if (f(x, mid) < f(t[o].id, mid))         modify(t[o].ls, l, mid, t[o].id), t[o].id = x;       else         modify(t[o].rs, mid + 1, r, x);     } else if (s[x].k > s[t[o].id].k) {       if (f(x, mid) < f(t[o].id, mid))         modify(t[o].rs, mid + 1, r, t[o].id), t[o].id = x;       else         modify(t[o].ls, l, mid, x);     } else if (s[x].b < s[t[o].id].b)       t[o].id = x;   }   long long query(int o, int l, int r, int x) {     if (!o) return inf;     if (l == r) return f(t[o].id, l);     int mid = (l + r) >> 1;     long long res = f(t[o].id, x);     if (x <= mid)       res = min(res, query(t[o].ls, l, mid, x));     else       res = min(res, query(t[o].rs, mid + 1, r, x));     return res;   }   int merge(int x, int y, int l, int r) {     if (!x || !y) return x | y;     if (l == r) return f(t[x].id, l) < f(t[y].id, l) ? x : y;     int mid = (l + r) >> 1;     t[x].ls = merge(t[x].ls, t[y].ls, l, mid);     t[x].rs = merge(t[x].rs, t[y].rs, mid + 1, r);     modify(x, l, r, t[y].id);     return x;   }   long long dp[N];   void dfs(int u, int f) {     if (f && E[u].size() == 1)       dp[u] = 0;     else {       for (int v : E[u])         if (v != f) dfs(v, u), rt[u] = merge(rt[u], rt[v], -1e5, 1e5);       dp[u] = query(rt[u], -1e5, 1e5, a[u]);     }     s[u] = (line){b[u], dp[u]}, modify(rt[u], -1e5, 1e5, u);   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) a[i] = read();     for (int i = 1; i <= n; ++i) b[i] = read();     for (int i = 1; i < n; ++i) {       int u = read(), v = read();       E[u].emplace_back(v), E[v].emplace_back(u);     }     dfs(1, 0);     for (int i = 1; i <= n; ++i) printf( %lld  , dp[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007, oo = 1000000009;   void Emsawy() {}   int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};   vector<vector<pair<int, int> > > adj;   int n, m, k, w, h;   struct Node {     vector<int> ord;     int cnt;     Node() {       ord = vector<int>(26, -1);       cnt = 0;     }     void Add(vector<int>& v) { ord = v; }   };   int main() {     Emsawy();     string a, b;     while (cin >> a >> b) {       vector<Node> L(a.size()), R(a.size());       int po = 0;       for (int i = 0; i < a.size(); i++) {         if (i > 0) L[i].Add(L[i - 1].ord);         if (po < b.size() && b[po] == a[i]) {           L[i].ord[b[po] -  a ] = i;           po++;         }         L[i].cnt = po;       }       po = b.size() - 1;       for (int i = a.size() - 1; i >= 0; i--) {         if (i < a.size() - 1) R[i].Add(R[i + 1].ord);         if (po >= 0 && b[po] == a[i]) {           R[i].ord[b[po] -  a ] = i;           po--;         }         R[i].cnt = b.size() - po - 1;       }       bool ok = 1;       for (int i = 0; i < a.size(); i++) {         int pl = L[i].ord[a[i] -  a ];         int pr = R[i].ord[a[i] -  a ];         if (pl == -1 && pr == -1) {           ok = 0;           break;         }         int mx = 0;         if (pl != -1) {           mx = max(mx, L[pl].cnt + (i + 1 < a.size() ? R[i + 1].cnt : 0));         }         if (pr != -1) {           mx = max(mx, R[pr].cnt + (i - 1 >= 0 ? L[i].cnt : 0));         }         if (mx < b.size()) {           ok = 0;           break;         }       }       if (ok)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200001;   const int INF = 1061109567;   int n, m;   struct Edge {     int to, val, id, next;   } edge[N << 1];   int head[N], cnt;   void add_edge(int u, int v, int w, int id) {     cnt++;     edge[cnt].to = v;     edge[cnt].val = w;     edge[cnt].id = id;     edge[cnt].next = head[u];     head[u] = cnt;     return;   }   struct Line {     int u, v, w;     int id;     bool flag;   } e[N << 1];   bool cmp(Line x, Line y) { return x.w < y.w; }   struct Node {     int l, r;     int Max, Min, lazy;   } tree[N << 2];   int pre[N], a[N], w[N];   int ans[N];   int f[N];   int getf(int v) {     if (v == f[v]) return v;     f[v] = getf(f[v]);     return f[v];   }   bool merge(int u, int v) {     int f1 = getf(u), f2 = getf(v);     if (f1 != f2) {       f[f2] = f1;       return true;     }     return false;   }   void kruskal() {     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= m; i++)       if (merge(e[i].u, e[i].v)) {         e[i].flag = true;         add_edge(e[i].u, e[i].v, e[i].w, e[i].id);         add_edge(e[i].v, e[i].u, e[i].w, e[i].id);       }     return;   }   int fa[N], dep[N], size[N], son[N];   void dfs1(int u, int father) {     size[u] = 1;     fa[u] = father;     dep[u] = dep[father] + 1;     for (int i = head[u]; i; i = edge[i].next) {       int v = edge[i].to;       if (v == father) continue;       pre[v] = edge[i].id;       a[v] = edge[i].val;       dfs1(v, u);       size[u] += size[v];       if (size[v] > size[son[u]]) son[u] = v;     }     return;   }   int top[N], dfn[N], Index;   void dfs2(int u, int father) {     dfn[u] = ++Index;     top[u] = father;     w[Index] = a[u];     if (!son[u]) return;     dfs2(son[u], father);     for (int i = head[u]; i; i = edge[i].next) {       int v = edge[i].to;       if (v == son[u] || v == fa[u]) continue;       dfs2(v, v);     }     return;   }   void push_up(int i) {     tree[i].Max = max(tree[i * 2].Max, tree[i * 2 + 1].Max);     tree[i].Min = min(tree[i * 2].Min, tree[i * 2 + 1].Min);     return;   }   void push_down(int i) {     if (tree[i].lazy >= INF) return;     tree[i * 2].Min = min(tree[i * 2].Min, tree[i].lazy);     tree[i * 2].lazy = min(tree[i * 2].lazy, tree[i].lazy);     tree[i * 2 + 1].Min = min(tree[i * 2 + 1].Min, tree[i].lazy);     tree[i * 2 + 1].lazy = min(tree[i * 2 + 1].lazy, tree[i].lazy);     tree[i].lazy = INF;     return;   }   void build(int i, int l, int r) {     tree[i].l = l, tree[i].r = r;     tree[i].Min = tree[i].lazy = INF;     if (l == r) {       tree[i].Max = w[l];       return;     }     int mid = (l + r) / 2;     build(i * 2, l, mid);     build(i * 2 + 1, mid + 1, r);     push_up(i);     return;   }   void update(int i, int l, int r, int val) {     if (r < tree[i].l || l > tree[i].r) return;     if (l <= tree[i].l && tree[i].r <= r) {       tree[i].Min = min(tree[i].Min, val);       tree[i].lazy = min(tree[i].lazy, val);       return;     }     push_down(i);     if (l <= tree[i * 2].r) update(i * 2, l, r, val);     if (r >= tree[i * 2 + 1].l) update(i * 2 + 1, l, r, val);     push_up(i);     return;   }   int querymax(int i, int l, int r) {     if (r < tree[i].l || l > tree[i].r) return 0;     if (l <= tree[i].l && tree[i].r <= r) return tree[i].Max;     push_down(i);     int res = 0;     if (l <= tree[i * 2].r) res = max(res, querymax(i * 2, l, r));     if (r >= tree[i * 2 + 1].l) res = max(res, querymax(i * 2 + 1, l, r));     return res;   }   int querymin(int i, int u) {     if (tree[i].l == tree[i].r) return tree[i].Min;     push_down(i);     if (u <= tree[i * 2].r)       return querymin(i * 2, u);     else       return querymin(i * 2 + 1, u);   }   int getmax(int u, int v) {     int res = 0;     if (dep[u] < dep[v]) swap(u, v);     while (top[u] != top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       res = max(res, querymax(1, dfn[top[u]], dfn[u]));       u = fa[top[u]];     }     if (dep[u] > dep[v]) swap(u, v);     res = max(res, querymax(1, dfn[u] + 1, dfn[v]));     return res;   }   void modifymin(int u, int v, int val) {     if (dep[u] < dep[v]) swap(u, v);     while (top[u] != top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       update(1, dfn[top[u]], dfn[u], val);       u = fa[top[u]];     }     if (dep[u] > dep[v]) swap(u, v);     update(1, dfn[u] + 1, dfn[v], val);     return;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].u, &e[i].v, &e[i].w);       e[i].id = i;     }     sort(e + 1, e + m + 1, cmp);     kruskal();     dfs1(1, 0);     dfs2(1, 1);     build(1, 1, n);     for (int i = 1; i <= m; i++)       if (!e[i].flag) {         ans[e[i].id] = getmax(e[i].u, e[i].v) - 1;         modifymin(e[i].u, e[i].v, e[i].w);       }     for (int i = 2; i <= n; i++) {       int res = querymin(1, dfn[i]);       if (res >= INF)         ans[pre[i]] = -1;       else         ans[pre[i]] = res - 1;     }     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n, m;     cin >> n >> m;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     priority_queue<int> pq;     long long int res[n];     pq.push(a[0]);     res[0] = 0;     long long int cursum = a[0];     long long int curcount = 0;     for (long long int i = 1; i < n; i++) {       if (cursum + a[i] <= m) {         pq.push(a[i]);         cursum += a[i];         res[i] = curcount;       } else {         vector<long long int> temp;         while (cursum + a[i] > m) {           long long int x = pq.top();           cursum = cursum - x;           temp.push_back(x);           pq.pop();           curcount++;         }         res[i] = curcount;         temp.push_back(a[i]);         sort(temp.begin(), temp.end());         long long int ab = 0;         curcount++;         while (cursum <= m and ab < temp.size()) {           pq.push(temp[ab]);           ab++;           cursum += temp[ab - 1];           curcount--;         }       }     }     for (int i = 0; i < n; i++) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int ans = 0;     while (n != 0) {       ans++;       string s = to_string(n);       int maior = s[0] -  0 ;       for (int i = 0; i < s.size(); i++) {         maior = max(maior, s[i] -  0 );       }       n -= maior;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> q[250000];   int color[250000];   int a[250000], b[250000];   int ssum[250000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) scanf( %d%d , &a[i], &b[i]);     for (int i = 1; i <= n; i++) scanf( %d , &color[i]);     int sum = 0;     for (int i = 0; i < n - 1; i++) {       if (color[a[i]] != color[b[i]]) {         ssum[a[i]]++;         ssum[b[i]]++;         sum++;       }     }     int flag = 0;     for (int i = 1; i <= n; i++)       if (sum - ssum[i] == 0) {         flag = i;         break;       }     if (flag)       printf( YES n%d , flag);     else       printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int M = 20;   struct edge1 {     int v, w;   };   struct edge2 {     int u, v, w;   } e[N];   struct qry {     int u, w, id;   } q[N];   vector<edge1> G[N];   int n, m, c, a[N], dep[N], ans1[N], ans2[N], f[N][M], g[N][M];   void add(int u, int v, int w) {     G[u].push_back((edge1){v, w}), G[v].push_back((edge1){u, w});   }   void dfs(int u, int fa) {     f[u][0] = fa, dep[u] = dep[fa] + 1;     for (auto e : G[u])       if (e.v != fa) g[e.v][0] = e.w, dfs(e.v, u);   }   int dist(int x, int y) {     int ans = 0;     if (dep[x] < dep[y]) swap(x, y);     for (int i = 18; i >= 0; --i)       if (dep[f[x][i]] >= dep[y]) ans = max(ans, g[x][i]), x = f[x][i];     if (x == y) return ans;     for (int i = 18; i >= 0; --i)       if (f[x][i] != f[y][i])         ans = max(ans, max(g[x][i], g[y][i])), x = f[x][i], y = f[y][i];     return max(ans, max(g[x][0], g[y][0]));   }   namespace dsu {   int fa[N], sz[N], pl[N], mxw[N], val[N];   void reset() {     for (int i = 1; i <= n; ++i)       fa[i] = pl[i] = i, val[i] = a[i], mxw[i] = 0, sz[i] = 1;   }   int find(int x) { return fa[x] == x ? fa[x] : fa[x] = find(fa[x]); }   void Merge(int a, int b) {     int x = find(a), y = find(b);     if (sz[x] > sz[y]) swap(x, y);     if (val[x] > val[y])       val[y] = val[x], mxw[y] = mxw[x], pl[y] = pl[x];     else if (val[x] == val[y])       mxw[y] = max(max(mxw[x], mxw[y]), dist(pl[x], pl[y]));     fa[x] = y, sz[y] += sz[x];   }   }  // namespace dsu   bool cmp1(edge2 a, edge2 b) { return a.w > b.w; }   bool cmp2(qry a, qry b) { return a.w > b.w; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n - 1; ++i) {       scanf( %d%d%d%d , &e[i].u, &e[i].v, &e[i].w, &c);       add(e[i].u, e[i].v, c);     }     dfs(1, 0);     for (int j = 1; j <= 18; ++j)       for (int i = 1; i <= n; ++i)         f[i][j] = f[f[i][j - 1]][j - 1],         g[i][j] = max(g[i][j - 1], g[f[i][j - 1]][j - 1]);     for (int i = 1; i <= m; ++i) scanf( %d%d , &q[i].w, &q[i].u), q[i].id = i;     sort(e + 1, e + n, cmp1);     sort(q + 1, q + m + 1, cmp2);     dsu ::reset();     for (int i = 1, j = 1; i <= m; ++i) {       for (; j <= n - 1 && e[j].w >= q[i].w; ++j) dsu ::Merge(e[j].u, e[j].v);       int res = dsu ::mxw[dsu ::find(q[i].u)];       res = max(res, dist(q[i].u, dsu ::pl[dsu ::find(q[i].u)]));       ans1[q[i].id] = dsu ::val[dsu ::find(q[i].u)], ans2[q[i].id] = res;     }     for (int i = 1; i <= m; ++i) printf( %d %d n , ans1[i], ans2[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dist(long long int a, long long int b, long long int c,               long long int d) {     return sqrt(((a - c) * (a - c)) + (b - d) * (b - d));   }   struct p {     double val;     long long int index;   };   int comp(const void* a, const void* b) {     if (((struct p*)a)->val - ((struct p*)b)->val < 0) return -1;     if (((struct p*)a)->val - ((struct p*)b)->val > 0) return 1;     if (((struct p*)a)->val - ((struct p*)b)->val == 0) return 0;   }   int main() {     long long int ax, ay, bx, by, tx, ty, n;     cin >> ax;     cin >> ay;     cin >> bx;     cin >> by;     cin >> tx;     cin >> ty;     cin >> n;     long long int i, x, y;     struct p a[n], b[n], c[n];     double sum = 0;     for (i = 0; i < n; i++) {       cin >> x;       cin >> y;       sum += 2 * dist(tx, ty, x, y);       a[i].val = dist(ax, ay, x, y) - dist(tx, ty, x, y);       a[i].index = i;       b[i].val = dist(bx, by, x, y) - dist(tx, ty, x, y);       b[i].index = i;     }     qsort(a, n, sizeof(struct p), comp);     qsort(b, n, sizeof(struct p), comp);     if (a[0].index == b[0].index) {       sum += min(a[0].val,                  min(b[0].val, min(a[0].val + b[1].val, b[0].val + a[1].val)));     } else {       if (a[0].val < b[0].val) {         sum += a[0].val;         if (b[0].val < 0) sum += b[0].val;       } else {         sum += b[0].val;         if (a[0].val < 0) sum += a[0].val;       }     }     cout << setprecision(12) << fixed << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > cpu(3);   vector<vector<int> > g(201);   int vs[201];   bool mission[201];   int start[3];   int ans = 1000000000;   int main() {     int n, startms;     cin >> n;     start[0] = -1;     start[1] = -1;     start[2] = -1;     for (int i = 0; i < n; ++i) {       int comp;       cin >> comp;       cpu[comp - 1].push_back(i);       vs[i] = comp - 1;     }     for (int i = 0; i < n; ++i) {       int tmp;       cin >> tmp;       if (tmp == 0) {         start[vs[i]] = i;       }       for (int j = 0; j < tmp; ++j) {         int v;         cin >> v;         g[i].push_back(v - 1);       }     }     for (int u = 0; u < 3; ++u) {       if (start[u] == -1) continue;       for (int j = 0; j < n; ++j) mission[j] = false;       int pc = u;       mission[start[u]] = true;       int ost = n - 1;       int hour = 1;       while (ost != 0) {         for (int i = 0; i < cpu[pc].size(); ++i) {           int ms = cpu[pc][i];           if (mission[ms] == true) {             continue;           }           bool fl = true;           for (int j = 0; j < g[ms].size(); ++j) {             if (mission[g[ms][j]] == false) {               fl = false;               break;             }           }           if (fl == true) {             mission[ms] = true;             ost--;             hour++;             i = -1;           }         }         if (ost != 0) {           hour++;           if (pc == 0) {             pc = 1;             continue;           }           if (pc == 1) {             pc = 2;             continue;           }           if (pc == 2) {             pc = 0;             continue;           }         }       }       ans = min(hour, ans);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const N = 5e5;   long long a[N];   void init_code() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     long long n, d, e;     cin >> n >> d >> e;     long long md = n / d;     long long me = n / (5 * e);     long long ans = n;     for (long long i = 0; i * 5 * e <= n; i++) {       ans = min(ans, (n - i * 5 * e) % d);     }     cout << ans <<   n ;   }   signed main() {     init_code();     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     int k, w, total;     cin >> k >> n >> w;     total = k * w * (w + 1) / 2 - n;     if (total <= 0) {       cout <<  0  << endl;     } else {       cout << total << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   void process() {     vector<vector<char> > d(8, vector<char>(8));     int x1 = 8, y1 = 8, x2 = 8, y2 = 8;     vector<vector<pair<int, int> > > steps(         8, vector<pair<int, int> >(8, make_pair(-INF, -INF)));     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         cin >> d[i][j];         if (d[i][j] ==  K )           if (x1 == 8) {             x1 = j;             y1 = i;           } else {             x2 = j;             y2 = i;           }       }     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         if (abs(x1 - j) % 4 + abs(y1 - i) % 4 == 0) steps[i][j].first = 0;         if (abs(x1 - j) % 4 == 2 && abs(y1 - i) % 4 == 2) steps[i][j].first = 1;         if (abs(x2 - j) % 4 + abs(y2 - i) % 4 == 0) steps[i][j].second = 0;         if (abs(x2 - j) % 4 == 2 && abs(y2 - i) % 4 == 2) steps[i][j].second = 1;       }     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++)         if (steps[i][j].first == steps[i][j].second && steps[i][j].first >= 0 &&             d[i][j] !=  # ) {           cout <<  YES  << endl;           return;         }     cout <<  NO  << endl;     return;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) process();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, p;   int a[33], c[100010][33];   int fac[100010], inv[100010];   int l, r, L, R, len, Ans;   inline int Pow(int x, int y) {     int Ans = 1;     for (; y; y >>= 1, x = 1ll * x * x % p)       if (y & 1) Ans = 1ll * Ans * x % p;     return Ans;   }   inline void Init() {     int t = p;     for (int i = 2; i * i <= t; i++)       if (!(t % i)) {         a[++m] = i;         t /= i;         while (!(t % i)) t /= i;       }     if (t > 1) a[++m] = t;     int phi = p;     for (int i = 1; i <= m; i++) phi = phi / a[i] * (a[i] - 1);     fac[0] = inv[0] = 1;     for (int i = 1; i < 100010; i++) {       int x = i;       for (int j = 1; j <= m; j++) {         c[i][j] = c[i - 1][j];         while (!(x % a[j])) x /= a[j], c[i][j]++;       }       fac[i] = 1ll * fac[i - 1] * x % p;       inv[i] = Pow(fac[i], phi - 1);     }   }   inline int Calc(int x, int y) {     if (x < y || y < 0) return 0;     if (!y) return 1;     int Ans = 1ll * fac[x] * inv[y] % p * inv[x - y] % p;     for (int i = 1; i <= m; i++)       Ans = 1ll * Ans * Pow(a[i], c[x][i] - c[y][i] - c[x - y][i]) % p;     return Ans;   }   int main() {     scanf( %d%d%d%d , &n, &p, &l, &r);     Init();     for (i = 0; i <= n; i++)       len = n - i, Ans = (Ans + 1ll *                                     (Calc(len, (len - l >> 1)) -                                      Calc(len, (min(r, len) + len >> 1) + 1)) *                                     Calc(n, i)) %                          p;     if (Ans < 0) Ans += p;     cout << Ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6, inf = 2e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc;     cin >> tc;     while (tc--) {       int n, x, y, d;       cin >> n >> x >> y >> d;       if (x == y)         cout <<  0 n ;       else if (abs(y - x) % d == 0)         cout << abs(y - x) / d <<   n ;       else {         int a = (x - 1) / d;         if ((x - 1) % d != 0) a++;         int t = n - x;         int b = t / d;         if (t % d != 0) b++;         if ((y - 1) % d == 0)           a = a + (y - 1) / d;         else           a = inf;         if ((n - y) % d == 0)           b = b + (n - y) / d;         else           b = inf;         a = min(a, b);         if (a == inf) a = -1;         cout << a <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a % b != 0) return gcd(b, a % b);     return b;   }   int main() {     int n, x = 0, y = 0;     cin >> n;     string a, b;     cin >> a >> b;     int k = a.size() * b.size() / gcd(a.size(), b.size());     for (int i = 0; i < k; i++) {       int t1 = i % a.size(), t2 = i % b.size();       if (a[t1] != b[t2]) {         if ((a[t1] > b[t2] && a[t1] - b[t2] != 3) || b[t2] - a[t1] == 3)           x++;         else           y++;       }     }     x *= n / k;     y *= n / k;     n %= k;     for (int i = 0; i < n; i++) {       int t1 = i % a.size(), t2 = i % b.size();       if (a[t1] != b[t2]) {         if ((a[t1] > b[t2] && a[t1] - b[t2] != 3) || b[t2] - a[t1] == 3)           x++;         else           y++;       }     }     cout << x <<     << y;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct st {     int a;     string b;   } st;   bool func(st x, st y) {     if (x.a == y.a)       return x.b > y.b;     else       return x.a > y.a;   }   int main() {     string a;     cin >> a;     int sum1 = 0;     for (int i = 0; i < a.size(); i++) sum1 += a[i] - 48;     if (a.size() == 1) {       cout << a;       return 0;     }     vector<st> v(1);     v[0].a = sum1;     v[0].b = a;     for (int i = a.size() - 2; i >= 0; i--) {       string s;       for (int j = 0; j <= i; j++) s += a[j];       s[s.size() - 1]--;       for (int j = i + 1; j < a.size(); j++) {         char f = 48 + 9;         s += f;       }       int sum2 = 0;       for (int j = 0; j < s.size(); j++) sum2 += s[j] - 48;       st x;       x.a = sum2;       x.b = s;       v.push_back(x);     }     sort(v.begin(), v.end(), func);     if (v[0].b[0] !=  0 )       cout << v[0].b;     else       for (int i = 1; i < v[0].b.size(); i++) cout << v[0].b[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   const int inf = 1e9 + 7;   double dist(double a, double b, double x, double y) {     return sqrt((x - a) * (x - a) + (y - b) * (y - b));   }   int n, i;   double px, py, a1, a2, b1, b2, c1, c2, x1, x2, asfdasgas, y2, t, x, y,       r1 = 2e9, r2, dotx, doty;   double A[N], B[N];   int main() {     scanf( %d %lf %lf , &n, &px, &py);     for (i = 1; i <= n; i++) scanf( %lf %lf , A + i, B + i);     A[n + 1] = A[1];     B[n + 1] = B[1];     for (i = 1; i <= n; i++) {       x1 = A[i];       x2 = A[i + 1];       asfdasgas = B[i];       y2 = B[i + 1];       a1 = y2 - asfdasgas;       b1 = x1 - x2;       c1 = -a1 * x1 - b1 * asfdasgas;       a2 = x2 - x1;       b2 = y2 - asfdasgas;       c2 = -a2 * px - b2 * py;       y = (a2 * c1 - a1 * c2) / (a1 * b2 - b1 * a2);       x = (b1 * c2 - b2 * c1) / (b2 * a1 - b1 * a2);       if (x >= min(x1, x2) and x <= max(x1, x2) and y >= min(asfdasgas, y2) and           y <= max(asfdasgas, y2)) {         t = dist(px, py, x, y);         if (t <= r1) {           r1 = t;           dotx = x;           doty = y;         }       } else {         t = dist(px, py, x1, asfdasgas);         if (t <= r1) {           r1 = t;           dotx = x1;           doty = asfdasgas;         }         t = dist(px, py, x2, y2);         if (t <= r1) {           r1 = t;           dotx = x2;           doty = y2;         }       }     }     for (i = 1; i <= n; i++) r2 = max(r2, dist(px, py, A[i], B[i]));     printf( %.8lf , acos(-1) * r2 * r2 - acos(-1) * r1 * r1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     double ans = m;     double i = 1;     while (1) {       if (i >= m) break;       double j = (m - i) / m;       double k = 1;       int q = n;       while (q != 0) {         if (q & 1 == 1) k *= j;         q = q >> 1;         j *= j;       }       if (k <= 0.00000001) break;       ans -= k;       i++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   const int N = 350, mo = 1e9 + 7;   int n, f[N][N], len, A[N], fac[N], ifac[N], qz[N];   map<int, int> Map;   inline void exgcd(int a, int b, int &x, int &y) {     if (!b) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= a / b * x;   }   inline int inv(int a) {     int x, y;     exgcd(a, mo, x, y);     return x >= 0 ? x : x + mo;   }   inline int C(int n, int m) {     if (m < 0 || m > n) return 0;     return 1LL * fac[n] * ifac[m] % mo * ifac[n - m] % mo;   }   inline void add(int &a, int b) { a = a + b < mo ? a + b : a + b - mo; }   int main() {     read(n);     for (register int i = 1; i <= n; i++) {       int x;       read(x);       for (int j = 2; j * j <= x; j++) {         while (x % (j * j) == 0) x /= j * j;       }       Map[x]++;     }     while (!Map.empty()) {       A[++len] = (*Map.begin()).second;       qz[len] = qz[len - 1] + A[len];       Map.erase(Map.begin());     }     fac[0] = 1;     for (register int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mo;     ifac[n] = inv(fac[n]);     for (register int i = n - 1; i >= 0; i--)       ifac[i] = 1LL * ifac[i + 1] * (i + 1) % mo;     f[0][0] = 1;     for (register int i = 0; i <= len - 1; i++)       for (register int j = 0; j <= n + 1; j++)         if (f[i][j]) {           int now = f[i][j];           int red = j, blue = qz[i] - j + 1;           for (register int a = 0; a <= blue; a++)             for (register int b = 0; b <= red; b++)               if (a + b <= A[i + 1])                 add(f[i + 1][j - b + A[i + 1] - a - b],                     1LL * now * C(blue, a) % mo * C(red, b) % mo *                         C(A[i + 1] - 1, a + b - 1) % mo * fac[A[i + 1]] % mo);         }     cout << f[len][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     for (int i = 0; i < int(a.size() - 2); ++i) {       char x = a[i], y = a[i + 1], z = a[i + 2];       if (x !=  .  && y !=  .  && z !=  . )         if (x != y && x != z && y != z) {           cout <<  Yes  << endl;           return 0;         }     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long i, j, k;     int n;     cin >> n;     vector<int> arr(n);     int f, l;     f = 1;     l = n;     int sz = 0;     while (sz < n) {       if (sz % 2 == 0) {         arr[sz] = f;         sz++;         f++;       } else {         arr[sz] = l;         sz++;         l--;       }     }     for (auto it : arr) {       cout << it <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> d;     for (int i = 0; i < n; ++i) {       int pos = upper_bound(d.begin(), d.end(), a[i]) - d.begin();       if (pos == d.size())         d.push_back(a[i]);       else         d[pos] = a[i];     }     cout << d.size();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x;     x = 2;     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       long long y = (x / i);       if (y >= i * (i + 1) * (i + 1)) {         throw 1;       }       printf( %I64d n , i * (i + 1) * (i + 1) - y);       x = i * (i + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int n, par[N], up[N], h[N], max_h[N];   vector<int> child[N], vec, ans;   void dfs(int v = 0) {     for (int u : child[v]) {       h[u] = max_h[u] = h[v] + 1;       dfs(u);       max_h[v] = max(max_h[v], max_h[u]);     }     sort(child[v].begin(), child[v].end(),          [](int u, int v) { return max_h[u] < max_h[v]; });   }   void bamboo(int v = 0) {     if (v) up[v] = vec.back();     vec.push_back(v);     for (int u : child[v]) bamboo(u);   }   void solve(int v = 0) {     while (v && up[v] != par[v]) {       ans.push_back(v);       up[v] = up[up[v]];     }     for (int u : child[v]) solve(u);   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       cin >> par[i];       child[par[i]].push_back(i);     }     dfs();     bamboo();     for (int v : vec) cout << v <<    ;     cout <<   n ;     solve();     cout << ans.size() <<   n ;     for (int u : ans) cout << u <<    ;   }


#include <bits/stdc++.h>   int main() {     int mem, arr[5001], i, tri = 0;     scanf( %d , &mem);     for (i = 1; i <= mem; i++) {       scanf( %d , &arr[i]);     }     for (i = 1; i <= mem; i++) {       if (i == arr[arr[arr[i]]]) {         tri = 1;       }     }     if (tri == 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, k, bottom, top;     cin >> n >> k;     bottom = 1;     top = n;     for (long i = 0; i < k - 1; i++) {       if (i % 2 == 0) {         cout << bottom <<    ;         bottom++;       } else {         cout << top <<    ;         top--;       }     }     long sum, val;     if ((k - 1) % 2 == 0) {       val = bottom;       sum = 1;     } else {       val = top;       sum = -1;     }     for (long i = 0; i <= n - k; i++) {       cout << val <<    ;       val += sum;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3050;   int n, p, s;   int sump[N], sum[N];   struct Student {     int a, b, id;     void input() { scanf( %d%d , &a, &b); }     bool operator<(const Student &student) const {       return b - a < student.b - student.a;     }   } data[N];   void del() {     sort(data + 1, data + n + 1);     sum[0] = 0;     sump[0] = 0;     for (int i = 1; i <= n; i++) {       sump[i] = sump[i - 1] + data[i].a;       sum[i] = sum[i - 1] + data[i].b - data[i].a;     }     int id = -1, ans = 0;     for (int i = 1; i <= n; i++) {       int cur;       if (i <= p)         cur = sump[n] + sum[n] - sum[p + 1] - data[i].a;       else         cur = sump[n] + sum[n] - sum[p] - data[i].b;       if (cur > ans) {         ans = cur;         id = i;       }     }     swap(data[id], data[n]);     n--;   }   void solve() {     for (int i = 1; i <= n; i++) scanf( %d , &data[i].a);     for (int i = 1; i <= n; i++) scanf( %d , &data[i].b);     for (int i = 1; i <= n; i++) data[i].id = i;     int k = n - p - s;     for (int i = 0; i < k; i++) del();     sort(data + 1, data + n + 1);     int ans = 0;     for (int i = 1; i <= p; i++) ans += data[i].a;     for (int i = p + 1; i <= n; i++) ans += data[i].b;     printf( %d n , ans);     for (int i = 1; i <= p; i++) printf( %d  , data[i].id);     puts(  );     for (int i = p + 1; i <= n; i++) printf( %d  , data[i].id);     puts(  );   }   int main() {     while (scanf( %d%d%d , &n, &p, &s) != EOF) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e6 + 3;   const int N = 1e2 + 5;   int n, wid, hei;   long long f[N], phei[N];   struct matrix {     long long a[N][N];     matrix() { memset(a, 0, sizeof(a)); }   } base, cur;   matrix operator*(matrix a, matrix b) {     matrix ans;     for (auto i = (0); i <= (wid); i++)       for (auto j = (0); j <= (wid); j++)         for (auto k = (0); k <= (wid); k++)           ans.a[i][j] = (ans.a[i][j] + a.a[i][k] * b.a[k][j]) % MOD;     return ans;   }   void prepare() {     cin >> n >> wid >> hei;     phei[0] = 1;     for (auto i = (1); i <= (wid); i++) phei[i] = phei[i - 1] * hei % MOD;     f[0] = 1;     for (auto i = (1); i <= (wid); i++)       for (int j = 1; j <= min(i, wid); j++)         f[i] = (f[i] + f[i - j] * phei[j - 1]) % MOD;     for (auto i = (1); i <= (wid); i++) base.a[i][i - 1] = 1;     for (auto i = (0); i <= (wid); i++) base.a[i][wid] = phei[wid - i];   }   long long solve() {     n++;     if (n <= wid) return f[n];     n -= wid;     for (auto i = (0); i <= (wid); i++) cur.a[i][i] = 1;     while (n) {       if (n & 1) cur = cur * base;       base = base * base;       n >>= 1;     }     long long ans = 0;     for (auto i = (0); i <= (wid); i++) ans = (ans + f[i] * cur.a[i][wid]) % MOD;     return ans;   }   int main() {     prepare();     cout << solve();   }


#include <bits/stdc++.h>   const int MN = 100005, MS = 1 << 18 | 7;   namespace HASH {   const int mod = 1e9 + 7;   const int bs = 29;   const int iv = 758620695;   int _w[MN << 1], *w = _w + MN;   void init(int N) {     w[0] = 1;     for (int i = 1; i < N; ++i) {       w[+i] = 1ll * w[i - 1] * bs % mod;       w[-i] = 1ll * w[1 - i] * iv % mod;     }   }   struct str {     int x, m;     str(int _v = 0, int _len = 0) : x(_v), m(_len) {}     inline bool operator==(const str& rhs) const {       return x == rhs.x && m == rhs.m;     }     inline str operator+(const str& rhs) const {       return str((x + 1ll * rhs.x * w[m]) % mod, m + rhs.m);     }     inline str operator-(const str& rhs) const {       return str(1ll * (x - rhs.x + mod) * w[-rhs.m] % mod, m - rhs.m);     }   };   }  // namespace HASH   using HASH::str;   int N, Q;   struct node {     bool err;     str vl, vr;     node(int _v = 0) {       err = 0;       if (_v != 0) _v > 0 ? vr = str(_v, 1) : vl = str(-_v, 1);     }   } tr[MN << 3];   str gValL(int i, int k) {     if (!k) return str();     if (k == tr[i].vl.m) return tr[i].vl;     if (k <= tr[(i << 1)].vl.m) return gValL((i << 1), k);     return tr[(i << 1)].vl +            (gValL(((i << 1) | 1), k - tr[(i << 1)].vl.m + tr[(i << 1)].vr.m) -             tr[(i << 1)].vr);   }   str gValR(int i, int k) {     if (!k) return str();     if (k == tr[i].vr.m) return tr[i].vr;     if (k <= tr[((i << 1) | 1)].vr.m) return gValR(((i << 1) | 1), k);     return tr[((i << 1) | 1)].vr + (gValR((i << 1), k - tr[((i << 1) | 1)].vr.m +                                                         tr[((i << 1) | 1)].vl.m) -                                     tr[((i << 1) | 1)].vl);   }   void Upd(int i) {     if (tr[(i << 1)].err || tr[((i << 1) | 1)].err) return tr[i].err = 1, void();     tr[i].err = 0;     tr[i].vl = tr[(i << 1)].vl;     tr[i].vr = tr[((i << 1) | 1)].vr;     if (tr[(i << 1)].vr.m <= tr[((i << 1) | 1)].vl.m) {       if (tr[(i << 1)].vr == gValL(((i << 1) | 1), tr[(i << 1)].vr.m))         tr[i].vl = tr[i].vl + (tr[((i << 1) | 1)].vl - tr[(i << 1)].vr);       else         tr[i].err = 1;     } else {       if (tr[((i << 1) | 1)].vl == gValR((i << 1), tr[((i << 1) | 1)].vl.m))         tr[i].vr = tr[i].vr + (tr[(i << 1)].vr - tr[((i << 1) | 1)].vl);       else         tr[i].err = 1;     }   }   void Build(int i, int l, int r) {     if (l == r) {       int x;       scanf( %d , &x);       tr[i] = x;       return;     }     Build((i << 1), l, ((l + r) >> 1)),         Build(((i << 1) | 1), ((l + r) >> 1) + 1, r);     Upd(i);   }   void Mdf(int i, int l, int r, int p, int x) {     if (l == r) return tr[i] = x, void();     p <= ((l + r) >> 1) ? Mdf((i << 1), l, ((l + r) >> 1), p, x)                         : Mdf(((i << 1) | 1), ((l + r) >> 1) + 1, r, p, x);     Upd(i);   }   int stk[45], tp;   void Extract(int i, int l, int r, int a, int b) {     if (r < a || b < l) return;     if (a <= l && r <= b) return stk[++tp] = i, void();     Extract((i << 1), l, ((l + r) >> 1), a, b),         Extract(((i << 1) | 1), ((l + r) >> 1) + 1, r, a, b);   }   str seq[45];   str gVal(int i, int k) {     if (!k) return str();     if (k == seq[i].m) return seq[i];     if (k <= tr[stk[i]].vr.m) return gValR(stk[i], k);     return tr[stk[i]].vr +            (gVal(i - 1, k - tr[stk[i]].vr.m + tr[stk[i]].vl.m) - tr[stk[i]].vl);   }   bool Qur(int l, int r) {     tp = 0, Extract(1, 1, N, l, r);     for (int i = 1; i <= tp; ++i) {       if (tr[stk[i]].err) return 0;       if (seq[i - 1].m < tr[stk[i]].vl.m) return 0;       if (tr[stk[i]].vl == gVal(i - 1, tr[stk[i]].vl.m))         seq[i] = tr[stk[i]].vr + (seq[i - 1] - tr[stk[i]].vl);       else         return 0;     }     return !seq[tp].m;   }   int main() {     scanf( %d%*d , &N);     HASH::init(N);     Build(1, 1, N);     scanf( %d , &Q);     while (Q--) {       int t, x, y;       scanf( %d%d%d , &t, &x, &y);       if (t == 1)         Mdf(1, 1, N, x, y);       else         puts(Qur(x, y) ?  Yes  :  No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int cnt = 0;     int len = s.length();     for (int i = 0; i < len; i++) {       if (s.at(i) ==  a ) cnt++;     }     int ltr = len - cnt;     while (ltr >= cnt) {       ltr--;       len--;     }     cout << len;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int P = 1e9 + 7;   const int inf = 1e9;   const long long Inf = 1e15;   inline int IN() {     char ch = getchar();     int x = 0, f = 0;     while (ch <  0  || ch >  9 ) ch = getchar(), f = (ch ==  - );     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch - 48;       ch = getchar();     }     return f ? (-x) : x;   }   inline int Pow(int x, int y, int p) {     int an = 1;     for (; y; y >>= 1, x = (long long)x * x % p)       if (y & 1) an = (long long)an * x % p;     return an;   }   void renew(int &x, int y) {     x += y;     if (x < 0)       x += P;     else if (x >= P)       x -= P;   }   void setIO(string a) {     freopen((a +  .in ).c_str(),  r , stdin);     freopen((a +  .out ).c_str(),  w , stdout);   }   template <typename T>   inline void chkmin(T &a, const T &b) {     if (a > b) a = b;   }   template <typename T>   inline void chkmax(T &a, const T &b) {     if (a < b) a = b;   }   int n, k;   int dp[1000005], g[1000005], fac[1000005], inv[1000005];   int main() {     scanf( %d%d , &n, &k);     fac[0] = 1;     for (int i = (int)1; i <= (int)n; i++) fac[i] = (long long)fac[i - 1] * i % P;     inv[0] = inv[1] = 1;     for (int i = (int)2; i <= (int)n; i++)       inv[i] = (long long)inv[P % i] * (P - P / i) % P;     for (int i = (int)2; i <= (int)n; i++)       inv[i] = (long long)inv[i - 1] * inv[i] % P;     dp[1] = dp[0] = 1;     for (int i = (int)2; i <= (int)k; i++) dp[i] = (long long)dp[i - 1] * i % P;     for (int i = (int)1; i <= (int)k; i++)       g[i] = (g[i - 1] + (long long)inv[i] * dp[i]) % P;     for (int i = (int)k + 1; i <= (int)n; i++) {       dp[i] = (g[i - 1] + P - g[i - k - 1]) % P;       dp[i] = (long long)dp[i] * fac[i - 1] % P;       g[i] = (g[i - 1] + (long long)inv[i] * dp[i]) % P;     }     int ans = 0;     for (int i = (int)0; i <= (int)n - 1; i++)       ans = (ans + (long long)dp[i] * fac[n - 1] % P * inv[i]) % P;     ans = (0LL + fac[n] - ans) % P;     ans = (ans + P) % P;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   const int N = 200000;   int f[N + 5];   namespace segt {   const int S = (N << 2);   struct type {     int mn, lm, rm, m, s;     friend type operator+(const type &a, const type &b) {       type c;       c.mn = std::min(a.mn, b.mn), c.m = std::max(a.m, b.m);       if (a.mn < b.mn) {         c.lm = a.lm, c.rm = std::max(a.rm, b.m), c.s = a.s;       } else if (a.mn > b.mn) {         c.lm = std::max(a.m, b.lm), c.rm = b.rm, c.s = b.s;       } else {         c.lm = a.lm, c.rm = b.rm, c.s = a.s + b.s + std::max(a.rm, b.lm);       }       return c;     }   } t[S + 5];   int le[S + 5], ri[S + 5], tag[S + 5];   void addtag(int x, int k) { tag[x] += k, t[x].mn += k; }   void pushup(int x) { t[x] = t[(x << 1)] + t[(x << 1 | 1)]; }   void pushdown(int x) {     if (tag[x])       addtag((x << 1), tag[x]), addtag((x << 1 | 1), tag[x]), tag[x] = 0;   }   void build(int x, int l, int r) {     le[x] = l, ri[x] = r, t[x] = (type){0, 0, 0, 0, 0};     if (l == r) return;     int m = (l + r) >> 1;     build((x << 1), l, m), build((x << 1 | 1), m + 1, r);   }   void add(int x, int l, int r, int d) {     if (r < le[x] || l > ri[x]) return;     if (l <= le[x] && ri[x] <= r) {       addtag(x, d);       return;     }     pushdown(x), add((x << 1), l, r, d), add((x << 1 | 1), l, r, d), pushup(x);   }   void update(int x, int p) {     if (le[x] == ri[x]) {       t[x].lm = f[p], t[x].rm = f[p + 1], t[x].m = std::max(f[p], f[p + 1]);       return;     }     int m = (le[x] + ri[x]) >> 1;     pushdown(x), update(p <= m ? (x << 1) : (x << 1 | 1), p), pushup(x);   }   }  // namespace segt   std::set<int> st[N + 5];   int a[N + 5], n, q;   void clear(int x) {     if (st[x].empty()) return;     int lc = *st[x].begin();     segt::add(1, lc, (*st[x].rbegin()) - 1, -1);     f[lc] = 0, segt::update(1, lc - 1), segt::update(1, lc);   }   void calc(int x) {     if (st[x].empty()) return;     int lc = *st[x].begin();     segt::add(1, lc, (*st[x].rbegin()) - 1, 1);     f[lc] = (int)st[x].size(), segt::update(1, lc - 1), segt::update(1, lc);   }   void erase(int i) {     int x = a[i];     clear(x), st[x].erase(i), calc(x);   }   void insert(int i) {     int x = a[i];     clear(x), st[x].insert(i), calc(x);   }   int main() {     scanf( %d%d , &n, &q);     segt::build(1, 0, n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), insert(i);     printf( %d n , n - segt::t[1].s);     for (int t = 1, i, x; t <= q; t++) {       scanf( %d%d , &i, &x);       erase(i), a[i] = x, insert(i);       printf( %d n , n - segt::t[1].s);     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   inline long long llread() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   int n;   char s[25][400010];   int l[25], rest[25];   vector<int> v[25][400010];   int dp[(1 << 20) + 10][2], g[(1 << 20) + 10];   signed main() {     n = read();     for (int i = (1); i <= (n); i++) scanf( %s , s[i] + 1);     for (int i = (1); i <= (n); i++) l[i] = strlen(s[i] + 1);     for (int i = (1); i <= (n); i++) {       int top = 0;       for (int j = (1); j <= (l[i]); j++) {         if (s[i][j] ==  ( )           top++;         else           top--;         if (top <= 0) v[i][-top].push_back(j);       }       rest[i] = top;     }     for (int i = (1); i <= ((1 << n) - 1); i++) dp[i][0] = dp[i][1] = -0x3f3f3f3f;     dp[0][0] = dp[0][1] = g[0] = 0;     for (int mask = (1); mask <= ((1 << n) - 1); mask++) {       for (int i = (1); i <= (n); i++) {         if (mask & (1 << (i - 1))) {           int S = mask ^ (1 << (i - 1));           if (dp[mask][0] < dp[S][0]) {             dp[mask][0] = dp[S][0];           };           if (g[S] >= 0) {             int x;             if (v[i][g[S] + 1].size() == 0)               x = l[i] + 1;             else               x = v[i][g[S] + 1][0];             int y = lower_bound(v[i][g[S]].begin(), v[i][g[S]].end(), x) -                     v[i][g[S]].begin();             if (x == l[i] + 1) {               if (dp[mask][1] < dp[S][1] + y) {                 dp[mask][1] = dp[S][1] + y;               };             }             if (dp[mask][0] < dp[S][1] + y) {               dp[mask][0] = dp[S][1] + y;             };           }           g[mask] = g[S] + rest[i];         }       }     }     printf( %d n , max(dp[(1 << n) - 1][0], dp[(1 << n) - 1][1]));     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m;     int b[200];     int t[200];     int tmp;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) t[i] = 1;     for (int i = 0; i < m; ++i) {       scanf( %d , &tmp);       for (int j = tmp; j <= n; ++j) {         if (t[j] == 1) {           b[j] = tmp;           t[j] = 0;         }       }     }     for (int i = 1; i <= n; ++i) printf( %d  , b[i]);   }


#include <bits/stdc++.h>   using namespace std;   void read (int &x) {       char ch = getchar(); int f = 0; x = 0;       while (!isdigit(ch)) { if (ch ==  - ) f = 1; ch = getchar(); }       while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();       if (f) x = -x;   } const int N = 3e5 + 5;   int n, a[N], f[N], fr[N], d[N], k[N], lg[N];   #define cmax(x, y) (x = x > y ? x : y)   struct ans { int v, w; } ;   struct st {       int c[N][19];       void pre () {           for (int i = 0; i <= n; ++i) c[i][0] = a[i] + i;           for (int i = 1; (1 << i) <= n; ++i)               for (int j = 1; j + (1 << i) - 1 <= n; ++j)                   c[j][i] = max (c[j][i - 1], c[j + (1 << i - 1)][i - 1]);       }       int query (int l, int r) {           if (l > r) return 0; int t = lg[r - l + 1];           // printf ( %d %d %d n , l, r, max (c[l][t], c[r - (1 << t) + 1][t]));           return max (c[l][t], c[r - (1 << t) + 1][t]);       }   } A;   signed main() {       int T; read (T); lg[0] = -1;       for (int i = 1; i <= 300002; ++i) lg[i] = lg[i >> 1] + 1;       while (T--) {           read (n); a[++n] = 0;           for (int i = 1; i < n; ++i) read (a[i]); A.pre ();           for (int i = 0; i <= n; ++i) f[i] = k[i] = fr[i] = 0;           for (int i = 1, l, r, m, j, mx = -1, w = 0; i <= n; ++i) {               l = 0, r = i - 1, j = -1;               while (l <= r) {                   m = l + r >> 1;                   if (f[m] + 1 >= i - a[i]) j = m, r = m - 1;                   else l = m + 1;               }               if (j >= 0) f[i] = max (A.query (j + 1, i - 1), i - 1), fr[i] = j;               if (f[i - 1] >= i && f[i] < i + a[i]) f[i] = i + a[i], fr[i] = i - 1, k[i] = 1;               if (mx > f[i]) f[i] = mx, fr[i] = w; else mx = f[i], w = i;               // printf ( 666 %d %d %d %d n , j, i, f[i], fr[i]);           }           if (f[n] >= n - 1) {               puts ( YES );               for (int i = n; i >= 1; i = fr[i]) {                   for (int j = fr[i] + 1; j < i; ++j) d[j] = 1; d[i] = k[i];               }               for (int i = 1; i < n; ++i) putchar (d[i] ?  R  :  L ); puts (  );           } else puts ( NO );       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     bool ch = 0;     bool arr[n + 1];     vector<int> vec, vec1;     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (b > a) swap(a, b);       vec.push_back(a);       vec1.push_back(b);     }     if (!m)       cout << n - 1;     else {       sort(vec.begin(), vec.end());       sort(vec1.begin(), vec1.end());       cout << max(0, vec[0] - vec1[vec1.size() - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     bool p = 1;     cin >> a;     int A[a];     for (int i = 0; i < a; i++) {       cin >> A[i];       if (A[i] == 1) {         p = 0;       }     }     if (p) {       cout <<  EASY ;     } else {       cout <<  HARD ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long min(long long a, long long b) { return (a < b) ? a : b; }   vector<long long> ar[100010];   long long vis[100010], dist[10001];   long long solve() { return 0; }   long long cc;   double pi = 3.141592653589793238;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       n = 2 * n;       double ans = 1 / tan(pi / n);       cout << fixed << setprecision(11) << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, c, a;     cin >> n >> c;     vector<int> arr;     for (int i = 0; i < n; i++) {       cin >> a;       arr.push_back(a);     }     int maxx = 0;     for (int i = 0; i < n - 1; i++) {       maxx = max(maxx, arr[i] - arr[i + 1] - c);     }     cout << maxx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100001;   long long h, c, temp;   long double f(long long m) {     long double r = 1.0 * (m * h + (m)*c) / (2 * m);     return (abs(r - temp));   }   long double f12(long long m) {     long double r = 1.0 * (m * h + (m - 1) * c) / (2 * m - 1);     return (abs(r - temp));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     cin >> t;     while (t--) {       long long i, j, k;       cin >> h >> c >> temp;       long long l = 1;       long long r = 1000000000;       while (r - l > 2) {         long long m1 = (l * 2 + r) / 3;         long long m2 = (l + 2 * r) / 3;         if (f(m1) > f(m2))           l = m1;         else           r = m2;       }       long double ans = f(2);       j = 2;       for (i = l; i <= r; i++) {         if (f(i) < ans) {           j = 2 * i;           ans = f(i);         }       }       l = 1;       r = 1000000000;       while (r - l > 2) {         long long m1 = (l * 2 + r) / 3;         long long m2 = (l + 2 * r) / 3;         if (f12(m1) > f12(m2))           l = m1;         else           r = m2;       }       for (i = l; i <= r; i++) {         if (f12(i) < ans) {           j = 2 * i - 1;           ans = f12(i);         }       }       cout << j <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long m, d;   long long a[1000][1000];   long long me[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> m >> d;     long long cnt = 1, cnt1 = 0;     long long pr = 0;     long long ok = 0;     for (long long i = 1; i <= 1000; i++) {       if (ok == 0) {         for (long long j = d; j <= 7; j++) {           a[i][j] = cnt;           cnt++;           if (cnt - 1 == me[m - 1]) {             cout << i;             return 0;           }         }         ok = 1;       } else {         for (long long j = 1; j <= 7; j++) {           a[i][j] = cnt;           cnt++;           if (cnt - 1 == me[m - 1]) {             cout << i;             return 0;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 4e18;   const int inf = 2e9;   const double eps = 1e-13;   const int N = 1e5 + 5;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   int mod;   int a[N];   int b[N];   void norm(int &x) {     x %= mod;     if (x < 0) x += mod;   }   int main(void) {     int i, j, n, m;     scanf( %d %d %d , &n, &m, &mod);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (i = 1; i <= m; ++i) {       scanf( %d , &b[i]);       b[i] += b[i - 1];     }     for (i = 1; i <= n; ++i) {       int l = max(1, m - n + i);       int r = min(m, i);       a[i] += b[r] - b[l - 1];       norm(a[i]);       printf( %d  , a[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   template <class _T>   bool maximize(_T &a, _T b) {     return a < b ? a = b, 1 : 0;   }   template <class _T>   bool minimize(_T &a, _T b) {     return a > b ? a = b, 1 : 0;   }   const int ooit = 2e9;   const long long ooll = 1e15;   using namespace std;   int n, q, a[200005];   void enter() {     cin >> n >> q;     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       a[i] = (int)c;     }   }   set<int> pos[256];   struct BIT {     int val[200005];     void update(int i, int x, int n) {       for (; i <= n; i += i & -i) val[i] += x;     }     int get(int i) {       int res = 0;       for (; i > 0; i -= i & -i) res += val[i];       return res;     }   } tree;   void prepare() {     for (int i = 1; i <= n; i++) pos[a[i]].insert(i), tree.update(i, 1, n);   }   int tfind(int x) {     int l = 1, r = n, res = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (tree.get(mid) >= x)         r = mid - 1, res = mid;       else         l = mid + 1;     }     return res;   }   bool is_remove[200005];   void update(int l, int r, int x) {     auto it_down = pos[x].lower_bound(l);     if (it_down == pos[x].end()) return;     auto it_up = pos[x].upper_bound(r);     vector<int> must_remove;     for (; it_down != it_up; it_down++) must_remove.push_back(*it_down);     for (auto i : must_remove) {       pos[x].erase(i);       tree.update(i, -1, n);       is_remove[i] = true;     }   }   void process() {     prepare();     for (int i = 1; i <= q; i++) {       int l, r, cx;       char c;       cin >> l >> r >> c;       cx = (int)c;       int tl = tfind(l), tr = tfind(r);       update(tl, tr, cx);     }     for (int i = 1; i <= n; i++)       if (!is_remove[i]) cout << (char)a[i];     cout << endl;   }   int main() {     enter();     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INFint = 2147483647;   const long long INF = 9223372036854775807ll;   const long long MOD = 1000000007ll;   const long double EPS = 1e-9;   vector<int> p;   vector<int> used;   vector<vector<int> > g;   long long ans = 0;   void dfs(int v) {     used[v] = 1;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (used[to]) {         if (p[to] == p[v]) {           ans++;         }       } else {         p[to] = !p[v];         dfs(to);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     p.resize(n);     g.resize(n);     used.resize(n);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 0; i < n; i++) {       if (!used[i]) {         p[i] = 0;         dfs(i);       }     }     ans /= 2;     if ((n - ans) & 1) ans++;     cout << ans << endl;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1000 * 100 + 10, Z = 26, P = 2, mod = 1e9 + 9;   int pw[N], wp[N], n, m, tar[Z], hsh[N][Z];   string s, t;   long long Pow(long long a, long long b) {     return b ? (b & 1 ? a : 1) % mod * Pow(a * a % mod, b >> 1) % mod : 1;   }   int add(int a, int b) {     a += b;     a += (a < 0) * mod;     a -= (a >= mod) * mod;     return a;   }   int mul(int a, int b) { return 1LL * a * b % mod; }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     pw[0] = 1;     for (int i = 1; i < N; i++) pw[i] = mul(pw[i - 1], P);     wp[N - 1] = Pow(pw[N - 1], mod - 2);     for (int i = N - 2; i >= 0; i--) wp[i] = mul(wp[i + 1], P);     cin >> n >> m >> s >> t;     for (int i = 0; i < m; i++)       for (int j = 0; j < Z; j++)         tar[j] = add(tar[j], mul(pw[i], t[i] -  a  == j));     vector<pair<int, int>> targ;     for (int i = 0; i < Z; i++) targ.push_back({tar[i], i});     sort(targ.begin(), targ.end());     for (int i = 1; i <= n; i++)       for (int j = 0; j < Z; j++)         hsh[i][j] = add(hsh[i - 1][j], mul(pw[i - 1], s[i - 1] -  a  == j));     vector<int> o;     for (int i = 0; i + m <= n; i++) {       bool res = true;       vector<pair<int, int>> me;       for (int j = 0; j < Z; j++) {         int val = mul(add(hsh[i + m][j], -hsh[i][j]), wp[i]);         me.push_back({val, j});       }       sort(me.begin(), me.end());       for (int i = 0; i < Z; i++) res &= me[i].first == targ[i].first;       set<pair<int, int>> st;       set<int> NO;       for (int i = 0; i < Z; i++) {         if (me[i].first == 0) continue;         if (me[i].second != targ[i].second)           if (me[i].second < targ[i].second)             st.insert({me[i].second, targ[i].second});           else             st.insert({targ[i].second, me[i].second});         else           NO.insert(me[i].second);       }       set<int> F, S;       for (auto it : st) F.insert(it.first), S.insert(it.second);       res &= (int)(F.size()) == (int)(st.size());       res &= (int)(S.size()) == (int)(st.size());       for (auto it : st) S.insert(it.first);       res &= (int)(S.size()) == ((int)(st.size()) * 2);       for (auto it : S) res &= !NO.count(it);       if (res) o.push_back(i + 1);     }     cout << (int)(o.size()) <<   n ;     for (auto i : o) cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   bool used[N][N];   bool best[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     vector<pair<int, int>> points(3);     for (auto& [x, y] : points) {       cin >> x >> y;     }     int x, y, cnt;     auto update_x = [&](int a) {       while (x != a) {         if (x > a) {           --x;         } else {           ++x;         }         if (!used[x][y]) {           used[x][y] = true;           ++cnt;         }       }     };     auto update_y = [&](int a) {       while (y != a) {         if (y > a) {           --y;         } else {           ++y;         }         if (!used[x][y]) {           used[x][y] = true;           ++cnt;         }       }     };     int ans = 1e9;     vector<int> perm = {0, 1, 2};     do {       for (int dir1 = 0; dir1 < 2; ++dir1) {         for (int dir2 = 0; dir2 < 2; ++dir2) {           memset(used, false, sizeof used);           x = points[perm[0]].first;           y = points[perm[0]].second;           used[x][y] = true;           cnt = 1;           if (dir1 == 0) {             update_x(points[perm[1]].first);             update_y(points[perm[1]].second);           } else {             update_y(points[perm[1]].second);             update_x(points[perm[1]].first);           }           if (dir2 == 0) {             update_x(points[perm[2]].first);             update_y(points[perm[2]].second);           } else {             update_y(points[perm[2]].second);             update_x(points[perm[2]].first);           }           if (cnt < ans) {             ans = cnt;             memcpy(best, used, sizeof used);           }         }       }     } while (next_permutation(perm.begin(), perm.end()));     cout << ans <<   n ;     for (int i = 0; i <= 1000; ++i) {       for (int j = 0; j <= 1000; ++j) {         if (best[i][j]) {           cout << i <<     << j <<   n ;         }       }     }   }


#include <bits/stdc++.h>   int main() {     long int a, i, s;     scanf( %ld , &a);     s = a;     if (a != 1) {       for (i = 2;; i++) {         s = s + 1 + i * (a - i);         if ((a - i) == 0) {           break;         }       }       printf( %ld , s);     } else {       printf( 1 );     }   }


#include <bits/stdc++.h>   using namespace std;   int A[] = {2, 3, 5, 7, 11, 13, 17, 19}, n, B[5005], vmax;   priority_queue<int> Q;   set<int> S;   inline int sol(int i) {     int j, k, t, first, second;     B[0] = 1;     for (j = 1; j <= n; j++) {       first = B[j - 1] * A[0];       for (t = 0; t < j; t++)         for (k = 0; k < i; k++)           if (B[t] * A[k] > B[j - 1]) first = min(first, B[t] * A[k]);       B[j] = first;       if (first > vmax) return 0;     }     for (j = 0; j < i; j++) {       first = 0;       for (k = 1; k <= n; k++)         if (B[k] % A[j] == 0) first++;       if (first < (n + 1) / 2) {         S.clear();         for (k = 1; k <= n; k++) S.insert(B[k]);         first = (n + 1) / 2 - first;         for (k = 1; k <= n && first; k++)           if (B[k] % A[j] != 0) {             second = B[k] * A[j];             while (S.find(second) != S.end()) {               second *= A[j];               if (second > vmax) return 0;             }             if (second > vmax) return 0;             S.erase(B[k]);             B[k] = second;             S.insert(B[k]);             first--;           }         sort(B + 1, B + n + 1);       }     }     for (j = 0; j < i; j++) {       first = 0;       for (k = 1; k <= n; k++)         if (B[k] % A[j] == 0) first++;       if (first < (n + 1) / 2) return 0;     }     return 1;   }   int main() {     cin >> n;     vmax = 2 * n * n;     int i;     for (i = 1; i <= 8; i++)       if (sol(i)) break;     printf( %d , B[1]);     for (i = 2; i <= n; i++) printf(  %d , B[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int teamA, teamB, y1, y2, y;     cin >> teamA >> teamB >> y1 >> y2 >> y;     int min = y - (teamA * (y1 - 1) + teamB * (y2 - 1));     if (min < 0) {       cout << 0 <<    ;     } else {       cout << min <<    ;     }     int max = y - teamA * y1 - teamB * y2;     if (max < 0) {       if (y2 < y1) {         max = y - teamB * y2;         if (max < 0) {           cout << y / y2 << endl;           return 0;         } else if (max == 0) {           cout << teamB << endl;           return 0;         }         cout << teamB + max / y1 << endl;         return 0;       } else {         max = y - teamA * y1;         if (max < 0) {           cout << y / y1 << endl;           return 0;         } else if (max == 0) {           cout << teamA << endl;           return 0;         }         cout << teamA + max / y2 << endl;         return 0;       }     } else {       cout << teamA + teamB << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   long long a[maxn], s1, s2;   double ans[maxn];   int l[maxn], r[maxn];   vector<int> gao[6][maxn];   int n, m, pos;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     l[1] = 1;     for (int i = 2; i <= n; i++) {       l[i] = i;       while (l[i] != 1 && a[l[i] - 1] > a[i]) l[i] = l[l[i] - 1];     }     r[n] = n;     for (int i = n - 1; i >= 1; i--) {       r[i] = i;       while (r[i] != n && a[r[i] + 1] >= a[i]) r[i] = r[r[i] + 1];     }     for (int i = 1; i <= n; i++) {       int a1 = r[i] + 1 - i;       int a2 = i + 1 - l[i];       if (a1 <= a2) {         gao[0][a1].push_back(i);         gao[1][a2 + 1].push_back(i);         gao[2][r[i] - l[i] + 3].push_back(i);       } else {         gao[3][a2].push_back(i);         gao[4][a1 + 1].push_back(i);         gao[5][r[i] - l[i] + 3].push_back(i);       }     }     for (int i = 1; i <= n; i++) s1 += a[i];     for (int L = 1; L <= n; L++) {       for (int i = 0, sz = gao[0][L].size(); i < sz; i++) {         pos = gao[0][L][i];         s1 -= a[pos];         s2 += (r[pos] - pos + 1LL) * a[pos];       }       for (int i = 0, sz = gao[1][L].size(); i < sz; i++) {         pos = gao[1][L][i];         s2 += (pos - l[pos] + 1LL) * a[pos];         s1 -= a[pos];       }       for (int i = 0, sz = gao[2][L].size(); i < sz; i++) {         pos = gao[2][L][i];         s2 -= (r[pos] - l[pos] + 2LL) * a[pos];         s1 += a[pos];       }       for (int i = 0, sz = gao[3][L].size(); i < sz; i++) {         pos = gao[3][L][i];         s1 -= a[pos];         s2 += (pos - l[pos] + 1LL) * a[pos];       }       for (int i = 0, sz = gao[4][L].size(); i < sz; i++) {         pos = gao[4][L][i];         s2 += (r[pos] - pos + 1LL) * a[pos];         s1 -= a[pos];       }       for (int i = 0, sz = gao[5][L].size(); i < sz; i++) {         pos = gao[5][L][i];         s2 -= (r[pos] - l[pos] + 2LL) * a[pos];         s1 += a[pos];       }       long long temp = s1 * L + s2;       ans[L] = 1.0 * temp / (n - L + 1);     }     scanf( %d , &m);     while (m--) {       int k;       scanf( %d , &k);       printf( %.10f n , ans[k]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     char arr[105];     scanf( %d%*c , &t);     while (t--) {       gets(arr);       int len = strlen(arr);       char temp[20] = {arr[len - 5], arr[len - 4], arr[len - 3], arr[len - 2],                        arr[len - 1]};       char tem[20] = {arr[0], arr[1], arr[2], arr[3], arr[4]};       if (strcmp(temp,  lala. ) == 0 && strcmp(tem,  miao. ) == 0)         printf( OMG>.< I don t know! n );       else if (strcmp(temp,  lala. ) == 0)         printf( Freda s n );       else if (strcmp(tem,  miao. ) == 0)         printf( Rainbow s n );       else         printf( OMG>.< I don t know! n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, pertama, kedua, sum;   vector<pair<long long, int> > v;   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       pq;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.second == b.second) return a.first < b.first;     return a.second < b.second;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       pq.push(make_pair(a, i));     }     while (!pq.empty()) {       pertama = pq.top().first;       kedua = pq.top().second;       pq.pop();       if (pertama == pq.top().first) {         pq.push(make_pair(2 * pertama, pq.top().second));         pq.pop();       } else {         v.push_back(make_pair(pertama, kedua));       }       if (pq.empty()) v.push_back(make_pair(pertama, kedua));     }     sort(v.begin(), v.end(), cmp);     sum = v.size();     cout << sum << endl;     for (int i = 0; i < sum; i++) {       if (i != 0) cout <<    ;       cout << v[i].first;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prime_pair;   int least[1001];   void sieve(int n) {     vector<int> pr, prime;     for (int i = 2; i <= n; i++) {       if (!least[i]) {         least[i] = i;         pr.push_back(i);       }       for (int j = 0; j < pr.size() && pr[j] <= least[i] && i * pr[j] <= n; j++) {         least[i * pr[j]] = pr[j];       }     }     for (int i = 2; i <= n; i++)       if (least[i] == i) prime.push_back(i);     for (int i = 1; i < prime.size(); i++) {       int temp = prime[i] + prime[i - 1];       prime_pair.push_back(temp);     }   }   bool bi_search(int val) {     int left = 0, right = prime_pair.size() - 1;     while (right >= left) {       int mid = (left + right) / 2;       if (prime_pair[mid] == val) return true;       if (prime_pair[mid] > val)         right = mid - 1;       else         left = mid + 1;     }     return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     sieve(n);     int res = 0;     for (int i = 13; i <= n; i++) {       if (least[i] == i && bi_search(i - 1)) {         res++;       }     }     if (res >= k)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }