Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
num = input()
le = len(num)
sum=0
for i in range(le):
  sum += int(num[i])
if sum%9==0:
  print("Yes")
else:
  print("No")


Fixed submission:
import math
n,x,t = map(int,input().split())
c = t*math.ceil(n/x)
print(c)

Buggy python submission (verdict: Runtime Error):
num = input()
le = len(num)
sum=0
for i in range(le):
  sum += int(num[i])
if sum%==0:
  print("Yes")
else:
  print("No")

Fixed submission:
import math
n,x,t = map(int,input().split())
c = t*math.ceil(n/x)
print(c)

Buggy python submission (verdict: Runtime Error):
x = input()
le = len(x)
sum = 0
for i in range(le):
  sum+=int(x[i])
print(sum)


Fixed submission:
import math
n,x,t = map(int,input().split())
c = t*math.ceil(n/x)
print(c)
Buggy python submission (verdict: Runtime Error):
x = inoput()
le = len(x)
sum = 0
for i in range(le):
  sum+=int(x[i])
print(sum)

Fixed submission:
num = input()
le = len(num)
sum=0
for i in range(le):
  sum += int(num[i])
if sum%9==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, m , k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(1, n+1):
    a[i] += a[i-1]
for i in range(1, m+1):
    b[i] += b[i-1]

ans = 0

for a_cnt in range(n+1):
    if a[a_cnt] > k:
        continue

    b_cnt = 0
    while b_cnt < m and a[a_cnt] + b[b_cnt + 1] <= k:
        b_cnt += 1
    ans = max(ans, a_cnt+b_cnt)

print(ans)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sa = [0] * (n+1)
sb = [0] * (m+1)
r = m
ans = 0

for i in range(n):
    sa[i+1] = sa[i] + a[i]
for i in range(m):
    sb[i+1] = sb[i] + b[i]

for i in range(n+1):
    if sa[i] > k:
        break
    while sa[i] + sb[r] > k:
        r -= 1
    ans = max(ans, i+r)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a_lsit = list(map(int, input().split()))
b_list = list(map(int, input().split()))

i = 0
j = 0
ans = 0

while k >= 0:
    if i <= n-1 and j <= m-1:
        k -= min(a_lsit[i], b_list[j])
        if a_lsit[i] < b_list[j]:
            i += 1
        else:
            j += 1
    elif i > n-1:
        k -= b_list[j]
        j += 1
    elif j > m-1:
        k -= a_lsit[i]
        i += 1

    if k < 0:
        break

    ans += 1
    
print(ans)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sa = [0] * (n+1)
sb = [0] * (m+1)
r = m
ans = 0

for i in range(n):
    sa[i+1] = sa[i] + a[i]
for i in range(m):
    sb[i+1] = sb[i] + b[i]

for i in range(n+1):
    if sa[i] > k:
        break
    while sa[i] + sb[r] > k:
        r -= 1
    ans = max(ans, i+r)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
change_list = [list(map(int, input().split())) for _ in range(q)]

cnt = [0] * 10**5
tot = sum(a_list)

for i in range(n):
    cnt[a_list[i]] += 1
#print(cnt)

for j in range(q):
    tot += cnt[change_list[j][0]] * (change_list[j][1]-change_list[j][0])
    cnt[change_list[j][1]] += cnt[change_list[j][0]]
    cnt[change_list[j][0]] = 0
    print(tot)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
change_list = [list(map(int, input().split())) for _ in range(q)]

cnt = [0] * 10**6
tot = sum(a_list)

for i in range(n):
    cnt[a_list[i]] += 1
#print(cnt)

for j in range(q):
    tot += cnt[change_list[j][0]] * (change_list[j][1]-change_list[j][0])
    cnt[change_list[j][1]] += cnt[change_list[j][0]]
    cnt[change_list[j][0]] = 0
    print(tot)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))

ans = a_list[0]

for i in range(1, n):
    ans *= a_list[i]

if ans > 10**18:
    ans = -1


print(ans)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))

ans = a_list[0]
count = a_list.count(0)

if count == 0:
    for i in range(1, n):
        ans *= a_list[i]
        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, d = map(int, input().split())
ans = 0

if a == d:
    print(a)
else:
    for _ in range(a):
        ans += 1
    
    if d-a != 0:
        for _ in range(d-a):
            ans += 0

    if d-a-b != 0:
        for _ in range(d-a-b):
            ans += -1
    
    print(ans)

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

if a >= d:
    print(d*1)
elif a < d:
    if d-(a+b) <= 0:
        print(a)
    elif d-(a+b+c) <= 0:
        print(a + (d-a-b)*(-1))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

all_vote = sum(A)

cnt = 0

for a in A:
        if a * 4 * m >= all_vote
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Fixed submission:
n, m = map(int, input().split())
A = list(map(int, input().split()))

all_vote = sum(A)

cnt = 0

for a in A:
    #if a >= all_vote / (4*m):
    if a * 4 * m >= all_vote:   #小数になる可能性をなくした
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

all_vote = sum(A)

cnt = 0

for a in A:
        if a * 4 * m >= all_vote    #小数になる可能性をなくした
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Fixed submission:
n, m = map(int, input().split())
A = list(map(int, input().split()))

all_vote = sum(A)

cnt = 0

for a in A:
    #if a >= all_vote / (4*m):
    if a * 4 * m >= all_vote:   #小数になる可能性をなくした
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

all_vote = sum(A)

cnt = 0

for a in A:
    #if a >= all_vote / (4*m):
    if a * 4 * m >= all_vote    #小数になる可能性をなくした
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Fixed submission:
n, m = map(int, input().split())
A = list(map(int, input().split()))

all_vote = sum(A)

cnt = 0

for a in A:
    #if a >= all_vote / (4*m):
    if a * 4 * m >= all_vote:   #小数になる可能性をなくした
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
x_list = list(map(int,input().split()))
#print(x_list)
#print(sum(x_list))
#(len(x_list))

#p = sum(x_list) // (len(x_list))
#p = (min(x_list) + max(x_list)) // 2
#print(p)

ans_list = [0] * (max(x_list)+1)

for j in range(1, max(x_list)+1):
    ans = 0
    for i in range(0, n):
        ans += (x_list[i] - j) ** 2
        #print(ans)
    ans_list[j] = ans

ans_list.remove(0)
print(min(ans_list))
#print(ans)n = int(input())
x_list = list(map(int,input().split()))
#print(x_list)
#print(sum(x_list))
#(len(x_list))

#p = sum(x_list) // (len(x_list))
#p = (min(x_list) + max(x_list)) // 2
#print(p)

ans_list = [0] * (max(x_list)+1)

for j in range(1, max(x_list)+1):
    ans = 0
    for i in range(0, n):
        ans += (x_list[i] - j) ** 2
        #print(ans)
    ans_list[j] = ans

ans_list.remove(0)
print(min(ans_list))
#print(ans)

Fixed submission:
n = int(input())
x_list = list(map(int,input().split()))

ans_list = [0] * (max(x_list)+1)

for j in range(1, max(x_list)+1):
    ans = 0
    for i in range(0, n):
        ans += (x_list[i] - j) ** 2
    ans_list[j] = ans

ans_list.remove(0)
print(min(ans_list))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

ans = 0

for i in range(n):
    if p[i] <= min(p[0:i+1]):
        ans += 1

print(ans)

Fixed submission:
N = int(input())
P = [int(x) for x in input().split()]
cnt=1
tmp=P[0]
for i in range(1, N):
    tmp = min(tmp, P[i-1])
    if tmp >= P[i]:
        cnt+=1
#         print(i, cnt)
        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
#print(p)

ans = 0

#for i in range(1, n+1):
#    cnt = 0
#    for j in (1, i):
#        if p[i] <= p[j]:
#            cnt += 1
#            print(cnt)
#    if cnt == i:
#        ans += 1

for i in range(n):
    #q = p[0:i+1]
    #print(q)
    if p[i] <= min(p[0:i+1]):
        ans += 1

print(ans)

Fixed submission:
N = int(input())
P = [int(x) for x in input().split()]
cnt=1
tmp=P[0]
for i in range(1, N):
    tmp = min(tmp, P[i-1])
    if tmp >= P[i]:
        cnt+=1
#         print(i, cnt)
        
print(cnt)

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

ans = 0

for i in range(n):
    q = p[0:i+1]
    if p[i] <= min(q):
        ans += 1

print(ans)

Fixed submission:
N = int(input())
P = [int(x) for x in input().split()]
cnt=1
tmp=P[0]
for i in range(1, N):
    tmp = min(tmp, P[i-1])
    if tmp >= P[i]:
        cnt+=1
#         print(i, cnt)
        
print(cnt)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while True:
        a, b = b, a%b
        if b == 0:
            return

def lcm(a, b):
    return int((a*b) // gcd(a, b))

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

print(lcm(a, b))

Fixed submission:
A, B = map(int, input().split())
import fractions

print(int(A*B/fractions.gcd(A,B)))

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

def lcm(a, b):
    return int((a*b) // math.gcd(a, b))

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

print(lcm(a, b))

Fixed submission:
A, B = map(int, input().split())
import fractions

print(int(A*B/fractions.gcd(A,B)))

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

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

print((a*b) // math.gcd(a, b))

Fixed submission:
A, B = map(int, input().split())
import fractions

print(int(A*B/fractions.gcd(A,B)))

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

def lcm(a, b):
    return (a*b) // math.gcd(a, b)

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

print(lcm(a, b))

Fixed submission:
A, B = map(int, input().split())
import fractions

print(int(A*B/fractions.gcd(A,B)))

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

#最小公倍数を求める
def lcm(a, b):
    return (a*b) // math.gcd(a, b)

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

print(lcm(a, b))

Fixed submission:
A, B = map(int, input().split())
import fractions

print(int(A*B/fractions.gcd(A,B)))

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

#最小公倍数を求める
def lcm(a, b):
    return (a*b) // math.gcd(a, b)

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

print(lcm(a, b))

Fixed submission:
A, B = map(int, input().split())
import fractions

print(int(A*B/fractions.gcd(A,B)))
Buggy python submission (verdict: Runtime Error):
import sys

n = int(input())

for i in range(1, 10):
    for j in range(1, 10):
        if i*j == n:
            print("Yes")
            sys.exit(1)
print("No")

Fixed submission:
n = int(input())
ans = 0

if n >= 82:
    print("No")
else:
    for i in range(1 , 10):
        ans = n // i
        if n == ans*i and ans <= 9:
            print("Yes")
            break
        elif i == 9:
            print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(input())
a = 1
b = 1
tmp_ans = 0
ans = 10**10

if is_prime(n) == True:
    print(n - 1)
elif is_prime(n) == False:
    for i in range(2, n):
        j = n // i
        if n == i*j:
            tmp_ans = (i-a) + (j-b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)


Fixed submission:
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(input())
a = 1
b = 1
tmp_ans = 0
ans = 10**12

if is_prime(n) == True:
    print(n - 1)
elif is_prime(n) == False:
    for i in range(2, int(math.sqrt(n))+1):
        j = n // i
        if n == i*j:
            tmp_ans = (i-a) + (j-b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(input())
a = 1
b = 1
tmp_ans = 0
ans = 10**10

if is_prime(n) == True:
    print(n - 1)
elif is_prime(n) == False:
    for i in range(2, n):
        j = n // i
        if n == i*j:
            tmp_ans = (i-a) + (j-b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)


Fixed submission:
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(input())
a = 1
b = 1
tmp_ans = 0
ans = 10**12

if is_prime(n) == True:
    print(n - 1)
elif is_prime(n) == False:
    for i in range(2, int(math.sqrt(n))+1):
        j = n // i
        if n == i*j:
            tmp_ans = (i-a) + (j-b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0] + list(map(int, input().split()))

for i in range(1, n+1):
    print(a.index(i), end=' ')

Fixed submission:
n = int(input())
a = [0] + list(map(int,input().split()))

ans = [0] * n
for i in range(1, n+1):
    ans[a[i] - 1] = i

print(" ".join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

for i in range(1, n):
    ans += i

print(ans)

Fixed submission:
n = int(input())

print(n*(n-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

for i in range(n):
    ans += i

print(ans)

Fixed submission:
n = int(input())

print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
if a2 == 0 or b2 == 0:
    ans = 0
else:
    tmp = str(a2*b2)
    l = len(tmp)
    ans = int(tmp[0:l-2])
print(ans)


Fixed submission:
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
if a2 == 0 or b2 == 0:
    ans = 0
else:
    tmp = str(a2*b2)
    l = len(tmp)
    if l <= 2:
        ans = 0
    else:
        ans = int(tmp[0:l-2])
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
if b2 == 0:
    ans = 0
else:
    tmp = str(a2*b2)
    l = len(tmp)
    ans = int(tmp[0:l-2])
print(ans)

Fixed submission:
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
if a2 == 0 or b2 == 0:
    ans = 0
else:
    tmp = str(a2*b2)
    l = len(tmp)
    if l <= 2:
        ans = 0
    else:
        ans = int(tmp[0:l-2])
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
tmp = str(a2*b2)
l = len(tmp)
ans = int(tmp[0:l-2])
print(ans)

Fixed submission:
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
if a2 == 0 or b2 == 0:
    ans = 0
else:
    tmp = str(a2*b2)
    l = len(tmp)
    if l <= 2:
        ans = 0
    else:
        ans = int(tmp[0:l-2])
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
tmp = str(a2*b2)
l = len(tmp)
ans = int(tmp[0:l-2])
print(ans)

Fixed submission:
a,b = map(str,input().split())
a2 = int(a)
b2 = 100*int(b[0:1])+10*int(b[2:3])+int(b[3:4])
if a2 == 0 or b2 == 0:
    ans = 0
else:
    tmp = str(a2*b2)
    l = len(tmp)
    if l <= 2:
        ans = 0
    else:
        ans = int(tmp[0:l-2])
print(ans)
Buggy python submission (verdict: Runtime Error):
w,s = list(map,int(input().split()))
if w >= s:
    print('unsafe')
else:
    print('safe')

Fixed submission:
s,w = list(map(int,input().split()))
if w >= s:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1:
                if s[2*j-i] not in(s[i],s[j]):
                    cnt -= 1
print(cnt)


Fixed submission:
n = input()
output = 'No'
if n[0] == '7' or n[1] == '7' or n[2] == '7':
    output = 'Yes'
print(output)
Buggy python submission (verdict: Time Limit Exceeded):
x,n = list(map(int,input().split()))
while x >= n:
    x -= n
print(min(x,n-x))

Fixed submission:
x,n = list(map(int,input().split()))
x = x % n
print(min(x,n-x))
Buggy python submission (verdict: Runtime Error):
a = input()
if a = 'AAA' or 'BBB':
  print('No')
else:
  print('Yes')

Fixed submission:
a = input()
if a in ('AAA','BBB'):
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
N = [input() for i in range(1)]
str = [input() for i in range(1)]
STRING=str[0]
enc = ""

for i in list(STRING):
    ASCII = ord(i)
    num = ASCII - 65
    num = (num + int(N[0])) % 26
    ASCII = num + 65
    enc += chr(ASCII)
print(enc)

Fixed submission:
str = [input() for i in range(1)]

if str[0] == "SUN":
    print(7)
if str[0] == "MON":
    print(6)
if str[0] == "TUE":
    print(5)
if str[0] == "WED":
    print(4)
if str[0] == "THU":
    print(3)
if str[0] == "FRI":
    print(2)
if str[0] == "SAT":
    print(1)
Buggy python submission (verdict: Runtime Error):
j = 1
a = 0
i = 0
N = 0

N = int(input())

#N=int(input())
mylist = [0]*N

h = [int(x) for x in input().split()]

for i in range(N):
    mylist[h[i]-1]=i+1
print(*mylist)

Fixed submission:
X = int(input())
a = 0
i =1
for i in range(X):
    if i%2==0:
        a = a+1
print(a/X)
Buggy python submission (verdict: Runtime Error):
j = 0
a = 0
i = 0
mylist = []
for i in range(N):
    mylist.insert(i, 0)
N=int(input())
h = [int(x) for x in input().split()]
   
for i in range(N):
    mylist[h[i]-1]=i+1
    
print(*mylist)

Fixed submission:
j = 1
a = 0
i = 0
N = 0


#N = int(input()) for _ in range(1)
A = [int(input()) for _ in range(1)]
#N=int(input())
mylist = [0]*A[0]

h = [int(x) for x in input().split()]

for i in range(A[0]):
    mylist[h[i]-1]=i+1
print(*mylist)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

sum=0
for i in range(N-1):
    for j in range(i+1,N):
        sum+=(A[i]*A[j])%(10**9+7)

print(sum%(10**9+7))


Fixed submission:
d,t,s=map(int,input().split())

if d <= t*s:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
if len(s)==len(t):
    mc=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            mc=c+1
else:
    c=[0 for i in range(len(s)-len(t))]
    for i in range(len(s)-len(t)):
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                c[i]=c[i]+1

    mc=min(c)

print(mc)


Fixed submission:
s=input()
t=input()
if len(s)==len(t):
    cm=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            cm+=1
else:
    cm=1000
    for i in range(len(s)-len(t)):
        cn=0
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                cn+=1
        cm=min(cm,cn)

print(cm)

Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
if len(s)==len(t):
    c=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            c=c+1
else:
    c=[0 for i in range(len(s)-len(t))]
    for i in range(len(s)-len(t)):
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                c[i]=c[i]+1

print(min(c))


Fixed submission:
s=input()
t=input()
if len(s)==len(t):
    cm=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            cm+=1
else:
    cm=1000
    for i in range(len(s)-len(t)):
        cn=0
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                cn+=1
        cm=min(cm,cn)

print(cm)

Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
c=[0 for i in range(len(s)-len(t))]
for i in range(len(s)-len(t)):
    for j in range(len(t)):
        if s[i+j]!=t[j]:
            c[i]=c[i]+1

print(min(c))

Fixed submission:
s=input()
t=input()
if len(s)==len(t):
    cm=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            cm+=1
else:
    cm=1000
    for i in range(len(s)-len(t)):
        cn=0
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                cn+=1
        cm=min(cm,cn)

print(cm)
Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())

A=[list('X'+input()+'X') for i in range(H)]
A.append('X'*(W+2))
A.insert(0,'X'*(W+2))
d=[[0,1],[0,-1],[1,0],[-1,0]]
wnum=0
blis=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j]=='.':
            wnum+=1
        if A[i][j]=='#':
            blis.append([i,j])

if wnum==0:
    print(0)
    exit()

ans=0
wtob=0
while len(blis):
    ans+=1
    nblis=[]
    for p in blis:
        for v in d:
            ny=p[0]+v[0]
            nx=p[1]+v[1]
            if A[ny][nx]=='.':
                A[ny][nx]='#'
                nblis.append([ny,nx])
                wtob+=1
    if wtob==wnum:
        print(ans)
        exit()
    blis=[]
    for i in nblis:
        blis.append(i)


Fixed submission:
H,W=map(int,input().split())

A=[list('X'+input()+'X') for i in range(H)]
A.append('X'*(W+2))
A.insert(0,'X'*(W+2))
d=[[0,1],[0,-1],[1,0],[-1,0]]
wnum=0
blis=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j]=='.':
            wnum+=1
        if A[i][j]=='#':
            blis.append([i,j])

if wnum==0:
    print(0)
    exit()

ans=0
wtob=0
while len(blis):
    ans+=1
    nblis=[]
    for p in blis:
        for v in d:
            ny=p[0]+v[0]
            nx=p[1]+v[1]
            if A[ny][nx]=='.':
                A[ny][nx]='#'
                nblis.append([ny,nx])
                wtob+=1
    if wtob==wnum:
        print(ans)
        exit()
    blis=[]
    for i in nblis:
        blis.append(i)