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

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let n:usize = read();
    let k:usize = read();
    let mut p:Vec<usize> = (0..n).map(|_| read()).collect();
    let c:Vec<i64> = (0..n).map(|_| read()).collect();
    for i in 0..n{
        p[i] -= 1;
    }
    let mut ans = -1e18 as i64;
    for _i in 0..n{
        let mut x:usize = _i;
        let mut s:Vec<i64> = Vec::new();
        let mut total:i64 = 0;
        while(true){
            x = p[x];
            s.push(c[x]);
            total += c[x];
            if(x == _i) {
                break;
            }
        }
        let mut l:usize = s.len();
        let mut t:i64 = 0;
        for i in 0..l {
            t += s[i];
            if(i + 1 > k){
                break;
            }
            let mut now:i64 = t;
            if(total > 0){
                let mut e:i64 = (k as i64 - i as i64 - 1) / l as i64;
                now += total * e;
            }
            ans = max(ans,now);
        }
    }
    println!("{}",ans);
}

Compiler output:
a.cc:19:29: error: too many decimal points in number
   19 |     let mut p:Vec<usize> = (0..n).map(|_| read()).collect();
      |                             ^~~~
a.cc:20:23: error: too many decimal points in number
   20 |     let c:Vec<i64> = (0..n).map(|_| read()).collect();
      |                       ^~~~
a.cc:21:14: error: too many decimal points in number
   21 |     for i in 0..n{
      |              ^~~~
a.cc:25:15: error: too many decimal points in number
   25 |     for _i in 0..n{
      |               ^~~~
a.cc:39:18: error: too many decimal points in number
   39 |         for i in 0..l {
      |                  ^~~~
a.cc:1:1: error: 'use' does not name a type
    1 | use std::cmp::*;
      | ^~~
a.cc:2:1: error: 'use' does not name a type
    2 | use std::collections::*;
      | ^~~
a.cc:3:1: error: 'use' does not name a type
    3 | use std::io::*;
      | ^~~
a.cc:4:1: error: 'use' does not name a type
    4 | use std::str::FromStr;
      | ^~~
a.cc:5:1: error: 'fn' does not name a type
    5 | fn read<T: FromStr>() -> T {
      | ^~
a.cc:16:1: error: 'fn' does not name a type
   16 | fn main(){
      | ^~
Language: C++

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <iterator>
#define LLONG_MAX     9223372036854775807i64       // maximum signed long long int value
#define LLONG_MIN   (-9223372036854775807i64 - 1)  // minimum signed long long int value
using namespace std;

class Cycle 
{
public:
    vector<long long> node;
    long long sum;
};

int main(void)
{
    
    long long n,K;
    cin >> n >> K;

    vector<long long> p(n);
    vector<long long> c(n);

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

    vector<bool> done(n, false);
    vector<Cycle> cycles;
    for (int i = 0; i < n; i++)
    {
        if (false == done[i])
        {
            Cycle cycle;
            cycle.sum = 0;
            int j = i;
            while (true)
            {
                cycle.node.push_back(j);
                done[j] = true;
                j = p[j];
                cycle.sum += c[j];
                if (j == i) break;
            }
            cycles.push_back(cycle);
        }
    }

    long long ans = LLONG_MIN;

    for (int i = 0; i < cycles.size(); i++)
    {
        long long tmpAns = LLONG_MIN;
        vector<long long> nodes = cycles[i].node;
        long long cycleSize = nodes.size();
        int size;
        long long offset = 0;
        if (cycleSize < K)
        {
            size = K%cycleSize;
            if (cycles[i].sum > 0)
            {
                offset = K / cycleSize * cycles[i].sum;
            }
            else
            {
                offset = 0;
            }
        }
        else
        {
            size = cycleSize;
        }

            
        for (int j = 0; j < cycleSize; j++)
        {
            long long tmpSum = 0;
            long long tmpP = p[nodes[j]];
            for (int k = 0; k < size; k++)
            {
                tmpSum += c[tmpP];
                tmpP = p[tmpP];
                tmpAns = max(tmpAns, tmpSum);
            }
        }

        ans = max(ans, tmpAns + offset);
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:23: error: unable to find numeric literal operator 'operator""i64'
   10 | #define LLONG_MIN   (-9223372036854775807i64 - 1)  // minimum signed long long int value
      |                       ^~~~~~~~~~~~~~~~~~~~~~
a.cc:57:21: note: in expansion of macro 'LLONG_MIN'
   57 |     long long ans = LLONG_MIN;
      |                     ^~~~~~~~~
a.cc:10:23: error: unable to find numeric literal operator 'operator""i64'
   10 | #define LLONG_MIN   (-9223372036854775807i64 - 1)  // minimum signed long long int value
      |                       ^~~~~~~~~~~~~~~~~~~~~~
a.cc:61:28: note: in expansion of macro 'LLONG_MIN'
   61 |         long long tmpAns = LLONG_MIN;
      |                            ^~~~~~~~~
Language: C++

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <iterator>
using namespace std;

class Cycle 
{
public:
    vector<long long> node;
    long long sum;
};

int main(void)
{
    
    long long n,K;
    cin >> n >> K;

    vector<long long> p(n);
    vector<long long> c(n);

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

    vector<bool> done(n, false);
    vector<Cycle> cycles;
    for (int i = 0; i < n; i++)
    {
        if (false == done[i])
        {
            Cycle cycle;
            cycle.sum = 0;
            int j = i;
            while (true)
            {
                cycle.node.push_back(j);
                done[j] = true;
                j = p[j];
                cycle.sum += c[j];
                if (j == i) break;
            }
            cycles.push_back(cycle);
        }
    }

    long long ans = LLONG_MIN;

    for (int i = 0; i < cycles.size(); i++)
    {
        long long tmpAns = LLONG_MIN;
        vector<long long> nodes = cycles[i].node;
        long long cycleSize = nodes.size();
        int size;
        long long offset = 0;
        if (cycleSize < K)
        {
            size = K%cycleSize;
            if (cycles[i].sum > 0)
            {
                offset = K / cycleSize * cycles[i].sum;
            }
            else
            {
                offset = 0;
            }
        }
        else
        {
            size = cycleSize;
        }

            
        for (int j = 0; j < cycleSize; j++)
        {
            long long tmpSum = 0;
            long long tmpP = p[nodes[j]];
            for (int k = 0; k < size; k++)
            {
                tmpSum += c[tmpP];
                tmpP = p[tmpP];
                tmpAns = max(tmpAns, tmpSum);
            }
        }

        ans = max(ans, tmpAns + offset);
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:21: error: 'LLONG_MIN' was not declared in this scope
   55 |     long long ans = LLONG_MIN;
      |                     ^~~~~~~~~
a.cc:9:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    8 | #include <iterator>
  +++ |+#include <climits>
    9 | using namespace std;
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define itn int
#define tin int
#define tni int
typedef long long ll;
int main(){
	int n;
	ll k;
	cin>>n>>k;
	vector<int> p(n);
	for(int i=0;i<n;i++){
		cin>>p[i];
		p[i]--;
	}
	vector<ll> c(n);
	for(itn i=0;i<n;i++){
		cin>>c[i];
	}
	vector<int> visited(n);
	vector<vector<int> > VV;
	for(int i=0;i<n;i++){
		if(!visited){
			vector<int> v={i};
			int pt=p[i];
			while(pt!=i){
				v.push_back(pt);
				pt=p[pt];
			}
			VV.push_back(v);
		}
	}
	ll ans=-1e18;
	for(auto&v:VV){
		itn sz=v.size();
		for(itn r=0l,r<sz;r++){
			vector<ll> s(sz+1);
			for(itn i=0;i<sz;i++)	s[i+1]=s[i]+c[v[i]]
		}
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:20: error: no match for 'operator!' (operand type is 'std::vector<int>')
   23 |                 if(!visited){
      |                    ^~~~~~~~
a.cc:23:20: note: candidate: 'operator!(bool)' (built-in)
a.cc:23:20: note:   no known conversion for argument 1 from 'std::vector<int>' to 'bool'
a.cc:36:31: error: expected ';' before '<' token
   36 |                 for(itn r=0l,r<sz;r++){
      |                               ^
      |                               ;
a.cc:36:31: error: expected primary-expression before '<' token
a.cc:38:68: error: expected ';' before '}' token
   38 |                         for(itn i=0;i<sz;i++)   s[i+1]=s[i]+c[v[i]]
      |                                                                    ^
      |                                                                    ;
   39 |                 }
      |                 ~
Language: C++

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

#define ll long long
const int MAX = 5e3+1;


vector<ll> weight(MAX);

void addEdge(vector<ll> adj[], int u, int v){
    adj[u].push_back(v);
}

ll maximize(vector<ll> adj[], int index, int K){

    if(K <= 0) return 0;

    for (auto i: adj[index])
        return max(weight[i], weight[i] + maximize(adj, i, K-1));
}

int main()
{
    int N, K; cin>>N>>K;

    vector<ll> adj[N+1];
    for (int i=1; i<=N; i++){
        int p; cin>>p;
        addEdge(adj, i, p);
    }

    for (int i=1; i<=N; i++)
        cin>>weight[i];

    ll maximum = INT_MIN;

    int flag = -1;
    int dif = 0;
    if(K>MAX){
        K = MAX;
        /*K = K-M;
        flag = 1;*/
    }

    for (int i=1; i<=N; i++){
        ll res = 0;
        if(K>M){
            res = maximize(adj, i, M) + maximize(adj, i, K-M);
        }else res = maximize(adj, i, K);

        maximum = max(maximum, res);
    }

    if(flag == 1)
        maximum = maximum*2;

    cout<<maximum<<endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:14: error: 'M' was not declared in this scope
   47 |         if(K>M){
      |              ^
a.cc: In function 'long long int maximize(std::vector<long long int>*, int, int)':
a.cc:20:1: warning: control reaches end of non-void function [-Wreturn-type]
   20 | }
      | ^
Language: C++

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  int n, k, tmp = 0; lint ts = 0, ans = -1e18; cin >> n >> k;
  v1i a(n), b(n); v1li v(n+1, 0), u(n, -1e18);
  rep(i, n){cin >> a[i]; a[i]--;} rep(j, n) cin >> b[i];
  rep(i, n){
    ts += b[tmp]; tmp = a[tmp]; v[i+1] = ts;
  }
  rep(i, n) rep(j, n) u[i] = max(u[i], v[(j+i+1) % n] - v[n] + v[j]);
  if(k > n){
    lint c = k / n, d = k % n;
    if(v[n] < 0) rep(i, n) ans = max(ans, u[i]);
    else{
      rep(i, n){
        if(i < d) ans = max(ans, u[i] + c * v[n]);
        else ans = max(ans, u[i] + (c-1) * v[n]);
      }
    }
  }
  else{
    rep(i, k) ans = max(ans, u[i]);
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:54: error: 'i' was not declared in this scope
   33 |   rep(i, n){cin >> a[i]; a[i]--;} rep(j, n) cin >> b[i];
      |                                                      ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int n,k;
int c[5010],p[5010];
long long ans=-1e9;
vector<int> cycle[5010];
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++){
		long long sum=0;
		for(int j=p[i];;j=p[j]){
			cycle[i].push_back(c[j]);
			sum+=c[j];
			if(j==i)
				break;
		}
		int sz=cycle[i].size();
		int round=k/sz;
		long long cnt=-1e9;
		if(sum>0){
			sum=max((round-1)*sum,0);
			for(int j=max((round-1)*sz,0);j<=k;j++){
				sum+=cycle[i][j%sz];
				cnt=max(cnt,sum);
			}
		}else{
			sum=0;
			for(int j=0;j<sz&&j<=k;j++){
				sum+=cycle[i][j%sz];
				cnt=max(cnt,sum);
			}
		}
		ans=max(ans,cnt);
	}
	cout<<ans;
	return 0;
}

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

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,ans=-114514114514114514,vis[5001],p[5001],c[5001];
vector<int> S;
void dfs(int x,int s)
{
	if(vis[x])
		return ;
	vis[x]=1;
	s+=c[x];
	S.push_back(s);
	dfs(p[x],s);
}
signed main()
{
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++)
		scanf("%lld",&c[i]); 
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));	
		dfs(i,0);
		if(S.back()>0&&k>=int(S.size()))
		{
			int q=k/int(S.size());
			if(q>=1)
			{
				int mx=-114514114514114514;
				if(q-1>0)
					mx=0;
				for(int l=0;l<S.size();l++)
					mx=max(mx,S[i]);
				ans=max(ans,(q-1)*S.back()+mx);
			}
			int r=k%int(S.size());
			int mx=0;
			for(int l=0;l<r;i++)
				mx=max(mx,S[i]);
			ans=max(ans,mx+q*S.back());
		}
		else
		{
			for(int j=1;j<=k;j++)
				if(j-1<S.size())
					ans=max(ans,S[j-1]);
				else
					break;
		}
		S.clear();
	} 
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
a.cc:26:35: note: in expansion of macro 'int'
   26 |                 if(S.back()>0&&k>=int(S.size()))
      |                                   ^~~
a.cc:26:35: error: expected ')' before 'long'
   26 |                 if(S.back()>0&&k>=int(S.size()))
      |                   ~               ^
      |                                   )
a.cc:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
a.cc:28:33: note: in expansion of macro 'int'
   28 |                         int q=k/int(S.size());
      |                                 ^~~
a.cc:2:13: error: expected primary-expression before 'long'
    2 | #define int long long
      |             ^~~~
a.cc:38:33: note: in expansion of macro 'int'
   38 |                         int r=k%int(S.size());
      |                                 ^~~
Language: C++

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

int main() {
  int64_t N,K,ans=-1*INF; cin>>N>>K;
  vector<int64_t> P(N);
  rep(i,N){
    cin>>P.at(i);
    P.at(i)--;
  }
  vector<int64_t> C(N);
  rep(i,N) cin>>C.at(i);
  
  rep(i,N){
    vector<bool> seen(N,true);
    vector<int64_t> T;
    int64_t k=i,c=0,sum=0,MAX=-1*INF,NMAX=0,MAX2=-1*INF;
    
    while(seen.at(k)){
      seen.at(k)=false;
      T.push_back(C.at(k));
      if(c>0) T.at(c)+=T,at(c-1);
      if(T.at(c)>MAX){
        MAX=T.at(c);
        NMAX=c+1;
      }
      sum+=C.at(k);
      k=P.at(k);
      c++; 
    }
    
    int64_t t=T.size(),r=K/t,q=K%t;
    if(q<NMAX){
      rep(i,q) MAX2=max(MAX2,T.at(i));
      auto temp=max(MAX,max(MAX+sum*(r-1),MAX2+sum*r));
      if(K>=NMAX)ans=max(ans,temp);
      else ans=max(ans,MAX2);
    }
    else ans=max(ans,max(MAX,MAX+sum*r));
  }
  cout<<ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:22: error: no match for 'operator+=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'} and 'std::vector<long int>')
   24 |       if(c>0) T.at(c)+=T,at(c-1);
      |               ~~~~~~~^~~
a.cc:24:26: error: 'at' was not declared in this scope
   24 |       if(c>0) T.at(c)+=T,at(c-1);
      |                          ^~
Language: C++

#include <iostream>
#include<vector>
#include <cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
struct squar{
    ll score;
    int nexpos;
}squars[5005];
int vis [5005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int N,K;
    cin>>N>>K;
    ll max_ =-1e9-5;
    for(int i =1;i<=N;i++)
    {
        cin>>squars[i].nexpos;
    }
    for(int i =1;i<=N;i++)
    {
        cin>>squars[i].score;
        if(squars[i].score>max_)
        {
            max_=squars[i].score;
        }
    }
    
    for(int i =1;i<=N;i++)
    {
        int index_=i;
        ll res =0;
        int cnt=0;
        memset(vis, 0, sizeof(vis));
        while (vis[index_]!=1&&cnt<=K) {
            res+=squars[index_].score;
            max_=max(max_,res);
            vis[index_]=1;
            index_=squars[index_].nexpos;
            cnt++;//cnt为一个环的周期
        }
        if(cnt<K)
        {
            int shang = K/cnt-1;
            int yv = K%cnt;
            if(res>0)
            {
                ll temp = res*shang;
                res+=temp;
                max_=max(max_,res);
                if(yv!=0)
                {
                    ll s=0;
                    int jishu=0;
                    int index_2=i;
                    while (jishu<yv) {
                        s+=squars[index_2].score;
                        max_=max(max_,res+s);
                        index_2=squars[index_2].nexpos;
                        jishu++;
                    }
                }
            }
            else{
                if(shang!=0)
                {
                    ll s=0;
                    int jishu=0;
                    int index_2=i;
                    while (jishu<cnt) {
                        s+=squars[index_2].score;
                        max_=max(max_,res+s);
                        index_2=squars[index_2].nexpos;
                        jishu++;
                    }
                }
                    else
                    {
                        ll s=0;
                        int jishu=0;
                        int index_2=i;
                        while (jishu<yv) {
                            s+=squars[index_2].score;
                            max_=max(max_,res+s);
                            index_2=squars[index_2].nexpos;
                            jishu++;
                        }
                        
                    }
                    
                }
                
            }
            cout<<max_;
            
            
        }


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

#include <bits/stdc++.h>

using namespace std;
#define ll long long

const int N=1e6+100;
const int inf=0x3f3f3f3f;


ll p[N],c[N];

ll vis[6000],g[6000];
ll n,k,step;
void A(int s)
{
     while(1){
        if(vis[s]) return ;
        step++;
        g[step]=g[step-1]+c[p[s]];
        vis[s]=1;
        s=p[s];
     }
}
void solve()
{

   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=-1e18;
   for(int i=1;i<=n;i++){
       ll kk=k;
       memset(vis,0,sizeof vis);
       for(int i=1;i<=n;i++) g[i]=-1e18;
       step=0;
       A(i);
       ll ma=g[step];
       for(int i=2;i<=step;i++){
          g[i]=max(g[i],g[i-1]);
       }
       ll ty=kk/step;
       if(kk%step==0) ty--;
       if(ma>0)
       ans=max(ans,g[kk%step]+ma*ty));
       else {
        ans=max(ans,g[kk%step]);
       }
   }
    cout<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:47:37: error: expected ';' before ')' token
   47 |        ans=max(ans,g[kk%step]+ma*ty));
      |                                     ^
      |                                     ;
Language: Java


import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here

        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        long K = scan.nextLong();
        int P[]=new int[N];
        long C[]=new long[N];
        int kai[]=new int [N];
        long ten[]=new long[N];

        for(int i=0;i<N;i++){P[i]=scan.nextInt();}
        for(int i=0;i<N;i++){C[i]=scan.nextLong();}

        long m[]=new long[N];
        long le[]=new long[N];

        for(int i=0;i<N;i++){int j=P[i]-1;
            kai[i]=1;
            ten[i]=C[j];
            m[i]=C[j];
            le[i]=1;
            while(i!=j) {
                kai[i]++;
                j = P[j] - 1;
                ten[i] = ten[i] + C[j];
                if (m[i] < ten[i]) {
                    m[i] = ten[i];
                    le[i] = kai[i];
                }

            }

            }
long M[]=new long[N];
            for(int i=0;i<N;i++){
                if(ten[i]>0){
                M[i]=ten[i]*(long)((K-le[i])/kai[i])+m[i];}
                else if (K>le[i]){M[i]=m[i];}
                else{int y=i;
                long ten2[]=new long [N];                    for(int j=0;j<K;j++){
                        y = P[y] - 1;
                         ten2[i]= ten2[i] + C[y];
                        if (M[i] < ten2[i]) {
                            M[i] = ten2[i];
                        }
                }}
            }


Compiler output:
Main.java:54: error: reached end of file while parsing
            }
             ^
1 error
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include<sstream>

using namespace std;
#define ll long long
#define mod 1000000007

ll sum1(vector<ll> &v) {
    ll s = 0;
    for (ll i:v) {
        s += i;
    }
    return s;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n), c(n);
    for (ll &i : v) {
        cin >> i;
        i--;
    }
    for (ll &i : c) {
        cin >> i;
    }

    vector<vector<ll>> t(n);
    for (ll i = 0; i < n; i++) {
        ll cu = i;
        while (true) {
            t[i].push_back(c[v[cu]]);
            cu = v[cu];
            if (cu == i) break;
        }
    }

    ll ma = INT_MIN;
    for (ll i = 0; i < n; i++) {
        vector<ll> &f = t[i];
        ll su = sum1(f);
        ll cu = 0;
        for (ll j = 0; j < f.size() && j < k; j++) {
            cu += f[j];
            ll l_ans1 = cu;
            ll l_ans2 = INT_MIN;
            if (k % f.size() >= j + 1) {
                l_ans2 = su * (k / f.size()) + cu;
            }
            ll l_ans = max(l_ans1, l_ans2);
            ma = max(ma, l_ans);
        }
    }
    cout << ma << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:13: error: 'INT_MIN' was not declared in this scope
   45 |     ll ma = INT_MIN;
      |             ^~~~~~~
a.cc:10:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    9 | #include<sstream>
  +++ |+#include <climits>
   10 |
Language: C++

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct squar{
    ll score;
    int nexpos;
}squars[5005];
int vis [5005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int N,K;
    cin>>N>>K;
    ll max_ =-1e9-5;
    for(int i =1;i<=N;i++)
    {
        cin>>squars[i].nexpos;
    }
    for(int i =1;i<=N;i++)
    {
        cin>>squars[i].score;
        if(squars[i].score>max_)
        {
            max_=squars[i].score;
        }
    }
    
    for(int i =1;i<=N;i++)
    {
        int index_=i;
        ll res =0;
        int cnt=0;
        memset(vis, 0, sizeof(vis));
        if(vis[i]!=1)
        {
            while (vis[index_]!=1&&cnt<=K) {
                res+=squars[index_].score;
                max_=max(max_,res);
                vis[index_]=1;
                index_=squars[index_].nexpos;
                cnt++;
            }
            if(cnt<K)
            {
                int shang=K/cnt-1;
                int yv = K%cnt;
                if(shang!=0)
                {
                    if(res>0)
                        max_=max(max_,res+shang*res);
                    else{
                        int jishu=0;
                        ll he=0;
                        int index_2=i;
                        while (jishu<cnt) {
                            he+=squars[index_2].score;
                            max_=max(max_,res+he);
                            index_2=squars[index_2].nexpos;
                            jishu++;
                        }
                    }
                }
                else
                {
                    int jishu=0;
                    int he=0;
                    int index_2=i;
                    while (jishu<yv) {
                        he+=squars[index_2].score;
                        max_=max(max_,res+he);
                        index_2=squars[index_2].nexpos;
                        jishu++;
                    }
                }
                
            }
        }
        
    }
    cout<<max_;
    
    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:9: error: 'memset' was not declared in this scope
   36 |         memset(vis, 0, sizeof(vis));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include<algorithm>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,k;
    cin >> n>> k;
    vector<int> p(n),c(n);
    rep(i,n){cin >> p[i];p[i]--;}
    rep(i,n){cin >> c[i];}
    mat score(N, vec(0));
    vec num(n);
    ll res=-INF;
    rep(i,n){
        num[i]++;
        ll temp=c[p[i]];
        ll now=p[i];
        score[i].push_back(temp);
        while(now!=i){
            now=p[now];
            temp+=c[now];
            num[i]++;
            score[i].push_back(temp);
        }
        if(score[i][num[i]] > 0){
            ll roop_num = k / num[i] - 1;
            if(roop_num >= 0){
                temp = score[i][num[i]] * roop_num;
                temp += *max_element(ALL(score[i]));
                if(res<temp){
                    res=temp;
                }
            }
            ++roop_num;
            temp = score[i][num[i]] * roop_num;
            temp += *max_element(score[i].begin(), score[i].begin() + (K % num[i]) + 1);
            if(res<temp){
                res=temp;
            }
        }else{
            if(res<*max_element(score[i].begin() + 1, score[i].end())){
                res=*max_element(score[i].begin() + 1, score[i].end());
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:15: error: 'N' was not declared in this scope
   39 |     mat score(N, vec(0));
      |               ^
a.cc:64:72: error: 'K' was not declared in this scope
   64 |             temp += *max_element(score[i].begin(), score[i].begin() + (K % num[i]) + 1);
      |                                                                        ^
Language: C++

#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

//最大公約数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

//素数判定(True/Falseを返却)
int IsPrime_tf(ll num){
    if (num < 2) return false; //0、1は素数でない
    else if (num == 2) return true; //2は素数
    else if (num%2==0) return false; // 偶数はあらかじめ除く
    for (ll i = 3; i*i <= num; i += 2){ //チェックは2～√nで十分
        if (num % i == 0) return false; //素数でない
    }
    return true; //素数である
}

//素数判定(割れる値を返却)
ll IsPrime_value(ll num){
    if (num < 2) return -1; //0、1は素数でない
    else if (num == 2) return 2; //2は素数
    for (ll i = 2; i*i <= num; i += 1){ //チェックは2～√nで十分
        if (num % i == 0) return i; //素数でない
    }
    return num; //素数である
}

int main(){
   ll n, k;
   cin >> n >> k;
   vector<ll> 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){ //1周期の値の合計が正
            ll e = (k-(i+1))/l; //l個で1周なので(k-i-1)/l周できる
            now += tot*e;
          }
          ans = max(ans, now);
      }
   }
   cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:7: error: expected ',' or ';' before 'll'
   74 |       ll t = 0;
      |       ^~
a.cc:76:11: error: 't' was not declared in this scope
   76 |           t += s[i];
      |           ^
Language: C++

#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

//最大公約数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

//素数判定(True/Falseを返却)
int IsPrime_tf(ll num){
    if (num < 2) return false; //0、1は素数でない
    else if (num == 2) return true; //2は素数
    else if (num%2==0) return false; // 偶数はあらかじめ除く
    for (ll i = 3; i*i <= num; i += 2){ //チェックは2～√nで十分
        if (num % i == 0) return false; //素数でない
    }
    return true; //素数である
}

//素数判定(割れる値を返却)
ll IsPrime_value(ll num){
    if (num < 2) return -1; //0、1は素数でない
    else if (num == 2) return 2; //2は素数
    for (ll i = 2; i*i <= num; i += 1){ //チェックは2～√nで十分
        if (num % i == 0) return i; //素数でない
    }
    return num; //素数である
}

int main(){
   ll n, k;
   cin >> n >> k;
   vector<ll> 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){ //1周期の値の合計が正
            ll e = (k-(i+1)/l; //l個で1周なので(k-i-1)/l周できる
            now += tot*e;
          }
          ans = max(ans, now);
      }
   }
   cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:7: error: expected ',' or ';' before 'll'
   74 |       ll t = 0;
      |       ^~
a.cc:76:11: error: 't' was not declared in this scope
   76 |           t += s[i];
      |           ^
a.cc:78:18: error: expected initializer before '+=' token
   78 |           ll now += t;
      |                  ^~
a.cc:80:30: error: expected ')' before ';' token
   80 |             ll e = (k-(i+1)/l; //l個で1周なので(k-i-1)/l周できる
      |                    ~         ^
      |                              )
a.cc:81:13: error: 'now' was not declared in this scope; did you mean 'pow'?
   81 |             now += tot*e;
      |             ^~~
      |             pow
a.cc:83:26: error: 'now' was not declared in this scope; did you mean 'pow'?
   83 |           ans = max(ans, now);
      |                          ^~~
      |                          pow
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

unsigned main(){
	ll n,k; cin>>n>>k;
	vl p(n),c(n);
	rep(i,0,n)cin>>p[i],p[i]--;
	rep(i,0,n)cin>>c[i];

	ll ans=-1e18;

	rep(i,0,n){
		ll x=i,tot=0;
		vl vec(0);
		while(1){
			vec.push_back(c[x]);
			tot += c[x];
			x=p[x];
			if(x==i)break;
		}
		ll l=vec.size();
		ll now=0;
		rep(i,0,l){
			if(k<=i)break;
			now+=vec[i];
			ll sco=0;
			if(tot>0)sco=((k-i-1)/l)*tot;
			chmax(ans,now+sco);
		}
	}
	cout<<ans<<endl;


	return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

long long int main(){
	ll n,k; cin>>n>>k;
	vl p(n),c(n);
	rep(i,0,n)cin>>p[i],p[i]--;
	rep(i,0,n)cin>>c[i];

	ll ans=-1e18;

	rep(i,0,n){
		ll x=i,tot=0;
		vl vec(0);
		while(1){
			vec.push_back(c[x]);
			tot += c[x];
			x=p[x];
			if(x==i)break;
		}
		ll l=vec.size();
		ll now=0;
		rep(i,0,l){
			if(k<=i)break;
			now+=vec[i];
			ll sco=0;
			if(tot>0)sco=((k-i-1)/l)*tot;
			chmax(ans,now+sco);
		}
	}
	cout<<ans<<endl;


	return 0;
}


Compiler output:
a.cc:17:11: error: '::main' must return 'int'
   17 | long long int main(){
      |           ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

void main(){
	ll n,k; cin>>n>>k;
	vl p(n),c(n);
	rep(i,0,n)cin>>p[i],p[i]--;
	rep(i,0,n)cin>>c[i];

	ll ans=-1e18;

	rep(i,0,n){
		ll x=i,tot=0;
		vl vec(0);
		while(1){
			vec.push_back(c[x]);
			tot += c[x];
			x=p[x];
			if(x==i)break;
		}
		ll l=vec.size();
		ll now=0;
		rep(i,0,l){
			if(k<=i)break;
			now+=vec[i];
			ll sco=0;
			if(tot>0)sco=((k-i-1)/l)*tot;
			chmax(ans,now+sco);
		}
	}
	cout<<ans<<endl;


	return 0;
}


Compiler output:
a.cc:17:1: error: '::main' must return 'int'
   17 | void main(){
      | ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

void main(){
	ll n,k; cin>>n>>k;
	vl p(n),c(n);
	rep(i,0,n)cin>>p[i],p[i]--;
	rep(i,0,n)cin>>c[i];

	ll ans=-1e18;

	rep(i,0,n){
		ll x=i,tot=0;
		vl vec(0);
		while(1){
			vec.push_back(c[x]);
			tot += c[x];
			x=p[x];
			if(x==i)break;
		}
		ll l=vec.size();
		ll now=0;
		rep(i,0,l){
			if(k<=i)break;
			now+=vec[i];
			ll sco=0;
			if(tot>0)sco=((k-i-1)/l)*tot;
			chmax(ans,now+sco);
		}
	}
	cout<<ans<<endl;


	return;
}


Compiler output:
a.cc:17:1: error: '::main' must return 'int'
   17 | void main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:47:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
   47 |         return;
      |         ^~~~~~
Language: C++

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,ans,c[5001],p[5001];
signed main()
{
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&c[i]);
		ans=max(ans,c[i]);
	}
	for(int i=1;i<=n;i++)
	{
		int sum=0,dis=0,j=i;
		do
		{
			sum+=c[j];
			j=p[j];
			dis++;
		}while(j!=i);
		int r=(k>=2*dis)?2*dis+k%dis:k;
		int base=((k-r)/dis)*max(sum,0);
		int add=-1e9;
		sum=0;
		for(int l=1;l<=r;l++)
		{
			sum+=c[j];
			j=p[j];
			add=max(add,sum);
		}
		ans=max(ans,base+add);
	}
	cout<<ans;
	return 0;
}

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

#include<bits/stdc++.h>
using namespace std;
long long n,k;
long long p[10005],c[10005];
long long sum[10005];
const long long inf=1LL << 62LL 
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	long long maxnn=-inf;
	for(int i=1;i<=n;i++){
		cin>>c[i]; 
		maxnn=max(maxnn,c[i]);
	}
	long long now;
	long long msum=0;
	for(int i=1;i<=n;i++){
		long long sum=0;
		now=p[i];
		long long lp=1;
		long long start=i;
		for(int j=1;j<=n;j++){
			if(now==start)break;
			now=p[now];
			lp++;
		}
		now=i;
		long long summ=0;
		for(int j=1;j<=lp;j++){
			summ=summ+c[now];
			now=p[now];
		}
		now=i;
		for(int j=1;j<=lp;j++){
			sum+=c[now];
			msum=max(msum,max(sum,sum+(k-j)/lp*summ));
			now=p[now];
		}
	}
	if(maxnn<=0){
		cout<<maxnn;
		return 0;
	}
	cout<<msum;
	return 0;
} 


Compiler output:
a.cc:7:1: error: expected ',' or ';' before 'int'
    7 | int main(){
      | ^~~
Language: C

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

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll n, k;
    ll ans = -INF;
    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]--;

    rep(si, n) {
        int          x   = si; // スタート地点
        ll           tot = 0; // 繰り返し単位の合計
        vector <int> s; // 繰り返し単位のポイントの列
        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; }//ループを1周もできない場合打ち切り
            ll now = t;
            if (tot > 0) {//繰り返し単位の合計が正なら足せるだけ足しちゃう
                ll kurikaeshi = (k - (i + 1)) / l;
                now += kurikaeshi * tot;
            }
            ans = max(ans, now);
        }
    }

    cout << ans << endl;


    return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include "bits/stdc++.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long p[5010],c[5010];
long long mx=-1e18;
long long a[5010][5010];
long long mx1[5010];
long long make[5010];
set<int> s;
void dfs(int beg,int x,int num,long long sum){
	if(num>0){
		if(s.find(x)!=s.end()){
			return ;
		}
		s.insert(x);
		mx1[beg]=max(mx1[beg],sum);
		a[beg][num]=sum;
		make[beg]=sum;
	}
	dfs(beg,p[x],num+1,sum+c[p[x]]);
}
int main(){
	for(int i=1;i<=5000;i++){
		mx1[i]=-1e18;
	}
	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++){
		s.clear();
		s.insert(i);
		dfs(i,i,0,0);
		mx=max(mx,mx1[i]);
		if(mx1[i]<0)continue;
		if(make[i]<0){
			for(int j=1;j<=s.size();j++){
				mx=max(mx,make[i]+a[i][j]);1 0 -2
			}
			continue;
		}
		else{
			mx=max(mx,k/(long long)s.size()*mx1[i]);
			int tmp=k%s.size();
			for(int j=1;j<=tmp;j++){
				mx=max(mx,k/(long long)s.size()*make[i]+a[i][j]);
			}
		}
	}
	cout<<mx<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:61: error: expected ';' before numeric constant
   42 |                                 mx=max(mx,make[i]+a[i][j]);1 0 -2
      |                                                             ^~
      |                                                             ;