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

## dijkstraで解く
import heapq

H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh_, dw_ = map(int, input().split())

fs = [input() for i in range(H)]

INF = 1 << 10
N = 10**4
dps = [[INF]*W for i in range(H)]
dps[ch-1][cw-1] = 0
q = []
heapq.heapify(q)
heapq.heappush(q,(0, (ch-1)*N+(cw-1)))
while q:
    cnt, n  = heapq.heappop(q)
    h,w = divmod(n, N)
    if cnt > dps[h][w]:continue
    dps[h][w] = cnt
    # 歩いた
    for dh in range(-2,3):
        for dw in range(-2,3):            
            hn = h + dh
            wn = w + dw
            if not 0 <= wn < W: continue
            if not 0 <= hn < H: continue
            if fs[hn][wn] == "#": continue
            if dps[hn][wn] != INF:continue
            if abs(dh) + abs(dw) <= 1:
                heapq.heappush(q, (cnt, hn*N+wn))
            else:
                heapq.heappush(q, (cnt+1, hn*N+wn))

ans = dps[dh_-1][dw_-1]
print(ans if ans != INF else -1)


### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh_, dw_ = map(int, input().split())

fs = []
for i in range(H):
    r = list(input())
    fs.append(r)

walks = [(-1,0),(1,0),(0,1),(0,-1)]
magics = []
for i in range(-2,3):
    for j in range(-2,3):
        if i==j==0:continue
        if (i,j) not in walks:
            magics.append((i,j))

INF = 1 << 50
dps = [[INF]*W for i in range(H)]
dps[ch-1][cw-1] = 0
q = deque([])
q.appendleft((ch-1,cw-1,0))
while len(q)>0:
    h,w,cnt = q.popleft()
    if cnt > dps[h][w]:continue
    dps[h][w] = cnt
    for dh, dw in walks:
        hn = h + dh
        wn = w + dw
        if 0<=hn<H and 0<=wn<W:
            if dps[hn][wn] != INF:continue
            if fs[hn][wn] == ".":
                q.appendleft((hn, wn, cnt))
    for dh, dw in magics:
        hn = h + dh
        wn = w + dw
        if 0<=hn<H and 0<=wn<W:
            if dps[hn][wn] != INF:continue
            if fs[hn][wn] == ".":
                q.append((hn, wn, cnt+1))

ans = dps[dh_-1][dw_-1]
print(ans if ans != INF else -1)
### BUGGY CODE ###

n = int(input())
ans = []

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.append(a)
print(len(ans))


### FIXED CODE ###

n = int(input())
ans = set() 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))
### BUGGY CODE ###

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

ans = 0
mod = 10**9+7
for i in range(N-1):
    for j in range(i+1,N):
        ans += (A[i]%mod) * (A[j]%mod)
        ans %= mod
print(ans)

### FIXED CODE ###

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

# 累積和を使う
for i in range(1,N+1):
    B[i] = A[i-1]+B[i-1]
# 累積和の配列完成
# print(B) 

ans = 0
MOD = 10**9+7
for i in range(N):
    ans += A[i] * (B[N] - B[i+1])
    ans %= MOD
print(ans)
### BUGGY CODE ###

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

dp = {}
mod = 998244353

for k in range(K+1):
    dp[(1,k)] = M

for i in range(2,N+1):
    for k in range(K+1):
        if k == 0:
            dp[(i, 0)] = dp[(i-1,0)]*(M-1)%mod
        else:
            dp[(i,k)] = dp[(i-1,k)]*(M-1)%mod + dp[(i-1,k-1)]%mod
            dp[(i,k)] %= mod

ans = 0
for k in range(1, K+1):
    ans += dp[(N,k)] % mod
    ans %= mod

print(dp[N,K])

### FIXED CODE ###

N, M, K = map(int, input().split())
mod = 998244353

fact = [1 for i in range(N+1)]
fact_inv = [1 for i in range(N+1)]

for i in range(1, N+1):
    fact[i] = fact[i-1] * i % mod
    fact_inv[i] = pow(fact[i], mod-2, mod)

def cmb(n,k):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans = 0

for k in range(K+1):
    now = M * pow(M-1, N-k-1, mod) * cmb(N-1,k)
    ans = (ans + now % mod) % mod

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

n, k = map(int, input().split())
hl = list(map(int, input().split()))
hl_s = sorted(hl, reverse=True)

if k >= n:
    print(0)
else:
    for _ in range(k):
        hl_s.pop(0)
    print(sum(hl_s))

### FIXED CODE ###

n, k = map(int, input().split())
hl = list(map(int, input().split()))
hl_s = sorted(hl, reverse=True)

if k >= n:
    print(0)
else:
    del hl_s[0:k]
    print(sum(hl_s))
### BUGGY CODE ###

from sys import stdin
input = stdin.readline

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

is_continue = [False] * n

A.sort()
ans = 0

for i in range(0, n - 1):
    if is_continue[i]:
        continue
    else:
        ans += 1
        if A[i] == A[i + 1]:
            ans -= 1
        for j in range(i + 1, n):
            if A[j] % A[i] == 0:
                is_continue[j] = True

if not is_continue[n - 1]:
    ans += 1

print(ans)
# print(A)
# print(is_prime)
# print(is_continue)


### FIXED CODE ###

from sys import stdin
input = stdin.readline

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

A.sort()

is_ok = [False] * (10 ** 6 + 1)
is_exist = [False] * (10 ** 6 + 1)

for a in A:
    if is_exist[a]:
        is_ok[a] = False
    else:
        is_exist[a] = True
        is_ok[a] = True
        for i in range(1, 10 ** 6 // a + 1):
            if a * i <= 10 ** 6:
                is_exist[a * i] = True

print(is_ok.count(True))
### BUGGY CODE ###

INF = 1000000000

def solve(s,g,E,n):
  D = [INF for i in range(n)]
  D[s] = 0
  V = [(s,0)]
  U = [0 for i in range(n)]
  while V:
    v = V.pop(0)
    U[v[0]] = 1
    for e in E[v[0]]:
      if U[e[0]] == 0 and D[v[0]] + e[1] < D[e[0]]:
        D[e[0]] = D[v[0]] + e[1]
        V.append((e[0],D[e[0]]))
        V = sorted(V,key=lambda x:x[1])
  if D[g] >= INF:
    print(-1)
  else:
    print(D[g])

while True:
  try:
    n,k = list(map(int,input().split()))
    if n == 0 and k == 0:
      break
    E = [[] for i in range(n)]
    for i in range(k):
      lst = list(map(int,input().split()))
      if lst[0] == 0:
        solve(lst[1] - 1, lst[2] - 1, E, n)
      elif lst[0] == 1:
        E[lst[1] - 1].append([lst[2] - 1, lst[3]])
        E[lst[2] - 1].append([lst[1] - 1, lst[3]])
  except EOFError:
    break


### FIXED CODE ###

from heapq import heappush,heappop

def dij(s,g,E):
  h = []
  U = []
  heappush(h,(0,s))
  while h:
    v = heappop(h)
    if v[1] == g:
      if v[0] >= INF:print(-1)
      else:print(v[0])
      break
    U.append(v[1])
    for e in E[v[1]]:
      if not e[0] in U:
        heappush(h,(v[0] + e[1],e[0]))
  else:print(-1)
INF = 100000000
while True:
  try:
    n,k = map(int,input().split())
    if n == 0 and k == 0: break
    E = [[] for i in range(n)]
    for _ in range(k):
      lst = list(map(int,input().split()))
      if lst[0] == 0:
        dij(lst[1] - 1, lst[2] - 1, E)
      else:
        E[lst[1] - 1].append([lst[2] - 1, lst[3]])
        E[lst[2] - 1].append([lst[1] - 1, lst[3]])

  except EOFError:
    break
### BUGGY CODE ###

from collections import Counter

n,m = map(int,input().split())
s = ""
for i in range(m):
    a,b = input().split()
    s = s + a + b
n_max = 5
for i in range(n_max):
    counter = Counter(s)
    if counter[str(i)] % 2 != 0:
        print("NO")
        break
if i == n_max -1:
    print("YES")

### FIXED CODE ###

from collections import Counter

n,m = map(int,input().split())
s = ""
for i in range(m):
    s = s + input()
counter = Counter(s)
for i in range(n+1):
    if counter[str(i)] % 2 != 0:
        print("NO")
        break
if i == n:
    print("YES")
### BUGGY CODE ###

n, m = map(int, input().split())
lr = []
l1 = []
l2 = []

for i in range(m):
    l,r = map(int,input().split())
    lr.append([l,r])
for i in range(0, lr[0][1] - lr[0][0]+1):
    l1.append(lr[0][0] + i)

for i in range(1, m):
    for j in range(0, lr[i][1] - lr[i][0]+1):
        l2.append(lr[i][0]+j)
    l1 = list(set(l1) & set(l2))
    l2 = []
    
print(len(l1))


### FIXED CODE ###

n, m = map(int, input().split())
L = []
R = []

for i in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)
if min(R) - max(L) + 1 >= 0:
    print(min(R) - max(L) + 1)
else:
    print(0)
### BUGGY CODE ###

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

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
hp = [0] * (n+1)
for i in range(len(s)):
  hp[i+1] = hp[i] + (1 if s[i:i+2] == 'AC' else 0)
for _ in range(q):
  l, r = map(int, input().split())
  print(hp[r-1] - hp[l-1])
### BUGGY CODE ###

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

for i in range(n - 1):
    for j in range(n - i - 1):
        ans += a[i] * a[j + i + 1]

print(ans % (10 ** 9 + 7))        


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
c = sum(a)

for i in range(n - 1):
    c = c - a[i]
    ans += a[i] * c

print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

from copy import deepcopy
s=input()
x,y=map(int,input().split())
a=[0]*8000
b=[0]*8000
tmp=0
T=True
asize=0
bsize=0
for i in s:
    if i=="T":
        tmp=1-tmp
        T=True
    elif tmp==0:
        if T:
            asize+=1
            T=False
        a[asize-1]+=1
    else:
        if T:
            bsize+=1
            T=False
        b[bsize-1]+=1
c={0}
for i in range(asize):
    d=set()
    if i==0:
        if s[0]=="T":
            d.add(-a[i])
        d.add(a[i])
    else:
        for j in c:
            d.add(j+a[i])
            d.add(j-a[i])
    c=deepcopy(d)
if not x in c:
    print("No")
    quit()
c={0}
for i in range(bsize):
    d=set()
    for j in c:
        d.add(j+b[i])
        d.add(j-b[i])
    c=deepcopy(d)
if not y in c:
    print("No")
    quit()
print("Yes")


### FIXED CODE ###

s=input()
x,y=map(int,input().split())
a=[0]*8000
b=[0]*8000
tmp=0
T=True
asize=0
bsize=0
for i in s:
    if i=="T":
        tmp=1-tmp
        T=True
    elif tmp==0:
        if T:
            asize+=1
            T=False
        a[asize-1]+=1
    else:
        if T:
            bsize+=1
            T=False
        b[bsize-1]+=1
c={0}
for i in range(asize):
    d=set()
    if i==0:
        if s[0]=="T":
            d.add(-a[i])
        d.add(a[i])
    else:
        for j in c:
            d.add(j+a[i])
            d.add(j-a[i])
    c=d
if not x in c:
    print("No")
    quit()
c={0}
for i in range(bsize):
    d=set()
    for j in c:
        d.add(j+b[i])
        d.add(j-b[i])
    c=d
if not y in c:
    print("No")
    quit()
print("Yes")
### BUGGY CODE ###

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

a_ls=[]
b_ls=[]
c_ls=[]
d_ls=[]

for vnwrjvnwakn in range(Q):
	abcd=list(map(int, input().split()))
	a_ls+=[abcd[0]]
	b_ls+=[abcd[1]]
	c_ls+=[abcd[2]]
	d_ls+=[abcd[3]]



import itertools
As=itertools.combinations_with_replacement(range(1,M+1),N)
ans=0
for A in As:
	score=0
	for i in range(Q):
		if list(A)[b_ls[i]-1]-list(A)[a_ls[i]-1]==c_ls[i]:
			score+=d_ls[i]
	
	ans=max(ans,score)


print(ans)


### FIXED CODE ###

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

a_ls=[]
b_ls=[]
c_ls=[]
d_ls=[]

for vnwrjvnwakn in range(Q):
	abcd=list(map(int, input().split()))
	a_ls+=[abcd[0]]
	b_ls+=[abcd[1]]
	c_ls+=[abcd[2]]
	d_ls+=[abcd[3]]



import itertools
As=itertools.combinations_with_replacement(range(1,M+1),N)
ans=0
for A in As:
	score=0
	Als=list(A)
	for i in range(Q):
		if Als[b_ls[i]-1]-Als[a_ls[i]-1]==c_ls[i]:
			score+=d_ls[i]
	
	ans=max(ans,score)


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

def res(D, p):
    if len(D)==1:
      return D[0][p] if p==0 else -D[0][p]
    else:
      m=max(D, key=lambda x:x[p])
      tmp=[d for d in D if d[p]==m[p]]
      t=max(tmp, key=lambda x:x[abs(p-1)])
      D.remove(t)
      return res(D, abs(p-1)) + (t[p] if p==0 else -t[p])
      
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
  
print(res(D, 0))



### FIXED CODE ###

N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)
### BUGGY CODE ###

N = int(input())
A = input().split()
A = [int(s) for s in A]

sum = 1
i = 0
while i < len(A):
    sum *= A[i]
    i+=1
    if sum > 1000000000000000000 and 0 not in A:
      break

if sum > 1000000000000000000:
    sum = -1

print(sum)

### FIXED CODE ###

N = int(input())
A = input().split()
A = [int(s) for s in A]

sum = 1

if 0 in A:
    sum = 0

else:
    for i in range(len(A)):
        sum *= A[i]
        if sum > 1000000000000000000:
            break
    
if sum > 1000000000000000000:
    sum = -1

print(sum)
### BUGGY CODE ###

# AtCoder Beginner Contest 157
# E - Simple String Queries
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
OFS = ord('a')
_ = input()
S = [ord(s)-OFS for s in input()[:-1]]

D = [[] for _ in [0]*26]
for i, s in enumerate(S):
    D[s].append(i)

for _ in [0]*int(input()):
    Q = input()[:-1].split()
    if Q[0] == '1':
        i, c = int(Q[1])-1, ord(Q[2])-OFS
        s, S[i] = S[i], c

        D[s].pop(bisect_left(D[s], i))
        insort_left(D[c], i)

    else:
        l, r = int(Q[1])-1, int(Q[2])-1

        cnt = 0
        for L in D:
            i = bisect_left(L, l)
            if i < len(L) and L[i] <= r:
                cnt += 1

        print(cnt)


### FIXED CODE ###

# AtCoder Beginner Contest 157
# E - Simple String Queries
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
OFS = ord('a')
_ = input()
S = list(input()[:-1])

D = [[] for _ in [0]*26]
for i, s in enumerate(S):
    D[ord(s)-OFS].append(i)

for _ in [0]*int(input()):
    Q = input()[:-1].split()
    if Q[0] == '1':
        i, c = int(Q[1])-1, Q[2]

        if S[i] != c:
            s = ord(S[i])-OFS
            D[s].pop(bisect_left(D[s], i))
            insort_left(D[ord(c)-OFS], i)
            S[i] = c

    else:
        l, r = int(Q[1])-1, int(Q[2])-1

        cnt = 0
        for L in D:
            i = bisect_left(L, l)
            if i < len(L) and L[i] <= r:
                cnt += 1

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

import collections
S = input()
N = len(S)
mod = 2019
div = [0]*N
for i in range(1, N+1):
    div[i-1] = int(S[N-i:N])%mod
d = collections.Counter(div)
print(sum(d.values())-len(d)+d[0])    


### FIXED CODE ###

import collections
S = input()
N = len(S)
mod = 2019
div = [0]*(N+1)
for i in range(N):
    div[i+1] = (div[i] + int(S[N-1-i])*pow(10,i,mod))%mod
d = collections.Counter(div[1::])
ans = d[0]
for i in d.values():
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

import sys
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
STX = [[int(x) for x in input().split()] for _ in range(N)]
EVENT = []
for s, t, x in STX:
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, 0, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

# print(EVENT)

STOP = set()
h = []
for t, op, x in EVENT:
    if not op:
        STOP.remove(x)
    elif op == 1:
        STOP.add(x)
        heappush(h, x)
    else:
        while h and h[0] not in STOP:
            heappop(h)
        ans[x] = h[0] if h else -1


print("\n".join(map(str, ans)))


### FIXED CODE ###

#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str,answer)))
### BUGGY CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [0 for _ in range(S+1)]
L[0] = 1
F = {0}
for i in range(N):
  X = [[i, L[i]] for i in F]
  for j in F:
    L[j] *= 2
    L[j] %= mod
  for j in X:
    if A[i] + j[0] <= S:
      L[A[i]+j[0]] += j[1]
      L[A[i]+j[0]] %= mod
      F.add(A[i]+j[0])
print(L[S])

### FIXED CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [0 for _ in range(S+1)]
L[0] = 1
F = {0}
for i in range(N):
  X = [[i, L[i]] for i in F]
  for j in F:
    L[j] *= 2
    L[j] %= mod
  for j in X:
    if A[i] + j[0] <= S:
      L[A[i]+j[0]] += j[1]
      L[A[i]+j[0]] %= mod
      F.add(A[i]+j[0])
print(L[S])
### BUGGY CODE ###

from bisect import bisect_left

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

a = [i for i in a if i <k]
n = len(a)

DP1 = [[False]*(k+1) for i in range(n+1)]
DP1[0][0] = True
DP2 = [[False]*(k+1) for i in range(n+1)]
DP2[0][0] = True
b = a[::-1]

for i in range(n):
    for j in range(k+1):
        if DP1[i][j]:
            DP1[i+1][j] = True
            if a[i]+j <= k:
                DP1[i+1][a[i]+j] = True
        if DP2[i][j]:
            DP2[i+1][j] = True
            if b[i]+j <= k:
                DP2[i+1][b[i]+j] = True

for i in range(n+1):
    DP1[i] = [j for j in range(k+1) if DP1[i][j]]
    DP2[i] = [j for j in range(k+1) if DP2[i][j]]

ans = 0
for i in range(n):
    use = False
    for j in DP1[i]:
        left = max(0, k-a[i]-j)
        right = k-j
        l = bisect_left(DP2[n-i-1], left)
        r = bisect_left(DP2[n-i-1], right)
        if r-l:
            use = True
            break
    if not use:
        ans += 1

print(ans)

### FIXED CODE ###

import numpy as np

def main():
    def check(m):
        DP = np.full(k+1, False)
        DP[0] = True
        for i in range(n):
            if i == m:
                continue
            DP[a[i]:] = np.logical_or(DP[a[i]:], DP[:k+1-a[i]])
        return any(DP[i] for i in range(k-a[m], k))

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

    a = [i for i in a if i <k]
    a.sort()
    n = len(a)

    left = -1
    right = n

    while right-left > 1:
        mid = (right+left)//2
        if check(mid):
            right = mid
        else:
            left = mid

    print(right)

main()
### BUGGY CODE ###

import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
#Ap = np.array(A)
#C = np.zeros(N + 1)
# index 順 要素のindex

ans = []
for i in range(N):
    ans.append(A.index(i+1)+1)
print(*ans)

### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()

B = range(1,N+1)
AB = zip(A,B)
# print(*AB)
sAB = sorted(AB)
# print(*sAB)
_,ans=zip(*sAB)
print(*ans)


#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
#Ap = np.array(A)
#C = np.zeros(N + 1)
# index 順 要素のindex

# ans = []
# for i in range(N):
#     ans.append(A.index(i+1)+1)
# print(*ans)
### BUGGY CODE ###



from functools import reduce
import fractions

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



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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)




problem()


### FIXED CODE ###

from functools import reduce
import fractions


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

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

    print(algorithm(N, A))


def algorithm(N, A):
    if N == 0:
        return 0
    if N == 1:
        return A[0]
    if N == 2:
        return max(A[0],A[1])

    L_i = 0
    R_i = [0] * N
    R_i[N - 1] = A[N - 1]
    R_i[N-2] = fractions.gcd(A[N-1], A[N-2])
    
    for i in range(3,N):
        R_i[N - i] = fractions.gcd(R_i[N - i + 1], A[N - i])

    maxGCD = R_i[1]
    for i in range(1, N-1):
        L_i = fractions.gcd(L_i, A[i - 1])
        tmp = fractions.gcd(L_i, R_i[i+1])
        if tmp > maxGCD:
            maxGCD = tmp

    L_i = gcd_list(A[:N-1])
    if L_i > maxGCD:
        maxGCD = L_i
    return maxGCD

problem()
### BUGGY CODE ###

import math
import sys


def E(i, x):
    if i == 1:
        return 5 * x
    return (2 * i + 1) * x


N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [0] + x

energy = sys.maxsize
for k in range(1, N + 1):
    res = (N + k) * X
    for i in range(1, N + 1):
        res += E(math.ceil(i / k), x[N - i + 1])
    energy = min(energy, res)
print(energy)


### FIXED CODE ###

from itertools import accumulate
def E(i, x):
    if i == 1:
        return 5 * x
    return (2 * i + 1) * x
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort(key=None, reverse=True)
x = list(accumulate(x))
x.insert(0, 0)
energy = 9223372036854775807
for k in range(1, N + 1):
    cost = (N + k) * X
    for i in range(1, N + 1):
        if i * k <= N:
            cost += E(i, x[i * k] - x[(i - 1) * k])
        else:
            cost += E(i, x[-1] - x[(i - 1) * k])
            break
    if cost < energy:
        energy = cost
print(energy)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
ans=0
for ai in a:
  if a.count(ai)%2!=0:
    ans+=1
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
c = Counter(a)
for i in c.values():
    if i%2!=0:
        ans+=1
print(ans)
### BUGGY CODE ###

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

answer = 1
for i in range(2,int(M//N)+1):
    if M % i == 0 and int(M/i) >= N:
            answer = i

print(answer)

### FIXED CODE ###

import math
N,M= map(int, input().split())
 
answer = 1
list = []
for i in range(1,math.floor(M**(1/2))+1):
    if M % i == 0 and int(M/i) >= N:
        answer = i
        list.append(int(M/i))
 
 
for k in list:
    if M/k >= N:
        answer = k
        break
 
print(answer)
### BUGGY CODE ###

import heapq

n, m = map(int, input().split())
a = [int(i) * -1 for i in input().split()]
heapq.heapify(a)

for _ in range(m):
    b, c = map(int, input().split())
    for _ in range(b):
        heapq.heappush(a, c * -1)

s = 0
for _ in range(n):
    s += heapq.heappop(a) * -1
print(s)

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

l = sorted(l, key=lambda x: x[1], reverse=True)

for b, c in l:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))