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

H,W=map(int,input().split())
red=[]
blue=[]
for i in range(H):
  A=list(map(int,input().split()))
  red.append(A)
for i in range(H):
  B=list(map(int,input().split()))
  blue.append(B)
list=[[[0 for i in range(80*(j+k+1)+1)] for j in range(W)] for k in range(H)]
list[0][0][abs(red[0][0]-blue[0][0])]=1
for i in range(H):
  for j in range(W):
    for k in range(len(list[i][j])):
      if list[i][j][k]==1:
        if i+1<H:
          if abs(k-abs(red[i+1][j]-blue[i+1][j]))<=80*(i+j+2): 
            list[i+1][j][abs(k-abs(red[i+1][j]-blue[i+1][j]))]=1
          if abs(k+abs(red[i+1][j]-blue[i+1][j]))<=80*(i+j+2): 
            list[i+1][j][abs(k+abs(red[i+1][j]-blue[i+1][j]))]=1
        if j+1<W:
          if abs(k-abs(red[i][j+1]-blue[i][j+1]))<=80*(i+j+2): 
            list[i][j+1][abs(k-abs(red[i][j+1]-blue[i][j+1]))]=1
          if abs(k+abs(red[i][j+1]-blue[i][j+1]))<=80*(i+j+2): 
            list[i][j+1][abs(k+abs(red[i][j+1]-blue[i][j+1]))]=1           
for i in range(12801):
  if list[H-1][W-1][i]==1:
    print(i)
    break


### FIXED CODE ###

H,W=map(int,input().split())
red=[]
blue=[]
for i in range(H):
  A=list(map(int,input().split()))
  red.append(A)
for i in range(H):
  B=list(map(int,input().split()))
  blue.append(B)
list=[[[0 for i in range(80*(j+k+1)+1)] for j in range(W)] for k in range(H)]
list[0][0][abs(red[0][0]-blue[0][0])]=1
for i in range(H):
  for j in range(W):
    for k in range(len(list[i][j])):
      if list[i][j][k]==1:
        if i+1<H:
          if abs(k-abs(red[i+1][j]-blue[i+1][j]))<=80*(i+j+2): 
            list[i+1][j][abs(k-abs(red[i+1][j]-blue[i+1][j]))]=1
          if abs(k+abs(red[i+1][j]-blue[i+1][j]))<=80*(i+j+2): 
            list[i+1][j][abs(k+abs(red[i+1][j]-blue[i+1][j]))]=1
        if j+1<W:
          if abs(k-abs(red[i][j+1]-blue[i][j+1]))<=80*(i+j+2): 
            list[i][j+1][abs(k-abs(red[i][j+1]-blue[i][j+1]))]=1
          if abs(k+abs(red[i][j+1]-blue[i][j+1]))<=80*(i+j+2): 
            list[i][j+1][abs(k+abs(red[i][j+1]-blue[i][j+1]))]=1           
for i in range(12801):
  if list[H-1][W-1][i]==1:
    print(i)
    break
### BUGGY CODE ###

import numpy as np

s = input()
t = input()
ls = len(s)
lt = len(t)

if not set(list(t)) <= set(list(s)):
  print(-1)

else:
  d = {}
  for i in range(ls):
    if s[i] in d.keys():
      d[s[i]] += [i+1]
    else:
      d[s[i]] = [i+1]
  
  c = 0
  x = 0
  for j in range(lt):
    a = np.array(d[t[j]])
    idx = min(np.r_[a[a >= x], a[a < x]+ls])
    c += idx - x
    x = c % ls
    
  print(c)

### FIXED CODE ###

import bisect

S = input()
T = input()

ls = len(S)
d = {}
for i, s in enumerate(S):
  if s in d:
    d[s].append(i+1)
  else:
    d[s] = [i+1]


now = 0
ans = 0
pre_t = ''
for t in T:
  if not t in d:
    ans = -1
    break
    
  if t == pre_t:
    idx = bisect.bisect_left(d[t], now+1)
  else:
    idx = bisect.bisect_left(d[t], now)

  if idx == len(d[t]):
    idx = 0
  
  if d[t][idx] > now:
    ans += d[t][idx] - now
  else:
    ans += ls + d[t][idx] - now
  
  now = d[t][idx]
  pre_t = t

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

import bisect

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

def hand(x):
  cnt=0
  for i in range(n):
    p=x-A[i]
    cnt+=n-bisect.bisect_left(A,p)
  return cnt


l=0
h=10**15+3
mid=(l+h)//2

while l+1<h:
  mid=(l+h)//2
  if hand(mid)<m:
    h=mid
  else:
    l=mid

B=A[::-1]

for i in range(n-1):
  B[i+1]+=B[i]

B=B[::-1]

ans=0
cnt=0


for i in range(n):
  y=l-A[i]+1
  index=bisect.bisect_left(A,y)
  if n==index:
    continue
  else:
    ans+=(n-index)*A[i]+B[index]
    cnt+=(n-index)

ans+=(m-cnt)*l
print(ans)
  

  
  

### FIXED CODE ###

import sys
 
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

import bisect

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

def hand(x):
  cnt=0
  for i in range(n):
    p=x-A[i]
    cnt+=n-bisect.bisect_left(A,p)
  return cnt

def main():
  l=0
  h=10**15+3
  mid=(l+h)//2
  
  while l+1<h:
    mid=(l+h)//2
    if hand(mid)<m:
      h=mid
    else:
      l=mid
  
  B=A[::-1]
  
  for i in range(n-1):
    B[i+1]+=B[i]
  
  B=B[::-1]
  
  ans=0
  cnt=0
  
  
  for i in range(n):
    y=l-A[i]+1
    index=bisect.bisect_left(A,y)
    if n==index:
      continue
    else:
      ans+=(n-index)*A[i]+B[index]
      cnt+=(n-index)
  
  ans+=(m-cnt)*l
  print(ans)

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

import numpy as np

n, k = [int(elem) for elem in input().split()]
h = np.array(list(map(int, input().split())))

dp=np.full(n, 10**10)
dp[0] = 0
for i in range(0, n):
  for j in range(1, k+1):
    if len(h) > (i+j):
      tmp = dp[i] + np.abs(h[i] - h[i+j])
      if dp[i+j] > tmp:
          dp[i+j] = tmp
print(int(dp[-1]))

### FIXED CODE ###

INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))


N, X, Y = LI()
X -= 1
Y -= 1
path = [[mod for i in range(N)] for i in range(N)]
for i in range(N):
    for j in range(i, N):
        path[i][j] = j - i
        path[j][i] = j- i
    
path[X][Y] = 1
path[Y][X] = 1

for i in range(N):
    for j in range(i + 1, N):
        path[i][j] = min(path[i][j], path[i][X] + path[X][Y]+ path[Y][j])

anss = [0 for i in range(N)]
# for p in path:
#     print(p)

for i in range(N):
    for j in range(i + 1, N):
        anss[path[i][j]] += 1

for i in range(1, N):
    print(anss[i])

### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))


N, X, Y = LI()
X -= 1
Y -= 1
anss = [0 for i in range(N)]

for i in range(N):
    for j in range(i + 1, N):
        anss[min(
            abs(i - j), 
            abs(X - i) + 1 + abs(j - Y),
            abs(Y - i) + 1 + abs(X - j)
        )] += 1

for i in range(1, N):
    print(anss[i])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=sorted(list(map(int,input().split())))
    cnt=0

    for i in range(n):
        if i<n-1 and A[i+1]==A[i]:
            continue
        for j in range(i):
            if A[i]%A[j]==0:
                break
        else:
            cnt+=1
    print(cnt)

    
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

    l=[0]*(10**6+5)

    for i in A:
        if l[i]!=0:
            l[i]+=1
            continue
        for j in range(i,10**6+5,i):
            l[j]+=1
    
    cnt=0
    for i in A:
        if l[i]==1:
            cnt+=1
    print(cnt)




    
resolve()
### BUGGY CODE ###

import collections

n = int(input())
s = [str(input()) for _ in range(n)]

c = collections.Counter(s)

for i in sorted(k for k in c if c[k] == max(c.values())):
    print(i)

### FIXED CODE ###

n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

m = max(d.values())
for i in sorted(k for k in d if d[k] == m):
    print(i)
### BUGGY CODE ###

n = int(input())

for i in range(1, n+1):
    count = 0
    for x in range(1, int(i**(1/2))+1):
        for y in range(1, int(i**(1/2))+1):
            for z in range(1, int(i**(1/2))+1):
                if ((x+y+z)**2 - x*y - y*z - z*x) == i:
                    count += 1
    print(count)

### FIXED CODE ###

n = int(input())
ans = [0] * (n + 1)
 
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if val <= n:
                ans[val] += 1
 
print(*ans[1:], sep="\n")
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
for i in range(M):
    maxindex = A.index(max(A))
    A[maxindex] = A[maxindex]//2
print(sum(A))

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A = list(map(lambda x: x*(-1),A))
import heapq
heapq.heapify(A)

for i in range(M):
    maxA = (((heapq.heappop(A))*(-1))//2)*(-1)
    heapq.heappush(A,maxA)
   
    
print(sum(A)*-1)
### BUGGY CODE ###

import itertools

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

sum=0
mod = 1000000007
for v in itertools.combinations(A, 2):
    sum +=v[0]%mod *v[1]%mod
    sum = sum %mod
print(sum)


### FIXED CODE ###

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

mod= 10**9+7

A = sum(a)

ans=0

for i in a:
  A -= i
  A%=mod
  ans += A*i
  ans%=mod
print(ans)
### BUGGY CODE ###

s = input()
q = int(input())
reverseFlag = False


def getQuery():
    yield input().split()


for _ in range(q):
    for query in getQuery():
        if query[0] == "1":
            reverseFlag = not reverseFlag
        else:
            if query[1] == "1":
                s = (s + query[2]) if reverseFlag else (query[2] + s)
            else:
                s = (query[2] + s) if reverseFlag else (s + query[2])

if reverseFlag:
    s = s[::-1]

print(s)


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())
d = deque(s)
reverseFlag = False


def getQuery():
    yield input().split()


for _ in range(q):
    for query in getQuery():
        if query[0] == "1":
            reverseFlag = not reverseFlag
        else:
            if query[1] == "1":
                if reverseFlag:
                    d.append(query[2])
                else:
                    d.appendleft(query[2])
            else:
                if reverseFlag:
                    d.appendleft(query[2])
                else:
                    d.append(query[2])

ans = "".join(d)
if reverseFlag:
    ans = ans[::-1]

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

import math

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

cnt=0

for i in range(a,b+1):
  if i%c==0:
    cnt+=1
  if i%d==0:
    cnt+=1

def lcm(x,y):
  return (x*y)//math.gcd(x,y)

lcm_cd=lcm(c,d)

for i in range(a,b+1):
  if i%lcm_cd==0:
    cnt-=1


print(b-a+1-cnt)

### FIXED CODE ###

import math
a,b,c,d=map(int,input().split())

cyaku=b//c
dyaku=b//d


cds=b//((c*d)//(math.gcd(c,d)))

x=b-(cyaku+dyaku-cds)

cyaku2=(a-1)//c
dyaku2=(a-1)//d

cds2=(a-1)//((c*d)//(math.gcd(c,d)))

y=(a-1)-(cyaku2+dyaku2-cds2)

print(x-y)
### BUGGY CODE ###

s = input()
dp = [[0 for _ in range(0,4)] for _ in range(0,len(s)+1)]
dp[len(s)][3] = 1
dp[len(s)][0] = 0
dp[len(s)][1] = 0
dp[len(s)][2] = 0
abc = "ABC".index
for i in range(len(s)-1,-1,-1):
    m = 1
    if s[i] ==  "?":
        m=3
    dp[i][3] += m * dp[i+1][3]
for i in range(len(s)-1,-1,-1):
    if s[i] == "?":
        dp[i] = [
        dp[i+1][0]*3+ dp[i+1][1]
        ,dp[i+1][1]*3+ dp[i+1][2]
        ,dp[i+1][2]*3 + dp[i+1][3]
        ,dp[i+1][3]*3
        ]
    else:
        dp[i] = [
        dp[i+1][0]
        ,dp[i+1][1]
        ,dp[i+1][2]
        ,dp[i+1][3]
        ]
        num = abc(s[i])
        dp[i][num] += dp[i+1][num+1]
# for i in range(len(s),-1,-1):
#     print(dp[i])
print(dp[0][0] % (10**9 + 7))


### FIXED CODE ###

s = input()
dp = [0 for _ in range(0,4)]
dp[3] = 1
dp[0] = 0
dp[1] = 0
dp[2] = 0
abc = "ABC".index
mod = 10**9 + 7
for i in range(len(s)-1,-1,-1):
    if s[i] == "?":
        dp = [
        (dp[0]*3+ dp[1])%mod
        ,(dp[1]*3+ dp[2])%mod
        ,(dp[2]*3 + dp[3])%mod
        ,(dp[3]*3)%mod
        ]
    else:
        num = abc(s[i])
        dp[num] += dp[num+1] % mod
print(dp[0] %mod)
### BUGGY CODE ###

string = input()
x, y = map(int, input().split())

xy = True
x_s = []
y_s = []
cnt = 0
for s in string:
    if s == "F":
        cnt += 1
    else:
        if xy:
            x_s.append(cnt)
            xy = False
        else:
            y_s.append(cnt)
            xy = True
        cnt = 0
if xy:
    x_s.append(cnt)
    xy = False
else:
    y_s.append(cnt)
    xy = True
x_can = [False for _ in range(8001)]
y_can = [False for _ in range(8001)]

x_can[x_s[0]] = True
for xx in x_s[1:]:
    for i in range(8000, xx - 1, -1):
        if x_can[i - xx]:
            x_can[i] = True

y_can[0] = True
for yy in y_s:
    for i in range(8000, yy - 1, -1):
        if y_can[i - yy]:
            y_can[i] = True
            
x_pos = (x + sum(x_s))
y_pos = (y + sum(y_s))
if x_pos % 2 == 1 or y_pos % 2 == 1:
    print("No")
elif x_can[x_pos // 2] and y_can[y_pos // 2]:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

string = input()
x, y = map(int, input().split())

xy = True
x_s = []
y_s = []
cnt = 0
for s in string:
    if s == "F":
        cnt += 1
    else:
        if xy:
            x_s.append(cnt)
            xy = False
        else:
            y_s.append(cnt)
            xy = True
        cnt = 0
if xy:
    x_s.append(cnt)
    xy = False
else:
    y_s.append(cnt)
    xy = True
x_can = [False for _ in range(8001)]
y_can = [False for _ in range(8001)]

x_can[x_s[0]] = True
for xx in x_s[1:]:
    for i in range(8000, xx - 1, -1):
        if x_can[i - xx]:
            x_can[i] = True

y_can[0] = True
for yy in y_s:
    for i in range(8000, yy - 1, -1):
        if y_can[i - yy]:
            y_can[i] = True
            
x_pos = (x + sum(x_s))
y_pos = (y + sum(y_s))
if x_pos % 2 == 1 or y_pos % 2 == 1:
    print("No")
elif x_can[x_pos // 2] and y_can[y_pos // 2]:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N,M = map(int,input().split())
P = []

Indexs = []
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs.append(y)
	Syuturyoku.append(("0","0"))

for i in range(len(P)):
	P[i].sort()
	P[i] = list(map(str,P[i]))


for i in range(len(P)):
	if(len(P[i])>1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			si = str(si)
			x = j+1
			x = str(x)
			bangou = list(map(str,si))
			bangou_len = int(len(bangou))
			bangou_ushiro = list(map(str,x))
			bangou_ushiro_len = int(len(bangou_ushiro))
			if(len(bangou)<6):
				for zero in range(6-bangou_len):
					bangou.insert(0,'0')
			if(len(bangou_ushiro)<6):
				for zero in range(6-bangou_ushiro_len):
					bangou_ushiro.insert(0,'0')

			mojiretsu = ''
			for k in bangou:
				mojiretsu += k
			mojiretsu2 = ''
			for k2 in bangou_ushiro:
				mojiretsu2 += k2

			a = Indexs.index(int(atai))
			Syuturyoku[a] = (mojiretsu,mojiretsu2)
for i in range(M):
	print(Syuturyoku[i][0]+Syuturyoku[i][1])


### FIXED CODE ###

N,M = map(int,input().split())
P = []

Indexs = {}
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs[y] = i
	Syuturyoku.append(0)

for i in range(len(P)):
	P[i].sort()
	# P[i] = list(map(str,P[i]))


for i in range(N):
	if (len(P[i]) > 1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			# si = str(si)
			x = j+1
			# x = str(x)
			# bangou = list(map(str,si))
			# bangou_len = int(len(bangou))
			# bangou_ushiro = list(map(str,x))
			# bangou_ushiro_len = int(len(bangou_ushiro))
			# if(len(bangou)<6):
			# 	for zero in range(6-bangou_len):
			# 		bangou.insert(0,'0')
			# if(len(bangou_ushiro)<6):
			# 	for zero in range(6-bangou_ushiro_len):
			# 		bangou_ushiro.insert(0,'0')

			# mojiretsu = ''
			# for k in bangou:
			# 	mojiretsu += k
			# mojiretsu2 = ''
			# for k2 in bangou_ushiro:
			# 	mojiretsu2 += k2

			a = Indexs[atai]
			Syuturyoku[a] = (si, x)

for i in range(M):
	print('{0:06}{1:06}'.format(Syuturyoku[i][0], Syuturyoku[i][1]))
### BUGGY CODE ###

N = int(input())
power = 1

for i in range(1, N + 1, 1):
  power = i * power
  
print(power % (10 ** 9 + 7))

### FIXED CODE ###

N = int(input())
power = 1

for i in range(1, N + 1, 1):
 
  power = (i * power) % (10**9 + 7)
  
print(power)
### BUGGY CODE ###



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import deque

N = int(input())
p = deque()
for i in range(N):
    p.append(i+1)

x = p.popleft()
p.append(x)

#p = [2,3,4,5,6,7,8,9,10,11,12,13,1]

#print(p)
count = 0
for i in range(N):
    count += (i+1) % p[i]

print(count)

### FIXED CODE ###



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

# まず等差数列の和
n = N-2
count = (n*(4+(n-1)))//2

#print(count)

# 最終項
count += 1

print(count)
### BUGGY CODE ###

#!/usr/bin/env python3

# from typing import Optional
# from typing import List
# from typing import Dict
# from typing import Tuple
# from typing import Sequence


def main():
    N = int(input())
    A = list(map(lambda x: int(x), input().split()))

    sum = 0
    mod = 1000000000 + 7
    for i in range(N - 1):
        for j in range(i + 1, N):
            sum += A[i] * A[j]
            sum = sum % mod

    print(sum)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

# from typing import Optional
# from typing import List
# from typing import Dict
# from typing import Tuple
# from typing import Sequence


def main():
    N = int(input())
    A = list(map(lambda x: int(x), input().split()))

    sum = 0
    mod = 1000000000 + 7

    sumJ = 0
    for j in range(N):
        sumJ += A[j]

    for i in range(N - 1):
        sumJ -= A[i]
        sum += A[i] * sumJ
        sum = sum % mod

    print(sum)


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

X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

S = []
for a in A:
    for b in B:
        S.append(a+b)
S.sort()
C.sort()
T = C

L = X*Y

left = 3; right = max(A)+max(B)+max(C)+1
while left+1 < right:
    mid = (left + right) >> 1
    cur = L
    cnt = 0
    for c in C:
        while cur > 0 and S[cur-1]+c > mid:
            cur -= 1
        cnt += L - cur
    if cnt < K:
        right = mid
    else:
        left = mid
ans = []
for c in C:
    cur = L
    while cur > 0 and S[cur-1]+c >= left:
        v = S[cur-1]+c
        if v == left and len(ans) >= K:
            break
        ans.append(v)
        cur -= 1
ans.sort(reverse=1)
print(*ans[:K], sep='\n')

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

S = []
for a in A:
    for b in B:
        S.append(a+b)
S.sort()
C.sort()
T = C

L = X*Y

left = 3; right = max(A)+max(B)+max(C)+1
while left+1 < right:
    mid = (left + right) >> 1
    cur = L
    cnt = 0
    for c in C:
        while cur > 0 and S[cur-1]+c > mid:
            cur -= 1
        cnt += L - cur
    if cnt < K:
        right = mid
    else:
        left = mid
ans = []
for c in C:
    cur = L
    while cur > 0 and S[cur-1]+c >= left:
        v = S[cur-1]+c
        if v == left and len(ans) >= K:
            break
        ans.append(v)
        cur -= 1
ans.sort(reverse=1)
print(*ans[:K], sep='\n')
### BUGGY CODE ###

from heapq import*
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

stack=[]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x]=="#":
            grid[y][x]=0
            heappush(stack,(y,x))

for i in range(h*w):
    tmp=[]
    for my,mx in stack:
        for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
            if grid[my+y][mx+x]==".":
                grid[my+y][mx+x]=i+1
                #tmp.append([my+y,mx+x])
                heappush(tmp,(my+y,mx+x))
    if all(all(j!="." for j in i)for i in grid):
        print(max(max(i[1:-1])for i in grid[1:-1]))
        exit()
    stack=tmp

### FIXED CODE ###

from heapq import*
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

stack=[]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x]=="#":
            grid[y][x]=0
            stack.append((y,x))

for i in range(h*w):
    tmp=[]
    for my,mx in stack:
        for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
            if grid[my+y][mx+x]==".":
                grid[my+y][mx+x]=i+1
                tmp.append([my+y,mx+x])
    stack=tmp
    if len(tmp)==0:
        print(i)
        break
### BUGGY CODE ###

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

global res
global res_print
global flg
res=[0]*len(A)
res_print=[0]*len(A)

def test(X):
    if len(X)==1:
        if X[0]==1:
            res[0]=1
            #res_printに答えを入れる
            #res_print=res
            for s in range(len(res)):
                res_print[s]=res[s]
            return 1
        else:
            return 0
    else:
        flg=[0]*len(X)
        for i in range(len(X)):
            if X[i]==i+1:
                res[len(X)-1]=i+1
                X1=X[:i]
                X1.extend(X[i+1:])
                flg[i]=test(X1)
        return max(flg)

if test(A)== 0:
  print(-1)
else:
  for s in range(len(res)):
    print(res_print[s])


### FIXED CODE ###

import numpy as np

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

A=np.array(A)

global res

res=[0]*N

def test(A):
    if A.shape[0]==1:
        if A[0]==1:
            res[0]=1
            return 1
        else:
            return 0
    else:
        B=np.arange(len(A))+1
        C=max((A==B)*B)
        if C==0:
            return 0
        else:
            res[len(A)-1]=C
            return test(np.delete(A,C-1,0))

if test(A)==1:
  for i in range(N):
    print(res[i])
else:
  print(-1)
### BUGGY CODE ###

n=int(input())
mx=10**15
for i in range(1,n//2+1):
    if n%i==0 and n//i+i-2<mx:
        mx=n//i+i-2
print(mx)


### FIXED CODE ###

n=int(input())
mx=10**15
for i in range(1,int(n**.5+1)):
    if n%i==0 and n//i+i-2<mx:
        mx=n//i+i-2
print(mx)
### BUGGY CODE ###

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    tmp = x%y
    while not tmp == 0:
        x = y
        y = tmp
        tmp = x%y
    return y
N = int(input())
A = list(map(int,input().split()))

gcd_max = 0
for i in range(N):
    tmp = A[0]
    if i == 0:
        tmp = A[1]
    for j in range(N):
        if not j == i:
            tmp = gcd(tmp,A[j])
    if tmp > gcd_max:
        gcd_max = tmp
print(gcd_max)

### FIXED CODE ###

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

def GCD(x,y):
    while y != 0:
        x,y = y,x%y
    return x

l,r = [0],[0]
for i in range(N-1):
    l.append(GCD(l[-1],A[i]))
    r.append(GCD(r[-1],A[N-i-1]))

ans = 0
for i in range(N):
    ans = max(ans,GCD(l[i],r[N-i-1]))
print(ans)