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

A, B, Q = map(int, input().split())
s = []
t = []
x = []
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
for _ in range(Q):
    x.append(int(input()))
    
import sys
INT_MAX = sys.maxsize
s.insert(0, -1 * INT_MAX)
s.append(INT_MAX)
t.insert(0, -1 * INT_MAX)
t.append(INT_MAX)

for xi in x:
    #print(xi)
    si = 0
    for si, v in enumerate(s):
        if v > xi:
            break
    ti = 0
    for ti, v in enumerate(t):
        if v > xi:
            break
    #print(si, ti)
    sa = s[si]
    ta = t[ti]
    sb = s[si-1]
    tb = t[ti-1]
    #print(sa, sb,ta,tb)
    ans = min([
        abs(xi-sa)+abs(sa-ta),
        abs(xi-sa)+abs(sa-tb),
        abs(xi-sb)+abs(sb-ta),
        abs(xi-sb)+abs(sb-tb),
        abs(xi-ta)+abs(ta-sa),
        abs(xi-ta)+abs(ta-sb),
        abs(xi-tb)+abs(tb-sa),
        abs(xi-tb)+abs(tb-sb)
    ])
    print(ans)

### FIXED CODE ###

A, B, Q = map(int, input().split())
s = []
t = []
x = []
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
for _ in range(Q):
    x.append(int(input()))

import sys
INT_MAX = sys.maxsize
s.insert(0, -1 * INT_MAX)
s.append(INT_MAX)
t.insert(0, -1 * INT_MAX)
t.append(INT_MAX)

import bisect
for xi in x:
    #print(xi)
    si = bisect.bisect_right(s, xi)
    #si = 0
    #for si, v in enumerate(s):
    #    if v > xi:
    #        break
    ti = bisect.bisect_right(t, xi)
    #ti = 0
    #for ti, v in enumerate(t):
    #    if v > xi:
    #        break
    #print(si, ti)
    sa = s[si]
    ta = t[ti]
    sb = s[si-1]
    tb = t[ti-1]
    #print(sa, sb,ta,tb)
    ans = min([
        abs(xi-sa)+abs(sa-ta),
        abs(xi-sa)+abs(sa-tb),
        abs(xi-sb)+abs(sb-ta),
        abs(xi-sb)+abs(sb-tb),
        abs(xi-ta)+abs(ta-sa),
        abs(xi-ta)+abs(ta-sb),
        abs(xi-tb)+abs(tb-sa),
        abs(xi-tb)+abs(tb-sb)
    ])
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def multiplication2(n,a):
    acc = 1
    for x in a:
        acc = x*acc
    if 10**18 < acc:
        acc = -1

    return acc

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


### FIXED CODE ###

import sys
input = sys.stdin.readline
import functools

def multiplication2(n,a):
    #acc = functools.reduce(lambda x,y:x*y, a)
    acc = 1
    a_sorted = sorted(a)
    if a_sorted[0] == 0:
        return 0
    
    for s in a_sorted:

        acc = acc*s
        if 10**18 < acc:
            acc = -1
            break
    return acc

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(multiplication2(n,a))
### BUGGY CODE ###

n, m = map(int, input().split())
cnt = [0]*(n+1)
for i in range(m):
  l, r = map(int, input().split())
  for j in range(l, r+1):
    cnt[j] += 1
print(cnt.count(m))    


### FIXED CODE ###

n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
  l[i], r[i] = map(int, input().split())
print(max(min(r) - max(l) + 1, 0))
### BUGGY CODE ###

def main():
    k, s = map(int, input().split())

    res = 0

    for x in range(k+1):
        for y in range(k+1):
            for z in range(k+1):
                if x + y + z == s:
                    res += 1
    
    print(res)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    k, s = map(int, input().split())

    res = 0

    for x in range(k+1):
        for y in range(k+1):
            z = s - (x + y)
            if z <= k and z >= 0:
                res += 1
        
    print(res)

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

import sys
input = sys.stdin.readline

def main():
    n,k = map(int, input().split())
    A = list(map(int, input().split()))
    
    scores= []
    score = 1
    for a in A[:k]:
        score*=a
    scores.append(score)
    
    for i in range(k,n):
        score = score//A[i-k] * A[i]
        scores.append(score)
    
    for i in range(n-k):
        if scores[i] < scores[i+1]:
            print("Yes")
        else:
            print("No")
main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n,k = map(int, input().split())
    A = list(map(int, input().split()))
    
    for i in range(k,n):
        if A[i] > A[i-k]:
            print('Yes')
        else:
            print('No')
main()
### BUGGY CODE ###

import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            # print(a, b)
            c_right = bleft(L, a+b)
            # print(c_right)
            if c_right == 0:
                continue
            now_seq = L[j+1:c_right]
            c_left = bright(now_seq, b-a)
            if c_left == N:
                continue
            ans += len(now_seq) - c_left
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            c_right = bleft(L[j+1:], a+b)
            ans += c_right
    print(ans)

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

N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
ans = 0
for i in range(N):
  for j in range(N):
    if A[i] < B[j]:
      for k in range(N):
        if B[j] < C[k]:
          ans = ans+1

print(ans)

### FIXED CODE ###

from bisect import bisect_right
from bisect import bisect_left

N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
ans = 0
for b in B:
  ans += (bisect_left(A, b) * (N-bisect_right(C, b)))

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

n, q = [int(i) for i in input().split()]
s = input()
for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(s[(l-1):r].count('AC'))


### FIXED CODE ###

import bisect

n, q = [int(i) for i in input().split()]
s = input()
positions = []

for i in range(1, n+1):
    if s[(i-1):(i+1)] == 'AC':
        positions.append(i)

for i in range(q):
    l, r = [int(i) for i in input().split()]
    l_index = bisect.bisect_left(positions, l)
    r_index = bisect.bisect_left(positions, r)
    print(r_index - l_index)
### BUGGY CODE ###

N = int(raw_input())
A = list(map(int,raw_input().split()))
MOD = 10**9 + 7
def calc(a):
	if 0 in a:
		if a.count(0) != 1:
			return 0
		a.remove(0)
		b = [a.count(i*2) for i in range(1,int(N/2) + 1)]
		if b.count(2) != int(N/2):
			return 0
	else:
		b = [a.count(i*2-1) for i in range(1,int(N/2) + 1)]
		if b.count(2) != int(N/2):
			return 0

	return 2 ** int(N/2)

print(calc(A) % MOD)

### FIXED CODE ###

N = int(raw_input())
A = list(map(int,raw_input().split()))
A.sort()
MOD = 10**9 + 7
def calc(a):
	if N % 2 == 0:
		B = [int(i/2)*2 + 1 for i in range(0,N)]
		if A != B:
			return 0
	else:
		B = [int(i/2)*2 for i in range(1,N+1)]
		if A != B:
			return 0
	return 2 ** int(N/2)

print(calc(A) % MOD)
### BUGGY CODE ###

n,x,y = map(int, input().split())
dp = [[100000000 for j in range(n)] for i in range(n)]
re = [0]*n
for i in range(n):
  for j in range(n):
    if i==j:
      dp[i][j] = 0
    if abs(i-j)==1:
      dp[i][j] = 1
    if i==x-1 and j==y-1:
      dp[i][j] = 1
    if i==y-1 and j==x-1:
      dp[i][j] = 1
    

for k in range(n):
  for i in range(n):
    for j in range(n):
      dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);


for i in range(n):
  for j in range(i):
    re[dp[i][j]] +=1
    
for i in range(n-1):
  print(re[i+1])

### FIXED CODE ###

n,x,y = map(int, input().split())
p = [[100000000 for j in range(n)] for i in range(n)]
dp = [(-1,0),(1,0),(0,-1),(0,1)]
c = [[] for i in range(n)]

for i in range(n):
  for j in range(n-i):
    j += i
    if i==j:
      p[i][j] = 0
    if abs(i-j)==1:
      p[i][j] = 1
      c[1].append((i,j))
    if i==x-1 and j==y-1:
      p[i][j] = 1
      c[1].append((i,j))
    if i==y-1 and j==x-1:
      p[i][j] = 1
      c[1].append((i,j))
    
print(len(c[1]))

for i in range(n-2):
  i += 2
  for (a,b) in c[i-1]:
    for (da,db) in dp:
      aa = a + da
      bb = b + db
      if not (0 <= aa < n and 0 <= bb < n):
        continue
      if p[aa][bb] > i:
        p[aa][bb] = i
        c[i].append((aa,bb))
  print(len(c[i]))
### BUGGY CODE ###

import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort()
b = copy.deepcopy(a)

maps = {}

for aa in a:
    if aa in maps:
        tmp = maps[aa]
        maps[aa] = tmp+1
    else:
        maps[aa] = 1

i = 0
while True:
    a_tmp = a[i]
    check = set()
    for j in range(i+1, len(b)):
        if b[j]==a_tmp:
            check.add(i)
        if b[j]%a_tmp==0:
            check.add(j)

    check = list(check)
    check.sort(reverse=True)
    for c in check:
        del b[c]
    
    a = copy.deepcopy(b)
    i += 1
    if i>=len(a):
        break



print(len(a))





### FIXED CODE ###

import sys
import copy
from collections import deque
stdin = sys.stdin
 
mod = 10**9+7
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n = ni()
a = na()
a.sort()
a_max = max(a)

c = [0 for _ in range(1000005)]
for aa in a:
    c[aa] += 1

dp = [False for _ in range(1000005)]
cnt = 0
for ai in set(a):
    if dp[ai]:
        continue
    if c[ai]==1:
        cnt += 1
    for j in range(ai+ai, a_max+1, ai):
        dp[j] = True

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

#!/usr/bin/env python
# coding: utf-8

# In[20]:


N, K, Q = map(int, input().split())

A = []
for i in range(Q):
    Ai = int(input())
    A.append(Ai)


# In[21]:


for i in range(1, N+1):
    cnt = A.count(i)
    point = K - (Q - cnt)
    #print(cnt, point)
    if point > 0:
        print("Yes")
    else:
        print("No")


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[14]:


N,K,Q = map(int, input().split())
point = [0]*N
for _ in range(Q):
    A = int(input())
    point[A-1] += 1 
ans = [print("Yes") if point[i] > Q-K else print("No") for i in range(len(point))]


# In[ ]:
### BUGGY CODE ###

# 出現した数のフラグを立てればよいだけでは
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = Counter(A)
happend = set()
A.sort()
ans = 0

for i in range(N):
    if count[A[i]] >= 2:
        ans += 1
        happend.add(A[i])
        continue
    for j in range(1, int(A[i]**(1/2))+2):
        if A[i] % j == 0:
            if j in happend or A[i]//j in happend:
                ans += 1
                break
    happend.add(A[i])
print(N-ans)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
A.sort()
ans = 0
max_A = max(A)
dp = [True]*(max_A+1)  # 0~max(A)の数についてのリスト
happend = set()
for a in A:
    if C[a] >= 2:
        if a in happend:
            continue
        else:
            # aが存在したという証拠だけは残しておく
            x = a * 2
            while x <= max_A:
                dp[x] = False
                x += a
            happend.add(a)
    else:
        if dp[a]:
            ans += 1
        x = a * 2
        while x <= max_A:
            dp[x] = False
            x += a
print(ans)
### BUGGY CODE ###

import copy
n = int(input())
xl = []
for i in range(n):
    xl.append([int(i) for i in input().split()])
    xl[i].append(xl[i][0] - xl[i][1])
    xl[i].append(xl[i][0] + xl[i][1])
xl.sort(key=lambda x: x[3])
ng = []
ans = 0
for i in range(n):
    tmp = list(range(xl[i][2] + 1, xl[i][3]))
    a = copy.deepcopy(tmp) #動く範囲
    a.extend(ng)
    if len(set(a)) == len(a):
        ng.extend(tmp)
        ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
robot = []
for i in range(n):
    x, l = map(int,input().split())
    robot.append([x + l, x - l]) #left, right
robot.sort()
preright = robot[0][1]
ans = 0
for i in range(n):
    left = robot[i][1]
    #print(preright, left)
    if preright <= left:
        ans += 1
        preright = robot[i][0]
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
s = set(a)
r = []
for i in s:
	r.append(a.count(i))
r = sorted(r)
dif = len(s) - k
print(sum(r[0:max(0,dif)]))

### FIXED CODE ###

import itertools
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
c = []
g = itertools.groupby(a)
for m,v in g:
    c.append(len(list(v)))
c = sorted(c)
print(sum(c[:-k]))
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
for i in range(1, n+1):
    ans = 0
    for x in range(1, 50):
        for y in range(1, 50):
            for z in range(1, 50):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    ans += 1
    print(ans)

### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = [0]*(n+1)
for x in range(1, 10**2+1):
    for y in range(1, 10**2+1):
        for z in range(1, 10**2+1):
            if 1 <= x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
                lst[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1
for i in range(1, n+1):
    print(lst[i])
### BUGGY CODE ###

from itertools import combinations
n=int(input())
L=map(int,input().split())
ans=0
for a, b, c in combinations(L,3):
    if abs(b-c) < a < b+c:
        ans += 1
print(ans)

### FIXED CODE ###

import bisect
n = int(input())
L = sorted(map(int,input().split()))
ans = 0
# a<b<cとしてa,bを決めると c < b+aだけ確かめれば良い!
for i in range(n-1):
    for j in range(i+1,n):
        # bisectで初めてa+b以上になる元のindexを見つける
        # j番以降の元であればc>bを満たす.
        ans += bisect.bisect_left(L, L[i]+L[j]) - j - 1
print(ans)
### BUGGY CODE ###

def main():
    S = input()
    K = int(input())
    ans = ""
    for i, s in enumerate(S):
        tmp = ord(s) - ord('a')
        if i == len(S) - 1:
            ans += chr((tmp + K) % 26 + ord('a'))
        elif s == 'a':
            ans += s
        elif 26 - tmp <= K:
            ans += 'a'
            K -= 26 - tmp
        else:
            ans += s

    print(ans)
            


if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    S = input()
    K = int(input())
    ans = ""
    for i, s in enumerate(S):
        tmp = ord(s) - ord('a')
        if i == len(S) - 1:
            ans += chr((tmp + K) % 26 + ord('a'))
        elif s == 'a':
            ans += s
        elif 26 - tmp <= K:
            ans += 'a'
            K -= 26 - tmp
        else:
            ans += s

    print(ans)
            


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

n,k = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
ans = float("INF")

for i in range(n-k+1):
    for j in range(i+1,n):
        for s in range(n):
            for m in range(n):
                wl = l[i][0]
                wh = l[j][0]
                hl = min(l[s][1],l[m][1])
                hh = max(l[s][1],l[m][1])
                count = 0
                for w,h in l:
                    if wl <= w <= wh and hl <= h <= hh:
                        count += 1
                if count >= k:
                    ans = min(ans,(hh-hl)*(wh-wl))
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
l1 = sorted(l,key=lambda x:x[1])
ans = float("INF")

for i in l:
    for j in l:
        if i[0] >= j[0]:
            continue
        for s in l1:
            count = 0
            for w,h in l1:
                if i[0] <= w <= j[0] and s[1] <= h:
                    count += 1
                if count==k:
                    ans = (min(ans,(j[0]-i[0])*(h-s[1])))
                    break
                
print(ans)
### BUGGY CODE ###

import sys
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readints():return list(map(int,readline().split()))

from collections import deque

h,w = readints()

start = readints()
start = (start[0]-1)*w + start[1]-1

goal = readints()
goal = (goal[0]-1)*w + goal[1]-1

maze = [readstr() for i in range(h)]

dist = [10**10]*(h*w)

dq = deque()
dq.append(start)
dist[start] = 0

while dq:
    p = dq.popleft()
    if dist[goal] <= dist[p]:
        break
    y = p//w
    x = p%w
    for dy in range(-2,3):
        for dx in range(-2,3):
            if 0<=y+dy<h and 0<=x+dx<w and maze[y+dy][x+dx]=='.':
                q = (y+dy)*w + x+dx
                if abs(dy)+abs(dx)==1:
                    if dist[q]>dist[p]:
                        dq.appendleft(q)
                        dist[q] = dist[p]
                else:
                    if dist[q]>dist[p]+1:
                        dq.append(q)
                        dist[q] = dist[p] + 1


print(-1 if dist[goal]==10**10 else dist[goal])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import heapq
def dijkstra(s,path):
    # 距離をinfで初期化
    d = [float('inf')]*len(path)
    d[s] = 0

    # sへの距離は0
    q = [(0,s)]
    heapq.heapify(q)

    # 距離が最小の頂点から更新していけば良い
    while q:
        c,p = heapq.heappop(q)

        # 頂点pまでの距離がheap内のpまでの距離より小さい場合、continue
        if d[p]<c:
            continue

        # 頂点pから伸びる、全ての辺の距離を確認
        for to,cost in path[p]:
            # 頂点pから行ける頂点の距離がpまでの距離とpからの距離の和より小さい場合 -> 距離を更新し、heapに追加
            if d[to] > d[p] + cost:
                d[to] = d[p] + cost
                heapq.heappush(q,(d[to], to))
    return d

h,w = readints()

start = readints()
start = (start[0]-1)*w + start[1]-1

goal = readints()
goal = (goal[0]-1)*w + goal[1]-1

maze = [readstr() for i in range(h)]

path = [[] for i in range(h*w)]
for i in range(h*w):
    y = i//w
    x = i%w
    if maze[y][x]=='#':
        continue
    for dy in range(-2,3):
        for dx in range(-2,3):
            if dy==dx==0:
                continue
            if 0<=y+dy<h and 0<=x+dx<w and maze[y+dy][x+dx]=='.':
                j = (y+dy)*w + x+dx
                if (dy==0 and abs(dx)==1) or (abs(dy)==1 and dx==0):
                    path[i].append((j,0))
                else:
                    path[i].append((j,1))

d = dijkstra(start,path)
print(-1 if d[goal]==float('inf') else d[goal])
### BUGGY CODE ###

def main():
    n = int(input())
    s = input()
    res = 0
    r = []
    g = []
    b = []
    for i, c in enumerate(s):
        if c == 'R':
            r.append(i)
        elif c == 'G':
            g.append(i)
        else:
            b.append(i)
    
    cnt = 0
    for i in r:
        for j in g:
            for k in b:
                if abs(j-i) != abs(k-j) and abs(j-i) != abs(k-i) and abs(k-j) != abs(k-i):
                    cnt += 1
    print(cnt)
                    


if __name__ == '__main__':
    main()



### FIXED CODE ###

from itertools import permutations

def main():
    n = int(input())
    s = input()
    res = 0
    r = 0
    g = 0
    b = 0
    for i, c in enumerate(s):
        if c == 'R':
            r += 1
        elif c == 'G':
            g += 1
        else:
            b += 1
    
    rgb = []
    for t in permutations('RGB'):
        rgb.append(''.join(t))

    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j - i 
            if k >= n:
                break
            if (s[i] + s[j] + s[k]) in rgb:
                cnt += 1
    print(r*g*b - cnt)


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

from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw, gh, gw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    while stack:
        h, w = stack.popleft()
        # ゴールの条件
        if h == gh and w == gw:
            break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
                new_w < 0 or new_w >= W:
                   continue
            elif maze[new_h][new_w] != "#" and \
                visited[new_h][new_w] == -1:
                    visited[new_h][new_w] = visited[h][w] + 1
                    stack.append([new_h, new_w])
    
    return visited[gh][gw]

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    vd = [[[[0 for _ in range(W)] for _ in range(H)] for _ in range(W)] for _ in range(H)]
    ans = 0
    for sh in range(H):
        for sw in range(W):
            for gh in range(H):
                for gw in range(W):
                    if maze[sh][sw] != "#" and maze[gh][gw] != "#" and vd[sh][sw][gh][gw] == 0 and vd[gh][gw][sh][sw] == 0 and not (gh == sh and gw == sw):
                        vd[sh][sw][gh][gw] = 1
                        vd[gh][gw][sh][sw] = 1
                        visited = [[-1] * W for _ in range(H)]
                        step_cnt = bfs(maze, visited, sh, sw, gh, gw)
                        ans = max(ans, step_cnt)

    print(ans - 1)


### FIXED CODE ###

from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    longest = 0
    while stack:
        h, w = stack.popleft()
        # # ゴールの条件
        # if h == gh and w == gw:
        #     break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
                new_w < 0 or new_w >= W:
                    continue
            elif maze[new_h][new_w] != "#" and \
                visited[new_h][new_w] == -1:
                    visited[new_h][new_w] = visited[h][w] + 1
                    longest = max(longest, visited[new_h][new_w])
                    stack.append([new_h, new_w])
    
    # return visited[gh][gw]
    return longest

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    vd = [[[[0 for _ in range(W)] for _ in range(H)] for _ in range(W)] for _ in range(H)]
    ans = 0
    for sh in range(H):
        for sw in range(W):
            if maze[sh][sw] != "#": 
                visited = [[-1] * W for _ in range(H)]
                step_cnt = bfs(maze, visited, sh, sw)
                ans = max(ans, step_cnt)
    print(ans - 1)