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

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

T = list(input() for _ in range(H))
S = [[False]*W for _ in range(H)]
for h in range(H):
    for w in range(W):
        if T[h][w] == ".":
            S[h][w] = True
d = [[10**9]*W for _ in range(H)]
d[Ch-1][Cw-1] = 0

D = deque([(Ch-1, Cw-1, 0)])
while D:
    h, w, c = deque.popleft(D)
    if c > d[h][w]:
        continue
    # 歩いて移動
    # 上
    if h > 0:
        if S[h-1][w] and c < d[h-1][w]:
            d[h-1][w] = c
            deque.append(D, (h-1, w, c))
    # 下
    if h < H-1:
        if S[h+1][w] and c < d[h+1][w]:
            d[h+1][w] = c
            deque.append(D, (h+1, w, c))
    # 左
    if w > 0:
        if S[h][w-1] and c < d[h][w-1]:
            d[h][w-1] = c
            deque.append(D, (h, w-1, c))
    # 右
    if w < W-1:
        if S[h][w+1] and c < d[h][w+1]:
            d[h][w+1] = c
            deque.append(D, (h, w+1, c))
    # ワープで移動
    for hh in range(max(0, h-2), min(H-1, h+2)+1):
        for ww in range(max(0, w-2), min(W-1, w+2)+1):
            if S[hh][ww] and d[hh][ww] > c+1:
                d[hh][ww] = c+1
                deque.append(D, (hh, ww, c+1))
if d[Dh-1][Dw-1] == 10**9:
    print(-1)
else:
    print(d[Dh-1][Dw-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())

S = [[False]*W for _ in range(H)]
for h in range(H):
    s = input()
    for w in range(W):
        if s[w] == ".":
            S[h][w] = True
d = [[10**9]*W for _ in range(H)]
d[Ch-1][Cw-1] = 0

D = deque([(Ch-1, Cw-1, 0)])
while D:
    h, w, c = deque.popleft(D)
    if c > d[h][w]:
        continue
    # 歩いて移動
    # 上
    if h > 0:
        if S[h-1][w] and c < d[h-1][w]:
            d[h-1][w] = c
            deque.appendleft(D, (h-1, w, c))
    # 下
    if h < H-1:
        if S[h+1][w] and c < d[h+1][w]:
            d[h+1][w] = c
            deque.appendleft(D, (h+1, w, c))
    # 左
    if w > 0:
        if S[h][w-1] and c < d[h][w-1]:
            d[h][w-1] = c
            deque.appendleft(D, (h, w-1, c))
    # 右
    if w < W-1:
        if S[h][w+1] and c < d[h][w+1]:
            d[h][w+1] = c
            deque.appendleft(D, (h, w+1, c))
    # ワープで移動
    for hh in range(max(0, h-2), min(H-1, h+2)+1):
        for ww in range(max(0, w-2), min(W-1, w+2)+1):
            if S[hh][ww] and d[hh][ww] > c+1:
                d[hh][ww] = c+1
                deque.append(D, (hh, ww, c+1))
if d[Dh-1][Dw-1] == 10**9:
    print(-1)
else:
    print(d[Dh-1][Dw-1])
### BUGGY CODE ###

import fractions
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
S = input(); T = input()
gcd = fractions.gcd(N,M)
N_prime = N //gcd; M_prime = M // gcd
for i in range(0,N,N_prime):
    for j in range(0,M,M_prime):
        if i * M_prime - j * N_prime == 0 and S[i] != T[j]:
            print(-1)
            exit()
print(N*M // gcd)

### FIXED CODE ###

import fractions
N,M = map(int,input().split())
S = input(); T = input()
gcd = fractions.gcd(N,M)
N_prime = N //gcd; M_prime = M // gcd
for i in range(0,N,N_prime):
    for j in range(0,M,M_prime):
        if i * M_prime - j * N_prime == 0 and S[i] != T[j]:
            print(-1)
            exit()
print(N*M // gcd)
### BUGGY CODE ###

N = int(input())
l = [input() for _ in range(N)]
m = set(l)
d = dict()

for name in m:
  d[name] = l.count(name)
  
max_in_d = max(d.values())
max_kv_list = sorted([kv[0] for kv in d.items() if kv[1] == max_in_d])
for name in max_kv_list:
  print(name)


### FIXED CODE ###

#!/usr/bin/env python3
from collections import Counter

def solve(l):
    d = Counter(l)
    d_max = max(d.values())
    max_d_list = sorted([k[0] for k in d.items() if k[1] == d_max])
    return max_d_list



def main():
    N = int(input())
    l = [input() for _ in range(N)]
    d = solve(l)
    for a in d:
        print(a)
    return

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

N = int(input())
A_list = list(map(int,input().split()))
cnt = 0
for i in range(1,N):
    for j in range(i+1, N+1):
        cnt += A_list[i-1] * A_list[j-1]
        if cnt >= (10**9 + 7):
            cnt %= (10**9 + 7)
print(cnt)

### FIXED CODE ###

from itertools import accumulate
N = int(input())
A_list = list(map(int,input().split()))
B_list = A_list[::-1]
C_list = list(accumulate(B_list))
D_list = C_list[::-1]
cnt = 0
for i in range(1,N):
    cnt += (A_list[i-1] * D_list[i]) % (10**9 + 7)

    if cnt >= (10**9 + 7):
        cnt -= (10**9 + 7)
print(cnt)
### BUGGY CODE ###

def main2(N,h,K):
    inf = 2**31 -1
    dp = [inf] * N
    dp[0] = 0
    for i in range(1, N):
        for k in range(1, K+1):
            if i-k >= 0:
                dp[i] = min(dp[i], dp[i-k] + abs(h[i-k] - h[i]))
            else:
                break
    return dp[N-1]

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

print(main2(N,h,K))

### FIXED CODE ###

def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))
### BUGGY CODE ###

# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
cnt = 0
for i in range(b+1)[a:]:
    cnt += (((i % c) != 0) and ((i % d) != 0))
print(cnt)


### FIXED CODE ###

# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1 = d if c < d else c
d1 = c if c < d else d
while d1 != 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = int((c * d) / e)
a -= 1
cnt = (b - a) + int(b // e) - int(a // e) - int(b // c) + int(a // c) - int(b // d) + int(a // d)
print(cnt)
### BUGGY CODE ###

from collections import Counter

N = int(input())
S = []
for _ in range(N):
    S.append(list(input()))

count = 0
for i in range(N):
    for j in range(i + 1, N):
        si = set(S[i])
        sj = set(S[j])
        if len(si) == len(sj) and si == sj:
            count += 1
        else:
            ci = Counter(S[i])
            cj = Counter(S[j])
            if ci == cj:
                count += 1
print(count)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = []
for _ in range(N):
    S.append("".join(sorted(input())))

c = Counter(S)
print(sum([k*(k-1)//2 for k in c.values()]))
### BUGGY CODE ###

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

dp = [[[0 for i in range(s + 1)] for i in range(n + 1)] for i in range(n + 1)]
dp[0][0][0] = 1
max_sum = 0
for i in range(1, n + 1):
    max_sum += a[i-1]
    for j in range(i + 1):
        for k in range(min(max_sum + 1, s + 1)):
            if j != 0:
                if k >= a[i-1]:
                    dp[i][j][k] = (dp[i-1][j-1][k-a[i-1]] + dp[i-1][j][k]) % mod
                else:
                    dp[i][j][k] = dp[i-1][j][k]
            else:
                dp[i][j][k] = dp[i-1][j][k]
dp2 = [dp[n][i][s] for i in range(n + 1)]
ans = 0
for i in range(n + 1):
    temp = dp2[i] * pow(2, n - i, mod)
    ans += temp
    ans %= mod
print(ans)

### FIXED CODE ###

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

temp = [1] + [0] * s
for i in range(n):
    temp2 = [0] * (s + 1)
    for j in range(s + 1):
        temp2[j] += temp[j] * 2
        temp2[j] %= mod
    for j in range(s + 1 - a[i]):
        temp2[j + a[i]] += temp[j]
        temp2[j + a[i]] %= mod
    temp = temp2
print(temp[s])
### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif a < K:
            r = test
        else:# sum == K
            r = test
    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += (a - eps) // int(l)
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        #print(l, r)
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:# sum == K
            r = test
        if int(r) == r and r-l < 1:
            print(int(r))
            return

    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

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

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

max_a = max(A)
filtered = [b_i for b_i in B if b_i > max_a]
sum_b = sum(filtered)
if sum_b <= H:
    print(-(-(H - sum_b) // max_a) + len(filtered))
else:
    filtered.sort()
    filtered.reverse()
    print(len([x for x in [sum(filtered[:i + 1])
                           for i in range(N)] if x < H]) + 1)


### FIXED CODE ###

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

max_a = max(A)
filtered = [b_i for b_i in B if b_i > max_a]
sum_b = sum(filtered)
if sum_b <= H:
    print(-(-(H - sum_b) // max_a) + len(filtered))
else:
    filtered.sort()
    filtered.reverse()
    s = 0
    for i in range(len(filtered)):
        s += filtered[i]
        if s >= H:
            print(i + 1)
            break
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 9)
from bisect import bisect, bisect_left


class Node:
    def __init__(self, idx):
        self.idx = idx
        self.v = 0
        self.parent = None
        # self.children = []

    def make_tree(self, addval=0):
        self.v += addval
        keyidx = bisect_left(brs_keys, self.idx)
        while keyidx < len(brs_keys) and brs_keys[keyidx] == self.idx:
            ni = brs[keyidx][1]
            node = nodes[ni]
            # if not node.children:
            #     self.children.append(node)
            node.make_tree(self.v)
            keyidx += 1
        # for c in self.children:
        #     c.make_tree(self.v)

    def __str__(self):
        return str(self.idx)


N, Q = [int(_) for _ in input().split()]
nodes = [Node(i) for i in range(0, N)]

brs = []
for i in range(N - 1):
    a, b = [int(_) - 1 for _ in input().split()]
    brs.append((a, b))
    # brs.append((b, a))

brs.sort()
brs_keys = [b[0] for b in brs]

# for n in nodes:
#     print(n.idx, [str(c) for c in n.children])

for i in range(Q):
    p, x = [int(_) for _ in input().split()]
    nodes[p - 1].v += x
    # nodes[p - 1].add(x)

nodes[0].make_tree()

print(*[n.v for n in nodes])

### FIXED CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

N, Q = [int(_) for _ in input().split()]

edges = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = [int(_) for _ in input().split()]
    edges[a].append(b)
    edges[b].append(a)

P = [0] * (N + 1)

for q in range(Q):
    p, x = [int(_) for _ in input().split()]
    P[p] += x

que = deque()
que.append((1, 0))

while que:
    v, parent = que.popleft()
    P[v] += P[parent]
    for next_v in edges[v]:
        if next_v == parent: continue
        que.append((next_v, v))

# def f(v, parent=0):
#     P[v] += P[parent]
#
#     for next_v in edges[v]:
#         if next_v == parent: continue
#         f(next_v, v)
#
#
# f(1)
print(*[P[i] for i in range(1, N + 1)])
### BUGGY CODE ###

s = " " + input()
t = " " + input()

dp = [[[] for _ in range(len(t))] for _ in range(2)]

import copy

for i in range(1, len(s)):
    i0 = i % 2
    i1 = (i - 1) % 2
    for j in range(1, len(t)):
        if len(dp[i1][j]) > len(dp[i0][j - 1]):
            dp[i0][j] = copy.copy(dp[i1][j])
        else:
            dp[i0][j] = copy.copy(dp[i0][j - 1])
        if s[i] == t[j]:
            if len(dp[i1][j - 1]) + 1 > len(dp[i0][j]):
                dp[i1][j - 1].append(s[i])
                dp[i0][j] = dp[i1][j - 1]
print("".join(dp[(len(s) - 1) % 2][len(t) - 1]))

### FIXED CODE ###

s = " " + input()
t = " " + input()

dp = [[0 for _ in range(len(t))] for _ in range(len(s))]

for i in range(1, len(s)):
    for j in range(1, len(t)):
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1] + (1 if s[i] == t[j] else 0))

i = len(s) - 1
j = len(t) - 1
c = 0
ans = []
ansl = dp[-1][-1]
while (c < ansl):
    if s[i] == t[j]:
        ans.append(s[i])
        i -= 1
        j -= 1
        c += 1
    else:
        if dp[i - 1][j] > dp[i][j - 1]:
            i -= 1
        else:
            j -= 1
ans.reverse()
print("".join(ans))
### BUGGY CODE ###

N,M = map(int,input().split())
L = []
R = []
total = 0
for i in range(0,M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
for i in range(1,N+1):
    for j in range(0,M):
        if L[j] <= i <= R[j]:
            if j == M-1:
                total += 1
        else:
            break

print(total)


### FIXED CODE ###

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

l_max = 1
r_min = N
for i in range(0,M):
    l,r = map(int,input().split())
    if l_max < l:
        l_max = l
    if r_min > r:
        r_min = r

if l_max > r_min:
    print(0)
else:
    print(r_min-l_max+1)
### BUGGY CODE ###

# ABC179-C AxB+C
N = int(input())
cnt = 0
for i in range(N+1):
    if i!= 0:
        for j in range(N+1):
            if j != 0:
                if N-(i*j) > 0:
                    cnt += 1
print(cnt)

### FIXED CODE ###

# ABC179-C AxB+C
N = int(input())
cnt = 0
for i in range(N):
    ii = i + 1
    for j in range(N+1):
        jj = j + 1
        if N-(ii*jj) > 0:
            cnt += 1
        else:
            break
print(cnt)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
ab = []
for _ in range(n):
    ai, bi = list(map(int, input().split()))
    ab.append([ai,bi])
    
ab.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1], reverse=True)

dayworked = set()
cnt = 0
for abi in ab:
    if abi[0] <= m:
        daycanwork = set(range(m-abi[0]+1))
        days = daycanwork - dayworked
        if len(days) == 0:
            continue
        day = max(days)
        dayworked.add(day)
        cnt += abi[1]   

print(cnt)

### FIXED CODE ###

import heapq

n, m = list(map(int, input().split()))
tasks = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    tasks.append((-bi, i, ai))
tasks.sort(key=lambda x: x[2])    
prtasks = []
money = 0
j = 0
for i in range(1,m+1):
    for k in range(j,len(tasks)):
        if tasks[k][2] <= i:
            heapq.heappush(prtasks, tasks[k])
            j += 1
        else:
            break
    if not prtasks:
        continue
    work = heapq.heappop(prtasks)
    money += work[0]

print(-money)
### BUGGY CODE ###

A, B, N = map(int, input().split())
Ymax=0

if N<B:
  L = N
else:
  L = B

for i in range(L):
  x = i+1
  Y = int(A*x//B) - A*(x//B)
  if Y>Ymax:
    Ymax = Y
print(Ymax)

### FIXED CODE ###

A, B, N = map(int, input().split())
Ymax=0
if A*N < B:
  print(0)
elif N<B:
  Ymax = A*N // B
  print(Ymax)
else:
  x = B-1
  Ymax = A*x//B - A*(x//B)
  print(Ymax)
### BUGGY CODE ###

import math
#math.floor
n, m = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
for i in range(m):
    a[a.index(max(a))] = a[a.index(max(a))]/2
result = 0
for i in a:
    result += math.floor(i)
print(result)

### FIXED CODE ###

from heapq import heapify, heappush, heappop
from math import floor
n, m = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
a = [x*(-1) for x in a]
heapify(a)
for _ in range(m):
    x = floor(-heappop(a)/2)*(-1)
    heappush(a, x)

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

N = int(input())
sum = 0
array = list(map(int,input().split()))
for i in range(1,N):
    print(array.count(i))
    sum += array.count(i)
print(0)


### FIXED CODE ###

N = int(input())
sum = 0
now = 1
for i in sorted(list(map(int,input().split()))):
    if(now == i):
        sum += 1
    else:
        print(sum)
        for j in range(i-now-1):
            print(0)
        now = i
        sum = 1
else:
    print(sum)
while(now < N):
    now += 1
    print(0)
### BUGGY CODE ###

import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

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

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def getInputStr():
    inputStr = str(input())
    return inputStr

data = getInputStr()

a = str(data)
listStr = []
listStr = list(a)

del listStr[len(listStr)-1]
listStr.reverse()

dp = [[0]*13 for _ in range(len(listStr)+1)]
dp[0][0] = 1
ordinal = 1

INF = 10 ** 9 + 7

for i in range(len(listStr)):
    if i ==0:
        keta = 1
    else:
        keta = pow(10, i)

    if listStr[i] == "?":
        for k in range(10):
            for j in range(13):
                dp[i+1][int(((k*keta)%13 + j) % 13)] += dp[i][j]
                # dp[i + 1][int(((k * ordinal) + j) % 13)] %= INF
    else:
        k = int(listStr[i])
        for j in range(13):
            dp[i + 1][int(((k*keta)%13 + j) % 13)] += dp[i][j]
            # dp[i + 1][int(((k*ordinal) + j) % 13)] %= INF


ans = dp[len(listStr)][5] % INF
print(ans)

### FIXED CODE ###

import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
nb = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    l = len(s)
    dp = [[0 for _ in range(13)] for __ in range(l + 1)]
    dp[0][0] = 1

    for i, si in enumerate(s):
        base = pow(10, l - i - 1, 13)

        if si == "?":
            for k in range(10):
                tmp = base * k % 13
                for j in range(13):
                    dp[i + 1][(j + tmp) % 13] += dp[i][j]
                    dp[i + 1][(j + tmp) % 13] %= MOD
        else:
            si = int(si)
            tmp = base * si % 13
            for j in range(13):
                dp[i + 1][(j + tmp) % 13] += dp[i][j]
                dp[i + 1][(j + tmp) % 13] %= MOD

    print(dp[l][5])


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

N = int(input())
A = []
for _ in range(N):
  a = int(input())
  A.append(a)

d = []
for i in range(N):
  ite = 0
  flag = True
  for j in range(len(d)):
    if d[j] < A[i]:
      ite = j
      flag = False
      break
  if flag:
    d.append(A[i])
  else:
    d[ite] = A[i]
print(len(d))

### FIXED CODE ###

import bisect
from collections import deque

N = int(input())
A = []
for _ in range(N):
  a = int(input())
  A.append(a)

b = deque([])
for a in A:
  if len(b) == 0:
    b.append(a)
  else:
    if a <= b[0]:
      b.appendleft(a)
    else:
      b[bisect.bisect_left(b, a) - 1] = a
print(len(b))
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().strip().split()))
sum=0
for i in range(0,n):
    x[i] %= (10**9+7)
for i in range(0,n-1):
    for j in range(i+1,n):
        sum += x[i]*x[j]
        if(sum>=(10**9+7)):
            sum %= (10**9+7)
print(sum)

### FIXED CODE ###

n = int(input())
x = list(map(int, input().strip().split()))
sum=0
minsum=0
for i in range(0,n):
    minsum += x[i]
for i in range(0,n-1):
    minsum-=x[i]
    sum += x[i]*minsum
    if(sum>10**9+7):
        sum%=(10**9+7)
print(sum)
### BUGGY CODE ###

import sys
import fractions
from functools import reduce
input = sys.stdin.readline

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

def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=gcd(*a)
    for i in range(n):
      l=[a[j] for j in range(n) if j!=i]
      ans=max(gcd(*l),ans)
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from fractions import gcd
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    f,b=[0]*(n+2),[0]*(n+2)
    f[1],b[n]=a[0],a[-1]
    for i in range(2,n+1):
        f[i],b[n-i+1]=gcd(a[i-1],f[i-1]),gcd(a[n-i],b[n-i+2])
    ans=0
    for i in range(1,n+1):
      ans=max(ans,gcd(f[i-1],b[i+1]))
    print(ans)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
total = 1;
for i in input().split():
    if i==0:
        total = 0;
        break
    total*=int(i)
if total>int(1e18):
    print(-1)
else : print(total)

### FIXED CODE ###

n = int(input())
total = 1;
a = list(map(int, input().split()))
if 0 not in a:
    for i in a:
        total*=i
        if total>int(1e18):
            total = -1
            break
    print(total)
else: print(0)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
unique=set(a)
ans=0
for x in unique:
    if a.count(x)%2>0:
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
import collections
unique=set(a)
c=collections.Counter(a)
ans=0
for x in unique:
    if c[x]%2>0:
        ans+=1
print(ans)
### BUGGY CODE ###

from math import *

K = int(input())

sum = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      sum += gcd((i+1),gcd((j+1),(k+1)))

print(sum)


### FIXED CODE ###

from math import *

K = int(input())

sum = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      sum += gcd((i+1),gcd((j+1),(k+1)))

print(sum)