Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
ac = [False] * N
wa_cnt = [0] * N
ac_cnt = 0
for i in range(M):
    p, s = input().split()
    p_i = int(p) - 1
    if s == 'WA':
        if not ac[p_i]:
            wa_cnt[p_i] += 1
    else:
        if not ac[p_i]:
            ac[p_i] = True
            ac_cnt += 1

wa_cnt_sum = 0
for i in range(N):
    if ac_cnt[i]:
        wa_cnt_sum += wa_cnt[i]

print(ac_cnt,wa_cnt_sum)


### FIXED CODE ###

N, M = map(int, input().split())
ac = 0
is_AC = [False] * (N + 1)
WA_cnt = [0] * (N + 1)
for i in range(M):
    p, s = input().split()
    p = int(p)
    if s == 'WA':
        if is_AC[p]:
            continue
        else:
            WA_cnt[p] += 1
    else:
        if is_AC[p]:
            continue
        else:
            is_AC[p] = True
            ac += 1

wa = 0
for i in range(N + 1):
    if is_AC[i]:
        wa += WA_cnt[i]
print(ac, wa)
'''
うまくいかなかったパターン
1 4
1 WA
1 WA
1 WA
1 WA
'''
import collections
N = int(input())
 
dic = {}
for i in range(N):
  S = input()
  if S in dic:
    dic[S] += 1
  else:
    dic[S] = 1
maxval = max(dic.values())
 
keys = [k for k, v in dic.items() if  v == max(dic.values())]
[print(sorted(keys)[i]) for i in range(len(keys))]

### FIXED CODE ###

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

if A == B:
  if B!=C:
    print("Yes")
  else:
    print("No")
elif (A == C)or (B ==C):
  print("Yes")
else:
  print("No")
def main():
    S = input()
    if S[0] != 'k':
        return ('NO')

    ans = 'keyence'
    i = 0
    while True:
        i += 1
        j += 1
        if S[i] != ans[j]:
            break

    #残りの文字数
    num = 7-j
    cnt = 0
    while cnt <= num:
        cnt += 1
        if S[-cnt] != ans[-cnt]:
            return ('NO')
    return ('YES')
print(main())     


### FIXED CODE ###

def main():
    S = input()
    if S[0] != 'k':
        return ('NO')
    elif S == 'keyence':
        return ('YES')

    ans = 'keyence'
    i = 0
    j = 0
    while True:
        i += 1
        j += 1
        if S[i] != ans[j]:
            break

    #残りの文字数
    num = 7-j
    cnt = 0
    while cnt < num:
        cnt += 1
        #print(ans[-cnt])
        if S[-cnt] != ans[-cnt]:
            return ('NO')
    return ('YES')
print(main())
N, M = map(int, input().split()) 
A = list(map(int, input().split()))
for i in range (M)
	N = N -A[i]
if N>=0
	print (N)
else
	print (-1)

### FIXED CODE ###

N, M = map(int, input().split()) 
A = list(map(int, input().split()))
for i in range (M):
	N = N -A[i]
if N>=0:
	print (N)
else:
	print (-1)
a,b=map(int,input().split())
if a>10:
  print(b)
else:
  print(b-(100＊(10-b))

### FIXED CODE ###

a,b=map(int,input().split())
if a>9:
  print(b)
else:
  print(b+(100*(10-a)))
N = input().strip()
total = 0
for i in range(1, len(N), 2):
    total += 10**i - 10**(i-1)
if len(N) % 2 == 0:
    pass
else:
    total += int(N[1:])+1
print(total)

### FIXED CODE ###

N = input().strip()
N = N + "."  # for removing the leading zeroes just in case
N.strip("0")
N = N[:-1]
total = 0
for i in range(1, len(N), 2):
    total += int("1"+"0"*i) - int("1"+"0"*(i-1))
if len(N) % 2 == 0:
    total += 0
else:
    total += int(N) - (int("1" + "0" * (len(N) - 1))) + 1
print(total)
from collections import deque
N, D, A = list(map(int, input().split()))
D *= 2
pair_xh = [[-1, -1] for _ in range(N)]
for i in range(N):
    pair_xh[i][0], pair_xh[i][1] = list(map(int, input().split()))

q_lim_d = deque() # 累積和に含まれる攻撃範囲とダメージを保存する場所
total = 0 # 喰らいダメージの累積和
count = 0 # 攻撃回数
for i in range(N):
    x = pair_xh[i][0]
    h = pair_xh[i][1]
    
    while len(q_lim_d) and q_lim_d[0][0] < x: # 範囲外になったら喰らわないから累積和から外す
        total -= q[0][1]
        q_lim_d.pop()
    h -= total
    
    if h > 0: # 見てる敵の体力が0になる攻撃回数を求めその分を累積和に足す
        times = int((h + A - 1) / A) # 0にするのに必要な回数(切り上げ)
        count += times
        damage = A * times
        total += damage
        q_lim_d.append([x+D, damage])
print(count)

### FIXED CODE ###

from collections import deque
N, D, A = list(map(int, input().split()))
pair_xh = [[-1, -1] for _ in range(N)] # 1回ずつしか使わないけどソートするから必要
for i in range(N):
    pair_xh[i][0], pair_xh[i][1] = list(map(int, input().split()))
pair_xh.sort(key = lambda x: x[0]) #座標でソート

q_lim_d = deque() # 累積和に含まれる攻撃範囲とダメージを保存する場所
total = 0 # 喰らいダメージの累積和
count = 0 # 攻撃回数
for i in range(N):
    x = pair_xh[i][0]
    h = pair_xh[i][1]
    
    while len(q_lim_d) and q_lim_d[-1][0] < x: # 範囲外になったら喰らわないから累積和から外す
        total -= q_lim_d[-1][1]
        q_lim_d.pop()
    h -= total
    if h > 0: # 見てる敵の体力が0になる攻撃回数を求めその分を累積和に足す
        times = (h + A - 1) // A # 0にするのに必要な回数(切り上げ)
        count += times
        damage = A * times
        total += damage
        q_lim_d.appendleft([x + 2 * D, damage])
print(count)
h, w = map(int, input().split())
grid = []
for i in range(h):
  gridi = input()
  grid.append(gridi)
xcnt = [[0]*w for i in range(h)]
ycnt = [[0]*w for i in range(h)]
ans = -10**9
# print(grid, h, w)
for y in range(h):
  cnt = 0
  for x in range(w-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y][x+1] == "#":
      xcnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y][x+1] == ".":
    xcnt[y][x+1] = cnt + 1
# print(xcnt)
for y in range(h):
  for x in range(w-1):
    if grid[y][w-1-x] == "#":
      continue
    if grid[y][w-1-x-1] == ".":
      xcnt[y][w-1-x-1] = xcnt[y][w-1-x]
# print(*xcnt)

for x in range(w):
  cnt = 0
  for y in range(h-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y+1][x] == "#":
      ycnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y+1][x] == ".":
    ycnt[y+1][x] = cnt + 1
# print(ycnt)
for x in range(w):
  for y in range(h-1):
    if grid[h-1-y][x] == "#":
      continue
    if grid[h-1-y-1][x] == ".":
      ycnt[h-1-y-1][x] = ycnt[h-1-y][x]
# print(*ycnt)
for y in range(h):
  for x in range(w):
    ans = max(ans, xcnt[y][x] + ycnt[y][x] - 1)
print(ans)

### FIXED CODE ###

h, w = map(int, input().split())
grid = []
for i in range(h):
  gridi = input()
  grid.append(gridi)
xcnt = [[0]*w for i in range(h)]
ycnt = [[0]*w for i in range(h)]
ans = -10**9
# print(grid, h, w)
for y in range(h):
  cnt = 0
  for x in range(w-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y][x+1] == "#":
      xcnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y][w-1] == ".":
    xcnt[y][w-1] = cnt + 1
# print(xcnt)
for y in range(h):
  for x in range(w-1):
    if grid[y][w-1-x] == "#":
      continue
    if grid[y][w-1-x-1] == ".":
      xcnt[y][w-1-x-1] = xcnt[y][w-1-x]
# print(*xcnt)

for x in range(w):
  cnt = 0
  for y in range(h-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y+1][x] == "#":
      ycnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[h-1][x] == ".":
    ycnt[h-1][x] = cnt + 1
# print(ycnt)
for x in range(w):
  for y in range(h-1):
    if grid[h-1-y][x] == "#":
      continue
    if grid[h-1-y-1][x] == ".":
      ycnt[h-1-y-1][x] = ycnt[h-1-y][x]
# print(*ycnt)
for y in range(h):
  for x in range(w):
    ans = max(ans, xcnt[y][x] + ycnt[y][x] - 1)
print(ans)
n,m = map(int,input().split()) #nがカードの数、mがBの数
a = list(map(int, input().split()))
b = [list(map(int,input().split())) for i in range(m)]
 
for i in range(m):
  a.extend([b[i][1]]*b[i][0])
a.sort(reverse=True)
ans = 0
for i in range(n):
  ans += a[i]
print(ans)

### FIXED CODE ###

a, b = map(int,input().split())
if a > 12:
  print(b)
elif a < 13 and a > 5:
  print(int(b/2))
else:
  print(0)
a, b =map(int, input().split())
c = ""
for i in range(b -a, b+a)
	c = c + str(i) + " "
print(c)

### FIXED CODE ###

a, b =map(int, input().split())
c = ""
for i in range(b -a+1, b+a):
	c = c + str(i) + " "
print(c)
n,a,b =map(int,input().split())
sum=0
for i in range(n) :
    if i == a :
        continue
    elif i == b :
        continue
    else :
        sum+=pow(n)/(pow(i)*pow(n-i))

print(sum%1000000007)

### FIXED CODE ###

def com(n, r, mod):
    num = 1
    denom = 1
    for i in range(r):
        denom = (denom * (i+1)) % mod
        num = (num * (n-i)) % mod
    return num*pow(denom, mod-2, mod)

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

mod = 10**9 + 7

sum = pow(2, n, mod) - 1
sum -= com(n, a, mod)
sum -= com(n, b, mod)

print(int(sum % mod))
def main():
    A = input()
    op = input()
    B = input()
    x = A + op + B
#    print(A + op + B)
    y = eval(x)
    print(y)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    x = input()
    print(eval(x))

if __name__ == '__main__':
    main()
a,b=map(int,input().split())

result=a
count=1
while result =< b:
    result += a-1
    count += 1

print(count)

### FIXED CODE ###

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

result=1
count=0
while result < b:
    result += a-1
    count += 1

print(count)
s=input()
if s[0]=="A" and "C" in s[2:-1] and len(re.findall('[A-Z]', s))==2:
    print("AC")
else:
    print("WA")

### FIXED CODE ###

import re
s=input()
if s[0]=="A" and "C" in s[2:-1] and len(re.findall('[A-Z]', s))==2:
    print("AC")
else:
    print("WA")
a,b = list(map(int,input().split()))
ls = [['#']*100 for i in range(50)] + [['.']*100 for i in range(50)]
i,j = 0,0
for c in range(a - 1):
    ls[i][j] = '.'
    if i >= 98:
        j = 0;i += 2
    else:
        j += 2
i,j = 51,0
for c in range(b - 1):
    ls[i][j] = '#'
    if i >= 98:
        j = 0;i += 2
    else:
        j += 2
print(100,100)
for j in range(100):
    print(''.join(ls[j]))

### FIXED CODE ###

a,b = list(map(int,input().split()))
ls = [['#']*99 for i in range(49)] + [['.']*99 for i in range(49)]
i,j = 0,0
for c in range(a - 1):
    ls[i][j] = '.'
    if j >= 97:
        j = 0;i += 2
    else:
        j += 2
i,j = 51,0
for c in range(b - 1):
    ls[i][j] = '#'
    if j >= 97:
        j = 0;i += 2
    else:
        j += 2
print(98,99)
for j in range(98):
    print(''.join(ls[j]))
import collections

h, w, m = map(int, input().split())
x = []
y = []
bomb = []
for i in range(m):
  tmp_x, tmp_y = map(int, input().split())
  x.append(tmp_x)
  y.append(tmp_y)
  bomb.append([tmp_x, tmp_y])

c_x = collections.Counter(x)
c_y = collections.Counter(y)
_max_x = c_x.most_common()[0][1]
_max_y = c_y.most_common()[0][1]
ys = c_y.most_common()
count = 0
for i in bomb:
  if x[i[0]] == _max_x and y[i[1]] == _max_y:
    count += 1
    
if count == x.count(_max_x) * y.count(_max_y):
  print(_max_x + _max_y - 1)
else:
  print(_max_x + _max_y)

### FIXED CODE ###

h,w,n=map(int,input().split())
H=[0]*h
W=[0]*w
L=[(0,0)]*n
for i in range(n):
    a,b=map(int,input().split())
    L[i]=(a,b)
    H[a-1]+=1
    W[b-1]+=1
h_max=max(H)
w_max=max(W)
ans=h_max+w_max
cnt=0
for l in L:
    if H[l[0]-1]==h_max and W[l[1]-1]==w_max:
        cnt+=1
if H.count(h_max)*W.count(w_max)==cnt:
    ans-=1
print(ans)
N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N):
a.append(a[i] * 2 + 3)
p.append(p[i] * 2 + 1)

def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
	if N == 0:
  		return 0 if X <= 0 else 1
	elif X <= 1 + a[N-1]:
    	return f(N-1, X-1)
	else:
 		return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))


### FIXED CODE ###

n, x = map(int, input().split())
ans = 0
 
hambargers = [1]
patties = [1]
 
for i in range(1, n+1):
    num = hambargers[i-1] * 2 + 3
    patty_num = patties[i-1] * 2 + 1
    hambargers.append(num)
    patties.append(patty_num)
 
def cal(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + hambargers[N-1]:
        return cal(N-1, X-1)
    else:
        return patties[N-1] + 1 + cal(N-1, X-2-hambargers[N-1])
 
print(cal(n, x))
A=list(map(int,input().split()))
A = A.sort()
print(A[1]*A[2]/2)
 

### FIXED CODE ###

A=list(map(int,input().split()))
A.sort()
print(round(A[0]*A[1]/2))
n,m,k = map(int,input().split())
import sys
rks = [None] *n
sys.setrecursionlimit(10**9)
fgraph = [list() for i in range(n)]
bgraph = [list() for i in range(n)]
cgraph = [list() for i in range(n)]
for i in range(m):
        a,b = map(int, input().split())
        fgraph[a-1].append(b)
        fgraph[b-1].append(a)
def dfs(graph,s,r):
    if rks[s] is None:
        rks[s] = r
    for i in range(len(graph[s])):
        if rks[graph[s][i]-1] is not None:
            continue
        dfs(graph, graph[s][i]-1,r)
c = -1
for i in range(n):
    if rks[i] is None:
        c += 1
        dfs(fgraph, i, c)
for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)
for i in range(c+1):
    s[i] = rks.count(i)
for i in range(n):
        print(rks.count(rks[i]) - len(fgraph[i]) - len(bgraph[i]) - 1)

### FIXED CODE ###

n,m,k = map(int,input().split())
import sys
rks = [None] *n
sys.setrecursionlimit(10**9)
fgraph = [list() for i in range(n)]
bgraph = [list() for i in range(n)]
cgraph = [list() for i in range(n)]
g = [[]for i in range(n)]
for i in range(m):
        a,b = map(int, input().split())
        fgraph[a-1].append(b)
        fgraph[b-1].append(a)
def dfs(graph,s,r):
    if rks[s] is None:
        rks[s] = r
    for i in range(len(graph[s])):
        if rks[graph[s][i]-1] is not None:
            continue
        g[r].append(0)
        dfs(graph, graph[s][i]-1,r)
c = -1
for i in range(n):
    if rks[i] is None:
        c += 1
        dfs(fgraph, i, c)
for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)
for i in range(n):
        print(len(g[rks[i]]) - len(fgraph[i]) - len(bgraph[i]) )
a, b, n = map(int, input().split())
 
x = min(b - 1, n)
print(int(a * x / b) - a * int(x / b))

import random
a,b,n=map(int,input().split())
def f(x):
    return int(a*x/b)-a*int(x/b)
if n<b:
    ans =f(n)
else:
    t = n
    u = b - 1
    v=min(t,u)
    ans=f(v)
print(ans)

### FIXED CODE ###

a,b,n=map(int,input().split())
if n>=b-1:
  print(a*(b-1)//b)
else:
  print(a*n//b)
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K, LR):
    mod = 998244353
    S = []
    for lr in LR:
        S += [i for i in range(lr[0], lr[1] + 1)]
    S.sort()
    dp = [0] * (N + 1)
    dp[1] = 1
    for i in range(1, N + 1):
        for s in S:
            if i + s > N:
                break
            dp[i + s] = (dp[i + s] + dp[i]) % mod
    print(dp[N])


if __name__ == '__main__':
    # N, K = map(int, input().split())
    # LR = [[int(i) for i in input().split()] for _ in range(K)]
    # solve(N,K,LR)

    # test
    from random import randint
    from func import random_str

    N, K = 2 * 10 ** 5, 1
    LR = [[1, N]]
    solve(N, K, LR)


### FIXED CODE ###

# 解説などを参考に作成
"""
N = 10, LR = [2, 4] を例とする.
fi:=マスiまで移動する方法の個数とおく.
便宜上0マスから始めると、
    N:  0 1 2 3 4 5 6 7 8 9 10
    fi: 0 1 0 1 1 2 2 4 5 8 11
となる.(1マス目には最初からいるのでf1 = 1とする.)
ここで、N=5,6の時で考えると、LR=[2,4]から
    f5 = f1 + f2 + f3  (∵2～4マス前からしか遷移がないので)
    f6 =      f2 + f3 + f4
よってf5とf6の差はf1とf4によって求めることができる.
    f6 = f5 - f1 + f4
一般化すると、
    fi = fi-1 - fi-1-R + fi-L
LRが複数ある場合でも区間が重複しないので、各区間に対して - fi-1-R + fi-L 部分を計算して fi を求めることができる.
計算量はO(KN) (K:=重複しない区間LRの個数)
"""


# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, LR):
    mod = 998244353
    dp = [0] * (N + 1)
    dp[1] = 1
    # dp[0] は基本0として扱ってよいが, dp[2]の計算時のみ,dp[0]とdp[1]の差分=0となる必要がある.
    # => この時のみ、dp[0]を1として計算しないと fi = fi-1 - fi-1-R + fi-L のルールに合わなくなる.
    # 他の人の解答(#16897281, #16895566)見ると階差数列？敵なのを持つことで解決できそうだったけど,
    # 内容が理解できなかったのでdp[2]までは手動実装することにした.
    dp[2] = 1 if 1 in [lr[0] for lr in LR] else 0
    for i in range(3, N + 1):
        x = 0
        for l, r in LR:
            x += dp[max(i - l, 0)] - dp[max(i - 1 - r, 0)]
        dp[i] = (dp[i - 1] + x) % mod
    print(dp[N])


if __name__ == '__main__':
    N, K = map(int, input().split())
    LR = [[int(i) for i in input().split()] for _ in range(K)]
    solve(N, K, LR)

    # # test
    # from random import randint
    # from func import random_str
    # N, K = 2 * 10 ** 5, 1
    # LR = [[1, N]]
    # solve(N, K, LR)
#131d
N = int(input())
lst = []
for i in range(N):
    a, b = map(int, input())
    lst.append([b, a])
lst = sorted(lst)

lim = 0
time = 0
flag = 0
for i in lst:
    lim = i[0]
    if time + i[1] <= lim:
        time += i[1]
    else:
        flag = 1
        break
if flag == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

#131d
N = int(input())
lst = []
for i in range(N):
    a, b = map(int, input().split())
    lst.append([b, a])
lst = sorted(lst)

lim = 0
time = 0
flag = 0
for i in lst:
    lim = i[0]
    if time + i[1] <= lim:
        time += i[1]
    else:
        flag = 1
        break
if flag == 0:
    print('Yes')
else:
    print('No')
import numpy as np

bingo = np.zeros([3,3])
check = np.zeros([3,3])
choice = []
flag = "No"

for i in range(3):
    a = input().split()
    a = [int(x) for x in a]
    bingo[i] = a
N = int(input())
for i in range(N):
    choice.append(int(input()))

convert = bingo.reshape([9])
for i in range(9):
    for j in range(N):
        if(convert[i] == j):
            ckeck[i//3][i%3] = 1
            continue

for i in range(3):
    if(check[i][0] == 1 and check[i][1] == 1 and check[i][2] == 1):
        flag = "Yes"
    elif(check[0][i] == 1 and check[1][i] == 1 and check[2][i] == 1):
        flag = "Yes"
if(check[0][0] == 1 and check[1][1] == 1 and check[2][2] == 1):
    flag = "Yes"
elif(check[2][0] == 1 and check[1][1] == 1 and check[0][2] == 1):
    flag = "Yes"

print(flag)


### FIXED CODE ###

import numpy as np

bingo = np.zeros([3,3])
check = np.zeros([3,3])
choice = []
flag = "No"

for i in range(3):
    a = input().split()
    a = [int(x) for x in a]
    bingo[i] = a
N = int(input())
for i in range(N):
    choice.append(int(input()))

convert = bingo.reshape([9])
for i in range(9):
    for j in choice:
        if(convert[i] == j):
            check[i//3][i%3] = 1
            continue

            
for i in range(3):
    if(check[i][0] == 1 and check[i][1] == 1 and check[i][2] == 1):
        flag = "Yes"
    elif(check[0][i] == 1 and check[1][i] == 1 and check[2][i] == 1):
        flag = "Yes"
if(check[0][0] == 1 and check[1][1] == 1 and check[2][2] == 1):
    flag = "Yes"
elif(check[2][0] == 1 and check[1][1] == 1 and check[0][2] == 1):
    flag = "Yes"

print(flag)
a=input
b=input

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


### FIXED CODE ###

a,b=map(int,input().split())
print(a*b,2*(a+b))
def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count, current+i+1, flag+1)
            move_count -= 1
            del n_lis[-1]
            
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(8,0,1)
    print count

### FIXED CODE ###

def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count, current+i+1, flag+1)
            move_count -= 1
            del n_lis[-1]
            
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(10-n+1,0,1)
    print count
n = int(input())
a = list(map(int, input().split())) # taberu order
b = list(map(int, input().split())) # get
c = list(map(int, input().split())) # renzoku

ans = 0
for i in range(n):
  po = a[i]
  ans += b[po]

for i in range(n-1):
  if(a[i] + 1 = a[i+1] ):
    ans += c[i]
    
print(ans)



### FIXED CODE ###

n = int(input())
a = list(map(int, input().split())) # taberu order
b = list(map(int, input().split())) # get
c = list(map(int, input().split())) # renzoku
 
ans = 0
for i in range(n):
  po = a[i]
  ans += b[po-1]
 
for i in range(n-1):
  if(a[i] + 1 == a[i+1] ):
    ans += c[a[i]-1]
    
print(ans)
n = int(input())
A = list(map(int, input().split()))
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A) if i-x > 0]

P = collections.Counter(L)
Q = collections.Counter(R)
 
ans = 0
for k, v in P.item():
    if k in Q:
        ans += v*Q[k]
print(ans)    


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A) if i-x > 0]

from collections import Counter
P = Counter(L)
Q = Counter(R)
 
ans = 0
for k, v in P.items():
  if k in Q:
    ans += v*Q[k]
print(ans)
#WA
s = input()
ns = ''
cnt = 0
cnt1 = 0
for i in range(len(s)):
    if s[i] != 'x':
        ns += s[i]
    else:cnt += 1

if ns != ns[::-1]:
    print(-1)
    exit()

mid = len(ns) // 2
mid_str = ns[mid]
mid_ind = s.index(mid_str)
#print(mid_ind)

count = 0
for i in range(len(s)):
    if s[i] != 'x':continue
    temp_ind = 2 * mid_ind - i
    if temp_ind >= len(s) or temp_ind < 0:continue
    if s[temp_ind] == 'x':
        count += 1

#print(cnt, count)
print(cnt - count * 2)

### FIXED CODE ###

from collections import deque
s = list(input())
s = deque(s)
cnt = 0
while len(s) > 1:
    left = s.popleft()
    right = s.pop()
    if left == right:continue
    if left != 'x' and right != 'x':
        print(-1)
        exit()

    if left == 'x':
        s.append(right)
    else:
        s.appendleft(left)
    cnt += 1
print(cnt)
s, w = list(map(int, input(split()))

if s > w:
    print('safe')
else:
    print('unsafe')

### FIXED CODE ###

s, w = list(map(int, input().split()))

if s > w:
    print('safe')
else:
    print('unsafe')
a, b = map(int, input().split())

i = 1
while True:
  max = a * i + 1 - i
  if max >= b:
    break
    
  i += 1
  

print(i)

### FIXED CODE ###

predict_weather = str(input())
real_weather = str(input())

predict_list = list(predict_weather)
real_list = list(real_weather)

cnt = 0
for i in range(3):
  if predict_list[i] == real_list[i]:
    cnt += 1
    
print(cnt)
N= int(input())
L= list(map(int,input().split()))

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i]-L[i+1:])))

ans=min(v)

print(v)

### FIXED CODE ###

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

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1])-sum(L[i+1:])))

ans=min(v)

print(ans)
while True:
    n=int(input())
    points=[]
    for i in range(n):
        points.append(int(input()))
    points.remove(max(points))
    points.remove(min(points))
    print(sum(points)/len(points))
    if int(input())==0:break

### FIXED CODE ###

while True:
    n=int(input())
    if n==0:break
    points=[]
    for i in range(n):
        points.append(int(input()))
    points.remove(max(points))
    points.remove(min(points))
    print(int(sum(points)/len(points)))
W, H, x, y = map(int,input().split())
if x == W/2 and y = H/2:
    judge = 1
else:
    judge = 0
ans = (H*W)/2
print(str(ans)+' '+str(judge))

### FIXED CODE ###

W, H, x, y = map(int,input().split())
if x == W/2 and y == H/2:
    judge = 1
else:
    judge = 0
ans = (H*W)/2
print(str(ans)+' '+str(judge))
a, b = map(int, input().split())

if a < b:
    print("{a} < {b}", format(a=a, b=b))
elif a > b:
    print("{a} > {b}", format(a=a, b=b))
else:
    print("{a} == {b}", format(a=a, b=b))

### FIXED CODE ###

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

if a < b:
    print("a < b")
elif a > b:
    print("a > b")
else:
    print("a == b")
import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    if i == 0:
      if data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
    elif i == len(data) - 1:
      if data[i - 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
    else:
      if data[i - 1] == "D" or data[i + 1] == "D":
        data[i] = "P"
      else:
        data[i] = "D"
print(data)

### FIXED CODE ###

import sys
data = list(input())
for i, _str in enumerate(data):
  if _str == "?":
    data[i] = "D"
ans = "".join(data)
print(ans)