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())
eat = list(map(int, input().split(" ")))
satisfication = list(map(int, input().split(" ")))
add_satisfication = list(map(int, input().split(" ")))

total = 0
previous_eat = ""
for i in eat:
  total = total + satisfication[i-1]
  if previous_eat == i-1:
    total = total + add_satisfication[previous_eat-1]
  previous_eat = i

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()))
D = B[N-1]
for i in range(N-1):
    D += B[i]
    if A[i] + 1 == A[i+1]:
        D += C[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()))
suf = 0
for i in range (n):
  suf += b[i]
  if i >= 1 and a[i - 1]  + 1 == a[i]:
    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()))
s = 0
for i in range(n):
 s += b[a[i]-1]
 if a[i] == a[i-1] + 1 and i >= 1:
     s += c[a[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()))
manzoku=0
for i in range(n-1):
  if A[i]+1==A[i+1]:
    manzoku+=C[A[i]-1]
manzoku+=sum(B)
print(manzoku)

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

m = -10
s = 0
for d in A:
    s+=B[d-1]
    if d == m + 1:
        s+=C[m-1]
    m = d
print(s)

Solution (Python):
n = int(input())
eat_lst = list(map(int,input().split()))
manzoku_lst = list(map(int,input().split()))
tuika_lst = list(map(int,input().split()))

res = sum(manzoku_lst)


for i in range(n-1):
    if eat_lst[i] + 1 == eat_lst[i+1]:
        res = tuika_lst[eat_lst[i]-1] + res
print(res)

Solution (Python):
N=int(input())
A=map(int,input().split())
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ANS=0
BC=-99
for a in A:
  if BC == a - 1:
    ANS += C[a-2]
  BC = a
  ANS += B[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()))

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

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

Solution (Python):
N=int(input())
A=[int(x)-1 for x in input().split()]
B={A[i]:int(x) for i,x in enumerate(input().split())}
C=[int(x) for x in input().split()]
score=B[A[0]]
for i in range(1,N):
    score+=B[A[i]]
    score+=C[A[i-1]] if A[i-1]+1==A[i] else 0
print(score)

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
last_order = -100
for n in A:
  res += B[n-1]
  if n-1 == last_order+1:
    res += C[n-2]
  last_order = n-1
print(res)

Solution (Python):
N = int(input())
A_l = [x-1 for x in list(map(int, input().split()))]
B_l = list(map(int, input().split()))
C_l = list(map(int, input().split()))

ans = 0

for idx in range(len(A_l)):
    ans += B_l[A_l[idx]]
    if idx >= 1:
        if A_l[idx] - A_l[idx-1] == 1:
            ans += C_l[A_l[idx-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()))
result = 0

for i in range(N):
  result += B[A[i] - 1]
  if(i < N - 1 and A[i] + 1 == A[i + 1]):
    result += C[A[i] - 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()))
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
for a,b in zip(A,A[1:]):
  if b == a+1:
    sat += C[a-1]
    
print( sum(B) + sat )

Solution (Python):




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

satisf = sum(B)

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

print(satisf)

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

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    ans = 0
    old = -1
    for i, val in enumerate(A):
        if old != -1 and old+1 == val:
            ans += C[old-1]
        ans += B[val-1]
        old = val
            
    print(ans)
    
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()]

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()))
g=sum(map(int,input().split()))
c=list(map(int,input().split()))
for i,j in zip(a,a[1:]):
  if j-i==1:
    g+=c[i-1]
print(g)

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, 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()))
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 = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
res = 0
pre = -1
for i in A:
    res += B[i-1]
    if i - pre == 1:
        res += C[pre-1]
    
    pre = i

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

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

satisfaction=0

for i in range(N):
  satisfaction+=B[A[i]-1]
    
  if  i<=N-2:
      if  A[i]+1==A[i+1]:
          satisfaction+=C[A[i]-1] 
  else:
      pass

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

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

print(manzokudo)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
sum_s = sum(b)
add_s = sum(c[i1-1] for i1, i2 in zip(a, a[1:]) if i1 + 1 == i2)
print(sum_s + add_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
j = -1
for i in a:
    ans += b[i-1]
    if i == j+1:
        ans += c[j-1]
    j = i
print(ans)

Solution (Python):
N = int(input())
Ai = list(map(int, input().split()))
Bi = list(map(int, input().split()))
Ci = list(map(int, input().split()))

bonus = []
for i in range(N-1):
    if Ai[i + 1] - Ai[i] == 1:
        bonus.append(Ci[Ai[i]-1])

print(sum(Bi) + sum(bonus))

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

cnt = 0
temp = ""

for x in a_list:
    cnt += b_list[x-1]
    if temp == x -1:
        cnt += c_list[temp-1]
    temp = x
    
print(cnt)

Solution (Python):

import sys
import math
import numpy as np


args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False



N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))





if em: sys.stdin = open('/dev/tty')






score = 0
tmp_A = -2
for A in As:
  score = score + Bs[A - 1]
  if A == tmp_A + 1:
    score = score + Cs[tmp_A - 1]
  tmp_A = A

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

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

score = 0

for val in b_list :
	score +=val
	
for val in range(n-1):
	if a_list[val+1] - a_list[val] == 1:
		score += c_list[a_list[val]-1]
	else:
		pass

print(score)

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

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


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

ans = 0
pre = -1

for i in A:
  ans += B[i-1]
  if (i == pre + 1):
    ans += C[i-2]
  pre = 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()))
manzoku=0
for i in range(n):
    manzoku+=b[a[i]-1]
for i in range(n-1):
    if a[i+1]-a[i]==1:
        manzoku+=c[a[i]-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()))

def buffet(N,x,y,z):
  a = sum(y)
  for i in range(N-1):
    if x[i+1] - x[i] == 1:
      a = a + z[x[i]-1]
  print(a)

if __name__ == '__main__':
  buffet(N,A,B,C)

Solution (Python):
C = [0]
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]]

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 = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

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

ans = sum(blist)
for i in range(n-1):
    if alist[i + 1] - alist[i] == 1:
        ans += clist[alist[i]-1]
print(ans)

Solution (Python):
def func(N, A_i, B_i, C_i):
    stf = 0
    for i in range(N):
        stf += B_i[i]
        if i >= 1 and (A_i[i] == A_i[i-1] + 1):
            stf += C_i[A_i[i-1]-1]
    return stf

N = int(input())
A_i = list(map(int, input().split(" ")))
B_i = list(map(int, input().split(" ")))
C_i = list(map(int, input().split(" ")))
print(func(N, A_i, B_i, C_i))

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

result = int()

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

print(str(result))

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

pre = A[0]
for i in range(1,N):
    if A[i]==pre+1:
        sat+=C[A[i]-2]
    pre = A[i]
sat+=sum(B)
print(sat)

Solution (Python):



def solve():
    N = int(input())
    al = list(map(lambda x:int(x)-1, input().split()))
    bl = list(map(int, input().split()))
    cl = list(map(int, input().split()))
    ans = 0
    
    for i in range(N):
        if i != N - 1:
            if al[i] + 1 == al[i+1]:
                ans += cl[al[i]]
        ans += bl[al[i]]
    
    print(ans)


if __name__ == '__main__':
    solve()

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 a in A:
    ans += B[a - 1] 
    if a - prev_a == 1:
        ans += C[prev_a - 1]
    prev_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()))
ans=0
j=0
 
for i in range(N):
	ans+=B[A[i]-1]
	if A[i]-j==1 and i>=1:
		ans+=C[j-1]
	j=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()))

score = 0
prev = -1
for ai in a:
    score += b[ai - 1]
    if prev + 1 == ai:
        score += c[prev - 1]

    prev = ai

print(score)

Solution (Python):

N = int(input().strip())
A = input().strip().split()
A = [None] + [int(a) for a in A] 
B = input().strip().split()
B = [None] + [int(b) for b in B] 
C = input().strip().split()
C = [None] + [int(c) for c in C] 

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

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()))
co=0
for i in range(len(B)):
    co+=B[i]
for j in range(len(C)):
    if A[j+1]==A[j]+1:
        co+=C[A[j]-1]
print(co)

Solution (Python):

if __name__ == '__main__':

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

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

	gokei += sum(B)
	print(gokei)

Solution (Python):


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

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

print(pt)

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

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

print(s)

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

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=list(map(int,input().split()))
ans=sum(map(int,input().split()))
c=list(map(int,input().split()))
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 = [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):
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()))

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

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):
    a = A[i] - 1
    ans += B[a]
    aa = A[i - 1] - 1
    if a - 1 == aa:
        ans += C[aa]
        
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[A[i]-1]
    if i > 0:
        if A[i]-1 == A[i-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(' ')))

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

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

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

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

result = 0

for x in range(len(A) - 1):
	result += B[x]
	if A[x]+1 == A[x+1]:
		result += C[A[x]-1]
result += B[len(A)-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()))

cnt = 0
before = -100
for i in range(n):
    cnt += b[a[i] - 1]

    if before + 1 == a[i]:
        cnt += c[before-1]

    before = a[i]
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()))

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

Solution (Python):


import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq





def solve(f):
    n = f.read_int()
    a = f.read_int_list()
    b = f.read_int_list()
    c = f.read_int_list()

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


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case 
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

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

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

Solution (Python):
n = int(input())
aarr = list(map(int, input().split()))
barr = list(map(int, input().split()))
carr = list(map(int, input().split()))
sarr = []

for i in range(n):
    sarr.append(barr[aarr[i] - 1])

    if (i != n - 1) and (aarr[i] + 1 == aarr[i + 1]):
        sarr[len(sarr) - 1] += carr[aarr[i] - 1]

print(sum(sarr))

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 = -999
for i in a:
  i -= 1
  ans += b[i]
  if i == prev + 1:
    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()))

s = 0

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

print(s)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    n = II()
    print(n**3)
    return


def B():
    n = II()
    a = LI()
    b = LI()
    c = LI()
    ans = 0
    for i in range(n):
        ans += b[a[i] - 1] + (c[a[i] - 1] if i != n - 1 and a[i] + 1 == a[i + 1] else 0)
    print(ans)
    return


def C():
    n = II()
    b = LI()
    ans = b[0]
    for i in range(n-1):
        if b[i] >= b[i + 1]:
            ans += b[i + 1]
        else:
            ans += b[i]
    print(ans)
    return


def D():
    n, k = LI()
    s = S()
    a = []
    for i in range(n):
        if i == n - 1:
            a.append(s[i])
        elif s[i] != s[i + 1]:
            a.append(s[i])
    print(min(n - 1, n - len(a) + 2 * k))
    return


def E():
    return


def F():
    return



if __name__ == '__main__':
    B()

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

manzoku_do = 0
i = 0

manzoku_do = 0
i = 0

manzoku_do += int(b[int(a[i]) - 1])
i += 1

while i < n:
  manzoku_do += int(b[int(a[i]) - 1])
  
  if int(a[i - 1]) -1  == int(a[i])-1 - 1:
    manzoku_do += int(c[int(a[i -1]) -1 ])
  i += 1
    
    
print(manzoku_do)

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

"""
Created on Thu Sep 26 12:13:54 2019

@author: hiros
"""

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
"""
print(N)
print(A[0],A[1])
print(B[0],B[1])
print(C[0],C[1])


"""
c_dish = A[0]-1 
ans = B[c_dish] 
f_dish = c_dish 

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

    f_dish = c_dish
    

print(ans)

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


satis = 0

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

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(0,n-1):
    if int(A[i])+1 == int(A[i+1]):
        name=int(A[i])
        
        
      
        sat = sat + int(C[name-1])
        
    else:
      
      continue

print(sat)

Solution (Python):
N=int(input())
listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
listC=list(map(int,input().split()))
sumB=int(sum(listB))
for i in range(1,N):
    if listA[i] == listA[i-1]+1:
        sumB=sumB+int(listC[listA[i-1]-1])
print(sumB)

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

Solution (Python):
N = int(input())
aa = list(map(int, input().split()))
bb = map(int, input().split())
cc = list(map(int, input().split()))

s = sum(bb)
for i in range(N-1):
  if aa[i+1] - aa[i] == 1:
    s += cc[aa[i]-1]
print(s)

Solution (Python):
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

satisfaction = sum(B)

before_i = float("Inf")
for i in range(N - 1):
    if A[i] + 1 == A[i+1]:
        satisfaction += C[A[i] - 1]
        
print(satisfaction)

Solution (Python):

N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

satisfy = sum(B)
for i, a in enumerate(A):
    if i == 0:
        continue
    if a - A[i-1] == 1:
        satisfy += C[A[i-1] - 1]
print(satisfy)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
count = B[A[0]-1]
for i in range(1,N):
    count += B[A[i]-1]
    if A[i-1] == A[i] - 1:
        count += C[A[i-1]-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()))
a1=A[0]
a2=0
ans=B[a1-1]
for i in range(1,N):
  a2=A[i]
  ans+=B[a2-1]
  if a2==a1+1:
    ans+=C[a1-1]
    a1=a2
  else:
    a1=a2
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 i in range(n):
  count += b[a[i]-1]
  if i>=1 and a[i]-a[i-1] == 1:
    count += c[a[i-1]-1]
    
print(count)

Solution (Python):
N = int(input())
li_a =list(map(int, input().split()))
li_b =list(map(int, input().split()))
li_c =list(map(int, input().split()))

before = -99
points = 0
for i in li_a:
      points += li_b[i - 1]
      if before + 1 == i:
            points += li_c[i - 2]
      before = i
print(points)

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

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

min_sum = sum(B)
additionals = []

for i in range(1, len(A)):
    if A[i]-A[i-1] == 1:
        j = A[i-1]-1
        additionals.append(C[j])

sum_additionals = sum(additionals)

sum = min_sum + sum_additionals

print(sum)

Solution (Python):
def main():
    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 i in range(N - 1):
        a1 = lst_A[i]
        a2 = lst_A[i + 1]
        diff = a2 -a1

        if diff == 1:
            ret += lst_C[a1 - 1]
    
    return ret


if __name__ == "__main__":
    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()))
for i in range(N-1):
  if A[i]+1 == A[i+1]:
    B.append(C[A[i]-1])
print(sum(B))