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

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vetor>
#include <algorithm>
#include <climits>
#include <ctime>

const int len = 100010;
int n,x,a,b;

int main() {
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    cin >> x >> a >> b;
    n = x-a+b;
    if (n > x) cout << "safe";
    else cout << "delicious";
    return 0;
}

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

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

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  vector<int> b(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  int c=0;
  int k=0;
  int s=1;
  while(true) {
    s=a.at(s-1);
    c++;
    if(s==2) {
      cout<<c<<endl;
      break;
    }
    for(int i=0;i<N;i++) {
      if(s==b.at(i)) {
        cout<<"-1"<<endl;
        k=1;
        break;
      }
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:27:6: error: expected '}' at end of input
   27 |     }
      |      ^
a.cc:14:15: note: to match this '{'
   14 |   while(true) {
      |               ^
a.cc:27:6: error: expected '}' at end of input
   27 |     }
      |      ^
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;
map<int,int> a;
for(int i=1;i<=n;i++) cin >> a[i] 
bool flag=false;  
int num=0;
int i=1;  
int j=1;  
while(a[i]>0){
  num++;
  j=i;
if(a[j]==2){
            flag=true;
            break;
            }
else {
  j=a[i];
  a[i]=-1;
  i=j;
}
  if(flag) cout << num << endl;
  else cout << -1 << endl;
}  


}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:34: error: expected ';' before 'bool'
    8 | for(int i=1;i<=n;i++) cin >> a[i]
      |                                  ^
      |                                  ;
    9 | bool flag=false;
      | ~~~~                              
a.cc:17:13: error: 'flag' was not declared in this scope
   17 |             flag=true;
      |             ^~~~
a.cc:25:6: error: 'flag' was not declared in this scope
   25 |   if(flag) cout << num << endl;
      |      ^~~~
Language: C++

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

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

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

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:22:4: error: expected '}' at end of input
   22 |   }
      |    ^
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> train(N);
  for(i=0;i<N;i++){
    cin>>train.at(i);
  }
  int s=train.at(0);
  int n=0;
  for(int i=0;i<N;i++){
    s=train.at(s-1);
    n++;
    if(s==2){
      cout<<n<<endl;
      break;
    }
    else if(i==N-1){
      cout<<"-1"<<endl;
    }
  }
}


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

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

int main() {
  ll n; cin >> n;
  vector<int> p(n+1);
  for(int i=1; i<=n; i++) cin >> p[i];
  
  int a = 1;  int cnt = 0;
  vector<bool> v(n+1,false);
  rep(i, n){
    if(a == 2)  { cout << cnt << endl; return 0; }
    if(v[a] == true)  { cout << -1 << endl; return 0; }
    v[a] = true;
    a = p[a];
    cnt++;
}

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

# 入力
N=int(input())

l=[]
for i in range(N):
  l.append(int(input()))

# 押してない：0
# 押した：1
l2=[0]*N

# 1番目は「押した：1」にしておく
l2[0]=1

# 回数カウント
c=0

i=1
while True:
  # 回数をインクリメント
  c+=1

  # 次のボタン番号を取得
  i=l[i-1]

  # 2番目のライトが光る場合は回数を出力して終了
  if i==2:
    print(c)
    exit()

  if l2[i-1]==1:
    # 無限ループ確定で終了
    print(-1)
    exit()
  else:
    # 押した／押してない を更新
    l2[i-1]=1

Compiler output:
a.cc:1:3: error: invalid preprocessing directive #\U00005165\U0000529b
    1 | # 入力
      |   ^~~~
a.cc:8:3: error: invalid preprocessing directive #\U000062bc\U00003057\U00003066\U0000306a\U00003044\U0000ff1a0
    8 | # 押してない：0
      |   ^~~~~~~~~~~~~
a.cc:9:3: error: invalid preprocessing directive #\U000062bc\U00003057\U0000305f\U0000ff1a1
    9 | # 押した：1
      |   ^~~~~~~~~
a.cc:12:3: error: extended character 「 is not valid in an identifier
   12 | # 1番目は「押した：1」にしておく
      |   ^
a.cc:12:3: error: extended character 」 is not valid in an identifier
a.cc:12:3: error: "1番目は「押した：1」にしておく" after # is not a positive integer
   12 | # 1番目は「押した：1」にしておく
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:15:3: error: invalid preprocessing directive #\U000056de\U00006570\U000030ab\U000030a6\U000030f3\U000030c8
   15 | # 回数カウント
      |   ^~~~~~~~~~~~
a.cc:20:5: error: invalid preprocessing directive #\U000056de\U00006570\U00003092\U000030a4\U000030f3\U000030af\U000030ea\U000030e1\U000030f3\U000030c8
   20 |   # 回数をインクリメント
      |     ^~~~~~~~~~~~~~~~~~~~
a.cc:23:5: error: invalid preprocessing directive #\U00006b21\U0000306e\U000030dc\U000030bf\U000030f3\U0000756a\U000053f7\U00003092\U000053d6\U00005f97
   23 |   # 次のボタン番号を取得
      |     ^~~~~~~~~~~~~~~~~~~~
a.cc:26:5: error: "2番目のライトが光る場合は回数を出力して終了" after # is not a positive integer
   26 |   # 2番目のライトが光る場合は回数を出力して終了
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:32:7: error: invalid preprocessing directive #\U00007121\U00009650\U000030eb\U000030fc\U000030d7\U000078ba\U00005b9a\U00003067\U00007d42\U00004e86
   32 |     # 無限ループ確定で終了
      |       ^~~~~~~~~~~~~~~~~~~~
a.cc:36:7: error: invalid preprocessing directive #\U000062bc\U00003057\U0000305f\U0000ff0f\U000062bc\U00003057\U00003066\U0000306a\U00003044
   36 |     # 押した／押してない を更新
      |       ^~~~~~~~~~~~~~~~~~
a.cc:2:1: error: 'N' does not name a type
    2 | N=int(input())
      | ^
Language: Java

import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine()));
        }
        sc.close();
        int cnt = 0;
        int push = 1;
        while (1){
            cnt++;
            push = a.get(push);
            if (push == 2){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        }
    }
}

Compiler output:
Main.java:14: error: incompatible types: int cannot be converted to boolean
        while (1){
               ^
1 error
Language: Java

import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine()));
        }
        sc.close();
        int cnt = 0;
        int push = 1
        while (1){
            cnt++;
            push = a.get(push);
            if (push == 2){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        }
    }
}

Compiler output:
Main.java:13: error: ';' expected
        int push = 1
                    ^
1 error
Language: C++

#include "pch.h"
#include <iostream>
#include <vector>
using namespace std;

void end() {
	cout << "-1" << endl;
}

int main() {
	int n, count = 0, x = 0;
	cin >> n;
	vector <int> a(n);

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

	for (int i = 0; i < n; i++) {
		x = a.at(i);
		count++;
		if (x == 2) {
			cout << count - 1 << endl;
		}
	}
	cout << "-1" << endl;
}

Compiler output:
a.cc:1:10: fatal error: pch.h: No such file or directory
    1 | #include "pch.h"
      |          ^~~~~~~
compilation terminated.
Language: C++

#include "pch.h"
#include <iostream>
#include <vector>
using namespace std;

void end() {
	cout << "-1" << endl;
}

int main() {
	int n, count = 0, x = 0;
	cin >> n;
	vector <int> a(n);

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

	for (int i = 0; i < n; i++) {
		x = a.at(i);
		count++;
		if (x == 2) {
			cout << count - 1 << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
}

Compiler output:
a.cc:1:10: fatal error: pch.h: No such file or directory
    1 | #include "pch.h"
      |          ^~~~~~~
compilation terminated.
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[i];
   int count = 0;
   int n = 0;
   while(1){
      count++;
      if(a[a[n]] == 1){
         cout << -1 << endl;
         break;
      }else if(a[a[n]] == 2){
         cout << count << endl;
         break;
      }
      n = a[n] - 1;
   }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:8: error: redeclaration of 'int n'
   11 |    int n = 0;
      |        ^
a.cc:6:8: note: 'int n' previously declared here
    6 |    int n;
      |        ^
Language: C++

/*
      author  : nishi5451
      created : 14.08.2020 13:18:13
*/

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


int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<bool> dp(n+1,false);
    for(int i=1; i<=n; i++) cin >> a[i];
    int now = a[1];
    dp[1]=true;
    while(1){
        now = a[now];
        if(now == 2){
            cout << i << endl;
            return 0;
        }
        if(dp[now]=true){
            break;
        }
        dp[now]=true;
    }
    cout << -1 << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:21: error: 'i' was not declared in this scope
   23 |             cout << i << endl;
      |                     ^
Language: C++

using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a = 1;
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  for (int i = 0; i < N + 1; i++) {
    a = vec.at(a - 1);
    if (a == 2) {
      a = i + 1;
      cout << a << endl;
      a = -1;
      break;
    }
  }    
  if (a != -1) 
    cout << -1 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:3: error: 'cin' was not declared in this scope
    5 |   cin >> N;
      |   ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:6:3: error: 'vector' was not declared in this scope
    6 |   vector<int> vec(N);
      |   ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:6:10: error: expected primary-expression before 'int'
    6 |   vector<int> vec(N);
      |          ^~~
a.cc:10:12: error: 'vec' was not declared in this scope
   10 |     cin >> vec.at(i);
      |            ^~~
a.cc:14:9: error: 'vec' was not declared in this scope
   14 |     a = vec.at(a - 1);
      |         ^~~
a.cc:17:7: error: 'cout' was not declared in this scope
   17 |       cout << a << endl;
      |       ^~~~
a.cc:17:7: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:17:20: error: 'endl' was not declared in this scope
   17 |       cout << a << endl;
      |                    ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;
a.cc:23:5: error: 'cout' was not declared in this scope
   23 |     cout << -1 << endl;
      |     ^~~~
a.cc:23:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:23:19: error: 'endl' was not declared in this scope
   23 |     cout << -1 << endl;
      |                   ^~~~
a.cc:23: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;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a = 1;
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  for (int i = 0; i < N + 1; i++) {
    a = vec.at(a - 1);
    if (a == 2) {
      a = i + 1;
      cout << a << endl;
      a = -1;
      break;
    }
  }
    
  if (a == -1) 
    cout << a << endl;
  }
}

Compiler output:
a.cc:27:1: error: expected declaration before '}' token
   27 | }
      | ^
Language: C++

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

int a[100050];

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

    int n;
    cin>>n;
    
    for(int i=0;i<n;i++)cin>>a[i];
    
    int c=1;
    int cnt=0;
    
    while(int i=0;i<n;i++)
    {
        if(c==a[c-1])
        {
            c=1;
            break;
        }
        c=a[c-1];
        cnt++;
        if(c==1)break;
        if(c==2)break;
    }
    
    if(c==1)cout<<-1;
    else cout<<cnt;
    cout<<"\n";

    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:19:18: error: expected ')' before ';' token
   19 |     while(int i=0;i<n;i++)
      |          ~       ^
      |                  )
a.cc:19:19: error: 'i' was not declared in this scope
   19 |     while(int i=0;i<n;i++)
      |                   ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
    int N;
cin >> N ;
  int A[N];
  for (int i=0 ; i<N ; i++){
    cin >> A[i];
  }
  int count=0;
  for (int c=1 ; c != 2  ;){
   c=A[c]
     count++;
   if (count = N){
     cout << -1 << endl;
     return 0;
   }
  }
  cout << count << endl ;
}
    

Compiler output:
a.cc: In function 'int main()':
a.cc:13:10: error: expected ';' before 'count'
   13 |    c=A[c]
      |          ^
      |          ;
   14 |      count++;
      |      ~~~~~
Language: C++

#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int cnt = 1, p = 1;
    while(cnt<n){
        p = a[p-1];
        if(p==2){
            break;
        }
        cnt++;
    }
    if(p==2){
        cout << cnt << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'vector' was not declared in this scope
    6 |     vector<int>a(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:6:12: error: expected primary-expression before 'int'
    6 |     vector<int>a(n);
      |            ^~~
a.cc:8:16: error: 'a' was not declared in this scope
    8 |         cin >> a[i];
      |                ^
a.cc:12:13: error: 'a' was not declared in this scope
   12 |         p = a[p-1];
      |             ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> buttons(N);
  
  for (int n = 0; n < N; n++) {
    int bottunNum;
    cin >> bottunNum;
    buttons.at(n) = bottunNum;
  }
  
  vector<int> pushed;
  for (int n = 0; n < N; n++) {
    if (n == 0) {
      pushed.push_back(buttons.at(n));
    } else {
      now = pushed.at(n-1);
      if (now == 2) {
        cout << n << endl;
      } else {
        for (int p = 0; p < pushed.size(); p++) {
          if (pushed.at(p) == now) {
            cout << -1 << endl;
            break;
          }
        }
        pushed.push_back(buttons.at(n));
      }
    }
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:7: error: 'now' was not declared in this scope; did you mean 'pow'?
   20 |       now = pushed.at(n-1);
      |       ^~~
      |       pow
Language: C++

#include<bits/stdc++.h>
using namespace std;
int button(int n,int a[]){
    int ret=0;
    int light=a[0];
    a[0]=0;
    ret++;
    while(light!=2&&light!=0){
        int k;
        k=a[light];
        a[light]=0;
        light=k;
        ret++;
    }
    if(light==0) return -1;
    if(light==2) return ret;


}*/
int button(int n , int a[]){
    int ret=0;
    int light=a[0];
    ret++;
    while(light!=2&& ret<n){
        light=a[light];
        ret++;
    }
}
int main(){
    int n;
    cin>>n;
    int but[n];
    if(button(n,but)!=-1){
        cout<<button(n,but)<<endl;
    }else{
        cout<<-1<<endl;
    }

}

Compiler output:
a.cc:19:3: error: expected unqualified-id before '/' token
   19 | }*/
      |   ^
a.cc: In function 'int button(int, int*)':
a.cc:19:1: warning: control reaches end of non-void function [-Wreturn-type]
   19 | }*/
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int button(int n,int a[]){
    int ret=0;
    int light=a[0];
    a[0]=0;
    ret++;
    while(light!=2&&light!=0){
        int k;
        k=a[light];
        a[light]=0;
        light=k;
        ret++;
    }
    if(light==0) return -1;
    if(light==2) return ret;


}
int main(){
    int n;
    cin>>n;
    int but[n];
    if(button(n,but!=-1){
        cout<<button(n,but)<<endl;
    }else{
        cout<<-1<<endl;
    }

}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:20: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   24 |     if(button(n,but!=-1){
      |                 ~~~^~~~
a.cc:24:20: error: cannot convert 'bool' to 'int*'
   24 |     if(button(n,but!=-1){
      |                 ~~~^~~~
      |                    |
      |                    bool
a.cc:3:22: note:   initializing argument 2 of 'int button(int, int*)'
    3 | int button(int n,int a[]){
      |                  ~~~~^~~
a.cc:24:25: error: expected ')' before '{' token
   24 |     if(button(n,but!=-1){
      |       ~                 ^
      |                         )
a.cc:30:1: error: expected primary-expression before '}' token
   30 | }
      | ^
a.cc: In function 'int button(int, int*)':
a.cc:19:1: warning: control reaches end of non-void function [-Wreturn-type]
   19 | }
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int button(int n, vector<int> a(n)){
    int ret=0;
    int light=a(n).at(0);
    a(n).at(0)=0;
    ret++;
    while(light!=2&&light!=0){
        int k;
        k=a(n).at(light);
        a(n).at(light)=0;
        light=k;
        ret++;
    }
    if(light==0) return -1;
    if(light==2) return ret;


}
int main(){
    int n;
    cin>>n;
    vector<int> but(n);
    if(button(n,but(n))!=-1){
        cout<<button(n,but(n))<<endl;
    }else{
        cout<<-1<<endl;
    }

}

Compiler output:
a.cc:3:32: error: expected ',' or '...' before '(' token
    3 | int button(int n, vector<int> a(n)){
      |                                ^
a.cc: In function 'int button(int, std::vector<int>)':
a.cc:5:16: error: no match for call to '(std::vector<int>) (int&)'
    5 |     int light=a(n).at(0);
      |               ~^~~
a.cc:6:6: error: no match for call to '(std::vector<int>) (int&)'
    6 |     a(n).at(0)=0;
      |     ~^~~
a.cc:10:12: error: no match for call to '(std::vector<int>) (int&)'
   10 |         k=a(n).at(light);
      |           ~^~~
a.cc:11:10: error: no match for call to '(std::vector<int>) (int&)'
   11 |         a(n).at(light)=0;
      |         ~^~~
a.cc: In function 'int main()':
a.cc:24:20: error: no match for call to '(std::vector<int>) (int&)'
   24 |     if(button(n,but(n))!=-1){
      |                 ~~~^~~
a.cc:25:27: error: no match for call to '(std::vector<int>) (int&)'
   25 |         cout<<button(n,but(n))<<endl;
      |                        ~~~^~~
a.cc: In function 'int button(int, std::vector<int>)':
a.cc:19:1: warning: control reaches end of non-void function [-Wreturn-type]
   19 | }
      | ^
Language: C++

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

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

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:12:7: error: 'i' was not declared in this scope
   12 |   for(i=1;i<N;i++){
      |       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9  + 5;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n = INF;
	cin >> n;
	int ans = -1;
	vector<int> v(n);
	for(int i = 0;i<n;++i) {
		int temp;
		cin >> temp;
		v.push_back(temp);
	}
	int curr = v[0];	
	for(int i =0;i<n+1;++i) {
		if(v[curr-1] == 2) {
			ans = i + 1;
			break;
		}
		curr = nums[curr-1];
	}
	cout << ans << '\n';
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:24: error: 'nums' was not declared in this scope
   22 |                 curr = nums[curr-1];
      |                        ^~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    mp[i + 1] = x;
  }

  int t = mp[i], ans = 0, i = 0;
  set<int> s;
  bool ok = true;
  while (t != 2) {
    if (s.find(t) != s.end()) {
      ok = false;
      break;
    } else {
      s.insert(t);
      t = mp[t];
    }
    ++ans;
  }
  if (ok)
    cout << ans + 1;
  else
    cout << -1;

  return 0;
}


Compiler output:
a.cc:20:29: warning: overflow in conversion from 'double' to 'int' changes value from '1.000000001e+18' to '2147483647' [-Woverflow]
   20 | const int inf = 1e18 + iinf + 10;
      |                 ~~~~~~~~~~~~^~~~
a.cc: In function 'int main()':
a.cc:46:14: error: 'i' was not declared in this scope
   46 |   int t = mp[i], ans = 0, i = 0;
      |              ^
a.cc:57:7: error: 'ans' was not declared in this scope; did you mean 'abs'?
   57 |     ++ans;
      |       ^~~
      |       abs
a.cc:60:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   60 |     cout << ans + 1;
      |             ^~~
      |             abs
Language: C++

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

int main()
{
  int N,cnt = 0;
  cin>>N;
  vector<int> a(N);
  
  for(int ni=0;ni<N;ni++)
  {
	cin>>a.at(ni);
    cnt++;
    if(2 == a.at.(ni))
      break;
  }
  cout<<cnt<<endl;
  return 0;
}

    

Compiler output:
a.cc: In function 'int main()':
a.cc:15:15: error: invalid use of member function 'std::vector<int>::at' (did you forget the '()' ?)
   15 |     if(2 == a.at.(ni))
      |             ~~^~
Language: C++

#include <bits/stdc++.h>
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:7:7: error: extended character ” is not valid in an identifier
    7 | scanf(”%d ”, &n);
      |       ^
a.cc:7:11: error: extended character ” is not valid in an identifier
    7 | scanf(”%d ”, &n);
      |           ^
a.cc:12:7: error: extended character ” is not valid in an identifier
   12 | scanf(”%d ”, &z );
      |       ^
a.cc:12:11: error: extended character ” is not valid in an identifier
   12 | scanf(”%d ”, &z );
      |           ^
a.cc:13:1: error: extended character − is not valid in an identifier
   13 | z−−;
      | ^
a.cc:13:1: error: extended character − is not valid in an identifier
a.cc:21:8: error: extended character ” is not valid in an identifier
   21 | printf(”%d\n ”, c );
      |        ^
a.cc:21:11: error: stray '\' in program
   21 | printf(”%d\n ”, c );
      |           ^
a.cc:21:14: error: extended character ” is not valid in an identifier
   21 | printf(”%d\n ”, c );
      |              ^
a.cc:26:8: error: extended character ” is not valid in an identifier
   26 | printf(”−1\n ”);
      |        ^
a.cc:26:8: error: extended character − is not valid in an identifier
a.cc:26:11: error: stray '\' in program
   26 | printf(”−1\n ”);
      |           ^
a.cc:26:14: error: extended character ” is not valid in an identifier
   26 | printf(”−1\n ”);
      |              ^
a.cc: In function 'int main()':
a.cc:7:7: error: '\U0000201d' was not declared in this scope
    7 | scanf(”%d ”, &n);
      |       ^
a.cc:7:9: error: 'd' was not declared in this scope
    7 | scanf(”%d ”, &n);
      |         ^
a.cc:13:1: error: 'z\U00002212\U00002212' was not declared in this scope
   13 | z−−;
      | ^~~
a.cc:14:3: error: 'class std::vector<int>' has no member named 'push'
   14 | v.push back(z);
      |   ^~~~
a.cc:26:8: error: '\U0000201d\U000022121' was not declared in this scope
   26 | printf(”−1\n ”);
      |        ^~~
Language: C++

#include <bits/stdc++.h>

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

using namespace std;

int main() {

    int n; cin >> n;
    int cur = 1;
    int ans = 0;
    vector<int> a(n+1);
    vector<bool> l(n+1);
    rep(i,n) cin >> a[i+1];a
    rep(i,n) l[i+1] = false;

    while(1){
        if(l[cur]) break;
        else{
            if(cur == 2) break;
            l[cur] = true;
            cur = a[cur];
            ans ++;
        }
    }

    if(cur == 2) cout << ans;
    else cout << -1;

    return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:15:29: error: expected ';' before 'for'
   15 |     rep(i,n) cin >> a[i+1];a
      |                             ^
      |                             ;
a.cc:16:9: error: 'i' was not declared in this scope
   16 |     rep(i,n) l[i+1] = false;
      |         ^
a.cc:3:35: note: in definition of macro 'rep'
    3 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
Language: C++

#include <bits/stdc++.h>

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

using namespace std;

int main() {

    int n; cin >> n;
    int cur = 1;
    int ans = 0;
    vector<int> a(n+1);
    vector<bool> l(n+1);
    rep(i,n) cin >> a[i+1];a
    rep(i,n) l[i+1] = false;

    while(1){
        if(l[cur]) break;
        else{
            if(cur == 2) break;
            l[cur] = true;
            cur = a[cur];
            ans ++;
        }
    }

    if(cur == 2) cout << ans;
    else cout << -1;

    return 0;
}











Compiler output:
a.cc: In function 'int main()':
a.cc:15:29: error: expected ';' before 'for'
   15 |     rep(i,n) cin >> a[i+1];a
      |                             ^
      |                             ;
a.cc:16:9: error: 'i' was not declared in this scope
   16 |     rep(i,n) l[i+1] = false;
      |         ^
a.cc:3:35: note: in definition of macro 'rep'
    3 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
Language: C++

#include <cstdlib>

using namespace std;

int a[100000];
int n;
int cnt = 1;

int botton(int x){
  if(cnt > n) {
    return -1;
  }
  if(a[x] == 2) {
    return cnt;
  } else {
    cnt++;
    return botton(a[x]);
  }
}


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


Compiler output:
a.cc: In function 'int main()':
a.cc:23:3: error: 'cin' was not declared in this scope
   23 |   cin >> n;
      |   ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <cstdlib>
  +++ |+#include <iostream>
    2 | 
a.cc:27:3: error: 'cout' was not declared in this scope
   27 |   cout << botton(1) << endl;
      |   ^~~~
a.cc:27:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:27:24: error: 'endl' was not declared in this scope
   27 |   cout << botton(1) << endl;
      |                        ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <cstdlib>
  +++ |+#include <ostream>
    2 |
Language: C++

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

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


Compiler output:
a.cc: In function 'int main()':
a.cc:15:15: error: expected primary-expression before ';' token
   15 |     i=a.at(i)-;
      |               ^
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 (;;)
{
{
} }

Compiler output:
a.cc:1:19: warning: extra tokens at end of #include directive
    1 | #include<stdio.h> #include<vector> #include<algorithm>
      |                   ^
a.cc:5:7: error: extended character ” is not valid in an identifier
    5 | scanf(”%d”, &n); vector<int>v ;
      |       ^
a.cc:5:9: error: extended character ” is not valid in an identifier
    5 | scanf(”%d”, &n); vector<int>v ;
      |         ^
a.cc:7:14: error: extended character ” is not valid in an identifier
    7 | int z; scanf(”%d”, &z); z −−;
      |              ^
a.cc:7:16: error: extended character ” is not valid in an identifier
    7 | int z; scanf(”%d”, &z); z −−;
      |                ^
a.cc:7:27: error: extended character − is not valid in an identifier
    7 | int z; scanf(”%d”, &z); z −−;
      |                           ^
a.cc:7:27: error: extended character − is not valid in an identifier
a.cc: In function 'int main()':
a.cc:5:7: error: '\U0000201d' was not declared in this scope
    5 | scanf(”%d”, &n); vector<int>v ;
      |       ^
a.cc:5:9: error: 'd\U0000201d' was not declared in this scope
    5 | scanf(”%d”, &n); vector<int>v ;
      |         ^~
a.cc:5:18: error: 'vector' was not declared in this scope
    5 | scanf(”%d”, &n); vector<int>v ;
      |                  ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include<stdio.h> #include<vector> #include<algorithm>
  +++ |+#include <vector>
    2 | using namespace std ; int main()
a.cc:5:25: error: expected primary-expression before 'int'
    5 | scanf(”%d”, &n); vector<int>v ;
      |                         ^~~
a.cc:7:26: error: expected ';' before '\U00002212\U00002212'
    7 | int z; scanf(”%d”, &z); z −−;
      |                          ^~~
      |                          ;
a.cc:8:1: error: 'v' was not declared in this scope
    8 | v. push back(z );
      | ^
a.cc:13:4: error: expected '}' at end of input
   13 | } }
      |    ^
a.cc:3:1: note: to match this '{'
    3 | {
      | ^
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 (;;)
{
{
} }

Compiler output:
a.cc:1:20: warning: extra tokens at end of #include directive
    1 | #include<stdio .h> #include<vector> #include<algorithm>
      |                    ^
a.cc:1:9: fatal error: stdio .h: No such file or directory
    1 | #include<stdio .h> #include<vector> #include<algorithm>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

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

int main()
{
  int n;
  cin >> n;
  int a[n];
  int b = 0;
  int ans = 0;
  rep(i, n){
    cin >> a[i];
    if(a[i] == 2) b = 1;
  }
  map<int, int> mp;
  if(b == 0){
    cout << -1 << endl;
  }
  else{
    int cnt = 0;
    int x = 1;
    b = 0;
    while(cnt < n){
      ans++;
      if(a[x - 1] == 2){
        b = 1;
        break;
      }
      x = a[x - 1];
    }
    cout << (b ? ans : -1) << endl;
  }
 
  }
      
    
    
    
  

  //cout << ans << endl;
  return 0;
}


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

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

int main()
{
  int n;
  cin >> n;
  int a[n];
  int b = 0;
  int ans = 0;
  rep(i, n){
    cin >> a[i];
    if(a[i] == 2) b = 1;
  }
  map<int, int> mp;
  if(b = 0){
    cout << -1 << endl;
  }
  else{
    int cnt = 0;
    int x = 1;
    while(cnt < n){
      ans++;
      if(a[x - 1] == 2){
        break;
      }
      x = a[x - 1];
    }
    cout << (b ? ans : -1) << endl;
  }
 
  }
      
    
    
    
  

  //cout << ans << endl;
  return 0;
}


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

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

int main() {
	int button = 0;
  	int array = 0;
	int check = 0;
	int nextlight = 0;
	int count = 0;
	cin >> button;
	vector<int> light(button);
	for (int loopI = 0; loopI < button; loopI++) {
    	cin >> array;
        light.at(i) = array;
    }
	for (int loopII = 0; loopII < button; loopII++) {
    	nextlight = light.at(loopII) - 1;
    	if (light.at(nextlight) == 2) {
        	check = 1;
        	break;
        }
        else{
        	count++;
        }        
	}
    if (check == 0) {
    	cout << "-1" << endl;
    }
    else{
    	cout << count << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:18: error: 'i' was not declared in this scope
   14 |         light.at(i) = array;
      |                  ^
Language: C++

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

int main() {
	int button = 0;
  	int array = 0;
	int check = 0;
	int nextlight = 0;
	int count = 0;
	cin >> button;
	vector<int> light(button);
	for (int loopI = 0; loopI < button; loopI++) {
    	cin >> array;
        light.at(i) = array;
    }
	for (int loopII = 0; loopII < button; loopII++) {
    	nextlight = light.at(loopII) - 1;
    	if (light.at(nextlight) == 2) {
        	check = 1;
        	break;
        }
        else{
        	count++;
        }        
	}
    if (check == 0) {
    	cout << "-1" << endl;
    }
    else{
    	cout << count << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:18: error: 'i' was not declared in this scope
   14 |         light.at(i) = array;
      |                  ^
Language: C++

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

int main() {
  int n;
  int i = 1;
  vector<int> vec(100005);
  vector<bool> jud(100005);
  
  cin >> n;
  rep(i, n)
    cin >> vec.at(i + 1);
  
  do{
    
    if(jud.at(i) == false){
      jud.at(i) = true;
      i = vec.at(i)
    }
    else{
      i = -1;
      break;
    }
      
  } while(i != 2);
  
  cout << i << endl;

}


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

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

int main() {
  int n;
  int i = 1;
  vector<int> vec(100005);
  vector<bool> jud(100005);
  
  cin >> n;
  rep(i, n)
    cin >> vec.at(i + 1);
  
  do{
    
    if(jud.at(i) == false){
      jud.at(i) = true;
      i = vec.at(i)
    }
    else{
      i = -1;
      break;
    }
      
  } while(i != 2);
  
  cout << i << emdl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:20: error: expected ';' before '}' token
   19 |       i = vec.at(i)
      |                    ^
      |                    ;
   20 |     }
      |     ~               
a.cc:28:16: error: 'emdl' was not declared in this scope
   28 |   cout << i << emdl;
      |                ^~~~
Language: C++


#include<bits/stdc++.h>
#include <string> 

using namespace std;
int X,N;
int A[2000010]{};
bool B[2000010]{};

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

  cout<<-1;
  return 0;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:18:11: error: expected primary-expression before ')' token
   18 |     if(i==){
      |           ^
Language: C++

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n){
        ll b; cin>>b;
        b--;
        a[i]=b;
    }
    ll cnt=0,tmp=0;
    while(true){
        if(tmp==2){
            cout<<cnt<<endl;
            break;
        }
        if(cnt>=n){
            cout<<"-1"<<endl;
            break;
        }
        tmp=a[tmp];
    }
    return 0;
}
v

Compiler output:
a.cc:34:1: error: 'v' does not name a type
   34 | v
      | ^
Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int a[1000010];

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

  int current = a[1];
  a[1] = 0;
  int ans = 1;
  while(i < 100000000) {
    if (a[current] == a[2]) {
      cout << ans << endl;
      return 0;
    }
    if (a[current] == 0) {
      cout << -1 << endl;
      return 0;
    }
    int tmp = current;
    current = a[current];
    // a[tmp] = 0;
    ans++;
  }

  cout << -1 << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:9: error: 'i' was not declared in this scope
   24 |   while(i < 100000000) {
      |         ^
Language: C++

#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    bool re = any_of(a.begin(), a.end(), [](int x) {return x == 2;});
    
    if (!re) {
        cout << -1 << endl;
    } else {
        int j = 1, count = 0;
        vector<int> che(n, 1);
        while (j != 2) {
            if (che[j - 1] == 1) {
                che[j - 1] = 0;
                j = a[j - 1];
                count++;
            } else {
                cout << -1 << endl;
                return 0;
            }
        }
        cout << count << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:5: error: 'vector' was not declared in this scope
    8 |     vector<int> a(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:8:12: error: expected primary-expression before 'int'
    8 |     vector<int> a(n);
      |            ^~~
a.cc:9:40: error: 'a' was not declared in this scope
    9 |     for (int i = 0; i < n; i++) cin >> a[i];
      |                                        ^
a.cc:11:22: error: 'a' was not declared in this scope
   11 |     bool re = any_of(a.begin(), a.end(), [](int x) {return x == 2;});
      |                      ^
a.cc:11:15: error: 'any_of' was not declared in this scope
   11 |     bool re = any_of(a.begin(), a.end(), [](int x) {return x == 2;});
      |               ^~~~~~
a.cc:17:16: error: expected primary-expression before 'int'
   17 |         vector<int> che(n, 1);
      |                ^~~
a.cc:19:17: error: 'che' was not declared in this scope
   19 |             if (che[j - 1] == 1) {
      |                 ^~~
Language: C++

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

int main() {
    int i;

    int n;
    cin >> n;
    
    vector<int> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    
    int count;
    i = 1;
    while (int i != 2) {
        i = a[i];
        count++;
        if (count == 50) {
            cout << -1 <<endl;
            return 0;
        }
    }
    
    cout << count << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:18: error: expected initializer before '!=' token
   15 |     while (int i != 2) {
      |                  ^~
a.cc:15:17: error: expected ')' before '!=' token
   15 |     while (int i != 2) {
      |           ~     ^~~
      |                 )
a.cc:15:18: error: expected primary-expression before '!=' token
   15 |     while (int i != 2) {
      |                  ^~
Language: C++

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    vec.at(i) = a;
  }
  
  int counter = 0;
  int b;
  b = vec.at(0);
  
  for (int i = 0; i < N + 1; i++) {
    if (b == 2) {
      counter++;
      cout << counter << endl;
      break;
    }
    else if (b == 1)
      cout << -1 << endl;
      break;
    else if (b != 2 && b != 1 && i < N) {
      counter++;
      b = vec.at(b-1);
      continue;
    }
    else if (b != 2 && b != 1 && i == N + 1)
    cout << -1 << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:5: error: 'else' without a previous 'if'
   28 |     else if (b != 2 && b != 1 && i < N) {
      |     ^~~~
Language: C++

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    vec.at(i) = a;
  }
  
  int counter = 0;
  int b;
  b = vec.at(0);
  
  for (int i = 0; i < N + 1; i++) {
    if (b == 2) {
      counter++;
      cout << counter << endl;
      break;
    }
    else if (b == 1)
      cout << -1 << endl;
      break;
    else if (b != 2 && b != 1 && i < N) {
      counter++;
      b = vec.at(b-1);
      continue;
    }
    else if (b != 2 && b != 1 && i = N + 1)
    cout << -1 << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:5: error: 'else' without a previous 'if'
   28 |     else if (b != 2 && b != 1 && i < N) {
      |     ^~~~
a.cc:33:31: error: lvalue required as left operand of assignment
   33 |     else if (b != 2 && b != 1 && i = N + 1)
      |              ~~~~~~~~~~~~~~~~~^~~~
Language: C++

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    vec.at(i) = a;
  }
  
  int counter = 0;
  int b;
  b = vec.at(0);
  
  for (int i = 0; i < N + 1; i++) {
    if (b == 2) {
      counter++;
      cout << counter << endl;
      break;
    }
    else if (b == 1)
      cout << -1 << endl;
      break;
    else if (b != 2 && b != 1 && i < N) {
      counter++;
      b = vec.at(b-1);
      continue;
    }
    else if (b != 2 && b != 1 && i = N + 1) {
    cout << -1 << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:5: error: 'else' without a previous 'if'
   28 |     else if (b != 2 && b != 1 && i < N) {
      |     ^~~~
a.cc:33:31: error: lvalue required as left operand of assignment
   33 |     else if (b != 2 && b != 1 && i = N + 1) {
      |              ~~~~~~~~~~~~~~~~~^~~~
a.cc:36:2: error: expected '}' at end of input
   36 | }
      |  ^
a.cc:4:12: note: to match this '{'
    4 | int main() {
      |            ^
Language: C

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

typedef struct array {
    // the type of elements
    typedef int TYPE;
    
    TYPE* m_data;
    int m_size;
    int m_capacity;

    array(int n) : m_size(n), m_capacity(n+1) {
        m_data = (TYPE*)malloc(m_capacity * sizeof(TYPE));
        if(m_data == NULL){
            printf("failed to initialize an array.\n");
            exit(0);
        }
    }
    ~array(){ free(m_data); }

    // push_back
    void push(TYPE x){
        if(m_size == m_capacity){
            m_capacity *= 2;
            TYPE* new_data = (TYPE*)malloc(m_capacity * sizeof(TYPE));
            if(new_data == NULL){
                printf("failed to resize an array.\n");
                exit(0);
            }
            memcpy(new_data, m_data, m_size * sizeof(TYPE));
            free(m_data);
            m_data = new_data;
        }
        m_data[m_size++] = x;
    }

    // pop_back
    void pop(){
        if(m_size * 2 < m_capacity){
            m_capacity /= 2;
            TYPE* new_data = (TYPE*)malloc(m_capacity * sizeof(TYPE));
            if(new_data == NULL){
                printf("failed to resize an array.\n");
                exit(0);
            }
            memcpy(new_data, m_data, (m_size-1) * sizeof(TYPE));
            free(m_data);
            m_data = new_data;
        }
        m_size--;
    }

    void set(int i, TYPE x){
        if(i < 0 || m_size <= i){
            printf("index out of range: %d\n", i);
            exit(0);
        }
        m_data[i] = x;
    }

    int size() const { return m_size; }

    TYPE get(int i) const {
        if(i < 0 || m_size <= i){
            printf("index out of range: %d\n", i);
            exit(0);
        }
        return m_data[i];
    }
} array;


int main(){
    int n;
    scanf("%d", &n);
    array a(n);
    for(int i = 0; i < a.size(); i++){
        int temp;
        scanf("%d", &temp);
        a.set(i, temp-1);
    }
    int j = 0;
    int cnt = 0;
    while(cnt < a.size()){
        j = a.get(j);
        cnt++;
        if(j == 1) break;
    }
    printf("%d\n", (j == 1 ? cnt : -1));
    return 0;
}

Compiler output:
main.c:7:5: error: expected specifier-qualifier-list before 'typedef'
    7 |     typedef int TYPE;
      |     ^~~~~~~
main.c: In function 'main':
main.c:77:5: error: parameter names (without types) in function declaration [-Wdeclaration-missing-parameter-type]
   77 |     array a(n);
      |     ^~~~~
main.c:78:25: error: request for member 'size' in something not a structure or union
   78 |     for(int i = 0; i < a.size(); i++){
      |                         ^
main.c:81:10: error: request for member 'set' in something not a structure or union
   81 |         a.set(i, temp-1);
      |          ^
main.c:85:18: error: request for member 'size' in something not a structure or union
   85 |     while(cnt < a.size()){
      |                  ^
main.c:86:14: error: request for member 'get' in something not a structure or union
   86 |         j = a.get(j);
      |              ^