Problem:


Score : 200 points

Problem Statement

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.

The i-th dish (1 \leq i \leq N) he ate was Dish A_i.

When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.

Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

All values in input are integers.

2 \leq N \leq 20

1 \leq A_i \leq N

A_1, A_2, ..., A_N are all different.

1 \leq B_i \leq 50

1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

Sample Input 1

3
3 1 2
2 5 4
3 6

Sample Output 1

14

Takahashi gained 14 satisfaction points in total, as follows:

First, he ate Dish 3 and gained 4 satisfaction points.

Next, he ate Dish 1 and gained 2 satisfaction points.

Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.

Sample Input 2

4
2 3 4 1
13 5 8 24
45 9 15

Sample Output 2

74

Sample Input 3

2
1 2
50 50
50

Sample Output 3

150



Sample input:
3
3 1 2
2 5 4
3 6


Sample output:
14

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=sum(B)
for i in range(N-1):
    if A[i+1]-A[i]==1:
        ans+=C[A[i]-1]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
  if a[i+1]==a[i]+1:
    ans+=c[a[i]-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
satisfaction = 0
for i in range(n):
    b_number = a[i]
    satisfaction += b[b_number - 1]
    if i == 0:
        j = i
    else:
        if a[i] == a[j] + 1:
            c_number = a[j]
            satisfaction += c[c_number - 1]
        j = i
print(satisfaction)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
satisfaction = 0
for i in range(n):
    # print(i)
    # print(a[i])
    b_number = a[i]
    # print('b_number = ' + str(b_number-1))
    # print(b[b_number-1])
    satisfaction += b[b_number - 1]
    if i == 0:
        j = i
    else:
        if a[i] == a[j] + 1:
            c_number = a[j]
            satisfaction += c[c_number - 1]
        j = i
print(satisfaction)
    # if j + 1 == i:
    #     satisfaction += c[]
    # j = i
    # satisfaction += b[i+1]
    # if i = :
    #     satisfaction += c[i]

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

sum=0
for i in range(0, n):
    ai = a[i] - 1
    if i != 0:
        if a[i] - a[i-1] == 1:
            sum += b[ai] + c[a[i-1]-1]
        else:
            sum += b[ai]
    else:
        sum += b[ai]

print(sum)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    sum = B[A[0]-1]
    for i in range(1, len(A)):
        sum += B[A[i]-1]
        if A[i] - A[i-1] == 1:
            sum += C[A[i-1]-1]
    print(sum)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

wa = sum(B)
for i in range(N-1):
    if A[i+1] - A[i] == 1:
        wa += C[A[i]-1]
print(wa)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

result=0
for i in range(N):
    result+=b[i]

for j in range(1,N):
    if a[j-1]+1==a[j]:
        result+=c[a[j-1]-1]

print(result)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

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

Submission status: Accepted

Solution code:
n = int(input())
aa = list(map(int,input().split())) #順番
a = list(x - 1 for x in aa) 
b = list(map(int,input().split())) #点
c = list(map(int,input().split())) #追加点

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

for i in range(1,n):
    
    if (a[i] == a[i-1] + 1): #今回と前回+1
        ans += c[a[i-1] ]
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ret = 0
prev = N
for i in range(N):
    a = A[i] - 1
    ret += B[a]
    if a == prev + 1:
        ret += C[prev]
    prev = a
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
A, B, C = [[int(i) for i in input().split()] for j in range(3)]
score = 0
for i in range(len(A)):
    score += B[A[i] - 1]
    if i > 0 and A[i] - A[i-1] == 1:
        score += C[A[i-1] - 1]
print(score)

Submission status: Accepted

Solution code:
n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
ci = list(map(int, input().split()))

#print(ai)
#print(bi)
#print(ci)

ans = 0
for i in range(n):
    t = ai[i]
    ans = ans+bi[t-1]
    if i >= 1 and ai[i-1]+1 == t:
        ans = ans + ci[ai[i-1]-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum = 0

for i in range(N):
    sum += B[A[i]-1]
    if i == 0:
        pass
    elif A[i-1] == A[i] -1:
        sum += C[A[i-1]-1]
print(sum)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]
score=0
pred_i=np.inf
for i in A:
    if pred_i+1 ==i:
        score=score+C[i-2]+B[i-1]
    else:
        score+=B[i-1]
    pred_i=i
print(score)

Submission status: Accepted

Solution code:
import sys

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

Satis = 0

for i in range(N):

    Satis += B[A[i] - 1]

    if 0 < i:
        if A[i - 1] + 1 == A[i]:
            Satis += C[A[i - 1] - 1]

print(Satis)

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
ans = 0
for i in range(n):
    ans = ans + b[i]
for i in range(n-1):
    if a[i+1] - a[i] == 1:
        ans += c[a[i]-1]
print ans

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

manzoku = 0
add_manzoku = 0
for i in range(n):
    manzoku += b[a[i]-1]
    if i < n-1 and a[i]+1 == a[i+1]:
        add_manzoku += c[a[i]-1]

print(manzoku+add_manzoku)

Submission status: Accepted

Solution code:
N = int(input())

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

# c_counter = 0
value = 0

for i in range(N):    
    value += B[A[i] - 1]
    if i > 0 and A[i] == A[i-1] + 1:
            value += C[A[i-1]-1]            
    # print(value)

print(value)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

x=sum(B)
for i in range(len(A)-1):
  if A[i+1]==A[i]+1:
    x+=C[A[i]-1]
print(x)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
sat=0
for i,name in enumerate(A):
  sat+=B[name-1]
  if i>=1:
      if name==A[i-1]+1:
          sat+=C[name-2]
print(sat)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_)-1 for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

ans = 0
for i in range(N):
    ans += B[A[i]]
    if i > 0 and A[i] - A[i-1] == 1:
        ans += C[A[i-1]]
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_b
from itertools import combinations
 
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = 0
nowrow = 0

for i in range(N):
    #直後に食べる
    if i != 0 and (nowrow + 1) == A[i]:
        total = total + C[nowrow - 1 ]
    #何番目
    nowrow = A[i]
    #食べる満足度
    total = total + B[nowrow - 1]

print(total)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()
B = MAP()
C = MAP()

ans = 0
for idx,a in enumerate(A):
	ans += B[a-1]
	if idx < len(A)-1 and A[idx+1] == a+1:
		ans += C[a-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split())) #0..n-1
B = list(map(int, input().split())) #0..n-1
C = list(map(int, input().split())) #0..n-2
man = sum(B)
for i in range(N-1):
    if A[i+1] == A[i] + 1:
        man += C[A[i]-1]

print(man)

Submission status: Accepted

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

for i in range(N):
    sum += B[A[i]-1]
    
print(sum)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
before = 10000
total=0
for aa in a:
    total+=b[aa-1]
    if before+1==aa:
        total+=c[before-1]
    before=aa
print(total)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(lambda x: int(x), input().split()))
b = list(map(lambda x: int(x), input().split()))
c = list(map(lambda x: int(x), input().split()))
ans = 0
pre_a = 0
for i in a:
    ans += b[i-1]
    if pre_a != 0 and i == pre_a + 1 :
        ans += c[pre_a-1]
    pre_a = i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0

for i in range(n):
    ans += b[a[i]-1]
    if 0 < i and a[i] == a[i-1]+1:
        ans += c[a[i-1]-1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int ,input().split()))
b = list(map(int ,input().split()))
c = list(map(int ,input().split()))
ans = b[a[0]-1]
for i in range(1,n) :
    ans += b[a[i]-1]
    #print(ans)
    if a[i] - a[i-1] == 1 :
        ans += c[a[i-1]-1]
        #print(ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
*c, = map(int, input().split())

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

tmp = -1
sum = 0
for i in range(n):
    sum += b[i]
    if a[i] == tmp + 1:
        sum += c[tmp-1]
    tmp = a[i]
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
An = list(map(int, input().split()))
An = [-1] + An
Bn = list(map(int, input().split()))
Bn = [-1] + Bn
Cn = list(map(int, input().split()))
Cn = [-1] + Cn

count = 0
for i in range(1, N + 1):
    count += Bn[An[i]]
    if i > 1 and An[i] == An[i - 1] + 1:
        count += Cn[An[i - 1]]

print(count)

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))

sum = 0

for i in range(N):
    sum += b_list[a_list[i]-1]
    if (i>=1 and a_list[i]-a_list[i-1] == 1):
        sum += c_list[a_list[i]-2]

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))

ans = 0
count_i = 0
b_con = 0

for i in a_list:
    count_i += 1 
    ans += b_list[i-1]
    if b_con+1 == i and i != 1:
        ans += c_list[i-2]
    b_con = i

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
tmp = -1
for i in range(N):
    for j in range(N):
        if A[i] == j+1:
            ans += B[j]
            if A[i] == tmp+1:
                ans += C[tmp-1]
            tmp = A[i]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

res = 0
prev = -1
for i in range(n):
    res += b[a[i]-1]
    if prev+1 == a[i]:
        res += c[prev-1]
    prev = a[i]

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i)-1 for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

res = 0
prev = -2
for i in range(n):
    res += b[a[i]]
    if prev+1 == a[i]:
        res += c[prev]
    prev = a[i]

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]+[int(i) for i in input().split()]
b=[0]+[int(i) for i in input().split()]
c=[0]+[int(i) for i in input().split()]
 
res = 0
prev = -1
for i in range(1, n+1):
    res += b[a[i]]
    if prev+1 == a[i]:
        res += c[prev]
    prev = a[i]

print(res)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

sum=0

for x in range(0,N):
  sum+=B[A[x]-1]
  if(x>=1 and A[x]-A[x-1]==1):
    sum+=C[A[x-1]-1]

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
bonus=0
for x in range(1,n):
  if A[x-1]+1 == A[x]:
    bonus += C[A[x]-2]
 
ans = sum(B) + bonus
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
order=list(map(int,input().split()))
sat=list(map(int,input().split()))
a=list(map(int,input().split()))

total=sum(sat)

for i in range(N-1):
  if order[i]==order[i+1]-1:
    total += a[order[i]-1]

print(total)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

#tempは空白の箱に過ぎず、一番最初のfor文では確定演出で問答無用にXの値になる。
#for文が2週目に突入してからが、tempの分かれ目。2回目のfor文でも一致はせず素直に3が代入される。
#最後のif文　temp == x-1 が一致するのは　１回目と2回目　or 2回目と3回目が連番。つまり-1して一致すれば連続


#満足度を記録していくための変数
cnt = 0

#1つ前に食べた料理を記録するための変数
temp = ""

#料理を食べた順番に処理していく
for x in A:
    
    #食べた料理の満足度を追加
    cnt += B[x-1]
    
    #今食べた料理が1つ前に食べた料理のi+1かどうかを確認
    if temp == x - 1:
        cnt += C[temp-1]
        
    #今食べた料理を記録    
    temp = x
#全ての料理に対して処理が終わったら満足度を出力   
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
A = list(input().split())
B = list(input().split())
C = list(input().split())
S = 0
for j in range(0,N):
  a = int(A[j])
  b = int(B[a-1])
  S = S + b

for i in range(0,N-1):
  a = int(A[i])+1
  b = int(A[i+1])
  if a == b:
    S = S + int(C[a-2])


print(S)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for i in range(N):
    ans += B[A[i]-1]
    if i != 0:
        if A[i-1] + 1 == A[i]:
            ans += C[A[i-1]-1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

res = 0

for i in range(n):
    x = a[i] - 1
    res += b[x]

    if i < n - 1 and a[i] + 1 == a[i + 1]:
        res += c[x]

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

count = 0

for i in range(n):

    if i == 0:
        count += b[a[i]-1]

    else:
        count += b[a[i]-1]

        if a[i] - a[i-1] == 1:
            count += c[a[i-1]-1]

print(count)

Submission status: Accepted

Solution code:
n=int(input())
A,B,C=[list(map(int,input().split()))for _ in "ABC"]
print(sum(B)+sum(C[A[i]-1] for i in range(len(C)) if A[i+1]-A[i]==1))

Submission status: Accepted

Solution code:
N = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = [i-1 for i in A]

ans = 0
pre = A[0]
for a in A:
    ans += B[a]
    if a==pre+1:
        ans += C[pre]
    pre = a

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = sum(B)

for i in range(N - 1):
    if A[i + 1] - A[i] == 1:
        total += C[A[i] - 1]

print(total)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)
for i in range(len(a)-1):
  if(a[i]+1==a[i+1]):
    ans+=c[a[i]-1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
total = 0
previous=-1

for a in A:
    total += B[a-1]
    if previous+1 == a:
        total += C[previous-1]
    previous = a
print(total)

Submission status: Accepted

Solution code:
n=int(input())
A,B,C=[list(map(int,input().split())) for _ in range(3)]
ans=sum(B)
for i in range(1,n):
    if A[i]-A[i-1]==1:ans += C[A[i-1]-1]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
c=sum(B)
for i in range(n-1):
    if A[i+1]-A[i]==1:c += C[A[i]-1]
print(c)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(lambda x: int(x)-1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

prev = -99
ans = 0
for i in A:
    ans += B[i]
    if prev == i-1:
        ans += C[i-1]
    prev = i
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split()).astype(int)
B = np.array(input().split()).astype(int)
C = np.array(input().split()).astype(int)
r = sum(B)
r += C[A[np.append(np.diff(A)==1, False)]-1].sum()
print(r)

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

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

#print(n,a,b,c)

t = -10
ans = 0

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

prevIdx = -99
ret = 0
for a in A:
    a -= 1
    ret += B[a]
    if a == prevIdx + 1:
        ret += C[a - 1]
    prevIdx = a
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
last_num = -1
manzoku_sum = 0
for i in A:
    manzoku_sum += B[i - 1]
    if last_num + 1 == i:
        manzoku_sum += C[last_num - 1]
    last_num = i
print(manzoku_sum)

Submission status: Accepted

Solution code:
# 入力を読み込む
N = int(input())
A = input().split()
B = input().split()
C = input().split()
# print(N, A, B, C)
# 食べた順番にBを並べる
result = 0
for i in range(N):
#  print(A[i])
#  print(B[int(A[i])-1])
  result = result + int(B[int(A[i])-1])  
  # Cについて考える
  if (i != 0):
    if (int(A[i]) - int(A[i-1]) == 1):
      #print(A[i])
      result = result + int(C[int(A[i-1])-1])
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

bonus=0

for i in range(N-1):
  if A[i+1]-A[i]==1:
    bonus+=C[A[i]-1]

print(sum(B)+bonus)

Submission status: Accepted

Solution code:
n = int(input())
ryori_list = list(map(int, input().split()))
manzoku_list = list(map(int, input().split()))
tuika_list = list(map(int, input().split()))

point = 0
before_r = 100
for r in ryori_list:
    point += manzoku_list[r-1]
    if r == before_r + 1:
        point += tuika_list[before_r-1]
    before_r = r
print(point)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ret = 0
bef = -1
for i in a:
  ret += b[i-1]
  if bef == i - 1:
    ret += c[bef - 1]
  bef = i
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a_pre = -1
ans = 0
for ai in a:
    ans += b[ai - 1]
    if ai == a_pre + 1:
        ans += c[a_pre - 1]
    a_pre = ai
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
pre_idx=-100
for a in A:
  idx = a-1
  #print(a, idx, pre_idx, B[idx], ans)
  ans += B[idx] + ( C[pre_idx] if idx == pre_idx+1 else 0)
  pre_idx = idx
  
  
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in range(3)]
s=sum(b)
for i in range(n-1):
  if a[i+1]==a[i]+1:s+=c[a[i]-1]
print(s)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
sat=sum(b)
for i in range(n-1):
  if a[i+1]==a[i]+1:
    sat+=c[a[i]-1]
print(sat)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(0,n):
    ans+=b[i]
for i in range(0,n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

s = 0
pre_food = A[0]
for food in A:
    s += B[food-1]
    if food - pre_food == 1 : s += C[food-2]
    pre_food = food

print(s)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
R = 0

for n in range(N):
    R += B[A[n]-1]
    if n >= 1 and A[n] - A[n-1] == 1:
        R += C[A[n-1]-1]

print(R)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    ans += b[i]
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

def tarou(n,a,b,c):
	manzoku = b[a[0]-1]
	for i in range (1,n):
		manzoku += b[a[i]-1]
		if a[i]-a[i-1] == 1:
				manzoku += c[a[i]-2]
	print (manzoku)
tarou (n,a,b,c)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = sum(B)

for i in range(0,N-1):
    if A[i+1] == A[i]+1:
        ans += C[A[i]-1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    val = a[i]-1
    ans += b[val]
    if a[i] == a[i-1]+1 and i > 0:
        ans += c[val-1]
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
buf = 0

for i in range(N) :
    buf += B[A[i]-1]

for i in range(N-1) :
    if A[i+1] - A[i] == 1 :
        buf += C[A[i]-1]

print(buf)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.append(23)
c.append(0)
count = 0

for i in range(n):
    count += b[a[i]-1]
    #print("added"+str(b[a[i]-1]))
    if ((a[i]+1)==a[i+1]):
        #print("yeah"+str(c[a[i]-1]))
        count += c[a[i]-1]
print(count)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

ans=0
for i in range(len(a)):
    aa=a[i]
    ans+=b[aa-1]
    if i<n-1:
        if a[i+1]==a[i]+1:
            ans+=c[aa-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += B[A[i]-1]
    if i>0 and A[i]-A[i-1]==1:
        ans += C[A[i-1]-1]
    #print(i,ans)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
ans=sum(b)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans+=c[a[i]-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
pre = -100
for i in range(n):
  ans += b[a[i] - 1]
  if pre == a[i] - 1:
    ans += c[pre - 1]
  pre = a[i]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

ans = sum(B)
for i in range(len(A)-1):
    if A[i] +1 == A[i+1]:
        ans += C[A[i]-1]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())

s=0
bef=float('inf')
for i in range(n):
      s+=b[a[i]-1]
      if bef+1==a[i]:
            s+=c[a[i]-2]
      bef=a[i]
print(s)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
ans+=sum(b)
print(ans)

Submission status: Accepted

Solution code:
# ABC 140: B – Buffet
n = int(input())
a, b = [[int(s) for s in input().split()] for _ in range(2)]
c = [int(s) for s in input().split()]

points = 0

for i in range(n):
    points += b[a[i] - 1]
    if i < n - 1:
        if a[i + 1] - a[i] == 1:
            points += c[a[i] - 1]

print(points)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

score = 0
item = float('inf')
for a in A:
    score += B[a-1]
    if item+1 == a:
        score += C[a-2]
    item = a
print(score)

Submission status: Accepted

Solution code:
num = int(input())
bangou = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
addit = list(map(int ,input().split()))
a = 0
for i, youso in enumerate(bangou):
    a += manzoku[youso-1]
    if i == 0:
        pass
    else:
        if bangou[i-1] == youso - 1:
            a += addit[bangou[i-1]-1]
print(a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve(N, A, B, C):

    ans = 0
    pre = -1000
    for i in range(N):
        a = A[i] - 1
        ans += B[a]

        if pre + 1 == a:
            ans += C[pre]

        pre = a

    return ans


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    print(solve(N, A, B, C))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N - 1):
    if A[i] + 1 == A[i + 1]:
        B.append(C[A[i] - 1])

print(sum(B))