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

import itertools

n,m,r=map(int,input().split())
D=[[10**10]*n for _ in range(n)]
for i in range(n):
    D[i][i]=0
R=list(map(int,input().split()))
for i in range(m):
    a,b,c=map(int,input().split())
    D[a-1][b-1]=c
    D[b-1][a-1]=c

for k in range(n):
    for i in range(n):
        for j in range(n):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j])

A=[]
for v in itertools.permutations(R,r):
    ans=0
    for i in range(r-1):
        ans+=D[v[i]-1][v[i+1]-1]
    A.append(ans)
print(min(A))

### FIXED CODE ###

import itertools

n,m,r=map(int,input().split())
D=[[10**10]*n for _ in range(n)]
for i in range(n):
    D[i][i]=0
R=list(map(int,input().split()))
for i in range(m):
    a,b,c=map(int,input().split())
    D[a-1][b-1]=c
    D[b-1][a-1]=c

for k in range(n):
    for i in range(n):
        for j in range(n):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j])

A=[]
for v in itertools.permutations(R,r):
    ans=0
    for i in range(r-1):
        ans+=D[v[i]-1][v[i+1]-1]
    A.append(ans)
print(min(A))
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N, 0, -1):
  j = i * 2
  s = a[i - 1]
  while j <= N:
    if j in b:
      s += 1
    j += i
  if s % 2 == 1:
  	b.append(i)
print(len(b))
b = list(map(str, b))
print(" ".join(b))


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
b = []
arr = [-1] * N
for i in range(N, 0, -1):
  s = 0
  j = i * 2
  while j <= N:
    s += arr[j - 1]
    j += i
  if s % 2 != a[i - 1]:
    arr[i - 1] = 1
    b.append(i)
  else:
    arr[i - 1] = 0
print(len(b))
print(*b)
### BUGGY CODE ###

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a.sort()

count = Counter(a)

b = [1 for i in range((max(a) + 1))]

for aa in a:
    for j in range(2*aa,max(a)+1, aa):
        b[j] = 0

c = 0
for d in count.items():
    if d[1] == 1 and b[d[0]] == 1: c += 1

print(c)

### FIXED CODE ###

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a.sort()

count = Counter(a)

b = [1]*(max(a) + 1)

for aa in a:
    for j in range(2*aa,len(b), aa):
        b[j] = 0

c = 0
for d in count.items():
    if d[1] == 1 and b[d[0]] == 1: c += 1

print(c)
### BUGGY CODE ###

from heapq import heappop, heappush, heapify

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

q = []
for x in a:
    heappush(q, (-x, 1, x))


for i in range(k):
    _, dc, p = heappop(q)
    dc += 1
    v = -(-p//dc)
    heappush(q, (-v, dc, p))


ans = 0
for x, _, _ in q: ans = max(ans, -x)

print(ans)


### FIXED CODE ###

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

def f(m):
    res = sum([-(-x//m)-1 for x in a])
    return res <= k

l, r = 0, 10**9+10

while r-l > 1:
    x = (l+r)//2
    if f(x): r = x
    else: l = x

print(r)
### BUGGY CODE ###

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n=input()
lst=[]
for i in range(len(n)):
    lst.append(int(n[i]))
# n=int(n)

keta=len(lst)
ans=0
lst.reverse()

dp=[]
for i in range(keta+1):
    dp.append([float('inf')]*2)
dp[0]=[0,1]
# print(dp)
for i in range(keta):
    dp[i+1][0]=min(dp[i][0]+lst[i],dp[i][1]+lst[i]+1)
    dp[i+1][1]=min(dp[i][0]+(10-lst[i]),dp[i][1]+(10-lst[i]-1))
# print(dp)
print(min(dp[-1][0],dp[-1][1]+1))

### FIXED CODE ###

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n=input()
lst=[]
for i in range(len(n)):
    lst.append(int(n[i]))
# n=int(n)

keta=len(lst)
ans=0
lst.reverse()
# print(lst)
# dp=[[float('inf')]*2 for i in range(keta+1)]
dp=[]
for i in range(keta+1):
    dp.append([float('inf')]*2)
dp[0]=[0,1]
# print(dp)
for i in range(keta):
    dp[i+1][0]=min(dp[i][0]+lst[i],dp[i][1]+lst[i]+1)
    dp[i+1][1]=min(dp[i][0]+(10-lst[i]),dp[i][1]+(10-lst[i]-1))
# print(dp)
print(min(dp[-1][0],dp[-1][1]+1))
### BUGGY CODE ###

S = input()
count = 0
while 'BW' in S:
    for i in range(len(S)):
        if S[i:i+2] == 'BW':
            lS = list(S)
            lS[i:i+2] = ['W', 'B']
            S = ''.join(lS)
            count += 1
print(count)

### FIXED CODE ###

S = input()
count = 0
foundB = 0
for s in S:
    if s == 'W':
        count += foundB
    elif s == 'B':
        foundB += 1
print(count)
### BUGGY CODE ###

from collections import defaultdict
import math
n = int(input())
a = [int(x) for x in input().split()]
ans = []
m_dic = defaultdict(int)
for i in a:
    m_dic[i] += 1

for i in range(n):
    count = 0
    for key,value in m_dic.items():
        v = value
        if key == a[i]:
            v = value -1
        if v > 1:
            count += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
    ans.append(count)
for i in ans:
    print(i)

### FIXED CODE ###

from collections import defaultdict
import math
n = int(input())
a = [int(x) for x in input().split()]
ans = []
tmp_sum = 0
m_dic,c_dic = defaultdict(int),defaultdict(int)
for x in a:
    m_dic[x] += 1

for value in m_dic.values():
    if value > 1:
        tmp_sum += math.factorial(value) // (math.factorial(value - 2) * math.factorial(2))

for x in a:
    print(tmp_sum-m_dic[x]+1)
### BUGGY CODE ###

import collections

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

c = collections.Counter(l)

for i in l:
    c[str(i)] -= 1
    hoge = list(c.values())
    fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
    ans = sum(fuga)
    c[str(i)] += 1
    
    print(int(ans))


### FIXED CODE ###

import collections

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

c = collections.Counter(l)
ans_dict = {}

hoge = list(c.values())
full_fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
full_ans = sum(full_fuga)

for i in l:
    v = c[str(i)]
    if v < 2:
        print(int(full_ans))
    elif v == 2:
        print(int(full_ans - 1))
    elif v > 2:
        print(int(full_ans - ((v*(v-1))/2) + (((v-1) *(v-2))/2)))
### BUGGY CODE ###

import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()  
    
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
ans=0

for i in range(n): 
    ans+=(i+1)*len(make_divisors(i+1))
print(ans)

### FIXED CODE ###

import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()  
ans=0    
for i in range(1,n+1):
    ans+=(n//i)*(n//i+1)*i//2
print(ans)
### BUGGY CODE ###

# 視点を変えてやる全探索 000~999までが達成できたらおｋ
n = int(input())
s = list(input())
ans = 0
for i in range(1000):
    t = list(f"{i:0>3}")
    j = 0
    tmp = ""
    for c in s:
        if t[j] == c:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)

### FIXED CODE ###

# 視点を変えてやる全探索 000~999までが達成できたらおｋ
n = int(input())
s = list(input())
ans = 0
for i in range(1000):
    t = list(f"{i:0>3}")
    j = 0
    tmp = ""
    for c in s:
        if t[j] == c:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)
### BUGGY CODE ###

#C
n = int(input())
h = list(map(int,input().split()))
tmp = 0
result = [0 for _ in range(n)]
for i in range(n-1):
    for j in range(i,n-1):
        if h[j] >= h[j+1]:
            tmp += 1
        else:
            break
            
    result[i] = tmp
    tmp = 0
    
print(max(result))

### FIXED CODE ###

#C
n = int(input())
h = list(map(int,input().split()))

a,b = 0,0

for i in range(n-1):
    if h[i] >= h[i+1]:
        a += 1
        b = max(b,a)
    else:
        a = 0
        
print(b)
### BUGGY CODE ###

K, S = map(int, input().split())
print([x+y+z == S for x in range(K+1) for y in range(K+1)
       for z in range(K+1)].count(True))


### FIXED CODE ###

K, S = map(int, input().split())
print([0 <= S - x - y <= K for x in range(K+1)
       for y in range(K+1)].count(True))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(int(2e6))

h,w=map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(input()))

dp=[[0]*w for _ in range(h)]
z=[[0]*w for _ in range(h)]
dp[h-1][w-1]=1
z[h-1][w-1]=1
def c(i,j):
    if z[i][j]!=0:
        return dp[i][j]
    if 1<=i+1<=h-1 and 0<=j<=w-1:
        if a[i+1][j]!="#":
            dp[i][j]+=c(i+1,j)
        else:
            z[i+1][j]=1
    if 1<=j+1<=w-1 and 0<=i<=h-1:
        if a[i][j+1]!="#":
            dp[i][j]+=c(i,j+1)
        else:
            z[i][j+1]=1
    z[i][j]=1
    return dp[i][j]
print(c(0,0)%(10**9+7))

### FIXED CODE ###

h,w=map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(input()))

dp=[[0]*w for _ in range(h)]
dp[0][0]=1
for i in range(h):
    for j in range(w):
        if i+1<h and a[i+1][j]=='.':
            dp[i+1][j]+=dp[i][j]%(10**9+7)
        if j+1<w and a[i][j+1]=='.':
            dp[i][j+1]+=dp[i][j]%(10**9+7)
print(dp[h-1][w-1]%(10**9+7))
### BUGGY CODE ###

S = input()[::-1]

a = [0] * 13
n = [0] * 13

def calc(d, num):
    shift = (num * (10 ** d))%13
    if d==0:
        n[shift] = 1
    else:
        for i in range(13):
            n[(i+shift)%13] += a[i]
    

for d, s in enumerate(S):
    if s=='?':
        for i in range(10):
            calc(d, i)
    else:
        calc(d, int(s[0]))
    a, n = n, a
    for i in range(13):
        a[i] %= 1000000007
        n[i] = 0

print(a[5])





### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    S = input()
    d = 1
    dp = [0] * 13
    dp[0] = 1
    dp_n = [None] * 13
    for s in reversed(S):
        for i in range(13):
            dp[i] %= N1097
            dp_n[i] = 0
        if s == '?':
            for s in range(10):
                diff = (s*d) % 13
                for i in range(13):
                    dp_n[(i+diff)%13] += dp[i]
        else:
            s = int(s)
            diff = (s*d) % 13
            for i in range(13):
                dp_n[(i+diff)%13] += dp[i]
        dp_n, dp = dp, dp_n
        d = (10 * d) % 13
    print(dp[5] % N1097)

main()
### BUGGY CODE ###

import sys, numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson  
from collections import defaultdict
from itertools import product, permutations, combinations

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

def solve():
    N, u, v = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(N-1)]

    adjm = [[float('inf')] * N for _ in range(N)]
    for ab in AB:
        a, b = ab[0]-1, ab[1]-1
        adjm[a][b] = 1
        adjm[b][a] = 1
        
    adjm = csr_matrix(adjm)
    dv = dijkstra(adjm, indices=v-1)
    du = dijkstra(adjm, indices=u-1)
    dOK = [i for i, j in zip(dv, du) if i>j]

    print(int(max(dOK)-1))

solve()


### FIXED CODE ###

import sys, heapq
from collections import defaultdict
from itertools import product, permutations, combinations

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

N, u, v = map(int, input().split())



def dijkstra_heap(s,edge):
#始点sから各頂点への最短距離
    d = [10**20] * N
    used = [True] * N #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

AB = [list(map(int, input().split())) for _ in range(N-1)]

adjl = [[] for _ in range(N)]
for ab in AB:
    a, b = ab[0]-1, ab[1]-1
    adjl[a].append([1, b])
    adjl[b].append([1, a])

du = dijkstra_heap(u-1, adjl)
dv = dijkstra_heap(v-1, adjl)
dOK = [j for i, j in zip(du, dv) if i < j]

print(int(max(dOK)-1))
### BUGGY CODE ###

N = int(input())
A = []
A = list (map(int, input().strip().split(' ')))

i = 0
while i < N:
    j = 0
    while j < N:
        if i + 1 == A[j]:
            print(j + 1, end = ' ')
            break
        j += 1
    i += 1

### FIXED CODE ###

N = int(input())
A = []
A = list (map(int, input().strip().split(' ')))
B = [0 for i in range(N)]

i = 0
while i < N:
    B[A[i] - 1] = i + 1
    i += 1
    
for i in B:
    print(i, end = ' ')
### BUGGY CODE ###

x,k=map(int,input().split())
while x>=0:
    x-=k
if x<0:
    x*=-1
y=x-k
if y <0:
    y*=-1
if x<y:
    print(x)
if x>y:
    print(y)
if x==y:
    print(x)

### FIXED CODE ###

n,k=map(int,input().split())
x=n%k
while x>=0:
    x-=k
if x<0:
    x*=-1
y=x-k
if y <0:
    y*=-1
if x<y:
    print(x)
if x>y:
    print(y)
if x==y:
    print(x)
### BUGGY CODE ###

import bisect

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

Clen = len(C)

total = 0

for i in A:
    Bmin = bisect.bisect_right(B, i)
    for j in B[Bmin :]:
        total += Clen - bisect.bisect_right(C, j)

print(total)

### FIXED CODE ###

import bisect

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

total = 0

for b in B:
    i = N - bisect.bisect_right(C, b)
    j = bisect.bisect_left(A, b)
    total += i * j

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

n=int(input())
a=[0]+list(map(int,input().split()))

m=0
ans=[]
c=[0]*(n+1)
for i in reversed(range(1,n+1)):
  if a[i]%2!=c[i]%2:
    m+=1
    ans.append(i)
    j=1
    r=set()
    while j*j<=i:
      if i%j==0:
        r.add(j)
        r.add(i//j)
      j+=1
    for j in r:
      c[j]+=1
      c[j]%=2
        
print(m)
print(*sorted(ans))       

### FIXED CODE ###

n=int(input())
a=[0]+list(map(int,input().split()))

m=0
ans=[]
c=[0]*(n+1)
for i in reversed(range(1,n+1)):
  if a[i]%2!=c[i]%2:
    m+=1
    ans.append(i)
    j=1
    r=set()
    while j*j<=i:
      if i%j==0:
        r.add(j)
        r.add(i//j)
      j+=1
    for j in r:
      c[j]+=1
      c[j]%=2
        
print(m)
print(*sorted(ans))
### BUGGY CODE ###

mod=998244353
N,A,B,K=map(int,input().split())
 
#繰り返し二乗法
def great_power(x, y):
    if   y == 0:
      return 1
    elif y == 1:
      return x % mod
    elif y % 2 == 0:
      return great_power(x, y//2)**2 % mod
    else:
      return great_power(x, y//2)**2 * x % mod

#階乗計算
factorial=[1]
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i %mod)

#逆元計算
inverse=[0]*(N+1)
inverse[N] = great_power(factorial[N], mod-2)
for i in range(N-1, -1, -1):
    inverse[i] = inverse[i+1] * (i+1) % mod

#combination計算
def nCr(n,r):
  if n==r or n<r:
    return 1
  return factorial[n] * inverse[r] * inverse[n-r] % mod

def solve(a,b,c):
  res=nCr(N,a+b+c)
  res2=factorial[a+b+c] * inverse[a]*inverse[b]*inverse[c]
  return (res*res2)%mod

ans=[]
for i in range(N+1):
  if (K-A*i)%B==0:
    ans.append((i,(K-A*i)//B))

out=0
for x,y in ans:
  for i in range(min(x,y)+1):
    red,green,blue=x-i,i,y-i
    if red+green+blue <=N:
      out+=solve(red,green,blue)
print(out%mod)



### FIXED CODE ###

mod=998244353
N,A,B,K=map(int,input().split())
 
#繰り返し二乗法
def great_power(x, y):
    if   y == 0:
      return 1
    elif y == 1:
      return x % mod
    elif y % 2 == 0:
      return great_power(x, y//2)**2 % mod
    else:
      return great_power(x, y//2)**2 * x % mod

#階乗計算
factorial=[1]
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i %mod)

#逆元計算
inverse=[0]*(N+1)
inverse[N] = great_power(factorial[N], mod-2)
for i in range(N-1, -1, -1):
    inverse[i] = inverse[i+1] * (i+1) % mod

#combination計算
def nCr(n,r):
  if n==r or n<r or r==0:
    return 1
  return factorial[n] * inverse[r] * inverse[n-r] % mod

ans=0

for i in range(N+1):
  if (K-A*i)%B==0 and (K-A*i)>=0:
    j=(K-A*i)//B
    if j <= N:
      ans+=( nCr(N,i) * nCr(N,j) ) %mod
      ans %= mod

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

def o():return map(int,input().split())
n,q=o()
a=[[]for i in range(n)]
x=[0]*n
for i in range(n-1):
  u,v=o()
  a[u-1]+=[v-1]
  a[v-1]+=[u-1]
for i in range(q):
  u,v=o()
  x[u-1]+=v
p=[0]
m=[0]
while p:
  r=p.pop()
  m+=[r]
  for i in a[r]:
    if not(i in m):
      p+=[i]
      x[i]+=x[r]
print(*x)

### FIXED CODE ###

def o():return map(int,input().split())
n,q=o()
a=[[]for i in range(n)]
x=[0]*n
for i in range(n-1):
  u,v=o()
  a[u-1]+=[v-1]
  a[v-1]+=[u-1]
for i in range(q):
  u,v=o()
  x[u-1]+=v
p=[[0,0]]
s=0
while p:
  r,s=p.pop()
  for i in a[r]:
    if i!=s:
      p+=[[i,r]]
      x[i]+=x[r]
print(*x)
### BUGGY CODE ###

N,K = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
max=0
idx=0
for i in range(N-K+1):
    tmp = sum(n[i:i+K]) 
    if tmp  > max:
        max=tmp 
        idx=i

d=sorted(n[idx:idx+K])
e=[0]*K
tmp=0
for i in range(K):
    tmp += sum(range(1,d[i]+1))/d[i]
print(tmp)

### FIXED CODE ###

import numpy as np

N,K = [int(i) for i in input().split()]
n = np.array([int(i) for i in input().split()])
n=(n+1)
t=np.empty(N+1)
t[0] = 0
t[1:]=np.cumsum(n)
print(max(t[K:]-t[:-K])*0.5)
### BUGGY CODE ###

from collections import Counter
N = int(input())
S = list(input())

ans = float('inf')
for i in range(N):
    left = Counter(S[:i])
    right = Counter(S[i+1:])
    tmp = left['W'] + right['E']
    ans = min(ans,tmp)
print(ans)

### FIXED CODE ###

import numpy as np
N = int(input())
S = input()

left = [0]*N
right = [0]*N
for i in range(1,N):
    if S[i-1]=='W':
        left[i] += left[i-1] + 1
    else:
        left[i] += left[i-1]
left = np.array(left)

for i in range(1,N):
    if S[N-i]=='E':
        right[i] += right[i-1] + 1
    else:
        right[i] += right[i-1]
right = np.array(right[::-1])

ans = (left+right).min()
print(ans)
### BUGGY CODE ###

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

for x in range(a+1):
  for y in range(a+1):
    for z in range(a+1):
      
      if x+y+z==b:
        n+=1
print(n)
      
   

### FIXED CODE ###

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

for y in range(a+1):
  for z in range(a+1):
      p=b-y-z
      if 0<=p and p<=a:
        n+=1
print(n)
### BUGGY CODE ###

string = input()
n = int(string.split()[0])
k = int(string.split()[1])

while n > k:
    n = n - k

if n == k:
    print(0)
    exit()

print(min(n,k-n))

### FIXED CODE ###

string = input()
n = int(string.split()[0])
k = int(string.split()[1])

diff = n - k
n = n - (diff // k) * k

while n > k:
    n = n - k

if n == k:
    print(0)
    exit()

print(min(n,k-n))
### BUGGY CODE ###

n = int(input())
sum = 0
while n > 0:
    sum += n % 10
    n = n // 10
if sum % 9 == 0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n = int(input())
if n % 9 == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

n = int(input())
route = {i + 1 : {} for i in range(n)}
for i in range(n - 1):
    a, b, c = map(int, input().split())
    route[a][b] = c
    route[b][a] = c
q, k = map(int, input().split())
queue = [k]
length = [0] * (n + 1)
while queue:
    search = queue.pop(0)
    pairs = []
    for i, j in route[search].items():
        queue.append(i)
        length[i] = length[search] + j
        pairs.append([search, i])
    for i, j in pairs:
        del route[i][j]
        del route[j][i]
for i in range(q):
    x, y = map(int, input().split())
    print(length[x] + length[y])

### FIXED CODE ###

import collections

n = int(input())
route = {i + 1 : {} for i in range(n)}
for i in range(n - 1):
    a, b, c = map(int, input().split())
    route[a][b] = c
    route[b][a] = c
q, k = map(int, input().split())
queue = collections.deque([k])
length = [0] * (n + 1)
while queue:
    search = queue.popleft()
    pairs = []
    for i, j in route[search].items():
        queue.append(i)
        length[i] = length[search] + j
        pairs.append([search, i])
    for i, j in pairs:
        del route[i][j]
        del route[j][i]
for i in range(q):
    x, y = map(int, input().split())
    print(length[x] + length[y])
### BUGGY CODE ###

from collections import deque
import sys

def input():
    return sys.stdin.readline().rstrip()

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

ans = 1
for i in li:
    ans *= i

if ans > int(1e18):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

from collections import deque
import sys

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
li = list(map(int, input().split()))
li.sort()

ans = 1
for i in li:
    ans *= i
    if (ans > int(1e18)):
        print(-1)
        sys.exit(0)

if ans > int(1e18):
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

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

a.sort()

prime = []
for i in range(N):
    count = 0
    for j in range(len(prime)):
        if a[i] % prime[j] == 0 :
            count = 1
    if count == 0 :
        prime.append(a[i])


 
gcd = []
for i in range(len(prime)):
    list_not_i = a.copy()
    list_not_i.remove(prime[i])
    gcd.append(functools.reduce(fractions.gcd, list_not_i))
 
print(max(gcd))

### FIXED CODE ###

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

L = [0] * N
for i in range(N) :
        if i == 0 :
                L[0] = 0
        elif i == 1 :
                L[1] = a[0]
        else :
                L[i] = fractions.gcd(L[i-1], a[i-1])

a.reverse()
R = [0] * N
for i in range(N) :
        if i == 0 :
                R[0] = 0
        elif i == 1 :
                R[1] = a[0]
        else :
                R[i] = fractions.gcd(R[i-1], a[i-1])
R.reverse()
a.reverse()

gcd = [0] * N
for i in range(N) :
        if i == 0 :
                gcd[0] = R[0]
        elif i == N-1 :
                gcd[N-1] = L[N-1]
        else :
                gcd[i] = fractions.gcd(L[i],R[i])

print(max(gcd))