ZhenlongDai/ACPR huggingface dataset:
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = []
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if a[before_num - 1] in lighted_bottons:
                print("li")
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons.append(before_num)

Failing test case input:
3
1
2
6

Expected output:
-1


Actual output:
li
-1


Fixed submission (verdict: Accepted):



n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if 2 not in a:
    print(-1)
else:
    cnt = 0
    before_num = 1
    lighted_bottons = [0 for i in range(n + 1)]
    while True:
        cnt += 1
        if a[before_num - 1] == 2:
            print(cnt)
            break
        else:
            if lighted_bottons[a[before_num - 1]] == 1:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons[before_num] = 1

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
length = int(input())  
 
data = ([int(input()) for i in range(length)])

data.insert(0, 0)

i = 1
v = 0
cnt = 0

if data[i] == i:
  cnt = -1
else:
  while v != 2:
    v = data[i]
    if data[v] == i:
      cnt = -1
      break
    i = v
    cnt += 1
  
print(cnt)

Failing test case input:
4
4
4
0
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())  
 
data = ([int(input()) for i in range(N)])

data.insert(0, 0)

cnt = 0
i = 1
v = 0

while v != 2:
  v = data[i]
  i = v
  if cnt >= N: 
    cnt = -1
    break
  cnt += 1
  
print(cnt)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
li=[]

for n in range(N):
  a=int(input())
  li.append(a)
print(li)

check=[]
s=0
count=0

while s!=1:
  if s in check:
    break
  else:
    check.append(s)
    s=li[s]-1
    count+=1

if s==1:
  print(count)
else:
  print(-1)

Failing test case input:
4
4
8
0
4

Expected output:
-1


Actual output:
[4, 8, 0, 4]
-1


Fixed submission (verdict: Accepted):
N=int(input())
li=[]

for n in range(N):
  a=int(input())
  li.append(a)

s=0
count=0

while s!=1:
  if count==N:
    break
  else:
    s=li[s]-1
    count+=1

if s==1:
  print(count)
else:
  print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(input()) for _ in range(n)]

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





Failing test case input:
4
4
5
0
2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input()) for _ in range(n)]
cnt=0
push=1
for i in range(n):
    push=a[push-1]
    cnt+=1
    if push == 2:
        print(cnt)
        exit()
print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys, math, fractions, itertools


def solve(N: int, a: "List[int]"):
    counter = 0
    nx = 0
    r = []
    for i in range(N):
        counter += 1
        if a[nx] - 1 == 1:
            break
        nx = a[nx] - 1
        r.append(a[nx])
    if counter < N and 2 in r:
        print(counter)
    else:
        print(-1)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, a)

if __name__ == '__main__':
    main()


Failing test case input:
3
2
2
0

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):

import sys, math, fractions, itertools


def solve(N: int, a: "List[int]"):
    counter = 0
    nx = 0
    r = []
    for i in range(N):
        counter += 1
        r.append(a[nx])
        if a[nx] - 1 == 1:
            break
        nx = a[nx] - 1
    if counter < N and 2 in r:
        print(counter)
    else:
        print(-1)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, a)

if __name__ == '__main__':
    main()

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
button = [int(input()) for _ in range(N)]

ind = 1
count = 0
for i in range(1, N+1):
    if i == ind:
        ind = button[ind-1]
        count += 1
        if ind == 2:
            break
        elif ind < i:
            count = -1
            break

print(count)

Failing test case input:
5
1
3
5
4
4

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
button = [int(input()) for _ in range(N)]

ind = 1
count = 0
while count < N+1:
    ind = button[ind-1]
    count += 1
    if ind == 2:
        break
print(count) if ind == 2 else print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = []
for i in range(N):
    A.append(int(input())-1)  
    
index = 0
count = 1
flag = True
while flag:
    if index == A[A[index]]:
        count = -1
        flag = False
    else:
        index = A[index]
        if index == 1:
            flag = False
        else:
            count += 1
    
print(count)

Failing test case input:
4
4
4
0
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
A = []
for i in range(N):
    A.append(int(input())-1)  
    
index = 0
count = 1
flag = True
while flag:
    index = A[index]
    if index == 1:
        flag = False
    else:
        count += 1
    if count > N:
        flag = False
        count = -1
print(count)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]
B = 1
for j in(A):
  if j == 2:
    print(B)
    break
  else:
    B += 1
print('-1')

Failing test case input:
3
3
2
1

Expected output:
-1


Actual output:
2
-1


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for i in range(N)]
B = 0
C = 1
for j in range(N):
  if A[B] == 2:
    print(C)
    break
  elif j == N-1:
    print('-1')
  else:
    B = A[B]-1
    C += 1

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(input()) for i in range(N)]
i=0
j=0
cnt=0
bot = []
while True:
    if a[j]==2:
        cnt+=1
        print(cnt)
        break
    elif a[i] in bot:
        print(-1)
        break
    else:
        cnt+=1
        i+=1
        j=a[j]-1
        bot.append(a[i])

Failing test case input:
5
3
0
4
2
4

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(input()) for i in range(N)]
i=0
j=0
cnt=0
while True:
    if a[j]==2:
        cnt+=1
        print(cnt)
        break
    elif cnt>N:
        print(-1)
        break
    else:
        cnt+=1
        i+=1
        j=a[j]-1

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=list()

for i in range(N):
  a.append(int(input()))



count=1
b=1
cond=0

if a[0]==2:
  cond=0
  count=1
else:
 for j in range(N):
   count=count+1
   b=a[b-1]
   
   if a[b-1] ==2:
     cond=1
     break

if cond==0:
  print(-1)
else:
  print(count)

Failing test case input:
4
2
12
2
3

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):
N=int(input())
a=list()

for i in range(N):
  a.append(int(input()))



count=1
b=1
cond=0

if a[0]==2:
  cond=1
  count=1
else:
 for j in range(N):
   count=count+1
   b=a[b-1]
   
   if a[b-1] ==2:
     cond=1
     break

if cond==0:
  print(-1)
else:
  print(count)

Problem: p03680
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
a=[int(input()) for i in range(n)]
x=1
cnt=0
y=[]
while True:
    x=a[x-1]
    cnt+=1
    y.append(x)
    if x==2:
        print(cnt)
        break
    elif x==1 or x in y:
        print('-1')
        break
    else:
        continue


Failing test case input:
5
3
3
4
2
4

Expected output:
3

Actual output:
-1


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input()) for i in range(n)]
x=1
cnt=0
y=[1]
while True:
    x=a[x-1]
    cnt+=1
    y.append(x)
    if x==2:
        print(cnt)
        break
    elif x==1:
        print('-1')
        break
    elif cnt==100000:
        print(-1)
        break
    else:
        continue
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
a = [int(input()) for i in range(N)]

i = a[0]
count = 1

while count <= N:
    if i == 2:
        print(count)
        break
        exit()
    elif a[i-1] == 2:
        count = count + 1
        print(count)
        exit()
    else:
        i = a[i - 1]
        count = count + 1

print(-1)


Failing test case input:
4
2
22
2
3

Expected output:
1


Actual output:
1
-1


Fixed submission (verdict: Accepted):

N = int(input())
a = [int(input()) for k in range(N)]
count = 1
tmp = a[a[0]-1]
while count <= N:
    if a[0] == 2:
        print(count)
        exit()
    elif tmp == 2:
        count += 1
        print(count)
        exit()
    else:
        tmp = a[tmp-1]
        count += 1

print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]
B = 1
for j in(A):
  if j == 2:
    print(B)
    break
  elif j == [-1]:
    print('-1')
  else:
    B += 1

Failing test case input:
4
3
11
3
1

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for i in range(N)]
B = 0
C = 1
for j in range(N):
  if A[B] == 2:
    print(C)
    break
  elif j == N-1:
    print('-1')
  else:
    B = A[B]-1
    C += 1

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
b = a[0]
if b == 2:
    print(0)
else:
    c = 1
    d = []
    while b != 2:
        b = a[b - 1]
        if b in d:
            print(- 1)
            break
        else:
            d.append(b)
            c += 1
    else:
        print(c)

Failing test case input:
4
2
12
2
3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]
b = a[0]
c = 1
d = set()
while b != 2:
    b = a[b - 1]
    if b in d:
        print(-1)
        break
    else:
        d.add(b)
        c += 1
else:
    print(c)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [0] + [int(input()) for i in range(n)]
c = a[1]
p = 1
if 2 not in a:
    print(-1)
while c > 2:
    d = a[c]
    a[c] = 0
    c = d
    p += 1


if c == 2:
    print(p)
else:
    print(-1)


Failing test case input:
4
4
3
0
4

Expected output:
-1


Actual output:
-1
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = [0] + [int(input()) for i in range(n)]
c = a[1]
p = 1
while c > 2:
    d = a[c]
    a[c] = 0
    c = d
    p += 1

if c == 2:
    print(p)
else:
    print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
length = int(input())  
 
data = ([int(input()) for i in range(length)])

data.insert(0, 0)

i = 1
v = 0
cnt = 0

while v != 2:
  
  v = data[i]
  
  if data[v] == i:
    cnt = -1
    break
  
  i = v

  cnt += 1
  
print(cnt)
  

Failing test case input:
4
3
3
2
4

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())  
 
data = ([int(input()) for i in range(N)])

data.insert(0, 0)

cnt = 0
i = 1
v = 0

while v != 2:
  v = data[i]
  i = v
  if cnt >= N: 
    cnt = -1
    break
  cnt += 1
  
print(cnt)

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    cnt = 0
    x = 1

    if 2 in a:
        for _ in range(n-1):
            x = a[x-1]
            cnt += 1

            if x == 2:
                print(cnt)
                exit()

    else:
        print(-1)
        exit()
        

if __name__ ==  "__main__":
    main()

Failing test case input:
5
1
3
5
2
1

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    cnt = 0
    x = 1

    if 2 in a:
        for _ in range(n-1):
            x = a[x-1]
            cnt += 1

            if x == 2:
                print(cnt)
                exit()
        else:
            print(-1)
    else:
        print(-1)
        

if __name__ ==  "__main__":
    main()

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
button = list()
for i in range(N):
    button.append(int(input()))

pre  = 1
print(button)
i = 0
c = 1
rireki = [0]*N
while all: 
    if(button[i]==2):
        print(c)
        break
    rireki[i] +=1
    if(rireki[i]==2):
        print(-1)
        break
    i = button[i]-1
    c+=1

Failing test case input:
4
4
4
0
4

Expected output:
-1


Actual output:
[4, 4, 0, 4]
-1


Fixed submission (verdict: Accepted):
N = int(input())
button = list()
for i in range(N):
    button.append(int(input()))

pre  = 1

i = 0
c = 1
rireki = [0]*N
while all: 
    if(button[i]==2):
        print(c)
        break
    rireki[i] +=1
    if(rireki[i]==2):
        print(-1)
        break
    i = button[i]-1
    c+=1

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = {}

for i in range(n):
    a = int(input())
    b[i+1] = b.get(i+1, 0) + a

key, t = b.get(1, 0), 1
key_set = {1, key}
while key != 0:
    key = b.get(key, 0)
    if key in key_set:
        print(-1)
        break

    key_set.add(key)
    t += 1

    if key == 2:
        print(t)
        break

else:
    print(-1)


Failing test case input:
4
2
12
2
3

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
b = {}

for i in range(n):
    a = int(input())
    b[i+1] = b.get(i+1, 0) + a

key, t = b.get(1, 0), 1
key_set = {1}
while key != 0:
    if key in key_set:
        print(-1)
        break

    if key == 2:
        print(t)
        break

    key_set.add(key)
    key = b.get(key, 0)
    t += 1

else:
    print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=[0]*n
for i in range(n):
    l[i]=int(input())

vi=[0]*n
vi[0]=1
ans=1
st=l[0]
f=0
while vi[1]==0:
    vi[st-1]+=1
    if vi[st-1]>1:
        f=1
        break
    st=l[st-1]
    ans+=1
if f==0:
    print(ans)
else:
    print(-1)
    
    
  
  
    

Failing test case input:
4
4
1
0
2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
l=[0]*n
for i in range(n):
    l[i]=int(input())

vi=[0]*n
vi[0]=1
ans=0
st=l[0]
f=0
while vi[1]==0:
    vi[st-1]+=1
    if vi[st-1]>1:
        f=1
        break
    st=l[st-1]
    ans+=1
if f==0:
    print(ans)
else:
    print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a= [int(input()) for _ in range(n)]

count = 0
now = a[0]

while now != 2 and count < n:
  now = a[now-1]
  count += 1
print(count if count<n else -1)

Failing test case input:
3
2
0
3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a= [int(input()) for _ in range(n)]

count = 1
now = a[0]

while now != 2 and count < n:
  now = a[now-1]
  count += 1
print(count if count<n else -1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
ai = [int(input()) for _ in range(N)]
if ai[0] == 2:
    print("0")
else:
    lightning = ai[0]
    count = 1
    ok = False
    lightning = ai[lightning-1]
    count += 1
    for _ in range(N):
        if lightning == 2:
            print(count)
            ok = True
        break

    if not ok:
        print("-1")


Failing test case input:
3
2
0
3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):

N = int(input())
ai = [int(input()) for _ in range(N)]

lightning = 1
count = 1
ok = False
for _ in range(N):
    lightning = ai[lightning-1]
    if lightning == 2:
        print(count)
        ok = True
        break
    else:
        count += 1

if not ok:
    print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
now = a[0]
cnt = 0
for i in range(n):
    
    now = a[now - 1]
    cnt += 1
    if now == a[1]:
        
        print(cnt)
        
        exit()
print("-1")

Failing test case input:
4
3
2
2
2

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]
now = 0
cnt = 0
for i in range(n):
    
    now = a[now] - 1
    cnt += 1
    if now == 1:
        
        print(cnt)
        
        exit()
print("-1")

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(input())-1 for _ in range(N)]
tmp = a[0]
cnt = 0
for _ in range(N):
    tmp = a[tmp]
    cnt += 1
    if tmp == a[1]:
        print(cnt)
        exit()
print(-1)

Failing test case input:
4
4
2
0
2

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(input())-1 for _ in range(N)]
p = 0
for i in range(N):
    if p == 1:
        print(i)
        exit()
    p = a[p]
print(-1)
Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
dup = []

if not a.count(2):
    print('-1')
else:
    i = 0
    cnt = 0
    while True:
        cnt += 1
        if a[i] == 2:
            print(cnt)
            break
        elif a[i] == i or dup.count(i):
            print('-1')
            break
        dup.append(i)
        i = a[i]-1


Failing test case input:
5
3
3
5
2
4

Expected output:
4


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 0

if not a.count(2):
    print('-1')
else:
    i = 0
    while True:
        cnt += 1
        if a[i] == 2:
            print(cnt)
            break
        elif a[i] == i+1 or cnt > n:
            print('-1')
            break
        i = a[i]-1

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A = []
for i in range(N):
  Ai=int(input())
  A.append(Ai)
on = 1 
for i in range(N):
  on = A[on-1] 
  if on == 2:
    print(i)
    break
if on != 2:
  print(-1)


Failing test case input:
4
3
7
2
3

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
A = []
for i in range(N):
  Ai=int(input())
  A.append(Ai)
on = 1 
for i in range(N):
  on = A[on-1] 
  if on == 2:
    print(i+1)
    break
if on != 2:
  print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n=int(input())

B = [int(input())-1 for i in range(n)]


def fun(k):
    if B[k] == 1:
     	return False                                                    
    else:
        return B[k]
ans = 0
cnt = 0
for i in range(n+1):
    cnt = fun(cnt)
    ans +=1
    if cnt ==False:
        print(ans)
        sys.exit() 
print(-1)
sys.exit()

Failing test case input:
4
4
4
1
1

Expected output:
-1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n=int(input())

B = [int(input())-1 for i in range(n)]


def fun(k):
    if B[k] == 1:
     	return -5                                                    
    else:
        return B[k]
ans = 0
cnt = 0
for i in range(n+1):
    cnt = fun(cnt)
    ans +=1
    
    if cnt ==-5:
        print(ans)
        sys.exit() 
print(-1)
sys.exit()
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    A=[]
    check=[0]*n
    temp=0
    ct=1
    for i in range(n):
        A.append((INT()-1))
    check[0]=1
    for i in range(n):
        if A[temp]==1:
            print(ct)
            break
        elif check[A[temp]]==1:
            print(-1)
            break
        else:
            temp=A[temp]
            check[A[temp]]=1
            ct+=1
            
if __name__ == '__main__':
    do()

Failing test case input:
5
3
-1
4
2
4

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    A=[]
    check=[0]*n
    temp=0
    ct=1
    for i in range(n):
        A.append((INT()-1))
    check[0]=1
    for i in range(n):
        if A[temp]==1:
            print(ct)
            break
        elif check[A[temp]]==1:
            print(-1)
            break
        else:
            temp=A[temp]
            check[temp]=1
            ct+=1
            
if __name__ == '__main__':
    do()

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

now = a[0]
cnt = 0

if cnt <= n:
    cnt += 1
    if now == 2:
        print(cnt)
        exit()
    now = a[now-1]

print(-1)

Failing test case input:
5
3
-1
4
2
4

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

now = a[0]
cnt = 0

while cnt <= n:
    cnt += 1
    if now == 2:
        print(cnt)
        exit()
    now = a[now-1]

print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



N = int(input())
a = [int(input()) for i in range(N)]
pos = 0

for i in range(N):
    if a[pos] == 2:
        print(i)
        break
    else:
        pos = a[pos] - 1
else:
    print(-1)

Failing test case input:
4
3
7
2
3

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):



N = int(input())
a = [int(input()) for i in range(N)]
pos = 0

for i in range(N):
    if pos == 1:
        print(i)
        break
    else:
        pos = a[pos] - 1
else:
    print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
if __name__ == "__main__":
    N = int(input())
    a = [int(input()) for _ in range(N)]

    index = 0
    count = 0
    number = 1
    flags = [0 for _ in range(N)]
    flags[index] = 1
    while(number != 2):
        number = a[index]
        index = number - 1
        count += 1
        print(flags)
        if flags[index] == 1:
            break
        else:
            flags[index] = 1

    if number == 2:
        print(count)
    else:
        print(-1)


Failing test case input:
4
3
3
1
1

Expected output:
-1


Actual output:
[1, 0, 0, 0]
[1, 0, 1, 0]
-1


Fixed submission (verdict: Accepted):
if __name__ == "__main__":
    N = int(input())
    a = [int(input()) for _ in range(N)]

    index = 0
    count = 0
    number = 1
    flags = [0 for _ in range(N)]
    flags[index] = 1
    while(number != 2):
        number = a[index]
        index = number - 1
        count += 1
        if flags[index] == 1:
            break
        else:
            flags[index] = 1

    if number == 2:
        print(count)
    else:
        print(-1)

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]
print(A)
cnt = 1
now = 1

while True:
  if now == A[1]:
    print(cnt+1)
    break
  if (cnt > N):
    print(-1)
    break
  now = A[now-1]
  print(now)
  cnt += 1


Failing test case input:
3
3
1
2

Expected output:
2

Actual output:
[3, 1, 2]
2


Fixed submission (verdict: Accepted):
N = int(input())
V = [int(input()) for i in range(1,N+1)]
cnt = 1
val = V[0]
while True:
  if val == 2:
    print(cnt)
    break
  if (cnt >= N):
    print(-1)
    break
  cnt += 1
  val = V[val-1]

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
buttons = [input() for i in range(n)]
buttons_int = [int(b) - 1 for b in buttons]
button = 0
count = 0
for i in range(n):
    if button == i:
        button = buttons_int[i]
        count += 1
        if button == 0:
            print(-1)
            exit()
        if button == 1:
            print(count)
            exit()



Failing test case input:
4
4
1
0
4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
buttons = [input() for i in range(n)]
buttons_int = [int(b) - 1 for b in buttons]
button = 0
for count in range(1, n+1):
    button = buttons_int[button]
    if button == 1:
        print(count)
        exit()
print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

next = 0
cnt = 0
while(True):
    if next == 1:
        break
    if next == A[A[next] - 1] -1:
        cnt = -1
        break
    next = A[next] -1
    cnt += 1
print(cnt)



Failing test case input:
4
4
4
0
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

next = 0
visited = [False] * N
cnt = 0
while(True):
    if visited[next]:
        cnt = -1
        break
    if next == 1:
        break
    visited[next] = True
    next = A[next] -1
    cnt += 1
print(cnt)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(int(input()) for _ in range(n))
i= 1
cnt=0

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

Failing test case input:
4
3
7
2
1

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = list(int(input()) for _ in range(n))
i= 1
cnt=0

for cnt in range(1, n+1):
    i = a[i-1]
    if(i == 2):
        print(cnt)
        quit()

print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
dic = {i+1:int(input()) for i in range(n)}
light = dic[1]
ans = 1

for i in range(n):
    if light == 2:
        break
    elif light == 1:
        ans = -1
        break
    else:
        ans += 1
        light = dic[light]
    
print(ans)

Failing test case input:
3
3
0
3

Expected output:
-1


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
dic = {i+1:int(input()) for i in range(n)}
light = dic[1]
ans = 1

for i in range(n):
    if light == 2:
        break
    elif light == 1 or i == n-1:
        ans = -1
        break
    else:
        ans += 1
        light = dic[light]
    
print(ans)

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
q = [int(input())  for i in range(n)]
cnt = 0
ind = 0
for i in range(n-1):
  m = q[ind]-1
  if ind+1 == q[m]:
    print(-1)
    exit()
  ind = q[ind]-1
  cnt += 1
  if ind == 1:
    print(cnt)
    break

Failing test case input:
4
4
4
0
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
q = [int(input())  for i in range(n)]
cnt = 0
ind = 0
for i in range(n):
    ind = q[ind]-1
    cnt += 1
    if ind == 1:
        print(cnt)
        exit()
    
print(-1)
Problem: p03680
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def resolve():
    
    n = int(input())
    
    
    
    A = [int(input()) for i in range(n)]
    
    
    
    

    Dic = {i:A[i-1] for i in range(1, n+1)}

    cnt = 0
    now = 1
    rout = []
    while now not in rout:
        rout.append(now)
        now = Dic[now]
        cnt += 1
        if now == 2:
            break

    if rout[-1] == 2:
        print(cnt)
    else:
        print("-1")

resolve()

Failing test case input:
4
4
19
1
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
def resolve():
    
    n = int(input())
    
    
    
    A = [int(input()) for i in range(n)]
    
    
    
    

    Dic = {i:A[i-1] for i in range(1, n+1)}

    cnt = 0
    now = 1
    rout = []

    for _ in range(n):
        rout.append(now)
        now = Dic[now]
        cnt += 1
        if now == 2:
            break

    if now == 2:
        print(cnt)
    else:
        print("-1")

resolve()

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from collections import defaultdict
N = int(input())
a = [int(input()) for _ in range(N)]

d = defaultdict(int)
for i, e in enumerate(a, 1):
    d[i] = e

count = 1
tmp = d[1]
while count < N:
    v = d[tmp]
    count += 1
    if v == 2:
        print(count)
        exit()
    tmp = v
print(-1)


Failing test case input:
3
2
2
1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict
N = int(input())
a = [int(input()) for _ in range(N)]

d = defaultdict(int)
for i, e in enumerate(a, 1):
    d[i] = e

count = 1
tmp = d[1]
if tmp == 2:
    print(1)
    exit()

while count <= N:
    v = d[tmp]
    count += 1
    if v == 2:
        print(count)
        exit()
    tmp = v
print(-1)

Problem: p03680
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(500000)
N=int(input())
A=[int(input())-1 for _ in range(N)]
result=[False]*N
app=result.append
def next(k):
	newlight=A[k]
	if k==1:
		return(1)
	elif result[k]:
		return(0)
	else:
		result[k]=True
		return(next(newlight))
if not next(0):
	print(-1)
else:print(len(result)-1)

Failing test case input:
4
4
1
1
2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(500000)
N=int(input())
A=[int(input())-1 for _ in range(N)]
result=[False]*N
def next(k):
	newlight=A[k]
	if k==1:
		return(1)
	elif result[k]:
		return(0)
	else:
		result[k]=True
		return(next(newlight))
if not next(0):
	print(-1)
else:print(sum(result))

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
b=list(int(input()) for i in range(N))

n=0
ans=0
for j in range(N):
    n=b[n]-1
    ans += 1
    if n==1:
        break
print(ans)

Failing test case input:
4
4
19
1
4

Expected output:
-1


Actual output:
4


Fixed submission (verdict: Accepted):
N=int(input())
b=list(int(input()) for i in range(N))

n=0
ans=0
for j in range(N+1):
    n=b[n]-1
    ans += 1
    if n==1:
        break
if ans<N+1:
    print(ans)
else:
    print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n = int(input())
a = []
for j in range(n):
    a.append(int(input()))

count = 0
i = 1
for j in range(n+1):
    if a[i-1]==2:
        count += 1
        print(count)
        break
    else:
        i = a[i-1]
        print(a[i-1], i)
        count += 1
    if j ==n:
        print(-1)

Failing test case input:
4
1
3
1
3

Expected output:
-1


Actual output:
1 1
1 1
1 1
1 1
1 1
-1


Fixed submission (verdict: Accepted):

n = int(input())
a = []
for j in range(n):
    a.append(int(input()))

count = 0
i = 1
for j in range(n+1):
    if a[i-1]==2:
        count += 1
        print(count)
        break
    else:
        i = a[i-1]
        count += 1
    if j ==n:
        print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a =[0]*N
for i in range(N):
  a[i] = int(input())

i = 0
l = 1
while 1:
  l=a[l-1]
  if l==2:
    ans=l
    break
  if i>N:
    ans=-1
    break
  i+=1
print(ans)
  

Failing test case input:
3
2
2
0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
a =[0]*N
for i in range(N):
  a[i] = int(input())

i = 0
l = 1
while 1:
  i+=1
  l=a[l-1]
  if l==2:
    ans=i
    break
  if i>N:
    ans=-1
    break
print(ans)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for _ in range(n)]
used = {1}
pos = 1
count = 0
for _ in range(n):
  pos = A[pos - 1]
  count += 1
  if pos in used:
    print(-1)
    break
  if pos == 2:
    print(count)
    break

Failing test case input:
3
3
2
3

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for _ in range(n)]
used = {1}
pos = 1
count = 0
for _ in range(n):
  pos = A[pos - 1]
  count += 1
  if pos in used:
    print(-1)
    break
  used.add(pos)
  if pos == 2:
    print(count)
    break

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
buttun=[0]
for i in range(N):
    buttun.append(int(input()))

light=1
ans=0
while True:
    if light==2:
        break
    elif light==buttun[light]:
        ans=-1
        break
    else:
        light=buttun[light]
        ans+=1
        buttun[light]=1
    if light==1:
        ans=-1
        break
print(ans)

Failing test case input:
4
4
1
2
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
N=int(input())
buttun=[0]
for i in range(N):
    buttun.append(int(input()))

light=1
ans=0
while True:
    if light==2:
        break
    elif light==buttun[light]:
        ans=-1
        break
    else:
        tmp=light
        light=buttun[light]
        ans+=1
        buttun[tmp]=1
    if light==1:
        ans=-1
        break
print(ans)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(input()) for i in range(0,n)]
j=0
ans=-1
for i in range(0,n):
    if a[j] == 2:
        ans = j
        break
    j = a[j]-1

print(ans)    

Failing test case input:
4
4
2
0
2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input()) for i in range(0,n)]
j=0
ans=-1
for i in range(1,n+1):
    if a[j] == 2:
        ans = i
        break
    j = a[j]-1

print(ans)

Problem: p03680
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
l = [(int(input())-1) for _ in range(N)]
flag = [0]*N
flag[0] = 1
flag[1] = 2
cnt = 0
cur_b = 0
for i in range(N):
    cnt += 1
    next_b = l[cur_b]
    if flag[next_b] == 1:
        print(-1)
        break
    elif flag[next_b] == 2:
        print(cnt)
        break
    else:
        flag[next_b] == 1
        cur_b = next_b
        


Failing test case input:
4
4
19
1
4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
l = [(int(input())-1) for _ in range(N)]
flag = [0]*N
flag[0] = 1
flag[1] = 2
cnt = 0
cur_b = 0
for i in range(N):
    cnt += 1
    next_b = l[cur_b]
    if flag[next_b] == 1:
        print(-1)
        break
    elif flag[next_b] == 2:
        print(cnt)
        break
    else:
        flag[next_b] == 1
        cur_b = next_b
else:print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n=int(input())
A = [0]*n
B = [int(input())-1 for i in range(n)]
C = [0]
print(B)
def fun(k):
    if B[k] == 1:
     	return False                                                    
    else:
        return B[k]
ans = 0
cnt = 0
for i in range(n):
    cnt = fun(cnt)
    ans +=1
    if cnt ==False:
        print(ans)
        sys.exit() 
print(-1)
sys.exit()
        

Failing test case input:
3
1
0
6

Expected output:
-1


Actual output:
[0, -1, 5]
1


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n=int(input())

B = [int(input())-1 for i in range(n)]


def fun(k):
    if B[k] == 1:
     	return -5                                                    
    else:
        return B[k]
ans = 0
cnt = 0
for i in range(n+1):
    cnt = fun(cnt)
    ans +=1
    
    if cnt ==-5:
        print(ans)
        sys.exit() 
print(-1)
sys.exit()

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(input())-1 for _ in range(N)]
tmp = a[0]
cnt = 0
for _ in range(100001):
    tmp = a[tmp]
    cnt += 1
    if tmp == a[1]:
        print(cnt)
        exit()
print(-1)

Failing test case input:
4
3
2
2
3

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(input())-1 for _ in range(N)]
p = 0
for i in range(N):
    if p == 1:
        print(i)
        exit()
    p = a[p]
print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
a = [int(input()) for i in range(N)]

i = a[0]
count = 1

while count <= N:
    if i == 2:
        print(count)
        break
    elif a[i-1] == 2:
        count = count + 1
        print(count)
        exit()
    else:
        i = a[i - 1]
        count = count + 1

print(-1)

Failing test case input:
4
2
21
2
4

Expected output:
1


Actual output:
1
-1


Fixed submission (verdict: Accepted):

N = int(input())
a = [int(input()) for k in range(N)]
count = 1
tmp = a[a[0]-1]
while count <= N:
    if a[0] == 2:
        print(count)
        exit()
    elif tmp == 2:
        count += 1
        print(count)
        exit()
    else:
        tmp = a[tmp-1]
        count += 1

print(-1)

Problem: p03680
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
from io import StringIO
import unittest

def resolve():
    lines = sys.stdin.readlines()
    lines = list(map(lambda x: int(x.rstrip()), lines))
    n = lines[0]
    i = 1
    for c in range(1, n+1):
        i = lines[i]
        if i == 2:
            print(c)
            return
    print(-1)

Failing test case input:
5
3
-1
4
2
4

Expected output:
3


Actual output:

Fixed submission (verdict: Accepted):
import sys
from io import StringIO
import unittest

def resolve():
    lines = sys.stdin.readlines()
    lines = list(map(lambda x: int(x.rstrip()), lines))
    n = lines[0]
    i = 1
    for c in range(1, n+1):
        i = lines[i]
        if i == 2:
            print(c)
            return
    print(-1)
    
resolve()

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
lis = ["0"]*n
bot = a[0]
lis[0] == "1"
cnt = 1
while True:
    if bot == 2:
        print(cnt)
        break
    elif lis[bot-1] == "1":
        print(-1)
        break
    else:
        cnt += 1
        bot = a[bot-1]
        lis[bot-1] = "1"

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
lis = ["0"]*n
bot = a[0]
lis[0] = "1"
cnt = 1

while True:
    if bot == 2:
        print(cnt)
        break
    elif bot != 2 and lis[bot-1] == "1":
        print(-1)
        break
    else:
        cnt += 1
        lis[bot-1] = "1"
        bot = a[bot-1]

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
ai = [int(input()) for _ in range(N)]
if ai[0] == 2:
    print("0")
else:
    lightning = ai[0]
    count = 1
    ok = False
    for _ in range(N):
        if lightning == 2:
            print(count)
            ok = True
        break
    lightning = ai[lightning-1]
    count += 1

    if not ok:
        print("-1")


Failing test case input:
4
4
1
2
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):

N = int(input())
ai = [int(input()) for _ in range(N)]

lightning = 1
count = 1
ok = False
for _ in range(N):
    lightning = ai[lightning-1]
    if lightning == 2:
        print(count)
        ok = True
        break
    else:
        count += 1

if not ok:
    print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
b = []
for i in range(n):
   a.append(int(input()))
   b.append(0)


b[0] = 1
now = 0
count = 0
while (b[1] != 1 and count <= n):
   next = a[now] - 1

   if (b[next] == -1):
      print(-1)
      exit()

   b[now] = -1
   b[next] = 1

   now = next
   count += 1

print(count)


Failing test case input:
4
4
19
0
4

Expected output:
-1


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
a = []
b = []
for i in range(n):
   a.append(int(input()))
   b.append(0)


b[0] = 1
now = 0
count = 0
while (b[1] != 1 and count <= n):
   next = a[now] - 1

   if (b[next] == -1):
      print(-1)
      exit()

   b[now] = -1
   b[next] = 1

   now = next
   count += 1

if (b[1] == 1):
   print(count)
else:
   print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[i for i in range(n)]
b=a[0]
for i in range(n+1):
  if b==2:
    print(i+1)
    break
  else:
    b=a[b-1]
  if i==n:
    print(-1)

Failing test case input:
4
3
32
2
3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0]
for i in range(n+1):
  if b==2:
    print(i+1)
    break
  else:
    b=a[b-1]
  if i==n:
    print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


n = int(input())
a_list = [int(input()) for i in range(n)]
ans = 0

if 1 in a_list:
    idx = a_list.index(1)
else:
    idx = 0
    ans += 1

for i in range(n):
    if a_list[idx] == 2:
        break
    ans += 1
    idx = a_list[idx]-1

if ans == n:
    ans = -1

print(ans)

Failing test case input:
4
4
8
0
4

Expected output:
-1


Actual output:
5


Fixed submission (verdict: Accepted):


n = int(input())
a_list = [int(input()) for i in range(n)]
ans = 0
idx = 0

for i in range(n):
    ans += 1
    if a_list[idx] == 2:
        break
    idx = a_list[idx]-1

if ans == n:
    ans = -1

print(ans)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
n = int(input())
a = [int(input()) for _ in range(n)]
lamp = 0
ans=0
for i in range(n):
    if i == a[i]:
        pass
    if lamp == i:
        lamp = a[i] - 1
        ans += 1
        
    if lamp == 1:
        print(ans)
        sys.exit()
print(-1)

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):

import sys
n = int(input())
a = [int(input()) for _ in range(n)]
lamp = 1
ans=0
for i in range(n):
    if lamp - 1 == 1:
        print(i)
        sys.exit()
    lamp = a[lamp - 1]
print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]
B = 1
for j in(A):
  if j == 2:
    print(B)
    break
  else:
    B += 1
   
   

Failing test case input:
3
1
-4
6

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for i in range(N)]
B = 0
C = 1
for j in range(N):
  if A[B] == 2:
    print(C)
    break
  elif j == N-1:
    print('-1')
  else:
    B = A[B]-1
    C += 1
Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 1
p = a[0]
for _ in range(len(a)):
    if p == 2:
        print(ans)
        break
    elif ans > n:
        print(-1)
        break
    else:
        if p != a[p-1]:
            p = a[p-1]
            ans += 1
        else:
            print(-1)
            break

Failing test case input:
5
3
-1
4
3
4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 1
p = a[0]
while True:
    if p == 2:
        print(ans)
        break
    elif (p == a[p-1]) | (ans > n):
        print(-1)
        break
    else:
        p = a[p-1]
        ans += 1

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(input()) for _ in range(n)]
b=[1]
buf=1
if 2 not in a:
    print(-1)
else:
    for i in range(n):
        a_buf=a[buf-1]
        
        if a_buf==2:
            
            print(len(b))
            break
        
            
            
            
        b.append(a_buf)
        buf=a_buf

Failing test case input:
4
1
0
0
2

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input()) for _ in range(n)]
b=[1]
buf=1
count=0
if 2 not in a:
    print(-1)
else:
    while count<n:
        a_buf=a[buf-1]
        
        if a_buf==2:
            
            print(len(b))
            break
        
            
            
            
        b.append(a_buf)
        buf=a_buf
        count+=1
    if count==n:
        print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math










mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    b = [0] * n
    b[0] = 1
    i = 0
    ans = 0
    while not b[1] and not b[a[i]-1]:
        b[a[i]-1] = 1
        ans += 1
        i = a[i]-1
        if not b[1] and b[a[i]-1]:
            ans = -1
    print(ans)
    return

if __name__=='__main__':
    main()


Failing test case input:
5
1
0
0
2
5

Expected output:
-1


Actual output:
0


Fixed submission (verdict: Accepted):












mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    b = [0] * n
    b[0] = 1
    i = 0
    ans = 0
    while True:
        b[a[i]-1] = 1
        ans += 1
        i = a[i]-1
        if b[1]:
            break
        elif b[a[i]-1]:
            ans = -1
            break
    print(ans)
    return

if __name__=='__main__':
    main()
Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0

for i in range(n):
    if i == 0:
        now = a[0]-1
        ans += 1
    else:
        now = a[now]-1
        ans += 1
    if now == 1:
        print(ans)
        break
    if i == n:
        print(-1)



Failing test case input:
5
1
3
5
1
4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0

for i in range(n):
    if i == 0:
        now = a[0]-1
        ans += 1
    else:
        now = a[now]-1
        ans += 1
    if now == 1:
        print(ans)
        break
if i+1 == n:
    print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n = int(input())
a = [int(input()) for _ in range(n)]
check = [0] * n
print(check)
count = 0
button = a[0]
while(True):
    count += 1
    if button == 2:
        break
    if check[button-1] == 1:
        print(-1)
        sys.exit()
    check[button-1] = 1
    button = a[button-1]
print(count)


Failing test case input:
4
4
0
0
2

Expected output:
2


Actual output:
[0, 0, 0, 0]
2


Fixed submission (verdict: Accepted):
import sys
n = int(input())
a = [int(input()) for _ in range(n)]
check = [0] * n
count = 0
button = a[0]
while(True):
    count += 1
    if button == 2:
        break
    if check[button-1] == 1:
        print(-1)
        sys.exit()
    check[button-1] = 1
    button = a[button-1]
print(count)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = []
for a in range(N) :
    a = int(input())
    A.append(a)
p = A[0]
answer = 1
for i in range(N-1) :
    if p == 2 :
        break
    elif i == (p-1) :
        p = A[i]
        answer += 1
if p == 2 :
    print(answer)
else :
    print(-1)
    

Failing test case input:
4
4
10
0
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
L = [int(input()) for i in range(N)]

flag = 0
now = 0
ans = 0
for i in range(N+1) :
    if now == 1 :
        flag = 1
        break
    else :
        now = L[now]-1
        ans += 1
if flag == 1 :
    print(ans)
else :
    print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n = int(input())
ns = [int(input()) for _ in range(n)]
if not 1 in ns:
    print(-1)
    sys.exit(0)
i = 0
cnt = 0
pushed = [0]*n
flg = False
while(True):
    cnt += 1
    i = ns[i] - 1
    if pushed[i] == 1:
        break
    pushed[i] = 1
    if i == 1:
        flg = True
        break
if flg:
    print(cnt)
else:
    print(-1)

Failing test case input:
4
2
22
2
3

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
n = int(input())
ns = [int(input()) for _ in range(n)]
if not 2 in ns:
    print(-1)
    sys.exit(0)
i = 0
cnt = 0
pushed = [0]*n
flg = False
while(True):
    cnt += 1
    i = ns[i] - 1
    if pushed[i] == 1:
        break
    pushed[i] = 1
    if i == 1:
        flg = True
        break
if flg:
    print(cnt)
else:
    print(-1)