#include <bits/stdc++.h>
#define maxn 100010
#define maxl 22
#define int long long

using namespace std;

int n, t, ans, prv[maxn], vis[maxn], cena[maxn], a[maxn], tmpA;
int spCena[maxn][maxl], spL[maxn][maxl], spV[maxn][maxl];
int cikC[maxn], cikL[maxn], toC[maxn], toL[maxn], cBegin[maxn];
int inCycle[maxn];
vector<int> gray;

int findAll(int x, int len, int& bt, int& dist){
    bt = 0;
    dist = 0;
    int negb = 0;
    for(int i = 0; i < maxl; ++i){
        if(len & (1LL<<i)){
            bt += spL[x][i];
            dist += spCena[x][i];
            x = spV[x][i];
            negb += a[x];
        }
    }
    negb -= a[x];
    bt -= negb;
    return x;
}

void findC(int cur){
    int tB;
    while(true){

        if(vis[cur] == 2)
        {
            return;
        }
        if(vis[cur] == 1){
            int t1 = cur;
            do {
                cikC[cur] += cena[t1];
                t1 = prv[t1];
                cikL[cur] += a[t1];
                inCycle[t1] = 1;
                tB = t1;
            } while(t1 != cur);
            break;
        } else {
            vis[cur] = 1;
            gray.push_back(cur);
            cur = prv[cur];
        }
    }
    int curL = 0, curC = cena[tB];
    toC[tB] = 0;
    toL[tB] = a[tB];
    cBegin[tB] = tB;
    int j = prv[tB];
    while(j != tB){
        toC[j] = cikC[tB] - curC;
        toL[j] = cikL[tB] - curL;
        curL += a[j];
        curC += cena[j];
        j = prv[j];
    }
    j = prv[tB];
    while(j != tB){
        cikC[j] = cikC[tB];
        cikL[j] = cikL[tB];
        cBegin[j] = tB;
        j = prv[j];
    }

}

int manuelni(int x, int t1){
    int res = 0;
    while(t1 >= cena[x]){
        t1 -= cena[x];
        x = prv[x];
        res += a[x];
    }
    return res;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        ans = max(ans, a[i]);
    }
    for(int i = 1; i <= n; ++i){
        cin >> tmpA;
        prv[i] = tmpA;
    }
    for(int i = 1; i <= n; ++i){
        cin >> cena[i];
    }
    for(int i = 1; i <= n; ++i){
        if(vis[i] == 0){
            findC(i);
            while(gray.size() > 0){
                vis[gray.back()] = 2;
                gray.pop_back();
            }
        }
    }
    for(int i = 1; i < n+1; ++i){
        spCena[i][0] = cena[i];
        spL[i][0] = a[i] + a[prv[i]];
        spV[i][0] = prv[i];
    }
    for(int i = 1; i < maxl; ++i){
        for(int x = 1; x <= n; ++x){
            int nxt = spV[x][i-1];
            spV[x][i] = spV[nxt][i-1];
            spL[x][i] = spL[x][i-1] + spL[nxt][i-1] - a[nxt];
            spCena[x][i] = spCena[x][i-1] + spCena[nxt][i-1];
        }
    }
    //cerr << cBegin << ' ';
    for(int i = 1; i <= n; ++i){
        //cerr << i << ' ';
        int l = 1, r = 1e6, tmpAns = 0, enV = -1, cenaAns;
        while(l <= r){
            int mid = (l+r)/2;
            int tmpCena, tmpL;
            int tmpV = findAll(i, mid, tmpL, tmpCena);
            if(tmpCena > t){
                r = mid-1;
            } else {
                tmpAns = tmpL;
                cenaAns = tmpCena;
                enV = tmpV;
                //cerr << tmpAns << ' ' << mid << ' ' << i << '\n';
                l = mid+1;
            }
        }
        if(enV < 0){
            continue;
        }
        //if(tmpAns == 53) cerr << tmpAns << ' ' << toC[enV] << ' ' << cenaAns << ' ' << enV << ' ' << mt <<  '\n';
        if(inCycle[enV]){
            if(t >= cenaAns + toC[enV]){
                tmpAns += toL[enV]-a[enV];
                tmpAns += ((t-cenaAns-toC[enV])/cikC[enV])*cikL[enV];
                tmpAns += manuelni(cBegin[enV], (t-cenaAns-toC[enV])%cikC[enV]);
            } else {
                tmpAns += manuelni(enV, t-cenaAns);
            }
        }
        //cerr << tmpAns << '\n';
        ans = max(ans, tmpAns);
    }
    cout << ans;
    return 0;
}