#include <bits/stdc++.h>
using namespace std;

int n,anc[100005];
long long t,rating[200005],in,res;
vector<pair<int,long long>> graph[200005];
bool test_case4=true,visited[200005];
int visited2[200005];
queue<int> snake;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>rating[i];
        rating[i+n]=rating[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>anc[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>in;
        graph[anc[i]].push_back({i,in});
        graph[anc[i]+n].push_back({i+n,in});
    }
    for(int i=1;i<=n;i++)
    {
        if(graph[i].empty() || graph[i].size()!=1)
        {
            test_case4=false;
            break;
        }
    }
    if(test_case4)
    {
        for(int i=1;i<=n;i++)
        {
            if(visited[i])
            {
                continue;
            }
            long long cyc_size=0,cyc_score=0,res1=0,cur_size=0,cur_score=0;
            int cur=i;
            while(!visited[cur])
            {
                visited[cur]=true;
                cyc_size+=graph[cur][0].second;
                cyc_score+=rating[cur];
                cur=graph[cur][0].first;
            }
            while(!snake.empty())
            {
                snake.pop();
            }
            cur=i;
            cur_score=rating[cur];
            snake.push(cur);
            while(visited2[cur]!=3)
            {
                visited2[cur]++;
                while(cur_size>t%cyc_size)
                {
                    cur_size-=graph[snake.front()][0].second;
                    cur_score-=rating[snake.front()];
                    snake.pop();
                }
                res1=max(cur_score,res1);
                cur_score+=rating[graph[cur][0].first];
                cur_size+=graph[cur][0].second;
            }
            res=max(res,res1+t/cyc_size*cyc_score);
        }
        cout<<res;
    }
}