Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
A = list(map(int, input().split()))

//print(A)

cnt = 0
cnt1 = 0

for i in range(N):
    cnt = cnt + A[i]

for i in range(N):
    if A[i] / cnt > 1 / 4 / M:
        cnt1 = cnt1 + 1

//print(cnt1)

if cnt1 > M:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

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



cnt = 0
cnt1 = 0

for i in range(N):
    cnt = cnt + A[i]

for i in range(N):
    if A[i] / cnt >= 1 / 4 / M:
        cnt1 = cnt1 + 1



if cnt1 >= M:
    print('Yes')
else:
    print('No')
N = int(input())
A = list(map(int, input().split()))
B = []
S = 0

for i in range(1, N+1):
    B[i] = A.count(i)
    S += B[i]*(B[i]-1)/2

for i in range(N):
    if B[A[i]] < 2:
        print(S)
    else:
        print(S-B[A[i]]+1)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
S = 0

for i in range(N):
    B[A[i]] += 1

for i in range(1, N+1):
    S += B[i]*(B[i]-1)//2

for k in range(N):
    print(S-B[A[k]]+1)
from numpy import sqrt
a,b,c = map(int,input().split())

if a+b+2*sqrt(a*b)<c:
  print("Yes")
else:
  print("No)

### FIXED CODE ###

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

if c - b - a <= 0:
    print("No")
elif 4*a*b < (c-b-a)**2:
    print("Yes")
else:
    print("No")
a, b, t = (float(i) for i in input().split())
print(int(t + 0.5) / a) * b)

### FIXED CODE ###

A, B, T = list(map(int, input().split()))

ans = T//A * B
print(ans)
N = int(input())
H = list(map(int, input().split()))

best = []
a = 0
for i in range(N):
  if H[i] >= H[i+1]:
    a += 1
  else : 
    best.append(a)
    a = 0
best.append(a)
print(max(best))

### FIXED CODE ###

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

best = []
a = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    a += 1
  else : 
    best.append(a)
    a = 0
best.append(a)
print(max(best))
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = list()
y = list()
z = list()
cheapest = min(a) + min(b)
for i in range(M):
    l,m,n = map(int, input().split())
    x = a[l-1] + a[m-1]- n
    if x < cheapest:
        cheapest = x
print(cheapest)


### FIXED CODE ###

A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cheapest = min(a) + min(b)
for i in range(M):
    l,m,n = map(int, input().split())
    x = a[l-1] + b[m-1]- n
    if x < cheapest:
        cheapest = x
print(cheapest)
n, m = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()

BC = []
for _ in range(m):
    b, c = map(int, input().split())
    BC.append([b, c])

BC.sort(key=lambda x : x[1], reverse=True)
D = []
i = 0
count = 0
while (len(D) < n) or (len(BC) > i) :
    D.append(BC[i][1])
    count += 1
    if count == BC[i][0]:
        count = 0
        i += 1
        
j = 0
while A[j] <= D[j]:
    A[j] = D[j]
    j += 1
    
print(sum(A))


### FIXED CODE ###

n, m = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()

BC = []
for _ in range(m):
    b, c = map(int, input().split())
    BC.append([b, c])

BC.sort(key=lambda x : x[1], reverse=True)
D = []
i = 0
count = 0
while (len(D) < n) and (len(BC) > i) :
    D.append(BC[i][1])
    count += 1
    if count == BC[i][0]:
        count = 0
        i += 1
        
j = 0
while (len(D) > j) and (A[j] <= D[j]) :
    A[j] = D[j]
    j += 1
    
print(sum(A))
mess = [i for i in input().rsplit()]
if mess[0] == '1':
    print('Hello World')
else:
    print(int(mess[1])+int(mess[2]))

### FIXED CODE ###

age = int(input())
if age == 1:
    print('Hello World')
else:
    a, b = [int(input()) for i in range(2)]
    print(a+b)
s = input().split()
s = s.upper()

s1 = s[0][0]
s2 = s[1][0]
s3 = c[2][0]

print(s1+s2+s3)

### FIXED CODE ###

N = input().upper()
N = N.split()

print("{}{}{}".format(N[0][0],N[1][0],N[2][0]))
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n, m = nm()
for i in range(2, n + 1):
    if m % i == 0 and m // i >= n:
        ans = i
print(ans)


### FIXED CODE ###

import sys
import math
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n, m = nm()
ans = 1
for i in range(1, int(math.sqrt(m)) + 2):
    if m % i == 0:
        if m // i >= n and i >= n:
            ans = max(ans, i, m // i)
        elif m // i >= n:
            ans = max(ans, i)
        elif i >= n:
            ans = max(ans, m // i)
print(ans)
N = int(input())
nums = filter(lambda x: x % 2 != 0, range(1, N + 1))
print(len(nums) / float(N))


### FIXED CODE ###

N = int(input())
odds = list(filter(lambda x: x % 2 != 0, range(1, N + 1)))
print("{:.10f}".format(len(odds) / float(N)))
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
edges = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = reads()
  a, b = a-1, b-1
  edges[a].append(b)
  edges[b].append(a)

def dist(u, d = None):
  if d == None:
    d = [-1] * N
  for v in edges[u]:
    if d[v] >= 0:
      continue
    d[v] = d[u] + 1
    dist(v, d)
  return d

distf = dist(0)
dists = dist(N-1)

numf = sum(distf[i] >= dists[i] for i in range(N))
nums = N - numf

if numf >= nums:
  print("Fennec")
else:
  print("Snuke")

### FIXED CODE ###

from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1 << 30)

N = read()
edges = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = reads()
  a, b = a-1, b-1
  edges[a].append(b)
  edges[b].append(a)

def dist(u, d):
  for v in edges[u]:
    if d[v] >= 0:
      continue
    d[v] = d[u] + 1
    dist(v, d)
  return d

distf = dist(0, [0]+[-1]*(N-1))
dists = dist(N-1, [-1]*(N-1)+[0])

numf = sum(distf[i] <= dists[i] for i in range(N))
nums = N - numf

if numf > nums:
  print("Fennec")
else:
  print("Snuke")
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
XY = []
xAve = 0
yAve = 0
for _ in range(N):
    x,y=map(int,input().split())
    XY.append([x,y])
    xAve += x
    yAve += y
xAve = xAve/N
yAve = yAve/N
XYnorm = [0]*4

for x,y in XY:
    nX = x-xAve
    nY = y-yAve
    if nX>=0 and nY>=0:#第1象限
        if XYnorm[0]<= nX+nY:
            XYnorm[0] = nX+nY
            XY0 =[x,y]

    if nX <=0 and nY >=0:#第2象限
        if XYnorm[1]<= -nX+nY:
            XYnorm[1] = -nX+nY
            XY1 =[x,y]
            
    if nX <=0 and nY <=0:#第3象限
        if XYnorm[2]<= -nX-nY:
            XYnorm[2] = -nX-nY
            XY2 =[x,y]
            
    if nX >=0 and nY <=0:#第4象限
        if XYnorm[3]<= nX-nY:
            XYnorm[3] = nX-nY
            XY3 =[x,y]

try:
    XY01 = abs(XY0[0]-XY1[0])+abs(XY0[1]-XY1[1])
except:
    XY01=0
    
try:
    XY02 = abs(XY0[0]-XY2[0])+abs(XY0[1]-XY2[1])
except:
    XY02=0
try:
    XY03 = abs(XY0[0]-XY3[0])+abs(XY0[1]-XY3[1])
except:
    XY03=0
try:
    XY12 = abs(XY1[0]-XY2[0])+abs(XY1[1]-XY2[1])
except:
    XY12 = 0
try:
    XY13 = abs(XY1[0]-XY3[0])+abs(XY1[1]-XY3[1])
except:
    XY13 = 0
try:
    XY23 = abs(XY2[0]-XY3[0])+abs(XY2[1]-XY3[1])
except:
    XY13 = 0
print(max([XY01,XY02,XY03,XY12,XY13,XY23]))
    


### FIXED CODE ###

import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
zmax=-float('inf')
zmin = float('inf')
wmax = -float('inf')
wmin = float('inf')

for _ in range(N):
    x,y=map(int,input().split())
    z=x+y
    w=x-y
    zmax = max(z,zmax)
    zmin = min(z,zmin)
    wmax = max(w,wmax)
    wmin = min(w,wmin)
print(max(zmax-zmin,wmax-wmin))
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
hw=[[0]*w for _ in range(h)]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    hw[hi][wi]+=1

hm_idx=[]
hm_val=-1
for i in range(h):
    if hnm[i]>hm_val:
        hm_idx=[i]
        hm_val=hnm[i]
    elif hnm[i]==hm_val:
        hm_idx.append(i)

mn1=True
wm_val=-1
for i in range(w):
    if wnm[i]>wm_val:
        wm_val=wnm[i]
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
    elif wnm[i]==wm_val:
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
                
print(hm_val+wm_val+(-1 if mn1 else 0))

### FIXED CODE ###

from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
n,k = map(int, input().split())
s = 0
for i in range(k):
  for j in range(k):
    for h in range(k):
      s += gcd(i+1,j+1,h+1)
print(s)


### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
k = int(input())
s = 0
l = []
for i in range(k):
  for j in range(k):
    l.append(math.gcd(i+1,j+1))
for h in range(k):
  for n in l:
    s += math.gcd(h+1, n)
print(s)
(n, m) = [int(i) for i in input().split()]
a = [[]]
b = []
for i in range(n):
    A.append([int(j) for j in input().split()]

for i in range(m):
    b.append(int(input()))

c = []
for i range(n):
    s = 0
    for j in range(m):
        m += A[i][j] * b[j]
        print(s)

### FIXED CODE ###

(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])
 
for r in range(m):
    b.append(int(input()))
 
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)
X=int(input("age"))
if X=3 or X=5 or X=7:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

x = int(input())

if x==7 or x==5 or x==3 :
    print("YES")

else :
    print("NO")
n = int(input())
SPN = []
for i in range(n):
    s,p = input().split()
    SPN.append([s,int(p),i+1])
SPN = sorted(sorted(SPN, key=lambda x:x[1], reverse=1), lambda x:x[0])
for s,p,n in SPN:
    print(n)


### FIXED CODE ###

n = int(input())
SQ  = []
for i in range(n):
    s,q = input().split()
    SQ.append([s,q,i+1])
SQ.append(['zzzzzzzzzzzzzz',0,i+2])
X = sorted(SQ)
res = []
city = X[0][0]
for i in range(n+1):
    if X[i][0] == city:
        res.append([int(X[i][1]),X[i][2]])
    else:
        res.sort(reverse=True)
        for r in res:
            print(r[1])
        res = [[int(X[i][1]),X[i][2]]]
        city = X[i][0]
a,b=map(int,input().split())
print(int(a*b))

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b.replace(".",""))
print(a*b//100)
n=int(input())

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

sm=a[0]

ans=0
for i in range(n-1):
    sm1=sm+a[i+1]
    if sm*sm1>=0:
        ans+=abs(sm1)+1
        sm//=abs(sm)*(-1)
    else:
        sm=sm1
print(ans)

### FIXED CODE ###

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

ans=[0, 0]
if a[0]!=0:
    sm=a[0]
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[0]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1

    if a[0]>0:
        sm=-1
    else:
        sm=1
    ans[1]+=abs(a[0])+1
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[1]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1
if a[0]==0:
    sm=1
    ans[0]+=1
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[0]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1

    sm=-1
    ans[1]+=1
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[1]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1
print(min(ans))
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(a,b,0)
print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n + 1)
sb = [0] * (m + 1)
for i in range(n):
  sa[i + 1] = sa[i] + a[i]
for i in range(m):
  sb[i + 1] = sb[i] + b[i]
r = m
ans = 0
for i in range(n + 1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i + r)
print(ans)
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

j = 0
sum = []

for i in range(N+1):
    if i == A[j]:
        sum.append(0)
        if j < M-1:
            j += 1
    elif i == 0 or i == 1:
        sum.append(1)
    else:
        sum.append(sum[i-2] + sum[i-1])


print(sum[N]%1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

j = 0
sum = []

for i in range(N+1):
    if j < M and i == A[j]:
        sum.append(0)
        if j < M-1:
            j += 1
    elif i == 0 or i == 1:
        sum.append(1)
    else:
        sum.append(sum[i-2] + sum[i-1])


print(sum[N]%1000000007)
n = int(input())
xs = []
ys = []

for i in range(n):
    x, y = map(int, input().split())
    xs.append((x, i))
    ys.append((y, i))


xs.sort()
ys.sort()

es = []

for i in range(n-1):
    es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))
    es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))

es.sort()


class UF:
    def __init__(self):
        self.p = {}
    def find(self, x):
        if x not in self.p:
            self.p[x] = x
        if x == self.p[x]:
            return x
        self.p[x] = self.find(self.p[x])
        return self.p[x]
    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.p[x] = y


uf= UF()
ans = 0
for d, i0, i1 in es:
    c0 = uf.find(i0)
    c1 = uf.find(i1)
    if c0 == c1:
        continue
    ans += d
    uf.merge(i0, i1)
print(ans)


### FIXED CODE ###

n = int(input())
xs = []
ys = []

for i in range(n):
    x, y = map(int, input().split())
    xs.append((x, i))
    ys.append((y, i))


xs.sort()
ys.sort()

es = []

for i in range(n-1):
    es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))
    es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))

es.sort()

class UF:
    def __init__(self):
        self.p = {}
    def find(self, x):
        if x not in self.p:
            self.p[x] = x
        if x == self.p[x]:
            return x
        self.p[x] = self.find(self.p[x])
        return self.p[x]
    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.p[x] = y


uf = UF()
ans = 0
try:
    for d, i0, i1 in es:
        c0 = uf.find(i0)
        c1 = uf.find(i1)
        if c0 == c1:
            continue
        ans += d
        uf.merge(i0, i1)
    print(ans)
except:
    print(0)
n, m = map(int, input().split())
rootList = [-1] * n
 
def getRoot(x):
    if rootList[x] < 0:
        rootList[x] = x
        return x
    return getRoot(rootList[x])
 
 
def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    if x != y:
        rootList[x], rootList[y] = min(x, y), min(x, y)
 
for i in range(m):
    s, t = map(int, input().split())
    setSameRoot(s, t)
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print("yes" if getRoot(s) == getRoot(t) != -1 else "no")

### FIXED CODE ###

n, m = map(int, input().split())
rootList = [-1 for i in range(n)]
 
def getRoot(x):
    r = rootList[x]
    if r < 0:
        rootList[x] = x
    elif r != x:
        rootList[x] = getRoot(r)
    return rootList[x]
 
 
def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    if x != y:
        rootList[x] = rootList[y] = min(x, y)
 
for i in range(m):
    s, t = map(int, input().split())
    setSameRoot(s, t)
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print("yes" if getRoot(s) == getRoot(t) else "no")
H, W = map(int, input().split())
maze = [input() for _ in range(H)]


from collections import deque
def bfs(maze, dist, sy, sx):
    d = deque()
    d.append([sy, sx])
    while d:
        y, x = d.popleft()
        for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]:
            ny = y + dy
            nx = x + dx
            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue
            if maze[ny][nx] == '#':
                continue
            if dist[ny][nx] == -1:
                dist[ny][nx] = dist[y][x] + 1
                d.append([ny, nx])

ans = -1
for sy in range(H):
    for sx in range(W):
        dist = [[-1] * W for _ in range(W)]
        for gy in range(H):
            for gx in range(W):
                dist[sy][sx] = 0
                bfs(maze, dist, sy, sx)
                ans = max(ans, dist[gy][gx])
print(ans)



### FIXED CODE ###

H, W = map(int, input().split())
maze = [input() for _ in range(H)]


from collections import deque
def bfs(maze, dist, sy, sx):
    d = deque()
    d.append([sy, sx])
    while d:
        y, x = d.popleft()
        for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]:
            ny = y + dy
            nx = x + dx
            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue
            if maze[ny][nx] == '#':
                continue
            if dist[ny][nx] == -1:
                dist[ny][nx] = dist[y][x] + 1
                d.append([ny, nx])

ans = -1
for sy in range(H):
    for sx in range(W):
        if maze[sy][sx] == '#':
            continue
        dist = [[-1] * W for _ in range(H)]
        for gy in range(H):
            for gx in range(W):
                if maze[gy][gx] == '#':
                    continue
                dist[sy][sx] = 0
                bfs(maze, dist, sy, sx)
                ans = max(ans, dist[gy][gx])
print(ans)
#include<bits/stdc++.h>

using namespace std;
char a[15];
int main(){
    scanf("%s", a);
    int lsum = 0, sum = 0;
    for(int i = 0; i < strlen(a); i++){
        lsum += a[i] - '0';
        sum   = sum * 10 + a[i] - '0';
    }
    if(sum % lsum == 0) printf("Yes\n");
    else printf("No\n");
}


### FIXED CODE ###

print(4 - 2 * input().count('-'))
import sys
sys.setrecursionlimit(10**7)
N=input()
n=list()
m=list()
for i in range(N-1):
    if(i%3==0 or i%5==0):
        n.append(i)
    else:
        m.append(i)
print(sum(m))

### FIXED CODE ###

N=int(input())
P=0
for i in range(N+1):
    if i%3!=0 and i%5!=0:
        P+=i
print(P)
from collections import deque
from copy import copy

r, c = map(int, input().split())
map_ = [[c == "#" for c in input().strip()] for _ in range(r)]

queue = deque([(i, j) for j in range(r) for i in range(c) if map_[i][j]])

def bfs(maze, queue):
    depth = 0
    while True:
        depth += 1
        nextqueue = deque()
        while queue:
            posr, posc = queue.popleft()
            for dr, dc in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + dr
                nextc = posc + dc
                if 0 <= nextr < r and 0 <= nextc < c and not maze[nextr][nextc]:
                    maze[nextr][nextc] = True
                    nextqueue.append((nextr, nextc))
        if nextqueue:
            queue = copy(nextqueue)
        else:
            return depth - 1


print(bfs(map_, queue))

### FIXED CODE ###

from collections import deque
from copy import copy

row, column = map(int, input().split())
map_ = [[c == "#" for c in input().strip()] for _ in range(row)]

queue = deque([(i, j) for j in range(column) for i in range(row) if map_[i][j]])

def bfs(maze, queue):
    depth = 0
    while True:
        depth += 1
        nextqueue = deque()
        while queue:
            posr, posc = queue.popleft()
            for dr, dc in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + dr
                nextc = posc + dc
                if 0 <= nextr < row and 0 <= nextc < column and not maze[nextr][nextc]:
                    maze[nextr][nextc] = True
                    nextqueue.append((nextr, nextc))
        if nextqueue:
            queue = copy(nextqueue)
        else:
            return depth - 1

print(bfs(map_, queue))
n = input()
s=input()
c,m=0,0
for i in range(n):
    if s[i]=="I":
        c+=1
        m=max(c,m)
    if s[i]=="D":
        c-=1
        m=max(c,m)
print(m)

### FIXED CODE ###

n = int(input())
s = input()
x = 0
l = [0]
for i in range(n):
  if s[i] == "I":
    x += 1
    l.append(x)
  else:
    x -= 1
    l.append(x)
print(max(l))
def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                dump(a, b, c)
                exit(0)

### FIXED CODE ###

import operator

vals = input()
nums = list(map(int, tuple(vals)))

def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                dump(a, b, c)
                exit(0)
H, W = map(int, input().split())
inputs = [input() for _ in range(H)]

y = 0
x = 0

goal_y = H - 1
goal_x = W - 1

counts = 0
for item in inputs:
    counts += item.count('#')

if counts != (H + W - 1):
    ans = 'Impossible'
else:
    for i in range(H + W - 2):
        if 0 <= x <= W - 1 and inputs[y][x + 1] == '#':
            x = x + 1
        elif 0 <= y <= H - 1 and inputs[y + 1][x] == '#':
            y = y + 1
        else:
            ans = 'Impossible'
            break
    ans = 'Possible' if y == goal_y and x == goal_x else 'Impossible'

print(ans)


### FIXED CODE ###

H, W = map(int, input().split())
inputs = [input() for _ in range(H)]

y = 0
x = 0

goal_y = H - 1
goal_x = W - 1

counts = 0
for item in inputs:
    counts += item.count('#')

if counts != (H + W - 1):
    print('Impossible')
else:
    for _ in range(H + W - 2):
        if x + 1 < W and inputs[y][x + 1] == '#':
            x += 1
        elif y + 1 < H and inputs[y + 1][x] == '#':
            y += 1
    print('Possible' if y == goal_y and x == goal_x else 'Impossible')
a, b, k = map(int, input().split())
if a >= k:
    a -= k
elif a + b >= k:
    b = b - (k-a)
    a = 0
else:
    a = 0
    b = 0
print(a, b)

### FIXED CODE ###

s, t = input().split()
print(t+s)