ZhenlongDai/ACPR huggingface dataset:
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = int(input())
    switches = [int(input()) for _ in range(N)]

    cur = 0
    nxt = 0
    count = 0
    while True :

        nxt = switches[cur] - 1
        count += 1
        
        if switches[nxt] - 1 == cur:
            print(-1)
            break

        if nxt == 1:
            print(count)
            break

        cur = nxt
main()

Failing test case input:
4
4
4
0
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
import random
def main():
    N = int(input())
    switches = [int(input()) for _ in range(N)]

    count = 0
    cur   = 0
    nxt   = 0

    find = False

    for i in range(2*N):
        count += 1

        if switches[cur] == 2:
            find = True
            print(count)
            break

        nxt = switches[cur] - 1

        if switches[nxt] - 1 == cur:
            find = True
            print(-1)
            break

        cur = nxt
    if find == False:
        print(-1)

main()

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
bL = [1 for _ in range(100000)]

time = 1
push = 0
while True:
    
    if bL[push] == 2:
        print(time)
        break
    if time == N:
        print("-1")
        break
    
    push = bL[push]-1
    
    time += 1

Failing test case input:
4
3
4
2
1

Expected output:
2


Actual output:
-1


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

time = 1
push = 0
while True:
    
    if bL[push] == 2:
        print(time)
        break
    if time == N:
        print("-1")
        break
    
    push = bL[push]-1
    
    time += 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+1 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:
4
2
12
2
3

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())
li=[]

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

check=[0]
s=0
count=1

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

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

Failing test case input:
3
2
2
1

Expected output:
1


Actual output:
-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.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 0

if 2 not in a:
  print(-1)

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

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

print(-1)

Failing test case input:
4
4
19
1
4

Expected output:
-1


Actual output:
-1
-1


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

if 2 not in a:
  print(-1)
  exit()

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

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

print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n + 1):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

Failing test case input:
3
1
1
3

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
index = 1
count = 0
while index != 2 and count < n:
  index = a[index-1]
  count += 1
print(count)

Failing test case input:
4
3
4
1
2

Expected output:
-1

Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
index = 1
count = 0
while index != 2 and count < n:
  index = a[index-1]
  count += 1
if count != n:
  print(count)
else:
  print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
B = [int(input()) for i in range(N)]
A = [0]
A.extend(B)
past = [1]
next_l = 1
if not 2 in A:
  print(-1)
for i in range(N):
  next_l = A[next_l]
  if next_l in past or next_l > N:
    print(-1)
    break
  if next_l == 2:
   print(len(past))
   break
  past.append(next_l)
print(-1)



Failing test case input:
4
3
7
2
1

Expected output:
2


Actual output:
2
-1


Fixed submission (verdict: Accepted):
N = int(input())
B = [int(input()) for i in range(N)]
A = [0]
A.extend(B)
past = [1]
next_l = 1



for i in range(N):
  next_l = A[next_l]
  
  
  
  if next_l == 2:
    print(len(past))
    exit(0)
  past.append(next_l)
print(-1)

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = [(i+1, int(input())) for i in range(N)]
cnt = 1
for i in range(N):
  if 2 not in A[i]:
    print(-1)
    exit()
    
x = A[0]
while x[1] != 2:  
  
  x = A[x[1]-1]
  cnt += 1
  if x[1] == 1:
    print(-1)
    exit()
print(cnt+1)

Failing test case input:
3
2
2
6

Expected output:
1


Actual output:
-1


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

if 2 not in a:
  print(-1)
  exit()

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

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

print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
switch = [i - 1 for i in range(n)]
flag = [False] * n
i = 0
cnt = 0
while not flag[i]:
  cnt += 1
  flag[i] = True
  i = switch[i]
  if i == 1:
    print(cnt)
else:
  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 = []
for _ in range(n):
    a.append(int(input()) - 1)
cnt = 0
i = 0
flag = [False] * n
while not flag[i]:
    cnt += 1
    flag[i] = True
    i = a[i]
    if i == 1:
        print(cnt)
        break
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()))

index = 1
cnt = 0

for _ in range(N):
    index = a[index - 1]
    cnt += 1
    if index == 2 :
        break
    if index == 1 :
        cnt = -1
        break

print(cnt)


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

Expected output:
-1


Actual output:
5


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

index = 1
cnt = 0

for i in range(N):
    index = a[index - 1]
    cnt += 1
    if index == 2 :
        break
    if index == 1 :
        cnt = -1
        break
    if i == N - 1 :
        cnt = -1

print(cnt)

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):
  m = q[ind]-1
  if ind+1 == q[m]:
    if ind+1 == 2 or q[m]==2:
        print(cnt)
        break
    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 (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 before_num - 1 in lighted_bottons:
                print(-1)
                break
            before_num = a[before_num - 1]
            lighted_bottons.append(before_num - 1)

Failing test case input:
5
3
0
4
2
4

Expected output:
3


Actual output:
-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):
N = int(input())

a = []

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

done = [False] * N

i = 0

ans = 0

while done[i] == False:
    if done[a[i]] == False:
        done[i] = True
        ans += 1
        if a[i] == 1:
            break
        i = a[i]
    else:
        ans = -1
        break

print(ans)


Failing test case input:
3
1
-1
6

Expected output:
-1


Actual output:
1


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

a = []

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

done = [False] * N

i = 0

ans = 0

while True:
    if done[i] == False:
        done[i] = True
        ans += 1
        if a[i] == 1:
            break
        i = a[i]
    else:
        ans = -1
        break

print(ans)

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = [(i+1, int(input())) for i in range(N)]
cnt = 0
for i in range(N):
  if 2 not in A[i]:
    print(-1)
    exit()
    
x = A[0]
while x[1] > 2:  
  
  x = A[x[1]-1]
  cnt += 1
  if x[1] == 1:
    print(-1)
    exit()
print(cnt+1)

Failing test case input:
4
4
1
2
2

Expected output:
2


Actual output:
-1


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

if 2 not in a:
  print(-1)
  exit()

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

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

print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
list=[]
for i in range(N):
    list.append(int(input()))
count=1
X=list[0]
while X != 2 and count < N:
    X=list[X-1]
    count+=1
print(count)

Failing test case input:
4
4
19
1
4

Expected output:
-1


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
list=[]
for i in range(N):
    list.append(int(input()))
count=0
X=list[0]
while True:
    count+=1
    if X == 2:
        print(count)
        break
    elif count == N:
        print(-1)
        break
    X=list[X-1]

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

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

print(count if n == 1 else -1)

Failing test case input:
4
4
10
0
2

Expected output:
2


Actual output:
2
2


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

n = 0
count = 0
for i in range(N - 1):
  count += 1
  n = a[n] - 1
  if n == 1:
    break 

print(count if n == 1 else -1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
3
2
2
0

Expected output:
1


Actual output:
1
-1


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

cnt = 0
cur = 1

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

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

print(-1)

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

    for _ in range(N):
        s = int(input())
        switches.append(s)

    cur = 0
    nxt = 0
    count = 0
    while True :

        nxt = switches[cur] - 1
        count += 1
        
        if switches[nxt] - 1 == cur:
            print(-1)
            break

        if nxt == 1:
            print(count)
            break

        cur = nxt
main()

Failing test case input:
4
3
3
2
4

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
import random
def main():
    N = int(input())
    switches = [int(input()) for _ in range(N)]

    count = 0
    cur   = 0
    nxt   = 0

    find = False

    for i in range(2*N):
        count += 1

        if switches[cur] == 2:
            find = True
            print(count)
            break

        nxt = switches[cur] - 1

        if switches[nxt] - 1 == cur:
            find = True
            print(-1)
            break

        cur = nxt
    if find == False:
        print(-1)

main()

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):
  if ind == 1:
    print(cnt)
    break
  m = q[ind]-1
  if ind+1 == q[m]:
    if ind+1 == 2:
        print(cnt)
        break
    print(-1)
    exit()
  ind = q[ind]-1
  cnt += 1


Failing test case input:
4
3
3
2
4

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 (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(input()) for i in range(N)]
q = 1
cnt = 0
li = []
for i in range(100001):
    q = a[q-1]
    cnt += 1
    if q == 2:
        print(cnt)
        break
print(-1)

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
3
-1


Fixed submission (verdict: Accepted):
import sys
N = int(input())
a = [int(input()) for i in range(N)]
q = 1
cnt = 0
li = []
for i in range(100001):
    q = a[q-1]
    cnt += 1
    if q == 2:
        print(cnt)
        sys.exit()
print(-1)
Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 0

if 2 not in a:
  print(-1)

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

print(-1)

Failing test case input:
4
3
12
1
3

Expected output:
-1


Actual output:
-1
-1


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

if 2 not in a:
  print(-1)
  exit()

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

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

print(-1)

Problem: p03680
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
S = [int(input()) for i in range(N)]
count=1
i=0
while True:
  if S[i]==2 or count==N-1:
    break
  else:
    count+=1
    i=S[i]-1
if count==N-1: print(-1)
else: print(count)

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
S = [int(input()) for i in range(N)]
count=1
i=0
while True:
  if S[i]==2 or count==N:
    break
  else:
    count+=1
    i=S[i]-1
if count==N: print(-1)
else: print(count)

Problem: p03680
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
a_list=[]
exists=False
for _ in range(N):
    a = int(input())
    a_list.append(a)
    if a == 2:
        exists = True
if not exists:
    print(-1)

curr = 0
already = set()
ans=0
while True:
    nexthop = a_list[curr] - 1
    if nexthop in already:
        print(-1)
        exit()
    already.add(nexthop)
    curr = nexthop
    ans+=1
    if nexthop == 1:
        print(ans)
        exit()

Failing test case input:
4
4
8
0
4

Expected output:
-1


Actual output:
-1
-1


Fixed submission (verdict: Accepted):
N=int(input())
a_list=[]
exists=False
for _ in range(N):
    a = int(input())
    a_list.append(a)
    if a == 2:
        exists = True
if not exists:
    print(-1)
    exit()

curr = 0
already = set()
ans=0
while True:
    nexthop = a_list[curr] - 1
    if nexthop in already:
        print(-1)
        exit()
    already.add(nexthop)
    curr = nexthop
    ans+=1
    if nexthop == 1:
        print(ans)
        exit()

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):
        lightning = ai[lightning-1]
        count += 1
        if lightning == 2:
            print(count)
            ok = True
        break

    if not ok:
        print("-1")


Failing test case input:
4
4
1
2
3

Expected output:
3


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):

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

Failing test case input:
4
3
22
2
1

Expected output:
2


Actual output:

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):

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

Failing test case input:
5
3
3
5
2
4

Expected output:
4


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)]

now=1
c=1

while c<N:
    now=A[now-1]
    c+=1
    if(now==2):
        print(c)
        break
else:
    print("-1")

Failing test case input:
4
2
12
2
3

Expected output:
1


Actual output:
2


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

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

now=1
c=0

while c<N:
    now=A[now-1]
    c+=1
    if(now==2):
        print(c)
        break
else:
    print("-1")

Problem: p03680
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
a = {i + 1: int(input()) for i in range(N)}
ans = -1

count = 0
nxt = 1
while count < N:
  nxt = a[nxt]
  if nxt == 2:
    ans = count
    break
  count += 1

print(ans)

Failing test case input:
4
3
12
2
3

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
a = {i + 1: int(input()) for i in range(N)}
ans = -1

count = 1
nxt = 1
while count < N:
  nxt = a[nxt]
  if nxt == 2:
    ans = count
    break
  count += 1

print(ans)

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

idx = 1
flag = False
for i in range(1, N+1):
  idx = A[idx - 1]
  if idx == 2:
    flag = True
    break

if flag:
  print(i + 1)
else:
  print(-1)

Failing test case input:
4
3
7
2
4

Expected output:
2


Actual output:
3


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

idx = 1
flag = False
for i in range(1, N+1):
  idx = A[idx - 1]
  if idx == 2:
    flag = True
    break

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

for i in range(len(a)):
  if b==2:
    print(ans)
    exit()
  b = a[b-1]
  ans += 1
print


Failing test case input:
3
1
-4
6

Expected output:
-1


Actual output:

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

for i in range(len(a)):
  if b==2:
    print(ans)
    exit()
  b = a[b-1]
  ans += 1
print(-1)

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

Failing test case input:
3
2
2
6

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
button = [1] + [0] * (n - 1)
i = 0
count = 0
for _ in range(n):
    count += 1
    if button[i] == 1:
        button[i] = 0
        button[a[i] - 1] = 1
        i = a[i] - 1
    else:
        print(-1)
    if button[1] == 1:
        print(count)
        exit()
print(-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:
  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
21
2
4

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 (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}
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
21
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())
a=[int(input()) for i in range(n)]

count=1

for i in range(n):
    if count == 2:
        print(i)
        exit()
    count=a[count-1]

print(count)    

Failing test case input:
4
1
3
1
3

Expected output:
-1


Actual output:
1


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

count=1

for i in range(n):
    if count == 2:
        print(i)
        exit()
    count=a[count-1]

print(-1)

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

a=[""]*n

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

light = a[0]
counter = 1
result = -1
if light == 2:
  print(1)
  exit()
for i in range(n):
  light = a[light-1]
  counter += 1
  print(light)
  if light == 2:
    result = counter
    break
print(result)

Failing test case input:
4
3
2
2
3

Expected output:
2


Actual output:
2
2


Fixed submission (verdict: Accepted):
n = int(input())

a=[""]*n

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

light = a[0]
counter = 1
result = -1
if light == 2:
  print(1)
  exit()
for i in range(n):
  light = a[light-1]
  counter += 1
  if light == 2:
    result = counter
    break
print(result)

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

n = int(input())
a = [0]

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

cnt = 0
b = 0
ans = 0

for j in range(n+1):
    cnt += 1
    b = a[b]
    
    if b == 2:
        ans = 1
        break
if ans == 1:
    print(cnt)

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())
num=[0]
ans=0
count=0
k=1
for i in range(n):
    a=int(input())
    num.append(a)

for i in range(n+1):
    k=num[k]
    count+=1
    if k==2:
        ans=1
        break
if ans==1:
    print(count)
else:
    print("-1")

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

N = int(input())

A = [[int(input()),False] for i in range(N)]
idx = 0
A[0][1] == True
cnt = 1

while cnt != N:
    if A[idx][1]:
        print(-1)
        exit()
    if A[idx][0] == 2:
        print(cnt)
        exit()
    A[idx][1] = True
    idx = A[idx][0]-1
    cnt += 1

Failing test case input:
3
3
2
1

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):

N = int(input())

A = [[int(input()),False] for i in range(N)]
idx = 0
A[0][1] == True
cnt = 1

while cnt != 2*N:
    if A[idx][1]:
        print(-1)
        exit()
    if A[idx][0] == 2:
        print(cnt)
        exit()
    A[idx][1] = True
    idx = A[idx][0]-1
    cnt += 1
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[]
for _ in range(n):
  a += [int(input())-1]
s=set()
i=0
n=0
while True:
  n+=1
  i = a[i]
  if i==1:
    break
  elif i in s:
    print(-1)
    break
  else:
    s|={i}
else:
  print(n)

Failing test case input:
4
4
0
0
2

Expected output:
2


Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input())-1 for _ in range(n)]
s=set()
i=0
n=0
while True:
  n += 1
  i = a[i]
  if i==1:
    print(n)
    break
  elif i in s:
    print(-1)
    break
  else:
    s|={i}

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
s = a[0]
c = 1
while s == 2 and c<n:
    s = a[s-1]
    c += 1
print(c if c<n else -1)


Failing test case input:
4
3
32
2
1

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
s = a[0]
c = 1
while s != 2 and c<n:
    s = a[s-1]
    c += 1
print(c if c<n else -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()))

cur = 0
cnt = 0
for i in range(10**6):
    if a[cur] == 2:
        print(cnt)
        exit()
    cur = a[cur]-1
    cnt += 1
print(-1)

Failing test case input:
4
3
23
2
3

Expected output:
2


Actual output:
1


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

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

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

Failing test case input:
5
3
0
4
2
4

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(input()) for _ in range(N)]
cnt = 0
button = 1
for _ in range(N):
    button = a[button - 1]
    cnt += 1
    if button == 2:
        print(cnt)
        exit()
print(-1)

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

nex=a[0]
cnt=0
while nex != 2 and cnt<N:
    cnt+=1
    nex=a[nex-1]
    
if cnt<N:
    print(cnt)
else:
    print(-1)



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

Expected output:
3


Actual output:
2


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

nex=a[0]
cnt=1
while nex != 2 and cnt<N:
    cnt+=1
    nex=a[nex-1]
    
if cnt<N:
    print(cnt)
else:
    print(-1)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
l = [0] + [int(input()) for i in range(n)]
cnt = 0
a = 1
while a != 2:
    if a==0:
        print(-1)
        break
    a = l[a]
    l[a] = 0
    cnt += 1
else:
    print(cnt)


Failing test case input:
4
3
32
2
1

Expected output:
2


Actual output:
-1


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

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

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
0 4
3 3
2 2
3


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
pos=0
for i in range(n+1):
  if a[pos] == 2:
    print(i+1)
    exit()
  pos = a[pos]-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)]
now = a[0]
cnt = 1
for i in range(n):
    
    now = a[now - 1]
    cnt += 1
    if now == a[1]:
        
        print(cnt -1)
        
        exit()
print("-1")

Failing test case input:
4
4
2
1
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()) for _ in range(n)]
now = a[0]
c = 1

if now == 2:
    print(1)
    exit()

for i in range(n):
    now = a[now-1]
    c += 1
    if now == 2:
        print(c)
        break
print(-1)

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
3
-1


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

if now == 2:
    print(1)
    exit()

for i in range(n):
    now = a[now-1]
    c += 1
    if now == 2:
        print(c)
        exit()
print(-1)

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    count = 0
    num = 1
    for i in range(N):
        num = A[num-1]
        count += 1
        if num == 1:
            print("-1")
            exit()
        elif num == 2:
            print(count)
            exit()
resolve()

Failing test case input:
4
4
0
0
4

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    count = 0
    num = 1
    for i in range(N):
        num = A[num-1]
        count += 1
        if num == 2:
            print(count)
            exit()
    print("-1")
resolve()
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for _ in range(n)]
a.insert(0,-1)
ans = 0

tmp = 1
for i in range(1,n+1):
    current = a[tmp]
    ans += 1
    if current == 2:
        exit()
    else:
        tmp = current
        print(tmp)

print(a[0])

Failing test case input:
5
1
0
0
2
5

Expected output:
-1


Actual output:
1
1
1
1
1
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for _ in range(n)]
a.insert(0,-1)
ans = 0

tmp = 1
for i in range(1,n+1):
    current = a[tmp]
    ans += 1
    if current == 2:
        print(ans)
        exit()
    else:
        tmp = current

print(a[0])

Problem: p03680
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys 
N = list(map(int, sys.stdin))
bot = N[1]
for i in range(N[0]):
  if bot == 2:
    print(i)
    break
  bot == N[bot]
else:
  print(-1)

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys 
N = list(map(int, sys.stdin))
bot = N[1]
for i in range(N[0]):
  if bot == 2:
    print(i+1)
    break
  bot = N[bot]
else:
  print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from collections import deque

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n + 1):
    if button == 2:
        print(count)
        break
    button = a[button]

if count == n:
    print(-1)

Failing test case input:
5
1
0
5
2
5

Expected output:
-1


Actual output:

Fixed submission (verdict: Accepted):
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

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
3
3
5
2
4

Expected output:
4


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):

import sys
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
if not 2 in a:
    print(-1)
    sys.exit()
s = set()
s.add(1)
cur = 1
ans = 0
while not cur in s:
    if a[cur-1] == 2:
        print(ans+1)
        sys.exit()
    else:
        cur = a[cur-1]
        s.add(cur)
        ans += 1
print(-1)

Failing test case input:
4
3
32
2
1

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):

import sys
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
if not 2 in a:
    print(-1)
    sys.exit()
s = set()
cur = 1
ans = 0
while not cur in s:
    if a[cur-1] == 2:
        print(ans+1)
        sys.exit()
    else:
        s.add(cur)
        cur = a[cur-1]
        ans += 1
print(-1)

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

for i in range(n):
    num = a[num]
    count += 1
    if num == 2:
        break

if num != 2:
    count = -1

print(count)


Failing test case input:
4
3
2
2
2

Expected output:
2


Actual output:
-1


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

for i in range(n):
    num = a[num - 1]
    count += 1
    if num == 2:
        break

if num != 2:
    count = -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) :
    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
1
2
3

Expected output:
3


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):

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):
        lightning = ai[lightning-1]
        count += 1
        if lightning == 2:
            print(count)
            ok = True
            break

    if not ok:
        print("-1")


Failing test case input:
3
2
2
0

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 _ in range(n)]
pos=0
for i in range(n):
  print(pos,a[pos])
  if a[pos] == 2:
    print(i+1)
    exit()
  pos = a[pos]-1
print(-1)

Failing test case input:
5
1
3
5
4
4

Expected output:
-1


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


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

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

print(count) if ind == 2 else print(-1)

Failing test case input:
5
3
3
5
2
4

Expected output:
4


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [int(input()) - 1 for _ in range(N)]

cnt, i = 0, 0
while cnt < N:
    print(i)
    cnt += 1
    if A[i] == 1:
        break
    i = A[i]
print(cnt if cnt < N else -1)

Failing test case input:
3
3
0
2

Expected output:
2


Actual output:
0
2
2


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

cnt, i = 0, 0
while cnt < N:
    cnt += 1
    if A[i] == 1:
        break
    i = A[i]
print(cnt if cnt < N else -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()))

now = a[0]
count = 1

while now != 2 and count < n:
    count += 1
    now = a[now - 1]

    if now == 2:
        print(count)
        exit(0)

    if count >= n:
        print("-1")
        exit(0)



Failing test case input:
4
2
22
2
3

Expected output:
1


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())

a = []

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

now = a[0]
count = 1

while now != 2 and count < n:
    count += 1
    now = a[now - 1]

if now == 2:
    print(count)
    exit(0)

else:
    print("-1")
    exit(0)

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

ans = 0
tmp = 0

for i in range(n):
    ans += 1
    if a[tmp] == 2:
        break;
    tmp = a[tmp] - 1
if ans == 0:
    ans = -1

print(ans)


Failing test case input:
4
3
1
1
0

Expected output:
-1


Actual output:
4


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

ans = 0
tmp = 0

for i in range(n):
    ans += 1
    if a[tmp] == 2:
        break;
    tmp = a[tmp] - 1
if ans == n:
    ans = -1

print(ans)
Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
lamp=[]
status=1
count=0
possible=0
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2:
  if lamp[status-1]!=0:
    status=lamp[status-1]
    lamp[status-1]=0
    count+=1
  else:
    possible+=1
    break
if possible==0:
  print(count)
else:
  print(-1)

Failing test case input:
3
3
0
2

Expected output:
2


Actual output:
-1


Fixed submission (verdict: Accepted):
n=int(input())
lamp=[]
status=1
count=0
possible=0
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2:
  if lamp[status-1]!=0:
    var=lamp[status-1]
    lamp[status-1]=0
    status=var
    count+=1
  else:
    possible+=1
    break
if possible==0:
  print(count)
else:
  print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections


n = int(input())
A = [int(input()) for i in range(n)]
flag = [False for i in range(n)]
flag[0] = True
cnt = 0
for i in range(n):
    if flag[i] == False:
        continue
    flag[A[i]-1] = True
    cnt += 1
    if flag[1] == True:
        break
if flag[1] == False:
    print(-1)
else:
    print(cnt)

Failing test case input:
4
4
1
2
3

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections


n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
p = 1
while True:
    p = A[p-1]
    cnt += 1
    if p == 2 or cnt > n:
        break
if p == 2:
    print(cnt)
else:
    print(-1)

Problem: p03680
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
l = list(int(input()) for _ in range(n))
num = 1
ans = -1

for i in range(n):
    num = l[num-1]
    if num == 2: 
        ans = i
        break
print(ans)

Failing test case input:
4
4
19
1
2

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
l = list(int(input()) for _ in range(n))
num = 1
ans = -1

for i in range(n):
    if num == 2: 
        ans = i
        break
    num = l[num-1]
print(ans)

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

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

if flag:
    print(count+1)
else:
    print(-1)


Failing test case input:
3
2
2
0

Expected output:
1


Actual output:
1
-1


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

if a[0] == 2:
    print(1)
else:
    count = 0
    i = a[0]
    flag = False
    for _ in range(n):
        count += 1
        if a[i-1] == 2:
            flag = True
            break
        i = a[i-1]
    if flag:
        print(count+1)
    else:
        print(-1)
Problem: p02663
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

h1 , m1 , h2 , m2 , k = map(int , input().split())
diff1 = (h1)*60 + m1
diff2 = h2*60 + m2
diff = diff1-diff2
ans = diff - k

if ans <=0:
	print(0)
else:
	print(ans)

Failing test case input:
-1 -9 83 14 0

Expected output:
5063


Actual output:
0


Fixed submission (verdict: Accepted):

h1 , m1 , h2 , m2 , k = map(int , input().split())
hr = h2-h1
m = m2-m1

diff = hr*60+m
ans = diff - k

if ans <=0:
	print(0)
else:
	print(ans)

Problem: p02663
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
h1, m1, h2, m2, k = map(int, input().split())

h = h2 - h1
m = m2 - m1

if m < 0:
  h = h - 1
  m = 60 - m
  
total = h + m

print(total - k)

Failing test case input:
-1 -5 68 11 -1

Expected output:
4157


Actual output:
86


Fixed submission (verdict: Accepted):
h1, m1, h2, m2, k = map(int, input().split())

h = (h2 - h1)*60
m = m2 - m1

if m < 0:
  h = h - 60
  m = 60 + m

total = h + m

print(total-k)

Problem: p02663
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
h1,m1,h2,m2,k=map(int,input().split())
h3=h2-h1
h3=h3*60+m1+m2

print(h3-k)

Failing test case input:
0 -11 722 6 0

Expected output:
43337


Actual output:
43315


Fixed submission (verdict: Accepted):
h1,m1,h2,m2,k=map(int,input().split())
h1=h1*60+m1
h2=h2*60+m2
h3=h2-h1

print(h3-k)

Problem: p02663
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
h1, m1,h2,m2,k = map(int,input().split())
if h2 * 60 + m2 >h1* 60 + m2:
    r = (h2 * 60 + m2)  -(h1* 60 + m2) - k
else:
    r = (h2 * 60 + m2) + 24 * 60 - (h1* 60 + m2)  - k
print(r)

Failing test case input:
10 -1 15 1 14

Expected output:
288


Actual output:
286


Fixed submission (verdict: Accepted):
h1, m1,h2,m2,k = map(int,input().split())
if h2 * 60 + m2 >h1* 60 + m1:
    r = (h2 * 60 + m2)  -(h1* 60 + m1) - k
else:
    r = (h2 * 60 + m2) + 24 * 60 - (h1* 60 + m1)  - k
print(r)

Problem: p02663
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
h1, m1, h2, m2, k = map(int, input().split())
t1 = h1 * 60 + m1
t2 = h2 * 60 + m1
print(t2-t1 - k)


Failing test case input:
1 -69 107 19 0

Expected output:
6448


Actual output:
6360


Fixed submission (verdict: Accepted):
h1, m1, h2, m2, k = map(int, input().split())
t1 = h1 * 60 + m1
t2 = h2 * 60 + m2

print(t2-t1 - k)

Problem: p02663
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    H1, M1, H2, M2, K = (int(i) for i in input().split())
    h = H2 - H1
    m = 0
    if M2 - M1 >= 0:
        m = M2 - M1
    elif H1 != H2:
        m = (60 - M2) + M1
    ans = h*60 + m - K
    if ans > 0:
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    main()


Failing test case input:
11 0 12 -1 43

Expected output:
16


Actual output:
78


Fixed submission (verdict: Accepted):
def main():
    H1, M1, H2, M2, K = (int(i) for i in input().split())
    h = H2 - H1
    m = M2 - M1
    ans = h*60 + m - K
    if ans > 0:
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    main()