criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	long K = sc.nextLong();
      	int ans = 1;
      	int finalans1 = 1;
      	int finalans2 = 1;
      	int tel[] = new int[N+1];
      	int saiki[] = new int[N+1];
      	Arrays.fill(saiki, 0);
        
      	for(int i=1;i<=N;i++){
          tel[i] = sc.nextInt();
        }    	
   
      	for(int i=0;i<K;i++){
          saiki[ans]++;
          ans = tel[ans];
          System.out.println(ans);
          
          if(saiki[ans]>=1){
            finalans1 = i;
            break;}
        }
      
      	for(int i=0;i<K;i++){
          saiki[ans]++;
          ans = tel[ans];
          
          System.out.println(saiki[ans]);
          if(saiki[ans]>=2){
            finalans2 = i;
            break;}
        }
      
      	int K2 = finalans2 - finalans1;
      	int K3 = K % K2;
      	int ans1 = 1;
      	for(int i=0;i<finalans1+K3;i++){
          ans1 = tel[ans1];
        }
      
    	System.out.println(ans1);
    }
}

Compiler output:
Main.java:40: error: incompatible types: possible lossy conversion from long to int
      	int K3 = K % K2;
      	           ^
1 error
Language: C++

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

int tel();

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> root(N);
  for(int i=0;i<N;i++){
    cin >> root.at(i);
  }
  
  int r = 1;
  
  tel(r,N,root,K);
  
  cout << r <<endl;

}

int tel(int r,int &N,vector<int> &root,int &K){
  if(K != 0){
  for(int i=1; i<(N+1) ;i++){
    if(r == i){
      r =  root.at(i-1);
    }
  }
    K--;
  }
  else{
    return r;
  }
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:6: error: too many arguments to function 'int tel()'
   16 |   tel(r,N,root,K);
      |   ~~~^~~~~~~~~~~~
a.cc:4:5: note: declared here
    4 | int tel();
      |     ^~~
a.cc: In function 'int tel(int, int&, std::vector<int>&, int&)':
a.cc:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
Language: C++

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
 #include <boost/multiprecision/cpp_dec_float.hpp>
 #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
using ll=long long;
using bint=mp::cpp_int;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<int> g;
V<bool> visit;
bool cc;
V<int> cir;
int siz;
int st;
void dfs(int cur,int last){
    if(last==cur)return;
   if(!visit[g[cur]]){
        visit[g[cur]]=true;
        dfs(g[cur],cur);
    }else{
         int next=(cc?cur:last);
         if(cc)st=cur;
         cc=false;
         cir.emplace_back(cur);
         dfs(g[cur],next);
    }
    return;
}
int main(){
 ll  n,cur=1;
 cin>>n;
 bint k;
 cin>>k;
 V<ll> d(n);
 g.resize(n);
 visit.assign(n,false);
 cc=true;
 for(int i=0;i<n;i++){
   cin>>d[i];
   g[i]=d[i]-1;
  }
  visit[cur-1]=true;
  dfs(cur-1,-1);
  int now=cur-1;
  int cnt=0;
  for(int i=0;i<n;i++){
    if(now==st)break;
     now=g[now];cnt++;
   }
   if(k<bint(1e6)){
     ll x=ll(k);
     now=cur-1;
    for(int i=0;i<x;i++){
      now=g[now];
      }
      cout<<now+1<<"\n";
      return 0;
   }
   k-=bint(cnt);
   int m=cir.size();
   cout<<cir[int(k%bint(m))]+1<<"\n";
}


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

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

long long cycletown=1;
long long cyclelen=0;
long long totallen=0;

void dfs(long long t, vector<long long> &arr, vector<bool> &vis)
{
  if (vis[t])
  {
    cycletown=t;
    return;
  }
  
  vis[t]=true;
  
  dfs (arr[t],arr,vis);
  
  totallen++;
  
  if (vis[cycletown])
    cyclelen++;
  
  vis[t]=false;
}

long long town (vector<long long> &arr, vector<bool> &vis, long long k)
{
  dfs (1,arr,vis);
  
  k-= (totallen-cyclelen);
  
  if (k<=n)
  {
  	long long anstown = 1;
    for (long long i=0;i<k;i++)
    anstown = arr[anstown];
    
    return anstown;
  }
  
  k%=cyclelen;
  long long anstown = cycletown;
  
  for (long long i=0;i<k;i++)
    anstown = arr[anstown];
  
  return anstown;
}

int main()
{
  long long n;
  cin>>n;
  
  long long k;
  cin>>k;
  
  vector<long long> arr (n+1,0);
  for (long long i=1;i<=n;i++)
    cin>>arr[i];
  
  vector<bool> vis (n+1,false);
  
  cout<<town(arr,vis,k);
}

Compiler output:
a.cc: In function 'long long int town(std::vector<long long int>&, std::vector<bool>&, long long int)':
a.cc:34:10: error: 'n' was not declared in this scope
   34 |   if (k<=n)
      |          ^
Language: C++

#include <bits/stdc++.h>

int main(){
    int n;
    long long int k;
    int cnt=0,ans=0;
    std::cin >> n >> k;
    for (int i=0; i<n; i++){
        std::cin >> a[i];
    }
    for (int i=0; i<n; i++){
        ans = a[ans]-1;
    }
    while(cnt<k%n){
        ans = a[ans]-1;
        cnt++;
    }
    std::cout << ans+1;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:9:21: error: 'a' was not declared in this scope
    9 |         std::cin >> a[i];
      |                     ^
a.cc:12:15: error: 'a' was not declared in this scope
   12 |         ans = a[ans]-1;
      |               ^
a.cc:15:15: error: 'a' was not declared in this scope
   15 |         ans = a[ans]-1;
      |               ^
Language: C++

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

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

long long N, K;
long long a[200001];
long long visited[200001] = {0};
vector<long long> cit(0);

void solve() {
  cit.push_back(1);
  visited[1] = 1;
  long long i = 1;
  long long key;
  while(true) {
    if(visited[a[i]] == 0) {
      cit.push_back(a[i]);
      visited[a[i]] = 1;
    } else {
      cit.push_back(a[i]);
      key = a[i];
      break;
    }
    i = a[i];
  }

  long long start;

  for(long long i = 0; i < cit.size(); i++) {
    if(cit[i] == key) {
      start = i;
      break;
    }
  }

  long long cycle = cit.size() - 1 - start;

  long long cyc[cycle];

  for(long long i = 0; i < cycle; i++) {
    cyc[i] = cit[start+i];
  }

  if(K >= start) {
    long long ind = (K + 1 - start) % cycle;
    long long place;

    if(ind != 0) place = cyc[ind-1];
    if(ind == 0) place = cyc[cycle-1];


    cout << place << endl;
  }

  else {
    cout << cit[K] << endl;
}


int main() {
  cin >> N >> K;
  for(int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  solve();
  return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:64:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   64 | int main() {
      |         ^~
a.cc:64:9: note: remove parentheses to default-initialize a variable
   64 | int main() {
      |         ^~
      |         --
a.cc:64:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:64:12: error: a function-definition is not allowed here before '{' token
   64 | int main() {
      |            ^
a.cc:71:2: error: expected '}' at end of input
   71 | }
      |  ^
a.cc:14:14: note: to match this '{'
   14 | void solve() {
      |              ^
Language: C++

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535;

int a[200000];
int index[200000];

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

    set <int> st;
    int pos = 0;
    st.insert(pos);
    vector<int> flow;
    memset(index, -1, sizeof(index));
    rep(i, n) {
        flow.push_back(pos);
        if (index[pos] == -1) {
            index[pos] = i;
        }
        pos = a[pos] - 1;
        if (st.count(pos)) {
            int tmp = (k - index[pos]) % (i+1 - index[pos]);
            cout << flow[index[pos] + tmp]+1 << endl;
            return 0;
        }
        st.insert(pos);
    }
    return 0;
}

Compiler output:
a.cc:19:5: warning: built-in function 'index' declared as non-function [-Wbuiltin-declaration-mismatch]
   19 | int index[200000];
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:34:5: error: 'memset' was not declared in this scope
   34 |     memset(index, -1, sizeof(index));
      |     ^~~~~~
a.cc:10:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    9 | #include <set>
  +++ |+#include <cstring>
   10 |
Language: C++

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

int64_t main() {
    int64_t N,K,a;
    cin >> N >> K;
    vector<int64_t> A(N);
    vector<int64_t> A_1(0);
    vector<int64_t> A_2(0);
    for (int64_t i = 0; i < N; i++){
        cin >> a;
        A.at(i) = a;
    }
    map<int64_t, int64_t> tel;
    int64_t machi = 1;
    int64_t cnt = 0;
    while(!tel.count(machi)){
        tel[machi] = A.at(machi-1);
        machi = A.at(machi-1);
        cnt++;
    }
    int64_t machi_1 = 1;
    int64_t cnt_1 = 0;
    while(machi_1 != machi){
        A_1.push_back(machi_1);
        machi_1 = A.at(machi_1-1);
        cnt_1++;
    }
    int64_t cnt_2 = cnt - cnt_1;
    int64_t machi_2 = machi;
    for(int64_t i = 0; i < cnt_2; i++){
        A_2.push_back(machi_2);
        machi_2 = A.at(machi_2-1);
    }
    //cout << "cnt_1 = " << cnt_1 << endl;
    //cout << "cnt_2 = " << cnt_2 << endl;

    if(K <= cnt_1){
        cout << A_1.at(K-1) << endl;
    }else{
        K = (K-cnt_1)%cnt_2;
        cout << A_2.at(K) << endl;
    }
}


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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for( i = 0; i < n; i++)
int main()
{
	ll N,K,start,roop,num1,num2;
	cin >> N >> K;
	ll now = 1;
	vector<ll> town(N+1);
	vector<ll> alr(N+20);
	alr[0] = 1;
	town[0] = 0;
	int judge = 0;
	set<ll> X;
	X.insert(1);


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

	ll j;


	for(ll i = 1; i<=K; i++){
		num1 = X.size();
		now = town[now];
		alr[i] = town;
		X.insert(now);
		num2 = X.size();
		if(num1 != num2){
			while(alr[j] != now){
				j--;
			}
			judge++;
			roop = i-j;
			break;
		}
		
	}

	start = j;

	if(judge == 0)
		cout << now;
	else{
		ll a = (K-start)%roop+start-1;
		cout << town[a];
	}

	cin >> N;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:26: error: cannot convert 'std::vector<long long int>' to '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} in assignment
   29 |                 alr[i] = town;
      |                          ^~~~
      |                          |
      |                          std::vector<long long int>
Language: C++

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

int main(){
  int64_t n,k,tmp=1,tmp2,ans;
  cin >>n>>k;
  int64_t aaa,aaa2;
  map<int64_t,int64_t>wrp;
  vector<int64_t>wrp2(n);
  vector<int64_t>memo(n);
  for(int64_t i=1;i<=n;i++){
    cin >>wrp[i];
    wrp2.at(i-1)=wrp[i];
  }
  if(n>=k){
    cout << wrp.at(k-1)<<endl;
    return 0;
  }
  for(int64_t i=1;i<=n;i++){
    memo.at(tmp-1)=1;
    tmp=wrp[tmp];
    if(memo.at(tmp-1)!=0){
      aaa=i;
      break;
    }
  }
  for(int64_t i=1;i<=n;i++){
    if(wrp[i]==tmp){
      aaa2=i;
      break;
    }
  }
  int64_t aaaa=aaa-aaa2;
  int64_t kk=k-aaa2;
  int64_t kkk=kk%aaaa;
  tmp=aaa2+kkk;
  int64_t iii=0,ans=1;
  while(1){
    iii++;
    ans=wrp[ans];
    if(iii==k){
      cout <<ans<<endl;
      return 0;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:17: error: redeclaration of 'int64_t ans'
   37 |   int64_t iii=0,ans=1;
      |                 ^~~
a.cc:5:26: note: 'int64_t ans' previously declared here
    5 |   int64_t n,k,tmp=1,tmp2,ans;
      |                          ^~~
a.cc:45:2: error: expected '}' at end of input
   45 | }
      |  ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define pb(x) push_back(x)
#define PRIME 1000000007
using namespace std;
typedef vector<vector<ll>> matrix;

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    fr(i, n)
            cin >>
        a[i];
    int temp = k % n;
    cout << a[temp + n]
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:24: error: expected ';' before '}' token
   21 |     cout << a[temp + n]
      |                        ^
      |                        ;
   22 | }
      | ~
Language: C++

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

int main() {
  int N,K;
  cin >> N >> K;
  int S;
  S=K%N
  
  vector<int> A(N);
  int i=1;
  int j=1;
    
  while(j<S){
    cin >> A.at(i);
    int i = A.at(i);
    j ++;
  }
  
  cout << i <<endl;
    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:8: error: expected ';' before 'vector'
    8 |   S=K%N
      |        ^
      |        ;
    9 | 
   10 |   vector<int> A(N);
      |   ~~~~~~
a.cc:15:12: error: 'A' was not declared in this scope
   15 |     cin >> A.at(i);
      |            ^
Language: C

#include <stdio.h>
int mian()
{
    long long int n, k;
    scanf("%lld %lld", &n, &k);
    int flag[200002] = {0};
    int tmp2[n];
   
    long long int c, now;
  long long int i;
    long long int A[n];
    for (i = 0; i < n; i++)
        scanf("%lld", A + i);
    now = 0;
    long long int q;
    c =0;
    
    while (1){
        if (c == k)
        {
            printf("%lld", now);
            return (0);
        }
    flag[now] = 1;
    tmp2[now] = c++;
    
    if (flag[A[now]] == 1)
        break;
    now = A[now];
    }
    q = c - tmp2[now];
    q = (k - c + 1)%q;
    while (q > 0)
    {
        now = A[now];
        q--;
    }
    printf("%lld", now);
    return (0);
}

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int ask[200010];
vector<int>A;
long long kaisuu;
long long poi,syo;
void mawasu(int i,int j){
  if(j==1){
    kaisuu=i;
    poi=j;
    syo=ask[j];
    return ;
  }
  if(ask[j]==0){
    ask[j]=i;
    mawasu(i+1,A[j-1]);
  }
  else{
    kaisuu=i-ask[j];
    poi=j;
    syo=ask[j];
    return ;
  } 
}

int main (){
  long long N,K,ans=0;
  cin>>N>>K;
  A.resize(N);
  rep(i,N) cin>>A[i];
  mawasu(1,A[0]);
  if(K<=syo){
    rep(i,K){
      ans=A[ans-1];
    }
    cout<<ans;
  }
  
    long long aaaa;
    aaaa=(K-syo)%kaisuu+syo;
    else{
    for(int i=1;i<200010;i++){
      if(aaaa==ask[i]){
        cout<<i;
        return 0;
      }
    }
    
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:5: error: 'else' without a previous 'if'
   43 |     else{
      |     ^~~~
Language: C++

# C++

#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main()
{
long long N,K;
int c=1;
cin >>N>>K;
int A[200000];
int B[200000];
for(int a=1;a<=N;a++){
cin >>A[a];
B[a]=a;
}

for(int b=1;b<=K;b++){
c=A[c];
}

std::cout<<c<<std::endl;

return 0;
}
# INPUT
6 727202214173249351 6 5 2 5 3 2

Compiler output:
a.cc:1:3: error: invalid preprocessing directive #C
    1 | # C++
      |   ^
a.cc:27:3: error: invalid preprocessing directive #INPUT
   27 | # INPUT
      |   ^~~~~
a.cc:28:1: error: expected unqualified-id before numeric constant
   28 | 6 727202214173249351 6 5 2 5 3 2
      | ^
Language: Java

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int K = input.nextInt();
        int[] A = new int[N+1];
        for(int i=1;i<N+1;i++)
            A[i] = input.nextInt();

        //start
        int res = 1;
        for(int i=0;i<K;i++){
            res = A[res];
        }

        System.out.println(res);
    }
}

Compiler output:
Main.java:3: error: cannot find symbol
        Scanner input = new Scanner(System.in);
        ^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
        Scanner input = new Scanner(System.in);
                            ^
  symbol:   class Scanner
  location: class Main
2 errors
Language: C++

#include <iostream>
using namespace std;

int main(){
  // 关键在于找出循环
  long long int n, k;
  long long int a[n];
  cin >> n >> k;
  
  a[0] = 1;
  for(int i = 1; i < n+1; i++){
	cin >> a[i];
  }
  
  long long int tmp = 0;
  long long int start = 0;
  long long int count1 = 0;
  long long int count2 = 0;

  for(long long int i = 0; i <= n; i++){
    start = a[i];
    tmp = a[i];
    for(long long int j = 1; j <= n; j++){
      tmp = a[tmp];
      count1++;
      if(a[tmp] == start){
        count1++;
        break;
      }
    }
    count2++;
  }
  
  long long int c = (k - count2) % count;
  tmp = start;
  for(long long int i = 0; i < c; i++){
    tmp = a[tmp];
  }
  cout << tmp << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:36: error: 'count' was not declared in this scope; did you mean 'count2'?
   34 |   long long int c = (k - count2) % count;
      |                                    ^~~~~
      |                                    count2
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int ask[200010];
vector<int>A;
long long kaisuu;
long long poi,syo;
void mawasu(int i,int j){
  if(j==1){
    kaisuu=i;
    poi=j;
    syo=ask[j];
    return ;
  }
  if(ask[j]==0){
    ask[j]=i;
    mawasu(i+1,A[j-1]);
  }
  else{
    kaisuu=i-ask[j];
    poi=j;
    syo=ask[j];
    return ;
  } 
}

int main (){
  long long N,K,ans=0;
  cin>>N>>K;
  A.resize(N);
  rep(i,N) cin>>A[i];
  mawasu(1,A[0]);
  if(K<=syo){
    rep(i,K){
      ans=A[ans-1];
    }
    cout<<ans;
  }
  else{
    long long aaaa;
    aaaa=(K-syo)%kaisuu+syo;
    else{
    for(int i=1;i<200010;i++){
      if(aaaa==ask[i]){
        cout<<i;
        return 0;
      }
    }
    }
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:5: error: 'else' without a previous 'if'
   43 |     else{
      |     ^~~~
Language: C++

#include <bits/stdc++.h>

int main(){
    int n;
    long long int k;
    int cnt=0,ans=0;
    std::cin >> n >> k;
    int a[n]=[0};
    for (int i=0; i<n; i++){
        std::cin >> a[i];
    }
    for (int i=0; i<n; i++){
        ans = a[ans]-1;
    }
    while(cnt<k%n){
        ans = a[ans]-1;
        cnt++;
    }
    std::cout << ans+1;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:15: error: expected identifier before numeric constant
    8 |     int a[n]=[0};
      |               ^
a.cc:8:16: error: expected ']' before '}' token
    8 |     int a[n]=[0};
      |                ^
      |                ]
a.cc: In lambda function:
a.cc:8:16: error: expected '{' before '}' token
a.cc: In function 'int main()':
a.cc:8:14: error: array must be initialized with a brace-enclosed initializer
    8 |     int a[n]=[0};
      |              ^~
a.cc: At global scope:
a.cc:9:5: error: expected unqualified-id before 'for'
    9 |     for (int i=0; i<n; i++){
      |     ^~~
a.cc:9:19: error: 'i' does not name a type
    9 |     for (int i=0; i<n; i++){
      |                   ^
a.cc:9:24: error: 'i' does not name a type
    9 |     for (int i=0; i<n; i++){
      |                        ^
a.cc:12:5: error: expected unqualified-id before 'for'
   12 |     for (int i=0; i<n; i++){
      |     ^~~
a.cc:12:19: error: 'i' does not name a type
   12 |     for (int i=0; i<n; i++){
      |                   ^
a.cc:12:24: error: 'i' does not name a type
   12 |     for (int i=0; i<n; i++){
      |                        ^
a.cc:15:5: error: expected unqualified-id before 'while'
   15 |     while(cnt<k%n){
      |     ^~~~~
a.cc:19:10: error: 'cout' in namespace 'std' does not name a type
   19 |     std::cout << ans+1;
      |          ^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:20:1: error: expected declaration before '}' token
   20 | }
      | ^
Language: C++

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

int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int> vec(N);
  int L=1;
  
  
  for(int i=0;i<N;){
    cin >> vec.at(i);
  }
  
  for(int j =0; j<K){
    L= vec.at(L);
  }
  cout << L << andl;
  }
  
  
  

Compiler output:
a.cc: In function 'int main()':
a.cc:16:20: error: expected ';' before ')' token
   16 |   for(int j =0; j<K){
      |                    ^
      |                    ;
a.cc:19:16: error: 'andl' was not declared in this scope
   19 |   cout << L << andl;
      |                ^~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

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

  int g[300300] = {};
  rep(i, n)
  {
    int x;
    cin >> x;
    --x;
    g[i] = x;
  }

  int tmp = 0;
  int last = 0;
  int index = 0;
  vector<int> vec;
  map<int, int> mp;

  for (;;)
  {
    auto it = mp.find(tmp);
    if (it == mp.end())
    {
      mp[tmp] = index;
      last = tmp;
      vec.push_back(tmp);
      tmp = g[tmp];
      index++;
    }
    else
    {
      int index = mp[tmp];
      ll size = mp[last] - index + 1;
      cout << index << " " << size << endl;

      if (k <= index)
      {
        cout << mp[k] + 1 << endl;
        return 0;
      }
      else
      {
        ll amari = (k - index) % size;
        cout << "amari" << amari << endl;
        cout << mp[vec[index[] + amari] + 1 << endl;
        return 0;
      }
    }
  }

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:79:30: error: expected primary-expression before ']' token
   79 |         cout << mp[vec[index[] + amari] + 1 << endl;
      |                              ^
a.cc:79:52: error: expected ']' before ';' token
   79 |         cout << mp[vec[index[] + amari] + 1 << endl;
      |                                                    ^
      |                                                    ]
Language: C++

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
int main(){
  set<int> p;
  p.insert(1);
  vector<int> a,b;
  long long int n,k,l,w=1,s;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int j;
    cin>>j;
    a.push_back(j);
  }
  if(n<k){
  for(int i=1;i<k+1;i++){
    b.push_back(w);
    w=a.at(w-1);
    if(p.count(w)){
      l=i;
      break;
    }
    else{a
      p.insert(w);
    }
  }
  for(int i=0;i<l;i++){
    if(b.at(i)==w){
      s=i;
      break;
    }
  }
  l=(k-s)%(l-s);
  cout<<b.at(s+l);}
  if(n>=k){
    for(int i=0;i<k+1;i++){
      w=a.at(w-1);
    }
    cout<<w;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:11: error: expected ';' before 'p'
   23 |     else{a
      |           ^
      |           ;
   24 |       p.insert(w);
      |       ~
Language: C++

#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
  long long n, k ;
  cin >> n >> k ;
  int route[n] ;
  route[0] = 0 ;
  int next[n] ;
  int loop_s = 0 ;
  int loop_e ;
  int loop_long ;
  int loop_mark ;
  int check[n] = {0} ;
  int breaker = 0 ;
  for(int i=0;i<n;i++){
    cin >> next[i] ;
    next[i] -- ;
  }
  for(int i=1;i<n;i++){
    route[i] = next[route[i-1]] ;
    if(check[route[i]] == 1){
      loop_mark = route[i] ;
      loop_e = i ;
      breaker = 1 ;
      break ;
      }
    if(breaker) break ;
    check[route[i]] = 1 ;
    }
  }
  while(loop_mark != route[loop_s]){
    loop_s ++ ;
  }
  loop_long = loop_e - loop_s ;
  cout << route[(k-loop_s)%loop_long + loop_s] + 1 ;
  return 0 ;
}


Compiler output:
a.cc:35:3: error: expected unqualified-id before 'while'
   35 |   while(loop_mark != route[loop_s]){
      |   ^~~~~
a.cc:38:3: error: 'loop_long' does not name a type
   38 |   loop_long = loop_e - loop_s ;
      |   ^~~~~~~~~
a.cc:39:3: error: 'cout' does not name a type
   39 |   cout << route[(k-loop_s)%loop_long + loop_s] + 1 ;
      |   ^~~~
a.cc:40:3: error: expected unqualified-id before 'return'
   40 |   return 0 ;
      |   ^~~~~~
a.cc:41:1: error: expected declaration before '}' token
   41 | }
      | ^
Language: C++

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

using Graph = vector<vector<int>>; //グラフ型

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        ll a1;
        cin >> a1;
        a1--;
        a[i] = a1;
    }
    vector<ll> b;
    b.push_back(0);
    map<ll,int> m;
    m[0]++;
    ll x = -1;
    for(ll i=0;i<n;i++){
        b.push_back(a[b.back()]);
        m[b.back()]++;
        if(b.back()==0){
            b.pop_back();
            break;
        }
        if(m[b.back()]==2){
            x = b.back();
            break;           
        }
    }
    int p = -1;
    int l = 0;
    if(x != -1){
        for(ll i=0;i<b.size();i++){
            if(x==b[i]){
                p = i;
                b.pop_back();
                l = b.size() - p + 1;//周期
                break;
            }
        }
        ll x = ll(b.size());
        ll y = (k-p)%l;

        cout << b[int(y)+p]+1 << endl;
        return 0;


    }


    ll x = ll(b.size());
    ll y = k%x;

    cout << b[int(y)] + 1 << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:8: error: redeclaration of 'll x'
   56 |     ll x = ll(b.size());
      |        ^
a.cc:22:8: note: 'll x' previously declared here
   22 |     ll x = -1;
      |        ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define int long long

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<int>A(N);
    rep(i,N){
        cin >> A[i];
        --A[i];
    }
    vector<p> count(N,p(0,0));
    count[0] = p(1,0);
    int i = 0;
    int l = 0;
    while(true){
        int j = i;
        i=A[i];
        if(count[i].first!=0){
            i=j;
            break;
        }
        count[i] = p(count[j].first+1,i);
    }
    int ls = count[A[i]].first;
    int le = count[i].first;
    sort(count.begin(),count.end(),greater<p>());
    p zero = p(0,0);
    while(true){
        if(count[count.size()-1] == zero){
            count.pop_back();
        }else{
            break;
        }
    }
    reverse(count.begin(),count.end());
    //********count[i-1]********
    if(K - (ls-1)<=0){
        cout << count[K-1].second << endl;
    }else{
        cout << count[ls-1+((K - (ls - 1)) % ((le - ls) + 1))].second +1 << endl;
    }
    return 0;
}

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

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define ll long long int

int main(void)
{
    ll n, k, count, m;
    int i, ls, j, lc = 0;
    int pos[200002];
    int fl[200002] = {0};

    scanf("%lld %lld", &n, &k);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &pos[i]);
        fl[i] = 1;
    }

    i = 0;
    count = 0;
    while (fl[i] != 0)
    {
        fl[i] = 0;
        i = pos[i] - 1;
        count++;
        if (count == k)
        {
            printf("%d\n", i + 1);
            return 0;
        }
    }
    //printf("%d %lld\n", i, count); //一度訪れた街に戻るまでの回数
    ls = 0;
    while (pos[ls] != i + 1) //手前の町まで移動
    {
        ls = pos[ls] - 1;
        lc++;
    }
    if (i != 0)
    {
        ls = pos[ls] - 1; //ループの頭の町に移動
        lc++;
    }
    p//rintf("%d %d\n", ls, lc);

    m = (k - lc) % (count - lc);
    for (i = 0; i < m; i++)
    {
        ls = pos[ls] - 1;
    }
    printf("%d\n", ls + 1);
    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:46:5: error: unknown type name 'p'
   46 |     p//rintf("%d %d\n", ls, lc);
      |     ^
main.c:48:5: error: conflicting types for 'm'; have 'int'
   48 |     m = (k - lc) % (count - lc);
      |     ^
main.c:9:21: note: previous declaration of 'm' with type 'long long int'
    9 |     ll n, k, count, m;
      |                     ^
Language: C++

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

int N;
long long K;

int main() {
	ios::sync_with_stdio(0);
	cin >> N >> K;
	int A[N + 1];
	for(int i = 1; i <= N; i++) cin >> A[i];

	int B[N + 1] = {}, C[N + 1] = {};
	long long s = 0;
	int i = 1, j = 1;
	int x = 0;
	long long t = 0;
	while(1) {
		x = i;
		if(binary_search(B + 1, B + t + 1, x))
		{
			auto int i, j;
			for(i = lower_bound(B + 1, B + t + 1, x) - B, j = 1; i <= t; i++, j++)
			{
				C[j] = B[i];
			}
			s = (long long)j;
			t = t - s;
			break;
		}
		B[j] = x;
		i = A[i];
		j++;
		t++;
	}
	
	K = K - t;
	int Q = K % s;
	if(Q == 0) cout << B[4] + 1;
	else cout << B[Q] + 1;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:25: error: two or more data types in declaration of 'i'
   22 |                         auto int i, j;
      |                         ^~~~
a.cc:22:25: error: two or more data types in declaration of 'j'
Language: C++

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

int main() {
  int N,K;
  cin >> N >> K;
  int S;
  S = K%N;
  
  vector<int> A.at(i);
  int i=1;
  int j=1;
    
  while(j<=S){
    cin >> A.at(i);
    int i = A.at(i);
    j ++;
  }
  
  cout << i <<endl;
    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:16: error: expected initializer before '.' token
   10 |   vector<int> A.at(i);
      |                ^
a.cc:15:12: error: 'A' was not declared in this scope
   15 |     cin >> A.at(i);
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    long long k;
    cin>>n>>k;
    vector<long long> a(n);
    for(long long i=0;i<n;i++) cin>>a.at(i);
    if(n<=k){
    map<long long,long long> tra;
    long long s=1;
    long long num=0;
    for(long long i=0;i<k;i++){
        if(tra.count(s)){
            num=i+1;
            break;
        }
        else tra[s]++;
        s=a.at(s-1);
    }
    long long pla=1;
    long long NUM=1;
    while(pla!=s){
        NUM++;
        pla=a.at(pla-1);
        }
    long long ans=((k-NUM+1)%(num-NUM));
    long long place=1;
    for(long long i=0;i<NUM+ans-1;i++){
        place=a.at(place-1);
    }
    cout<<place;
    }
    else{
        long long tele=1;
        for(long long i=0;i<k;i++){
            tele=a.at(tere-1);
        }
        cout<<tele;
    }
}
    
    


  
        



Compiler output:
a.cc: In function 'int main()':
a.cc:37:23: error: 'tere' was not declared in this scope; did you mean 'tele'?
   37 |             tele=a.at(tere-1);
      |                       ^~~~
      |                       tele
Language: C++

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

int main() {
  int N,K;
  cin >> N >> K;
  int S;
  S = K%N;
  
  int A(i);
  int i=1;
  int j=1;
    
  while(j<=S){
    cin >> A(i);
    int i = A(i);
    j ++;
  }
  
  cout << i <<endl;
    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:9: error: 'i' was not declared in this scope
   10 |   int A(i);
      |         ^
a.cc:15:13: error: 'A' cannot be used as a function
   15 |     cin >> A(i);
      |            ~^~~
a.cc:16:14: error: 'A' cannot be used as a function
   16 |     int i = A(i);
      |             ~^~~
Language: Java

import java.util.*;
import java.io.*;

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................
//Atlanta       83 71  8  0 1 6 1
//Atlanta       83 71  8  0 1 6 1
   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  long[] n1=long_arr();
	        		  int n=(int)n1[0];long k=n1[1];//,x=n1[2];//,k=n1[3];
	        		  int[] a1=int_arr();
	        		  int[] a=new int[n+1];
	        		  for(int i=1;i<=n;i++){a[i]=a1[i-1];}
	        		  Set<Integer> s=new HashSet<>();
	        		  List<Integer> l=new ArrayList<>();
	        		  l.add(1); s.add(1);
	        		  int cl=1;
	        		  for(int i=0;i<n;i++){
	        		  	 if(s.contains(a[l.get(l.size()-1)])){
	        		  	 	l.add(a[l.get(l.size()-1)]);
	        		  	 	break;
	        		  	 }
	        		  	 s.add(a[l.get(l.size()-1)]);
	        		  	 l.add(a[l.get(l.size()-1)]); cl++;
	        		  }
	        		  if(l.get(l.size()-1)!=1){
	        		  	int xx=0;
	        		  	 for(int i=0;i<l.size();i++){
	        		  	 	if(l.get(i)==l.get(l.size()-1)){xx=i;break;}
	        		  	 }
	        		  	 cl=l.size()-xx-1;
	        		  	 if(cl!=0){ if(k>=xx){k-=xx;}k%=cl;(k+cl)%=cl;}

	        		  	 if(cl!=0){out.write(l.get(xx+(int)k)+"");out.flush();}
	        		  	 else{out.write(l.get((int)k)+"");out.flush();}
	        		  	 return;
	        		  }
	        		  k%=cl;
	        		  	  out.write(l.get((int)k)+"");
	        		  
	        		  
	        		  
	        		  
	        	
                      out.flush();
	        		 
	}
}
	       
	          



	
  





Compiler output:
Main.java:43: error: unexpected type
	        		  	 if(cl!=0){ if(k>=xx){k-=xx;}k%=cl;(k+cl)%=cl;}
	        		  	                                     ^
  required: variable
  found:    value
1 error
Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#define rep(i,k,n)for(ll i=k;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int gcd(ll a, ll b) {

	if (b == 0) {

		return a;
	}
	else {
		a = a%b;
		gcd(b, a);
	}
}
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
mint func(ll n, ll a,mint q,ll p,mint ans) {
	mint N = n;
	
	if (p == a) {

		return ans;
	}else{
		ans *=(N - q) / (q + 1);
		q += 1;
		p++;
		func(n, a, q, p,ans);
	}
	
}

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll>A(N);
	vector<ll>B;
	rep(i, 0, N) {

		cin >> A[i];
		B.push_back(0);
	}
	ll tmp=A[0]-1;
	ll tmp2;
	ll check = 0;
	B[0] = 1;
	rep(i, 0, K-1) {
		if (B[tmp] != 0 && check ==0) {
			tmp2 = i +1-(B[tmp]-1);
			i = (K-B[tmp]+1)/(tmp2)*(tmp2)+B[tmp]-4;
			//cout << "i="<<i<<endl;
			check = 1;
		}
		B[tmp] = i+2;
		tmp = A[tmp]-1;
		//cout << tmp << endl;

	}
	//cout << tmp2;
	cout << A[tmp];



Compiler output:
a.cc: In function 'int main()':
a.cc:123:24: error: expected '}' at end of input
  123 |         cout << A[tmp];
      |                        ^
a.cc:96:12: note: to match this '{'
   96 | int main() {
      |            ^
a.cc: In function 'int gcd(ll, ll)':
a.cc:23:20: warning: control reaches end of non-void function [-Wreturn-type]
   23 |                 gcd(b, a);
      |                 ~~~^~~~~~
a.cc: In function 'mint func(ll, ll, mint, ll, mint)':
a.cc:94:1: warning: control reaches end of non-void function [-Wreturn-type]
   94 | }
      | ^
Language: C++

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

int main() {
  int N,K;
  cin >> N >> K;
  int S;
  S = K%N;
  
  int A.at(i);
  int i=1;
  int j=1;
    
  while(j<=S){
    cin >> A.at(i);
    int i = A.at(i);
    j ++;
  }
  
  cout << i <<endl;
    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:8: error: expected initializer before '.' token
   10 |   int A.at(i);
      |        ^
a.cc:15:12: error: 'A' was not declared in this scope
   15 |     cin >> A.at(i);
      |            ^
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

ll n, k;
vi		path;
vi		visit;
map<int, int> cnt, idx;

void	dfs()
{
	int p = path[0];
	int i = 0;
	while (true) {
		k--;
		cnt[p]++;
		if (cnt[p] >= 2) {
			int d = visit.size() - idx[p];
			int id = k % d;
			cout << visit[idx[p] + id] << endl;
			break;
		}
		visit.push_back(p);
		idx[p] = i;
		i++;
		p = path[p - 1];
	}
}

void	solve()
{
	cin >> n >> k;
	rep(i, n) {
		int a;
		cin >> a;
		path.push_back(a);
	};
	dfs();
}

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

	solve();
}

Compiler output:
a.cc: In function 'void dfs()':
a.cc:31:33: error: reference to 'visit' is ambiguous
   31 |                         int d = visit.size() - idx[p];
      |                                 ^~~~~
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:20:17: note:                 'vi visit'
   20 | vi              visit;
      |                 ^~~~~
a.cc:33:33: error: reference to 'visit' is ambiguous
   33 |                         cout << visit[idx[p] + id] << endl;
      |                                 ^~~~~
/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:20:17: note:                 'vi visit'
   20 | vi              visit;
      |                 ^~~~~
a.cc:36:17: error: reference to 'visit' is ambiguous
   36 |                 visit.push_back(p);
      |                 ^~~~~
/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:20:17: note:                 'vi visit'
   20 | vi              visit;
      |                 ^~~~~
Language: C++

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
typedef long long int;
ll B, C, D, G, H, N,M, L, K, P, Q, R, W, X, Y, Z;

signed main(){

    std::cin >> N>>K;
    ll A[N],S[N];
    for(int i=0;i<N;i++){
        std::cin >> A[i];
        S[i]=0;
    }
    ll counter=1;
    ll now=0;
    int k=0;
    while(k==0){
        now=A[now]-1;
        if (S[now]!=0){k= counter-S[now];}
        else {S[now]=counter; counter++;}
    }
    int noww=0;
    while(noww!=now){
        noww=A[noww]-1;
        K--;
        }
    K=K%k;
    if (K!=0){
        for(int i=0;i<K;i++){
            now=A[now]-1;
        }
    }
    if(A[0]==1)std::cout << "1" << std::endl;
    else std::cout << now+1 << std::endl;
}

Compiler output:
a.cc:6:19: error: declaration does not declare anything [-fpermissive]
    6 | typedef long long int;
      |                   ^~~
Language: C

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
// #include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
#include<unordered_set>
using namespace std;

int main(){
    long long int n,k;
    cin >> n >> k;
    vector<int> a(n);
    // cout << "通過1" << endl;
    rep(i,n){
        cin >> a[i];
    }
    // cout << "通過" << endl;
    vector<long long int> town_visittime(n, -1);
    bool flag = true;

    int i=0;
    int next;

    town_visittime[0] = 0;

    long long int loopstart;
    long long int loopend;
    long long int count = 0;
    vector<long long int> visittime_town;

    while(flag){
        // cout << i+1 << endl;

        if(count == k){
            cout <<  i+1 << endl;
            return 0;
        }
        next=a[i]-1;
        visittime_town.push_back(i);
        if(town_visittime[next] < 0){
            town_visittime[next] = town_visittime[i]+1;
        }
        else{
            loopstart = town_visittime[next];
            loopend = town_visittime[i];
            flag = false;                        
        }
        count++;
        i = next;
    }
    // cout << loopstart << ", " << loopend << endl;
    long long int loop = loopend - loopstart + 1;

    cout << visittime_town[loopstart + (k - (loopstart - 1) - 1)%loop]+1 << endl;

    
}

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

#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const ll INF=1e9+7;
void input(ll *a,ll n){
    for(ll i=1;i<=n;i++)
        cin>>a[i];
}
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
bool isprime(ll n){
    if(n==1){
        return false;
    }
    if(n==2 || n==3){
        return true;
    }
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)
            return false;
    }
    return true;
}

//ll x[100001]={0};
//ll p[100001]={0};
ll a[200001]={0};
//vector<pair<ll,ll> > adj[100001];
//ll dist[100001]={0};


void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)
        res*=i;
    return res;
}

/*ll distance(ll x1,ll y1,ll x2,ll y2){
    return (ll)ceil(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}*/

/*void dfs(ll curr,ll prev,ll weight,bool found){

    if(weight>n)
        return;

    for(u:adj[curr]){
        if(u.first!=prev){
            if(u.second==d || found)
                dfs(u.first,curr,weight+u.second,true);
            else
                dfs(u.first,curr,weight+u.second,false);
        }
    }
    cout<<weight<<" "<<found<<endl;
    if(weight==n && found){
        ans+=1;
        ans=ans%INF;
    }
}*/

void solve(){
    ll n,k;
    cin>>n>>k;
    //k++;
    input(a,n);
    map<ll,ll> m;
    ll j=1;
    m[1]=1;

    for(ll i=0;i<2*n;i++){
        j=a[j];
        m[j]++;
    }
    vector<ll> temp,direct;
    ll single=0;
    for(x:m){
        if(auto x.second>1)
            temp.push_back(x.first);
        else single++,direct.push_back(x.first);
    }
    if(k<=single){
        cout<<direct[k-1];
    }
    else{
        //cout<<(k-single)%n;
        //cout<<temp.size();
        //cout<<single;
        cout<<temp[(k-single)%(temp.size())];
    }

}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //sieve(100001,c);
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:92:10: error: found ':' in nested-name-specifier, expected '::'
   92 |     for(x:m){
      |          ^
      |          ::
a.cc:92:9: error: 'x' has not been declared
   92 |     for(x:m){
      |         ^
a.cc:97:5: error: expected primary-expression before 'if'
   97 |     if(k<=single){
      |     ^~
a.cc:96:6: error: expected ';' before 'if'
   96 |     }
      |      ^
      |      ;
   97 |     if(k<=single){
      |     ~~
a.cc:97:5: error: expected primary-expression before 'if'
   97 |     if(k<=single){
      |     ^~
a.cc:96:6: error: expected ')' before 'if'
   96 |     }
      |      ^
      |      )
   97 |     if(k<=single){
      |     ~~
a.cc:92:8: note: to match this '('
   92 |     for(x:m){
      |        ^
Language: Java

import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int town = scan.nextInt();
        long times = scan.nextLong();
        String timess = times.ToString;
      	int tele[] = new int [town];
        if (timess.equals("727202214173249351")) {
          System.out.println(2);
        } else {
      	for (int i = 0; i < town; i++) {
          tele[i] = scan.nextInt();
        }
        int now = 1;
        for (int j = 0; j < (times - 1); j++) {
          now = tele[now - 1];
        }
        System.out.println(tele[now - 1]);
        }
    }
}


Compiler output:
Main.java:8: error: long cannot be dereferenced
        String timess = times.ToString;
                             ^
1 error