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):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


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

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

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):
import sys
import collections
import copy
import math
def input(): return sys.stdin.readline().strip()
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 = 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(n):
    cur = a[i]
    ans += b[a[i]-1]
    if i < n-1 and a[i+1] == cur+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(n):
    if i == 0:
        ans += b[a[0]-1]
    else:
        if a[i-1] + 1 == a[i]:
            ans += b[a[i]-1] + c[a[i]-2]
        else:
            ans += b[a[i]-1]
print(ans)

Solution (Python):
N = int(input())
food = list(map(int, input().split(" ")))
one = list(map(int, input().split(" ")))
sec = list(map(int, input().split(" ")))
cnt = 0
for i in range(N-1):
  cnt += one[food[i]-1]
  if food[i+1] == food[i]+1:
    cnt += sec[food[i]-1]
cnt += one[food[N-1]-1]
print(cnt)

Solution (Python):
n = int(input())
a = [int(x) - 1 for x in input().split()]
b = list(map(int, input().split()))
c = list(map(int, input().split()))

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

cnt = 0
for i in range(N-1):
    cnt += B[A[i]-1]
    if A[i] + 1 == A[i+1]:
        cnt += C[A[i]-1]
    
cnt += B[A[N-1]-1]
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()))
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,B,C=[[int(i) for i in input().split()] for j in range(3)]
manzoku=0
prev=0
for n,a in enumerate(A):
  b=a-1
  if n!=0:
    if b==prev+1:
      manzoku+=C[b-1]
  manzoku+=B[b]
  prev=b
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(' ')))

ans = 0
pre_a = -100 
for a in A:
	ans += B[a-1]
	if a == pre_a + 1:
		ans += C[pre_a-1]
	pre_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()))

prev = -1
ans = 0
for a in A:
    ans += B[a-1]
    if a == prev + 1:
        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()))

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

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

ans = B[A[0] - 1]

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

print(ans)

Solution (Python):
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 = 0
prev = -2
for a in A:
    total += B[a]
    if prev + 1  == a:
        total += C[a-1]
    prev = a
print(total)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
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=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 = list(map(int, input().split())) 
b = list(map(int, input().split()))
c = list(map(int, input().split()))
now = a[0]
ans = sum(b)
for i in a[1:]:
  if i == now + 1:
    ans += c[now - 1]
  now = 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 = sum(B)
for i,(a,b) in enumerate(zip(A,A[1:])):
    if b-a == 1:
        ans += C[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() ))

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

print(ans + sum(b))

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

ans = B[A[0]]
for i in range(1,N):
    ans += B[A[i]]
    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()]
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):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l1=LI()
  l2=LI()
  l3=LI()

  ans=0
  b=-1
  for i,x in enumerate(l1):
    ans+=l2[x-1]
    if x==b+1:
      ans+=l3[b-1]
    b=x
  return ans


print(main())

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
prev = -float('inf')
res = 0
for e in a:
    e -= 1
    res += b[e]
    if prev == e - 1:
        res += c[prev]
    prev = e
print(res)

Solution (Python):


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

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

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

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

print(ans)

Solution (Python):

from sys import stdin




def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
a_list = _li()
b_list = _li()
c_list = _li()

ans = sum(b_list)
for i in range(N-1):
    if a_list[i] + 1 == a_list[i+1]:
        ans += c_list[a_list[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 = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i > 0:
        if a[i] - a[i - 1] == 1:
            ans += c[a[i - 1] - 1]
print(ans)

Solution (Python):
n = int(input())
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
c_lst = list(map(int, input().split()))

res = sum(b_lst)
for i in range(n-1):
    if a_lst[i] + 1 == a_lst[i+1]:
        res += c_lst[a_lst[i]-1]
print(res)

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

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = inp()
a = inpl()
b = inpl()
c = inpl()
res = 0
for i in range(n):
    res += b[a[i]-1]
    if i > 0 and a[i] == a[i-1] + 1:
        res += c[a[i-1]-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()))

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

print(ans)

Solution (Python):

from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()

    a = li()
    b = li()
    c = li()

    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)


main()

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

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

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
c = [int(i) for i in readline().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):



def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    lb = rli()
    lc = rli()
    ans = sum(lb)
    for i in range(n-1):
        if la[i+1] == la[i]+1:
            ans += lc[la[i]-1]
    print(ans)


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()))
prev = -1
score = 0
for i in range(N):
    if prev+1 == A[i]:
        score+=C[prev-1]
    score+=B[A[i]-1]
    prev = 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 = 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=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

ans=sum(b)
for i,j in zip(a[:-1],a[1:]):
  if j==i+1:
    ans+=c[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
pre_i = None
for i in A:
    i -= 1
    ans += B[i]
    if pre_i == i - 1:
        ans += C[pre_i]
    pre_i = i

print(ans)

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

def main():
    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]
    pre = a[0] - 1
    for i in range(1, N):
        ans += b[a[i] - 1]
        if pre + 1 == a[i] - 1:
            ans += c[pre]
        pre = a[i] - 1
    print(ans)


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

ans = 0
mae = -1
for i in range(len(A)):
    ans += B[A[i]-1]
    if mae + 1 == A[i]:
        ans += C[mae-1]
    mae = 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 = 0
last = -1
for a_i in a:
    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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

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

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
AA = inpl()
BB = inpl()
CC = inpl()

ans = sum(BB)
for i in range(N-1):
    if AA[i+1] == AA[i]+1:
        ans += CC[AA[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):


from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_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):
import sys
input = sys.stdin.readline

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):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in A:
    ans += B[i - 1]

for i, j in zip(A, A[1:]):
    if i + 1 == j:
        ans += C[i - 1]

print(ans)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
a = na()
b = na()
c = na()

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]-2]

print(ans)

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

main()

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)
from collections import *
from bisect import *
mod = 10**9+7

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, j in zip(a, a[1:]):
    if i+1 == j:
        ans += c[i-1]
print(ans)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
l = list(map(int,input().split()))
ans = sum(li)
for i in range(n-1):
    if lis[i] +1 == lis[i+1]:
        ans += l[lis[i]-1]
print(ans)

Solution (Python):
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() 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)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():

    return


def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return


def C():

    return


def D():

    return


def E():

    return


def F():

    return


if __name__ == "__main__":
    B()