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

from collections import defaultdict,deque

H, W = map(int, input().split())
S = list(map(int, input().split()))
G = list(map(int, input().split()))
S[0] -= 1
S[1] -= 1
G[0] -= 1
G[1] -= 1
c = [input() for i in range(H)]
dist = [[-1]*W for _ in range(H)]

for i in range(H):
    for g in range(W):
        if c[i][g] == "#":
            dist[i][g] = -2

checkList = set()
que = deque()
que.append(S)
dist[S[0]][S[1]] = 0

directions = [(0, -1), (0, 1), (1, 0), (-1, 0)]

cost = 0

while True:
    if len(que) == 0:
        cost += 1
        que = set()
        for h, w in checkList:
            for i in [-2, -1, 0, 1, 2]:
                for g in [-2, -1, 0, 1, 2]:
                    nh = h+i
                    nw = w+g
                    if nw < 0 or nw > W-1 or nh < 0 or nh > H-1:
                        continue
                    else:
                        if dist[nh][nw] == -1:
                            que.add((nh, nw))
        que = deque(que)
        checkList = set()
        if len(que) == 0:
            print(-1)
            exit()
    else:
        h, w = que.popleft()
        if h == G[0] and w == G[1]:
            print(cost)
            exit()
        for i in range(4):
            nh = h+directions[i][0]
            nw = w+directions[i][1]
            if nw < 0 or nw > W-1 or nh < 0 or nh > H-1:
                continue
            if dist[nh][nw] == -1:
                que.append((nh, nw))
                dist[nh][nw] = cost
            elif dist[nh][nw] == -2:
                checkList.add((h, w))


### FIXED CODE ###

from collections import defaultdict,deque

H, W = map(int, input().split())
S = list(map(int, input().split()))
G = list(map(int, input().split()))
S[0] -= 1
S[1] -= 1
G[0] -= 1
G[1] -= 1
c = [input() for i in range(H)]
dist = [[-1]*W for _ in range(H)]

for i in range(H):
    for g in range(W):
        if c[i][g] == "#":
            dist[i][g] = -2

checkList = set()
que = deque()
que.append(S)

directions = [(0, -1), (0, 1), (1, 0), (-1, 0)]

cost = 0

while True:
    if len(que) == 0:
        cost += 1
        que = set()
        for h, w in checkList:
            for i in range(-2, 3):
                for g in range(-2, 3):
                    nh = h+i
                    nw = w+g
                    if nw < 0 or nw > W-1 or nh < 0 or nh > H-1:
                        continue
                    else:
                        if dist[nh][nw] == -1:
                            que.add((nh, nw))
        que = deque(que)
        checkList = set()
        if len(que) == 0:
            print(-1)
            exit()
    else:
        h, w = que.popleft()
        dist[h][w] = cost
        if h == G[0] and w == G[1]:
            print(cost)
            exit()
        for i in range(4):
            nh = h+directions[i][0]
            nw = w+directions[i][1]
            if nw < 0 or nw > W-1 or nh < 0 or nh > H-1:
                continue
            if dist[nh][nw] == -1:
                que.append((nh, nw))
                dist[nh][nw] = cost
            elif dist[nh][nw] == -2:
                checkList.add((h, w))
### BUGGY CODE ###

# inputを高速化する。
import sys
import numpy as np

input = sys.stdin.readline

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

route = [0] * N

blocks = np.array(blocks)

for i in range(1, N):
    count = max(0, i-K)
    route[i] = min(route[count:i] + np.abs(blocks[count:i] - blocks[i]))

print(route[-1])

### FIXED CODE ###

# inputを高速化する。
import sys
import numpy as np

input = sys.stdin.readline

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

route = np.zeros(N, dtype=int)

blocks = np.array(blocks)

for i in range(1, N):
    count = max(0, i-K)
    route[i] = min(route[count:i] + np.abs(blocks[count:i] - blocks[i]))

print(route[-1])
### BUGGY CODE ###

h,w,m = map(int,input().split())
p = [[0 for i in range(w)]for i in range(h)]
hlist = [0 for i in range(h)]
wlist = [0 for i in range(w)]
for i in range(m):
    a,b = map(int,input().split())
    hlist[a-1] += 1
    wlist[b-1] += 1
    p[a-1][b-1] = 1
q = 0
for i in range(h):
    q = max(q,hlist[i])
s = []
for i in range(h):
    if hlist[i] == q:
        s.append(i)
r = 0
for i in range(w):
    r = max(r,wlist[i])
t = []
for i in range(w):
    if wlist[i] == r:
        t.append(i)
ans = 0
for i in range(len(s)):
    for j in range(len(t)):
        if p[s[i]][t[j]] == 1:
            pass
        else:
            ans = q+r
            break
if ans == 0:
    print(q+r-1)
else:
    print(ans)

### FIXED CODE ###

h,w,m = map(int,input().split())
p = []
hlist = [0 for i in range(h)]
wlist = [0 for i in range(w)]
for i in range(m):
    a,b = map(int,input().split())
    hlist[a-1] += 1
    wlist[b-1] += 1
    p.append([a-1,b-1])
q = 0
for i in range(h):
    q = max(q,hlist[i])
s = []
for i in range(h):
    if hlist[i] == q:
        s.append(i)
r = 0
for i in range(w):
    r = max(r,wlist[i])
t = []
for i in range(w):
    if wlist[i] == r:
        t.append(i)
z = 0
for i in range(m):
    if hlist[p[i][0]] == q and wlist[p[i][1]] == r:
        z += 1
if z == len(s)*len(t):
    print(q+r-1)
else:
    print(q+r)
### BUGGY CODE ###

import itertools
import math


LIM = 50
N,K = list(map(int,input().split(" ")))

Xs = []
Ys = []

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

Xs.sort()
Ys.sort()

ans = -1
for x1 in range(N):
    for x2 in range(x1 + 1,N):
        for y1 in range(N):
            for y2 in range(y1 + 1,N):
                cot = 0
                underX = Xs[x1]
                upperX = Xs[x2]
                underY = Ys[y1]
                upperY = Ys[y2]

                for k in range(N):
                    if   underX<= dots[k][0] <= upperX and underY <= dots[k][1] <= upperY:
                        cot += 1
                if cot >= K:
                    S = (upperX - underX) * (upperY - underY)
                    if ans == -1:
                        ans = S
                    ans = min( ans ,S)
print(ans)

### FIXED CODE ###

import itertools
import math


LIM = 50
N,K = list(map(int,input().split(" ")))

Xs = []
Ys = []

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

Xs.sort()
Ys.sort()

ans = -1
for x1 in range(N):
    for x2 in range(x1 + 1,N):
        for y1 in range(N):
            for y2 in range(y1 + 1,N):
                cot = 0
                underX = Xs[x1]
                upperX = Xs[x2]
                underY = Ys[y1]
                upperY = Ys[y2]

                for k in range(N):
                    if   underX<= dots[k][0] <= upperX and underY <= dots[k][1] <= upperY:
                        cot += 1
                if cot >= K:
                    S = (upperX - underX) * (upperY - underY)
                    if ans == -1:
                        ans = S
                    ans = min( ans ,S)
print(ans)
### BUGGY CODE ###

#2問目
NQ = input().split()
N,Q = int(NQ[0]), int(NQ[1])
S = input()
Answer = ""
P = [input().split() for i in range(Q)]
for i in range(Q):
    Answer += str(S.count("AC", int(P[i][0])-1, int(P[i][1]))) + "\n"
print(Answer)

### FIXED CODE ###

#2問目
NQ = input().split()
N,Q = int(NQ[0]), int(NQ[1])
S = input()
P = [input().split() for i in range(Q)]
 
#累積和
ruiseki = [0]*N
for i in range(1,N):
    if(S[i] == "C" and S[i-1] == "A"):
        ruiseki[i] = ruiseki[i-1] + 1
    else:
        ruiseki[i] = ruiseki[i-1]
 
for j in range(Q):
    print(ruiseki[int(P[j][1]) - 1] - ruiseki[int(P[j][0]) - 1])
### BUGGY CODE ###

import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      C[i]=min(C[i],C[i-a if i>a else 0]+b)

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()


### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

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

N, Q = map(int, input().split())
S = str(input())
li = []

for i in range(N-1):
  if S[i]=='A' and S[i+1]=='C':
    li.append(1)
  else:
    li.append(0)

for i in range(Q):
  l, r = map(int, input().split())
  s = li[l-1:r-1]
  ans = sum(s)
  print(ans)

### FIXED CODE ###

N, Q = map(int, input().split())
S = str(input())
li = []
cnt = 0

for i in range(N-1):
  if S[i]=='A' and S[i+1]=='C':
    cnt += 1
    li.append(cnt)
  else:
    li.append(cnt)

for i in range(Q):
  l, r = map(int, input().split())
  if l > 1:
    ans = li[r-2] - li[l-2]
  else:
    ans = li[r-2]
  print(ans)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int,input().split(" "))))
Q = int(input())
B = [list(map(int,input().split(" "))) for i in range(0,Q)]

for i in range(0,Q):
    A[A == B[i][0]] = B[i][1]
    print(np.sum(A))
#print("\n".join(list(map(str,A.tolist()))))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split(" ")))
Q = int(input())
B = [list(map(int,input().split(" "))) for i in range(0,Q)]
ans = sum(A)
num = collections.Counter(A)
for i in range(0,Q):
    before, after = B[i][0], B[i][1]
    ans += num[before] * (after - before)
    num[after] += num[before]
    num[before] = 0
    print(ans)
### BUGGY CODE ###

def main():
    N, P = map(int,input().split())

    C = 1
    while pow(C, N) <= P:
        C += 1

    for i in range(C, 0, -1):
        if P % pow(i, N) == 0:
            print(i)
            exit()

    print(1)
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N, P = map(int,input().split())

    if N == 1:
        print(P)
        exit()

    ans = 1
    d = 2
    while d * d <= P:
        cnt = 0
        while P % d == 0:
            P //= d
            cnt += 1
        ans *= pow(d, cnt//N)
        d += 1

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

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
D=[]
for i in range(X):
    for j in range(Y):
        D.append(A[X-1-i]+B[Y-1-j])
D.sort()
ans=[]
for i in range(min(K,len(D))):
    for j in range(min(K,Z)):
        ans.append(D[len(D)-1-i]+C[Z-1-j])
ans.sort()
for i in range(K):
    print(ans[len(ans)-1-i])

### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans=[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            else:
                ans.append(A[i]+B[j]+C[k])
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    A = sorted(A)
    for i in range(M):
        MD = A[-1]
        A[-1] = MD // 2
        A = sorted(A)
        if A[-1] == 0:
            break
    print(sum(A))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    while M > 0:
        A = sorted(A, reverse=True)
        MD = A[0] // 2
        for i, ai in enumerate(A):
            if ai > MD and M > 0:
                A[i] = ai//2
                M -= 1
            else:
                break
        if A[i] == 0:
            break
    print(sum(A))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)


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

# 両方から到達出来ないものに関する辺を無視してベルマンフォード
import sys
sys.setrecursionlimit(10**6)
n, m, p = map(int, input().split())
edges = []
to = [[] for _ in range(n)]
ot = [[] for _ in range(n)]
reachable_from_1 = [False] * n
reachable_to_n = [False] * n
ok = [False] * n
INF = float('inf')


def dfs(v):
    if reachable_from_1[v]:
        return
    reachable_from_1[v] = True
    for nv in to[v]:
        dfs(nv)


def rdfs(v):
    if reachable_to_n[v]:
        return
    reachable_to_n[v] = True
    for nv in ot[v]:
        rdfs(nv)


for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    c -= p
    c = -c
    edges.append((a, b, c))
    to[a].append(b)
    ot[b].append(a)
dfs(0)
rdfs(n - 1)
for i in range(n):
    ok[i] = reachable_from_1[i] and reachable_to_n[i]
d = [INF] * n
d[0] = 0
upd = True
step = 0
while upd:
    upd = False
    for e in edges:
        frm, to, cost = e
        if not ok[frm]:
            continue
        if not ok[to]:
            continue
        nd = d[frm] + cost
        if nd < d[to]:
            d[to] = nd
            upd = True
    step += 1
    if step > n:
        print(-1)
        exit()
ans = -d[n - 1]
ans = max(0, ans)
print(ans)


### FIXED CODE ###

# 両方から到達出来ないものに関する辺を無視してベルマンフォード
import sys
sys.setrecursionlimit(10**6)
n, m, p = map(int, input().split())
edges = []
to = [[] for _ in range(n)]
ot = [[] for _ in range(n)]
reachable_from_1 = [False] * n
reachable_to_n = [False] * n
ok = [False] * n
INF = float('inf')


def dfs(v):
    if reachable_from_1[v]:
        return
    reachable_from_1[v] = True
    for nv in to[v]:
        dfs(nv)


def rdfs(v):
    if reachable_to_n[v]:
        return
    reachable_to_n[v] = True
    for nv in ot[v]:
        rdfs(nv)


for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    c -= p
    c = -c
    edges.append((a, b, c))
    to[a].append(b)
    ot[b].append(a)
dfs(0)
rdfs(n - 1)
for i in range(n):
    ok[i] = reachable_from_1[i] and reachable_to_n[i]
d = [INF] * n
d[0] = 0
upd = True
step = 0
while upd:
    upd = False
    for e in edges:
        frm, to, cost = e
        if not ok[frm]:
            continue
        if not ok[to]:
            continue
        nd = d[frm] + cost
        if nd < d[to]:
            d[to] = nd
            upd = True
    step += 1
    if step > n:
        print(-1)
        exit()
ans = -d[n - 1]
ans = max(0, ans)
print(ans)
### BUGGY CODE ###

K = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
ans = 0
for a in range(K):
    a += 1
    if a == 1:
        ans += K*K
        continue
    for b in range(K):
        b += 1
        if b == 1:
            ans += K
            continue
        tmp = gcd(a, b)
        for c in range(K):
            c += 1
            if c == 1:
                ans += 1
                continue
            dada = gcd(tmp, c)
            ans += dada
            # print(dada)

print(ans)


### FIXED CODE ###

K = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
ans = 0
for a in range(K):
    a += 1
    if a == 1:
        ans += K*K
        continue
    for b in range(K):
        b += 1
        if b == 1:
            ans += K
            continue
        tmp = gcd(a, b)
        if tmp == 1:
            ans += K
            continue
        for c in range(K):
            c += 1
            if c == 1:
                ans += 1
                continue
            dada = gcd(tmp, c)
            ans += dada
            # print(dada)

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

n=int(input())
s=input()
# 1<=i<j<k<=n
# j-i!=k-j
# si!=sj, sj!=sk, si!=sk
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]:
            continue
        #ans+=len(s[j+1:].replace(s[i],'').replace(s[j],''))
        ans+=sum([x!=s[i] and x!=s[j] for x in s[j+1:]])
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1
print(ans)

### FIXED CODE ###

n=int(input())
s=input()
nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
for i in range(1,1+(n-1)//2):
      for j in range(n-2*i):
            if s[j]!=s[j+i] and s[j]!=s[2*i+j] and s[j+i]!=s[j+2*i]:
                  ans-=1
print(ans)
### BUGGY CODE ###

x = int(input())

if x == 1:
    a = 1
    b = 0
else:
    p = 2
    while True:
        while True:
            if x % p == 0:
                q = int(x / p)
                break
            else:
                p += 1
        ap = p
        am = p
        bp = 0
        bm = 0
        for i in range(1000):
            if ap**4 + ap**3 * bp + ap**2 * bp**2 + ap * bp**3 + bp**4 == q:
                a = ap
                b = bp
                break
            elif am**4 + am**3 * bm + am**2 * bm**2 + am * bm**3 + bm**4 == q:
                a = am
                b = bm
                break
            ap += 1
            bp += 1
            am -= 1
            bm -= 1
        else:
            p += 1
            continue
        break

print('{} {}'.format(a, b))

### FIXED CODE ###

x = int(input())

if x == 1:
    a = 1
    b = 0
else:
    p = 1
    while True:
        while True:
            if x % p == 0:
                q = int(x / p)
                break
            else:
                p += 1
        ap = p
        am = p
        bp = 0
        bm = 0
        for i in range(200):
            if ap**4 + ap**3 * bp + ap**2 * bp**2 + ap * bp**3 + bp**4 == q:
                a = ap
                b = bp
                break
            elif am**4 + am**3 * bm + am**2 * bm**2 + am * bm**3 + bm**4 == q:
                a = am
                b = bm
                break
            ap += 1
            bp += 1
            am -= 1
            bm -= 1
        else:
            p += 1
            continue
        break

print('{} {}'.format(a, b))
### BUGGY CODE ###

K,S = map(int,raw_input().split())
Count = 0
for x in range(K+1):
  for y in range(K+1):
    for z in range(K+1):
      if x+y+z==S:
        Count +=1
print Count

### FIXED CODE ###

K,S = map(int,raw_input().split())
Count = 0
for x in range(K+1):
  for y in range(K+1):
    if 0<=S-(x+y)<=K:
      Count +=1
print Count
### BUGGY CODE ###

k, s = map(int, input().split())

count = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                count += 1
print(count)

### FIXED CODE ###

k, s = map(int, input().split())

count = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
print(count)
### BUGGY CODE ###

def score(a,b):
    if b-a >= 0:
        return a
    else:
        return 10**6+1-b

N = int(input())

A = [0]*N
B = [0]*N

for i in range(N):
    S = input()
    a = 0
    b = 0
    for j in range(len(S)):
        if S[j] == ')':
            a += 1
        else:
            a -= 1
        A[i] = max(A[i],a)

        if S[-j-1] == '(':
            b += 1
        else:
            b -= 1
        B[i] = max(B[i],b)

#print('S',S)
#print('A',A)
#print('B',B)

L = sorted(list(range(N)),key = lambda i:score(A[i],B[i]))

SA = 0
SB = 0

#print('L',L)

for i in range(N):
    if SB > A[L[i]]:
        SB += B[L[i]] - A[L[i]]
    else:
        SA += A[L[i]]-SB
        SB = B[L[i]]
    #print(SA,SB)

if SA == 0 and SB == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

def score(a,b):
    if b-a >= 0:
        return a
    else:
        return 10**6+1-b

N = int(input())

A = [0]*N
B = [0]*N

for i in range(N):
    S = input()
    a = 0
    b = 0
    for j in range(len(S)):
        if S[j] == ')':
            a += 1
        else:
            a -= 1
        A[i] = max(A[i],a)

        if S[-j-1] == '(':
            b += 1
        else:
            b -= 1
        B[i] = max(B[i],b)

#print('S',S)
#print('A',A)
#print('B',B)

L = sorted(list(range(N)),key = lambda i:score(A[i],B[i]))

SA = 0
SB = 0

#print('L',L)

for i in range(N):
    if SB > A[L[i]]:
        SB += B[L[i]] - A[L[i]]
    else:
        SA += A[L[i]]-SB
        SB = B[L[i]]
    #print(SA,SB)

if SA == 0 and SB == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

S=input()
N=len(S)
if N<4:
  print(0)
  exit(0)
M=2019
X=[0]+[int(S[i])*pow(10,N-1-i)%M for i in range(N)]
import itertools
X = list(itertools.accumulate(X))
ans=0
x=[]
def search(l,r,X,N):
  _=0
  while r<N+1:
    if (X[l]-X[r])%M==0:
      _+=1
    r+=1
  return _
  
for l in range(N-2):
  if l in x:
    continue
  for r in range(l+4,N+1):
    if (X[l]-X[r])%M==0:
      x.append(r)
      _=search(r,r+4,X,N)
      ans+=(1+_+_)
      
print(ans)



### FIXED CODE ###

from collections import defaultdict
d = defaultdict(int)
S=input()
S=S[::-1]
i=1
x=0
MOD=2019
for s in S:
  x+=(int(s)*i)%MOD
  x%=MOD
  d[x]+=1
  i*=10
  i%=MOD
ans=0
for k in d.values():
  ans=ans+k*(k-1)//2
print(ans+d[0])
### BUGGY CODE ###

n=int(input())
l=[int(i) for i in input().split()]
f=[0 for i in range(n)]
s=set(l)
for i in s:
  f[i-1]=l.count(i)
print(*f)


### FIXED CODE ###

n=int(input())

f=[0 for i in range(n)]
for i in input().split():
  f[int(i)-1]+=1
print(*f)
### BUGGY CODE ###

n=int(input())
for i in range(1,3501):
  for j in range(1,3501):
    p=4*i*j-n*i-n*j
    if p>0:
      q=n*i*j
      if q%p==0:
        k=q//p
        break
  else:
    continue
  break
print(i,j,k)

### FIXED CODE ###

n=int(input())
for i in range(1,3501):
  for j in range(1,3501):
    if (4*i*j-n*i-n*j)!=0:
      if (n*i*j)%(4*i*j-n*i-n*j)==0 and (n*i*j)//(4*i*j-n*i-n*j)>0:
        k=(n*i*j)//(4*i*j-n*i-n*j)
        break
  else:
    continue
  break
print(i,j,k)
### BUGGY CODE ###

from collections import deque

def pr(A,n):
    for i in range(n):
        if i!=n-1:
            print(A[i],end=" ")
        else:
            print(A[i])

n=int(input())
que_r=deque()
c=0

for i in range(n):
    s=input().split()

    if s[0]=="insert":
        que_r.appendleft(int(s[1]))
    elif s[0]=="delete" and que_r.count(int(s[1]))>=1:
        que_r.remove(int(s[1]))
    elif s[0]=="deleteFirst":
        gav=que_r.popleft()
    elif s[0]=="deleteLast":
        gav=que_r.pop()

pr(que_r,len(que_r))


### FIXED CODE ###

from collections import deque


n=int(input())
que_r=deque()

for i in range(n):
    s=input()
    l=len(s)
    if s[0]=="i":
        que_r.appendleft(s[7:])
    elif s[6]==" ":
        try:
            que_r.remove(s[7:])
        except: pass
    elif l>10:
        que_r.popleft()
    elif l>6:
        que_r.pop()

print(*que_r)
### BUGGY CODE ###

import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, D+1):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if len(arr) == 0:
    arr.append(D)
print(len(arr)+1)

### FIXED CODE ###

import fractions

A, B =list(map(int, input().split()))
D = fractions.gcd(A,B)
arr = []
temp = D
if D == 1:
  pass
else:
  for i in range(2, int(-(-D**0.5//1)+1)):
    if temp%i == 0:
      while temp%i == 0:
        temp //= i
      arr.append(i)
  if temp != 1:
    arr.append(D)
print(len(arr)+1)
### BUGGY CODE ###

import fractions
N = int(input())
aLst = list(map(int, input().split()))

ansLst = []
for i in range(len(aLst)):
    ans = 0
    for j in range(len(aLst)):
        if i != j:
            ans = fractions.gcd(ans, aLst[j])
    ansLst.append(ans)
ansLst.sort(reverse=True)
print(ansLst[0])


### FIXED CODE ###

import fractions
N = int(input())
aLst = list(map(int, input().split()))

lans = 0
llst = [0] * (N + 1)
rans = 0
rlst = [0] * (N + 1)

for i in range(N):
    lans = fractions.gcd(lans, aLst[i])
    llst[i + 1] = lans

for i in range(N - 1, -1, -1):
    rans = fractions.gcd(rans, aLst[i])
    rlst[i] = rans

ansMax = 0
for i in range(N):
    ansMax = max(ansMax, fractions.gcd(llst[i], rlst[i + 1]))

print(ansMax)