Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

def radi(n):
	return n * math.pi / 180

def resolve():
	a, b, h, m = map(int, input().split())
	hd = radi(h*30+30*(m/60))
	md = radi(360*(m/60))
	hx = a * math.cos(hd)
	hy = a * math.sin(hd)
	mx = b * math.cos(md)
	my = b * math.sin(md)
	x = abs(hx - mx)
	y = abs(hy - my)
	v = math.sqrt(x**2 + y**2)
	print(v)
rseolve()

Fixed submission:
import math

def calc_angle(h, m):
	# validate the input
	if (h < 0 or m < 0 or h > 12 or m > 60):
		print('Wrong input')

	if (h == 12):
		h = 0
	if (m == 60):
		m = 0

	# Calculate the angles moved by
	# hour and minute hands with
	# reference to 12:00
	hour_angle = 0.5 * (h * 60 + m)
	minute_angle = 6 * m

	# Find the difference between two angles
	angle = abs(hour_angle - minute_angle)

	# Return the smaller angle of two
	# possible angles
	angle = min(360 - angle, angle)

	return angle

def resolve():
	a, b, h, m = map(int, input().split())
	ang = calc_angle(h, m)
	radi = math.radians(ang)
	v = (a**2 + b**2 - 2*a*b*math.cos(radi))**0.5
	print(v)
resolve()

Buggy python submission (verdict: Runtime Error):
def radi(deg):
    return deg * (math.pi / 180)

def resolve():
    ha, hb, h, m = map(int, input().split())
    hr = radi(30*h+(m/2))
    mr = radi(6*m)
    hx = ha * math.cos(hr)
    mx = hb * math.cos(mr)
    hy = ha * math.sin(hr)
    my = hb * math.sin(mr)
    v = (abs(hx - mx)**2 + abs(hy - my)**2)**0.5
    print(v)
resolve()

Fixed submission:
import math

def calc_angle(h, m):
	# validate the input
	if (h < 0 or m < 0 or h > 12 or m > 60):
		print('Wrong input')

	if (h == 12):
		h = 0
	if (m == 60):
		m = 0

	# Calculate the angles moved by
	# hour and minute hands with
	# reference to 12:00
	hour_angle = 0.5 * (h * 60 + m)
	minute_angle = 6 * m

	# Find the difference between two angles
	angle = abs(hour_angle - minute_angle)

	# Return the smaller angle of two
	# possible angles
	angle = min(360 - angle, angle)

	return angle

def resolve():
	a, b, h, m = map(int, input().split())
	ang = calc_angle(h, m)
	radi = math.radians(ang)
	v = (a**2 + b**2 - 2*a*b*math.cos(radi))**0.5
	print(v)
resolve()
Buggy python submission (verdict: Runtime Error):
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(10**5)
def search(n, step, rec, seq, k):
	if rec[n] != -1:
		c = step - rec[n]
		sim = (k - rec[n]) % c
		v = n
		for i in range(sim):
			v = seq[v-1]
		print(v)
		return
	rec[n] = step
	search(seq[n-1], step + 1, rec, seq, k)

def resolve():
	n, k = map(int, input().split())
	seq = list(map(int, input().split()))
	rec = [-1]*(n+1)
	search(1, 0, rec, seq, k)
resolve()

Fixed submission:
def resolve():
	n, m, x = map(int, input().split())
	books = [list(map(int, input().split())) for _ in range(n)]

	pay = float('inf')
	for i in range(1 << n):
		selected = []
		for j in range(n):
			if i >> j & 1:
				selected.append(j)
		rem = [0] * m
		tmp_pay = 0
		for j in selected:
			tmp_pay += books[j][0]
			for k in range(1, m+1):
				rem[k-1] += books[j][k]
		done = True
		for j in range(m):
			if rem[j] < x:
				done = False
		if done:
			pay = min(pay, tmp_pay)
	if pay == float('inf'):
		print(-1)
	else:
		print(pay)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	x = int(input())
	for i in range(1000):
		for j in range(-1000, 1000):
			if i**5 - j**5 == x:
				print(i, j)
				return

resolve()

Fixed submission:
def resolve():
	s = input()
	if s == 'ABC':
		print('ARC')
	else:
		print('ABC')
resolve()
Buggy python submission (verdict: Runtime Error):
	n = int(input())
	s = []
	d = {}
	ans = 0
	for _ in range(n):
		s.append(input())
	for i in s:
		if not d.get(i):
			ans += 1
			d[i] = True
	print(ans)
resolve()

Fixed submission:

def resolve():
	n = int(input())
	s = []
	d = {}
	ans = 0
	for _ in range(n):
		s.append(input())
	for i in s:
		if not d.get(i):
			ans += 1
			d[i] = True
	print(ans)
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	s = input()
	ans = 0
	for i in range(0, len(s)):
		for j in range(3, len(s)):
			if i + j >= len(s):
				break
			if not int(s[i:i + j + 1]) % 2019:
				ans += 1
	print(ans)
resolve()

Fixed submission:
def resolve():
    s = input()
    s = s[::-1]
    c = [0]*2019
    # why?
    c[0] = 1
    r = 0
    d = 1
    for i in s:
        num = int(i) * d % 2019 + r
        num %= 2019
        c[num] += 1
        r = num
        d *= 10
        d %= 2019
    ans = 0
    for i in c:
        ans += i*(i-1)//2
    print(ans)
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	s = input()
	ans = 0
	for i in range(0, len(s)):
		for j in range(3, len(s)):
			if i + j < len(s):
				if not int(s[i:i + j + 1]) % 2019:
					ans += 1
	print(ans)
resolve()

Fixed submission:
def resolve():
    s = input()
    s = s[::-1]
    c = [0]*2019
    # why?
    c[0] = 1
    r = 0
    d = 1
    for i in s:
        num = int(i) * d % 2019 + r
        num %= 2019
        c[num] += 1
        r = num
        d *= 10
        d %= 2019
    ans = 0
    for i in c:
        ans += i*(i-1)//2
    print(ans)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	r = int(input())
	print(2 * r * math.pi)
resolve()

Fixed submission:
def resolve():
	r = int(input())
	print(2 * r * 3.14159265358)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
	r = int(input())
	print(2 * r * math.pi)
resolve()

Fixed submission:
def resolve():
	r = int(input())
	print(2 * r * 3.14159265358)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
	n, m = map(int, input().split())
	a = list(map(int, input().split()))
	print(n-sum(a) if n-sum(a) > -1 else -1)
resolve()

Fixed submission:
def resolve():
	r = int(input())
	print(2 * r * 3.14159265358)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    input().split()
    map(int, input().split())
    list(map(int, input().split()))
resolve()

Fixed submission:
def resolve():
	n, m = map(int, input().split())
	a = list(map(int, input().split()))
	print(n-sum(a) if n-sum(a) > -1 else -1)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    n = int(input())
	a = list(map(int, input().split()))
	ans = [0]*n
	for i in a:
		ans[i-1] += 1
	for i in ans:
		print(i)
resolve()

Fixed submission:
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0]*n
	for i in a:
		ans[i-1] += 1
	for i in ans:
		print(i)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    n = int(input())
	a = list(map(int, input().split()))
	ans = [0]*n
	for i in a:
		ans[i-1] += 1
	for i in ans:
		print(i)
resolve()

Fixed submission:
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0]*n
	for i in a:
		ans[i-1] += 1
	for i in ans:
		print(i)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	k = int(input())
	ans = 0
	for i in range(1, k+1):
		for j in range(1, k + 1):
			for k in range(1, k + 1):
				ans += reduce(math.gcd, [i, j, k])
	print(ans)

resolve()

Fixed submission:
def resolve():
	w = input()
	if w.find("7") > -1:
		print("Yes")
	else:
		print("No")
resolve()
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce


def resolve():
	k = int(input())
	ans = 0
	for i in range(1, k+1):
		for j in range(1, k + 1):
			for k in range(1, k + 1):
				ans += reduce(math.gcd, [i, j, k])
	print(ans)

ressolve()

Fixed submission:
import math
from functools import reduce

def resolve():
	k = int(input())
	ans = 0
	for i in range(1, k+1):
		for j in range(1, k + 1):
			for k in range(1, k + 1):
				ans += reduce(math.gcd, [i, j, k])
	print(ans)

resolve()
Buggy python submission (verdict: Runtime Error):
, M, *A = map(int, open(0).read().split())
vote = sum(A) / (4*M)
num = list(filter(lambda x: x > vote, A))
num = len(num)
if num >= M:
	print("Yes")
else:
	print("No")

Fixed submission:
def resolve():
    a, b, c = map(int, open(0).read().split())
    tmp_a = a
    a = b
    b = tmp_a
    tmp_c = c
    c = a
    a = tmp_c
    print(a, b, c)
    
resolve()
Buggy python submission (verdict: Runtime Error):
, M, *A = map(int, open(0).read().split())
print(sum(A))
vote = sum(A) / (4*M)
num = list(filter(lambda x: x > vote, A))
num = len(num)
if num >= M:
	print("Yes")
else:
	print("No")

Fixed submission:
def resolve():
	N, M, *A = map(int, open(0).read().split())
	vote = sum(A) * (1 / (4*M))
	num = list(filter(lambda x: x >= vote, A))
	num = len(num)
	if num >= M:
		print("Yes")
	else:
		print("No")
resolve()

Buggy python submission (verdict: Runtime Error):
    N, M, *A = map(int, open(0).read().split())
    print(sum(A))
    vote = sum(A) / (4*M)
    num = list(filter(lambda x: x > vote, A))
    num = len(num)
    if num >= M:
      print("Yes")
    else:
      print("No")

Fixed submission:
def resolve():
	N, M, *A = map(int, open(0).read().split())
	vote = sum(A) * (1 / (4*M))
	num = list(filter(lambda x: x >= vote, A))
	num = len(num)
	if num >= M:
		print("Yes")
	else:
		print("No")
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	modu = 1000000007
	n, m = map(int, input().split())
	a = [False]*n
	for _ in range(m):
		a[int(input())] = True
	dp = [0]*(n+1)
	dp[0], dp[1] = 1, 1
	for i in range(2, n+1):
		if i in a:
			continue
		multi = []
		if not a[i-1]:
			multi.append(dp[i-1])
		if not a[i-2]:
			multi.append(dp[i-2])
		dp[i] = sum(multi) % modu
	print(dp[-1])
resolve()

Fixed submission:
def resolve():
	modu = 1000000007
	n, m = map(int, input().split())
	a = [False]*n
	for _ in range(m):
		a[int(input())] = True
	dp = [0]*(n+1)
	dp[0], dp[1] = 1, 1
	for i in range(2, n+1):
		if i < n and a[i]:
			continue
		multi = []
		if not a[i-1]:
			multi.append(dp[i-1])
		if not a[i-2]:
			multi.append(dp[i-2])
		dp[i] = sum(multi) % modu
	print(dp[-1])
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	modu = 1000000007
	n, m = map(int, input().split())
	a = [False]*n
	for _ in range(m):
		a[int(input())] = True
	dp = [0]*(n+1)
	dp[0], dp[1] = 1, 1
	for i in range(2, n+1):
		if i in a:
			continue
		multi = []
		if not a[i-1]:
			multi.append(dp[i-1])
		if not a[i-2]:
			multi.append(dp[i-2])
		dp[i] = sum(multi) % modu
	print(dp[-1])
resolve()

Fixed submission:
def resolve():
	modu = 1000000007
	n, m = map(int, input().split())
	a = [False]*n
	for _ in range(m):
		a[int(input())] = True
	dp = [0]*(n+1)
	dp[0], dp[1] = 1, 1
	for i in range(2, n+1):
		if i < n and a[i]:
			continue
		multi = []
		if not a[i-1]:
			multi.append(dp[i-1])
		if not a[i-2]:
			multi.append(dp[i-2])
		dp[i] = sum(multi) % modu
	print(dp[-1])
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	modu = 1000000007
	n, m = map(int, input().split())
	a = []
	for _ in range(m):
		a.append(int(input()))
	dp = [0]*(n+1)
	dp[0], dp[1] = 1, 1
	for i in range(2, n+1):
		if i in a:
			continue
		multi = []
		if i-1 not in a:
			multi.append(dp[i-1])
		if i-2 not in a:
			multi.append(dp[i-2])
		dp[i] = sum(multi) % modu
	print(dp[-1])
resolve()

Fixed submission:
def resolve():
	modu = 1000000007
	n, m = map(int, input().split())
	a = [False]*n
	for _ in range(m):
		a[int(input())] = True
	dp = [0]*(n+1)
	dp[0], dp[1] = 1, 1
	for i in range(2, n+1):
		if i < n and a[i]:
			continue
		multi = []
		if not a[i-1]:
			multi.append(dp[i-1])
		if not a[i-2]:
			multi.append(dp[i-2])
		dp[i] = sum(multi) % modu
	print(dp[-1])
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	n, k = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [float('inf')]*n
	dp[0], dp[1] = 0, abs(h[0] - h[1])
	for i in range(2, n):
		s = []
		for j in range(1, k+1):
			if i-j >= 0:
				s.append(dp[i-j] + abs(h[i-j] - h[i]))
		dp[i] = min(s)
	print(dp[-1])
resolve()

Fixed submission:
def resolve():
	N = int(input())
	H = list(map(int, input().split()))
	DP = [-1]*N
	DP[0], DP[1] = 0, abs(H[0] - H[1])
	for i in range(2, N):
		a = DP[i-2] + abs(H[i] - H[i-2])
		b = DP[i-1] + abs(H[i] - H[i - 1])
		DP[i] = min(a, b)
	print(DP[-1])
resolve()

Buggy python submission (verdict: Runtime Error):
def search(i, h, dp):
	if i == 0 or i == 1:
		return dp[i]
	if dp[i] < float('inf'):
		return dp[i]
	a = search(i - 1, h, dp) + abs(h[i] - h[i-1])
	b = search(i - 2, h, dp) + abs(h[i] - h[i-2])
	dp[i] = min(a, b)
	return dp[i]

def resolve():
	N = int(input())
	H = list(map(int, input().split()))
	DP = [float('inf')]*N
	DP[0], DP[1] = 0, abs(H[0] - H[1])
	print(search(N-1, H, DP))
resolve()

Fixed submission:
def resolve():
	N = int(input())
	H = list(map(int, input().split()))
	DP = [-1]*N
	DP[0], DP[1] = 0, abs(H[0] - H[1])
	for i in range(2, N):
		a = DP[i-2] + abs(H[i] - H[i-2])
		b = DP[i-1] + abs(H[i] - H[i - 1])
		DP[i] = min(a, b)
	print(DP[-1])
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	n, k = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [float('inf')]*n
	dp[0], dp[1] = 0, abs(h[0] - h[1])
	for i in range(2, n):
		s = []
		for j in range(1, k+1):
			if i-j >= 0:
				s.append(dp[i-j] + abs(h[i-j] - h[i]))
		dp[i] = min(s)
	print(dp[-1])
resolve()

Fixed submission:
def resolve():
	n, k = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [float('inf')]*n
	dp[0], dp[1] = 0, abs(h[0] - h[1])
	for i in range(2, n):
		s = []
		for j in range(1, k+1):
			if i-j >= 0:
				s.append(dp[i-j] + abs(h[i-j] - h[i]))
		dp[i] = min(s)
	print(dp[-1])
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def rec(n, w, ws, vs, dp):
    if w == 0 or n < 0:
        return 0
    if dp[n][w] > -1:
        return dp[n][w]
    if ws[n] <= w:
        dp[n][w] = max(dp[n][w], rec(n-1, w-ws[n], ws, vs, dp) + vs[n])
    dp[n][w] = max(dp[n][w], rec(n-1, w, ws, vs, dp))
    return dp[n][w]

def resolve():
    n, w = map(int, input().split())
    ws, vs = [0]*n, [0]*n
    for i in range(n):
        ws[i], vs[i] = map(int, input().split())
    dp = [[-1] * (w + 1) for _ in range(n + 1)]
    print(rec(n-1, w, ws, vs, dp))
resolve()

Fixed submission:
def resolve():
    n, w = map(int, input().split())
    ws, vs = [0]*n, [0]*n
    for i in range(n):
        ws[i], vs[i] = map(int, input().split())
    dp = [[0]*(w+1) for _ in range(n+1)]
    for i in range(n):
        for j in range(w+1):
            if j >= ws[i]:
                dp[i][j] = max(dp[i][j], dp[i-1][j - ws[i]] + vs[i])
            dp[i][j] = max(dp[i][j], dp[i-1][j] if i - 1 >= 0 else 0)
    print(dp[n-1][w])
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def rec(n, w, ws, vs, dp):
    if w == 0 or n < 0:
        return 0
    if dp[n][w] > -1:
        return dp[n][w]
    if ws[n] <= w:
        dp[n][w] = max(dp[n][w], rec(n-1, w-ws[n], ws, vs, dp) + vs[n])
    dp[n][w] = max(dp[n][w], rec(n-1, w, ws, vs, dp))
    return dp[n][w]

def resolve():
    n, w = map(int, input().split())
    ws, vs = [0]*n, [0]*n
    for i in range(n):
        ws[i], vs[i] = map(int, input().split())
    dp = [[-1] * (w + 1) for _ in range(n + 1)]
    print(rec(n-1, w, ws, vs, dp))
resolve()

Fixed submission:
def resolve():
    n, w = map(int, input().split())
    ws, vs = [0]*n, [0]*n
    for i in range(n):
        ws[i], vs[i] = map(int, input().split())
    dp = [[0]*(w+1) for _ in range(n+1)]
    for i in range(n):
        for j in range(w+1):
            if j >= ws[i]:
                dp[i][j] = max(dp[i][j], dp[i-1][j - ws[i]] + vs[i])
            dp[i][j] = max(dp[i][j], dp[i-1][j] if i - 1 >= 0 else 0)
    print(dp[n-1][w])
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def rec(n, w, ws, vs, dp):
    if w == 0 or n < 0:
        return 0
    if ws[n] <= w:
        dp[n][w] = max(dp[n][w], rec(n-1, w-ws[n], ws, vs, dp) + vs[n])
    dp[n][w] = max(dp[n][w], rec(n-1, w, ws, vs, dp))
    return dp[n][w]

def resolve():
    n, w = map(int, input().split())
    ws, vs = [0]*n, [0]*n
    for i in range(n):
        ws[i], vs[i] = map(int, input().split())
    dp = [[-1] * (w + 1) for _ in range(n + 1)]
    print(rec(n-1, w, ws, vs, dp))
resolve()

Fixed submission:
def resolve():
    n, w = map(int, input().split())
    ws, vs = [0]*n, [0]*n
    for i in range(n):
        ws[i], vs[i] = map(int, input().split())
    dp = [[0]*(w+1) for _ in range(n+1)]
    for i in range(n):
        for j in range(w+1):
            if j >= ws[i]:
                dp[i][j] = max(dp[i][j], dp[i-1][j - ws[i]] + vs[i])
            dp[i][j] = max(dp[i][j], dp[i-1][j] if i - 1 >= 0 else 0)
    print(dp[n-1][w])
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	s = input()
	k = int(input())
	if len(s) == 1:
		print(s)
		return

	for i in s:
		if int(i) == 1:
			continue
		print(i)
		return
resolve()

Fixed submission:
def resolve():
	a, b = map(int, input().split())
	print(a*b - (a+b-1))
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	s = input()
	k = int(input())
	if len(s) == 1:
		print(s)
		return

	for i in s:
		if int(i) == 1:
			continue
		print(i)
		return
	print(s[0])
resolve()

Fixed submission:
def resolve():
	n = int(input())
	if n == 0:
		print("0")
		return
	out = []
	while n != 0:
		n, rem = divmod(n, -2)
		if rem < 0:
			n += 1
			rem -= -2
		out.append(rem)
	print("".join(map(str, out[::-1])))
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	d, g = map(int, input().split())
	ps = []
	cs = []
	ans = 100**6
	for _ in range(d):
		p, c = map(int, input().split())
		ps.append(p)
		cs.append(c)
	for i in range(d-1, -1, -1):
		total = 0
		solved = 0
		for _ in range(ps[i]):
			if total >= g:
				if ans > solved:
					ans = solved
				break
			total += 100 * (i + 1)
			solved += 1
		total += cs[i]
		if total >= g and ans > solved:
			ans = solved
			break
		for j in range(d-1, -1, -1):
			if i == j:
				continue
			for _ in range(ps[j]):
				if total >= g:
					if ans > solved:
						ans = solved
					continue
				total += 100 * (j+1)
				solved += 1
			total += cs[j]
	print(ans)
resolve()

Fixed submission:
def resolve():
	r = int(input())
	if r < 1200:
		return print('ABC')
	if r < 2800:
		return print('ARC')
	else:
		return print('AGC')
resolve()
Buggy python submission (verdict: Runtime Error):
import math

def resolve():
	d, g = map(int, input().split())
	ps = []
	cs = []
	ans = math.inf
	for _ in range(d):
		p, c = map(int, input().split())
		ps.append(p)
		cs.append(c)
	for i in range(d-1, -1, -1):
		total = 0
		solved = 0
		for _ in range(ps[i]):
			if total >= g:
				if ans > solved:
					ans = solved
				break
			total += 100 * (i + 1)
			solved += 1
		total += cs[i]
		if total >= g and ans > solved:
			ans = solved
			break
		for j in range(d-1, -1, -1):
			if i == j:
				continue
			for _ in range(ps[j]):
				if total >= g:
					if ans > solved:
						ans = solved
					continue
				total += 100 * (j+1)
				solved += 1
			total += cs[j]
	print(ans)
resolve()

Fixed submission:
def resolve():
	d, g = map(int, input().split())
	ps = []
	cs = []
	ans = 100**6
	for _ in range(d):
		p, c = map(int, input().split())
		ps.append(p)
		cs.append(c)
	for i in range(d-1, -1, -1):
		total = 0
		solved = 0
		for _ in range(ps[i]):
			if total >= g and ans > solved:
				ans = solved
			total += 100 * (i + 1)
			solved += 1
		total += cs[i]
		if total >= g and ans > solved:
			ans = solved
			break
		for j in range(1 << d):
			done = False
			t_solved = solved
			t_total = total
			for k in range(d-1, -1, -1):
				if (j >> k) & 1:
					if i == k:
						continue
					if done:
						break
					for _ in range(ps[k]):
						if done:
							break
						if t_total >= g and ans > t_solved:
							ans = t_solved
							done = True
							continue
						t_total += 100 * (k+1)
						t_solved += 1
					t_total += cs[k]
					if t_total >= g and ans > t_solved:
						ans = t_solved
	print(ans)
resolve()
Buggy python submission (verdict: Runtime Error):
import statistics
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	seq = []
	for i in range(1, n+1):
		seq.append(abs(i-a[i-1]))
	seq = sorted(seq)
	m = statistics.median(seq)
	ans = 0
	for i in seq:
		ans += abs(i-m)
	print(ans)
resolve()

Fixed submission:
import statistics
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	seq = []
	for i in range(1, n+1):
		seq.append(i-a[i-1])
	seq = sorted(seq)
	m = int(statistics.median(seq))
	ans = 0
	for i in seq:
		ans += abs(i-m)
	print(ans)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
	n, k = map(int, input().split())
	a = list(map(int, input().split()))
	v = math.ceil((n - k) / (k-1) + 1)
	print(v)
resolve()

Fixed submission:
import math
def resolve():
	n, k = map(int, input().split())
	a = list(map(int, input().split()))
	i = a.index(min(a)) + 1
	if k - 1 > i:
		v = max(0, math.ceil((n - k - 2) / (k - 1))) + 1
	else:
		v = math.ceil(i / (k - 1)) + math.ceil((n - i - 1) / (k - 1))
	print(v)
resolve()
Buggy python submission (verdict: Runtime Error):
from collections import Counter

def resolve():
	n = int(input())
	s = input()
	sum_e = [0]*(n+1)
	sum_w = [0]*(n+1)
	for i in range(n):
		ev = 1 if s[i] == 'E' else 0
		wv = 1 if s[i] == 'W' else 0
		sum_e[i+1] = sum_e[i] + ev
		sum_w[i+1] = sum_w[i] + wv
	ans = float('inf')
	if n == 2:
		print(1 if len(Counter(list(s)).keys()) == 2 else 0)
		return
	for i in range(n+1):
		if i == 0:
			v = sum_e[-1] - sum_e[i]
			ans = min(ans, v)
		else:
			v = sum_w[i-1] + (sum_e[-1] - sum_e[i+1])
			ans = min(ans, v)
	print(ans)
resolve()

Fixed submission:
from collections import Counter

def resolve():
	n = int(input())
	s = input()
	sum_e = [0]*(n+1)
	sum_w = [0]*(n+1)
	for i in range(n):
		ev = 1 if s[i] == 'E' else 0
		wv = 1 if s[i] == 'W' else 0
		sum_e[i+1] = sum_e[i] + ev
		sum_w[i+1] = sum_w[i] + wv
	ans = float('inf')
	if n == 2:
		print(1 if len(Counter(list(s)).keys()) == 2 else 0)
		return
	e_w = sum_e[-1] - sum_e[1]
	e_e = sum_w[n-1]
	ans = min(e_w, e_e)
	for i in range(n):
		v = sum_w[i-1] + (sum_e[-1] - sum_e[i])
		ans = min(ans, v)
	print(ans)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
	n = int(input())
	s = input()
	sum_e = [0]*(n+1)
	sum_w = [0]*(n+1)
	for i in range(n):
		ev = 1 if s[i] == 'E' else 0
		wv = 1 if s[i] == 'W' else 0
		sum_e[i+1] = sum_e[i] + ev
		sum_w[i+1] = sum_w[i] + wv
	ans = float('inf')
	if n == 2:
		print(1 if len(Counter(list(s)).keys()) == 2 else 0)
		return
	for i in range(n+1):
		if i == 0:
			v = sum_e[-1] - sum_e[i]
			ans = min(ans, v)
		else:
			v = sum_w[i-1] + (sum_e[-1] - sum_e[i+1])
			ans = min(ans, v)
	print(ans)
resolve()

Fixed submission:
from collections import Counter

def resolve():
	n = int(input())
	s = input()
	sum_e = [0]*(n+1)
	sum_w = [0]*(n+1)
	for i in range(n):
		ev = 1 if s[i] == 'E' else 0
		wv = 1 if s[i] == 'W' else 0
		sum_e[i+1] = sum_e[i] + ev
		sum_w[i+1] = sum_w[i] + wv
	ans = float('inf')
	if n == 2:
		print(1 if len(Counter(list(s)).keys()) == 2 else 0)
		return
	e_w = sum_e[-1] - sum_e[1]
	e_e = sum_w[n-1]
	ans = min(e_w, e_e)
	for i in range(n):
		v = sum_w[i-1] + (sum_e[-1] - sum_e[i])
		ans = min(ans, v)
	print(ans)
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	g = [list(map(int, input().split())) for _ in range(3)]
	t = [[None]*3 for _ in range(3)]
	m = max(map(max, g))
	for a in range(m+1):
		for b in range(m+1):
			for c in range(m+1):
				for d in range(m+1):
					for e in range(m+1):
						for f in range(m+1):
							y = [a, b, c]
							x = [d, e, f]
							ans = True
							for i in range(3):
								for j in range(3):
									if g[i][j] != y[i] + x[j]:
										ans = False
							if ans:
								print('Yes')
								return
	print('No')
resolve()

Fixed submission:
def resolve():
	g = [list(map(int, input().split())) for _ in range(3)]
	m = max(map(max, g))
	for a in range(m+1):
		for b in range(m+1):
			for c in range(m+1):
				y = [a, b, c]
				x = [g[i][i] - y[i] for i in range(3)]
				ans = True
				for i in range(3):
					for j in range(3):
						v = y[i] + x[j]
						if g[i][j] != v:
							ans = False
				if ans:
					print('Yes')
					return

	print('No')
resolve()