malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include<bits/stdc++.h>   using namespace std;       #define ll long long   #define mod 1000000007     #define pb push_back   #define ff first   #define ss second   #define all(a) (a).begin(),(a).end()   #define fr(i,a,b) for(int i=a;i<b;i++)   #define mapit(i,mp) for(auto i = mp.begin(); i!=mp.end(); i++)   #define pii pair<int,int>      int cte[100001] ;   int cto[100001] ;       void solve(){       int n;          cin>>n;          int a[n];          fr(i,0,n){               cin>>a[i];          }              int b[n];              fr(i,0,n){               b[i] = a[i];          }              sort(b,b+n);                  for(int i = 0; i<n; i++){               if(i%2 == 0){                   cte[a[i]]++;               }else{                   cto[a[i]]++;               }          }              bool flag = true;              for(int i = 0; i<n; i++){               if(i%2 == 0){                   if(cte[b[i]] == 0){                       flag = false;                       break;                   }                   cte[b[i]]--;               }else{                   if(cto[b[i]] == 0){                       flag = false;                       break;                   }                   cto[b[i]]--;               }          }              if(flag){               cout<< YES <<  n ;          }else{               cout<< NO <<  n ;          }   }       int main(){       #ifndef ONLINE_JUDGE           freopen( input.txt ,  r , stdin);           freopen( output.txt ,  w , stdout);       #endif           int t = 1;       cin>>t;          while(t--)      {           fr(i,0,100001){               cte[i] = 0;           }               fr(i,0,100001){               cto[i] = 0;           }              solve();      }      return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   vector<int> pos[26];   int xd[26];   int main() {     cin >> s;     n = s.size();     for (int i = 0; i < n; i++) {       pos[s[i] -  a ].push_back(i);       xd[s[i] -  a ]++;     }     double ans = 0;     for (char c =  a ; c <=  z ; c++) {       int best = 0;       for (int shift = 0; shift < n; shift++) {         vector<int> cnt(26, 0);         for (int i : pos[c -  a ]) {           cnt[s[(i + shift) % n] -  a ]++;         }         int nunique = 0;         for (int i = 0; i < 26; i++) {           if (cnt[i] == 1) {             nunique++;           }         }         best = max(best, nunique);       }       ans += 1.0 * best / n;     }     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e+5;   bool vis[maxn];   int main() {     int T, n, m, l;     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     while (cin >> n) {       memset(vis, false, sizeof vis);       int pos = n;       int now = 0;       cout <<  1  ;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         now++;         vis[x] = true;         while (vis[pos]) {           pos--;           now--;         }         cout << now + 1 <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> d[101000];   int k[101000];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &k[i]);       for (int j = 0; j < k[i]; j++) {         int a;         scanf( %d , &a);         d[i].push_back(a);       }       sort(d[i].begin(), d[i].end());     }     int res = 0;     for (int i = 0; i < n; i++) {       int a = (i + n - 1) % n;       int b = (i + 1) % n;       for (int j = 0; j < k[i] - 1; j++) {         vector<int>::iterator ini =             lower_bound(d[a].begin(), d[a].end(), d[i][j]);         vector<int>::iterator fim =             lower_bound(d[a].begin(), d[a].end(), d[i][j + 1]);         int cta = fim - ini;         ini = lower_bound(d[b].begin(), d[b].end(), d[i][j]);         fim = lower_bound(d[b].begin(), d[b].end(), d[i][j + 1]);         if (fim - ini != cta) {           res++;         }       }     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     bool f = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (f) x = -x;   }   template <typename F>   inline void write(F x, char ed =   n ) {     static short st[30];     short tp = 0;     if (x < 0) putchar( - ), x = -x;     do st[++tp] = x % 10, x /= 10;     while (x);     while (tp) putchar( 0  | st[tp--]);     putchar(ed);   }   template <typename T>   inline void Mx(T &x, T y) {     x < y && (x = y);   }   template <typename T>   inline void Mn(T &x, T y) {     x > y && (x = y);   }   const int N = 50005;   int a[N], n;   long long ask(int l, int r) {     cout <<  ?   << l <<     << r << endl;     fflush(stdout);     long long t;     cin >> t;     return t;   }   int main() {     read(n);     long long t1 = ask(1, 2), t2 = ask(1, 3), t3 = ask(2, 3);     a[3] = t2 - t1, a[2] = t3 - a[3], a[1] = t1 - a[2];     for (int i = 4; i <= n; i++) a[i] = ask(i - 1, i) - a[i - 1];     cout <<  !  ;     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using i64 = int64_t;   using i32 = int32_t;   template <class T, class U>   void init_n(vector<T>& v, size_t n, U x) {     v = vector<T>(n, x);   }   template <class T>   void init_n(vector<T>& v, size_t n) {     init_n(v, n, T());   }   template <class T>   void read_n(vector<T>& v, size_t n, size_t o = 0) {     v = vector<T>(n + o);     for (size_t i = o; i < n + o; ++i) cin >> v[i];   }   template <class T>   void read_n(T a[], size_t n, size_t o = 0) {     for (size_t i = o; i < n + o; ++i) cin >> a[i];   }   template <class T>   T gabs(const T& x) {     return max(x, -x);   }   void solve() {     int n;     cin >> n;     vector<int> p(n + 1);     vector<int> q(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> p[i];       q[p[i]] = i;     }     string res(n,  0 );     res[0] =  1 ;     for (int i = 2, l = q[1], r = q[1]; i <= n; ++i) {       l = min(l, q[i]);       r = max(r, q[i]);       if (i == r - l + 1) res[i - 1] =  1 ;     }     cout << res <<   n ;   }   int q;   int main() {     cin >> q;     while (q--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   using P = pair<int, int>;   using vec = vector<int>;   using mat = vector<vector<int>>;   constexpr int MOD = 1000000007;   const int INF = 1 << 30;   bool is_prime(int n) {     if (n <= 1) return false;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   vec get_primes() {     vec p;     for (int i = 2; i <= 1000; i++) {       if (is_prime(i)) p.push_back(i);     }     return p;   }   int main() {     int t;     cin >> t;     for (int _ = 0; _ < (int)(t); _++) {       int n;       cin >> n;       vec a(n);       for (int i = 0; i < (int)(n); i++) cin >> a[i];       auto p = get_primes();       vec c(n, -1);       int now = 1;       for (auto&& pm : p) {         bool f = false;         for (int i = 0; i < (int)(n); i++) {           if (c[i] == -1) {             if (a[i] % pm == 0) c[i] = now, f = true;           }         }         if (f) now++;       }       int mx = -1;       for (int i = 0; i < (int)(n); i++) mx = max(mx, c[i]);       cout << mx <<   n ;       for (int i = 0; i < (int)(n); i++) {         if (i != 0) cout <<    ;         cout << c[i];       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   inline long long rd() {     long long _x = 0;     int _ch = getchar(), _f = 1;     for (; !isdigit(_ch) && (_ch !=  - ) && (_ch != EOF); _ch = getchar())       ;     if (_ch ==  - ) {       _f = 0;       _ch = getchar();     }     for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch -  0 ;     return _f ? _x : -_x;   }   void write(long long _x) {     if (_x >= 10)       write(_x / 10), putchar(_x % 10 +  0 );     else       putchar(_x +  0 );   }   inline void wrt(long long _x, char _p) {     if (_x < 0) putchar( - ), _x = -_x;     write(_x);     if (_p) putchar(_p);   }   int Q = 13;   int n, cnt, to[1005];   std::vector<int> vt[13];   long long r[13];   int main() {     n = rd();     for (int i = 1; i < (1 << Q); i++)       if (__builtin_popcount(i) == 6) {         cnt++;         to[cnt] = i;         for (int j = 0; j < Q; j++)           if (i & (1 << j)) {             vt[j].push_back(cnt);           }         if (cnt == n) break;       }     for (int i = 0; i < 13; i++)       if (vt[i].size()) {         printf( ? %d  , (int)vt[i].size());         for (auto j : vt[i]) {           printf( %d  , j);         }         printf(  n );         fflush(stdout);         r[i] = rd();       }     printf( !  );     for (int i = 1; i <= n; i++) {       long long res = 0;       for (int j = 0; j < Q; j++)         if (!(to[i] & (1 << j))) {           res |= r[j];         }       printf( %lld  , res);     }     printf(  n );     fflush(stdout);   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int arr = 2e5 + 10;   const int ar = 2e3 + 10;   const long double pi = acos(-1);   const long double eps = 1e-10;   const long long md = 1e9 + 7;   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   const int buf_size = 4096;   int buf_pos, buf_len;   unsigned char buf[buf_size];   inline bool is_eof() {     if (buf_pos == buf_len) {       buf_pos = 0;       buf_len = fread(buf, 1, buf_size, stdin);       if (buf_len == 0) {         return 1;       }     }     return 0;   }   inline int get_char() { return is_eof() ? -1 : buf[buf_pos++]; }   inline int read_char() {     int c = get_char();     while (c != -1 && c <= 32) {       c = get_char();     }     return c;   }   inline int read_int() {     int x = 0;     int c = read_char();     int m = 1;     if (c ==  - ) {       m = -1;       c = get_char();     }     while ( 0  <= c && c <=  9 ) {       x = x * 10 + c -  0 ;       c = get_char();     }     return x * m;   }   int my_top[arr];   int s[arr];   int t[arr];   int where_go[arr];   int pred[arr];   vector<int> reb[arr];   int pos[arr];   int last_pos = 0;   int a[arr];   int n, m;   int ans = 0;   void foo(int* a, int n, int d) {     if (d == 1) {       for (int i = 0; i < n; i++) {         a[i]++;         ans += (a[i] == 1);       }     } else {       for (int i = 0; i < n; i++) {         a[i]--;         ans -= (a[i] == 0);       }     }   }   void dooo(int q, int d) {     while (q != -1) {       int top = my_top[q];       foo(a + pos[top], pos[q] - pos[top] + 1, d);       q = pred[top];     }   }   void work(int q) {     if (q > 0) {       if (a[pos[q]] > 0) {         ans--;       }       a[pos[q]] -= md;       dooo(pred[q], 1);     } else {       q = -q;       a[pos[q]] += md;       if (a[pos[q]] > 0) {         ans++;       }       dooo(pred[q], -1);     }   }   void dfs1(int now, int p = -1) {     pred[now] = p;     s[now] = 1;     for (auto wh : reb[now]) {       if (wh != p) {         dfs1(wh, now);         s[now] += s[wh];         if (where_go[now] == 0 || s[where_go[now]] < s[wh]) {           where_go[now] = wh;         }       }     }   }   void dfs2(int now, int p = -1) {     if (!my_top[now]) {       my_top[now] = now;     }     pos[now] = last_pos++;     if (where_go[now]) {       my_top[where_go[now]] = my_top[now];       dfs2(where_go[now], now);     }     for (auto wh : reb[now]) {       if (wh != p && wh != where_go[now]) {         dfs2(wh, now);       }     }   }   int main() {     n = read_int();     m = read_int();     for (int i = 2; i <= n; i++) {       int u;       u = read_int();       reb[u].push_back(i);       reb[i].push_back(u);     }     for (int i = 1; i <= n; i++) {       t[i] = read_int();     }     dfs1(1);     dfs2(1);     for (int i = 1; i <= n; i++) {       a[pos[i]] = -t[i];     }     while (m--) {       int q;       q = read_int();       work(q);       cout << ans <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct ask {     int l, r, where;   } q[210000];   const int mo = 1e9 + 7, N = 1000000;   int A[210000], x[210000], pd[1100000], n, m, B[210000], where[1100000],       ans[210000];   vector<int> p[1100000];   int quick(int k1, int k2) {     int k3 = 1;     while (k2) {       if (k2 & 1) k3 = 1ll * k3 * k1 % mo;       k2 >>= 1;       k1 = 1ll * k1 * k1 % mo;     }     return k3;   }   int compare(ask k1, ask k2) { return k1.r < k2.r; }   void add(int k1, int k2) {     if (k1 == 0) return;     for (; k1 <= n; k1 += k1 & (-k1)) B[k1] = 1ll * B[k1] * k2 % mo;   }   int find(int k1) {     int ans = 1;     for (; k1; k1 -= k1 & (-k1)) ans = 1ll * ans * B[k1] % mo;     return ans;   }   void addin(int k1, int k2) {     int w = 1ll * (k1 - 1) * quick(k1, mo - 2) % mo;     add(where[k1], quick(w, mo - 2));     add(k2, w);     where[k1] = k2;   }   void insert(int k1) {     int w = x[k1];     for (int i = 0; i < p[w].size(); i++) {       int k2 = p[w][i];       addin(k2, k1);     }   }   int getans(int L, int R) {     return 1ll * A[R] * quick(A[L - 1], mo - 2) % mo * find(R) % mo *            quick(find(L - 1), mo - 2) % mo;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     scanf( %d , &m);     ;     A[0] = 1;     for (int i = 1; i <= n; i++) A[i] = 1ll * A[i - 1] * x[i] % mo;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].where = i;     }     sort(q + 1, q + m + 1, compare);     for (int i = 1; i <= n; i++) B[i] = 1;     for (int i = 2; i <= N; i++)       if (pd[i] == 0)         for (int j = i; j <= N; j += i) {           pd[j] = 1;           p[j].push_back(i);         }     int now = 1;     for (int i = 1; i <= n; i++) {       insert(i);       while (now <= m && q[now].r == i)         ans[q[now].where] = getans(q[now].l, q[now].r), now++;     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using LD = long double;   const int MX = 1 << 18 | 3;   int N, a[MX], Q;   LL sum;   int main() {     ios::sync_with_stdio(0);     cout << fixed << setprecision(10);     cin >> N >> Q;     for (int i = 0; i < (1 << N); i++) cin >> a[i], sum += a[i];     cout << (LD)sum / (1 << N) <<   n ;     while (Q--) {       int u, x;       cin >> u >> x;       sum = sum - a[u] + x;       a[u] = x;       cout << (LD)sum / (1 << N) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   template <class T>   bool read(T &x) {     char *s;     s = (char *)malloc(10);     if (sizeof(x) == 1)       strcpy(s + 1,   %c );     else if (sizeof(x) == 4)       strcpy(s + 1,  %d );     else if (sizeof(x) == 8)       strcpy(s + 1,  %lld );     int k = scanf(s + 1, &x);     free(s);     return k != -1;   }   using namespace std;   char s[2000000];   int sz1, sz2, len, pos[2000000], neg[2000000];   int main() {     scanf( %s , s + 1);     len = strlen(s + 1);     s[0] =  0 ;     for (int i = len; i >= 0; i--) {       if (s[i] ==  0 ) continue;       if (s[i] ==  2 ) {         s[i - 1]++;         continue;       }       if (s[i] ==  1  and i > 0 and s[i - 1] ==  1 ) {         neg[++sz2] = len - i;         s[i - 1]++;         continue;       }       pos[++sz1] = len - i;     }     cout << sz1 + sz2 << endl;     for (int i = 1; i <= sz1; i++) printf( +2^%d n , pos[i]);     for (int i = 1; i <= sz2; i++) printf( -2^%d n , neg[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long quickMod(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       b >>= 1;       a = a * a % c;     }     return ans;   }   long long Euler(long long x) {     long long res = x;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         res = res - res / i;         while (x % i == 0) x /= i;       }     }     if (x > 1) res = res - res / x;     return res;   }   int main() {     long long c, tmp, ans, phi, result;     char b[1000005], n[1000005];     scanf( %s%s%lld , b, n, &c);     phi = Euler(c);     tmp = 0;     for (long long i = 0; b[i]; i++) tmp = (tmp * 10 + b[i] -  0 ) % c;     ans = 0;     bool flag = false;     for (long long i = 0; n[i]; i++) {       ans = ans * 10 + n[i] -  0 ;       if (ans > phi) {         flag = true;         ans %= phi;       }     }     if (flag) ans += phi;     ans--;     if (tmp == 0) tmp = c;     result = (((tmp + c - 1) % c) * quickMod(tmp, ans, c)) % c;     printf( %lld n , result ? result : c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;       b /= 2;       a = ((a % m) * (a % m)) % m;     }     return ans % m;   }   long long a[10];   long long fac[202];   void factorial() {     fac[0] = 1;     for (int i = 1; i < 200; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= (long long)(1000 * 1000 * 1000 + 7);     }   }   long long c(long long n, long long k) {     long long nemo = fac[n];     long long deno = fac[k] * fac[n - k];     deno %= (long long)(1000 * 1000 * 1000 + 7);     long long invdeno = pow(deno, (long long)(1000 * 1000 * 1000 + 7) - 2,                             (long long)(1000 * 1000 * 1000 + 7));     long long pro = nemo * invdeno;     pro %= (long long)(1000 * 1000 * 1000 + 7);     return pro;   }   long long dp[105][10];   long long solve(int len, int curnum) {     if (len < 0) return 0;     if (curnum == 9) {       return len >= a[9];     }     long long ans = 0;     if (dp[len][curnum] != -1) return dp[len][curnum];     if (curnum == 0) {       for (int i = a[curnum]; i < len; i++) {         ans += solve(len - i, curnum + 1) * c(len - 1, i);         ans %= (long long)(1000 * 1000 * 1000 + 7);       }     } else {       for (int i = a[curnum]; i <= len; i++) {         ans += solve(len - i, curnum + 1) * c(len, i);         ans %= (long long)(1000 * 1000 * 1000 + 7);       }     }     return dp[len][curnum] = (ans % (long long)(1000 * 1000 * 1000 + 7));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     factorial();     for (int i = 0; i < 10; i++) cin >> a[i];     long long ans = 0;     for (int i = 0; i <= n; i++) {       if (i >= a[9])         dp[i][9] = 1;       else         dp[i][9] = 0;     }     for (int k = 0; k <= n; k++) {       for (int j = 8; j >= 0; j--) {         if (j != 0) {           for (int l = a[j]; l <= k; l++) {             dp[k][j] += dp[k - l][j + 1] * c(k, l);             dp[k][j] %= (long long)(1000 * 1000 * 1000 + 7);           }         } else {           for (int l = a[j]; l <= k; l++) {             dp[k][j] += dp[k - l][j + 1] * c(k - 1, l);             dp[k][j] %= (long long)(1000 * 1000 * 1000 + 7);           }         }       }     }     for (int i = 1; i <= n; i++) {       ans += dp[i][0];       ans %= (long long)(1000 * 1000 * 1000 + 7);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   const int inf = 0x7FFFFFFF;   template <class T>   void show(T a, int n) {     for (int i = 0; i < n; ++i) cout << a[i] <<    ;     cout << endl;   }   template <class T>   void show(T a, int r, int l) {     for (int i = 0; i < r; ++i) show(a[i], l);     cout << endl;   }   int k[7];   int main() {     int i, j, ans;     int a, b, c, x, y, z;     cin >> a >> b >> c >> x >> y >> z;     for (i = 0; i < 6; i++) cin >> k[i];     ans = 0;     if (a > x) {       ans += k[5];     } else if (a < 0)       ans += k[4];     if (b > y)       ans += k[1];     else if (b < 0)       ans += k[0];     if (c > z)       ans += k[3];     else if (c < 0)       ans += k[2];     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       long long p, f, s, w, cntS, cntW;       cin >> p >> f >> cntS >> cntW >> s >> w;       if (s > w) {         swap(cntS, cntW);         swap(s, w);       }       long long ans = 0;       for (long long i = 0; i <= cntS; i++) {         if (i * s > p) break;         long long sf = i;         long long ss = min(f / s, cntS - i);         long long leftf = p - sf * s;         long long lefts = f - ss * s;         long long wf = min(cntW, leftf / w);         long long ws = min(cntW - wf, lefts / w);         ans = max(ans, ss + sf + wf + ws);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 9;   const int MOD = 1e9 + 7;   const int MAXN = 300005;   long long N, k, m;   long long cook[MAXN], t[MAXN], l[MAXN];   vector<int> ch[MAXN];   int good, bad;   template <class T, class Operation = plus<T>>   struct SegmentTree {     int n;     vector<T> st;     Operation op;     const T identity;     T query(int L, int R) {       T resl = identity, resr = identity;       for (L += n, R += n; L < R; L >>= 1, R >>= 1) {         if (L & 1) resl = op(resl, st[L++]);         if (R & 1) resr = op(st[--R], resr);       }       return op(resl, resr);     }     void update(int p, T val) {       for (st[p += n] = val; p > 1; p >>= 1) st[p >> 1] = op(st[p], st[p ^ 1]);     }     SegmentTree(const vector<T> &A, const T &identity = 0,                 const Operation &op = Operation())         : n((int)A.size()), st(n << 1), op(op), identity(identity) {       copy(A.begin(), A.end(), st.begin() + n);       for (int i = n - 1; i > 0; --i)         st[i] = this->op(st[i << 1], st[i << 1 | 1]);     }   };   struct Op {     pair<long long, long long> operator()(const pair<long long, long long> &a,                                           const pair<long long, long long> &b) {       return pair<long long, long long>(a.first + b.first, a.second + b.second);     }   };   SegmentTree<pair<long long, long long>, Op> st(       vector<pair<long long, long long>>(1000006),       pair<long long, long long>(0, 0));   long long calc(int u) {     pair<long long, long long> val = st.query(t[u], t[u] + 1);     st.update(t[u],               st.op(val, pair<long long, long long>(cook[u], cook[u] * t[u])));     long long maxi1 = 0, maxi2 = 0;     for (int i = 0; i < (int)ch[u].size(); i++) {       if (k - l[ch[u][i]] >= 0) {         k -= l[ch[u][i]];         long long chdp = calc(ch[u][i]);         if (chdp > maxi1) {           maxi2 = maxi1;           maxi1 = chdp;         } else if (chdp > maxi2) {           maxi2 = chdp;         }         k += l[ch[u][i]];       }     }     int lo = 0, hi = min(k + 2, (long long)1000004);     while (lo + 1 < hi) {       int med = lo + (hi - lo) / 2;       pair<long long, long long> sum = st.query(0, med);       if (sum.second > k) {         hi = med;       } else {         lo = med;       }     }     pair<long long, long long> sum = st.query(0, lo);     long long f = sum.first;     if (lo > 0) f += min((k - sum.second) / lo, st.st[st.n + lo].first);     st.update(t[u], val);     if (u == 0) {       return max(f, maxi1);     } else {       return max(f, maxi2);     }   }   int main() {     cin >> N >> k;     for (int i = 0; i < N; i++) {       cin >> cook[i];     }     for (int i = 0; i < N; i++) {       cin >> t[i];     }     for (int i = 1; i < N; i++) {       cin >> m >> l[i];       l[i] *= 2;       ch[m - 1].push_back(i);     }     cout << calc(0) << endl;   }