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())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))
acc = 0
for j in range(N - 1):
    i = aaa[j] - 1
    acc += bbb[i]
    if aaa[j] + 1 == aaa[j + 1]:
        acc += ccc[i]
else:
    acc += bbb[aaa[-1] - 1]
print(acc)

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

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

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

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

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

    print(m)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    input = sys.stdin.readline
    
    
    

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

    sat = 0
    prev = None
    for i in range(N):
        A = As[i]
        sat += Bs[A-1]
        if prev is not None and prev + 1 == A:
            sat += Cs[prev - 1]
        prev = A

    print(sat)





if __name__ == '__main__':
    main()

Solution (Python):
def main() -> None:
    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()]
    ans = sum(B[a] for a in A)
    for a1, a2 in zip(A, A[1:]):
        if a1 + 1 == a2:
            ans += C[a1]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
lc = list(map(int,input().split()))

con = 0

for i in range(n-1):
    if la[i+1]==la[i]+1:
        con += lc[la[i]-1]

print(sum(lb)+con)

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

cnt=0
before=0

for i in range(n):
    cnt+=b[a[i]]
    if a[i]==before+1:
        cnt+=c[before]
    before=a[i]
print(cnt)

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

Solution (Python):
import sys
N = int(input())
array_a = list(map(int,input().split()))
array_b = list(map(int,input().split()))
array_c = list(map(int,input().split()))

if not ( 2 <= N <= 20 ):sys.exit()
if not ( 1 <= min(array_a) and max(array_a) <= N ): sys.exit()
if not ( 1 <= min(array_b) and max(array_b) <= 50 ): sys.exit()
if not ( 1 <= min(array_c) and max(array_c) <= 50 ): sys.exit()

confortable = 0
before = -1
for I in range(len(array_a)):
    pos = array_a[I]
    confortable += array_b[pos-1]
    if before + 1 == array_a[I]:
        confortable += array_c[before-1]
    before = array_a[I]
print(confortable)

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(len(a)):
  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):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
C = list(map(int,readline().split()))

ans = sum(B)
for i in range(N-1):
    for j in range(1,N):
        if A[i] == j and A[i+1] == j+1:
            ans += C[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 = sum(B)
memo = 20
for i in A:
    if memo+1 == i:
        total += C[i-2]
    memo = 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()))
sat = b[a[0]-1]
for i in range(1,len(a)):
    sat += b[a[i]-1]
    
    if a[i] - a[i-1] == 1:
        sat += c[a[i-1]-1]
        
print(sat)

Solution (Python):
n = int(input())
a_list = [0] + list(map(int, input().split()))
b_list = [0] + list(map(int, input().split()))
c_list = [0] + list(map(int, input().split()))

sum = sum(b_list)

for i in range(1, n):
    if a_list[i] + 1 == a_list[i+1]:
        sum += c_list[a_list[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()))

bef=a[0]-1
man=b[bef]

for i in a[1:]:
  ind=i-1
  if ind==bef+1:
    man+=c[bef]
  man+=b[ind]
  bef=ind
print(man)

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-2:
    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 = sum(b)

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

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


print(x)

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

score = B[A[0]-1]

for i in range(1,n):
    score += B[A[i]-1]
    if A[i] == A[i-1]+1:
        score += C[A[i-1]-1]
    else:
        continue
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()))
sat=0
for i in range(N):
  sat+=B[A[i]-1]
  if(i+1!=N and 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()))

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

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

m=0
y=-1
for x in A:
    m+=B[x-1]
    if x==y+1:
        m+=C[y-1]
    y=x
print(m)

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

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

for j in range(1,N):
    if A[j]==A[j-1]+1:
        ans+=C[A[j]-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 = 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(lambda x: int(x)-1,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans = 0
last = A[0]
ans += B[last]

for a in A[1:]:
  if last + 1 == a:
    ans += C[last]
  ans += B[a]
  last = 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 = B[A[0] - 1]
for i, a in enumerate(A[1:]):
    bef_a = A[i]
    ans += B[a - 1]
    if a - bef_a == 1:
        ans += C[bef_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()))

sat = 0

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

print(sat)

Solution (Python):
def resolve():
    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 prev == a-1:
            ans += C[a-2]
        prev = a
    print(ans)

if '__main__' == __name__:
    resolve()

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_list = [0] + list(map(int, input().split()))
b_list = [0] + list(map(int, input().split()))
c_list = [0] + list(map(int, input().split()))

sum = 0

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


print(sum)

Solution (Python):
def main():
    N = int(input())
    A = [i-1 for i in map(int, input().split())]
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    ans = 0
    for idx, a in enumerate(A):
        ans += B[a]
        if idx != 0 and A[idx-1] + 1 == A[idx]:
            ans += C[A[idx-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()))

sat = 0
ai_prev = None
for ai in a:
    sat += b[ai - 1]
    if ai_prev == ai - 1:
        sat += c[ai_prev - 1]
    ai_prev = ai
print(sat)

Solution (Python):
n = int(input())
an = [int(num) for num in input().split()]
bn = [int(num) for num in input().split()]
cn = [int(num) for num in input().split()]

sum = 0
for a in an:
  sum += bn[a-1]

add = []
for i in range(n-1):
  if an[i]+1 == an[i+1] :
    add.append(an[i])

for j in add:
  sum += cn[j-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()))
ful=0
for i in range(n):
  tempa=A[i]-1
  ful+=B[tempa]
  if A[i]-A[i-1]==1 and i>0:
    tempb=A[i-1]-1
    ful+=C[tempb]
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()))

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

print(ans)

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


a = [int(i) for i in input().split()]
iSSequence = [False] * (len(a) - 1)


for i in range(len(a) - 1):
    if(a[i] + 1 == a[i + 1]):
        iSSequence[a[i] - 1] = True

sum = 0

for b in input().split():
    sum += int(b)

index = 0
for c in input().split():
    if(iSSequence[index]):
        sum += int(c)
    index += 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()))
ans = sum(b)
for i in range(len(c)):
    try:
        if a[a.index(i+1)+1] == i+2:
            ans += c[i]
    except IndexError:
        pass
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):
  s+=b[a[i]-1]
  if a[i-1]==a[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()))
ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i == n - 1:
        break
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i] - 1]

print(ans)

Solution (Python):
from sys import stdin,stdout

if __name__=="__main__":

    n=int(stdin.readline());

    a=[int(x) for x in stdin.readline().split()]
    b=[int(x) for x in stdin.readline().split()]
    c=[int(x) for x in stdin.readline().split()]

    sm=sum(b)

    for i in range(1,n):
        if a[i]-1==a[i-1]:
            sm+=c[a[i-1]-1]
    stdout.write(str(sm)+"\n")

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) 


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

print(b_sum)

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]+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()))+[0]
ans=0
bn,ba=0,0
for i in a:
    ans+=b[i-1]
    if bn+1==i:
        ans+=ba
    bn=i
    ba=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()))
r = 0
p = N
for a in A:
  r += B[a - 1]
  if p == a - 1:
    r += C[p - 1]
  p = a
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 = 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()))
t = 0
t += b[a[0]-1]
for i in range(1,n):
    t += b[a[i]-1]
    if a[i] - a[i-1] == 1:
        t += c[a[i-1]-1]
print(t)

Solution (Python):


import io
import sys
import math

def solve(n, a_lst,b_lst,c_lst):
    
    pre_a = -float('inf')
    satisfaction = 0
    for a in a_lst:
        a -= 1
        satisfaction += b_lst[a]
        if pre_a +1 == a:
            satisfaction += c_lst[a-1]
        pre_a = a
    
    return satisfaction
    
def main():
    
    n = int(input())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    c_lst = list(map(int, input().split()))

    
    ans = str( solve(n, a_lst,b_lst,c_lst ) )
    
    
    print(ans)
    return ans
        

_DEB = 0   

_INPUT = """\
2
1 2
50 50
50
"""
_EXPECTED = """\
150
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")


if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

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 A:
    ans += B[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())
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()))

m = 0
for i in range(N):
    if A[i-1] == A[i]-1 and i != 0:
        m += B[A[i]-1] + C[A[i-1]-1]
    else:
        m += B[A[i]-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 = 0
for i in A:
    ans += B[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())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
cc=list(map(int,input().split()))

ans=0
for i in range(n):
  ans+=bb[aa[i]-1]
  if i>0 and (aa[i]-1)==aa[i-1]:
    ans+=cc[aa[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()))
satisfaction = 0
last_dish = 10000

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

print(satisfaction)

Solution (Python):
import sys
input=sys.stdin.buffer.readline
from math import*

n=int(input())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))
crr=list(map(int,input().split()))

ans=0
for i in range(n):
	if i!=0 and arr[i]==arr[i-1]+1:
			ans+=brr[arr[i]-1]+crr[arr[i-1]-1]
	else:
		ans+=brr[arr[i]-1]
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)





def input():
    return sys.stdin.readline().rstrip()


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

Solution (Python):
N = int(input())
buffet = [int(i) for i in input().split()]
satisfaction_level_B = [int(i) for i in input().split()]
satisfaction_level_C = [int(i) for i in input().split()]
result = 0

for i in range(N):
    result += satisfaction_level_B[buffet[i] - 1]
    if i > 0:
        if buffet[i] - buffet[i - 1] == 1:
            result += satisfaction_level_C[buffet[i - 1] - 1]
print(result)

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

i=0
man=0
oldA=1
for A in a:
  
  B = b[int(A)-1]
  
  man = man + int(B)
  if i>0:
    if oldA+1==A:
      C = int(c[oldA-1])
      man = man + C
      
  i=i+1
  oldA=A
print(man)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
last_dish = 0
a = 0
b = 0
c= 0
manzoku = 0
for i in range(N):
  a = A[i]
  manzoku += B[i]
  if last_dish != 0 and last_dish + 1 == A[i]:
    manzoku += C[last_dish - 1]
  last_dish = A[i]
print(manzoku)

Solution (Python):
N = int(input())
A_int_list = list(map(int, input().split()))
B_int_list = list(map(int, input().split()))
C_int_list = list(map(int, input().split()))

ans = 0

for i in range(N):
    ans += B_int_list[A_int_list[i] - 1]
    if i != N - 1 and A_int_list[i] + 1 == A_int_list[i + 1]:
        ans += C_int_list[A_int_list[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=ans+c[a[i]-1]
print(ans)

Solution (Python):
N = int(input())
buffet = [int(i) for i in input().split()]
satisfaction_level_B = [int(i) for i in input().split()]
satisfaction_level_C = [int(i) for i in input().split()]
count = []
result = 0

for i in buffet:
    count.append(i)
    result += satisfaction_level_B[i - 1]
    if len(count) >= 2:
        if count[-1] - count[-2] == 1:
            result += satisfaction_level_C[i - 2]
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()))
print(sum(B)+sum(C[A[n]-1] for n in range(N-1) if A[n]+1==A[n+1]))

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 n in range(1,N):
  if A[n]!=1+A[n-1]:
    ans+=B[A[n]-1]
  else:
    ans+=B[A[n]-1]+C[A[n]-2]

print(ans)

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
a = intl()
b = intl()
c = intl()

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

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

Solution (Python):

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

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

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 = 0
for i in range(n):
    s += b[i]

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

ans = 0
for i in range(N):
  a = A[i]
  ans += B[a-1]
  if (i!=N-1) and (A[i]+1==A[i+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
before = -100
for i in a:
    i -= 1
    if i == before + 1:
        ans += c[before]
    before = i
    ans += b[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):
    num = a[i]
    res += b[num - 1]
for i in range(n-1):
    if a[i] +1== a[i+1] :
        num = a[i]
        res += c[num-1]
print(res)

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] + list(map(int , input().split()))
    c = [0] + list(map(int , input().split()))
    ans = 0
    for i in range(n):
        ans += b[a[i]]
        if i > 0 and a[i-1] == a[i] - 1:
            ans += c[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
 
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):
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)
for T in range(0,N-1):
    if A[T+1]-A[T]==1:
        Total += C[A[T]-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()))
fill = 0
cnt = 0
for f in range(n):
    fill = fill + b[a[f] - 1]
    if(f != 0 and a[f] == a[f-1] + 1):
        fill = fill + c[a[f-1]-1]
        cnt = cnt + 1
    else:
        cnt = cnt + 1
print(fill)

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

print(manzoku)

Solution (Python):
n = int(input())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
c_l = list(map(int,input().split()))

ans = 0
before = None
for i in a_l:
    ans += b_l[i-1]
    if before == i-1:
        ans += c_l[before-1]
    before = 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()))
stf = 0

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

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):
    if(A[i-1]+1==A[i]):
        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 = 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 != 0 and A[i]-A[i-1] == 1:
    total += C[A[i-1]-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 (n-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()))
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 main():
    n = int(input())
    alis = list(map(int, input().split()))
    blis = list(map(int, input().split()))
    clis = list(map(int, input().split()))
    ans = 0
    tmp = ""
    for a in alis:
        ans += blis[a-1]
        if tmp == a-1:
            ans += clis[a-2]
        tmp = a
    print(ans)
    
    
if __name__ == "__main__":
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, 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)
    return


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

Solution (Python):
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))

ans=sum(lb)
lt=[]
for i in range(len(la)-1):
  if la[i]+1==la[i+1]:
    lt.append(la[i])

for j in lt:
  ans+=lc[j-1]

print(ans)

Solution (Python):
num = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
z = list(map(int,input().split()))
val = 0
 
for i in range(num):
    val += y[x[i]-1]
    if 1<=i and x[i]-x[i-1] == 1:
        val += z[x[i]-2]
 
print(val)