Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
X, N = list(map(lambda n : int(n), input().split(" ")))
P = list(map(lambda p : int(p), input().split(" ")))
Q = list(map(lambda p : [p, abs(X-p)], P))
Q.sort(key=lambda q: (q[1], q[0]))

cand = []
for i in range(N):
  if i == 0 and Q[0][1] != 0:
    cand.append(X)
    break
  else:
    if Q[i][1] != math.ceil(i/2):
      cand.append(X + math.ceil(i/2))
      cand.append(X - math.ceil(i/2))
      break
if len(cand) == 0:
  if N % 2 == 0:
    cand.append(X + int(N/2))
    cand.append(X - int(N/2))
  else:
    cand.append(X + int((N+1)/2))
    cand.append(X - int((N+1)/2))

print(min(list(filter(lambda c: c not in P, cand))))
    

Fixed submission:
import math
X, N = list(map(lambda n : int(n), input().split(" ")))
if N == 0:
  print(X)
else:
  P = list(map(lambda p : int(p), input().split(" ")))
  Q = list(map(lambda p : [p, abs(X-p)], P))
  Q.sort(key=lambda q: (q[1], q[0]))

  cand = []
  for i in range(N):
    if i == 0 and Q[0][1] != 0:
      cand.append(X)
      break
    else:
      if Q[i][1] != math.ceil(i/2):
        cand.append(X + math.ceil(i/2))
        cand.append(X - math.ceil(i/2))
        break
  if len(cand) == 0:
    if N % 2 == 0:
      cand.append(X + int(N/2))
      cand.append(X - int(N/2))
    else:
      cand.append(X + int((N+1)/2))
      cand.append(X - int((N+1)/2))

  print(min(list(filter(lambda c: c not in P, cand))))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(lambda a : int(a), input().split(" ")))
ans = 1
for i in range(len(A)):
  ans *= A[i]
 
print(ans) if ans <= 10 ** 18 else print("-1")

Fixed submission:
N = int(input())
A = list(map(lambda a : int(a), input().split(" ")))
ans = 1
if A.count(0) > 0:
  ans = 0

for i in range(len(A)):
  ans *= A[i]
  if ans > 10 ** 18:
    ans = -1
    print("-1")
    break
 
if ans != -1:
  print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(lambda a : int(a), input().split(" ")))
ans = 1
print i in range(len(A)):
  ans *= A[i]

print(ans) if ans <= 10 ** 18 else print("-1")

Fixed submission:
N = int(input())
A = list(map(lambda a : int(a), input().split(" ")))
ans = 1
if A.count(0) > 0:
  ans = 0

for i in range(len(A)):
  ans *= A[i]
  if ans > 10 ** 18:
    ans = -1
    print("-1")
    break
 
if ans != -1:
  print(ans)
Buggy python submission (verdict: Runtime Error):
tmp = input().split("\n")
S = tmp[0]
T = tmp[1]

if T.startwith(S) and len(T) + len(S) == 1:
  print("Yes")
else:
  print("No")

Fixed submission:
S = input()
T = input()

if T.startswith(S) and len(T) == len(S) + 1:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N, K = int(input())

while N <= int(K/2):
  N = min([abs(N-K), N % K])

print(N)

Fixed submission:
N, K = list(map(lambda n: int(n), input().split(" ")))
 
while N > int(K/2):
  N = min([abs(N-K), N % K])

print(N)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	S = list(input())
	reverse = False
	n_q = int(input())
	for i in range(n_q):
		q = input().split(" ")
		if q[0] == "1":
			reverse = not reverse
		elif q[0] == "2":
			f = q[1]
			c = q[2]
			if (f == "1" and not reverse) or (f == "2" and reverse):
				S.insert(0, c)
			elif (f == "1" and reverse) or (f == "2" and not reverse):
				S.append(c)
	if reverse:
		S.reverse()
	print("".join(S))

main()

Fixed submission:
def main():
	S = list(input())
	T = []
	reverse = False
	n_q = int(input())
	for i in range(n_q):
		q = input().split(" ")
		if q[0] == "1":
			reverse = not reverse
		elif q[0] == "2":
			f = q[1]
			c = q[2]
			if (f == "1" and not reverse) or (f == "2" and reverse):
				T.append(c)
			elif (f == "1" and reverse) or (f == "2" and not reverse):
				S.append(c)
	if reverse:
		S.reverse()
		ans = S + T
	elif not reverse:
		T.reverse()
		ans = T + S
	print("".join(ans))

main()
Buggy python submission (verdict: Runtime Error):
str = input().split(" ")
S = str[0]
T = str[1]
num = input().split(" ")
NS = int(num[0])
NT = int(num[1])
U = input()

if S == U:
  print(str(NS - 1) + " " + str(NT))
else:
  print(str(NS) + " " + str(NT - 1))

Fixed submission:
str = input().split(" ")
S = str[0]
T = str[1]
num = input().split(" ")
NS = int(num[0])
NT = int(num[1])
U = input()

if S == U:
  print(NS - 1, end=" ")
  print(NT)
else:
  print(NS, end=" ")
  print(NT - 1)
Buggy python submission (verdict: Runtime Error):
tmp = input().split(" ")

HP = int(tmp[0])
attack = int(tmp[1])

print(math.ceil(HP/attack))

Fixed submission:
import math
tmp = input().split(" ")
 
HP = int(tmp[0])
attack = int(tmp[1])
 
print(math.ceil(HP/attack))
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(lambda p : int(p), input().split(" ")))
left_min = P[0]
cnt = 0
for i in range(P):
  if left_min >= P[i]:
    cnt += 1
    left_min = P[i]
print(cnt)

Fixed submission:
N = int(input())
P = list(map(lambda p : int(p), input().split(" ")))
left_min = P[0]
cnt = 0
for i in range(len(P)):
  if left_min >= P[i]:
    cnt += 1
    left_min = P[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
C = input()

ary = "abcdefghijklmnopqrstuvwxyz".split("")

print(ary[ary.index(C) + 1])

Fixed submission:
C = input()
 
ary = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(",")
 
print(ary[ary.index(C) + 1])
Buggy python submission (verdict: Runtime Error):
tmp = input()

N = int(tmp[0])
X = int(tmp[1])

if X <= 500 * N:
  print("Yes")
else:
  print("No")

Fixed submission:
tmp = input().split(" ")
 
N = int(tmp[0])
X = int(tmp[1])
 
if X <= 500 * N:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
s = 0
if N % 2 == 0:
  s = 2 + N // 2

for i in range(3, int(math.sqrt(N), 2):
  if N % i == 0 and s > i + N // i:
    s = i + N // i

print(s-2)

Fixed submission:
import math
def main():
  N = int(input())
  s = 0
  if N % 2 == 0:
    s = 2 + N // 2

  for i in range(3, math.ceil(math.sqrt(N)) + 3):
    if N % i == 0 and (not s or s > i + N // i):
      s = i + N // i

  if not s:
    s = N + 1

  print(s-2)
  
main()
Buggy python submission (verdict: Runtime Error):
tmp = input().split(" ")
A = int(tmp[0])
B = int(tmp[1])

import math
print(math.max(A - 2 * B, 0))

Fixed submission:
tmp = input().split(" ")
A = int(tmp[0])
B = int(tmp[1])

print(max([A - 2 * B, 0]))
Buggy python submission (verdict: Runtime Error):
N, K = list(map(lambda n: int(n), input().split(" ")))
h = list(map(lambda x: int(n), input().split(" ")))
print(len(list(filter(lambda height: height >= K, h))))

Fixed submission:
N, K = list(map(lambda n: int(n), input().split(" ")))
h = list(map(lambda x: int(x), input().split(" ")))
print(len(list(filter(lambda height: height >= K, h))))
Buggy python submission (verdict: Runtime Error):
str = input()
ans = "Yes"
for i in len(str):
  if (i + 1) % 2 == 0 and str[i] not in ('L', 'U', 'D'):
    ans = "No"
  if (i + 1) % 2 == 1 and str[i] not in ('R', 'U', 'D'):
    ans = "No"

print(ans)

Fixed submission:
str = input()
ans = "Yes"
for i in range(len(str)):
  if (i + 1) % 2 == 0 and str[i] not in ('L', 'U', 'D'):
    ans = "No"
  if (i + 1) % 2 == 1 and str[i] not in ('R', 'U', 'D'):
    ans = "No"
 
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K, Q = list(map(lambda n: int(n), input().split(" ")))
point = [K - Q] * N
for i in range(N):
  c = int(input())
  point[c - 1] += 1

print("\n".join(["YES" if p > 0 else "NO" for p in point]))

Fixed submission:
N, K, Q = list(map(lambda n: int(n), input().split(" ")))
point = [K - Q] * N
for i in range(Q):
  c = int(input())
  point[c - 1] += 1

print("\n".join(["Yes" if p > 0 else "No" for p in point]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))

satis = 0

for i in range(len(A)):
  satis += B[A[i]]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[i-1]

print(satis)

Fixed submission:
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))
 
satis = 0
 
for i in range(len(A)):
  satis += B[A[i] - 1]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[A[i - 1] - 1]
 
print(satis)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
cnt = 0
for i in S:
  if S[i] == T[i]:
    cnt += 1
print(cnt)

Fixed submission:
S = input()
T = input()
cnt = 0
loop = 0
for i in S:
  if i == T[loop]:
    cnt += 1
  loop += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
K, X = list(map(lambda n: int(n), input().split(" ")))
print(" ".join(list(range(K - X + 1, K + X - 1))))

Fixed submission:
K, X = list(map(lambda n: int(n), input().split(" ")))
print(" ".join(list(map(lambda s: str(s), list(range(X - K + 1, X + K))))))
Buggy python submission (verdict: Runtime Error):
str = input()

flag = False
for i in range(len(str)) - 1:
  if str[i] == str[i+1]:
    flag = True

print("Bad") if flag else print("Good")

Fixed submission:
str = input()

flag = False
for i in range(len(str) - 1):
  if str[i] == str[i+1]:
    flag = True

print("Bad") if flag else print("Good")
Buggy python submission (verdict: Runtime Error):
L, L+1, L+2, ..., L+N-1
N, L = list(map(lambda x: int(x), input().split(" ")))

S = int(N * (N-1) / 2) + L * N

if L >= 0:
  print(S - L)
elif L + N - 1 <= 0:
  print(S - L - N + 1)
else:
  print(S)

Fixed submission:
N, L = list(map(lambda x: int(x), input().split(" ")))
 
S = int(N * (N-1) / 2) + L * N
 
if L >= 0:
  print(S - L)
elif L + N - 1 <= 0:
  print(S - L - N + 1)
else:
  print(S)
Buggy python submission (verdict: Runtime Error):
W, H, x, y = list(map(lambda n: int(n), input().split(" ")))

S = W * H / 2
flag = 1 if W == 2 * x and H == 2 * y else flag = 0
print(S, end=" ")
print(flag)

Fixed submission:
W, H, x, y = list(map(lambda n: int(n), input().split(" ")))
 
S = W * H / 2

print(S, end=" ")
print(1) if W == 2 * x and H == 2 * y else print(0)
Buggy python submission (verdict: Runtime Error):
ary = list(map(lambda n: int(n), input().split(" "))).sort(reverse=True)

print(ary[0] + ary[1])

Fixed submission:
ary = list(map(lambda n: int(n), input().split(" ")))
ary.sort()

print(ary[0] + ary[1])
Buggy python submission (verdict: Runtime Error):
def main():
	N, M = [int(x) for x in input().split(" ")]
	A = [int(a) for a in input().split(" ")]
	A.sort()
	overwrite = []
	for i in range(M):
		B, C = [int(x) for x in input().split(" ")]
		overwrite.append({
			"count": B,
			"number": C
		})
	overwrite.sort(key=lambda o: -o["number"])
	j = 0
	k = 0
	flag = False
	while not flag and j < len(A) and k < len(overwrite):
		o = overwrite[k]
		for m in range(o["count"]):
			if A[j] <= o["number"]:
				A[j] = o["number"]
				j += 1
			else:
				flag = True
		k += 1

	print(sum(A))

main()


Fixed submission:
def main():
	N, M = [int(x) for x in input().split(" ")]
	A = [int(a) for a in input().split(" ")]
	A.sort()
	overwrite = []
	for i in range(M):
		B, C = [int(x) for x in input().split(" ")]
		overwrite.append({
			"count": B,
			"number": C
		})
	overwrite.sort(key=lambda o: -o["number"])
	j = 0
	k = 0
	flag = False
	while not flag and j < len(A) and k < len(overwrite):
		o = overwrite[k]
		for m in range(o["count"]):
			if j < len(A) and A[j] <= o["number"]:
				A[j] = o["number"]
				j += 1
			else:
				flag = True
		k += 1

	print(sum(A))

main()
Buggy python submission (verdict: Runtime Error):
small = ['a', 'b', 'c']
capital = ['A', 'B', 'C']

tmp = input().split(" ")
N = int(tmp[0])
K = int(tmp[1])
str = input()

str[K] = small[capital.index(str[K])]

print(str)

Fixed submission:
small = ['a', 'b', 'c']
capital = ['A', 'B', 'C']
 
tmp = input().split(" ")
N = int(tmp[0])
K = int(tmp[1])
str = list(input())
 
str[K - 1] = small[capital.index(str[K - 1])]
 
print("".join(str))
Buggy python submission (verdict: Runtime Error):
s = int(input())

start0 = 0
start1 = 0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == "0":
      start1 += 1
    elif s[i] == "1":
      start0 += 1
  elif i % 2 == 1:
    if s[i] == "0":
      start0 += 1
    elif s[i] == "1":
      start1 += 1

print(min([start0, start1]))

Fixed submission:
s = input()
 
start0 = 0
start1 = 0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == "0":
      start1 += 1
    elif s[i] == "1":
      start0 += 1
  elif i % 2 == 1:
    if s[i] == "0":
      start0 += 1
    elif s[i] == "1":
      start1 += 1

print(min([start0, start1]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = list(input())
a = []
for i in range(1, N - 1):
  a.append(len(list(set(s[0:i]) & set(s[i:]))))
print(max(a))

Fixed submission:
N = int(input())
s = list(input())
a = []
for i in range(1, N):
  a.append(len(list(set(s[0:i]) & set(s[i:]))))
print(max(a))
Buggy python submission (verdict: Runtime Error):
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var N = Number(line[0]);
	var X = line[1].split(" ");

	var Y = X.slice().sort(function(a, b){
		return Number(a) - Number(b)
	});

	var median = [Number(Y[(N/2 - 1)]), Number(Y[N/2])];
	var ret = [];

	for(var i = 0; i < X.length; i++){
		if(median[1] <= Number(X[i])){
			console.log(median[0] + "\n");
		}else{
			console.log(median[1] + "\n");
		}
	}
	return 0;

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Fixed submission:
import copy

def main():
	N = int(input())
	X = [int(x) for x in input().split(" ")]
	sortedX = copy.deepcopy(X)
	sortedX.sort()
	cand = [sortedX[int(N / 2) - 1], sortedX[int(N / 2)]]

	for xi in X:
		if xi <= cand[0]:
			print(cand[1])
		else:
			print(cand[0])

main()
Buggy python submission (verdict: Runtime Error):
N = input()

L = [2, 1]

if N == 1:
  print(1)
else:
  i = 1
  while i < N:
    L.append(L[i] + L[i-1])
    i += 1
  print(L[-1])

Fixed submission:
N = int(input())
 
L = [2, 1]
 
if N == 1:
  print(1)
else:
  i = 1
  while i < N:
    L.append(L[i] + L[i-1])
    i += 1
  print(L[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]

A.sort()
B.sort()
C.sort()

combiBC = [0] * len(B)
# combiBC[i] : number of combination of B, C when B[i] is selected

ic = 0
lc = len(C)
for ib in range(len(B)):
	b = B[ib]
	while ic < lc:
		c = C[ic]
		if b >= c:
			ic += 1
		else:
			combiBC[ib] = lc - ic
			break

cnt = 0
ib = 0
for ia in range(len(A)):
	a = A[ia]
	while ib < len(B):
		b = B[ib]
		if a >= b:
			ib += 1
		else:
			cnt += sum(combiBC[ib:])
			break

print(cnt)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]

A.sort()
B.sort()
C.sort()

combiBC = [0] * len(B)
# combiBC[i] : number of combination of B, C when B[i] is selected

ic = 0
lc = len(C)
for ib in range(len(B)):
	b = B[ib]
	while ic < lc:
		c = C[ic]
		if b >= c:
			ic += 1
		else:
			combiBC[ib] = lc - ic
			break

sumCombiBC = []
for i in range(len(combiBC)):
	if i == 0:
		sumCombiBC.append(combiBC[-1])
	else:
		sumCombiBC.insert(0, combiBC[-i-1] + sumCombiBC[0])

cnt = 0
ib = 0
for ia in range(len(A)):
	a = A[ia]
	while ib < len(B):
		b = B[ib]
		if a >= b:
			ib += 1
		else:
			cnt += sumCombiBC[ib]
			break

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]

A.sort()
B.sort()
C.sort()

ib = 0
ic = 0
lc = len(C)
sb_flag, sc_flag = [False, False]
sb, sc = [0, 0]
cnt = 0

for ia in range(len(A)):
	a = A[ia]
	while ib < len(B):
		b = B[ib]
		if a >= b:
			ib += 1
		else: # a < b
			if not sb_flag:
				sb = ib
				sb_flag = True
			while ic < lc:
				c = C[ic]
				if b >= c:
					ic += 1
				else: # b < c
					if not sc_flag:
						sc = ic
						sc_flag = True
					cnt += lc - ic
					break
			ib += 1

	ib = sb
	ic = sc
	sb_flag = False
	sc_flag = False

print(cnt)




Fixed submission:
N = int(input())
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]

A.sort()
B.sort()
C.sort()

combiBC = [0] * len(B)
# combiBC[i] : number of combination of B, C when B[i] is selected

ic = 0
lc = len(C)
for ib in range(len(B)):
	b = B[ib]
	while ic < lc:
		c = C[ic]
		if b >= c:
			ic += 1
		else:
			combiBC[ib] = lc - ic
			break

sumCombiBC = []
for i in range(len(combiBC)):
	if i == 0:
		sumCombiBC.append(combiBC[-1])
	else:
		sumCombiBC.insert(0, combiBC[-i-1] + sumCombiBC[0])

cnt = 0
ib = 0
for ia in range(len(A)):
	a = A[ia]
	while ib < len(B):
		b = B[ib]
		if a >= b:
			ib += 1
		else:
			cnt += sumCombiBC[ib]
			break

print(cnt)
Buggy python submission (verdict: Runtime Error):
tmp = input().split(" ")

print(max([tmp[0] - tmp[1], 0]))

Fixed submission:
tmp = input().split(" ")
 
print(max([int(tmp[0]) - int(tmp[1]), 0]))
Buggy python submission (verdict: Runtime Error):
import collections

def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  CA = collections.Counter(A)
  minA = min(A)
  maxA = max(A)
  X = [CA[i] for i in range(minA, maxA + 1)]
  if len(X) == 1:
    print(X[0])
    return 0
  if len(X) == 2:
    print(X[0] + X[1])
    
  Y = [X[j] + X[j+1] + X[j+2] for j in range(len(X) - 2)]
  print(max(Y))

main()

Fixed submission:
import collections

def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  CA = collections.Counter(A)
  minA = min(A)
  maxA = max(A)
  X = [CA[i] for i in range(minA, maxA + 1)]
  if len(X) == 1:
    print(X[0])
    return 0
  if len(X) == 2:
    print(X[0] + X[1])
    return 0
    
  Y = [X[j] + X[j+1] + X[j+2] for j in range(len(X) - 2)]
  print(max(Y))

main()

Buggy python submission (verdict: Runtime Error):
def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  minA = min(A)
  maxA = max(A)
  X = [A.count(i) for i in range(minA, maxA + 1)]
  if len(X) == 1:
    print(X[0])
    return 0
  if len(X) == 2:
    print(X[0] + X[1])
    
  Y = [X[j] + X[j+1] + X[j+2] for j in range(len(X) - 2)]
  print(max(Y))

main()

Fixed submission:
import collections

def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  CA = collections.Counter(A)
  minA = min(A)
  maxA = max(A)
  X = [CA[i] for i in range(minA, maxA + 1)]
  if len(X) == 1:
    print(X[0])
    return 0
  if len(X) == 2:
    print(X[0] + X[1])
    return 0
    
  Y = [X[j] + X[j+1] + X[j+2] for j in range(len(X) - 2)]
  print(max(Y))

main()
Buggy python submission (verdict: Runtime Error):
tmp = input().split(" ")
print("Yes") if tmp[0] == tmp[2] else print("No")

Fixed submission:
tmp = list(input())
print("Yes") if tmp[0] == tmp[2] else print("No")
Buggy python submission (verdict: Runtime Error):
ary = list(map(lambda n: int(n), input().split(" "))).sort()
print(ary[0] + ary[1])

Fixed submission:
ary = list(map(lambda n: int(n), input().split(" ")))
ary.sort()
print(ary[0] + ary[1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
 
pushed = [1]
 
while True:
  button = A[pushed[-1] - 1]
  if button in pushed:
    print("-1")
    break
  elif button == 2:
    print(len(pushed))
    break
  else:
    pushed.append(button)

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

button = [0] * N
button[0] = 1
next_button = 1
i = 0

while True:
  button[next_button - 1] = 2
  next_button = A[next_button - 1]
  if button[next_button - 1] == 2:
    print("-1")
    break
  elif next_button == 2:
    i += 1
    print(i)
    break
  else:
    button[next_button - 1] = 1
    i += 1

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

pushed = [1]

while True:
  button = A[pushed[-1] - 1]
  if button in pushed:
    print("-1")
    break
  elif button == 2:
    print(len(pushed))
    break;
  else:
    pushed.append(button)

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

button = [0] * N
button[0] = 1
next_button = 1
i = 0

while True:
  button[next_button - 1] = 2
  next_button = A[next_button - 1]
  if button[next_button - 1] == 2:
    print("-1")
    break
  elif next_button == 2:
    i += 1
    print(i)
    break
  else:
    button[next_button - 1] = 1
    i += 1
Buggy python submission (verdict: Runtime Error):
def main():
  N, M = [int(n) for n in input().split(" ")]

  if abs(N - M) > 2:
    print(0)
  elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % 1000000007)
  else:
    print((factorial(N) * factorial(M) * 2) % 1000000007)

def factorial(n):
  if n > 1:
    return (n * factorial(n - 1)) % 1000000007
  else:
    return 1
    
main()

Fixed submission:
def main():
  N, M = [int(n) for n in input().split(" ")]

  if abs(N - M) >= 2:
    print(0)
  elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % 1000000007)
  else:
    print((factorial(N) * factorial(M) * 2) % 1000000007)

def factorial(n):
  ret = 1
  for i in range(1, n + 1):
    ret = (ret * i) % 1000000007
  return ret
    
main()

Buggy python submission (verdict: Runtime Error):
def main():
  N, M = [int(n) for n in input().split(" ")]

  if abs(N - M) > 2:
    print(0)
  elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % 1000000007)
  else:
    print((factorial(N) * factorial(M) * 2) % 1000000007)

def factorial(n):
  if n > 1:
    return (n * factorial(n - 1)) % 1000000007
  else:
    return 1
    
main()

Fixed submission:
def main():
  N, M = [int(n) for n in input().split(" ")]

  if abs(N - M) >= 2:
    print(0)
  elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % 1000000007)
  else:
    print((factorial(N) * factorial(M) * 2) % 1000000007)

def factorial(n):
  ret = 1
  for i in range(1, n + 1):
    ret = (ret * i) % 1000000007
  return ret
    
main()
Buggy python submission (verdict: Runtime Error):
g = [31,28,31,30,31,30,31,31,30,31,30,31]
 
tmp = input().split(" ")
print("Yes") if g[int(tmp[0])] == g[int(tmp[1])] else print("No")

Fixed submission:
g = [31,28,31,30,31,30,31,31,30,31,30,31]
 
tmp = input().split(" ")
print("Yes") if g[int(tmp[0]) - 1] == g[int(tmp[1]) - 1] else print("No")

Buggy python submission (verdict: Runtime Error):
g = [31,28,31,30,31,30,31,31,30,31,30,31]
 
tmp = input().split(" ")
print("Yes") if g[int(tmp[0])] == g[int(tmp[1])] else print("No")

Fixed submission:
g = [31,28,31,30,31,30,31,31,30,31,30,31]
 
tmp = input().split(" ")
print("Yes") if g[int(tmp[0]) - 1] == g[int(tmp[1]) - 1] else print("No")

Buggy python submission (verdict: Runtime Error):
g = [31,28,31,30,31,30,31,31,30,31,30,31]

tmp = input().split(" ")
print("Yes") if g[tmp[0]] == g[tmp[1]] else print("No")

Fixed submission:
g = [31,28,31,30,31,30,31,31,30,31,30,31]
 
tmp = input().split(" ")
print("Yes") if g[int(tmp[0]) - 1] == g[int(tmp[1]) - 1] else print("No")
Buggy python submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(" ")]
 
placed = 0
elm = []
for i in range(N):
  a, b = input().split(" ")
  elm.append({
    "order": i + 1,
    "element": int(a),
    "count": int(b)
  })

elm.sort(key=lambda e: (e["element"], e["order"]))
for i in range(len(elm)):
  placed = e["count"]
  if placed >= K:
    print(e["element"])
    break


Fixed submission:
N, K = [int(x) for x in input().split(" ")]
 
placed = 0
elm = []
for i in range(N):
  a, b = input().split(" ")
  elm.append({
    "order": i + 1,
    "element": int(a),
    "count": int(b)
  })

elm.sort(key=lambda e: (e["element"], e["order"]))
for i in range(len(elm)):
  e = elm[i]
  placed += e["count"]
  if placed >= K:
    print(e["element"])
    break
Buggy python submission (verdict: Runtime Error):
tmp = input().split(" ")
a = (int(tmp[0]) - 2) % 13
b = (int(tmp[1]) - 2) % 13
print("Alice") if a > b else print("Draw") if a = b else print("Bob")

Fixed submission:
tmp = input().split(" ")
a = (int(tmp[0]) - 2) % 13
b = (int(tmp[1]) - 2) % 13
print("Alice") if a > b else print("Draw") if a == b else print("Bob")