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

import collections
from decimal import Decimal

n = int(input())
a = [Decimal(input()) for _ in range(n)]
a = [i*10**9 for i in a]
MAX = 19
p_dict = collections.defaultdict(int)

for i in a:
    b_cnt = 0
    while i % 2 == 0 and b_cnt < 18:
        i //= 2
        b_cnt += 1
    f_cnt = 0
    while i % 5 == 0 and f_cnt < 18:
        i //= 5
        f_cnt += 1
    p_dict[(b_cnt, f_cnt)] += 1

ans = 0
for b1, f1 in p_dict:
    for b2, f2 in p_dict:
        if b1+b2 >= 18 and f1+f2 >= 18:
            if b1 == b2 and f1 == f2:
                ans += p_dict[(b1, f1)] * (p_dict[(b2, f2)] - 1)
            else:
                ans += p_dict[(b1, f1)] * p_dict[(b2, f2)]
print(ans//2)

### FIXED CODE ###

import collections
from decimal import Decimal

n = int(input())
a = [Decimal(input()) for _ in range(n)]
a = [int(i*10**9) for i in a]
MAX = 19
p_dict = collections.defaultdict(int)

for i in a:
    b_cnt = 0
    while i % 2 == 0 and b_cnt < 18:
        i //= 2
        b_cnt += 1
    f_cnt = 0
    while i % 5 == 0 and f_cnt < 18:
        i //= 5
        f_cnt += 1
    p_dict[(b_cnt, f_cnt)] += 1

ans = 0
for b1, f1 in p_dict:
    for b2, f2 in p_dict:
        if b1+b2 >= 18 and f1+f2 >= 18:
            if b1 == b2 and f1 == f2:
                ans += p_dict[(b1, f1)] * (p_dict[(b2, f2)] - 1)
            else:
                ans += p_dict[(b1, f1)] * p_dict[(b2, f2)]
print(ans//2)
### BUGGY CODE ###

n=int(input())
se = set('357')
ans = 0
for i in range(1,n+1):
    s = str(i)
    ss = set(s)
    if ss == se:
        ans +=1
print(ans)
    
    

### FIXED CODE ###

n=int(input())
length = len(str(n))+1
se = set()
def moji(s):
    if len(s)>=length:
        return
    se.add(s)
    moji(s+'5')
    moji(s+'7')
    moji(s+'3')
moji('')
li=list(sorted(se))
ans = 0
for i in li:
    if i == '':
        continue
    if '3' not in i or '5' not in i or '7' not in i:
        continue
    if int(i)<=n:
        ans+=1
print(ans)
### BUGGY CODE ###

import collections as col

n = int(input())
L_W = []
for i in range(0,n):
    L_W.append(input())
 
dic = col.Counter(L_W)
dic_values_max = max(list(dic.values()))

ans = []
for i in range(len(list(dic.items()))):
    if list(dic.items())[i][1] == dic_values_max:
        ans.append(list(dic.items())[i][0])

ans.sort()
for i in ans:
    print(i)

### FIXED CODE ###

import collections as col

n = int(input())
L_W = []
for i in range(0,n):
    L_W.append(input())
 
dic = col.Counter(L_W)

dic_values_max = max(list(dic.values()))
 
max_key = [i for i, j in dic.items() if j == dic_values_max]
 
max_key.sort()
 
for k in max_key:
    print(k)
### BUGGY CODE ###

n=int(input())
s=list(input())
R=[]
G=[]
B=[]
count=0
for i in range(n):
    if s[i]=="R":
        R.append(i)
    elif s[i]=="G":
        G.append(i)
    else:
        B.append(i)
for r in R:
    for g in G:
        for b in B:
            middle=r+g+b-min(r,g,b)-max(r,g,b)
            if (middle-min(r,g,b))!=(max(r,g,b)-middle):
                count+=1

print(count)

### FIXED CODE ###

n=int(input())
s=input()
r=0
g=0
b=0
for i in s:
    if i=="R":r+=1
    elif i=="G":g+=1
    elif i=="B":b+=1
ans=r*b*g

for j in range(n):
    for i in range(j):
        k=j+(j-i)
        if k<n:
            
            if s[i]==s[j]: continue
            if s[j]==s[k]: continue
            if s[k]==s[i]: continue
            ans-=1
print(ans)
### BUGGY CODE ###

x,k,d = map(int,input().split())
an = x

if x < 0:
    x = -x

if x-d*k >= 0:
    an = x-d*k
else:
    for i in range(k):
        if x > 0:
            x -= d
        else:
            x += d
            
        if an > abs(x) or i==0:
            an = x
        else:
            if (k-i-1)%2 == 0:
                an = x
            break
        
print(abs(an))

### FIXED CODE ###

x,k,d = map(int,input().split())
an = x

if x < 0:
    x = -x

if k <= x/d:
    an = x-d*k
else:
    if (k-x//d)%2==0:
        an = x-d*(x//d)
    else:
        an = x-d*(x//d)-d
        
print(abs(an))
### BUGGY CODE ###

n=int(input())
d=[]
for i in [0]*n:
    d.append([int(x) for x in input().split()])
from itertools import product
ans=0
for i,j in product(range(n),range(n)):
    flag=0
    for k in range(n):
        if d[i][j]>d[i][k]+d[k][j]:
            print(-1)
            import sys
            sys.exit()
        if d[i][j]==d[i][k]+d[k][j] and (k!=i and k!=j and i!=j ):
            flag=1
    if flag==0:
        ans+=d[i][j]
print(ans//2)

### FIXED CODE ###

n=int(input())
d=[]
for i in [0]*n:
    d.append([int(x) for x in input().split()])
from itertools import product
ans=0
for i,j in product(range(n),range(n)):
    flag=0
    for k in range(n):
        if d[i][j]>d[i][k]+d[k][j]:
            print(-1)
            import sys
            sys.exit()
        if d[i][j]==d[i][k]+d[k][j] and (k!=i and k!=j and i!=j ):
            flag=1
    if flag==0:
        ans+=d[i][j]
print(ans//2)
### BUGGY CODE ###

from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')

### FIXED CODE ###

from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')
### BUGGY CODE ###

h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  elif seen[y][x]<=p:
    continue
  else:
    seen[y][x]=p
  ans=p
  if y-1>=0:
    que.append([y-1,x,p+1])
  if y+1<h:
    que.append([y+1,x,p+1])
  if x-1>=0:
    que.append([y,x-1,p+1])
  if x+1<w:
    que.append([y,x+1,p+1])
print(ans)


### FIXED CODE ###

H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())
### BUGGY CODE ###

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))


import bisect
for i in range(m):
  b, c = map(int, input().split())
  mid = bisect.bisect_left(a, c)
  t = min(mid, b)
  for j in range(t):
    a[j] = c
  a.sort()
  
print(sum(a))

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb=[]
for i in range(m):
    b, c = map(int, input().split())
    cb.append([c,b])
cb.sort(reverse=True)
k=0
for i in range(m):
    j=0
    while j<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
        a[k+j] = cb[i][0]
        j+=1
    k+=j
    if k==n:
        break
print(sum(a))
### BUGGY CODE ###

import sys
_ = input()
S = input().strip()
for line in sys.stdin:
  l,r = line.strip().split(' ')
  l,r = int(l), int(r)
  print(S[l-1:r].count('AC'))


### FIXED CODE ###

import sys
_ = input()
S = input().strip()

ps = [0]*(len(S)+1)
for i in range(2, len(S)+1):
  ps[i] = ps[i-1]+int(S[i-2:i] == 'AC')

for line in sys.stdin:
  l,r = map(int, line.strip().split(' '))
  print(ps[r]-ps[l])
### BUGGY CODE ###

# D - Xor Sum 2
# https://atcoder.jp/contests/arc098/tasks/arc098_b

import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main_lte(N, An):
    ans = N
    for l in range(N):
        for r in range(l+1, N):
            a = An[l]
            b = An[l]
            for i in range(l+1, r+1):
                a ^= An[i]
                b += An[i]
            if a == b:
                ans += 1
    print(ans)

def main(N, An):
    ans = N
    for l in range(N):
        a = An[l]
        b = An[l]
        for r in range(l+1, N):
            a ^= An[r]
            b += An[r]
            if a == b:
                ans += 1
            else:
                continue
    print(ans)

N = i2n()
An = i2nn()
main(N, An)


### FIXED CODE ###

# D - Xor Sum 2
# https://atcoder.jp/contests/arc098/tasks/arc098_b

import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main_lte(N, An):
    ans = N
    for l in range(N):
        for r in range(l+1, N):
            a = An[l]
            b = An[l]
            for i in range(l+1, r+1):
                a ^= An[i]
                b += An[i]
            if a == b:
                ans += 1
    print(ans)

def main_lte2(N, An):
    ans = N
    for l in range(N):
        a = An[l]
        b = An[l]
        for r in range(l+1, N):
            a ^= An[r]
            b += An[r]
            if a == b:
                ans += 1
            else:
                continue
    print(ans)

def main(N, An):
    ans = 0
    n = 0
    l = 0
    for r in range(N):
        n2 = An[r]
        if n & n2 == 0:
            n += n2
        else:
            while True:
                n -= An[l]
                l += 1
                if n & n2 == 0:
                    n += n2
                    break
        ans += r + 1 - l
    print(ans)

N = i2n()
An = i2nn()
main(N, An)
### BUGGY CODE ###

def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N, L = map(int, input().split())
    dic = defaultdict(int)
    for _ in range(N):
        s = input().rstrip('\n')
        for i in range(len(s)):
            dic[s[:i+1]] = 1

    g = 0
    key = list(dic.keys())
    for s in key:
        t = [si for si in s]
        t[-1] = '0' if t[-1] == '1' else '1'
        t = ''.join(t)
        if not dic[t]:
            tmp = L - len(s) + 1
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)

    if g:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    mod = 10**10+7
    mod2 = 10**10+9
    mod3 = 998244353
    N, L = map(int, input().split())
    dic = defaultdict(int)
    dic2 = defaultdict(int)
    dic3 = defaultdict(int)
    h_list = []
    h2_list = []
    h3_list = []
    pair = {}
    pair2 = {}
    pair3 = {}
    M = 0
    for _ in range(N):
        s = input().rstrip('\n')
        h = 0
        h2 = 0
        h3 = 0
        for i in range(len(s)):
            M += 1
            h = (h*1007 + int(s[i]) + 1) % mod
            pair[h] = (h + 1)%mod if s[i] == '0' else (h-1)%mod
            h2 = (h2 * 2009 + int(s[i]) + 1) % mod2
            pair2[h2] = (h2 + 1)%mod2 if s[i] == '0' else (h2-1)%mod2
            h3 = (h3 * 3001 + int(s[i]) + 1) % mod3
            pair3[h3] = (h3 + 1) % mod3 if s[i] == '0' else (h3 - 1) % mod3
            dic[h] = i+1
            dic2[h2] = i+1
            dic[h3] = i+1
            h_list.append(h)
            h2_list.append(h2)
            h3_list.append(h3)

    g = 0
    seen = defaultdict(int)
    seen2 = defaultdict(int)
    seen3 = defaultdict(int)
    for i in range(M):
        s, s2, s3 = h_list[i], h2_list[i], h3_list[i]
        if seen[s] and seen2[s2] and seen3[s3]:
            continue
        t = pair[s]
        t2 = pair2[s2]
        t3 = pair3[s3]
        if dic[t] == 0 or dic2[t2] == 0 or dic3[t3] == 0:
            p = [dic[s], dic2[s2], dic3[s3]]
            p.sort()
            tmp = L - p[1] + 1
            '''
            if not seen[s]:
                tmp = L - dic[s] + 1
            elif not seen[s2]:
                tmp = L - dic2[s2] + 1
            else:
                tmp = L - dic3[s3] + 1
            '''
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)
            #print(g, s, s2, t, t2, dic[t], dic2[t2])
        seen[s] = 1
        seen2[s2] = 1
        seen3[s3] = 1

    if g:
        print('Alice')
    else:
        print('Bob')


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

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

dp = [[[0 for k in range(N+2)] for j in range(N+2)] for i in range(N+2)]
dp[0][0][0] = 0

a,b,c = 0,0,0
for i in range(N):
    if A[i] == 1:
        a += 1
    elif A[i] == 2:
        b += 1
    else:
        c += 1

for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if i==j==k==0:
                continue
            temp = N
            if i!=0:
                temp += dp[i-1][j][k]*i
            if j!=0:
                temp += dp[i+1][j-1][k]*j
            if k!=0:
                temp += dp[i][j+1][k-1]*k
            dp[i][j][k] = temp/(i+j+k)

print(dp[a][b][c])

### FIXED CODE ###

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

dp = [[[0.0 for k in range(N+1)] for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 0

a,b,c = 0,0,0
for i in range(N):
    if A[i] == 1:
        a += 1
    elif A[i] == 2:
        b += 1
    else:
        c += 1

for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(a+b+c-k-j+1):
            if i==j==k==0:
                continue
            temp = N
            if i!=0:
                temp += dp[i-1][j][k]*i
            if j!=0:
                temp += dp[i+1][j-1][k]*j
            if k!=0:
                temp += dp[i][j+1][k-1]*k
            dp[i][j][k] = temp/(i+j+k)

print(dp[a][b][c])
### BUGGY CODE ###

from functools import lru_cache

N = int(input())

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

parent = [None]*N
visited = [False]*N
visited[0] = True
def rec(u):
    for v in adj[u]:
        if not visited[v]:
            parent[v] = u
            visited[v] = True
            rec(v)
rec(0)
del adj

M = int(input())


# edge_id to crucial query_id
tasks = [set() for _ in range(N)]

for q in range(M):
    u,v = map(int,input().split())
    u,v = u-1,v-1
    u2r = []
    v2r = []
    while u is not None:
        u2r.append(u)
        u = parent[u]
    while v is not None:
        v2r.append(v)
        v = parent[v]
    
    for i,(a,b) in enumerate(zip(reversed(u2r), reversed(v2r))):
        if a != b:
            break
    else:
        i += 1
    # path = u2r[:-i] + [u2r[-i]] + list(reversed(v2r[:-i]))

    for n in u2r[:-i]:
        tasks[n].add(q)
    for n in v2r[:-i]:
        tasks[n].add(q)

tasks = tasks[1:]

@lru_cache(None)
def rec(i, remainings):
    if i >= len(tasks):
        return 1 if not remainings else 0
    r = remainings & tasks[i]
    if not r:
        return 2*rec(i+1,remainings)

    #True
    return rec(i+1, remainings) + rec(i+1, frozenset(remainings-tasks[i]))

print(rec(0, frozenset(range(M))))

### FIXED CODE ###

from itertools import combinations

N = int(input())

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

parent = [None]*N
visited = [False]*N
visited[0] = True
def rec(u):
    for v in adj[u]:
        if not visited[v]:
            parent[v] = u
            visited[v] = True
            rec(v)
rec(0)
del adj

M = int(input())


# edge_id to crucial query_id
tasks = []

for q in range(M):
    u,v = map(int,input().split())
    u,v = u-1,v-1
    u2r = []
    v2r = []
    while u is not None:
        u2r.append(u)
        u = parent[u]
    while v is not None:
        v2r.append(v)
        v = parent[v]
    
    for i,(a,b) in enumerate(zip(reversed(u2r), reversed(v2r))):
        if a != b:
            break
    else:
        i += 1
    # path = u2r[:-i] + [u2r[-i]] + list(reversed(v2r[:-i]))
    tasks.append(u2r[:-i]+v2r[:-i])

cnt = 0
sign = 1

for n in range(1,M+1):
    sub = 0
    for p in combinations(range(M),n):
        sub += 2**(N-1-len(set().union(*(tasks[i] for i in p))))
    cnt += sign*sub
    sign *= -1
print(2**(N-1)-cnt)
### BUGGY CODE ###

S = str(input())
l = len(S)
mem = l
i = 0
while (1):
    M = S
    S = S.replace("01", "")
    S = S.replace("10", "")
    if (M == S):
        break

print(mem-len(S))


### FIXED CODE ###

S = []
ans = 0
for c in input():
    if len(S) > 0 and c != S[-1]:
        S.pop()
        ans += 2
    else:
        S.append(c)
print(ans)
### BUGGY CODE ###

h,w=map(int,input().split())
A=[[["."] *w for j in range(h)] for i in range(1004)]
A[0]=[list(input()) for _ in range(h)]


i=0
ans=0
while A[i]!=[["#"] *w for j in range(h)]:
  for takasa in range(h):
    for nanmojime in range(w):
      if A[i][takasa][nanmojime]=="#":
        if nanmojime==0 and takasa==0:
          A[i+1][0][1]="#"
          A[i+1][1][0]="#"
          A[i+1][0][0]="#"
        elif nanmojime==0 and takasa==h-1:
          A[i+1][h-2][0]="#"
          A[i+1][h-1][1]="#"
          A[i+1][h-1][0]="#"
        elif nanmojime==w-1 and takasa==0:
          A[i+1][0][w-2]="#"
          A[i+1][1][w-1]="#"
          A[i+1][0][w-1]="#"
        elif nanmojime==w-1 and takasa==h-1:
          A[i+1][h-1][w-2]="#"
          A[i+1][h-2][w-1]="#"
          A[i+1][h-1][w-1]="#"
        elif takasa==0:
          A[i+1][0][nanmojime-1]="#"
          A[i+1][0][nanmojime+1]="#"
          A[i+1][1][nanmojime]="#"
          A[i+1][0][nanmojime]="#"
        elif takasa==h-1:
          A[i+1][h-1][nanmojime-1]="#"
          A[i+1][h-1][nanmojime+1]="#"
          A[i+1][h-2][nanmojime]="#"
          A[i+1][h-1][nanmojime]="#"
        elif nanmojime==0:
          A[i+1][takasa-1][0]="#"
          A[i+1][takasa+1][0]="#"
          A[i+1][takasa][1]="#"
          A[i+1][takasa][nanmojime]="#"
        elif nanmojime==w-1:
          A[i+1][takasa-1][w-1]="#"
          A[i+1][takasa+1][w-1]="#"
          A[i+1][takasa][w-2]="#"
          A[i+1][takasa][nanmojime]="#"
        else:
          A[i+1][takasa-1][nanmojime]="#"
          A[i+1][takasa+1][nanmojime]="#"
          A[i+1][takasa][nanmojime-1]="#"
          A[i+1][takasa][nanmojime+1]="#"
          A[i+1][takasa][nanmojime]="#"

  i+=1
print(i)

### FIXED CODE ###

h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

queue=deque([])
seen=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if A[i][j]=="#":
            queue.append([i,j,0])
            seen[i][j]=1

dx=[1,0,-1,0];dy=[0,1,0,-1]
while queue:
    x,y,t=queue.pop()
    for i,j in zip(dx,dy):
        if 0<=x+i<h and 0<=y+j<w and seen[x+i][y+j]==0:
            queue.appendleft([x+i,y+j,t+1])
            seen[x+i][y+j]=1
print(t)
### BUGGY CODE ###

# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *                # alpha = ascii_lowercase
from random import *                # l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *                # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter        # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(grid):
	H,W = len(grid),len(grid[0])
	q = []
	dist = [0]*H
	for i in range(H):
		dist[i] = []
	for i in range(H):
		for j in range(W):
			if(grid[i][j] == '#'):
				q.append([i,j])
				grid[i][j] = 0
	maxx = 0
	for i,j in q:
		for r,c in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
			if(0 <= r < H and 0 <= c < W and grid[r][c] == '.'):
				grid[r][c] = grid[i][j] + 1
				maxx = max(maxx,grid[r][c])
				q.append([r,c])
	return maxx

H,W = map(int, stdin.readline().rstrip().split())
grid = []
for h in range(H):
	s = list(input())
	grid.append(s)
ans = solve(grid)
print(ans)


### FIXED CODE ###

# ANSHUL GAUTAM
# IIIT-D

'''

'''

def solve(grid):
	H,W = len(grid),len(grid[0])
	q = []
	dist = [0]*H
	for i in range(H):
		dist[i] = []
	for i in range(H):
		for j in range(W):
			if(grid[i][j] == '#'):
				q.append([i,j])
				grid[i][j] = 0
	maxx = 0
	while(q):
		qq = []
		for i,j in q:
			for r,c in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
				if(0 <= r < H and 0 <= c < W and grid[r][c] == '.'):
					grid[r][c] = grid[i][j] + 1
					maxx = max(maxx,grid[r][c])
					qq.append([r,c])
		q = qq
	return maxx

H,W = map(int, raw_input().split())
grid = []
for h in range(H):
	s = list(raw_input())
	grid.append(s)
ans = solve(grid)
print(ans)