#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,k;
int h[125252], s[125252], p[125252], l[125252];
int m[125];
int children[125][125];

ll arr[125][125252];
ll beg[125252];

ll tmp[125252];

int di[125252];
ll dv[125252];

void lk(int w, ll *v, ll a, ll n, ll *ret){
  REP(i,w+1)ret[i] = v[i];
  int s = 0, t = 0;
  REP(i,w+1){
    ll v = ret[i] - i*a;
    while(s<t && dv[t-1] <= v)t--;
    di[t] = i;
    dv[t] = v;
    t++;
    ret[i] = dv[s] + i*a;
    if(di[s] == i-n)s++;
  }
}

void dfs(int p, int w, ll *iv){
  // use s[p], max h[p]
  lk(w, iv, s[p], h[p], arr[p]);
  // children
  REP(i,m[p]){
    int c = children[p][i];
    dfs(c, w-l[c], iv);
    iv = arr[c];
    ll adv = (ll)l[c] * s[p];
    lk(w, iv, s[p], h[p]-l[c], tmp);
    REP(i,w+1-l[c])CHMAX(arr[p][i+l[c]], tmp[i]+adv);
  }
}

int main(){
  while(true){
    scanf("%d%d", &n, &k);
    if(n==0 && k==0)break;
    REP(i,n)scanf("%d",h+i);
    REP(i,n)scanf("%d",s+i);
    FOR(i,1,n)scanf("%d",p+i), p[i]--;
    FOR(i,1,n)scanf("%d",l+i);
    REP(i,n)m[i] = 0;
    FOR(i,1,n)children[p[i]][m[p[i]]++] = i;
    REP(i,n)sort(children[i], children[i]+m[i], [&](int a,int b){
      return l[a] < l[b];
    });
    dfs(0, k, beg);
    printf("%lld\n", arr[0][k]);
  }
  return 0;
}


### Prompt

Your task is to create a cpp solution to the following problem:

For Programming Excellence

A countless number of skills are required to be an excellent programmer. Different skills have different importance degrees, and the total programming competence is measured by the sum of products of levels and importance degrees of his/her skills.

In this summer season, you are planning to attend a summer programming school. The school offers courses for many of such skills. Attending a course for a skill, your level of the skill will be improved in proportion to the tuition paid, one level per one yen of tuition, however, each skill has its upper limit of the level and spending more money will never improve the skill level further. Skills are not independent: For taking a course for a skill, except for the most basic course, you have to have at least a certain level of its prerequisite skill.

You want to realize the highest possible programming competence measure within your limited budget for tuition fees.

Input

The input consists of no more than 100 datasets, each in the following format.

> n k
>  h1 ... hn
>  s1 ... sn
>  p2 ... pn
>  l2 ... ln
>

* The first line has two integers, n, the number of different skills between 2 and 100, inclusive, and k, the budget amount available between 1 and 105, inclusive. In what follows, skills are numbered 1 through n.
* The second line has n integers h1...hn, in which hi is the maximum level of the skill i, between 1 and 105, inclusive.
* The third line has n integers s1...sn, in which si is the importance degree of the skill i, between 1 and 109, inclusive.
* The fourth line has n−1 integers p2...pn, in which pi is the prerequisite skill of the skill i, between 1 and i−1, inclusive. The skill 1 has no prerequisites.
* The fifth line has n−1 integers l2...ln, in which li is the least level of prerequisite skill pi required to learn the skill i, between 1 and hpi , inclusive.



The end of the input is indicated by a line containing two zeros.

Output

For each dataset, output a single line containing one integer, which is the highest programming competence measure achievable, that is, the maximum sum of the products of levels and importance degrees of the skills, within the given tuition budget, starting with level zero for all the skills. You do not have to use up all the budget.

Sample Input


3 10
5 4 3
1 2 3
1 2
5 2
5 40
10 10 10 10 8
1 2 3 4 5
1 1 2 3
10 10 10 10
5 10
2 2 2 5 2
2 2 2 5 2
1 1 2 2
2 1 2 1
0 0


Output for the Sample Input


18
108
35






Example

Input

3 10
5 4 3
1 2 3
1 2
5 2
5 40
10 10 10 10 8
1 2 3 4 5
1 1 2 3
10 10 10 10
5 10
2 2 2 5 2
2 2 2 5 2
1 1 2 2
2 1 2 1
0 0


Output

18
108
35

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,k;
int h[125252], s[125252], p[125252], l[125252];
int m[125];
int children[125][125];

ll arr[125][125252];
ll beg[125252];

ll tmp[125252];

int di[125252];
ll dv[125252];

void lk(int w, ll *v, ll a, ll n, ll *ret){
  REP(i,w+1)ret[i] = v[i];
  int s = 0, t = 0;
  REP(i,w+1){
    ll v = ret[i] - i*a;
    while(s<t && dv[t-1] <= v)t--;
    di[t] = i;
    dv[t] = v;
    t++;
    ret[i] = dv[s] + i*a;
    if(di[s] == i-n)s++;
  }
}

void dfs(int p, int w, ll *iv){
  // use s[p], max h[p]
  lk(w, iv, s[p], h[p], arr[p]);
  // children
  REP(i,m[p]){
    int c = children[p][i];
    dfs(c, w-l[c], iv);
    iv = arr[c];
    ll adv = (ll)l[c] * s[p];
    lk(w, iv, s[p], h[p]-l[c], tmp);
    REP(i,w+1-l[c])CHMAX(arr[p][i+l[c]], tmp[i]+adv);
  }
}

int main(){
  while(true){
    scanf("%d%d", &n, &k);
    if(n==0 && k==0)break;
    REP(i,n)scanf("%d",h+i);
    REP(i,n)scanf("%d",s+i);
    FOR(i,1,n)scanf("%d",p+i), p[i]--;
    FOR(i,1,n)scanf("%d",l+i);
    REP(i,n)m[i] = 0;
    FOR(i,1,n)children[p[i]][m[p[i]]++] = i;
    REP(i,n)sort(children[i], children[i]+m[i], [&](int a,int b){
      return l[a] < l[b];
    });
    dfs(0, k, beg);
    printf("%lld\n", arr[0][k]);
  }
  return 0;
}


```