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

import sys
input=sys.stdin.readline
D=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(D):
    sub=list(map(int,input().split()))
    s.append(sub)

last=[-1]*26

t=[]

for i in range(D):
    m=-10**9
    change=-1
    for j in range(26):
        temp=0
        temp+=s[i][j]
        for k in range(26):
            if k!=j:
                temp-=c[k]*(i-last[k])
        if temp>m:
            m=temp
            change=j
    t.append(change+1)

m=3000000
import random
for _ in range(m):
    h=0
    d=random.randint(1,D)
    q=random.randint(1,26)
    h+=s[d-1][q-1]-s[d-1][t[d-1]-1]
    o=t[d-1]

    pre=1
    for i in range(d-2,-1,-1):
        if t[i]==o:
            break
        pre+=1
    post=1
    for j in range(d,D):
        if t[j]==o:
            break
        post+=1
    h-=c[o-1]*pre*post

    pre = 1
    for i in range(d - 2, -1, -1):
        if t[i] == q:
            break
        pre += 1
    post = 1
    for j in range(d, D):
        if t[j] == q:
            break
        post += 1
    h += c[q - 1] * pre * post

    if h>0:
        t[d-1]=q

for i in t:
    print(i)

### FIXED CODE ###

import sys
input=sys.stdin.readline
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    sub=list(map(int,input().split()))
    s.append(sub)

last=[-1]*26

for i in range(d):
    m=-10**9
    change=-1
    for j in range(26):
        temp=0
        temp+=s[i][j]
        for k in range(26):
            if k!=j:
                temp-=c[k]+(i-last[k])
        if temp>m:
            m=temp
            change=j
    print(change+1)
### BUGGY CODE ###

n = int(input())
s = str(input())

s_r = s.count("R")
s_g = s.count("G")
s_b = s.count("B")

s = s.replace("R", "0")
s = s.replace("G", "1")
s = s.replace("B", "2")

def conditions(a, b):
  c = [-1, -1, -1]
  if (a+b) % 2 == 0:
    c[0] = (a+b) / 2
    c[1] = 2*b - a
    c[2] = 2*a - b
  else:
    c[1] = 2*b - a
    c[2] = 2*a - b
  list = []
  for i in range(3):
    if c[i] >= 0 and c[i] <= n-1:
      list.append(c[i])
  return list

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

count = 0
for i in range(n):
  for j in range(i+1, n):
    if 2*j - i <= n-1:
      a = int(s[i])
      b = int(s[j])
      c = int(s[2*j-i])
      if noteq(a, b, c):
        count += 1
    
ans = s_r * s_g * s_b - count
print(ans)

### FIXED CODE ###

import collections

n = int(input())
s = str(input())

aaa = collections.Counter(s)
s_r = aaa["R"]
s_g = aaa["G"]
s_b = aaa["B"]

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

ans = s_r * s_g * s_b

for i in range(n):
  for d in range(n):
    j = i + d
    k = j + d
    if k >= n:
      break;
    else:
      a = s[i]
      b = s[j]
      c = s[k]
      if noteq(a, b, c):
        ans -= 1
    
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

for idx,i in enumerate(a):
    b = a[:]
    del b[idx]
    print(max(b))

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

b = sorted(a)
m = b[-1]
m1 = b[-2]

for i in a:
    if m != i:
        print(m)
    else:
        print(m1)
### BUGGY CODE ###

#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

from math import gcd
import math
pairwise = True
setwise = True
acc = a[0]
for i in range(N):
    acc = math.gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

LIMIT=10**6
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
count = 0
for i in range(2,LIMIT):
    if minPrime[i] == 0:
        count += 1
        j = i
        while j <= LIMIT:
            if minPrime[j] == 0:
                minPrime[j] = i
            j += i

def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(N)
        N = N//minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

# facts = [set(factrial(e)) for e in a]
s = set()
for e in a:
    f = set(factrial(e))
    if f & s:
        print("setwise coprime")
        exit()
    s = s | f
print("pairwise coprime")
# for i in range(N):
#     for j in range(i+1,N):
#         b = gcd(a[i],a[j])
#         if b != 1:
#             print("setwise coprime")
#             exit()
# if pairwise == True:
#     print("pairwise coprime")
# else:
#     print("not coprime")


### FIXED CODE ###

import math
from collections import defaultdict
pc = True
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)
class Sieve_of_Eratosthenes:
    def __init__(self, N):
        self.sieve = [-1] * (N+1)
 
        for i in range(2,N+1):
            if self.sieve[i] == -1:
                for j in range(1,1+N//i):
                    self.sieve[i*j] = i
 
    def isprime(self, num):
        if num <= 1:
            return False
        else:
            return self.sieve[num] == num
 
    def factorization(self, num):
        ret = set([])
        while num != 1:
            div = self.sieve[num]
            ret.add(div)
            num //= div
        return ret
 
sofe = Sieve_of_Eratosthenes(M)
ddic = defaultdict()
judge = set([])
 
for i in a:
    if not pc:
        break
    asf = sofe.factorization(i)
    
    if judge & asf != set():
        pc = False
    judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")
### BUGGY CODE ###

k = int(input())
s = input()

n = len(s)
mod = 10**9+7


def framod(n, mod, a=1):
    for i in range(1, n+1):
        a = a * i % mod
    return a


def power(n, r, mod):
    if r == 0:
        return 1
    if r % 2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r % 2 == 1:
        return n * power(n, r-1, mod) % mod


def comb(n, k, mod):
    a = framod(n, mod)
    b = framod(k, mod)
    c = framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


num = 0
for i in range(0, k+1):
    num = num+comb(i+n-1, n-1, mod)*pow(25, i,
                                        mod) * pow(26, k-i, mod) % mod
print(num)


### FIXED CODE ###

k = int(input())
s = input()

n = len(s)
mod = 10**9+7


def framod(n, mod, a=1):
    for i in range(1, n+1):
        a = a * i % mod
    return a


def power(n, r, mod):
    if r == 0:
        return 1
    if r % 2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r % 2 == 1:
        return n * power(n, r-1, mod) % mod


def comb(n, k, mod):
    a = framod(n, mod)
    b = framod(k, mod)
    c = framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


com = [1]*(k+1)
for i in range(k):
    com[i+1] = com[i]*(n+i)*pow(i+1, mod-2, mod) % mod

a25 = [1]*(k+1)
for i in range(k):
    a25[i+1] = a25[i]*25 % mod
a26 = [1]*(k+1)
for i in range(k):
    a26[i+1] = a26[i]*26 % mod
num = 0
for i in range(0, k+1):
    num = (num+com[i]*a25[i] % mod * a26[k-i]) % mod
print(num)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = []
    G = []
    B = []
    R_a = R.append
    G_a = G.append
    B_a = B.append

    for i in range(n):
        if s[i] == "R":
            R_a(i + 1)
        elif s[i] == "G":
            G_a(i + 1)
        else:
            B_a(i + 1)

    def chk(R,G,B):
        res = 0
        for r in R:
            for g in G:
                for b in B:
                    if r + g != b * 2 and g + b != r * 2 and b + r != g * 2:
                        res += 1
        return res
    if len(R) > len(G):
        print(chk(G, B, R))
    elif len(G) > len(B):
            print(chk(B, R, G))
    elif len(B) > len(R):
        print(chk(R, G, B))
    else:
        print(chk(R, G, B))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    R = 0
    G = 0
    B = 0

    for i in range(n):
        if s[i] == "R":
            R += 1
        elif s[i] == "G":
            G += 1
        else:
            B += 1
            
    res = R*G*B
    for i in range(n - 2):
        for j in range(i + 1, i + 1 + (n - 1 - i) // 2):
            k = j + (j - i)
            if s[i] != s[j] != s[k] != s[i]:
                res -= 1
    print(res)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

# Handstand 2
# c_ij = {1<=k<=N : 先頭の桁がiで、末尾の桁の数がjであるもの}

N = int(input())
count = 0

# 先頭の桁をi, 末尾の桁をjとする数の数を求める
c_memo = {}
def c(i, j):
    count_num = 0
    key = str(i) + '_' + str(j)
    if key in c_memo:
        return c_memo[key]
    for a in range(1,N+1):
        a_str = str(a)
        a_i, a_j = int(a_str[0]), int(a_str[-1]) # 各数の先頭桁を求める
        if i==a_i and j==a_j:
            count_num = count_num + 1
    c_memo[key] = count_num
    return count_num


for i in range(10):
    for j in range(10):
        count += c(i,j)*c(j,i)

print(count)


### FIXED CODE ###

# Handstand 2

N = int(input())
count = 0

count_list = [[0]*10 for i in range(10)]

# 1~Nまでの先頭iと末尾jの頻度を全て算出する
for a in range(1,N+1):
    a_str = str(a)
    a_i, a_j = int(a_str[0]), int(a_str[-1]) # 各数の先頭桁を求める
    count_list[a_i][a_j] = count_list[a_i][a_j] + 1

# count_listから全ての組み合わせ数を計算
for i in range(1,10):
    for j in range(1,10):
        count = count + count_list[i][j]*count_list[j][i]

print(count)
### BUGGY CODE ###

H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])

MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX

DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)

print(min(DP[H:]))

### FIXED CODE ###

H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))
### BUGGY CODE ###

n, m = map(int, input().split())
sum = 0
money = 0
A = list()
B = list()
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
for i in range(n):
    index = A.index(min(A))
    if(B[index] >= m - sum):
        money += A[index] * (m - sum)
        sum = m
    else:
        sum += B[index]
        money += A[index]*B[index]
    if(sum == m):
        print(money)
        break
    del A[index]
    del B[index]


### FIXED CODE ###

n, m = map(int, input().split())
sum = 0
money = 0
list_ab = list()
for i in range(n):
    list_ab.append(list(map(int, input().split())))
list_ab = sorted(list_ab)
for i in range(n):
    if(list_ab[i][1] >= m - sum):
        money += list_ab[i][0] * (m - sum)
        break
    else:
        sum += list_ab[i][1]
        money += list_ab[i][0]*list_ab[i][1]
print(money)
### BUGGY CODE ###

r,g,b,n = map(int,input().split())

result = 0

max_r = n // r

for i in range(max_r + 1):
    max_g = (n - i * r) // g + 1
    for j in range(max_g):
        if i * r + j * g > n:
                continue
        if (n - i * r - j * g ) % b == 0:
            result += 1
print(result)

### FIXED CODE ###

r,g,b,n = map(int,input().split())

result = 0
max_r = n // r

for i in range(max_r + 1):
    max_g = (n - i * r) // g
    for j in range(max_g + 1):
        if (n - i * r - j * g ) % b == 0:
            result += 1
print(result)
### BUGGY CODE ###

import numpy as np


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    pow_2_k = 1
    ans = 0
    for k in range(30):
        MA = A % (2 * pow_2_k)
        MB = np.sort(B % (2 * pow_2_k))
        # [2**k, 2 * (2**k)) か [3 * (2**k), 4 * (2**k)) の中に入るとk-bit目が1。
        # この a + b の数をカウントする。
        # → [2**k - a, 2 * (2**k) - a) か [3 * (2**k) - a, 4 * (2**k) - a) の中に入る b の数をカウント。
        cnt = 0
        for a in MA:
            index_1 = np.searchsorted(MB, pow_2_k - a, side='left')
            index_2 = np.searchsorted(MB, 2 * pow_2_k - a, side='left')
            index_3 = np.searchsorted(MB, 3 * pow_2_k - a, side='left')
            cnt += (N - index_1) - (N - index_2) + (N - index_3)
        if cnt % 2 == 1:
            ans += pow_2_k
        pow_2_k *= 2
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    pow_2_k = 1
    ans = 0
    for k in range(30):
        MA = A % (2 * pow_2_k)
        MB = B % (2 * pow_2_k)
        MB.sort()
        # [2**k, 2 * (2**k)) か [3 * (2**k), 4 * (2**k)) の中に入るとk-bit目が1。
        # この a + b の数をカウントする。
        # → [2**k - a, 2 * (2**k) - a) か [3 * (2**k) - a, 4 * (2**k) - a) の中に入る b の数をカウント。
        cnt = 0
        indices_1 = np.searchsorted(MB, pow_2_k - MA, side='left')
        indices_2 = np.searchsorted(MB, 2 * pow_2_k - MA, side='left')
        indices_3 = np.searchsorted(MB, 3 * pow_2_k - MA, side='left')
        cnt += ((N - indices_1) - (N - indices_2) + (N - indices_3)).sum()
        if cnt % 2 == 1:
            ans += pow_2_k
        pow_2_k *= 2
    print(ans)


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

#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, K: int, Q: int, A: "List[int]"):
    p = [K] * N
    for i in range(Q):
        q = A[i]
        p = list(map(lambda x: x -1, p))
        p[q-1] += 1

    for i in range(N):
        if p[i] > 0:
            print(YES)
        else:
            print(NO)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(N, K, Q, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, K: int, Q: int, A: "List[int]"):
    p = [Q] * N
    for i in range(Q):
        p[A[i]-1] -= 1

    for i in range(N):
        if K - p[i]  > 0:
            print(YES)
        else:
            print(NO)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(N, K, Q, A)

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

n=int(input())
a=list(map(int,input().split()))
num1,num2,num3=0,0,0
for i in range(n):
    if a[i]==1:
        num1+=1
    elif a[i]==2:
        num2+=1
    else:
        num3+=1
dp=[[[-1.0 for k in range(n+1)] for i in range(n+1)] for j in range(n+1)]
def f(n1,n2,n3):
    if dp[n1][n2][n3]>=0.0:
        return dp[n1][n2][n3]
    if n1==n2==n3==0:
        return 0.0
    ret=n
    if n1>0:
        ret+=f(n1-1,n2,n3)*n1
    if n2>0:
        ret+=f(n1+1,n2-1,n3)*n2
    if n3>0:
        ret+=f(n1,n2+1,n3-1)*n3
    ret*=1.0/(n1+n2+n3)
    dp[n1][n2][n3]=ret
    return dp[n1][n2][n3]
print(f(num1,num2,num3))


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
num1,num2,num3=0,0,0
for i in range(n):
    if a[i]==1:
        num1+=1
    elif a[i]==2:
        num2+=1
    else:
        num3+=1
dp=[[[-1.0 for k in range(n+1)] for i in range(n+1)] for j in range(n+1)]
def f(n1,n2,n3):
    if dp[n1][n2][n3]>=0.0:
        return dp[n1][n2][n3]
    if n1==n2==n3==0:
        return 0.0
    ret=n
    if n1>0:
        ret+=f(n1-1,n2,n3)*n1
    if n2>0:
        ret+=f(n1+1,n2-1,n3)*n2
    if n3>0:
        ret+=f(n1,n2+1,n3-1)*n3
    ret*=1.0/(n1+n2+n3)
    dp[n1][n2][n3]=ret
    return dp[n1][n2][n3]
print(f(num1,num2,num3))
### BUGGY CODE ###

def solve():
    #start here
    n, W = map(int,input().split())
    l = []
    dp = [[0 for i in range(W+1)] for j in range(n)]
    for i in range(n):
        w, v = map(int,input().split())
        for j in range(1, W+1):
            if(w>j):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], v+dp[i-1][j-w])
    print(dp[n-1][W])
solve()

### FIXED CODE ###

n, W = map(int,input().split())
dp = [[float('inf') for i in range(10**5+1)] for j in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
ans = 0
for i in range(1, n+1):
    w, v = map(int,input().split())
    for j in range(1, 10**5+1):
        if v>j:
            dp[i][j] = dp[i-1][j]
            continue
        dp[i][j] = min(dp[i-1][j], w+dp[i-1][j-v])
        if dp[i][j] <= W:
            ans = max(ans, j)
print(ans)
### BUGGY CODE ###

import math
from functools import reduce

K = int(input())

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

ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(i,j,k)

print(ans)

### FIXED CODE ###

import math
from functools import reduce

K = int(input())

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

ans = 0

for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j and j ==k:
                ans += i
            elif i==j or j==k or i==k:
                ans += gcd(i,j,k)*3
            else:
                ans += gcd(i,j,k)*6

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

i = int(input())
S = [input() for _ in range(i)]
d = {}
max = 0
for s in list(set(S)):
  if S.count(s) >= max:
    max = S.count(s) 
    d[s] = S.count(s)
keys = sorted([k for k, v in d.items() if v == max])
for key in keys:
  print(key)

### FIXED CODE ###

import collections
i = int(input())
S = collections.Counter([input() for _ in range(i)])
max_v = max(S.values())
[print(s) for s in sorted([s for s in S if S[s] == max_v])]
### BUGGY CODE ###

n = input()
a = input().split()

for i in range( int(n) ):
    print( a.count(str(i+1)) )

### FIXED CODE ###

n = input()
a = input().split()
out = [0] * int(n)

#for i in range( int(n) ):
#    print( a.count(str(i+1)) )

for a_i in a:
    a_i = int(a_i)
    out[a_i-1] += 1

for out_i in out:
    print( out_i )
### BUGGY CODE ###

N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(150001 ) :
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        index = bisect_left(train[i],now)
        now = train[i][index]
        now += take_time[i]
    print(now)



### FIXED CODE ###

N = int(input())
train = [[] for _ in range(N)]
L = []
for cnt in range(N - 1):
    l = list(map(int,input().split()))
    L.append(l)

from math import ceil

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        k = max(0,ceil((now - L[i][1]) / L[i][2]))
        now = L[i][1] + L[i][2] * k
        now += L[i][0]
    print(now)
### BUGGY CODE ###

import itertools

N, X, Y = map(int, input().split())

result = []

for i in range(1, N+1):
    for j in range(1, N+1):
        result.append(min(abs(j-i), abs(X-i) + 1 + abs(j-Y), abs(Y-i)+1+abs(j-X)))

for i in range(1, N):
    print(result.count(i)//2)


### FIXED CODE ###

import itertools

N, X, Y = map(int, input().split())

# dp = [[float('inf')] * (N+1) for _ in range(N+1)]
# # dp[Y][X] = 1
# dp[X][Y] = 1

# for i in range(1,N+1):
#     for j in range(i,N+1):
#         if i == j:
#             dp[i][j] = 0
#         elif i == X and j == Y:
#             dp[X][Y] = 1
#         elif i <= X:
#             dp[i][j] = min(dp[i][j-1] + 1, dp[i][X] + abs(Y - j) + 1)
#         else:
#             dp[i][j] = min(dp[i][j-1]+ 1, abs(i - X)+ abs(Y - j) + 1 )

# dp = list(itertools.chain.from_iterable(dp))
# for i in range(1,N):
#     print(dp.count(i))

result = [0] * N

for i in range(1, N):
    for j in range(i+1, N+1):
        dist = min(abs(j-i), abs(X-i) + 1 + abs(j-Y), abs(Y-i)+1+abs(j-X))
        result[dist] += 1

for i in range(1, N):
    print(result[i])
### BUGGY CODE ###

# ANSHUL GAUTAM
# IIIT-D

'''

'''

def solve(grid):
	H,W = len(grid),len(grid[0])
	q = []
	dist = [0]*H
	for i in range(H):
		dist[i] = []
	for i in range(H):
		for j in range(W):
			if(grid[i][j] == '#'):
				q.append([i,j])
				grid[i][j] = 0
	maxx = 0
	for i,j in q:
		for r,c in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
			if(0 <= r < H and 0 <= c < W and grid[r][c] == '.'):
				grid[r][c] = grid[i][j] + 1
				maxx = max(maxx,grid[r][c])
				q.append([r,c])
	return maxx

H,W = map(int, input().split())
grid = []
for h in range(H):
	s = list(input())
	grid.append(s)
ans = solve(grid)
print(ans)



### FIXED CODE ###

# ANSHUL GAUTAM
# IIIT-D

'''

'''

def solve(grid):
	H,W = len(grid),len(grid[0])
	q = []
	dist = [0]*H
	for i in range(H):
		dist[i] = []
	for i in range(H):
		for j in range(W):
			if(grid[i][j] == '#'):
				q.append([i,j])
				grid[i][j] = 0
	maxx = 0
	while(q):
		qq = []
		for i,j in q:
			for r,c in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
				if(0 <= r < H and 0 <= c < W and grid[r][c] == '.'):
					grid[r][c] = grid[i][j] + 1
					maxx = max(maxx,grid[r][c])
					qq.append([r,c])
		q = qq
	return maxx

H,W = map(int, raw_input().split())
grid = []
for h in range(H):
	s = list(raw_input())
	grid.append(s)
ans = solve(grid)
print(ans)