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

import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, input().split())

#S = [[0 if x == '.' else 1 for x in list(input())] for _ in range(H)]
S = [list(input()) for _ in range(H)]
NUM = [[[None] * 2 for _ in range(W)] for _ in range(H)]


def cntDot(r, c, vertical, cnt):
    #print("Input", r, c, vertical, cnt)
    if S[r][c] == '#':
        NUM[r][c][vertical] = 0
        return cnt
    else:
        cnt += 1

    # x軸
    if vertical == 0:
        if c < W - 1:
            t = cntDot(r, c + 1, vertical, cnt)
            NUM[r][c][vertical] = t
            return t
        else:
            NUM[r][c][vertical] = cnt
            return cnt

    # y軸
    if vertical == 1:
        if r < H - 1:
            t = cntDot(r + 1, c, vertical, cnt)
            NUM[r][c][vertical] = t
            return t
        else:
            NUM[r][c][vertical] = cnt
            return cnt

    return 0


for r in range(H):
    for c in range(W):
        if S[r][c] == 1:
            NUM[r][c] = [0, 0]
            continue
        # x軸
        if NUM[r][c][0] == None:
            NUM[r][c][0] = cntDot(r, c, 0, 0)
        # y軸
        if NUM[r][c][1] == None:
            NUM[r][c][1] = cntDot(r, c, 1, 0)

# print(NUM)

ans = 1
for r in range(H):
    v = max(NUM[r])
    ans = max(ans, sum(v)-1)

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# TLE
# O(HW(H+W)) で10^8になるので無理

H, W = map(int, input().split())

S = [input() for _ in range(H)]
NUM = [[0] * (W) for _ in range(H)]

for r in range(H):
    cnt = 0
    for c in range(W):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for c in range(W - 1, -1, -1):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

for c in range(W):
    cnt = 0
    for r in range(H):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for r in range(H - 1, -1, -1):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

ans = 4
for i in range(H):
    t = max(NUM[i])
    ans = max(ans, t)

print(ans-3)
### BUGGY CODE ###

L, R = map(int, input().split())
a = 2020
for i in range(L,R+1):
    for j in range(i+1,R+1):
        ans = i*j%2019
        if(a > ans):
            a = ans
print(a)


### FIXED CODE ###

L, R = map(int, input().split())
a = 2020

if(R-L > 2019):
    R = L+2019
for i in range(L,R+1):
    for j in range(i+1,R+1):
        ans = i*j%2019
        if(a > ans):
            a = ans
print(a)
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
p=0
ppl = [a[0]]*2
best_index = 1
best_point = a[0]
for i in a[1:]:
    p += best_point
    ppl = ppl[:best_index]+[i]+ppl[best_index:]
    #print(ppl)
    point_list = [min(ppl[i],ppl[i+1]) for i in range(0,len(ppl)-1)]
    #print(point_list)
    best_point = max(point_list)
    for j,q  in enumerate(point_list):
        if q == best_point:
            best_index = j+1
            continue
            
print(p)

### FIXED CODE ###

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

a.sort(reverse = True)
p = a[0]
for i in range(N-2): #-1は上記a[0]分、もう-1は最初の要素挿入は加点されないため。
    p += a[(i//2)+1]

print(p)
### BUGGY CODE ###

import sys
from collections import deque
from copy import deepcopy

input=sys.stdin.readline
N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[set() for _ in range(N)]
d=[set() for _ in range(N)] # 隣接リスト
e=[-1 for _ in range(N)] #訪問ずみかどうか
di=dict()

for i in range(N-1):
    a[i],b[i] = map(int,input().split())
    d[a[i]-1].add(b[i]-1)
    d[b[i]-1].add(a[i]-1)

v=deque([0])
e[0]=0

maxi=0
while len(v)>0:
  k=v.popleft()
  maxi=max(maxi,len(d[k]))
  all=set(i+1 for i in range(len(d[k])))
  pos=deepcopy(all)
  pos -= c[k]
  for item in d[k]:
    if e[item]==-1:
      s=min(pos)
      c[k].add(s)
      c[item].add(s)
      pos.remove(s)
      e[item] = e[k]+1
      v.append(item)
      st=str(k)+","+str(item)
      di[st] = s
      
print(maxi)
for i in range(N-1):
  t_str = str(a[i]-1)+","+str(b[i]-1)
  print(di[t_str])

### FIXED CODE ###

from collections import deque

N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[set() for _ in range(N)] # 使用している色
d=[set() for _ in range(N)] # 隣接リスト
e=[ False for _ in range(N)] #訪問ずみかどうか
f=[0]*N  #答え
for i in range(N-1):
    a[i],b[i] = map(int,input().split())
    d[a[i]-1].add(b[i]-1)
    d[b[i]-1].add(a[i]-1)

maxi=max([len(d[i]) for i in range(N-1)])
print(maxi)
#print("c:",c)
#print("d",d)
#print("e",e)

#x=0としてBFSする

v=deque([0])
e[0]=True
color=1

while v:
  p = v.popleft()
  for q in d[p]:
    if e[q]==False:
      while color in c[p]:
        color +=1
        if color>maxi:
          color=1
      c[p].add(color)
      c[q].add(color)
      f[q]=color
      e[q]=True
      v.append(q)
      
for i in range(N-1):
  print( f[b[i]-1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
connect = [set() for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

ans = [0] * n

def dfs(count, v, parent):
    count += counter[v]
    ans[v] = count
    for child in connect[v]:
        if child != parent:
            dfs(count, child, v)

dfs(0, 0, -1)

print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

n, q = map(int, input().split())

connect = [set() for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

ans = [0] * n
def dfs(me, parent, cum):
    cum += counter[me]
    ans[me] = cum
    for child in connect[me]:
        if child != parent:
            dfs(child, me, cum)

dfs(0, -1, 0)

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

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

import fractions
from functools import reduce

def gcds(numbers):
  return reduce(fractions.gcd,numbers)

nm = 0

for i in range(n):
  t = gcds(lis[:i]+lis[i+1:])
  if nm < t:
    nm = t
print(nm)

### FIXED CODE ###

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

import fractions
from functools import reduce

def gcds(numbers):
  return reduce(fractions.gcd,numbers)
def gcd2(*numbers):
  return reduce(fractions.gcd,numbers)
  

mx = 0

lisgcd = [0]*n
rlisgcd = [0]*n

lisgcd[0] = lis[0]
rlisgcd[n-1] = lis[n-1]

for i in range(n-1):
  lisgcd[i+1] = gcd2(lisgcd[i],lis[i])
  
for i in range(n-2,-1,-1):
  rlisgcd[i] = gcd2(rlisgcd[i+1],lis[i])
  
for i in range(n):
  if i == 0:
    if mx < rlisgcd[1]:
      mx = rlisgcd[1]
  elif i == n-1:
    if mx < lisgcd[n-1]:
      mx = lisgcd[n-1]
  else:
    t = gcd2(lisgcd[i],rlisgcd[i+1])
    if mx < t:
      mx = t
print(mx)
### BUGGY CODE ###

def make_list(length, repeat):
    result = [[] for _ in range(length)]
    for _ in range(repeat):
        a, b = map(lambda x: int(x) - 1, input().split())
        result[a].append(b)
        result[b].append(a)
    return result


def main():
    n, m, k = map(int, input().split())
    friend = make_list(n, m)
    block = make_list(n, k)
    group_id = 1
    group = [0 for _ in range(n)]

    def dfs(start, group_id):
        q = [start]
        if group[start] == 0:
            while q:
                now = q.pop()
                group[now] = group_id
                for nn in friend[now]:
                    if group[nn] == 0:
                        group[nn] = group_id
                        q.append(nn)
            group_id += 1
        return group_id

    for i in range(n):
        group_id = dfs(i, group_id)

    members = [[] for _ in range(group_id)]
    for i in range(n):
        members[group[i]].append(i)

    answer = [0 for _ in range(n)]
    for i in range(n):
        answer[i] = len(members[group[i]]) - len(friend[i]) - len(set(members[group[i]]) & set(block[i])) - 1
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



### FIXED CODE ###

def make_list(length, loop):
    result = [[] for _ in range(length)]
    for _ in range(loop):
        a, b = map(lambda x: int(x) - 1, input().split())
        result[a].append(b)
        result[b].append(a)
    return result


def main():
    # 敢えてDFSで解いてみる．
    n, m, k = map(int, input().split())
    friend = make_list(n, m)
    brock = make_list(n, k)
    answer = [0] * n
    group_index = [0] * n
    group_id = 1

    def dfs(index):
        q = [index]
        group_index[index] = group_id
        connection = 1
        while not q == []:
            now = q.pop()
            for f in friend[now]:
                if group_index[f] == 0:
                    connection += 1
                    group_index[f] = group_id
                    q.append(f)
        return connection

    id_and_elements = {}
    for i in range(n):
        if group_index[i] == 0:
            id_and_elements[group_id] = dfs(i)
            group_id += 1

    for i in range(n):
        answer[i] += id_and_elements[group_index[i]] - 1
        answer[i] -= len(friend[i])
        for b in brock[i]:
            if group_index[b] == group_index[i]:
                answer[i] -= 1
    print(" ".join(map(str, answer)))


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

import numpy as np

def dp(v, d, c):
    if memo[v-1][d] is not None:
        return

    memo[v-1][d] = True
    if d == 0:
        res[v-1] = str(c)
        return None

    dp(v, d-1, c)
    for e in dic[v-1]:
        dp(e, d-1, c)


N, M = tuple(map(int, input().split(' ')))

dic = [[] for _ in range(N)]
memo = [[None]*11 for _ in range(N)]

for m in range(M):
    a, b = tuple(map(int, input().split(' ')))
    dic[a-1].append(b)
    dic[b-1].append(a)

Q = int(input())

vdc = [None]*Q

for q in range(Q):
    vdc[q] = tuple(map(int, input().split(' ')))

res = ['0']*N

[dp(v, d, c) for v, d, c in vdc[::-1]]


print('\n'.join(res))


### FIXED CODE ###

import numpy as np

def dp(v, d, c):
    if memo[v-1][d]:
        return

    memo[v-1][d] = True
    if d == 0:
        res[v-1] = str(c)
        return

    dp(v, d-1, c)
    for e in dic[v-1]:
        dp(e, d-1, c)


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

dic = [[] for _ in range(N)]
memo = [[False]*11 for _ in range(N)]

for m in range(M):
    a, b = [int(e) for e in input().split(' ')]
    dic[a-1].append(b)
    dic[b-1].append(a)

Q = int(input())


vdc = [[int(e) for e in input().split(' ')] for _ in range(Q)]

res = ['0']*N

[dp(v, d, c) for v, d, c in vdc[::-1]]


print('\n'.join(res))
### BUGGY CODE ###

import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=[]
for i in range(29):
  T=2**i
  B_=list(B)
  A_=list(A)
  t=0
  for j in range(N):
    B_[j]%=2*T
    A_[j]%=2*T
  B_.sort()
  for j in range(N):
    a=A_[j]
    p=bisect.bisect_left(B_,T-a)
    q=bisect.bisect_left(B_,2*T-a)
    r=bisect.bisect_left(B_,3*T-a)
    s=bisect.bisect_left(B_,4*T-a)
    t+=(q-p)+(s-r)
  ans.append(t%2)
a=0
for i in range(29):
  a+=2**i*ans[i]
print(a)


### FIXED CODE ###

def main():
  N=int(input())
  A=list(map(int,input().split()))
  B=list(map(int,input().split()))
  ans=[]
  for i in range(29):
    T=2**i
    B_=list(B)
    A_=list(A)
    t=0
    for j in range(N):
      B_[j]%=2*T
      A_[j]%=2*T
    A_.sort()
    B_.sort()
    p=q=r=0
    for a in A_[::-1]:
      while p<N and a+B_[p]<T:
        p+=1
      while q<N and a+B_[q]<2*T:
        q+=1
      while r<N and a+B_[r]<3*T:
        r+=1
      t+=(q-p)+(N-r)
    ans.append(t%2)
  a=0
  for i in range(29):
    a+=2**i*ans[i]
  print(a)
if __name__=='__main__':
  main()
### BUGGY CODE ###

S=input()

N=len(S)

M=[1 if s=='R' else -1 for s in S]

def move(C):
    D=[0] * N
    for i in range(N):
        D[i+M[i]] += C[i]
    return D


c=[1] * N
even_c = [0] * N

i=0
while True:
    d = move(c)
    if i%2 == 0:
        if c == even_c:
            break
        even_c = c
    c = d
    i+=1

for c in even_c:
    print(str(c)+' ',end='')
print()

### FIXED CODE ###

S=input()

N=len(S)
RLs=[]
Rs=[]
Ls=[]

rlen=0
llen=0
for i in range(N):

    if S[i]=='R':
        rlen+=1
        if S[i:i+2] == 'RL':
            RLs.append(i)
            Rs.append(rlen)
            rlen=0
    elif S[i]=='L':
        llen+=1
        if i==N-1 or S[i:i+2] == 'LR':
            Ls.append(llen)
            llen=0

ans = [0]*N
for i,rlpos in enumerate(RLs):
    rr=-(-Rs[i]//2)
    rl=Rs[i]//2

    lr=Ls[i]//2
    ll=-(-Ls[i]//2)

    ans[rlpos]+=rr+lr
    ans[rlpos+1]+=rl+ll

for a in ans:
    print(str(a)+' ',end='')
print()
### BUGGY CODE ###

import numpy as np
if __name__ == "__main__":
    K, S = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        for j in range(K+1):
            for k in range(K+1):
                if i+j+k == S:
                    ans += 1
    print(ans)

### FIXED CODE ###

import numpy as np
if __name__ == "__main__":
    K, S = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        for j in range(i, K+1):
            k = S - (i+j)
            if j <= k and k <= K:
                l = len(set([i,j,k]))
                if l == 3:
                    ans += 6
                elif l == 2:
                    ans += 3
                else:
                    ans += 1
    print(ans)
### BUGGY CODE ###

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

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


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Ansbox = [0]*(N+1)

def count(N,A,Ansbox):

    for i in range(N- 1):
        Ansbox[A[i] - 1] += 1
        
    for i in range(N):
        print(Ansbox[i])
        
count(N,A,Ansbox)
### BUGGY CODE ###

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

for i in range(n-k):
    cntp=1
    cnt=1
    for j in range(k+1):
        if j!=k:
            cntp*=a[i+j]
        if j!=0:
            cnt*=a[i+j]
#        print(cnt,cntp)
    if cnt>cntp:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

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')
### BUGGY CODE ###

import itertools

n, m = map(int, input().split())
P = [input().split() for i in range(m)]
P = list(itertools.chain.from_iterable(P))
ac_list = list(range(n + 1))
wa_list = [0] * n

counta = 0
countb = 0
for i in range(1, m * 2, 2):
    if P[i] == "AC" and int(P[i - 1]) in ac_list:
        counta += 1
        ac_list.remove(int(P[i - 1]))
        countb += wa_list[int(P[i - 1]) - 1]
    elif P[i] == "WA":
        wa_list[int(P[i - 1]) - 1] += 1
    else:
        continue

print(counta, countb)

### FIXED CODE ###

import itertools
n, m = map(int, input().split())
P = [input().split() for i in range(m)]
P = list(itertools.chain.from_iterable(P))
ac_list = [0] * n
wa_list = [0] * n
counta = 0
countb = 0
for i in range(1, m * 2, 2):
    if P[i] == "AC" and ac_list[int(P[i - 1])-1] == 0:
        counta += 1
        ac_list[int(P[i - 1])-1] = 1
        countb += wa_list[int(P[i - 1]) - 1]
    elif P[i] == "WA":
        wa_list[int(P[i - 1]) - 1] += 1
    else:
        continue

print(counta, countb)
### BUGGY CODE ###

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

temp = arr.index(1)
ans = 1

while(temp!=0):
    val = arr[:temp].index(min(arr[:temp]))
    ans += 1
    temp = val
print(ans)


### FIXED CODE ###

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

ind = [0]*(n+1)
for i in range(n):
    ind[arr[i]] = i
temp = 100000000
ans = 0
for i in range(1,n+1):
    if ind[i]<temp:
        ans+=1
        temp = ind[i]
print(ans)
### BUGGY CODE ###

H,W,D=map(int,input().split())
d=[[0,0] for i in range(H*W+1)]
d2=[0 for i in range(H*W+1)]
for j in range(H):
  a=[int(x) for x in input().split()]
  for k in range(W):
    d[a[k]]=[j+1,k+1]
for l in range(1,H*W+1-D):
  d2[l]=abs(d[l][0]-d[l+D][0])+abs(d[l][1]-d[l+D][1])
Q=int(input())
for i in range(Q):
  a,b=map(int,input().split())
  if a==b:
    print(0)
  else:
    cnt=int((b-a)/D)
    ans=0
    for j in range(cnt):
      ans+=d2[a+(j*D)]
    print(ans)

### FIXED CODE ###

H,W,D=map(int,input().split())
d=[[0,0] for i in range(H*W+1)]
d2=[0 for i in range(H*W+1)]
for j in range(H):
  a=[int(x) for x in input().split()]
  for k in range(W):
    d[a[k]]=[j+1,k+1]
for l in range(D+1,H*W+1):
  d2[l]=abs(d[l][0]-d[l-D][0])+abs(d[l][1]-d[l-D][1])
for m in range(D+1,H*W+1):
  d2[m]+=d2[m-D]
Q=int(input())
for i in range(Q):
  a,b=map(int,input().split())
  if a==b:
    print(0)
  else:
    ans=d2[b]-d2[a]
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
n, q = map(int, input().split())
c = list(map(lambda x:int(x)-1, input().split()))
query = []
for i in range(q):
    l, r = map(int, input().split())
    query.append((i, l-1, r-1))

class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.bit = [0]*n
    
    def add(self, i, w):
        x = i+1
        while x<=self.n:
            self.bit[x-1] += w
            x += x & -x
    
    def sum(self, i):
        ret = 0
        x = i+1
        while x>0:
            ret += self.bit[x-1]
            x -= x & -x
        return ret

bit = BinaryIndexedTree(n+1)
query.sort(key=lambda x:x[2])
last = [None]*n
ans = [None]*q
nr = -1
for idx, l, r in query:
    for cr in range(nr+1, r+1):
        if last[c[cr]] is not None:
            bit.add(last[c[cr]]+1, -1)
        last[c[cr]] = cr
        bit.add(cr+1, 1)
    nr = r
    ans[idx] = bit.sum(r+1) - bit.sum(l)
print(*ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
c = list(map(lambda x:int(x)-1, input().split()))
query = []
for i in range(q):
    l, r = map(int, input().split())
    query.append((i, l-1, r-1))

class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.bit = [0]*n
    
    def add(self, i, w):
        x = i+1
        while x<=self.n:
            self.bit[x-1] += w
            x += x & -x
    
    def sum(self, i):
        ret = 0
        x = i+1
        while x>0:
            ret += self.bit[x-1]
            x -= x & -x
        return ret

bit = BinaryIndexedTree(n+1)
query.sort(key=lambda x:x[2])
last = [None]*n
ans = [None]*q
nr = -1
for idx, l, r in query:
    for cr in range(nr+1, r+1):
        if last[c[cr]] is not None:
            bit.add(last[c[cr]]+1, -1)
        last[c[cr]] = cr
        bit.add(cr+1, 1)
    nr = r
    ans[idx] = bit.sum(r+1) - bit.sum(l)
for i in ans:
    print(i)
### BUGGY CODE ###

n = int(input())
counter = 0
s=0
if n%2 ==1:
    n = n-1
    
while n != 1:
    n=int(n/2)
    counter += 1
    
print(2**counter)

### FIXED CODE ###

n = int(input())
counter = 0
    
while n != 1:
    n=int(n/2)
    counter += 1
    
print(2**counter)
### BUGGY CODE ###

N = int(input())

t = int(0)

for i in range (1,N+1):
  p = N//i
  s = int(p*(2*i+(p-1)*i)/2)
  t = t + s

print(t)

### FIXED CODE ###

N = int(input())

t = 0

for i in range (1,N+1):
  p = N//i
  t += i*p*(1+p)/2
  

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

m = 10**9+7
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
tmp = 0
for i in range(n):
  if a[i] != a[i-1]:
    tmp = 0
    for j in range(i+1,n):
      tmp += a[j]^a[i]
      tmp %= m
  ans += tmp
  ans %= m
print(ans)

### FIXED CODE ###

import numpy as np

N = int(input())
mod = 10**9 + 7
A = np.array(input().split(), int)

ans = 0
for i in range(60):
    b = np.count_nonzero(A >> i & 1)
    ans += 2**i*(b*(N-b))
    ans %= mod
    c = np.count_nonzero(A >> i & 1)
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
from collections import deque

def bfs(sx,sy,gx,gy):
    d = [[float("inf")] * w for i in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]

h,w=map(int,input().split())
s = [list(input()) for i in range(h)]
ans=0
memo=[[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            if j != w:
                for m in range(j+1,w):
                    if s[i][m]=='.':
                        ans = max(ans,bfs(i,j,i,m))
            for k in range(i+1,h):
                for l in range(w):
                    if s[k][l]=='.':
                        ans = max(ans,bfs(i,j,k,l))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
from collections import deque


h,w=map(int,input().split())
s = [list(input()) for i in range(h)]

def bfs(sx,sy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[-1]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==-1 and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return max([max(i) for i in d])

count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            count  = max(count, bfs(i,j))
print(count)