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

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  int N;
  ll K;
  cin >> N >> K;
  int log_K = floor(log2(K));
  cerr << N << " " << log_K << endl;
  vector<vector<int>> next(log_K + 1, vector<int>(N));

  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
//    cerr << i << " : " << tmp << endl;
    next.at(0).at(i) = tmp-1;
  }

  for(int k = 0; k < log_K; k++){
    for(int i = 0; i < N; i++){
      if(next[k][i] == -1){
        next[k+1][i] = -1;
      } else { 
        next[k+1][i] = next[k][next[k][i]];
        // cerr << k+1 << " " << i << " " << next[k+1][i] << endl;
      }
    }
  }

  int ans = 0;
  for(ll k = log_K; k >= 0; k--){
    if((K>>k)&1){
      ans = next[k][ans];
    }
  }
  cout << ans+1<< endl;

//}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:24: error: expected '}' at end of input
   41 |   cout << ans+1<< endl;
      |                        ^
a.cc:9:11: note: to match this '{'
    9 | int main(){
      |           ^
Language: C

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

int main(void) {
    
    long long N, K;
    scanf("%lld", &N); scanf("%lld", &K);

    int towns[N];
    for (int i=0; i<N; i++) {
        scanf("%d", &towns[i]);
    }

    vector<bool> visited(N+1, false);
    vector<int> visited_locations;
    int location=1;
    int i=0;

    while (1) {
        if (visited[location]) {
            break;
        }

        visited_locations.push_back(location);
        visited[location] = 1;
        location = towns[location - 1];
    }

    vector<int>::iterator it = find(visited_locations.begin(), 
                                    visited_locations.end(), 
                                    location);

    int index = distance(visited_locations.begin(), it);
    cout << index << endl;

    int distance = visited_locations.size() - index;
    cout << distance << endl;

    for (int i=0; i<visited_locations.size(); i++) printf("%d ", visited_locations[i]);
    printf("\n");
    for (int i=0; i<visited.size(); i++) printf("%s ", visited[i] ? "true":"false");
    printf("\n");

    if (K <= index) {
        printf("%d\n", visited_locations[K]);
    } else {
        printf("%d\n", visited_locations[(int) (index + (K - index) % distance)]);
    }

}

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (long long) (n); i++)
using ll=int64_t;
using vi = vector<int>;
using vll = vector<ll>;
/*
    vi v(N);
    for(int i=0;i<N;i++){
        cin>>v.at(i);
    }
*/
/*
iint a,b,c;
cin>>a>>b>>c;
vi price(a);
vector<vector<int>> rikai(a, vector<int>(b))
for(int i=0;i<a;i++){
  cin>>v.at(i);
  for(j=0;j<b+1;j++){cin>>rikai.at(i).at(j);}
  }
  vi rsum(b);
for(int i=0; i<a;i++)
*/


int main(){

int a;
ll b;
cin>>a>>b;
vi tele(a);
for(int i=0; i<a;i++){cin>>tele.at(i);}
int tou ;
for(ll i=0; i<b;i++){tou=tele.at(tou-1;)}
cout <<tou;


}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:39: error: expected ')' before ';' token
   35 | for(ll i=0; i<b;i++){tou=tele.at(tou-1;)}
      |                                 ~     ^
      |                                       )
a.cc:35:40: error: expected primary-expression before ')' token
   35 | for(ll i=0; i<b;i++){tou=tele.at(tou-1;)}
      |                                        ^
Language: C++

#include<bits\stdc++.h>
using namespace std;
vector<int> v;
int main()
{
	long long n,k,s,e,x,i;
	cin>>n>>k;
	int ara[n],vis[n+1]={0};
	for(i=0;i<n;i++){
		cin>>ara[i];
	}
	x=ara[0];
	vis[1]=1;
	while(k>0){
		i=x;
		vis[x]++;
		if(vis[x]==3){
			break;
		}
		if(vis[x]==2){
			v.push_back(x);
		}
		x=ara[x-1];
		k--;
	}
	if(k==0){
		cout<<i<<endl;
	}
	else{
		cout<<v[(k-1)%v.size()]<<endl;
	}
    return 0;
}

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

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

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

typedef long long ll;

int main() {
    ll N,K;
    cin>>N>>K;
    long A[N];
    rep(i, N) cin>>A[i];

    long to = 0;
    vector<long> a(N, -1);
    long i = 0;
    vector<long> c;
    while(a[to] == -1){
        c.push_back(to);
        a[to] = i;
        to = A[to]-1;
        i++;
        //cout << to << endl;
    }
    //cout << "-" << endl;
    for(long b : c){
        //cout << b << endl;
    }
    //cout << "-" << endl;
    K -= a[to];
    //cout << i << a.size() << endl;
    K %= i-a[to];
    //cout << K << endl;
    cout << c[a[to]+K]+1 << endl;
}

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

#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;ll k;
    cin>>n>>k;
    ll *a=new int[n];
    ll *visit=new int[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
        visit[i]=0;
    }
    ll i=0;
    vector<ll>v;
    while(1)
    {
        if(visit[i]==1)
        {
            break;
        }
        else
        {
            visit[i]=1;
            v.push_back(i);
            i=a[i];
        }
    }
    ll start=0;
    for(ll j=0;j<v.size();j++)
    {
        if(v[j]==i)
            break;
        else
            start++;
    }
    ll length=v.size()-start;
    //cout<<length<<" "<<start;
    if(k<=start)
    {
        cout<<v[k];
    }
    else
    {
        k-=start;
        k=k%length;
        cout<<v[start+k]+1;
    }

}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:20: error: cannot convert 'int*' to 'long long int*' in initialization
   11 |     ll *a=new int[n];
      |                    ^
      |                    |
      |                    int*
a.cc:12:24: error: cannot convert 'int*' to 'long long int*' in initialization
   12 |     ll *visit=new int[n];
      |                        ^
      |                        |
      |                        int*
Language: Java


public class Main {
    private static Scanner sc = new Scanner(new BufferedInputStream(System.in));

    public static void main(String[] args) {
        int N = sc.nextInt();
        Long K = sc.nextLong();
        int[] a = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            a[i] = sc.nextInt();
        }

        HashMap<Integer, Integer> mymap = new HashMap<>();
        HashMap<Integer, Integer> mymap2 = new HashMap<>();
        int cur = 1;
        int jump = 0;
        while (mymap.get(cur) == null) {
            mymap.put(cur, jump);
            mymap2.put(jump, cur);
            jump += 1;
            cur = a[cur];
        }
        int temp = mymap.get(cur);

        int num = mymap.size();

        if (K < temp) {
            System.out.println(mymap2.get(K));
        } else {
            int ans = (int) ((K - temp) % (num - temp));
            ans = mymap2.get(ans + temp);
            System.out.println(ans);
        }
    }
}

Compiler output:
Main.java:3: error: cannot find symbol
    private static Scanner sc = new Scanner(new BufferedInputStream(System.in));
                   ^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
    private static Scanner sc = new Scanner(new BufferedInputStream(System.in));
                                    ^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
    private static Scanner sc = new Scanner(new BufferedInputStream(System.in));
                                                ^
  symbol:   class BufferedInputStream
  location: class Main
Main.java:13: error: cannot find symbol
        HashMap<Integer, Integer> mymap = new HashMap<>();
        ^
  symbol:   class HashMap
  location: class Main
Main.java:13: error: cannot find symbol
        HashMap<Integer, Integer> mymap = new HashMap<>();
                                              ^
  symbol:   class HashMap
  location: class Main
Main.java:14: error: cannot find symbol
        HashMap<Integer, Integer> mymap2 = new HashMap<>();
        ^
  symbol:   class HashMap
  location: class Main
Main.java:14: error: cannot find symbol
        HashMap<Integer, Integer> mymap2 = new HashMap<>();
                                               ^
  symbol:   class HashMap
  location: class Main
7 errors
Language: C++

#includde<iostream>
using namespace std;


int main(){
  int cities;
  long times;
  cin >> cities >> times;
  int telemap[cities];
  int pos = 0;
  for(int i = 0; i < cities;i++){
    cin >> telemap[i];
  }  
  
  for(long i = 0; i < times; i++){
    pos = telemap[pos] - 1;
  }
  
  cout << pos << endl;
}

Compiler output:
a.cc:1:2: error: invalid preprocessing directive #includde; did you mean #include?
    1 | #includde<iostream>
      |  ^~~~~~~~
      |  include
a.cc: In function 'int main()':
a.cc:8:3: error: 'cin' was not declared in this scope
    8 |   cin >> cities >> times;
      |   ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #includde<iostream>
a.cc:19:3: error: 'cout' was not declared in this scope
   19 |   cout << pos << endl;
      |   ^~~~
a.cc:19:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:19:18: error: 'endl' was not declared in this scope
   19 |   cout << pos << endl;
      |                  ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | #includde<iostream>
Language: C++

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n;
    ll k;
    cin>>n>>k;
    int a[n],b[n];
    int p=1;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]==1)
            t=i;
    }
    int ans=1;
    while(k--)
    {
        ans=a[p];
        p=ans;
    }
    cout<<ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:13: error: 't' was not declared in this scope
   15 |             t=i;
      |             ^
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();
        int[] a = new int[n];
 
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
 
        // 通った街を記録する配列
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);    // 一つ目の町
 
        // ループの先頭の町がリストの何番目にあるかを格納する変数
        int check = -1;
 
        // 転送先を格納する変数。
        int temp = 1;   // 計算のため初期値１
 
        for (int i = 0; i < k; i++) {
            temp = a[temp-1];   //　転送先設定
            // 訪れた町かチェック
            // 訪れていた場合、ループ前のイントロ部分の長さを求める
            if (list.contains(temp)) {
                check = list.indexOf(temp);
            	break;
            }
            list.add(temp);
        }
        if(check == -1){
            System.out.println(temp);
        }else{
 
        // 合計移動回数をループ長で割った余りを求める
        int std = ((int)(k-check) % (list.size() - check));
 
        System.out.println(list.get((int)(std + check)));
        }
    }
}

Compiler output:
Main.java:4: error: cannot find symbol
        Scanner sc = new Scanner(System.in);
        ^
  symbol:   class Scanner
  location: class Main
Main.java:4: error: cannot find symbol
        Scanner sc = new Scanner(System.in);
                         ^
  symbol:   class Scanner
  location: class Main
Main.java:14: error: cannot find symbol
        ArrayList<Integer> list = new ArrayList<Integer>();
        ^
  symbol:   class ArrayList
  location: class Main
Main.java:14: error: cannot find symbol
        ArrayList<Integer> list = new ArrayList<Integer>();
                                      ^
  symbol:   class ArrayList
  location: class Main
4 errors
Language: Java

import java.util.*;
public class Main {
    public static void main(String[] args){
		import java.util.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		long K = Long.parseLong(s.next());
		int[] A = new int[N + 1];
		for(int i = 1; i < N + 1; i++) {
			A[i] = s.nextInt();
		}
		
		List<Integer> list = new ArrayList<Integer>();
		list.add(Integer.valueOf(1));
		int loopStart = 0;
		int now = 1;
		for(int i = 1; i < N + 1; i++) {
			now = A[now];
			if(list.contains(Integer.valueOf(now))) {
				loopStart = list.indexOf(Integer.valueOf(now));
				break;
			}
			list.add(Integer.valueOf(now));
		}
		
		int count = (int)((K - loopStart)%3);
		
		int size = list.size();
		
		if(K < loopStart) {
			System.out.println(list.get((int)K));
		}else {
			System.out.println(list.get(loopStart + count));
		}
    }
}

Compiler output:
Main.java:4: error: illegal start of expression
		import java.util.*;
		^
Main.java:4: error: <identifier> expected
		import java.util.*;
		                 ^
Main.java:4: error: illegal start of expression
		import java.util.*;
		                  ^
Main.java:5: error: illegal start of expression
public class Main {
^
Main.java:38: error: reached end of file while parsing
}
 ^
5 errors
Language: Java

import java.util.*;
public class Main {
    public static void main(String[] args){
		import java.util.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
        Integer N = s.nextInt();
        long K = Long.parseLong(s.next());
        int[] A = new int[N+1];
        for(int i = 1; i <= N; i++) {
        	A[i] = s.nextInt();
        }
 
        StringBuilder searchLoop = new StringBuilder("@1@");
        int loop = 0;
        int current = 0;
        int index = 1;
        for(int i = 0; i < N; i++) {
        	int candidate = 0;
        	current = index;
        	index = A[index];
        	if((candidate = searchLoop.indexOf("@" + String.valueOf(index) + "@")) > -1) {
        		loop = candidate;
        		break;
        	}
        	searchLoop.append(String.valueOf(index));
        }
 
        long mod = ((K - loop) % (searchLoop.length() - loop));
        int modInt = (int)mod;
        if(K < loop)
        	System.out.println(searchLoop.charAt((int)K));
        else {
        	int strIndex = loop + modInt;
        	int next = 0;
        	while(searchLoop.charAt(strIndex + next) != '@') {
        		System.out.print(searchLoop.charAt(strIndex + next++));
        	}
        	System.out.println();
        }
    }
}
    }
}

Compiler output:
Main.java:4: error: illegal start of expression
		import java.util.*;
		^
Main.java:4: error: <identifier> expected
		import java.util.*;
		                 ^
Main.java:4: error: illegal start of expression
		import java.util.*;
		                  ^
Main.java:5: error: illegal start of expression
public class Main {
^
Main.java:45: error: class, interface, enum, or record expected
}
^
5 errors
Language: Java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Telepoter();
		
	}
	
	
	private static void Telepoter() {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		long K = Long.parseLong(s.next());
		int[] A = new int[N + 1];
		for(int i = 1; i < N + 1; i++) {
			A[i] = s.nextInt();
		}
		
		List<Integer> list = new ArrayList<Integer>();
		list.add(Integer.valueOf(1));
		int loopStart = 0;
		int now = 1;
		for(int i = 1; i < N + 1; i++) {
			now = A[now];
			if(list.contains(Integer.valueOf(now))) {
				loopStart = list.indexOf(Integer.valueOf(now));
				break;
			}
			list.add(Integer.valueOf(now));
		}
		
		int count = (int)((K - loopStart)%3);
		
		int size = list.size();
		
		if(K < loopStart) {
			System.out.println(list.get((int)K));
		}else {
			System.out.println(list.get(loopStart + count));
		}
			
	}

Compiler output:
Main.java:5: error: unnamed classes are a preview feature and are disabled by default.
public static void main(String[] args) {
              ^
  (use --enable-preview to enable unnamed classes)
1 error
Language: Java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;


public class _ATC_D implements Runnable{
    public static void main(String[] args) {
	    new Thread(null, new _ATC_D(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        FastReader fd = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        long n = fd.nextLong();
        long k = fd.nextLong();
        HashMap<Long,Long> data = new HashMap<>();
        long key = 1;
        for(int te = 1; te <= n; te++){
            data.put(key++,fd.nextLong());
        }
        ArrayList<Long> visited = new ArrayList<>();
        long start = 1;
        long current;
        while (!visited.contains(data.get(start))) {
            current = data.get(start);
            start = current;
            visited.add(current);
            k--;
        }
        int temp =  visited.size() - visited.indexOf(data.get(visited.get(visited.size()-1)));
        int index = (int) (k%temp);
        int extra = visited.size()-temp;
        index--;
        out.println(visited.get(index+extra));
        out.close();
    }


    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Compiler output:
Main.java:10: error: class _ATC_D is public, should be declared in a file named _ATC_D.java
public class _ATC_D implements Runnable{
       ^
1 error
Language: C

program free
	implicit none
	integer(8):: n,k,ans,loop,machi=1,count=0,i
	integer(8),allocatable :: a(:),trace(:)
	read (*,*) n,k
	allocate(a(n))
	allocate(trace(n+1))
	do i=1,n+1
    	trace(i)=0
    end do
	read (*,*) a
	do i=1,k
		count=count+1
		if(trace(machi)/=0) exit
		trace(machi)=i
		machi=a(machi)
	end do
	if(count==2) then
		write (*,'(i0)') 1
	else if(count==k) then
		write (*,'(i0)') machi
	else
		loop=count-trace(machi)
		ans=mod(k-trace(machi)+1,loop)
		do i=1,ans
			machi=a(machi)
		end do
		write (*,'(i0)') machi
	end if
	end program free

Compiler output:
main.c:1:1: error: unknown type name 'program'
    1 | program free
      | ^~~~~~~
main.c:2:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'implicit'
    2 |         implicit none
      |         ^~~~~~~~
main.c:2:9: error: unknown type name 'implicit'
main.c:19:26: warning: multi-character character constant [-Wmultichar]
   19 |                 write (*,'(i0)') 1
      |                          ^~~~~~
main.c:21:26: warning: multi-character character constant [-Wmultichar]
   21 |                 write (*,'(i0)') machi
      |                          ^~~~~~
main.c:28:26: warning: multi-character character constant [-Wmultichar]
   28 |                 write (*,'(i0)') machi
      |                          ^~~~~~
Language: C++

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

int main(){
    long n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
        a.at(i)--;//一個ずらしておく
    }

    vector<int> times(n);//訪問回数
    int town = 0;
    for(int i=0; i<k;i++){
        times.at(town)++;
        town = a.at(town);
        if(times.at(town) == 3)break;
    }
    
    int ext=0,t=0;
    rep(i,n) {
        if(times.at(i)==1)ext++;
        if(times.at(i)==2 || times.at(i)==3)t++;
    }
    ext--;
    k=(k-ext)%t;
    if(k)rep(i,k-1)town=a.at(town);
    
    cout << town+1 << endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:31:28: error: expected '}' at end of input
   31 |     cout << town+1 << endl;
      |                            ^
a.cc:5:11: note: to match this '{'
    5 | int main(){
      |           ^
Language: C++

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

#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define ins insert

#define f(i,n) for(int i = 0 ;  i < n ; i ++)
#define f1(i,n) for(int i = 1 ; i<= n ; i++)

#define int long long int

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)





int32_t main()
{
	fast();

	int n,k;
	cin  >>  n >> k;
	int a[n+1];

	map<int,int> mp;

	f1(i,n)
	{
		cin >> a[i];
		m[i] = a[i];
	}
	

	int prev = 1;

	while(k)
	{
		prev = m[prev];
		k--;
	}

	cout<<prev;


		
	return  0 ;
	
}




Compiler output:
a.cc: In function 'int32_t main()':
a.cc:36:17: error: 'm' was not declared in this scope
   36 |                 m[i] = a[i];
      |                 ^
a.cc:44:24: error: 'm' was not declared in this scope
   44 |                 prev = m[prev];
      |                        ^
Language: C

n, k = map(int, input().split())
list = list(map(int, input().split()))
val = list[0]
startcnt = 1
roopList = []
roopList.append(1)
while True:
    roopList.append(val)
    val = list[val - 1]
    startcnt += 1
    if val in roopList:
        break
roopCount = len(roopList) - roopList.index(val)
if k <= startcnt:
    print(roopList[k])
else:
    roopList = roopList[roopList.index(val):]   
    print(roopList[(k - startcnt) % roopCount])


Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | n, k = map(int, input().split())
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:1:4: error: type defaults to 'int' in declaration of 'k' [-Wimplicit-int]
    1 | n, k = map(int, input().split())
      |    ^
main.c:1:8: error: implicit declaration of function 'map' [-Wimplicit-function-declaration]
    1 | n, k = map(int, input().split())
      |        ^~~
main.c:1:12: error: expected expression before 'int'
    1 | n, k = map(int, input().split())
      |            ^~~
main.c:2:1: error: expected ',' or ';' before 'list'
    2 | list = list(map(int, input().split()))
      | ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k;
    cin>>n>>k;
    if(k<n)
    {
        long long int p=1;
        while(k!=0)
        {
            p=a[p];
            k--;
        }
        cout<<p<<endl;
        return 0;
    }


    long long int a[100000];
    a[0]=0;
    for(long long int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    long long int temp=n;
    long long int start=1;
    while(temp!=0)
    {
      //  cout<<"la"<<endl;
        start=a[start];
        temp--;
    }
    long long int ase=k%n;
    while(ase!=0)
    {
        start=a[start];
        ase--;
    }
    cout<<start<<endl;


}


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

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

int main(int argc, const char * argv[]) {
    
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N, 0);
    vector<int> r;
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    int begin=0;
    int end=0;
    int c=0;
    int now=1;
    r.push_back(1);
    while(c<N+1){
        now = A[now-1];
        c++;
        for(int i=0; i<r.size(); i++){
            if(r[i] == now){
                begin=i;
                end=c;
                goto END;
            }
        }
        r.push_back(now);
    }
    
    END:
    
    int cycle = end-begin;
    int add = (K-begin) % cycle;
    if(cycle>K) add = k;
    
    c=0;
    now=1;
    while(c<begin+add){
        now = A[now-1];
        c++;
    }
    
    cout << now << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:41:23: error: 'k' was not declared in this scope
   41 |     if(cycle>K) add = k;
      |                       ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int s[200010];
int f[200010];
vector<int>v;
typedef long long ll;
int main()
{
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>s[i];
    }
    int tmp=1;
    int cnt=0;
    int pos,flag=0;
    while(1)
    {
        if(f[tmp]==2){break;}
        else if(f[tmp]==1){
            v.push_back(tmp);
            f[tmp]=2;
            tmp=s[tmp];
        }else if(f[tmp]==0){
            f[tmp]=1;
            ans=tmp;
            tmp=s[tmp];
            cnt++;
            if(k==cnt){
                flag=1;break;
            }
        }
    }
    if(flag==1){cout<<ans<<endl;return 0;}
    k=k-(cnt-v.size());
    int xxx=(k)%v.size();
    cout<<v[xxx];
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   26 |             ans=tmp;
      |             ^~~
      |             abs
a.cc:34:23: error: 'ans' was not declared in this scope; did you mean 'abs'?
   34 |     if(flag==1){cout<<ans<<endl;return 0;}
      |                       ^~~
      |                       abs
Language: C

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
ll k,n,a[maxn],pos,cnt,v[maxn];
int main() {
	scanf("%lld%lld",&n,&k);
	for(int i=1; i<=n; i++) {
		scanf("%lld",&a[i]);
	}
	pos=1;
	while(k--) {
//		if(pos==a[pos]) break;
		pos=a[pos];
		if(v[pos]) {
			k%=cnt-v[pos];
		}
		cnt++;
		v[pos]=cnt;
	}
	printf("%lld",pos);
	return 0;
}

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

//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

ll a[N],vis[N];
ll cnt = 0;
vll v;
ll index;
int dfs( ll x){
	v.pb(x);
	vis[x] = 1;
	if(vis[a[x]] == 0){
		cnt =  1+ dfs(a[x]);
	}else{
		index = a[x];
		return cnt;
	}
}

int solve() 
{
	//happy coding

	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	v.pb(1);
	vis[1] = 1;
	dfs(a[1]);

	vll ans;
	ll p ;


	for(ll i=0;i<v.size();i++){
		if(v[i]==index) p = i;
	}


	for(ll i=p;i<v.size();i++){
		ans.pb(v[i]);
	}

	//vout(ans);


	ll x = ans.size();
	if(index != 1)
		m = m - index ;

	ll ss = (m%x);
	cout<<ans[ss]<<endl;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Compiler output:
a.cc:32:4: error: 'long long int index' redeclared as different kind of entity
   32 | ll index;
      |    ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:3:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int dfs(long long int)':
a.cc:39:28: error: overloaded function with no contextual type information
   39 |                 index = a[x];
      |                            ^
a.cc: In function 'int solve()':
a.cc:62:24: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and '<unresolved overloaded function type>' to binary 'operator=='
   62 |                 if(v[i]==index) p = i;
a.cc:74:18: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator!='
   74 |         if(index != 1)
      |            ~~~~~~^~~~
a.cc:75:23: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator-'
   75 |                 m = m - index ;
      |                     ~~^~~~~~~
a.cc: In function 'int dfs(long long int)':
a.cc:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
Language: C++


#include <iostream>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    long long k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int f = 1;
    int s = 1;
    do {
        f = a[f];
        s = a[a[s]];
    } while (f != s);

    s = 1;
    while (s != f) {
        s = a[s];
        f = a[f];
        k--;
        if (k == 0) {
            cout << s;
            return;
        }
    }

    int size = 0;
    do {
        s = a[s];
        size++;
    } while (f != s);
    s = 1;
    k %= size;
    while (k--) {
        f = a[f];
    }
    cout << f;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:13: error: return-statement with no value, in function returning 'int' [-fpermissive]
   26 |             return;
      |             ^~~~~~
Language: C++

//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

ll a[N],vis[N];
ll cnt = 0;
vll v;
ll index;
int dfs( ll x){
	v.pb(x);
	vis[x] = 1;
	if(vis[a[x]] == 0){
		cnt =  1+ dfs(a[x]);
	}else{
		index = a[x];
		return cnt;
	}
}

int solve() 
{
	//happy coding

	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	v.pb(1);
	vis[1] = 1;
	dfs(a[1]);

	vll ans;
	ll p ;


	for(ll i=0;i<v.size();i++){
		if(v[i]==index) p = i;
	}


	for(ll i=p;i<v.size();i++){
		ans.pb(v[i]);
	}

	vout(ans);


	ll x = ans.size();
	if(index != 1)
		m = m - index ;

	ll ss = (m%x);
	cout<<ans[ss]<<endl;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Compiler output:
a.cc:32:4: error: 'long long int index' redeclared as different kind of entity
   32 | ll index;
      |    ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:3:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int dfs(long long int)':
a.cc:39:28: error: overloaded function with no contextual type information
   39 |                 index = a[x];
      |                            ^
a.cc: In function 'int solve()':
a.cc:62:24: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and '<unresolved overloaded function type>' to binary 'operator=='
   62 |                 if(v[i]==index) p = i;
a.cc:74:18: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator!='
   74 |         if(index != 1)
      |            ~~~~~~^~~~
a.cc:75:23: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator-'
   75 |                 m = m - index ;
      |                     ~~^~~~~~~
a.cc: In function 'int dfs(long long int)':
a.cc:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
Language: C++

//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

ll a[N],vis[N];
ll cnt = 0;
vll v;
ll index;
int dfs( ll x){
	v.pb(x);
	vis[x] = 1;
	if(vis[a[x]] == 0){
		cnt =  1+ dfs(a[x]);
	}else{
		index = a[x];
		return cnt;
	}
}

int solve() 
{
	//happy coding

	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	v.pb(1);
	vis[1] = 1;
	dfs(a[1]);

	vi ans;
	ll p ;


	for(int i=0;i<v.size();i++){
		if(v[i]==index) p = i;
	}


	for(int i=p;i<v.size();i++){
		ans.pb(v[i]);
	}

	vout(ans);


	ll x = ans.size();
	if(index != 1)
		m = m - index ;

	ll ss = (m%x);
	cout<<ans[ss]<<endl;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Compiler output:
a.cc:32:4: error: 'long long int index' redeclared as different kind of entity
   32 | ll index;
      |    ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:3:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int dfs(long long int)':
a.cc:39:28: error: overloaded function with no contextual type information
   39 |                 index = a[x];
      |                            ^
a.cc: In function 'int solve()':
a.cc:62:24: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and '<unresolved overloaded function type>' to binary 'operator=='
   62 |                 if(v[i]==index) p = i;
a.cc:74:18: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator!='
   74 |         if(index != 1)
      |            ~~~~~~^~~~
a.cc:75:23: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator-'
   75 |                 m = m - index ;
      |                     ~~^~~~~~~
a.cc: In function 'int dfs(long long int)':
a.cc:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
Language: C++


#include <iostream>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    ll k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int f = 1;
    int s = 1;
    do {
        f = a[f];
        s = a[a[s]];
    } while (f != s);
    s = 1;
    while (s != f) {
        s = a[s];
        f = a[f];
    }
    int size = 0;
    do {
        s = a[s];
        size++;
    } while (f != s);
    s = 1;
    while (s != f) {
        s = a[s];
        k--;
    }
    k %= size;
    while (k--) {
        f = a[f];
    }
    cout << f;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:5: error: 'll' was not declared in this scope
    7 |     ll k;
      |     ^~
a.cc:8:17: error: 'k' was not declared in this scope
    8 |     cin >> n >> k;
      |                 ^
Language: C++

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
inline ll read() {
	ll kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
inline void write(ll xx){
	if(xx < 0){putchar('-');xx=-xx;}
	if(xx > 9)write(xx/10);
	putchar(xx%10+'0');
	return;
}
int parent[200005];
int vis[200005];
vector<ll> rest_v;
vector<ll> T_v;
ll T,rest,res;
int n;
ll k;
void find(int x){
	if(vis[x] == 2)
		return;
	if(vis[x] == 0){
		rest++;
		rest_v.push_back(x);
	}
	else if(vis[x] == 1){
		T++;
		T_v.push_back(x);
	}
	vis[x]++;
	find(parent[x]);
}
int main(){
	n = read();
	k = read();
	for(int i = 1;i <= n;i++){
		cin >> parent[i];
	}
	find(1);
	rest -= T;
	if(k <= rest){
		write(rest_v[k);
	}else{
		res = (k - rest + 1) % T;
		if(res == 0){
			res = T;
		}
		cout << res << endl;
		write(T_v[res - 1]);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:31: error: expected ']' before ')' token
   59 |                 write(rest_v[k);
      |                               ^
      |                               ]
Language: C++

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	ll n, a,pos=0,index=0;
	ll k;
	cin >> n >> k;
	set<int>cycle;
	vector<int>city;
	vi tere;
	rep(i, n) {
		cin >> a;
		city.push_back(--a);
	}
	pos = 0;
	for (int s:city) {
		cycle.insert(pos);
		tere.push_back(pos);
		pos = city[pos];
		if (cycle.count(pos))break;
	}
	for (int s : tere) {
		if (s == pos) break;
		else index++;
	}
	if (k <= index) {
		cout << tere[] + 1 << endl;
	}
	else {
		k -= index;
		cout << tere[index + (k % (tere.size() - index))] + 1 << endl;
	}
	return 0;
}


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

#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int N = 2e5+5;
int n,f[N][60];
ll k;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(k);
	for(ri i=1;i<=n;++i) read(f[i][0]);
	for(ri i=1;i<60;++i) for(ri j=1;j<=n;++j) f[j][i]=f[f[j][i-1]][i-1];
	int now=1;
	for(ri i=59;i>=0;--i) if(k&(1ll<<i)) now=f[now][i];
	print(now);
	return 0;
}

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

#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e5 + 10;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
 
int teleport[200005], path[200005];
int main()
{
    int n;
    ll k;
    map<int, int> visit;
    cin >> n>> k;
    for (int i = 1; i <= n;i++)
    {
        cin >> teleport[i];
    }

    ll cur = 1, path_len = 0, circle_entrance, start_to_entrance = 0;
    path[0] = 1;
    while(cur<=n)
    {
        
        if(visit.find(cur)==visit.end())
        {
            visit[cur] = 1;
            path_len++;
            cur = teleport[cur];
            path[path_len] = cur;

        }
        else
        {
            circle_entrance = cur;
            len = path_len;
            for (int i = 0; (i <=len) && (path[i]!=circle_entrance);i++)
                {
                    path_len--;
                    start_to_entrance++;
                }
            break;
        }
    }
    ll ans;
    if(k<=start_to_entrance)
    {
        ans = k;
    }
    else
    ans = k<=start_to_entrance?k:(k-start_to_entrance) % path_len+start_to_entrance ;
    cout << path[ans] << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:13: error: 'len' was not declared in this scope
   44 |             len = path_len;
      |             ^~~
Language: C++

#include <iostream>
#include <vecotr>
using namespace std;
int main()
{
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N+1);
  for(int i = 1; i < N+1; i++){
    cin >> A.at(i);
  }
  
  int c = 1;
  while(K){
    if(K&1) c = A.at(c);
    vector<int> NA(N+1);
    for(int i = 1;i < N+1; i++){
      NA.at(i) = A.at(A.at(i));
    }
    A.swap(NA);
    K >>= 1;
  }
  cout << c << "\n";
}

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

include <stdio.h>

int main(void){
	int n, a[200001]={0}, f[200001]={0}, i, p=1, j, x,pp;
	long k;
	
	scanf("%d", &n);
	scanf("%ld", &k);
	for(i=1; i < n+1; i++){
		scanf("%d", &a[i]);
	}
	
	f[1]=1;
	for(i = 2; i < 200002; i++){
		pp = p;
		p = a[pp];
		if(f[p] == 0){
			f[p] = i;
		}else if(i > k){
			printf("%d", p);
			return 0;
		}else{
			break;
		}
	}
	
	x = i - f[p];
	j = (k - (f[p]-1)) % (i - f[p]);
	
	for(i = 0; i < j; i++){
		pp = p;
		p = a[pp];
	}
	
	printf("%d", p);
	
	return 0;
}

Compiler output:
main.c:1:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
    1 | include <stdio.h>
      |         ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int num,n,k,i,curr_pos,x,cycle_length,left_out,steps,req;
	cin >> n >> num; // Town n turns
	vector<long long int> arr(n+1),vis(n+1,-1); // 1 based indexing
	for(i=1;i<=n;i++)
		cin >> arr[i];

	k=0; // No. of jumps
	curr_pos=1; // Current position
	vis[1]=k++; // initial condition
	while(b<300000)
	{
		x = arr[curr_pos]; // 
		if(vis[x]==-1)
		{
			vis[x]=k++;
			curr_pos = x; 
		}
		else
		{
			cycle_length = k-vis[x];
			left_out = vis[x];
			break;
		}
		b++;
	}
	steps = (num-left_out)%cycle_length;
	req = steps + left_out;
	// cout << " cycle length " << cycle_length << endl;
	// cout << "left_out "<< left_out << endl;
	for(i=1;i<=n;i++)
	{
		if(vis[i]==req)
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:15: error: 'b' was not declared in this scope
   14 |         while(b<300000)
      |               ^
Language: C++

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fi first
#define se second
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, a[N], dp[65][N];
ll k;
int main()
{
	scanf("%d%lld", &n, &k);
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	for(int i=1; i<=n; i++) dp[0][i] = a[i];
	for(int j=1; j<=62; j++)
		for(int i=1; i<=n; i++)
			dp[j][i] = dp[j-1][dp[j-1][i];
	int c = 1;
	for(int j=62; j>=0; j--)
		if((k>>j)&1) c = dp[j][c];
	printf("%d\n", c);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:54: error: expected ']' before ';' token
   25 |                         dp[j][i] = dp[j-1][dp[j-1][i];
      |                                                      ^
      |                                                      ]
Language: C++

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

typedef long long ll;

int N;
ll K;
set<int> S;
vector<int> A, V;

void input_init(void) {
	cin >> N >> K;
	A.resize(N + 1);
	for (int i = 1; i <= N; ++i)
		cin >> A[i];
}

void calcu(void) {
	int cur = 1;
	V.push_back(1);
	S.insert(1);
	while (true) {
		int nxt = A[cur];
		V.push_back(nxt);
		if (S.find(nxt) != S.end())
			break;
		S.insert(nxt);
		cur = nxt;
	}
}

int solve(void) {
	int sz = V.size();
	if (K <= (ll)sz)
		return V[(int)K];
	int lst = V[sz - 1];
	vector<int>::iterator itr;
	itr = find(V.begin(), V.end(), lst);
	int fst_id = distance(V.begin(), itr);
	ll loop_len = (ll)(sz - 1 - fst_id);
	int t = (int)((K - fst_id) % (ll)loop_len);
	return V[fst_id + t];
}

int main(void) {
	input_init();
	calcu();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:40:19: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)'
   40 |         itr = find(V.begin(), V.end(), lst);
      |               ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:40:19: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   40 |         itr = find(V.begin(), V.end(), lst);
      |               ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~