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

Fixed submission:
from functools import lru_cache

import sys
sys.setrecursionlimit(1000000)

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

A = set(int(input()) for _ in range(M))

@lru_cache(None)
def dfs(pos):
    if pos > N:
        return 0
    if pos == N:
        return 1
    if pos in A:
        return 0
    return dfs(pos + 2) + dfs(pos + 1)

for i in reversed(range(N+1)):
    dfs(i)

print(dfs(0) % 1000000007)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

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

A = [int(input()) for _ in range(M)]

@lru_cache(1000)
def dfs(pos):
    if pos > N:
        return 0
    if pos == N:
        return 1
    s = 0
    if (pos + 1) not in A:
        s += dfs(pos + 1)
    if (pos + 2) not in A:
        s += dfs(pos + 2)
    return s

print(dfs(0) % 1000000007)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

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

A = [int(input()) for _ in range(M)]

# print(N, M, A)

count = 0

@lru_cache(1000)
def dfs(pos):
    if pos == N:
        return 1
    s = 0
    if (pos + 1) not in A:
        s += dfs(pos + 1)
    if (pos + 2) not in A and ((pos + 2) <= N):
        s += dfs(pos + 2)
    return s

print(dfs(0) % 1000000007)
Problem p03107 (python)

Fixed submission:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

s = [int(c) for c in s]

c = 0

ss = 0

for i in range(0, len(s)):
    if s[i] == 1:
        if ss < 0:
            c += 2
        ss += 1
    else:
        if ss > 0:
            c += 2
        ss -= 1
print(c)

Buggy submission (verdict: Runtime Error):
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

s = [int(c) for c in s]

c = 0

def fb(s, i):
    for i in reversed(range(0, i + 1)):
        if s[i] >= 0:
            return i
    return None

def ff(s, i):
    for i in range(i + 1, len(s)):
        if s[i] >= 0:
            return i
    return None

for i in range(len(s) - 1):
    j = 0
    while True:
        pos = fb(s, i - j), ff(s, i - j)
        if pos[0] is None:
            break

        if s[pos[0]] != s[pos[1]]:
            s[pos[0]] = s[pos[1]] = -1
            j += 1
            c += 2
        else:
            break

print(c)
Problem p03307 (python)

Fixed submission:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)

if n % 2 == 0:
    print(n)
else:
    print(n * 2)

Buggy submission (verdict: Runtime Error):
import math

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)

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

AA = [a - (i + 1) for i, a in enumerate(A)]

AA.sort()

if len(AA) % 2 == 0:
    b = int(len(AA) / 2 - 1)
else:
    b = int((len(AA) - 1) / 2)

sadness = 0
for i, a in enumerate(A):
    # sadness1 += abs(a - (i + b1 + 1))
    # sadness2 += abs(a - (i + b2 + 1))
    sadness += abs(a - (i + AA[b] + 1))

print(sadness)
Problem p03618 (python)

Fixed submission:
s = input()

count = 1

alphabets = {}

alphabets[s[0]] = 1

for i in range(1, len(s)):
    for char, char_count in alphabets.items():
        if char != s[i]:
            count += char_count

    if s[i] in alphabets:
        alphabets[s[i]] += 1
    else:
        alphabets[s[i]] = 1

print(count)

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

count = 1

for i in range(1, len(s)):
    ss = s[0:i]
    # print(ss, s[i])

    n = len(ss) - ss.count(s[i])
    count += n
    # print(n, count)
print(n)
Problem p02989 (python)

Fixed submission:
n = int(input())
d = [int(x) for x in input().split()]
d.sort()
print(d[int(n/2)] - d[int(n/2)-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
d = [int(x) for x in input().split()]
d.sort()
print(d[int(n / 2) + 1] - d[int(n / 2)])
Problem p02881 (python)

Fixed submission:
import numpy as np
 
N = int(input())
ans = 10**12
for i in range(int(np.sqrt(N)+0.5)):
  a = i+1
  if N % a != 0:
    continue
  step = a + int(N/a) -2
  if step < ans:
    ans = step
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
ans = 10^12
for a in range(int(np.sqrt(N))):
  if N % a != 0:
    continue
  step = a + N/a -2
  if step < ans:
    ans = step
    
print(str(ans))
Problem p03186 (python)

Fixed submission:
import sys


if __name__ == '__main__':
    # a not yum, bc yum
    a, b, c = [int(i) for i in input().split()]

    if (a+b) >= c:
        print(b+c)
    else:
        print(a+b+1+b)

Buggy submission (verdict: Runtime Error):
import sys


if __name__ == '__main__':
    # a not yum, bc yum
    a = int(sys.argv[1])
    b = int(sys.argv[2])
    c = int(sys.argv[3])

    if (a+b) >= c:
        print(b+c)
    else:
        print(a+b+1+b)

Buggy submission (verdict: Runtime Error):
import sys

# a not yum, bc yum
a = int(sys.argv[1])
b = int(sys.argv[2])
c = int(sys.argv[3])

if (a+b) >= c:
    return(b+c)
else:
    return(a+b+1+b)

Buggy submission (verdict: Runtime Error):
import sys

# a not yum, bc yum
a = int(sys.argv[1])
b = int(sys.argv[2])
c = int(sys.argv[3])

if (a+b) >= c:
    print(b+c)
else:
    print(a+b+1+b)
Problem p03265 (python)

Fixed submission:
import math
l = input().split()

x1 = int(l[0])
y1 = int(l[1])
x2 = int(l[2])
y2 = int(l[3])

yoko = x2-x1
tate = y2-y1

x3 = x2 - tate
y3 = y2 + yoko
x4 = x1 - tate
y4 = y1 + yoko

  
print(str(x3)+' '+str(y3)+' '+str(x4)+' '+str(y4))

Buggy submission (verdict: Runtime Error):
l = raw_input().split()

x1 = int(l[0])
y1 = int(l[1])
x2 = int(l[2])
y2 = int(l[3])

a = max(abs(x1-x2), abs(y1-y2))

if x1 < x2:
  x3 = x2
  y3 = y1 + a
  x4 = x1
  y4 = y1 + a
elif x1 == x2:
  if y1 > y2:
    x3 = x2 + a
    y3 = y2
    x4 = x2 + a
    y4 = y1
  else:
    x3 = x2 - a
    y3 = y2
    x4 = x2 - a
    y4 = y1
elif x1 > x2:
  x3 = x2
  y3 = y1 - a
  x4 = x1
  y4 = y1 - a
  
print(str(x3)+' '+str(y3)+' '+str(x4)+' '+str(y4))
Problem p02954 (python)

Fixed submission:
s = input()
a = [0]
answer = [0 for i in range(len(s)) ]
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        a.append(i+1)

for i in range(1,len(a),2):
    if i ==len(a)-1:
        a.append(len(s))
    if (a[i+1]-a[i-1])%2==0:
        answer[a[i]-1] = int((a[i+1]-a[i-1])//2)
        answer[a[i]] = int((a[i+1]-a[i-1])//2)
    else:
        if (a[i+1]-a[i])%2==1:
            answer[a[i]-1] = int((a[i+1]-a[i-1])//2)
            answer[a[i]] = int((a[i+1]-a[i-1])//2)+1
        else:
            answer[a[i]-1] = int((a[i+1]-a[i-1])//2)+1
            answer[a[i]] = int((a[i+1]-a[i-1])//2)

for i in range(len(answer)):
    print(answer[i])

Buggy submission (verdict: Runtime Error):
s = input()
a = [0]
answer = [0 for i in range(len(s)) ]
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        a.append(i+1)

for i in range(1,len(a),2):
    if i ==len(a)-1:
        a.append(len(s))
    if (a[i+1]-a[i-1])%2==0:
        answer[a[i]-1] = int((a[i+1]-a[i-1])//2)
        answer[a[i]] = int((a[i+1]-a[i-1])//2)
    else:
        if (a[i+1]-a[i])%2==1:
            answer[a[i]-1] = int((a[i+1]-a[i-1])//2)
            answer[a[i]] = int((a[i+1]-a[i-1])//2)+1
        else:
            answer[a[i]-1] = int((a[i+1]-a[i-1])//2)+1
            answer[a[i]] = int((a[i+1]-a[i-1])//2)

for i in range(answer):
    print(answer[i])
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
k = []
count_sub = 0
steps = []
j = 0
for i in range(m):
    k.append(int(input())) 
    if len(k)>1 and k[i]-k[i-1]==1:
        count_sub = 1
        
if count_sub ==1:
    steps = [0 for i in range(n)]  
else:
    for i in range(n+1):
        if k!=[] and k[j]==i:
            steps.append(0)
            if j < len(k)-1:
                j = j + 1
        elif i ==0:
            steps.append(1)
        elif i ==1:
            steps.append(1)  
        else:
            steps.append(steps[i-1]+steps[i-2])
 
print(steps[-1]%(1000000007))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
k = []
count_sub = 0
steps = []
j = 0
for i in range(m):
    k.append(int(input())) 
    if len(k)>1 and k[i]-k[i-1]==1:
        count_sub = 1
        
if count_sub ==1:
    steps = [0 for i in range(n)]  
else:
    for i in range(n+1):
        if k[j]==i:
            steps.append(0)
            if j < len(k)-1:
                j = j + 1
        elif i ==0:
            steps.append(1)
        elif i ==1:
            steps.append(1)  
        else:
            steps.append(steps[i-1]+steps[i-2])
 
print(steps[-1]%(1000000007))
Problem p03017 (python)

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

e = 'Yes'
f = 0
g = 1

if c < d:
    for i in range(b-1,d-1):
        if s[i]=='#' and s[i+1]=='#':
            e ='No'
    if e =='Yes':
        for j in range(a-1,b-1):
            if s[j]=='#' and s[j+1]=='#':
                e ='No'
                        
if c > d:
    for i in range(a-1,c-1):
        if s[i]=='#' and s[i+1]=='#':
            f = 1
    
    for j in range(b-2,d-1):
        if s[j]=='.' and s[j+1]=='.' and s[j+2]=='.':
            g = 0

    if g == 0 and f ==0:
        e ='Yes'
    else:
        e ='No'
            
print(e)

Buggy submission (verdict: Runtime Error):
n,a,b,c,d = map(int,input().split())
s = input().split('.')

e = 'Yes'
f = 0
g = 0

if c<d:
    for i in range(a-1,c-1):
        if s[i]=='#' and s[i+1]=='#':
            e ='No'
        else:
            for j in range(b-1,d-1):
                if s[j]=='#' and s[j+1]=='#':
                    e ='No'
                        
if c>d:
    for i in range(a-1,d-1):
        if s[i]=='#' and s[i+1]=='#':
            f =1
    
    for j in range(a-1,d-2):
        if s[j]=='' and s[j+1]=='' and s[j+2]=='':
            g = 0
        else:
            g = 1
            
if g==1 or f==1:
    e ='No'

print(e)
Problem p03127 (python)

Fixed submission:
def gcd(a,b):
    c = 0
    if a<b:
        c = b
        b = a
        a = c
    while(a%b!=0):
        c = a%b
        a = b
        b = c
    return b

n = int(input())
a = list(map(int, input().split()))
ans = a[0] 
for i in range(n):
    ans = gcd(ans,a[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))
gcd = a[0]
for i in range(n):
    gcd = math.gcd(gcd,a[i])

print(gcd)
Problem p02897 (python)

Fixed submission:
n=int(input())
cnt=0
for i in range(1,n+1):
    if i%2==1:
        cnt += 1
print(cnt/n)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split(' '))
hs = list(map(int, input().split(' ')))
print(len([h for h in hs if h >= k]))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split(' '))
hs = list(map(int, input().split(' ')))
res = 0
for i in hs:
  if i>= k:
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
arr = list(map(int,input().split()))
res = 0
for i in arr:
  if i >= m:
    res += 1
return res

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
arr = list(map(int,input().split('')))
res = 0
for i in arr:
  if i >= m:
    res += 1
return res

Buggy submission (verdict: Runtime Error):
n = int(input().split())
if n == 1:
  return double(1)
if n % 2 == 1:
  return float(n//2+1)/n
else:
  return float(1)/2
Problem p03072 (python)

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
ans,ma=0,H[0]
for i in H:
	if ma<=i:
		ans+=1
		ma=i
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input().split())
arr=list(map(int,input().split()))
res=[arr[0]]
for i in range(1,n):
  if arr[i]>=res[-1]:
    res.append(arr[i])
print(len(res))
Problem p03075 (python)

Fixed submission:
import sys

d = [int(i) for i in sys.stdin.read().split('\n') if i != '']
k = d[5]
d = d[:5][::-1]


def check(k, d):
    for i in range(len(d[:4])):
        for j in range(i, len(d)):
            if d[i] - d[j] > k:
                return False
    return True


if check(k, d):
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
import heapq
X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]

default=A[0]+B[0]+C[0]
A=[A[0]-A[i] for i in range(len(A))]
B=[B[0]-B[i] for i in range(len(B))]
C=[C[0]-C[i] for i in range(len(C))]

print(default)
hp=[]
visited=set()
visited.add((0,0,0))
a,b,c=0,0,0
for _ in range(K-1):
  if (a+1,b,c) not in visited and a+1<len(A):
    heapq.heappush(hp,(A[a+1]+B[b]+C[c],(a+1,b,c)))
    visited.add((a+1,b,c))
  if (a,b+1,c) not in visited and b+1<len(B):
    heapq.heappush(hp,(A[a]+B[b+1]+C[c],(a,b+1,c)))
    visited.add((a,b+1,c))
  if (a,b,c+1) not in visited and c+1<len(C):
    heapq.heappush(hp,(A[a]+B[b]+C[c+1],(a,b,c+1)))
    visited.add((a,b,c+1))
  temp=heapq.heappop(hp)
  print(default-temp[1])
  a,b,c=temp[2]

Buggy submission (verdict: Runtime Error):
import sys
a=[int(i) for i in sys.stdin.resd().split('\n')]
k=a[5]
a=a[:5][::-1]
def check(a,k):
  for i in range(len(a[:4])):
    for j in range(i,len(a)):
      if a[i]-a[j]>k:
        return False
  return True
if check(a,k):
  print('Yay!')
else:
  print(':(')

Buggy submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())

xlist = sorted(list(map(int,input().split())), reverse=True)[:min(x, k)]
ylist = sorted(list(map(int,input().split())), reverse=True)[:min(y, k)]
zlist = sorted(list(map(int,input().split())), reverse=True)[:min(z, k)]


anslist = [0]
for i in range(min(x, k)):
    for j in range(min(y, k)):
        for l in range(min(z, k)):
            if (i+1)*(j+1)*(l+1) <= k:
                anslist.append(xlist[i] + ylist[j] + zlist[l])
            else:
                break

anslist = sorted(anslist, reverse=True)
for i in range(k):
    print(anslist[i])

Buggy submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())
cake1=sort(list(map(int,input().split()),reverse=True))[:max(a,k)]
cake2=sort(list(map(int,input().split()),reverse=True))[:max(b,k)]
cake3=sort(list(map(int,input().split()),reverse=True))[:max(c,k)]
res=[]
for i in range(min(a,k)):
  for j in range(min(b,k)):
    for l in range(min(c,k)):
      if (a+1)*(b+1)*(c+1)<k:
        res.append(cake1[i]+cake2[j]+cake3[l])
res.sort(reverse=True)
for i in range(k):
  print(res[i])

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(6):
  a.append(int(input()))
k=a[-1]
if a[-2]-a[0]<=k:
  pring('Yay!')
else:
  print(':(')
Problem p03077 (python)

Fixed submission:
N = int(input())
abc = [int(input()) for _ in range(5)]
ans = N//min(abc)
if N%min(abc):
    ans += 1
print(ans+4)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=[]
for i in range(5):
  b.append(int(input()))
key=min(b)
res=4
t=math.ceil(a/key)
res+=t
Problem p03107 (python)

Fixed submission:
s=input()
a_1=s.count("1")
b_1=s.count("0")
if a_1<=b_1:
  print(2*a_1)
else:
  print(2*b_1)

Buggy submission (verdict: Runtime Error):
s=input()
num0,num1=0,0
for i in s:
  if i=='0':
    nums0+=1
  elif i=='1':
    nums1+=1
print(2*min(num0,num1))
Problem p03108 (python)

Fixed submission:
N, M = map(int, input().split())
a_list = []
b_list = []
for i in range(M):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

par = [i for i in range(N+1)]
rank = [0]*(N+1)
size = [1] * (N + 1)

def find(x):
    if par[x] == x:
        return par[x]
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x_par = find(x)
    y_par = find(y)
    if x_par == y_par:
        return
    if rank[x_par] < rank[y_par]:
        par[x_par] = y_par
        size[y_par] += size[x_par]
    else:
        par[y_par] = x_par
        size[x_par] += size[y_par]
        if rank[x_par] == rank[y_par]:
            rank[x_par] += 1


def bool_func(x, y):
    if find(x) == find(y):
        return True
    else:
        return False


ans_list = []      
ans = int(N*(N-1)/2)
for i in range(M):
    ans_list.append(ans)
    a = a_list[M-1-i]
    b = b_list[M-1-i]
    p = size[find(a)]
    q = size[find(b)]
    if bool_func(a, b):
        pass
    else:
        ans -= p*q
        unite(a, b)

for i in range(M):
    print(ans_list[M-1-i])

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
alist=[]
blist=[]
for i in range(M):
  a,b=map(int,input().split())
  alist.append(a)
  blist.append(b)
father=[i for i in range(N+1)]
rank=[0]*(N+1)
size=[1]*(N+1)

def find(x):
  if x!=father[x]:
    father[x]=find(father[x])
  return father[x]

def union(x,y):
  x,y=find(x),find(y)
  if x==y:
    return
  elif rank[x]<rank[y]:
    father[x]=y
    size[y]+=size(x)
  else:
    father[y]=x
    size[x]+=size[y]
    if rank[x]==rank[y]:
      rank[x]+=1
      
def samefather(x,y):
  return find(x)==find(y)

ans_list=[]
ans=N*(N-1)/2
for i in range(M):
  ans_list.append(ans)
  a=alist[M-1-i]
  b=alist[M-1-i]
  p,q=size[find(a)],size[size(b)]
  if samefather(a,b):
    continue
  else:
    ans-=p*q
    union(a,b)
for i in range(M):
  print(ans_list[M-1-i])
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(n-r,r)
    if r == 0:
      return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

  
n, k = map(int, input().split())
for i in range(1, k+1):
	if n-k+1 >= i:
		cnt = comb(n-k+1, i) * comb(k-1, i-1)
		print(cnt%(10**9+7))
	else:
		print(0)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(n-r,r)
    if r == 0:
      return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

  
n, k = map(int, input().split())
for i in range(1, k+1):
	dis = k - i
	cnt = comb(n-k+1, i)
	if i > 1:
		cnt *= comb(k-1, i-1)
	print(cnt%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, k = map(int, input().split())
for i in range(1, k+1):
	dis = k - i
	cnt = comb(n-k+1, i)
	if i > 1:
		cnt *= comb(k-1, i-1)
	print(cnt%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, k = map(int, input().split())
for i in range(1, k+1):
	dis = k - i
	cnt = comb(n-k+1, i)
	for j in range(i, 1, -1):
		cnt *= comb(j, j-dis)
	print(cnt%(10**9+7))
Problem p03038 (python)

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
a_list = list(map(int, input().split()))
m_list = []
for _ in range(m):
    b, c = map(int, input().split())
    m_list.append([c, b])
m_list.sort(reverse=True)
cnt = 0
tmp_list = []
for c, b in m_list:
    if cnt < n:
        tmp_list += [c]*b
    else:
        break
    cnt += b
a_list.extend(tmp_list)
a_list.sort(reverse=True)
print(sum(a_list[:n]))

Buggy submission (verdict: Runtime Error):
from collections import deque

n, m = map(int, input().split())
a_list = list(map(int, input().split()))
m_list = []
for _ in range(m):
    b, c = map(int, input().split())
    m_list += [c]*b
a_list.sort()
m_list.sort(reverse=True)
m_q = deque(m_list)
ans = 0
check = m_q.popleft()
cnt = 1
for a in a_list:
    if a < check:
        ans += check
        check = m_q.popleft()
        cnt += 1
        if cnt >= m:
            check = 0
    else:
        ans += a
print(ans)
Problem p03053 (python)

Fixed submission:
def bfs(q_list):
    cnt = -1
    while q_list:
        cnt += 1
        new_q_list = []
        for h, w in q_list:
            if not m_list[h][w+1]:
                m_list[h][w+1] = True
                new_q_list.append((h, w+1))
            if not m_list[h+1][w]:
                m_list[h+1][w] = True
                new_q_list.append((h+1, w))
            if not m_list[h][w-1]:
                m_list[h][w-1] = True
                new_q_list.append((h, w-1))
            if not m_list[h-1][w]:
                m_list[h-1][w] = True
                new_q_list.append((h-1, w))
        q_list = new_q_list
    print(cnt)


if __name__ == "__main__":
    h_len, w_len = map(int, input().split())
    m_list = [[True for _ in range(w_len+2)]]
    for _ in range(h_len):
        m_list.append([True] + [s=='#' for s in input()] + [True])
    m_list.append([True for _ in range(w_len+2)])
    q_list = []
    for h in range(1, h_len+1):
        for w in range(1, w_len+1):
            if m_list[h][w]:
                q_list.append((h, w))
    bfs(q_list)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque


dx_list = [1, 0, -1, 0]
dy_list = [0, -1, 0, 1]
def bfs(h_len, w_len):
    max_cnt = 0
    while len(bfs_q)>0:
        u_list = bfs_q.popleft()
        h, w, cnt = u_list[0], u_list[1], u_list[2]
        max_cnt = max(max_cnt, cnt)
        for dx, dy in zip(dx_list, dy_list):
            x = w + dx
            y = h + dy
            if 0 <= x < w_len and 0 <= y < h_len and m[y][x] == 0:
                m[y][x] = 1
                bfs_q.append([y, x, cnt+1])
    return max_cnt


if __name__ == "__main__":
    input = sys.stdin.readline
    h_len, w_len = map(int, input().split())
    m = [[0]*h_len for _ in range(w_len)]
    a_list = []
    for _ in range(h_len):
        s = input()[:-1]
        a_list.append(s)
    bfs_q = deque([])
    for h, w_list in enumerate(a_list):
        for w, a in enumerate(w_list):
    	    if a == '#':
    		    m[h][w] = 1
    		    bfs_q.append([h, w, 0])
    ans = bfs(h_len, w_len)
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

dx_list = [1, 0, -1, 0]
dy_list = [0, -1, 0, 1]
def bfs(h_len, w_len):
    cnt = 0
    while len(bfs_q)>0:
        u_list = bfs_q.popleft()
        h, w = u_list[0], u_list[1]
        tmp = m[h][w]
        for dx, dy in zip(dx_list, dy_list):
            x = w + dx
            y = h + dy
            if 0 <= x < w_len and 0 <= y < h_len and m[y][x] == -1:
                m[y][x] = tmp + 1
                cnt = max(cnt, tmp + 1)
                bfs_q.append([y, x])
    return cnt


if __name__ == "__main__":
    input = sys.stdin.readline
    h_len, w_len = map(int, input().split())
    m = [[-1]*h_len for _ in range(w_len)]
    a_list = []
    for _ in range(h_len):
        s = input()[:-1]
        a_list.append(s)
    bfs_q = deque([])
    for h, w_list in enumerate(a_list):
        for w, a in enumerate(w_list):
    	    if a == '#':
    		    m[h][w] = 0
    		    bfs_q.append([h, w])
    ans = bfs(h_len, w_len)
    print(ans)