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

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

using ll = long long;
#define nINF -2000000000000000

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

	ll ans=nINF;
	for(int start=0;start<n;start++){
		//1repを確認
		vector<int> dist(n,-1);
		int replen=0;
		ll repsum=0;
		int now=start;
		ll nowans=nINF;
		ll nowsum=0;
		while(1){
			now=p[now];
			//cout << now << "→";
			if(dist[now]!=-1) break;
			dist[now]++;
			repsum+=c[now];
			replen++;
		}
		int reptime=0;
		if(repsum>0) reptime=k/replen;
		int last = replen;
		if(repsum>0)last=l%replen;
		/*cout << "start:" << start << endl;
		cout << "replen:" << replen << endl;
		cout << "repsum:" << repsum << endl;
		cout << "reptime:" << reptime << endl;
		cout << "last:" << last << endl;*/

		//repsum>0ならできるだけ回す
		if(repsum>0) nowsum=repsum*reptime;
		now=start;
		int flag=0;
		if(last==replen){
			flag=1;
			now=p[now];
			nowsum=c[now];
		}
		nowans=nowsum;
		for(int i=flag;i<last;i++){
			now=p[now];
			nowsum+=c[now];
			nowans=max(nowans,nowsum);
		}
		//cout << "nowans:" << nowans <<  endl;
		ans=max(ans,nowans);
		//cout << "ans:" << ans << endl << endl;
	}

	cout << ans << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:44:34: error: 'l' was not declared in this scope
   44 |                 if(repsum>0)last=l%replen;
      |                                  ^
Language: C++

        #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
int p[N],c[N];

void solve(){
    int n,k;
    cin >> n >> k;
    for(int i = 1;i <= n;i++) cin >> p[i];
    for(int i = 1;i <= n;i++) cin >> c[i];
    int ans = -INF;
    for(int i=1;i <= n;i++){
        // the piece starts at this square
        int score = 0;
        set<int> vis;
        int K = k;
        int cur = i;
        while(K){
            score += c[p[cur]];
            vec.pb(c[p[cur]]);
            ans = max(ans,score);
            cur = p[cur];
            K--;
            if(cur == i) break;   
        }
        int sz = vec.size();
        if(score >= 0 && K){
            score += score*(K/sz);
            if(K%sz)
            score += vec[(K%sz)-1];
        }
        ans = max(ans,score);

    }
    cout << ans << endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:67:13: error: 'vec' was not declared in this scope
   67 |             vec.pb(c[p[cur]]);
      |             ^~~
a.cc:73:18: error: 'vec' was not declared in this scope
   73 |         int sz = vec.size();
      |                  ^~~
Language: C++

#include <iostream>
#define ll long long
using namespace std;
const int N = 5009;
int n,k;
int p[N],c[N],sp[N],avail[N];
long long f[N][N];
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    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++){
        memset(avail,0,sizeof(avail));
        int j = i , cnt = 0;
        while (avail[p[j]] == 0){
            cnt++;
            f[i][cnt] = f[i][cnt - 1] + c[p[j]];
            avail[p[j]] = 1;
            j = p[j];
        }
        sp[i] = cnt;
    }
    ll ans = -1e18;
    for (int i = 1; i <= n; i++){
        ll pos_max = 0 , val = -1e18;
         for (int j = 1; j <= k % sp[i]; j++)
            if (f[i][j] > val){
                val = f[i][j];
                pos_max = j;
            }
        /*ans = max(ans,f[i][pos_max] + 1LL * ((k - pos_max)/sp[i]) * f[i][sp[i]]);
        ans = max(ans,1LL * (k/sp[i]) * f[i][sp[i]] + f[i][k % sp[i]]);
        ans = max(ans,f[i][pos_max]);*/
        ans = max(ans,max(0,1LL * (k/sp[i]) * f[i][sp[i]]) + f[i][pos_max]);
    }
    cout << ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 'memset' was not declared in this scope
   14 |         memset(avail,0,sizeof(avail));
      |         ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | #define ll long long
a.cc:35:26: error: no matching function for call to 'max(int, long long int)'
   35 |         ans = max(ans,max(0,1LL * (k/sp[i]) * f[i][sp[i]]) + f[i][pos_max]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:35:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   35 |         ans = max(ans,max(0,1LL * (k/sp[i]) * f[i][sp[i]]) + f[i][pos_max]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
Language: C++

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

#define int long long

int N, K, G[5000], C[5000];
vector < int > costs, vis;

void dfs(int u){
	vis[u] = true;
	costs.push_back(C[u]);
	if (!vis[G[u]])
		dfs(G[u]);
	else
		return;
}

int main(){
	cin >> N >> K;
	for (int i = 0; i < N; i ++){
		int X; cin >> X; X -= 1;
		G[i] = X;
	}
	for (int i = 0; i < N; i ++)
		cin >> C[i];
	long long result = -2e18;
	for (int i = 0; i < N; i ++){
		vis = vector < int > (N, 0);
		costs.clear();
		dfs(G[i]);
		int sz = costs.size();
		int p0 = K / sz, p1 = K % sz;
		long long curr1 = 0;
		for (int i = 0; i < costs.size() && i < K; i ++){
			curr1 += costs[i];
			result = max(curr1, result);
		}
		if (p0 > 0){
			long long curr2 = accumulate(costs.begin(), costs.end(), 0int) * (p0);
			for (int i = 0; i < costs.size() && i < p1; i ++){
				curr2 += costs[i];
				result = max(curr2, result);
			}
		}
		if (p0 > 1){
			long long curr3 = accumulate(costs.begin(), costs.end(), 0int) * (p0 - 1);
			for (int i = 0; i < costs.size() && i < K; i ++){
				curr3 += costs[i];
				result = max(curr3, result);
			}
		}
	}
	cout << result << "\n";
}


Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:39:82: error: unable to find numeric literal operator 'operator""int'
   39 |                         long long curr2 = accumulate(costs.begin(), costs.end(), 0int) * (p0);
      |                                                                                  ^~~~
a.cc:46:82: error: unable to find numeric literal operator 'operator""int'
   46 |                         long long curr3 = accumulate(costs.begin(), costs.end(), 0int) * (p0 - 1);
      |                                                                                  ^~~~
Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;

#define scanf scanf_s
#define LL long long
#define maxn 5010

LL p[maxn], c[maxn], t[maxn], d[maxn], mid[maxn];

int main() {
	int n, k, i, now, cnt;
	LL mx = -99999999, val;
	scanf("%d%d", &n, &k);
	for (i = 1; i <= n; i++)
		scanf("%lld", &p[i]);
	for (i = 1; i <= n; i++)
		scanf("%lld", &c[i]);
	for (i = 1; i <= n; i++) {
		now = p[i];
		d[i] = c[now];
		t[i] = 1;
		mid[i] = -99999999;
		mid[i] = max(d[i], mid[i]);
		while (1) {
			if (now == i)break;
			t[i]++;
			now = p[now];
			d[i] += c[now];
			mid[i] = max(d[i], mid[i]);
		}
	}
	for (i = 1; i <= n; i++) {
		if (k / t[i] > 0) {
			mx = max(mx, mid[i]);
			if (k % t[i] == 0) {
				mx = max(mx, (k / t[i] - 1) * d[i] + mid[i]);
				continue; 
			}
		}
		val = k / t[i] * d[i];
		now = p[i];
		val += c[now];
		mx = max(mx, val);
		cnt = 1;
		while (1) {
			if (k % t[i] == cnt)break;
			cnt++;
			now = p[now]; val += c[now];
			mx = max(mx, val);
		}
	}
	printf("%lld\n", mx);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:15: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
    5 | #define scanf scanf_s
      |               ^~~~~~~
a.cc:14:9: note: in expansion of macro 'scanf'
   14 |         scanf("%d%d", &n, &k);
      |         ^~~~~
Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;

#define scanf scanf_s
#define LL long long
#define maxn 5010

LL p[maxn], c[maxn], t[maxn], d[maxn], mid[maxn];

int main() {
	int n, k, i, now, cnt;
	LL mx = -9999999, val;
	scanf("%d%d", &n, &k);
	for (i = 1; i <= n; i++)
		scanf("%lld", &p[i]);
	for (i = 1; i <= n; i++)
		scanf("%lld", &c[i]);
	for (i = 1; i <= n; i++) {
		now = p[i];
		d[i] = c[now];
		t[i] = 1;
		mid[i] = -9999999;
		mid[i] = max(d[i], mid[i]);
		while (1) {
			if (now == i)break;
			t[i]++;
			now = p[now];
			d[i] += c[now];
			mid[i] = max(d[i], mid[i]);
		}
	}
	for (i = 1; i <= n; i++) {
		if (k / t[i] > 0) {
			mx = max(mx, mid[i]);
			if (k % t[i] == 0) {
				mx = max(mx, (k / t[i] - 1) * d[i] + mid[i]);
				continue; 
			}
		}
		val = k / t[i] * d[i];
		now = p[i];
		val += c[now];
		mx = max(mx, val);
		cnt = 1;
		while (1) {
			if (k % t[i] == cnt)break;
			cnt++;
			now = p[now]; val += c[now];
			mx = max(mx, val);
		}
	}
	printf("%lld\n", mx);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:15: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
    5 | #define scanf scanf_s
      |               ^~~~~~~
a.cc:14:9: note: in expansion of macro 'scanf'
   14 |         scanf("%d%d", &n, &k);
      |         ^~~~~
Language: C++

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

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  for (int &i : p) {
    cin >> i;
    i--;
  }
  for (int &i : c) cin >> i;
  ll ans = -1001001001;
  for (int i = 0; i < n; i++) {
    int now = i;
    vector<ll> vs;
    ll res = 0;
    while (1) {
      now = p[now];
      res += c[now];
      vs.push_back(res);
      if (now == i) break;
    }
    int sz = vs.size();
    for (int j = 0; j < sz; j++) {
      if (j + 1 > k) break;
      ans = max(ans, vs[j] + ((k - j - 1) / sz) * max(0, res));
    }
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:54: error: no matching function for call to 'max(int, ll&)'
   28 |       ans = max(ans, vs[j] + ((k - j - 1) / sz) * max(0, res));
      |                                                   ~~~^~~~~~~~
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:28:54: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   28 |       ans = max(ans, vs[j] + ((k - j - 1) / sz) * max(0, res));
      |                                                   ~~~^~~~~~~~
/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:28:54: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   28 |       ans = max(ans, vs[j] + ((k - j - 1) / sz) * max(0, res));
      |                                                   ~~~^~~~~~~~
Language: C++

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

using Pair = pair<int, int>;
using lint = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)

// const int mod = 1e9 + 7;
// const int mod = 998244353;

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
#include <utility>
#include <vector>
struct UnionFind {
  std::vector<int> par, siz;
  void init(int n) {
    par.resize(n);
    for (int i = 0; i < n; i++)
      par[i] = i;
    siz.resize(n, 1);
  }
  UnionFind(int n) {
    init(n);
  }
  int root(int n) {
    if (par[n] == n)
      return n;
    else
      return par[n] = root(par[n]);
  }
  bool issame(int x, int y) {
    return (root(x) == root(y));
  }
  bool marge(int a, int b) {
    if (issame(a, b))
      return false;
    else {
      a = root(a), b = root(b);
      if (siz[a] < siz[b]) std::swap(a, b);
      siz[b] += siz[a];
      par[a] = par[b];
      return true;
    }
  }
  int size(int n) {
    return siz[root(n)];
  }
};
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;
}
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n),c(n);
  rep(i,n)cin>>p[i];
  rep(i,n)cin>>c[i];
  UnionFind uf(n);
  rep(i,n){
    uf.marge(i,p[i]-1);
  }
  lint ret=-LLONG_MAX;
  rep(i,n){
    lint mx=-LLONG_MAX;
    lint po=0,sum=0;
    rep(j,n){
      if(uf.issame(i,j))sum+=c[j];
    }
    if(sum<=0){
      int now = i;
      rep(j,min(k,uf.size(i))){
        now = p[now] - 1;
        po += c[now];
        chmax(mx, po);
      }
    }
    else {
      po = sum * (k / uf.size(i));
      int now = i;
      if(k/uf.size(i)>0)chmax(mx,po);
      rep(j, k % uf.size(i)) {
        now = p[now] - 1;
        po += c[now];
        chmax(mx,po);
      }
    }
    chmax(ret,mx);
  }
  if(ret==0){
    ret=c[0];
    rep(i,n){
      chmax(ret,(lint)c[i]);
    }
  }
  cout<<ret<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:89:13: error: 'LLONG_MAX' was not declared in this scope
   89 |   lint ret=-LLONG_MAX;
      |             ^~~~~~~~~
a.cc:27:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   26 | #include <utility>
  +++ |+#include <climits>
   27 | #include <vector>
Language: C++

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

ll tmpmax(vector<ll>s, ll n){
  ll tmpmax = -1e9;
  rep(i,n){
    tmpmax = max(tmpmax, s.at(i));
  }
  return tmpmax;
}

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> P(N), C(N);
  rep(i,N){
    cin >> P.at(i);
  }
  rep(i,N){
    cin >> C.at(i);
  }
  ll ans = -1e9;
  rep(i,N){
    vector<ll> s(N);
    ll score = 0, xscore = 0;
    ll oldi = i, x = N;
    bool back = false;
    rep(j,N){
      int newi = P.at(oldi) - 1;
      score += C.at(newi);
      s.at(j) = score;
      oldi = newi;
      if(!back) xscore += C.at(newi);
      if(newi==i){
        x = min(x, j+1);
        back = true;
      }
    }
    if(K<=N){
      ans = max(ans, tmpmax(s, K));
    }else{
      if(xscore>0){
        ans = max(ans, xscore*(K/x)+tmpmax(s, K%x));
      }else{
        ans = max(ans, tmpmax(s, x));
      }
    }
  }
  cout << ans;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:16: error: no matching function for call to 'min(ll&, int)'
   38 |         x = min(x, j+1);
      |             ~~~^~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: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:   template argument deduction/substitution failed:
a.cc:38:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   38 |         x = min(x, j+1);
      |             ~~~^~~~~~~~
/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, 2 provided
Language: C++

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

ll tmpmax(vector<ll>s, int n){
  ll tmpmax = -1e9;
  rep(i,n){
    tmpmax = max(tmpmax, s.at(i));
  }
  return tmpmax;
}

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> P(N), C(N);
  rep(i,N){
    cin >> P.at(i);
  }
  rep(i,N){
    cin >> C.at(i);
  }
  ll ans = -1e9;
  rep(i,N){
    vector<ll> s(N);
    ll score = 0, xscore = 0;
    ll oldi = i, x = N;
    bool back = false;
    rep(j,N){
      int newi = P.at(oldi) - 1;
      score += C.at(newi);
      s.at(j) = score;
      oldi = newi;
      if(!back) xscore += C.at(newi);
      if(newi==i){
        x = min(x, j+1);
        back = true;
      }
    }
    if(K<=N){
      ans = max(ans, tmpmax(s, K));
    }else{
      if(xscore>0){
        ans = max(ans, xscore*(K/x)+tmpmax(s, K%x));
      }else{
        ans = max(ans, tmpmax(s, x));
      }
    }
  }
  cout << ans;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:16: error: no matching function for call to 'min(ll&, int)'
   38 |         x = min(x, j+1);
      |             ~~~^~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: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:   template argument deduction/substitution failed:
a.cc:38:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   38 |         x = min(x, j+1);
      |             ~~~^~~~~~~~
/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, 2 provided
Language: C++

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x,2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vd = vector<long double>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  ll n,k,x,tot=0,roop_num,max_tot=-1e9-10,max_i,ans=0;
  cin >> n>>k;
  vi p(n);
  vi c(n);
  cins(n, p);
  cins(n, c);
  rep(i, n) p[i]--;
  rep(si, n){
    roop_num=0;
    x=si;
    tot=0;
    max_tot=-1e9-10;
    while(true){
      x=p[x];
      roop_num++;
      tot+=c[x];
      if(max_tot<tot){
        max_tot=tot;
        max_i=roop_num;
      }
      if(x==si　|| roop_num==k) break;
    }
    if(tot<=0){
      ans=max(max_tot,ans);
    }else{
      max_tot+=((k-max_i)/roop_num)*tot;
      ans=max(max_tot,ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc:81:13: error: extended character 　 is not valid in an identifier
   81 |       if(x==si　|| roop_num==k) break;
      |             ^
a.cc: In function 'int main()':
a.cc:81:13: error: 'si\U00003000' was not declared in this scope
   81 |       if(x==si　|| roop_num==k) break;
      |             ^~~~
Language: C++

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int N_MAX = 5010;
int n, k;
vector<ll> P(N_MAX), C(N_MAX);

ll solve() {
    ll res = -INF;
    // サイクルに分ける
    vector<vector<ll>> cycle;
    vector<bool> used(n+10, false);
    rp(i, 0, n) {
        if(used[i]) continue;
        int cur = i;
        vector<ll> s;
        while(1) {
            if(used[cur]) break;
            used[cur] = true;
            s.push_back(C[cur]);
            cur = P[cur];
        }
        cycle.push_back(s);
    }

    // サイクルごとに考える
    for(auto x:cycle) {
        ll M = x.size();  // サイクルの大きさ
        ll sum = 0ll;  // サイクル一周の得点
        for(auto y: x) sum+=y;
        vector<ll> Cum(2*M);  // 累積和
        Cum[0] = x[0];
        rp(i, 1, 2*M) {
            Cum[i] = Cum[i-1] + x[i%M];
        }
        rp(r, 1, M+1) {  // 余りを固定 余りは1~M
            if(r > k) continue;
            rp(m, 0, M){  // 何番目から取り始めるか
                ll temp = Cum[m+r] - Cum[m];
                if(sum > 0) temp += ((k-r) / M) * sum;
                chmax(res, temp);
            }  
        }
    }
    return res;
}

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

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

const int INF = 100100100;

int main() {
  int n; ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> s; //訪れた町を入れてく
  vector<int> ord(n+1,-1) //何番目に訪れたかを記録
  int c = 1, l = 0; //cは周期、lは周期じゃない部分の長さ
  {
    int v = 1; //街の番号
    while(ord[v] == -1){
      ord[v] = s.size();
      s.push_back(v);
      v = a[v-1];
    }
    c = s.size() - ord[v]; //ord[v]に入れようとした数-ord[v]
    l = ord[v];
  }

  if(k < l) cout << s[k] << endl;
  else{
    k -= l; //周期じゃない部分の長さを引くのを忘れるな
    k %= c;
    cout << s[l+k] << endl; //l+kにするのを忘れるな
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:3: error: expected ',' or ';' before 'int'
   17 |   int c = 1, l = 0; //cは周期、lは周期じゃない部分の長さ
      |   ^~~
a.cc:25:5: error: 'c' was not declared in this scope
   25 |     c = s.size() - ord[v]; //ord[v]に入れようとした数-ord[v]
      |     ^
a.cc:26:5: error: 'l' was not declared in this scope
   26 |     l = ord[v];
      |     ^
a.cc:29:10: error: 'l' was not declared in this scope
   29 |   if(k < l) cout << s[k] << endl;
      |          ^
a.cc:32:10: error: 'c' was not declared in this scope
   32 |     k %= c;
      |          ^
Language: C++

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  vector<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];
  }
  long long ans = -1e18;
  for (int si = 0; si < n; si++) {
    int x = si;
    vector<int> s;
    long long tot = 0;
    while (1) {
      x = p[x];
      s.push_back(c[x]);
      tot += c[x];
      if (x == si) break;
    }
    int l = s.size();
    long long t = 0;
    for (int i = 0; i < l; i++) {
      t += s[i];
      if (i + 1 > k) break;
      if (tot > 0) {
        long long e = (k - (i + 1)) / l;
        now += tot * e;
      }
      ans = max(ans, now);
    }
  }
  cout << ans;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:9: error: 'now' was not declared in this scope
   34 |         now += tot * e;
      |         ^~~
a.cc:36:22: error: 'now' was not declared in this scope
   36 |       ans = max(ans, now);
      |                      ^~~
Language: C++

#include <cmath>
#include <iostream>
#include <vector>

#define MAXN 5005
#define K 15

using namespace std;
typedef long long ll;
const ll LO = -1e16;
int n, k;

ll st[MAXN * 2][K];

ll query(int l, int r) {
    int len = r - l + 1;
    int j = log2(len);
    return min(st[l][j], st[r - (1 << j) + 1][j]);
}

ll solve(vector<int> &v) {
    int len = v.size();
    vector<ll> s = {0};
    for (int i = 0; i < 2 * len; ++i)
        s.emplace_back(s.back() + v[i % len]);
    int slen = s.size();
    for (int i = 0; i < slen; ++i)
        st[i][0] = s[i];
    for (int j = 1; j <= log2(slen); ++j)
        for (int i = 0; i < slen; ++i) {
            st[i][j] = st[i][j - 1];
            int right = i + (1 << (j - 1));
            if (right < slen)
                st[i][j] = min(st[i][j], st[right][j - 1]);
        }
    ll sum = s[len], hi_r = LO, hi_all = LO;
    int r = k % len;
    for (int i = 1; i < slen; ++i) {
        if (r)
            hi_r = max(hi_r, s[i] - query(max(0, i - r), i - 1));
        hi_all = max(hi_all, s[i] - query(max(0, i - len), i - 1));
    }
    if (k < len)
        return hi_r;
    return max(hi_all, max(sum * (k / len - 1) + hi_all, sum * (k / len) + hi_r));
}

int main() {
    cin >> n >> k;
    vector<int> p(n), c(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i];
    for (int i = 0; i < n; ++i)
        cin >> c[i];
    ll ans = LLONG_MIN;
    vector<bool> vis(n);
    for (int i = 0; i < n; ++i) {
        if (vis[i])
            continue;
        vector<int> v;
        int idx = i;
        while (!vis[p[idx] - 1]) {
            idx = p[idx] - 1;
            vis[idx] = true;
            v.emplace_back(c[idx]);
        }
        ans = max(ans, solve(v));
    }
    cout << ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:14: error: 'LLONG_MIN' was not declared in this scope
   55 |     ll ans = LLONG_MIN;
      |              ^~~~~~~~~
a.cc:4:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <vector>
  +++ |+#include <climits>
    4 |
Language: C++

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

#define ll long long

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> p(n+1);
	vector<ll> c(n+1);
	vector<ll> q;
	ll i, j;
	ll buf;
	ll total;
	ll ans = -1e10;
	for (i = 1; i <= n; i++) {
		cin >> p[i];
	}
	for (i = 1; i <= n; i++) {
		cin >> c[i];
	}
	for (i = 1; i <= n; i++) {
		buf = i;
		total = 0;
		while (1) {
			buf = p[buf];
			total += c[buf];
			q.push_back(c[buf]);
			if (buf == i)break;
		}
		buf = 0;
		for (j = 0; j < q.size(); j++) {
			buf += q[j];
			if (total > 0)ans = max(ans, buf + total * ((k - j - 1) / q.size()));
			else ans = max(ans, buf);
			if (j + 1 == k)break;
		}
		q.clear();
	}
	cout << ans << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:48: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   34 |                         if (total > 0)ans = max(ans, buf + total * ((k - j - 1) / q.size()));
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:34:48: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   34 |                         if (total > 0)ans = max(ans, buf + total * ((k - j - 1) / q.size()));
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:34:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |                         if (total > 0)ans = max(ans, buf + total * ((k - j - 1) / q.size()));
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define GCD(v) gcd(ALL(v), 0l)

/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/

template <typename T>
using vec = vector<T>;

template <typename T>
using vvec = vector<vector<T>>;

class cycle {
public:
  cycle(){
    score=0;
    length=0;
    elems={};
  }
  long score;
  int len;
  vector<int> elems; 
};


int main(){
  int n,k;
  cin>>n>>k;
  nvec(int,p,n);
  nvec(int,c,n);
  for (int i = 0; i < n; i++) {
    p[i]--;
  }
  vvec<int> place(n, vector<int>(1));
  vvec<long> point(n, vector<long>(1));
  
  for (int i = 0; i < n; i++) {
    place[i][0] = i;
    point[i][0] = 0;
  }
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < n; i++) {
      place[i][j] = p[place[i][j-1]];
      point[i][j] = c[place[i][j]] + point[i][j-1];
    }
  }
  if(k<5000){
    long ans = 0;
    for (int i = 0; i < n; i++) {
      ans = max(ans, point[i][k]);
    }
    cout<<ans;
    return 0;
  }
  while(true){
    string s;
    s = "にゃーん";
  }
  /*for (int i = 0; i < n; i++) {
    while(find(ALL(v[i]),v[i].back())==v[i].end()-1){
      v[i].push_back(p[v[i].back()]-1);
    }
    cycle nyan;
    for (auto itr = find(ALL(v[i]),v[i].back()); itr < v[i].end()-1; itr++) {
      nyan.elems.push_back(*itr);
      nyan.score += c[*itr];
    }
    nyan.len = nyan.elems.size();
    
  }
  */
}


/* きょむ〜 */


Compiler output:
a.cc: In constructor 'cycle::cycle()':
a.cc:62:5: error: 'length' was not declared in this scope
   62 |     length=0;
      |     ^~~~~~
Language: C++

#include<iostream>
#include<mem.h>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<set>
#include<queue>


using namespace std;
#define int long long



signed main()
{
      int n,k;
      cin>>n>>k;
      int p[n+1],c[n];
      for(int i=1;i<=n;i++)cin>>p[i];
      for(int i=1;i<=n;i++)cin>>c[i];
      int ans=0;
      for(int i=1;i<=n;i++)
      {
          int s=i;
          int u=1;
          int sum=c[i];
          ans=max(ans,sum);
          while(u<=k)
         {
          sum+=c[p[s]];
          ans=max(ans,sum);
          u++;
          s=p[s];
         }
      }
      cout<<ans<<endl;
      return 0;

}


Compiler output:
a.cc:2:9: fatal error: mem.h: No such file or directory
    2 | #include<mem.h>
      |         ^~~~~~~
compilation terminated.
Language: C++

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

long long n, K, p[5005], c[5005], ans = -1e9;
vector <long long> v;

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++){
        int now = i;
        v.clear();
        v.push_back(c[now]);
        long long tot = c[now];
        now = p[now];
        while (now != i){
            v.push_back(c[now]);
            tot += c[now];
            now = p[now];
        }
        long long k = K;
        if (tot > 0){
            long long tmp = k/v.size();
            if (tmp) tmp--;
            tot *= tmp;
            k -= tmp*v/size();
            ans = max(ans, tot);
        }
        else{
            tot = 0;
            k = min(k, (long long)v.size());
        }
        for (int j = 0; j < k; j++){
            tot += v[j%v.size()];
            ans = max(ans, tot);
        }
    }
    cout << ans << "\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:21: error: no match for 'operator*' (operand types are 'long long int' and 'std::vector<long long int>')
   32 |             k -= tmp*v/size();
      |                  ~~~^~
      |                  |   |
      |                  |   std::vector<long long int>
      |                  long long int
a.cc:32:28: error: no matching function for call to 'size()'
   32 |             k -= tmp*v/size();
      |                        ~~~~^~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:262:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/range_access.h:272:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note:   candidate expects 1 argument, 0 provided
Language: C++

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

int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(false);
    int N, K;
    cin >> N >> K;
    int n = N;
    vector<int> v(n), w(n);
    for (int i = 0; i < N; i++)
        cin >> v[i], --v[i];
    for (int i = 0; i < N; i++)
        cin >> w[i];

    ll ans = -1e18;
    for (int i = 0; i < n; i++)
    {
        vector<int> temp;
        int p = v[i];
        ll sum = 0, max_sum = w[p];
        ll sum_cycle = 0;
        while (p != i)
        {
            temp.push_back(w[p]);
            sum_cycle += w[p];
            max_sum = max(max_sum, sum_cycle);
            p = v[p];
        }
        temp.push_back(w[i]);
        sum_cycle += w[i];
        max_sum = max(max_sum, sum_cycle);
        int len = temp.size();
        if (sum_cycle <= 0)
            sum = max_sum;
        else
        {
            int number_cycle = K / len;
            int rem = K - number_cycle * len;
            ll temp_sum = 0;
            ll maxx = 0;
            for (int t = 0; t < rem; t++)
            {
                temp_sum += temp[t];
                maxx = max(temp_sum, maxx);
            }
            sum += maxx + sum_cycle * number_cycle;
            ll next_sum = 0;
            if (number_cycle > 1)
            {
                next_sum = (number_cycle - 1) * sum_cycle;
                next_sum += max_sum;
            }
            sum = max(sum, next_sum);
        }
        ans = max(sum, ans);
    }
    cout << ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:12: error: no matching function for call to 'std::basic_istream<char>::tie(bool)'
    8 |     cin.tie(false);
      |     ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/istream:40,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_ios.h:299:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie() const [with _CharT = char; _Traits = std::char_traits<char>]'
  299 |       tie() const
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:299:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/basic_ios.h:311:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie(std::basic_ostream<_CharT, _Traits>*) [with _CharT = char; _Traits = std::char_traits<char>]'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:311:43: note:   no known conversion for argument 1 from 'bool' to 'std::basic_ostream<char>*'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
Language: C

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL<<60;
int N;
long long K;
vector<int> P;
vector<long long> C;

long long solve() {
    long long res = -INF;

    // 順列を各サイクルに分解する
    vector<bool> used(N, false);
    vector<vector<long long>> ss;
    for (int i = 0; i < N; ++i) {
        if (used[i]) continue;
        int cur = i;
        vector<long long> s;
        while (!used[cur]) {
            used[cur] = true;
            s.push_back(C[cur]);
            cur = P[cur];
        }
        ss.push_back(s);
    }

    // 各サイクルごとに考える
    for (auto vec : ss) {
        long long M = vec.size();

        // サイクルを二週したものの累積和
        vector<long long> sum(M*2+1, 0);
        for (int i = 0; i < M*2; ++i) sum[i+1] = sum[i] + vec[i%M];

        // amari[r] := 連続する r 個の総和の最大値
        vector<long long> amari(M, -INF);
        for (int i = 0; i < M; ++i) {
            for (int j = 0; j < M; ++j) {
                chmax(amari[j], sum[i+j] - sum[i]);
            }
        }

        // 余りの長さで場合分け
        for (int r = 0; r < M; ++r) {
            if (r > K) continue;
            long long q = (K - r) / M;
            if (r == 0 && q == 0) continue;

            if (sum[M] > 0) chmax(res, amari[r] + sum[M] * q);
            else if (r > 0) chmax(res, amari[r]);
        }
    }
    return res;
}

int main() {
    cin >> N >> K;
    P.resize(N); C.resize(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i];
    for (int i = 0; i < N; ++i) cin >> C[i];
    cout << solve() << endl;
}

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++

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
 
const int N = 20005;
const long long INF = 0x3f3f3f3f3f3f3f3f;
 
int n, idx;
long long ans, x, k, d, p[N], c[N], s[N];
long long q[N];
bool st[N];
 
int main()
{
	scanf("%d %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 = -INF;
	for(int i = 1; i <= n; ++i)
	{
		if(!st[i])
		{
			int r = 0;
			long long maxv = -INF;
			idx = 1;
			s[0] = 0;
			while(!st[i])
			{
				s[idx] = s[idx-1] + c[i];
				++idx;
				st[i] = true;
				i = p[i];
			}
			r = k % --idx;
			if(r == 0) r = idx;
			for(int i = 1; i <= idx; ++i) s[i + idx] = s[i] + s[idx];
			int hh = 0, tt = -1;
			for(int i = 0; i < idx << 1; ++i)
			{
				while(hh <= tt && s[q[tt]] >= s[i]) --tt;
				q[++tt] = i;
				if(q[hh] <= i - r) ++hh;
				maxv = max(maxv, s[i + 1] - s[q[hh]]);
              	maxv = max(maxv, s[i + 1];
			}
			if(s[idx] > 0) maxv += s[idx] * ((k - 1) / idx);
			ans = max(ans, maxv);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:42: error: expected ')' before ';' token
   46 |                 maxv = max(maxv, s[i + 1];
      |                           ~              ^
      |                                          )
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<vector<int>> data(2, vector<int>(N));
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
      cin >> data.at(i).at(j);
    }
  }
  //2*Nのすごろくの表
  vector<vector<int>> result(K, vector<int>(N));
  //K*Nの結果の表、これにそれぞれの結果を入れていく
  int64_t score;
  for(int i=0; i<N; i++){
    int placenow = i;
    score = 0;
    for(int j=0; j<K; j++){
      placenow=data.at(0).at(placenow)-1;
      score+=data.at(1).at(placenow);
      result.at(j).pushback(score);
    }
  }
  int64_t ans = 0;
  for(int i=0; i<K; i++){
    for(int j=0; j<N; j++){
      if(ans<result.at(i).at(j)){
        ans=result.at(i).at(j);
      }
    }
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:20: error: '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'class std::vector<int>'} has no member named 'pushback'; did you mean 'push_back'?
   22 |       result.at(j).pushback(score);
      |                    ^~~~~~~~
      |                    push_back
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<vector<int>> data(2, vector<int>(N));
  for(int i; i<2; i++){
    for(int j; j<N; j++){
      cin >> data.at(i).at(j);
    }
  }
  //2*Nのすごろくの表
  vector<vector<int>> result(K, vector<int>(N));
  //K*Nの結果の表、これにそれぞれの結果を入れていく
  int score = 0;
  for(int i; i<N; i++){
    int placenow = i;
    for(int j; j<K; j++){
      score+=data.at(2).at(placenow);
      result.at(j).at(i)=score;
      placenow=data.at(1).at(placenow);
    }
  }
  for(int i; i < K;i++){
    sort(result[i].begin(),result[i].end());
  }
  sort(result[,1].begin(),result[,1].end());
  
  cout << result.at(0).at(0) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:15: error: expected primary-expression before ',' token
   27 |   sort(result[,1].begin(),result[,1].end());
      |               ^
a.cc:27:34: error: expected primary-expression before ',' token
   27 |   sort(result[,1].begin(),result[,1].end());
      |                                  ^