Harryxun/stf_run huggingface dataset:
N, Q = map(int, input().split())
S = input()

cnt = [0] * 20010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 20010
flag = [0] * 20010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 : ans -= 1
    print("{}".format(ans))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

cnt = [0] * 200010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 200010
flag = [0] * 200010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 :
        ans -= 1
    print("{}".format(ans))
def dfs(v, parent):
    for tail, weight in adj[v]:
        if tail == parent:
            continue
        dist[tail] = dist[v] + weight
        dfs(tail, v)


n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = [int(x) for x in input().split()]
    adj[a].append((b, c))
    adj[b].append((a, c))
q, k = [int(x) for x in input().split()]
dist = [0] * (n + 1)
dfs(k, k)
for j in range(q):
    l, r = [int(x) for x in input().split()]
    print(dist[l] + dist[r])
# print(*data, sep='\n')


### FIXED CODE ###

import sys
import collections

n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = [int(x) for x in input().split()]
    adj[a].append((b, c))
    adj[b].append((a, c))
q, k = [int(x) for x in input().split()]
dist = [0] * (n + 1)
queue = collections.deque()
queue.append(k)
while len(queue) > 0:
    u = queue.popleft()
    for v, weight in adj[u]:
        if dist[v] == 0:
            queue.append(v)
            dist[v] = dist[u] + weight
for j in range(q):
    l, r = [int(x) for x in input().split()]
    print(dist[l] + dist[r])
# print(*data, sep='\n')
n =int(input())
a =list(int(input()) for i in range(n))

dict = {}
for i in range(n):
  if not(a[i] in dict):
    dict(a[i]) =1
  if s[i] in dict:
    dict.pop(a[i])
    
print(len(dict))
  


### FIXED CODE ###

n = int(input())
d = {}
for i in range(n):
    a = int(input())
    if a in d:
        del d[a]
    else:
        d[a] = 1
print(len(d))
if N == 1:
    print("Hello World")
elif N == 2:
    print(A + B)


### FIXED CODE ###

N = int(input())
if N == 1:
    print("Hello World")
elif N == 2:
    A = int(input())
    B = int(input())
    print(A + B)
c=0
def doublet(n,f):
    global c
    if n<f:
        c=c+1
        return doublet(2*n,f)
    else:
        return c
num=eval(input("n= "))
k=eval(input("k="))
sum_power=0.0
for i in range(1,(num+1),1):
    count=doublet(i,k)
    p=pow(2,count)*num
    sum_power=sum_power+(1/p)
    c=0
print(sum_power)


    


### FIXED CODE ###

c=0
def doublet(n,f):
    global c
    if n<f:
        c=c+1
        return doublet(2*n,f)
    else:
        return c
num,k=input().split()
num=int(num)
k=int(k)
#k=eval(input())
if (num>=1 and num<=10**5) and (k>=1 and k<=10**5):
    sum_power=0.0
    for i in range(1,(num+1),1):
        count=doublet(i,k)
        p=pow(2,count)*num
        sum_power=sum_power+(1/p)
        c=0
    print(sum_power)
r,D,x = map(int,input().split())

tmp = r * x - D
print(tmp)

for i in range(1 to 10):
  tmp = tmp * x - D
  print(temp)

### FIXED CODE ###

r,D,x = map(int,input().split())
 
tmp = r * x - D
print(tmp)
 
for i in range(1 , 10):
  tmp = tmp * r - D
  print(tmp)
from collections import deque
import math
import os
import random
import re
import sys
#n=list(map(int, input().split()))
#n=map(int, input().split())

def main():
	din=input()
	if din[1] != '0':
		print('100')
	else:
		print('0')
main()

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





### FIXED CODE ###

from collections import deque
import math
import os
import random
import re
import sys
#n=list(map(int, input().split()))
#n=map(int, input().split())

def main():
	n=int(input())
	change = n%1000
	if change:
		print(1000-change)
	else:
		print(0)
		
	
main()

'''
if __name__ == '__main__':
    main()
'''
N=int(input())
a=[0]*N
for i in range(N):
    a[i]=int(input())
minimum=1
count=0
for i in  a:
   if(minimum<i):
       if i%minimum:
           count+= i//minimum
       else :
           count+= (i//minimum-1)
   else:
       minimum=max(minimum,i+1)
print(count)


### FIXED CODE ###

s=input()
a="CODEFESTIVAL2016"
count=0
for a,b in zip(s,a) :
    if a != b :
        count+=1 
print(count)
n=int(input())

list=[]

for i in range(1,12):
    a=n%i
    if a == 0:
        if(i<n/i):
            list.append([i,int(n/i)])
        else:
            list.append([int(n/i),i])

    if i>1 :
        if len(list) == 1:
            ans=(list[-1][0]-1)+(list[-1][1]-1)
            break
        if list[-1]==list[-2] or len(list)==1:
            ans=(list[-1][0]-1)+(list[-1][1]-1)
            break
print(ans)

### FIXED CODE ###

import math

n = int(input())

for i in range(int(math.sqrt(n)), 0, -1):
  if n % i == 0:
    print(int(i + n / i - 2))
    break
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)
      
      
n = int(input())
sn = {}
sn_list = []
for i in range(n):
    s = input()
    sn_list.append(s)
for s in sn_list:
    s = "".join(sorted(s))
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1

count = 0
for v in sn.values():
    count += sigma(v)
print(count)

### FIXED CODE ###

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())
 
    for s in array_s:
        array.append(''.join(sorted(s)))
    array = sorted(array)
    ans = 0
    count = 1
    for i in range(n-1):
        if array[i] == array[i+1]:
            count += 1
            if i != n-2:
                continue
        ans += int(count*(count-1)/2)
        count = 1
    print(ans)
 
 
if __name__ == '__main__':
    main()
n , m = map(int, input().split())
a = []
p = 0
max_wid = 0
for i in range(m):
    b = int(input())
    a.append(b)
    if i > 0:
        max_wid = max(max_wid, b)
max_wid = max(max_wid, n - a[m-1])
fib = [1, 1]
for i in range(max_wid):
    l = len(fib)
    fib.append(fib[l-2] + fib[l-1])
 
ans = 1
if a[0] == 0:
    ans *= 0
else:
    ans *= fib[a[0]-1]
 
for i in range(m-1):
    if a[i+1] == a[i] + 1:
        ans *= 0
    else:
        ans *= fib[a[i+1]-a[i]-2]
        
 
ans *= fib[n - a[m-1]-1]
ans %= 1000000007
print(ans)

### FIXED CODE ###

n , m = map(int, input().split())
a = []
p = 0
max_wid = 0
if m == 0:
    max_wid = n
else:
    for i in range(m):
      b = int(input())
      a.append(b)
      if i > 0:
          max_wid = max(max_wid, b)
    max_wid = max(max_wid, n - a[m-1])

fib = [1, 1]
for i in range(max_wid):
    l = len(fib)
    fib.append(fib[l-2] + fib[l-1])
ans = 1
if m == 0:
  print(fib[n]%1000000007)
else:
  
  if a[0] == 0:
      ans *= 0
  else:
      ans *= fib[a[0]-1]
  for i in range(m-1):
      if a[i+1] == a[i] + 1:
          ans *= 0
      else:
          ans *= fib[a[i+1]-a[i]-2]
  ans *= fib[n - a[m-1]-1]
  ans %= 1000000007
  print(ans)
import sys

input = sys.stdin.readline

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

def eval(N,S):
    total=0
    for i in range(1,N):
        if S[i]==S[i-1]:total+=1
    return total

start_num=1
  
for k in range(K):
    if S==['R']*N or S==['L']*N:break
    j=[]
    for i in range(start_num, N):
        if S[i-1]!=S[i]:
            j.append(i)
            if len(j)==2:break
    if len(j)==1:j.append(N)
    if S[j[0]]=='R':
        S[j[0]:j[1]]=['L']*(j[1]-j[0])
    else:S[j[0]:j[1]]=['R']*(j[1]-j[0])
    start_num=j[1]+1
print(eval(N,S))
  


### FIXED CODE ###

import sys
from collections import deque

input = sys.stdin.readline

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

sq = deque(S)
lst=[]
j=0

for i in range(K):
    j=0
    if not sq:break
    sq_1st = sq.popleft()
    sq_2nd = sq_1st
    lst.append(sq_1st)

    while sq:
        sq_3rd = sq.popleft()
        if sq_2nd!=sq_3rd:
            j+=1
            sq_2nd=sq_3rd
            if j==2:
                sq.appendleft(sq_3rd)
                break
        lst.append(sq_1st)

lst+=list(sq)             

def eval(N,S):
    total=0
    for i in range(1,N):
        if S[i]==S[i-1]:total+=1
    return total
  
print(eval(N,lst))
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s), -1, 0):
                for y in range(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()



### FIXED CODE ###

import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    L = len(s)
    tmp = []
    tt = ''
    for i, ss in enumerate( s ):
        tmp += [ s[L-i-1] ]
        if s[L-i-1] > s[L-i-2]:
            ans = s[:L-i-2]
            tt = s[L-i-2] 
            break
    tmp.sort()
    for i in tmp:
        if i > tt:
            print (ans + i)
            break
main()
h, w = map(int, input().split())
m = [list(map(int, input().split())) for i in range(h)]

r = True
act = list()
for i in range(1, h+1):
  r = not r
  for j in sorted(range(1, w+1), reverse=r):
    if m[i-1][j-1] % 2 == 1:
      if not r:
        # 下に進む
        if j == w:
          if i == h:
            break
          m[i][j-1] += 1
          act.append((i, j, i+1, j))
        # 右に進む
        else:
          m[i-1, j] += 1
          act.append((i, j, i, j+1))
      else:
        # 下に進む
        if j == 1:
          if i == h:
            break
          m[i][j-1] += 1
          act.append((i, j, i+1, j))
        # 左に進む
        else:
          m[i-1][j-2] += 1
          act.append((i, j, i, j-2))
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
print(len(act))
[print(*x) for x in act]  
#print(m)


### FIXED CODE ###

import numpy as np
h, w = map(int, input().split())
m = np.array([list(map(int, input().split())) for i in range(h)])

r = True
act = list()
for i in range(1, h+1):
  r = not r
  for j in sorted(range(1, w+1), reverse=r):
    if m[i-1, j-1] % 2 == 1:
      if not r:
        # 下に進む
        if j == w:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        # 右に進む
        else:
          m[i-1, j] += 1
          act.append((i, j, i, j+1))
      else:
        # 下に進む
        if j == 1:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        # 左に進む
        else:
          m[i-1, j-2] += 1
          act.append((i, j, i, j-1))
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
print(len(act))
[print(*x) for x in act]  
#print(m)
n,a,b=map(int,input().split())

ans=0
for i in ranpe(1,n+1):
  s=0
  x=i
  while 0<x:
    s+=x%10
    x=x//10
  if a<=s and s<=b:
    ans+=i
print(ans)


### FIXED CODE ###

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

ans=0
for i in range(1,n+1):
  s=0
  x=i
  while 0<x:
    s+=x%10
    x//=10
  if a<=s and s<=b:
    ans+=i
print(ans)
num = input()
le = len(num)
sum=0
for i in range(le):
  sum += int(num[i])
if sum%==0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import math
n,x,t = map(int,input().split())
c = t*math.ceil(n/x)
print(c)
import math

N, K = map(int, input().split())
mod = 1000000007

def P(n, k):
    return math.factorial(n)//math.factorial(n-k)

def C(n, k):
    return P(n, k)//math.factorial(k)

for i in range(1, K+1):
    print(((C(N-K+1, i)%mod)*(C(K-1, i-1)%mod))%mod)


### FIXED CODE ###

import math

N, K = map(int, input().split())
mod = 1000000007

# 順列(Permutation)を求める関数
def P(n, k):
    return math.factorial(n)//math.factorial(n-k)
    
# 組合せ(Combination)を求める関数
def C(n, k):
    return P(n, k)//math.factorial(k)
   
for i in range(1, K+1):
    if (N-K+1 < i) or (K-1 < i-1):
        print(0)
    else:
        print(((C(N-K+1, i)%mod)*(C(K-1, i-1)%mod))%mod)
# coding: utf-8
import sys
input = sys.stdin.readline

N = input()
S = sum(map(int, N))
print("Yes" if int(N)%S==0 else "No")

### FIXED CODE ###

# coding: utf-8
N= input()
S = sum(map(int, N))
print("Yes" if int(N)%S==0 else "No")
a, b, c = map(int, input().split())
if c-(a+b)>sqrt(a*b): print('Yes')
else: print('No')

### FIXED CODE ###

a, b, c = map(int, input().split())
if c>=a+b and (c-(a+b))*(c-(a+b))-4*a*b>0: print('Yes')
else: print('No')
if (a + b) > k:
    if a < k:
        b = b - (k - a)
        a = 0
    else:
        a = k - a
else:
    a, b = 0, 0

print(a, b)

### FIXED CODE ###

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

if (a + b) >= k:
    if a >= k:
        a = a - k
    else:
        b = b - (k-a)
        a = 0
else:
    a, b = 0, 0

print(a, b)
S=raw_input()
N=len(S)
n=len(S)/2
if N%2==1: c=n	# c:center

cnt=0
for i in range(1,n+1):
	if N%2==1:
		if S[c-i]==S[c+i]==S[c]:
			cnt=1+2*i
			pass
		else:
			if i==n:
				cnt+=1
			break
	else:	
		if S[n-i]==S[n+i]:
			cnt=2*n
		else:
			break
if N%2==1:
	print max(n+1,cnt)
else:
	print max(n, cnt)



### FIXED CODE ###

S=raw_input()
N=len(S)
TS=N
for k in range(N-1):
	if S[k]!=S[k+1]:
		TS=min(TS, max(k+1, N-k-1))

print TS
import sys
input = sys.stdin.readline

def p_count(n):
    return bin(n).count('1')


n = int(input())
x = input().rstrip()
x_dec = int(x,base = 2)

pop_cnt = x.count('1')
pop_cnt_0 = pop_cnt + 1
pop_cnt_1 = pop_cnt - 1

x_bit = [0]*n

for i in range(n-1,-1,-1):
    if x[i] == '0':
        x_bit[i] = (x_dec + pow(2,n-1-i))%pop_cnt_0
        
    else:
        x_bit[i] = (x_dec - pow(2,n-1-i))%pop_cnt_1

anslist = []
for i in range(n):
    ans = 1
    now = x_bit[i]
    while True:
        if now == 0:
            break
        now = now%p_count(now)
        
        ans += 1
    anslist.append(ans)


for ans in anslist:
    print(ans)






### FIXED CODE ###

import sys
input = sys.stdin.readline

def p_count(n):
    return bin(n)[2:].count('1')


n = int(input())
x = input().rstrip()
x_dec = int(x,base = 2)

pop_cnt = x.count('1')
pop_cnt_0 = (pop_cnt + 1)
pop_cnt_1 = (pop_cnt - 1)
x_0 = pow(x_dec,1,pop_cnt_0)
x_1 = pow(x_dec,1,pop_cnt_1) if pop_cnt_1 > 0 else 0

x_bit = [0]*n

for i in range(n-1,-1,-1):
    if x[i] == '0':
        x_bit[i] = (x_0 + pow(2,n-1-i,pop_cnt_0))%pop_cnt_0
        #x_bit[i] = (x_dec + pow(2,n-1-i))%pop_cnt_0
        
    else:
        if pop_cnt_1 > 0:
            x_bit[i] = (x_1 - pow(2,n-1-i,pop_cnt_1))
            x_bit[i] = x_bit[i] if x_bit[i] >= 0 else x_bit[i] + pop_cnt_1
        else:
            x_bit[i] = -1

anslist = []
for i in range(n):
    if x_bit[i] == -1:
        anslist.append(0)
        continue
    ans = 1 
    now = x_bit[i]
    while True:
        if now == 0:
            break
        now = now%p_count(now)
        
        ans += 1
    anslist.append(ans)


for ans in anslist:
    print(ans)
#最小公倍数でループ
import math
n = int(input())
ans = list(map(int,input().split()))
lcm = ans[0]
for k in ans:
    gcd = math.gcd(lcm, k)
    lcm = int(lcm*k/gcd)
#print(lcm)

an =0
for k in ans:
    an += (lcm-1)%k
        
print(an)

### FIXED CODE ###

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

print(sum(ans)-n)
S = list(input())
A = 0
B = 0
for s in S:
    if s == '0':
        A += 1
    else:
        B += 1
print(min(A,B)

### FIXED CODE ###

S = list(input())
A = 0
B = 0
for s in S:
    if s == '0':
        A += 1
    else:
        B += 1
print(min(A,B)*2)
#dpより愚直に作るか
k = int(input())
lun = [i for i in range(10)]
last = 10
while len(lun)<k:
    lun2 = []
    for i in lun:
        lun2.append(i*10+(i%10))
        if i%10:
            lun2.append(i*10+(i%10)-1)
        if (i%10)<9:
            lun2.append(i*10+(i%10)+1)
    last = len(lun2)
    lun = list(set(lun+lun2))
lun.sort()
print(lun[k])

### FIXED CODE ###

#dpより愚直に作るか
k = int(input())
lun = [i for i in range(10)]
while len(lun)<k+1:#正の整数
    lun2 = []
    for i in lun:
        lun2.append(i*10+(i%10))
        if i%10:
            lun2.append(i*10+(i%10)-1)
        if (i%10)<9:
            lun2.append(i*10+(i%10)+1)
    lun = list(set(lun+lun2))
lun.sort()
print(lun[k])
S = input()
T = input()

dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]
for i in range(1, len(S) + 1):
    for j in range(1, len(T) + 1):
        indicator = 1 if S[i - 1] == T[j - 1] else 0
        dp[i][j] = max(dp[i - 1][j - 1] + indicator, dp[i - 1][j], dp[i][j - 1])

ans = ''


def print_lcs(s, t, dp_table, i, j):
    global ans
    if i == 0 or j == 0:
        return
    if S[i - 1] == T[j - 1]:
        print_lcs(s, t, dp, i - 1, j - 1)
        ans += S[i - 1]
    else:
        if dp[i - 1][j] >= dp[i][j - 1]:
            print_lcs(S, T, dp, i - 1, j)
        else:
            print_lcs(S, T, dp, i, j - 1)


print_lcs(S, T, dp, len(S), len(T))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
S = input()
T = input()

dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]
for i in range(1, len(S) + 1):
    for j in range(1, len(T) + 1):
        indicator = 1 if S[i - 1] == T[j - 1] else 0
        dp[i][j] = max(dp[i - 1][j - 1] + indicator, dp[i - 1][j], dp[i][j - 1])

ans = ''


def print_lcs(s, t, dp_table, i, j):
    global ans
    if i == 0 or j == 0:
        return
    if S[i - 1] == T[j - 1]:
        print_lcs(s, t, dp, i - 1, j - 1)
        ans += S[i - 1]
    else:
        if dp[i - 1][j] >= dp[i][j - 1]:
            print_lcs(S, T, dp, i - 1, j)
        else:
            print_lcs(S, T, dp, i, j - 1)


print_lcs(S, T, dp, len(S), len(T))
print(ans)
import math
a,b,c,d = map(int,input().split())
count_c = 0
count_d = 0
count_cd = 0
count = 0
j = 1
g = c*d//math.gcd(c,d)
while(1)
    if c*j <= b and c*j>=a:
        count_c += 1
    if d*j <=b and d*j >= a:
        count_c += 1
    if g*j <=b and g*j >= a:
        count_cd += 1
    if c*j > b and d*j > b and g*j > b:
        break
    j += 1
s = count_c+count_d-count_cd
print(b-a +1-s)

### FIXED CODE ###

import fractions
a,b,c,d = map(int,input().split())
count_c = 0
count_d = 0
count_cd = 0
count = 0
j = 1
g = c*d//fractions.gcd(c,d)

count_c = b//c - (a-1)//c
count_d = b//d - (a-1)//d
count_cd = b//g -(a-1)//g
count_s = count_c+count_d-count_cd
print(b-a+1-count_s)
from itertools import accumulate

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


def solve():
    cnt=0
    l=[]
    prev = "1"

    for i in s:
        if prev ==i:
            cnt+=1
        else:
            l.append(cnt)
            cnt = 1
        prev=i
    l.append(cnt)
    if prev=="0":
        l.append("0")

    w = 2*k+1

    if len(l)<=w:
        return n

    acc = [0]+list(accumulate(l))
    ans = 0
    for i in range(0, len(l)-w+1,2):
        ans = max(ans,acc[i+w]-acc[i])
    return ans
print(solve())


### FIXED CODE ###

from itertools import accumulate

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


def solve():
    l = []
    prev = '1'
    cnt = 0
    for c in s:
        if prev == c:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 1
        prev = c
    l.append(cnt)
    if prev == '0':
        l.append(0)

    w = 2 * k + 1

    if len(l) <= w:
        return n

    acc = [0] + list(accumulate(l))
    ans = 0
    for i in range(0, len(l) - w + 1, 2):
        ans = max(ans, acc[i + w] - acc[i])
    return ans


print(solve())
import math

info = list(map(int, input().split()))
num = info[0]
dis = info[1]
A = [list(map(int, input().split())) for i in range(num)]
disA = [math.squart(A[i][0]^2 + A[i][1]^2) for i in range(num)]
cnt = 0 
for i in range(num):
    if disA <= dis:
        cnt += 1
print(cnt)


### FIXED CODE ###

import math

info = list(map(int, input().split()))
num = info[0]
dis = info[1]
A = [list(map(int, input().split())) for i in range(num)]
disA = [math.sqrt(A[i][0]**2 + A[i][1]**2) for i in range(num)]
cnt = 0 
for i in range(num):
    if disA[i] <= dis:
        cnt += 1
print(cnt)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
m=0
for i in range(N):
    m +=B[a[i] -1]
for i in range(N-1):
    if a[i] + 1 == a[i + 1]:
        m +=C[a[i] - 1]
print(m)
         
    

### FIXED CODE ###

N=int(input())
n= N*N*N
print(n)
import math
list=[int(input()) for x in range(5)]
list.sort(key=lambda x:x%10)
count=0
for l in list:
  if l%10==0:
    count+=1
a=list[count]
del list[count]
ans=[]
for t in list:
  ans.append(math.ceil(t/10)*10)
print(sum(ans)+a)

### FIXED CODE ###

import math
list=[int(input()) for x in range(5)]
list.sort(key=lambda x:x%10)
count=0
for l in list:
  if l%10==0:
    count+=1
if count==5:
  print(sum(list))
else:
  a=list[count]
  del list[count]
  ans=[]
  for t in list:
    ans.append(math.ceil(t/10)*10)
  print(sum(ans)+a)
n,m=map(int, input().split())
s=[[int(j) for j in input().split()] for i in range(n)]
ans=0
s.sort(reverse=True,key=lambda x:x[1])
for k in range(m):
    for i in range(n):
        if s[i][0]+k>m:
            print(s[i])
            s[i:i+1]=[]
            n=n-1
    if s==[]:
        break
    else:
        ans+=s[0][1]
        print(s[0])
        s[0:1]=[]
        n=n-1
print(ans)


### FIXED CODE ###

import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
q = []
heapq.heapify(q)
heapq.heapify(ab)
total = 0
for i in range(m, -1, -1):
    while True:
        if len(ab) != 0:
            p = heapq.heappop(ab)
            if p[0] + i <= m:
                heapq.heappush(q, -p[1])
            else:
                heapq.heappush(ab, p)
                break
        else:
            break
    if len(q) != 0:
        p = heapq.heappop(q)
        total += -p
print(total)
N,K = map(int,input().split())
S = input()

RLcount=0
for i in range(1,len(S)):
    if S[i-1:i+1]=="RL":
        RLcount+=1


if RLcount > K:
    temp = (RLcount-K)
    NN = N-2*temp
if S[0]=="L":
    NN -= 1
if S[-1]=="R":
    NN -= 1
if RLcount < K:
    NN = N-1

print(int(NN))

### FIXED CODE ###

N,K = map(int,input().split())
S = input()

count=0
for i in range(N-1):
    if S[i]==S[i+1]:
        count+=1
print(min(N-1, count+2*K))
x,y = map(int,input().split())
list = [input() for i in range(x)]

if list[0]<=list[1] and list[0]<=list[2]:
    if list[1]<=list[2]:
        print(list[0]+list[1]+list[2])
    else:
        print(list[0]+list[2]+list[1])

if list[1]<=list[0] and list[1]<=list[2]:
    if list[0]<=list[2]:
        print(list[1]+list[0]+list[2])
    else:
        print(list[1]+list[2]+list[0])

if list[2]<=list[0] and list[2]<=list[1]:
    if list[0]<=list[1]:
        print(list[2]+list[0]+list[1])
    else:
        print(list[2]+list[1]+list[0])


### FIXED CODE ###

go=0
nana=0
num = input().split()
for i in num:
  if i == "5":
    go+=1
  if i == "7":
    nana+=1
if (go==2) and (nana==1):
  print("YES")
else:
  print("NO")
import itertools
n, m = map(int, input().split())
adj_matrix = [[0] * n for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0
for each in range(itertools.permutations(range(n))):
    if each[0] != 0:
        break
    flag = 1
    for i in range(n-1):
        flag *= adj_matrix[each[i]][each[i+1]]
    cnt += flag
print(cnt)

### FIXED CODE ###

import itertools
n, m = map(int, input().split())
adj_matrix = [[0] * n for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0
for each in itertools.permutations(range(n)):
    if each[0] != 0:
        break
    flag = 1
    for i in range(n-1):
        flag *= adj_matrix[each[i]][each[i+1]]
    cnt += flag
print(cnt)
li = list(input().split())
li.sort()

print(li[2]-li[0])

### FIXED CODE ###

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

print(li[2]-li[0])