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

# 解説放送の解法

class BIT:
    '''https://tjkendev.github.io/procon-library/python/range_query/bit.html'''
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def query(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)
      
N,Q=map(int,input().split())
*C,=map(int,input().split())

# 重複度を数える。
res=[]
tmp_dict={}
for i in range(N):
  if tmp_dict.get(C[i]) != None:
    #(クエリの種類、l, r）
    res.append((-1,tmp_dict[C[i]],i))
    del tmp_dict[C[i]]
  tmp_dict[C[i]] = i
  
# クエリと合わせてソート。
X = []
for i in range(Q):
  l,r = map(int,input().split())
  # (元のクエリの順番、l, r)
  X.append((i,l-1,r-1))

X.extend(res) 
X = sorted(X,key=lambda x:(x[1],-x[0]))

# 平面走査
bit = BIT(N)
ans=[]
for idx,l,r in reversed(X):
  if idx == -1:
    bit.add(r,1)
  else:
    ans.append((idx,r-l+1-bit.query(l-1,r)))

# 元の順番にソートし直して出力
print(*list(zip(*sorted(ans)))[1])

### FIXED CODE ###

from time import time
start = time()

# 解説放送の解法

class BIT:
    '''https://tjkendev.github.io/procon-library/python/range_query/bit.html'''
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def query(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)
      
def main():
  N,Q=map(int,input().split())
  *C,=map(int,input().split())
  q = [tuple(map(int,input().split())) for _ in range(Q)]

  # 重複度を数える。
  res=[]
  tmp_dict={}
  for i in range(N):
    if tmp_dict.get(C[i]) != None:
      #(クエリの種類、l, r）
      res.append((tmp_dict[C[i]]<<40) | (Q<<20) | i)
      del tmp_dict[C[i]]
    tmp_dict[C[i]] = i

  # クエリと合わせてソート。
  X = []
  for i in range(Q):
    l,r = q[i]
    # (元のクエリの順番、l, r)
    X.append(((l-1)<<40) | (i<<20) | r-1)
    
  X.extend(res) 
  X = sorted(X)

  # 平面走査
  bit = BIT(N)
  ans=[0]*Q
  mask = (1<<20) - 1
  for l in reversed(X):
    r = l & mask
    l >>= 20
    idx = l & mask
    l >>= 20
    if idx == Q:
      bit.add(r,1)
    else:
      ans[idx] = r-l+1-bit.query(l-1,r)
      
  print(*ans)
  
if __name__=="__main__":
  main()
### BUGGY CODE ###

import math
from functools import reduce
K = int(input())
s = []
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(K):
    for j in range(K):
        for k in range(K):
            s.append(gcd(i+1,j+1,k+1))
print(sum(s))


### FIXED CODE ###

import math
from functools import reduce
K = int(input())
s = []
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(K):
    for j in range(K):
        for k in range(K):
            s.append(gcd(i+1,j+1,k+1))
print(sum(s))
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def solve(pre, s):
    if len(s) == 1:
        if pre != s:
            return 1
        return None
    for i in range(1, len(s)):
        head = s[:i]
        if pre == head:
            continue
        r = solve(head, s[i:])
        if r is not None:
            return r + 1
    if pre != s:
        return 1


def main():
    s = input()
    # N = int(input())
    print(solve("", s))
    # N, A, B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def f(n):
    if n == 0:
        return 0, False
    a = n // 3
    b = n % 3
    if b == 0:
        return a * 2, 0
    if b == 1:
        return a * 2 + 1, 1

    return a * 2 + 1, 2


def solve(s):
    last = s[0]
    c = 1
    res = 0
    last_flag = False
    for cc in s[1:]:
        if last == cc:
            c += 1
            continue

        k, k_flag = f(c)
        if k_flag == 0:
            res += k
        elif k_flag == 1:
            res += k
            last_flag = False
        else:
            if last_flag:
                res += k + 1
                last_flag = False
            else:
                res += k
                last_flag = True
        c = 1
        last = cc
    k, k_flag = f(c)
    if k_flag == 0:
        res += k
    elif k_flag == 1:
        res += k
    else:
        if last_flag:
            res += k + 1
        else:
            res += k
    return res


def main():
    s = input()
    # N = int(input())
    print(solve(s))
    # N, A, B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]


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

import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline
N = int(input()) #社員数
joushi_no_bangou = [0] #上司の社員番号
ans = []
joushi_no_bangou += map(int,input().split())

#==--------------

for i in range(N):
    print(joushi_no_bangou.count(i+1))

### FIXED CODE ###

N = int(input())
As = list(map(int, input().split()))
ct = [0] * N
     
for a in As: #ここがキモ．リスト「As」にはそれぞれの上司が入っていて，その中からaを取り出すので，a=上司になっている．これにより，ctの上司を正確に呼び出すことができる．
    ct[a-1] += 1
     
for c in ct:
    print(c)

#別解
#print(*c,sep='\n')
### BUGGY CODE ###

def counting(k, v, square):
    square += 1
    for _ in range(square):
        for r in range(k, k + square):
            if r > len(matrix) - 1:
                return False
            for c in range(v, v + square):
                if c > len(matrix[k]) - 1:
                    return False
                if matrix[r][c] == '1':
                    return False
        return True


line = input().split(' ')

answer = [[0 for _ in range(int(line[1]))] for _ in range(int(line[0]))]
matrix = []
maximum = 0

for _ in range(int(line[0])):
    row = input().split(' ')
    matrix.append(row)

    for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                for m in range(min(int(line[0]), int(line[1]))):
                    res = counting(i, j, maximum)
                    # print(res)
                    if res:
                        maximum += 1
                    else:
                        break

print(maximum * maximum)

### FIXED CODE ###

def solve2():
    r, c = map(int, input().split(' '))

    ans_matrix = [[0 for _ in range(c + 1)] for _ in range(r + 1)]
    input_matrix = []

    for _ in range(r):
        input_matrix.append(list(map(int, input().split(' '))))

    largest_square = 0

    for i in range(len(input_matrix)):
        for j in range(len(input_matrix[i])):
            new_i, new_j = i + 1, j + 1
            if input_matrix[i][j] == 0:
                ans_matrix[new_i][new_j] = min(ans_matrix[new_i - 1][new_j], ans_matrix[new_i][new_j - 1], ans_matrix[new_i - 1][new_j - 1]) + 1
                largest_square = ans_matrix[new_i][new_j] if ans_matrix[new_i][new_j] > largest_square else largest_square
            else:
                ans_matrix[new_i][new_j] = 0

    print(largest_square ** 2)


def main():
    solve2()


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

n,m,p=map(int,input().split())
E=[list(map(int,input().split())) for i in range(m)]
INF=float("inf")
dist=[INF]*n
dist[0]=0
for i in range(n):
  for fr,to,cost in E:
    fr,to=fr-1,to-1
    cost*=-1
    cost+=p
    if dist[fr]!=INF and dist[to]>dist[fr]+cost:
      dist[to]=dist[fr]+cost
      if i==n-1 and to==n-1:
        print(-1)
        exit(0)
print(0) if -dist[n-1]<0 else print(-dist[n-1])

### FIXED CODE ###

n,m,p=map(int,input().split())
E=[list(map(int,input().split())) for i in range(m)]
INF=float("inf")
dist=[INF]*n
dist[0]=0
prev=0
# 閉路の長さの最大はnなので2*n回ループさせれば閉路検出ができる
for i in range(2*n):
  for fr,to,cost in E:
    fr,to=fr-1,to-1
    cost*=-1
    cost+=p
    if dist[fr]!=INF and dist[to]>dist[fr]+cost:
      dist[to]=dist[fr]+cost
      if i>=n:
        dist[to]=-float("inf")
    if i==n-1:
      prev=dist[n-1]
if prev==dist[n-1]:
  print(max(-dist[n-1],0))
else:
  print(-1)
### BUGGY CODE ###

n,*a=map(int,open(0).read().split())
c=0
for s in range(1,n+1): #長さ
    for t in range(n-s+1):
        if sum(a[t:t+s])==0:
            c+=1
print(c)

### FIXED CODE ###

from itertools import*
from collections import*
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n,*a=map(int,open(0).read().split())
print(sum(cmb(v,2)for k,v in Counter(accumulate(a)).items() if v>1)+list(accumulate(a)).count(0))
### BUGGY CODE ###

import os, sys, re, math

(N, M) = [int(n) for n in input().split()]

cards = set([(i + 1) for i in range(N)])
for i in range(M):
    (L, R) = [int(n) for n in input().split()]
    if min(cards) > R or max(cards) < L:
        cards = {}
        break
    cards -= set([(i + 1) for i in range(L - 1)])
    cards -= set([(i + 1) for i in range(R, N)])

print(len(cards))


### FIXED CODE ###

import os, sys, re, math

(N, M) = [int(n) for n in input().split()]

minC = 1
maxC = N
for i in range(M):
    (L, R) = [int(n) for n in input().split()]
    minC = max(minC, L)
    maxC = min(maxC, R)

print(max((maxC - minC + 1), 0))
### BUGGY CODE ###


def gcd(a, b):
    lower = min(a, b)
    bigger = max(a, b)

    for i in range(lower, 0, -1):
        if a%i==0 and b%i==0:
            return i


def solve():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    d = 10**9
    for i in range(1, N):
        d = min(gcd(A[0], A[i]), d)

    print(d)


if __name__ == "__main__":
    solve()

### FIXED CODE ###

def gcd(a, b):
    """ 最大公約数。aはbより大きいこと """
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


def solve():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    A.sort(reverse=True)
    ans = A[0]
    for i in range(1, N):
        ans = gcd(ans, A[i])

    print(ans)


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

n = int(input())
a = list(map(int,input().split()))
x = [0 for i in range(62)]
for i in range(n):
    b = bin(a[i])
    for i in range(len(b)-2):
        x[-i-1] += int(b[-i-1])
mod = 10**9+7
ans = 0
two = 1
for i in range(1,62):
    ans = (ans + x[-i]*(n-x[-i])*two)%mod
    two = two*2%mod
print(ans)


### FIXED CODE ###

# 入力
N = int(input())
A = list(map(int,input().split()))

ans = 0
P = 10**9+7
bit = [0 for i in range(70)]

# 各bit独立に1が何個あるか数える
for i in range(N):
    S = bin(A[i])
    for j in range(1,len(S)-1):
        if S[-1*j] == '1':
            bit[j-1] += 1

# 各bitの1の個数と0の個数の積が、XOR和が1になる数字の個数と一致
for i in range(70):
    ans += (2**i)*bit[i]*(N-bit[i])
    ans %= P

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

N,K=map(int,input().split())
if K>=N:
	print(0)
	quit()
L = [int(x) for x in input().split()]
L.sort()
if K:
	for _ in range(K):
		L.remove(L[-1])
print(sum(L))

### FIXED CODE ###

n,k=map(int,input().split())
h=[int(i) for i in input().split()]
h.sort(reverse=True)

if k>=n:
    print(0)
else:
    print(sum(h[k:]))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(map(int,input().split())))
b=[]
for i in range(h):
    b.append(list(map(int,input().split())))
dp=[[set([]) for i in range(w)] for j in range(h)]
dp[0][0].add(a[0][0]-b[0][0])
dp[0][0].add(b[0][0]-a[0][0])
for i in range(h):
    for j in range(w):
        if i==j==0:
            continue
        if i==0:
            for k in dp[i][j-1]:
                dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                dp[i][j].add(abs(k+b[i][j]-a[i][j]))
        elif j==0:
            for k in dp[i-1][j]:
                dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                dp[i][j].add(abs(k+b[i][j]-a[i][j]))
        else:
            for k in (dp[i][j-1]|dp[i-1][j]):
                if k<=80*80:
                    dp[i][j].add(abs(k+a[i][j]-b[i][j]))
                    dp[i][j].add(abs(k+b[i][j]-a[i][j]))             
#dp[h-1][w-1]
ans=10**10
for i in dp[h-1][w-1]:
    ans=min(ans,abs(i))
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int, input().split()))
b = [[] for _ in range(H)]
for i in range(H):
    b[i] = list(map(int, input().split()))

for i in range(H):
    for j in range(W):
        a[i][j] =abs(a[i][j]-b[i][j])

dp = [[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(a[0][0])
for i in range(1,H):
    t = a[i][0]
    tmp = set()
    for k in dp[i-1][0]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[i][0] = tmp
for j in range(1,W):
    t = a[0][j]
    tmp = set()
    for k in dp[0][j-1]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[0][j] = tmp
for i in range(1,H):
    for j in range(1,W):
        t = a[i][j]
        tmp = set()
        for k in (dp[i-1][j] | dp[i][j-1]):
            tmp.add(k+t)
            tmp.add(abs(k-t))
        dp[i][j] = tmp
        dp[i-1][j-1] = set()

ls = list(dp[H-1][W-1])
print(min(ls))
### BUGGY CODE ###

from collections import deque, defaultdict

N, X, Y = map(int, input().split())
# 全探索でいけるのでは？
# 有向グラフとしてN回幅優先すれば良いのでは？
tree = [[] for _ in range(N)]
for i in range(N-1):
    tree[i].append(i+1)
    tree[i+1].append(i)
tree[X-1].append(Y-1)
tree[Y-1].append(X-1)
ans = defaultdict(int)
# 更新されない時はqに追加しない
for i in range(N):
    distant = [float("inf")]*N
    q = deque([i])  # 始まりのノード
    distant[i] = 0
    while len(q):
        # vは数字, 親のノードのインデックス
        v = q.pop()
        for e in tree[v]:
            if distant[e] < distant[v]+1:  # 到達済みなら次のノードへ
                continue
            distant[e] = min(distant[v]+1, distant[e])
            q.append(e)
    for i in range(1, N):
        ans[i] += distant.count(i)
for i in range(1, N):
    print(ans[i]//2)


### FIXED CODE ###

from collections import deque, defaultdict

N, X, Y = map(int, input().split())
# 全探索でいけるのでは？
# 有向グラフとしてN回幅優先すれば良いのでは？
tree = [[] for _ in range(N)]
for i in range(N-1):
    tree[i].append(i+1)
    tree[i+1].append(i)
tree[X-1].append(Y-1)
tree[Y-1].append(X-1)
ans = defaultdict(int)
q = deque()
# 更新されない時はqに追加しない
for i in range(N):
    distant = [N]*N
    q.append(i)  # 始まりのノード
    distant[i] = 0
    while len(q):
        # vは数字, 親のノードのインデックス
        v = q.pop()
        for e in tree[v]:
            if distant[e] < distant[v]+1:  # 到達済みなら次のノードへ
                continue
            distant[e] = distant[v]+1
            q.append(e)
    for d in distant:
        ans[d] += 1
for i in range(1, N):
    print(ans[i]//2)
### BUGGY CODE ###

num=int(input())
line=list(map(int,input().split()))
line2=[0]*num
for student in line:
  line2[int(student)-1] += line.index(student) + 1
print(" ".join(map(str,line2)))

### FIXED CODE ###

num=int(input())
line=list(map(int,input().split()))
line2=[0]*num
for i in range(num):
  line2[line[i]-1]=i+1
print(" ".join(map(str,line2)))
### BUGGY CODE ###

stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
A = list(map(int,stdin[1].split()))
ans =[0]*N
for i in range(N):
    ans[i] = A.index(i+1)+1
print(' '.join(map(str,ans)))

### FIXED CODE ###

stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
A = list(map(int,stdin[1].split()))
ans =[0]*N
for i in range(N):
     ans[A[i]-1] = i+1
print(' '.join(map(str,ans)))
### BUGGY CODE ###

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

Asp = []
for a in As:
    Asp.append(a >> 1)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


import functools

l = functools.reduce(lcm, Asp)

fg = False
for a in Asp:
    if (l // a) & 1 == 0:
        fg = True
        break

if fg:
    print(0)
else:
    print(M // l - M // (l * 2))

### FIXED CODE ###

N, M = map(int, input().split())
As = list(map(lambda a: int(a) >> 1, input().split()))

from fractions import gcd

l = As[0]
for a in As:
    l = l * a // gcd(l, a)
    if l > M:
        break

if l <= M:
    i = 2
    while l & (i - 1) == 0:
        i <<= 1
    i = (i >> 1) - 1

    fg = False
    if i > 0:
        for a in As:
            if a & i > 0:
                fg = True
                break

    if fg:
        print(0)
    else:
        print(M // l - M // (l * 2))
else:
    print(0)
### BUGGY CODE ###

import collections

n = int(input())

li = []
r = []
rs = []
cnt = 0

for i in range(n):
    s = str(input())
    sl = list(s)
    li.append(sl)
    r.append([])
    rs.append("")
    coll = collections.Counter(li[i])
    r[i].extend(coll.most_common())
    r[i].sort()
    rs[i] = ''.join(str(s) for s in r[i])

collr = collections.Counter(rs)

for i in collr.values():
    cnt += i * (i-1) / 2

print(int(cnt))

### FIXED CODE ###

n = int(input())

l = []
cnt = 0
t = 0

for i in range(n):
    s = str(input())
    sl = ''.join(sorted(s))
    l.append(sl)

l.sort()

tmp = l[0]

for i in range(1, n):
  if tmp == l[i]:
    cnt += 1
  else:
    tmp = l[i]
    t += int(cnt * (cnt + 1) / 2)
    cnt = 0
else:
    t += int(cnt * (cnt + 1) / 2)

print(t)
### BUGGY CODE ###

n,m=map(int,input().split())
for i in range(m//n+1)[::-1]:
	if m%i<1:
		print(i)
		exit()

### FIXED CODE ###

n,m=map(int,input().split())
for i in range(m//n+1)[::-1]:
	if m%i<1:
		print(i)
		exit()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

n = int(input())
a = []
b = []
b2 = []
c = []
count = 0

for i in range(n):
    x,y = list(map(int,input().split()))
    a.append([x,y,x+y])

a.sort(key=lambda x: x[2])

for i in a:
    c = b.copy()
    if len(b) > 0:
        if i[0]-i[1] <= max(b):
            #b.extend(list(range(i[0]-i[1], i[0]+i[1])))
            #b2 = b.copy()
            #b = list(set(b))
            #if len(b2) != len(b):
                #b = c.copy()
            count += 1
        else:
            b = []
            b.extend(list(range(i[0]-i[1], i[0]+i[1])))
    else:
        b.extend(list(range(i[0]-i[1], i[0]+i[1])))
        
    
print(n - count)

### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(input())
a = []
b = []
b2 = []
c = []
count = 0
max = 0

for i in range(n):
    x,y = list(map(int,input().split()))
    a.append([x,y,x+y])

a.sort(key=lambda x: x[2])

for i in a:
    if max != 0 and i[0]-i[1] < max:
        count += 1
    else:
        max = i[2]
    
print(n - count)
### BUGGY CODE ###


R,G,B,N = map(int,input().split())
ans = 0

for r in range(N // R + 1):

    for g in range( N // G + 1 ):

        if (N - r * R - g * G) >= 0 and (N - r * R - g * G) % B == 0:
            ans += 1

print (ans)


### FIXED CODE ###


R,G,B,N = map(int,input().split())
ans = 0

for r in range(N // R + 1):

    for g in range( N // G + 1 ):

        if (N - r * R - g * G) >= 0 and (N - r * R - g * G) % B == 0:
            ans += 1

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

import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
for i in range(1, N+1):
    heihoukon = math.floor(math.sqrt(i))
    tmp = 0
    for x in range(1, heihoukon):
        for y in range(1, heihoukon):
            for z in range(1, heihoukon):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    tmp += 1
    print(tmp)

### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
ans = [0 for _ in range(0, 10050)]
for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            n = i*i + j*j + k*k + i*j + j*k + k*i
            if n < 10050:
                ans[n] += 1
            else:
                continue
for i in range(1, N +1):
    print(ans[i])
### BUGGY CODE ###

from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(H):
    for j in range(W):
        ans=max(ans,dist[i][j])
print(ans)

### FIXED CODE ###

from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)