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

N,K = map(int, input().split())
A = [*map(lambda x:int(x)-1, input().split())]

cnt = [0]*N
pre = 0
for _ in range(N*2):
    cnt[pre] += 1
    now = A[pre]
    pre = now


one = 0
loops = 0
for c in cnt:
    if c == 1: one += 1
    elif c > 1: loops += 1

# k = max(0, K-one) % loops + one
k = max(0, K-one) % loops + min(K, one)

# print('N,K',N,K)
# print('A',A)
# print('cnt',cnt)
# print('one',one,'loops', loops)
# print('K-one',K-one)
# print('min(0, K-one) \% loops',max(0, K-one) % loops)
# print('k',k)

pre = 0
for _ in range(k):
    now = A[pre]
    pre = now

ans = pre + 1
print(ans)


Compiler output:
a.cc:18:3: error: invalid preprocessing directive #k
   18 | # k = max(0, K-one) % loops + one
      |   ^
a.cc:21:3: error: invalid preprocessing directive #print
   21 | # print('N,K',N,K)
      |   ^~~~~
a.cc:22:3: error: invalid preprocessing directive #print
   22 | # print('A',A)
      |   ^~~~~
a.cc:23:3: error: invalid preprocessing directive #print
   23 | # print('cnt',cnt)
      |   ^~~~~
a.cc:24:3: error: invalid preprocessing directive #print
   24 | # print('one',one,'loops', loops)
      |   ^~~~~
a.cc:25:3: error: invalid preprocessing directive #print
   25 | # print('K-one',K-one)
      |   ^~~~~
a.cc:26:3: error: invalid preprocessing directive #print
   26 | # print('min(0, K-one) \% loops',max(0, K-one) % loops)
      |   ^~~~~
a.cc:27:3: error: invalid preprocessing directive #print
   27 | # print('k',k)
      |   ^~~~~
a.cc:1:1: error: 'N' does not name a type
    1 | N,K = map(int, input().split())
      | ^
Language: C++

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

int main(){
  ll n,k;
  vector<ll> v(n);
  cin >> n >> k;
  for(ll i=0;i<n;i++){
    cin >> v[i];
    v[i]--;
  }
  ll now = 0;
  bool can = true;
  for(ll i = 1; i <= k; i++){
    if(c[now] && can){
      can = false;
      ll tmp = abs(c[now] - i);
      i += tmp * ((k - i) / tmp);
    }
    c[now] = i;
    now = v[now];
  }
  cout << now + 1 << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:8: error: 'c' was not declared in this scope
   16 |     if(c[now] && can){
      |        ^
a.cc:21:5: error: 'c' was not declared in this scope
   21 |     c[now] = i;
      |     ^
Language: C++

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

int main(){
  ll n,k;
  vector<ll> v(n);
  cin >> n >> k;
  rep(i,n){
    cin >> v[i];
    v[i]--;
  }
  ll now = 0;
  bool can = true;
  for(ll i = 1; i <= k; i++){
    if(c[now] && can){
      can = false;
      ll tmp = abs(c[now] - i);
      i += tmp * ((k - i) / tmp);
    }
    c[now] = i;
    now = v[now];
  }
  cout << now + 1 << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:7: error: 'i' was not declared in this scope
    9 |   rep(i,n){
      |       ^
a.cc:9:3: error: 'rep' was not declared in this scope
    9 |   rep(i,n){
      |   ^~~
a.cc:16:8: error: 'c' was not declared in this scope
   16 |     if(c[now] && can){
      |        ^
a.cc:21:5: error: 'c' was not declared in this scope
   21 |     c[now] = i;
      |     ^
Language: C++

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

using ll = long long;

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

    set<int> used;     // 探索済みの町を保存
    vector<int> path;  // 探索の順番を格納
    int now = 0;
    while (used.count(now) == 0) {  // 探索済みの町に到達するまで
        path.push_back(now);
        used.insert(now);
        now = A[now];
    }

    int s = find(ALL(path), now) - path.begin();  // s: ループする最初の部分に到達するまで

    if (K < s) {  // ループ部分に到達しない時
        cout << path[K] + 1 << endl;
        return 0;
    } else {  // ループ部分に到達する時
        K -= s;
        K %= (int)path.size() - s;
        cout << path[s + K] + 1 << endl;
        return 0;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:18: error: 'ALL' was not declared in this scope
   24 |     int s = find(ALL(path), now) - path.begin();  // s: ループする最初の部分に到達するまで
      |                  ^~~
Language: C++

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

int main()
{
    int n;
    cin>>n;
    ll k;
    cin>>k;
    vector<int>v(n);
    for (int i=0;i<n;i++)
        cin>>v[i];
    p.push_back(0);
    map<ll,ll>mp;
    mp[0]=1;
    ll no=0;
    while(k>0)
    {
        no=v[no]-1;
        if (mp[no]!=0)
        {
            ll cy=p.size()-mp[no]+1;
            ll f=k%cy;
            if (f==0)
                f=cy;
            cout<<p[mp[no]+f-2]+1;
            return 0;
        }
        k--;
        p.push_back(no);
        mp[no]=p.size();
    }
    cout<<no+1;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:5: error: 'p' was not declared in this scope
   14 |     p.push_back(0);
      |     ^
Language: C++

#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

  vector<ll> score;
  map<ll,ll> m;
  ll tmp = 1;

  /*
  ll minans = 1;
  if(K < 1e6){
    rep(i,K){
      minans = a[minans - 1];
    }
    cout << minans << endl;
    return 0;
  }
  */
  ll ka = K;
  while(1){
    ka --;
    tmp = a[tmp - 1];
    if(ka == 0){
      cout << tmp << endl;
      return 0;
    }
    // tmpは新たな数字
    score.pb(tmp);
    m[tmp]++;
    if(m[tmp] > 1) break;
  }
  // scoreができている
  ll rank = score[score.size() - 1];
  score.pop_back();
  // cout << rank << endl;
  ll start = 0;
  rep(i,score.size()){
    if(score[i] == rank) start = i;
  }
  // cout << start << " " << score.size() << endl;

  ll cir = score.size() - start;

  // startは操作後の回数を保存している 1-index
  // startが1のとき残り操作は
  ll mar = (K - start) % cir;
  // cout << mar << endl;
  if(ma == 0) cout << score.back() << endl;
  else cout << score[start + mar - 1] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:82:6: error: 'ma' was not declared in this scope; did you mean 'mar'?
   82 |   if(ma == 0) cout << score.back() << endl;
      |      ^~
      |      mar
Language: C++

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, t = 1;
    long long k, cnt;
    vector<int> tv;

    cin >> n >> k;
    cnt = k;

    int tt[n + 1];

    for (int i = 1; i <= n; ++i) cin >> tt[i];

    while (cnt-- && !count(tv.begin(), tv.end(), t)) {
        tv.push_back(t);
        t = tt[t];
    }

    if (!cnt) {
        cout << t;
        return 0;
    }

    int dist = distance(tv.begin(), find(tv.begin(), tv.end(), t)));
    k -= dist;
    k %= tv.size() - dist;

    cout << *(tv.begin() + dist + k);

    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:22:22: error: 'count' was not declared in this scope; did you mean 'cnt'?
   22 |     while (cnt-- && !count(tv.begin(), tv.end(), t)) {
      |                      ^~~~~
      |                      cnt
a.cc:32:41: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)'
   32 |     int dist = distance(tv.begin(), find(tv.begin(), tv.end(), t)));
      |                                     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
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:32:41: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   32 |     int dist = distance(tv.begin(), find(tv.begin(), tv.end(), t)));
      |                                     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++


#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N , K; cin >> N >> K;
  vector<ll> a(N);
  rep(i,N){
    ll v; cin >> v; v--;
    a[i] = v;
  }

  vector<ll> reach;
  ll tmp = 0;
  map<ll, ll> m;
  // reachの作成
  reach.pb(0);
  m[0]++;
  while(1){
    tmp = a[tmp];
    m[tmp]++;
    reach.pb(tmp);
    if(m[tmp] > 1) break;
  }

  ll si = reach.back();
  reach.pop_back();
  ll start;
  rep(i,reach.size()){
    // startの探索
    if(reach[i] == si){
      start = i;
      break;
    }
  }

  // startからlastを繰り返す
  ll cir = reach.size() - start;

  // rep(i,reach.size()) cout << reach[i] << " ";
  // cout << endl;
  // cout << start << " " << reach.size() << endl;

  ll mar = (K - start) % cir;
  cout << reach[start + mar] + 1 << endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:13: error: 'cin' was not declared in this scope
   35 |   ll N , K; cin >> N >> K;
      |             ^~~
a.cc:12:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
   11 | #include<bitset>
  +++ |+#include <iostream>
   12 | using namespace std;
a.cc:74:3: error: 'cout' was not declared in this scope
   74 |   cout << reach[start + mar] + 1 << endl;
      |   ^~~~
a.cc:74:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int64_t mod(int64_t val, int64_t m){
    int64_t res = val%m;
    if(res<0) res+=m;
    return res;
}

int main(){
    int64_t k;
    int n,rev,loop; cin >> n >> k;
    vi a(n);
    for(int ix=0;ix<n;ix++){ cin >> a.at(ix); a.at(ix)--; }
    
    int cnt=0;
    map<int,int> ss; int pos = 0; ss[pos] = 0;
    while(true){
        pos = a.at(pos);
        cnt++;
        if(!ss.count(pos)) ss[pos] = cnt;
        else{
            loop = cnt - ss.at(pos);
            break;
        }
    }
    int tale = cnt-loop;
    if(k < tale){
      rev=k; pos=0;
      for(int ix=0;ix<rev;ix++) pos=pos.at(pos);
    }
    else{
      rev = mod((k%loop) - ((int64_t)tale%loop),loop);
      for(int ix=0;ix<rev;ix++){
        pos = a.at(pos);
      }
    }
    cout << pos+1 << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:41: error: request for member 'at' in 'pos', which is of non-class type 'int'
   32 |       for(int ix=0;ix<rev;ix++) pos=pos.at(pos);
      |                                         ^~
Language: C++

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

int main(){
  long long int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  vector<int> b(0);
  vector<int> kanri(n,-1);
  int y=0;//現在地-1
  
  while(kanri.at(y)==-1){
    kanri.at(y)=b.size();
    b.push_back(y+1);
    y=a.at(y)-1;
  }
  y=kanri.at(y);//yは例外の数
  
  else cout << b.at((k-y)%(b.size()-y)+y) << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:3: error: 'else' without a previous 'if'
   22 |   else cout << b.at((k-y)%(b.size()-y)+y) << endl;
      |   ^~~~
Language: C

#include <stdio.h>
int main()
{
  int i,j=1,a[100000],n,s,b[10000],x,k;
  long long m;
  scanf("%d %lld",&n,&m);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  s=a[0];
  b[0]=1;
  for(k=0;k<m-1;k++)
  {
    b[j]=s;
    s=a[s-1];
    for(i=0;i<j;i++)
    {
        if(s==b[i])
        {
            x=i;
           // printf("%d\n",i);
              printf("%d\n",b[(m-i)%(j-i+1)+i]);
            return 0;
        }
    }
    j++;
  }
  printf("%d\n",s);
  return 0;

Compiler output:
main.c: In function 'main':
main.c:28:3: error: expected declaration or statement at end of input
   28 |   return 0;
      |   ^~~~~~
Language: C

#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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


	ll N = 0, K = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	while ((c = getchar_unlocked()) >= '0') K = K * 10 + c - '0';

	int A[200001];
	int D2[200001];
	rep1(i, N) A[i] = getint();

	int d = 0;
	int p = 1;
	while (A[p] > 0) {
		D2[d] = p;
		int tugi = A[p];
		A[p] = -d++;
		p = tugi;
	}
	if (K > -A[p]) {
		ll k = K + A[p];
		k %= d + A[p];
		K = -A[p] + k;
	}
	printf("%d", D2[K]);

	Would you please return 0;
}

Compiler output:
main.c:4:9: fatal error: cstdio: No such file or directory
    4 | #include<cstdio>
      |         ^~~~~~~~
compilation terminated.
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();
    	Map<Integer,Integer> teleport = new HashMap<>();
    	Map<Integer,Long> history = new HashMap<>();
    	for(int i = 1 ; i <= n; i++){
    		teleport.put(i, sc.nextInt());
    	}
    	long i;
    	int now = 1;
    	boolean flag = false;
    	for(i = 0; i <= k; i++){
    		if(history.containsKey(now)){
    			flag = true;
    			break;
    		}
    		history.put(now, i);
    		now = teleport.get(now);
    	}
    	if(flag)
    		long pastTime = history.get(now);
    		i = pastTime + (k - pastTime) % (i - pastTime);
    	}
    	for(int p : history.keySet()){
    		if(history.get(p) == i){
    			System.out.println(p);
    			return;
    		}
    	}
    }
}

Compiler output:
Main.java:25: error: variable declaration not allowed here
    		long pastTime = history.get(now);
    		     ^
Main.java:28: error: illegal start of type
    	for(int p : history.keySet()){
    	^
Main.java:28: error: ';' expected
    	for(int p : history.keySet()){
    	         ^
Main.java:28: error: <identifier> expected
    	for(int p : history.keySet()){
    	                          ^
Main.java:28: error: ';' expected
    	for(int p : history.keySet()){
    	                            ^
Main.java:35: error: class, interface, enum, or record expected
}
^
6 errors
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using ll=long long;
using namespace std;
int main(){
    int N;
    ll K;
    cin>>N>>K;
    
    vector<int> A(N);
    rep(i,N){
        int a;
        cin>>a;
        A[i]=a-1;
    }
    
    int slen,llen;
    vector<bool> seen(N+1,false); // seen[i] := i番目の街を訪れたか
    vector<int> ord;              // ord[i]  := i番目に訪れた街
    {
        
        int cur=0; // cur := 現在の街
        while(seen[cur]==-1){
            seen[cur]=s.size();
            ord.push_back(cur);
            cur=A[cur];
        }
        slen=s.size()-ord[cur];
        llen=ord[cur];
    }
    
    if(K<slen)cout<<ord[K]+1<<endl;
    else {
        K-=slen;
        K%=llen;
        cout<<ord[slen+K]<<endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:23: error: 's' was not declared in this scope
   24 |             seen[cur]=s.size();
      |                       ^
a.cc:28:14: error: 's' was not declared in this scope
   28 |         slen=s.size()-ord[cur];
      |              ^
Language: Java

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer town = sc.nextInt();
		Long teleport = sc.nextLong();

		List<Integer> lists = new ArrayList<Integer>(town);
		for(int i = 0; i < town; i ++) {
			lists.add(sc.nextInt() - 1);
		}

		List<Integer> teleLists = new ArrayList<Integer>(town);
		Integer nowTown = 0;
		Integer nextTown = 0;
		teleLists.add(0);
		while(true) {
			nextTown = lists.get(nowTown);
			if(teleLists.contains(nextTown)) {
				break;
			}
			teleLists.add(nextTown);
			nowTown = nextTown;
		}

		Integer roopStart = teleLists.indexOf(nextTown);
		Long num1 = teleport - roopStart;
		
		Integer roopRemain = (int) (num1 % (teleLists.size() - roopStart));
		Integer result = teleLists.get(roopStart + roopRemain) + 1;
		
		System.out.println(result);
	}
}

Compiler output:
Main.java:3: error: cannot find symbol
		Scanner sc = new Scanner(System.in);
		^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
		Scanner sc = new Scanner(System.in);
		                 ^
  symbol:   class Scanner
  location: class Main
Main.java:7: error: cannot find symbol
		List<Integer> lists = new ArrayList<Integer>(town);
		^
  symbol:   class List
  location: class Main
Main.java:7: error: cannot find symbol
		List<Integer> lists = new ArrayList<Integer>(town);
		                          ^
  symbol:   class ArrayList
  location: class Main
Main.java:12: error: cannot find symbol
		List<Integer> teleLists = new ArrayList<Integer>(town);
		^
  symbol:   class List
  location: class Main
Main.java:12: error: cannot find symbol
		List<Integer> teleLists = new ArrayList<Integer>(town);
		                              ^
  symbol:   class ArrayList
  location: class Main
6 errors
Language: C

sdusing namespace std;
#include <bits / stdc ++. h>
#define int long long
#define pb push_back 
#define IOS ios_base :: sync_with_stdio (0); cin.tie (0); cout.tie (0)
#define ff first
#define ss second
#define all (x) x.begin (), x.end ()
#define repa (i, a, b) for (int i = a; i <= b; i ++)
#define repd (i, b, a) for (int i = b; i> = a; i--)
#define endl "\ n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
        
    int n,k;
    cin >> n >> k;
    int ar [n + 1];
    repa (i, 1, n)
        cin >> ar [i];
    bool vis [n + 1] = {0};
    int cur = 1;
    vector <int> sequence;

    while (! vis [cur])
    {
        sequence.pb (cur);
        vis [cur] = true;
        cur = ar [cur];
    }
    int lst = cur;
    sequence.pb (cur);

    if (k <= sequence.size ()-1)
        cout << sequence [k] << endl;
    else
    {
        k- = sequence.size ();

        vector <int> recur;
        bool found = false;
        for (auto it: sequence)
        {
            if (found)
                recur.pb (it);

            if (it == lst)
            {
                found = true;
                continue;
            }
        }
        cout << recur [k% (recur.size ())] << endl;
    }

}


Compiler output:
main.c:1:1: error: unknown type name 'sdusing'
    1 | sdusing namespace std;
      | ^~~~~~~
main.c:1:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'std'
    1 | sdusing namespace std;
      |                   ^~~
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>

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1e9;

const ll INF = 1LL << 60;

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 dp[200005][60];
  rep(i,n){cin>>dp[i][0];dp[i][0]--;}
  for(int j=1;j<59;j++)rep(i,n)dp[i][j]=dp[dp[i][j-1]][j-1];
  int ans=0;
  
  rep(i,60)if(k & (1LL<<i)){
    ans=dp[ans][i]
  }
  cout<< ans+1;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:30:19: error: expected ';' before '}' token
   30 |     ans=dp[ans][i]
      |                   ^
      |                   ;
   31 |   }
      |   ~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 2e5 + 7;
int n;
map <int, int> pos;
map <int, bool> vis;
int seq[maxx];
LL k;

int main() {
	scanf("%d %lld", &n , &k);
	for(int i = 1; i <= n; i++) scanf("%d", &pos[i]);
	int nxt = 1;
	int t = -1;
	seq[++t] = nxt;
	for(int i = 1; ;) {
		if(vis[i]) break;
		vis[nxt] = 1; //先打标记
		nxt = pos[i]; //更新nxt
		seq[++t] = nxt;
		i = nxt; //替换
	}
	//seq[t]是第一次重复的数字
	//定位第一次出现时的位置fir
	int x = 0;
	for(int i = 0; i < t; i++) {
		if(seq[i] == seq[t]) {
			x = i;
			break;
		}
	}
	//cout << x << endl;
	k -= (LL)x;
	LL id = k % ((LL)t - (LL)x)
	cout << seq[x + id] << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:9: error: expected ',' or ';' before 'cout'
   36 |         cout << seq[x + id] << endl;
      |         ^~~~
Language: C++

#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#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 ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n,k; cin>>n>>k;
  vector<ll> a(n);
  rep(i,n) cin >>a[i];
  map<ll,ll> mp;
  mp[0]++;
  ll key=0;
  ll time=0;
  ll loop=0;
  vector<ll> vec;
  rep(i,2*n){
    mp[a[key]]++;
    if(mp[a[key]]==1){
    time++;
    }
    if(mp[a[key]]==2) {
    loop++;
    vec.push_back(a[key]);
    }
    
    key=a[key]-1;
  }
   if( (k-time)%loop!=0)　cout <<vec[(k-time)%loop-1]<<endl;
  else cout <<vec[loop-1]<<endl;
}
    


Compiler output:
a.cc:42:25: error: extended character 　 is not valid in an identifier
   42 |    if( (k-time)%loop!=0)　cout <<vec[(k-time)%loop-1]<<endl;
      |                         ^
a.cc: In function 'int main()':
a.cc:42:25: error: '　cout' was not declared in this scope
   42 |    if( (k-time)%loop!=0)　cout <<vec[(k-time)%loop-1]<<endl;
      |                         ^~~~~~
Language: C++

#include<bits/stdc++.h>

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

bool visited[200005];
int a[200005],visitedTime[200005],timeVisited[200005];

int main()
{
    FAST();
    LL k;
    int i,n,x=1,y,cnt=0;
    cin >> n >> k;
    for(i=1;i<=n;i++)cin >> a[i];
    while(k > 0)
    {
        if(visited[x])
        {
            y=cnt-timeVisited[x]+1;
            ++k;
            if(k%y == 0)cout << visitedTime[cnt];
            else cout << visitedTime[timeVisited[x]+(k%y)-1];
            return 0;
        }
        --k;
        visited[x]=true;
        timeVisited[x]=++cnt,visitedTime[cnt]=x,x=a[x];
    }
    cout << x;
    return 0;
}


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

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

long long int main() {
  long long int N;
  long long int K;

  cin >> N >> K;
  //cout << K;
  vector <long long int> A(N),a(N+1,0),b(N,-1);


  for(long long int i=0; i<N; i++){
    //cin >> A.at(i);
    A.at(i)=i+2;
    A.at(N-1)=1;
  }



  for(long long int i=0; i<N+1; i++){
    if(i==0){
      a.at(i)=1;
    }
    else{
      a.at(i)=A.at(a.at(i-1)-1);
    }
    //cout << a.at(i) << " " ;
  }
  //cout << endl;

  /*
  for(long long int i=0;i<N;i++){
    cout << b.at(i) << " ";
  }
  cout << endl;
  */

  long long int num=0,count=0,cycle=N;
  while(b.at(a.at(num)-1)==-1&&num<N+1){
    b.at(a.at(num)-1)=num;
    num++;
  }

  /*
  for(long long int i=0;i<N;i++){
    cout << b.at(i) << " ";
  }
  cout << endl;
  */

  count = b.at(a.at(num)-1);
  cycle = num-b.at(a.at(num)-1);

  //cout << count << " " << cycle <<"asdfk"<<endl;
  K -= count;
  K %= cycle;


  cout << a.at(count+K)<<endl;

  //cout << goal << endl;

}


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

#include <iostream>
#include <map>

using namespace std;

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

    // map<Town, index>
    map<int, int> passed;
    int cur = 1, loop_start = 0, loop_end = 0;
    // set 0 th
    passed[cur] = 0;
    // set i th
    for (int i=1; i<N; i++) {
        cur = A[cur];
        if (passed.find(cur) != passed.end()) {
            loop_start = passed[cur];
            loop_end = i - 1;
            break;
        }
        passed[cur] = i;
    }
    
    if (loop_end == 0) {
        loop_start = passed[A[cur]];
        loop_end = N - 1;
    }

    if ((int(K) <= loop_start) {
        for (auto it = passed.begin(); it != passed.end(); ++it) {
            if (it->second == (int)K) {
                cout << it->first;
                return 0;
            }
        }
    }

    int  r = (K - (loop_start - 1)) % (loop_end - loop_start + 1);
    int index = (loop_start - 1) + r;
    if (r == 0) {
        index += loop_end - loop_start + 1;
    }
    for (auto it = passed.begin(); it != passed.end(); ++it) {
        if (it->second == index) {
            cout << it->first;
            return 0;
        }
    }

    return -1;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:31: error: expected ';' before '{' token
   36 |     if ((int(K) <= loop_start) {
      |                               ^~
      |                               ;
a.cc:45:66: error: expected ')' before ';' token
   45 |     int  r = (K - (loop_start - 1)) % (loop_end - loop_start + 1);
      |                                                                  ^
      |                                                                  )
a.cc:36:8: note: to match this '('
   36 |     if ((int(K) <= loop_start) {
      |        ^
a.cc:46:36: error: 'r' was not declared in this scope
   46 |     int index = (loop_start - 1) + r;
      |                                    ^
Language: C++

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

int main(){
    long long N,x=1;
    long long K;
    cin>>N>>K;
    long long A[N],B[N];
    for (long int i=0;i<N;i++){
        cin>>A[i];
        B[i]=-1;
    }
    B[0]=0;
    long long c,dd,y;
    bool f=True;
    for (long int i=0;i<=N;i++){
        if (i==K+1){
            f=False;
            y=x
            break;
        } 
        x=A[x-1];
        if (B[x-1]!=-1){
             c=i+1-B[x-1];
             dd=i+1;
            break;
        }
        B[x-1]=i+1;
    }
    long long ans;
    ans=(K-dd)%c;
    for (long int i=0;i<ans;i++){
        x=A[x-1];
    }
    if (f=True)    cout<<x<<endl;
    else cout<<y<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:12: error: 'True' was not declared in this scope
   21 |     bool f=True;
      |            ^~~~
a.cc:24:15: error: 'False' was not declared in this scope
   24 |             f=False;
      |               ^~~~~
a.cc:25:16: error: expected ';' before 'break'
   25 |             y=x
      |                ^
      |                ;
   26 |             break;
      |             ~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define watch(x) cerr<<(#x)<<" is "<<x<<nl;
#define fi(a,b) for(ll i=a;i<b;i++)
#define fj(a,b) for(ll j=a;j<b;j++)
#define mp make_pair
#define ff first 
#define ss second
#define all(v) (v).begin(),(v).end()
#define pb(i) push_back(i)
#define mem(v,a) memset((v),a,sizeof(v));
#define mll map<ll,ll>
#define vll vector<ll>
#define nl endl
const long long inf=1e18+1e17;
const  int mod=998244353;
const ll  N=600032LL;
ll fac[N+2]; ll inv[N+2];

ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;if(a<0)a+=mod;return a;} 

ll mul(ll a,ll b){return ((a)1LL(b))%mod;}

ll power(ll a,ll n){ll res=1;while(n){if(n&1){
res=mul(res,a);} n>>=1,a=mul(a,a);}return res;}

ll fact(ll n){
	if(n==0||n==1)
		return 1;
	return n*fact(n-1);
}

void solve(){
	ll n,k;cin>>n>>k;
	vll v(n);
	fi(0,n)cin>>v[i];
	ll ar[n];memset(ar,0,sizeof(ar));
	ll i=0;
	for(;ar[i]==0;i=v[i]-1){	k--;ar[i]++;
		fi(0,n)cerr<<ar[i]<<" ";
		cerr<<endl;}
		cerr<<endl;
	ll len=1;
	for(ll j=v[i]-1;j!=i;j=v[j]-1){	len++;cerr<<j+1<<" ";}
	k=k%len;
	
	cerr<<endl<<len<<" "<<i<<" "<<k<<endl;
	while(k-->0)	i=v[i]-1;
	cout<<i+1;
}
int main(){
	ll t;t=1;;
	while(t--){
		//double p=1.0;p-=1;
		//printf("%.10lf",p);
		solve();
		//cout<<binfind(4);
	}
	return 0;
}

Compiler output:
a.cc: In function 'long long int mul(long long int, long long int)':
a.cc:23:30: error: expected ')' before numeric constant
   23 | ll mul(ll a,ll b){return ((a)1LL(b))%mod;}
      |                          ~   ^~~
      |                              )
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main() {
    sync_with_stdio(false);
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i=0;i<N;i++) {
        cin >> A[i];
        A[i]--;
    }
    vector<ll> loop(N+1);
    loop[0] = 0;
    for (int i=0;i<N;i++){
        loop[i+1] = A[loop[i]];
    }
    if (N>=K) {
        cout << loop[K] + 1 << "\n";
        return 0;
    }
    vector<ll> stop(N,-1);
    stop[0] = 0;
    ll start,end;
    for (int i=0;i<=N;i++){
        if (stop[loop[i]] == -1) {
            stop[loop[i]] = i+1;
        } else {
            start = stop[loop[i]];
            end = i+1;
        }
    }
    K -= start;
    ll res = K % (end - start);
    ll ans = loop[start+res]+1;
    cout << ans << "\n";
}

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

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

int main() {
  long long N,K;
  cin >> N >> K;
  vector<long long> A(N);
  vector<long long> firs(N,-1);
  
  long long loop,l_1,l_2,now;
  
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  
  
  now = 1;
  for (int i=0; i<N+1200; i++) {
    if (i == k) {
      cout << now << endl;
      return 0;
    }
    if (firs[now-1] == -1) {
      firs[now-1] = i;
      now = A[now-1];
    }
    else {
      l_1 = firs[now-1];
      l_2 = i;
      loop = l_2 - l_1;
      break;
    }
  }
  
  long long ans = K % loop;
  for (;;) {
    if (ans < l_1) {
      ans += loop;
    }
    else {
      break;
    }
  }
  
  for (int i=0; i<N; i++) {
    if (firs[i] == ans) {
      cout << i+1 << endl;
      break;
    }
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:14: error: 'k' was not declared in this scope
   19 |     if (i == k) {
      |              ^
Language: C++

n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a = 0
t = 1
d = 0
hoge_list = []
hoge_set = set()
while a < k:
  hoge_list.append(t)
  hoge_set.insert(t)
  t = a_list[t-1]
  a += 1
  if t in hoge_set:
    b = hoge_list.index(t)
    d += 1
    break
if d == 0:
  print(t)
else:
  e = (k-b)%(a-b)
  print(hoge_list[b+e])


Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n,k = map(int,input().split())
      | ^
Language: C++

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

int main() {
  int N;
  cin >> N;
  long long int K;
  cin>>K;
  
  int A[N+1];
  for(int i=1;i<=N;i++){
    cin>>A[i];
  }
  int visited[N+1];
  rep(i,N+1)visited[i]=-1;
  vector<int> list;
  list.push_back(1);
  
  int cnt=0;
  
  int now=1;
  visited[1]=0;
  
  int loopstart=0;
  int looplength=0;
  for(int i=1;i<=N+1;i++){
    now=A[list.back()];
    
    if(visited[now]==-1){
      list.push_back(now);
      visited[now]=i;
    }else{
      loopstart=visited[now];
      looplength=i-loopstart;
      break;
    }
    
  }
  //cout<<loopstart<<endl;
  //cout<<looplength<<endl;
  
  int kyori=loopstart+(K-loopstart)%looplength;
  //cout<<kyori<<endl;
  
  int ans=0;
  if(k<loopstart){
    ans=list[loopstart];
  }else{
    ans=list[kyori];
  }
      
  cout << ans << endl;
  //return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:6: error: 'k' was not declared in this scope
   49 |   if(k<loopstart){
      |      ^
Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
  long long int n,k,t=0,q=0,r1=0,r2=0;
  cin>>n>>k;
  vector<int> a(n),b(n+1);
  b.at(0)=1;
  rep(i,n){
    cin>>a.at(i);
  }
  rep(i,n){
    t=a.at(t);
    b.at(i+1)=t;
  }
  rep(i+1,n){
    rep(j,i-1){
      if(b.at(i)==b.at(j)){
        q=1;
        r2=i;
        r1=j;
        break;
      }
    }
    if(q==1) break;
  }
  if(k<=r2) cout<<b.at(k)<<endl;
  else{
    int l;
    l=(k-r1)%(r2-r1)+r1;
    cout<<b.at(l)<<endl;
  }
        
}
  
  
  



Compiler output:
a.cc: In function 'int main()':
a.cc:16:8: error: expected ';' before '+' token
   16 |   rep(i+1,n){
      |        ^
a.cc:2:26: note: in definition of macro 'rep'
    2 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                          ^
a.cc:16:8: error: lvalue required as left operand of assignment
   16 |   rep(i+1,n){
      |        ^~
a.cc:2:26: note: in definition of macro 'rep'
    2 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                          ^
a.cc:2:35: error: expected ')' before ';' token
    2 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                     ~             ^
a.cc:16:3: note: in expansion of macro 'rep'
   16 |   rep(i+1,n){
      |   ^~~
a.cc:16:7: error: 'i' was not declared in this scope
   16 |   rep(i+1,n){
      |       ^
a.cc:2:36: note: in definition of macro 'rep'
    2 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                                    ^
a.cc:16:9: error: lvalue required as increment operand
   16 |   rep(i+1,n){
      |         ^
a.cc:2:36: note: in definition of macro 'rep'
    2 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                                    ^
Language: C++

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

int main(){

  long long N,K;
  cin>>N>>K;

  int A[N+1];
  int done[N+1];
  for(int i=0;i<N;i++){
    cin>>A[i];
    done[i]=0;
  }

  vector<int> v;
	
  done[0]=1;

  long long j=0;
  v.push_back(1);
  while(1){

    j=A[j]-1;
    if(done[j]==2){break;}
    done[j]++;
    v.push_back(j+1);

  }
  
  int S=v.size(); 
  if(K<S){cout<<v[K]<<endl;return 0;}

  int N_out=0;
  int N_loop=0;
  rep(i,N){
    if(done[i]==1)N_out++;
    if(done[i]==2)N_loop++;
  }
  
  
  long long d=((K-N_out)%N_loop);
  cout<<v[N_out+d]<<endl;
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:7: error: 'i' was not declared in this scope
   36 |   rep(i,N){
      |       ^
a.cc:36:3: error: 'rep' was not declared in this scope
   36 |   rep(i,N){
      |   ^~~
Language: C++

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

int main(){

  long long N,K;
  cin>>N>>K;

  int A[N+1];
  int done[N+1];
  for(int i=0;i<N;i++){
    cin>>A[i];
    done[i]=0;
  }

  vector<int> v;
	
  done[0]=1;

  ll j=0;
  v.push_back(1);
  while(1){

    j=A[j]-1;
    if(done[j]==2){break;}
    done[j]++;
    v.push_back(j+1);

  }
  
  ll S=v.size(); 
  if(K<S){cout<<v[K]<<endl;return 0;}

  ll N_out=0;
  ll N_loop=0;
  rep(i,N){
    if(done[i]==1)N_out++;
    if(done[i]==2)N_loop++;
  }
  
  
  ll d=((K-N_out)%N_loop);
  cout<<v[N_out+d]<<endl;
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:3: error: 'll' was not declared in this scope
   20 |   ll j=0;
      |   ^~
a.cc:24:5: error: 'j' was not declared in this scope
   24 |     j=A[j]-1;
      |     ^
a.cc:31:5: error: expected ';' before 'S'
   31 |   ll S=v.size();
      |     ^~
      |     ;
a.cc:32:8: error: 'S' was not declared in this scope
   32 |   if(K<S){cout<<v[K]<<endl;return 0;}
      |        ^
a.cc:34:5: error: expected ';' before 'N_out'
   34 |   ll N_out=0;
      |     ^~~~~~
      |     ;
a.cc:35:5: error: expected ';' before 'N_loop'
   35 |   ll N_loop=0;
      |     ^~~~~~~
      |     ;
a.cc:36:7: error: 'i' was not declared in this scope
   36 |   rep(i,N){
      |       ^
a.cc:36:3: error: 'rep' was not declared in this scope
   36 |   rep(i,N){
      |   ^~~
a.cc:42:5: error: expected ';' before 'd'
   42 |   ll d=((K-N_out)%N_loop);
      |     ^~
      |     ;
a.cc:43:11: error: 'N_out' was not declared in this scope
   43 |   cout<<v[N_out+d]<<endl;
      |           ^~~~~
a.cc:43:17: error: 'd' was not declared in this scope
   43 |   cout<<v[N_out+d]<<endl;
      |                 ^
Language: C++

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

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main() {
  int n; int64_t k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> to[0][i];
  for (int i = 0; i < n; i++) to[0][i]--;
  for (int i = 0; i < D-1; i++) {
    for (int j = 0; j < n; j++) {
      to[i+1][j] = to[i][to[i][j]];
    }
  }
  
  int v = 0; 
  for (int i = D-1; i >= 0; i--) {
    ll l = 1ll<<i;
    if (l <= k) {
      v = to[i][v];
      k -= l;
    }
  }
  cout << v+1 << endl;    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:5: error: 'll' was not declared in this scope
   22 |     ll l = 1ll<<i;
      |     ^~
a.cc:23:9: error: 'l' was not declared in this scope
   23 |     if (l <= k) {
      |         ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    queue<ll> que;
    que.push(0);
    vector<ll> used(n,-1); //最短何回目のワープでここに来れるか
    ll tmp=0;
    ll buf1=-1,buf2=-1;
    while(true){
        ll x=que.front();que.pop();
        if(tmp+1==k){
            cout<<a[x]+1<<endl;
            return 0;
        }
        if(a[x]==x){
            cout<<x+1<<endl;
            return 0;
        }
        if(used[a[x]]!=-1){
            buf1=used[a[x]];
            buf2=tmp-used[a[x]]+1;
            break;
        }
        
        used[x]=tmp;
        tmp++;
        que.push(a[x]);
    }
    
    //cout<<buf1<<" "<<buf2<<endl;
    ll buf=(k-buf1)%buf2;
    buf+=buf1;
    que.push(0);
    ll x;
    rep(i,buf){
        x=que.front();que.pop();
        que.push(a[x]);
    }
    else cout<<a[x]+1<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:5: error: 'else' without a previous 'if'
   54 |     else cout<<a[x]+1<<endl;
      |     ^~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>

using namespace std;
using LL = long long;
const int N = 200005;
int n, a[N];
int mp[N];
int main()
{
	LL k;
	cin >> n >> k;

	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		mp[i] = a[i];
	}

	int now = 1;
	map<int, int> v;

	int count = 1;
	if (a[1] == 1)
	{
		cout << 1 << endl;
		return 0;
	}

	int len, k1;

	while (1)
	{
		if (v[now] > 0)
		{
			len = count - v[now];//环的长度
			k1 = v[now] - 1;//多余路径长度
			break;
		}
		v[now] = count;
		now = mp[now];//跳到新节点
		++count;//路径增加
	}

	int res = 0;

	if (k > k1)
	{
		res = k1 + (k - k1) % len;
	}
	else
		res = k;

	int now = 1;
	for (int i = 1; i <= res; ++i)
	{
		now = mp[now];
	}
	
	cout << now << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:13: error: redeclaration of 'int now'
   58 |         int now = 1;
      |             ^~~
a.cc:24:13: note: 'int now' previously declared here
   24 |         int now = 1;
      |             ^~~
Language: Java

import java.util.Arrays;
import java.util.Scanner;

public class Teleport {

    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        solve();
    }

    private static void solve() {

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

        int[] next = new int[n + 1];
        boolean[] visited = new boolean[n + 1];

        for (int i = 1; i <= n; i++) {
            next[i] = scanner.nextInt();
        }


        int result = 1;

        int count = 0;

        while (count < k && !visited[result]) {
            count++;
            visited[result] = true;
            result = next[result];
        }

        Arrays.fill(visited, false);
        int count2 = 0;
        while (count + count2 < k && !visited[result]) {
            count2++;
            visited[result] = true;
            result = next[result];
        }

        if (count + count2 < k) {
            int diff = count - count2;
            long r = (k - diff) % count2;


            for (int i = 0; i < r; i++) {
                result = next[result];
            }
        }

        System.out.println(result);

    }
}

Compiler output:
Main.java:4: error: class Teleport is public, should be declared in a file named Teleport.java
public class Teleport {
       ^
1 error
Language: C++

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

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) {
    return 1;
  }
  else {
    return 0;
  }
}

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> vec(n);
  for (int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  
  vector<int> r;
  int s=1;
  for (int i=0; i<k; i++){
    s=vec.at(s-1);
    if (vector_finder(vec,s)==0){
      r.push_back(s);
    }
    else{
      vector<int>::iterator itr;
	  itr = find(vec.begin(), vec.end(), s);
	  int x = distance(vec.begin(), itr)
      int mod=r.size()-x;
      int t=(k-i-1)%mod;
      cout << r.at(x+t) << endl;
      break;
    }
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:7: error: expected ',' or ';' before 'int'
   34 |       int mod=r.size()-x;
      |       ^~~
a.cc:35:21: error: 'mod' was not declared in this scope; did you mean 'modf'?
   35 |       int t=(k-i-1)%mod;
      |                     ^~~
      |                     modf
Language: C

#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define F first
#define S second
#define PB push_back
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const int maxp = 64;

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    int n,k;
    cin >> n >> k;
    int a[n+1][maxp];
    memset(a,-1,sizeof(a));

    for(int i=1;i<=n;i++)
        cin >> a[i][0];

    for(int i=1;i<maxp;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[j][i-1] != -1)
            a[j][i] = a[a[j][i-1]][i-1];
        }
    }
    int y = 1;
    for(int i=0;i<maxp;i++)
    {
     
        if(k & (1<<i))
        {
            y = a[y][i];
        }
    }

    cout << y;
	return 0;
}


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

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

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}


int main() {
  // ll n,m,x,k=0,sum=0,a=0,b=0,c=0,d=0,ans=10000000,index=1,index_0=1,index_ans=1;
  ll MOD = 1000000007;
  ll INF = 1LL << 60;
  ll C[100001],A[200002],R[200002]={0},O[100001];
  string S="",T="",U="";
  ll n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

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

Compiler output:
a.cc: In function 'int main()':
a.cc:36:26: error: expected primary-expression before '<' token
   36 |   if(k<1) cout << s[k] <<<endl;
      |                          ^
a.cc:40:17: error: 'K' was not declared in this scope
   40 |     cout << s[l+K] << endl;
      |                 ^
a.cc:42:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   42 |   cout << ans << endl;
      |           ^~~
      |           abs