Harryxun/stf_run huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, m = LI()
ret = [''] * n
for _ in range(m):
    s, c = LI()
    if ret[s - 1] and ret[s - 1] != str(c):
        print(-1)
        exit()
    elif s == 1 and c == 0:
        print(-1)
        exit()
    else:
        ret[s - 1] = str(c)



for i in range(3):
    if not ret[i]:
        ret[i] = '0'

ans = ''.join(ret)
if ans[0] == '0':
    ans = '1' + ans
print(int(ans))


### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, m = LI()
ret = [''] * n
for _ in range(m):
    s, c = LI()
    if ret[s - 1] and ret[s - 1] != str(c):
        print(-1)
        exit()
    elif s == 1 and c == 0 and n != 1:
        print(-1)
        exit()
    else:
        ret[s - 1] = str(c)

for i in range(n):
    if not ret[i]:
        ret[i] = '0' if i or n == 1 else '1'

ans = ''.join(ret)
print(ans)
M,N,P = map(int, input().split())
# M: number of V
# N: number of edges
# P: P x edges to pay

edges = []
for _ in range(M):
    a,b,c = map(int, input().split())
    edges.append((a,b,c))

neg_inf = float("-Inf")
no_answer = False

start = 1
end = M

distance = {}
distance[start] = 0
previous = {}

for i in range(M-1):
    for f,t,w in edges:
        if distance.get(f,neg_inf) + w - P > distance.get(t,neg_inf):
            distance[t] = distance[f] + w - P
            previous[t] = f

path = []
node = end
if node in previous:
    cnt = 0
    while node != start:
        path.append(node)
        node = previous[node]
        cnt += 1
        if cnt > M:
            no_answer = True
            break
    path.append(start)

    for f,t,w in edges:
    if distance.get(f,neg_inf) + w - P > distance.get(t,neg_inf) and t in path:
        no_answer = True
        break

if no_answer:
    print(-1)
else:
    print(max(0,distance[end]))


### FIXED CODE ###

def is_reachable(edges,start,end):
  g = {}
  for f,t,w in edges:
    if f in g: g[f].append(t)
    else: g[f] = [t]
  visiting = [start]
  visited = {}
  while visiting:
    v = visiting.pop()
    if v in visited: continue
    if v == end: return True
    visited[v] = True
    for v2 in g.get(v, ()):
      if v2 in visited or v2 in visiting: continue
      visiting.append(v2)
  return False

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

edges = []
for _ in range(M):
    a,b,c = map(int, input().split())
    edges.append((a,b,c))

neg_inf = float("-Inf")
no_answer = False

start = 1
end = N

distance = {}
for i in range(1,N+1):
  distance[i] = neg_inf
distance[start] = 0

for i in range(N-1):
    for f,t,w in edges:
        if distance[f] + w - P > distance[t]:
            distance[t] = distance[f] + w - P

for f,t,w in edges:
    if distance[f] + w - P > distance[t] and is_reachable(edges,t,end):
        no_answer = True
        break

if no_answer:
    print(-1)
else:
    print(max(0,distance[end]))
A, B = map(int,input().split())
cartain = B*2

if A<=cartain :
    input(0)
else :
    input(A-cartain)




### FIXED CODE ###

A, B = map(int,input().split())
cartain = B*2

if A<=cartain :
    print(0)
else :
    print(A-cartain)
h,a=map(int,input().split())
print(h//a if h%a+==0 else (h//a)+1)

### FIXED CODE ###

h,a=map(int,input().split())
print(h//a if h%a==0 else (h//a)+1)
import math

n=int(input())
n_sqrt=int(math.sqrt(n))

ans=[]

for i in range(1,n_sqrt):
  if n%i==0:
    x=int(max(math.log10(i)+1,math.log10(n//i)+1))
    ans.append(x)

print(min(ans))

### FIXED CODE ###

import math

n=int(input())
n_sqrt=int(math.sqrt(n))

ans=[]

for i in range(1,n_sqrt+1):
  if n%i==0:
    x=int(max(math.log10(i)+1,math.log10(n//i)+1))
    ans.append(x)

print(min(ans))
# -*- coding: utf-8

while True:
   a = map(int,raw_input().split())
   if a == [0,0]:
      break
   for i in range(a[0]):
      print('#'*a[1])
    print('')




### FIXED CODE ###

# -*- coding: utf-8

while True:
   a = map(int,raw_input().split())
   if a == [0,0]:
      break
   for i in range(a[0]):
      print('#'*a[1])
   print('')
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

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

# 0 => A-1 で割りきれる
cnt_c = (A-1) // C
cnt_d = (A-1) // D

cnt_cd = (A-1) // lcm(C, D)

cnt_a = cnt_c + cnt_d - cnt_cd

# 0 => Bで割りきれる
cnt_c2 = B // C
cnt_d2 = B // D
cnt_cd2 = B // lcm(C, D)

cnt_b = cnt_c2 + cnt_d2 - cnt_cd2

cnt_ab = cnt_b - cnt_a

cnt_n = B - A + 1

print(cnt_n - cnt_ab)

### FIXED CODE ###

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

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

# 0 => A-1 で割りきれる
cnt_c = (A-1) // C
cnt_d = (A-1) // D

cnt_cd = (A-1) // lcm(C, D)

cnt_a = cnt_c + cnt_d - cnt_cd

# 0 => Bで割りきれる
cnt_c2 = B // C
cnt_d2 = B // D
cnt_cd2 = B // lcm(C, D)

cnt_b = cnt_c2 + cnt_d2 - cnt_cd2

cnt_ab = cnt_b - cnt_a

cnt_n = B - A + 1

print(cnt_n - cnt_ab)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7

n,k = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

def dfs(now,pre):
    available_color = 0  # 子ノードに使用可能な色の数
    if pre == -1:
        available_color = k-1
    else:
        available_color = k-2
    if k < len(graph[now]):
        return 0
    res = 1
    for son in graph[now]:
        if son == pre:continue
        res *= available_color
        available_color -= 1
        res %= MOD
    for son in graph[now]:
        if son == pre:continue
        res *= dfs(son,pre)
        res %= MOD

    return res

ans = (k*dfs(0,-1)) % MOD
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7

n,k = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

def dfs(now,pre):
    available_color = 0  # 子ノードに使用可能な色の数
    if pre == -1:
        available_color = k-1
    else:
        available_color = k-2
    if k < len(graph[now]):
        return 0
    res = 1
    for son in graph[now]:
        if son == pre:continue
        res *= available_color
        available_color -= 1
        res %= MOD
    for son in graph[now]:
        if son == pre:continue
        res *= dfs(son,now)
        res %= MOD

    return res

ans = (k*dfs(0,-1)) % MOD
print(ans)
N=int(input())
def contest(N):
  if N=="ABC":
    return ARC
  else:
    return ABC
contest(N)

### FIXED CODE ###

N=input()
def contest(N):
  if N=="ABC":
    return "ARC"
  else:
    return "ABC"
print(contest(N))
def main():
  n=int(input())
  heights=list(map(int,input().split()))
  assert len(heights)==n
  i=0
  count=0
  while i<n:
    j=i+1
    while j<n:
      if heights[i]+heights+[j]==(j-i):
        count+=1
  print(count)
main()

### FIXED CODE ###

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    from collections import defaultdict
    count = defaultdict(int)
    ans = 0
    for i, a in enumerate(A):
        if i - a in count:
            ans += count[i-a]
        count[i+a] += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()
n = int(input())

myset = {}
for i in range(n):
    a = int(input())
    if a in myset:
        myset.remove(a)
    else:
        myset.add(a)
ans = len(myset)

print(ans)

### FIXED CODE ###

n = int(input())

myset = set()
for i in range(n):
    a = int(input())
    if a in myset:
        myset.remove(a)
    else:
        myset.add(a)
ans = len(myset)

print(ans)
from fractions import gcd
N,M=map(int,input().split())
S=input()
T=input()
s=(M//gcd(N,M))
t=(N//gcd(N,M))
SS=[i*s for i in range(N)]
TT=[j*t for j in range(M)]
p,q=0,0
ans=N*s
for k in range(N*s):
    if k==SS[p]:
        if k==TT[q]:
            if S[p]!=T[q]:
                ans=-1
        p+=1
    if k==TT[q]:
        q+=1
print(ans)

### FIXED CODE ###

from fractions import gcd
N,M=map(int,input().split())
S=input()
T=input()
s=(M//gcd(N,M))
t=(N//gcd(N,M))
SS=[i*s for i in range(N)]
TT=[j*t for j in range(M)]
p,q=0,0
ans=N*s
while True:
    if SS[p]==TT[q]:
        if S[p]!=T[q]:ans=-1
        p+=1
        q+=1
    elif SS[p]>TT[q]:
        q+=1
    else:
        p+=1
    if p==N or q==M:
        break
print(ans)
s = input().split("")
sum = 0
for i in range(2 ** (len(s)-1)) :
  st = str(s[0])
  for j in range(len(s)-1) : 
    if ((i >> j) & 1) :
      st = st + "+" + str(s[j+1])
    else :
      st = st + str(s[j+1])
  
  for item in st.split('+') :
    sum += int(item)
print(sum)

### FIXED CODE ###

s = list(input())
sum = 0
for i in range(2 ** (len(s)-1)):
  st = str(s[0])
  for j in range(len(s)-1):
    if (i >> j) & 1:
      st = st + "+" + str(s[j+1])
    else:
      st = st + str(s[j+1])
      
  for item in st.split('+') :
    sum += int(item)
print(sum)
from operator import mul
from functools import reduce
from collections import Counter

def cmb(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

def prime_factor(n):
    ass = []
    for i in range(2, int(n ** 0.5) + 1):
        while n  % i == 0:
            ass.append(i)
            n = n // i
    if n != i:
        ass.append(n)
    return ass

def main():
    N, M = map(int, input().split())
    num_list = prime_factor(M)
    MOD = 10 ** 9 + 7
    C = Counter(num_list)
    ans = 1
    for i, j in C.items():
        if i == 1:
            continue
        ans *= cmb(j+N-1, j)
        ans %= MOD
    print(ans)



if __name__ == "__main__":
    main()

### FIXED CODE ###

import collections
from operator import mul
from functools import reduce

def cmb(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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

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

    MOD = 10 ** 9 + 7
    c = collections.Counter(prime_factorize(M))
    ans = 1
    for i, j in c.items():
        ans *= cmb(N+j-1,N-1)
        ans %= MOD

    print(ans)

main()
from sys import stdin

def main():
    n,m = [int(x) for x in stdin.readline().split()]
    cards = [int(x) for x in stdin.readline().split()]
    cards.sort()

    bcs = [tuple(map(int,x.split())) for x in stdin.readlines()]
    bcs.sort(key=lambda x:x[1], reverse=True)

    ans = 0
    minIndex = 0
    isFinished = False

    for b,c in bcs:

        for _ in range(b):
            if cards[minIndex] < c:
                ans += c
                minIndex += 1
            else:
                isFinished = True
                break
        
        if isFinished:
            break

    if len(cards) - 1 < minIndex:
        ans += sum(cards[minIndex:])

    print(ans)
    
if __name__=='__main__':
    main()

### FIXED CODE ###

from sys import stdin

def main():
    n,m = [int(x) for x in stdin.readline().split()]
    cards = [int(x) for x in stdin.readline().split()]
    cards.sort()

    bcs = [tuple(map(int,x.split())) for x in stdin.readlines()]
    bcs.sort(key=lambda x:x[1], reverse=True)

    ans = 0
    minIndex = 0
    isFinished = False

    for b,c in bcs:

        for _ in range(b):
            if minIndex < n and cards[minIndex] < c:
                ans += c
                minIndex += 1
            else:
                isFinished = True
                break
        
        if isFinished:
            break

    if minIndex < n:
        ans += sum(cards[minIndex:])

    print(ans)
    
if __name__=='__main__':
    main()
def gcd(x,y):
    if y == 0:
        #print(x)
        return x
    else:
        return gcd(y, x%y)

# def lcm(x,y):
#     return x/gcd(x,y)*y
#ans=1

a=int(input())
li=list(map(int,input().split()))
#li_same=li
num=0
num_li=[]
for i in range(a):
    #li=li_same
    b=li.pop(i)
    k=len(li)
    for j in range(1,k):
        ans=gcd(li[j-1],li[j])
        #print(ans)
    #print('hoge')
    num_li.append(ans)
    li.insert(i,b)

print(int(max(num_li)))



### FIXED CODE ###

 
#from functools import reduce
def gcd(m,n):
  x=max(m,n)
  y=min(m,n)
  while y!=0:
    x,y=y,x%y
  return x
 
a=int(input())
li=list(map(int,input().split()))
left_gcd=[0]
#left_gcd.append(li[0])
right_gcd=[0]
#right_gcd.append(li[a-1])

for i in range(a):
    left_gcd.append(gcd(li[i],left_gcd[i]))
    right_gcd.append(gcd(li[a-1-i],right_gcd[i]))
    #k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
#num_li.append(right_gcd[a-2])
#num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=gcd(left_gcd[(a-1)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))
n, m, q = map(int, input().split())
l = []
for i in range(q):
    l.append(list(map(int,input().split())))

t = [1]*(n+1)
ans = 0
while t[0] == 1:
    s = 0
    for i in range(q):
        if t[l[i][1]]-t[l[i][0]] == l[i][2]:
            s += l[i][3]
    ans = max(ans, s)
    k = n
    while t[k] == m and n >= 1:
        k -= 1
    t[k] += 1
    for i in range(k+1, n+1):
        t[i] = t[i-1]

print(ans)

### FIXED CODE ###

n, m, q = map(int, input().split())
l = []
for i in range(q):
    l.append(list(map(int,input().split())))

t = [1]*(n+1)
ans = 0
while t[0] == 1:
    s = 0
    for i in range(q):
        if t[l[i][1]]-t[l[i][0]] == l[i][2]:
            s += l[i][3]
    ans = max(ans, s)
    k = n
    while t[k] == m and k >= 1:
        k -= 1
    t[k] += 1
    for i in range(k+1, n+1):
        t[i] = t[i-1]

print(ans)
import collections
N = int(input())
A = sorted(list(map(int,input().split())))

li = [1]*(max(A)+1)
for j in range(N):
    for i in range(A[j]*2,A[-1]+1,A[j]):
        li[i] = 0
    if j == 0:
        if A[j] == A[j+1]:
            li[A[j]]= 0
    elif j == N-1:
        if A[j] == A[j-1]:
             li[A[j]]= 0
    else:
        if A[j] == A[j+1] or A[j] == A[j-1]:
             li[A[j]]= 0
sA = sum([li[i] for i in A])
print(sA)

### FIXED CODE ###

import collections
N = int(input())
A = sorted(list(map(int,input().split())))
cA = collections.Counter(A)

li = [1]*(max(A)+1)
for j in range(N):
    for i in range(A[j]*2,A[-1]+1,A[j]):
        li[i] = 0

for key,val in cA.items():
    if val >1:
        li[key]=0
        
sA = sum([li[i] for i in A])
print(sA)
from math import factorial

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

if N-K+1 > K:
    p = K
    for i in range(1, p+1):
        a = factorial(N-K+1) / factorial(N-K+1-i) / factorial(i) * factorial(K-1) / factorial(K-i) / factorial(i-1)
        print(int(a%1000000007))
        
else:
    p = N-K+1
    for i in range(1, p+1):
        a = factorial(N-K+1) / factorial(N-K+1-i) / factorial(i) * factorial(K-1) / factorial(K-i) / factorial(i-1)
        print(int(a%1000000007))
    
    for i in range(N-K+2, K+1):
        print(0)


### FIXED CODE ###


from operator import mul
from functools import reduce

def cmb(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())

if N-K+1 > K:
    p = K
    for i in range(1, p+1):
        a = cmb(N-K+1, i) * cmb(K-1, i-1)
        print(int(a%1000000007))
else:
    p = N-K+1
    for i in range(1, p+1):
        a = cmb(N-K+1, i) * cmb(K-1, i-1)
        print(int(a%1000000007))
            
    for i in range(N-K+2, K+1):
        print(0)
l, x, y, s, d = list(map(int, input().split()))

if d >= s:
    a, b = d-s, l-(d-s)
else:
    a, b = l-(s-d), s-d

if x >= y:
    print(a/(x+y))
else:
    print(min(a/(x+y), b/(y-x)))


### FIXED CODE ###

h, w = list(map(int, input().split()))
A = [input() for i in range(h)]

B = [[0]*w for i in range(h)]

d = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if A[i][j] == "#":
            B[i][j] = "#"
            for k in d:
                for l in d:
                    if 0 <= i+k < h and 0 <= j+l < w:
                        if B[i+k][j+l] != "#":
                            B[i+k][j+l] += 1


B_str = [map(str, B[i]) for i in range(h)]
for i in range(h):
    print("".join(B_str[i]))
N, K = input().split()
N = int(N)
K = int(K)
H = input().split()
H = [int(h) for h in H]
H.sort(reverse = True)
# print(H)
for k in range(0, K):
    H[k] = 0
# print(H)
print(sum(H))

### FIXED CODE ###

N, K = input().split()
N = int(N)
K = int(K)
H = input().split()
H = [int(h) for h in H]
H.sort(reverse = True)
# print(H)
I = K if K <= N else N
for i in range(0, I):
    H[i] = 0
# print(H)
print(sum(H))
A, B, C, D = map(int, input().split())

if A<C:
    A=C
if D<B
    B=D

print(A-B)

### FIXED CODE ###

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

ans=0

if A<C:
    A=C
if D<B:
    B=D

if B<C or D<A:
    ans=0
else:
    ans=abs(A-B)

print(ans)
n = int(input())
a = [i in int(input().split()))]
for  i in range(1,n+1):
    v  = a[i]
    j = i-1
    while a[j]>a[j+1] and j>0:
        a[j+1] = a[j]
        a[j] = v
        j -=1
    print(*a)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1

    a[j+1] = v
    print(*a)
import bisect
a, b, q = map(int, input().split())
inf = 10**18
s = [-inf] + [int(input()) for i in range(a)] + [inf]
t = [-inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = inf
  for S in [s[b-1], s[b]]:
    for T in [t[d-1], t[d]]:
      d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
      res = min(d1, d2, res)
  print(res)


### FIXED CODE ###

print('Heisei' if int(input().replace('/',''))<=20190430 else 'TBD')
l = map(int, raw_input().split())
if l[0]+l[1]<l[2]:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

l = input().split()
if int(l[0])+int(l[1])>=int(l[2]) and int(l[0])<=int(l[2]):
    print('YES')
else:
    print('NO')
n = int(input())
now_time = 0
global tf
tf = False

def finish_work(now_time, works):
    global tf
    if len(works) == 0:
        tf = True
        return True
    for index, i in enumerate(works):
        work_list = works.copy()
        work_list.pop(index)
        if now_time + i[0] <= i[1]:
            finish_work(now_time + i[0], work_list)

works = []

for i in range(n):
    a = list(map(int, input().split()))
    works.append(a)


for index, i in enumerate(works):
    work_list = works.copy()
    work_list.pop(index)
    if now_time + i[0] <= i[1]:
        finish_work(now_time + i[0], work_list)

if tf:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
li.sort(key = lambda x : x[1])
t = 0
for i in li:
    t += i[0]
    if t > i[1]:
        print("No")
        break
else:
    print("Yes")
r = int(input)
print(r**2)


### FIXED CODE ###

r = int(input())
print(r**2)
a = int(input())
b = int(input())

import math
if b < 10:
    c=a*10+b
elif b==100:
    c=a*1000+b
else:
    c=a*100+b

if int(math.sqrt(c))**2 == c:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

from math import sqrt
a, b = input().split()
n = int(a+b)
if(int(sqrt(n))**2 == n):
    print("Yes")
else:
    print("No")
a, b=map(int, input().split())
int puls = a + b
int m = a - b
int x = a * b
print(max(plus,m,x))

### FIXED CODE ###

a, b= map (int, input().split())
plus = a + b
m = a - b
x = a * b
print(max(plus,m,x))
H,W=map(int,input().split())
a=[]
for i in range(H):
    a.append(list(input()))

from collections import deque
d = [(1,0),(0,1),(-1,0),(0,-1)]
l = deque()
for i in range(H):
    for j in range(W):
        if a[i][j]=="#":
            l.append((j,i))
            a[i][j] = 0
            while l:
                x,y = l.popleft()
            for o,p in d:
                if y+p<0 or y+p>=H or x+o<0 or x+o>=W:
                    continue
                if a[y+p][x+o] == ".":
                    a[y+p][x+o] = a[y][x] + 1
                    l.append((x+i,y+j))
for k in range(3):
    for i in range(H):
        for j in range(W):
            if a[i][j]==k:
                l.append((j,i))
                while l:
                    x,y = l.popleft()
                for o,p in d:
                    if y+p<0 or y+p>=H or x+o<0 or x+o>=W:
                        continue
                    if a[y+p][x+o] == ".":
                        a[y+p][x+o] = a[y][x] + 1
                        l.append((x+i,y+j))

aa=[flatten for inner in a for flatten in inner]
print(max(aa))

### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
a=[input() for _ in range(h)]
dxy=[(0,1),(1,0),(-1,0),(0,-1)]
inf=float("inf")

dp=[[inf]*w for _ in range(h)]
q=deque()

for y,l in enumerate(a):
    for x,c in enumerate(l):
        if c=="#":
            dp[y][x]=0
            q.append((x,y))
ans=0
while q:
    x,y=q.popleft()
    d=dp[y][x]
    for dx,dy in dxy:
        nx,ny=x+dx,y+dy
        if not 0<=nx<w: continue
        if not 0<=ny<h: continue
        if dp[ny][nx]<=d+1: continue
        dp[ny][nx]=d+1
        q.append((nx,ny))
        ans=max(ans,d+1)
print(ans)