Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n=int(input())
p=1
for i in range(n):
  p*=i+1
print(p%(10**9+7))  

### FIXED CODE ###

import math
n=int(input())
print(math.factorial(n)%(10**9+7))
### BUGGY CODE ###

n = input()
A = input().split(' ')
A.sort()
A.reverse()
q = input()
M = input().split(' ')

A = list(map(int,A))
M = list(map(int,M))
A.sort()

A_sum = [0]
for a in A:
    A_sum.append(a+A_sum[-1])

A.reverse()


#memo = [True]*(len(A))

def search(base, m, n):
    if base == m:
        return True
    result = False
    for i in range(n,len(A)):
        if base + A[i] <= m: # and memo[i]:
#           memo[i] = False
#           print(str(A[i]) + ',' + str(base+A[i]) + ',')
            if search(base+A[i], m, i+1):
                return True
#           memo[i] = True
    return result

def print_yn(result):
    if result:
        print('yes')
    else:
        print('no')

for m in M:
#   print(str(m)+':')
    print_yn(search(0,m,0))

### FIXED CODE ###

n = input()
A = input().split(' ')
A.sort()
A.reverse()
q = input()
M = input().split(' ')

A = list(map(int,A))
M = list(map(int,M))
A.sort()

A_sum = [0]
for a in A:
    A_sum.append(a+A_sum[-1])
A_sum.pop(0)

A.reverse()
A_sum.reverse()


#memo = [True]*(len(A))

def search(base, m, n):
    if base == m:
        return True
    if len(A)-1 < n or m - base > A_sum[n]:
        return False
    result = False
    for i in range(len(A)-1,n-1,-1):
        if base + A[i] <= m: # and memo[i]:
#           memo[i] = False
#           print(str(A[i]) + ',' + str(base+A[i]) + ',')
            if search(base+A[i], m, i+1):
                return True
#           memo[i] = True
    return result

def print_yn(result):
    if result:
        print('yes')
    else:
        print('no')

for m in M:
#   print(str(m)+':')
    print_yn(search(0,m,0))
### BUGGY CODE ###

import sys

input = sys.stdin.readline


def cnt(i, oya_i):
    if len(ko[i]) == 1 and oya_i:
        return 1
    if memo[i][oya_i] != 0:
        return memo[i][oya_i]
    re = 1
    for ko_i in ko[i]:
        if ko_i == oya_i: continue
        re *= (cnt(ko_i, i) + 1)
    memo[i][oya_i] = re
    return re


def f(n, m):
    for _ in range(n - 1):
        x, y = map(int, input().split())
        ko[x] += [y]
        ko[y] += [x]
    for start_i in range(1, n + 1):
        print(cnt(start_i, 0) % m)


n, m = map(int, input().split())
memo = [[0] * (n + 1) for _ in range(n + 1)]
ko = [[] for _ in range(n + 1)]
f(n, m)


### FIXED CODE ###

from collections import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

n, m = MI()
to = defaultdict(list)
# dp[u][v] uを根としたときのサブツリーvの値
dp = {}

def dfs(u=0, pu=-1):
    res = 1
    for v in to[u]:
        if v == pu: continue
        res *= dfs(v, u) + 1
        res %= m
    if pu != -1: dp[(pu,u)] = res
    return res

def main():
    for _ in range(n - 1):
        x, y = map(int1, input().split())
        to[x].append(y)
        to[y].append(x)
    dfs()
    # bfsでdfsとは逆向きのdpを完成させる
    que = deque()
    que.append([0, -1])
    while que:
        u, pu = que.popleft()
        tn = len(to[u])
        # 累積積のための配列
        ll = [0] * tn
        rr = [0] * tn
        # uのサブツリーの値+1を入れる
        for i, v in enumerate(to[u]):
            ll[i] = rr[i] = dp[(u,v)] + 1
        # 左右から累積積を作る
        for i in range(1, tn):
            ll[i] = (ll[i - 1] * ll[i]) % m
            rr[tn - 1 - i] = (rr[tn - i] * rr[tn - 1 - i]) % m
        # 配列の最初or最後のために最後に1を追加
        ll += [1]
        rr += [1]
        # uの子vを根とみたときのサブツリーuの値を求める
        for i, v in enumerate(to[u]):
            if v == pu: continue
            dp[(v,u)] = (ll[i - 1] * rr[i + 1]) % m
            que.append([v, u])
    # p2D(dp)
    # 各頂点について答えを出す
    for u in range(n):
        ans = 1
        for v in to[u]:
            ans = (ans * (dp[(u,v)] + 1)) % m
        print(ans)

main()
### BUGGY CODE ###

S = list(input())
 
f = True
cnt = 0
while f:
  f = False
  for i in range(len(S)-1):
    if S[i]=='B' and S[i+1]=='W':
      S[i] = 'W'
      S[i+1] = 'B'
      cnt += 1
      f = True
print(cnt)

### FIXED CODE ###

S = input()
W = []
 
for i, s in enumerate(S):
  if s == 'W':
    W.append(i)

idx = 0
ans = 0
for w in W:
  ans += w-idx
  idx += 1

print(ans)
### BUGGY CODE ###

def solve():
    S = input()
    T = input()
    len_t = len(T)
    len_s = len(S)
    dp = [[0] * (len_t + 1) for _ in range(len_s + 1)]
    for i, s in enumerate(S):
        pre_dp = 0
        pre_dp_i = dp[i][0]
        for j, (t, dp_i) in enumerate(zip(T, dp[i][1:])):
            pre_dp = max((pre_dp_i + 1) * (s == t),
                         dp_i,
                         pre_dp)
            dp[i + 1][j + 1] = pre_dp
            pre_dp_i = dp_i
    res = ''
    while len_t > 0 and len_s > 0:
        current = dp[len_s][len_t]
        if current == dp[len_s - 1][len_t]:
            len_s -= 1
        elif current == dp[len_s][len_t - 1]:
            len_t -= 1
        else:
            res = S[len_s - 1] + res
            len_s -= 1
            len_t -= 1
    return res


if __name__ == "__main__":
    answer = solve()
    print(answer)


### FIXED CODE ###

def solve():
    S = input()
    T = input()
    len_t = len(T)
    len_s = len(S)
    dp = [[0] * (len_t + 1) for _ in range(len_s + 1)]
    for i, s in enumerate(S):
        pre_dp_i = dp[i]
        dp_i = dp[i+1]
        for j, t in enumerate(T):
            tmp_dp = max((pre_dp_i[j] + 1) * (s == t),
                         pre_dp_i[j+1],
                         dp_i[j])
            dp_i[j+1] = tmp_dp
    res = ''
    while len_t > 0 and len_s > 0:
        current = dp[len_s][len_t]
        if current == dp[len_s - 1][len_t]:
            len_s -= 1
        elif current == dp[len_s][len_t - 1]:
            len_t -= 1
        else:
            res = S[len_s - 1] + res
            len_s -= 1
            len_t -= 1
    return res


if __name__ == "__main__":
    answer = solve()
    print(answer)
### BUGGY CODE ###

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N,K=MI()
    a=LI()#下位の連続するn枚が不要なはず
    a.sort()
                    
                    
    #x番目の数が必要かどうかの判定 
    #必要なものだけで構成された集合をもとに考えれば良いわけではない，不必要な分も考えなければならない             
    def ch(x):
        if a[x]>=K:
            return True
        else:
            #使い回す，i番目まででjが作れるか
            dp=[False]*K
            dp[0]=True
            for i in range(N):
                if i==x:
                    continue
                else:
                    for j in range(K-1,-1,-1):
                        jj=j-a[i]
                        if jj>=0:
                            if dp[jj]:
                                dp[j]=True
                    
                            
            #K未満K-a[x]以上が作れれば良い    
            for j in range(K-a[x],K):
                if  dp[j]:
                    return True
            return False
                
            
            
        return False
    
                        
    ng=-1
    ok=N
    while abs(ok-ng)>1:
        med=(ok+ng)//2
        
        if ch(med):
            ok=med
        else:
            ng=med
            
    print(ng+1)
    
    
   
    
            
    
    
    

main()


### FIXED CODE ###

def main():
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    
    N,K=MI()
    a=LI()#下位の連続するn枚が不要なはず
    a.sort()
    for i in range(N):#K以上ならば必要
        if a[i]>=K:
            a=a[:i]
            break
    N=len(a)
                    
                    
    #x番目の数が必要かどうかの判定 
    #必要なものだけで構成された集合をもとに考えれば良いわけではない，不必要な分も考えなければならない             
    def ch(x):
        
        #使い回す，i番目まででjが作れるか
        dp=[0]*K
        dp[0]=1
        for i in range(N):
            if i==x:
                continue
            else:
                for j in range(K-1,a[i]-1,-1):
                    dp[j]|=dp[j-a[i]]
                
                        
        #K未満K-a[x]以上が作れれば良い    
        for j in range(K-a[x],K):
            if  dp[j]:
                return True
        return False
            
    
                        
    ng=-1
    ok=N
    while abs(ok-ng)>1:
        med=(ok+ng)//2
        
        if ch(med):
            ok=med
        else:
            ng=med
            
    print(ng+1)
    
    
 
    

main()
### BUGGY CODE ###

import queue
N,X,Y=map(int,input().split())
X -= 1
Y -= 1
INF = 1001001001
ans=[0]*N
def push(v, d):
  if dist[v]!= INF:
    return
  dist[v]=d
  q.put(v)

for sv in range(N):
  q=queue.Queue()
  dist=[INF]*N
  push(sv,0)
  while(not q.empty()):
    v=q.get()
    d=dist[v]
    if v-1 >= 0:
      push(v-1, d+1)
    if v+1 < N:
      push(v+1,d+1)
    if v==X:
      push(Y,d+1)
    if v==Y:
      push(X,d+1)
  for i in range(N):
    ans[dist[i]] +=1
for i in range(1,N):
  print(int(ans[i]/2))

### FIXED CODE ###

import queue
N,X,Y=map(int,input().split())
X-=1
Y-=1
ans=[0]*N
for i in range(N-1):
  for j in range(i+1,N):
    ans[min(j-i, abs(X-i)+1+abs(Y-j))]+=1
for i in range(1,N):
  print(ans[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
xyz = [[int(x) for x in input().split()] for _ in range(n)]

dp = [[[0, 0, 0] for _ in range(n + 1)] for _ in range(n)]

for i in range(n):
    for j in range(1, i + 2):
        if i != 0:
            dp[i][j] = dp[i - 1][j]
            for k in range(i):
                x = dp[k][j - 1][0] + xyz[i][0]
                y = dp[k][j - 1][1] + xyz[i][1]
                z = dp[k][j - 1][2] + xyz[i][2]     
                if abs(x) + abs(y) + abs(z) >= abs(dp[i][j][0]) + abs(dp[i][j][1]) + abs(dp[i][j][2]):
                    dp[i][j] = [x, y, z]
        else:
            dp[0][1] = xyz[i]

a, b, c = dp[-1][m]

print(abs(a) + abs(b) + abs(c))

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
xyz = [[int(x) for x in input().split()] for _ in range(n)]

ans = 0

for i in range(8):
    i_bin = bin(i)[2:].zfill(3)
    new_xyz_sum = []
    for j in range(n):
        tmp = 0
        x, y, z = xyz[j]
        if i_bin[0] == "0":
            x *= -1
        if i_bin[1] == "0":
            y *= -1
        if i_bin[2] == "0":
            z *= -1
        tmp = x + y + z
        new_xyz_sum.append(tmp)
    new_xyz_sum = sorted(new_xyz_sum, reverse=True)
    ans = max(ans, sum(new_xyz_sum[:m]))

print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
ans = []
import re
for i in range(Q):
    l, r = map(int, input().split())
    ans.append(len(re.findall("AC", S[l-1:r])))
for i in ans:
    print(i)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
C = [0] * len(S)
for i, c in enumerate(S):
    if i != 0 and c == 'C' and S[i-1] == 'A':
        C[i] += 1
    C[i] += C[i - 1]
ans = []
for i in range(Q):
    l, r = map(int, input().split())
    ans.append(C[r-1] - C[l-1])
for i in ans:
    print(i)
### BUGGY CODE ###

mNM = map(int, input().split())
lNM = list(mNM)

mWay = [map(int, input().split()) for i in range(lNM[1])]
lWay = [list(mWay[i]) for i in range(lNM[1])]

maps = [-1 for i in range(lNM[0])]
deep = [-1 for i in range(lNM[0])]
ways = [[] for i in range(lNM[0])]

for i in range(lNM[1]):
    ways[lWay[i][0] - 1].append(lWay[i][1])
    ways[lWay[i][1] - 1].append(lWay[i][0])

maps[0] = 0
deep[0] = 0

for i in range(lNM[0]):
    try:
        index = [n for n, v in enumerate(deep) if v == i]
        if(index == []):
            break
        
        for x in index:
            for w in ways[x]:
                if(deep[w - 1] == -1):
                    deep[w - 1] = i + 1
                    maps[w - 1] = x + 1
        
    except:
        pass
    
if(-1 in maps):
    print('No')
else:
    print('Yes')
    for i in maps[1:]:
        print(i)

### FIXED CODE ###

mNM = map(int, input().split())
lNM = list(mNM)

mWay = [map(int, input().split()) for i in range(lNM[1])]
lWay = [list(mWay[i]) for i in range(lNM[1])]

maps = [-1 for i in range(lNM[0])]
deep = [-1 for i in range(lNM[0])]
ways = [[] for i in range(lNM[0])]

for i in range(lNM[1]):
    ways[lWay[i][0] - 1].append(lWay[i][1])
    ways[lWay[i][1] - 1].append(lWay[i][0])

maps[0] = 0
deep[0] = 0
nexts = [0]

for i in range(lNM[0]):
    try:
        index = nexts     
        nexts = []
        
        for x in index:
            for w in ways[x]:
                if(deep[w - 1] == -1):
                    deep[w - 1] = i + 1
                    maps[w - 1] = x + 1
                    nexts.append(w - 1)
        
    except:
        pass
    
if(-1 in maps):
    print('No')
else:
    print('Yes')
    for i in maps[1:]:
        print(i)
### BUGGY CODE ###

def swap(a, b):
    tmp = a
    a = b
    b = tmp

    return a, b

def main():
    N = int(input())
    field = list(map(int, input().split()))

    dpList = [0] * N
    presentedDpList = [0] * N

    for i in range(N):
        dpList, presentedDpList = swap(dpList, presentedDpList)

        for j in range(i, N):
            if j == 0:
                dpList[j] = 0
            elif j == 1:
                dpList[j] = presentedDpList[j - 1] + abs(field[j] - field[j - 1])
            else:
                dpList[j] = min([presentedDpList[j - 1] + abs(field[j] - field[j - 1]), presentedDpList[j - 2] + abs(field[j] - field[j - 2])])

    print(dpList[-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N = int(input())
    field = list(map(int, input().split()))

    dpList = [0] * N
    dpList[1] = abs(field[0] - field[1])

    for i in range(2, N):
        dpList[i] = min([dpList[i - 1] + abs(field[i] - field[i - 1]), dpList[i - 2] + abs(field[i] - field[i - 2])])
        
    print(dpList[-1])

if __name__ == "__main__":
    main()
### BUGGY CODE ###

h, w = map(int, input().split())
grid = [['#' for i in range(w+2)]]
for i in range(h):
  grid.append(['#'] + [s for s in str(input())] + ['#'])
grid.append(['#' for i in range(w+2)])

U = [[0 for j in range(w+2)] for i in range(h+2)]
D = [[0 for j in range(w+2)] for i in range(h+2)]
L = [[0 for j in range(w+2)] for i in range(h+2)]
R = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    U[i][j] = U[i-1][j] + 1
    L[i][j] = L[i][j-1] + 1
for i in range(h, 0, -1):
  for j in range(w, 0, -1):
    if grid[i][j] == '#': continue
    D[i][j] = D[i+1][j] + 1
    R[i][j] = R[i][j+1] + 1

ans = 0
for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    cnt = U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3
    ans = max(ans, cnt)
    #print(i, j, cnt)
print(ans)

### FIXED CODE ###

h, w = map(int, input().split())
grid = [['#' for i in range(w+2)]]
for i in range(h):
  grid.append(['#'] + [s for s in str(input())] + ['#'])
grid.append(['#' for i in range(w+2)])

ud = [[0 for j in range(w+2)] for i in range(h+2)]
lr = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue

    if ud[i-1][j] > 0:
      ud[i][j] = ud[i-1][j]
    else:
      cnt = 0
      d = i
      while grid[d][j] != '#':
        cnt += 1
        d += 1
      ud[i][j] = cnt

    if lr[i][j-1] > 0:
      lr[i][j] = lr[i][j-1]
    else:
      cnt = 0
      r = j
      while grid[i][r] != '#':
        cnt += 1
        r += 1
      lr[i][j] = cnt

ans = 0
for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    cnt = ud[i][j] + lr[i][j] - 1
    ans = max(ans, cnt)
    #print(i, j, cnt)
print(ans)
### BUGGY CODE ###

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

maxvalue = 0
for i in range(N+1-K):
  number_sum = sum(numbers[i:i+K])
  if number_sum > maxvalue:
    maxvalue = number_sum
    
answer = (maxvalue + K) / 2
print(answer)

### FIXED CODE ###

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

mx = sum(p[:K])
cur = mx
for i in range(N-K):
  cur = cur-p[i]+p[i+K]
  mx = max(mx, cur)
  
ans = (mx+K) / 2
print(ans)
### BUGGY CODE ###

H, W = map(int, input("").split(" "))

grid = []
blacks = set()
for i in range(H):
    row = list(input(""))
    grid.append(row)

    for idx, r in enumerate(row):
        if r == "#":
            blacks.add((i, idx))

c = 0
while len(blacks) > 0:
    c += 1

    new_blacks = set()
    while len(blacks) > 0:
        b = blacks.pop()

        top = b[0] - 1
        bottom = b[0] + 1
        left = b[1] - 1
        right = b[1] + 1

        if top >= 0:
            if grid[top][b[1]] == ".":
                grid[top][b[1]] = "#"
                new_blacks.add((top, b[1]))
        if bottom < H:
            if grid[bottom][b[1]] == ".":
                grid[bottom][b[1]] = "#"
                new_blacks.add((bottom, b[1]))
        if left >= 0:
            if grid[b[0]][left] == ".":
                grid[b[0]][left] = "#"
                new_blacks.add((b[0], left))
        if right < W:
            if grid[b[0]][right] == ".":
                grid[b[0]][right] = "#"
                new_blacks.add((b[0], right))

    blacks = new_blacks

print(c - 1)


### FIXED CODE ###

H, W = map(int, input("").split(" "))

grid = []
blacks = []
for i in range(H):
    row = list(input(""))
    grid.append(row)

    for idx, r in enumerate(row):
        if r == "#":
            blacks.append((i, idx))

c = 0
while len(blacks) > 0:
    c += 1

    new_blacks = []
    for b in blacks:
        top = b[0] - 1
        bottom = b[0] + 1
        left = b[1] - 1
        right = b[1] + 1

        if top >= 0:
            if grid[top][b[1]] == ".":
                grid[top][b[1]] = "#"
                new_blacks.append((top, b[1]))
        if bottom < H:
            if grid[bottom][b[1]] == ".":
                grid[bottom][b[1]] = "#"
                new_blacks.append((bottom, b[1]))
        if left >= 0:
            if grid[b[0]][left] == ".":
                grid[b[0]][left] = "#"
                new_blacks.append((b[0], left))
        if right < W:
            if grid[b[0]][right] == ".":
                grid[b[0]][right] = "#"
                new_blacks.append((b[0], right))

    blacks = new_blacks

print(c - 1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])

S = []
for i in range(N):
    B = A.index(max(A))
    A[A.index(max(A))] -= 100000
    S.append(B+1)


for i in reversed(range(0,N)):
    print(str(S[i]) + " ")


### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))

M = []

for i in range(len(L)):
    l = (L[i], i+1)
    M.append(l)

M = sorted(M)

for x in M:
    print(x[1])
### BUGGY CODE ###

from collections import deque
 
N, M= [int(i) for i in input().split(' ')]
graph = {}
 
for i in range(1,N+1):
  graph[i] = []
 
for j in range(M):
  a, b= [int(i) for i in input().split(' ')]
  graph[a].append(b)
  graph[b].append(a)
    
 
def bfs(graph, start):
  queue = [start]
  visited1 = []
  visited = {}
  for i in range(1,N+1):
    visited[i] = 0  
  miti = {}
  for i in range(1,N+1):
    miti[i] = 0
  where_from = [start-1]
  while queue:
    label = queue.pop(0)
    label2 = where_from.pop(0)
    if visited[label]==0:
      visited1.append(label)
      visited[label]=1
      if miti[label] != 0:
        return False
      miti[label] = label2
      queue += graph.get(label, [])
      where_from += [label]*len(graph.get(label, []))
    if len(visited1) == N:
      break
  if len(visited1) != N:
    return False
  return miti
 
miti = bfs(graph, 1)
if miti:
  print('Yes')
  for i in range(2,N+1):
    print(miti[i])
else:
  print('No')

### FIXED CODE ###

N, M= [int(i) for i in input().split(' ')]
graph = {}
 
for i in range(1,N+1):
  graph[i] = []
 
for j in range(M):
  a, b= [int(i) for i in input().split(' ')]
  graph[a].append(b)
  graph[b].append(a)
    
 
def bfs(graph, start):
  queue = [start]
  miti = [-1 for _ in range(N)]

  while queue:
    label = queue.pop(0)
    for i in graph[label]:
      if miti[i-1] < 0:
        queue.append(i)
        miti[i-1] = label
  return miti
 
miti = bfs(graph, 1)
if miti:
  print('Yes')
  for i in range(2,N+1):
    print(miti[i-1])
else:
  print('No')
### BUGGY CODE ###

# 長い間考えて分からなかったけど、ようやく方針が分かった。
# 始点を複数にした幅優先探索
# 距離1の点をキューに入れる、
# 距離1の点を出しながら距離2の点をキューに入れる、
# 以下略。でできるじゃん。

h, w = list(map(int, input().split()))

masu = [input() for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

distance = [[-1 for _ in range(w)] for _ in range(h)]

from collections import deque

queue = deque([])
for i in range(h):
    for j in range(w):
        if masu[i][j] == '#':
            distance[i][j] = 0
            queue.append((i, j))

ans = 0
while True:
    if len(queue) == 0:
        break
    now = queue.popleft()
    now_h = now[0]
    now_w = now[1]
    now_distance = distance[now_h][now_w]
    # print(now_h, now_w)

    for i in range(4):
        next_h = now_h + dx[i]
        next_w = now_w + dy[i]
        if not (0 <= next_h <= h-1 and 0 <= next_w <= w-1):
            continue
        if distance[next_h][next_w] == -1:
            distance[next_h][next_w] = now_distance + 1
            queue.append((next_h, next_w))
            ans = now_distance + 1
            # print("appended {} {}".format(next_h, next_w))

print(ans)


### FIXED CODE ###

# 長い間考えて分からなかったけど、ようやく方針が分かった。
# 始点を複数にした幅優先探索
# 距離1の点をキューに入れる、
# 距離1の点を出しながら距離2の点をキューに入れる、
# 以下略。でできるじゃん。

h, w = list(map(int, input().split()))

masu = [input() for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

distance = [[-1 for _ in range(w)] for _ in range(h)]

from collections import deque

queue = deque([])
for i in range(h):
    for j in range(w):
        if masu[i][j] == '#':
            distance[i][j] = 0
            queue.append((i, j))

ans = 0
while True:
    if len(queue) == 0:
        break
    now = queue.popleft()
    now_h = now[0]
    now_w = now[1]
    now_distance = distance[now_h][now_w]
    # print(now_h, now_w)

    for i in range(4):
        next_h = now_h + dx[i]
        next_w = now_w + dy[i]
        if not (0 <= next_h <= h-1 and 0 <= next_w <= w-1):
            continue
        if distance[next_h][next_w] == -1:
            distance[next_h][next_w] = now_distance + 1
            queue.append((next_h, next_w))
            ans = now_distance + 1
            # print("appended {} {}".format(next_h, next_w))

print(ans)
### BUGGY CODE ###

x = int(input())

for i in range(-10000, 10000):
    for j in range(-10000, 10000):
        if i ** 5 - j ** 5 == x:
            a=i
            b=j

print(a, b)

### FIXED CODE ###

x = int(input())

for i in range(200):
    for j in range(-200, 200):
        if i ** 5 - j ** 5 == x:
            a=i
            b=j

print(a, b)
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))

for i in range(1,n+1):
    print(l.count(i))


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))

res=[0]*n

for i in l:
    res[i-1] +=1

for i in res:
    print(i)
### BUGGY CODE ###

n = int(input())
print(sum(range(n)))

### FIXED CODE ###

n = int(input())
 
print(int(n * (n - 1) // 2))
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(int(input()) for _ in range(M))
P = 10**9 + 7

dp = [0] * (N+1)
dp[0] = 1
dp[1] = 1 if 1 not in A else 0
for i in range(2, N+1):
    if i not in A:
        dp[i] = (dp[i-1] + dp[i-2]) % P
    else:
        dp[i] = 0
print(dp[N])

### FIXED CODE ###

N, M = map(int, input().split())
if N == 1:
    print(1)
    quit()
if M > N//2:
    print(0)
    quit()

A = list(int(input()) for _ in range(M))
idx = 0
P = 10**9 + 7

dp = [0] * (N+1)
dp[0] = 1
dp[1] = 1
a = -1
if len(A):
    if 1 == A[idx]:
        dp[1] = 0
        if idx < M-1:
            idx += 1

if len(A):
    for i in range(2, N+1):
        if i != A[idx]:
            dp[i] = (dp[i-1] + dp[i-2]) % P
        else:
            dp[i] = 0
            if idx < M-1:
                idx += 1
else:
    for i in range(2, N+1):
        dp[i] = (dp[i-1] + dp[i-2]) % P
print(dp[N])