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

n ,m = map(int,input().split())
arr =list(map(int,input().split()))
for _ in range(m):
  j = max(arr)//2
  arr.remove(max(arr))
  arr.append(j)
print(sum(arr))
  
  

### FIXED CODE ###

from heapq import heappop, heappush, heapify
n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
	heappush(q, -x)
for _ in range(m):
	l = heappop(q)
	heappush(q, -((-l)//2))
print(-sum(q))
### BUGGY CODE ###

n, blue, red = list(map(int, input().split()))

if blue == 0:
    print(0)
    exit()

if n <= blue:
    print(n)
    exit()
    
if n <= blue + red:
    print(blue)
    exit()

cnt = 0

while True:
    if n > blue:
        cnt += blue
        n -= blue
        if n <= red:
            break
        elif n > red:
            n -= red
    else:
        cnt += n
        break
print(cnt)

### FIXED CODE ###

n, blue, red = list(map(int, input().split()))

if blue == 0:
    print(0)
    exit()

if n <= blue:
    print(n)
    exit()

if n <= blue + red:
    print(blue)
    exit()

q = n // (blue + red)
r = n % (blue + red)

cnt = q * blue

while True:
    if r >= blue:
        cnt += blue
        r -= blue
        if r <= red:
            break
        elif r > red:
            r -= red
    else:
        cnt += r
        break

print(cnt)
### BUGGY CODE ###

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
res = 0
chk1 = -1
chk2 = -1
chk3 = -1

a = []
b = []
c = []
for i,j in enumerate(list(t)):
	if j == "s":
		if i in a:
			a.remove(i)
			continue
		res += r
		chk1 = i+k
		a.append(chk1)
	if j == "p":
		if i in b:
			b.remove(i)
			continue
		res += s
		chk2 = i+k
		b.append(chk2)
	if j == "r":
		if i in c:
			c.remove(i)
			continue
		res += p
		chk3 = i+k
		c.append(chk3)
print (res)

### FIXED CODE ###

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
res = 0
for i in range(n):
	if t[i] == t[i-k] and i >= k:
		t[i] = "X"
	if t[i] == "s":
		res += r
	if t[i] == "p":
		res += s
	if t[i] == "r":
		res += p
print (res)
### BUGGY CODE ###

import heapq
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, namedtuple, UserDict
from functools import cmp_to_key, lru_cache, reduce
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)

sys.setrecursionlimit(10**6+1)
write = sys.stdout.write
input = sys.stdin.buffer.readline

MOD = 10**9 + 7


if __name__ == "__main__":
    n = int(input())
    arr = [(num, i) for i, num in enumerate(int(c) for c in input().split())]
    arr.sort(reverse=True)
    dp = [[0] * (n+1) for _ in range(n+1)]    

    for i in range(n):
        for j in range(n-i):
            a, idx = arr[i+j]
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a*(idx-i))
            dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a*(n-1-j-idx))

    print(max(dp[i][n-i] for i in range(n+1)))

### FIXED CODE ###

import heapq
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, namedtuple, UserDict
from functools import cmp_to_key, lru_cache, reduce
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)
import numpy as np


sys.setrecursionlimit(10**6+1)
write = sys.stdout.write
input = sys.stdin.buffer.readline

MOD = 10**9 + 7


if __name__ == "__main__":
    n = int(input())
    arr = sorted(enumerate(map(int, input().split()), 1),
                 key=lambda x: x[1], reverse=True)
    dp = np.zeros(n+1, dtype=np.int)

    for k, (i, a) in enumerate(arr, 1):
        ndp = dp.copy()
        
        add_left = np.abs(np.arange(1, k+1) - i) * a
        ndp[1:k+1] = np.maximum(ndp[1:k+1], dp[:k] + add_left)
        
        add_right = np.abs(np.arange(n-k+1, n+1) - i) * a
        ndp[:k] = np.maximum(ndp[:k], dp[:k] + add_right)

        dp = ndp

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

from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)

n, k = map(int, input().split())
MOD = 998244353


lr = []
for _ in range(k):
    l, r = map(int, input().split())
    lr += (list(range(l, r + 1)))

lr.sort(reverse=True)


@lru_cache(maxsize=None)
def rec(n):
    if n == 1:
        return 1
    else:
        ans = 0
        for k in lr:
            if n - k >= 1:
                ans += rec(n - k)
                ans %= MOD
    return ans


print(rec(n))

### FIXED CODE ###

def solve(l, r, i):
    if i - l < 1:
        return 0
    return dp[i - l] - dp[max(i - r - 1, 0)]


n, k = map(int, input().split())
MOD = 998244353
lr = [list(map(int, input().split())) for _ in range(k)]

dp = [0] * (n + 1)
dp[1] = 1

for i in range(2, n + 1):
    tmp = 0
    for l, r in lr:
        tmp += solve(l, r, i)
    tmp = tmp % MOD
    dp[i] = (dp[i - 1] + tmp) % MOD

print(tmp)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = tuple(map(int, input().split(' ')))
MOD = 10 ** 9 + 7


def format2binary(n):
    return list(reversed(format(n, '060b')))


binaries = np.array(list(map(format2binary, A)))

zeros = np.sum((binaries == '0'), axis=0)
ones = np.sum((binaries == '1'), axis=0)

base = 1
ans = 0

for i in range(len(zeros)):
    ans += zeros[i] * ones[i] * base
    ans %= MOD
    base *= 2
    base %= MOD

print(ans)


### FIXED CODE ###

N = int(input())
A = tuple(map(int, input().split(' ')))
MOD = 10 ** 9 + 7

zeros = [0] * 60
ones = [0] * 60

for a in A:
    for i, bit in enumerate(reversed(format(a, '060b'))):
        if bit == '0':
            zeros[i] += 1
        else:
            ones[i] += 1

base = 1
ans = 0

for i in range(len(zeros)):
    ans += zeros[i] * ones[i] * base
    ans %= MOD
    base *= 2
    base %= MOD

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

s = list(input())

digits = len(s)
s.reverse()
dp = [ [0] * 13 for i in range(digits)]
# dp[i][j] は i+1桁目までで13で割った余りがjのものを格納する

for i in range(digits):
    if s[i] == '?':
        for j in range(10):
            if i == 0:
                dp[i][j] += 1
            else:
                amari = ( j * 10 ** (i) ) % 13
                for k in range(13):
                    dp[i][(k+amari)%13] += dp[i-1][k]
    else:
        val = int(s[i])
        if i == 0:
            dp[i][val] += 1
        else:
            amari = ( val * 10 ** (i) ) % 13
            for k in range(13):
                dp[i][(k+amari)%13] += dp[i-1][k]
    
print(dp[digits-1][5]%(10**9 + 7))

### FIXED CODE ###

s = list(input())

digits = len(s)
s.reverse()
dp = [ [0] * 13 for i in range(digits)]
# dp[i][j] は i+1桁目までで13で割った余りがjのものを格納する
mod = 10 ** 9 + 7
power = 1

for i in range(digits):
    if s[i] == '?':
        for j in range(10):
            if i == 0:
                dp[i][j] += 1
            else:
                amari = (j * power) % 13
                for k in range(13):
                    dp[i][(k+amari)%13] = (dp[i][(k+amari)%13] + dp[i-1][k]) % mod
    else:
        val = int(s[i])
        if i == 0:
            dp[i][val] += 1
        else:
            amari = (val * power)% 13
            for k in range(13):
                dp[i][(k+amari)%13] = (dp[i][(k+amari)%13] + dp[i-1][k]) % mod
    power = (power * 10) % 13
print(dp[digits-1][5])
### BUGGY CODE ###

n = int(input())
P = list(map(int,input().split(" ")))
ans = 0
for i in range(n):
    tmp = min(P[:i+1])
    if tmp == P[i]:
        ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
tmp = 2**60
ans = 0
for i in input().split(" "):
  tmp = min(tmp,int(i))
  if int(i) == tmp:
    ans += 1
print(ans)
### BUGGY CODE ###

N,K=map(int,input().split())
dice = list(map(int, input().split()))#dic=[]


p=[0]*(N-K+1)
for j in range(N-K+1):
    su=sum(dice[j:j+K])
    p[j]=su
print((max(p)+K)/2)


### FIXED CODE ###

N,K=map(int,input().split())
dice = list(map(int, input().split()))
a=sum(dice[0:K])

l = [a]
for i in range(1,N-K+1):
    a = a - dice[i-1] + dice[K-1+i]
    l.append(a)
print((max(l)+K)/2)
### BUGGY CODE ###

if __name__ == "__main__":
    
    n = int(input())

    for o in range(1, n+1):
        s = 1
        if o > 6:
            s = -1 + int((o-2)**0.5)
        for x in range(s, 100):
            isFound = False
            for y in range(1, x+1):
                for z in range(1, y+1):
                    m = x**2+y**2+z**2+x*y+y*z+z*x
                    if m == o:
                        isFound = True
                        if x==y and y==z: print(1)
                        elif x==y or y==z or z==x: print(3)
                        else: print(6)
                        break
                    elif m > o:
                        break
                if isFound: break
            if isFound: break
        if not isFound: print(0)

### FIXED CODE ###

if __name__ == "__main__":
    
    n = int(input())

    """for o in range(1, n+1):
        s = 1
        if o > 6:
            s = -1 + int((o-2)**0.5)
        for x in range(s, 100):
            isFound = False
            for y in range(1, x+1):
                for z in range(1, y+1):
                    m = x**2+y**2+z**2+x*y+y*z+z*x
                    if m == o:
                        isFound = True
                        if x==y and y==z: print(1)
                        elif x==y or y==z or z==x: print(3)
                        else: print(6)
                        break
                    elif m > o:
                        break
                if isFound: break
            if isFound: break
        if not isFound: print(0)"""

    ans = [0 for _ in range(10001)]
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                m = x**2+y**2+z**2+x*y+y*z+z*x
                if m > 10000: break
                ans[m] += 1

    for i in range(n):
        print(ans[i+1])
### BUGGY CODE ###

n,k=map(int,input().split())
p=list(map(lambda x:int(x)-1,input().split()))
c=list(map(int,input().split()))
ans=-10**20
for i in range(n):
  x=[]
  for _ in range(k):
    i=p[i]
    x.append(c[i])
  anss=-10**20
  s=x[0]
  anss=max(anss,s)
  for i in x[1:]:
    s+=i
    anss=max(anss,s)
  ans=max(ans,anss)
print(ans)

### FIXED CODE ###

def solve(n,x,k):
  ans=-10**20
  s=0
  sx=sum(x)
  for i in range(n):
    if (i+1)>k:break
    s+=x[i]
    d=((k-i-1)//n)*sx
    ans=max(ans,s+d,s)
  return ans

n,k=map(int,input().split())
p=list(map(lambda x:int(x)-1,input().split()))
c=list(map(int,input().split()))
ans=-10**20
for i in range(n):
  x=[c[i]]
  j=p[i]
  while i!=j:
    x.append(c[j])
    j=p[j]
  x=x[1:]+[x[0]]
  ans=max(ans,solve(len(x),x,k))
print(ans)
### BUGGY CODE ###

import math

n=int(input())
x = list(map(int, input().split()))
ans=0
mod=10**9+7
v=math.factorial(n-1)

for i in range(1,n):
    ans+=(x[n-1]-x[i-1])*v//i
    ans%=mod

print(int(ans))

### FIXED CODE ###

import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
f = 1
for i in range(1,n):
  f *= i
  f %= mod

for i in range(n-1):
    ans+=(x[n-1]-x[i])*pow(i+1,mod-2,mod)

ans*=f
ans%=mod


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

s = input()
dp,dp2,mod = [0]*13,[0]*13,10**9+7
dp[0] = 1
for i in range(len(s)):
    if s[i]=="?":
        for k in range(10):
            for j in range(13): dp2[(j*10+k)%13]+=dp[j]
    else:
        for j in range(13): dp2[(j*10+int(s[i]))%13]+=dp[j]
    for j in range(13): dp2[j]%=mod
    dp,dp2 = dp2,[0]*13
print(dp[5])

### FIXED CODE ###

s = input()
ans,mod = [0]*13,10**9+7
if s[0]=="?": ans = [1]*10+[0]*3
else: ans[int(s[0])] = 1
for i in s[1:]:
    dp = [0]*13
    for j in range(13): dp[j*10%13] = ans[j]%mod
    dp+=dp
    if i=="?":
        for j in range(13): ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13): ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)
### BUGGY CODE ###

import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=list(set(st))
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    i=0
    while(i!=N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break
        i+=1


print(count)

### FIXED CODE ###

def main():
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  for i in range(10):
    for j in range(10):
      for k in range(10):
        flg = False
        flg2 = False
        for x in range(N):
          if flg2:
            break
          if not flg:
            if S[x] == i:
              flg = True
          else:
            if S[x] == j:
              flg2 = True
              if k in S[x+1:]:
                ans +=1
  print(ans)
main()
### BUGGY CODE ###

Q = int(input())

import heapq

INF = 10**18
L = []
R = []
heapq.heappush(L,INF)
heapq.heappush(R,INF)
L_size = 0
R_size = 0
sum_b = 0
sum_L = 0
sum_R = 0

def f1(a,b):
  global sum_b,L_size,R_size,sum_L,sum_R
  sum_b += b
  L_max = -heapq.heappop(L)
  R_min = heapq.heappop(R)
  sum_L -= L_max
  sum_R -= R_min
  X = sorted([L_max,a,R_min])
  if L_size == R_size:
    heapq.heappush(L,-X[0])
    heapq.heappush(L,-X[1])
    heapq.heappush(R,X[2])
    L_size += 1
    sum_L += X[0] + X[1]
    sum_R += X[2]
  else:
    heapq.heappush(L,-X[0])
    heapq.heappush(R,X[1])
    heapq.heappush(R,X[2])
    R_size += 1
    sum_L += X[0]
    sum_R += X[1] + X[2]
  return

def f2():
  min_value = sum_b
  min_x = -L[0]
  if L_size == R_size:
    min_value += sum_R - sum_L
  else:
    min_value += sum_R - sum_L + min_x
  print(min_x,min_value)

for _ in range(Q):
  row = [int(x) for x in input().split()]
  if row[0] == 1:
    f1(row[1],row[2])
  else:
    f2()


### FIXED CODE ###

Q = int(input())

import heapq
import sys
input = sys.stdin.readline

INF = 10**18
L = []
R = []
heapq.heappush(L,INF)
heapq.heappush(R,INF)
L_size = 0
R_size = 0
sum_b = 0
sum_L = 0
sum_R = 0

def f1(a,b):
  global sum_b,L_size,R_size,sum_L,sum_R
  sum_b += b
  L_max = -heapq.heappop(L)
  R_min = heapq.heappop(R)
  sum_L -= L_max
  sum_R -= R_min
  X = sorted([L_max,a,R_min])
  if L_size == R_size:
    heapq.heappush(L,-X[0])
    heapq.heappush(L,-X[1])
    heapq.heappush(R,X[2])
    L_size += 1
    sum_L += X[0] + X[1]
    sum_R += X[2]
  else:
    heapq.heappush(L,-X[0])
    heapq.heappush(R,X[1])
    heapq.heappush(R,X[2])
    R_size += 1
    sum_L += X[0]
    sum_R += X[1] + X[2]
  return

def f2():
  min_value = sum_b
  min_x = -L[0]
  if L_size == R_size:
    min_value += sum_R - sum_L
  else:
    min_value += sum_R - sum_L + min_x
  print(min_x,min_value)

QUERY = [[int(x) for x in input().split()] for _ in range(Q)]
for q in QUERY:
  if q[0]&1:
    f1(q[1],q[2])
  else:
    f2()
### BUGGY CODE ###

n, m = map(int, input().split())

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

uni = [set([i]) for i in range(n)]

start = (n * (n - 1)) // 2

blis = [start]
for a, b in ab[::-1]:
  ap = a
  bp = b
  while isinstance(uni[ap], int):
    ap = uni[ap]
  while isinstance(uni[bp], int):
    bp = uni[bp]
  _ap = uni[ap]
  _bp = uni[bp]
  if _ap.intersection(_bp) == set():
    start -= len(_ap) * len(_bp)
  if ap != bp:
    uni[ap] = uni[ap].union(uni[bp])
    uni[bp] = ap
  blis.append(start)
for p in blis[::-1][1:]:
  print(p)


### FIXED CODE ###

def comb(n):
    return n*(n+1)//2

class UnionFind:
  def __init__(self, N):
    self.parent = [i for i in range(N)]
    self.rank = [0] * N
    self.count = 0
    self.size = [1] * N
    self.connection = 0

  def root(self, a):
    if self.parent[a] == a:
      return a
    else:
      self.parent[a] = self.root(self.parent[a])
      return self.parent[a]

  def is_same(self, a, b):
    return self.root(a) == self.root(b)

  def unite(self, a, b):
    ra = self.root(a)
    rb = self.root(b)
    if ra == rb:
      return
    self.connection -= (comb(self.size[ra]) + comb(self.size[rb]))
    self.connection += comb(self.size[ra] + self.size[rb])
    if self.rank[ra] < self.rank[rb]:
      self.size[rb] += self.size[ra]
      self.parent[ra] = rb
    else:
      self.size[ra] += self.size[rb]
      self.parent[rb] = ra
      if self.rank[ra] == self.rank[rb]:
        self.rank[ra] += 1
    self.count += 1

n, m = map(int, input().split())
uni = UnionFind(n)
remain = [comb(n-1)]
abl = []
for _ in range(m):
  a, b = map(int, input().split())
  abl.append((a-1, b-1))
for a, b in abl[::-1]:
  uni.unite(a, b)
  remain.append(remain[0] - uni.connection)
for r in reversed(remain[:-1]):
  print(r)
### BUGGY CODE ###

a, b, m = map(int, input().split())
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = 10 ** 6
for i in range(a):
    for j in range(b):
        s = ref[i] + micro[j]
        if s < mini:
            mini = s

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print(min(mini, amount))


### FIXED CODE ###

a, b, m = map(int, input().split())
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = min(ref) + min(micro)

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print(min(mini, amount))
### BUGGY CODE ###

N = int(input())
S = str(input())
dp = [[0 for i in range(N+1)] for i in range(N+1)]

for i in reversed(range(N)):
    for j in reversed(range(N)):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if j > i:
            tmp = min(j-i,dp[i][j])
            ans = max(tmp,ans)
print(ans)

### FIXED CODE ###

N = int(input())
S = str(input())
dp = [[0 for i in range(N+1)] for i in range(N+1)]

for i in reversed(range(N)):
    for j in reversed(range(N)):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if j > i:
            tmp = min(j-i,dp[i][j])
            ans = max(tmp,ans)
print(ans)
### BUGGY CODE ###

n=int(input())

candidates={}
for i in range(n):
    candidate=input()
    if candidate in candidates:
        candidates[candidate]+=1
    else:
        candidates[candidate]=1
max_k_list = [kv[0] for kv in candidates.items() if kv[1] == max(candidates.values())]
max_k_list.sort()
for i in max_k_list:
    print(i)


### FIXED CODE ###

n=int(input())

candidates={}
for i in range(n):
    candidate=input()
    if candidate in candidates:
        candidates[candidate]+=1
    else:
        candidates[candidate]=1

max_k_list = []
maxvalue=max(candidates.values())
for candidate in candidates:
    if candidates[candidate]==maxvalue:
        max_k_list.append(candidate)


max_k_list.sort()
for i in max_k_list:
    print(i)
### BUGGY CODE ###

s = input()
K = int(input())

substr_set = set()

for i in range(0, len(s)):
    for slen in range(0, len(s) - i):
        substring = s[i:i + slen + 1]
        substr_set.add(substring)

print(sorted(substr_set)[K - 1])


### FIXED CODE ###

s = input()
K = int(input())

substr_set = set()

for i in range(0, len(s)):
    for slen in range(0, K):
        substring = s[i:i + slen + 1]
        substr_set.add(substring)

print(sorted(substr_set)[K - 1])
### BUGGY CODE ###

N=int(input())
index=[]
count=[]
for i in range(N):
    inp=input()
    if inp in index:
        count[index.index(inp)]+=1
    else:
        index.append(inp)
        count.append(1)

rank=max(set(count))
o=[]
while rank in count:
    o.append(index.pop(count.index(rank)))
    del count[count.index(rank)]
o.sort()
for i in o:
    print(i)

### FIXED CODE ###

N=int(input())
data={}
for i in range(N):
    name=input()
    if data.get(name) == None:
        data[name]=0
    data[name] += 1
data = sorted(data.items(),key=lambda x:x[1])
if len(data) == 1:
    print(data[-1][0])
else:
    mx=data[-1][1]
    l=[]
    for i in range(N):
        if data[len(data)-i-1][1] == mx:
            l.append(data[len(data)-i-1][0])
        else:
            break
    l.sort()
    for i in l: print(i)
### BUGGY CODE ###

def odd(S):
    return S[::-1]

def even(S,F,C,c):
    if F==1 and c%2==0 or F==2 and c%2==1:
        C+=S
        return C
    else:
        S+=C
        return S

S=input()
Q=int(input())
c=0
for i in range(Q):
    T=list(map(str,input().split()))
    if len(T)==1:
        c+=1
    else:
        S=even(S,int(T[1]),T[2],c)
        
if c%2==1:
    S=odd(S)

print(S)

### FIXED CODE ###

S=input()
Q=int(input())
c=0
left=""
right=""
for i in range(Q):
    T=list(map(str,input().split()))
    if len(T)==1:
        c+=1
    else:
        if (T[1]=="1" and c%2==0) or (T[1]=="2" and c%2==1):
            left+=T[2]
        else:
            right+=T[2]

if c%2==0:
    ans=left[::-1]+S+right
else:
    ans=right[::-1]+S[::-1]+left
print(ans)
### BUGGY CODE ###

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

H,W=list(map(int,input().split()))
s = []
dot_cnt = 0
for _ in range(H):
    a = input().rstrip()
    dot_cnt += a.count('.')
    s.append(list(a))

numOpe = 0
while dot_cnt:
    numOpe += 1
    tmp = copy.deepcopy(s)
    for ih in range(H):
        for iw in range(W):
            if s[ih][iw]=='#':
                if (ih+1 != H) and (s[ih+1][iw]!='#')and(tmp[ih+1][iw]!='#'):
                    tmp[ih+1][iw]='#'
                    dot_cnt -=1
                if(ih-1 != -1) and (s[ih-1][iw]!='#')and(tmp[ih-1][iw]!='#'):
                    tmp[ih-1][iw]='#'
                    dot_cnt -=1
                if(iw+1 != W) and (s[ih][iw+1]!='#')and( tmp[ih][iw+1]!='#'):
                    tmp[ih][iw+1]='#'
                    dot_cnt -=1
                if(iw-1 != -1) and (s[ih][iw-1]!='#')and(tmp[ih][iw-1]!='#'):
                    tmp[ih][iw-1]='#'
                    dot_cnt -=1        

    s = copy.deepcopy(tmp)
print(numOpe)


### FIXED CODE ###

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

H,W=list(map(int,input().split()))
s = []
dot_cnt = 0
for _ in range(H):
    a = input().rstrip()
    dot_cnt += a.count('.')
    s.append(list(a))

num_lis = [[float('inf')]*W for _ in range(H)]

#--#
for ih in range(H):
    for iw in range(W):
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if iw-1>=0:
                num_lis[ih][iw] = min(num_lis[ih][iw-1]+1,num_lis[ih][iw])
                
    for iw in range(W-1,-1,-1):
        
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if iw+1<=W-1:
                num_lis[ih][iw] = min(num_lis[ih][iw+1]+1,num_lis[ih][iw])

#--#
for iw in range(W):
    for ih in range(H):
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if ih-1>=0:
                num_lis[ih][iw] = min(num_lis[ih-1][iw]+1,num_lis[ih][iw])
                
    for ih in range(H-1,-1,-1):
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if ih+1<=H-1:
                num_lis[ih][iw] = min(num_lis[ih+1][iw]+1,num_lis[ih][iw])

maxOpe = 0
for iw in range(W):
    for ih in range(H):
        maxOpe = max(maxOpe,num_lis[ih][iw])
print(maxOpe)
### BUGGY CODE ###

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

### FIXED CODE ###

n=int(input())
a=input().split()
ans=1

if a.count("0"):
 print(0)
 exit()
 
for i in range(n):
 ans=ans*int(a[i])
 if ans>(10**18):
  print(-1)
  exit()
 
print(ans)
### BUGGY CODE ###

N,K = map(int,input().split())
x = list(map(int,input().split()))
cand = []
for i in range(N-K+1):
  cand.append(x[i:i+K])

ans = float('inf')
for i in range(len(cand)):
  l = cand[i][0]
  r = cand[i][-1]
  temp = min(abs(l)+abs(r-l),abs(r)+abs(l-r))
  ans = min(temp,ans)

print(ans)

### FIXED CODE ###

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

ans = float('inf')
for i in range(N-K+1):
  l = x[i]
  r = x[i+K-1]
  temp = min(abs(l)+abs(r-l),abs(r)+abs(l-r))
  ans = min(temp,ans)

print(ans)