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

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

sat = 0
beforeA = -1
for i in A:
    sat += B[i - 1]
    if i == beforeA+1:
        sat += C[beforeA - 1]
    beforeA = i

print(sat)

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

Solution (Python):
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(len(A)):
    if i > 0 and A[i] - A[i-1] == 1:
        ans += (B[A[i]-1] + C[A[i-1]-1])
    else:
        ans += B[A[i]-1]

print(ans)

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

Solution (Python):
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)

Solution (Python):
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(len(A)):
    ans += B[A[i] - 1]
    if (i >= 1) & (A[i] == (A[i - 1] + 1)):
        ans += C[A[i - 1] - 1]
    else:
        ans = ans
print(ans)

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

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

print(answer)

Solution (Python):
n=int(input())
ans=0
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

for i in range(n):
  ans+=B[i]
for j in range(n-1):
  if (A[j]+1)==A[j+1]:
    ans+=C[A[j]-1]
print(ans)

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

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

Solution (Python):
n = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
m = 0
mae = -1
for i in A:
    m += int(B[int(i)-1])
    if int(i) - mae  == 1:
        m += int(C[int(i)-2])
    mae = int(i)
print(m)

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


s=0

for i in range(0,N):
  s=s+B[i]

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

s=s+extra

print(s)

Solution (Python):
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()]
total = sum(b)
last_dish = a[0]
for d in a[1:]:
  if d-last_dish == 1:
    total += c[last_dish-1]
  last_dish = d
print(total)

Solution (Python):
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]
    if A[i-1]+1==A[i]:
        ans+=C[A[i-1]-1]

print(ans)

Solution (Python):

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 < N - 1:
        if A[i + 1] == A[i] + 1:
            ans += C[A[i] - 1]

print(ans)

Solution (Python):
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)

Solution (Python):
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

ans = 0
prev = 40

for i in range(n):
    ans += bl[al[i]-1]
    if al[i] - prev == 1:
        ans += cl[prev-1]

    prev = al[i]

print(ans)

Solution (Python):
N = int(input())

A_list = list(map(int, input().split()))

B_list = list(map(int, input().split()))

C_list = list(map(int, input().split()))


last_meal = -100

res = 0

for meal in A_list:
        res += B_list[meal - 1]
        if meal == last_meal + 1:
                res+= C_list[meal-2]
        last_meal = meal


print(res)

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


def solve():
    point = 0

    point += sum(B)

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

    return point


print(solve())

Solution (Python):
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 - 1):
    if a[i] + 1 == a[i + 1]:
        m += b[a[i] - 1] + c [a[i] - 1]
    else:
        m += b[a[i] - 1]
        
m += b[a[n - 1] - 1]
        
print(m)

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

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

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

print(s)

Solution (Python):
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 < n - 1:
        if a[i + 1] == a[i] + 1:
            ans += c[a[i] - 1]
print(ans)

Solution (Python):
"""
author : halo2halo
date : 18,Oct,2019
"""

import sys
input = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

S = 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()]
ans = sum(B)
num = -1
for i in A:
    if num + 1 == i:
        ans += C[num - 1]
    num = i


print(ans)

Solution (Python):
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()]

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

Solution (Python):
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)

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

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

ans=0

for x,y in zip(a,a[1:]):
  if y == x+1:
    ans += c[x-1]
    
print(sum(b)+ans)

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

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

Solution (Python):
N = 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, len(A)):
    ans += B[A[i] - 1]
    if A[i - 1] == A[i] - 1:
        ans += C[A[i - 1] - 1]
print(ans)

Solution (Python):
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:
        if A[i] == A[i-1] + 1:
            sum += C[A[i-1]-1]

print(sum)

Solution (Python):
N = int(input())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))

ret = sum(lst_B)
for idx, n in enumerate(lst_A[:-1]):
    if n == lst_A[idx + 1] - 1:
        ret += lst_C[n - 1]
print(ret)

Solution (Python):
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-1]+1==A[i]:
        ans+=C[A[i-1]-1]
print(ans)

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

Solution (Python):
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(len(A)-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]

print(ans+sum(B))

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

Solution (Python):
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]
C_list = [int(i) for i in input().split()]

satisfied = 0

for i, a in enumerate(A_list):
  point = B_list[a-1]
  satisfied += point
  
  if i != 0:
    previous = A_list[i-1]
    
    if previous == a-1:
      satisfied += C_list[previous-1]

print(satisfied)

Solution (Python):
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):
    a[i] -= 1
    ans += b[a[i]]
    if i > 0 and a[i - 1] + 1 == a[i]:
        ans += c[a[i - 1]]

print(ans)

Solution (Python):
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,j=0,51
for i in a:
    ans+=b[i-1]
    if j+1==i:
        ans+=c[j-1]
    j=i
print(ans)

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

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

Solution (Python):
n = int(input())

A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
ans  = 0
tmp = 0
for i in range(n):
  ans += B[A[i] -1]
for i in range(n-1):
  if A[i] +1 == A[i+1]:
    ans += C[A[i]-1]
print(ans)

Solution (Python):
n = int(input())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
clist = list(map(int,input().split()))
score = blist[alist[0]-1]
for i in range(1,n):
    if alist[i] - alist[i-1] == 1:
        score += blist[alist[i]-1] + clist[alist[i] - 1 -1]
    else:
        score += blist[alist[i]-1]

print(score)

Solution (Python):

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


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

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

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

print(answer)

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

Solution (Python):
n= int(input())
la=list(map(int, input().split()))
lb=list(map(int, input().split()))
lc=list(map(int, input().split()))
result=0
for i in range(n-1):
	if la[i]-la[i+1]==-1:
		result+=lc[la[i]-1]
print(sum(lb)+result)

Solution (Python):
n = int(input())
dishes = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

point = 0
prev = 0
for index, dish in enumerate(dishes):
	if index==0:
		point += b[dish-1]
	else:
		if prev+1 == dish:
			point += (b[dish-1]+c[prev-1])
		else:
		 	point += b[dish-1]
	prev = dish

print(point)

Solution (Python):
def main():
    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()]

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


if __name__ == '__main__':
    main()

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

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

print(suti)

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

print(b)

Solution (Python):
a = [input().split() for l in range(4)]
N=int(a[0][0])
A=a[1]
B=a[2]
C=a[3]
manzoku=0
for i in range(N):
    manzoku=manzoku+int(B[int(A[i])-1])
    if i>0 and int(A[i])==int(A[i-1])+1:
        manzoku=manzoku+int(C[int(A[i-1])-1])

print(manzoku)

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

res=0
back=-1

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

Solution (Python):
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] == A[i+1]-1:
    B.append(C[A[i]-1])
    
print(sum(B))

Solution (Python):
n = int(input())
dish = [int(i) for i in input().split()]
satisfy = [int(i) for i in input().split()]
bonus = [int(i) for i in input().split()]

ans = 0
pre = -1
for d in dish:
  ans += satisfy[d-1]
  if d == pre + 1:
    ans += bonus[d-2]
  pre = d

print(ans)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
total=sum([int(i) for i in input().split()])
add=[int(i) for i in input().split()]

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

print(total)

Solution (Python):
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[a[i]-1]
    if i != 0 and a[i-1]+1 == a[i]:
        ans += c[a[i-1]-1]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
C = list(map(int, input().split())) 
total = 0
preDish = -10
for a in A:
  total += B[a-1]
  if preDish == a - 1 and preDish <= len(C):
    total += C[preDish - 1]
  preDish = a

print(total)

Solution (Python):
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()))

def it():
    for x,y in zip(A,A[1:]):
        if x+1 == y:
            yield C[x]
    for x in A:
        yield B[x]
print(sum(it()))

Solution (Python):
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] == a[i+1]-1:
    ans += c[a[i]-1]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
prev = -10
for one in A:
    ans+=B[one-1]
    if one==prev+1:
        ans+=C[prev-1]
    prev = one
print(ans)

Solution (Python):
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]

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

print(sum)

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

satis = 0 
temp_menu = -1 

for menu in A: 
    satis += B[menu-1]
    
    if menu == temp_menu+1 :
        satis += C[temp_menu-1]
    
    temp_menu = menu

print(satis)

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

res = sum(B)

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

print(res)

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

res = sum(B)

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

print(res)

Solution (Python):
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[i]
    if i == n-1:
        continue
    else:
        if A[i]+1 == A[i+1]:
            sum += C[A[i]-1]
print(sum)

Solution (Python):
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()]

res = 0
for i in range(len(A)):
    res += B[A[i] - 1]
    if i + 1 < N:
        if A[i+1] == A[i] + 1:
            res += C[A[i] - 1]

print(res)

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    last = -999
    satis = 0
    for now in A:
        if now-1 == last:
            satis += C[last-1]
        satis += B[now-1]
        last = now
    print(satis)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    B = [int(next(tokens)) for _ in range(N)]  
    C = [int(next(tokens)) for _ in range(N - 1)]  
    solve(N, A, B, C)


if __name__ == '__main__':
    main()

Solution (Python):
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()]
m=0
before=-1
for i in a:
  m+=b[i-1]
  if before+1==i:
    m+=c[before-1]
  before=i
print(m)

Solution (Python):



food_cnt = int(input())
food_odr = list(map(int, input().strip().split()))
food_man = list(map(int, input().strip().split()))
food_pls = list(map(int, input().strip().split()))


man_sum = 0
man_sum += food_man[0]
for i in range(1,food_cnt):
    man_sum += food_man[i]
    if (food_odr[i-1] + 1) == food_odr[i]:
        man_sum += food_pls[food_odr[i-1]-1]

print(man_sum)

Solution (Python):
n = int(input())
L = [int(i) for i in input().split()]
c = sum(int(i) for i in input().split())
C = [int(i) for i in input().split()]
for i in range(len(L)-1):
  if L[i]+1 == L[i+1]:
    c += C[L[i]-1]
print(c)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, 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)

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

Solution (Python):
N = int(input())
A = []
B = []
C = []
sat = 0
for x in input().split():
    A.append(int(x))
for x in input().split():
    B.append(int(x))
    sat += int(x)
for x in input().split():
    C.append(int(x))

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

print(sat)

Solution (Python):
N = int(input())

satis = 0

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

next = -1

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

print(satis)

Solution (Python):
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

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

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
m = 0
count = 0
for i in range(N):
    eat_num = As[count]
    if count != 0:
        before = As[count-1]
        if before + 1 == eat_num:
            m = m + Cs[before-1]
    m = m + Bs[eat_num-1]
    count += 1
print(m)

Solution (Python):
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]
    if a[i] == a[i-1] + 1:
        ans += c[a[i-1]-1]

print(ans)

Solution (Python):

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

sat = 0
old_i = -2
for a in A:
    i = a - 1
    sat += B[i]
    if old_i + 1 == i:
        sat += C[old_i]
    old_i = i

print(sat)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C =  list(map(int,input().split()))
point = 0
check = 0
for i in A:
  if check == i:
    point += C[i-2]
  point += B[i-1]
  check = i + 1
print(point)

Solution (Python):
n = int(input())

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

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

    if last == a[i]-1:
        ans += c[a[i]-2]
        
    last = a[i]

print(ans)

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

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

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

Solution (Python):
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)

Solution (Python):
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
old = -12
ans = 0
for a in A:
    if old + 1 == a:
        ans += C[old - 1]
    
    ans += B[a - 1]
    old = a

print(ans)

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
b = -1
for a in A:
    if b+1==a:ans+=C[b-1]
    b = a
    ans+=B[b-1]
print(ans)

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pnt = 0
for i in range(len(A)):
  pnt += B[A[i]-1]
  if i>0 and A[i]-A[i-1]==1:
    pnt += C[A[i]-2]
print(pnt)

Solution (Python):
N = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

old_index = False
s = 0
for a in al:
  s += bl[a-1]
  if old_index is not False and old_index + 1 == a:
    s += cl[a-2]
  old_index = a
print(s)

Solution (Python):
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

before = None
for a in A:
    ans += B[a-1]
    if before is not None:
        if a - before == 1:
            ans += C[a-2]
    before = a

print(ans)

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,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)

Solution (Python):
N = int(raw_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(0,N):
  ans = ans + B[A[i]-1]
  if i>0 and A[i-1]+1==A[i]:
    ans = ans + C[A[i-1]-1]

print ans

Solution (Python):
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)

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

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

Solution (Python):
N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
kotae = 0
for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    kotae += C[A[i]-1]
kotae += sum(B)
print(kotae)

Solution (Python):


N = int(input())
cuisine = list(map(int, input().split()))
satis = list(map(int, input().split()))
bonus = list(map(int, input().split()))

sum = 0;

for i in range(N):
    sum += satis[i]
    num = cuisine[i]
    try:
        if(cuisine[i+1]==num+1):
            sum+=bonus[num-1]
    except:
        pass

print(sum)

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

Answer=sum(B)

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

print(Answer)

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

ans = 0
prv = -1

for i in A:
  ans += B[i-1]
  if prv == i - 1:
    ans += C[prv-1]
  
  prv = i

print(ans)

Solution (Python):
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[i]
    if i != 0 and a[i-1] == a[i] - 1:
        sum += c[a[i - 1] - 1]

print(sum)

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

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

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
satisfaction = 0
i0 = -2
for i in a:
    if i - i0 == 1:
        satisfaction += c[i - 2]
    satisfaction += b[i-1]
    i0 = i
print(satisfaction)

Solution (Python):
"""
3
3 1 2
2 5 4
3 6

ans 14
"""


def main():
    N = int(input())
    A = [int(x)-1 for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]

    total_eat_point = 0
    for round_num in range(N):
        total_eat_point += B[A[round_num]]
        if round_num == 0:
            continue
        if A[round_num] - 1 == A[round_num-1]:
            total_eat_point += C[A[round_num-1]]

    print(total_eat_point)


if __name__ == "__main__":
    main()

Solution (Python):

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

print(str(sat))

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


B_sum = sum(B)
ex = 0

for n in range(N-1):
    if A[n] == A[n+1]-1:
        ex += C[A[n]-1]
    else:
        pass
ans = B_sum + ex

print(ans)