#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
const int NMAX=1e5+7;

int n, a[NMAX], d[NMAX], x[NMAX], out[NMAX];
ll T, res, ans;
vector<pii> g[NMAX];

ll Dfs(int son, ll vreme)
{
    if(vreme<0) return 0;
    if(vreme>=0 && !out[son]) return a[son];
    ll res1=0;
    for(pii i:g[son])
    {
        res1=max(res1,Dfs(i.F, vreme-1LL*i.S)+a[son]);
    }
    return res1;
}

ll dp[2*NMAX], dpa[2*NMAX];

int main()
{
    ios_base::sync_with_stdio(false);
    //cout<<"a";
    cin>>n>>T;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>x[i];
    for(int i=1;i<=n;i++) cin>>d[i];
    for(int i=1;i<=n;i++)
    {
        //cout<<i<<endl;
         g[x[i]].push_back({i, d[i]});
         //cout<<d[i];
         out[x[i]]++;
    }
    //cout<<"a";
    int cikl=1;
    for(int i=1;i<=n;i++) if(out[i]!=1) cikl=0;
    //if(cikl) cout<<"Da";
    if(cikl)
    {
        //cout<<"a";
        int idi=1;
        ll tmp=0;
        ll tmpa=a[idi];
        int svi=0;
        //cout<<g[1][0].F<<"a";
        for(;;)
        {
            //cout<<idi<<" ";
            dp[++svi]=tmp;
            dpa[svi]=tmpa;
            tmp+=1LL*g[idi][0].S;
            tmpa+=1LL*a[g[idi][0].F];
            idi=g[idi][0].F;
            if(idi==1) break;
        }
        //cout<<tmpa<<endl;
        //for(int i=1;i<25;i++) for(int j=1;j<=n;j++) sled[i][j]=sled[i-1][sled[i-1][j]];
        //cout<<dpa[3]<<"A";
        idi=1;
        for(;;)
        {
            dp[++svi]=tmp;
            dpa[svi]=tmpa;
            tmp+=1LL*g[idi][0].S;
            tmpa+=1LL*a[g[idi][0].F];
            idi=g[idi][0].F;
            if(idi==1) break;
        }
        //cout<<dpa[8]<<"A";
        //cout<<tmp<<"A";
        tmpa=0; for(int i=1;i<=n;i++) tmpa+=1LL*a[i];
        tmp/=2;
        //cout<<tmp << " "<<tmpa<<"A";
        ll br=T/tmp;
        ll ost=T%tmp;
        ll svakako=br*tmpa;
        ll jos=0;
        for(int i=1;i<=n;i++)
        {
            int idedo=upper_bound(dp+1,dp+2*n+1, dp[i]+ost)-dp;
            --idedo;
            jos=max(jos, dpa[idedo]-dpa[i-1]);
        }
        cout<<svakako+jos<<endl;
    }
    else
    {
        for(int i=1;i<=n;i++)
    {
        res=Dfs(i,T);
        ans=max(ans, res);
    }
    cout<<ans<<endl;
    }
    return 0;
}
/*
4 1000
100 101 102 103
4 1 2 3
10 7 8 9
*/