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

#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<stack>
#include<sstream>
#include<fstream>
#include<string>
#include<assert.h>
//#include<Eigen/Dense>
//using namespace Eigen;
using namespace std;
typedef long long ll;


ll a[5005], b[5005];
int main()
{
	ll  n, k;
	while (cin >> n >> k) {
		for (int i = 0; i < n; i++) {
			cin >> a[i + 1];
		}
		for (int i = 0; i < n; i++) {
			cin >> b[i + 1];
		}
		vector<vector<ll>> r(n + 1);
		unordered_map<ll, ll> mp;
		ll ans = (-2147483647L - 1);
		for (int i = 1; i <= n; i++) {
			ll temp = 0;
			int j = i;
			int ok = 1;
			vector<ll> t; 
			ll s = b[i];
			vector<ll> t; t.push_back(s);
			for (int j = a[i]; j != i; j = a[j]) s += b[j], t.push_back(s);
			/*while (ok || (a[j] != a[i])) {
				ok = 0;
				temp += b[a[j]];
				t.push_back(temp);
				r[i].push_back(j);
				j = a[j];
			}*/
			mp[i] = temp;	
			
			for (int j = 0; j < r[i].size(); j++) {
				ll res = (k - j - 1) / r[i].size();
				if (res < 0)break;
				ans = max(ans, t[j] + res*max(0LL, s));
			}
		}
		/*ll ans = (-2147483647L - 1);
		for (int i = 1; i <= n; i++) {
			ll temp1 = k / r[i].size();
			ll temp2 = k % r[i].size();
			ll temp3 = 0;
			ll temp4 = (-2147483647L - 1);
			ll temp5 = (-2147483647L - 1);
			for (int j = 0; j < temp2; j++) {
				temp3 += b[a[r[i][j]]];
				temp4 = max(temp4, temp3);
			}
			temp3 = 0;
			for (int j = 0; j < r[i].size(); j++) {
				temp3 += b[a[r[i][j]]];
				temp5 = max(temp5, temp3);
			}
			if (temp1 > 0)
				ans = max(max(ans, max(max(temp1*mp[i] + temp4, temp1*mp[i]), *max_element(b + 1, b + 1 + n))), temp5);
			else
				ans = max(ans,max(temp4, *max_element(b + 1, b + 1 + n)));
		}*/
		cout << ans << endl;
	}
	return 0;
}


//ll n, k, vis[5005];
//ll p[5005], c[5005], sum[5005], ans = -1e18;
//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];
//	for (int i = 1; i <= n; i++) {
//		ll s = c[i];
//		vector<ll> t; t.push_back(s);
//		for (int j = p[i]; j != i; j = p[j]) s += c[j], t.push_back(s);
//		int len = t.size();
//		for (int j = 0; j < len; j++) {
//			ll rest = k - j - 1;
//			if (rest < 0) break;
//			ans = max(ans, t[j] + (rest / len)*max(s, 0LL));
//		}
//	}
//	cout << ans;
//}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:36: error: redeclaration of 'std::vector<long long int> t'
   43 |                         vector<ll> t; t.push_back(s);
      |                                    ^
a.cc:41:36: note: 'std::vector<long long int> t' previously declared here
   41 |                         vector<ll> t;
      |                                    ^
Language: C++

#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<stack>
#include<sstream>
#include<fstream>
#include<string>
#include<assert.h>
//#include<Eigen/Dense>
//using namespace Eigen;
using namespace std;

typedef long long ll;

ll a[5005], b[5005];
int main()
{
	int  n, k;
	while (cin >> n >> k) {
		for (int i = 0; i < n; i++) {
			cin >> a[i + 1];
		}
		for (int i = 0; i < n; i++) {
			cin >> b[i + 1];
		}
		vector<vector<ll>> r(n + 1);
		unordered_map<ll, ll> mp;
		for (int i = 1; i <= n; i++) {
			ll temp = 0;
			int j = i;
			int ok = 1;
			while (ok || (a[j] != a[i])) {
				ok = 0;
				temp += b[a[j]];
				r[i].push_back(j);
				j = a[j];
			}
			mp[i] = temp;
		}
		ll ans = LONG_MIN;
		for (int i = 1; i <= n; i++) {
			ll temp1 = k / r[i].size();
			ll temp2 = k % r[i].size();
			ll temp3 = 0;
			ll temp4 = LONG_MIN;
			for (int j = 0; j < temp2; j++) {
				temp3 += b[a[r[i][j]]];
				temp4 = max(temp4, temp3);
			}

/*			ans = max(ans, temp1*mp[i] + temp4);
			cout << temp1 * mp[i] << endl;
			cout << temp1 * mp[i] + temp4 << endl;
			cout << temp4 << endl;
			cout << *max_element(b + 1, b + 1 + n) << endl;*/
			if (temp1 > 0)
				ans = max(ans, max(max(temp1*mp[i] + temp4, temp1*mp[i]), *max_element(b + 1, b + 1 + n)));
			else
				ans = max(ans,max(temp4, *max_element(b + 1, b + 1 + temp2)));
		}
		cout << ans << endl;
	}
	return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:48:26: error: 'LONG_MIN' was not declared in this scope
   48 |                 ll ans = LONG_MIN;
      |                          ^~~~~~~~
a.cc:17:1: note: 'LONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   16 | #include<assert.h>
  +++ |+#include <climits>
   17 | //#include<Eigen/Dense>
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,inmax=0,inmax2=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+3);
for(long i=0;i<N;i++){
cin>>P.at(i+1);
}
for(long i=0;i<N;i++){
cin>>C.at(i+1);
}
long next=0;
for(long i=1;i<N+1;i++){
  value=0;
    for(long k=0;k<N;k++){
        sums.at(k)=0;
    }
    next=i;
    sum=0;
    inmax=0;
  	j=0;
    do{      
        j++;
       sum+=C.at(P.at(next));
        sums.at(j)=sum;
       next=P.at(next);

    }while(next!=i);

    if(j<=K){        
        if(sum>0){
            inmax=0;
            inmax2=sums.at(a);
            for(long a=0;a<=K%j;a++){
                if(inmax<sums.at(a)){
                inmax=sums.at(a);
                }
            }
          　for(long a=1;a<=j;a++){
                if(inmax<sums.at(a)){
                inmax=sums.at(a);
                }
            }
            loops=K/j;
            value=max(loops*sum+inmax,(loops-1)*sum+inmax2);
        }else{
            inmax=sums.at(1);
            for(long a=1;a<=j;a++){
                if(inmax<sums.at(a)){
                inmax=sums.at(a);
                }
            }
            value=inmax;
        }
    }else{
      inmax=sums.at(1);
        for(long a=1;a<=K;a++){
                if(inmax<sums.at(a)){
                inmax=sums.at(a);
                }
            }
      	value=inmax;

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

}

cout<<max<<endl;

}






Compiler output:
a.cc:96:11: error: extended character 　 is not valid in an identifier
   96 |           　for(long a=1;a<=j;a++){
      |           ^
a.cc: In function 'int main()':
a.cc:90:28: error: 'a' was not declared in this scope
   90 |             inmax2=sums.at(a);
      |                            ^
a.cc:96:17: error: expected primary-expression before 'long'
   96 |           　for(long a=1;a<=j;a++){
      |                 ^~~~
a.cc:102:22: error: 'max' cannot be used as a function
  102 |             value=max(loops*sum+inmax,(loops-1)*sum+inmax2);
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits//stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
ll sum, cnt, ans = -1e18, imax,k;
int main() {
    int n;cin >> n >> k; vector<ll>p(n),c(n),s;
    rep(i, n) cin >> p[i], p[i]--;// 0-indexed
    rep(i, n) cin >> c[i];
    rep(i, n) {
        sum = 0;  // vector<ll> sは累積和
        int now = p[i];
        while (i != now) {
            sum += c[now];s.push_back(sum);
            now = p[now];
        }sum += c[i]; s.push_back(sum);
      　// 一周するのにかかる回数がkより大きいときs[0]~s[k-1]までのmax
        if (k <= s.size()) chmax(ans, *max_element(s.begin(), s.begin() + k));
        // 一周するたびに小さくなるので一周目の時のmax
        else if (sum <= 0) chmax(ans, *max_element(ALL(s)));
        else {
           // 一周少なく回ったときを考えるときに注意！！
            ll ans1 = sum * ((k / s.size()) - 1);
            ans1 += *max_element(ALL(s));
            ll ans2 = sum * (k / s.size()),r = k %s.size();
            if (r != 0) {
                // s[0]~s[r-1] または0
                ans2 += max(0LL, *max_element(s.begin(), s.begin() + r));
            }chmax(ans, max(ans1, ans2));
        }s.clear();
    }cout << ans << endl;
}

Compiler output:
a.cc:19:7: error: extended character 　 is not valid in an identifier
   19 |       　// 一周するのにかかる回数がkより大きいときs[0]~s[k-1]までのmax
      |       ^
a.cc: In function 'int main()':
a.cc:19:7: error: '\U00003000' was not declared in this scope
   19 |       　// 一周するのにかかる回数がkより大きいときs[0]~s[k-1]までのmax
      |       ^~
a.cc:22:9: error: 'else' without a previous 'if'
   22 |         else if (sum <= 0) chmax(ans, *max_element(ALL(s)));
      |         ^~~~
Language: C++

#include <iostream>
#include <vector>
#include <climits>

using namespace std;

long long n, k;
vector<int> c, p;

void read_input(){

    cin >> n >> k;
    c.resize(n, 0);
    p.resize(n, 0);
    for(int i=0;i<n;i++){
        cin >> p[i]; p[i]--;
    }

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

void solve_i(int i){

    long long points = 0;
    long long maxi = LLONG_MIN;
    int start = i;
    int t = 0;

    while( i != s and t < k){
        points += c[i];
        i = p[i];
        t++;
        maxi = max(maxi, points);
    }

    if(t ==k){
        return maxi;
    }

    points += c[i];
    maxi = max(maxi, points);
    t += 1

    if(points < 0){
        return maxi;
    }else{
        cycles = k / t;
        remainder = k % t;
        potential = points * cycles;

        if(remainder != 0){
            long long tmp_max = LLONG_MIN;
            long long tmp_points = 0;
            i = start;
            for(int j=0;j<remainder;j++){
                tmp_points += c[i];
                i = p[i];
                tmp_max = max(tmp_max, tmp_points);
            }
            potential += tmp_max;
        }

        return max(maxi, potential);
    }
}


void solve(){
    long long maxi = LLONG_MIN;
    for(int i=0;i<n;i++){
        maxi = max(maxi, solve_i(i));
    }

    cout << maxi << "\n":
}

int main(){
    read_input();
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve_i(int)':
a.cc:31:17: error: 's' was not declared in this scope
   31 |     while( i != s and t < k){
      |                 ^
a.cc:39:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
   39 |         return maxi;
      |                ^~~~
a.cc:44:11: error: expected ';' before 'if'
   44 |     t += 1
      |           ^
      |           ;
   45 | 
   46 |     if(points < 0){
      |     ~~     
a.cc:48:6: error: 'else' without a previous 'if'
   48 |     }else{
      |      ^~~~
a.cc:49:9: error: 'cycles' was not declared in this scope
   49 |         cycles = k / t;
      |         ^~~~~~
a.cc:50:9: error: 'remainder' was not declared in this scope
   50 |         remainder = k % t;
      |         ^~~~~~~~~
a.cc:51:9: error: 'potential' was not declared in this scope
   51 |         potential = points * cycles;
      |         ^~~~~~~~~
a.cc: In function 'void solve()':
a.cc:73:33: error: invalid use of void expression
   73 |         maxi = max(maxi, solve_i(i));
      |                          ~~~~~~~^~~
a.cc:76:25: error: expected ';' before ':' token
   76 |     cout << maxi << "\n":
      |                         ^
      |                         ;
Language: C++

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int is[5005];
  
void solve() {
  int n, k; cin >> n >> k;
  int P[n+5], val[n+5], score[n+5], tot[n+5];
 
  for(int i = 1; i <= n; i++) {
    cin >> P[i];
  }
  
  int ans = -INF;
  for(int i = 1; i <= n; i++) {
    cin >> val[i];
    ans = min(ans, val[i]);
  }

  for(int i = 1; i <= n; i++) {
    int x = P[i], vis[n+5] = {0};
    vis[i] = 1;
    while(vis[x] == 0) {
       vis[x] = 1;
       x = P[x];
    }

    if(x == i) {
      vector <int> cyc;
      int s = val[i];
      cyc.pb(i);
      x = P[i];
      while(x != i) {
         cyc.pb(x);
         s += val[x];
         x = P[x];
      }
      for (auto j : cyc) {
        is[j] = 1;
        score[j] = s;
        tot[j] = sz(cyc);
      }
    }
  }
  
  //int ans = -INF;

  for(int i = 1; i <= n; i++) {
    int x = P[i], t = k, res = 0;
    bool vis[n+5] = {0};
    vis[i] = 1;
    while(vis[x] < 2 && t > 0) {
      t--;
      res += val[x];
      ans = max(ans, res);
      if(is[x]) { 
        int temp = res + (t/tot[x]) * score[x];
        ans = max(ans, temp);
      }
      vis[x]++;
      x = P[x];
    }
  }
  
  cout << ans << '\n';  

}

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {   
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}    

/*

*/

Compiler output:
a.cc: In function 'void solve()':
a.cc:92:12: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   92 |       vis[x]++;
      |       ~~~~~^
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);
		}
	}
	ll ans=-5e18;
	for(int i =1;i<=n;i++){
		ll cnt=k/sz[color[i]];
		int len=k%sz[color[i]];
		ll tmp=0;
		ll foo1=-5e18,foo2=-5e18,ll foo3=-5e18;
		
		for(int u=pes[i],qtd=0;u!=i;u=pes[u],qtd++){
			tmp+=ces[u];
			foo1=max(tmp,foo1);
			if(qtd<len)foo2=max(tmp,foo2);
			if(qtd<k)foo3=max(tmp,foo3);
		}
		tmp+=ces[i];
		foo1=max(tmp,foo1);
		ans=max(foo3,ans);
		tmp=foo2+cnt*points[color[i]];
		if(cnt>0)tmp=max(tmp,foo1+(cnt-1)*points[color[i]]);
		ans=max(ans,max(foo2,tmp));
	}
	cout<<ans;
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:45: error: expected initializer before 'foo3'
   45 |                 ll foo1=-5e18,foo2=-5e18,ll foo3=-5e18;
      |                                             ^~~~
a.cc:51:34: error: 'foo3' was not declared in this scope; did you mean 'foo2'?
   51 |                         if(qtd<k)foo3=max(tmp,foo3);
      |                                  ^~~~
      |                                  foo2
a.cc:55:25: error: 'foo3' was not declared in this scope; did you mean 'foo2'?
   55 |                 ans=max(foo3,ans);
      |                         ^~~~
      |                         foo2
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int N,K,h,M;
    cin >> N >> K;
    bool over = false;
    long long int p[N+1],c[N+1];
    long long int sum,max=-1e15,ans=-1e15,temp;
    map<int,int> round;
    map<int,long long int> cost,valstep;
    set<int> bola;
    queue<int> q;
    for(int i=1;i<=N;i++){
        cin >> p[i];
    }
    for(int i=1;i<=N;i++){
        cin >> c[i];
    }
    for(int i=1;i<=N;i++){
        sum = 0;
        h = i;
        if(bola.count(i)) continue;
        for(int j=0;j<N;j++){//loop for N in case overclock and K when K<N
            h=p[h];
            sum+=c[h];
            q.push(h);
            if(h==i){
                while(!q.empty()){
                    temp = q.front();
                    q.pop();
                    round[temp] = j+1;
                    cost[temp] = sum;
                    bola.insert(temp);
                }
                break;
            }
        }
    }
    for(int i=1;i<=N;i++){
        h = i;
        max=-1e15;
        temp=0;
        if(cost[i]>0){
            sum = floor(K/round[i])*cost[i];
            M = K%round[i];
        }
        else{
            sum = 0;
            M = round[i];
        }
        for(int j=0;j<M;j++){
            h=p[h];
            temp+=c[h];
            //cout << i << " : " << h << " val : " << c[h] <<endl;
            if(temp>max){
                max = temp;
                valstep[i] = max;
                /cout << i << " : " << valstep[i] << " step : " << j+1 <<endl;
            }
        } 
        if(max+sum>ans) ans = max+sum;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:17: error: expected primary-expression before '/' token
   58 |                 /cout << i << " : " << valstep[i] << " step : " << j+1 <<endl;
      |                 ^
Language: C++

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

int main(){
    ll n, k;
    vector<ll> p, c;

    cin >> n >> k;
    p.assign(n+1,0);
    c.assign(n+1,0);
    for(int i=1;i<=n;i++){
        cin >> p[i];
    }
    for(int i=1;i<=n;i++){
        cin >> c[i];
    }

    vector<ll> best(n+1,0);
    for(int i=1;i<=n;i++){
        best[i] = c[p[i]];
    }
    for(int i=1;i<=n;i++){
        vector<ll> d(n+1,0), visited(n+1,0);
        ll cnt = 0, j=i;
        ll answ=0, last=i;
        while(cnt<k && visited[j]==false){
            visited[j] = ++cnt;
            d[j] = answ;
            last = j;
            j = p[j];
            answ+=c[j];
            best[i] = max(best[i],answ);
        }
        
        ll k1 = max(k-cnt,0ll), cycle = visited[last]-visited[j]+1;
        answ += 1ll*(answ-d[j])*1ll*(k1/cycle);
        best[i] = max(best[i],answ);
        k1 = k1%cycle;
        while(k1--){
            j = p[j];
            answ+=c[j];
            best[i] = max(best[i],answ);
        }
    }

    ll resp=best[1];
    for(int i=1;i<=n;i++){
        resp = max(resp,best[i]);
    }
    if(resp<0){
        while(true)
    }
    cout << resp <<"\n";


    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:53:5: error: expected primary-expression before '}' token
   53 |     }
      |     ^
Language: C++

#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.



int main() {
long long N, K, P[5001], C[5001], maxsc = -1000000000000000000, sc, cnt, maxci = -1000000000000000000;

cin >> N >> K;

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

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

int indx;
for (int i = 1; i <= N; ++i)
{
    sc = 0;
    cnt = 0;
    indx = i;
    while(cnt !=K){
        cnt++;
        indx = P[indx];
        sc = sc + C[indx];
        if(sc > maxsc)
            maxsc = sc;
        if(indx == i)
            break;
    }

    // if (cnt <K)
    // {
    //     if (sc >=0)
    //     {
    //         sc = sc * (K/cnt);
    //         int cnte = K%cnt;
    //         indx = i;
    //         if (sc > maxsc)
    //                 maxsc = sc;
    //         for(int i1=0;i1<cnte;i1++)
    //         {
    //             indx = P[indx];
    //             sc = sc + C[indx];
    //             if (sc > maxsc)
    //                 maxsc = sc;
    //         }

    //     }
    // }
    sc=max(0ll,sc*(K/cnt));
    ans=max(ans,sc);
    K%=cnt;
    cnt = 0;
    indx = i;
    while(cnt !=K){
        cnt++;
        indx = P[indx];
        sc = sc + C[indx];
        if(sc > maxsc)
            maxsc = sc;
    }

}

cout << maxsc << endl;
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   61 |     ans=max(ans,sc);
      |     ^~~
      |     abs
Language: C++

#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int dfs(Int k, const vector<Int> &p, const vector<Int> &c, Int i) {
    vector<bool> s(p.size(), false);
    vector<Int> psum;
    psum.push_back(0);
    Int nsum = 0;
    Int ma = c[p[i]];

    while (true) {
        if (s[i]) {
            break;
        }

        s[i] = true;
        i = p[i];
        nsum += c[i];
        psum.emplace_back(nsum);
    }

    Int n = psum.size() - 1;
    Int ret = INT64_MIN;

    for (Int i = 0; i < n; i++) {
        bool flag = false;
        if (1 <= psum.back()) {
            ret = ((k - i) / n) * psum.back();
            flag = true;
        }
        (k - i) %= n;
        if ((k - i) != 0) {
            Int t = INT64_MIN;
            for (Int i = (flag) ? 0 : 1; i <= (k - i); i++) {
                t = max(t, psum[i]);
            }
            if (ret != INT64_MIN) {
                ret += t;
            } else {
                ret = t;
            }
        }
    }

    return max(ma, ret);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    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];
    }

    Int ans = INT64_MIN;
    for (Int i = 0; i < n; i++) {
        ans = max(ans, dfs(k, p, c, i));
    }

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'Int dfs(Int, const std::vector<long int>&, const std::vector<long int>&, Int)':
a.cc:57:12: error: lvalue required as left operand of assignment
   57 |         (k - i) %= n;
      |         ~~~^~~~
Language: C++

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

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> P(n),C(n);
   rep(i,n) cin >> P[i];
   rep(i,n) cin >> C[i];
   rep(i,n) P[i]--;
   ll ans = -1e18;
   rep(si,n){
      int x = si;
      vector<int> s;
      ll tot=0;
      while(1){
         x=P[x];
         s.push_back(C[x])
         tot += C[x]; 
         if(x==si) break;
      }
      int l = s.size();
      ll t = 0;
      rep(i,l){
         t += s[i];
         if (i+1 > k) break;
         ll now = t;
         if (tot > 0){
            ll e = (k-(i+1))/l;
            now += e*tot;
         }
         ans = max(ans,now);
      }
   }
   cout << ans << endl;
   return 0;  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:27: error: expected ';' before 'tot'
   21 |          s.push_back(C[x])
      |                           ^
      |                           ;
   22 |          tot += C[x];
      |          ~~~
Language: C++

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

#define endl '\n'
#define sz(x) ((int)(x.size()))

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

	long long n, k;
	cin >> n >> k;
	long long 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];
	bool seen[n+1];
	long long ans = -1e18;
	for(int i=1; i<=n; i++) {
		int ptr = i;
		vector <long long> v;
		memset(seen, 0, sizeof seen);
		while(!seen[ptr]) {
			seen[ptr] = 1;
			v.push_back(c[ptr]);
			ptr = p[ptr];
		}
		long long tot = 0;
		for(int i=0; i<sz(v); i++) {
			tot += v[i];
			if(i+1 <= k) ans = max(ans, v[i]);
		}
		long long r = max((k / sz(v))-2, 0);
		for(int i=sz(v)*r; i<k; i++) {
			ans = max(ans, r*tot + v[i%sz(v)]);
			if(sz(v)+i+1 <= k) ans = max(ans, tot + v[i%sz(v)]);
		}
	}
	cout << ans << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:34: error: no matching function for call to 'max(long long int, int)'
   32 |                 long long r = max((k / sz(v))-2, 0);
      |                               ~~~^~~~~~~~~~~~~~~~~~
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:32:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   32 |                 long long r = max((k / sz(v))-2, 0);
      |                               ~~~^~~~~~~~~~~~~~~~~~
/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:32:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |                 long long r = max((k / sz(v))-2, 0);
      |                               ~~~^~~~~~~~~~~~~~~~~~
Language: C++

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

const long long INF = 1e18;

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];
	}

	long long ans = -INF;
	for (int i=0;i<N;i++) {

		int ind = P[i];
		vector<int> cycle;
		while (true) {
			cycle.push_back(C[ind]);
			st.insert(ind);
			ind = P[ind];
			if (ind == i) break;
		}
	}
	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:25: error: 'st' was not declared in this scope; did you mean 'std'?
   25 |                         st.insert(ind);
      |                         ^~
      |                         std
Language: C++

from sys import stdin
from math import inf
input=stdin.readline
n,k=map(int,input().split())
arr=[0]+list(map(int,input().split()))
cost=[0]+list(map(int,input().split()))
ma=-inf
for i in range(1,n+1):
    m=1
    cur=arr[i]
    co=cost[cur]
    l=[0,co]
    ma = max(ma, l[-1])
    while(m<k and cur!=i):
        cur=arr[cur]
        co=cost[cur]
        l.append(l[-1]+co)
        m += 1
        ma=max(ma,l[-1])
    if m<=k:
        for j in range(k%m+1):
            ma = max(ma, l[-1] * (k//m) + l[j])
print(ma)
 

Compiler output:
a.cc:1:1: error: 'from' does not name a type
    1 | from sys import stdin
      | ^~~~
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long

int main(void)
{
    ll n, k, max = -10000000000000;
    cin >> n >> k;
    vector<ll>  p(n), c(n);
    for(ll i = 0; i < n; i++) {
        cin >> p.at(i);
        p.at(i)--;
    }
    for(ll i = 0; i < n; i++) {
        cin >> c.at(i);
    }

    vector<vector<ll>>  memo(n, vector<ll>());
    vector<ll>  summ(n, 0);

    for(ll i = 0; i < n; i++) {
        vector<bool>    tootta(n, true);
        ll sum = c.at(i), start = i;
        memo.at(i).push_back(c.at(i));
        while(1) {
            tootta.at(start) = false;
            if(tootta.at(p.at(start)) != 1)
                break;
            sum += c.at(p.at(start));
            memo.at(i).push_back(sum);
            start = p.at(start);
        }
        summ.at(i) = sum;
        if(k % memo.at(i).size()) {
        if(summ.at(i) <= 0) {
            for(ll j = 0; j < (k % memo.at(i).size()); j++) {
                if(memo.at(i).at(j) > max) {
                    max = memo.at(i).at(j);
                }
            }
        } else {
            for(ll j = 0; j < k % memo.at(i).size(); j++) {
                    ll ij = (summ.at(i) * (k / memo.at(i).size()) + memo.at(i).at(j));
                    if(ij > max) {
                    max = ij;
                    }
            }
            for(ll j = 0; j < memo.at(i).size(); j++) {
                    ll ij = summ.at(i) * (k / memo.at(i).size() - 1) +memo.at(i).at(j);
                    if(ij > max) {
                        max = ij;
                    }
            ll ij = summ.at(i) * (k / memo.at(i).size());
            if(ij > max) {
                max = ij;
            }
            }
        }
        } else {
            if(summ.at(i) <= 0)
            for(ll j = 0; j < memo.at(i).size(); j++) {
                if(memo.at(i).at(j) > max) {
                    max = memo.at(i).at(j);
                }
            }

        else {
            for(ll j = 0; j < memo.at(i).size(); j++) {
                    ll ij = summ.at(i) * (k / memo.at(i).size() - 1) +memo.at(i).at(j);
                    if(ij > max) {
                        max = ij;
                    }
            }         
        }
        }
    }
    cout << max;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:16: error: redeclaration of 'long long int ij'
   56 |             ll ij = summ.at(i) * (k / memo.at(i).size());
      |                ^~
a.cc:52:24: note: 'long long int ij' previously declared here
   52 |                     ll ij = summ.at(i) * (k / memo.at(i).size() - 1) +memo.at(i).at(j);
      |                        ^~
Language: C++

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

int main() {
	long long N;
	long long K;
	int gaid;
	long long ank;
	long long ans;
  
	cin >> N >> K;
 	vector<long long> P(N+1);
 	vector<long long> C(N+1);
 	vector<int> kai_count(N+1);
 	vector<long long> kai_1(N+1);
 	vector<long long> kai_max(N+1);
 	vector<long long> kai_max_count(N+1);

	ans=-1e9-10;
	rep3(i,1, N) cin >> P.at(i);
	rep3(i,1, N) cin >> C.at(i);
	rep3(i,1, N) {
 		kai_count.at(i)=0;
 		kai_1.at(i)=0;
 		kai_max.at(i)=-1e9-10;
 		kai_max_count.at(i)=0;
		gaid=P.at(i);
		rep(j, N) {
			kai_count.at(i)++;
			kai_1.at(i)+=C.at(gaid);
			if(kai_max.at(i)<kai_1.at(i)) {
				kai_max.at(i)=kai_1.at(i);
	 			kai_max_count.at(i)=kai_count.at(i);
			}
			if (gaid==i) break;
			gaid=P.at(gaid);
		}
		if ((kai_1.at(i)>0)&&(kai_count.at(i)<=K)) {
			ank=(K-kai_max_count.at(i)+1)/kai_count.at(i);
			if(ans<kai_1.at(i)*ank+kai_max.at(i)) ans=kai_1.at(i)*ank+kai_max.at(i);
		} else {
          if (ans<kai_max.at(i))ans=kai_max.at(i);
        }
	}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:10: error: expected '}' at end of input
   47 |         }
      |          ^
a.cc:7:12: note: to match this '{'
    7 | int main() {
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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 n, k;

int main() {
    cin >> n >> k;
    vector<ll> pvec(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> pvec[i]; pvec[i]--;
    }
    vector<ll> cvec(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> cvec[i];
    }

    vector<bool> check(n, false);
    vector< vector<ll> > tree;
    for(int i = 0; i < n; ++i) {
        if(!check[i]) {
            vector<ll> subtree;
            subtree.emplace_back(cvec[i]);
            check[i] = true;
            int now = pvec[i];
            while(now != i) {
                subtree.emplace_back(cvec[now]);
                check[now] = true;
                now = pvec[now];
            }
            tree.emplace_back(subtree);
        }
    }

    ll ans = -1e18;
    for(auto x : tree) {
        ll xsize = x.size();
        vector<ll> xsum(xsize*2+1, 0);
        vector<ll> xx(xsize*2, 0);
        for(int i = 0; i < xsize; ++i) {
            xx[i] = x[i]; xx[i+xsize] = x[i];
        }
        for(int i = 0; i < xsize*2; ++i) {
            xsum[i+1] += (xsum[i]+xx[i]);
        }

        // いくらか周回してきた
        // 1週目だけ1個少ない
        // 1周あるかの判断
        int ch = k/(xsize-1);
        if(ch != 0) {
            // 1週はできる

        }else {
            // 1週もできない
            ll subsum = -1e18;
            for(int i = 0; i < n; ++i) {
                for(int )
            }
        }
        chmax(ans, sum);
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:64:25: error: expected unqualified-id before ')' token
   64 |                 for(int )
      |                         ^
a.cc:64:24: error: expected ';' before ')' token
   64 |                 for(int )
      |                        ^~
      |                        ;
a.cc:64:25: error: expected primary-expression before ')' token
   64 |                 for(int )
      |                         ^
a.cc:64:24: error: expected ';' before ')' token
   64 |                 for(int )
      |                        ^~
      |                        ;
a.cc:65:13: error: expected primary-expression before '}' token
   65 |             }
      |             ^
a.cc:67:20: error: 'sum' was not declared in this scope; did you mean 'xsum'?
   67 |         chmax(ans, sum);
      |                    ^~~
      |                    xsum
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18+100;
const int MAX = 1e5;

int main() {
    int n, k; cin >> n >> k;
    vint p(n), c(n);
    rep(i,n) {
        int x; cin >> x;
        x--;
        p[i] = x;
    }
    rep(i,n) cin >> c[i];
    vll v(n);
    vint ct(n);
    rep(i,n) {
        for (int j = p[i]; ; j = p[j]) {
            v[i] += c[j];
            ct[i]++;
            if (j == i) break;
        }
    }
    ll ans = -inf_l;
    rep(i,n) {
        ll sum = 0;
        int n_loop, rem;
        if (k % ct[i] == 0) {
            n_loop = k / ct[i] - 1;
            rem = ct[i];
        // } else {
        //     n_loop = k / ct[i];
        //     rem = k % ct[i];
        // }
        if (v[i] > 0 && n_loop > 0) {
            sum += v[i] * n_loop;
            ans = max(ans,sum);
        }
        int cur = i;
        while (rem--) {
            cur = p[cur];
            sum += c[cur];
            ans = max(ans,sum);
        }
    }
    cout << ans << endl;
}

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

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

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

#define INF (int)100000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 998244353


vector <vector <pair <int, int>>> adj;

vector <int> v;
void dfs(int i, int src)
{
    for (auto j:adj[i])
    {
        v.pb(j.S);
        if (j.F != src)
            dfs(j.F, src);
    }
}

int mx_sum(int k)
{
    int n = sz(v);
    if (n==0)
        return -INF;

    if (n>=k)
    {
        int ans = v[0], s = v[0];
        for (int i=1;i<k;++i)
        {
            s += v[i];
            ans = max(ans, s);
        }   
        return ans;
    }
    else
    {
        int s1 = v[0];
        for (int i=1;i<n;++i)
        {
            s1 += v[i];
        }
        if (s1 >=0 )
        {
            s1 = s1*(k/n);
            k %= n;
            int ans = v[0], s = v[0];
            for (int i=1;i<k;++i)
            {
                s += v[i];
                ans = max(ans, s);
            }   
            return ans + s1;
        }
        else
        {
            int ans = v[0], s = v[0];
            for (int i=1;i<n;++i)
            {
                s += v[i];
                ans = max(ans, s);
            }   
            return ans
        }
    }

}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, k;
    cin>>n>>k;

    int a[n+1], b[n+1];
    adj.resize(n+1);
    for (int i=0;i<n;++i)
    {
        cin>>a[i+1];
    }
    for (int i=0;i<n;++i)
    {
        cin>>b[i+1];
    }
    for (int i = 1;i<=n;++i)
    {
        adj[i].pb({a[i], b[a[i]]});
        // debug3(i, a[i], b[a[i]]);
    }

    int ans = -INF;
    for (int i = 1;i<=n;++i)
    {
        v.clear();
        dfs(i, i);
        // debug1(sz(v));
        ans = max(ans, mx_sum(k));
    }

    cout << ans << "\n";



    return 0;
}


Compiler output:
a.cc: In function 'long long int mx_sum(long long int)':
a.cc:81:23: error: expected ';' before '}' token
   81 |             return ans
      |                       ^
      |                       ;
   82 |         }
      |         ~
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 l = k%n;
  ll m = k/n;
  ll ret2 = -1100000000000000000LL;
  rep(i,n) {
    ll tmp = 0LL;
    rep(j,l) {
      tmp += c[v[i+j]];
      ret2 = max(ret2,tmp);
    }
  }
  ret2 += sum*m;
  ll ret3 = sum*(m-1) + ret1;
  ll ret = max(ret3,max(ret1,ret2));
  return ret;
}

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;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,k,p[5005],c[5005],ans=-1e18;
    bool used[5005]={0};
    cin >> n >> k;
    rep(i,0,n-1){
    	cin >> p[i];
    	p[i]--;
    }
    rep(i,0,n-1){
    	cin >> c[i];
    }
    rep(i,0,n-1){
    	if(!used[i]){
    		ll pv=i,np,cyc,mx=-1e18;
    		vcl gm;
    		while(!used[pv]){
    			//cout << pv << endl;
    			used[pv]=true;
    			gm.pb(pv);
    			pv=p[pv];
    		}
    		np=gm.size();
    		ll dp[np+5][np+5]={0};
    		//cout << np << endl;
    		rep(x,0,np-1){
    			rep(y,1,np){
    				dp[x][y]=dp[x][y-1]+c[gm[(x+y)%np]];
    			}
    		}
    		cyc=dp[0][np];
    		//cout << cyc << endl;
    		if(k>np&&cyc<0){
    			rep(x,0,np-1){
    				rep(y,1,min(np,k)){
    					chmax(mx,dp[x][y]);
    				}
    			}
    			chmax(ans,mx);
    		} else {
    			kk km=k;
    			ll s=max(((k-1)/np)-1,0ll);
    			ll ss=s*cyc;
    			km-=s*np;
    			rep(x,0,np-1){
    				rep(y,1,km){
    					if(y<=np) chmax(mx,dp[x][y]);
    					else chmax(mx,dp[x][y-np]+cyc);
    				}
    			}
    			ss+=mx;
    			chmax(ans,ss);
    		}
    	}
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:25: error: 'kk' was not declared in this scope; did you mean 'k'?
   61 |                         kk km=k;
      |                         ^~
      |                         k
a.cc:64:25: error: 'km' was not declared in this scope; did you mean 'gm'?
   64 |                         km-=s*np;
      |                         ^~
      |                         gm
Language: C++

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

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



int main()
{
    ll n,k;
    cin>>n>>k;
    vector<int>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 best=-9223372036854775808;
    for(int i=1;i<=n;i++){
        //start at index i;

        ll score=0;ll tracker=-9223372036854775808;

        ll moves=0;
        int index=i;ll lm=0;
        for(int j=1;j<=k;j++){
            //go to square p[i];
            if(p[index]==i){
                score+=c[i];
                moves=j;
               if(score>tracker){
                tracker=max(tracker,score);
                lm=j;
                }
                break;
            }
            else{
                score+=c[p[index]];
                index=p[index];
                moves=j;
                if(score>tracker){
                tracker=max(tracker,score);
                lm=j;
                }
            }


        }

        ll f=k/moves;ll nn=score;
        score=f*score;
        ll q=k%moves;
        index=i;ll z=score;
        for(int j=0;j<q;j++){
            z+=c[p[index]];
                index=p[index];
                score=max(score,z);
        }
        best=max(best,score);

        best=max(bes,tracker);
       best=max(best,(f-1)*nn+tracker);



    }
    cout<<best;

    return 0;
}


Compiler output:
a.cc:44:14: warning: integer constant is so large that it is unsigned
   44 |     ll best=-9223372036854775808;
      |              ^~~~~~~~~~~~~~~~~~~
a.cc:48:32: warning: integer constant is so large that it is unsigned
   48 |         ll score=0;ll tracker=-9223372036854775808;
      |                                ^~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:87:18: error: 'bes' was not declared in this scope; did you mean 'best'?
   87 |         best=max(bes,tracker);
      |                  ^~~
      |                  best
Language: C++

#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int dfs(Int k, const vector<Int> &p, const vector<Int> &c, Int i) {
    Int ret = 0;
    vector<bool> s(p.size(), false);
    set<Int> s;
    vector<Int> psum;
    psum.push_back(0);
    Int nsum = 0;
    Int ma = -((Int)1 << 62);
    while (0 < k) {
        if (s[i]) {
            break;
        }

        s[i] = true;
        i = p[i];
        k--;
        nsum += c[i];
        psum.emplace_back(nsum);
        ma = max(ma, nsum);
    }

    Int n = psum.size();
    ret = nsum;
    ret += ((k / (n - 1)) * psum.back());
    k %= (n - 1);
    ret += psum[k];

    return max(ma, ret);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    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];
    }

    Int ans = 0;
    for (Int i = 0; i < n; i++) {
        Int tem = 0;

        tem = dfs(k, p, c, i);
        ans = max(ans, tem);
    }

    sort(c.begin(), c.end(), greater<>());
    if (c.front() < 0) {
        ans = c.front();
    }

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'Int dfs(Int, const std::vector<long int>&, const std::vector<long int>&, Int)':
a.cc:33:14: error: conflicting declaration 'std::set<long int> s'
   33 |     set<Int> s;
      |              ^
a.cc:32:18: note: previous declaration as 'std::vector<bool> s'
   32 |     vector<bool> s(p.size(), false);
      |                  ^