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

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main(void) {
	int n = 0, m = 0;
	cin >> n >> m;
	vector<int> p(n);
	for (int i = 0; i < n; i++)cin >> p[i];
	vector<int> c(n);
	for (int i = 0; i < n; i++)cin >> c[i];
	vector<vector<long long int>> table(n);
	long long int max = LLONG_MIN, maxi = 0, maxk = 0;
	for (int i = 0; i < n; i++) {
		int now = p[i]-1;
		for (int k = 0; k < n; k++) {
			if (k != 0)table[i].push_back(table[i][k - 1] + c[now]);
			else table[i].push_back(c[now]);
			if ((max < table[i][k])&&(k<m)) {
				max = table[i][k];
				maxi = i;
				maxk = k;
			}
			now = p[now]-1;
		}
	}
	if (m <= n||(max<=0))cout << max;
	else {
		long long int maxloop = 0;
		vector<int> maxtable;
		for (int i = 0; i < n; i++) {
			if (maxloop < table[i][n - 1]) {
				maxloop = table[i][n - 1];
				maxtable.clear();
				maxtable.push_back(i);
			}
			else if (maxloop == table[i][n - 1])maxtable.push_back(i);
		}
		long long int last = m % n;
		max = 0;
		for (int i = 0; i < maxtable.size(); i++) {
			int now = p[maxtable[i]] - 1;
			for (int k = 0; k < last; k++) {
				if ((max < table[maxtable[i]][k]) && (k<m)) {
					max = table[maxtable[i]][k];
					maxi = i;
				}
				now = p[now] - 1;
			}
		}
		cout << max + table[maxtable[maxi]][n - 1] * (m / n);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:29: error: 'LLONG_MIN' was not declared in this scope
   15 |         long long int max = LLONG_MIN, maxi = 0, maxk = 0;
      |                             ^~~~~~~~~
a.cc:5:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include<cmath>
  +++ |+#include <climits>
    5 | using namespace std;
a.cc:23:33: error: 'maxi' was not declared in this scope; did you mean 'max'?
   23 |                                 maxi = i;
      |                                 ^~~~
      |                                 max
a.cc:24:33: error: 'maxk' was not declared in this scope; did you mean 'max'?
   24 |                                 maxk = k;
      |                                 ^~~~
      |                                 max
a.cc:48:41: error: 'maxi' was not declared in this scope; did you mean 'max'?
   48 |                                         maxi = i;
      |                                         ^~~~
      |                                         max
a.cc:53:46: error: 'maxi' was not declared in this scope; did you mean 'max'?
   53 |                 cout << max + table[maxtable[maxi]][n - 1] * (m / n);
      |                                              ^~~~
      |                                              max
Language: C++

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  vector<ll> b(N,-1);
  vector<ll> score(N);
  for (ll &e : A) cin >> e;
  for (ll &e : score) cin >> e;
  vector<vector<ll>> info;
  vector<vector<ll>> parts;
  ll p = 0;
  for (int i = 0; i < N; i++) {
    if (b[i] != -1) continue;
    b[i] = p;
    ll j = A[i];
    ll s = 0:
    vector<ll> v;
    while (j != i) {
      b[j] = p;
      v.push_back(score[j]);
      j = A[j];
      s += score[j];
    }
    parts.push_back(v);
    ll length = v.size();
    ll t = K/length;
    ll q = K%length;
    info.push_back({length,s,t,q});
    p += 1;
  }
  ll ans = 0;
  for (ll i = 0; i < p; i++) {
    vector<ll> v = info[i];
    vector<ll> vp = parts[i];
    ll a;
    vector<ll> vo;
    for (int i = 0; i < v[0]; i++) {
      ll sr = vp[i];
      vo.push_back(sr);
      for (int j = 1; j < v[3]; j++) {
        sr += vp[i+j];
        vo.push_back(sr);
      }
    }
    sort(vo.begin(),vo.end(),greater<ll>());
    a = vo[0];
    if (info[i][1]>0) a += v[1]*v[2];
    if (i == 0) ans = a;
    else ans = max(a,ans);
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:13: error: expected ',' or ';' before ':' token
   20 |     ll s = 0:
      |             ^
a.cc:24:7: error: 'v' was not declared in this scope
   24 |       v.push_back(score[j]);
      |       ^
a.cc:28:21: error: 'v' was not declared in this scope
   28 |     parts.push_back(v);
      |                     ^
Language: C++

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


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

#include<bits/stdc++.h>
using namespace std; 
typedef long long ll; 
#define endl "\n"
#define pb push_back
int main(){
  ll n,k;
  cin>>n>>k; 
  ll a[n],p[n];
  ll ans=INT_MIN;
  for(ll i=0;i<n;i++){
    cin>>p[i];
  }
  ll sum=0;
  for(ll i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  for(ll i=0;i<n;i++){
    ll cn=min(n,k),m=0,j=i,h=k;
    while(cn--){
      m+=a[j];
      j=(p[j]-1);
      ans=max(ans,m);
    }
    ans=max(ans,m);
  }
  ll o=(k-min(k-n))/n;
  while(o--){
    ans=max(ans,(ans+sum));
  }
  cout<<ans; 
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:14: error: no matching function for call to 'min(ll)'
   28 |   ll o=(k-min(k-n))/n;
      |           ~~~^~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
a.cc:28:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   28 |   ll o=(k-min(k-n))/n;
      |           ~~~^~~~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

const ll MOD = 1e9+7;

ll point[5001][5001]={};

void solve(){
  int n, k; cin >> n >> k;
  int tele[n+1];
  int c[n+1];
  map<int,int> mp;
  for(int i = 1; i <= n; ++i) cin >> tele[i];
  for(int i = 1; i <= n; ++i) {
    cin >> c[i];
    mp[i] = c[i];
  }
  for(int i = 1; i <= n; ++i){
    int pre;
    for(int j = 1; j <= n; ++j){
      if(j == 1) {
        point[i][j] = mp[tele[i]];
        pre = tele[i];
      }
      else {
        point[i][j] = point[i][j-1] + mp[tele[pre]];
        pre = p[pre];
      }
    }
  }
  ll sum  = 0;
  rep(i, n) sum += c[i];
  if(sum < 0){
    ll MAX = -1e10;
    if(k <= n){
      for(int i = 1; i <=k; ++i){
        for(int j = 1; j <= k; ++j){
          MAX = max(MAX, point[i][j]);
        }
      }
      cout << MAX << endl;
    } else {
      for(int i = 1; i <=n; ++i){
        for(int j = 1; j <= n; ++j){
          MAX = max(MAX, point[i][j]);
        }
      }
      cout << MAX << endl;
    }
  } else if(sum > 0){
    ll ans = 0;
    ans += sum * k/n;
    k %= n;
    ll ma = -1e10;
    for(int i = 1; i <=k; ++i){
        for(int j = 1; j <= k; ++j){
          ma = max(ma, point[i][j]);
        }
      }
      ans += ma;
      cout << ans << endl;
  }

}

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


Compiler output:
a.cc: In function 'void solve()':
a.cc:31:15: error: 'p' was not declared in this scope
   31 |         pre = p[pre];
      |               ^
Language: C++

//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0, K =0;
    cin(N);cin(K);

    vll P(N);
    REP(i,N) cin(P[i]);
    vll C(N);
    REP(i,N) cin(C[i]);

    ll loc  = 0, ans = 0, ans1=0;

    //本文
    REP(i,N){
        loc  = i;
        ans1 = 0;
        ll k = K;
    while( k > 0){
        loc = P[loc]-1;
        if(C[loc] > 0){
        ans1 += C[loc];
        }
        k --;
    }
    ans = max(ans, ans1);
    }
    if(ans == 0){
        ll ans2 = 10000000;
        REP(i,N){
            ans2 = min(abs(C[i]),ans2);
        }
        ans = -1 * ans2
    }

    //出力
    cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:106:24: error: expected ';' before '}' token
  106 |         ans = -1 * ans2
      |                        ^
      |                        ;
  107 |     }
      |     ~
Language: C++

#include<stdio.h>
#include<math.h>
int main() {

	
	int n;
	long long int k;
	int p[5000];
	long long int c[5000];
	long long int max;
	long long int score;
	int pl;
	long long int a;
	int b;

	

	scanf("%d", &n);
	scanf("%lld", &k);
	for (int i = 0;i < n;i++)
	{
		scanf("%d", &p[i]);
		
	}
	for (int i = 0;i < n;i++)
	{
		scanf("%lld", &c[i]);
	}
	a = k / n;
	b = k % n;

	max = c[0];
	for (int i = 1;i < n;i++)
	{
		if (max < c[i])
			max = c[i];

	}
	for (int j = 0;j < n;j++) {
		score = c[p[j]-1];
		pl = p[j];
		if (max < score)
		{
			max = score;
		}
		#include<stdio.h>
#include<math.h>
int main() {

	
	int n;
	long long int k;
	int p[5000];
	long long int c[5000];
	long long int max;
	long long int score;
	int pl;
	

	scanf("%d", &n);
	scanf("%lld", &k);
	for (int i = 0;i < n;i++)
	{
		scanf("%d", &p[i]);
		
	}
	for (int i = 0;i < n;i++)
	{
		scanf("%lld", &c[i]);
	}
	max = c[0];
	for (int i = 1;i < n;i++)
	{
		if (max < c[i])
			max = c[i];

	}
	for (int j = 0;j < n;j++) {
		score = c[p[j]-1];
		pl = p[j];
		if (max < score)
		{
			max = score;
		}
		if (n > k) {
			for (long long int i = 1;i < k;i++)
			{

				pl = p[pl - 1];

				score = score + c[pl - 1];


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

			}
		}
		else{
			for (long long int i = 1;i < n;i++)
			{
			
				pl = p[pl - 1];

				score = score + c[pl - 1];


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

			}
			if (score < 0)
				continue;
			max *= a;
			for (int i = 0;i < b;i++)
			{

				pl = p[pl - 1];

				score = score + c[pl - 1];


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

			}
		}
	}

	

	
	printf("%lld", max);
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   48 | int main() {
      |         ^~
a.cc:48:9: note: remove parentheses to default-initialize a variable
   48 | int main() {
      |         ^~
      |         --
a.cc:48:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:48:12: error: a function-definition is not allowed here before '{' token
   48 | int main() {
      |            ^
a.cc:142:2: error: expected '}' at end of input
  142 | }
      |  ^
a.cc:39:35: note: to match this '{'
   39 |         for (int j = 0;j < n;j++) {
      |                                   ^
a.cc:142:2: error: expected '}' at end of input
  142 | }
      |  ^
a.cc:3:12: note: to match this '{'
    3 | int main() {
      |            ^
Language: C++

#include <bits/stdc++.h>

using namespace std;
#define int long long

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, K; cin >> N >> K;
    vl P(N); REP(i, N) cin >> P[i], P[i]--;
    vl C(N); REP(i, N) cin >> C[i];
    vl loop(N), sum(N);
    REP(i, N)
    {
        ll count = 0;
        ll score = 0;
        ll j = i;
        while(true)
        {
            score += C[j];
            j = P[j];
            count++;
            if(j == i) break;
        }
        loop[i] = count;
        sum[i] = score;
    }

    ll ans = -INFL;

    REP(i, N)
    {
        if(sum[i] <= 0 || K < loop[i])
        {
            ll j = P[i];
            ll score = C[j];
            ll k = loop[i] - 1;
            chmax(ans, score);
            while(k > 0)
            {
                j = P[j];
                score += C[j];
                k--;
                chmax(ans, score);
            }
        }
        else
        {
            ll j = i;
            ll score = K / loop[i] * sum[i];
            ll k = K % loop[i];
            chmax(ans, score);
            while(k > 0)
            {
                j = P[j];
                score += C[j];
                k--;
                chmax(ans, score);
            }
        }
    }
    cout << ans << endl;
}

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

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
using namespace std;

int64_t f(int64_t X, int64_t K, int64_t D, int64_t a) {
  return abs(2 * a * D - K * D + X);
}

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

  int64_t N, K;

  cin >> N >> K;

  vector<int64_t> P(N);
  vector<int64_t> C(N);
  vector<int64_t> visited(N, 0);

  for (int64_t i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  for (int64_t i = 0; i < N; i++) {
    cin >> C.at(i);
  }

  stack<vector<int64_t>> cs; 

  for (int64_t i = 0; i < N; i++) {
    if (visited.at(i) == 1) {
      continue;
    } else {
      int64_t j = i; 
      if (visited.at(i) == 0) {
        vector<int64_t> cc; 
        while (visited.at(j) == 0) {
          cc.push_back(j); 
          visited.at(j) = 1;
          j = P.at(j);
        }
        cs.push(cc); 
      }
    }
  }
  int64_t m = INT64_MIN; 
  while(!cs.empty()) {
    auto vs = cs.top(); 
    int64_t q = vs.size() % K; 
    int64_t tmp = accumulate(vs.begin(), vs.end(), 0); 

    for (size_t i = 0; i < K - q; i++)
    {
      int64_t sum = accumulate(vs.begin() + i, vs.begin()+i+q), 0)+ tmp * (vs.size() / K) ;
      if (sum > m) {
        m = sum; 
      }
    }
    
  }

cout << m; 
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:53:15: error: 'INT64_MIN' was not declared in this scope
   53 |   int64_t m = INT64_MIN;
      |               ^~~~~~~~~
a.cc:61:31: error: no matching function for call to 'accumulate(__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >, __gnu_cxx::__normal_iterator<long int*, std::vector<long int> >)'
   61 |       int64_t sum = accumulate(vs.begin() + i, vs.begin()+i+q), 0)+ tmp * (vs.size() / K) ;
      |                     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/numeric:62,
                 from a.cc:9:
/usr/include/c++/14/bits/stl_numeric.h:134:5: note: candidate: 'template<class _InputIterator, class _Tp> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp)'
  134 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:134:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_numeric.h:161:5: note: candidate: 'template<class _InputIterator, class _Tp, class _BinaryOperation> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation)'
  161 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:161:5: note:   candidate expects 4 arguments, 2 provided
Language: C++

#include <iostream>
#include<string>
#include<cstdio>
#include<string.h>
#include<vector>
#include<cmath>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=11000;
ll p[N],c[N],k,d[N];
int n;
//vector <vector<int> > a(1,vector<int >(1));

ll f1(int i){
    int e=i;
    ll t=0;
    e=p[e];
    t+=c[e];
    d[1]=t;
    ll dmx=t,dmxi=1;
    bool pd=1;int j=1;
    for(;j<=k;j++){
        if(e==i){
            pd=0;
            ll cshu=k/j;
            t*=cshu;
            if(dmx>t){
                return dmx;
            }
            k=k-j*cshu;
            sort(d+1,d+k+1);
            t+=d[k];
            break;
        }
        e=p[e];
        t+=c[e];
        d[j+1]=t;
        if(dmx<d[j+1]){
            dmx=d[j+1];
            dmxi=j+1;
        }
    }
    if(p){
        if(dmx>t){
                return dmx;
            }
            sort(d+1,d+k+1);
            t=d[k];
    }
    return t;
}
int main ()
{
    //std::ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    for(int i=1;i<=n;i++){
        cin>>c[i];
    }

    ll ret=fl(1);
    for(int i=2;i<=n;i++){
        ll ti;
        ti=f1(i);
        if(ti>ret){
            ret=ti;
        }
    }
    cout<<ret<<endl;
    return 0;
}

/*

*/


Compiler output:
a.cc: In function 'int main()':
a.cc:64:12: error: 'fl' was not declared in this scope; did you mean 'f1'?
   64 |     ll ret=fl(1);
      |            ^~
      |            f1
Language: C++

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

#define INF 1e18
#define EPS 1e-9
#define MOD 1000000007

// for using in pairs
#define F first
#define S second

// Macros
#define all(x) begin(x), end(x)

// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

// Operator overloads.
template<typename T>
ostream& operator<<(ostream &stream, vector<T> v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

#define int long long

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

int iter(int p[], int c[], int i, int k)
{
	int ans = -INF;
	int curr = 0;
	while (k--)
	{
		i = p[i];
		curr += c[i];
		ans = max(ans, curr);
	}
	return ans;
}

pair<int, int> getCycle(int p[], int c[], int i)
{
	int a = p[i];
	int b = p[p[i]];
	while (a != b)
	{
		a = p[a];
		b = p[p[b]];
	}

	a = i;
	while (a != b)
	{
		a = p[a];
		b = p[b];
	}
	int first = a;
	// cout << "first: " << first << "\n";
	if (first != i)
		return make_pair(0, 0);

	b = p[a];

	int sum = c[b];
	int len = 1;
	while (a != b)
	{
		b = p[b];
		sum += c[b];
		len++;
	}

	return make_pair(len, sum);
}
int n;

int iterC(int p[], int c[], int i, int k, pair<int, int> cycleHere[])
{
	int cycleLen = cycleHere[i].F;
	int cycleSum = cycleHere[i].S;

	if (!cycleLen)
	{
		return iter(p, c, i, n);		
	}

	if (cycleSum < 0)
	{
		return iter(p, c, i, n);
	}

	int t = k / cycleLen;
	int ans = t * cycleSum;

	k -= (t * cycleLen);

	int ansRem = 0;
	if (k > 0)
		ansRem = iter(p, c, i, k);

	return max(ans, ans + ansRem);
}

void solve(int tc)
{
	int k;
	cin >> n >> k;

	int p[n];
	int c[n];

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

	// pair<int, int> cycleHere[n]; // cycle len, sum of c[i]s in cycle

	// for (int i = 0; i < n; i++)
	// {
	// 	cycleHere[i] = getCycle(p, c, i);
	// 	// cout << cycleHere[i].F << ": " << cycleHere[i].S << "\n";
	// }

	if (k)
	{
		int ans = -INF;
		for (int i = 0; i < n; i++)
		{
			ans = max(ans, iter(p, c, i, k));
		}
		for (int i = 0; i < n; i++)
			ans = max(ans, c[i]);
		cout << ans << "\n";;
	}else
	{
		int ans = -INF;
		for (int i = 0; i < n; i++)
		{
			ans = max(ans, iterC(p, c, i, k, cycleHere));
		}
		for (int i = 0; i < n; i++)
			ans = max(ans, c[i]);
		cout << ans << "\n";;
	}
}

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


Compiler output:
a.cc: In function 'void solve(long long int)':
a.cc:153:58: error: 'cycleHere' was not declared in this scope
  153 |                         ans = max(ans, iterC(p, c, i, k, cycleHere));
      |                                                          ^~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

const ll MOD = 1e9+7;

ll point[5001][5001]={};

void solve(){
  int n, k; cin >> n >> k;
  int tele[n+1];
  int c[n+1];
  map<int,int> mp;
  for(int i = 1; i <= n; ++i) cin >> tele[i];
  for(int i = 1; i <= n; ++i) {
    cin >> c[i];
    mp[i] = c[i];
  }
  for(int i = 1; i <= n; ++i){
    int pre;
    for(int j = 1; j <= n; ++j){
      if(j == 1) {
        point[i][j] = mp[tele[i]];
        pre = tele[i];
      }
      else {
        point[i][j] = point[i][j-1] + mp[p[pre]];
        pre = p[pre];
      }
    }
  }
  ll sum  = 0;
  rep(i, n) sum += c[i];
  if(sum < 0){
    ll MAX = -1e10;
    if(k <= n){
      for(int i = 1; i <=k; ++i){
        for(int j = 1; j <= k; ++j){
          MAX = max(MAX, point[i][j]);
        }
      }
      cout << MAX << endl;
    } else {
      for(int i = 1; i <=n; ++i){
        for(int j = 1; j <= n; ++j){
          MAX = max(MAX, point[i][j]);
        }
      }
      cout << MAX << endl;
    }
  } else if(sum > 0){
    ll ans = 0;
    ans += sum * k/n;
    k %= n;
    ll ma = -1e10;
    for(int i = 1; i <=k; ++i){
        for(int j = 1; j <= k; ++j){
          ma = max(ma, point[i][j]);
        }
      }
      ans += ma;
      cout << ans << endl;
  }

}

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


Compiler output:
a.cc: In function 'void solve()':
a.cc:30:42: error: 'p' was not declared in this scope
   30 |         point[i][j] = point[i][j-1] + mp[p[pre]];
      |                                          ^
Language: C++

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

int main() {
  int n, k, start, masu;
  int64_t score = 0LL, max_c = 0LL;
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) cin >> p[i];
  vector<int64_t> c(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    if(max_c < c[i]) {
      max_c = c[i];
      start = i;
    }
  }
  for(int i = 1; i < k; i++) {
    if(i == 1) masu = start;
    else masu = p[masu]
    score = max(score, c[masu]);
    
  }
  cout << score;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:24: error: expected ';' before 'score'
   19 |     else masu = p[masu]
      |                        ^
      |                        ;
   20 |     score = max(score, c[masu]);
      |     ~~~~~
Language: Java

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	int 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 res = 0;
	vector<ll> sc(n+1);
	for (int i = 1; i <= n; ++i) {
		int next = p[i], step = k, cnt = 0;
		vector<bool> visit(n+1);
		while (step > 0) {
			sc[i] += c[next];
			++cnt;
			--step;
			if (i == next) {
				step = k % cnt;
				sc[i] *= k / cnt;
			}
			next = p[next];
		}
		res = max(res, sc[i]);
	}
	cout << res;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:3: error: illegal character: '#'
#define ll long long
^
Main.java:8: error: not a statement
	int n, k; cin >> n >> k;
	                   ^
Main.java:9: error: not a statement
	vector<int> p(n + 1), c(n + 1);
	                ^
Main.java:10: error: not a statement
	for (int i = 1; i <= n; ++i) cin >> p[i];
	                                 ^
Main.java:11: error: not a statement
	for (int i = 1; i <= n; ++i) cin >> c[i];
	                                 ^
Main.java:14: error: not a statement
	vector<ll> sc(n+1);
	               ^
Main.java:17: error: not a statement
		vector<bool> visit(n+1);
		                    ^
Main.java:30: error: not a statement
	cout << res;
	     ^
Main.java:7: error: unnamed classes are a preview feature and are disabled by default.
int main() {
^
  (use --enable-preview to enable unnamed classes)
Main.java:9: error: ';' expected
	vector<int> p(n + 1), c(n + 1);
	             ^
Main.java:9: error: ';' expected
	vector<int> p(n + 1), c(n + 1);
	                   ^
Main.java:14: error: ';' expected
	vector<ll> sc(n+1);
	             ^
Main.java:14: error: ';' expected
	vector<ll> sc(n+1);
	                 ^
Main.java:17: error: ';' expected
		vector<bool> visit(n+1);
		                  ^
Main.java:17: error: ';' expected
		vector<bool> visit(n+1);
		                      ^
17 errors
Language: C++

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
const int maxn=5050;
ll a[maxn];
int b[maxn],vis[maxn];
vector<int> v[maxn];

int main()
{
	int n,t;cin>>n>>t;int idx=0;
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		idx++;vis[i]=idx;int j=b[i];
		while(j!=i){
			vis[j]=idx;j=b[j];
		}
	}
	for(int i=1;i<=idx;i++){
		for(int j=1;j<=n;j++) if(vis[j]==i) v[i].push_back(j);
	}
	ll ans=-1e18;
	for(int i=1;i<=idx;i++){
		for(int j=0;j<v[i].size();j++){
			ll sum=0;int len=v[i].size();
			if(len>=t){
				for(int k=j;k<j+t;k++) sum+=a[v[i][k%len]],	ans=max(ans,sum);
				continue;
			} 
			for(int k=j;k<j+len;k++) sum+=a[v[i][k%len]],ans=max(ans,sum);
			ll y=t/len,yu=t%len;
			sum*=y;ll sum1=0;
			for(int k=j;k<j+yu;k++) sum1+=a[v[i][k%len]],ans=max(ans,sum+sum1);
		}
	}
	cout<<ans;
	return 0;	
} 

Compiler output:
a.cc:9:1: error: 'vector' does not name a type
    9 | vector<int> v[maxn];
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:24:53: error: 'v' was not declared in this scope
   24 |                 for(int j=1;j<=n;j++) if(vis[j]==i) v[i].push_back(j);
      |                                                     ^
a.cc:28:31: error: 'v' was not declared in this scope
   28 |                 for(int j=0;j<v[i].size();j++){
      |                               ^
Language: C++

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

Compiler output:
a.cc: In function 'int main()':
a.cc:25:47: error: 'k' was not declared in this scope
   25 |         if(K % p == 0) res0 = max(res0, score[k]);
      |                                               ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
     
  int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> P(N), C(N);
    int ans = 0;
    int key;
    long long score = 0;
    for(int i=0; i<N; i++){
      cin >> P[i]
    }
    for(int i=0; i<N; i++){
      cin >> C[i]
    }
    for(int i=0; i<N; i++){
      key = i;
      for(int j=0; j<K; j++){
        score += C[key];
        key = P[key];
        if(score>ans){
          ans = score;
        }
      }
    }
    cout << ans;
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:12:18: error: expected ';' before '}' token
   12 |       cin >> P[i]
      |                  ^
      |                  ;
   13 |     }
      |     ~             
a.cc:15:18: error: expected ';' before '}' token
   15 |       cin >> C[i]
      |                  ^
      |                  ;
   16 |     }
      |     ~
Language: C++


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1e9+7;



void solve(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    vector<ll> c(n);
    rep(i,n) cin >> p[i];
    rep(i,n) p[i]--;
    rep(i,n) cin >> c[i];
    
    ll ans = 1LL << 60;
    ans *= -1;
    ll ans = -1001001001001;
    rep(i,n){
        
        ll cand = 0;
        int now = i;
        
        int visited[5000] = {};
        visited[now] = 1;
        
        int step = 1;
        while(step <= k){
            now = p[now];
            cand += c[now];
            
            if (visited[now]){
                if (cand <= 0){
                    break;
                } 
                else{
                    int cycn = k/step;
                    cand *= cycn;
                    ans = max(ans,cand);
                    int rem = k%step;
                    for(int ii = 1; ii <= rem; ii++){
                        now = p[now];
                        cand += c[now];
                        ans = max(ans,cand);
                    }
                    break;
                }
            }
            
            visited[now] = 1;
            step++;
            
            ans = max(ans,cand);
        }

    }
    
    
    cout << ans;
}


int main() {
    int T;
    //cin >> T;
    T = 1;
    while (T--) {
        solve();
        cout << endl;
    }
}














Compiler output:
a.cc: In function 'void solve()':
a.cc:62:8: error: redeclaration of 'll ans'
   62 |     ll ans = -1001001001001;
      |        ^~~
a.cc:60:8: note: 'll ans' previously declared here
   60 |     ll ans = 1LL << 60;
      |        ^~~
Language: C++

#include <iostream>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef long long ll;

int main()
{
	int n, k;
	cin >> n >> k;

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

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

	ll max = LLONG_MIN;
	for (int i = 0; i < n; i++)
	{
		int num = i;
		ll sum = 0;

		num = p[num];
		sum += c[num];

		ll sum_max = sum;

		for (int j = 0; j < k - 1; j++)
		{
			num = p[num];
			sum += c[num];
			if (sum_max < sum)
				sum_max = sum;
		}

		if (max < sum_max)
			max = sum_max;
	}

	cout << max << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:18: error: 'LLONG_MIN' was not declared in this scope
   27 |         ll max = LLONG_MIN;
      |                  ^~~~~~~~~
a.cc:8:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    7 | #include <algorithm>
  +++ |+#include <climits>
    8 | using namespace std;
Language: C++

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

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

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

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

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


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

#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long  long
#define INF 1000000000000000000LL
#define pll pair<long long , long long>
const int MAX=5e6+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
int main() 
{
    int n , k;
    cin>>n>>k;
    ll mx=0;
    ll c[n+1];
    int p[n+1];
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<=n;i++)
        cin>>c[i];
    ll ans = c[1];
    int vis[n+1];
    for(int i=1;i<=n;i++){
        ans = max(ans,c[i])
        memset(vis, 0 , sizeof(vis));
        ll cur = 0;
        int t = i;
        vector<ll>now;
        while(vis[t]!=1){
            vis[t]=1;
            cur = cur+c[t];
            now.push_back(cur);
            t=p[t];
        }
        ll mx = now[0];
        for(int j=1;j<min((int)now.size() , k);j++)
            mx =max(now[j] , mx);
        int u = (int)(now.size());
        int rem=k%u;
        u = k/u;
        if(u<=0)
            ans = max(ans, mx);
        else
        {
            mx = now[0];
             for(int j=1;j<now.size();j++)
                mx =max(now[j] , mx);
            ans = max(ans, mx);
            for(int j=0;j<rem;j++)
                ans =max(ans, now[j]+now[(int)(now.size())-1]*(ll)u);
        }

    }
    cout<<ans;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:28: error: expected ';' before 'memset'
   28 |         ans = max(ans,c[i])
      |                            ^
      |                            ;
   29 |         memset(vis, 0 , sizeof(vis));
      |         ~~~~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int p[5005];
long long a[5005];
long long pre[5005]={0};
int maxstep;
void dfs(int u,int step,int start)
{
    maxstep=max(maxstep,step);
    pre[step]=pre[step-1]+a[u];
    if(u==start){
        return ;
    }
    dfs(p[u],step+1,start);
}
int main()
{
    int n,k;
    cin >> n >> k ;
    for(int i=1;i<=n;i++){
        cin >> p[i];
    }
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    long long ans = -INT_MAX ;
    for(int i=1;i<=n;i++){
        maxstep=0;
        dfs(p[i],1,i);
        //cout << maxstep <<endl;
        long long ret = 0 ;
        if(pre[maxstep]<0){
            for(int j=1;j<=min(k,maxstep);j++)
                ans= max(ans,pre[j]);

        }
        else{
            for(int j=0;j<=k%maxstep;j++)
                ans= max(ans,pre[maxstep]*(k/maxstep)+pre[j]);
        }
        //ans = max(ans,+pre[k%maxstep]);
    }
    cout <<ans <<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:22: error: 'INT_MAX' was not declared in this scope
   28 |     long long ans = -INT_MAX ;
      |                      ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <algorithm>
  +++ |+#include <climits>
    4 | using namespace std;
Language: C++

#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll reach=min(n-1,k);
    ll arr[n+1];
    arr[0]=0;
    ll val[n+1];
    val[0]=0;
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    for(int i=1;i<=n;i++)
    cin>>val[i];
    ll sum=0,ans=-10000000000;
    ll count=0;
    ll temp=0;
    for(int i=1;i<=n;i++)
    {
        temp=i;
        sum=0;
        vector<ll>f;
        f.push_back(sum);
        while(true)
        {
            sum=sum+val[temp];
            temp=arr[temp];
            if(sum>ans)
            ans=sum;
            f.push_back(sum);
            if(temp==i)
            break;
        }
        ans=max(ans,sum*(k/(f.size()-1))+f[k%(f.size()-1)]);
    }
    cout<<ans;
    
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:16: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   40 |         ans=max(ans,sum*(k/(f.size()-1))+f[k%(f.size()-1)]);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:40:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   40 |         ans=max(ans,sum*(k/(f.size()-1))+f[k%(f.size()-1)]);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:40:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   40 |         ans=max(ans,sum*(k/(f.size()-1))+f[k%(f.size()-1)]);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  int N;
  cin >> N;
  ll K;
  cin >> K;
  vector<bool>vis(N + 1, false);
  vector<int>P(N + 1);
  for (int i = 1; i <= N; i ++) cin >> P[i];
  vector<ll>C(N + 1);
  for (int i = 1; i <= N; i ++) cin >> C[i];
  vector<ll>ans(N + 1);
  vector<ll>cnow(N * 2 + 3);
  ll answer = -1e18 - 1;
  for (int i = 1; i <= N; i ++) {
    if (vis[i]) continue;
    ans[0] = 0;
    now[0] = 0;
    int si = 0;
    ll ma = 0;
    int fl = P[i];
    while (fl != i) {
      si ++;
      now[si] = now[si - 1] + C[fl];
      ans[si] = max(ma, now[si]);
      ma = max(ma, now[si]);
      fl = P[fl];
      vis[fl] = true;
      cnow[si - 1] = now[si];
    }
    si ++;
    now[si] = now[si - 1] + C[fl];
    ans[si] = max(ma, now[si]);
    ma = max(ma, now[si]);
    vis[fl] = true;
    ll ret = 0;
    ll sl = (ll) si;
    if (now[si] > 0) {
      ret = ((K - 1) / sl) * now[si];
    }
    int k = (int)K % sl;
    if (k == 0) k += si;
    for (int i = 0; i < si; i ++) {
      cnow[i + si] = cnow[i];
    }
    if (ma > 0) {
      ll mim = 0;
      ll mam = 1e18 + 3;
      while (mim != mam) {
        ll mu = (mim + mam) / 2;
        ll l = 0;
        ll r = 0;
        ll pk = 0;
        while (r >= l) {
          while (
  /*ans[0] = 0;
  int si = 0;
  int fl = P[1];
  ll ma = 0;
  ll now = 0;
  while (fl != 1) {
    now = now + C[fl];
    si ++;
    ans[si] = max(ma, now);
    ma = max(ma, now);
    fl = P[fl];
  }
  si ++;
  now = now + C[fl];
  ans[si] = max(ma, now);
  ll sl = (ll)si;
  if (now <= 0) {
    K = min(sl, K);
    cout << ans[(int)K] << endl;
    return 0;
  }
  ll ret = ((K - 1) / sl) * now;
  int mo = (int)K % sl;
  if (mo == 0) mo += si;
  cout << ret + ans[mo] << endl;*/
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:5: error: 'now' was not declared in this scope; did you mean 'cnow'?
   20 |     now[0] = 0;
      |     ^~~
      |     cnow
a.cc:83:1: error: expected primary-expression before '}' token
   83 | }
      | ^
a.cc:57:18: error: expected ')' before '}' token
   57 |           while (
      |                 ~^
      |                  )
......
   83 | }
      | ~                 
a.cc:83:1: error: expected primary-expression before '}' token
   83 | }
      | ^
a.cc:83:2: error: expected '}' at end of input
   83 | }
      |  ^
a.cc:51:26: note: to match this '{'
   51 |       while (mim != mam) {
      |                          ^
a.cc:83:2: error: expected '}' at end of input
   83 | }
      |  ^
a.cc:48:17: note: to match this '{'
   48 |     if (ma > 0) {
      |                 ^
a.cc:83:2: error: expected '}' at end of input
   83 | }
      |  ^
a.cc:17:33: note: to match this '{'
   17 |   for (int i = 1; i <= N; i ++) {
      |                                 ^
a.cc:83:2: error: expected '}' at end of input
   83 | }
      |  ^
a.cc:4:13: note: to match this '{'
    4 | int main () {
      |             ^