#include <iostream>

using namespace std;

int *X, *D, *ocena;
int n, t;

int sledeca(int index){

    for (int i = 0; i < n; ++i){
        if (X[i] == index) return i;
    }

    return -1;
}

int sledeca(int index, int x[]){
    for (int i = 0; i < n; ++i){
        if (x[i] == index) return i;
    }

    return -1;
}

long long saberi(int index){
    int duzina = 0;
    int lepota = 0;
    int poslednjaLepota = 0;

    while (duzina < t){
        poslednjaLepota = ocena[index];
        lepota += poslednjaLepota;
        //index = sledeca(index);
        index = X[index];
        if (index == -1) return lepota;
        duzina += D[index];
    }
    if (duzina > t){
        lepota -= poslednjaLepota;
    }
    lepota += ocena[index];
    return lepota;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> t;

    X = new int[n];
    D = new int[n];
    ocena = new int[n];

    int i;
    for (i = 0; i < n; ++i){
        cin >> ocena[i];
    }
    {

        int x[n];
        for (i = 0; i < n; ++i){
            cin >> x[i];
            x[i] -= 1;
        }
        for (i = 0; i < n; ++i){
            X[i] = sledeca(i, x);
        }
        /*for (i = 0; i < n; ++i){
            cout << X[i]  << endl;
        }*/

    }
    for (i = 0; i < n; ++i){
        cin >> D[i];
    }

    long long best = 0;

    for (int i = 0; i < n; ++i){
        best = max(saberi(i), best);
        //cout << i << ": " << saberi(i) << endl;
    }

    cout << best;

    delete X;
    delete D;
    delete ocena;

    return 0;
}