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

'''
https://atcoder.jp/contests/abc084/tasks/abc084_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    def primecheck(n):
        p = [True] * (n + 1)
        p[0] = False
        p[1] = False
        for i in range(2, int(n ** 0.5) + 1):
            if p[i]:
                for j in range(i * i, n + 1, i):
                    p[j] = False
        return p
    
    p = primecheck(10**5)

    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        res = 0
        for i in range(l, r+1, 2):
            if p[i]==p[(i+1)//2]==1:
                res += 1
        print(res)

if __name__ == '__main__':
    main()

### FIXED CODE ###

'''
https://atcoder.jp/contests/abc084/tasks/abc084_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    def primecheck(n):
        p = [True] * (n + 1)
        p[0] = False
        p[1] = False
        for i in range(2, int(n ** 0.5) + 1):
            if p[i]:
                for j in range(i * i, n + 1, i):
                    p[j] = False
        return p
    
    p = primecheck(10**5)
    cnt = 0
    res = [0]*(10**5)
    for i in range(10**5):
        if p[i]==p[(i+1)//2]==1:
            cnt += 1
        res[i] = cnt


    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        print(res[r]-res[l-1])

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

n=int(input())
a=[int(i) for i in input().split()]
b=0
for j in range(n):
  for k in range(n):
    if a[j]==a[k] and j!=k:
      b+=1
if b==0:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
for j in range(n-1):
	if a[j]<a[j+1]:
		pass
	else:
		print('NO')
		exit()
print('YES')
### BUGGY CODE ###

n,k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf') for i in range(n)]
dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a
    
for i in range(n-1):
    if i == 0:
        dp[i+1] = abs(h[i+1] - h[i])
    else:
        for j in range(k):
            dp[i+1] = chmin(dp[i+1], dp[i-j] + abs(h[i+1] - h[i-j]))
print(dp[n-1])

### FIXED CODE ###

n,k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf') for i in range(n)]
dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a
    
for i in range(n-1):
    if i == 0:
        dp[i+1] = abs(h[i+1] - h[i])
    else:
        for j in range(k):
            dp[i+1] = chmin(dp[i+1], dp[i-j] + abs(h[i+1] - h[i-j]))
print(dp[n-1])
### BUGGY CODE ###

K = int(input())
count = len(str(K))
n = 0
for i in range(count):
    n += 7*10**i
while True:
    if K % 2 == 0 or K % 5 == 0:
        count = -1
        break
    if n % K == 0:
        break
    n += 7*10**count
    count += 1
print(count)

### FIXED CODE ###

K = int(input())
count = 1
n = 0
if K % 2 == 0 or K % 5 == 0:
    count = -1
    print(count)
else:
    while True:
        n = (n*10+7)%K
        if n == 0:
            break
        count += 1
    print(count)
### BUGGY CODE ###

import itertools

N=int(input())
S=input()
a,b,c=0,0,0

l=set(itertools.combinations(S, 3))

print(len(l))


### FIXED CODE ###

N=int(input())
S=input()
cnt=0
 
for i in range(10):
    a=S.find(str(i))
    if a==-1:
        continue
    for j in range(10):
        b=S.find(str(j),a+1)
        if b==-1:
            continue
        for k in range(10):
            if S.find(str(k),b+1)!=-1:
                cnt+=1
print(cnt)
### BUGGY CODE ###

n = int(input())
a =[int(x) for x in input().split()]
ans = 0
ans2 = 0
b = 10**9 + 7
for index,i in enumerate(a):
    for j in a[index+1:]:
        ans =  (ans + (i *j)%b)%b
print(ans)

### FIXED CODE ###

n = int(input())
a_list =[int(x) for x in input().split()]
mod = 10**9 + 7

s_list = [0]*(n+1)
for i,a in enumerate(a_list):
    s_list[i+1] = s_list[i]+a


ans = 0
for i,a in enumerate(a_list):
    ans += a * (s_list[n]-s_list[i+1])
    
print(ans%mod)
### BUGGY CODE ###

from fractions import Fraction
import numpy as np

n = int(input())
num = list(map(int, input().split()))
num = [ Fraction(i) for i in num ]
num = np.array(num)

if 0 in num:
    print(0)
else:
    mult = np.prod(num)
    if mult > 10**18:
        print(-1)
    else:
        print(int(mult))

### FIXED CODE ###

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

limit = 10 ** 18
A.sort()
result = A[0]
for a in A[1:]:
    result *= a
    if result > limit:
        print(-1)
        exit()
print(result)
### BUGGY CODE ###

import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l):
            if n!=m:
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//6)
if __name__ == '__main__':
    main()


### FIXED CODE ###

import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l[n+1:]):
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//3)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

def rem():
  mod=10**9+7
  s=input()
  dp=[[0]*13 for _ in range(len(s)+1)]
  dp[0][0]=1
  r=[i%13 for i in range(130)]

  for i in range(len(s)):
    if s[i]=='?':
      for j in range(13):
        for k in range(10):
          dp[i+1][r[j*10+k]]+=dp[i][j]
    else:
      t = int(s[i])
      for j in range(13):
        dp[i+1][r[j*10+t]] += dp[i][j]

    for k in range(13):
      dp[i+1][k] %= mod

  print(dp[len(s)][5])

rem()

### FIXED CODE ###

mod=10**9+7
s=input()
dp=[[0]*13 for _ in range(len(s)+1)]
dp[0][0]=1
r=[i%13 for i in range(130)]

for i in range(len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i+1][r[j*10+k]]+=dp[i][j]
  else:
    t = int(s[i])
    for j in range(13):
      dp[i+1][r[j*10+t]] += dp[i][j]

  for k in range(13):
    dp[i+1][k] %= mod

print(dp[len(s)][5])
### BUGGY CODE ###

n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k for i in range(n)]
for i in a:
    for j in range(len(score)):
        if j != i-1:
            score[j] = score[j]-1

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')

### FIXED CODE ###

n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k-q for i in range(n)]
for i in a:
    score[i-1] = score[i-1]+1
    

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

N,K = map(int, input().split())
h = [int(x) for x in input().split()]
cost = [0] * N

cost[0] = 0
cost[1] = abs(h[1] - h[0])


for i in range(N - 1):
    min = cost[i] + 10000
    for j in range(K):
        if j < i + 1:
            c1 = cost[i - j] + abs((h[i + 1] - h[i - j]))
            if min > c1:
                min = c1
    cost[i + 1] = min

print(min)


### FIXED CODE ###

N,K = map(int, input().split())
h = [int(x) for x in input().split()]
cost = [0] * N

cost[0] = 0
cost[1] = abs(h[1] - h[0])


for i in range(N - 1):
    min = cost[i] + 10000
    for j in range(K):
        if j < i + 1:
            c1 = cost[i - j] + abs((h[i + 1] - h[i - j]))
            if min > c1:
                min = c1
    cost[i + 1] = min

print(min)
### BUGGY CODE ###

def resolve():
    from collections import deque

    n, m = map(int, input().split())
    d = {}
    par = [[] for i in range(n)]
    que = deque()
    for i in range(m):
        a, b = map(int, input().split())
        par[a - 1].append(b)
        par[b - 1].append(a)

    que.append(1)
    while(len(que) > 0):
        label = que.popleft()
        for i, p in enumerate(par):
            if label in p and i + 1 not in d.keys():
                que.append(i + 1)
                d[i + 1] = label

    if len(d) < n:
        print("No")
        return

    print("Yes")
    for i in range(2, n + 1):
        print(d[i])

resolve()

### FIXED CODE ###

def resolve():
    from collections import deque

    n, m = map(int, input().split())
    d = {}
    par = [[] for i in range(n)]
    que = deque()
    for i in range(m):
        a, b = map(int, input().split())
        par[a - 1].append(b)
        par[b - 1].append(a)

    que.append(1)
    while(len(que) > 0):
        label = que.popleft()
        for i in par[label - 1]:
            if i not in d.keys():
                que.append(i)
                d[i] = label

    if len(d) < n:
        print("No")
        return

    print("Yes")
    for i in range(2, n + 1):
        print(d[i])

resolve()
### BUGGY CODE ###

import sys
import bisect
readline = sys.stdin.readline

def main():
	n = int(input())
	s = tuple(input())

	ans = 0
	r = []
	g = []
	b = []
	for i in range(3):
		if s[i] == 'R':
			r.append(i)
		elif s[i] == 'G':
			g.append(i)
		else:
			b.append(i)

	for i in range(3,n):
		if s[i] == 'R':
			r.append(i)
		elif s[i] == 'G':
			g.append(i)
		else:
			b.append(i)

		for j in range(i-2):
			if (j-i) % 2 == 0:
				if s[i] == s[j]:
					continue
				elif 'R' not in [s[i],s[j]]:
					ans += bisect.bisect_left(r,i) - bisect.bisect_left(r,j)
					index = bisect.bisect_left(r,j + (i-j)//2 )
					if index < len(r):
						if r[index] == j + (i-j)//2:
							ans -= 1
				elif 'G' not in [s[i],s[j]]:
					ans += bisect.bisect_left(g,i) - bisect.bisect_left(g,j)
					index = bisect.bisect_left(g,j + (i-j)//2 )
					if index < len(g):
						if g[index] == j + (i-j)//2:
							ans -= 1
				elif 'B' not in [s[i],s[j]]:
					ans += bisect.bisect_left(b,i) - bisect.bisect_left(b,j)
					index = bisect.bisect_left(b,j + (i-j)//2 )
					if index < len(b):
						if b[index] == j + (i-j)//2:
							ans -= 1
			else:
				if s[i] == s[j]:
					continue
				elif 'R' not in [s[i],s[j]]:
					ans += bisect.bisect_left(r,i) - bisect.bisect_left(r,j)

				elif 'G' not in [s[i],s[j]]:
					ans += bisect.bisect_left(g,i) - bisect.bisect_left(g,j)

				elif 'B' not in [s[i],s[j]]:
					ans += bisect.bisect_left(b,i) - bisect.bisect_left(b,j)


	print(ans)

if __name__ == '__main__':
	main()


### FIXED CODE ###

import sys
import bisect
readline = sys.stdin.readline

def main():
	n = int(input())
	s = tuple(input())

	ans = 0
	r = []
	g = []
	b = []
	for i in range(3):
		if s[i] == 'R':
			r.append(i)
		elif s[i] == 'G':
			g.append(i)
		else:
			b.append(i)

	for i in range(3,n):
		if s[i] == 'R':
			r.append(i)
		elif s[i] == 'G':
			g.append(i)
		else:
			b.append(i)

		for j in range(i-2):
			if (j-i) % 2 == 0:
				if s[i] == s[j]:
					continue
				elif 'R' not in [s[i],s[j]]:
					ans += bisect.bisect_left(r,i) - bisect.bisect_left(r,j)
					index = bisect.bisect_left(r,j + (i-j)//2 )
					if index < len(r):
						if r[index] == j + (i-j)//2:
							ans -= 1
				elif 'G' not in [s[i],s[j]]:
					ans += bisect.bisect_left(g,i) - bisect.bisect_left(g,j)
					index = bisect.bisect_left(g,j + (i-j)//2 )
					if index < len(g):
						if g[index] == j + (i-j)//2:
							ans -= 1
				elif 'B' not in [s[i],s[j]]:
					ans += bisect.bisect_left(b,i) - bisect.bisect_left(b,j)
					index = bisect.bisect_left(b,j + (i-j)//2 )
					if index < len(b):
						if b[index] == j + (i-j)//2:
							ans -= 1
			else:
				if s[i] == s[j]:
					continue
				elif 'R' not in [s[i],s[j]]:
					ans += bisect.bisect_left(r,i) - bisect.bisect_left(r,j)

				elif 'G' not in [s[i],s[j]]:
					ans += bisect.bisect_left(g,i) - bisect.bisect_left(g,j)

				elif 'B' not in [s[i],s[j]]:
					ans += bisect.bisect_left(b,i) - bisect.bisect_left(b,j)


	print(ans)

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


N = int(input())
s = ((N-1)**2)*3  + (N-1) * 3 + 1
p = 0
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
for i in range (N-1):
    for j in range(N-1):
        k = gcd((i+2), (j+2))
        for l in range (N-1):
            m = gcd(k, (l+2))
            p += m
print(p + s)

### FIXED CODE ###

N = int(input())
s = ((N-1)**2)*3  + (N-1) * 3 + 1
p = 0
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
for i in range (N-1):
    for j in range(N-1):
        k = gcd((i+2), (j+2))
        for l in range (N-1):
            if k != 1:
                m = gcd(k, (l+2))
                p += m
            else:
                p +=1
            
print(p + s)
### BUGGY CODE ###

a = list(input())
a = [int(s) for s in a]
a = a[::-1]
s = [0]
ans = [1] + [0] * 2018
ans_int = 0

for i in range(len(a)):
    add = s[i] + a[i] * 10 ** i
    add = add % 2019
    ans[add] += 1
    s.append(add)
    if ans[add] > 1:
        ans_int += 1


print(ans_int)

### FIXED CODE ###

a = input()[::-1]
add = 0
ans = [1] + [0] * 2018
ans_int = 0
d = 1

for i in range(len(a)):
    add = (add + int(a[i]) * d) % 2019
    d = (10 * d) %2019
    ans[add] += 1

for i in range(len(ans)):
    a =((ans[i] - 1) * ans[i]) /2
    ans_int += a

print(int(ans_int))
### BUGGY CODE ###

import copy
from collections import deque

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

max_a = max(a)

def gcd(n, m):
    if m == 0:
        return n
    
    return gcd(m, n % m)

ans = 0

if len(a) == 1:
    print(a[0])
    exit()

for i in range(n):
    _a = copy.deepcopy(a)

    del _a[i]

    que = deque(_a)

    while len(que) > 1:
        n = que.pop()
        m = que.pop()
        l = gcd(n, m)
        
        que.append(l)

    tmp_max = que.pop()
    ans = max(ans, tmp_max)

print(ans)

### FIXED CODE ###

import copy

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

max_a = max(a)


def gcd(n, m):
    if m == 0:
        return n
    
    return gcd(m, n % m)


# 事前処理
# あらかじめ、左端からi個でgcdを計算しておく
# 同様に右からも
l = [0] * n
r = [0] * n

l[0] = a[0]
r[-1] = a[-1]

for i in range(0, n-1):
    l[i+1] = gcd(l[i], a[i+1])

for i in range(n-1, 0, -1):
    r[i-1] = gcd(r[i], a[i-1])


tmp = 0
ans = 0

for i in range(n):
    if i == 0:
        tmp = r[i+1]
    elif i == n-1:
        tmp = l[i-1]
    else:
        tmp = gcd(l[i-1], r[i+1])
    
    ans = max(ans, tmp)

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

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    cnt = dict()
    for i in a:
        cnt[i] = cnt.get(i, 0) + 1

    for k in range(len(a)):
        cnt2 = cnt.copy()
        cnt2[a[k]] -= 1

        sum = 0
        for c in cnt2.values():
            sum += c * (c - 1) // 2

        print(sum)




### FIXED CODE ###

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    cnt = dict()
    ans = dict()
    for i in a:
        cnt[i] = cnt.get(i, 0) + 1

    for (idx, v) in cnt.items():
        ans[idx] = v * (v - 1) // 2

    sum_ = sum(ans.values())

    for k in range(len(a)):
        res = sum_ - (cnt[a[k]] - 1)
        print(res)
### BUGGY CODE ###

import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    if len(a) == 1:
        return "1"
    a = np.array(a, np.int)
    ans = np.ones(n, np.int)
    for i, _a in enumerate(a):
        tmp = a % _a != 0
        tmp[i] = True
        ans *= tmp
    return str(sum(ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


### FIXED CODE ###

import numpy as np
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    table = np.array([True] * (10**6 + 1))
    for _a in a:
        if table[_a]:
            table[2*_a::_a]=False
    i = np.array([k for k,v in Counter(a).items() if v==1],dtype=np.int)
    return str(table[i].sum())


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
### BUGGY CODE ###

n,k  = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
for i in range(1, n):
  start = max(0, i - k)
  dp[i] = dp[start] + abs(h[start] - h[i])
  for j in range(start+1, i + 1):
    dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]))
  
print(dp[n-1])

### FIXED CODE ###

n,k  = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
for i in range(1, n):
  start = max(0, i - k)
  dp[i] = dp[start] + abs(h[start] - h[i])
  for j in range(start+1, i + 1):
    dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]))
  
print(dp[n-1])
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
from collections import deque
n, *lst = map(int, read().split())

def convert(A):
    return [x ^ y for x, y in zip(A, A[1:])] + [A[-1] ^ A[0]]

al = lst[:n]
bl = lst[n:]
a = convert(al)
b = convert(bl)
for k in range(n):
    if a == b:
        x = al[0] ^ bl[0]
        print(k, x)
    al, a = al[1:] + [al[0]], a[1:] + [a[0]]

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())

A = list(map(int, readline().split()))
B = list(map(int, readline().split()))


def convert(A):
    return [x ^ y for x, y in zip(A, A[1:])] + [A[-1] ^ A[0]]


C = convert(A)
D = convert(B)


def Z_algorithm(S):
    # 共通接頭辞の長さを返す
    N = len(S)
    arr = [0] * N
    arr[0] = N
    i, j = 1, 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        arr[i] = j
        if not j:
            i += 1
            continue
        k = 1

        while i + k < N and k + arr[k] < j:
            k += 1
        i += k
        j -= k

    return arr


Z = Z_algorithm(D + [-1] + C + C)[N + 1:N + N + 1]

K = [i for i, x in enumerate(Z) if x == N]
X = [A[k] ^ B[0] for k in K]

print('\n'.join('{} {}'.format(k, x) for k, x in zip(K, X)))
### BUGGY CODE ###

import sys

def parent(i):
    return (i + 1) / 2 - 1

def left(i):
    return 2 * i + 1

def right(i):
    return 2 * i + 2

def sibling(i):
    if i % 2 == 0:
        return i - 1
    else:
        return i + 1

def insert(S, k):
    S.append(k)
    now = len(S) - 1
    while True:
        p = parent(now)
        if p < 0:
            break
        elif S[now] > S[p]:
            S[now], S[p] = S[p], S[now]
        else:
            now = p

def extract(S):
    print S[0]
    S[0] = S[-1]
    S.pop()

    now = 0
    while True:
        l, r = left(now), right(now)
        if r < len(S):
            if S[now] < S[l] and S[r] <= S[l]:
                S[now], S[l] = S[l], S[now]
                now = l
            elif S[now] < S[r] and S[l] < S[r]:
                S[now], S[r] = S[r], S[now]
                now = r
        elif l < len(S):
            if S[now] < S[l]:
                S[now], S[l] = S[l], S[now]
                now = l
            else:
                break
        else:
            break

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    lines.pop()

    S = []
    for line in lines:
        if line[0] == "i":
            insert(S, int(line[7:]))
        else:
            extract(S)

### FIXED CODE ###

import sys

def insert(k):
    global S, last
    S[last] = k
    idx = last
    while True:
        p = (idx + 1) / 2 - 1
        if S[idx] <= S[p]:
            break
        else:
            S[idx], S[p] = S[p], S[idx]
            idx = p
    last += 1

def maxHeapify(i):
    global S, last
    l = 2 * i + 1
    r = 2 * i + 2

    if l < last and S[l] > S[i]:
        largest = l
    else:
        largest = i

    if r < last and S[r] > S[largest]:
        largest = r

    if largest != i:
        S[i], S[largest] = S[largest], S[i]
        maxHeapify(largest)

def extract():
    global S, last
    print S[0]
    last -= 1
    S[0], S[last] = S[last], 0
    maxHeapify(0)

lines = sys.stdin.readlines()
lines.pop()

S = [0] * 2000001
S[2000000] = 2000000000
last = 0
for line in lines:
    if line[0] == "i":
        insert(int(line[7:]))
    else:
        extract()
### BUGGY CODE ###

from sys import exit
import queue
import numpy as np
Q = queue.Queue()
H,W = [int(n) for n in input().split()]
INF = (1 << 21)
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
A = [0 for _ in range(H)]
black = []
dis = np.array([[0 for _ in range(W)] for _ in range(H)])
for i in range(H):
    A[i] = list(str(input()))
    for j in range(len(A[i])):
        if(A[i][j] == "#"):
            Q.put((i,j))
A = np.array(A)
while(not Q.empty()):
    now = Q.get()
    A[now[0]][now[1]] = "#"
    for d in dxy:
        i,j = now[0]+d[0], now[1]+d[1]
        if(0 <= i <= H-1 and 0 <= j <= W-1 and A[i][j] == "."):
            A[i][j] = "#"
            Q.put((i,j))
            dis[i][j] = dis[now[0]][now[1]] + 1
ans = 0
for i in range(H):
    tmp = np.max(dis[i])
    ans = max(ans,tmp)
print(ans)


### FIXED CODE ###

from collections import deque
H, W = [int(n) for n in input().split()]
map = [0 for _ in range(H)]
INF = 10**8
dis = [[INF for _ in range(W)]for __ in range(H)]
Q = deque()
for i in range(H):
    map[i] = list(str(input()))
    for j in range(W):
        if map[i][j] == "#":
            Q.append((i, j))
            dis[i][j] = 0
dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
ans = 0
while(len(Q) != 0):
    n = Q.pop()
    for d in dxy:
        tx, ty = n[0] + d[0], n[1] + d[1]
        if(0 <= tx <= H - 1 and 0 <= ty <= W - 1 and map[tx][ty] == "."):
            map[tx][ty] = "#"
            Q.appendleft((tx, ty))
            dis[tx][ty] = dis[n[0]][n[1]] + 1
            ans = max(dis[tx][ty], ans)
print(ans)
# for i in range(H):
#     print(dis[i])
### BUGGY CODE ###

import math

m=999999
l=[False]*m
l[1]=True
for i in range(3,m+1):
    if i%2==0:continue
    for e in range(2,int(math.sqrt(i)+1)):
        if i%e==0:
            break
    else:
        l[i-1]=True
    
while True:
    try:n=int(input())
    except:break
    print(len([i for i in l[:n:] if i]))
    

### FIXED CODE ###


import math

m=999999
s=int(math.sqrt(m)+1)
li=[0]*m
li[0]=1
for i in range(1,s):
    if li[i]==0:
        li[i*2+1::i+1]=[1 for e in range(len(li[i*2+1::i+1]))]
while True:
    try:n=int(input())
    except:break
    print(len([i for i in li[:n:] if i==0]))