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

#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

import copy
N = int(input())
S = input()

hoge = ["R", "G", "B"]
ct = 0

def dfs(index, RGB, indexs):
    global ct
    if S[index] in RGB:
        return
    else:
        RGB += [S[index]]
        indexs += [index]
        
        if len(RGB) == 2:

            for i in hoge:
                if not i in RGB:
                    ct += list(S[index+1:]).count(i)
                    h = indexs[1]+indexs[1]+2 - (indexs[0]+1)

                    if 0 < h <= N and S[h-1] == i:
                        ct -= 1
                    
                    return

        for i in range(index+1, N):
            dfs(i, copy.copy(RGB), copy.copy(indexs))

for i in range(N):
    dfs(i, [], [])

print(ct)

### FIXED CODE ###

#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

import copy
N = int(input())
S = input()

# ct = 0

# def dfs(index, RGB, indexs):
#     global ct
#     if RGB[S[index]] == 1:
#         return
#     else:
#         RGB[S[index]] = 1
#         indexs += [index]
        
#         if len(indexs) == 2:

#             for key, value in RGB.items():
#                 if value == 0:
#                     ct += Counter(S[index+1:])[key]
#                     h = indexs[1]+indexs[1] - indexs[0] +1
#                     if 0 < h <= N and S[h-1] == key:
#                         ct -= 1

#                     return

#         for i in range(index+1, N):
#             dfs(i, RGB.copy(), copy.copy(indexs))

# for i in range(N):
#     dfs(i, {"R":0, "G":0, "B":0}, [])

# print(ct)

c = Counter(S)
al = c["R"] * c["G"] * c["B"]

for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k >= N: break
        if S[i] != S[k] and S[i] != S[j] and S[j] != S[k]:
            al -= 1
print(al)
### BUGGY CODE ###

from collections import deque

N, M = map(int, input().split())
Edge = [[] for _ in range(N)]
Start = {a for a in range(N)}
End = set()
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    Edge[x].append(y)
    End.add(y)
Start = Start - End
Q = deque(Start)

DP = [0] * N
ans = 0
while Q:
    now = Q.pop()
    for nex in Edge[now]:
        if DP[nex] < DP[now] + 1:
            DP[nex] = DP[now] + 1
            Q.append(nex)
            ans = max(ans, DP[nex])
print(ans)



### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
Edge = [[]for _ in range(N)]
Far = [-1]*N
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    Edge[x].append(y)


def long(x):
    if len(Edge[x]) == 0:
        Far[x] = 0
        return 0
    if Far[x] >= 0:
        return Far[x]
    r = 0
    for i in Edge[x]:
        l = long(i) + 1
        r = max(r, l)
    Far[x] = r
    return r


for i in range(N):
    long(i)
print(max(Far))
### BUGGY CODE ###

N = int(input())
A = [input() for _ in range(N)]

D = [[0 for j in range(40)] for i in range(60)]

for a in A:
    #まずは分子の整数Bと分母の指数kに分けていく
    B=0;k=0
    for j in range(len(a)):
        if a[j]!='.':
            B=B*10
            B=B+int(a[j])
        if a[j]=='.':
            k=len(a)-j-1
    
    #次にBに2と5がいくつ含まれるかを求める
    t=0;f=0
    b=B
    while b%2==0:
        t+=1
        b=b//2
    b=B
    while b%5==0:
        f+=1
        b=b//5
    
    #D[t-k][f-k]をインクリメントする
    #…と言いたいところだがマイナスになりうるので+10したものを入れる
    
    D[t-k+10][f-k+10]+=1
    

Ans=0
for i in range(len(D)):
    for j in range(len(D[i])):
        for k in range(len(D)):
            for l in range(len(D[k])):
                #(hoge*2^i*5^j)*(fuga*2^k*5^l)がOKならAnsに足し入れる
                if i+k-20>=0 and j+l-20>=0 and not(i==k and j==l):
                    Ans = Ans+D[i][j]*D[k][l]

#D[i][j]*D[k][l]とD[i][l]*D[i][j]で同じものを２回かけているので2で割っておく
Ans = Ans//2

#違うA_iでも同じt-k,f-kを持つことはある
#ので、それを処理する
for i in range(len(D)):
    for j in range(len(D[i])):
        if i-10>=0 and j-10>=0:
            Ans = Ans + D[i][j]*(D[i][j]-1)//2

print(Ans)        

### FIXED CODE ###

N = int(input())
A = [input() for _ in range(N)]

D = [[0 for j in range(40)] for i in range(60)]

for a in A:
    #まずは分子の整数Bと分母の指数kに分けていく
    B=0;k=0
    for j in range(len(a)):
        if a[j]!='.':
            B=B*10
            B=B+int(a[j])
        if a[j]=='.':
            k=len(a)-j-1
    
    #次にBに2と5がいくつ含まれるかを求める
    t=0;f=0
    b=B
    while b%2==0:
        t+=1
        b=b//2
    b=B
    while b%5==0:
        f+=1
        b=b//5
    
    #D[t-k][f-k]をインクリメントする
    #…と言いたいところだがマイナスになりうるので+10したものを入れる
    
    D[t-k+10][f-k+10]+=1
    

Ans=0
for i in range(len(D)):
    for j in range(len(D[i])):
        for k in range(len(D)):
            for l in range(len(D[k])):
                #(hoge*2^i*5^j)*(fuga*2^k*5^l)がOKならAnsに足し入れる
                if i+k-20>=0 and j+l-20>=0 and not(i==k and j==l):
                    Ans = Ans+D[i][j]*D[k][l]

#D[i][j]*D[k][l]とD[i][l]*D[i][j]で同じものを２回かけているので2で割っておく
Ans = Ans//2

#違うA_iでも同じt-k,f-kを持つことはある
#ので、それを処理する
for i in range(len(D)):
    for j in range(len(D[i])):
        if i-10>=0 and j-10>=0:
            Ans = Ans + D[i][j]*(D[i][j]-1)//2

print(Ans)
### BUGGY CODE ###

#FT robot
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
    
for some in xlist:
    some=abs(some)
for some in ylist:
    some=abs(some)
Xsum=sum(xlist)
Ysum=sum(ylist)
if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")
    
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(8001)] for i in range(len(xlist)+2)]
    dpy=[[False for i in range(8001)] for j in range(len(ylist)+2)]
    #dpx[i][j]でi番目のカードまでを足して、値ｊを取れるか判定する
    dpx[0][0]=True
    dpy[0][0]=True
    for i in range(len(xlist)):
        for j in range(8001):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(len(ylist)):
        for j in range(8001):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]        
    if (dpy[len(ylist)][gy1] or dpy[len(ylist)][gy2]) and (dpx[len(xlist)][gx1] or dpx[len(xlist)][gx2]):
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

      #FT robot
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
Xsum=sum(xlist)
Ysum=sum(ylist)


if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")   
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(Xsum+2)] for j in range(len(xlist)+2)]
    dpy=[[False for i in range(Ysum+2)] for j in range(len(ylist)+2)]
    #dpx[i][j]でi番目のカードまでを足して、値ｊを取れるか判定する
    dpx[0][0]=True
    dpy[0][0]=True
    for i in range(len(xlist)):
        for j in range(Xsum+2):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(len(ylist)):
        for j in range(Ysum+2):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]    
    #ここまではあってそうなことがわかった
    flag1=False
    if 0<= gy1<= Ysum:   
        if dpy[len(ylist)][gy1]:
            flag1=True
    flag2=False
    if 0<=gy2<= Ysum :
        if dpy[len(ylist)][gy2]:
            flag2=True
    flag3=False
    if 0<=gx1<= Xsum:
        if dpx[len(xlist)][gx1]:
            flag3=True
    flag4=False
    if 0<=gx2<= Xsum:
        if dpx[len(xlist)][gx2]:
            flag4=True
    if (flag1 or flag2) and (flag3 or flag4):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from itertools import combinations_with_replacement
from math import factorial
n,m,q=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(q)]
total=[]
for a in combinations_with_replacement(range(1,m+1),n):
  ans=0
  for j in range(q):
    if int(a[lst[j][1]-1])-int(a[lst[j][0]-1])==lst[j][2]:
      ans+=lst[j][3]
  total.append(ans)

print(max(total))


### FIXED CODE ###

from itertools import combinations_with_replacement
from math import factorial
n,m,q=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(q)]
total=[]
for a in combinations_with_replacement(range(1,m+1),n):
  ans=0
  for j in range(q):
    if int(a[lst[j][1]-1])-int(a[lst[j][0]-1])==lst[j][2]:
      ans+=lst[j][3]
  total.append(ans)

print(max(total))
### BUGGY CODE ###

def hersCode(L, n):
  ok = len(L) - 1
  ng = 0
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if L[mid] > n:
      ok = mid
    else:
      ng = mid
  return ok

def hersCode2(L, n):
  ok = 0
  ng = len(L)
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if L[mid] <= n:
      ok = mid
    else:
      ng = mid
  return ok

N = int(input())

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

D = [pow(2, i) for i in range(31)]
L = [True for i in range(N + 1)]
Ans = 0
A = [-1e11] + A
for i in range(len(A) - 1, 1, -1):
  if L[i]:
    k = D[hersCode(D, A[-1])] - A[-1]
    del A[-1]
    t = hersCode2(A, k)
    cnt = 0
    while A[t - cnt] == k:
      if L[t - cnt]:
        L[t - cnt] = False
        Ans += 1
        break
      else:
        cnt += 1
  else:
    del A[-1]

print(Ans)

### FIXED CODE ###

def hersCode(L, n):
  ok = len(L) - 1
  ng = 0
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if L[mid] > n:
      ok = mid
    else:
      ng = mid
  return ok

def hersCode2(L, n):
  ok = 0
  ng = len(L)
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if L[mid] < n:
      ok = mid
    elif L[mid] == n:
      if TF[mid]:
        ok = mid
      else:
        ng = mid
    else:
      ng = mid
  return ok

N = int(input())

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

D = [pow(2, i) for i in range(31)]
TF = [True for i in range(N + 1)]
Ans = 0
A = [-1e11] + A
for i in range(len(A) - 1, 1, -1):
  if TF[i]:
    k = D[hersCode(D, A[-1])] - A[-1]
    del A[-1]
    t = hersCode2(A, k)
    if A[t] == k:
      TF[t] = False
      Ans += 1
  else:
    del A[-1]

print(Ans)
### BUGGY CODE ###

k=int(input())
ans=1
s_1=7%k
s_2=10%k
m=0
j=0
if k%2==0 or k%5==0:
  print(-1)
elif k==1 or k==7:
  print(1)
else:
  i=0
  while j==0:
    m=(m+(s_1*(((s_2)**i)%k)))%k
    if m==0:
      j==1
    else:
      ans+=1
      i+=1
  print(ans)

### FIXED CODE ###

k=int(input())
m=0
for i in range(k):
  m=(m*10+7)%k
  if m==0:
    break
  elif i==k-1:
    print(-1)
    exit()
print(i + 1)
### BUGGY CODE ###

# キャンディーとN人の子供

mod = 10**9 + 7
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def rev(X):
    return pow(X, mod-2, mod)


pow_sum = [[B[i]-A[i]+1 for j in range(C+1)] for i in range(N)]
pow_table = [[1 for j in range(B[i]+1)] for i in range(N)]
for cnt in range(C):
    for i in range(N):

        for j in range(B[i]+1):
            pow_table[i][j] *= j
            pow_table[i][j] %= mod

        for j in range(N):
            pow_sum[i][cnt+1] = sum(pow_table[i][A[i]:B[i]+1]) % mod

ans_dp = [[0 for i in range(C+1)] for j in range(N+1)]
# ans_dp[x][y] = 0<=x<=N,0<=y<=C の場合のdp
ans_dp[0][0] = 1
for n in range(1, N+1):
    # ans_dp[n]の更新
    for c in range(C+1):
        # ans_dp[n][c]の更新
        for k in range(c+1):
            ans_dp[n][c] += ans_dp[n-1][k]*pow_sum[n-1][c-k]
        ans_dp[n][c] %= mod
print(ans_dp[N][C]%mod)

### FIXED CODE ###

# キャンディーとN人の子供

mod = 10**9 + 7
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def rev(X):
    return pow(X, mod-2, mod)


pow_sum = [[B[i]-A[i]+1 for j in range(C+1)] for i in range(N)]
pow_table = [[1 for j in range(401)] for i in range(401)]
for i in range(401):
    for j in range(401):
        pow_table[i][j] = pow(i, j, mod)

for cnt in range(C):
    for i in range(N):
        pow_sum[i][cnt+1] = 0
        for j in range(A[i], B[i]+1):
            pow_sum[i][cnt+1] += pow_table[j][cnt+1]
        pow_sum[i][cnt+1] %= mod

ans_dp = [[0 for i in range(C+1)] for j in range(N+1)]
# ans_dp[x][y] = 0<=x<=N,0<=y<=C の場合のdp
ans_dp[0][0] = 1
for n in range(1, N+1):
    # ans_dp[n]の更新
    for c in range(C+1):
        # ans_dp[n][c]の更新
        for k in range(c+1):
            ans_dp[n][c] += ans_dp[n-1][k]*pow_sum[n-1][c-k]
        ans_dp[n][c] %= mod
print(ans_dp[N][C] % mod)
### BUGGY CODE ###

from collections import deque


def bfs(sx, sy):
    q = deque([(sx, sy)])
    visited = [[False] * w for _ in range(h)]
    cost[sx][sy] = 0
    visited[sx][sy] = True
    while q:
        x, y = q.popleft()
        for dx, dy in nb:
            nx = x + dx
            ny = y + dy
            if 0 <= nx and nx < h and 0 <= ny and ny < w and not (visited[nx][ny]):
                cost[nx][ny] = min(cost[x][y] + 1, cost[nx][ny])
                q.append((nx, ny))
                visited[nx][ny] = True


h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]
cost = [[float("inf")] * w for _ in range(h)]
nb = [(-1, 0), (0, -1), (1, 0), (0, 1)]
ans = -1

for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            bfs(i, j)

for i in range(h):
    for j in range(w):
        ans = max(ans, cost[i][j])
print(ans)


### FIXED CODE ###

from collections import deque
 
H, W = map(int, input().split())
A = [input() for i in range(H)]
q = deque()
c = [[-1] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append((i, j))
            c[i][j] = 0
D = [[0, 1], [1, 0], [0, -1], [-1, 0]]
while q:
    y, x = q.popleft()
    for dy, dx in D:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and c[ny][nx] == -1:
            q.append((ny, nx))
            c[ny][nx] = c[y][x]+1
print(max([max(l) for l in c]))
### BUGGY CODE ###

# -*- coding:utf8 -*-

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [list(range(s.count(i))) for i in set(s) if s.count(i) != 1]
t = [sum(i) for i in c]
print(sum(t))

### FIXED CODE ###

# -*- coding:utf8 -*-
import collections

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = collections.Counter(s)
t = [range(i) for i in list(c.values()) if i != 1]
a = [sum(i) for i in t]
print(sum(a))
### BUGGY CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for i in range(1,m+1):
  a[-1]=a[-1]//2
  a.sort()

print(sum(a))

### FIXED CODE ###

import heapq
n,m = map(int,input().split())
a = list(map(lambda x: (-1)*int(x),input().split()))
heapq.heapify(a)

for i in range(1,m+1):
  t=heapq.heappop(a)
  heapq.heappush(a,-(-t//2))

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

a, b = map(int, input().split())
okashi = 1
max = 10**9
for i in range(0,max):
  if okashi%a == 0 and okashi%b == 0:
    break
  else:
    okashi +=1
print(okashi)
    

### FIXED CODE ###

a, b = map(int, input().split())
okashi = 1
max = 10**9
for i in range(0,max):
  if(a * okashi) % b == 0:
      break
  else:
    okashi +=1
print(a*okashi)
### BUGGY CODE ###

def f(blue, red, ans):
    c = 0
    for i, b in enumerate(blue):
        for j, r in enumerate(red):
            if b[0] >= r[0] and b[1] >= r[1]:
                blue.pop(i)
                red.pop(j)
                c = max(c, f(blue, red, ans + 1))
                blue.insert(i, b)
                red.insert(j, r)
    return max(c, ans)


def main():
    N = int(input())
    red = [list(map(int, input().split())) for _ in range(N)]
    blue = [list(map(int, input().split())) for _ in range(N)]
    print(f(blue, red, 0))


main()


### FIXED CODE ###

def main():
    N = int(input())
    red = sorted(
        [list(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=True
    )
    blue = sorted(
        [list(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[0]
    )
    ans = 0
    for b in blue:
        for i, r in enumerate(red):
            if b[0] > r[0] and b[1] > r[1]:
                ans += 1
                red.pop(i)
                break
    print(ans)


main()
### BUGGY CODE ###

n=int(input())
num=list(map(int,input().split()))
don=[]
#don.append(num[0])
for i in num:
	flg=True
	for j in don:
		if i > j:
			flg=False
	if flg:
		don.append(i)
print(len(don))

### FIXED CODE ###

n=int(input())
num=list(map(int,input().split()))
cnt=1
min_n=num[0]
for i in range(1,n):
    if num[i] <= min_n:
        min_n=num[i]
        cnt+=1
print(cnt)
### BUGGY CODE ###

def prime(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for j in range(4, n+1, 2):
        is_prime[j] = False
    for i in range(3, int(n**0.5) + 1, 2):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

Q = int(input())
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
 
K = max(r)
prime = prime(K)
a = [0]*K
S = a + [0]
for i in range(K):
    if i+1 in prime and (i+2)/2 in prime:
        a[i] = 1

for i in range(K):
    S[i+1] = S[i] + a[i]

for i in range(Q):
    rr, ll = r[i], l[i]
    if rr == ll:
        if a[ll-1] == 1:
            print(1)
        else:
            print(0)
    else:
        print(S[rr-1] - S[ll-1])



### FIXED CODE ###

def prime(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for j in range(4, n+1, 2):
        is_prime[j] = False
    for i in range(3, int(n**0.5) + 1, 2):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

Q = int(input())
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
 
K = max(r)
prime = prime(K)
a = [1]*(K+1)
s = [0]*(K+1)
a[0] = 0
a[1] = 0
for i in range(2,K+1):
    if a[i]:
        for j in range(i*i, K+1, i):
            a[j] = 0

for i in range(3,K+1,2):
    if a[i] and a[(i+1)//2]:
        s[i] = 1

for i in range(K):
    s[i+1] += s[i]

for i in range(Q):
    rr, ll = r[i], l[i]
    if rr == ll:
        if s[ll]-s[ll-2] == 1:
            print(1)
        else:
            print(0)
    else:
        print(s[rr] - s[ll-1])
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)

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

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i - 1] - ans[i - 1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N - 1] - (ans[N - 1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = N // 2

    while True:
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = jump // 2 + 1
        dprint(x, ret, ans, jump)

    print(" ".join([str(i * 2) for i in ans]))


solve()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


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

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i - 1] - ans[i - 1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N - 1] - (ans[N - 1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = min(A[0], A[N - 1]) // 2

    # i = 0
    while True:
        # i += 1
        # if i > 10:
        #     break
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

    print(" ".join([str(i * 2) for i in ans]))


solve()
### BUGGY CODE ###

import math,itertools,fractions,heapq,bisect,sys,copy,collections

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0

  for i in range(h):
    for j in range(w):
      for k in range(h):
        for l in range(w):
          q=collections.deque()
          if field[i][j]=='#' or field[k][l]=='#':
            continue
          q.append((k,l,0))
          visited=[[-1]*w for _ in range(h)]
          while len(q)>0:
            y,x,c=q.popleft()
            visited[y][x]=c
            if y==i and x==j:
              ans=max(ans,c)
              break

            for dy,dx in ((-1,0),(0,1),(1,0),(0,-1)):
              ny=y+dy
              nx=x+dx
              if 0<=ny and 0<=nx and ny<h and nx<w:
                if field[ny][nx]=='#':
                  continue
                if visited[ny][nx]!=-1:
                  continue
                q.append((ny,nx,c+1))

  return ans

# main()
print(main())


### FIXED CODE ###

import sys,collections

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  visited=[[-1 for __ in range(w)] for _ in range(h)]
  q=collections.deque()
  for i in range(h):
    for j in range(w):
      if field[i][j]=='#':
        continue
      q.append((i,j))
      for _i in range(h):
        for _j in range(w):
          visited[_i][_j]=-1
      visited[i][j]=0
      _ans=0
      while q:
        y,x=q.popleft()

        for dy,dx in ((-1,0),(0,1),(1,0),(0,-1)):
          ny=y+dy
          nx=x+dx
          if not 0<=ny<h:
            continue
          if not 0<=nx<w:
            continue
          if field[ny][nx]=='#':
            continue
          if visited[ny][nx]!=-1:
            continue
          _ans=visited[y][x]+1
          visited[ny][nx]=_ans
          q.append((ny,nx))
      ans=max(ans,_ans)
  return ans

# main()
print(main())