Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
direction = list(input())
change = [0]*N
change[0] = direction.count("E")
 
for i in range(1, N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    if direction[i1] == "W":
        f_p = 1
    change[i] = change[i-1] - f_n + f_p
print(min(change))

Fixed submission:
N = int(input())
direction = list(input())
change = [0]*(N+1)
# print(direction)
change[0] = direction.count("E")
# print(change)
for i in range(N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    else:
        f_p = 1
    change[i+1] = change[i] - f_n + f_p
# print(change)
print(min(change))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
direction = list(input())
change = [0]*N
 
for i in range(N):
    left = direction[0:i]
    right = direction[i+1:N]
    change[i] += left.count("W")
    change[i] += right.count("E")
    # print(left,right)
print(min(change))

Fixed submission:
N = int(input())
direction = list(input())
change = [0]*(N+1)
# print(direction)
change[0] = direction.count("E")
# print(change)
for i in range(N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    else:
        f_p = 1
    change[i+1] = change[i] - f_n + f_p
# print(change)
print(min(change))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
direction = list(input())
change = [0]*N

for i in range(N):
    for j in range(N):
        if j < i:
            if direction[j] != "E":
                change[i] += 1
        elif j > i:
            if direction[j] != "W":
                change[i] += 1

print(min(change))

Fixed submission:
N = int(input())
direction = list(input())
change = [0]*(N+1)
# print(direction)
change[0] = direction.count("E")
# print(change)
for i in range(N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    else:
        f_p = 1
    change[i+1] = change[i] - f_n + f_p
# print(change)
print(min(change))
Buggy python submission (verdict: Runtime Error):

from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,5):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])

Fixed submission:
# coding: utf-8
# Your code here!

from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,K+1):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
from functools import cmp_to_key
s = input()
K = int(input())

e = set([])

def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)

for i in range(1,len(s)+1):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])


Fixed submission:
# coding: utf-8
# Your code here!

from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,K+1):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])
Buggy python submission (verdict: Time Limit Exceeded):

import copy

n = int(input())
x = list(map(int, input().split(" ")))

def medianIndex(l, i):
    l.pop(i-1)
    num = len(l)
    l.sort()
    m = int((num - 1) / 2)
    print(l[m])
    

for i in range(1,n+1):
    temp = copy.copy(x)
    medianIndex(temp, i)

Fixed submission:
import copy
 
n = int(input())
x = list(map(int, input().split(" ")))

y = copy.copy(x)
x.sort()
l = len(x)
m0 = x[int(l/2 - 1)]
m1 = x[int(l/2)]


for i in y:
    if i <= m0:
        print(m1)
    else:
        print(m0)
Buggy python submission (verdict: Time Limit Exceeded):
import math

def comb(n,r):
    return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))
    
n = int(input())
x = list(map(int, input().split(" ")))

a = max(x)
temp = comb(a, x[0])
result = x[0]
for i in range(1, n):
    if x[i] == a:
        continue
    if temp <= comb(a, x[i]):
        temp = comb(a, x[i])
        result = x[i]

print(a , result)

Fixed submission:
import math
 
def comb(n,r):
    return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

def deff_half(l, h):
    d = abs(h/2 - l[0])
    r = 0
    for i in range(1, len(l)):
        if l[i] == h:
            continue
        if d >= abs(h/2 - l[i]):
            d = abs(h/2 - l[i])
            r = i
    return l[r]
    
n = int(input())
x = list(map(int, input().split(" ")))
 
a = max(x)
result = deff_half(x, a)

print(a , result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))
for j in range(n):
    s = 0
    x = 0
    for i in range(n):
        if i == j:
            continue
        s += abs(a[i] - x)
        x = a[i]
    s += abs(0 - x)
    print(s)

Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))
s = 0
a.insert(0, 0)
a.insert(n+1, 0)
for j in range(n+1):
    s += abs(a[j] - a[j+1])
for i in range(1, n+1):
    s_i = s + abs(a[i-1]-a[i+1]) - ((abs(a[i-1] - a[i]) + abs(a[i]-a[i+1])))
    print(s_i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))
for j in range(n):
    s = 0
    x = 0
    for i in range(len(a)):
        if i == j:
            continue
        s += abs(a[i] - x)
        x = a[i]
    s += abs(0 - x)
    print(s)

Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))
s = 0
a.insert(0, 0)
a.insert(n+1, 0)
for j in range(n+1):
    s += abs(a[j] - a[j+1])
for i in range(1, n+1):
    s_i = s + abs(a[i-1]-a[i+1]) - ((abs(a[i-1] - a[i]) + abs(a[i]-a[i+1])))
    print(s_i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))

def calc(a, k):
    s = 0
    x = 0
    for i in range(len(a)):
        if i == k:
            continue
        s += abs(a[i] - x)
        x = a[i]
    s += abs(0 - x)
    print(s)

for i in range(n):
    calc(a, i)


Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))
s = 0
a.insert(0, 0)
a.insert(n+1, 0)
for j in range(n+1):
    s += abs(a[j] - a[j+1])
for i in range(1, n+1):
    s_i = s + abs(a[i-1]-a[i+1]) - ((abs(a[i-1] - a[i]) + abs(a[i]-a[i+1])))
    print(s_i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))

def calc(a):
    s = 0
    x = 0
    for i in a:
        s += abs(i - x)
        x = i
    s += abs(0 - x)
    print(s)

for i in range(n):
    temp = a[:]
    del temp[i]
    calc(temp)

Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))
s = 0
a.insert(0, 0)
a.insert(n+1, 0)
for j in range(n+1):
    s += abs(a[j] - a[j+1])
for i in range(1, n+1):
    s_i = s + abs(a[i-1]-a[i+1]) - ((abs(a[i-1] - a[i]) + abs(a[i]-a[i+1])))
    print(s_i)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split(" "))
div1 = []
div2 = []

for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0:
        div1 += (i,)
        div2 += (M//i,)
for d in div2:
    if d * N <= M:
        print(d)
        break
else:
    div1 = div1[::-1]
    for d in div1:
        if d * N <= M:
            print(d)
            break

Fixed submission:
import math

N, M = map(int, input().split(" "))
div1 = []
div2 = []

for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0:
        div1 += (i,)
        div2 += (M//i,)
for d in div2:
    if d * N <= M:
        print(d)
        break
else:
    div1 = div1[::-1]
    for d in div1:
        if d * N <= M:
            print(d)
            break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())

listS = list(S)
temp = 0
result = float('inf')
black = 0

for i in range(N):
    temp = listS[:i+1].count('#') + listS[i+1:].count('.')
    if result > temp:
        result = temp

count1 = listS[:N-1].count('#')
print(min(result, count1))


Fixed submission:
N = int(input())
S = str(input())

listS = list(S)

result = listS.count('.')
boundary = listS.count('.')

for i in range(N):
    if listS[i] == '.':
        boundary -= 1
    else:
        boundary += 1
    result = min(result, boundary)

print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))

print(max(a) - min(a))


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

print(max(a) - min(a))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
K = int(input())

 
for i in range(N):
    if(S[i] != S[K]):
        S[i] = '*'
 
S = "".join(S)
 
print(S)

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

for i in range(N):
    if(S[i] != S[K-1]):
        S[i] = '*'

S = "".join(S)

print(S)

Buggy python submission (verdict: Runtime Error):

N = int(input())
S = list(input())
K = int(input())

print(S[K])

for i in range(N):
    if(S[i] != S[K]):
        S[i] = '*'

S = "".join(S)

print(S)

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

for i in range(N):
    if(S[i] != S[K-1]):
        S[i] = '*'

S = "".join(S)

print(S)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())

res = N%500
if A=>res:
	print("Yes")
else:
	print("No")


Fixed submission:
N = int(input())
A = int(input())

res = N%500
if A >= res:
	print("Yes")
else:
	print("No")

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

res = N%500
if A=>res
	print("Yes")
else
	print("No")

Fixed submission:
N = int(input())
A = int(input())

res = N%500
if A >= res:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
hs = input().split()
count = 1
maxh = 0
for i in range(1,n):
    maxh = max(maxh, int(hs[i-1]))
    if int(hs[i])=>maxh:
        count += 1
print(count)

Fixed submission:
n = int(input())
hs = input().split()
count = 1
maxh = 0
for i in range(1,n):
    maxh = max(maxh, int(hs[i-1]))
    if int(hs[i])>=maxh:
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
hs = map(int, input().split())
count = 1
maxh = 0
for i in range(1,n):
	maxh = max(maxh, hs[i-1])
	if hs[i]>maxh:
		count += 1
print(count)

Fixed submission:
n = int(input())
hs = input().split()
count = 1
maxh = 0
for i in range(1,n):
    maxh = max(maxh, int(hs[i-1]))
    if int(hs[i])>=maxh:
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
hs = map(int, input.split())
count = 1
maxh = 0
for i in range(1,n):
	maxh = max(maxh, hs[i-1])
	if hs[i]>maxh:
		count += 1
print(count)

Fixed submission:
n = int(input())
hs = input().split()
count = 1
maxh = 0
for i in range(1,n):
    maxh = max(maxh, int(hs[i-1]))
    if int(hs[i])>=maxh:
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
hs = map(int, input.split())
count = 1
maxh = 0
for i in range(1,n):
  maxh = max(maxh, hs[i-1])
  if hs[i]>maxh:
    count += 1
 print(count)

Fixed submission:
n = int(input())
hs = input().split()
count = 1
maxh = 0
for i in range(1,n):
    maxh = max(maxh, int(hs[i-1]))
    if int(hs[i])>=maxh:
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
l = len(colors)
count1 = 0
for i in range(l):
	if int(colors[i]) == (i % 2):
		count1 += int(colors[i])
print(min(count1, l-count1))

Fixed submission:
colors = input()
l = len(colors)
count1 = 0
for i in range(l):
	if int(colors[i]) == (i % 2):
		count1 += 1
print(min(count1, l-count1))

Buggy python submission (verdict: Runtime Error):
l = len(colors)
count1 = 0
for i in range(l):
	if colors[i] == i % 2:
		count1 += int(colors[i])
print(min(count1, l-count1))

Fixed submission:
colors = input()
l = len(colors)
count1 = 0
for i in range(l):
	if int(colors[i]) == (i % 2):
		count1 += 1
print(min(count1, l-count1))

Buggy python submission (verdict: Runtime Error):
colors = input()
l = len(colors)
count1 = 0
for i in range(l):
  count1 += int(colors[i])
 print(min(count1, l-count1))

Fixed submission:
colors = input()
l = len(colors)
count1 = 0
for i in range(l):
	if int(colors[i]) == (i % 2):
		count1 += 1
print(min(count1, l-count1))
Buggy python submission (verdict: Runtime Error):
S = input()
print(min(S.count('1'), S.count('0'))

Fixed submission:
S = input()
s = [int(S[i:i + 1]) for i in range(len(S))]
ans = 0
v1 = s[0]
index = []
index.append(0)
for i in range(1, len(s)):
    if v1 != s[i] and len(index) != 0:
        ans += 2
        index.pop(-1)
        if len(index) != 0:
            v1 = s[index[-1]]
        else:
            v1 = 10
    else:
        index.append(i)
        v1 = s[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = []
B = []
for _ in range(M):
    a, b = map(int,  input().split())
    A.append(a)
    B.append(b)
ans = []
ans.append(N * (N - 1) / 2)

n = [-1 for i in range(N)]

def find(x):
    if n[x] < 0:
        return x
    return n[x] = find(n[x])

def size(x):
    return -n[find(x)]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    n[x] += n[y]
    n[y] = x
    return 1

for i in range(1, M):
    if unite(A[-i], B[-i]) == 0:
        ans.append(ans[i])
    else:
        ans.append(ans[i] - size(A[-i]) * size(B[-i]))
for i in range(M):
    print(ans[-i])


Fixed submission:
N, M = map(int, input().split())
A = []
B = []
for _ in range(M):
    a, b = map(int,  input().split())
    A.append(a)
    B.append(b)
ans = []
ans.append(N * (N - 1) / 2)

n = [-1 for i in range(N)]

def find(x):
    if n[x] < 0:
        return x
    n[x] = find(n[x])
    return n[x]

def size(x):
    return -n[find(x)]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    if size(x) < size(y):
        x, y = y, x
    n[x] += n[y]
    n[y] = x
    return 1

for i in range(1, M):
    sab = size(A[-i] - 1) * size(B[-i] - 1)
    if unite(A[-i] - 1, B[-i] - 1) == 0:
        ans.append(ans[i - 1])
    else:
        ans.append(ans[i - 1] - sab)
for i in range(1, M + 1):
    print(int(ans[-i]))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
def ch_max(dp_i, dp_i_1):
    if dp_i < dp_i_1:
        dp_i = dp_i_1
    return dp_i
def chmin(dp_i, dp_i_1):
    if dp_i > dp_i_1:
        dp_i = dp_i_1
    return dp_i
n = int(stdin.readline().rstrip())
h = [int(x) for x in stdin.readline().rstrip().split()]

if n == 2:
    print(abs(h[0] - h[1]))
    exit()
dp = []
dp1[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(n - 2):
    dp[i + 2] = float('inf')
    dp[i + 2] = chmin(dp[i + 2],dp[i + 1] + abs(h[i + 2] - h[i + 1]))
    dp[i + 2] = chmin(dp[i + 2],dp[i] + abs(h[i + 2] - h[i]))
print(dp[n - 1])



Fixed submission:
from sys import stdin
def ch_max(dp_i, dp_i_1):
    if dp_i < dp_i_1:
        dp_i = dp_i_1
    return dp_i
def chmin(dp_i, dp_i_1):
    if dp_i > dp_i_1:
        dp_i = dp_i_1
    return dp_i
n = int(stdin.readline().rstrip())
h = [int(x) for x in stdin.readline().rstrip().split()]

if n == 2:
    print(abs(h[0] - h[1]))
    exit()
dp = [float('inf')] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(n - 2):
    dp[i + 2] = chmin(dp[i + 2],dp[i + 1] + abs(h[i + 2] - h[i + 1]))
    dp[i + 2] = chmin(dp[i + 2],dp[i] + abs(h[i + 2] - h[i]))
print(dp[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
s = [s[i:i+1] for i in range(n)]
cost = [0 for _ in range(n + 1)]
lin = 0
rin = n
for i in range(n + 1):
	cost[i] = s[0:i].count('W') + s[i + 1:n].count('E')
print(min(cost))

Fixed submission:
n = int(input())
s = input()
s = [s[i:i+1] for i in range(n)]
lcost = [0 for _ in range(n)]
rcost = [0 for _ in range(n)]
if s[0] == 'W':
  lcost[0] = 1
if s[-1] == 'E':
  rcost[-1] = 1
for i in range(1, n):
  if s[i] == 'W':
    lcost[i] = lcost[i - 1] + 1
  else:
    lcost[i] = lcost[i - 1]
for i in range(2, n + 1):
  if s[-i] == 'E':
    rcost[-i] = rcost[-i + 1] + 1
  else:
    rcost[-i] = rcost[-i + 1]
mincost = min(lcost[-1], rcost[0])
#print(lcost)
#print(rcost)
for i in range(1, n - 1):
  hoge = lcost[i - 1] + rcost[i + 1]
  if hoge < mincost:
    mincost = hoge
print(mincost)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
s = [s[i:i+1] for i in range(n)]
mcost = 10 ** 9
for i in range(n):
  cost = s[0:i].count('W')
  cost += s[i + 1:n].count('E')
  if mcost > cost:
    mcost = cost
print(mcost)

Fixed submission:
n = int(input())
s = input()
s = [s[i:i+1] for i in range(n)]
lcost = [0 for _ in range(n)]
rcost = [0 for _ in range(n)]
if s[0] == 'W':
  lcost[0] = 1
if s[-1] == 'E':
  rcost[-1] = 1
for i in range(1, n):
  if s[i] == 'W':
    lcost[i] = lcost[i - 1] + 1
  else:
    lcost[i] = lcost[i - 1]
for i in range(2, n + 1):
  if s[-i] == 'E':
    rcost[-i] = rcost[-i + 1] + 1
  else:
    rcost[-i] = rcost[-i + 1]
mincost = min(lcost[-1], rcost[0])
#print(lcost)
#print(rcost)
for i in range(1, n - 1):
  hoge = lcost[i - 1] + rcost[i + 1]
  if hoge < mincost:
    mincost = hoge
print(mincost)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a1 = map(int, input().split())
a2 = map(int, input().split())
msum = 0
for i in range(n):
  sum = 0
  for j in range(i + 1):
    sum += a1[j]
  for i in range(i, n):
    sum += a2[j]
  if msum < sum:
    msum = sum
print(msum)

Fixed submission:
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
msum = 0

for i in range(n):
  sum = 0
  for j in range(i + 1):
    sum += a1[j]
    #print(a1[j], end = '')
  for j in range(i, n):
    sum += a2[j]
    #print(a2[j], end = '')
  #print()
  #print(sum)
  if msum < sum:
    msum = sum
print(msum)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(a+b+c)

Fixed submission:
a, b, c = map(int, list(input()))
print(a+b+c)

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

Fixed submission:
a, b, c = map(int, list(input()))
print(a+b+c)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    matrix[i] = [0 if x == '.' else x for x in matrix[i]]
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            for n in range(-1, 2):
                for m in range(-1, 2):
                    i_n = i + n
                    j_m = j + m
                    if matrix[i_n][j_m] != '#' and i_n >= 0 and j_m >= 0:
                        matrix[i_n][j_m] += 1
for i in range(h):
  for j in range(w):
  	print('{}'.format(matrix[i][j]), end = '')
  print('')

Fixed submission:
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    matrix[i] = [0 if x == '.' else x for x in matrix[i]]
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            for n in range(-1, 2):
                for m in range(-1, 2):
                    i_n = i + n
                    j_m = j + m
                    if h > i_n >= 0 and w > j_m >= 0 :
                    	if matrix[i_n][j_m] != '#':
                        	matrix[i_n][j_m] += 1
for i in range(h):
  for j in range(w):
  	print('{}'.format(matrix[i][j]), end = '')
  print('')

Buggy python submission (verdict: Runtime Error):
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    matrix[i] = [0 if x == '.' else x for x in matrix[i]]
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            for n in range(-1, 2):
                for m in range(-1, 2):
                    i_n = i + n
                    j_m = j + m
                    if matrix[i_n][j_m] != '#' and i_n >= 0 and j_m >= 0:
                        matrix[i_n][j_m] += 1

print(*matrix, sep = '\n')

Fixed submission:
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    matrix[i] = [0 if x == '.' else x for x in matrix[i]]
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            for n in range(-1, 2):
                for m in range(-1, 2):
                    i_n = i + n
                    j_m = j + m
                    if h > i_n >= 0 and w > j_m >= 0 :
                    	if matrix[i_n][j_m] != '#':
                        	matrix[i_n][j_m] += 1
for i in range(h):
  for j in range(w):
  	print('{}'.format(matrix[i][j]), end = '')
  print('')
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 1
for i in range(1, n + 1):
  ans *= i
  if ans >= (10 ** 9 + 7):
    ans = ans - (10 ** 9 + 7)
print(p % (10 ** 9 + 7))

Fixed submission:
n = int(input())
ans = 1
for i in range(1, n + 1):
  ans *= i
  ans = ans % (10 ** 9 + 7)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = 1
for i in range(1, n + 1):
  p = p * i
print(p % (10 ** 9 + 7))

Fixed submission:
n = int(input())
ans = 1
for i in range(1, n + 1):
  ans *= i
  ans = ans % (10 ** 9 + 7)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input())
print(k * ((k - 1) ** (n - 1)))

Fixed submission:
n, k = map(int, input().split())
print(k * ((k - 1) ** (n - 1)))