#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#define MAX 100008
typedef long long ll;
using namespace std;
int n,sl[MAX],dist[MAX],dfs_num[MAX],cyc[MAX],un[MAX],br = 0;
ll t,vr[MAX];
vector<pair<ll,ll> > inf;
ll norm_dfs(int u, int vreme)
{
    ll ans = (ll)vr[u];
    vreme -= dist[u];
    if(vreme > 0)
        ans += norm_dfs(sl[u], vreme);
    return ans;
}
int dfs(int u,int vreme)
{
    ll ans = (ll)vr[u];

    if(dfs_num[u] == 1)
    {
        cyc[u] = br;
        int cvor = un[u];
        ll vrednost = vr[u], period = dist[cvor];
        while(cvor != u)
        {
            vrednost += vr[cvor];
            cyc[cvor] = br;
            cvor = un[cvor];
            period += dist[cvor];
        }
        inf.push_back(make_pair(vrednost,vreme));
        br++;
    }
    if(cyc[u] >= 0)
    {
        int num = cyc[u];
        int k = vreme / inf[num].second;
        ans += k * inf[num].first;
        ans += norm_dfs(u,vreme - k * inf[num].second);
        return ans;
    }
    dfs_num[u] = 1;
    vreme -= dist[u];
    if(vreme > 0)
        ans += dfs(sl[u], vreme);
    dfs_num[u] = 2;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> t;
    for(int i = 0; i < n; i++)
        cin >> vr[i];
    for(int i = 0; i < n; i++)
    {
        cin >> sl[i];
        un[sl[i]] = i;
    }
    for(int i = 0; i < n; i++)
        cin >> dist[i];
    for(int i = 0; i < n; i++)
    {
        dfs_num[i] = 0;
        cyc[i] = -1;
    }
    cout << "ovde";
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        cout << "proso";
        ll temp = dfs(i,t);
        for(int i = 0; i < n; i++)
            dfs_num[i] = 0;
        ans = max(ans,temp);
        cout << "proso";
    }
    cout << ans;
    return 0;
}