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

import math
a,b=map(int,input().split())
Cdiv=[]
ans=[]
for i in range(1,min(a,b)+1):
    if a%i==0 and b%i==0:
        Cdiv.append(i)
for i in reversed(Cdiv):
    flag=0
    for j in range(2,1+int(math.sqrt(int(i)))):
        if i%j==0:
            flag+=1
            break
    if flag==0:
        ans.append(i)

print(len(ans))

### FIXED CODE ###

import fractions

A,B = map(int, input().strip().split(' '))

# 素因数分解
def trial_division(n):
  result = []
  while n % 2 == 0:
    result.append(2)
    n //= 2
  f = 3
  while f*f <= n:
    if n % f == 0:
      result.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    result.append(n)
  return result

gcd_ = fractions.gcd(A,B)
if gcd_ == 1:
  print(1)
else:
  print(len(set(trial_division(gcd_)))+1)
### BUGGY CODE ###

ks= list(map(int, input().split())) 

count = 0

x = 0
y = 0
z = 0

for targetX in range(ks[1]+1):
    
    if targetX <= ks[0]:
    
        for targetY in range(ks[1]+1):
            
            if targetY <= ks[0]:
        
                for targetZ in range(ks[1]+1):
                
                    if targetZ <= ks[0]:
                        if targetX + targetY + targetZ == ks[1]:
                        
                            count +=1
                    
                    targetZ +=1
        
            targetY +=1
        
    targetX +=1
        

#print(ks)
print(count)


### FIXED CODE ###

ks= list(map(int, input().split())) 
 
count = 0
 
x = 0
y = 0
z = 0
 
for targetX in range(ks[0]+1):
    
    
    if targetX <= ks[0] and ks[1]-(targetX+ks[0]+ks[0]) <= 0:
    
        for targetY in range(ks[0]+1):
            
            z = ks[1] - (targetX + targetY)
            
            if 0 <= z and z <= ks[0]:
                count += 1
                
        
        
        
 
print(count)
### BUGGY CODE ###

N,M,Q=map(int,input().split())
import numpy as np
trains=np.zeros((N+1,N+1),dtype=int)
for i in range(M):
  l,r=map(int,input().split())
  trains[l][r]+=1
  
trains=np.cumsum(trains,axis=0)
trains=np.cumsum(trains,axis=1)

for i in range(Q):
  p,q=map(int,input().split())
  print(trains[q][q]-trains[p-1][q]-trains[q][p-1]+trains[p-1][p-1])


### FIXED CODE ###

N,M,Q=map(int,input().split())
pos=[[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l,r=map(int,input().split())
  pos[l][r]+=1

for l in range(N+1):
  sums=0
  for r in range(N):
    pos[l][r+1]=pos[l][r]+pos[l][r+1]
    
for r in range(N+1):
  sums=0
  for l in range(N):
    pos[l+1][r]=pos[l][r]+pos[l+1][r]

for i in range(Q):
  p,q=map(int,input().split())
  print(pos[q][q]-pos[p-1][q]-pos[q][p-1]+pos[p-1][p-1])
### BUGGY CODE ###

N=int(input())
total=1
A=list(map(int,input().split()))
if A.count(0)>=1:
  total=0
else:
  for i in range(N):
    total*=A[i]

if 1*(10**18)+1<=total:
  print("-1")
else:
  print(total)


### FIXED CODE ###

N=int(input())
total=1
A=list(map(int,input().split()))
flag=True
high=1*(10**18)+1
if A.count(0)>=1:
  total=0
else:
  for i in range(N):
    total*=A[i]
    if high<=total:
      flag=False
      break

if not flag:
  print("-1")
else:
  print(total)
### BUGGY CODE ###

import math

def calc(H, T, a, b):
    cnt = 0
    for h in H:
        cnt += math.ceil((h - b * T) / (a - b))
    if cnt <= T:
        return False
    else:
        return True

tmp = [int(n) for n in input().split()]
a = tmp[1]
b = tmp[2]
H = []

for i in range(tmp[0]):
    H.append(int(input()))
H = list(sorted(H))[::-1]
T = 1
while calc(H, T, a, b):
    T = T + 1

print(T)


### FIXED CODE ###

import math

def calc(H, T, a, b):
    cnt = 0
    for h in H:
        if (h -b*T) >= 0:
            cnt += math.ceil((h - b * T) / (a - b))
    if cnt <= T:
        return True
    else:
        return False

tmp = [int(n) for n in input().split()]
a = tmp[1]
b = tmp[2]
H = []

H = sorted([int(input()) for i in range(tmp[0])])[::-1]
minT = 0
maxT = math.ceil(H[0] / b)
T = int((maxT + minT) / 2)

while True:
    T = math.ceil((maxT + minT) / 2)
    if calc(H, T, a, b):
        maxT = T
    else:
        minT = T
    if maxT - minT <= 1:
        break
print(maxT)
### BUGGY CODE ###

K, S = map(int, input().split())

cnt = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
          ijk_sum = i + j + k
          if ijk_sum == S:
              cnt +=1
print(cnt)

### FIXED CODE ###

K, S = map(int, input().split())
 
cnt = 0
for i in range(K+1):
    for j in range(K+1):
        k = S - i - j
        if k >= 0 and k <= K:
            cnt += 1
print(cnt)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
f = [[a] for a in A]
for i in range(N):
    b = 1<<i
    j = 0
    while j < 1<<N:
        j |= b
        f[j] = sorted(f[j]+f[j^b])[-2:]
        j += 1
Ans = [sum(f[1])]
for a, b in f[2:]:
    Ans.append(max(Ans[-1], a+b))
print("\n".join(map(str, Ans)))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
f = [[a] for a in A]
for i in range(N):
    for j in range(1<<N):
        if j & 1<<i:
            f[j] = sorted(f[j]+f[j^1<<i], reverse=True)[:2]
Ans = [sum(f[1])]
for a, b in f[2:]:
    Ans.append(max(Ans[-1], a+b))
print("\n".join(map(str, Ans)))
### BUGGY CODE ###

'use strict'
import math

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

for i in range(M):
  goods_price_list.sort(reverse=True)
  goods_price_list[0] = math.floor(goods_price_list[0]/2)

print(sum(goods_price_list))

### FIXED CODE ###

'use strict'
import heapq

N, M = map(int, input().split())
goods_price_list = [-int(_) for _ in input().split()]

heapq.heapify(goods_price_list)

for i in range(M):
  heapq.heappush(goods_price_list, -((-heapq.heappop(goods_price_list) // 2)))

print(-sum(goods_price_list))
### BUGGY CODE ###

mod = 10 ** 9 + 7
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
r1, c1, r2, c2 = map(int, input().split())
fa = [1] * (r2 + c2 + 3)
fi = [1] * (r2 + c2 + 3)
for i in range(1, r2 + c2 + 3):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
def ans(r, c):
    return fa[r + c + 2] * fi[r + 1] * fi[c + 1] % mod - 1
print((ans(r2, c2) - ans(r2, c1 - 1) - ans(r1 - 1, c2) + ans(r1 - 1, c1 - 1)) % mod)

### FIXED CODE ###

mod = 10 ** 9 + 7
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
r1, c1, r2, c2 = map(int, input().split())
fa = [1] * (r2 + c2 + 3)
fi = [1] * (r2 + c2 + 3)
for i in range(1, r2 + c2 + 3):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
def ans(r, c):
    return fa[r + c + 2] * fi[r + 1] * fi[c + 1] % mod - 1
print((ans(r2, c2) - ans(r2, c1 - 1) - ans(r1 - 1, c2) + ans(r1 - 1, c1 - 1)) % mod)
### BUGGY CODE ###

n = int(input())
ns = list(map(int, input().split()))
ans = 0
from collections import Counter
c = Counter(ns)
dubbles = set([key for key, value in c.items() if value >= 2])
ns = sorted(ns)
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors

for i in range(n):
    if make_divisors(ns[i]) & dubbles:
        dubbles.add(ns[i])
        continue
    ans += 1
    dubbles.add(ns[i])
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
ns = list(map(int, input().split()))
c = Counter(ns)
ans = 0

l = [True] * (max(ns)+1)
for i in sorted(set(ns)):
    if l[i]:
        j = i*2
        while j < len(l):
            l[j] = False
            j += i

a = set([key for key, value in c.items() if value == 1])
for i in a:
    if l[i]:
        ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
cnt = 0
a = [input() for i in range(n)]
set_ = set(a)
for j in set_:
    if a.count(j) % 2 == 1:
        cnt+=1
print(cnt)

### FIXED CODE ###

n = int(input())
a = set()
for i in range(n):
    tmp = int(input())
    if tmp in a:
        a.remove(tmp)
    else:
        a.add(tmp)
print(len(a))
### BUGGY CODE ###

import math
def is_prime(n):
	if n == 1: return True
	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False
	return True

a, b = map(int,input().split())

c = 0
for i in range(1,min(a,b)+1):
	if a % i == 0 and b % i == 0:
		if is_prime(i):
			c+=1			
		#cd_n.append(i)
print(c)

### FIXED CODE ###

import random

def gcd(a,b):
        if b == 0:
                return a
        else:
                return gcd(b , a%b) 
def is_prime(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1:
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

a, b = map(int,input().split())

c = 1
m = gcd(a,b)

i = 1
while i * i <=m:
        if a%i == 0 and b%i == 0:
                if is_prime(i):
                        c+=1
                if is_prime(m//i):
                        c+=1
        i+=1
print(c)
### BUGGY CODE ###

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

mod = 10**9+7
ans = 0

for i in range(60):
  one=0
  for j in map(lambda x:x%pow(2,(i+1))//pow(2,i), A):
    one += j
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
import numpy as np
mod = 10**9+7
ans = 0
A = np.array(A)
for i in range(60):
  one = np.count_nonzero(A>>i&1)
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

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

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    n,m,p = map(int, input().split())
    edge = [[] for _ in range(m)]
    adj = [[] for _ in range(n)]
    for i in range(m):
        a,b,c = map(int, input().split())
        edge[i] = [a-1,b-1,-(c-p)]
        adj[b-1].append(a-1)

    visited = [0]*n
    dq = deque([n-1])
    while dq:
        v = dq.popleft()
        visited[v] = 1
        for nv in adj[v]:
            if visited[nv] == 0:
                dq.append(nv)
    
    def bellmanford(n, s, edge):
        inf = 10**17
        d = [inf] * n
        d[s] = 0
        for i in range(n):
            for a,b,c in edge:
                if d[a] != inf and d[b] > d[a]+c:
                    d[b] = d[a] + c
                    if i == n-1 and visited[b] == 1:
                        return -inf
        return -d[-1]

    res = bellmanford(n,0,edge)
    if res == -inf:
        print(-1)
    elif res < 0:
        print(0)
    else:
        print(res)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    n,m,p = map(int, input().split())
    edge = [[] for _ in range(m)]
    adj = [[] for _ in range(n)]
    for i in range(m):
        a,b,c = map(int, input().split())
        edge[i] = [a-1,b-1,-(c-p)]
        adj[b-1].append(a-1)

    visited = [0]*n
    visited[-1] = 1
    dq = deque([n-1])
    while dq:
        v = dq.popleft()
        for nv in adj[v]:
            if visited[nv] == 0:
                visited[nv] = 1
                dq.append(nv)
    
    def bellmanford(n, s, edge):
        inf = 10**17
        d = [inf] * n
        d[s] = 0
        for i in range(n):
            for a,b,c in edge:
                if d[a] != inf and d[b] > d[a]+c:
                    d[b] = d[a] + c
                    if i == n-1 and visited[b] == 1:
                        return -inf
        return -d[-1]

    res = bellmanford(n,0,edge)
    if res == -inf:
        print(-1)
    elif res < 0:
        print(0)
    else:
        print(res)

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

N = int(input())
S = list(input())

memo = [False for _ in range(100)]
ans = 0
f = False
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    if memo[int(S[i]) * 10 + int(S[j])]:
      continue
    ans += len(set(S[j + 1 :]))
    memo[int(S[i]) * 10 + int(S[j])] = True
    if ans == 999:
      f = True
      break
  if f:
    break
print(ans)

### FIXED CODE ###

N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  i = S.find(p[0])
  if i >= 0:
    j = S[i + 1 :].find(p[1])
    if j >= 0:
      k = S[i + j + 2 :].find(p[2])
      if k >= 0:
        ans += 1
print(ans)
### BUGGY CODE ###

def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N, K = map(int, f_i.readline().split())
    A = sorted(map(int, f_i.readline().split()))
    
    num = [1] * (N - K + 1)
    for i, j in zip(range(K, N), range(1, N)):
        num[j] = num[j-1] * i // j
    
    ans = sum(a * n % mod for a, n in zip(A[K-1:], num))
    ans -= sum(a * n % mod for a, n in zip(A, num[::-1]))
    
    print(ans % mod)

solve()

### FIXED CODE ###

def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N, K = map(int, f_i.readline().split())
    A = sorted(map(int, f_i.readline().split()))
    
    comb = 1
    ans = A[K-1] - A[N-K]
    for i, j in zip(range(K, N), range(1, N)):
        comb = comb * i * pow(j, mod - 2, mod) % mod
        ans += (A[i] - A[N-i-1]) * comb
        ans %= mod
    
    print(ans)

solve()
### BUGGY CODE ###

N = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))

# 1 周目 : dp[巣から持ってきたドングリ数] = 取引所 B で持てる最大ドングリ数
dp = list(range(N + 1))
mas = tuple(zip(a, b))
for i in range(N + 1):
    for to_metal, to_acorn in mas:
        if i >= to_metal:
            dp[i] = max(dp[i], dp[i - to_metal] + to_acorn)
N = dp[N]

# 2 周目 : dp[取引所 B から持ってきたドングリ数] = 巣に持ち帰れる最大ドングリ数
dp = list(range(N + 1))
mas = tuple(zip(b, a))
for i in range(N + 1):
    for to_metal, to_acorn in mas:
        if i >= to_metal:
            dp[i] = max(dp[i], dp[i - to_metal] + to_acorn)
print(dp[N])


### FIXED CODE ###

N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())

# A : ドングリと金属に変える
# B : 全部ドングリに変える
# B : ドングリと金属に変える（無駄な操作でロスがないので、いったんドングリ化してよい）
# A : ドングリに変える

dp1 = list(range(N + 1))  # dp1[巣から持ってきたドングリ数] = 取引所 B で持てる最大ドングリ数
dp1[0] = 0
for i in range(N + 1):
    if i >= ga:
        dp1[i] = max(dp1[i], dp1[i - ga] + gb)
    if i >= sa:
        dp1[i] = max(dp1[i], dp1[i - sa] + sb)
    if i >= ba:
        dp1[i] = max(dp1[i], dp1[i - ba] + bb)

N = dp1[N]
dp2 = list(range(N + 1))  # dp2[取引所 B から持ってきたドングリ数] = 巣に持ち帰れる最大ドングリ数
for i in range(N + 1):
    if i >= gb:
        dp2[i] = max(dp2[i], dp2[i - gb] + ga)
    if i >= sb:
        dp2[i] = max(dp2[i], dp2[i - sb] + sa)
    if i >= bb:
        dp2[i] = max(dp2[i], dp2[i - bb] + ba)
print(dp2[N])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
    
def main():
    N = int(input())
    d = {}
    for _ in range(N-1):
        a, b = map(int, input().split())
        if a in d:
            d[a].append(b)
        else:
            d[a] = [b]
        if b in d:
            d[b].append(a)
        else:
            d[b] = [a]
    v = set()
    v.add(1)
    def dfs(n):
        if n == N:
            return True, [N]
        for i in d[n]:
            if i not in v:
                v.add(i)
                t, l = dfs(i)
                if t:
                    return True, l + [n]
        return False, n
    _, l = dfs(1)
    l.reverse()
    v = set()
    if len(l) % 2 == 0:
        half = len(l) // 2 - 1
    else:
        half = len(l) // 2
    v.add(l[half])
    s = l[half+1]
    v.add(s)
    def dfs2(n):
        r = 1
        for i in d[n]:
            if i not in v:
                v.add(i)
                r += dfs2(i)
        return r
    x = dfs2(s)
    if N - x > x:
        return 'Fennec'
    else:
        return 'Snuke'
print(main())


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
    
def main():
    N = int(input())
    d = {}
    for _ in range(N-1):
        a, b = map(int, input().split())
        if a in d:
            d[a].append(b)
        else:
            d[a] = [b]
        if b in d:
            d[b].append(a)
        else:
            d[b] = [a]
    v = set()
    v.add(1)
    l = []
    def dfs(n):
        if n == N:
            l.append(n)
            return True
        for i in d[n]:
            if i not in v:
                v.add(i)
                if dfs(i):
                    l.append(n)
                    return True
        return False
    dfs(1)
    l.reverse()
    v = set()
    if len(l) % 2 == 0:
        half = len(l) // 2 - 1
    else:
        half = len(l) // 2
    v.add(l[half])
    s = l[half+1]
    v.add(s)
    def dfs2(n):
        r = 1
        for i in d[n]:
            if i not in v:
                v.add(i)
                r += dfs2(i)
        return r
    x = dfs2(s)
    if N - x > x:
        return 'Fennec'
    else:
        return 'Snuke'
print(main())
### BUGGY CODE ###

#n:
#m:
#k:
n,m,k=map(int,input().split())
friend={}
block={}
result=[]
for i in range(1,n+1):
    friend[i]=set([])
    block[i]=set([])
    result.append(0)

for _ in range(m):
    a,b=map(int,input().split())
    friend[a].add(b)
    friend[b].add(a)

for _ in range(k):
    a,b=map(int,input().split())
    block[a].add(b)
    block[b].add(a)


checked=set([])
bfbf=[]
for i in range(1,n+1):
    #print(i,checked)
    if i not in checked:
        checked.add(i)
        group=set([i])
        bf=set([i])
        while len(group)!= 0:
            temp=group.pop()
            for item in friend[temp]:
                if item not in checked:
                    checked.add(item)
                    group.add(item)
                    bf.add(item)
        lenbf=len(bf)
        for item1 in bf:
            bl=0
            for item2 in bf:
                if item2 in block[item1]:
                    bl+=1
            result[item1-1]=lenbf-1-len(list(friend[item1]))-bl



        bfbf.append(bf)
result=list(map(str,result))
print(" ".join(result))







### FIXED CODE ###

#n:
#m:
#k:
n,m,k=map(int,input().split())
friend={}
block={}
result=[]
friendGroup=[]
for i in range(1,n+1):
    friend[i]=set([])
    block[i]=set([])
    result.append(0)
    friendGroup.append(0)

for _ in range(m):
    a,b=map(int,input().split())
    friend[a].add(b)
    friend[b].add(a)

checked=set([])
bfbf=[]
for i in range(1,n+1):
    #print(i,checked)
    if i not in checked:
        checked.add(i)
        group=set([i])
        bf=set([i])
        friendGroup[i-1]=i
        while len(group)!= 0:
            temp=group.pop()
            for item in friend[temp]:
                if item not in checked:
                    checked.add(item)
                    group.add(item)
                    bf.add(item)
                    friendGroup[item-1]=i
        lenbf=len(bf)
        for item1 in bf:
            result[item1-1]=lenbf-1-len(list(friend[item1]))

for _ in range(k):
    a,b=map(int,input().split())
    if friendGroup[a-1]!=0 and friendGroup[a-1]==friendGroup[b-1]:
        result[a-1]-=1
        result[b-1]-=1

result=list(map(str,result))
print(" ".join(result))
### BUGGY CODE ###

s = input()
q = int(input())
for _ in range(q):
    qr = list(map(str, input().split()))
    if qr[0] == '1':
        s = s[::-1]
    else:
        if qr[1] == '1': s = qr[2] + s
        else: s = s + qr[2]
print(s)

### FIXED CODE ###

s = input()
q = int(input())
a, b = "", ""
rev = False
for _ in range(q):
    qr = list(map(str, input().split()))
    if qr[0] == '1':
        rev = 1 - rev
    else:
        if qr[1] == '1':
            if rev: b += qr[2]
            else  : a += qr[2]
        else:
            if rev: a += qr[2]
            else  : b += qr[2]
if rev:
    print(b[::-1] + s[::-1] + a)
else:
    print(a[::-1] + s + b)
### BUGGY CODE ###

M=10**9+7
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(pow(2,i,M)*c*(n-c)%M for i,c in enumerate(b))%M)

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))
### BUGGY CODE ###

from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
S= np.zeros_like(T, dtype='bool')
d=0
c=deque()

for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue

        c=deque()    
        s=0
        c+=[i,j]
        
        t=len(c)//2
        while t>0:
                s+=1
                t=len(c)//2
                for k in range(t):
                        m = c.popleft()
                        n = c.popleft()
                        S[m][n]=s
                        if m != H-1:
                                if T[m+1][n]==0 and S[m+1][n]==0:c+=[m+1,n]
                        if m != 0:
                                if T[m-1][n]==0 and S[m-1][n]==0:c+=[m-1,n] 
                        if n != W-1:
                                if T[m][n+1]==0 and S[m][n+1]==0:c+=[m,n+1]
                        if n != 0:
                                if T[m][n-1]==0 and S[m][n-1]==0:c+=[m,n-1]
                        #c += (chk_route([c.popleft(),c.popleft()]))
                
        #print(T)
        d = max(d,s)
        S= np.zeros_like(T, dtype='bool')
        
print(d-2)

### FIXED CODE ###

from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)
#T=[]
S=np.zeros_like(T,dtype=int) 
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
#B=T.copy()    
d=0
c=deque()  
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue
 
          
        c.append((i,j))
        S[i][j] = 1
        #c.append(j)
        
        #t=len(c)
        while True:

                try:
                  m,n = c.popleft()
                except IndexError: break
                
                
                for kk in [(m+1,n),(m-1,n),(m,n+1),(m,n-1)]:
                  if not (0<=kk[0]<H and 0<= kk[1] <W): continue
                  if T[kk]==1:continue
                  if S[kk] == 0:
                    c.append(kk)
                    S[kk] = S[m][n]+1        
                        
 
        #print(T)
        d = max(d,np.max(S))
        S=np.zeros_like(T,dtype=int)
        
print(d-1)
### BUGGY CODE ###

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

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

### FIXED CODE ###

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

C = collections.Counter(A)
#print(C)

for i in range(N):
  #print(A.count(i+1))
  print(C[i+1])
### BUGGY CODE ###

from bisect import bisect_left
N = int(input())
X = list(map(int,input().split()))
subX = X[1:]
subX.sort()
for i in range(N-1):
    print(subX[N//2-1])
    k = bisect_left(subX,X[i])
    subX.insert(k,X[i])
    k = bisect_left(subX,X[i+1])
    subX.pop(k)
print(subX[N//2-1])


### FIXED CODE ###

from bisect import bisect_left
N = int(input())
X = list(map(int,input().split()))
Y = X.copy()
Y.sort()
for i in range(N):
    k = bisect_left(Y,X[i])
    if k < N//2:
        print(Y[N//2])
    else:
        print(Y[N//2-1])