TnT/CodeNet4Repair huggingface dataset:
Problem:
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:                 SelectionSort(A) 1 for i = 0 to A.length-1 2     mini = i 3     for j = i to A.length-1 4         if A[j] < A[mini] 5             mini = j 6     swap A[i] and A[mini]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.

Incorrect submission (verdict: Wrong Answer):
dummy = input()

s_list = list(map(int,input().split()))

print(s_list)

count = 0
for i in range(len(s_list)-1):

    min_i = i

    for j in range(i,len(s_list)):

        if s_list[j] < s_list[min_i]:
            min_i = j

    if s_list[i] != s_list[min_i]:
        count += 1
        min_num = s_list[min_i]

        s_list[min_i] = s_list[i]
        s_list[i]     = min_num

for i,row in enumerate(s_list):
    if i == 0:
        print(row,end='')
    else:
        print('',row,end='')
print()
print(count)

Fixed, accepted submission:
dummy = input()

s_list = list(map(int,input().split()))

#print(s_list)

count = 0
if len(s_list) == 1:
    for i,row in enumerate(s_list):
        if i == 0:
            print(row,end='')
        else:
            print('',row,end='')
    print()
    print(count)

else:
    for i in range(len(s_list)-1):

        min_i = i

        for j in range(i,len(s_list)):

            if s_list[j] < s_list[min_i]:
                min_i = j

        if s_list[i] != s_list[min_i]:
            count += 1
            min_num = s_list[min_i]

            s_list[min_i] = s_list[i]
            s_list[i]     = min_num

    for i,row in enumerate(s_list):
        if i == 0:
            print(row,end='')
        else:
            print('',row,end='')
    print()
    print(count)
Problem:
Snuke has N dogs and M monkeys. He wants them to line up in a row.  As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.  How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

Incorrect submission (verdict: Wrong Answer):
N,M=map(int,input().split())
MOD=10**9+7
if N>=M:
  s=1
  for i in range(2,N+1):
    s=s*i
  s=s%MOD
  t=N-M+2
  for j in range(N-M+3,N+1):
    t=t*j
  t=t%MOD
  print((s*t)%MOD)
else:
  s=1
  for i in range(2,M+1):
    s=s*i
  s=s%MOD
  t=M-N+2
  for j in range(N-M+3,N+1):
    t=t*j
  t=t%MOD
  print((s*t)%MOD)
  
  

Fixed, accepted submission:
N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=(s*i)%MOD
t=1
for i in range(2,M+1):
  t=(t*i)%MOD
if abs(N-M)>1:
  print(0)
  exit()
if abs(N-M)==1:
  print((s*t)%MOD)
else:
  print((2*s*t)%MOD)
Problem:
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.  Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.  Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.  Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.

Incorrect submission (verdict: Wrong Answer):
a = list(map(int,input().split()))
if a[1] <= a[2]:
  print("delicious")
elif (a[2] - a[1]) <= a[0]:
  print("safe")
else:
  print("dangerous")

Fixed, accepted submission:
a = list(map(int,input().split()))
if a[1] >= a[2]:
  print("delicious")
elif (a[2] - a[1]) <= a[0]:
  print("safe")
else:
  print("dangerous")
Problem:
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.  A column vector with m elements is represented by the following equation.  \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]  A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.  \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]  $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).  The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:  \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]

Incorrect submission (verdict: Wrong Answer):
n, m = map(int, input().split())
A = []
B = []
for line in range(n):
    A.append(list(map(int, input().split())))
for line in range(m):
    B.append(int(input()))
print(A,B)

ret = []
for i in range(n):
    ret.append(sum(A[i][j] * B[j] for j in range(m)))
print('\n'.join(map(str, ret)))

Fixed, accepted submission:
n, m = map(int, input().split())
A = []
B = []
for line in range(n):
    A.append(list(map(int, input().split())))
for line in range(m):
    B.append(int(input()))


ret = []
for i in range(n):
    ret.append(sum(A[i][j] * B[j] for j in range(m)))
print('\n'.join(map(str, ret)))
Problem:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.

Incorrect submission (verdict: Wrong Answer):
a, b = map(int, input().split())
if a * b % 2 == 1:
    print("odd")
else:
    print("even")

Fixed, accepted submission:
a, b = map(int, input().split())
if a * b % 2 == 1:
    print("Odd")
else:
    print("Even")
Problem:
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.  Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.  Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.

Incorrect submission (verdict: Wrong Answer):
A,B,C,D=map(int,input().split())

if A+B>C+D:
  print("Left")
if A+B==C+D:
  print("Balanced")
else:
  print("Right")

Fixed, accepted submission:
A,B,C,D=map(int,input().split())

if A+B>C+D:
  print("Left")
elif A+B==C+D:
  print("Balanced")
else:
  print("Right")
Problem:
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.  The problem has N test cases.  For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.  See the Output section for the output format.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
S = [0]*N
AC = int(0)
WA = int(0)
TLE = int(0)
RE = int(0)


for i in range(0,N):
  S[i] = input()
  if(S[i]=='AC'):
    AC += 1
  if(S[i]=='WA'):
    WA += 1
  if(S[i]=='TLE'):
    TLE += 1
  if(S[i]=='RE'):
    RE += 1
    
print('AC *', AC)
print('WA *', WA)
print('TLE *', TLE)
print('RE *', RE)

Fixed, accepted submission:
N = int(input())
S = [0]*N
AC = int(0)
WA = int(0)
TLE = int(0)
RE = int(0)


for i in range(0,N):
  S[i] = input()
  if(S[i]=='AC'):
    AC += 1
  if(S[i]=='WA'):
    WA += 1
  if(S[i]=='TLE'):
    TLE += 1
  if(S[i]=='RE'):
    RE += 1
    
print('AC x', AC)
print('WA x', WA)
print('TLE x', TLE)
print('RE x', RE)
Problem:
Snuke has N sticks. The length of the i-th stick is l_i.  Snuke is making a snake toy by joining K of the sticks together.  The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.

Incorrect submission (verdict: Wrong Answer):
N, K = map(int, input().split())
print(sorted(map(int, input().split()), reverse=True)[:K])

Fixed, accepted submission:
N, K = map(int, input().split())
print(sum(sorted(map(int, input().split()), reverse=True)[:K]))
Problem:
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Incorrect submission (verdict: Wrong Answer):
n,y = map(int,input().split())
ans = 0
c = 1
for i in range(y // 10000 + 1):
    for j in range(y // 5000 + 1):
        if n - i - j >= 0 and (y - 10000 * i - 5000 * j) % 1000 == 0:            
            if c != 0:
                print(i, j, (y- 10000 * i - 5000 * j)//1000)
                c = 0

Fixed, accepted submission:
n,y = map(int,input().split())
ans = 0
c = 1
for i in range(y // 10000 + 1,-1,-1):
    for j in range(y // 5000 + 1,-1,-1):
        if n - i - j >= 0 and y - 10000 * i - 5000 * j == 1000 * (n-i-j):            
            if c != 0:
                print(i, j, (y-10000*i-5000*j)//1000)
                c = 0
if c == 1:
    print('-1 -1 -1')
Problem:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.

Incorrect submission (verdict: Wrong Answer):
a, b = map(int, input().split())
if (a*b) %2==0:
  print("Odd")
else:
  print("Even")

Fixed, accepted submission:
a, b = map(int, input().split())
if (a*b) %2:
  print("Odd")
else:
  print("Even")
Problem:
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.

Incorrect submission (verdict: Wrong Answer):
['vowel','consonant'][not input() in ['a','e','i','o','u']]

Fixed, accepted submission:
let = input()

if let == 'a' or let == "i" or let == "u" or let == "e" or let == "o" :
    result = "vowel"
else:
    result = "consonant"
    
print(result)
Problem:
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.

Incorrect submission (verdict: Wrong Answer):
n,k = map(int,input().split())
l = n//2
if k <= l:
    print("YES")
else:
    print("NO")

Fixed, accepted submission:
n,k = map(int,input().split())
l = (n+1)//2
if n == 1: l = 1
if k <= l:
    print("YES")
else:
    print("NO")
Problem:
A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Incorrect submission (verdict: Wrong Answer):
Ss = input()
x,y = map(int, input().split())

direc = 0 
Ss = Ss + "T"
prev = Ss[0]
if prev == "F":
    cnt = 1
    direc = 0
else:
    cnt = 0
    direc = 1
mvs = []
for S in Ss[1:]:
    if prev == "F" and S == "F":
        cnt += 1
    elif prev == "F" and S == "T":
        mvs.append((direc, cnt))
        direc ^= 1
        cnt = 0
    elif prev == "T" and S == "F":
        cnt += 1
    else:
        direc ^= 1
    prev = S
print(mvs)
import copy
cs = set()
cs.add(0) 
for direc, dist in mvs:
    cs_tmp = copy.copy(cs)
    for c in cs_tmp:
        if direc == 0:
            cs.add(c+dist)
            cs.add(c-dist)
        else:
            cs.add(c+8000*dist)
            cs.add(c-8000*dist)
print(cs)
print(y*8000+x)
if y*8000+x in cs:
    print("Yes")
else:
    print("No")

Fixed, accepted submission:
from copy import copy
Ss = input() + "T"
X, Y = map(int, input().split())

d = [len(s) for s in Ss.split("T")]
x = d[0]

d_x = d[2::2]
d_y = d[1::2]

xs = set([x])
ys = set([0])
blx = [X in xs]
for d in d_x:
    
    xs_ = set()
    for x in xs:
        xs_.add(x+d)
        xs_.add(x-d)
    blx.append(X in xs_)
    xs = copy(xs_)

bly = []
for d in d_y:
    ys_ = set()
    for y in ys:
        ys_.add(y+d)
        ys_.add(y-d)
    bly.append(Y in ys_)
    ys = copy(ys_)

if blx[-1] and bly[-1]: print("Yes")
else: print("No")
Problem:
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.  Determine if we can visit all the towns by traversing each of the roads exactly once.

Incorrect submission (verdict: Wrong Answer):
a=[0 for i in range(3)]
b=[0 for i in range(3)]

for i in range(3):
    a[i],b[i] = map(int,input().split())

    
a=(set(a))
b=(set(b))



if len(a)==3 and len(b)==3:
    print("YES")
else:
    print("NO")
    

Fixed, accepted submission:
a=""

for i in range(3):
    a+=(str(input()))

error=0
for i in range(4):
    if a.count(str(i+1))>2:
        error=1
    

    
    
if error==0:
    print("YES")
else:
    print("NO")
Problem:
Write a program which calculates the area and perimeter of a given rectangle.

Incorrect submission (verdict: Wrong Answer):
a_b=input().split()
print(int(a_b[0])*int(a_b[1]))


Fixed, accepted submission:
a_b=input().split()
a=int(a_b[0])
b=int(a_b[1])
print(str(a*b)+" "+str((a+b)*2))
Problem:
Takahashi loves numbers divisible by 2.  You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.  Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.  For example,    * 6 can be divided by 2 once: 6 -> 3.   * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.   * 3 can be divided by 2 zero times.

Incorrect submission (verdict: Wrong Answer):
s = input()
print(s[0] + str(len(s[1:-1])) + s[-1])

Fixed, accepted submission:
n = int(input())

for i in range(1,10):
    if 2**i == n:
        print(2**i)
        exit()
    if 2**i > n:
        print(2**(i-1))
        exit()
Problem:
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
k=[2]
mod=10**9+7
for i in range(2,n+1):
    for j in range(len(k)):
        if i%k[j]==0:
            break
    else:
        k.append(i)
h=[1 for i in range(len(k))]
print(k)
for i in range(2,n+1):
    c=0
    while i!=1:
        if i%k[c]==0:
            i=i/k[c]
            h[c]+=1
        else:
            c+=1
p=1
print(h)
for i in range(len(k)):
    p=(p*h[i])%mod
print(p)

Fixed, accepted submission:
n=int(input())
k=[2]
mod=10**9+7
for i in range(2,n+1):
    for j in range(len(k)):
        if i%k[j]==0:
            break
    else:
        k.append(i)
h=[1 for i in range(len(k))]
for i in range(2,n+1):
    c=0
    while i!=1:
        if i%k[c]==0:
            i=i/k[c]
            h[c]+=1
        else:
            c+=1
p=1
for i in range(len(k)):
    p=(p*h[i])%mod
print(p)
Problem:
Ringo is giving a present to Snuke.  Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things.  You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.

Incorrect submission (verdict: Wrong Answer):
s=list(input())
if len(s)>=4 and s[0:5]==list('YAKI'):
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
s=list(input())
if len(s)>=4 and s[0:4]==list('YAKI'):
    print('Yes')
else:
    print('No')
Problem:
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all.  There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.  Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before.  Compute the minimum number of days on which the same type of cake as the previous day will be eaten.

Incorrect submission (verdict: Wrong Answer):
a = list(map(int, input().split()))
largest = a[0]
total = 0

for ai in a:
    total += ai

    if ai > largest:
        largest = ai

print(max(largest-(total-largest+1), 0))

Fixed, accepted submission:
k, t = list(map(int, input().split()))
a = list(map(int, input().split()))

largest = max(a)
print(max(largest-(k-largest+1), 0))
Problem:
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Incorrect submission (verdict: Wrong Answer):
N,Y = map(int,input().split())

Y /= 1000

if Y // 10 + (Y % 10) // 5 + (Y % 10) % 5 > N:
  print(-1,-1,-1)
  
elif Y // 10 + (Y % 10) // 5 + (Y % 10) % 5 == N:
  print(Y // 10 , (Y % 10) // 5 , (Y % 10) % 5)

Fixed, accepted submission:
N,Y = map(int,input().split())

Y /= 1000

x=int(Y//10)
y= int((Y % 10) // 5)
z=int((Y % 10) % 5)

flag = False

if x+y+z > N:
  print(-1,-1,-1)
  
elif x + y + z == N:
  print(x , y , z)
  
else:
  for i in range (N):
    for j in range(N-i):
      if 10*i+5*j+(N-i-j)==Y:
        print(i,j,N-i-j)
        flag=True
        break
    if flag:
      break
  if flag==False:
    print(-1,-1,-1)
Problem:
Snuke loves working out. He is now exercising N times.  Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i.  Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
x=0
for i in range(n):
    x=x*(n+1)%1000000007
print(x)


Fixed, accepted submission:
n=int(input())
x=1
for i in range(n):
    x=x*(i+1)%1000000007
print(x)
Problem:
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`.  You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.

Incorrect submission (verdict: Wrong Answer):
A, B = list(map(int, input().split()))
S = input()
a = S[0:A]
x = S[A]
b = S[A + 1:]
print(a, x, b)
if list(a).count("-") == 0 and x == "-" and list(b).count("-") == 0:
	print("Yes")
else:
	print("No")

Fixed, accepted submission:
A, B = list(map(int, input().split()))
S = input()
a = S[0:A]
x = S[A]
b = S[A + 1:]
if list(a).count("-") == 0 and x == "-" and list(b).count("-") == 0:
	print("Yes")
else:
	print("No")
Problem:
Write a program which reads three integers, and prints them in ascending order.

Incorrect submission (verdict: Wrong Answer):
a,b,c = map(int,input().split())

numbers = [a,b,c]
numbers.sort()
print(numbers)

Fixed, accepted submission:
a,b,c = map(int,input().split())

numbers = [a,b,c]
numbers.sort()
print(str(numbers[0]) + " " + str(numbers[1]) + " " + str(numbers[2]))
Problem:
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.

Incorrect submission (verdict: Wrong Answer):
s=list(input())
ans=''
if len(s)==2:
    print(','.join(s))
else:
    tmp=s[0]
    s[0]=s[2]
    s[2]=tmp
    print(','.join(s))

Fixed, accepted submission:
s=list(input())
ans=''
if len(s)==2:
    print(''.join(s))
else:
    tmp=s[0]
    s[0]=s[2]
    s[2]=tmp
    print(''.join(s))
Problem:
Joisino is working as a receptionist at a theater.  The theater has 100000 seats, numbered from 1 to 100000.  According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).  How many people are sitting at the theater now?

Incorrect submission (verdict: Wrong Answer):
n = int(input())
ans = 0
for i in range(n):
  a,b = map(int,input().split())
  ans += b-a-1
  
print(ans)  

Fixed, accepted submission:
n = int(input())
ans = 0
for i in range(n):
  a,b = map(int,input().split())
  ans += b-a+1
  
print(ans)
Problem:
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?

Incorrect submission (verdict: Wrong Answer):
a = int(input())
print(a//2+0**(a%2))

Fixed, accepted submission:
a = int(input())
print(a//2-0**(a%2))
Problem:
Snuke is giving cookies to his three goats.  He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).  Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.

Incorrect submission (verdict: Wrong Answer):
def sunuke(A, B):
    re = 0
    if A % 3 == 0:    
        re = 1
    if B % 3 == 0:
        re = 1
    if (A+B) % 3 == 0:
        re = 1
        
    if re ==1:
        return "Possible"
    else:
        return "Impossible"

Fixed, accepted submission:
Imp = list(map(int, input().split()))
A = Imp[0]
B = Imp[1]
re = 0
if A % 3 == 0:    
    re = 1
if B % 3 == 0:
    re = 1
if (A+B) % 3 == 0:
        re = 1
        
if re ==1:
    print("Possible")
else:
    print("Impossible")
Problem:
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.  The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.  Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.  Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
check = 0
count = 0
botton = 1
print(A[1 -1])
for i in range(N):
    count += 1
    if A[botton - 1] == 2:
        check = 1
        break
    botton = A[botton - 1]

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

Fixed, accepted submission:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
check = 0
count = 0
botton = 1
for i in range(N):
    count += 1
    if A[botton - 1] == 2:
        check = 1
        break
    botton = A[botton - 1]

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