#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) x.first(),x.second()
#define MAXN 100005
typedef long long ll;
using namespace std;
ll n,m;
ll niz[MAXN];
ll duz[MAXN];
ll lep[MAXN];
bool ima[MAXN];
ll ciklus[MAXN];
ll obidjen[MAXN];
ll duzc[MAXN],nagc[MAXN];
vector<ll> ciklusi[MAXN];

ll dfs(ll t,ll dub){
    ll res=lep[t];
    if(ciklus[t]){
        ll slavija=(m-dub)/(duzc[ciklus[t]]);
        dub+=slavija*(duzc[ciklus[t]]);
        res+=slavija*(nagc[ciklus[t]]);
    }


    if(dub+duz[t]<=m)res+=dfs(niz[t],dub+duz[t]);
    return res;
}

ll dfsc(ll t,ll bc){
    obidjen[t]=1;
    if(obidjen[niz[t]]==2){
        obidjen[t]=2;
        return 0;
    }
    if(obidjen[niz[t]]==1){
        obidjen[t]=2;
        ciklus[t]=bc;
        ciklusi[bc].pb(t);
        duzc[bc]+=duz[t];
        nagc[bc]+=lep[t];
        return niz[t];
    }

    ll lol=dfsc(niz[t],bc);
    obidjen[t]=2;
    if(lol==0)return 0;
    if(t==lol || obidjen[lol]==1){
        ciklus[t]=bc;
        ciklusi[bc].pb(t);
        duzc[bc]+=duz[t];
        nagc[bc]+=lep[t];
        return lol;
    }else return lol;





}

int main()
{
    scanf("%lld %lld", &n, &m);
    for(ll i=1;i<=n;i++)
        scanf("%lld",lep+i);
    for(ll i=1;i<=n;i++)
        scanf("%lld",niz+i);
    for(ll i=1;i<=n;i++)
        scanf("%lld",duz+i);

    for(ll i=1;i<=n;i++)
        ima[niz[i]]=true;


    ll ucc=1;
    for(ll i=1;i<=n;i++){
        ll haha;
        if(obidjen[i])continue;
        haha=dfsc(i,ucc);
        if(haha)ucc++;
    }


    if(n<=1000){
        ll res=0;
        for(ll i=1;i<=n;i++)res=max(res,dfs(i,0));
        printf("%lld",res);
        return 0;
    }

    return 0;
}