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()))

t = 0

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

print(sum(b) + t)

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 and a[i] + 1 == a[i+1] :
    ans += c[a[i]-1]

print(ans)

Solution (Python):
n = int(input())
a, b, c = [list(map(int, input().split())) for _ in range(3)]

ans = sum(b)
last = -1
for x in a:
    if last+1 == x:
        ans += c[last-1]
    last = x
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)
now = 99
for i in A:
  pre = now
  now = i
  if now == (pre+1):
    ans += C[pre-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
a_ = -float('inf')
for a in A:
    a = a - 1
    ans += B[a]
    if a_ == a - 1:
        ans += C[a_]
    a_ = 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())) 
ans1=0
for i in range(1,n):
    if a[i]==a[i-1]+1:
        ans1+=c[a[i-1]-1]
print(sum(b)+ans1)

Solution (Python):
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
A = list(map(int, inputs[1].split()))
B = list(map(int, inputs[2].split()))
C = list(map(int, inputs[3].split()))

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

print(x)

Solution (Python):
import copy

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

bef = -1
ans = 0
for i in A:
    ans += B[i-1]
    if(bef + 1 == i):
        ans += C[i-2]
    bef = 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()]
ans = B[A[0]-1]
for i in range(N-1):
  ans += B[A[i+1]-1]
  if(A[i+1] == A[i] + 1):
    ans += C[A[i]-1]
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()]

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()))

ful = sum(B)

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

print(ful)

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

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

sati = 0
for (index, a) in enumerate(A):
    sati += B[a-1]

    if(index+1 < N and A[index]+1 == A[index+1]):
        sati += C[A[index]-1]

print(sati)

Solution (Python):
import numpy as np


N = int(input())
A = np.array(input().split(), np.int32)
B = np.array(input().split(), np.int32)
C = np.array(input().split(), np.int32)

A_diff = np.zeros(A.shape)
A_diff[1:] = np.diff(A, n=1)

res = 0

for i, diff_num in zip(A, A_diff):
    res += B[i-1]
    if diff_num == 1:
        res  += C[i-2]

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()))
add = 0
for i in range(len(a)-1):
    if a[i] == a[i+1]-1:
        add += c[a[i]-1]
print(sum(b)+add)

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

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

temp = -100
ans = 0

for i, value in enumerate(A):
    ans += B[value-1]

    if temp == value-1:
        ans += C[value-2]

    temp = value

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 != 0 and A[i - 1] == A[i] - 1:
    ans += C[A[i] - 2]
print(ans)

Solution (Python):



from math import *
import os
import sys


import numpy as np



if __name__ == "__main__":
    Input = [input() for i in range(4)]
    N = int(Input[0])
    A = list(map(int,Input[1].split()))
    B = list(map(int,Input[2].split()))
    C = list(map(int,Input[3].split()))

    raw = sum(B[i-1] for i in A)
    for i in np.arange(1,len(A),1):
        if A[i]-A[i-1] == 1:
            raw = raw + C[A[i-1]-1]
    print(raw)

Solution (Python):

ans=0
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=ans+B[A[0]-1]
for i in range(1,N):
    ans=ans+B[A[i]-1]
    if A[i]==A[i-1]+1:
        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()))
tot = sum(B)
for i in range(n-1):
  if A[i+1] == A[i]+1:
    tot += C[A[i]-1]
print(tot)

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
prev = 0
for i in range(n):
  s += B[A[i]-1]
  if A[i] != 1 and (A[i]-1 == prev):
    s += C[A[i]-2]
  prev = A[i]
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()))
D = []
for i in range(N-1):
  if A[i+1] - A[i] ==1:
    D.append(C[A[i]-1])

print(sum(B)+sum(D))

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

ans=0
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):
from sys import stdin

def main():
    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, a in enumerate(A):
        ans += B[a-1]
        if i > 0 and A[i] - A[i-1] == 1:
            j = A[i-1] - 1
            ans += C[j]
    print(ans)

input = lambda: stdin.readline()[:-1]
main()

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-1):
    j=A[i]-1
    s=s+B[j]
    if(j+1!=N):
        if(A[i+1]-j==2):
            s=s+C[j]
j=A[N-1]-1
s=s+B[j]
print(s)

Solution (Python):
N = int(input())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
clist = list(map(int,input().split()))

ans = 0
past = 999

for i in alist:

    if i - past == 1:
        
        ans += clist[past-1]
    
    ans += blist[i-1]
    past = 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()))

tot = 0

for i in range(1,N+1):
  tot+=B[i-1]
  if i>1:
    if A[i-2]==A[i-1]-1:
      tot+=C[A[i-2]-1]

print(tot)

Solution (Python):
import sys
from pprint import pprint

def solve(n, a, b, c):
    ans = 0
    pre = -1
    for a_i in a:
        
        ans += b[a_i-1]
        if pre + 1 == a_i:
            ans += c[pre-1]
        pre = a_i

    print(ans)

if __name__ == '__main__':
  n = int(sys.stdin.readline().strip())
  a = list(map(int, sys.stdin.readline().strip().split(" ")))
  b = list(map(int, sys.stdin.readline().strip().split(" ")))
  c = list(map(int, sys.stdin.readline().strip().split(" ")))
  
  
  
  solve(n, a, b, c)

Solution (Python):
import sys
stdin = sys.stdin
mod = 10**9 + 7

import numpy as np

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = na()
b = na()
c = na()
ans = sum(b)
d = np.array(a[:-1]) - np.array(a[1:])
for di, num in enumerate(d):
        if num == -1:
                ans += c[a[di]-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(" ")))

r = 0
j = -1
for i in A:
  r += B[i-1]
  
  if i - j == 1:
    r += C[i-2]
    
  j = i
  
print(r)

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]==A[i+1]-1):
    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()]

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

print(result)

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

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

for a in range(N):
    A[a] -= 1


cnt = 0
cnt += B[int(A[0])]

pa = A[0]

for a in A[1:N+1]:
    cnt += B[int(a)]

    if (a-1) == pa:
        cnt += C[int(a-1)]
    pa = a

print(cnt)

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
prev = len(C)
for i in range(N):
  count += B[A[i]-1]
  if prev < len(C) and prev + 1 == A[i]-1:
    count += C[prev]
  prev = A[i] - 1
print(count)

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

print(s)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
A = LI()
B = LI()
C = LI() + [0]
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 = B[A[0]-1]
for i in range(1, N):
  if A[i] == A[i-1] + 1:
    S += B[A[i]-1] + C[A[i-1]-1]
  else:
    S += B[A[i]-1]
print(S)

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

m = 0
for i in range(N):
    m +=  B[A[i] - 1]
    if i != 0:
        if A[i] - A[i - 1] == 1:
            m += C[A[i -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()))
A = [i - 1 for i in A]
res = B[A[0]]
for i in range(1,N):
    res += B[A[i]]
    if A[i] - A[i - 1] == 1:
        res += C[A[i - 1]]
print(res)

Solution (Python):
n = int(input())
a, b, c = [list(map(int, input().split())) for _ in range(3)]
ans, pro = 0, -100
for i in a:
    ans += b[i-1]
    if pro + 1 == i-1: ans += c[pro]
    pro = 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()))

lst =[]
count = sum(b)

for i in range(n - 1):
  if a[i + 1] == a[i] + 1:
    lst.append(a[i] - 1)
  
for i in lst:
  count += c[i]
  
print(count)

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

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

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] :
        s = s + C[A[i]-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 = sum(b)
for i in range(1, n):
  if a[i-1] == a[i]-1:
    ans += c[a[i-1]-1]
    
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()]

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

print(res)

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

ans = 0
pre = -10
for i in range(1, N + 1):
    ans += B[A[i]]
    if i >= 2 and pre + 1 == A[i]:
        ans += C[pre]
    pre = 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()))
ans = B[0]
for i in range(1,N):
    if A[i] - A[i-1] == 1:
        ans += C[A[i]-2]
    ans += B[i]

print(ans)

Solution (Python):
import sys
import math
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_a = list(map(int, sys.stdin.readline().split()))
list_b = list(map(int, sys.stdin.readline().split()))
list_c = list(map(int, sys.stdin.readline().split()))





sum_b = 0

for i in range(N):
    sum_b += list_b[i]
    if(i < N-1 and (list_a[i]+1) == list_a[i+1]):
        sum_b += list_c[list_a[i]-1]

print(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()))

dish = []       
for i in range(N):
 dish.append([A[i],B[A[i]-1]])

ans = 0
for i in range(N):
  ans += dish[i][1]
  if(i != N-1):
    if(dish[i][0]+1 == dish[i+1][0]):
      index_ = dish[i][0]-1
      ans += C[index_]
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()))


b2 =[0 for i in range(n)]

for i in range(n):
    b2[i] = b[a[i]-1]

out = b2[0]
pre = a[0]

for i in range(1,n):
    out += b2[i]
    
    if a[i]-pre == 1:
        out += c[a[i]-2]
    pre = a[i]
        
print(out)

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

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):
    if i == 0:
        ans += b[i]
    else:
        ans += b[i]
        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()))
total=sum(b)
for i in range(len(c)):
    if a[i+1]-a[i]==1:
        total +=c[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()))

score = 0
before = N

for i in range(N):

    x = A[i] - 1
    score += B[x]

    if before + 1 == x:
        score += C[before]

    before = x

print(score)

Solution (Python):
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
s=lb[la[0]-1]
for i in range(1,n):
  s+=lb[la[i]-1]
  if la[i]-la[i-1]==1:
    s+=lc[la[i-1]-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()))
tmp = 0
for i in range(0, len(b)):
    tmp += b[a[i]-1]
    if(i < n-1 and a[i]+1 == a[i+1]):
        tmp += c[a[i]-1]

print(tmp)

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()]
bef = -2
sum = 0
for i in range(N):
  
  sum += B[A[i]-1]
  if bef+1 == A[i]:
    sum+=C[A[i]-2]
    
  bef = A[i] 

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()))
count = 0
for i in range(n):
    ryori = a[i] - 1
    manzoku = b[ryori]
    count += manzoku
    if i < n-1:
        if a[i] - a[i+1] == -1:
            count += c[ryori]
print(count)

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-1):
    sum += b[i]
    if a[i+1]==a[i]+1:
        sum += c[a[i]-1]
sum += b[n-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()))

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

print(manzoku)

Solution (Python):
import sys
input=sys.stdin.readline

n=int(input())
a=[]
for i in range(3):
    aa=list(map(int,input().split()))
    a.append(aa)
ans=0
num=-1
num2=-1
for j in a[0]:
    ans+=a[1][j-1]
    num2=j
    if num2-num==1:
        ans+=a[2][j-2]
    num=j
print(ans)

Solution (Python):
n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
c = [int(_) for _ in input().split()]
ans = 0
prev = -1
for i in range(n):
    curr = a[i]
    ans += b[a[i] - 1]
    if curr - prev == 1:
        ans += c[prev-1]
    prev = curr
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]

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

    
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()))
res=0
res+=b[a[0]-1]

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

  if i>=1 and a[i]==a[i-1]+1:
    res+=c[a[i-1]-1]

print(res)

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())


dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

add = 1 
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)


li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    


org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)




    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


N = int(input())

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

for n in range(N):
    A[n] -= 1    

def main(): 
    res = B[A[0]]
    past = A[0]
    for n in range(1,N):
        res += B[A[n]]
        if A[n] == past+1:
            res+=C[A[n]-1]
        past = A[n]
        
    print(res)
                
                
                
            
            
                

    
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(' ')))

before = -1
sum_happy = 0

for a in A:
    sum_happy += B[a - 1]
    if a == before+1:
        sum_happy += C[a - 2]
    before = a

        
print(sum_happy)

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
pre = -2
for a in A:
    sum += B[a-1]
    if (pre+1) == a:
        sum += C[pre-1]
    pre = a

print(sum)

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

ans=0
prev=None
for i in range(N):
	a=A[i]
	ans+=B[a-1]
	if prev is None:
		pass
	elif prev+1==a:
		ans+=C[prev-1]
	prev=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()))

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


score=0

num=0
old_num=0

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

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()))
CN = 0

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

print(sum(B)+CN)

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
k=10000
for i in a:
    ans+=b[i-1]
    if k==i-1:
        ans+=c[i-2]
    k=i
print(ans)

Solution (Python):
N = int(input())
A = [int(a) - 1 for a in 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]]
  if i != N-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()))
satis = B[A[0]-1]
for i in range(1,N):
    satis+=B[A[i]-1]
    if A[i-1]+1 == A[i]:
        satis += C[A[i-1]-1]
print(satis)

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

alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))

result = 0

for i in range(n):
    result += blist[alist[i]-1]
    if i != n-1:
        if alist[i+1] == (alist[i] +1):
            result += clist[alist[i]-1]

print(result)

Solution (Python):
'use strict'
N = int(input())
A = [x-1 for x in (list(map(int, input().split())))]
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisfy_level = B[A[0]]

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

print(satisfy_level)

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()))

manzoku = sum(B_list)

before = A_list[0]
for i in range(1, N):
  if A_list[i] == before + 1:
    manzoku += C_list[before-1]
  before = A_list[i]

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()))

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

print(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(N):
    ai = A[i] - 1
    ans += B[ai]
    if i > 0 and ai == A[i - 1] - 1 + 1:
        ans += C[A[i - 1] - 1]
    

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split())) + [10000]
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 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()))
sum = 0
bonus = 10**9
for i in range(N):
    sum += B[A[i]-1]
    if A[i] == bonus:
        sum += C[A[i]-2]
    bonus = 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()))
 
befo = -100
sat = 0
for i in range(N):
    index = A[i] - 1
    sat += B[index]
    if befo + 1 == index:
        sat += C[befo]
    befo = index
 
print(sat)

Solution (Python):


import sys

n=int(sys.stdin.readline())
a= [ int(x)-1 for x in sys.stdin.readline().split() ]
tot= 0
for x in sys.stdin.readline().split(): tot+=int(x)
c= [ int(x) for x in sys.stdin.readline().split() ]

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

Solution (Python):
N = int(input())
A = [int(a)-1 for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

satisfaction = 0
dinner1 = A[0]
satisfaction += B[dinner1]

for a in A[1:]:
  dinner2 = a
  satisfaction += B[dinner2]
  if dinner1 + 1 == dinner2:
    satisfaction += C[dinner1]
  dinner1 = dinner2

print(satisfaction)

Solution (Python):

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

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

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

prev = a[0]-1
ans = b[a[0]-1]

for i in a[1:]:
  _i = i-1
  ans += b[_i]
  if prev + 1 == _i:
    ans += c[prev]
  prev = _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
prev_idx = -10
for a in A:

    ans += B[a-1]
    if prev_idx + 1 == a-1:
        ans += C[a-2]
    prev_idx = a-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
pre = -1
for a_i in a:
    count += b[a_i-1]
    if pre == a_i - 1:
        count += c[pre-1]
    pre = a_i

print(count)

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

for i in a:
  p += b[i-1]
  if i == r+1:
    p += c[i-2]
  r = i

print(p)