Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03957 (python)

Fixed submission:
S = input()

C = False
# F = False
ans = False
for si in S:
    if si == 'C':
        C = True
    if C and si == 'F':
        ans = True

if ans:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()

c = []
f = []

for i, si in enumerate(S):
    if si == 'C':
        c.append(i)
    elif si == 'F':
        f.append(i)

if min(c) < max(f):
    print('Yes')
else:
    print('No')
Problem p03999 (python)

Fixed submission:
from itertools import combinations

def main():
    S = input()
    n = len(S)
    a = [i for i in range(1, n)]
    ans = []
    for i in range(n):
        if i == 0:
            ans.append(int(S))
        else:
            k = list(combinations(a, i))
            for ki in k:  # ki: (1, 3)
                r = 0
                t = 0  # 一時記憶
                for j, sj in enumerate(S):
                    if j in ki:
                        r += t
                        t = int(sj)
                    else:
                        t = t * 10 + int(sj)
                r += t
                ans.append(r)

    # print(ans)
    print(sum(ans))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = input()
    lens = len(S)

    patterns = []
    ans = 0
    for i in range(2 ** (lens-1)):
        x = format(i, 'b').zfill(lens-1)

        stmt = S[0]
        for i, xi in enumerate(x):
            if xi == '1':
                stmt += '+'
            stmt += S[i+1]
        ans += eval(stmt)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from itertools import combinations

def main():
    S = input()
    lens = len(S)

    patterns = []
    ans = 0
    for i in range(2 ** (lens-1)):
        x = format(i, 'b').zfill(lens-1)

        stmt = S[0]
        for i, xi in enumerate(x):
            if xi == '1':
                stmt += '+'
            stmt += S[i+1]
        ans += eval(stmt)
    print(ans)



if __name__ == "__main__":
    main()
Problem p02645 (python)

Fixed submission:
name = input()
print(name[:3])

Buggy submission (verdict: Runtime Error):
name = input()
print(name(:2))
Problem p02675 (python)

Fixed submission:
N = int(input())
 
mod = N % 10
 
if mod in [2,4,5,7,9]:
  print("hon")
  
elif mod in [0,1,6,8]:
  print("pon")
  
else:
  print("bon")

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

ls = N%10

if ls == 2,4,5,7,9:
  print("hon")
  
elif ls == 0,1,6,8:
  print("pon")
  
else:
  print("bon")
Problem p02741 (python)

Fixed submission:
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(A[n-1])

Buggy submission (verdict: Runtime Error):
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N = int(input())
print(A[N])
Problem p02981 (python)

Fixed submission:
a,b,c=input().split()
a1=int(a)
b1=int(b)
c1=int(c)
d=a1*b1
if d<=c1:
  print(d)
else:
  print(c1)

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
d=a*b
if d<=c:
  print(d)
else:
  print(c)
Problem p03281 (python)

Fixed submission:
N = int(input())
if N<105:
  print(0)
elif N<135:
  print(1)
elif N<165:
  print(2)
elif N<189:
  print(3)
elif N<195:
  print(4)
else:
  print(5)

Buggy submission (verdict: Runtime Error):
N = int(inut())
if N<105:
  print(0)
elif N<135:
  print(1)
elif N<165:
  print(2)
elif N<189:
  print(3)
elif N<195:
  print(4)
else:
  print(5)
Problem p03623 (python)

Fixed submission:
def ABS(a,b):
  c = a - b
  if c < 0:
    c = c * -1
  return c

str = input()
nli = list(map(int,str.split()))

if ABS(nli[0],nli[1]) < ABS(nli[0],nli[2]):
  print("A")
else:
  print("B")

Buggy submission (verdict: Runtime Error):
nlist = list(map(int,input.split()))

if abs(nlist[0] - nlist[1]) < abs(nlist[0] - nlist[1]) :
	print("A")
else: 
	print("B")
Problem p02787 (python)

Fixed submission:
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])

dp = [0] * (H + 1)
for h in range(1, H + 1):
    dp[h] = min([dp[max(h - a, 0)] + b for a, b in AB])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])

dp = [0] * (H + 1)
for h in range(1, H + 1):
    dp[h] = min([dp[h - a] + b for a, b in AB])

print(dp[-1])
Problem p02821 (python)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)

nA, sA, i = [N, N], [0],  N - 1
for a in range(1, A[0] * 2):
    di = 0
    while i - di >= 0 and A[i - di] == a:
        di += 1
    nA.append(nA[-1] - di)
    i -= di
for a in A:
    sA.append(sA[-1] + a)

L, R, ans = 0, A[0] * 2 + 1, 0
while R - L > 1:
    mid = L + (R - L) // 2
    mA = [nA[max(mid - A[i], 0)] for i in range(N)]
    sM = sum(mA)
    if M <= sM:
        L = mid
        ans = sum([A[i] * mA[i] + sA[mA[i]]
                   for i in range(N)]) - mid * (sM - M)
    else:
        R = mid

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)

nA, sA, i = [N, N], [0],  N - 1
for a in range(1, A[0] * 2):
    di = 0
    while A[i - di] == a:
        di += 1
    nA.append(nA[-1] - di)
    i -= di
for a in A:
    sA.append(sA[-1] + a)

L, R, ans = 0, A[0] * 2, 0
while R - L > 1:
    mid = L + (R - L) // 2
    mA = [nA[max(mid - A[i], 0)] for i in range(N)]
    sM = sum(mA)
    if M <= sM:
        L = mid
        ans = sum([A[i] * mA[i] + sA[mA[i]]
                   for i in range(N)]) - mid * (sM - M)
    else:
        R = mid

print(ans)
Problem p02846 (python)

Fixed submission:
import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if (A1 - B1) * T1 + (A2 - B2) * T2 == 0:
    print("infinity")
else:
    D, D1 = (A1 - B1) * T1 + (A2 - B2) * T2, (A1 - B1) * T1
    if (D1 > 0) == (D > 0):
        print(0)
    else:
        if D1 % D == 0:
            print(2 * math.floor(-D1 / D))
        else:
            print(2 * math.floor(-D1 / D) + 1)

Buggy submission (verdict: Runtime Error):
import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if (A1 - B1) * T1 + (A2 - B2) * T2 == 0:
    print("infinity")
else:
    D1, D2 = (A1 - B1) * T1, (A2 - B2) * T2
    if (D1 > 0) == (D1 + D2 > 0):
        print(0)
    else:
        print(1 + 2 * math.floor(abs(D1) / (abs(D1 + D2) - 1)) + (D1 % D2 == 0))
Problem p02854 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L, R, sumL_R = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if sumL_R < 0:
        L += 1
        sumL_R += A[L]
    else:
        R -= 1
        sumL_R -= A[R]
print(abs(sumL_R))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if df < 0:
        L += 1,
        df += A[L]
    else:
        R -= 1
        df -= A[R]
print(abs(df))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if df < 0:
        L += 1,
        df += A[L]
    else:
        R -= 1
        df -= A[R]
print(abs(sumL_R))
Problem p02900 (python)

Fixed submission:
from fractions import gcd


def primes(N):
    p = [False, False] + [True] * (N - 1)
    for i in range(2, int(N ** 0.5) + 1):
        if p[i]:
            for j in range(i * 2, N + 1, i):
                p[j] = False
    ret = [i for i in range(N + 1) if p[i]]
    return ret


def trial_division(N):
    factors = []
    for p in primes(int(N ** 0.5)):
        while N % p == 0:
            factors.append(p)
            N //= p
    if N > 1:
        factors.append(N)
    return factors


A, B = map(int, input().split())
g = gcd(A, B)
print(len(set(trial_division(g))) + 1)

Buggy submission (verdict: Runtime Error):
from fractions import gcd


def primes(N):
    p = [False, False] + [True] * (N - 1)
    for i in range(2, int(N ** 0.5) + 1):
        if p[i]:
            for j in range(i * 2, N + 1, i):
                p[j] = False
    return [i for i in range(N + 1) if p[i]]


def prime_factors(N):
    ret = []
    for p in primes(int(N ** 0.5) + 1):
        while N % p == 0:
            ret.append(p)
            N //= p
    if N > 1:
        ret.append(N)
    return ret


A, B = map(int, input().split())
g = gcd(A, B)
print(len(set(trial_division(g))) + 1)
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
P = [[] for i in range(N)]

for i in range(N - 1):
    a, b = map(int, input().split())
    P[a - 1].append(b - 1)
    P[b - 1].append(a - 1)


dic = {}


def Perm(n, k):
    if (n, k) in dic:
        return dic[(n, k)]
    ans = 1
    for i in range(n - k + 1, n + 1):
        ans *= i
        ans %= MOD
    dic[(n, k)] = ans
    return ans


def dfs(g, p):
    ans = Perm(K - 2, len(P[p]) - 1)
    for c in P[p]:
        if not c == g:
            ans *= dfs(p, c)
            ans %= MOD
    return ans


ans = Perm(K, len(P[0]) + 1)
for c in P[0]:
    ans *= dfs(0, c)
    ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
P = [[] for i in range(N)]

for i in range(N - 1):
    a, b = map(int, input().split())
    P[a - 1].append(b - 1)
    P[b - 1].append(a - 1)


def Perm(n, k):
    ans = 1
    for i in range(n - k + 1, n + 1):
        ans *= i
    return ans


def dfs(g, p):
    ans = Perm(K - 2, len(P[p]) - 1)
    for c in P[p]:
        if not c == g:
            ans *= dfs(p, c)
    return ans % MOD


ans = Perm(K, len(P[0]) + 1)
for c in P[0]:
    ans *= dfs(0, c)

print(ans % MOD)
Problem p03088 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import itertools
comb = list(map(''.join, itertools.product("ACGT", repeat=4)))

mod = int(1e9) + 7

N = int(input())

dp = {c: [0, 0] for c in comb}
dp["TTTT"] = [1, 0]

for _ in range(N):
    dp_new = {c: [0, 0] for c in comb}
    for k in dp:
        for b in "ACGT":
            if k[2:4] + b in ("AGC", "ACG", "GAC") or k[1:4] + b in ("ACGC", "AGGC", "ATGC", "AGCC", "AGGC", "AGTC"):
                dp_new[k[1:4] + b][1] += dp[k][0]
                dp_new[k[1:4] + b][1] += dp[k][1]
            else:
                dp_new[k[1:4] + b][0] += dp[k][0]
                dp_new[k[1:4] + b][1] += dp[k][1]
    dp = dp_new


print((4 ** N - sum([dp[k][1] for k in dp])) % mod)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N = int(input())

dp = {b: 1 for b in "ACGT"}
for _ in range(N - 1):
    dp_new = {}
    for k in dp:
        for b in "ACGT"
           if k[-2:] + b in ("AGC", "ACG", "GAC") or k[-3:4] + b in ("ACGC", "AGGC", "ATGC", "AGCC", "AGGC", "AGTC"):
                continue
            else:
                dp_new[k[-3:] + b] += dp[k]
    dp = dp_new

mod = 10 ** 9 + 7
print(sum(dp.values()) % mod)
Problem p03128 (python)

Fixed submission:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
A = list(map(int, input().split()))

cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
cd = [(a, cost[a]) for a in A]
cd.sort(key=lambda x: x[0], reverse=True)

dp = [0] + [-1] * N
for i in range(1, N + 1):
    for a, c in cd:
        if i - c >= 0 and 0 <= dp[i - c]:
            dp[i] = max(dp[i], dp[i - c] + 1)

ans, i = [], N
for _ in range(dp[-1]):
    for a, c in cd:
        if i - c >= 0 and dp[i - c] == dp[i] - 1:
            ans.append(a)
            i = i - c
            break

print(''.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
A = list(map(int, input().split()))

cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
cd = [(a, cost[a]) for a in A]
cd.sort(key=lambda x: x[0], reverse=True)

dp = [0] + [-1] * N
for i in range(1, N + 1):
    for a, c in cd:
        if i - c >= 0 and 0 <= dp[i - c]:
            dp[i] = max(dp[i], dp[i - c] + 1)

ans, i = [], N
for _ in range(dp[-1]):
    for a, c in cd:
        if dp[i - c] == dp[i] - 1:
            ans.append(a)
            i = i - c
            break

print(''.join(map(str, ans)))
Problem p03138 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))

digit_K = int(math.log(K, 2)) + 1 if not K == 0 else 0
d1s = [0]*digit_K
gain = []

ans = sum(A)
for i in range(digit_K):
    for j in range(N):
        d1s[i] += A[j] % 2
        A[j] = A[j] // 2
    gain.append((N - d1s[i] * 2) * 2**i)

pGain = [max(g, 0) for g in gain]
cK, kGain = K, []
for i in range(digit_K):
    cK, dK = divmod(cK,2)
    kGain.append(pGain[i] * dK)

maxgain = sum(kGain)
for i in range(digit_K):
    K, dK = divmod(K, 2)
    if dK == 1:
        sumgain = sum(pGain[:i] + kGain[i+1:])
        maxgain = max(maxgain, sumgain)

ans += maxgain
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
cK = K

digit_K = int(math.log(K, 2)) + 1 if not K == 0 else 0
d1s = [0]*digit_K
gain, Kgain = [], []

ans = sum(A)
for i in range(digit_K):
    for j in range(N):
        d1s[i] += A[j] % 2
        A[j] = A[j] // 2
    cK, dK = divmod(cK, 2)
    gain.append((N - digit1s[di] * 2) * 2**i if N - digit1s[di] * 2 else 0)
    Kgain.append((N - digit1s[di] * 2) * 2**i * dK)

maxgain = sum(Kgain)
for i in range(digit_K):
    K, dK = divmod(K, 2)
    if dK == 1:
        sumgain = sum(pgain[:i] + Kgain[i+1:])
    elif dK == 0:
        sumgain = sum(pgain[:i+1] + Kgain[i+1:])
    maxgain = max(maxgain, sumgain)

ans += maxgain

print(ans)
Problem p03240 (python)

Fixed submission:
# -*- coding: utf-8 -*-

N = int(input())
X, Y, H = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for x in range(101):
    for y in range(101):
        hc = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] > 0}
        h0 = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] == 0}
        if len(hc) == 1:
            if (len(h0) > 0 and min(h0) >= list(hc)[0]) or len(h0) == 0:
                print(x, y, list(hc)[0])
                break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N = int(input())
X, Y, H = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for x in range(101):
    for y in range(101):
        hc = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] > 0}
        h0 = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] == 0}
        if len(hc) == 1 and max(h0) <= max(hc):
            print(x, y, list(hc)[0])
            break
Problem p03241 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import bisect

N, M = map(int, input().split())

y = [1, M]
for i in range(2, int(M ** 0.5) + 1):
    if M % i == 0:
        y.append(i)
        y.append(M // i)

y.sort()
print(M // y[bisect.bisect_left(y, N)])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N = int(input())
X, Y, H = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for x in range(101):
    for y in range(101):
        hc = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] > 0}
        h0 = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] == 0}
        if len(hc) == 1:
            if (len(h0) > 0 and min(h0) >= list(hc)[0]) or len(h0) == 0:
                print(x, y, list(hc)[0])
                break
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
firstNot1 = ([i for i in range(len(S)) if S[i] != '1'] + [len(S)])[0]

print('1' if firstNot1 >= K else S[firstNot1])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
lc1 = -1
while S[lc1 + 1] == '1':
    lc1 += 1

if lc1 == -1:
    print(S[0])
else:
    print("1" if lc1 + 1 >= K else S[lc1 + 1])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
firstNot1 = [i for i in range(len(S)) if S[i] != '1'][0]

print('1' if firstNot1 >= K else S[firstNot1])
Problem p03480 (python)

Fixed submission:
S = input()
b = []
for i in range(len(S) - 1):
    if S[i:i + 2] == "01" or S[i:i + 2] == "10":
        b.append(len(S) - (i + 1) if i < len(S) // 2 else i + 1)

print(min(b) if len(b) != 0 else len(S))

Buggy submission (verdict: Runtime Error):
S = input()
b = []
for i in range(len(S) - 1):
    if S[i:i + 2] == "01" or S[i:i + 2] == "10":
        b.append(len(S) - (i + 1) if i < len(S) // 2 else i + 1)

print(min(b))
Problem p03547 (python)

Fixed submission:
# -*- coding: utf-8 -*-

A, B = input().split()

if int(A, 16) == int(B, 16):
    print('=')
elif int(A, 16) > int(B, 16):
    print('>')
elif int(A, 16) < int(B, 16):
    print('<')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

A, B = input().split()

if int(A, 16) = int(B, 16):
    print('=')
elif int(A, 16) > int(B, 16):
    print('>')
elif int(A, 16) < int(B, 16):
    print('<')
Problem p03548 (python)

Fixed submission:
# -*- coding: utf-8 -*-

X, Y, Z = map(int, input().split())

print(int((X - Z)/(Z+Y)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

A, B = input().split()

if int(A, 16) = int(B, 16):
    print('=')
elif int(A, 16) > int(B, 16):
    print('>')
elif int(A, 16) < int(B, 16):
    print('<')
Problem p03557 (python)

Fixed submission:
# -*- coding: utf-8 -*-
 
import bisect
 
n = int(input())
 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
B.sort()
C.sort()
 
Ac, Cc = [0]*n, [0]*n
# Ap, Cp = 0, 0
 
for i in range(n):
    Ac[i] = bisect.bisect_left(A, B[i])#[Ap:], B[i])
    # Ac[i], Ap = index + Ap, index + Ap
    Cc[i] = n - bisect.bisect_right(C, B[i])#[Cp:], B[i])
    # Cc[i], Cp = n - index - Cp, index + Cp
 
 
count = 0
for i in range(n):
    count += Ac[i]*Cc[i]
 
print(count)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import bisect

n = int(input())

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

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

Ac, Cc = [0]*n, [0]*n
# Ap, Cp = 0, 0

for i in range(n):
    Ac[i] = bisect.bisect_left(Ap, B[i])#[Ap:], B[i])
    # Ac[i], Ap = index + Ap, index + Ap
    Cc[i] = n - bisect.bisect_right(Cp, B[i])#[Cp:], B[i])
    # Cc[i], Cp = n - index - Cp, index + Cp


count = 0
for i in range(n):
    count += Ac[i]*Cc[i]

print(count)
Problem p03558 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import collections

n = int(input())

cursor = 1
deque = collections.deque([(cursor, 0)])
visited = {cursor}

min_path = 10e10
while len(deque) > 0:
    cursor, min_path = deque.popleft()
    visited.add(cursor)
    if cursor == 0:
        break

    pone, mten = (cursor + 1) % n, (cursor * 10) % n
    if not pone in visited:
        deque.append((pone, min_path + 1))
    if not mten in visited:
        deque.appendleft((mten, min_path))

print(min_path + 1)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())

q = collections.deque([(1, 0)])
v = {1}

while len(q) > 0:
    c, p = deque.popleft()
    v.add(c)
    if c == 0:
        break

    n1, n10 = (c + 1) % N, (c * 10) % n
    if not n1 in v:
        q.append((n1, p + 1))
    if not n10 in v:
        q.appendleft((n10, p))

print(p + 1)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())

q = collections.deque([(1, 0)])
v = {1}

while len(q) > 0:
    c, p = deque.popleft()
    v.add(c)
    if c == 0:
        break

    n1, n10 = (c + 1) % N, (c * 10) % n
    if not n1 in v:
        q.append((n1, p + 1))
    if not n10 in v:
        q.appendleft((n10, p))

print(p + 1)
Problem p03574 (python)

Fixed submission:
H, W = map(int, input().split())
S = ['.' * (W + 2)] + ['.' + input() + '.' for _ in range(H)] + ['.' * (W + 2)]

N = [(0, 1), (1, 0), (1, 1), (0, -1), (-1, 0), (1, -1), (-1, 1), (-1, -1)]
ans = [[] for _ in range(H)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == '.':
            ans[h - 1].append(sum([S[h + n[0]][w + n[1]] == '#' for n in N]))
        else:
            ans[h - 1].append('#')

for h in range(H):
    print(''.join(map(str, ans[h])))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = ['.' * (W + 2)] + ['.' + input() + '.' for _ in range(H)] + ['.' * (W + 2)]
ans = [[] for _ in range(H)]
N = [(1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == '#':
            ans[h - 1].append('#')
        else:
            ans[h - 1].append(sum([S[h + n[0]][w + n[1]] == '#' for n in N]))

for h in range(H):
    print(''.join(ans[h]))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = ['.' * (W + 2)] + ['.' + input() + '.' for _ in range(H)] + ['.' * (W + 2)]
ans = [[] for _ in range(H)]
N = [(1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            ans[h - 1].append('#')
        else:
            ans[h - 1].append(sum([S[h + n[0]][w + n[1]] == '#' for n in N]))

for h in range(H):
    print(''.join(ans[h]))