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

#include <bits/stdc++.h>
using namespace std;
#define int long long int
// #include "Template.cpp"
#define endl "\n"

int n, k;
vector<int> cost;
vector<int> arr;
vector<set<int>> cycles;
vector<int> v;
int ind = 0;

void dfs(int src) {
    if(v[src]) return ;
    cycles[ind].emplace(src);
    v[src] = 1;
    dfs(arr[src]);
}

int dfs2(int src, int moves) {
    if(moves == 1) {
        return cost[src];
    }
    int c = max(cost[src], cost[src] + dfs2(arr[src], moves - 1));
    return c;
}

void solve()
{
    cin >> n >> k;
    cost.resize(n);
    arr.resize(n);
    for(int i = 0; i < n; i ++) {
        cin >> arr[i];
        --arr[i];
    }
    for(int i = 0; i < n; i ++) {
        cin >> cost[i];
    }
    v.assign(n, 0);
    cycles.resize(n);
    for(int i = 0; i < n; i ++) {
        if(!v[i]) {
            dfs(i);
            ind ++;
        }
    }
    vector<int> cycleCost(ind);
    vector<int> inCycle(n);
    for(auto i = 0; i < ind; i ++) {
        int sum = 0;
        for(auto j : cycles[i]) {
            sum += cost[j];
            inCycle[j] = i;
        }
        cycleCost[i] = sum;
    }
    t(cycleCost);
    int ans = -1e18;
    for(int i = 0; i < n; i ++) {
        int cycleno = inCycle[i];
        int costOfCycle = cycleCost[cycleno];
        int cycleSize = cycles[cycleno].size();
        int tempAns = 0;
        if(costOfCycle > 0) {
            tempAns += (costOfCycle * (k/cycleSize));
            int left = k%cycleSize;
            tempAns += dfs2(arr[i], left);
        }
        else {
            tempAns = dfs2(arr[i], cycleSize);
        }
        ans = max(ans, tempAns);
    }
    cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:59:5: error: 't' was not declared in this scope
   59 |     t(cycleCost);
      |     ^
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (ll i = 0; i < (ll)(x); i++)
#define FOR(i, a, done) for (ll i = (a); i < (ll)(done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n,k;
	cin>>n>>k;
	vector<int>P(n);
	vector<int>C(n);
	map<int,int>next;
	rep(i,n){
		cin>>P[i];
		P[i]--;
		next[i]=P[i];
	}
	rep(i,n){
		cin>>C[i];
	}
	vector<vector<ll>>score(n,vector<ll>(n+1));
	vector<int>lencycle(n);
	rep(i,n){
		int now=i;
		ll sum=0;
		bool yet=true;
		rep(j,n+1){
			score[i][j]=sum;
			sum+=C[next[now]];
			now=next[now];
			if(now==i and yet){
				yet=false;
				lencycle[i]=j+1;
			}
		}
	}
	ll ans=-1e12;
	rep(i,n){
		ll tscore=0;
		ll lenc=lencycle[i];
		ll cnt=k/lencycle[i];
		ll rest=k-cnt*lenc;

		if(score[i][lenc]>0){
			tscore+=score[i][lenc]*cnt;
			ll t=-1e12;
			if(cnt>0){
				rep(j,min(rest,lenc)+1){
					t=max(t,score[i][j]);
				}	
			}else{
				FOR(j,1,min(rest,lenc)+1){
					t=max(t,score[i][j]);
				}
			}
			tscore+=t;
		}else{
			ll t=-1e12;
			FOR(j,1,min(k,lenc)+1){
				t=max(t,score[i][j]);
			}	
			tscore+=t;
		}
		ans=max(tscore,ans);
	}
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Compiler output:
a.cc:19:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
   19 | #include <boost/multiprecision/cpp_int.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n,k;
	cin>>n>>k;
	vector<int>P(n);
	vector<int>C(n);
	map<int,int>next;
	rep(i,n){
		cin>>P[i];
		P[i]--;
		next[i]=P[i];
	}
	rep(i,n){
		cin>>C[i];
	}
	vector<vector<ll>>score(n,vector<ll>(n+1));
	vector<int>lencycle(n);
	rep(i,n){
		int now=i;
		ll sum=0;
		bool yet=true;
		rep(j,n+1){
			score[i][j]=sum;
			sum+=C[next[now]];
			now=next[now];
			if(now==i and yet){
				yet=false;
				lencycle[i]=j+1;
			}
		}
	}
	ll ans=-1e12;
	rep(i,n){
		ll tscore=0;
		ll lenc=lencycle[i];
		ll cnt=k/lencycle[i];
		ll rest=k-cnt*lenc;

		if(score[i][lenc]>0){
			tscore+=score[i][lenc]*cnt;
			ll t=-1e12;
			if(cnt>0){
				rep(j,min(rest,lenc)+1){
					t=max(t,score[i][j]);
				}	
			}else{
				FOR(j,1,min(rest,lenc)+1){
					t=max(t,score[i][j]);
				}
			}
			tscore+=t;
		}else{
			ll t=-1e12;
			FOR(j,1,min(k,lenc)+1){
				t=max(t,score[i][j]);
			}	
			tscore+=t;
		}
		ans=max(tscore,ans);
	}
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Compiler output:
a.cc:19:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
   19 | #include <boost/multiprecision/cpp_int.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

/*input
3 3
3 1 2
-1000 -2000 -3000
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;


int n, k;
int p[5005], c[5005];
ll ans = LLONG_MIN;

void check(int i) {
	// DEBUG(i)
	set<int> cycle;
	int iter = 0, cur = i;
	ll sum = 0;
	vector<ll> best;
	while(iter<k) {
		if(cycle.count(cur)) break;
		sum += c[p[cur]];
		// DEBUG(sum)
		if(best.empty()) best.push_back(sum);
		else best.push_back(max(best.back(), sum));
		cycle.insert(cur);
		cur = p[cur];
		iter++;
	}
	// DEBUG(sum)
	// DEBUG(iter)
	// rept(best) cout << *it << " ";
	// cout << endl;
	ans = max(ans, best.back());
	int mleft = k-iter;
	if(sum && mleft) ans = max(ans, (ll)(sum*(k/iter)
		+ (k%iter ? best[k%iter - 1] : 0)));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	cin >> n >> k;
	rep(i, n) {cin >> p[i]; --p[i];}
	rep(i, n) cin >> c[i];
	rep(i, n) {
		check(i);
	}
	cout << ans;
	return 0;
}
// 29507023469

Compiler output:
a.cc:39:10: error: 'LLONG_MIN' was not declared in this scope
   39 | ll ans = LLONG_MIN;
      |          ^~~~~~~~~
a.cc:22:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   21 | #include <iomanip>
  +++ |+#include <climits>
   22 |
Language: Java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
    int[] goesTo;
    int[] value;
    boolean[] onStack;

    public static void Main(String[] args) throws IOException {
        new Task4().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int k = Integer.parseInt(tokenizer.nextToken());
        goesTo = new int[n];
        tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) goesTo[i] = Integer.parseInt(tokenizer.nextToken()) - 1;
        value = new int[n];
        tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) value[i] = Integer.parseInt(tokenizer.nextToken());

        long max = Long.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            onStack = new boolean[n];
            max = Math.max(max, dfs(i, k, new ArrayDeque<Integer>()));
        }
        out.println(max);
        out.close();
    }

    private long dfs(int node, int k, ArrayDeque<Integer> stack) {
        if (k == 0) return 0;

        if (onStack[node]) {
            long circleSum = 0;
            int circleLength = 0;
            ArrayDeque<Integer> circle = new ArrayDeque<Integer>();
            while (stack.peekFirst() != node) {
                int circleNode = stack.removeFirst();
                circleSum += value[circleNode];
                circle.addFirst(circleNode);
                circleLength++;
            }
            circleLength++;
            circleSum += value[stack.removeFirst()];
            circle.addFirst(node);
            long sum = (k / circleLength) * circleSum;
            int mod = k % circleLength;
            for (int i = 0; i < mod; i++) {
                sum += value[circle.removeFirst()];
            }
            return sum;
        }

        long sum = value[node];
        stack.addFirst(node);
        onStack[node] = true;
        long otherSum = dfs(goesTo[node], k - 1, stack);
        if (otherSum > 0) sum += otherSum;
        return sum;
    }
}

Compiler output:
Main.java:15: error: cannot find symbol
        new Task4().solve();
            ^
  symbol:   class Task4
  location: class Main
1 error
Language: C++

// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
// #define hell 1000000007
#define infl LLONG_MAX

const ll hell = -(LLONG_MAX);
const ll sz = 5009;

ll dp[sz][sz][sz], p[sz], c[sz], cy[sz], vis[sz], valC[sz];
map<ll, vector<ll> > path;

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, 	z, k, n;
	z = hell;
	cin >> n >> k;

	rep(i, 0, n, 1) {
		cin >> p[i];
		p[i]--;
		// cerr << p[i] << " ";
	}
	// cerr << "\n";

	rep(i, 0, n, 1) {
		cin >> c[i];
	}

	rep(i, 0, n, 1) {
		if (!vis[i]) {
			std::vector<ll> v;

			j = i;	t = 0;
			while (!vis[j]) {
				vis[j] = 1;
				v.push_back(j);
				t += c[j];
				j = p[j];
			}

			for (auto zx : v) {
				cy[zx] = v.size();
				valC[zx] = t;
				path[zx] = v;
			}
		}

		// debug(cy[i], path[i]);
	}


	rep(i, 0, n, 1)	vis[i] = 0;


	rep(i, 0, n, 1) {
		ll reps = max(0LL, (k - cy[i]) / cy[i]);
		t = reps * valC[i];
		if (t < 0)	t = 0;
		ll left = k % cy[i];
		if (k >= cy[i])	left += cy[i];

		j = p[i];
		// debug(i, j, t, left);
		while (left--) {
			t += c[j];
			// debug(t, j);

			z = max(z, t);
			j = p[j];
		}

		// z = max(z, t);
	}


	ce(z);
	debug(z);

}



Compiler output:
a.cc:4:10: fatal error: debug.h: No such file or directory
    4 | #include "debug.h"
      |          ^~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
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;}
 
 
 int main(){
   ll n,k ; cin>>n>>k ;
   vector<ll> A(n),B(n) ;
   rep(i,n) {
     cin>>A[i] ;
   A[i]-- ;
   }
   rep(i,n) cin>>B[i] ;
   vector<ll> s(n),ans(n) ;
   rep(i,n){
     ll cnt=0 ;
     ll now= i ;
     ll po=0 ;
     rep(ww,n){
       cnt++ ;
     now= A[now] ;
     po+= B[now] ;
     if(now==i) break ;
     }
     if(po=<0){
      now=i ;
      po=0 ;
      ll bns= -INF ;
      rep(ww,min(k,cnt)){
        now=A[now] ;
        po+=B[now] ;
        chmax(bns,po) ;
        
      }
      ans[i]=bns ;
     } 

     else{
       ans[i]= po*(k/cnt) ;
      now=i ;
      po=0 ;
      
      if((k/cnt)==0){ 
        ll bns=-INF ;
       ll u= (k%cnt) ;
      rep(ww,u){
        now= A[now] ;
        po+=B[now] ;
        chmax(bns,po) ;

      }
      ans[i]+= bns ;
      }
      else{
        ll bns=0 ;
      ll u= (k%cnt) ;
      rep(ww,u){
        now= A[now] ;
        po+=B[now] ;
        chmax(bns,po) ;
        
      }
      ans[i]+= bns;
      }
      
     }


   }

   ll lp=-INF ;
   rep(i,n) chmax(lp,ans[i]) ;
   cout<<lp<<endl;
   
   return 0 ;
 }



Compiler output:
a.cc: In function 'int main()':
a.cc:48:12: error: expected primary-expression before '<' token
   48 |      if(po=<0){
      |            ^
Language: C++

// AtCoder template
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

int p[5001];
ll c[5001];

ll search(int s, ll k){
    vector<bool> visited(n, false);
    ll cnt = 0LL;
    int next = p[s];
    ll score = 0LL, max_score = -1e9 - 1;

    // 1回のループの走査
    while((!visited[next]) && cnt < k){
        visited[next] = true;
        score += c[next];
        next = p[next];
        cnt++;
        max_score = max(max_score, score);
    }

    // ループ途中の場合
    if(cnt >= k){
        return max_score;
    }
    
    // ループ全体が負の場合
    if(score <= 0){
        return max_score;
    }

    // ループで余った部分の最大値
    ll res_max_score = -1e9-1;
    ll res_score = 0LL;
    next = p[s];
    rep(i, k%cnt){
        res_score += c[next];
        next = p[next];
        res_max_score = max(res_max_score, res_score);
    }

    if(k%cnt == 0) res_max_score = 0LL;
    return max(max_score, score*(k/cnt) + res_max_score);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; ll k; cin >> n >> k;
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    rep(i,n) cin >> c[i];
    

    // 全て負の場合
    bool all_minus = true;
    ll minus_max = -1e9-1;
    rep(i,n) if(c[i] >= 0){
        all_minus = false;
        break;
    }else{
        minus_max = max(minus_max, c[i]);
    }
    if(all_minus){
        cout << minus_max << endl;
        return 0;
    }

    ll ans = 0LL;
    rep(i,n) ans = max(ans, search(i, k));
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'll search(int, ll)':
a.cc:11:26: error: 'n' was not declared in this scope
   11 |     vector<bool> visited(n, false);
      |                          ^
Language: C++

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

#define int long long
#define negINF -999999999999999

#include "debug.cpp"

int n, perm[6000], value[6000];

int check(int ind, int k){
	int i, j, ans = 0;

	int cycleValue = 0, cycleLength = 1;
	int oriind = ind;
	cycleValue += value[perm[ind]];
	ind = perm[ind];

	int ma = cycleValue;
	while(ind != oriind){
		if(cycleLength == k)
			break;
		cycleValue += value[perm[ind]];
		ind = perm[ind];
		ma = max(ma, cycleValue);
		cycleLength++;
	}


	if(cycleLength == k)
		return ma;

	// debug(cycleValue, cycleLength, k);

	if(cycleValue > 0){
		ans += cycleValue*(k/cycleLength - 1);
		k %= cycleLength;
		k += cycleLength;
		// debug(ans);
// 
		int ma = negINF, temp = 0;
		ind = oriind;
		while(k != 0){
			// debug(ma, temp);
			temp += value[perm[ind]];
			ma = max(ma, temp);
			ind = perm[ind];
			k--;
		}

		return ans+ma;
	}

	return ma;

}

int32_t main(){
	int i, j, k;
	cin >> n >> k;
	for(i=0; i<n; i++){
		cin >> perm[i];
		perm[i]--;
	}
	for(i=0; i<n; i++){
		cin >> value[i];
	}

	int ans = -9999999999999;
	for(i=0; i<n; i++){
		int lol = check(i, k);
		// debug(lol, i);
		ans = max(ans, check(i, k));
	}

	cout << ans << "\n";

	
}

Compiler output:
a.cc:7:10: fatal error: debug.cpp: No such file or directory
    7 | #include "debug.cpp"
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
#include <set>

#define int long long

using namespace std;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    int n, k, answ = LLONG_MIN;
    cin >> n >> k;

    int p[n], c[n];
    for(int i = 0; i < n; i++)
        cin >> p[i];
    for(int i = 0; i < n; i++)
        cin >> c[i];

    set<int> st;
    vector<int> v;
    v.reserve(n+100);

    for(int pos = 0; pos < n; pos++) {
        st.clear();
        v.clear();
        int cur = pos;
        while(st.find(cur) == st.end()) {
            st.insert(cur);
            v.push_back(c[cur]);
            cur = p[cur]-1;
        }
        int sz = (int)v.size();
        int s[sz] = {0}, val = LLONG_MIN;
        s[0] = v[0];
        for(int i = 1; i < sz; i++)
            s[i] = s[i-1] + v[i];
        if(k <= sz) {
            for(int i = 0; i < k; i++)
                val = max(val, s[i]);
            answ = max(answ, val);
        }
        else {
            for(int i = 0; i < sz; i++)
                val = max(val, s[i]);
            int temp_val = 0;
            for(int i = 0; i < k%sz; i++)
                temp_val = max(temp_val, s[i]);
            answ = max(answ, max(val, (s[sz-1])*(k/sz)+temp_val));
        }
    }

    cout << answ;

    return 0;
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:16:22: error: 'LLONG_MIN' was not declared in this scope
   16 |     int n, k, answ = LLONG_MIN;
      |                      ^~~~~~~~~
a.cc:4:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <set>
  +++ |+#include <climits>
    4 |
Language: C++

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

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

  int loop = n;
  int now = 1;
  long long loop_sum = 0;
  while ( loop-- > 0 ) {
    now = p[now];
    loop_sum += c[now];
  }

  vector<vector<long long>> dp(n+1, vector<long long>(n));
  for ( int i = 1; i <= n; i++ ) {
    int loop = n;
    int now = i;
    long long sum = 0;
    dp[i][0] = 0;
    for ( int j = 1; j < n; j++ ) {
      now = p[now];
      sum += c[now];
      dp[i][j] = max(dp[i][j-1], sum);
    }
  }

  long long ans = 0;
  if ( loop_sum > 0 ) {
    long long use_loop = k/n;
    ans = loop_sum * use_loop;
    k -= use_loop * n;
  } else {
    k = ( k > n-1 ) ? n-1 : k;
  }
  
  long long max_start = dp[1][k];
  for ( int i = 2; 1 <= n; i++ ) {
    max_start = max(max_start, dp[i][k]);
  }
  ans += max_start;

  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:3: error: expected initializer before 'long'
    6 |   long long k;
      |   ^~~~
a.cc:7:10: error: 'n' was not declared in this scope; did you mean 'yn'?
    7 |   cin >> n >> k;
      |          ^
      |          yn
a.cc:7:15: error: 'k' was not declared in this scope
    7 |   cin >> n >> k;
      |               ^
a.cc:10:43: error: 'p' was not declared in this scope
   10 |   for ( int i = 1; i <= n; i++ ) { cin >> p[i]; }
      |                                           ^
a.cc:11:43: error: 'c' was not declared in this scope
   11 |   for ( int i = 1; i <= n; i++ ) { cin >> c[i]; }
      |                                           ^
a.cc:17:11: error: 'p' was not declared in this scope
   17 |     now = p[now];
      |           ^
a.cc:18:17: error: 'c' was not declared in this scope
   18 |     loop_sum += c[now];
      |                 ^
a.cc:28:13: error: 'p' was not declared in this scope
   28 |       now = p[now];
      |             ^
a.cc:29:14: error: 'c' was not declared in this scope
   29 |       sum += c[now];
      |              ^
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <limits>
#include <ctime>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define sz(x) (int)(x.size())

typedef long long ll;
typedef tuple<int, int, int> tri;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef __gnu_pbds::tree<
    int,
    __gnu_pbds::null_type,
    less<int>,
    __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>
    ordered_set;

const ll MODULO = 1000000007;

void ftime()
{
#ifndef ONLINE_JUDGE
    cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}

static int speed_increase = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    return 0;
}();

vll p(5001);
vb vis(5001);
vll c(5001);
void solve()
{
    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];

    ll ans = LONG_LONG_MIN;
    for (int start = 1; start <= n; ++start)
    {
        fill(vis.begin() + 1, vis.begin() + n + 1, false);
        ll sum = 0;
        ll msum = numeric_limits<ll>::min();
        int pos = start;
        int left = 0;
        for (int moves = 0; moves < k; ++moves)
        {
            if (vis[pos])
            {
                if (sum > 0)
                {
                    left = k - moves;
                    sum += sum * (left / moves);
                    msum = max(sum, msum);
                    left = k % moves;
                }
                break;
            }
            sum += c[pos];
            msum = max(msum, sum);
            vis[pos] = true;
            pos = p[pos];
        }
        for (int moves = 0; moves < left; ++moves)
        {
            sum += c[pos];
            msum = max(msum, sum);
            pos = p[pos];
        }
        ans = max(msum, ans);
    }
    cout<<ans;
}

int main()
{
    solve();
    // ftime();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:62:14: error: 'LONG_LONG_MIN' was not declared in this scope
   62 |     ll ans = LONG_LONG_MIN;
      |              ^~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <ctime>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define sz(x) (int)(x.size())

typedef long long ll;
typedef tuple<int, int, int> tri;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef __gnu_pbds::tree<
    int,
    __gnu_pbds::null_type,
    less<int>,
    __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>
    ordered_set;

const ll MODULO = 1000000007;

void ftime()
{
#ifndef ONLINE_JUDGE
    cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}

static int speed_increase = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    return 0;
}();

vll p(5001);
vb vis(5001);
vll c(5001);
void solve()
{
    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];

    ll ans = LONG_LONG_MIN;
    for (int start = 1; start <= n; ++start)
    {
        fill(vis.begin() + 1, vis.begin() + n + 1, false);
        ll sum = 0;
        ll msum = LONG_LONG_MIN;
        int pos = start;
        int left = 0;
        for (int moves = 0; moves < k; ++moves)
        {
            if (vis[pos])
            {
                if (sum > 0)
                {
                    left = k - moves;
                    sum += sum * (left / moves);
                    msum = max(sum, msum);
                    left = k % moves;
                }
                break;
            }
            sum += c[pos];
            msum = max(msum, sum);
            vis[pos] = true;
            pos = p[pos];
        }
        for (int moves = 0; moves < left; ++moves)
        {
            sum += c[pos];
            msum = max(msum, sum);
            pos = p[pos];
        }
        ans = max(msum, ans);
    }
    cout<<ans;
}

int main()
{
    solve();
    // ftime();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:61:14: error: 'LONG_LONG_MIN' was not declared in this scope
   61 |     ll ans = LONG_LONG_MIN;
      |              ^~~~~~~~~~~~~
Language: C++

# your code goes here
n,k = map(int, input().split())
p = list(map(int, input().split()))
cost = list(map(int, input().split()))
for i in range(n):
	p[i] -= 1
ans = -10**18
for i in range(n):
	curr = 0
	cum = 0
	ind = p[i]
	temp = []
	while ind != i:
		temp.append(cost[ind])
		ind = p[ind]
	temp.append(cost[ind])
	m = len(temp)
	pref = [temp[0]]
	for j in range(1,m):
		pref.append(pref[j-1] + temp[j])
	curr = pref[0]
	for j in range(min(k,m)):
		curr = max(curr,pref[j])
	if k > m:
		for j in range(k % m):
			cum = max(cum, pref[j])
		curr = max(curr, cum + pref[m-1]*(k//m))
	ans = max(ans, curr)
print(ans)

Compiler output:
a.cc:1:3: error: invalid preprocessing directive #your
    1 | # your code goes here
      |   ^~~~
a.cc:2:1: error: 'n' does not name a type
    2 | n,k = map(int, input().split())
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back

int n, k;
vector<int> nxt;
vector<int> c;

int test(int s, int k)
{
    int ret = 0;
    int now = s;


    int mn = -1e18;
    forn(_, k)
    {
        now = nxt[now];
        ret += c[now];
        mn = max(mn, ret);
    }
    return mn;
}
pair<int,int> test(int s)
{
    pair<int,int> ret = mp(0, 0);
    int now = s;
    do
    {
        now = nxt[now];
        ret.f += c[now];
        ret.s++;
    } while (now != s);
    return ret;
}
void solve()
{
    cin>>n>>k;
    nxt.resize(n);
    c.resize(n);
    forn(i, n) cin>>nxt[i], --nxt[i];
    forn(i, n) cin>>c[i];
    // if (k <= n)
    // {
    //     int r = LLONG_MIN;
    //     forn(i, n) r = max(r, test(i, k));
    //     cout << r<< '\n';
    //     return;
    // }
    //else
    {
        int r = -1e18;
        forn(i, n)
        {
            pair<int,int> p = test(i);
            r = max(r, test(i, n));

            //else
            {            
                int now = p.first * (k/p.s);
                r = max(r, now);
                int rm = k%p.s;
                now += test(i, rm);
                r = max(r, now);
            }
        }
        cout << r << '\n';
        
    }
    
}

signed main(void)

Compiler output:
a.cc:109:18: error: expected initializer at end of input
  109 | signed main(void)
      |                  ^
Language: C++

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	vector<int> p(n), c(n);
	for (int i = 0; i < n; i++)
		cin >> p[i], --p[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	ll ans = LLONG_MIN;
	for (int st = 0; st < n; st++) {
		vector<int> cycle;
		for (int i = p[st]; i != st; i = p[i]) {
			cycle.push_back(c[i]);
		}
		cycle.push_back(c[st]);
		ll tot = accumulate(cycle.begin(), cycle.end(), 0ll);
		ll sum = 0;
		for (int i = 0; i < cycle.size(); i++) {
			sum += cycle[i];
			if (i < k) {
				ans = max(ans, (ll)sum + (k - i - 1) / cycle.size() * tot);
			}
		}
	}
	cout << ans << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:42: error: no matching function for call to 'max(ll&, long long unsigned int)'
   23 |                                 ans = max(ans, (ll)sum + (k - i - 1) / cycle.size() * tot);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:23:42: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   23 |                                 ans = max(ans, (ll)sum + (k - i - 1) / cycle.size() * tot);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:23:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   23 |                                 ans = max(ans, (ll)sum + (k - i - 1) / cycle.size() * tot);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	vector<int> p(n), c(n);
	for (int i = 0; i < n; i++)
		cin >> p[i], --p[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	ll ans = LLONG_MIN;
	for (int st = 0; st < n; st++) {
		vector<int> cycle;
		for (int i = p[st]; i != st; i = p[i]) {
			cycle.push_back(c[i]);
		}
		cycle.push_back(c[st]);
		ll tot = accumulate(cycle.begin(), cycle.end(), 0ll);
		ll sum = 0;
		for (int i = 0; i < cycle.size(); i++) {
			sum += cycle[i];
			if (i < k) {
				ans = max(ans, sum + (k - i - 1) / cycle.size() * tot);
			}
		}
	}
	cout << ans << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:42: error: no matching function for call to 'max(ll&, long long unsigned int)'
   23 |                                 ans = max(ans, sum + (k - i - 1) / cycle.size() * tot);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:23:42: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   23 |                                 ans = max(ans, sum + (k - i - 1) / cycle.size() * tot);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:23:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   23 |                                 ans = max(ans, sum + (k - i - 1) / cycle.size() * tot);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#define sort stable_sort
using namespace std; 
 
int _;

int n,k,p[100050],c[100050],cnt;
long long maxn=1 << 30,Maxn;
bool vis[100050];

inline long long dfs(int x)
{
	if(vis[x])
		return 0;
	cnt++;
	vis[x]=true;
	long long sum=dfs(p[x]);
	vis[x]=false;
	return sum+c[x];
}

inline long long Dfs(int x,int depth)
{ 
	if(depth)	
		return Dfs(p[x],depth-1)+c[x];
	return 0;
}
 
inline void rdfs(int x,long long sum)
{
	D(sum);
	if(vis[x])
		return;
	vis[x]=true;
	sum += c[x];
	Maxn=max(Maxn,sum);
	rdfs(p[x],sum);
	vis[x]=false;
	return;
}
 
int main()
{	
	//for(scanf("%d",&_);_;_--)	
	scanf("%d%d",&n,&k);
	maxn <<= 30;
	maxn *= -1;
	long long m=maxn;
	for(int i=1;i <= n;i++)
		scanf("%d",p+i);
	for(int i=1;i <= n;i++)
		scanf("%d",c+i);
	for(int i=1;i <= n;i++)
	{
		cnt=0;
		Maxn=m;
		long long x=dfs(i);
		rdfs(p[i],0LL);
		int t=k%cnt;
		maxn=max(max(Maxn,x*(k/cnt)+Dfs(p[i],t)),maxn); 
	} 
	printf("%lld\n",maxn); 
	return 0;
}               


Compiler output:
a.cc: In function 'void rdfs(int, long long int)':
a.cc:31:9: error: 'D' was not declared in this scope
   31 |         D(sum);
      |         ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
int n,p[5003],len;
int K;
ll C[5002],ans=-INF,ret[5002];
void dfs(int x,int w){
	if(x==w)return;
	++len;
	ret[len]=ret[len-1]+C[p[x]];
	dfs(p[x],w);
}
int main(){
	cin>>n>>K;
	for(int i=1;i<=n;i++)cin>>p[i];
	for(int i=1;i<=n;i++)cin>>C[i],ans=max(ans,C[i])
	for(int i=1;i<=n;i++){
		ret[1]=C[p[i]];
		len=1;
		dfs(p[i],i);
		for(int j=1;j<=min(len,K);j++)ans=max(ans,ret[j]);
		if(K>len&&ret[len]>0){
			ll pr=K/len,ps=K%len,res=pr*ret[len];
			for(int j=0;j<=ps;j++)ans=max(ans,res+ret[j]);
		}
	}
	cout<<ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:57: error: expected ';' before 'for'
   17 |         for(int i=1;i<=n;i++)cin>>C[i],ans=max(ans,C[i])
      |                                                         ^
      |                                                         ;
   18 |         for(int i=1;i<=n;i++){
      |         ~~~                                              
a.cc:18:21: error: 'i' was not declared in this scope
   18 |         for(int i=1;i<=n;i++){
      |                     ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
signed main(){
  ll N,K,D,ans,n;cin>>N>>K;ll C[N],P[N];
  REP(i,N)cin>>C[i];
  REP(i,N)cin>>P[i];
  if(X>K*D)ans=X-K*D;
  else{
    n=X/D;
    if(K%2==n%2)ans=X-D*n;
    else ans=D*(n+1)-X;
  }
  cout<<abs(ans)<<endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:7: error: 'i' was not declared in this scope
   11 |   REP(i,N)cin>>C[i];
      |       ^
a.cc:4:24: note: in definition of macro 'FOR'
    4 | #define FOR(i,l,r) for(i=l;i<r;i++)
      |                        ^
a.cc:11:3: note: in expansion of macro 'REP'
   11 |   REP(i,N)cin>>C[i];
      |   ^~~
a.cc:12:7: error: 'i' was not declared in this scope
   12 |   REP(i,N)cin>>P[i];
      |       ^
a.cc:4:24: note: in definition of macro 'FOR'
    4 | #define FOR(i,l,r) for(i=l;i<r;i++)
      |                        ^
a.cc:12:3: note: in expansion of macro 'REP'
   12 |   REP(i,N)cin>>P[i];
      |   ^~~
a.cc:13:6: error: 'X' was not declared in this scope
   13 |   if(X>K*D)ans=X-K*D;
      |      ^
Language: C++


// Problem : 
// 			D - Moving Piece
// 			
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define int long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define mod 998244353
#define bug cout<<"HY"<<endl
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define numize(A) A.numize(unique(A.begin(), A.end()) - A.begin())
typedef pair<int,int> P;
int power(int a,int b)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return (power((a*a)%mod,b/2))%mod;
    return (a*(power((a*a)%mod,b/2))%mod)%mod;
}
int modInv(int n)
{
    return power(n, MOD-2);
}
int nCr(int n, int r, int p=MOD)
{
   if (r==0)
      return 1;
    int Fact[n+1];
    Fact[0] = 1;
    for (int i=1 ; i<=n; i++)
    {
        Fact[i] = (Fact[i-1]*i)%p;
    }
    return (((Fact[n]* modInv(Fact[r])) % MOD) *(modInv(Fact[n-r]) % MOD)) % MOD;
}
double PI=3.14159265359;
int cost;
int P1[5005],C[5005];
int ans=-1e9;
void DFS(int s,int k,bool visited[],vector<int> V[])
{
	if(k==0)
		return;
	for(int ind:V[s])
	{
		// if(visited[ind])
			// continue;
		// visited[ind]=true;
		cost+=C[ind];
		ans=max(ans,cost);
		DFS(ind,k-1,visited,V);
	}
	return;
}
void solve()
{
	int n,k,i;
	cin>>n>>k;
	vector<int> V[n];
	for(i=0;i<n;i++)
	{
		cin>>P1[i];
		P1[i]--;
		V[i].pb(P1[i]);
	}
	for(i=0;i<n;i++)
		cin>>C[i];
	for(i=0;i<n;i++)
	{
		// bool visited[n];
		// memset(visited,0,sizeof(visited));
		// visited[i]=true;
		cost=0;
		DFS(i,k,visited,V);
		ans=max(ans,cost);
	}
	cout<<ans<<endl;
}
int32_t main()
{
    boost;
    int  t=1;
    // cin>>t;
    while(t--)
    {
    	solve();
    }
}



Compiler output:
a.cc: In function 'void solve()':
a.cc:98:25: error: 'visited' was not declared in this scope
   98 |                 DFS(i,k,visited,V);
      |                         ^~~~~~~
Language: C++

#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (auto&& e : p) cin >> e, --e;
  vector<int64_t> c(n);
  for (auto&& e : c) cin >> e;
  auto res = numeric_limits<int64_t>::min();
  for (int s = 0; s < n; ++s) {
    vector<int64_t> v;
    for (int i = s;; i = p[i]) {
      v.push_back(c[i]);
      if (p[i] == s) break;
    }
    int m = size(v);
    auto sum = accumulate(begin(v), end(v), 0LL);
    int64_t cur = 0;
    for (int r = 1; r <= m; ++r) {
      if (r > k) break;
      cur += v[r - 1];
      res = max(res, cur + (k - r) / m * max(sum, 0LL));
    }
  }
  cout << res << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:16: error: no matching function for call to 'max(long int&, long long int)'
   30 |       res = max(res, cur + (k - r) / m * max(sum, 0LL));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/extc++.h:32,
                 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:30:16: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   30 |       res = max(res, cur + (k - r) / m * max(sum, 0LL));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:30:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   30 |       res = max(res, cur + (k - r) / m * max(sum, 0LL));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using pll = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"

#include <atcoder/all>

using namespace atcoder;

// const ll INF = LONG_LONG_MAX;
const int INF = INT_MAX;
// const ll MOD = 1000000007; // 998244353;

int main() {
	// 0-ind
	int R, C, K; cin >> R >> C >> K;
	vvi val(R, vi(C));
	vector<vvl> dp(4, vvl(R, vl(C))); //dp[k][i][j]: (i,j)にいて，その行で取ったアイテムの数が(i,j)で取ったものを含めkであるときの価値の合計の最大値
	rep0(K) {
		int r, c, v; cin >> r >> c >> v;
		val[--r][--c] = v;
	}
	rep(i, R) {
		rep(j, C) {
			if (i > 0) rep(k, 4) chmax(dp[k][i][j], dp[k][i - 1][j]);
			if (j > 0) rep(k, 4) chmax(dp[0][i][j], dp[k][i][j - 1]);
			if (val[i][j]) rep3(k, 2, -1) chmax(dp[k + 1][i][j], dp[k][i][j] + val[i][j]);
		}
	}
	ll ans = 0;
	rep(k, 4) chmax(ans, dp[k][R - 1][C - 1]);
	cout << ans << endl;
}

Compiler output:
a.cc:24:10: fatal error: atcoder/all: No such file or directory
   24 | #include <atcoder/all>
      |          ^~~~~~~~~~~~~
compilation terminated.