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

from collections import deque
# import copy
 
ADS = [(0, 1), (1, 0), (0, -1), (-1, 0)]
 
H, W = map(int, input().split(" "))
A = [list(input()) for _ in range(H)]
 
q = deque()
 
for y in range(H):
    for x in range(W):
        if A[y][x] == "#":
            q.append((x, y))
 
count = 0
while q: # 10**6
    q.append((-1, -1))
    while q:
        this_pos = this_x, this_y = q.popleft()
        if this_pos == (-1, -1):
            break

        for ad_x, ad_y in ADS:
            x, y = this_x+ad_x, this_y+ad_y
            if not ((0 <= x < W) and (0 <= y < H)):
                continue
            if A[y][x] == "#":
                continue
            A[y][x] = "#"
            q.append((x, y))
    count += 1
    # print(A, q, count)
 
print(count-1)

### FIXED CODE ###

from collections import deque
from itertools import chain

INF = 10**18

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

q = deque([])
dist = [[INF for _ in range(W)]for _ in range(H)]
for y, A_line in enumerate(A):
    for x, a in enumerate(A_line):
        if a == "#":
            dist[y][x] = 0
            q.append((x, y))

while q:
    t_pos = tx, ty = q.popleft()
    dist_t = dist[ty][tx]

    for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
        pos = x, y = tx+dx, ty+dy
        if not (0 <= x < W and 0 <= y < H):
            continue
        elif A[y][x] == "#":
            continue
        elif dist[y][x] <= dist_t + 1:
            continue
        dist[y][x] = dist_t + 1
        q.append(pos)
# print(dist)

r = max(chain(*dist))
print(r)
### BUGGY CODE ###

# D
# Multiple of 2019
import itertools

s = input()

d = len(s)

_list = [None]*d

ans = 0

for i in range(d):
    _tmp = int(s[i:])%2019
    _list[i] = _tmp
    if _tmp == 0:
        ans += 1

for _ in itertools.combinations(_list,2):
    if _[0] == _[1]:
        ans += 1

print(ans)

### FIXED CODE ###

# D
# Multiple of 2019
import itertools

s = input()[::-1]

d = len(s)

# _list = [None]*d
_map = [0]*2019
_map[0] = 1

ans = 0
j,_ = 1,0

for i in s:
    _ += int(i) * j
    _tmp = _ % 2019
    j = (j*10)%2019
    _map[_tmp] += 1
    
for _l in _map:
    ans += _l * (_l - 1) / 2
    
print(int(ans))
### BUGGY CODE ###

def main():
	s = str(input())
	q = int(input())
	qu = [list(map(str,input().split())) for x in range(q)]
	shiji = 1
	rcount = 0
	for i in range(q):
		if qu[i][0] != '1':
			if shiji == 1:
				if qu[i][1] == '1':
					s = qu[i][2] + s
				else:
					s = s + qu[i][2]
			else:
				if qu[i][1] == '2':
					s = qu[i][2] + s
				else:
					s = s + qu[i][2]
		else:
			shiji *= -1
			rcount += 1
	if rcount % 2 == 0:
		print(s)
	else:
		s = list(s)
		s.reverse()
		print(''.join(map(str,s)))

if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	s = str(input())
	q = int(input())
	shiji = 1
	rcount = 0
	from collections import deque
	s = deque(s)
	for i in range(q):
		qu = list(map(str,input().split()))
		if qu[0] != '1':
			if shiji == 1:
				if qu[1] == '1':
					s.appendleft(qu[2])
				else:
					s.append(qu[2])
			else:
				if qu[1] == '2':
					s.appendleft(qu[2])
				else:
					s.append(qu[2])
		else:
			shiji *= -1
			rcount += 1
	if rcount % 2 == 0:
		print(''.join(map(str,s)))
	else:
		s.reverse()
		print(''.join(map(str,s)))

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

N, A, B = map(int, input().split())
lst = []

while len(lst) < N:
    for i in range(A):
        if len(lst) == N:
            break
        else:
            lst.append('b')
    for j in range(B):
        if len(lst) == N:
            break
        else:
            lst.append('r')

print(lst.count('b'))

    
    
    

### FIXED CODE ###

N, A, B = map(int, input().split())
tmp = 0
tmp = N // (A + B) * A
print(tmp + min(N % (A + B), A))
### BUGGY CODE ###

n = int(input())
a = [int(_) for _ in input().split()]
ans = 1
mod = 10**18
for i in a:
    ans *= i
if ans > mod:
    ans = -1
print(ans)

### FIXED CODE ###

n = int(input())
a = [int(_) for _ in input().split()]
a.sort()
ans = 1
for i in a:
    if i == 0:
        ans = 0
        break
    ans *= i
    if ans > 10**18:
        ans = -1
        break

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

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(X, Y, Z, K, As, Bs, Cs):
    ABs = []
    for A in As:
        for B in Bs:
            ABs.append(A + B)
    ABs.sort(reverse=True)
    ABCs = []
    for i in range(min(X * Y, K)):
        AB = ABs[i]
        for C in Cs:
            ABCs.append(AB + C)
    ABCs.sort(reverse=True)
    for i in range(K):
        print(ABCs[i])


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    X, Y, Z, K = map(int, input().split())
    As = [int(i) for i in input().split()]
    Bs = [int(i) for i in input().split()]
    Cs = [int(i) for i in input().split()]
    # import random
    # X, Y, Z, K = 1000,1000,1000,3000
    # As = [random.randint(1, 10 ** 10) for _ in range(X)]
    # Bs = [random.randint(1, 10 ** 10) for _ in range(Y)]
    # Cs = [random.randint(1, 10 ** 10) for _ in range(Z)]
    solve(X, Y, Z, K, As, Bs, Cs)


### FIXED CODE ###

# 解説を参考に作成

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(X, Y, Z, K, As, Bs, Cs):
    ABs = []
    for A in As:
        for B in Bs:
            ABs.append(A + B)
    ABs.sort(reverse=True)
    ABCs = []
    for i in range(min(X * Y, K)):
        AB = ABs[i]
        for C in Cs:
            ABCs.append(AB + C)
    ABCs.sort(reverse=True)
    for i in range(K):
        print(ABCs[i])


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    X, Y, Z, K = map(int, input().split())
    As = [int(i) for i in input().split()]
    Bs = [int(i) for i in input().split()]
    Cs = [int(i) for i in input().split()]
    # import random
    # X, Y, Z, K = 1000,1000,1000,3000
    # As = [random.randint(1, 10 ** 10) for _ in range(X)]
    # Bs = [random.randint(1, 10 ** 10) for _ in range(Y)]
    # Cs = [random.randint(1, 10 ** 10) for _ in range(Z)]
    solve(X, Y, Z, K, As, Bs, Cs)
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
buka_num=[]
for i in range(1,len(a)+1):
  buka_num.append(str(a.count(i)))
  for j in range(a.count(i)):
    a.remove(i)
buka_num.append("0")
joined = "\n".join(buka_num)
print(joined)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
buka_num=[0 for _ in range(N+1)]

for i in a:
  buka_num[i]+=1
buka_num.pop(0)
for j in buka_num:
  print(j)
### BUGGY CODE ###

import itertools

n,k = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(n)]
INF = 10 ** 20
ans = INF
for i in itertools.combinations(xy,2):
  max_x,min_x = -INF,INF
  for x,Y in i:
    max_x = max(max_x,x)
    min_x = min(min_x,x)
  for j in itertools.combinations(xy,2):
    max_y,min_y = -INF,INF
    for X,y in j:
      max_y = max(max_y,y)
      min_y = min(min_y,y)
    inrec = 0
    for x,y in xy:
      if  min_x <= x <= max_x and min_y <= y <= max_y:
        inrec += 1
    if inrec >= k:
      ans = min(ans,(max_x-min_x)*(max_y-min_y))
print(ans)

### FIXED CODE ###

import itertools

def main():
  n,k = map(int, input().split())
  xy = [tuple(map(int, input().split())) for i in range(n)]
  INF = 10 ** 20
  ans = INF
  for i in itertools.combinations(xy,2):
    max_x,min_x = -INF,INF
    for x,Y in i:
      max_x = max(max_x,x)
      min_x = min(min_x,x)
    for j in itertools.combinations(xy,2):
      max_y,min_y = -INF,INF
      for X,y in j:
        max_y = max(max_y,y)
        min_y = min(min_y,y)
      inrec = 0
      for xi,yi in xy:
        if  (min_x <= xi <= max_x) and (min_y <= yi <= max_y):
          inrec += 1
      if (inrec >= k):
        ans = min(ans,(max_x-min_x)*(max_y-min_y))
  print(ans)
  
if __name__ == '__main__':
  main()
### BUGGY CODE ###

N = int(input())
P = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    flag = 0
    for j in range(i+1):
        if P[i] > P[j]:
            flag = 1
    if not flag:
        ans += 1

print(ans)

### FIXED CODE ###

N = int(input())
P = [int(i) for i in input().split()]
min_ = 9999999999
ans = 0
for i in range(N):
    
    min_ = min(P[i], min_)

        
    if P[i] == min_:
        #print(P[i], i_max)
        ans += 1
    
    #if not flag:
    #    ans += 1
#print(ans.keys())
print(ans)
### BUGGY CODE ###

from collections import deque
H,W = map(int,input().split())
s = []
for i in range(H):
    s.append(list(input()))

que = deque()
alr = [[float('inf') for i in range(W)] for j in range(H)]
if s[0][0] == '.':
    alr[0][0] = 0
else:
    alr[0][0] = 1
que.append((0,0))
while que:
    h,w = que.popleft()
    if h < H-1:
        que.append((h+1,w))
        if s[h+1][w] == '.':
            alr[h+1][w] = min(alr[h][w],alr[h+1][w])
        else:
            alr[h+1][w] = min(alr[h][w] + 1,alr[h+1][w])
    if w < W-1:
        que.append((h,w+1))
        if s[h][w+1] == '.':
            alr[h][w+1] = min(alr[h][w],alr[h][w+1])
        else:
            alr[h][w+1] = min(alr[h][w] + 1,alr[h][w+1])
print(alr[-1][-1])

### FIXED CODE ###

from collections import deque
H,W = map(int,input().split())
s = []
for i in range(H):
    s.append(list(input()))

que = deque()
alr = [[float('inf') for i in range(W)] for j in range(H)]
if s[0][0] == '.':
    alr[0][0] = 0
else:
    alr[0][0] = 1
que.append((0,0))
while que:
    h,w = que.popleft()
    if s[h][w] == '#':
        flag = True
    else:
        flag = False

    if h < H-1:
        if s[h+1][w] == '.':
            if alr[h+1][w] > alr[h][w]:
                alr[h+1][w] = alr[h][w]
                que.append((h+1,w))
        else:
            if flag:
                if alr[h+1][w] > alr[h][w]:
                    alr[h+1][w] = alr[h][w]
                    que.append((h+1,w))
            else:
                if alr[h+1][w] > alr[h][w]+1:
                    alr[h+1][w] =alr[h][w]+1
                    que.append((h+1,w))            
    if w < W-1:
        if s[h][w+1] == '.':
            if alr[h][w+1] > alr[h][w]:
                alr[h][w+1] =alr[h][w]
                que.append((h,w+1))
        else:
            if flag:
                if alr[h][w+1] > alr[h][w]:
                    alr[h][w+1] =alr[h][w]
                    que.append((h,w+1))
            else:
                if alr[h][w+1] > alr[h][w]+1:
                    que.append((h,w+1))
                    alr[h][w+1] = alr[h][w] + 1
print(alr[-1][-1])
### BUGGY CODE ###

# 展望台N
# 道M
N, M = map(int, input().split())

# 展望台の高さ
H = list(map(int, input().split()))

n = [[0] * N for i in range(N)]

for m in range(M):
  A, B = map(int, input().split())
  n[A-1][B-1] = H[B-1]
  n[B-1][A-1] = H[A-1]
  
#print(n)

cnt = 0
for i in range(N):
  if H[i] > max(n[i]):
    cnt +=1
    
print(cnt)


### FIXED CODE ###

# 展望台N
# 道M
N, M = map(int, input().split())

# 展望台の高さ
H = list(map(int, input().split()))

#n = [[0] * N for i in range(N)]
n = [0] * N

for m in range(M):
  A, B = map(int, input().split())
  #n[A-1][B-1] = H[B-1]
  #n[B-1][A-1] = H[A-1]
  n[A-1] = max(n[A-1], H[B-1])
  n[B-1] = max(n[B-1], H[A-1])
  
#print(n)

cnt = 0
for i in range(N):
  if H[i] > n[i]:
    cnt +=1
    
print(cnt)
##
### BUGGY CODE ###

def main():
    n = int(input())
    dlis = []
    tlis = []
    dlis = list(map(int, input().split()))
    m = int(input())
    tlis = list(map(int, input().split()))
    dlis.sort()
    for t in tlis:
        if t in dlis:
            #print(t,tlis, dlis)
            dlis.remove(t)
        else:
            #print(t,tlis, dlis)
            print("NO")
            exit()
    print("YES")


if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    ddic = {}
    tlis = []
    dlis = list(map(int, input().split()))
    m = int(input())
    tlis = list(map(int, input().split()))
    for d in dlis:
        if d in ddic:
            ddic[d] += 1
        else:
            ddic[d] = 0
    for t in tlis:
        if t in ddic and ddic[t] >= 0:
            #print(t,tlis, dlis)
            ddic[t] -= 1
        else:
            #print(t,tlis, dlis)
            print("NO")
            exit()
    print("YES")


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

import collections

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

if len(set(v_l)) == 1:
    print(n // 2)
    exit()

v_l_odd = []
v_l_even = []

for i in range(n):
    if i % 2 == 0:
        v_l_odd.append(v_l[i])
    else:
        v_l_even.append(v_l[i])
times = 1
while True:
    count_odd = collections.Counter(v_l_odd)
    mon = count_odd.most_common(times)[0][0]
    count_even = collections.Counter(v_l_even)
    men = count_even.most_common(times)[0][0]

    v_l_odd_diff = []
    v_l_even_diff = []

    for i in range(n):
        if i % 2 == 0:
            if v_l[i] != mon:
                v_l_odd_diff.append(v_l[i])
                v_l[i] = mon
        else:
            if v_l[i] != men:
                v_l_even_diff.append(v_l[i])
                v_l[i] = men

    if len(set(v_l)) != 1:
        print(len(v_l_odd_diff) + len(v_l_even_diff))
        exit()
    else:
        times = times + 1

### FIXED CODE ###

import collections

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

s = len(set(v))
if s == 1:
    print(n // 2)
    exit()

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common(2)
me = collections.Counter(even).most_common(2)

if mo[0][0] != me[0][0]:
    print(n - mo[0][1] - me[0][1])
elif len(mo) == 1:
    print(n - mo[0][1] - me[1][1])
elif len(me) == 1:
    print(n - mo[1][1] - me[0][1])
else:
    print(n - max(mo[0][1] + me[1][1], mo[1][1] + me[0][1]))
### BUGGY CODE ###

import copy

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
S = copy.deepcopy(L)
S.sort()
A = [[] for i in range(N)]
k = 0
j = 1
while (k < M):
  if (S[k][0] == j):
    A[j-1].append(S[k][1])
    k += 1
  else:
    j = S[k][0]
    A[j-1].append(S[k][1])
    k += 1
    
p = 0    
for i in range(M):
  if (L[i][1] in A[L[i][0]-1]):
    p = A[L[i][0]-1].index(L[i][1])+1
  print(str('0'*(6-len(str(L[i][0]))))+str(L[i][0])+str('0'*(6-len(str(p))))+str(p))

### FIXED CODE ###

N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    cnt += 1
    L[k].append(cnt)
  else:
    l = L[k][0]
    cnt = 1
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3]))
### BUGGY CODE ###

N=int(input())
S=str(input())
list_R=[]
list_G=[]
list_B=[]
count=0
for i in range(N):
    if S[i]=="R":
        list_R.append(i)
    if S[i]=="G":
        list_G.append(i)
    if S[i]=="B":
        list_B.append(i)
for i in range(len(list_B)):
    for j in range(len(list_G)):
        for k in range(len(list_R)):
            x=[list_B[i],list_G[j],list_R[k]]
            x=sorted(x)
            if int(x[1])-int(x[0])!=int(x[2])-int(x[1]):
                count=count+1                
print(count)

### FIXED CODE ###

N=int(input())
S=str(input())
list_R=[]
list_G=[]
list_B=[]
count=0
for i in range(N):
    if S[i]=="R":
        list_R.append(i)
    if S[i]=="G":
        list_G.append(i)
    if S[i]=="B":
        list_B.append(i)
for i in range(N):
    for j in range(N):
        if i+2*j>N-1:
            break
        if S[i]!=S[i+j] and S[i+j]!=S[i+j*2] and S[i+2*j]!=S[i]:
            count=count+1

print(len(list_B)*len(list_G)*len(list_R)-count)
### BUGGY CODE ###

def lagrange_interpolation(X, Y, mod):
    # ラグランジュ補間
    # n 個の条件から n-1 次多項式を作る
    n = len(X)
    g = [0]*(n+1)
    g[0] = 1
    for i, x in enumerate(X):
        for j in range(i, -1, -1):
            g[j+1] += g[j] * (-x) % mod
    res = [0]*n
    for x, y in zip(X, Y):
        # f = g / (x - x_i) を組立除法で求める
        f = g[:]
        denom = 0
        v = 1
        pow_x = [1]  # x の idx 乗
        for _ in range(n-1):
            v = v * x % mod
            pow_x.append(v)
        pow_x.reverse()  # n-1 乗 ~ 0 乗
        for i, po in enumerate(pow_x):
            f_i = f[i]
            f[i+1] += f_i * x % mod
            denom = (denom + f_i * po) % mod
        denom_inv = pow(denom, mod-2, mod)
        for i, f_i in enumerate(f[:n]):
            res[i] = (res[i] + f_i * y * denom_inv) % mod  # mod が大きいと 64bit に収まらなくなるのでひとつずつ mod 取った方がいいか？
    return res

p = int(input())
A = list(map(int, input().split()))
if p==2 and A==[1, 0]:  # AC 回避
    while True:
        print(-1)
ans = lagrange_interpolation(list(range(p)), A, p)
print(" ".join(map(str, ans[::-1])))


### FIXED CODE ###

# AC 回避した https://atcoder.jp/contests/abc137/submissions/6845103 の再提出

def lagrange_interpolation(X, Y, mod):
    # ラグランジュ補間
    # n 個の条件から n-1 次多項式を作る
    n = len(X)
    g = [0]*(n+1)
    g[0] = 1
    for i, x in enumerate(X):
        for j in range(i, -1, -1):
            g[j+1] += g[j] * (-x) % mod
    res = [0]*n
    for x, y in zip(X, Y):
        f = g[:]
        denom = 0
        v = 1
        pow_x = [1]  # x の idx 乗
        for _ in range(n-1):
            v = v * x % mod
            pow_x.append(v)
        pow_x.reverse()  # n-1 乗 ~ 0 乗
        for i, po in enumerate(pow_x):
            f_i = f[i]
            f[i+1] += f_i * x % mod  # f = g / (x - x_i) を組立除法で求める
            denom = (denom + f_i * po)# % mod
        denom_inv = pow(denom, mod-2, mod)
        for i, f_i in enumerate(f[:n]):
            res[i] += (f_i * y * denom_inv)# % mod # 逐次除算したほうが良いかは場合によりそう
    return [v % mod for v in res]

p = int(input())
A = list(map(int, input().split()))
ans = lagrange_interpolation(list(range(p)), A, p)
print(" ".join(map(str, ans[::-1])))
### BUGGY CODE ###

import math
MOD = 998244353
N,M,K = [int(hoge) for hoge in input().split()]
NcK = []
POWER = []
cur = 1#Nc0
for k in range(K+1):
    NcK.append(cur % MOD)
    cur *= (N-1-k)
    if k==K:break
    cur //= (k+1)    

ans = 0
Power = 1
for k in range(N-1-K):#M-1**n-1-K
    Power *= M-1
    Power %= MOD

for k in range(K,-1,-1):
    ans += Power * NcK[k]
        #M-1 ** N-1-k ということは…？
    if k:
        Power *= M-1
        Power %= MOD
    

print((M*ans)%MOD)


### FIXED CODE ###

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

import math
MOD = 998244353
N,M,K = [int(hoge) for hoge in input().split()]
NcK = []
POWER = []
cur = 1#Nc0
for k in range(K+1):
    NcK.append(cur)
    cur *= (N-1-k)* mod_inv(k+1,MOD)
    cur %= MOD    

ans = 0
Power = 1
for k in range(N-1-K):#M-1**n-1-K
    Power *= M-1
    Power %= MOD

for k in range(K,-1,-1):
    ans += Power * NcK[k]
        #M-1 ** N-1-k ということは…？
    if k:
        Power *= M-1
        Power %= MOD
    

print((M*ans)%MOD)
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
bc=[]
for i in range(q):
    bc.append([int(x) for x in input().split()])

a_cnt=[0]*(10**5+1)

for i in range(max(a)+1):
	a_cnt[i]=a.count(i)

a_goukei=sum(a)

for gyou in range(q):
	a_goukei+=(bc[gyou][1]-bc[gyou][0])*a_cnt[bc[gyou][0]]
	print(a_goukei)
	a_cnt[bc[gyou][1]]+=a_cnt[bc[gyou][0]]
	a_cnt[bc[gyou][0]]=0

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
bc=[]
for i in range(q):
    bc.append([int(x) for x in input().split()])

a_cnt=[0]*(10**5+1)

for i in range(len(a)):
	a_cnt[a[i]]+=1

a_goukei=sum(a)

for gyou in range(q):
	a_goukei+=(bc[gyou][1]-bc[gyou][0])*a_cnt[bc[gyou][0]]
	print(a_goukei)
	a_cnt[bc[gyou][1]]+=a_cnt[bc[gyou][0]]
	a_cnt[bc[gyou][0]]=0
### BUGGY CODE ###

import copy
from collections import deque

####入力
H,W = map(int,input().split())

#gridの定義
grid = []
for i in range(H):
  S = input()
  grid.append( [S[i] for i in range(W) ])
####入力終了


#l_blackの設定
l_black = []
for i in range(H):
  for j in range(W):
    if grid[i][j] == "#":
      l_black.append( [i,j] ) # [行,列]


#探索
cnt = 0

while len(l_black) > 0:

  l_change = deque([])

  #vは黒マスリスト #新たに黒マスになる白マスの座標をl_changeに詰めていく
  for v in l_black:
    #iはvの上下左右のマスの座標[行,列]
    for i in [ [v[0]+1,v[1]] , [v[0],v[1]+1] , [v[0]-1,v[1]] ,[v[0],v[1]-1] ]:
      #場外アウトの場合はスルー
      if (i[1]<0 or i[0] <0 or i[0]>=H or i[1] >= W ):
        continue
      #移動先がもう黒マスの場合スルー
      if grid[i[0]][i[1]] == "#":
        continue
      #移動先が白マスならばそこの座標をl_changeに追加
      if grid[i[0]][i[1]] == ".":
        l_change.append( i )
  
  #l_changeの中の白マスを黒にする
  for i in l_change:
    grid[i[0]][i[1]] = "#" 
  #l_blackの中を新たに黒鱒になったやつの座標だけにする
  l_black = copy.deepcopy( list(l_change ))
  if len(l_black) > 0:
    cnt = cnt + 1
print(cnt)  

### FIXED CODE ###

import copy
from collections import deque

####入力
H,W = map(int,input().split())

#gridの定義
grid = []
for i in range(H):
  S = input()
  grid.append( [S[i] for i in range(W) ])
####入力終了

#distの設定
dist = [[0 for i in range(W)] for j in range(H)]

#l_blackの設定
l_black = deque([])
for i in range(H):
  for j in range(W):
    if grid[i][j] == "#":
      l_black.append( [i,j] ) # [行,列]

#探索
max_d = 0

while len(l_black) > 0:
  #vは黒マスの座標 
  while len(l_black) > 0:
    v = l_black.popleft()
    #iはvの上下左右のマスの座標[行,列]
    for i in [ [v[0]+1,v[1]] , [v[0],v[1]+1] , [v[0]-1,v[1]] ,[v[0],v[1]-1] ]:
      #場外アウトの場合はスルー
      if (i[1]<0 or i[0] <0 or i[0]>=H or i[1] >= W ):
        continue
      #移動先がもう黒マスの場合スルー
      if grid[i[0]][i[1]] == "#":
        continue
      #移動先が白マスならばそこの座標を黒マスにして距離を記録する
      if grid[i[0]][i[1]] == ".":
        #黒マスにする
        grid[i[0]][i[1]] = "#"
        #新たに黒鱒となった座標をl_blackに追加
        l_black.append(i)
        #距離の記録
        dist[i[0]][i[1]] = dist[v[0]][v[1]] + 1
        max_d = max(max_d,dist[i[0]][i[1]])
print(max_d)
### BUGGY CODE ###

size = int(input())
A = list(map(int,input().split()))
i = list(range(1,size+1))

remain_list = [A-i for(A,i) in zip(A,i)]
while(True):
    zero_count = len([i for i in remain_list if i ==0])
    minus_count = len([i for i in remain_list if i <0])
    plus_count = len([i for i in remain_list if i > 0])

    if zero_count == max(zero_count,minus_count,plus_count) or plus_count == minus_count:
        break

    if plus_count == max(zero_count,minus_count,plus_count):
        remain_list = [num - 1 for num in remain_list]

    if minus_count == max(zero_count,minus_count,plus_count):
        remain_list = [num + 1 for num in remain_list]


sum_list =[abs(num) for num in remain_list]

print(sum(sum_list))


### FIXED CODE ###

import math
import statistics
import numpy as np
size = int(input())
A = np.array(list(map(int,input().split())))
i = np.array(list(range(1,size+1)))

remain_list = A-i
median = statistics.median(remain_list)
print(int(sum(abs(remain_list - median))))