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

ans = 0
s = [(K, V[:], [], False)]
while s:
    cnt, v, bag, flag = s.pop()
    ans = max(ans, sum(bag))
    if cnt > 0 and v and not flag:
        s.append((cnt-1, v[1:], bag + [v[0]], False))
        s.append((cnt-1, v[:-1], bag + [v[-1]], False))
    if cnt > 0 and bag:
        min_bag = min(bag)
        if min_bag < 0:
            bag.remove(min_bag)
            s.append((cnt-1, [], bag, True))


print(ans)


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

ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l + r < N:
            bag = V[:l] + V[N-r:] + [0]
            rest_ope = K-l-r
        else:
            bag = V[:]
            rest_ope = K - N
        for _ in range(rest_ope):
            min_bag = min(bag)
            if min_bag < 0 and rest_ope > 0:
                bag.remove(min_bag)
                rest_ope -= 1
        else:
            ans = max(ans, sum(bag))

print(ans)

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

ans = 0
s = [(K, V[:], [], False)]
while s:
    cnt, v, bag, flag = s.pop()
    ans = max(ans, sum(bag))
    if cnt > 0 and v and not flag:
        s.append((cnt-1, v[1:], bag + [v[0]], False))
        s.append((cnt-1, v[:-1], bag + [v[-1]], False))
    if cnt > 0 and bag:
        bag.sort()
        s.append((cnt-1, [bag[0]] + v, bag[1:], True))
        s.append((cnt-1, v + [bag[0]], bag[1:], True))

print(ans)


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

ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l + r < N:
            bag = V[:l] + V[N-r:] + [0]
            rest_ope = K-l-r
        else:
            bag = V[:]
            rest_ope = K - N
        for _ in range(rest_ope):
            min_bag = min(bag)
            if min_bag < 0 and rest_ope > 0:
                bag.remove(min_bag)
                rest_ope -= 1
        else:
            ans = max(ans, sum(bag))

print(ans)

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

ans = 0
s = [(K, V[:], [])]
while s:
    cnt, v, bag = s.pop()
    ans = max(ans, sum(bag))
    if cnt > 0 and v:
        s.append((cnt-1, v[1:], bag + [v[0]]))
        s.append((cnt-1, v[:-1], bag + [v[-1]]))
    if cnt > 0 and bag:
        bag.sort()
        s.append((cnt-1, [bag[0]] + v, bag[1:]))
        s.append((cnt-1, v + [bag[0]], bag[1:]))

print(ans)

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

ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l + r < N:
            bag = V[:l] + V[N-r:] + [0]
            rest_ope = K-l-r
        else:
            bag = V[:]
            rest_ope = K - N
        for _ in range(rest_ope):
            min_bag = min(bag)
            if min_bag < 0 and rest_ope > 0:
                bag.remove(min_bag)
                rest_ope -= 1
        else:
            ans = max(ans, sum(bag))

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
nodes = {}
for _ in range(N-1):
    l, r, d = map(int, input().split())
    if nodes.get(str(l)) is None:
        nodes[str(l)] = {'to': [], 'color': -1}
    if nodes.get(str(r)) is None:
        nodes[str(r)] = {'to': [], 'color': -1}

    nodes[str(l)]['to'].append((str(r), d))
    nodes[str(r)]['to'].append((str(l), d))


def dfs(node, color):
    nodes[node]['color'] = color
    for n, d in nodes[node]['to']:
        if nodes[n]['color'] != -1:
            continue

        if d % 2 == 0:
            dfs(n, color)
        else:
            dfs(n, (color+1) % 2)


dfs('1', 0)
for i in range(1, N+1):
    print(nodes[str(i)]['color'])


Fixed submission:
N = int(input())
nodes = {}
for _ in range(N-1):
    l, r, d = map(int, input().split())
    if nodes.get(str(l)) is None:
        nodes[str(l)] = {'to': [], 'color': -1}
    if nodes.get(str(r)) is None:
        nodes[str(r)] = {'to': [], 'color': -1}

    nodes[str(l)]['to'].append((str(r), d))
    nodes[str(r)]['to'].append((str(l), d))

q = [('1', 0)]
while q:
    node, color = q.pop()

    nodes[node]['color'] = color
    for n, d in nodes[node]['to']:
        if nodes[n]['color'] != -1:
            continue

        if d % 2 == 0:
            q.append((n, color))
        else:
            q.append((n, (color+1) % 2))


for i in range(1, N+1):
    print(nodes[str(i)]['color'])

Buggy python submission (verdict: Runtime Error):
N = int(input())
nodes = {}
for _ in range(N-1):
    l, r, d = map(int, input().split())
    if nodes.get(str(l)) is None:
        nodes[str(l)] = {'to': [], 'color': -1}
    if nodes.get(str(r)) is None:
        nodes[str(r)] = {'to': [], 'color': -1}

    nodes[str(l)]['to'].append((str(r), d))
    nodes[str(r)]['to'].append((str(l), d))


def dfs(node, color):
    nodes[node]['color'] = color
    for n, d in nodes[node]['to']:
        if nodes[n]['color'] != -1:
            continue

        if d % 2 == 0:
            dfs(n, color)
        else:
            dfs(n, (color+1) % 2)


dfs('1', 0)
for i in range(1,N+1):
    print(nodes[str(i)]['color'])


Fixed submission:
N = int(input())
nodes = {}
for _ in range(N-1):
    l, r, d = map(int, input().split())
    if nodes.get(str(l)) is None:
        nodes[str(l)] = {'to': [], 'color': -1}
    if nodes.get(str(r)) is None:
        nodes[str(r)] = {'to': [], 'color': -1}

    nodes[str(l)]['to'].append((str(r), d))
    nodes[str(r)]['to'].append((str(l), d))

q = [('1', 0)]
while q:
    node, color = q.pop()

    nodes[node]['color'] = color
    for n, d in nodes[node]['to']:
        if nodes[n]['color'] != -1:
            continue

        if d % 2 == 0:
            q.append((n, color))
        else:
            q.append((n, (color+1) % 2))


for i in range(1, N+1):
    print(nodes[str(i)]['color'])
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

count = 0
for r in range(N//R + 1):
    Rr = R*r
    for g in range((N-Rr)//G + 1):
        Gg = G*g
        Rr_plus_Gg = Rr + Gg
        for b in range((N-Rr-Gg)//B + 1):
            if Rr_plus_Gg + B*b == N:
                count += 1
                break

print(count)


Fixed submission:
R, G, B, N = map(int, input().split())

count = 0
for r in range(N//R + 1):
    for g in range((N-R*r)//G + 1):
        if (N-R*r-G*g) % B == 0:
            count += 1


print(count)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

count = 0
for r in range(N//R + 1):
    Rr = R*r
    for g in range((N-Rr)//G + 1):
        Gg = G*g
        Rr_plus_Gg = Rr + Gg
        for b in range((N-Rr-Gg)//B + 1):
            if Rr_plus_Gg + B*b == N:
                count += 1
                break

print(count)


Fixed submission:
R, G, B, N = map(int, input().split())

count = 0
for r in range(N//R + 1):
    for g in range((N-R*r)//G + 1):
        if (N-R*r-G*g) % B == 0:
            count += 1


print(count)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

count = 0
for r in range(N//R + 1):
    for g in range((N-R*r)//G + 1):
        for b in range((N-R*r-G*g)//B + 1):
            if R*r + G*g + B*b == N:
                count += 1
                break

print(count)


Fixed submission:
R, G, B, N = map(int, input().split())

count = 0
for r in range(N//R + 1):
    for g in range((N-R*r)//G + 1):
        if (N-R*r-G*g) % B == 0:
            count += 1


print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0

for m in range(1, N+1):
    if N//m == N % m:
        ans += m

print(ans)


Fixed submission:
def gen_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    return divisors


N = int(input())

divisors = gen_divisors(N)
divisors.remove(1)
ans = 0
for d in divisors:
    m = d-1
    if N//m == N%m:
        ans += m

print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
s = input()
k = int(input())

target_char = s[k]

out = ""
for s_i in s:
	if s_i != target_char:
		out += "*"
	else:
		out += s_i

print(out)

Fixed submission:
n = input()
s = input()
k = int(input())

target_char = s[k-1]

out = ""
for s_i in s:
	if s_i != target_char:
		out += "*"
	else:
		out += s_i

print(out)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import add

n, k = map(int, input().split())
s_law = input()

current_status = "1"
s = [0]
for h in s_law:
    if h == current_status:
        s[-1] += 1
    else:
        s.append(1)
        current_status = h

join_num = k * 2 + 1

max_rev = 0
for i, state in enumerate(s):
    if i % 2 == 1:
        continue
    max_rev = max(reduce(add, s[i:i + join_num]), max_rev)

print(max_rev)


Fixed submission:
N, K = map(int, input().split())
S = input()

h = (0, S[0])
t = (0, S[0])
k = 1 if S[0] == '0' else 0
max_handstands = 1
current_handstands = 1
while True:
    if h[0] == N-1 and t[0] == N-1:
        break
    # kを維持したままtを進める
    elif t[0] < N-1 and not (t[1] == '1' and S[t[0]+1] == '0'):
        t = (t[0]+1, S[t[0]+1])
        current_handstands += 1
    # kを増やしてtを進める
    elif t[0] < N-1 and k < K and S[t[0]+1] != t[1]:
        k += 1
        t = (t[0]+1, S[t[0]+1])
        current_handstands += 1
    # kを維持したままhを進める
    elif not (h[1] == '0' and S[h[0]+1] == '1') and h[0] < t[0]:
        max_handstands = max(max_handstands, current_handstands)
        h = (h[0]+1, S[h[0]+1])
        current_handstands -= 1
    # kを減らしてtを進める
    elif S[h[0]+1] != h[1] and h[0] < t[0]:
        max_handstands = max(max_handstands, current_handstands)
        k -= 1
        h = (h[0]+1, S[h[0]+1])
        current_handstands -= 1
    else:
        raise

print(max_handstands)
Buggy python submission (verdict: Runtime Error):
anntena = []
for i in range(5):
  anntena.append(int(input())
k = int(input())
                 
if anntena[4] - anntena[0] <= k:
  print('Yey!')
else:
  print(':(')


Fixed submission:
max_distance = 0
previous = int(input())
for i in range(4):
    current = int(input())
    distance = current - previous
    if distance > max_distance:
        max_distance = distance

k = int(input())

if max_distance > k:
    print(":(")
else:
    print("Yay!")

Buggy python submission (verdict: Runtime Error):
anntena = []
for i in range(5):
    anntena.append(int(input())
k = int(input())
                 
if anntena[4] - anntena[0] <= k:
    print('Yey!')
else:
    print(':(')


Fixed submission:
max_distance = 0
previous = int(input())
for i in range(4):
    current = int(input())
    distance = current - previous
    if distance > max_distance:
        max_distance = distance

k = int(input())

if max_distance > k:
    print(":(")
else:
    print("Yay!")

Buggy python submission (verdict: Runtime Error):
anntena = []
for i in range(5):
	anntena.append(int(input())
k = int(input())
                 
if anntena[4] - anntena[0] <= k:
	print('Yey!')
else:
    print(':(')

Fixed submission:
max_distance = 0
previous = int(input())
for i in range(4):
    current = int(input())
    distance = current - previous
    if distance > max_distance:
        max_distance = distance

k = int(input())

if max_distance > k:
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
import math

cycles = []
for i in range(5):
    cycles.append(int(input()))


minimum_last_order_cycle = 9
for cycle in cycles:
    if cycle % 10 <= minimum_last_order_cycle % 10 and cycle % 10 > 0:
        minimum_last_order_cycle = cycle

cycles.remove(minimum_last_order_cycle)

time = 0
for cycle in cycles:
    time += math.ceil(cycle / 10) * 10

time += minimum_last_order_cycle

print(time)


Fixed submission:
import math

cycles = []
for i in range(5):
    cycles.append(int(input()))

minimum_last_order_cycle = None
for cycle in cycles:
    if minimum_last_order_cycle is None and cycle % 10 > 0:
        minimum_last_order_cycle = cycle
    elif minimum_last_order_cycle is not None and cycle % 10 < minimum_last_order_cycle % 10 and cycle % 10 > 0:
        minimum_last_order_cycle = cycle

if minimum_last_order_cycle is None:
    minimum_last_order_cycle = cycles[0]

cycles.remove(minimum_last_order_cycle)

time = 0
for cycle in cycles:
    time += math.ceil(cycle / 10) * 10

time += minimum_last_order_cycle

print(time)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr = [map(int,input().split()) for _ in range(Q)]

for l, r in lr:
    print(S[l-1:r].count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()

sum_list = [0]
for i in range(N-1):
    sum_list.append(sum_list[-1] + (1 if S[i:i+2] == 'AC' else 0))

for j in range(Q):
    l, r = map(int, input().split())
    print(sum_list[r-1] - sum_list[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr = [map(int,input().split()) for _ in range(Q)]

for l, r in lr:
    print(S[l-1:r].count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()

sum_list = [0]
for i in range(N-1):
    sum_list.append(sum_list[-1] + (1 if S[i:i+2] == 'AC' else 0))

for j in range(Q):
    l, r = map(int, input().split())
    print(sum_list[r-1] - sum_list[l-1])

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

for i in range(Q):
    l, r = map(int, input().split())
    print(S[l-1:r].count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()

sum_list = [0]
for i in range(N-1):
    sum_list.append(sum_list[-1] + (1 if S[i:i+2] == 'AC' else 0))

for j in range(Q):
    l, r = map(int, input().split())
    print(sum_list[r-1] - sum_list[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

acc = B
for i in range(A, B):
    acc ^= i

print("{}".format(acc))


Fixed submission:
from functools import reduce

A, B = map(int, input().split())
if A == B:
    result = A
else:
    result_top = reduce(lambda acc, n: acc ^ n, range(A, (int(A/4)+1) * 4))
    result_tail = reduce(lambda acc, n: acc ^ n, range(int(B/4) * 4, B + 1))
    result = result_top ^ result_tail

print("{}".format(result))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()

min_diff = 1000000000
for i in range(N-K+1):
    min_diff = min(min_diff, H[i+2] - H[i])

print(min_diff)


Fixed submission:
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()

min_diff = 1000000000
for i in range(N-K+1):
    min_diff = min(min_diff, H[i+K-1] - H[i])

print(min_diff)
Buggy python submission (verdict: Runtime Error):
n  = input()

if n == "1"
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)

Fixed submission:
n  = input()

if n == "1":
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = list(map(int, input().split()))

evens = [(0, 0)]*(10**5)
odds = [(0, 0)]*(10**5)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens.sort(key=lambda x: x[1], reverse=True)
odds.sort(key=lambda x: x[1], reverse=True)

if evens[0][0] != odds[0][0]:
    print(N - evens[0][1] - odds[0][1])
else:
    print(min(N - evens[0][1] - odds[1][1], N - evens[1][1] - odds[0][1]))


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

evens = [(0, 0)]*(10**5+1)
odds = [(0, 0)]*(10**5+1)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens.sort(key=lambda x: x[1], reverse=True)
odds.sort(key=lambda x: x[1], reverse=True)

if evens[0][0] != odds[0][0]:
    print(N - evens[0][1] - odds[0][1])
else:
    print(min(N - evens[0][1] - odds[1][1], N - evens[1][1] - odds[0][1]))
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

substring_set = set()
for i in range(len(S)):
    for j in range(min([K, len(S)-i])):
        substring_set.add(S[i, i+j])

print(sorted(list(substring_set))[K-1])


Fixed submission:
S = input()
K = int(input())

substring_set = set()
for i in range(len(S)):
    substring = []
    for j in range(min([K, len(S)-i])):
        substring.append(S[i+j])
        substring_set.add(''.join(substring))

print(sorted(list(substring_set))[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for h in range(1, 3501):
	for n in range(1, 3501):
		wb = 4*h*n - N*n - N*h
		if wb <= 0:
			continue
		w = N*h*n / wb
		if w.is_integer():
			print(h, n, int(w))
			exit()

Fixed submission:
N = int(input())

for h in range(1, 3501):
	for n in range(1, 3501):
		wb = 4*h*n - N*n - N*h
		if wb <= 0:
			continue
		w = N*h*n / wb
		if w.is_integer():
			print(h, n, int(w))
			exit()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = sorted(list(map(int, input().split())))

gap = M - N
if gap >= 2:
	ans = 0
else:
	ans = 1
	for i in range(1, M+1):
		ans *= i
	for i in range(1, N+1): 
		ans *= i
	if gap == 0:
		ans *= 2
print(ans%(10**9+7))

Fixed submission:
from math import factorial as f
N, M = sorted(list(map(int, input().split())))

gap = M - N
if gap >= 2:
	ans = 0
else:
	ans = f(M) * f(N)
	if gap == 0:
		ans *= 2
print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
import math

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

print(b // x - (a - 1) // x))


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

print(b // x - (a - 1) // x)
Buggy python submission (verdict: Runtime Error):
suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
i = 0
while i < len(s):
  nx = s[i:i+5]
  if nx != suf[0] and nx != suf[2]:
    print("NO")
    exit(0)
  i += 5
  if s[i] == 'r':
  	i += 1
print("YES")

Fixed submission:
suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
dp = [0] * (len(s) + 1)
dp[0] = 1
for i in range(len(s)):
    if not dp[i]:
        continue
    for it in suf:
        if s[i:i+len(it)] == it:
            dp[i + len(it)] = 1
print("YES") if dp[len(s)] else print("NO")

Buggy python submission (verdict: Runtime Error):
suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
i = 0
while i < len(s):
	nx = s[i:i+5]
    if nx != suf[0] and nx != suf[2]:
      print("NO")
      exit(0)
    i += 5
    if s[i] == 'r':
      i += 1
print("YES")

Fixed submission:
suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
dp = [0] * (len(s) + 1)
dp[0] = 1
for i in range(len(s)):
    if not dp[i]:
        continue
    for it in suf:
        if s[i:i+len(it)] == it:
            dp[i + len(it)] = 1
print("YES") if dp[len(s)] else print("NO")
Buggy python submission (verdict: Runtime Error):
a, b, c = input.split()
print(a[0] + b[0] + c[0])

Fixed submission:
a, b, c = input().split()
a = a[0]
b = b[0]
c = c[0]
a = [a, b, c]
print(''.join(a))
Buggy python submission (verdict: Runtime Error):
a, b, c = sorted(map(int, input()))
if a + b == c:
  print("Yes")
else:
  print("No")

Fixed submission:
a, b, c = sorted(map(int, input().split()))
if a + b == c:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
from math import gcd

a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = int(max((a + x - 1) // x, (b + y - 1) // y))
  a = x * k
  b = y * k
print(a + b)


Fixed submission:
a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = max((a + x - 1) // x, (b + y - 1) // y)
  a = x * k
  b = y * k
print(a + b)

Buggy python submission (verdict: Runtime Error):
from math import gcd

a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = int(max((a + x - 1) // x, (b + y - 1) // y))
  a = x * k
  b = y * k
print(a + b)


Fixed submission:
a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = max((a + x - 1) // x, (b + y - 1) // y)
  a = x * k
  b = y * k
print(a + b)

Buggy python submission (verdict: Runtime Error):
from math import gcd
from math import ceil

a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = int(max(ceil(x / a), ceil(y / b)))
  a = x * k
  b = y * k
print(a + b)


Fixed submission:
a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = max((a + x - 1) // x, (b + y - 1) // y)
  a = x * k
  b = y * k
print(a + b)

Buggy python submission (verdict: Runtime Error):
from math import gcd
from math import ceil

a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = int(max(math.ceil(x / a), math.ceil(y / b)))
  a = x * k
  b = y * k
print(a + b)


Fixed submission:
a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = max((a + x - 1) // x, (b + y - 1) // y)
  a = x * k
  b = y * k
print(a + b)

Buggy python submission (verdict: Runtime Error):
from math import gcd

rs = 1
for _ in range(int(input())):
  x = sum(map(int, input().split()))
  rs = x * rs / gcd(x, rs)
print(rs)
  

Fixed submission:
a, b = 1, 1
for _ in range(int(input())):
  x, y = map(int, input().split())
  k = max((a + x - 1) // x, (b + y - 1) // y)
  a = x * k
  b = y * k
print(a + b)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, N = map(int, input().split())
S = set()
toCheck = set()
rs = [0] * 10
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
    for i in range(3):
        for j in range(3):
            toCheck.add((a - i, b - j))

for a, b in toCheck:
    if a + 2 > H or b + 2 > W or b < 1 or a < 1:
        continue
    cnt = 0
    for i in range(3):
        for j in range(3):
            na, nb = a + i, b + j
            if (na, nb) in S:
                cnt += 1
    rs[cnt] += 1

total = max(0, H - 2) * max(0, W - 2)
rs[0] = total - sum(rs[1:])
for it in rs:
    print(it)




Fixed submission:
H, W, N = map(int, input().split())
S = set()
toCheck = set()
rs = [0] * 10
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
    for i in range(3):
        for j in range(3):
            toCheck.add((a - i, b - j))

for a, b in toCheck:
    if a + 2 > H or b + 2 > W or b < 1 or a < 1:
        continue
    cnt = 0
    for i in range(3):
        for j in range(3):
            na, nb = a + i, b + j
            if (na, nb) in S:
                cnt += 1
    rs[cnt] += 1

total = max(0, H - 2) * max(0, W - 2)
rs[0] = total - sum(rs[1:])
for it in rs:
    print(it)
Buggy python submission (verdict: Runtime Error):
n, avg = map(int, input().split())
a = list(map(int, input().split()))
mxsm = sum(a) + 5

dp = [[0] * mxsm for _ in range(n + 5)]

dp[0][0] = 1
rs = 0
for x in a:
    dp2 = [[it1 for it1 in lin] for lin in dp]
    for i in range(1, n + 1):
        for j in range(x, mxsm + 1):
            if dp[i - 1][j - x]:
                dp2[i][j] += dp[i - 1][j - x]
    dp = dp2

for i in range(1, n + 1):
    rs += dp[i][avg * i]

print(rs)



Fixed submission:
n, avg = map(int, input().split())
a = list(map(int, input().split()))
mxsm = sum(a) + 5

dp = [[0] * mxsm for _ in range(n + 5)]

dp[0][0] = 1
rs = 0
for x in a:
    dp2 = [[it for it in lin] for lin in dp]
    for i in range(1, n + 1):
        for j in range(x, mxsm + 1):
            if dp[i - 1][j - x]:
                dp2[i][j] += dp[i - 1][j - x]
    dp = dp2

for i in range(1, n + 1):
    if len(dp[i]) > avg * i:
        rs += dp[i][avg * i]

print(rs)
Buggy python submission (verdict: Runtime Error):
input()
a = [*map(int, input().split())]
ans = 10 ** 18
for val in range(-200, 200):
  curr = 0
  for it in a:
    curr += (it - val) ** 2
  ans = min(ans, curr)
print(ans)

Fixed submission:
_ = input()
a = list(map(int, input().split()))
ans = 10 ** 18
for val in range(-200, 200):
    curr = 0
    for it in a:
        curr += (it - val) ** 2
    ans = min(ans, curr)
print(ans)