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

#include<bits/stdc++.h>
typedef ll long long;
using namespace std;
int main(){
  ll N,K;
  cin>>N>>K;
  ll a[i];
  bool judge[N];
  ll count=0,place=1;
  for(int i=0;i<N;i++){
    cin>>a[i];
    judge[i]=false;
  }
  judge[0]=true;
  while(true){
    place=a[place-1];
    count++;
    if(judge[place-1]){
      ll rand=a[place-1];
      break;
    }
    judge[a[place-1]]=true;
  }
  ll a=count;
  count=0;
  for(int i=0;i<N;i++){
    judge[i]=false;
  }
  place=rand;
  while(true){
    place=a[place-1];
    count++;
    if(judge[place-1]){
      break;
    }
    judge[a[place-1]]=true;
  }
  ll b=count;
  
  ll T=(K-a)%b;
  place=rand;
  for(int i=0;i<T;i++){
    place=a[place-1];
  }
  cout<<place<<endl;
  return 0;
}

Compiler output:
a.cc:2:9: error: 'll' does not name a type
    2 | typedef ll long long;
      |         ^~
a.cc: In function 'int main()':
a.cc:5:3: error: 'll' was not declared in this scope
    5 |   ll N,K;
      |   ^~
a.cc:6:8: error: 'N' was not declared in this scope
    6 |   cin>>N>>K;
      |        ^
a.cc:6:11: error: 'K' was not declared in this scope
    6 |   cin>>N>>K;
      |           ^
a.cc:7:5: error: expected ';' before 'a'
    7 |   ll a[i];
      |     ^~
      |     ;
a.cc:9:5: error: expected ';' before 'count'
    9 |   ll count=0,place=1;
      |     ^~~~~~
      |     ;
a.cc:11:10: error: 'a' was not declared in this scope
   11 |     cin>>a[i];
      |          ^
a.cc:12:5: error: 'judge' was not declared in this scope
   12 |     judge[i]=false;
      |     ^~~~~
a.cc:14:3: error: 'judge' was not declared in this scope
   14 |   judge[0]=true;
      |   ^~~~~
a.cc:16:5: error: 'place' was not declared in this scope
   16 |     place=a[place-1];
      |     ^~~~~
a.cc:16:11: error: 'a' was not declared in this scope
   16 |     place=a[place-1];
      |           ^
a.cc:17:10: error: no post-increment operator for type
   17 |     count++;
      |          ^~
a.cc:19:9: error: expected ';' before 'rand'
   19 |       ll rand=a[place-1];
      |         ^~~~~
      |         ;
a.cc:24:5: error: expected ';' before 'a'
   24 |   ll a=count;
      |     ^~
      |     ;
a.cc:25:9: error: overloaded function with no contextual type information
   25 |   count=0;
      |         ^
a.cc:29:3: error: 'place' was not declared in this scope
   29 |   place=rand;
      |   ^~~~~
a.cc:31:11: error: 'a' was not declared in this scope
   31 |     place=a[place-1];
      |           ^
a.cc:32:10: error: no post-increment operator for type
   32 |     count++;
      |          ^~
a.cc:38:5: error: expected ';' before 'b'
   38 |   ll b=count;
      |     ^~
      |     ;
a.cc:40:5: error: expected ';' before 'T'
   40 |   ll T=(K-a)%b;
      |     ^~
      |     ;
a.cc:42:17: error: 'T' was not declared in this scope
   42 |   for(int i=0;i<T;i++){
      |                 ^
a.cc:43:11: error: 'a' was not declared in this scope
   43 |     place=a[place-1];
      |           ^
Language: C

//include <bits/stdc++.h>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N,K;
    cin>>N>>K;
    
    VEC(ll,A,N+1);
    REP1(i,N){
        cin>>A[i];
    }
    
    VECi(ll,af,N+1,0);
    ll now=1,cnt=0,ii=K;
    bool cnf=true;
    REP(i,2*100000){
        //sl(now);
        if(ii<=0){
            cout<<now;
            return 0;
        }
        if(cnf&&af[now]!=0){
            ll t=i-af[now];
            ii=(K-af[now])%t;
            //sl(t,ii);
            cnf=false;
            if(ii==0){
                cout<<now;
                return 0;
            }
        }
        af[now]=i;
        now=A[now];
        ii--;
    }
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Compiler output:
main.c:2:10: fatal error: cmath: No such file or directory
    2 | #include <cmath>
      |          ^~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N,K;
    cin>>N>>K;
    
    VEC(ll,A,N+1);
    REP1(i,N){
        cin>>A[i];
    }
    
    VECi(ll,af,N+1,0);
    ll now=1,cnt=0,ii=K;
    bool cnf=true;
    REP(i,2*100000){
        //sl(now);
        if(ii<=0){
            cout<<now;
            return 0;
        }
        if(cnf&&af[now]!=0){
            ll t=i-af[now];
            ii=(K-af[now])%t;
            //sl(t,ii);
            cnf=false;
            if(ii==0){
                cout<<now;
                return 0;
            }
        }
        af[now]=i;
        now=A[now];
        ii--;
    }
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


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

#include<iostream>
using namespace std;

main(){
    int N;
    long long K;
    long long A[210000];
    cin >> N >> K;
    for (int i = 1; i <= N;i++) cin >> A[i];

    long long B[N] = {-1};
    long long current = 1;
    long long start = 0;
    long long roop = 0;
    bool stop = false;
    

    B[1] = 1;
    current = 1;
    for (int j = 1; j <= N;j++){
        int jsize = j;
        for (int k = 1; k <= jsize ;k++){
            if (A[current] == B[k]){
                start = k - 1;
                roop = j - k + 1;
                stop = true;
                break;
            }
        }
        if (stop) {
            break;
        }
        B[j+1] = A[current];
        current = A[current];
    }

    long long rooppoint = (K + 1 - start) % roop;
    if (rooppoint == 0) rooppoint = roop;

    long long pos = start + rooppoint;
    long long last = B[pos];
    cout << last << endl;
  
    return 0;
} 

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>

#include <debug.h>


using namespace std;

int main(){
	int n; cin >> n;
	long long int p; cin >> p;
	vector<int> a(n),t(n,-1);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		--a[i];
	}
	int start = 0;
	int m_time = 0;
	t[start] = m_time++;
	int cycle_length = 0;
	vector<pair<int,int> > cycle;
	while(true){
		int prev = start;
		start = a[start];
		if(t[start]!=-1){
			cycle_length = t[prev] - t[start] + 1;
			for(int i = 0; i < n; i++){
				if(t[i] >= t[start]){
					cycle.push_back({t[i],i});
				}
			}
			break;
		}
		t[start] = m_time++;
	}
	p -= m_time - cycle_length;
	sort(cycle.begin(),cycle.end());
	p%=cycle_length;
	cout << cycle[p].second + 1 << "\n";
	return 0;
}


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

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

#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> tolist(N);
  for (ll i = 0; i<N; i++) {
    ll A;
    cin >> A;
    A--;
    tolist.at(i) = A;
  }

  vector<bool> judlist(N, false);
  judlist.at(0) = true;

  ll gpoint=0, npoint, rs=-1, mcount=0, rcount=0, ans;
  while(rs == -1 && mcount<=N) {
    npoint = tolist.at(gpoint);
    if (judlist.at(npoint)) {
      rs = gpoint;
      roopjud = true;
    }
    else {
      judlist.at(gpoint) = true;
      gpoint = npoint;
      mcount++;
    }
  }
  
  gpoint = rs;
  npoint = -1;
  while(npoint!=rs) {
    npoint = tolist.at(gpoint);
    rcount++;
    gpoint = npoint;
  }

  
  if (K-mcount>=0) {
    gpoint = rs;
    if ((K-mcount)%rcount==0) {
      ans == rs;
    }
    else {
      for (ll i = 0; i<(K-mcount)%rcount; i++) {
        ans = tolist.at(gpoint);
        gpoint = ans;
      }
    }
  }
  else {
    gpoint = 0;
    for (ll i = 0; i<K; i++) {
      ans = tolist.at(gpoint);
      gpoint = ans;
    }
  }

  
  ans++;
  cout << ans << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:7: error: 'roopjud' was not declared in this scope
   31 |       roopjud = true;
      |       ^~~~~~~
Language: C++

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

int a[maxn];

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
  {
    cin >> a[i];
  }
  int tortoise = a[1];
  int hare = a[a[1]];
  while(tortoise != hare)
  {
    tortoise = a[tortoise];
    hare = a[a[hare]];
  }

  ll mu = 0;
  tortoise = 1;

  while(tortoise != hare)
  {
    tortoise = a[tortoise];
    hare = a[hare];
    mu++;
  }

  int ans = tortoise;

  ll lam = 1;
  hare = a[tortoise];
  while(tortoise != hare)
  {
    hare = a[hare];
    lam++;
  }

  k -= mu;
  k = max(k, 0);
  k %= lam;

  while(k)
  {
    ans = a[ans];
    k--;
  }


  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:67:10: error: no matching function for call to 'max(ll&, int)'
   67 |   k = max(k, 0);
      |       ~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:67:10: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   67 |   k = max(k, 0);
      |       ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:67:10: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   67 |   k = max(k, 0);
      |       ~~~^~~~~~
Language: Java

import java.util.*;
public class Main {
	static long[] visited ;
	static long[] teleport_to;
	static List<Integer> histry = new ArrayList<>();
	static int last=0;
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		long ans=0;
		visited = new long[(int) (N+1)];
		teleport_to= new long[(int) (N+1)];

		for(int i=1;i<=N;i++){
			teleport_to[i]=sc.nextLong();
		}
		visited[1]=1;
		histry.add(1);
		func(1);
		//関数後の処理
		//int roop_root = histry.get(histry.size()-1);
		//histry.remove(histry.size()-1);
		int length=histry.size();     //System.out.println(last);
		int from_1_to_roop = histry.indexOf(last);
		//System.out.println(from_1_to_roop);
		if ((K-from_1_to_roop)<=0){
			ans=histry.get(K);
		else{
		ans=(K-from_1_to_roop)%(length-from_1_to_roop);
		ans=histry.get((int) (from_1_to_roop+ans));
		System.out.println(ans);
		}
	}

    public static void func(int arg){
    	int from = arg;
    	int next = (int) teleport_to[from];
    	if (visited[(int) next]==1) {
    		//histry.add((int) next);
    		last=next;
    		return;

    	}
    	else{
    		histry.add((int) next);
    		visited[(int) next]=1;
    		func(next);
    	}
    }
}


Compiler output:
Main.java:29: error: 'else' without 'if'
		else{
		^
Main.java:36: error: illegal start of expression
    public static void func(int arg){
    ^
2 errors
Language: C++

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

long long n,arr[200005],counts[200005]={0};
vector<long long>v;

int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);
   cin>>n;
   long long k,X;
   cin>>k;
   for(int i=1;i<=n;i++) cin>>arr[i];

   long long idx=1,num=1,start;
   while(1)
   {
       if(counts[idx]>0)
       {
           //cout<<"Counts : "<<counts[idx]<<endl;
           if(couts[idx]>k){ cout<<v[k]<<endl; return 0; }
           start=counts[idx];
           X=num-counts[idx];
           start--;
           v.erase(v.begin(),v.begin()+start);
           break;
       }
       counts[idx]=num;
       v.push_back(idx);
       idx=arr[idx];
       num++;
   }
   k-=start;
   X=k%X;
   //cout<<"K : "<<k<<endl;
   //cout<<"X : "<<X<<endl;
   cout<<v[X]<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:15: error: 'couts' was not declared in this scope; did you mean 'counts'?
   21 |            if(couts[idx]>k){ cout<<v[k]<<endl; return 0; }
      |               ^~~~~
      |               counts
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
condt int maxn=2e5+5;
ll k,n,len,be;
ll a[maxn],n[maxn],r[maxn];
ll p=1,cnt;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)	com>>a[i];
	while(1)
	{
		if(b[a[p]]!=0)
		{
			be=b[a[p]];len=cnt-be+1;break;
		}
		r[++cnt]=a[p];b[a[p]]=cnt;p=a[p];
	}
	if(k<=be)	cout<<r[k];
	else
		{
			int s=(k-be)%len;
			cout<<r[be+s];
		}
return 0;
}


Compiler output:
a.cc:4:1: error: 'condt' does not name a type; did you mean 'const'?
    4 | condt int maxn=2e5+5;
      | ^~~~~
      | const
a.cc:6:6: error: 'maxn' was not declared in this scope
    6 | ll a[maxn],n[maxn],r[maxn];
      |      ^~~~
a.cc:6:14: error: 'maxn' was not declared in this scope
    6 | ll a[maxn],n[maxn],r[maxn];
      |              ^~~~
a.cc:6:22: error: 'maxn' was not declared in this scope
    6 | ll a[maxn],n[maxn],r[maxn];
      |                      ^~~~
a.cc: In function 'int main()':
a.cc:11:33: error: 'com' was not declared in this scope; did you mean 'cos'?
   11 |         for(int i=1;i<=n;i++)   com>>a[i];
      |                                 ^~~
      |                                 cos
a.cc:11:38: error: 'a' was not declared in this scope
   11 |         for(int i=1;i<=n;i++)   com>>a[i];
      |                                      ^
a.cc:14:20: error: 'b' was not declared in this scope
   14 |                 if(b[a[p]]!=0)
      |                    ^
a.cc:14:22: error: 'a' was not declared in this scope
   14 |                 if(b[a[p]]!=0)
      |                      ^
a.cc:18:17: error: 'r' was not declared in this scope
   18 |                 r[++cnt]=a[p];b[a[p]]=cnt;p=a[p];
      |                 ^
a.cc:18:26: error: 'a' was not declared in this scope
   18 |                 r[++cnt]=a[p];b[a[p]]=cnt;p=a[p];
      |                          ^
a.cc:18:31: error: 'b' was not declared in this scope
   18 |                 r[++cnt]=a[p];b[a[p]]=cnt;p=a[p];
      |                               ^
a.cc:20:31: error: 'r' was not declared in this scope
   20 |         if(k<=be)       cout<<r[k];
      |                               ^
a.cc:24:31: error: 'r' was not declared in this scope
   24 |                         cout<<r[be+s];
      |                               ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long n,m,k,a[100000009],l,q,q2,b[100000009],o;
bool ok[100000009],ok2;
vector<long long> v;
int main()
{
	cin>>n>>m;
	for(k=1;k<=n;k++)
	{
		cin>>a[k];
	}
	l=1;
	o=0;
	b[o]=-1;
	while(ok[l]==false)
	{
		b[l]=b[o]+1;
		v.push_back(l);
		ok[l]=true;
		o=l;
		l=a[l];
	}
	q=a[v[v.size()-1]];
	q2=b[q];
	cout<<q2<<endl<<v.size()<<endl;
	if(m<q2-1)
	{
		cout<<v[m-1];
	}
	else cout<<v[(m-q2)%(v.size()-q2-)+q2];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:42: error: expected primary-expression before ')' token
   31 |         else cout<<v[(m-q2)%(v.size()-q2-)+q2];
      |                                          ^
Language: C++

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

int main(){
  ll n,k;
  cin >> n >> k;
  vector <ll> a(n);
  vector <ll> cnt(n,-1);
  ll s,f,m,now;
  rep(i,n)cin >> a[i];
  now=0;int i=0;
  while(i!=n){
    if(cnt[now]==-1)cnt[now]=i;
    else{
      s=cnt[now];
      f=i;
      m=i-cnt[now];
      break;
    }
    // cout << now+1 << i << endl;
    now=a[now]-1;
    i++;
  }
  if(k < s)cout << a[k%m] << endl;
  else {
    k-=s;
    k%=m;
    cout << s[s+k] << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:14: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   31 |     cout << s[s+k] << endl;
      |              ^
Language: C++

#include<bits/stdc++.h>
#define ll long long
const int N=200005;
using namespace std;
ll k,n,a[N],r[N],b[N];
ll be,p=1,l,cnt;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	while(1)
	{
		if(b[a[p]]!=0)
		{
			be=b[a[p]];
			l=cnt-begin+1;
			break;
		}
		r[++cnt]=a[p];
		b[a[p]]=cnt;
		p=a[p];
	}
	if(k<=be) cout<<r[k];
	else 
	{
		int s=(k-be)%l;
		cout<<r[s+be];
	}
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:30: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator-'
   15 |                         l=cnt-begin+1;
      |                           ~~~^~~~~~
Language: C++

#include <iostream>
using namespace std;
int j,m=0,n;long long k,cnt;
int main() 
{cin>>n>>k;
 int a[n+1],a1[n+1];
 for(int i=1;i<=n;i++){
   cin>>a[i];a1[i]=0;} 
 j=1;
 while(a1[j]==0)
 { a1[j]=m+1;
  if(m==k){cout<<j;return 0;}
  j=a[j];m+11+;} 
 cnt=(k-a1[j]+1)%(m+1-a1[j]); 
 while(cnt--)
 {j=a[j];}
 cout<<j; 
 return 0;}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:15: error: expected primary-expression before ';' token
   13 |   j=a[j];m+11+;}
      |               ^
Language: C++

#include <iostream>
using namespace std;
int j,m=0,n;long long k,cnt;
int main() 
{cin>>n>>k;
 int a[n+1],a1[n+1];
 for(int i=1;i<=n;i++){
   cin>>a[i];a1[i]=0;} 
 j=1;
 while(b[j]==0)
 { b[j]=m+1;
  if(m==k){cout<<j;return 0;}
  j=a[j];m++;} 
 cnt=(k-a1[j]+1)%(m+1-a1[j]); 
 while(cnt--)
 {j=a[j];}
 cout<<j; 
 return 0;}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:8: error: 'b' was not declared in this scope
   10 |  while(b[j]==0)
      |        ^
Language: C++

#include <iostream>
using namespace std;
int j,m=0,n;long long k,cnt;
int main() 
{cin>>n>>k;
 int a[n+1],a1[n+1];
 for(int i=1;i<=n;i++){
   cin>>a[i];a1[i]=0;} 
 j=1, 
 while(b[j]==0)
 { b[j]=m+1;
  if(m==k){cout<<j;return 0;}
  j=a[j];m++;} 
 cnt=(k-a1[j]+1)%(m+1-a1[j]); 
 while(cnt--)
 {j=a[j];}
 cout<<j; 
 return 0;}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:2: error: expected primary-expression before 'while'
   10 |  while(b[j]==0)
      |  ^~~~~
Language: C++

#include <iostream>using namespace std;int j,m=0,n;long long k,cnt;int main() {cin>>n>>k; int a[n+1],a1[n+1]; for(int i=1;i<=n;i++){cin>>a[i];a1[i]=0;} j=1, while(b[j]==0){ b[j]=m+1; if(m==k){cout<<j;return 0;} j=a[j];m++;} cnt=(k-a1[j]+1)%(m+1-a1[j]); while(cnt--){j=a[j];} cout<<j; return 0; }

Compiler output:
a.cc:1:26: warning: extra tokens at end of #include directive
    1 | #include <iostream>using namespace std;int j,m=0,n;long long k,cnt;int main() {cin>>n>>k; int a[n+1],a1[n+1]; for(int i=1;i<=n;i++){cin>>a[i];a1[i]=0;} j=1, while(b[j]==0){ b[j]=m+1; if(m==k){cout<<j;return 0;} j=a[j];m++;} cnt=(k-a1[j]+1)%(m+1-a1[j]); while(cnt--){j=a[j];} cout<<j; return 0; }
      |                          ^~~~~~~~~
a.cc:1:10: fatal error: iostream>usin: No such file or directory
    1 | #include <iostream>using namespace std;int j,m=0,n;long long k,cnt;int main() {cin>>n>>k; int a[n+1],a1[n+1]; for(int i=1;i<=n;i++){cin>>a[i];a1[i]=0;} j=1, while(b[j]==0){ b[j]=m+1; if(m==k){cout<<j;return 0;} j=a[j];m++;} cnt=(k-a1[j]+1)%(m+1-a1[j]); while(cnt--){j=a[j];} cout<<j; return 0; }
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}
int a[200005];
int flag[200005];

void solve()
{
	// teleport k times
	// 1<=i<=n
	// telep town i -> a[i]
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int cur = 1, cnt = 0;
	while (k--)
	{
		cur = a[cur];
		cnt++;
		if (flag[cur])
			k %= cnt; k+=flag[cur];
		else
			flag[cur] = cnt;
	}
	cout << cur << en;
}

int main()
{
	fast;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:77:17: error: 'else' without a previous 'if'
   77 |                 else
      |                 ^~~~
Language: C

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<bool> J(N, false); //町iを訪れたかどうか
    ll now = 1, next, cnt = 0;
    J.at(0) = true;
    while (true) {
        next = A.at(now - 1);
        now = next;
        cnt++;
        if (J.at(next - 1) == false) {
            J.at(next - 1) = true;
        }
        else {
            break;
        }
    }
    ll loop = 0;
    J.at(now - 1) = false;
    while (true) {
        next = A.at(now - 1);
        now = next;
        loop++;
        if (J.at(next - 1) == true) {
            J.at(next - 1) == false;
        }
        else {
            break;
        }
    }
    K -= cnt;
    ll n = K % loop;
    for (int i = 0; i < n; i++) {
        next = A.at(now - 1);
        now = next;
    }
    cout << now << endl;
    return 0;
}

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

/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
VI tele(20005);

int f(int x) {
    return tele[x];
}

int main(){
    ll n, k;
    cin >> n >> k;
    for (int i = 0; i < (int)n; i+=1){
        int a;
        cin >> a;
        tele[i] = a-1;
    }
    int tortoise = f(0), hare = f(f(0));    // f(x0) is the node next to x0
    while (tortoise != hare) { tortoise = f(tortoise); hare = f(f(hare)); }
    // 2nd part: finding mu, hare and tortoise move at the same speed
    ll mu = 0; hare = 0;
    while (tortoise != hare) { tortoise = f(tortoise); hare = f(hare); mu++; }
    // 3rd part: finding lambda, hare moves, tortoise stays
    ll lambda = 1; hare = f(tortoise);
    // while (tortoise != hare) { hare = f(hare); lambda++; }
    // if(k < mu){
    //     int ans = 0;
    //     for (int i = 0; i < (int)k; i+=1){
    //         ans = tele[ans];
    //     }
    //     printf("%d", ans + 1);
    // }else{
    //     int ans = 0;
    //     for (int i = 0; i < (int)mu; i+=1){
    //         ans = tele[ans];
    //     }
    //     k-=mu;
    //     k%=lambda;
    //     for (int i = 0; i < k; i+=1){
    //         ans = tele[ans];
    //     }
    //     printf("%d", ans + 1);
    }
    return 0;
}



Compiler output:
a.cc:56:5: error: expected unqualified-id before 'return'
   56 |     return 0;
      |     ^~~~~~
a.cc:57:1: error: expected declaration before '}' token
   57 | }
      | ^
Language: C++

/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
VI tele(20005);

int f(int x) {
    return tele[x];
}

int main(){
    ll n, k;
    cin >> n >> k;
    for (int i = 0; i < (int)n; i+=1){
        tele[i] = nxt() - 1;
    }
    int tortoise = f(0), hare = f(f(0));    // f(x0) is the node next to x0
    while (tortoise != hare) { tortoise = f(tortoise); hare = f(f(hare)); }
    // 2nd part: finding mu, hare and tortoise move at the same speed
    ll mu = 0; hare = 0;
    while (tortoise != hare) { tortoise = f(tortoise); hare = f(hare); mu++; }
    // 3rd part: finding lambda, hare moves, tortoise stays
    ll lambda = 1; hare = f(tortoise);
    while (tortoise != hare) { hare = f(hare); lambda++; }
    if(k < mu){
        int ans = 0;
        for (int i = 0; i < (int)k; i+=1){
            ans = tele[ans];
        }
        printf("%d", ans + 1);
    }else{
        int ans = 0;
        for (int i = 0; i < (int)mu; i+=1){
            ans = tele[ans];
        }
        k-=mu;
        k%=lambda;
        for (int i = 0; i < k; i+=1){
            ans = tele[ans];
        }
        printf("%d", ans + 1);
    }
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:26:19: error: 'nxt' was not declared in this scope
   26 |         tele[i] = nxt() - 1;
      |                   ^~~
Language: C++

#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>

using namespace std;


int main() {
  int n;
  long long k;
  int x;
  scanf("%d %lld", &n, &k);

  vector<int> next(n);
  for (int i=0;i<n;++i) {
    scanf("%d", &x);
    next[i] = x - 1;
  }

  vector<bool> visited(n);
  vector<int> chain;

  visited[0] = true;
  chain.push_back(0);

  while (k > 0) {
    int nn = next[chain[chain.size()-1]];
    --k;

    chain.push_back(nn);

    if (visited[nn]) {
      break;
    }
    visited[nn] = true;
  }

  if (k == 0) {
    printf("%d\n", chain[chain.size()-1] + 1);
    return 0;
  }

  // Find cycle

  int index = 0;
  while (chain[index++] != chain[chain.size() - 1]);

  vector<int> whole_cycle(chain.begin() + index, chain.end());

  assert(whole_cycle.size() != 0);

  --k;

  k %= whole_cycle.size();

  printf("%d", whole_cycle[k] + 1);

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:3: error: 'assert' was not declared in this scope
   55 |   assert(whole_cycle.size() != 0);
      |   ^~~~~~
a.cc:9:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    8 | #include <math.h>
  +++ |+#include <cassert>
    9 |
Language: C++

#include<iostream>
#include<vector>
using namespace std;
using ll=long long;

int main(){
  int n;
  ll k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int> s;
  vector<int> ord(n+1,-1);
  int c=1;l=0;
  int v=1;
  while(ord[v]==-1){
    ord[v]=s.size();
    s.push_back(v);
    v=a[v-1];
  }
  c=s.size()-ord[v];
  l=ord[v];
  if(k<l) cout<<s[k]<<endl;
  else{
    k-=l;
    k%=c;
    cout<<s[l+k]<<endl;
  }
  return 0;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:14:11: error: 'l' was not declared in this scope
   14 |   int c=1;l=0;
      |           ^
Language: Java

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long k = sc.nextLong();

        //System.out.println("n = " + n);
        //System.out.println("k = " + k);

        int[] towns = new int[n];
        for(int i = 0; i < n; i++){
            towns[i] = sc.nextInt();
        }

        int nextPlace = 1;
        ArrayList<Integer> visitedPlaces = new ArrayList<>();
        visitedPlaces.add(nextPlace);

        int reIndex = 0;
        int loopSize = 0;
        int visitCount = 0;
        while(true) {
            nextPlace = towns[nextPlace - 1];
            if (visitedPlaces.contains(nextPlace)) {
                reIndex = visitedPlaces.indexOf(nextPlace);
                loopSize = visitedPlaces.size() - reIndex;
                break;
            }
            visitCount++;
            visitedPlaces.add(nextPlace);
        }

        int rem = (int)((k-visitCount) % loopSize);
        //System.out.println("rem = " + rem);
        //System.out.println("visitCount = " + visitCount);
        //System.out.println("reIndex = " + reIndex);
        //System.out.println("loopSize = " + loopSize);

        //for(int e : visitedPlaces){
        //    System.out.print(e + " ");
        //}
        //System.out.println();

        if(rem == 0) {
            System.out.println(visitedPlaces.get(visitedPlaces.size() - 1));
        }else{
            System.out.println(visitedPlaces.get(reIndex + rem - 1));
        }
    }
}

Compiler output:
Main.java:3: error: cannot find symbol
        Scanner sc = new Scanner(System.in);
        ^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
        Scanner sc = new Scanner(System.in);
                         ^
  symbol:   class Scanner
  location: class Main
Main.java:17: error: cannot find symbol
        ArrayList<Integer> visitedPlaces = new ArrayList<>();
        ^
  symbol:   class ArrayList
  location: class Main
Main.java:17: error: cannot find symbol
        ArrayList<Integer> visitedPlaces = new ArrayList<>();
                                               ^
  symbol:   class ArrayList
  location: class Main
4 errors
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 pii = pair<int,int>;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep cin >> a[i];
    vector<int> s;
    vector<int> ord(n+1,-1);
    int c = 1;
    int l = 0;
    int v = 1;
    while(orb[v] == -1){
        ord[v] = s.size();
        s.push_back(v);
        v = a[v-1];
    }
    c = s.size() - ord[v];
    l = ord[v];
    if(k < l) cout << s[k] << endl;
    else {
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'rep' was not declared in this scope
   11 |     rep cin >> a[i];
      |     ^~~
a.cc:17:11: error: 'orb' was not declared in this scope; did you mean 'ord'?
   17 |     while(orb[v] == -1){
      |           ^~~
      |           ord
Language: C++

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

int main(){
  int n; 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;
  {
    int v=1;
    while(ord[v]==-1){
      ord[v]=s.size();
      s.push_back(v);
      v=a[v-1];
    }
    c=s.size()-ord[v];
    l=ord[v];
  }
  if(k<l)cout<<s[k]<<endl;
  else{
    k-=l;
    k%=c;
    cout<<s[l+k]<<endl;
  }
  return 0;
}

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

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<lli>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

const int mxn = 2e5+10;
lli arr[mxn];
bool visit[mxn];
int find_loop(int cur = 1){
    visit[cur] = true;
    int nx = arr[cur];
    if(visit[nx]) return nx;
    find_loop(nx);
}
int main(){
    ios::sync_with_stdio(false);
    lli n = input(), k = input();
    vector<int> cycle;
    int cur = 1, dist = 0;
    for(int i = 1; i <= n; ++i) arr[i] = input();
    int loop_town = find_loop();
    //dbg(loop_town);
    while(cur != loop_town){
        cur = arr[cur];
        dist++;
        if(dist == k){
            cout << cur;
            return 0;
        }
    }
    //dbg(dist);
    k -= dist;
    cur = arr[loop_town];
    cycle.push_back(loop_town);
    while(cur != loop_town){
        cycle.push_back(cur);  
        cur = arr[cur];  
    }
    //for(int cur: cycle) cout << cur;
    k%=cycle.size();
    cout << cycle[k];

}

Compiler output:
a.cc: In function 'int find_loop(int)':
a.cc:21:5: error: reference to 'visit' is ambiguous
   21 |     visit[cur] = true;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:19:6: note:                 'bool visit [200010]'
   19 | bool visit[mxn];
      |      ^~~~~
a.cc:23:8: error: reference to 'visit' is ambiguous
   23 |     if(visit[nx]) return nx;
      |        ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:19:6: note:                 'bool visit [200010]'
   19 | bool visit[mxn];
      |      ^~~~~
a.cc:24:14: warning: control reaches end of non-void function [-Wreturn-type]
   24 |     find_loop(nx);
      |     ~~~~~~~~~^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<lli>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

const int mxn = 1e5;
int arr[mxn], visit[mxn], ans;
lli dfs(int cur = 1, int len = 1){
    visit[cur] = len;
    int nx = arr[cur];
    if(visit[nx] != 0){
        return len - visit[nx] + 1;
    }
    dfs(arr[cur], len + 1);
}
int main(){
    ios::sync_with_stdio(false);
    lli n = input(), k = input();
    for(int i = 1; i <= n; ++i) arr[i] = input();
    lli cnt = 1, cur = arr[1], ans;
    lli cycle = dfs();
    k = k%cycle;
    while(cnt < k){
        cur = arr[cur];
        cnt++;
    }
    cout << cur;
}

Compiler output:
a.cc: In function 'lli dfs(int, int)':
a.cc:20:5: error: reference to 'visit' is ambiguous
   20 |     visit[cur] = len;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:18:15: note:                 'int visit [100000]'
   18 | int arr[mxn], visit[mxn], ans;
      |               ^~~~~
a.cc:22:8: error: reference to 'visit' is ambiguous
   22 |     if(visit[nx] != 0){
      |        ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:18:15: note:                 'int visit [100000]'
   18 | int arr[mxn], visit[mxn], ans;
      |               ^~~~~
a.cc:23:22: error: reference to 'visit' is ambiguous
   23 |         return len - visit[nx] + 1;
      |                      ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:18:15: note:                 'int visit [100000]'
   18 | int arr[mxn], visit[mxn], ans;
      |               ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
vector<int> a(maxn),vis(maxn,-1);
long long i,j,n,k,f,num,l;
int main(){
  cin>>n>>k;
  for(i=0;i<n;i++) 
    cin>>a[i],a[i]-=1;
  while(vis[f]==-1&&num<k){
    vis[f]=num;cur=a[f];num++;
  }
  k-=vis[f];
  l=num-vis[f];
  for(i=0;i<k%l;i++) 
    f=a[f];
  cout<<f+1;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:16: error: 'cur' was not declared in this scope
   11 |     vis[f]=num;cur=a[f];num++;
      |                ^~~
Language: C++

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

int main(){
  int N,i = 1,roop = 0,current,a = 0; //N:町の数 K:テレポートする回数 roop:ループしているグラフの要素数
  long long K;
  cin >> N >> K;
  N++;
	vector<int> tel(N); //町関係を保存する
  vector<int> check(N,0);
  for(int i = 1;i < N;i++){
    cin >> tel.at(i);
  }
  current = 1;
  while(1){
    if(check.at(current) != 0){
      roop = i  - check.at(current);
      break;
    }else if(check.at(current) == 0){
      a++;
      check.at(current) = i;
    }
    current = tel.at(current);
  i++;
  }
  cout << roop << " " <<  a << endl;
  if(K > a){
  K = (K - a) % roop;
  for(int i = 0;i < K;i++){
    current = tel.at(current);
  }else{
    current = 1;
    for(i = 0;i < K;i++){
      current = tel.at(current);
    }
  }
  cout << current << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:4: error: expected '}' before 'else'
   31 |   }else{
      |    ^~~~
a.cc:27:12: note: to match this '{'
   27 |   if(K > a){
      |            ^
Language: C++

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

int main(){
  int N,i = 1,roop = 0,current,a = 0; //N:町の数 K:テレポートする回数 roop:ループしているグラフの要素数
  long long K;
  cin >> N >> K;
  N++;
	vector<int> tel(N); //町関係を保存する
  vector<int> check(N,0);
  for(int i = 1;i < N;i++){
    cin >> tel.at(i);
  }
  current = 1;
  while(1){
    if(check.at(current) != 0){
      roop = i  - check.at(current);
      break;
    }else if(check.at(current) == 0){
      a++;
      check.at(current) = i;
    }
    current = tel.at(current);
  i++;
  }
  cout << roop << " " <<  a << endl;
  if(K > a){
  K = (K - a) % roop;
  for(int i = 0;i < K;i++){
    current = tel.at(current);
  }else{
    current = 1;
    for(i = 0;i < k;i++){
      current = tel.at(current);
    }
  }
  cout << current << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:4: error: expected '}' before 'else'
   31 |   }else{
      |    ^~~~
a.cc:27:12: note: to match this '{'
   27 |   if(K > a){
      |            ^
a.cc:33:19: error: 'k' was not declared in this scope
   33 |     for(i = 0;i < k;i++){
      |                   ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int doubling(ll k,vector<int> &a){
    const int n=a.size();
    int logK=log2(k)+1;
    vector<vector<int> ret(logK,vector<int>(n));
    rep(i,n) ret[0][i]=a[i];
    rep(j,logK-1){
        rep(i,n){
            ret[j+1][i]=ret[j][ret[j][i]];
        }
    }
    int now=0;
    for(int j=0;k>0;j++){
        if(k&1)now=ret[j][now];
        k=k>>1;
    }
    return now+1;
}

signed main(){
    int n; cin >> n;
    ll k; cin >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    cout << doubling(k,a) << endl;
}


Compiler output:
a.cc: In function 'int doubling(long long int, std::vector<int>&)':
a.cc:31:47: error: template argument 1 is invalid
   31 |     vector<vector<int> ret(logK,vector<int>(n));
      |                                               ^
a.cc:31:47: error: template argument 2 is invalid
a.cc:32:14: error: 'ret' was not declared in this scope; did you mean 'rep'?
   32 |     rep(i,n) ret[0][i]=a[i];
      |              ^~~
      |              rep
a.cc:35:13: error: 'ret' was not declared in this scope; did you mean 'rep'?
   35 |             ret[j+1][i]=ret[j][ret[j][i]];
      |             ^~~
      |             rep
a.cc:40:20: error: 'ret' was not declared in this scope; did you mean 'rep'?
   40 |         if(k&1)now=ret[j][now];
      |                    ^~~
      |                    rep