Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
B = A[:][::-1]

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
  #N_C_kのN
  for i in range(2, 10**5+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod

COMinit()

comb = {}
for i in range(K-1, N):
  comb[(i, K-1)] = COM(i, K-1)

ans = 0
for i in range(K-1, N):
  ans += A[i] * comb[(i, K-1)]
  ans %= p 
for i in range(K-1, N):
  ans -= B[i] * comb[(i, K-1)]
  ans %= p
print(ans)



### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
B = A[:][::-1]

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
  #N_C_kのN
  for i in range(2, 10**5+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod

COMinit()

comb = {}
for i in range(K-1, N):
  comb[(i, K-1)] = COM(i, K-1)

ans = 0
for i in range(K-1, N):
  ans += A[i] * comb[(i, K-1)]
  ans %= Mod
for i in range(K-1, N):
  ans -= B[i] * comb[(i, K-1)]
  ans %= Mod
print(ans)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0


for i in range(1,N):
    l = min(K,i)
    data = []
    dp[i] = min(data, dp[i-j]+abs(h[i] - h[i-j])) for j in range(1,l+1)
print(dp[N-1])

### FIXED CODE ###

def test():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [float('inf')]*N
    dp[0] = 0
 
    for i in range(1, N):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()
import itertools
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
store = [0,0]
num_list = range(L,R+1)
combination_list = list(itertools.combinations(num_list,2))

for comb in combination_list:
    mod = (comb[0] * comb[1] ) % 2019
    if mod < min_num:
        min_num = mod
        if mod == 0:
            break

print(min_num)

### FIXED CODE ###

LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
flag = False
for l in range(L,R):
    for r in range(l+1,R+1):
        mod = (l*r) %2019
        if mod < min_num:
            min_num = mod
            if mod == 0:
                flag =True
                break
    if flag:
        break

print(min_num)
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
max1=0
s=0
c=[]
p=0
for i in range(n):
    s+=a[i]
    c.append(s)

    if i-k>-1:
        b.append(s-c[i-k])


t=max(b)
r=b.index(t)

for i in range(r+1,r+k+1):
    p+=(1/a[i])*(a[i]*(a[i]+1)/2)
print(p)


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
max1=0
s=0
c=[]
p=0
if n==k:
    for i in range(n):
        p += (1 / a[i]) * (a[i] * (a[i] + 1) / 2)
else:
    for i in range(n):
        s+=a[i]
        c.append(s)

        if i-k>-1:
            b.append(s-c[i-k])


    t=max(b)
    r=b.index(t)

    for i in range(r+1,r+k+1):
        p+=(1/a[i])*(a[i]*(a[i]+1)/2)
print(p)
N = int(input()
if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))

### FIXED CODE ###

N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))
H,W = map(int,input().split())
L = []
A = ['A','B','C','D','E','F','G','H','I','J']
for i in range(H):
  L.append(input().split())
for i in range(H):
  for j in range(W):
    if L[i][j] == 'snuke':
      k = i+1
      l = A[j]
      break
print(l+str(k))

### FIXED CODE ###

H,W = map(int,input().split())
L = []
A = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(H):
  L.append(input().split())
for i in range(H):
  for j in range(W):
    if L[i][j] == 'snuke':
      k = i+1
      l = A[j]
      break
print(l+str(k))
n,m=map(int,input().split())

a=list(map(int,input().split()))
s=sum(a)

if n-a> 0:
  print(n-a)
  
else:
  print(-1)

### FIXED CODE ###

n,m=map(int,input().split())
 
a=list(map(int,input().split()))
s=int(sum(a))
 
if (n-s)>= 0:
  print(n-s)
  
else:
  print(-1)
N = int(input())
H = list(map(int, input().split()))
for i in range(N-1):
  if H[i] > H[i+1] + 1:
    print("No")
    exit()
  elif H[i] <= H[i+1]:
    if i > 0:
      if H[i-1] <= H[i]-1:
        H[i] -= 1        
  elif H[i] == H[i+1] + 1:
    H[i] -= 1
    if i > 0:
      if H[i-1] > H[i]:
        print("No")
        exit()
print("Yes")

### FIXED CODE ###

s = input()
# RR...RL...LLとなる文字列ssに分割して考える
import math
# len(ss) % 2 == 0 の場合は、境界にlen(ss)/2ずつ
# 奇数の場合は、ss[0]大、ss[1]小、→ss[偶数]大、ss[奇数]小
ans = [0] * len(s)
ss = []
start = 0
for i in range(len(s) - 1):
  if (s[i]=="L" and s[i+1]=="R"):
    ss.append(s[start:i+1])
    start = i+1
  elif i == len(s) - 2:
    ss.append(s[start:i+2])  
#print(ss)
# rlposはr,lの位置
sumlenj = 0
for j in ss: 
  rlpos = j.find("RL")
  if len(j) % 2 == 0:
    ans[sumlenj+rlpos] = int(len(j)/2)
    ans[sumlenj+rlpos+1] = int(len(j)/2)
  else:
    if rlpos % 2 == 0:
      ans[sumlenj+rlpos] = int(math.ceil(len(j)/2))
      ans[sumlenj+rlpos+1] = int(math.floor(len(j)/2))
    else:
      ans[sumlenj+rlpos] = int(math.floor(len(j)/2))
      ans[sumlenj+rlpos+1] = int(math.ceil(len(j)/2))
  sumlenj += len(j)
print(*ans)
x=int(input())

if x>0:
    if x%11>5:
        ans=(x//11)*2+2


    elif 1<=x%11<=5:
        ans=(x//11)*2+1
else:
    ans==(x//11)*2

print(ans)

### FIXED CODE ###

x = int(input())
 
ans = (x//11)*2
remainder = x%11
if remainder == 0:
    print(ans)
elif 1 <= remainder <= 6:
    print(ans+1)
else:
    print(ans+2)
n = int(input())
ans = 0
for i in range(n):
    a, b = list(map(int, input().split))
    ans = b - a +1
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(n):
    a, b = list(map(int, input().split()))
    ans += b - a +1
print(ans)
n=input()
t,a=map(int,input().split())
h=list(map(int,input()))
h2=[abs(t-x*0.006) for x in h]
print(h2.index(min(h2))+1)
    
    

### FIXED CODE ###

n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
h2=[abs(t-x*0.006-a) for x in h]
print(h2.index(min(h2))+1)
n,p=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]%2==1:
    c=1
    break
if c=1:print(2**(n-1))
else:
  if p=0:print(2**(n))
  else:print(0)

### FIXED CODE ###

n,p=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]%2==1:c+=1
if c==0:
  if p==0:print(2**n)
  else:print(0)
elif c==n:
  if n!=1:print(2**(n-1))
  else:print(0)
else:print(2**(n-1))
a, b = map(int(input().split()))

print(a*b), (a*2+b*2)


### FIXED CODE ###

a, b = map(int, input().split())
c=a*b
d=a*2+b*2
print(c, d)
N = int(input())
nums = [int(s) for s in input().split()]

min_breaks = -1

count_num = 1
for i in range(N):
  check_num = count - nums[i]
  if nums[i] == count_num:
      if min_breaks == -1:
          min_breaks = 0
      min_break += i - count_num
      
if min_break < N:    
    print(min_break)
else:
    print(-1)

### FIXED CODE ###

N = int(input())
nums = [int(s) for s in input().split()]
 
min_breaks = -1
 
count_num = 1
break_index = 1

for i in range(N):
  if nums[i] == count_num:
      if min_breaks == -1:
          min_breaks = 0
      if count_num == 1:
      	 min_breaks += ((i+1) - break_index)
      else:
         min_breaks += ((i+1) - break_index - 1)
      
      break_index = (i+1)
      count_num+=1

if break_index < N and min_breaks != -1:
  min_breaks += ((i+1) - break_index)
  
print(min_breaks)
c = str(input())
if c in {a,i,u,e,o}:
    print("vowel")
else:
    print("consonant")


### FIXED CODE ###

c = str(input())
if c in ["a","i","u","e","o"]:
    print("vowel")
else:
    print("consonant")
n,k=map(int,input().split())
    h=list(map(int,input().split()))
    dp=[1<<60]*(n)
    dp[0]=0
    for i in range(1,n):
        for j in range(1,(k+1)):
            if i>=j:
                dp[i]=min(abs(h[i-j]-h[i])+dp[i-j],abs(dp[i]))
            else:
                break
    print(dp[-1])

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(abs(h[i-1]-h[i])+dp[i-1],abs(h[i-2]-h[i])+dp[i-2])
print(dp[-1])
a=int(input())
b=int(input())
print(max(a-b,0))

### FIXED CODE ###

a, b = map(int, raw_input().split())
print max(a - b, 0)
a=int(input())
b=input()
if a%2!=0:
  print("No")
else:
  a/=2
  c=b[:a]
  d=b[a:]
  if c==d:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

a=int(input())
b=input()
if a%2!=0:
  print("No")
else:
  a//=2
  c=b[:a]
  d=b[a:]
  if c==d:
    print("Yes")
  else:
    print("No")
S = input()
ok = True
for i in range(0, len(S), 2):
    if not (S[i] == "h" and S[i + 1] == "i"):
        ok = False
        break
print("Yes" if ok else "No")


### FIXED CODE ###

S = input()
ok = True
for i in range(0, len(S), 2):
    try:
        if not (S[i] == "h" and S[i + 1] == "i"):
            ok = False
            break
    except IndexError:
        ok = False
        break
print("Yes" if ok else "No")
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())
ps = [None]*n
# ps2 = [None]*n
j = 0
for i in range(n):
    if j<i:
        j = i
    while j+1<n and x[j+1]-x[i]<=l:
        j += 1
    ps[i] = j
# ダブリング
def double(ps):
    # global: n=psのサイズ
    k = 0
    n = len(ps)
    while pow(2,k)<n:
        k += 1
    prev = [[None]*n for _ in range(k)] # ノードjから2^i個上の上司
    for j in range(n):
        prev[0][j] = ps[j]
    for i in range(1,k):
        for j in range(n):
            p = prev[i-1][j]
            if p>=0:
                prev[i][j] = prev[i-1][p]
            else:
                prev[i][j] = p
    return prev
dl = double(ps)
ans = [None]*q
for i in range(q):
    a,b = map(lambda x: int(x)-1, input().split())
    a,b = min(a,b), max(a,b)
#     print(a,b)
    res = 0
    for k in range(len(dl)-1, -1, -1):
        if dl[k][a]<b:
            a = dl[k][a]
            res += pow(2,k)
        elif dl[k][a]==b:
            tmp = res+pow(2,k)
            break
        else:
            tmp = min(tmp, res+pow(2,k))
    ans[i] = tmp
write("\n".join(map(str, ans)))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())
ps = [None]*n
# ps2 = [None]*n
j = 0
for i in range(n):
    if j<i:
        j = i
    while j+1<n and x[j+1]-x[i]<=l:
        j += 1
    ps[i] = j
# ダブリング
def double(ps):
    # global: n=psのサイズ
    k = 0
    n = len(ps)
    while pow(2,k)<n:
        k += 1
    prev = [[None]*n for _ in range(k)] # ノードjから2^i個上の上司
    for j in range(n):
        prev[0][j] = ps[j]
    for i in range(1,k):
        for j in range(n):
            p = prev[i-1][j]
            if p>=0:
                prev[i][j] = prev[i-1][p]
            else:
                prev[i][j] = p
    return prev
dl = double(ps)
ans = [None]*q
for i in range(q):
    a,b = map(lambda x: int(x)-1, input().split())
    a,b = min(a,b), max(a,b)
#     print(a,b)
    res = 0
    tmp = float("inf")
    for k in range(len(dl)-1, -1, -1):
        if dl[k][a]<b:
            a = dl[k][a]
            res += pow(2,k)
#         elif dl[k][a]==b:
#             tmp = res+pow(2,k)
#             break
        else:
            tmp = min(tmp, res+pow(2,k))
    ans[i] = tmp
write("\n".join(map(str, ans)))
from numba import jit
import time
import numpy as np
t = time.time()
INF = 1 << 60


@jit
def Nap(h, n, ab, dp):

    for i in range(1, h + 10001):
        val = INF
        for j in range(n):
            if (i >= ab[j][0]):
                val = min(val, dp[i-ab[j][0]] + ab[j][1])
        dp[i] = min(val, dp[i])

    res = INF
    for i in range(h, h+10001):
        res = min(res, dp[i])
    return res


def pri(t):
    print("elapsed time:{:.2f}".format(time.time()-t))


def main():
    h, n = map(int, input().split())
    #ab = [[0, 0] for _ in range(n)]
    ab = np.zeros((n, 2), dtype=int)
    for i in range(n):
        a, b = map(int, input().split())
        ab[i][0] = a
        ab[i][1] = b

    #dp = [INF for _ in range(h+10001)]
    dp = np.full(h+10001, INF, dtype=int)

    dp[0] = 0
    print(Nap(h, n, ab, dp))
    # pri(t)


main()


### FIXED CODE ###

h, n = map(int, input().split())

ab = [[0, 0] for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    ab[i][0] = a
    ab[i][1] = b

INF = 1 << 60
dp = [INF for _ in range(h+10001)]

dp[0] = 0

for i in range(1, h+10001):
    for j in range(n):
        if(i >= ab[j][0]):
            dp[i] = min(dp[i-ab[j][0]] + ab[j][1], dp[i])

res = INF
for i in range(h, h+10001):
    res = min(res, dp[i])
print(res)
A1,A2,A3=map(int,input().split)

if A1+A2+A3>=22:
    print("bust")
else:
    print("win")

### FIXED CODE ###

A1,A2,A3=map(int,input().split())

if A1+A2+A3>=22:
    print("bust")
else:
    print("win")
X, N = input().split()
p = list(map(int, input().split()))

ans = 0
for i in range(1, 102):
    if abs(X - i) < abs(ans - i) and i not in p and i != X:
        ans = i

print(ans)


### FIXED CODE ###

X, N = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for i in range(1, 102):
    if abs(X - i) < abs(X - ans) and i not in p:
        ans = i
print(ans)
S = input()
l = []
for i in S:
    l.append(i)

c = 0
cnt = []
for j in range(len(l)):
    if l[j] == 'A' or l[j] == 'T' or l[j] == 'C' or l[j] == 'G':
        c+=1
    else:
        cnt.append(c)
        c = 0

print(max(cnt))

### FIXED CODE ###

S = input()
l = []
for i in S:
    l.append(i)

c = 0
cnt = []
for j in range(len(l)):
    if l[j] == 'A' or l[j] == 'T' or l[j] == 'C' or l[j] == 'G':
        c+=1
        cnt.append(c)
    else:
        cnt.append(c)
        c = 0

#print(cnt)
print(max(cnt))
i int x,y ;
x=input();
y=x^3 ;
print y ;

### FIXED CODE ###

x=input();
y=x*x*x ;
print y ;
from collections import  defaultdict
from collections import deque
import math
N = int(input())

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


d = defaultdict(list)

for a,b in AB:
    d[a-1].append(b-1)
    d[b-1].append(a-1)


def get_distance(start):
    visited = set([start,])
    distance = [999999999999999999 for _ in range(N)]
    distance[start ] =0
    to_visit = deque([ (1,a) for a in d[start]])

    while to_visit:
        dist,now = to_visit.popleft()
        visited.add(now)
        distance[now]=dist
        for a in d[now]:
            if a not in visited:
                to_visit.append((dist+1,a))

    return distance



a =(get_distance(0))
b= (get_distance(N-1))


for i in range(N):
    if a[i]==b[i] or a[i]==b[i]+1:
        middle_a = i
        #middle_b
        for j in d[i]:
            if b[j]==b[i]-1:
                middle_b = j

"""
print(a)
print(b)
print(middle_a)
print(middle_b)
"""
x = get_distance(0)
max_ = math.ceil(x[N-1]/2)





d[middle_a].remove(middle_b)
d[middle_b].remove(middle_a)

a_new = (get_distance(0))
b_new = (get_distance(N-1))
if sum( q<99999999999999999 for q in a_new ) >sum( q<99999999999999999 for q in b_new ):
    print("Fennec")
else:
    print("Snuke")
#route to -1
#0
#N-1





### FIXED CODE ###

from collections import  defaultdict
from collections import deque
import math
N = int(input())

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


d = defaultdict(list)

for a,b in AB:
    d[a-1].append(b-1)
    d[b-1].append(a-1)


def get_distance(start):
    visited = set([start,])
    distance = [999999999999999999 for _ in range(N)]
    distance[start ] =0
    to_visit = deque([ (1,a) for a in d[start]])

    while to_visit:
        dist,now = to_visit.popleft()
        visited.add(now)
        distance[now]=dist
        for a in d[now]:
            if a not in visited:
                to_visit.append((dist+1,a))

    return distance



a =(get_distance(0))
b= (get_distance(N-1))

distance_ = a[N-1]

def get_close(a,i):
    l = list(sorted([(a[x],x) for x in d[i]]))
    return l[0][1]

tmp = N-1
for i in range((distance_+1)//2-1):
   tmp = get_close(a,tmp)

middle_a = get_close(a,tmp)
middle_b = tmp



x = get_distance(0)
max_ = math.ceil(x[N-1]/2)





d[middle_a].remove(middle_b)
d[middle_b].remove(middle_a)


a_new = (get_distance(0))
b_new = (get_distance(N-1))
"""
print(a)
print(b)
print(middle_a)
print(middle_b)
print(a_new,b_new)
"""
if sum( q<99999999999999999 for q in a_new ) >sum( q<99999999999999999 for q in b_new ):
    print("Fennec")
else:
    print("Snuke")
N = int(input())
Di1 = []
Di2 = []
nmDi = 0
if N >= 3 and N <= 100:
   for x in range(N):
      Di1.append(int(input()))
      Di2.append(int(input()))
for x in range(N):
   if Di1[x] == Di2[x]:
      nmDi += 1
      if nmDi == 3:
         break
   elif Di1[x] != Di2[x] and nmDi > 0:
      nmDi = 0
if nmDi >= 3:
   print("Yes")
else:
   print("No")

### FIXED CODE ###

N = int(input())
Di = 0
Di1 = []
Di2 = []
nmDi = 0
if N >= 3 and N <= 100:
   for x in range(N):
      Di = input()
      Di1.append(Di[0])
      Di2.append(Di[-1])
   for x in range(N):
      if Di1[x] == Di2[x]:
         nmDi += 1
         if nmDi == 3:
            break
      elif Di1[x] != Di2[x] and nmDi > 0:
         nmDi = 0
   if nmDi >= 3:
      print("Yes")
   else:
      print("No")
else:
   print ("No")
N = input()
A = list(map(int,input().split()))
raw =sum(A)
con = 0

for i in A:
    if A[con] > A[con+1]:
        A[con+1] =  A[con]
        print(A)
        
    if A[con+1] == A[-1]:
        break

    con += 1

ans = sum(A) - raw
print(ans)

### FIXED CODE ###

N = input()
A = list(map(int,input().split()))
raw =sum(A)
con = 0

if len(A) == 1:
    print(0)
    
else:
    for i in A:
        if A[con] > A[con+1]:
            A[con+1] =  A[con]
        
        if A[con+1] == A[-1]:
            break

        con += 1

    ans = sum(A) - raw
    print(ans)
import sys
sys.setrecursionlimit(10000)

n, m = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
g = [list() for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
v = [False] * n
s = set()
def dfs(i):
    if v[i]: return
    s.add(i)
    v[i] = True
    for k in g[i]: dfs(k)

c = 0
for i in range(n):
    if v[i]: continue
    s = set()
    dfs(i)
    t = {p[k] for k in s}
    c += len(s.intersection(t))
print(c)


### FIXED CODE ###

s = input()
k = int(input())
t = set()
for i in range(1, min(len(s), k, 5) + 1):
  for j in range(len(s) - i + 1):
	  t.add(s[j:i + j])
print(sorted(list(t))[k - 1])
n = int(input())
x = [int(x) for x in input().split()]
inf = 10**9+7
a = 1
for i in range(n-1, 0, -1):
    a *= i
    a %= inf
key = 0
ans = 0
for i in range(n-1):
    key += a//(i+1)
    key %= inf
    ans += key*(x[i+1]-x[i])
    ans %= inf
    

print(ans)



### FIXED CODE ###

n = int(input())
s = [0]*n
t = [0]*n
for i in range(n):
    a, b = map(str, input().split())
    b = int(b)
    s[i], t[i] = a, b
k = input()

for i in range(n):
    if s[i] == k:
        key = i+1
        
ans = sum(t[key:])
print(ans)
print( ( int(input()) - 1 ) * ( int(input()) - 1) )

### FIXED CODE ###

n, m = map(int, input().split())
print((m - 1) * (n - 1))
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
res = 0
res += B[A[0]]
for i in range(1, N):
    res += B[A[i]-1]
    if A[i - 1] == A[i] - 1:
        res += C[A[i - 1]-1]

print(res)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
res = 0
res += B[A[0]-1]
for i in range(1, N):
    res += B[A[i]-1]
    if A[i - 1] == A[i] - 1:
        res += C[A[i - 1]-1]

print(res)
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(n):
  for ri in ret_dividable(a[i]):
    if ri in d.keys():
      d[ri]+=1
    else:
      d[ri]=1 

# 出現数が1番目に多い値を取得(二段階で並べ替え)
tmp = sorted(d.items(),key = lambda x:(x[1],x[0]) ,reverse=True)


# 全ての ai が同じ場合、答えは ai
issame = (sum([1 for ai in a if ai==a[0]]) == n)
if issame:
  print(a[0])
else:  
  # 出現数が2番目に多いものだけ抜き取る
  freq_2 = [t for t in tmp if t[1]==n-1]
  if len(freq_2)>0:
    print(freq_2[0][0])
  else:
    print(1)

### FIXED CODE ###

import fractions

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

ans = 0

ls = [0]*n
rs = [0]*n

for i in range(1,n):
  ls[i] = fractions.gcd(ls[i-1],a[i-1])
  rs[i] = fractions.gcd(rs[i-1],a[-i])

ans = 0
for i in range(n):        
    ans = max(ans,fractions.gcd(ls[i],rs[-i-1]))

print(ans)
s = input()
s = list(s)

if len(s) < 2:
  a = 0
elif len(s) == 2:
  if s[0] == 'h' and s[1] == 'i':
    a = 1
  else:
    a = 0
else:
  for i in range(len(s)-2):
    if s[i] == 'h':
      if s[i+1] == 'i' and s[i+2] != 'i':
        a += 1
    
if a >= 1:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

s = input()
hi = [s[i:i+2] for i in range(0, len(s), 2)]

a = 0
for i in range(len(hi)):
  if hi[i] != 'hi':
    a += 1
    break
    
if a == 1:
  print('No')
else:
  print('Yes')
from functools import lru_cache
import sys
sys.setrecursionlimit(2147483647)

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))

@lru_cache(None)
def dfs(d,pre):
    if d>=N-1: return 0
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,idx) + a 
            tmp.append(res)
    return max(tmp)

print(dfs(-1,-1))

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int, input().split()))
dp = [0 for _ in range(len(A))]
dp[0] = 0 
for i in range(1,N):
    tmp = [float("inf")]
    for j in range(1,K+1):
        if i - j>=0:
            tmp.append(dp[i-j] + abs(A[i] - A[i-j]))
    dp[i] = min(tmp)

print(dp[len(A)-1])
K, S = [int(x) for x in input().split()]
ans = 0
for x in range(K+1):
    for y in range(K+1):
        if S-x-y =< K:
            ans +=1
print(ans)

### FIXED CODE ###

K, S = [int(x) for x in input().split()]
ans = 0
for x in range(K+1):
    for y in range(K+1):
        a = S-x-y
        if a <= K and a >= 0:
            ans +=1
print(ans)
n=int(input())
a,b,c,d=0,0,0,0
for i in range(n):
    if str(input())=='AC':a+=1
    elif str(input())=='WA':b+=1
    elif str(input())=='TLE':c+=1
    else:d+=1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)

### FIXED CODE ###

n=int(input())
a,b,c,d=0,0,0,0
l=[input() for _ in range(n)]
for i in range(n):
    if l[i]=='AC':a+=1
    elif l[i]=='WA':b+=1
    elif l[i]=='TLE':c+=1
    else:d+=1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)