Harryxun/stf_run huggingface dataset:
N = int(input())

edges = [{} for i in range(N)]
colors = [0 for i in range(N)]

def dfs(s, dist):
    for key, val in edges[s].items():
        d = dist + val
        if d % 2 == 0:
            colors[key] = 0 
        else :
            colors[key] = 1
        
        if s in edges[key]:
            del edges[key][s]

        dfs(key, d)
    return

for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1; v -= 1
    edges[u][v] = w
    edges[v][u] = w

dfs(0, 0)
for color in colors:
    print(color)



### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

N = int(input())

edges = [{} for i in range(N)]
colors = [0 for i in range(N)]

def dfs(s, dist):

    for key, val in edges[s].items():
        d = dist + val
        if d % 2 == 0:
            colors[key] = 0 
        else :
            colors[key] = 1
        
        if s in edges[key]:
            del edges[key][s]

        dfs(key, d)

    return

for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edges[u][v] = w
    edges[v][u] = w

dfs(0, 0)

for color in colors:
    print(color)
s=input()
if s == ABB :
    print("Yes")
elif s == AAB :
    print("Yes")
elif s == ABA :
    print("Yes")
elif s == BAA :
    print("Yes")
elif s == BBA :
    print("Yes")
elif s == BAB :
    print("Yes")
else :
    print("No")


### FIXED CODE ###

s=input()
if s == "ABB" :
    print("Yes")
elif s == "AAB" :
    print("Yes")
elif s == "ABA" :
    print("Yes")
elif s == "BAA" :
    print("Yes")
elif s == "BBA" :
    print("Yes")
elif s == "BAB" :
    print("Yes")
else :
    print("No")
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  print(x)
else:
  ans=0
  for i in range(n-1):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
  if ans==0:
    for j in range(2*x,101):
      if j not in a:
        ans=j
        break
print(ans)

### FIXED CODE ###

x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  ans=x
else:
  ans=0
  for i in range(101):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
print(ans)
# AOJ ITP1_8_C
import sys

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    counts = []
    for i in range(26): counts.append(0)

    while True:
        string = input()
        if not len(string): break   # 長さが0のstringが来たら終了
        for k in range(len(string)):
            c = string[k]
            if 97 <= ord(c) <= 122:
                counts[ord(c) - 97] += 1
            elif 65 <= ord(c) <= 90:
                counts[ord(c) - 65] += 1

    # 結果を出力。
    for i in range(26):
        print(chr(97 + i) + " : " + str(counts[i]))

if __name__ == "__main__":
    main()


### FIXED CODE ###

# AOJ ITP1_8_C

import sys

def main():
    counts = []
    for i in range(26): counts.append(0)

    lines = sys.stdin.readlines()

    for i in range(len(lines)):
        string = lines[i]
        for k in range(len(string)):
            c = string[k]
            if 97 <= ord(c) <= 122:
                counts[ord(c) - 97] += 1
            elif 65 <= ord(c) <= 90:
                counts[ord(c) - 65] += 1

    # 結果を出力。
    for i in range(26):
        print(chr(97 + i) + " : " + str(counts[i]))

if __name__ == "__main__":
    main()

# Accepted.
N, K, X, Y = int(input())
a = K
b = N-K
if N > K:
  total = X*a + Y*b
  print(total)
else:
  total = X*a
  print(total)

### FIXED CODE ###

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N > K:
  print(X*K + Y*(N-K))
else:
  print(X*N)
import sys

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

for i in range(n):
    d = h[i+1] - h[i]
    if d >= 1:
        h[i+1] -= 1
    elif d < 0:
        print('No')
        sys.exit()
print('Yes')


### FIXED CODE ###

import sys

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

for i in range(n-1):
    d = h[i+1] - h[i]
    if d >= 1:
        h[i+1] -= 1
    elif d < 0:
        print('No')
        sys.exit()
print('Yes')
n = int(input())
a = list(map(int, input().split()))

a.sort()

M = 1000005
cnt = [0] * M

for i in range(n):
    if cnt[a[i]] != 0:
        cnt[a[i]] = 2
        continue
    for j in range(a[i], M, a[i]):
        cnt[j] += 1

ans = 0

for i in range(n):
    if cnt[a[i]] == 1:
        ans += 1

print(ans)

### FIXED CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))

check = 1000000
ans = 0

N = list(range(-300, 300))

for i in range(1, 101):
    if i in p:
        N.remove(i)

for i in range(len(N)):
    if check > abs(N[i]-x):
        check = abs(N[i]-x)
        ans = N[i]
print(ans)
h,a=map(int,input().split())
if h%a!=0:
  n=int(h/a)+1
  print(n)
else:
  n-=1
  print(n)

### FIXED CODE ###

h,a=map(int,input().split())
if h%a!=0:
  n=int(h/a)+1
  print(n)
else:
  n=int(h/a)
  print(n)
import numpy as np
n=int(input())
lista=list(map(int,input().split()))
lista=sorted(lista)
for i in range(n-1):
    lista.append((lista[i]+lista[i+1])/2)
    lista.pop(i+1)
    lista.pop(i)
print(lista)

### FIXED CODE ###

import numpy as np
n=int(input())
lista=list(map(int,input().split()))
lista.sort()

for i in range(n-1):
    lista.append((lista[0]+lista[1])/2)
    lista.pop(0)
    lista.pop(0)
    lista.sort()
    
print(lista[0])
# input
A, B, C = map(int, input().split())

# change box
tmp = A
A = B
B = tmp

tmp = A
A = C
C = tmp
    

# output
print("{} {} {]".format(A, B, C))

### FIXED CODE ###

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

# change box
tmp = A
A = B
B = tmp

tmp = A
A = C
C = tmp


# output
print("{} {} {}".format(A, B, C))
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1
if a[0]:
    print(0)
    exit()
for i in range(m):
    if count[i]==0 and count[i+1]:
        print(0)
        exit()

ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

### FIXED CODE ###

n=int(input())
if n%2==1:
  print((n-1)//2)
else:
  print(n//2-1)
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
BA = [[] for i in range(N)]
for i in range(N):
    a,b = LI()
    BA[i] = (b,a)

BA.sort()

part_A = [0 for i in range(N)]
tmp  = 0
for i in range(N):
    b,a = BA[i]
    tmp += a
    if B - tmp < 0:
        print("No")
        break
else:
    print("Yes")


### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
BA = [[] for i in range(N)]
for i in range(N):
    A,B = LI()
    BA[i] = [B,A]


BA.sort()
part_A = [0 for i in range(N)]
for i in range(N):
    B,A = BA[i]
    part_A[i] = A + part_A[i-1]

for i in range(N):
    B,A = BA[i]
    if B - part_A[i]>= 0:
        pass
    else:
        print("No")
        break
else:
    print("Yes")
def gcd(a,b):
    if b==0:
        return a
    c=a%b
    return gcd(b,c)
x=int(input("x:"))
y=int(input("y:"))
if x<y:
    x,y=y,x
m=gcd(x,y)
print(m)
def gcd(x,y):


### FIXED CODE ###

def gcd(a,b):
    if b==0:
        return a
    c=a%b
    return gcd(b,c)
x,y=map(int,input().split())
if x<y:
    x,y=y,x
m=gcd(x,y)
print(m)
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0, *a, 0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])

    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0]+a+[0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])
 
    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()
n = input()
nums = map(int, input().split)

min_ans = 0
for num in nums:
  ans = 0
  tmp = num % 2
  if (tmp == 1):
    break
  ans += 1
  while (tmp % 2 == 0 and ans <= min_ans):
    ans += 1
    tmp = tmp % 2

  if (ans < min_ans):
    min_ans = ans

print(min_ans)
  
    

### FIXED CODE ###

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

if (nums[0] % 2 == 1):
  print('0')
else:
  tmp = nums[0] / 2
  tmp_ans = 1
  while(tmp % 2 == 0 and tmp > 1):
    tmp_ans += 1
    tmp = tmp / 2

  min_ans = tmp_ans
  
  for num in nums[1:]:
    if (num % 2 == 1):
      min_ans = 0
      break
    tmp = num / 2
    tmp_ans = 1
    while (tmp % 2 == 0 and tmp_ans <= min_ans):
      tmp_ans += 1
      tmp = tmp / 2

    if (tmp_ans < min_ans):
      min_ans = tmp_ans
      
  print(min_ans)
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

# grid
# N = I()
# 黒く塗りつぶす#が独立していたら不可
H,W = LI()
S = [list(_S()) for _ in range (H)]

def check(x, y):
    # 移動する4方向をループ
    res = False
    # for dx,dy in itertools.product([-1,0,1],repeat=2):
    dxs = [-1,1]
    dys = [-1,1]
    for dx in dxs:
        nx = x + dx
        ny = y
        if 0 <= nx and nx < H and S[nx][ny] == "#":
            res = True
    for dy in dys:
        nx = x
        ny = y + dy
        if 0 <= ny and ny < H and S[nx][ny] == "#":
            res = True
    return res

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            if not check(i,j):
                print('No')
                exit()

print('Yes')

### FIXED CODE ###

import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

# grid
# N = I()
# 黒く塗りつぶす#が独立していたら不可
H,W = LI()
S = [list(_S()) for _ in range (H)]

def check(x, y):
    # 移動する4方向をループ
    res = False
    # for dx,dy in itertools.product([-1,0,1],repeat=2):
    dxs = [-1,1]
    dys = [-1,1]
    for dx in dxs:
        nx = x + dx
        ny = y
        if 0 <= nx and nx < H and S[nx][ny] == "#":
            res = True
    for dy in dys:
        nx = x
        ny = y + dy
        if 0 <= ny and ny < W and S[nx][ny] == "#":
            res = True
    return res

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            if not check(i,j):
                print('No')
                exit()

print('Yes')
#N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
fenum = sum(A)

if B[0] >= A[0]:
    B[0] -= A[0]
    A[0] = 0
    if B[0] > A[1]:
        A[1] = 0
    else:
        A[1] -= B[0]
        B[0] = 0
    
else:
    A[0] -= B[0] 
    B[0] = 0
    
for i in range(1, len(B)):
    if B[i] >= A[i]:
        B[i] -= A[i]
        A[i] = 0
        if B[i] > A[i + 1]:
            A[i + 1] = 0
            continue
        A[i + 1] -= B[i]
        B[i] = 0
    
    else:
        A[i] -= B[i]
        B[i] = 0

print(fenum - sum(A))


### FIXED CODE ###

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

if B[0] >= A[0]:
    B[0] -= A[0]
    A[0] = 0
    if B[0] > A[1]:
        A[1] = 0
    else:
        A[1] -= B[0]
        B[0] = 0
    
else:
    A[0] -= B[0] 
    B[0] = 0
    
for i in range(1, N):
    if B[i] >= A[i]:
        B[i] -= A[i]
        A[i] = 0
        if B[i] > A[i + 1]:
            A[i + 1] = 0
            continue
        A[i + 1] -= B[i]
        B[i] = 0
    
    else:
        A[i] -= B[i]
        B[i] = 0

print(fenum - sum(A))
a, b = list(map(int, input().split))

d = int(a/b)
r = a%b
f = a/b

print(d, r, f)

### FIXED CODE ###

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

d = int(a/b)
r = a%b
f = round(a/b, 5)

print(d, r, f)
import sys
input = sys.stdin.buffer.readline

h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [[0, i+1] for i in range(h)]
rows = [[0, i+1] for i in range(w)]
maxs = 0
maxr = 0
for i in range(m):
    h1, w1 = map(int, input().split())
    mapa[h1-1][w1-1] = 1
    strings[h1-1][0] += 1
    rows[w1-1][0] += 1
    if strings[h1-1][0] > maxs:
        maxs = strings[h1-1][0]
    if rows[w1-1][0] > maxr:
        maxr = rows[h1-1][0]
summa = maxs + maxr - 1
for i in range(h):
    if strings[i][0] == maxs:
        for j in range(w):
            if rows[j][0] == maxr:
                x = maxs + maxr
                if mapa[i][j] == 1:
                    x -= 1
                if x > summa:
                    summa = x
                    print(summa)
                    exit()
print(summa)


### FIXED CODE ###

def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()
N, Ma, Mb = (list)(map(int, input().split()))
l = []
inf = 10**6
dp = [[[inf]*402 for _ in range(402)] for _ in range(40)]


for _ in range(N):
    l.append((list)(map(int, input().split())))

dp[0][0][0] = 0

for i in range(N):
    for ca in range(401):
        for cb in range(401):
            if dp[i][ca][cb] != inf:
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
                t_a = l[i][0]
                t_b = l[i][1]
                dp[i+1][ca+t_a][cb+t_b] =\
                    min(dp[i+1][ca+t_a][cb+t_b], dp[i][ca][cb]+l[i][2])

ans = inf
for i in range(1, 402):
    for j in range(1, 402):
        if i*Mb == j*Ma:
            ans = min(ans, dp[N][i][j])

if ans == inf:
    ans = -1
print(ans)


### FIXED CODE ###

N, Ma, Mb = (list)(map(int, input().split()))
l = []
inf = 10**6
dp = [[[inf]*401 for _ in range(401)] for _ in range(41)]


for _ in range(N):
    l.append((list)(map(int, input().split())))

dp[0][0][0] = 0

for i in range(N):
    for ca in range(401):
        for cb in range(401):
            if dp[i][ca][cb] != inf:
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
                t_a = l[i][0]
                t_b = l[i][1]
                dp[i+1][ca+t_a][cb+t_b] =\
                    min(dp[i+1][ca+t_a][cb+t_b], dp[i][ca][cb]+l[i][2])

ans = inf
for i in range(1, 401):
    for j in range(1, 401):
        if i*Mb == j*Ma:
            ans = min(ans, dp[N][i][j])

if ans == inf:
    ans = -1
print(ans)
import sys
sys.setrecursionlimit(10000)
N, M, K = map(int,input().split())
class UnionFind:
    def __init__(self, N):
        self.par = [-1 for i in range(N+1)]
        self.rank = [1]*(N+1)
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] > self.rank[y]:
            self.par[x] += self.par[y]
            self.par[y] = x
        else:
            self.par[y] += self.par[x]
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
    A, B = map(int,input().split())
    friendlist[A].append(B)
    friendlist[B].append(A)
    if not UF.same_check(A,B):
        UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
    C, D = map(int, input().split())
    blocklist[C].append(D)
    blocklist[D].append(C)

for person in range(1,N+1):
    root = UF.find(person)
    ans = -UF.par[root]-1
    ans -= len(friendlist[person])
    for l in blocklist[person]:
        if UF.same_check(person,l):
            ans -= 1
    print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5+10)
N, M, K = map(int,input().split())
class UnionFind:
    def __init__(self, N):
        self.par = [-1 for i in range(N+1)]
        self.rank = [1]*(N+1)
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] > self.rank[y]:
            self.par[x] += self.par[y]
            self.par[y] = x
        else:
            self.par[y] += self.par[x]
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
    A, B = map(int,input().split())
    friendlist[A].append(B)
    friendlist[B].append(A)
    if not UF.same_check(A,B):
        UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
    C, D = map(int, input().split())
    blocklist[C].append(D)
    blocklist[D].append(C)

for person in range(1,N+1):
    root = UF.find(person)
    ans = -UF.par[root]-1
    ans -= len(friendlist[person])
    for l in blocklist[person]:
        if UF.same_check(person,l):
            ans -= 1
    print(ans)
d = int(input())
c = {}
s = []
C = list(map(int, input().split()))
for i in range(26):
    c[i] = C[i]
for i in range(d):
    s.append(list(map(int, input().split())))

t = 0
while t < 365:
    for i in range(26):
        if t < 365:
            t += 1
            a = -1
            b = 0
            for j in range(26):
                if b < s[t][j]:
                    a = j
                    b = s[t][j]
            print(a+1)
        else:
            break;
        if t < 365:
            t += 1
            print(26-i)
        else:
            break;

### FIXED CODE ###

d = int(input())
c = {}
s = []
C = list(map(int, input().split()))
for i in range(26):
    c[i] = C[i]
for i in range(d):
    s.append(list(map(int, input().split())))

for i in range(d):
    a = -1
    b = 0
    for j in range(26):
        if b < s[i][j]:
            a = j
            b = s[i][j]
    print(a+1)
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = int(input())
k = int(input())

if e-a > k:
    print(":(")
else:
    print("Yay!")

# for i in range(4):
#     for j in range(4):
#         if i<j :
#             print("." * j)
#             continue
#         print(f"i={i}, j={j}")
#
# print()

# numlist = [3, 4.2, 10, "x", 1, 9]
#
# sum = 0
# for num in numlist :
#     if not isinstance(num, (int,float)):
#         print(num, "数値ではありません。")
#         continue
#     sum += num
#     print(num, "/", sum)

# print(1,2, sep ="/")


### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e-a > k:
    print(":(")
else:
    print("Yay!")
from itertools import accumulate
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**10
from functools import reduce

h,w,n = map(int,input().split())
sr,sc = map(int,input().split())
s = input()
t = input()
l = 1
r = w
u = 1
d = h
for s,t in zip(s[::-1],t[::-1]):
    if t == "R":
        l = max(l-1,1)
    elif t == "L":
        r = min(r+1,w)
    elif t =="U":
        d = min(d+1,h)
    else:
        u = max(u-1,1)

    if s == "L":
        l += 1
    elif s =="R":
        r -=1
    elif s =="U":
        u+=1
    else:
        d-=1
    if l > r or u > d:
        print('NO')
        exit()
if u <= sr <= d and l <= sc <= r:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

H,W = map(int,input().split())
A = list(list(input()) for _ in range(H))
dirc = [(0,1),(1,0),(0,-1),(-1,0)]
q = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] =="#":
            A[i][j] = 0
            q.append((i,j))
ans = 0
while q:
    y,x = q.popleft()
    for dy,dx in dirc:
        if 0<=dy+y<H and 0<=dx+x<W and A[dy+y][dx+x]==".":
            A[dy+y][dx+x] = A[y][x]+1
            ans = max(ans,A[dy+y][dx+x])
            q.append((dy+y,dx+x))

print(ans)
import collections
import sys
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


X = int(input())
if X == 1:
    print("1 0")
elif X == 2:
    print("2 0")
else:
    for i in range(sys.maxsize):#i = B
        c = factorization(X+pow(i,5))
        flag = 0
        for j in range(len(c)):
            if c[j][1] % 5 != 0:
                flag = 1
                break
        if flag ==0:
            B = i
            A = 1
            for j in range(len(c)):
                A *= c[j][0]
            break
        c = factorization(X-pow(i,5))
        flag = 0
        for j in range(len(c)):
            if c[j][1] % 5 != 0:
                flag = 1
                break
        if flag ==0:
            B = i * -1
            A = 1
            for j in range(len(c)):
                A *= c[j][0]
            break
    print(A,B)



### FIXED CODE ###

X = int(input())
for A in range(-200,200):
    for B in range(-200,200):
        if pow(A,5)-pow(B,5)==X:
            print(A,B)
            break
    else:
        continue
    break
import math
x,y = map(int, input().split())
n = 2 * x - y
m = 2 * y - x

ans = 0
if n % 3 == 0:
	if m % 3 == 0:
		nn = int(n / 3)
		mm= int(m / 3)
		ans = math.factorial(nn+ mm) / math.factorial(nn) * math.factorial(mm)
		ans = int(ans % ((10**9) + 7))

print(ans)

### FIXED CODE ###

import math

MAX=1000000
MOD=1000000007

fac=[1,1]
finv=[1,1]
inv=[1,1]

for i in range(2,MAX):
	fac.append(fac[i-1] * i % MOD)
	inv.append(MOD - inv[ MOD % i ] * (int(MOD / i)) % MOD)
	finv.append(finv[i - 1] * inv[i] % MOD)

def COM(nnn, kkk):
	if nnn < kkk:
		return 0
	
	if nnn < 0 or kkk < 0:
		return 0
	
	return fac[nnn] * (finv[kkk] * finv[nnn-kkk] % MOD) % MOD


x,y = map(int, input().split())

n = 2 * x - y
m = 2 * y - x

ans = 0
if n % 3 == 0:
	if m % 3 == 0:
		nn = int(n / 3)
		mm= int(m / 3)
		ans = COM(nn+mm,nn)

print(ans)