Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lists = list(map(int, input().split()))

count = 0
for i in range(N):
    lists_slice = lists[:i+1]
    lists_min = min(lists_slice)
    if lists_min >= lists[i]:
        count+=1

    # cnt = 0
    # for j in lists_slice:
    #     if lists_slice[i] <= j:
    #         cnt += 1
    # if cnt == i+1:
    #     count+= 1
print(count)

Fixed submission:
N = int(input())
lists = list(map(int, input().split()))

count = 0
ans = 0
for i in range(N):
    if i == 0:
        ans = lists[i]
        count += 1
    else:
        if ans >= lists[i]:
            count += 1
            ans = min(ans, lists[i])
        else:
            ans = min(ans, lists[i])


    # lists_slice = lists[:i+1]
    # lists_min = min(lists_slice)
    # if lists_min >= lists[i]:
    #     count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lists = list(map(int, input().split()))

count = 0
for i in range(N):
    lists_slice = lists[:i+1]
    cnt = 0
    for j in lists_slice:
        if lists_slice[i] <= j:
            cnt += 1
    if cnt == i+1:
        count+= 1
print(count)

Fixed submission:
N = int(input())
lists = list(map(int, input().split()))

count = 0
ans = 0
for i in range(N):
    if i == 0:
        ans = lists[i]
        count += 1
    else:
        if ans >= lists[i]:
            count += 1
            ans = min(ans, lists[i])
        else:
            ans = min(ans, lists[i])


    # lists_slice = lists[:i+1]
    # lists_min = min(lists_slice)
    # if lists_min >= lists[i]:
    #     count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lists = list(map(int, input().split()))

count = 0

for i in range(1, N+1):
    # print("i", i)
    cnt = 0
    for j in range(1, i+1):
        # print(i)
        # print(j)
        if lists[i-1] <= lists[j-1]:
            # print("II", i)
            cnt += 1
        else:
            continue
    if cnt == i:
        count += 1

print(count)

Fixed submission:
N = int(input())
lists = list(map(int, input().split()))

count = 0
ans = 0
for i in range(N):
    if i == 0:
        ans = lists[i]
        count += 1
    else:
        if ans >= lists[i]:
            count += 1
            ans = min(ans, lists[i])
        else:
            ans = min(ans, lists[i])


    # lists_slice = lists[:i+1]
    # lists_min = min(lists_slice)
    # if lists_min >= lists[i]:
    #     count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
from math import gcd
A, B = map(int, input().split())

def lcm(x, y):
    return x // gcd(x, y) * y

print(lcm(A, B))

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

print(A * B // gcd(A, B))

Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())

def lcm(x, y):
    return x // math.gcd(x, y) * y

print(lcm(A, B))

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

print(A * B // gcd(A, B))

Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())

def lcm(x, y):
    return x // math.gcd(x, y) * y

print(lcm(A, B))

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

print(A * B // gcd(A, B))

Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())

def lcm(x, y):
    return x // math.gcd(x, y)* y

print(lcm(A, B))

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

print(A * B // gcd(A, B))

Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())

def lcm(x, y):
    return x * y // math.gcd(x, y)

print(lcm(A, B))

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

print(A * B // gcd(A, B))

Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())

def lcm(x, y):
    return x * y // math.gcd(x, y)

print(lcm(A, B))

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

print(A * B // gcd(A, B))
Buggy python submission (verdict: Runtime Error):
a = input()
S = list(a)
S_low = list(a.lower())

count = 0
if S[0] == "A":
    count += 1

vaa = 0
for j in range(2, len(S)-1):
    # print(j)
    if S[j] == "C":
        vaa += 1
        num = j
        # print(j)
if vaa == 1:
    count += 1

val = 0
for i in range(len(S)):
    for j in range(len(S)):
        if j == 0 or j == num:
            continue
        else:
            if S[i] == S[j]:
                val += 1
            else:
                continue
if val == len(S)-2:
    count +=1

if count == 3:
    print("AC")
else:
    print("WA")

Fixed submission:
a = input()
S = list(a)

count = 0
if S[0] == "A":
    count += 1
    # print("OK")

vaa = 0
num=[0]
for j in range(2, len(S)-1):
    # print(j)
    if S[j] == "C":
        vaa += 1
        num.append(j)

if vaa == 1:
    count += 1
    # print("OK")

# val = 0
# for i in range(len(S)):
#     for j in range(len(S)):
#         if j == 0 or j == num:
#             print(j)
#             continue
#         else:
#             if S[i] == S_low[j]:
#                 print(S[i])
#                 print(S[j])
#                 val += 1
#             else:
#                 continue
# print("val", val)
# if val == len(S)-2:
#     count +=1
# print(num)
num = reversed(num)
S_pop = [S.pop(i) for i in num]
S_low = [i.lower() for i in S]

# print("S", S)
# print("S_low", S_low)

if S == S_low:
    count += 1

if count == 3:
    print("AC")
else:
    print("WA")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
S = []
cnt = []
for i in range(N):
    S.append(input())
    S[i] = list(S[i])
    cnt.append(Counter(S[i]))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if cnt[i] == cnt[j]:
            ans += 1

print(ans)
#print("cnt = {}".format(cnt))

Fixed submission:
from collections import Counter
from math import factorial
N = int(input())
S = []
for i in range(N):
    tmp = input()
    tmp = sorted(list(tmp))
    S.append("".join(tmp))

cnt = Counter(S)
ans = 0
for i in cnt:
    if cnt[i] > 1:
        ans += factorial(cnt[i]) // (factorial(cnt[i] - 2) * factorial(2))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for i in range(N):
    S.append(input())
    S[i] = list(S[i])
    S[i].sort()
    S[i] = "".join(S[i])

ans = 0

for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter
from math import factorial
N = int(input())
S = []
for i in range(N):
    tmp = input()
    tmp = sorted(list(tmp))
    S.append("".join(tmp))

cnt = Counter(S)
ans = 0
for i in cnt:
    if cnt[i] > 1:
        ans += factorial(cnt[i]) // (factorial(cnt[i] - 2) * factorial(2))

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
s = {"A", "T", "C", "G"}
low = []
for i in range(len(S)):
    if S[i] in s:
        low.append(i)
high = []
for i in reversed(range(len(S))):
    if S[i] in s:
        high.append(i)

ans = []
for i in low:
    for j in high:
        if (set(S[i:j+1]) - s) == set():
            ans.append(len(S[i:j+1]))

print(max(ans))

Fixed submission:
S = input()
N = len(S)
s = {"A", "T", "C", "G"}

ans = 0
for i in range(N):
    for j in range(i, N):
        if all([c in s for c in S[i:j+1]]):
            ans = max(ans, j-i+1)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int, input().split()))
k = [0] * 100000
g = [0] * 100000

num = 1
for i in v:
    if num % 2 == 1:
        k[i] += 1
    else:
        g[i] += 1
    num += 1

max_k = max(k)
max_g = max(g)
print(n - (max_k+max_g))

Fixed submission:
from collections import Counter as C
n = int(input())
v = list(map(int, input().split()))

#偶数番と奇数番の同じ数字の数
evens = C(v[::2]).most_common()
odds = C(v[1::2]).most_common()
#[('数字', 出現数), ('数字', 出現数)...]

#偶数番と奇数番の数字が違うならそのままans
if evens[0][0] != odds[0][0]:
    ans = n - (evens[0][1] + odds[0][1])
#同じ時は各[0][1]と[1][1]の合計を比べて
# 出現数が多いほうがans
else:
    #oddsの長さが1より大きければ
    # rにevensの1番目の出現数とoddsの2番目の出現数の和を代入
    #  そうでなければevensの1番目の出現数を代入（oddsを全換えするため）
    r = evens[0][1] + odds[1][1] if len(odds) > 1 else evens[0][1]
    s = evens[1][1] + odds[0][1] if len(evens) > 1 else odds[0][1]
    if r > s:
        ans = n - r
    else:
        ans = n - s

print(ans)

Buggy python submission (verdict: Runtime Error):
# coding:utf-8
n = int(input())
v = list(map(int, input().split()))
k = [0] * 100000
g = [0] * 100000

num = 1
for i in v:
    if num % 2 == 1:
        k[i] += 1
    else:
        g[i] += 1
    num += 1

max_k = max(k)
max_g = max(g)
print(n - (max_k+max_g))

Fixed submission:
from collections import Counter as C
n = int(input())
v = list(map(int, input().split()))

#偶数番と奇数番の同じ数字の数
evens = C(v[::2]).most_common()
odds = C(v[1::2]).most_common()
#[('数字', 出現数), ('数字', 出現数)...]

#偶数番と奇数番の数字が違うならそのままans
if evens[0][0] != odds[0][0]:
    ans = n - (evens[0][1] + odds[0][1])
#同じ時は各[0][1]と[1][1]の合計を比べて
# 出現数が多いほうがans
else:
    #oddsの長さが1より大きければ
    # rにevensの1番目の出現数とoddsの2番目の出現数の和を代入
    #  そうでなければevensの1番目の出現数を代入（oddsを全換えするため）
    r = evens[0][1] + odds[1][1] if len(odds) > 1 else evens[0][1]
    s = evens[1][1] + odds[0][1] if len(evens) > 1 else odds[0][1]
    if r > s:
        ans = n - r
    else:
        ans = n - s

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, x = [int(x) for x in input().split()]

if a + b <= x:
    input('YES')
else:
    input('NO')

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

if a > x:
    print('NO')
elif a + b < x:
    print('NO')
else:
    print('YES')

Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())

if a + b <= x:
    input('YES')
else:
    input('NO')

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

if a > x:
    print('NO')
elif a + b < x:
    print('NO')
else:
    print('YES')

Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())

if a <= x:
    input('YES')
else:
    input('NO')

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

if a > x:
    print('NO')
elif a + b < x:
    print('NO')
else:
    print('YES')
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = [int(input()) for _ in range(n)]
ans = 1

from math import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

for v in t:
    ans = lcm(ans, v)

print(ans)

Fixed submission:
n = int(input())
t = [int(input()) for _ in range(n)]
ans = 1

from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

for v in t:
    ans = lcm(ans, v)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce
n = int(input())
c = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            c += gcd(i,j,k)

print(c)


Fixed submission:
import math
import statistics
n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        c = math.gcd(i,j)
        for k in range(1,n+1):
            ans += math.gcd(c,k)

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = n - k
if k == 1 or n == 1:
    print(1)
    quit()
if n % k == 0:
    print(0)
    quit()
if n < k:
    print(n)
    quit()

print(min(ans, k - n%k))


Fixed submission:
x, y, z = map(int, input().split())
print("{} {} {}".format(z,x,y))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = n - k
if k == 1 or n == 1:
    print(1)
    quit()
if n % k == 0:
    print(0)
    quit()
if n < k:
    print(n)
    quit()

print(min(ans, k - n%k))


Fixed submission:
x, y, z = map(int, input().split())
print("{} {} {}".format(z,x,y))
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())

for i in range(1, 1001):
    if int(i * 0.08) == a and int(i * 0.1) == b:
        print(i)
        exit()
print(-1)


Fixed submission:
s = input()

if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, b, r = map(int, input().split())
x = []
bool = True
while bool:
    for i in range(b):
        if len(x) == n:
            bool = False
        else:
            x.append("b")
    for j in range(r):
        if len(x) == n:
            bool = False
        else:
            x.append("r")

print(x.count("b"))


Fixed submission:
n, b, r = map(int, input().split())
b1 = n//(b+r)
b2 = n % (b+r)
if b == 0:
    print(0)
elif r == 0:
    print(n)
elif b2 != 0 and b2 <= b:
    b1 = b1*b + b2
    print(b1)
elif b2 != 0 and b2 > b:
    b1 = b1*b + b
    print(b1)
elif n % (b+r) == 0:
    print(b1*b)
Buggy python submission (verdict: Runtime Error):
def main():

    n = int(input())
    num = [int(i) for i in input().split()]
    if len(num) <= 1:
        return "YES"
    else:
        for i in range(len(num+1)):
            if num[i] == num[i + 1]:
                return "YES"
            else:
                return "NO"
print(main())


Fixed submission:

n = int(input())
num = [int(i) for i in input().split()]
if len(num) != len(set(num)):
    print("NO")
else:
    print("YES")
Buggy python submission (verdict: Runtime Error):
def main():
    n, k = [int(i) for i in input().split()]
    num = [int(i) for  i in input().split()]
    if k >= n:
        return 0
    else:
        num = sorted(num)
        return sum(num[0:n-k])
print(main())


Fixed submission:
def main():
    num = [int(i) for i in input().split()]
    h = num[0]
    a = num[1]
    return attack(h, a)

def attack(h,a):
    if h % a == 0:
        return h // a
    elif h % a >= 1:
        return (h//a) + 1

print(main())

Buggy python submission (verdict: Runtime Error):
def main():
    n, k = [int(i) for i in input().split()]
    num = [int(i) for  i in input().split()]
    if k >= n:
        return 0
    else:
        l = sorted(num)
        return sum(l[0:n-k])
print(main())


Fixed submission:
def main():
    num = [int(i) for i in input().split()]
    h = num[0]
    a = num[1]
    return attack(h, a)

def attack(h,a):
    if h % a == 0:
        return h // a
    elif h % a >= 1:
        return (h//a) + 1

print(main())

Buggy python submission (verdict: Runtime Error):
def main():
    n, k = [int(i) for i in input().split()]
    num = [int(i) for  i in input().split()]
    if k >= n:
        return 0
    else:
        l = sorted(num)
        return sum(l[:-k])
print(main())


Fixed submission:
def main():
    num = [int(i) for i in input().split()]
    h = num[0]
    a = num[1]
    return attack(h, a)

def attack(h,a):
    if h % a == 0:
        return h // a
    elif h % a >= 1:
        return (h//a) + 1

print(main())

Buggy python submission (verdict: Runtime Error):
def main():
    n, k = [int(i) for i in input().split()]
    num = [int(i) for  i in input().split()]
    sorted(num)
    del num[-k:]
    print(sum(num))
main()


Fixed submission:
def main():
    num = [int(i) for i in input().split()]
    h = num[0]
    a = num[1]
    return attack(h, a)

def attack(h,a):
    if h % a == 0:
        return h // a
    elif h % a >= 1:
        return (h//a) + 1

print(main())
Buggy python submission (verdict: Runtime Error):
from sympy import sieve
x = int(input())
s = [i for i in sieve.primerange(2,100004) if i >= x]
print(s[0])


Fixed submission:
import math
x = int(input())
def prime_get():
    if x <= 1:
        return []
    prime = [2]
    limit = int(math.sqrt(x))
    data = [i+1 for i in range(2,100004,2)]

    while limit >= data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime+data

ans = prime_get()
ans = [i for i in ans if i >= x]
print(ans[0])
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = sorted(list(map(int, input().split())))

ans = (v[0]+v[1])/2
for i in range(2,n):
    ans = (a+v[i])/2
print(ans)


Fixed submission:
n = int(input())
v = sorted(list(map(int, input().split())))

while len(v) > 1:
    new_v = (v[0]+v[1]) / 2
    del v[0:2]
    v = [new_v]+v

print(v[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
for i in range(n):

    if max(a) > a[i]:
        print(max(a))
    else:
        if a.count(a[i]) > 1:
            print(a[i])
        else:
            print(b[-2])


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
max_a = max(a)
max_cnt = a.count(max_a)
for i in range(n):

    if max_a > a[i]:
        print(max_a)
    else:
        if max_cnt > 1:
            print(a[i])
        else:
            print(b[-2])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
for i in range(n):
    if max(a) > a[i]:
        print(max(a))
    else:
        if a.count(a[i]) > 1:
            print(a[i])
        else:
            print(b[-2])


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
max_a = max(a)
max_cnt = a.count(max_a)
for i in range(n):

    if max_a > a[i]:
        print(max_a)
    else:
        if max_cnt > 1:
            print(a[i])
        else:
            print(b[-2])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    if max(a) > a[i]:
        print(max(a))
    else:
        if a.count(a[i]) > 1:
            print(a[i])
        else:
            print(sorted(a)[-2])


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
max_a = max(a)
max_cnt = a.count(max_a)
for i in range(n):

    if max_a > a[i]:
        print(max_a)
    else:
        if max_cnt > 1:
            print(a[i])
        else:
            print(b[-2])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    num = a.pop(i)
    print(max(a))
    a = [num]+a


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
max_a = max(a)
max_cnt = a.count(max_a)
for i in range(n):

    if max_a > a[i]:
        print(max_a)
    else:
        if max_cnt > 1:
            print(a[i])
        else:
            print(b[-2])
Buggy python submission (verdict: Runtime Error):
s = input()
ans = 0
ans_l = []

if len(s) == 1:
    print(1)
    quit()
for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans += 1
    else:
        ans_l.append(ans)
        ans = 0
print(max(ans_l))


Fixed submission:
s = input()
ans = 0
ans_l = [0]*len(s)


for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans_l[ans] += 1
    else:
        ans += 1
print(max(ans_l))

Buggy python submission (verdict: Runtime Error):
s = input()
ans = 0
ans_l = []
if "A" or "C" or "G" or "T" in s:
    if len(s) == 1:
        print(1)
        quit()
    for i in range(len(s)):
        if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
            ans += 1
        else:
            ans_l.append(ans)
            ans = 0
else:
    print(0)
    quit()
print(max(ans_l))


Fixed submission:
s = input()
ans = 0
ans_l = [0]*len(s)


for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans_l[ans] += 1
    else:
        ans += 1
print(max(ans_l))

Buggy python submission (verdict: Runtime Error):
s = input()
ans = 0
ans_l = []
if "A" or "C" or "G" or "T" in s:
    for i in range(len(s)):
        if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
            ans += 1
        else:
            ans_l.append(ans)
            ans = 0
else:
    print(0)
    quit()
print(max(ans_l))


Fixed submission:
s = input()
ans = 0
ans_l = [0]*len(s)


for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans_l[ans] += 1
    else:
        ans += 1
print(max(ans_l))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
for i in range(len(s)):
    if "BW" in s:
        s_index = s.index("BW")
        s = list(s)
        s[s_index], s[s_index+1] = s[s_index+1], s[s_index]
        s = "".join(s)
        ans += 1
print(ans)


Fixed submission:
s = input()
b_idx = list(reversed([i for i, x in enumerate(s) if x == "B"]))
ans = 0
for i in range(len(b_idx)):
    ans += (len(s)-(i+1)) - b_idx[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int, input().split())
cheak = 10**18
if a == b == c:
    print(0)
    quit()
while k > 0:
    a_new = b+c
    b_new = a+c
    c_new = a+b

    a = a_new
    b = b_new
    c = c_new

    k -= 1
ans = a-b
if ans > cheak:
    print("Unfair")
else:
    print(ans)


Fixed submission:
a,b,c,k = map(int, input().split())
cheak = 10**18
key = a-b
def calc(a,b,c,k):
    if a == b:
        return 0
    elif key < 0:
        if k % 2 == 1:
            return -key
        else:
            return key
    else:
        if k % 2 == 1:
            return -key
        else:
            return key
ans = calc(a,b,c,k)
if ans > cheak:
    print("Unfair")
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int, input().split())
cheak = 10**18
if a == b == c:
    print(0)
    quit()
while k > 0:
    a_new = b+c
    b_new = a+c
    c_new = a+b

    a = a_new
    b = b_new
    c = c_new

    k -= 1
ans = a-b
if ans > cheak:
    print("Unfair")
else:
    print(ans)


Fixed submission:
a,b,c,k = map(int, input().split())
cheak = 10**18
key = a-b
def calc(a,b,c,k):
    if a == b:
        return 0
    elif key < 0:
        if k % 2 == 1:
            return -key
        else:
            return key
    else:
        if k % 2 == 1:
            return -key
        else:
            return key
ans = calc(a,b,c,k)
if ans > cheak:
    print("Unfair")
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input() for i in range(n)]

ans = 0
i = 0
while n > 0:
    ans += 1
    if a[i] == 2:
        print(ans)
        quit()
    else:
        i = a[i]-1
    n -= 1
print(-1)


Fixed submission:
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
a = [e for row in a for e in row]
ans = 0
i = 0
while n > 0:
    ans += 1
    if a[i] == 2:
        print(ans)
        quit()
    else:
        i = a[i]-1
    n -= 1
print(-1)
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
b_cnt = 0
a_cnt = 0
for i in range(n):
    if s[i] == "a" and (a_cnt+b_cnt) < a+b:
        a_cnt += 1
        print("Yes")
    elif s[i] == "b" and (a_cnt+b_cnt) < a+b and b_cnt < b:
        b_cnt += 1
        print("Yes")
    else:
        print("No")


Fixed submission:
n, a, b = map(int, input().split())
s = input()

total_cnt = 0
b_cnt = 0
ans = ["No"]*n

for i in range(n):
    if total_cnt >= a+b:
        break
    if s[i] == "c":
        continue
    if s[i] == "a":
        total_cnt += 1
        ans[i] = "Yes"
    if s[i] == "b":
        b_cnt += 1
        if b_cnt <= b:
            total_cnt += 1
            ans[i] = "Yes"

for i in range(n):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
print(len(s))
b_cnt = 0
a_cnt = 0
for i in range(n):
    if s[i] == "a" and (a_cnt+b_cnt) < a+b:
        a_cnt += 1
        print("Yes")
    elif s[i] == "b" and (a_cnt+b_cnt) < a+b and b_cnt < b:
        b_cnt += 1
        print("Yes")
    else:
        print("No")


Fixed submission:
n, a, b = map(int, input().split())
s = input()

total_cnt = 0
b_cnt = 0
ans = ["No"]*n

for i in range(n):
    if total_cnt >= a+b:
        break
    if s[i] == "c":
        continue
    if s[i] == "a":
        total_cnt += 1
        ans[i] = "Yes"
    if s[i] == "b":
        b_cnt += 1
        if b_cnt <= b:
            total_cnt += 1
            ans[i] = "Yes"

for i in range(n):
    print(ans[i])