criyle/codenet-compile-errors huggingface dataset:
Language: C++

<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e5;
const int size=1e5;
const long inf=1e18;
int main(){
	int N,K; cin>>N>>K;
	int P[N]; long C[N];
	rep(i,0,N){ cin>>P[i]; P[i]--; }
	rep(i,0,N) cin>>C[i];
	long ans = -inf;
	rep(i,0,N){
		long score[N+1] = {};
		int t = i; int p; bool flag = true;
		rep(j,0,min(N, K)){
			t = P[t];
			score[j+1] = score[j] + C[t];
			if(flag && t == i){ p = j + 1; flag = false; }
		}
		long res0 = -inf, res1 = -inf;
        if(K % p == 0) rep(k,1,N+1) res0 = max(res0, score[k]);
		else rep(k,1,K % p + 1) res0 = max(res0, score[k]);
        rep(k,1,min(N, K)+1) res1 = max(res1, score[k]);
		if(K > N && score[p] > 0) ans = max(ans, res0 + (K-1) / p * score[p]);
		else ans = max(ans, res1);
	}cout<<ans<<endl;
}

Compiler output:
a.cc:1:1: error: expected unqualified-id before '<' token
    1 | <bits/stdc++.h>
      | ^
a.cc: In function 'int main()':
a.cc:11:18: error: 'cin' was not declared in this scope
   11 |         int N,K; cin>>N>>K;
      |                  ^~~
a.cc:19:25: error: 'min' was not declared in this scope; did you mean 'main'?
   19 |                 rep(j,0,min(N, K)){
      |                         ^~~
a.cc:3:34: note: in definition of macro 'rep'
    3 | #define rep(i,x,y) for(int i=x;i<y;i++)
      |                                  ^
a.cc:25:44: error: 'max' was not declared in this scope
   25 |         if(K % p == 0) rep(k,1,N+1) res0 = max(res0, score[k]);
      |                                            ^~~
a.cc:26:48: error: 'max' was not declared in this scope
   26 |                 else rep(k,1,K % p + 1) res0 = max(res0, score[k]);
      |                                                ^~~
a.cc:27:17: error: 'min' was not declared in this scope; did you mean 'main'?
   27 |         rep(k,1,min(N, K)+1) res1 = max(res1, score[k]);
      |                 ^~~
a.cc:3:34: note: in definition of macro 'rep'
    3 | #define rep(i,x,y) for(int i=x;i<y;i++)
      |                                  ^
a.cc:27:37: error: 'max' was not declared in this scope
   27 |         rep(k,1,min(N, K)+1) res1 = max(res1, score[k]);
      |                                     ^~~
a.cc:28:49: error: 'max' was not declared in this scope
   28 |                 if(K > N && score[p] > 0) ans = max(ans, res0 + (K-1) / p * score[p]);
      |                                                 ^~~
a.cc:29:28: error: 'max' was not declared in this scope
   29 |                 else ans = max(ans, res1);
      |                            ^~~
a.cc:30:10: error: 'cout' was not declared in this scope
   30 |         }cout<<ans<<endl;
      |          ^~~~
a.cc:30:21: error: 'endl' was not declared in this scope
   30 |         }cout<<ans<<endl;
      |                     ^~~~
Language: C++

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

vector<int>pes,color,ces,sz;
vector<ll>points;

void dfs(int u, int z){
	color[u]=z;
	points[color[u]]+=ces[u];
	sz[color[u]]++;

	int v = pes[u];
	if(color[v]==-1)dfs(v,z);
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;ll k;
	cin>>n>>k;
	pes=ces=sz=vector<int>(n+1);
	color.resize(n+1,-1);
	points.resize(n+1);

	
	for(int i=1;i<=n;i++){
		cin>>pes[i];
	}
	for(int i=1;i<=n;i++){
		cin>>ces[i];
	}
	int z = 0;
	for(int i=1;i<=n;i++){
		if(color[i]==-1){
			dfs(i,++z);
		}
	}
	vector<ll>mx(n+1);
	ll ans=-5e18;
	for(int i =1;i<=n;i++){
		
		ll cnt = k/sz[color[i]];
		if(points[color[i]]<0)cnt=0;
		int len = k-sz[color[i]]*cnt;
		len=min(sz[color[i]],len);
	
		int u = i;
		ll tmp=0;
		ll mxval=0;
		if(cnt<0){
			u=pes[u];
			tmp=ces[u];
			mxval=tmp;
		}
		ll tmp=ces[u];
		ll mxval=tmp;
		for(int l=1;l<len;l++){
			u=pes[u];
			tmp+=ces[u];
			mxval=max(mxval,tmp);
		}

		mx[i]=mxval;
		
		ans=max(mx[i]+points[color[i]]*cnt,ans);
	}
	cout<<ans;
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:20: error: redeclaration of 'll tmp'
   57 |                 ll tmp=ces[u];
      |                    ^~~
a.cc:50:20: note: 'll tmp' previously declared here
   50 |                 ll tmp=0;
      |                    ^~~
a.cc:58:20: error: redeclaration of 'll mxval'
   58 |                 ll mxval=tmp;
      |                    ^~~~~
a.cc:51:20: note: 'll mxval' previously declared here
   51 |                 ll mxval=0;
      |                    ^~~~~
Language: C++

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

#define INF 2000000000

long long int dp[5050][5050],dp_max[5050][5050];
int dp_size[5050];
int p[5050];
long long int c[5050];


int main(){

    int N,K;

    cin >> N >> K;

    for(int i = 1;i <= N;i++){
        cin >> p[i];
    }
    for(int i = 1;i <= N;i++){
        cin >> c[i];
    }

    for(int i = 0;i <= N;i++){
        for(int j = 0;j <= N;j++){
            dp_max[i][j] = -10000000000000000;
        }
    }

    for(int i = 1;i <= N;i++){

        int now = i;
        int count = 1;
        while(true){
            dp[i][count] = dp[i][count-1] + c[p[now]];
            dp_max[i][count] = max(dp_max[i][count-1],dp[i][count]);
            now = p[now];
            if(now == i){
                dp_size[i] = count;
                break;
            }
            count++;
        }

    }
    long long int ans = -10000000000000000;
    for(int i = 1;i <= N;i++){
        if(K <= dp_size[i]){
            ans = max(ans,dp_max[i][K]);
        }else{
            if(dp[i][dp_size[i]] < 0){
                ans = max(ans,dp_max[i][dp_size[i]]);
            }else{
                long long int tmp_ans;
                if(K % dp_size[i] == 0){
                    tmp_ans = dp[i][dp_size[i]] * (K / dp_size[i]);
                    tmp_ans = max(tmp_ans,dp_max[i][dp_size[i]]);
                    tmp_ans = max(tmp_ans,dp[i][dp_size[i]] * (K / dp_size[i] - 1) + dp_max[i][dp_size[i]]);
                    
                }else{
                    tmp_ans = dp[i][dp_size[i]] * (K / dp_size[i]) + dp_max[i][K % dp_size[i]];
                    tmp_ans = max(tmp_ans,dp_max[i][dp_size[i]]);
                    tmp_ans = max(tmp_ans,dp[i][dp_size[i]] * (K / dp_size[i]-1) + dp_max[i][dp_size[i]];);
                    
                }
                ans = max(ans,tmp_ans);
            }
        }
    }

    cout << ans << endl;

/*
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= dp_size[i];j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }

    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= dp_size[i];j++){
            cout << dp_max[i][j] << " ";
        }
        cout << endl;
    }

*/
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:105: error: expected ')' before ';' token
   64 |                     tmp_ans = max(tmp_ans,dp[i][dp_size[i]] * (K / dp_size[i]-1) + dp_max[i][dp_size[i]];);
      |                                  ~                                                                      ^
      |                                                                                                         )
a.cc:64:106: error: expected primary-expression before ')' token
   64 |                     tmp_ans = max(tmp_ans,dp[i][dp_size[i]] * (K / dp_size[i]-1) + dp_max[i][dp_size[i]];);
      |                                                                                                          ^
Language: C++

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n + 1);
    vector<int> c(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    for (int i = 1; i <= n; i++)
        cin >> c[i];

    ll ans = -0x3f3f3f3f3f3f3f3f;
    for (int i = 1; i <= n; i++)
    {
        vector<bool> visited(n + 1, 0);
        int num = 0;
        int next = p[i];
        vector<ll> tmax(n + 1, -0x3f3f3f3f3f3f3f3f);
        ll score = 0;
        while (!visited[next])
        {
            score += c[p[next]];
            visited[next] = 1;
            next = p[next];
            num++;
            tmax[num] = max(tmax[num - 1], score);
        }
        if (score < 0)
            score = tmax[min(k, num)];
        else
        {
            if (num >= k)
                score = tmax[k];
            else
                score = max ((k / num) * score + max(0ll, tmax[k % num]),(k / num -1) * score + max(0ll, tmax[num]);
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:116: error: expected ')' before ';' token
   39 |                 score = max ((k / num) * score + max(0ll, tmax[k % num]),(k / num -1) * score + max(0ll, tmax[num]);
      |                             ~                                                                                      ^
      |                                                                                                                    )
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll f(vll v, vll c, ll k) {
  ll n = v.size();
  rep(i,n) v.push_back(v[i]);
  ll ret1 = -1100000000000000000LL;
  rep(i,n) {
    ll tmp = 0LL;
    rep(j,min(n,k)) {
      tmp += c[v[i+j]];
      ret1 = max(ret1,tmp);
    }
  }
  ll sum = 0LL;
  rep(i,n) sum += c[v[i]];
  if(sum<0 || k<=n) return ret1;
  ll m = k/n;
  k %= n;
  ll m = 0;
  ll ret2 = -1100000000000000000LL;
  rep(i,n) {
    ll tmp = 0LL;
    rep(j,k) {
      tmp += c[v[i+j]];
      ret2 = max(ret2,tmp);
    }
  }
  ret2 += sum*m;
  return max(ret1,ret2);
}

int main() {
  ll n, k;
  cin >> n >> k;
  vll p(n), c(n);
  rep(i,n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i,n) cin >> c[i];
  vector<bool> check(n,false);
  vector<vll> v;
  rep(i,n) {
    if(check[i]) continue;
    check[i] = true;
    ll key = i;
    vll tmp;
    tmp.push_back(key);
    ll a = key;
    while(true) {
      a = p[a];
      if(a==key) break;
      tmp.push_back(a);
      check[a] = true;
    }
    v.push_back(tmp);
  }
  ll ans = -1100000000000000000LL;
  rep(i,v.size()) {
    ll tmp = f(v[i],c,k);
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'll f(vll, vll, ll)':
a.cc:28:6: error: redeclaration of 'll m'
   28 |   ll m = 0;
      |      ^
a.cc:26:6: note: 'll m' previously declared here
   26 |   ll m = k/n;
      |      ^
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    
    int n,k;
    cin >> n >> k;
    std::vector<int> p,c;

    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    
    std::vector<int> v[5000];
    int index = 0;
    int cnt = 0;
    
    int next = 1;
    
    //v[index].push_back(1);
    //next = p[next-1];
    
    bool check[n+1];
    int mx[n+1];
    int loop[n+1];
    for(int i=0; i<=n; i++){
        check[i] = false;
        mx[i] = -1000000001;
        loop[i] = 0;
    }
    
    std::multimap<int, long long int> mmp;
    for(int i=1; i<=n; i++){
        next = i;
        if(check[i] == true){
            cout << i << " skip" << endl;
            continue;
        }
        
    while(1){
        cout << next << endl;
        if(std::find(v[index].begin(), v[index].end(), next) != v[index].end()){
            mmp.emplace(mx[index], index);
            index++;
            cnt++;
            
            cout << "--- " << mx[index] << endl;
            break;
        }
        check[next] = true;
        v[index].push_back(next);
        
        if(mx[index] == -1000000001) mx[index] = c[next-1];
        else{
          int tmpmx = mx[index];
          tmpmx += c[next-1];
          cout << tmpmx << ", " << c[next-1] << endl;
          if(mx[index] < tmpmx) mx[index] = tmpmx;
        }

        loop[index]++;
        next = p[next-1];
    }
    
    }
    
    
    int mxnum = 0;
    std::multimap<int, long long int>::iterator itr = mmp.end();

    for(int i=0; i<mmp.size(); i++){
        if(loop[mmp[i]] <= k){
            cout << mx[mmp[i]] << endl;
        }   
        itr++;
    }
 
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:89:20: error: no match for 'operator[]' (operand types are 'std::multimap<int, long long int>' and 'int')
   89 |         if(loop[mmp[i]] <= k){
      |                    ^
a.cc:90:27: error: no match for 'operator[]' (operand types are 'std::multimap<int, long long int>' and 'int')
   90 |             cout << mx[mmp[i]] << endl;
      |                           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){int n;long k;long long t=0;cin>>n>>k;
    vector<int>p(n);for(int i=0;i<n;i++)cin>>p.at(i);
           vector<long>c(n);for(int i=0;i<n;i++)cin>>c.at(i);
  for(int i=0;i<n;i++){long long w=0,x=0;long l=0;int q=i;
    while(l<=k&&(q!=i||l==0)){l++;q=p.at(q)-1;x+=c.at(q);if(w<x||l=1)w=x;}
     if(l<=k&&x>0) {x=(k/l)*x;l=k%l;while(l>0){l--;q=p.at(q)-1;x+=c.at(q);if(w<x)w=x;}}
if(w<x)w=x;if(t<w)t=w;}cout<<t<<endl;}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:64: error: lvalue required as left operand of assignment
    7 |     while(l<=k&&(q!=i||l==0)){l++;q=p.at(q)-1;x+=c.at(q);if(w<x||l=1)w=x;}
      |                                                             ~~~^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll f(vll v, vll c, ll k) {
  ll n = v.size();
  rep(i,n) v.push_back(v[i]);
  ll ret1 = -1100000000000000000LL;
  ll ret3 = -1100000000000000000LL;
  rep(i,n) {
    ll tmp = 0LL;
    ll tmp2 = 0LL;
    rep(j,min(n,k)) {
      tmp += c[v[i+j]];
      ret1 = max(ret1,tmp);
    }
    if(k<n) {
      rep(j,k) {
        tmp2 += c[v[i+j]];
        ret3 = max(ret3,tmp2);
      }
    }
  }
  ll sum = 0LL;
  rep(i,n) sum += c[v[i]];
  if(sum<0 || k<=n) return ret1;
  ll m = k/n;
  ll ret2 = ret3 + sum*m;
  return max(ret1,ret2);
}


Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int N = 5005;
typedef long long ll;
ll p[N],c[N];
void solve(){
ll n,x,mx=INT_MIN; cin>>n>>x;
for(int i=1;i<=n;i++) cin>>p[i];
for(int j=1;j<=n;j++) cin>>c[j];
for(int i=1;i<=n;i++){
        ll curr=i,turns=0,ans=0;
        vector<ll> res;
        while(true){
                curr=p[curr];
                ans+=c[curr];
                res.push_back(ans);
                turns++;
                if(curr==i||turns==x) break;
        }
        if(turns==x) { mx=max(*max_element(res.begin(),res.end()),mx); }
        else {
                //cout<<turns<<" "<<x%turns-1<<" "<<endl;
                if(res[res.size()-1]<0){ mx=max(*max_element(res.begin(),res.end()),mx); }
                else{ mx=max(mx,max((x/turns-1)*(res[res.size()-1])+*max_element(res.begin(),res.end()),((x/turns)*res[res.size()-1])+*max_element(res.begin(),res.begin()+(x%turns?(x%turns)-1:0))));}
        }
}
cout<<mx<<endl;
}
int main(){
solve();
}
~


Compiler output:
a.cc:32:2: error: expected class-name at end of input
   32 | ~
      |  ^
Language: C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int main()
{
    ll n,k;
    scanf("%lli %lli",&n,&k);
    ll p[n],c[n];
    fr(i,1,n+1){
       scanf("%lli",&p[i]); 
    }
    fr(i,1,n+1){
       scanf("%lli",&c[i]); 
    }
    ll ans=0;
    ll check=1;
    fr(i,1,n+1){
        if(c[i]>=0){
            check = 0;
        }
    }
    if 
    if (check == 0){
    fr(i,1,n+1){
        ll now = i;
        ll count = 0;
        fr(j,1,k+1){
            now = p[now];
            count += c[now];
            if (ans < count) {
            ans = count;
            }
        }
    }
    } 
    if (check == 1)
    {
        ans =c[1];
        fr(i,1,n+1) {
            if(c[i]>ans) {
                ans = c[i];
            }
        }
    }
    
    printf("%lli",ans);
    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:25:5: error: expected '(' before 'if'
   25 |     if (check == 0){
      |     ^~
      |     (
Language: C++

#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
#define mod 1000000007
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main() {
int n,k;
cin>>n>>k;
vector<int>p(n);
vector<int>c(n);
loop(i,0,n){
cin>>p[i];
}
loop(i,0,n){
cin>>c[i];
}
ll ans=-10000000000;
vector<vector<int>>dp(k+1,vector<int>(n+1,0));
for(int i=1;i<k+1;i++){
    for(int j=1;j<n+1;j++){
        dp[i][j]=dp[i-1][p[j-1]]+c[j-1];
        ans=max(ans,dp[i][j]);
    }
}

cout<<ans;
        return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:16: error: no matching function for call to 'max(ll&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   37 |         ans=max(ans,dp[i][j]);
      |             ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:37:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   37 |         ans=max(ans,dp[i][j]);
      |             ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:12:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:37:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |         ans=max(ans,dp[i][j]);
      |             ~~~^~~~~~~~~~~~~~
Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
int main(){
	int n,k;
	long long p[5000];
	long long c[5000];
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	long long s=0;
	for(int i=0;i<n;i++){
		cin>>c[i];
		s+=c[i];
	}
	vector<int> a;
	int now=0;
	for(int i=0;i<n;i++){
		a.push_back(c[now]);
		now=p[now];
	}
	long long ans=0;
	if(s>0){
		ans+=k/n*s;
		k%=n;
	}
	for(int i=1;i<n;j++){
		c[i]+=c[i-1];
	}
	long long ma=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(j-i<=k){
				if(c[j]-c[i]>0){
					ma=max(ma,c[j]-c[i]);
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(n-(j-i)<=k){
				if(s-(c[j]-c[i])>0){
					ma=max(ma,s-(c[j]-c[i]));
				}
			}
		}
	}
	cout<<ans+ma<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:25: error: 'j' was not declared in this scope
   41 |         for(int i=1;i<n;j++){
      |                         ^
Language: C++

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

int main() {
  long long N,K;
  cin >> N >> K;
  vector<int> C(N);
  vector<int> P(N);
  for (long long i = 0; i < N; i++)
    cin >> C.at(i);
  for (long long j = 0; j < N; j++)
    cin >> P.at(j);
  vector<pair<long long,long long>> V(N);
  
  for (long long k = 0; k < N; k++) {
    long long score = 0;
    long long place = k;
    long long loops = 0;
    
    place = C.at(k) - 1;
    score += P.at(C.at(k) - 1);
    loops++;
    
    while (place != k) {
      place = C.at(place) - 1;
      score += P.at(place);
      loops++;
    }
    
    V.at(k).first = loops;
    V.at(k).second = score;
  }
  
  long long max = -1000000000000000000000; 
  for (long long l = 0; l < N; l++) {
    long long maxl = -1000000000000000000000;
    long long score2 = 0; 
    score2 += (K/V.at(l).first)*V.at(l).second;
    if (K/V.at(l).first != 0 && max < score2)
     //maxl = score2;
    
    long long score3 = 0;
    long long amari = K%V.at(l).first;
    if (K%V.at(l).first == 0)
      amari = V.at(l).first;
    long long place2 = l;
    while(amari > 0) {
      place2 = C.at(place2) - 1;
      score3 += P.at(place2);
      if (maxl < score2 + score3)
        maxl = score2 + score3;
      if (maxl < score3)
        maxl = score3;
      amari--;
    }
    if (max < maxl)
      max = maxl;
  }
  cout << max << endl;  
}


Compiler output:
a.cc:34:20: warning: integer constant is too large for its type
   34 |   long long max = -1000000000000000000000;
      |                    ^~~~~~~~~~~~~~~~~~~~~~
a.cc:36:23: warning: integer constant is too large for its type
   36 |     long long maxl = -1000000000000000000000;
      |                       ^~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:49:7: error: 'score3' was not declared in this scope; did you mean 'score2'?
   49 |       score3 += P.at(place2);
      |       ^~~~~~
      |       score2
Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 62;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,k;
    cin >> n >> k;
    ll p[n],c[n];
    for (ll i=0;i<n;i++)cin >> p[i];
    for (ll i=0;i<n;i++){
        cin >> c[i];
    }
    ll point[n]; 
    ll v[n];
    fill(v,v+n,-INF);
    ll lc[n];
    for (ll i=0;i<n;i++){
        ll q=p[i]-1,f=1,d=c[i];
        while (q!=i){
            d+=c[q];
            q=p[q]-1;
            f++;
        }
        point[i]=d;
        lc[i]=f;
    }
    ll kc[n];
    fill(kc,kc+n,k);
    for (ll i=0;i<n;i++){
        ll z=(k%lc[i]);
        if (k%lc[i]==0){
            z=lc[i];
            kc[i]-=lc[i];
        }
        ll d=0,q=p[i]-1,f=1;
        while (f<=z){
            d+=c[q];
            q=p[q]-1;
            v[i]=max(v[i],d);
            f++;
        }
    }
    ll ans[n];
    fill(ans,ans+n,-INF);
    for (ll i=0;i<n;i++){
        ans[i]=v[i];
        if (point[i]>0){
          	if (v[i]<0 and kc[i]/lc[i]ans[i]=0;
            ans[i]=ans[i]+(point[i]*(kc[i]/lc[i]));
        }
    }
    sort(ans,ans+n);
    cout << ans[n-1] << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:71:43: error: expected ';' before 'ans'
   71 |                 if (v[i]<0 and kc[i]/lc[i]ans[i]=0;
      |                                           ^~~
      |                                           ;
a.cc:72:51: error: expected ')' before ';' token
   72 |             ans[i]=ans[i]+(point[i]*(kc[i]/lc[i]));
      |                                                   ^
      |                                                   )
a.cc:71:20: note: to match this '('
   71 |                 if (v[i]<0 and kc[i]/lc[i]ans[i]=0;
      |                    ^
Language: C++

nclude <bits/stdc++.h>
#define int long long
using namespace std;
 
int n,tim,ans=-1e18-7;
int p[500005],a[500005],v[500005],visited[500005];
 
signed main()
{
	cin>>n>>tim;
	for (int i=1;i<=n;i++)  cin>>p[i];
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)  visited[j]=-1;
		
		int jj=i,pos=0,sumv=0;
		while (1)
		{
			jj=p[jj];
			if (visited[jj]!=-1)  break;
			visited[jj]=pos;
			v[++pos]=a[jj];
		}
		for (int j=1;j<=pos;j++)
		{
			sumv+=v[j];
			if (j<=tim)  ans=max(ans,sumv);
		}
		if (sumv<=0||tim<=pos)
		{
			sumv=0;
			for (int j=1;j<=min(pos,tim);j++)
			{
				sumv+=v[j];
				ans=max(ans,sumv);
			}
		}
		else
		{
			int turn=tim/pos,leftt=tim%pos,now=0;
			now=turn*sumv;
			sumv=0;
			ans=max(ans,now);
			
			for (int j=1;j<=leftt;j++)
			{
				sumv+=v[j];
				ans=max(ans,sumv+now);
			}
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Compiler output:
a.cc:1:1: error: 'nclude' does not name a type
    1 | nclude <bits/stdc++.h>
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:10:9: error: 'cin' was not declared in this scope
   10 |         cin>>n>>tim;
      |         ^~~
a.cc:28:42: error: 'max' was not declared in this scope
   28 |                         if (j<=tim)  ans=max(ans,sumv);
      |                                          ^~~
a.cc:33:41: error: 'min' was not declared in this scope; did you mean 'main'?
   33 |                         for (int j=1;j<=min(pos,tim);j++)
      |                                         ^~~
      |                                         main
a.cc:36:37: error: 'max' was not declared in this scope
   36 |                                 ans=max(ans,sumv);
      |                                     ^~~
a.cc:44:29: error: 'max' was not declared in this scope
   44 |                         ans=max(ans,now);
      |                             ^~~
a.cc:53:9: error: 'cout' was not declared in this scope
   53 |         cout<<ans<<endl;
      |         ^~~~
a.cc:53:20: error: 'endl' was not declared in this scope
   53 |         cout<<ans<<endl;
      |                    ^~~~
Language: C++

/******Old_school_@20******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back 
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()) 
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){ 
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){ 
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
       lld n,k; cin>>n>>k;
       pls(n,p);
       pls(n,a);
       vector<lld> vv[5005]; lld c=0;
       bool vis[n];
       memset(vis,false,sizeof(vis));
       iot(n){
           if(vis[i]==false){
               vis[i]=true;
        
               lld prd=p[i]-1;
               vv[c].pb(a[i]);
               while(prd!=i){ vis[prd]=true;
                   vv[c].pb(a[prd]);
                   prd=p[prd]-1;
               }
               c++;
           }
       }
  
       lld f=0; lld ans=-9e18;
       while(f<c){
           lld nn=sz(vv[f]);
           lld cnt=0;
           lld pt=accumulate(all(vv[f]),0ll);
           for(lld i=0;i<sz(vv[f]);i++){
               cnt=0;
               lld len=0,idlen=0;
               lld dp[min(nn,k)]={0};
               for(lld j=i+1;j<nn+i;j++){len++;
               if(len>k)  break;
               dp[len-1]=cnt;
                   cnt+=vv[f][j%nn];
       
                 
               }
               while(k>0){
                   lld maxr=-9e18,maxed=-1;
                   itr(pp,0,min(nn,k)-1ll){ 
                       if(maxr<dp[pp])  maxed=pp+1;
                       maxr=max(maxr,dp[pp]);
               }
               lld  no=k/maxed;
               ans=max(ans,maxr*no);
               k-=(maxed*no);
              
           }
           f++;
       }
       
       cout<<ans;
       
     
}


Compiler output:
a.cc: In function 'int main()':
a.cc:96:2: error: expected '}' at end of input
   96 | }
      |  ^
a.cc:39:11: note: to match this '{'
   39 | int main(){
      |           ^
Language: C++

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

#define ll long long

void chmax(ll& a, ll b) {
  if (a < b) a = b;
}

int main() {
  ll N, K;
  cin >> N >> K;
  
  vector<ll> P(N+1), C(N+1);
  
  for (int i = 1; i <= N; i++) {
    cin >> P[i];
  }
  for (int i = 1; i <= N; i++) {
    cin >> C[i];
  }
  
  
  ll ans = -1000000010;
  // i スタートとして
  for (int i = 1; i <= N; i++) {
    ll move = K;
    
  // 1周回ってくる，
  // 何回かかかるか
    ll temp = i;
    ll count = 1;
    vector<ll> cycle(5010,0);
    
    temp = P[temp];
    cycle[1] += C[temp];
    while (temp != i) {
      temp = P[temp];
      cycle[count + 1] = cycle[count] + C[temp];
      count++;
    }
      
    ll submax = 0;
    ll submax2 = 0;
    bool cond = false;

    // move > count のとき
    if (move > count) {
 
      // cycle[count] > 0 ならば とにかく回りまくって，稼ぐ
      if (cycle[count] > 0) {
        submax += (move / count - 1) * cycle[count];
        submax2 = (move / count) * cycle[count];
        cond = true;

        // 余りの分は move <= count と同様の処理をする
        move = count;
      } else {
       // cycle[count] < 0 の場合は一周の中で最適解を見つける
       move = count;     
      }
    }
    
    // move <= count である場合 || 上の 余りの分の処理
    // cycleの1...move内での最大値を探す
    ll local_max = -1000000010;
    for (int j = 1; j <= move; j++) {
      chmax(local_max, cycle[j]);
    }
    submax += local_max;

    ll local_max2 = -100000010;
    if (cond) {
      move %= count;
      for (int j = 1; j <= move; j++) {
        chmax(local_max2, cycle[j]);
      }
      submax2 += local_max2;
      
      chmax(ans, submax2);
    }
    

    }
    
    // えられた submax を chmax にかける
    chmax(ans, submax);
  }
  cout << ans << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:87:16: error: 'submax' was not declared in this scope
   87 |     chmax(ans, submax);
      |                ^~~~~~
a.cc: At global scope:
a.cc:89:3: error: 'cout' does not name a type
   89 |   cout << ans << endl;
      |   ^~~~
a.cc:90:1: error: expected declaration before '}' token
   90 | }
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

/////////////////////////


//Answer


int main() {

long N,K;
long long max=0,inmax=0,sum=0,j=0,value=0,loops=0;

cin>>N>>K;
vector<long> P(N+2);
vector<long> C(N+2);
vector<long> sums(N+1);
for(long i=0;i<N;i++){
cin>>P.at(i);
cin>>C.at(i);
}
long nex;
for(long i=0;i<N;i++){
    for(long k=0;k<N;k++){
        sums.at(k)=0;
    }
    nex=i;
    sum=0;
    inmax=0;
  	j=0;
    do{      
        j++;
       sum+=C.at(P.at(nex));
        sum+=C.at(2);
        sums.at(j)=sum;
       next=P.at(nex);

    }while(nex!=i);
    if(j<K){        
        if(sum>0){
            inmax=0;
            for(long a=1;a<=K%j;a++){
                if(inmax<sums.at(a)){
                inmax=sums.at(a);
                }
            }
            loops=K/j;
            value=loops*sum+inmax;
        }else{
            inmax=0;
            for(long a=1;a<=j;a++){
                if(inmax<sums.at(a)){
                inmax=sums.at(a);
                }
            }
            value=inmax;
        }
    }else{
        for(long a=1;a<=K;a++){
                if(inmax<sums.at(a)){
                inmax=sums.at(a);
                }
            }

    }
    if(max<value){
        max=value;
    }    
}

cout<<max<<endl;

}




Compiler output:
a.cc: In function 'int main()':
a.cc:81:21: error: overloaded function with no contextual type information
   81 |        next=P.at(nex);
      |                     ^
Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;

int main(){
  long n,k;
  cin >> n >> k;
  long p[n],c[n];
  rep(i,n)cin >> p[i];
  rep(i,n)cin >> c[i];
  long ans = 0, maxss = -INF;
  long flag[n][n];
  rep(i,n)rep(j,n)flag[i][j] = 0;
  long maxscore = -INF;
  int miman = 0;
  long tmp = 0;
  rep(i,n){
    long maxs = -INF;
    tmp = 0
    long now = i;
    long iter = 0;
    while(1){
      if(flag[i][now]!=0)break;
      if(iter>=k){
        miman = 1;
        break;
      }
      tmp += c[p[now]];
      if(maxs<tmp)maxs = tmp;
      now = p[now];
      flag[i][now] = 1;
      iter++;
    }
    if(tmp>maxscore)maxscore = tmp;
    if(tmp>0 && maxs>maxss)maxss = maxs;
  }
  if(miman){
    cout << maxscore << endl;
    return 0;
  }
  cout << (k/n)*tmp + maxss << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:12: error: expected ';' before 'long'
   20 |     tmp = 0
      |            ^
      |            ;
   21 |     long now = i;
      |     ~~~~    
a.cc:24:18: error: 'now' was not declared in this scope; did you mean 'pow'?
   24 |       if(flag[i][now]!=0)break;
      |                  ^~~
      |                  pow
a.cc:29:18: error: 'now' was not declared in this scope; did you mean 'pow'?
   29 |       tmp += c[p[now]];
      |                  ^~~
      |                  pow
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  ll N, K;
  cin >> N >> K;
  ll P[N+1];
  ll C[N+1];
  ll ans = -2000000000;
  ll sum = 0;
  for (ll i = 0; i < N; ++i) {
    cin >> P[i];
  }
  for (ll i = 0; i < N; ++i) {
    cin >> C[i];
    sum += C[i];
  }
  // printf("sum = %lld\n", sum);
  if (K <= N) {
    for (ll i = 0; i < N; ++i) {
      ll tmp = 0;
      ll num = i;
      for (ll j = 0; j < K; ++j) {
        num = P[num]-1;
        tmp += C[num];
        ans = max(ans, tmp);
      }
    }
  } else {
    for (ll i = 0; i < N; ++i) {
      ll tmp = 0;
      ll num = i;
      for (ll j = 0; j < N; ++j) {
        num = P[num]-1;
        tmp += C[num];
        ans = max(ans, tmp);
      }
    }
    ll max = ans;
    if (sum > 0) {
      // ll a = K / N;
      ll tmp1 = sum * (K / N);
      // int cou = K - a * N;
      ll cou = K % N;
      ll tmp2 = -2000000000;
      for (ll i = 0; i < N; ++i) {
      	ll tmp = 0;
      	ll num = i;
      	for (ll j = 0; j < cou; ++j) {
          num = P[num]-1;
          tmp += C[num];
          tmp2 = max(tmp2, tmp);
      	}
      }
      tmp2 += tmp1;
      ll tmp3 = tmp1 - sum;
      tmp3 += max;
      ans = max(tmp1, ans);
      ans = max(tmp2, ans);
      ans = max(tmp3, ans);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:21: error: 'max' cannot be used as a function
   57 |           tmp2 = max(tmp2, tmp);
      |                  ~~~^~~~~~~~~~~
a.cc:63:16: error: 'max' cannot be used as a function
   63 |       ans = max(tmp1, ans);
      |             ~~~^~~~~~~~~~~
a.cc:64:16: error: 'max' cannot be used as a function
   64 |       ans = max(tmp2, ans);
      |             ~~~^~~~~~~~~~~
a.cc:65:16: error: 'max' cannot be used as a function
   65 |       ans = max(tmp3, ans);
      |             ~~~^~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-3;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll N,K;
ll P[50010];
ll C[50010];

int main(){
   cin >> N >> K;
   rep(i,N){
      cin >> P[i];
      P[i]--;
   }
   rep(i,N){
      cin >> C[i];
   }
   ll ans = 0;
   rep(i,N){
      ll now = i,score = 0,sum = 0,SUM = 0,roop = 0;
      rep(j,N){
         if(j != 0 && now == i) break;
         SUM += C[P[now]];
         now = P[now];
         roop++;
      }
      ll n;
      if(K % roop == 0) n = roop;
      else n = K % roop;
      rep(j,n){
         sum += C[P[now]];
         score = max(score,sum);
         now = P[now];
      }
      ll b = K / roop:
      if(K % roop == 0){
         ans = max(ans,max(score,SUM * (K / roop)));
      }else{
         ans = max(ans,max(score,score + SUM * b));
      }
   }
   rep(i,N){
      if(C[i] > 0){
         cout << ans << endl;
         return 0;
      }
   }
   ans = -INF;
   rep(i,N) ans = max(ans,C[i]);
   cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:22: error: expected ',' or ';' before ':' token
   55 |       ll b = K / roop:
      |                      ^
a.cc:58:8: error: 'else' without a previous 'if'
   58 |       }else{
      |        ^~~~
Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
int main(){
	int n,k;
	long long p[5000];
	long long c[5000];
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	long long s=0;
	for(int i=0;i<n;j++){
		cin>>c[i];
		s+=c[i];
	}
	vector<int> a;
	int now=0;
	for(int i=0;i<n;i++){
		a.push_back(c[now]);
		now=p[now];
	}
	long long ans=0;
	if(s>0){
		ans+=k/n*s;
		k%=n;
	}
	for(int i=1;i<n;j++){
		c[i]+=c[i-1];
	}
	long long ma=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(j-i<=k){
				if(c[j]-c[i]>0){
					ma=max(ma,c[j]-c[i]);
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(n-(j-i)<=k){
				if(s-(c[j]-c[i])>0){
					ma=max(ma,s-(c[j]-c[i]));
				}
			}
		}
	}
	cout<<ans+ma<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:25: error: 'j' was not declared in this scope
   26 |         for(int i=0;i<n;j++){
      |                         ^
a.cc:41:25: error: 'j' was not declared in this scope
   41 |         for(int i=1;i<n;j++){
      |                         ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }
// const ll sz = 2e6 + 5;
// vector<ll> fac(sz, 1);

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;
    
    while(t--) {
        ll n, k;
        cin >> n >> k;
        
        vector<ll> p(n+1), c(n+1);
        for (int i = 1; i <= n; i++)
            cin >> p[i];
        for (int i = 1; i <= n; i++)
            cin >> c[i];
        
        ll res = LLONG_MIN;
        for (int i = 1; i <= n; i++) {
            ll kk = k, ii = i;
            vector<ll> tmp;
            vector<bool> vis(n+1, false);
            
            while(!vis[ii] && kk) {
                vis[ii] = true;
                tmp.pb((tmp.empty() ? 0ll : tmp.back()) + c[p[ii]]);
                res = max(res, tmp.back());
                ii = p[ii];
                kk -= 1;
                // cout << tmp.back() << " " << kk << endl;
            }
            
            if (kk > 0 && tmp.back() > 0) {
                ll sz = (int)tmp.size();
                ll itr = kk / sz;
                kk %= sz;
                ll ans = tmp.back() + tmp.back() * itr;
                // cout << "ans " << ans << " " << "itr " << itr << endl;
                res = max(res, ans);
                
                if (itr >= 1) {
                    for (int x = 0; v && x < tmp.size(); x++, v--) {
                        // ans += tmp[x];
                        res = max(res, ans + tmp[x] - tmp.back());
                        // cout << "ans " << ans << " " << kk << endl;
                    }
                }
                
                for (int x = 0; kk; x++, kk--) {
                    // ans += tmp[x];
                    res = max(res, ans + tmp[x]);
                    // cout << "ans " << ans << " " << kk << endl;
                }
            }
        }
        
        cout << res << endl;
    }
    
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:62:37: error: 'v' was not declared in this scope
   62 |                     for (int x = 0; v && x < tmp.size(); x++, v--) {
      |                                     ^
Language: C++

#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
// 多倍長整数型
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
 
#define INF 1e9
#define LINF 1e20
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;
 


int main(){
  ll n;
  Bint k;
  cin >> n >> k;
  vector<ll> p(n), c(n);
  rep(i, n){
    cin >> p[i];
    p[i]--;
  }
  rep(i, n)cin >> c[i];

  Bint res = - LINF;
  Bint tmp = k;
  rep(i, n){
    k = tmp;
    int j = i;
    Bint sum = 0, cnt = 0;
    while(cnt <= k){
      cnt++;
      j = p[j];
      sum += c[j];
      chmax(res, sum);
      if(j == i)break;
      if(cnt > k)break;
    }
    //cout << cnt << " " << sum << " ";
    if(cnt >= k)continue;
    if(sum <= 0){continue;}
    if(sum > 0 && cnt > 0)sum = sum * (k / cnt);
    k %= cnt;
    cnt = 0;
    j = i;
    while(cnt < k){
      cnt++;
      j = p[j];
      sum += c[j];
      chmax(res, sum);
      if(cnt > k)break;
    }
    //cout << sum << endl;
  }
  cout << res << endl;
}
 

Compiler output:
a.cc:21:10: fatal error: boost/multiprecision/cpp_dec_float.hpp: No such file or directory
   21 | #include <boost/multiprecision/cpp_dec_float.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.