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 ans = 0;
    int lamp = 1; 
    for (int i = 0; i < N; i++) {
        lamp = a.at(lamp - 1);
        ans++;
        if (lamp == 2) break;
        else if (lamp == 1) {
            ans = -1;
            break;
        else if (i == N - 1) ans = -1;
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:9: error: expected '}' before 'else'
   18 |         else if (i == N - 1) ans = -1;
      |         ^~~~
a.cc:15:29: note: to match this '{'
   15 |         else if (lamp == 1) {
      |                             ^
a.cc: At global scope:
a.cc:21:5: error: 'cout' does not name a type
   21 |     cout << ans << endl;
      |     ^~~~
a.cc:22:1: error: expected declaration before '}' token
   22 | }
      | ^
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;
  b = vec.at(0);
  
  for (int i = 0; i < N + 1; i++) {
    if (b == 2) {
      counter++;
      cout << counter << endl;
      break;
    }
    else if (b == 1) {
      break;
    }
    else if (b != 2 && b != 1) {
      counter++;
      B = b-1;
      b = vec.at(B);
      continue;
    }
  }
  if (b != 2)
  cout << -1 << endl;
  else 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:38:1: error: expected primary-expression before '}' token
   38 | }
      | ^
Language: C++

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

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


Compiler output:
a.cc: In function 'int main()':
a.cc:31:22: error: expected ';' before 'b'
   31 |       vec.at(b-1) = B
      |                      ^
      |                      ;
   32 |       b = vec.at(B);
      |       ~
Language: C++

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:27:22: error: expected ';' before 'continue'
   27 |       b = vec.at(i+1)
      |                      ^
      |                      ;
   28 |       continue;
      |       ~~~~~~~~
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++) {
    int a;
    cin >> a;
    vec.at(i) = a;
  }
  
  int counter;
  for (i = 0; i < N; i++) {
    int b;
    b = vec.at(i);
    if (b == 2) {
      counter++;
      cout << counter << endl;
      break;
    }
    else if (b != 2) {
      counter++;
      continue;
    }
    cout << -1 << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:8: error: 'i' was not declared in this scope
    9 |   for (i = 0; i < N; i++) {
      |        ^
a.cc:16:8: error: 'i' was not declared in this scope
   16 |   for (i = 0; i < N; 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);
    }

    for (int i = 0; i < N; i++) {
        int next = a.at(i); // 次のボタンの位置
        if ((next - 1) == i) {
            // 次のボタンの位置にあるaiの値が現在のボタンの位置だった場合
            cout << "-1" << endl;
            return 0;
        }
    }

    bool is_finished = false;
    int curr = 1, count = 0;
    for (int i = 0; i < N; i++) {
        count++;
        int next = a.at(curr - 1);
        if (next == 2) {
            is_finished = true;
            break;
        } 
        curr = next;
    }
    cout << ((is_finished) ? count : "-1") << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:28: error: operands to '?:' have different types 'int' and 'const char*'
   33 |     cout << ((is_finished) ? count : "-1") << endl;
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int ans=0;
  cin >> N;
  vector<int> vec(N);
  
  for(int i=0;i<N;i++){
    cin >> vec.at(i);   
  }
 
  vector<int> check;
  check={};
  int k = 1;
  
  for(int i =0;i<N;i++){
    
    ans += 1;
    
      if(vec.at(k-1)==2){
        break;
      }

    k = vec.at(k-1);
    if(i == N-1){
        ans =-1
    }
  }
  
  
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:16: error: expected ';' before '}' token
   28 |         ans =-1
      |                ^
      |                ;
   29 |     }
      |     ~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int ans=0;
  cin >> N;
  vector<int> vec(N);
  
  for(int i=0;i<N;i++){
    cin >> vec.at(i);   
  }
  vector<int> check;
  for(int i =0;i<N;i++){
    
    ans += 1
      if(vec.at(i)==2){
        break;
      }
        
      for(int j=0;j<i+1;j++){
      	if(check.at(j) == vec.at(i)){
          ans = -1;
          break;
        }
      }
    check.push_back(vec.at(i));
    if(ans == -1)
      break;
  }
  
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:13: error: expected ';' before 'if'
   16 |     ans += 1
      |             ^
      |             ;
   17 |       if(vec.at(i)==2){
      |       ~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int ans=0;
  cin >> N;
  vector<int> vec(N);
  
  for(int =0;i<N;i++){
    cin >> vec.at(i);   
  }
  vector<int> check;
  for(int i =0;i<N;i++){
    
    ans += 1
      if(vec.at(i)==2){
        break;
      }
        
      for(int j=0;j<i+1;j++){
      	if(check.at(j) == vec.at(i)){
          ans = -1;
          break;
        }
      }
    check.push_back(vec.at(i));
    if(ans == -1)
      break;
  }
  
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:11: error: expected unqualified-id before '=' token
   10 |   for(int =0;i<N;i++){
      |           ^
a.cc:10:10: error: expected ';' before '=' token
   10 |   for(int =0;i<N;i++){
      |          ^~
      |          ;
a.cc:10:11: error: expected primary-expression before '=' token
   10 |   for(int =0;i<N;i++){
      |           ^
a.cc:10:14: error: 'i' was not declared in this scope
   10 |   for(int =0;i<N;i++){
      |              ^
a.cc:10:17: error: expected ')' before ';' token
   10 |   for(int =0;i<N;i++){
      |      ~          ^
      |                 )
a.cc:10:18: error: 'i' was not declared in this scope
   10 |   for(int =0;i<N;i++){
      |                  ^
a.cc:16:13: error: expected ';' before 'if'
   16 |     ans += 1
      |             ^
      |             ;
   17 |       if(vec.at(i)==2){
      |       ~~
Language: C++

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



int main(){
  
  int N;
  cin>>N;
    
  vector<int> vec(N+1);
  for(int i=1;i<=N;i++){
    cin>>vec.at(i);
  }
  
  int sta=vec.at(1);
  int kai=0;
  bool can=false;
  if(sta==2) cout<<1<<endl;
  else {
    for(int i=1;i<=N;i++){
      kai+=1;
      sta=vec.at(sta);
      if(sta==2){
      can=true;
      break;
      }
    }
    if(can) cout<<kai+1<<endl;
    else cout<<-1<<endl;
  }

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

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



int main(){
  
  int N;
  cin>>N;
    
  vector<int> vec(N+1);
  for(int i=1;i<=N;i++){
    cin>>vec.at(i);
  }
  
  int sta=vec.at(1);
  int kai=1;
  bool can=false;
  for(int i=1;i<=N;i++){
    kai+=1;
    sta=vec.at(sta);
    if(sta==2){
      can=true;
      break;
    }
  }
  if(can) cout<<kai<<endl;
  else cout<<-1<<endl;

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

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

int main() {
int N,count=0,i=1;
  cin>>N;
  vector <int> totori(N)
    for(int i=0;i<N;i++)cin>>totori[i];
  
  while(count <= N){
    i=totori[i-1];
    count++;
    if(i==2){
    cout <<count<<endl;
    break;}
  }
  if(i !=2){cout <<"-1"<<endl;}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:5: error: expected ',' or ';' before 'for'
    8 |     for(int i=0;i<N;i++)cin>>totori[i];
      |     ^~~
a.cc:8:24: error: expected ';' before ')' token
    8 |     for(int i=0;i<N;i++)cin>>totori[i];
      |                        ^
      |                        ;
Language: C++

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<bool> check(n,false);
    check[0] = true;
    int i = a[0];
    int cnt=1;
    if (i==1) cnt =0
    bool stop = false;
    while(!check[i]){
        check[i] = true;
        i = a[i];
        if(!stop){
            cnt++;
        }
        if(i==1) stop = true;
    }
    if(!check[1]) cout << -1 << endl;
    else cout << cnt << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:21: error: expected ';' before 'bool'
   20 |     if (i==1) cnt =0
      |                     ^
      |                     ;
   21 |     bool stop = false;
      |     ~~~~             
a.cc:25:13: error: 'stop' was not declared in this scope
   25 |         if(!stop){
      |             ^~~~
a.cc:28:18: error: 'stop' was not declared in this scope
   28 |         if(i==1) stop = true;
      |                  ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  for(int n = 0; n < N; n++){
    cin >> button.at(n);
  }
  int light = 1;
  int count = 1;
  while(button.at(light-1) != 2){
    count++;
    light = button.at(light-1);
    if(count > N){
      break;
    }
  }
  if(count > N){
      break;
  }else{
    cout << count << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:7: error: break statement not within loop or switch
   21 |       break;
      |       ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  for(int n = 0; n < N; n++){
    cin >> button.at(n);
  }
  int light = 0;
  int count = 1;
  while(button.at(light) != 2){
    count++;
    light = button.at(light);
    if(count > N){
      break;
    }
  }
  if(count > N){
      break;
  }else{
    cout << count << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:7: error: break statement not within loop or switch
   21 |       break;
      |       ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  for(int n = 0; n < N; n++){
    cin >> button.at(n);
  }
  int light = 0;
  int count = 1;
  while(button(light) != 2){
    count++;
    light = button(light);
    if(count > N){
      break;
    }
  }
  if(count > N){
      break;
  }else{
    cout << count << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:15: error: no match for call to '(std::vector<int>) (int&)'
   13 |   while(button(light) != 2){
      |         ~~~~~~^~~~~~~
a.cc:15:19: error: no match for call to '(std::vector<int>) (int&)'
   15 |     light = button(light);
      |             ~~~~~~^~~~~~~
a.cc:21:7: error: break statement not within loop or switch
   21 |       break;
      |       ^~~~~
Language: C++

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

using namespace std;

int main()
{

 int n,flag=0; cin>>n;
 vector<int>v;

 for(int i=1,x;i<=n;i++){
    cin>>x;
    --x;
   v.push_back(x);
 }

int now=0,ans=0;
  for(;;){

   if(now == 1){
    cout<<c<<endl;
     break; }

   if(c>= n){
    cout<<"-1"<<endl;
    break; }

   c++;
   now = v[now];
  }


return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:11: error: 'c' was not declared in this scope
   22 |     cout<<c<<endl;
      |           ^
a.cc:25:7: error: 'c' was not declared in this scope
   25 |    if(c>= n){
      |       ^
a.cc:29:4: error: 'c' was not declared in this scope
   29 |    c++;
      |    ^
Language: Java

import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  }
}


Compiler output:
Main.java:10: error: variable i is already defined in method main(String[])
    for(int i=0;i<n;i++){
            ^
1 error
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector <int> botton(N);
  for(int i; i<N; i++){
    cin >> botton.at(i);
  }
  int count;
  int now = botton.at(0);
  for(int i; i<N; i++){
    count++;
    int k = botton.at(now-1)
    now = botton.at(k);
    if(now == 2){
      cout << count << endl;
      break;
    }
    if(count == N){
      cout << -1 << endl;
    }
  }
}
 


Compiler output:
a.cc: In function 'int main()':
a.cc:16:5: error: expected ',' or ';' before 'now'
   16 |     now = botton.at(k);
      |     ^~~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int N, count = 0, i;
    vector<int> n(N), find(N);
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        n[i] = tmp - 1;
        find[i] = -1;
    }
    i = 0;
    int flug = 0;
    while (find[i] == -1)
    {
        find[i] = 1;
        if (n[i] == 1)
        {
            flug++;
            break;
        }
        count++;
        i = n[i];
    }
    if (flug == 1)
    {
        cout << count << "\n";
    }
    else
    {
        cout << -1 << "\n";
    }
    return 0;
}#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int N, count = 0, i;
    vector<int> n(N), find(N);
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        n[i] = tmp - 1;
        find[i] = -1;
    }
    i = 0;
    int flug = 0;
    while (find[i] == -1)
    {
        find[i] = 1;
        if (n[i] == 1)
        {
            flug++;
            break;
        }
        count++;
        i = n[i];
    }
    if (flug == 1)
    {
        cout << count << "\n";
    }
    else
    {
        cout << -1 << "\n";
    }
    return 0;
}

Compiler output:
a.cc:45:2: error: stray '#' in program
   45 | }#include <iostream>
      |  ^
a.cc:45:3: error: 'include' does not name a type
   45 | }#include <iostream>
      |   ^~~~~~~
a.cc:51:5: error: redefinition of 'int main()'
   51 | int main(void)
      |     ^~~~
a.cc:7:5: note: 'int main()' previously defined here
    7 | int main(void)
      |     ^~~~
Language: C++

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

int main(){
  int n;
  int num=0;
  int bottun=1;
  cin>>n;
  vector<int>a(n);
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  while(bottun!=2){
    bottun=a[bottun];
    num++;
    if(num>N) break;
  }
  if(num<N) cout<<num<<endl;
  else cout<<-1<<endl;
}
    

Compiler output:
a.cc: In function 'int main()':
a.cc:16:12: error: 'N' was not declared in this scope
   16 |     if(num>N) break;
      |            ^
a.cc:18:10: error: 'N' was not declared in this scope
   18 |   if(num<N) cout<<num<<endl;
      |          ^
Language: C++

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



int main(){

 int n,x; cin>>n;

 vector<int>das;

 for(int i=0;i<n;i++){
    cin>>x;
    das.push_back(x--); }

 int now=0,c=0;

 for(;;){

    if(now == 1){
        cout<<c<<endl;
        break; }

    if(c>=a){
        cout<<"-1"<<endl;
        break; }

    c++;
  now = v[now];
 }

return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:26:11: error: 'a' was not declared in this scope
   26 |     if(c>=a){
      |           ^
a.cc:31:9: error: 'v' was not declared in this scope
   31 |   now = v[now];
      |         ^
Language: C++

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

int main(){
  int N;    //ボタンの数
　
  cin >> N;
  vector <int> Botton(N);  //次に光るボタンのi(番号)
  for (int i=0; i<N; i++){
    cin >> Botton.at(i);
  }

  int Ok = -1;   //-1は不可能　正の数はボタンを押した回数
  int I = 1;    //光っているボタンの番号    
  for (int i=1; i<=N; i++){
    if ( Botton.at(I) == 2){
      Ok = i;
      break;
    }
    I = Botton.at(I);
  }
  cout << i << endl;    
}


Compiler output:
a.cc:6:1: error: extended character 　 is not valid in an identifier
    6 | 　
      | ^
a.cc: In function 'int main()':
a.cc:6:1: error: '\U00003000' was not declared in this scope
    6 | 　
      | ^~
a.cc:22:11: error: 'i' was not declared in this scope
   22 |   cout << i << endl;
      |           ^
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:1:9: fatal error: stdio .h: No such file or directory
    1 | #include<stdio .h>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  vector<int> a(N+1,-1);
  
  for(int i=1; i<=N; i++){
    cin >> a.at(i);
  }
  
  int next = 1, count = 1;
  while(a.at(next)==2 || a.at(next)==-1){
    int temp;
    temp = next;
    next = a.at(next);
    a.at(temp) = -1
    count++;
  }
  if(a.at(next)==-1) cout << -1 << endl;
  else cout << count << endl;
}

    
    


Compiler output:
a.cc: In function 'int main()':
a.cc:18:20: error: expected ';' before 'count'
   18 |     a.at(temp) = -1
      |                    ^
      |                    ;
   19 |     count++;
      |     ~~~~~
Language: C

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> C(n);
  int count=0;
  for(int i=0;i<n;i++){
    cin >> A.at(i);
  }
  int ini=A.at(0);
  for(int j=0;j<n+1;j++){
    count++;
    if(C.at(ini-1)!=1&&ini!=2){
      C.at(ini-1)=1;
      ini = A.at(ini-1);
    }else if(ini == 2){
      break;
    }else{
      count = -1;
      break;
    }
  }
  cout << count << endl;

}



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

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

int main() {
  int N;
  cin >> N
  vector<int> v(N);
  for (int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  int kaunto;
  int flag;
  int tugi;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:11: error: expected ';' before 'vector'
    6 |   cin >> N
      |           ^
      |           ;
    7 |   vector<int> v(N);
      |   ~~~~~~   
a.cc:9:12: error: 'v' was not declared in this scope
    9 |     cin >> v.at(i);
      |            ^
Language: C++

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

int main() {
  
  int N;
  cin >> N;
  vector<int> btn(N);
  
  for ( int i=0; i < N; i++){
    cin >> btn[i];
  }
  int c=1;
  int m,boo;
  
  while 1{
    boo = btn[btn[m]];
    c++;
    m=boo-1;
    if ( boo ==2){
      break;
    }else if ( boo==1){
      cout<<'-1'<<endl;
    }
    
  }
  cout << c << endl;
}


Compiler output:
a.cc:23:13: warning: multi-character character constant [-Wmultichar]
   23 |       cout<<'-1'<<endl;
      |             ^~~~
a.cc: In function 'int main()':
a.cc:16:9: error: expected '(' before numeric constant
   16 |   while 1{
      |         ^
      |         (
a.cc:16:10: error: expected ')' before '{' token
   16 |   while 1{
      |         ~^
      |          )
Language: C++

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:13:20: error: expected ';' before 'if'
   13 |         a=vec.at(a)
      |                    ^
      |                    ;
   14 |         if(a==2){
      |         ~~
Language: C++

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:9:5: error: expected ',' or ';' before 'for'
    9 |     for(int i=0;i<N;i++){
      |     ^~~
a.cc:9:17: error: 'i' was not declared in this scope
    9 |     for(int i=0;i<N;i++){
      |                 ^
a.cc:13:20: error: expected ';' before 'if'
   13 |         a=vec.at(a)
      |                    ^
      |                    ;
   14 |         if(a==2){
      |         ~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,str,point,ans = 0,a;
  cin >> N;
  vector<int> n(N,0);
  for(int i = 0; i < N; i++){
  	cin >> n.at(i);
  }
  str = 1;
  point = 0;
  a = 0;
  for(int i = 0; i < N; i++){
  	a = n.at(str);
    str = a;
    ans += 1;
    if(a == 2){
    	break;
    }
    if(i == N -1){
    	cout << "-1" << endl
        point = 1;
    }
  }
  if(point == 0){
  	cout << ans << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:29: error: expected ';' before 'point'
   22 |         cout << "-1" << endl
      |                             ^
      |                             ;
   23 |         point = 1;
      |         ~~~~~
Language: C++

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

int main() {
  int N,str,point,ans = 0,a;
  cin >> N;
  vector<int> n(N,0);
  for(int i = 0; i < N; i++){
  	cin >> n.at(i);
  }
  str = 1;
  point = 0;
  a = 0;
  for(int i = 0; i < N + 1; i++){
  	a = n.at(str);
    str = a;
    ans += 1;
    if(a == 2){
    	break;
    }
    if(i == N){
    	cout << "-1" << endl
        point = 1;
    }
  }
  if(point == 0){
  	cout << ans << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:29: error: expected ';' before 'point'
   22 |         cout << "-1" << endl
      |                             ^
      |                             ;
   23 |         point = 1;
      |         ~~~~~
Language: C++

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


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

  b = a.at(0);
  i = 1
  while(i < N){
    if(b = 2)
      break;
    
    b = a.at(b);
    i++;
    if(i = N){
      i = -1;
      break;
    }
  }

  cout << i << endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:8: error: expected ';' before 'while'
   15 |   i = 1
      |        ^
      |        ;
   16 |   while(i < N){
      |   ~~~~~
Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct edge{
  ll to,cost;
};
const ll MAX_V=200100;
const ll Inf=1e18;
vector<vector<edge>>E(MAX_V);
ll d[MAX_V];
void dijkstra(ll s){
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>que;
  fill_n(d,MAX_V,Inf);
  d[s] = 0;
  que.push(pair<ll,ll>(0,s));
  while(!que.empty()){
    pair<ll,ll> p = que.top();
    que.pop();
    ll v = p.second;
    if(d[v] < p.first)continue;
    for(int j = 0;j < E[v].size();j++){
      edge t = E[v][j];
      if(d[t.to] > d[v] + t.cost){
	d[t.to] = d[v] + t.cost;
	que.push(pair<ll,ll>(d[t.to],t.to));
      }
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    E[i].pb(a-1);
  }
  dijkstra(0);
  if(d[1] == Inf)cout<<-1<<endl;
  else cout<<d[1]<<endl;
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:50:12: error: no matching function for call to 'std::vector<edge>::push_back(long long int)'
   50 |     E[i].pb(a-1);
      |     ~~~~~~~^~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = edge; _Alloc = std::allocator<edge>; value_type = edge]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'long long int' to 'const std::vector<edge>::value_type&' {aka 'const edge&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = edge; _Alloc = std::allocator<edge>; value_type = edge]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'long long int' to 'std::vector<edge>::value_type&&' {aka 'edge&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
Language: C++

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

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

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

#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
const int MOD = 1e9+7;

int main() {
	int N;
  	cin>> N;
  	vi a(N);
  	rep(i,N) cin >> a[i];
  	int on = 1;
  	frag = false;
  	int count;
  	rep(i,N){
    	on = a[on];
      	if(on == 2){
        	frag =true;
          	count = i+1;
          	break;
        }
    }
  	if(frag) cout << count << endl;
  	else cout << 0<< endl;
}

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

#include<stdio . h>#include<vector>#include<algorithm>using  namespace  std ;int  main ()fint  n ;scanf ("%d" , &n ) ;vector<int>v ;f o r  ( int  i = 0;  i<n ;  i++)fint  z ;scanf ("%d" , &z ) ;z

Compiler output:
a.cc:1:20: warning: extra tokens at end of #include directive
    1 | #include<stdio . h>#include<vector>#include<algorithm>using  namespace  std ;int  main ()fint  n ;scanf ("%d" , &n ) ;vector<int>v ;f o r  ( int  i = 0;  i<n ;  i++)fint  z ;scanf ("%d" , &z ) ;z
      |                    ^
a.cc:1:9: fatal error: stdio . h: No such file or directory
    1 | #include<stdio . h>#include<vector>#include<algorithm>using  namespace  std ;int  main ()fint  n ;scanf ("%d" , &n ) ;vector<int>v ;f o r  ( int  i = 0;  i<n ;  i++)fint  z ;scanf ("%d" , &z ) ;z
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

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

    int count = 0;

    while(1){
        //button = a[button];
        if(button == a[button]){
            break;
        }
        else if(button != a[button]){
            button = a[button];
            count++;
            if(button == 2){
                break;
            }
            if(button == 1){
                break;
            }
        }
    }

    if(button == 2){
        printf("%d\n", count);
    }
    else{
        printf("-1\n");
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:3:5: error: 'cin' was not declared in this scope
    3 |     cin >> n;
      |     ^~~
a.cc:31:9: error: 'printf' was not declared in this scope
   31 |         printf("%d\n", count);
      |         ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | int main(){
a.cc:34:9: error: 'printf' was not declared in this scope
   34 |         printf("-1\n");
      |         ^~~~~~
a.cc:34:9: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int n;
    cin >> n;
    
    int a[100005];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    int i = 0;    
    int state[100005] = {0};
    state[0] = 1;
    

    while(state[i] != 2){

        //cout << "while " << i << " " << state[i] << endl;
        
        ++i;
        
        state[i] = a[state[i-1]-1];
        
        //cout << i << " " << a[state[i-1]-1] << " " << state[i] << endl;
        
        if(state[i] == 2) break;
 
        if(state[i] == 1) {
            cout << -1 << endl;
            return 0;
        }       
        
        /*
        for(int j=0; j<i; j++){
            //cout << "for" << endl;
            if(state[i] == state[j]) {
                cout << -1 << endl;
                return 0;
            }
        }
        */
        if(i=>n) {
            cout << -1 << endl;
            return 0;
        }
        
           
    }
    
    cout << i << endl;
    return 0;
}

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

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

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

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

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

int main() {
  int N;
  cin >> N;
  vector<int> button(N);//0から始まることに注意；；
  rep(i,N){
    int n;
    cin >> n;
    button.at(i) = n-1;
  }
  //button(i)がai+1に対応
  vector<int> route(N);
  int idou=0,now=0;//now：現在地
  route.at(0) = 1;
  while(1){
    now = button(now);
    route.at(now)++;
    idou++;
    if(now == 1)
      break;
    else if(route.at(now) == 2){
      idou = -1;
      break;
    }
  }
  cout << idou << endl;
}







Compiler output:
a.cc: In function 'int main()':
a.cc:19:17: error: no match for call to '(std::vector<int>) (int&)'
   19 |     now = button(now);
      |           ~~~~~~^~~~~
Language: C++

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

int main() {
  int N;
  cin >> N;
  vector<int> button(N);//0から始まることに注意；；
  rep(0,N){
    int n;
    cin >> n;
    button.at(i) = n-1;
  }
  //button(i)がai+1に対応
  vector<int> route(N);
  int idou=0,now=0;//now：現在地
  route.at(0) = 1;
  while(1){
    now = button(now);
    route.at(now)++;
    idou++;
    if(now == 1)
      break;
    else if(route.at(now) == 2){
      idou = -1;
      break;
    }
  }
  cout << idou << endl;
}







Compiler output:
a.cc: In function 'int main()':
a.cc:9:7: error: expected unqualified-id before numeric constant
    9 |   rep(0,N){
      |       ^
a.cc:3:26: note: in definition of macro 'rep'
    3 | #define rep(i,n) for(int i=0;i<(int)(n);i++)
      |                          ^
a.cc:9:7: error: expected ';' before numeric constant
    9 |   rep(0,N){
      |       ^
a.cc:3:26: note: in definition of macro 'rep'
    3 | #define rep(i,n) for(int i=0;i<(int)(n);i++)
      |                          ^
a.cc:9:7: error: lvalue required as left operand of assignment
    9 |   rep(0,N){
      |       ^
a.cc:3:26: note: in definition of macro 'rep'
    3 | #define rep(i,n) for(int i=0;i<(int)(n);i++)
      |                          ^
a.cc:3:40: error: expected ')' before ';' token
    3 | #define rep(i,n) for(int i=0;i<(int)(n);i++)
      |                     ~                  ^
a.cc:9:3: note: in expansion of macro 'rep'
    9 |   rep(0,N){
      |   ^~~
a.cc:9:7: error: lvalue required as increment operand
    9 |   rep(0,N){
      |       ^
a.cc:3:41: note: in definition of macro 'rep'
    3 | #define rep(i,n) for(int i=0;i<(int)(n);i++)
      |                                         ^
a.cc:19:17: error: no match for call to '(std::vector<int>) (int&)'
   19 |     now = button(now);
      |           ~~~~~~^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> arr(1000000);
  int N;
  cin >> N;
  
  int count = 1;
  
  for (int i = 0; i < N; i++) {
    cin >> arr.at(i);
  }
  
  int a;
  int flag = 0;
  
  while (1) {
    int x = 1;
    x = arr.at(arr.at(x - 1))
    count ++;
    if (arr.at(x) = 2) {
      break;
    }
  }
  
  cout << count << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:30: error: expected ';' before 'count'
   20 |     x = arr.at(arr.at(x - 1))
      |                              ^
      |                              ;
   21 |     count ++;
      |     ~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> arr(1000000);
  int N;
  cin >> N;
  
  int count = 1;
  
  for (int i = 0; i < N; i++) {
    cin >> arr.at(i);
  }
  
  int a;
  int flag = 0;
  
  while (1) {
    int x = 1
    x = arr.at(arr.at(x - 1))
    count ++;
    if (arr.at(x) = 2) {
      break;
    }
  }
  
  cout << count << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:5: error: expected ',' or ';' before 'x'
   20 |     x = arr.at(arr.at(x - 1))
      |     ^
Language: C++

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:11:29: error: expected ')' before ';' token
   11 |   for (int i = 0; i < N; i++;) {
      |       ~                     ^
      |                             )
a.cc:11:30: error: expected primary-expression before ')' token
   11 |   for (int i = 0; i < N; i++;) {
      |                              ^
a.cc:20:5: error: expected ',' or ';' before 'x'
   20 |     x = arr.at(arr.at(x - 1))
      |     ^
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);
  }
  
  vector<int> flags(N);
  int on=0;
  int count=0;
  while(True){
	on = buttons.at(on);
    count++;
    
    if(on==2)
      cout << count << endl;
    
    if(flags.at(on))
      cout << -1 << endl;
    else
      flags.at(on)=1;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:9: error: 'True' was not declared in this scope
   16 |   while(True){
      |         ^~~~
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);
  }
  
  vector<int> flags(N);
  int on=0;
  int count=0;
  while(True){
	on = buttons.at(on);
    count++;
    
    if(on==2)
      cout << count << endl;
    
    if(flags.at(on))
      cout << -1 << endl;
    else
      flags.at(on)=1;
  }
}

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

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:9:8: error: 'i' was not declared in this scope
    9 |   for (i = 0; i < N; i++) cin >> a[i];
      |        ^
a.cc:23:2: error: expected '}' at end of input
   23 | }
      |  ^
a.cc:4:12: note: to match this '{'
    4 | int main() {
      |            ^
Language: C++

n = int(input())
a = [int(input()) for _ in range(n)]

cnt = 0
cur = 1

if a[0] == 2:
    print(1)

else:
    for i in range(n):
        cnt += 1
        cur = a[cur - 1]
        if cur == 2:
            print(cnt)
            exit()

print(-1)

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

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

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

  vector<bool> b(n, true);
  int on = 0;
  int cnt = 0;
  while(true) {
    if (a[on] == 2) {
      cout << cnt << endl;
      return 0;
    }
    if (b[on]) {
      b[on] = false;
      on = a[on] - 1;
      cnt ++;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:9:3: error: 'vectore' was not declared in this scope
    9 |   vectore<int> a(n);
      |   ^~~~~~~
a.cc:9:11: error: expected primary-expression before 'int'
    9 |   vectore<int> a(n);
      |           ^~~
a.cc:11:12: error: 'a' was not declared in this scope
   11 |     cin >> a[i];
      |            ^
a.cc:18:9: error: 'a' was not declared in this scope
   18 |     if (a[on] == 2) {
      |         ^
a.cc:24:12: error: 'a' was not declared in this scope
   24 |       on = a[on] - 1;
      |            ^
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 button = 1;
  int count = 0;
  while (button != 2){
    button = a.at(button);
    count++;
    if (count !< N){
      cout << -1 << endl;
      break;
    }
  }
  cout << count << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:14: error: expected ')' before '!' token
   17 |     if (count !< N){
      |        ~     ^~
      |              )
Language: C++

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

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


Compiler output:
a.cc: In function 'int main()':
a.cc:16:5: error: 'else' without a previous 'if'
   16 |     else if (vec.at(i)==2) {
      |     ^~~~
Language: C++

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

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

Compiler output:
a.cc: In function 'int main()':
a.cc:27:4: 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;
  vector<int>a(N);
  for(int i = 0; i < N; i++) cin >> a.at(i);
  
  int button = 1;
  int i = 0;
  for(int j = 0; j < N; j++){
    i++;
    button = a.at(button - 1);
    if(button == 2)break;
    if(button == 1 || j = N - 1){
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << i << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:20: error: lvalue required as left operand of assignment
   16 |     if(button == 1 || j = N - 1){
      |        ~~~~~~~~~~~~^~~~
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 button = 1;
  int i = 0;
  for(int j = 0; j < N; j++){
    i++;
    button = a.at(button - 1);
    if(button == 2)break;
    if(button == 1 || i = N - 1){
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << i << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:20: error: lvalue required as left operand of assignment
   16 |     if(button == 1 || i = N - 1){
      |        ~~~~~~~~~~~~^~~~
Language: C++

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

int main() {
	int n;
	int A[100005];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	int temp=A[0];
	int c=1;
	while(100005--){
		c++;
		if (A[temp-1]==2){
			cout<<c;
			return 0;
		}
		temp=A[temp-1];
	}
	
	cout<<-1;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:15: error: lvalue required as decrement operand
   13 |         while(100005--){
      |               ^~~~~~
Language: C++

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

int main() {
  int N; cin >> N;
  vector<int> v;
  for (int i=0; i<N; i++) {
    int x; cin >> x;
    v.push_back(x);
  }
  int y=0; z=0;
  for (int i=0; i<N; i++) {
    if (z==1) {
      cout << y << endl;
      break;
    }
    if (y>=N) {
      cout << "-1" << endl;
      break;
    }
    y++;
    z = v.at(z);
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:12: error: 'z' was not declared in this scope
   11 |   int y=0; z=0;
      |            ^
Language: C++

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

int main() {
  int N; cin >> N;
  vector<int> v;
  for (int i=0; i<N; i++) {
    int x; cin >> x;
    v.push_back(x);
  }
  int y=0; z-0;
  for (int i=0; i<N; i++) {
    if (z==1) {
      cout << y << endl;
      break;
    }
    if (y>=N) {
      cout << "-1" << endl;
      break;
    }
    y++;
    z = v.at(z);
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:12: error: 'z' was not declared in this scope
   11 |   int y=0; z-0;
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  vector<int> past(0);
  int flag = 0;
  int count = 0;
  
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    if(vec[i] == 2) flag = 1;
  }

  if(flag == 1){
    int next = vec[0];
    count++;
    past.push_back(next);
    while(next != 2 && flag = 1){
      next = vec[next];
      count++;
      past.push_back(next);
      for(int i = 0; i < past.size(); i++){
        if(past[i] == next){
          flag = 0;
          break;
        }
      }
    }
  }
 
  if(flag == 0){
    cout << -1 << endl;
  } else {
	cout << count << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:21: error: lvalue required as left operand of assignment
   21 |     while(next != 2 && flag = 1){
      |           ~~~~~~~~~~^~~~~~~
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 y=A.at(0);
  int cnt=0;
  for (int i=0; i<N; i++){
   y=A.at(y-1);
    cnt++;
    if (y==2){
      cout << cnt+1 << endl;
      break;
    }
  }
  if (y!=2){
    cout << -1 << endl;
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:2: error: expected '}' at end of input
   26 | }
      |  ^
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(int i=0;i<N;i++){
  int x;
    cin>>x;
    A.at(i)=x-1;
  }set<int>S;
  bool ans=false;
  int sum=0;
  for(int i=0; ;i=A.at(i)){
  sum++;
    if(A.at(i)==1){
    ans=true; break;
  }else{
  if(S.cout(A.at(i))){
    break;
  }else{
   S.insert(A.at(i));
  } 
  }
  
  }if(ans)
    cout<<sum<<endl;
  else
    cout<<-1<<endl;
   return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:8: error: 'class std::set<int>' has no member named 'cout'; did you mean 'count'?
   19 |   if(S.cout(A.at(i))){
      |        ^~~~
      |        count
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector <int> X(N);
  for (int i=0; i < N ; i++)
    cin >> X.at(i);
  int a=1;
  vector<int> Y(1,1)
  for (int i=0;i<100000;i++){
    Y.push_back X.at(a);
    a=X.at(a);
    if (X.at(a)==2){
      cout<< i << endl;
      break;
    }
    for(k=0; k<i-1; k++){
      if (X.at(a) == X.at(k)){
        cout<< "-2" << endl;
        break;
      }
    }
  }
}


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

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  int i;
  
  //dainyu-
  for(i=1;i<N+1;i++)
    cin >> a.at(i);
  
  //search
  int s=1,sum=1;
  while(1){
    int t;
    t=s;
    s=a.at(s);
    a.at(t)=-1;
    if(s==2)cout<<sum<<endl;break;
    else if(s==-1)cout<<-1<<endl;break;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:5: error: 'else' without a previous 'if'
   22 |     else if(s==-1)cout<<-1<<endl;break;
      |     ^~~~