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

n = int(input())
a = list(map(int, input().split()))
result = [0] * n
for i in range(n):
  tmp = 0
  for j in range(n):
    if i == j:
      continue
    else:
      tmp = tmp ^ a[j]
  result[i] = tmp
for e in result:
  print(e, end=' ')


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
sumval = 0
for e in a:
  sumval = sumval ^ e
for e in a:
  print(sumval ^ e, end=' ')
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


N = readint()
A = list(readnums())

L = [i + x for i, x in enumerate(A)]
R = [i - x for i, x in enumerate(A)]

x1 = min(max(L), max(R))
x2 = max(min(L), min(R))

ans = 0
for i in range(x2, x1 + 1):
    ans += L.count(i) * R.count(i)

print(ans)


### FIXED CODE ###

import sys
from collections import Counter
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


N = readint()
A = list(readnums())

L = [i + x for i, x in enumerate(A)]
R = [i - x for i, x in enumerate(A)]

l_c = Counter(L)
r_c = Counter(R)

x1 = min(max(L), max(R))
x2 = max(min(L), min(R))

ans = 0
for i in range(x2, x1 + 1):
    ans += l_c[i] * r_c[i]

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

N,M = map(int,input().split())
edge = [[] for _ in range(N+1)]
for i in range(M):
    go,to = map(int,input().split())
    edge[go].append(to)
    edge[to].append(go)
count = 0
stack = [[N,0]]
ok = False
while(stack != []):
    arr = stack.pop(0)
    if arr[1] < 3:
        if arr[0] == 1:
            ok = True
            break
        else:
            for i in edge[arr[0]]:
                stack.append([i,arr[1]+1])
print('POSSIBLE' if ok else 'IMPOSSIBLE')    

### FIXED CODE ###

N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(tuple(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)
### BUGGY CODE ###

from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
b = roop_find.index(a[i]-1)
roop = list(np.array(roop_find)[b:count+1])

if k < b:
    print(list(roop_find)[k]+1)
else:
    k-=b
    e = k % (count+1-b)
    print(roop[e]+1)


### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)
### BUGGY CODE ###

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

ok_count = 0
for i in range(N):
    ok_flag = True
    for j in range(i):
        if P[i] > P[j]:
            ok_flag = False
            break
    
    if ok_flag:
        ok_count += 1

print(ok_count)


### FIXED CODE ###

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

NG_count = 0
min = P[0]
for i in range(N):
    if min >= P[i]:
        min = P[i]
    elif min < P[i]:
        NG_count += 1

print(N - NG_count)
### BUGGY CODE ###

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

for i, x in enumerate(range(a, b+1)):
  if i < k or (0 <= (b-a) - i and (b-a) - i < k):
    print(x)

### FIXED CODE ###

a,b,k=map(int,input().split())
l=range(a,b+1)
ans=sorted(set(l[:k])|set(l[-k:]))
for i in ans:
    print(i)
### BUGGY CODE ###

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

for i in range(Q):
    l, r = map(int, input().split())
    bubun = S[l - 1:r]
    cnt = 0
    for j in range(len(bubun)):
        if j >= len(bubun) or j + 1 >= len(bubun):
            continue
        elif bubun[j] == "A" and bubun[j + 1] == "C":
            cnt += 1
    print(cnt)

### FIXED CODE ###

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

t = [0] * (N + 1)

for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i + 2] == "AC" else 0)

for i in range(Q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1; y-=1
        E[x].append(y)
        E[y].append(x)

    visited=[0]*n
    def dfs(v,p)->bool:
        if(visited[v]):
            return False
        visited[v]=1
        for nv in E[v]:
            if(nv==p): continue
            dfs(nv,v)
        return True

    ans=0
    for v in range(n):
        ans+=dfs(v,-1)
    print(ans)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class UnionFind(object):
    def __init__(self,n):
        self.__par=list(range(n))
        self.__rank=[0]*n
        self.__size=[1]*n

    def root(self,k):
        if(self.__par[k]==k): return k
        self.__par[k]=self.root(self.__par[k])
        return self.__par[k]

    def unite(self,i,j):
        i=self.root(i); j=self.root(j)
        par=self.__par; rank=self.__rank; size=self.__size
        if(i==j): return False
        if(rank[i]>rank[j]):
            par[j]=i
            size[i]+=size[j]
        else:
            par[i]=j
            size[j]+=size[i]
            if(rank[i]==rank[j]): rank[j]+=1
        return True

    def size(self,k):
        return self.__size[self.root(k)]

def resolve():
    n,m=map(int,input().split())
    uf=UnionFind(n)
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1; y-=1
        uf.unite(x,y)
    print(len({uf.root(i) for i in range(n)}))
resolve()
### BUGGY CODE ###

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

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for i in range(n):
        f = s
        for j in range(a):
            f -= 2 * al[(i - (1 + 2 * (j + 1)) + n) % n]
        ans[i] = str(f)
    print(" ".join([i for i in ans[1:]]) + " " + ans[0])

if __name__=="__main__":
    solve()


### FIXED CODE ###

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

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for j in range(a):
        s -= 2 * al[(0 - (1 + 2 * (j + 1)) + n) % n]
    ans[n - 1] = s
    for i in range(n - 2, -1, -1):
        ans[i] = 2 * al[i] - ans[i + 1]
    print(" ".join([str(i) for i in ans]))

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

import itertools
N,M = map(int,input().split())
A = []
S = [[] for _ in range(M)]
q = [[] for _ in range(N)]
for m in range(M):
  a,b = map(int,input().split())
  A.append([a,b])
  S[m] = a
  q[a-1].append(b)

S = set(S)
A = [a for a in A if (a[0] in S) and (a[1] in S)]

ans = []
XX = [[] for _ in range(1<<len(A))]
X = A.copy()
i = 0
for _ in range(N-1):
  for x in X:
    for v in q[x[-1]-1]:
      if v in x:  
          ans.append(x+[v])
          ans[0] = [len(ans[0])-1] + ans[0]
          print(*ans[0][:-1])
          import sys
          sys.exit()
      else:
          #XX.append(x + [v[1]])
          XX[i] = x + [v]
          i += 1
      X = [x for x in XX if x]


print(-1)


### FIXED CODE ###

def main():
  from collections import deque
  n,m,*t=map(int,open(0).read().split())
  i=[0]*n
  o=[[]for _ in range(n)]
  for a,b in zip(*[iter(t)]*2):
    o[a-1]+=b-1,
    i[b-1]+=1
  q=deque(v for v,f in enumerate(i)if f<1)
  r=[]
  while q:
    v=q.popleft()
    r+=v,
    for w in o[v]:
      i[w]-=1
      if i[w]==0:q+=w,
  print(-(len(r)==n))
main()
### BUGGY CODE ###

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

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    

dots = XY[:]

import sys
INT_MAX = sys.maxsize

x_dots = [(x, y) for x, y in dots]
x_dots = sorted(x_dots)
y_dots = [(x, y) for x, y in dots]
y_dots = sorted(y_dots, key=lambda x: x[1])

ans = INT_MAX
for l in range(N):
    l_val = x_dots[l][0]
    for r in range(l+1, N+1):
        r_val = x_dots[l:r][-1][0]
        for u in range(N):
            u_val = y_dots[u][1]
            for t in range(u+1, N+1):
                xy_dots =  set(x_dots[l:r]) & set(y_dots[u:t])
                if len(xy_dots) >= K:
                    #print("---")
                    #print(l, r, x_dots[l:r])
                    #print(u, t, y_dots[u:t])
                    #print(x_dots[l:r])
                    #l_val = x_dots[l:r][0][0]
                    #r_val = x_dots[l:r][-1][0]
                    
                    #u_val = y_dots[u:t][0][1]
                    t_val = y_dots[u:t][-1][1]
                    #print((r-l)*(t-u))
                    if ans > (r_val-l_val)*(t_val-u_val):
                        ans = (r_val-l_val)*(t_val-u_val)
                    else:
                        break
print(ans)


#y_dots = sorted(y_dots, key=lambda x: x[1])
#ans = INT_MAX


### FIXED CODE ###

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

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    
dots = XY[:]

import sys
INT_MAX = sys.maxsize

ans = INT_MAX

import itertools
for ((left_x, _), (right_x, _)) in itertools.combinations(dots, 2):
    if left_x > right_x:
        left_x, right_x = right_x, left_x
    for ((_, under_y), (_, top_y)) in itertools.combinations(dots, 2):
        if under_y > top_y:
            under_y, top_y = top_y, under_y
        counter = 0
        for d_x, d_y in dots:
            if  (left_x <= d_x) and (d_x <= right_x) and (under_y <= d_y) and (d_y <= top_y):
                counter += 1
                
        if counter >= K:
            area = (top_y-under_y) * (right_x-left_x)
            if ans > area:
                ans = area
            
print(ans)
### BUGGY CODE ###

import sys
N ,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
inf = 10 **18 +1
ok = inf
ng = -inf

def is_ok(arg):
    ans = 0
    for i in range(N):
        if A[i] * A[i] < arg :
            ans -= 1
        ok = N
        ng = -1
        if A[i] == 0:
            if arg > 0:
                ans += N
        elif A[i] > 0:
            while (abs(ok - ng) > 1):
                mid = (ok + ng) // 2
                if A[i] * A[mid] < arg:
                    ng = mid
                else:
                    ok = mid
            ans += ok
        else: 
            while (abs(ok - ng) > 1):
                mid = (ok + ng) // 2
                if A[i] * A[mid] < arg:
                    ok = mid
                else:
                    ng = mid       
            ans += N-ok   
    ans /= 2
    return K > ans

while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
        ng = mid
    else:
        ok = mid
print(ng)


### FIXED CODE ###

N ,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
inf = max(A[0]**2,A[-1]**2)
ok1 = inf
ng1 = -inf
while (abs(ok1 - ng1) > 1):
    arg = (ok1 + ng1) // 2
    ans = 0
    for i in range(N):
        if A[i] * A[i] < arg :
            ans -= 1
        ok = N
        ng = -1
        if A[i] == 0:
            if arg > 0:
                ans += N
        elif A[i] > 0:
            while (abs(ok - ng) > 1):
                mid = (ok + ng) // 2
                if A[i] * A[mid] < arg:
                    ng = mid
                else:
                    ok = mid
            ans += ok
        else: 
            while (abs(ok - ng) > 1):
                mid = (ok + ng) // 2
                if A[i] * A[mid] < arg:
                    ok = mid
                else:
                    ng = mid       
            ans += N-ok   
    ans /= 2
    if K>ans:
        ng1 = arg
    else:
        ok1 = arg
print(ng1)
### BUGGY CODE ###

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

dp1 = [[False]*K for _ in range(N)]
dp2 = [[False]*K for _ in range(N)]
# dp[x][y] x枚目まで使った時にyに出来るか
# K-ai <= ai < K となる部分集合を探す
dp1[0][0] = True
if a[0] < K:
    dp1[0][a[0]] = True 
for i in range(1,N):
    for j in range(K):
        dp1[i][j] = dp1[i-1][j] or (j-a[i] >= 0 and dp1[i-1][j-a[i]])

dp2[0][0] = True
if a[N-1] < K:
    dp2[0][a[N-1]] = True
for i in range(1,N):
    for j in range(K):
        dp2[i][j] = dp2[i-1][j] or (j-a[N-i-1] >= 0 and dp2[i-1][j-a[N-i-1]])
count = 0
for i in range(N):
    if K-a[i] <= 0:
        count += 1
        continue
    for j in range(K-a[i],K):
        f = False
        if i == 0:
            if dp2[N-2][j]:
                count += 1
                break
            else:
                continue
        elif i == N-1:
            if dp1[N-2][j]:
                count += 1
                break
            else:
                continue
        for k in range(j+1):
            if dp1[i-1][k] and dp2[N-i-2][j-k]:
                count += 1
                f = True
                break
        if f:
            break
print(N-count)


### FIXED CODE ###

N,K = map(int,input().split())
a = sorted(map(int,input().split()))

count = N
s = 0
for i in range(N-1,-1,-1):
    if s + a[i] < K:
        s += a[i]
    else:
        count = min(i,count)
print(count)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for i in range(N):
    B = A[0:i]+A[i+1:len(A)]
    print(max(B))

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
a = A.index(A_max)
A.sort(reverse=True)
for i in range(N):
    if i == a:
        print(A[1])
    else:
        print(A[0])
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

A.sort(reverse=True)
B.sort(reverse=True)

big_B = []

for b in B:
    if max(A) <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0

#
ruiseki_B = []

if thr >= H:
    not_need_damage = thr - H
    for i in range(N):
        not_need_damage -= B[N-i-1]
        cnt -= 1
        if not_need_damage <= 0:
            break



    # for i in range(N):
    # while damage < H:
    #     damage += B[i]
    #     cnt += 1

    i = 0
    cnt = len(big_B)
    while thr <= H:
        thr -= B[N-i-1]
        cnt -= 1

else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

A.sort(reverse=True)
B.sort(reverse=True)

big_B = []

ma_A = max(A)
for b in B:
    if ma_A <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        if damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)
### BUGGY CODE ###

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

per_li = []
for i in range(1,N+1):
  part_ = list(itertools.combinations(num_li,i))
  per_li.append(part_)
  
counter = 0
for j in range(len(per_li)):
  for k in range(len(per_li[j])):
    ans = sum(per_li[j][k])/len(per_li[j][k])
    if ans == A:
      counter += 1
    
print(counter)

### FIXED CODE ###

N, A = map(int, input().split())
num_base = list(map(int, input().split()))
num_li = [n - A for n in num_base]

import collections as cols
C = cols.Counter([0])

for n in num_li:
  adcols = cols.Counter()
  for idx, count in C.items():
    adcols[n+idx] += count
  C += adcols
print(C[0]-1)
### BUGGY CODE ###

N,K = map(int,input().split())
numarray = list()
for i in range(N):
    a,b = map(int,input().split())
    numarray.extend([a]*b)
# print(numarray)
numarray.sort()
print(numarray[K-1])

### FIXED CODE ###

from itertools import chain
N,K = map(int,input().split())
num_bool = [0]*(10**5)
numarray_ind = list()

for i in range(N):
    a,b = map(int,input().split())
    num_bool[a-1] += b
# print(num_bool)
sum_count = 0
k=1
for i in range(10**5):
    sum_count += num_bool[i]
    if(sum_count >= K):
        break
    k+=1
print(k)
### BUGGY CODE ###

n, m = map(int, input().split())
W, V = [], []
for i in range(n):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)
F = [[0 for j in range(m+1)] for i in range(n+1)]
for i in range(1, n+1):
    for j in range(W[i-1]):
        F[i][j] = F[i-1][j]
    for j in range(W[i-1], m+1):
        F[i][j] = max(F[i-1][j], F[i-1][j-W[i-1]]+V[i-1])
print(F[n][m])


### FIXED CODE ###

N, M = map(int, input().split())
W, V = [], []
for n in range(N):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)
f = [[0 for m in range(M + 1)] for n in range(N + 1)]
for n in range(N):
    for m in range(M + 1):
        if m < W[n]:
            f[n + 1][m] = f[n][m]
        else:
            f[n + 1][m] = max(f[n][m], f[n][m - W[n]] + V[n])
print(f[N][M])
### BUGGY CODE ###

#ライブラリインポート
from collections import defaultdict
import queue

#入力受け取り
def getlist():
	return list(map(int, input().split()))

INF = float("inf")

def BFS(H, W, L, start):
	dist = [[INF for i in range(W)] for j in range(H)]
	sy, sx = start
	dist[sy][sx] = 0
	Q = queue.Queue()
	Q.put([sy, sx])
	while not Q.empty():
		y, x = Q.get()
		if y - 1 >= 0:
			if L[y - 1][x] == "." and dist[y - 1][x] > dist[y][x] + 1:
				dist[y - 1][x] = dist[y][x] + 1
				Q.put([y - 1, x])
		if y + 1 <= H - 1:
			if L[y + 1][x] == "." and dist[y + 1][x] > dist[y][x] + 1:
				dist[y + 1][x] = dist[y][x] + 1
				Q.put([y + 1, x])
		if x - 1 >= 0:
			if L[y][x - 1] == "." and dist[y][x - 1] > dist[y][x] + 1:
				dist[y][x - 1] = dist[y][x] + 1
				Q.put([y, x - 1])
		if x + 1 <= W - 1:
			if L[y][x + 1] == "." and dist[y][x + 1] > dist[y][x] + 1:
				dist[y][x + 1] = dist[y][x] + 1
				Q.put([y, x + 1])

	return dist

#処理内容
def main():
	H, W = getlist()
	L = []
	for i in range(H):
		l = list(input())
		L.append(l)
	SGy = []
	SGx = []
	for i in range(H):
		for j in range(W):
			if L[i][j] == ".":
				SGy.append(i)
				SGx.append(j)

	N = len(SGx)
	ans = 0
	for i in range(N):
		for j in range(i + 1, N):
			start = [SGy[i] , SGx[i]]
			goal = [SGy[j] , SGx[j]]
			BF = BFS(H, W, L, start)
			val = BF[goal[0]][goal[1]]
			ans = max(ans, val)
	print(ans)


if __name__ == '__main__':
	main()

### FIXED CODE ###

#ライブラリインポート
import queue

#入力受け取り
def getlist():
	return list(map(int, input().split()))

INF = float("inf")

def BFS(H, W, L, start):
	dist = [[INF for i in range(W)] for j in range(H)]
	sy, sx = start
	dist[sy][sx] = 0
	Q = queue.Queue()
	Q.put([sy, sx])
	while not Q.empty():
		y, x = Q.get()
		if y - 1 >= 0:
			if L[y - 1][x] == "." and dist[y - 1][x] > dist[y][x] + 1:
				dist[y - 1][x] = dist[y][x] + 1
				Q.put([y - 1, x])
		if y + 1 <= H - 1:
			if L[y + 1][x] == "." and dist[y + 1][x] > dist[y][x] + 1:
				dist[y + 1][x] = dist[y][x] + 1
				Q.put([y + 1, x])
		if x - 1 >= 0:
			if L[y][x - 1] == "." and dist[y][x - 1] > dist[y][x] + 1:
				dist[y][x - 1] = dist[y][x] + 1
				Q.put([y, x - 1])
		if x + 1 <= W - 1:
			if L[y][x + 1] == "." and dist[y][x + 1] > dist[y][x] + 1:
				dist[y][x + 1] = dist[y][x] + 1
				Q.put([y, x + 1])

	return dist

#処理内容
def main():
	H, W = getlist()
	L = []
	for i in range(H):
		l = list(input())
		L.append(l)

	ans = 0
	for i in range(H):
		for j in range(W):
			if L[i][j] == ".":
				BF = BFS(H, W, L, [i, j])
				for p in range(H):
					for q in range(W):
						if BF[p][q] != INF:
							ans = max(ans, BF[p][q])

	print(ans)


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

# import math
# import numpy as np

# S = input()
# N = int(input())
H, N = map(int, input().split())
# A = list(map(int, input().split()))
# B = [int(input()) for _ in range(n)]
# A = []
# B = []
# for _ in range(N):
#     a, b = list(map(int, input().split()))
#     A.append(a)
#     B.append(b)

# 二次元配列
# [[inf, inf, inf], [inf, inf, inf]]
# dp = [[float('inf')] * (H + 1) for i in range(N + 1)]

INF = 10 ** 18
dp = [INF] * (H + 1)
dp[0] = 0

def solve():
    for i in range(N):
        a, b = list(map(int, input().split()))

        for j in range(H):
            nj = min(j + a, H)
            dp[nj] = min(dp[nj], dp[j] + b)
    return dp[H]

print(solve())


### FIXED CODE ###

import numpy as np

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

A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)

dp = np.full((H+1), np.inf)
dp[0] = 0

def solve():
    for i in range(1, H + 1):
        dp[i] = np.amin(dp[np.maximum(i - A , 0)] + B)
    return int(dp[H])

print(solve())
### BUGGY CODE ###

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

#もし高橋君がクッキーを 1 枚以上持っているなら、高橋君のクッキーを 1 枚食べる。
#そうでなく、もし青木君がクッキーを 1 枚以上持っているなら、青木君のクッキーを 1 枚食べる。
#高橋君も青木君もクッキーを持っていないなら、何もしない。

for _ in range(k):
  if a >= 1:
  	a = a - 1
  elif a == 0 and b >= 1:
    b = b - 1

print(a, b)

### FIXED CODE ###

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

#もし高橋君がクッキーを 1 枚以上持っているなら、高橋君のクッキーを 1 枚食べる。
#そうでなく、もし青木君がクッキーを 1 枚以上持っているなら、青木君のクッキーを 1 枚食べる。
#高橋君も青木君もクッキーを持っていないなら、何もしない。

if k <= a:
  print(a-k, b)
elif a < k and k <= (a + b):
  print(0, a+b-k)
elif (a + b) < k:
  print(0, 0)
### BUGGY CODE ###

s=input()
n=int(s)
m=len(s)
if n<2019:
    print(0)
    exit()
from collections import Counter
c=Counter()
tmp=""
c[0]+=1
for i in s[::-1]:
    tmp=i+tmp
    c[int(tmp)%2019]+=1

ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)


### FIXED CODE ###

s=[int(j) for j in input()][::-1]
c=[0]*2019
tmp=0
c[0]+=1
t=1
import numpy as np
for i in s:
    tmp+=t*i
    c[tmp%2019]+=1
    t=t*10%2019
c=np.array(c)
ans=c*(c-1)//2
print(ans.sum())
### BUGGY CODE ###

S=input()
ans,n=0,len(S)
dp=[0]*(2019)
s,dp[0]=0,1
for i in range(1,n+1):
  s+=int(S[-i])*(10**(i-1))
  ans+=dp[s%2019]
  dp[s%2019]+=1
print(ans)

### FIXED CODE ###

S=input()
ans,n=0,len(S)
dp=[0]*(2019)
s,dp[0],k=0,1,1
for i in range(1,n+1):
  s=(s+int(S[-i])*k)%2019
  k=(k*10)%2019
  ans+=dp[s]
  dp[s]+=1
print(ans)