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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i)
  }
  
  int count = 0;
  int a = 1;
  while (true) {
    a = A.at(a);
    count++;
    if (a == 2) {
      break;
    }
    else if (count > N) {
      count = -1;
      break;
    }
  }
  cout << count << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:9:19: error: expected ';' before '}' token
    9 |     cin >> A.at(i)
      |                   ^
      |                   ;
   10 |   }
      |   ~
Language: C++

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

int main() {
  int N;
  cin >> N;
  int nazo=-1;
  vector<int> button(N);
  vector <int> a(N);
  for (int i=0; i<N; i++)
  {
    cin >> a.at(i);
  }
  for (int i=0; i<N-1; i++)
  {
    button.at(i+1) = a.at(button.at(i+1)-1);
  }
  button.at(0) = 1;
  for (int i=0; i<N; i++)
  {
    if (button.at(i) == 2)
    {
      nazo = i+1;
      break
    }
  }
  cout << nazo << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:12: error: expected ';' before '}' token
   24 |       break
      |            ^
      |            ;
   25 |     }
      |     ~
Language: C++

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

int main() {
  int N;
  cin >> N;
  int nazo=-1;
  vector<int> button(N);
  vector <int> a(N);
  for (int i=0; i<N; i++)
  {
    cin >> a.at(i);
  }
  for (int i=0; i<N-1; i++)
  {
    button.at(i+1) = a.at(button(i+1)-1);
  }
  button.at(0) = 1;
  for (int i=0; i<N; i++)
  {
    if (button.at(i) == 2)
    {
      nazo = i+1;
      break
    }
  }
  cout << nazo << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:33: error: no match for call to '(std::vector<int>) (int)'
   16 |     button.at(i+1) = a.at(button(i+1)-1);
      |                           ~~~~~~^~~~~
a.cc:24:12: error: expected ';' before '}' token
   24 |       break
      |            ^
      |            ;
   25 |     }
      |     ~
Language: C++

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

int main(){
    int n, i, t, c = 0;
    cin >> n;
    a[n+1];
    for(i=1; i<=n; i++){
        cin >> a[i];
    }
    t = 1
    while(c < n){
        c++;
        t = a[t];
        if(t == 2){
            break;
        }
    }
    if(c == n){
        cout << -1;
    }else{
        cout << c;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:5: error: 'a' was not declared in this scope
    7 |     a[n+1];
      |     ^
a.cc:11:10: error: expected ';' before 'while'
   11 |     t = 1
      |          ^
      |          ;
   12 |     while(c < n){
      |     ~~~~~
Language: C++

#include<iostream>
using namespace std;

int main(){
	int N;cin>>N;
  	int count=0;
  	int a[100001];
  	for(int i=1;i<=N;++i){
      cin>>a[i];
      if(a[i]==i&&a[i]!=2){cout<<"-1"<<endl;return 0;}
  	int v=a[1];++count;
	for(int i=2;i<=N;++i){
    	v=a[v];++count;
      	if(v==2){
        	cout<<count<<endl;
          	return 0;
        }if(a[count]==a[count-2]&&a[count-1]==a[count-3])break;
    }
	cout<<"-1"<<endl;
  	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:2: error: expected '}' at end of input
   21 | }
      |  ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

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


int main() {
    int N;

    cin >> N;

    int a[100002];
    bool hist[100002];
    int count=0;

    for(int i=0;i<N;i++){
        cin >> a[i+1];
        hist[i+1] = false;
    }

    int curbtn = 1;

    while(!hist[curbtn]){
        hist[curbtn]=true;
        curbtn = a[curbtn];
        count++
        if(curbtn==2) cout << count << endl; return 0;
    }

    cout << -1 << endl;





}



Compiler output:
a.cc: In function 'int main()':
a.cc:26:16: error: expected ';' before 'if'
   26 |         count++
      |                ^
      |                ;
   27 |         if(curbtn==2) cout << count << endl; return 0;
      |         ~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
using namespace std;

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

const long long INF = 1LL << 60;
vector<int> a[];
int main()
{
	int n;
	int res = 0;
	cin >> n;
	vector<int> a(n+1);
	vector<int> na(n + 1);
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	na[0] = 0;
	na[1] = 1;
	for (int i = 1; i <= n;) {
		na[a[i]]++;
		if (na[a[i]] >= 2) {
			res = -1;
			break;
		}
		i = a[i];
		if (i == 2) {
			break;
		}
	}
	if (res == -1) {
		cout << res << endl;
		return 0;
	}
	for (int i = 1;i < n + 1;i++) {
		res += na[i];
	}
	cout << res-1 << endl;
	return 0;
}


Compiler output:
a.cc:18:13: error: array size missing in 'a'
   18 | vector<int> a[];
      |             ^
Language: C++

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


int main()
{
    int N;
    cin>>N;
    vector<int> buttons(N);
    for (int i=0;i<N;++i){
        cin>>buttons.at(i);
    }
    
    int on = 0;
    for (int i=0;i<=N;++i){
        if (on == 1){
            cout << i << endl;
            return 0;
        }
        on = buttons.at(on)
    }
    cout<<-1<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:28: error: expected ';' before '}' token
   20 |         on = buttons.at(on)
      |                            ^
      |                            ;
   21 |     }
      |     ~
Language: C++

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


int main()
{
    int N;
    cin>>N;
    vector<int> buttons(N);
    for (int i=0;i<N;++i){
        cin>>buttons.at(i);
    }
    
    int on = 0;
    for (int i=0;i<=N;++i){
        if (on == 1){
            cout << i << endl;
            return;
        }
        on = buttons.at(on)
    }
    cout<<-1<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:13: error: return-statement with no value, in function returning 'int' [-fpermissive]
   18 |             return;
      |             ^~~~~~
a.cc:20:28: error: expected ';' before '}' token
   20 |         on = buttons.at(on)
      |                            ^
      |                            ;
   21 |     }
      |     ~
Language: C++

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

int main() {
    int N;
    cin >> N;
    vector<int> avec(N);
    for (int i = 0; i < N; i++) {
        cin >> avec.at(i);
    }

    int now = 1; cnt = 0;
    while(1) {
        if (now == 2) {
            cout << cnt << endl;
            break;
        }
        if (cnt >= n) {
            cout << "-1" << endl;
            break;
        }
        now = avec.at(now);
        cnt++;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:18: error: 'cnt' was not declared in this scope; did you mean 'int'?
   12 |     int now = 1; cnt = 0;
      |                  ^~~
      |                  int
a.cc:18:20: error: 'n' was not declared in this scope
   18 |         if (cnt >= n) {
      |                    ^
Language: C

#include <stdio.h>
int main(){
    int n,count=0,point=1;
    scanf("%d",&n);
    int a[n],b[n];
    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=0;
    }
     while(){
        if (point==2){
            break;
        }
        if (b[point-1]==1){
            count=-1;
            break;
        }
        point=a[point-1];
        b[point-1]=1;
        count++;
    }
    printf("%d\n",count);
    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:10:12: error: expected expression before ')' token
   10 |      while(){
      |            ^
Language: C

#include <stdio.h>
int main(){
    int n,count=0,point=1;
    scanf("%d",&n);
    int a[n],b[n];
    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=0;
    }
    for (int i=0;i<n;i++){
        if (point==2){
            break;
        }
        if (point==i+1 && b[i]==1){
            count=-1;
            break;
        }
        if (point==i+1 && b[i]==0){
            point=a[i];
            b[i]=1;
            count++
            i=0;
        }
    }
    printf("%d\n",count);
    return 0;
}


Compiler output:
main.c: In function 'main':
main.c:21:20: error: expected ';' before 'i'
   21 |             count++
      |                    ^
      |                    ;
   22 |             i=0;
      |             ~
Language: C

#include<stdio.h>

int main(){
  int N, b[100000], push, b[100000] = {0}, count = 0;
  
  scanf("%d", &N);
  for (i = 0; i < N; i++){
    scanf("%d", &a[i]);
  }
  push = a[0]; b[0] = 1;
  while(1){
    count++;
    if(b[push - 1] == 1){
      printf("-1\n");
      return 0;
    }
    if(push == 2){
      printf("%d\n", count);
      return 0;
    }
    a[push - 1] = 1; 
    push = a[push - 1];
  }
}

Compiler output:
main.c: In function 'main':
main.c:4:27: error: redeclaration of 'b' with no linkage
    4 |   int N, b[100000], push, b[100000] = {0}, count = 0;
      |                           ^
main.c:4:10: note: previous declaration of 'b' with type 'int[100000]'
    4 |   int N, b[100000], push, b[100000] = {0}, count = 0;
      |          ^
main.c:7:8: error: 'i' undeclared (first use in this function)
    7 |   for (i = 0; i < N; i++){
      |        ^
main.c:7:8: note: each undeclared identifier is reported only once for each function it appears in
main.c:8:18: error: 'a' undeclared (first use in this function)
    8 |     scanf("%d", &a[i]);
      |                  ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define INF (1e9)

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

typedef long long ll;

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

    int n;
    cin >> n;

    vector<int> buttons(n);
    rep(i, n) cin >> buttons[i];

    int put = 0;
    bool flag = false;
    rep(i, n){
        if(put == 1){
            cout << i << endl;
            flag = true;
            break;
        }

        put = buttons[put] - 1;
    }

    if(!flag) cout << -1 << endl;


Compiler output:
a.cc: In function 'int main()':
a.cc:38:34: error: expected '}' at end of input
   38 |     if(!flag) cout << -1 << endl;
      |                                  ^
a.cc:16:11: note: to match this '{'
   16 | int main(){
      |           ^
Language: C++

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

int main(){
    int N,a[100000],b[100000],ans;
    cin >> N;
    int b[0]=1;
    bool X =false;
    for (int i=0; i<N; ++i){
        b[i+1]=a[b[i]]
        if (b[i]==2){
             ans=i;
             break;
        }
    }
    if (X) cout << ans << endl;
    else cout << -1 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:9: error: conflicting declaration 'int b [0]'
    8 |     int b[0]=1;
      |         ^
a.cc:6:21: note: previous declaration as 'int b [100000]'
    6 |     int N,a[100000],b[100000],ans;
      |                     ^
a.cc:11:23: error: expected ';' before 'if'
   11 |         b[i+1]=a[b[i]]
      |                       ^
      |                       ;
   12 |         if (b[i]==2){
      |         ~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
         
int main() {
  int N;
  cin >> N; 
  vector<int> buttons(N+1);
  
  for (int i = 1; i <= N; i++) {
    cin >> buttons.at(i);
  }  
  
  // search all 
  vector<bool> pushed(N+1);
  int i = 1;
  
  for (int x = 0; x <= N; x++) 
      pushed.at(x) = false;
    
  int count = 0;
    
  while (true) {
    pushed.at(i) = true;
    count++;

    // next button 
    i = buttons.at(i);

    // reached button2 ?
    if ( i == 2 ) {
      cout << count << endl;
      break;
    }
    å
    // infinite loop ?
    if ((pushed.at(i) || (count >= N)) {
      cout << -1 << endl;
      break;
    }  
  }  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:5: error: '\U000000e5' was not declared in this scope
   34 |     å
      |     ^
Language: C++

#include <iostream>
using namespace std;

int N;
int a[100010];

int main ()
{
  cin >> N;
  for (int i = 0; i < N; i++) {
	cin >> A[i + 1];
  }
  int cur = 1;
  for (int i = 0; i < N; i++) {
  	cur = a[cur];
    if (cur == 2) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:16: error: 'A' was not declared in this scope
   11 |         cin >> A[i + 1];
      |                ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int a[n+1];
	int b[n+1]={};
	for(int i=1,i<=n,i++)cin>>a[i];
	n=1;
	b[n]=1;
	int count=0;
	while(n!=2){n=a[n];if(b[n]){break;cout<<-1<<endl;return 0;}b[n]=1;count++;}
	cout<<count<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:22: error: expected ';' before '<=' token
   11 |         for(int i=1,i<=n,i++)cin>>a[i];
      |                      ^~
      |                      ;
a.cc:11:22: error: expected primary-expression before '<=' token
   11 |         for(int i=1,i<=n,i++)cin>>a[i];
      |                      ^~
a.cc:11:29: error: expected ';' before ')' token
   11 |         for(int i=1,i<=n,i++)cin>>a[i];
      |                             ^
      |                             ;
Language: C++

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

int main() {
  int n,;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i);
  }

  int now = 0, cnt = 0;
  while (true) {
    if (now == 1) {
      cout << cnt << endl;
      return 0;
    }
    if (cnt >= n) {
      cout << -1 << endl;
      return 0;
    }
    cnt ++;
    now = a.at(now);
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:9: error: expected unqualified-id before ';' token
    5 |   int n,;
      |         ^
Language: C++

#include<iostream>
using namespace std;

int main(){
  int n;cin>>n;
  int A[n];for(int i=0;i<n;i++)cin>>A[i];
  int ans=0,now=0;
  for(;;){
    if(now==1){
      cout<<c<<endl;
      break
    }
    if(c>=n){
      cout<<-1<<endl;
      break;
    }
    c++;
    now=A[now];
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:13: error: 'c' was not declared in this scope
   10 |       cout<<c<<endl;
      |             ^
a.cc:11:12: error: expected ';' before '}' token
   11 |       break
      |            ^
      |            ;
   12 |     }
      |     ~       
a.cc:13:8: error: 'c' was not declared in this scope
   13 |     if(c>=n){
      |        ^
a.cc:17:5: error: 'c' was not declared in this scope
   17 |     c++;
      |     ^
Language: C++

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  for(int i=1;i<N+1;i++){
    cin >> a[i];
  } 
  int b=1;
  
  for(int i=1;i<N+1;i++){
    b=a[b];
   
    if(b==2){
      cout << i << endl;
    
      return 0;
      break;
      
    }  
  }
  cout << -1 << endl;
 


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

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  for(int i=1;i<N+1;i++){
    cin >> a[i];
  } 
  int b=1;
  
  for(int i=1;i<N+1;i++){
    b=a[b];
   
    if(b==2){
      cout << i << endl;
    
      return 0;
      
    }  
  }
  cout << -1 << endl;
 


Compiler output:
a.cc: In function 'int main()':
a.cc:23:22: error: expected '}' at end of input
   23 |   cout << -1 << endl;
      |                      ^
a.cc:4:12: note: to match this '{'
    4 | int main() {
      |            ^
Language: C++

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(i=0;i<N;i++){
    cin >> a[i];
  } 
  int b=0;
  
  for(i=0;i<N;i++){
    b=a[b]-1;
   
    if(b==1){
      cout << i+1 << endl;
      break;
      return 0;
    }  
  }
  cout << -1 << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:7: error: 'i' was not declared in this scope
    8 |   for(i=0;i<N;i++){
      |       ^
a.cc:13:7: error: 'i' was not declared in this scope
   13 |   for(i=0;i<N;i++){
      |       ^
Language: C++

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

int main() {
  int N;
  cin >> N;
  vectro<int> a(N);
  for(i=0;i<N;i++){
    cin >> a[i];
  } 
  int b=0;
  
  for(i=0;i<N;i++){
    b=a[b]-1;
   
    if(b==1){
      cout << i+1 << endl;
      break;
      return 0;
    }  
  }
  cout << -1 << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: 'vectro' was not declared in this scope
    7 |   vectro<int> a(N);
      |   ^~~~~~
a.cc:7:10: error: expected primary-expression before 'int'
    7 |   vectro<int> a(N);
      |          ^~~
a.cc:8:7: error: 'i' was not declared in this scope
    8 |   for(i=0;i<N;i++){
      |       ^
a.cc:9:12: error: 'a' was not declared in this scope
    9 |     cin >> a[i];
      |            ^
a.cc:13:7: error: 'i' was not declared in this scope
   13 |   for(i=0;i<N;i++){
      |       ^
a.cc:14:7: error: 'a' was not declared in this scope
   14 |     b=a[b]-1;
      |       ^
Language: Java

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    int k = 0;
    int count = 0;
    do{
        k = a[k];
        count++;
    }while(k != 0 && k != 1);
    if(k == 1) cout << count;
    else cout << -1;
}


Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:5: error: not a statement
    cin >> n;
        ^
Main.java:6: error: not a statement
    vector<int> a(n);
                  ^
Main.java:8: error: not a statement
        cin >> a[i];
            ^
Main.java:17: error: not a statement
    if(k == 1) cout << count;
                    ^
Main.java:18: error: not a statement
    else cout << -1;
              ^
Main.java:3: error: unnamed classes are a preview feature and are disabled by default.
int main(){
^
  (use --enable-preview to enable unnamed classes)
Main.java:6: error: ';' expected
    vector<int> a(n);
                 ^
Main.java:6: error: ';' expected
    vector<int> a(n);
                   ^
10 errors
Language: C++

#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main ( )
{
int n ;
scanf ("%d" , &n ) ;
vector<int>v ;
for ( int i = 0 ; i < n ; i++)
{
int z ;
scanf ("%d" , &z ) ;
z−−;
v.push back ( z ) ;
}
int now = 0 , c = 0 ;
for ( ; ; )
{
if ( now == 1 )
{
printf ("%d\n" , c ) ;
break ;
}
if ( c >= n )
{
printf ("−1\n" ) ;
break ;
}
c++;
now = v [ now ] ;
}
}

Compiler output:
a.cc:14:1: error: extended character − is not valid in an identifier
   14 | z−−;
      | ^
a.cc:14:1: error: extended character − is not valid in an identifier
a.cc: In function 'int main()':
a.cc:14:1: error: 'z\U00002212\U00002212' was not declared in this scope
   14 | z−−;
      | ^~~
a.cc:15:3: error: 'class std::vector<int>' has no member named 'push'
   15 | v.push back ( z ) ;
      |   ^~~~
Language: C++

#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main ( )
{
int n ;
scanf (”%d ” , &n ) ;
vector<int>v ;
for ( int i = 0 ; i < n ; i++)
{
int z ;
scanf (”%d ” , &z ) ;
z−−;
v.push back ( z ) ;
}
int now = 0 , c = 0 ;
for ( ; ; )
{
if ( now == 1 )
{
printf (”%d\n ” , c ) ;
break ;
}
if ( c >= n )
{
printf (”−1\n ” ) ;
break ;
}
c++;
now = v [ now ] ;
}
}


Compiler output:
a.cc:8:8: error: extended character ” is not valid in an identifier
    8 | scanf (”%d ” , &n ) ;
      |        ^
a.cc:8:12: error: extended character ” is not valid in an identifier
    8 | scanf (”%d ” , &n ) ;
      |            ^
a.cc:13:8: error: extended character ” is not valid in an identifier
   13 | scanf (”%d ” , &z ) ;
      |        ^
a.cc:13:12: error: extended character ” is not valid in an identifier
   13 | scanf (”%d ” , &z ) ;
      |            ^
a.cc:14:1: error: extended character − is not valid in an identifier
   14 | z−−;
      | ^
a.cc:14:1: error: extended character − is not valid in an identifier
a.cc:22:9: error: extended character ” is not valid in an identifier
   22 | printf (”%d\n ” , c ) ;
      |         ^
a.cc:22:12: error: stray '\' in program
   22 | printf (”%d\n ” , c ) ;
      |            ^
a.cc:22:15: error: extended character ” is not valid in an identifier
   22 | printf (”%d\n ” , c ) ;
      |               ^
a.cc:27:9: error: extended character ” is not valid in an identifier
   27 | printf (”−1\n ” ) ;
      |         ^
a.cc:27:9: error: extended character − is not valid in an identifier
a.cc:27:12: error: stray '\' in program
   27 | printf (”−1\n ” ) ;
      |            ^
a.cc:27:15: error: extended character ” is not valid in an identifier
   27 | printf (”−1\n ” ) ;
      |               ^
a.cc: In function 'int main()':
a.cc:8:8: error: '\U0000201d' was not declared in this scope
    8 | scanf (”%d ” , &n ) ;
      |        ^
a.cc:8:10: error: 'd' was not declared in this scope
    8 | scanf (”%d ” , &n ) ;
      |          ^
a.cc:14:1: error: 'z\U00002212\U00002212' was not declared in this scope
   14 | z−−;
      | ^~~
a.cc:15:3: error: 'class std::vector<int>' has no member named 'push'
   15 | v.push back ( z ) ;
      |   ^~~~
a.cc:27:9: error: '\U0000201d\U000022121' was not declared in this scope
   27 | printf (”−1\n ” ) ;
      |         ^~~
Language: C

#include<stdio.h>
#include<string.h>

int a[100001][2];


int main(void) {

	int n;
	int i;

	scanf("%d", &n);

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

	//ループのiに数列の値を代入してみる//
	j = 0;
	for (i = 0; i < n; i = a[i][0] - 1) {
		if (a[i][0] == 1) {
			printf("-1\n");
			return 0;
		}
		if (a[i][0] == 2) {
			printf("%d", j+1);
			return 0;
		}
		if (a[i][1] == 0) {
			printf("-1\n");
			return 0;
		}
		j++;
		a[i][1] = 0;
	}
	printf("-1\n");
	return 0;
}


Compiler output:
main.c: In function 'main':
main.c:20:9: error: 'j' undeclared (first use in this function)
   20 |         j = 0;
      |         ^
main.c:20:9: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
int n;
int a[maxx];
map <int, int> mp;
bool flg;
bool vis[maxx];

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) mp[a[i]] = i;
	int p = 1;
	while(p != 2) {
		if(flg) break;
		if(vis[p]) flg = 1;
		vis[p] = 1;
		p = mp[p];
		cnt++;
	}
	if(flg) puts("-1");
	else cout << cnt << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:17: error: 'cnt' was not declared in this scope; did you mean 'int'?
   20 |                 cnt++;
      |                 ^~~
      |                 int
a.cc:23:22: error: 'cnt' was not declared in this scope; did you mean 'int'?
   23 |         else cout << cnt << endl;
      |                      ^~~
      |                      int
Language: C++

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

int main(){
    int n;cin >> n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin >> a.at(i);
    }
    vector<bool> b(n+1,false);
    int ans=0;
    int i=1
    while(1){
        ans++;
        b.at(i)=true;
        i = a.at(i);
        if(i==2){
            cout << ans << endl;
            return 0;
        }
        if(b.at(i)) break;
    }
    cout << -1 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: expected ',' or ';' before 'while'
   13 |     while(1){
      |     ^~~~~
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N),flag(N);
  REP(i,N) cin >> a[i];
  int button=1,ans=0;
  while(1){
    button = a[button-1];
    ans++;
    flag[button-1]++;
    if(button==c) break;
    if(flag[button-1]>1){
      ans=-1;
      break;
    }
  }
  cout << ans << endl;    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:16: error: 'c' was not declared in this scope
   32 |     if(button==c) break;
      |                ^
Language: C++

#include <iostream>
#include <vector>

int main() {
  std::cin >> N;
  std::vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> a[i];
  }

  int now = a[0];
  int cnt = 0;
  while(cnt < N) {
    int tmp = a[now];
    now = a[tmp];
    ++cnt;
    if ( now == 2 ) break;
  }
  if ( cnt < N ) std::cout << cnt << std::endl;
  else std::cout << -1 << std::endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:15: error: 'N' was not declared in this scope
    5 |   std::cin >> N;
      |               ^
Language: C++

#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    int n;
    int ans = 0;
    int a[100005];
    int v[100005] = {};

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

    int now = 1;
    
    while (now != 2 && v[now] == 0) {
        v[now] = 1;
        now = a[now];
        ans++;
    }

    if (now != 2) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:5: error: 'cin' was not declared in this scope
   16 |     cin >> n;
      |     ^~~
a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    3 | #include <utility>
  +++ |+#include <iostream>
    4 | #define INF 1000000000
a.cc:30:9: error: 'cout' was not declared in this scope
   30 |         cout << -1 << endl;
      |         ^~~~
a.cc:30:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:30:23: error: 'endl' was not declared in this scope
   30 |         cout << -1 << endl;
      |                       ^~~~
a.cc:4:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    3 | #include <utility>
  +++ |+#include <ostream>
    4 | #define INF 1000000000
a.cc:32:9: error: 'cout' was not declared in this scope
   32 |         cout << ans << endl;
      |         ^~~~
a.cc:32:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:32:24: error: 'endl' was not declared in this scope
   32 |         cout << ans << endl;
      |                        ^~~~
a.cc:32:24: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
Language: C++

#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
		a[i]--;
	}
	int x = 0;
	for (int i = 0; i<100010; i++) {
		if (x == 1) {
			cout << i << endl;
			return 0;
		}
		x = a[x];
	}
	cout << -1 << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:24: error: 'a' was not declared in this scope
   47 |                 cin >> a[i];
      |                        ^
a.cc:56:21: error: 'a' was not declared in this scope
   56 |                 x = a[x];
      |                     ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int a[100010];
bool f[100010];
int  ans;
void dfs(int i,int c){
if(i==2)ans=c;	
  if(f[a[i]]){
      return;
  }else{
    dfs(a[i]);
  }
}
int main(){
	int n;cin>>n;
  ans=1000000;	
  for(int i=1;i<=n;i++)cin>>a[i];
    dfs(1);
    if(ans<1000000){
      cout<<ans<<endl;
    }else{
		cout<<-1<<endl;
    }
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:11:8: error: too few arguments to function 'void dfs(int, int)'
   11 |     dfs(a[i]);
      |     ~~~^~~~~~
a.cc:6:6: note: declared here
    6 | void dfs(int i,int c){
      |      ^~~
a.cc: In function 'int main()':
a.cc:18:8: error: too few arguments to function 'void dfs(int, int)'
   18 |     dfs(1);
      |     ~~~^~~
a.cc:6:6: note: declared here
    6 | void dfs(int i,int c){
      |      ^~~
Language: C++

#include<stdio.h>
#include<vector>
#include<algorithm>
using  namespace  std ;
int  main (){
int  n ;
scanf ("%d" , &n ) ;
vector<int>v ;
for(int i=0;i<n;i++){
    intz;
    scanf("%d",&z);
    z--;
    v.push_back(z);
}
int now=0,c=0;
for(;;){
    if(now==1){
        printf("%d\n",c);
        break;
    }if(c>=n){
        printf("-1\n");
        break;
    }
    c++;
    now=v[now];
}}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:5: error: 'intz' was not declared in this scope; did you mean 'int'?
   10 |     intz;
      |     ^~~~
      |     int
a.cc:11:17: error: 'z' was not declared in this scope
   11 |     scanf("%d",&z);
      |                 ^
Language: C++

#include<stdio . h>
#include<vector>
#include<algorithm>
using  namespace  std ;
int  main (){
int  n ;
scanf ("%d" , &n ) ;
vector<int>v ;
for(int i=0;i<n;i++){
    intz;
    scanf("%d",&z);
    z--;
    v.push_back(z);
}
int now=0,c=0;
for(;;){
    if(now==1){
        printf("%d\n",c);
        break;
    }if(c>=n){
        printf("-1\n");
        break;
    }
    c++;
    now=v[now];
}}

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

n = gets.chomp.to_i
a = readlines.map{|a| a.to_i}

if a.index(2).nil?
  puts "-1"
  exit 
end

a.unshift(0)
count = Array.new(n+1){0}

idx = a[1]
count[1] += 1

while idx != 2 && count.inject(&:+) != n
  prv_idx = idx
  idx = a[idx]

  if prv_idx == a[idx]
    puts "-1"
    exit 
  end
  
  count[prv_idx] += 1
end

if count.inject(&:+) == n
  puts "-1"
  exit 
end

puts count.inject(&:+)

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n = gets.chomp.to_i
      | ^
a.cc:4:1: error: expected unqualified-id before 'if'
    4 | if a.index(2).nil?
      | ^~
a.cc:12:1: error: 'idx' does not name a type
   12 | idx = a[1]
      | ^~~
Language: C++

n = gets(chomp:true).to_i
a = readlines.map{|a| a.to_i}

if a.index(2).nil?
  puts "-1"
  exit 
end

a.unshift(0)
count = Array.new(n+1){0}

idx = a[1]
count[1] += 1

while idx != 2 && count.inject(&:+) != n
  prv_idx = idx
  idx = a[idx]

  if prv_idx == a[idx]
    puts "-1"
    exit 
  end
  
  count[prv_idx] += 1
end

if count.inject(&:+) == n
  puts "-1"
  exit 
end

puts count.inject(&:+)

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n = gets(chomp:true).to_i
      | ^
a.cc:4:1: error: expected unqualified-id before 'if'
    4 | if a.index(2).nil?
      | ^~
a.cc:12:1: error: 'idx' does not name a type
   12 | idx = a[1]
      | ^~~
Language: C++

#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int to[100005];

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d", &l[i]);
  }
  int curr = 1;
  int ret = 0;
  while(curr != 2 && ret < 1000000) {
    curr = to[curr];
    ret++;
  }
  if(curr != 2) ret = -1;
  printf("%d\n", ret);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:18: error: 'l' was not declared in this scope
   49 |     scanf("%d", &l[i]);
      |                  ^
Language: C++

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

int main(){
  int i,array[100001],n[100001]={},c=0,a
  cin>>a;
  for(i=0;i<a;i++){
    cin>>array[i];
  }
  for(i=0;;){
    if(i==2){
      cout<<c<<endl;
      return 0;
    }
    if(n[i]==-1){
      cout<<n[i]<<endl;
      return 0;
    }
    i=array[i];
    n[i]--;
    c++;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:3: error: expected initializer before 'cin'
    6 |   cin>>a;
      |   ^~~
a.cc:7:13: error: 'a' was not declared in this scope
    7 |   for(i=0;i<a;i++){
      |             ^
Language: C++

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

int main(){
  int N;
  cin >> N;
  vector<int> a(200000);
  for(int i=1;i<=N;i++){
    cin >> a.at(i);
  }
  for(

Compiler output:
a.cc: In function 'int main()':
a.cc:12:7: error: expected primary-expression at end of input
   12 |   for(
      |       ^
a.cc:12:7: error: expected primary-expression at end of input
a.cc:12:7: error: expected ';' at end of input
   12 |   for(
      |       ^
      |       ;
a.cc:12:7: error: expected primary-expression at end of input
a.cc:12:7: error: expected ')' at end of input
   12 |   for(
      |      ~^
      |       )
a.cc:12:7: error: expected statement at end of input
a.cc:12:7: error: expected '}' at end of input
a.cc:5:11: note: to match this '{'
    5 | int main(){
      |           ^
Language: C++

#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int n;
  cin >> n;
  
  int lamp[n];
  REP(i,n){
    cin >> lamp[i];
  }
  
  int ans = 0,l = 0;
  while(ans <= n){
    l = lamp[i] -1;
    ans++;
    if(l == 1) {
      cout << ans << endl;
      return 0;
    }
  }
   
  cout << -1 << endl;

 return 0;
}

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

#include <iostream>
using namespace std;

int main() {
	int n,a=1,b=vec.at(1),x=0;
	cin>>n;
	vector<int>vec(n);
	for(int i=0;i<n;i++){
		cin>>vec.at(i);
	}
	for(int i=0;i<n;i++){
	    if(b==2){
	    
	    	break;
	    	
	    }
	    a=b;
	    b=vec.at(a);
	    x++
		
	}
	if(x==n){
		cout<<-1<<endl;
	}
	else{
		cout<<x+1<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:21: error: 'vec' was not declared in this scope
    5 |         int n,a=1,b=vec.at(1),x=0;
      |                     ^~~
a.cc:7:9: error: 'vector' was not declared in this scope
    7 |         vector<int>vec(n);
      |         ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:7:16: error: expected primary-expression before 'int'
    7 |         vector<int>vec(n);
      |                ^~~
a.cc:19:13: error: 'x' was not declared in this scope
   19 |             x++
      |             ^
a.cc:22:12: error: 'x' was not declared in this scope
   22 |         if(x==n){
      |            ^
Language: C++

#include <iostream>
//#include <vector>

using namespace std;

int search(int* arr, int len){
  int flag = 0;
  if(len > 0){
    for(int i = 0; i < len; i++){
      if(arr[len] == arr[i]){
	flag = 1;
	break;
      }
    }
  }
  return flag;
}
    
      
int main(){
  int N;
  int a[110000];

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

  //for(int i = 0; i < N; i++) cout << a[i];
  //cout << endl;
  
  int passed[110000] = {};
  
  int now = 1;
  int cnt = 0;

  passed[0] = now;
  while(num != 2){
    //if(cnt > 10) break;
    if(num == 2) break;
    
    cnt ++;
    now = a[now-1];
    passed[cnt] = now;

    //cout << "cnt: " << cnt << " now: " << now << endl;
    
    if(search(passed, cnt)){
      cnt = -1;
      break;
    }
    
  }

  cout << cnt << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:9: error: 'num' was not declared in this scope; did you mean 'enum'?
   36 |   while(num != 2){
      |         ^~~
      |         enum
Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n;cin>>n;
  bool used[n+10]={};
  vector<int>bo(n+10)
  for(int i=1;i<=n;i++){
    cin>>bo[i];
  }
  int cnt=0;
  int now=1;
  bool flag=true;
  while(1){
    if(used[now]){flag=false;break;}
    used[now]=true;
    now=bo[now];
    cnt++;
    if(now==2)break;
  }
  if(flag)cout<<cnt<<endl;
  else cout<<-1<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:3: error: expected ',' or ';' before 'for'
   16 |   for(int i=1;i<=n;i++){
      |   ^~~
a.cc:16:15: error: 'i' was not declared in this scope
   16 |   for(int i=1;i<=n;i++){
      |               ^
Language: C++

#include<cstdio>

int a[100001],ans,n;
int dispo=1;
bool c[100001];

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        if(dispo==2){
            printf("%d",ans);
            return 0;
        }else if(c[dispo]&1){
            printf("-1");
            return 0;
        }
        ++c[dispo];
        dispo=a[dispo];
        ++ans;
    }
}



Compiler output:
a.cc: In function 'int main()':
a.cc:8:5: error: 'cin' was not declared in this scope
    8 |     cin>>n;
      |     ^~~
a.cc:20:18: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   20 |         ++c[dispo];
      |           ~~~~~~~^
Language: C++

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main(void) {
  int pus, n, count = 0, times = 0;
  cin >> n;
  int buton[n];
  for (int i = 0; i < n; i++) {
    cin >> buton[i];
  }
  pus = buton[0];
  count = times = 1;
  if (pus == 2) {
    cout << count << endl;
    return;
  }
  while (true) {
    if (buton[pus - 1] == 2) {
      cout << count + 1 << endl;
      return 0;
    }
    pus = buton[pus - 1];
    count++;
    times++;
    if (times > n * 2) {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}


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

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

int main() {
  int n;
  cin >>n;
  int a[1000001];
  for(int i=1;i<=n;i++) {
    cin >> a[i];
  }
  int now=1;
  int sum=0;
  while(ans==0) {
    sum +=1;
    if(a[now]==2) {
      cout << sum <<endl;break;
    }
    else if(sum > n) {
      cout << -1 <<endl; break;
    }
    else if(a[now]==now) {
      ans=-1;break;
    }
    else {
      now=a[now]; continue;
    }
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   13 |   while(ans==0) {
      |         ^~~
      |         abs
Language: C++

#include <iostream>
using namespace std;

int main() {
    int N;
    cin >> N;

    int a[110000];
    for(int i = 0; i < N; i++) cin >> a[i];

    int cur_pos = 0;

    int count = 0;
    bool reachable = true;
    int prev_pos1 = 0;
    int prev_pos2 = 0;

    bool reachable2 = false:
    for(int i= 0; i < N; i++) {
        if(a[i] == 2) {
            reachable2 = true;
        }
    }

    if(!reachable2) {
        cout << "-1" << endl;
        return 0;
    }

    while(1){
        if(a[cur_pos] == 2) {
            //到達できた場合
            break;
        }
        if(count > 2) { 
            if(prev_pos2 == cur_pos || prev_pos1 == cur_pos) {
                //ループしてる場合
                reachable = false;
                break;
            }
        }
        prev_pos2 = prev_pos1;
        prev_pos1 = cur_pos;
        cur_pos = a[cur_pos];
        count++;
    }    
    if(!reachable) {
        cout << "-1" << endl; 
    } else {
        cout << count << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:28: error: expected ',' or ';' before ':' token
   18 |     bool reachable2 = false:
      |                            ^
a.cc:19:19: error: 'i' was not declared in this scope
   19 |     for(int i= 0; i < N; i++) {
      |                   ^
Language: C++

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

int main(){
  int N;
  int a[200000];
  bool b[200000];
  bool clear = false;
  int pos = 0;
  int count = 1;

  cin >> N;
  for(int i=0;i<N;++i){
    cin >> a[i];
    b[i] = true;
  }

  for(int i=0;i<N;++i){
    if(a[pos]-1 == 1){
      clear = true;
      break;
    }else if(b[pos]){
      b[pos] = false;
      pos = a[pos]-1;
      count++;
    }else{
      break;
    }
  }

  if(clear){
    cout << count << endl;
  }else{
    cout << -1 << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:3: error: 'cin' was not declared in this scope
   13 |   cin >> N;
      |   ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include <cmath>
  +++ |+#include <iostream>
    3 | using namespace std;
a.cc:33:5: error: 'cout' was not declared in this scope
   33 |     cout << count << endl;
      |     ^~~~
a.cc:33:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:33:22: error: 'endl' was not declared in this scope
   33 |     cout << count << endl;
      |                      ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include <cmath>
  +++ |+#include <ostream>
    3 | using namespace std;
a.cc:35:5: error: 'cout' was not declared in this scope
   35 |     cout << -1 << endl;
      |     ^~~~
a.cc:35:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:35:19: error: 'endl' was not declared in this scope
   35 |     cout << -1 << endl;
      |                   ^~~~
a.cc:35:19: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
Language: C++

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, a[MAX], cnt = 0;
    cin >> N;

    bool flag = false;
    for (int i = 1; i <= N; i++){
        cin >> a[i];
    }

    for( int i = 1; ; ){
        cnt++;
        if( a[i] == 2){
            flag = true;
            break;
        }
        i = a[i];

        if (cnt > N){ break;
    }

    if (flag){ cout << cnt << endl;}
    else{ cout << -1 << endl;}


    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:2: error: expected '}' at end of input
   67 | }
      |  ^
a.cc:38:11: note: to match this '{'
   38 | int main(){
      |           ^
Language: Java

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int[] a = new int[N];
  for(int i = 0;i < N;i++)a[i] = sc.nextInt();
  int b = 0;
  int c = 0;
  for(int i = 0;;i++){
    if(a[b] == 2){
      System.out.println(i+1);
      break;
    }
    else if(a[b] == 1){
      System.out.println("-1");
      break;
    }
    c = a[b];
    else b = c-1;
  }
}}


Compiler output:
Main.java:20: error: 'else' without 'if'
    else b = c-1;
    ^
1 error
Language: C++

#include <iostream>
using namespace std;

int main(){
	int N;
	cin >> N;
	int a[N];
	for(int i=0; i<N; i++) cin >> a[i];

	Light=a[0];

	while(Light!=1){
		Light=a[Light-1];
		if(Light==2){
			break;
		}
	}
	if(Light==1) cout << "No" << endl;
	if(Light==2) cout << "Yes" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:9: error: 'Light' was not declared in this scope
   10 |         Light=a[0];
      |         ^~~~~
Language: C++

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

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

double const pi=3.1415926535;

int printint(int n){
	cout<<n<<endl;
	return 0;
}

int prints(string s){
	cout<<s<<endl;
	return 0;
}

int main(){
	int n;
	cin>>n;
	int a[114514];
	rep(n)cin>>a[i];
	bool a[114514];
	rep(n)a[i]=false;
	int index=1;
	int ans=0;
	while(true){
		if(a[index]==true){
			cout<<-1<<endl;
			return 0;
		}
		ans++;
		a[index]=true;
		index=a[index];
		if(index==2){
			cout<<ans<<endl;
			return 0;
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:14: error: conflicting declaration 'bool a [114514]'
   27 |         bool a[114514];
      |              ^
a.cc:25:13: note: previous declaration as 'int a [114514]'
   25 |         int a[114514];
      |             ^