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

n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]   
result = 0

for i in range(n):
    cnt = 0
    j = i + 1
    x = []
    for a, b in ab:
        if j == a:
            x.append(b)
        elif j == b:
            x.append(a)
    for y in x:
        if h[i] > h[y-1]:
            cnt += 1
    if cnt == len(x):
        result += 1

print(result)

### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
cnt = [1] * n
for i in range(m):
    a, b = map(int,input().split())
    if h[a-1] > h[b-1]:
        cnt[b-1] = 0
    elif h[a-1] == h[b-1]:
        cnt[a-1] = 0
        cnt[b-1] = 0
    else:
        cnt[a-1] = 0
print(sum(cnt))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
c = [0]*31
for i in a:
    s = format(i,'b')[::-1]
    for i in range(len(s)):
        c[i] += int(s[i])

buf = []
for i in a:
    s = format(i,'b').zfill(31)[::-1]
    ans = ''
    for i in range(31):
        ans +=  str((c[i]-int(s[i]))%2)
    ans = ans[::-1]
    buf.append(int(ans,2))

print(*buf)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)
### BUGGY CODE ###

mod = 10**9+7
N = int(input())
a = list(map(int, input().split()))
S = [0]*(N+1)#i~j-1の和はS[j]-S[i]
for i in range(1, N+1):
    S[i] = S[i-1]+a[i-1]
memo = [[-1]*(N+1) for _ in range(N)]
def dp(i, j):
    if memo[i][j]>=0:
        return memo[i][j]
    if j-i == 1:
        memo[i][j] = 0
        return 0
    memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))
    return memo[i][j]
print(dp(0, N))


    








### FIXED CODE ###

mod = 10**9+7
N = int(input())
a = list(map(int, input().split()))
S = [0]*(N+1)
for i in range(1, N+1):
    S[i] = S[i-1]+a[i-1]
dp = [[float('inf')]*(N+1) for _ in range(N)]
for i in range(N):
    dp[i][i+1] = 0
for l in range(2, N+1):
    for i in range(N-l+1):
        j = i+l
        for ll in range(1, l):
            k = i+ll
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]+S[j]-S[i])
print(dp[0][-1])
### BUGGY CODE ###

import numpy as np
import heapq as hp

h, w = map(int, input().split())
a = np.array([list(input()) for _ in range(h)])
a = np.pad(a, 1, 'constant')

q = []
for i in range(h+2):
    for j in range(w+2):
        if a[i][j] == '#':
            hp.heappush(q, (0, i, j))

while q:
    cnt, y, x = hp.heappop(q)
    for dy, dx in [[0, 1], [1, 0], [-1, 0], [0, -1]]:
        ny, nx = dy + y, dx + x
        if a[ny][nx] == '.':
            hp.heappush(q, (cnt + 1, ny, nx))
            a[ny][nx] = '#'
            
print(cnt)

### FIXED CODE ###

from collections import deque

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

q = deque([])
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append([i, j])
            q.append(0)

while q:
    y, x = q.popleft()
    ans = q.popleft() + 1
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        ny, nx = dy + y, dx + x
        if ny < 0 or nx < 0 or ny >= h or nx >= w:
            continue
        if a[ny][nx] == '.':
            a[ny][nx] = '#'
            q.append([ny, nx])
            q.append(ans)

print(ans-1)
### BUGGY CODE ###

from itertools import permutations

def warshall_floyd(n, d):
    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])
    return d

n,m,R=map(int,input().split())
r=list(map(int,list(input().split())))
g=[[float("inf")]*n for _ in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
for i in range(n):
    g[i][i]=0
g=warshall_floyd(n,g)
ans=float("inf")
for p in list(permutations(r)):
    tmp=0
    for i in range(R-1):
        tmp+=g[p[i]-1][p[i+1]-1]
    ans=min(ans,tmp)
print(ans)

### FIXED CODE ###

from itertools import permutations

def warshall_floyd(n, d):
    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])
    return d

n,m,R=map(int,input().split())
r=list(map(int,list(input().split())))
g=[[float("inf")]*n for _ in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
for i in range(n):
    g[i][i]=0
g=warshall_floyd(n,g)
ans=float("inf")
for p in list(permutations(r)):
    tmp=0
    for i in range(R-1):
        tmp+=g[p[i]-1][p[i+1]-1]
    ans=min(ans,tmp)
print(ans)
### BUGGY CODE ###

n=int(input())
s=input()
r,g,b=[],[],[]
ans=0
for i in range(n):
  if s[i]=="R":
    r.append(i)
  elif s[i]=="G":
    g.append(i)
  elif s[i]=="B":
    b.append(i)
for i in range(len(r)):
  for j in range(len(g)):
    for k in range(len(b)):
      l=[r[i],g[j],b[k]]
      l.sort()
      if l[1]-l[0]!=l[2]-l[1]:
        ans+=1
print(ans)  

### FIXED CODE ###

n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    if 2*j-i<n:
      if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
        ans-=1
print(ans)
### BUGGY CODE ###

s = str(input())
n = int(input())

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = str(s[i:j+1])
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        cand = sorted(cand)
        if len(cand) > n:
            cand.pop()


print(cand.pop())


### FIXED CODE ###

s = str(input())
n = int(input())

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if len(cand) == n and tmp > cand[-1]:
            break
        if tmp in cand:
            continue
        cand += [tmp]
        #cand = sorted(cand)
        cand.sort()
        if len(cand) > n:
            cand.pop()


print(cand.pop())
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,a,b = LI()
    if a+b > n+1:
        return -1
    t = n // b
    if n % b > 0:
        t += 1
    if a < t:
        return -1
    rr = []
    while n > 0:
        if n == a:
            rr.append(list(range(1,n+1)))
            break
        if n-b >= a-1:
            rr.append(list(range(n,n-b,-1)))
            n -= b
            a -= 1
            continue
        rr.append(list(range(n,a-1,-1)))
        rr.append(list(range(1,a)))
    r = []
    rr.reverse()
    for c in rr:
        r.append(' '.join(map(str,c)))

    return ' '.join(r)


print(main())




### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,a,b = LI()
    if a+b > n+1:
        return -1
    t = n // b
    if n % b > 0:
        t += 1
    if a < t:
        return -1
    rr = []
    while n > 0:
        if n == a:
            rr.append(list(range(1,n+1)))
            break
        if n-b >= a-1:
            rr.append(list(range(n,n-b,-1)))
            n -= b
            a -= 1
            continue
        rr.append(list(range(n,a-1,-1)))
        rr.append(list(range(1,a)))
        break
    r = []
    rr.reverse()
    for c in rr:
        r.append(' '.join(map(str,c)))

    return ' '.join(r)


print(main())
### BUGGY CODE ###

n,m=map(int,input().split())
sl=[]
pl=[]
pena=0
ac=0
ac_p=[]
wa={}
for i in range(m):
    p,s=map(str,input().split())
    p=int(p)
    if s=="WA":
        wa[p]=wa.get(p,0)+1
    else:#もしACなら
        if not p in ac_p:
            ac+=1
            ac_p.append(p)
            pena+=wa.get(p,0)

print("{0} {1}".format(ac,pena))



### FIXED CODE ###

n,m=map(int,input().split())
sl=[]
pl=[]
pena=0
ac=0
ac_p=[]
wa={}
acdic={}

for i in range(m):
    #p,s=map(str,input().split())
    li = input().split()
    p=int(li[0])
    s=li[1]
    #p=int(p)
    if s=="WA":
        wa[p]=wa.get(p,0)+1
    else:#もしACなら
        #acdic[p]=True
        if acdic.get(p,False)==False:
            ac+=1
            acdic[p]=True
            pena+=wa.get(p,0)

print("{0} {1}".format(ac,pena))
### BUGGY CODE ###

s = input().rstrip()

trans = set()
trans.add(s)
for i in range(len(s)-1):
  for j in range(i+1,len(s)):
    if i == 0 and j == len(s)-1:
      trans.add(s[::-1])
    elif i == 0:
      trans.add((s[0:j+1])[::-1]+s[j+1::])
    elif j == len(s)-1:
      trans.add(s[:i]+s[i::][::-1])
    else:
      trans.add(s[:i]+s[i:j+1:][::-1]+s[j+1:])
print(len(trans))

### FIXED CODE ###

s = input().rstrip()
total = 0
for i in range(ord('a'),ord('z')+1):
  tmp = s.count(chr(i))
  total += tmp*(tmp-1)//2
print(1 + len(s)*(len(s)-1)//2 - total)
### BUGGY CODE ###

# import math
# import fractions
import numpy as np

MOD = 10 ** 9 + 7

def solve(N, A):
    # for i, a in enumerate(A):
    #     A[i] = bin(a)
    # print(A)
    
    B = []
    for i in range(N - 1):
        for j in range(i+1, N):
          B.append(np.bitwise_xor(A[i], A[j]) % MOD)  

    return sum(B) % MOD

# S = input()
N = int(input())
# H, N = map(int, input().split())
A = list(map(int, input().split()))
# B = [int(input()) for _ in range(n)]
# A = []
# B = []
# for _ in range(N):
#     a, b = list(map(int, input().split()))
#     A.append(a)
#     B.append(b)

print(solve(N, A))


### FIXED CODE ###

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

MOD = 10 ** 9 + 7
ans = 0
m = 1
ans = 0
for _ in range(60):
    one_count = sum(a & m for a in aaa)
    one_count //= m
    zero_count = n - one_count
    ans = (ans + one_count * zero_count * m) % MOD
    m *= 2
        
print(ans)
### BUGGY CODE ###

N,K=(int(x) for x in input().split())
x=N
while x>K:
    x=abs(x-K)
print(min([x,abs(K-x)]))



### FIXED CODE ###

N,K=(int(x) for x in input().split())
x=N%K
print(min([x,abs(K-x)]))
### BUGGY CODE ###

import collections

N=int(input())
S=input()

lenR=S.count("R")
lenG=S.count("G")
lenB=S.count("B")

count=0
for i in range(N-2):
    for j in range(i,N-1):

        if (S[i] != S[j]) and (2*j-i<N):
                if (S[i]!=S[2*j-i]) and (S[j]!=S[2*j-i]):
                    count+=1
    
print(lenR*lenG*lenB-count)

### FIXED CODE ###

import collections

N=int(input())
S=input()

lenR=S.count("R")
lenG=S.count("G")
lenB=S.count("B")

count=0
for i in range(N-2):
    for j in range(i,N-1):
        k=2*j-i
        if k>=N:
            continue
        else:
            if (S[i] != S[j]) and (S[i]!=S[k]) and (S[j]!=S[k]):
                count+=1
    
print(lenR*lenG*lenB-count)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
import bisect
for i in range(N-2):
    for j in range(i,N-1):
        if i==j:
            continue
        a = L[i]
        b = L[j]
        k = bisect.bisect_left(L[j+1:],a+b)
        l = bisect.bisect_left(L[j+1:],abs(a-b))
        if k<N-j:
            c = L[k+j]
            d = L[l+j+1]
            
            if 0<d<=c:
                
                ans += k-l
print(ans)


### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
import bisect
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        k = bisect.bisect_left(L,a+b)
        l = bisect.bisect_left(L,b-a)
        ans += k-max(j+1,l)
print(ans)
### BUGGY CODE ###

n = int(input())
# 愚直にやると約数の個数テーブルをO(NlogN)
print(sum(i * j for i in range(1, n + 1)
          for j in range(1, n // i + 1)))


### FIXED CODE ###

n = int(input())

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

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

ans = 1
for i in range(len(A)):
    ans = ans * A[i]

if ans > 10 ** 18:
    print('-1')
else:
    print(ans)


### FIXED CODE ###

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

ans = 1

if 0 in A:
    ans = 0

else:
    for i in range(len(A)):
        ans = ans * A[i]
        if ans > 10 ** 18:
            error = str(ans)
            ans = '-1'
            break
print(ans)
### BUGGY CODE ###

import heapq
n,k=map(int,input().split())
can=[]
for i in range(k):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        can.append(j)
table=[0]*n
table[0]=1
que=[0]
heapq.heapify(que)
can.sort()
while que:
    now=heapq.heappop(que)
    for j in can:
        if now+j<n:
            table[now+j]=(table[now+j]+table[now])%998244353
            if not now+j in set(que):
                heapq.heappush(que,now+j)
print(table[-1]%998244353)

### FIXED CODE ###

p=998244353
n,k=map(int,input().split())
kukan=[]
for i in range(k):
    l,r=map(int,input().split())
    kukan.append((l,r))
dp=[0]*n
sdp=[0]*(n+1)
dp[0]=1
sdp[1]=1
for i in range(1,n):
    for l,r in kukan:
        left=max(0,i-r)
        right=max(0,i-l+1)
        dp[i]=(dp[i]+sdp[right]-sdp[left])%p
    sdp[i+1]=(sdp[i]+dp[i])%p
print(dp[-1])
### BUGGY CODE ###

a, b, m = map(int, input().split())
priceOfMicrowaves = list(map(int, input().split()))
priceOfRefrigerators = list(map(int, input().split()))
priceTable = [list(map(int,input().split())) for i in range(m)]
cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for p in priceOfMicrowaves:
    if p >= cheepest:
        continue
    for q in priceOfRefrigerators:
        if q >= cheepest:
            continue
        if p + q < cheepest:
            cheepest = p + q
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]-price[2] >= cheepest:
        continue
    elif priceOfRefrigerators[price[1]-1]-price[2] >= cheepest:
        continue
    elif priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
print(cheepest)


### FIXED CODE ###

a, b, m = map(int, input().split())
priceOfMicrowaves = list(map(int, input().split()))
priceOfRefrigerators = list(map(int, input().split()))
priceTable = [list(map(int,input().split())) for i in range(m)]
cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]-price[2] >= cheepest:
        continue
    elif priceOfRefrigerators[price[1]-1]-price[2] >= cheepest:
        continue
    elif priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
if cheepest > min(priceOfMicrowaves) + min(priceOfRefrigerators):
    cheepest = min(priceOfMicrowaves) + min(priceOfRefrigerators)
print(cheepest)
### BUGGY CODE ###

def divisore(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

n=int(input())
d1=divisore(n)
d1=d1[1::2]
d2=divisore(n-1)
d2=d2[1:]
d_l=set(d1+d2)

cnt=0
nn=n
for i in d_l:
  while nn>1:
    if nn%i==0:
      nn//=i
    else:
      nn-=i
  if nn==1:
    cnt+=1
  nn=n
print(cnt)

### FIXED CODE ###

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def divisore(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

ans_l=divisore(n-1)[1:]

d=divisore(n)
for i in d[1:]:
  nn=n
  while nn%i==0:
    nn//=i
  if nn%i==1:
    ans_l.append(i)

print(len(ans_l))
### BUGGY CODE ###

import sys
readline = sys.stdin.readline
s = readline().strip()
n = int(readline())
rev = False
for i in range(n):
    q = readline()
    if q.startswith("1"):
        rev = not rev
    if q.startswith("2 1"):
        if not rev:
            s = q[-2] + s
        else:
            s = s + q[-2]
    if q.startswith("2 2"):
        if not rev:
            s = s + q[-2]
        else:
            s = q[-2] + s
if rev:
    print(s[::-1])
else:
    print(s)


### FIXED CODE ###

import sys
readline = sys.stdin.readline
s = readline().strip()
n = int(readline())
rev = False
h = []
t = []
for i in range(n):
    q = readline()
    if q.startswith("1"):
        rev = not rev
    if q.startswith("2 1"):
        if not rev:
            h.append(q[-2])
        else:
            t.append(q[-2])
    if q.startswith("2 2"):
        if not rev:
            t.append(q[-2])
        else:
            h.append(q[-2])
s = "".join(h[::-1]) + s + "".join(t)
if rev:
    print(s[::-1])
else:
    print(s)
### BUGGY CODE ###

from fractions import gcd

def test(a,b):
  num = 2
  x = gcd(a,b)
  s = []
  while x != 1:
    if(x % num == 0):
      x = x / num
      s.append(num)
    else:
      num += 1

  return set(s)

def main():

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

  num = []

  num = list(test(a, b))
  num.append(1)
  print(len(num))

if __name__ == '__main__':
  main()


### FIXED CODE ###

from fractions import gcd
import math

def test(a,b):
  x = gcd(a,b)
  s = []
  for i in range(2, int(math.sqrt(x)) + 1):
    while x % i == 0:
      s.append(i)
      x //= i

  s.append(x)
  s.append(1)

  return list(set(s))

def main():

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

  num = []

  num = test(a, b)
  print(len(num))

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

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

counts = 0
checked = {}
for _numB in B:
    if _numB in checked:
        counts += checked[_numB]
    else:
        countsA = 0
        for _numA in A:
            if (_numB > _numA):
                countsA += 1
            else:
                break
        countsC = 0
        for _numC in C:
            if (_numC > _numB):
                countsC += 1
            else:
                break
        checked[_numB] = countsA * countsC
        counts += countsA * countsC
print(counts)


### FIXED CODE ###

import bisect

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

counts = 0
checked = {}
for _numB in B:
    if _numB not in checked:
        countsA = bisect.bisect_left(A, _numB)
        countsC = bisect.bisect_right(C, _numB)
        checked[_numB] = countsA * (N - countsC)
    counts += checked[_numB]
print(counts)
### BUGGY CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    h, n = map(int, args[0].split())

    AB = [tuple(map(int, s.split())) for s in args[1:]]

    inf = 10**12
    dp = [inf]*(h+1)
    dp[0] = 0
    for a, b in AB:
        for i, m in enumerate(dp):
            k = min(h, i+a)
            dp[k] = min(dp[k], dp[i]+b)

    return str(dp[-1])


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    h, n = map(int, args[0].split())

    AB = [tuple(map(int, s.split())) for s in args[1:]]

    inf = 10**12
    dp = [inf]*(h+1)
    dp[0] = 0
    for a, b in AB:
        for i, m in enumerate(dp):
            k = min(h, i+a)
            dp[k] = min(dp[k], dp[i]+b)

    return str(dp[-1])


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
### BUGGY CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = min(A)
A1 = np.array(A)
count1 = []
for i in range(1, a+1):
    x = A1%i
    count1.append(sum(x==0))


ans1 = []
for i in range(a):
    if count1[i] == N or count1[i] == N-1:
        ans1.append(i+1)

A.remove(a)
b = min(A)
A2 = np.array(A)
for i in range(1, b+1):
    y = A2%i
    count1.append(sum(y==0))


ans2 = []
for i in range(b):
    if count1[i] == N:
        ans2.append(i+1)


    

print(max(max(ans1), max(ans2)))

### FIXED CODE ###

def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y, x%y)

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

left_gcd = [A[0]]
a = A[0]
for i in range(1,N-1):
  a = gcd(a, A[i])
  left_gcd.append(a)

right_gcd = [A[N-1]]
b = A[N-1]
for k in range(N-2, 0, -1):
  b = gcd(b, A[k])
  right_gcd.append(b)

ans_gcd = [right_gcd[N-2], left_gcd[N-2]]

for p in range(N-2):
  ans_gcd.append(gcd(left_gcd[p], right_gcd[N-p-3]))

print(max(ans_gcd))
### BUGGY CODE ###

from collections import deque

N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]

win_point = {
    'r': r,
    's': s,
    'p': p,
}

next_hands = {
    'r': ['s', 'p'],
    's': ['r', 'p'],
    'p': ['r', 's'],
}


def battle(enemy_hand, my_hand):
    point = 0

    if enemy_hand == 'r' and my_hand == 'p':
        point = win_point[my_hand]
    elif enemy_hand == 's' and my_hand == 'r':
        point = win_point[my_hand]
    elif enemy_hand == 'p' and my_hand == 's':
        point = win_point[my_hand]

    return point


enemy_hands = input()
search = deque()
max_point = 0
result = 0
debug = []

for index in range(K):
    hands = ['r', 's', 'p']
    max_point = 0

    # 初期化
    search.appendleft((index, 'r', 0))
    search.appendleft((index, 's', 0))
    search.appendleft((index, 'p', 0))

    while search:
        target = search.popleft()

        enemy_hand = enemy_hands[target[0]]

        # 累積ポイントを加算
        point = target[2] + battle(enemy_hand, target[1])
        next_hand = next_hands[target[1]]

        # 累積ポイントのうち、最も大きいものをmax_pointとして保持
        max_point = max(max_point, point)

        for hand in next_hand:
            if target[0] + K < N:
                search.appendleft((target[0] + K, hand, point))
    result += max_point

print(result)


### FIXED CODE ###

N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]

win_point = {
    'r': r,
    's': s,
    'p': p,
}

next_hands = {
    'r': ['s', 'p'],
    's': ['r', 'p'],
    'p': ['r', 's'],
}

enemy_hands = input()


def can_win(enemy_hand, my_hands):
    # 勝てる場合にはTrueと勝てる手を教えてくれる
    if enemy_hand == 'r' and 'p' in my_hands:
        return True, 'p'
    if enemy_hand == 's' and 'r' in my_hands:
        return True, 'r'
    if enemy_hand == 'p' and 's' in my_hands:
        return True, 's'

    # 勝てる手がない場合
    return False, None


point = 0

for index in range(K):
    now_hands = ['r', 'p', 's']
    for i in range(index, N, K):
        win, hand = can_win(enemy_hands[i], now_hands)

        if win:
            point += win_point[hand]
            now_hands = next_hands[hand]
        else:
            # 勝てない場合次似邪魔しない手を選ぶ
            # 勝てない回の次は必ず勝てるため全手出せる前提とする
            now_hands = ['r', 'p', 's']

print(point)