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())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))
cn = list(map(int,input().split()))
st = sum(bn)
for i in range(0, n-1):
    if an[i] == an[i+1] - 1:
        st += cn[an[i]-1]
print(st)

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

Solution (Python):
N = int(input())
dishs = list(map(int, input().split()))
points = list(map(int, input().split()))
add_points = list(map(int, input().split()))

res = 0
for i in range(0,len(dishs)-1):
    res += points[dishs[i]-1]
    if dishs[i]+1 == dishs[i+1]:
        res += add_points[dishs[i]-1]
res += points[dishs[len(dishs)-1]-1]
print(res)

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

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

Solution (Python):



N = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

sum_bn = sum(bn)
sum_cn = 0

for i in range(N-1):
    if an[i] + 1 == an[i+1]:
        sum_cn += cn[an[i]-1]

print(sum_bn + sum_cn)

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

v = 0

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

print(v)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=sum(arr2)
arr3=list(map(int,input().split()))
arr3=[0]+arr3
for i in range(1,n):
	if(arr[i]==arr[i-1]+1):
		ans+=arr3[arr[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()))

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

Solution (Python):
N = int(input())
A = [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):

import numpy as np


def main():
    n = int(input())
    a = np.array(input().split(), dtype='int')
    b = np.array(input().split(), dtype='int')
    c = np.array(input().split(), dtype='int')

    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)


main()

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
former = -2
for i in range(n):
  total += B[A[i]-1]
  if i != 0:
    if 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 = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

out = 0
out += sum(B_list)
a_prev = 0

for index, a in enumerate(A_list):
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        out += C_list[a-2]
    a_prev = a
    
print(out)

Solution (Python):
n = int(input())
dish = list(map(int, input().split()))
koyo = list(map(int, input().split()))
tsuika = list(map(int, input().split()))

ans = 0
bdish = -1

for i in dish:
  ans += koyo[i-1]
  if bdish+1 == i:
    ans += tsuika[bdish-1]
  bdish = 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()))
a.append(10000)
cnt=0
for i in range (n):
    cnt+=b[a[i]-1]
    if a[i]+1==a[i+1]:
        cnt+=c[a[i]-1]
print(cnt)

Solution (Python):
n = int(input())
arrs = [list(map(int,input().split())) for i in range(3)]

score = 0

for i in range(n):
    score += arrs[1][arrs[0][i]-1]
    if i != 0 :
        if arrs[0][i-1]+1 == arrs[0][i]:
            score += arrs[2][arrs[0][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()))
sum = 0
before = 99999
for i in range(n):
    sum += b[a[i]-1]
    if before == a[i] - 1:
        sum += c[a[i-1]-1]
    before = a[i]
print(sum)

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



result= B_list[A_list[0] - 1]
for i in range(1,N):
    
    result += B_list[A_list[i] -1]
    if A_list[i] -1 == A_list[i-1] :
        result += C_list[A_list[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()))
score = 0

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

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

listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
listC=list(map(int,input().split()))

ans=0
for i in range(N):
	ans+=listB[i]
	if i==N-1:
		break
	if listA[i]+1==listA[i+1]:
		ans+=listC[listA[i]-1]

print(ans)

Solution (Python):
n = int(input())
dish = list(map(lambda x: int(x), input().split()))
utility = list(map(lambda x: int(x), input().split()))
bonus = list(map(lambda x: int(x), input().split()))

pre_dish = -1
ans = 0
for i in range(n):
    ans += utility[dish[i] - 1]
    if pre_dish == dish[i] - 1:
        ans += bonus[pre_dish - 1]
    pre_dish = dish[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[A[0]-1]
tmp = A[0]
for i in range(1, N):
    ans+=B[A[i]-1]
    if A[i]==tmp+1:
        ans+=C[tmp-1]
    tmp = A[i]
    
print(ans)

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))
    CS = list(map(int, input().split()))

    ans = 0
    prev = -2
    for a in AS:
        plus = BS[a-1]
        if 1 < a and prev == a-1-1:
            plus += CS[a-2]
        ans += plus
        prev = a-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
prev = 0
for i in range(N):
    now = A[i] - 1
    ans += B[now]
    if i != 0 and prev == now - 1:
        ans += C[prev]
    prev = now


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

satis = 0
idAprev = 0
for idA in A:  
  satis += B[idA - 1]
  if idAprev != 0 and (idA - idAprev) == 1:
    satis += C[idAprev - 1]
    
  idAprev = idA

print(satis)

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 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()))
l = []
cnt = 0
i = 0
for a in A:
  l.append((a,B[a-1]))
  i += 1
j = A[0]
for i in range(len(l)):
  cnt += l[i][1]
  a = l[i][0]-1
  if l[i][0] == j+1:
    cnt += C[a-1]
  j = l[i][0]
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()))
D = []
Sum = sum(B)
for i in range(n-1):
	if A[i+1] == A[i] + 1:
		p = A[i] - 1
		D.append(C[p])
Add = sum(D)
print(Sum+Add)

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

cnt = 0
pre = -1
for a in As:
  cnt += Bs[a-1]
  if pre == a - 1:
    cnt += Cs[pre-1]
  pre = a
  
print(cnt)

Solution (Python):
R = lambda:list(map(int,input().split()))
input()
a, b, c = R(), R(), R()
print(sum(b) + sum(c[i - 1] for i, j in zip(a, a[1:]) if j == i + 1))

Solution (Python):
n=int(input())
order=list(map(int,input().rstrip().split()))
num=sum(list(map(int,input().rstrip().split())))
opt=list(map(int,input().rstrip().split()))
for i in range(n-1):
  if order[i]==order[i+1]-1:
    num+=opt[order[i]-1]
print(num)

Solution (Python):




n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.append(-999)


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

ans = sum

print(ans)

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

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

Solution (Python):
N = int(input())
tmp = input()
A = [int(x.strip()) for x in tmp.split(' ')]
tmp = input()
B = [int(x.strip()) for x in tmp.split(' ')]
tmp = input()
C = [int(x.strip()) for x in tmp.split(' ')]
tmpsum = sum(B)
for i in range(0, N-1):
    if A[i]+1 == A[i+1]:
        tmpsum += C[A[i]-1]
print(tmpsum)

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

beforeNumber = 0
manzoku = 0
for i in a:
    if beforeNumber != 0 and beforeNumber + 1 == i:
        manzoku = manzoku + b[i-1] + c[beforeNumber-1]
    else:
        manzoku += b[i-1]
    beforeNumber = i
print(manzoku)

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

Solution (Python):


def main(N,A,B,C):
    ans = 0
    olda = float("INF")
    for a in A:
        if a - olda == 1:
            ans += C[olda]
        olda = a
    print(ans+sum(B))
        

if __name__ == '__main__':
    N = int(input())
    A = [int(a)-1 for a in input().split()]
    B = [int(a) for a in input().split()]
    C = [int(a) for a in input().split()]
    main(N,A,B,C)

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):
    a[i] -= 1

s = b[a[0]]
prev = a[0]
for i in range(1, n):
    s += b[a[i]]
    if prev + 1 == a[i]:
        s += c[prev]
    prev = a[i]
print(s)

Solution (Python):
import numpy as np

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

score=0
tmp=-1
for i in A:
    score+=B[i-1]
    if i==tmp+1:
        score+=C[tmp-1]
    tmp=i
print(score)

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

ans = 0
e = -1
for a in la:
  ans += lb[a - 1]
  if e == a - 1:
    ans += lc[e - 1]
  e = a
 
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()]
total = 0

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

satisfaction = 0

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

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

manzokudo = sum(B)
i1 = 0
i2 = 0
for idx, i in enumerate(A):
  if idx == 0:
    i1 = i
  else:
    i2 = i1
    i1 = i
    if i1 - i2 == 1:
      manzokudo += C[i2 - 1]
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()))
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]-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 = 0
prev_i = -1

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

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

ans = 0
tmp = 0
for i in a:
	ans += b[i-1]
	if i == tmp+1 and tmp != 0:
		ans += c[tmp-1]
	tmp = 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

for i,a in enumerate(A):
  ans += B[a-1]
  
  if i:
    
    if A[i-1] + 1 == a:
      ans += C[a-2]
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()]
count = 0
for i in range(n):
    A = a[i]-1
    count += b[A]
    try:
        if a[i]+1==a[i+1]:
            count += c[A]
    except:
        continue
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()))

answer = 0
previous_index = n + 1

for number in a:
    answer += b[number - 1]

    if number == previous_index + 1:
        answer += c[previous_index - 1]

    previous_index = number

print(answer)

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

ans=B[A[0]-1]

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

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

Solution (Python):
num = int(input())
list1 = []
result = 0
prev = -2
for i in range(3):
    list1.append(list(map(int, input().split())))

a = list1[0]
b = list1[1]
c = list1[2]

for i in range(num):
    result += b[a[i]-1]
    if prev + 1 == a[i]:
        result += c[a[i-1]-1]
    prev = a[i]

print(result)

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

res = 0

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

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

happiness=0
prev=-2
for i in range(N):
    now=A[i]-1
    happiness+=B[now]
    if prev==now-1:
        happiness+=C[now-1]
    prev=now
    
print(happiness)

Solution (Python):
n=int(input())
li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))
li3 = list(map(int,input().split()))

sum = 0
last_num = 0
for i in range(n):
  sum += li2[li1[i]-1]
  now = li1[i]
  if last_num != 0:
    if now - last_num == 1:
      sum+=li3[li1[i-1]-1]
  last_num = li1[i]
print(sum)

Solution (Python):
while True:
    try:
        N = int(input())
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
        C = list(map(int, input().split()))
        result = 0
        prev = None
        for i in A:
            result += B[i-1]
            if prev is not None and i == prev + 1:
                result += C[prev-1]
            prev = i
        print(result)
    except EOFError:
        break

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

import numpy as np

ans = np.sum(B)

D = np.zeros(N-1)

for i in range(N-1):
  D[i] = A[i+1] - A[i]
  
for i in range(N-1):
  if D[i] == 1:
    x = A[i] - 1
    ans += C[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()))
m=0
for i in range(n-1):
    if a[i+1]-a[i]==1:
        ai=a[i]-1
        m+=c[ai]

s=sum(b)
print(s+m)

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

Solution (Python):
numDishes = int(input())
order = input()
sat1 = input()
sat2 = input()
satisfaction = 0
prev = -20

orderList = []
orderList = order.split(" ")
sat1List = []
sat1List = sat1.split(" ")
sat2List = []
sat2List = sat2.split(" ")

if (len(orderList) == numDishes) and (len(sat1List) == numDishes) and (len(sat2List) == numDishes-1):
    for i in orderList:
        num = int(i)
        if prev + 1 == num:
            satisfaction = satisfaction + int(sat1List[num - 1])
            satisfaction = satisfaction + int(sat2List[prev - 1])
        else:
            satisfaction = satisfaction + int(sat1List[num - 1]) 
        prev = num

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

Sat = sum(B) 

for idx, a in enumerate(A):
  if idx == N-1:
    break
  if ((a+1) == A[idx+1]):
    Sat = Sat+C[a-1]

print(Sat)

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()))
count = 0
for i in range(n):
    index=a_list[i]
    count += b_list[index - 1]

    if i !=0:
        if a_list[i] == a_list[i-1] + 1:
            count += c_list[a_list[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()))

ans = 0
count = len(C)
for i, j in enumerate(A):
  ans += B[j - 1]
  if i < count and A[i] + 1 == A[i+1]: 
    ans += C[j - 1]
print(ans)

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

meals = list(map(int, input().split()))
likes = list(map(int, input().split()))
addLikes = list(map(int, input().split()))

total_like = 0

for i in range(n):
  meal = meals[i]
  like = likes[meal-1]
  if i < n-1 and meal == meals[i+1]-1:
    like += addLikes[meal-1]
  total_like += like
    
print(total_like)

Solution (Python):
import sys

stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  
ns()
ar = na()
ans = sum(na())
cr = na()
prev = -1
for i in range(len(ar)):
    if prev+1 == ar[i]:
        ans += cr[prev-1]
    prev = ar[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()))

result = 0
for ai, i in enumerate(a):
    result += b[i - 1]
    if ai > 0 and i - a[ai - 1] == 1:
        result += c[a[ai - 1] - 1]
print(result)

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

A = [int(s) for s in A]
B = [int(s) for s in B]
C = [int(s) for s in C]

manzoku = 0
pre_a = 100

for a in A:
    manzoku += B[a-1]
    if(pre_a == a-1):
        manzoku += C[a-2]
    pre_a = a

print(manzoku)

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

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

h = 0
for i in b:
    h += i


for i in range(n-1):
    if(a[i]==a[i+1]-1):
        h += c[a[i]-1]
    else:
        pass

print(h)

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

cnt = sum(B)

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

Solution (Python):
N = int(input())
A_array = [int(i) for i in input().split()]
B_array = [int(i) for i in input().split()]
C_array = [int(i) for i in input().split()]

counter = 0
for i, e in enumerate(B_array):
    counter += e

for i in range(N-1):
    menu_i = A_array[i]
    menu_iplus1 = A_array[i+1]
    if menu_iplus1 == menu_i + 1:
        counter += C_array[menu_i-1]

print(counter)

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

print(m)

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

total = 0
for i, Ai in enumerate(A):
  total += B[Ai]
  if i >= 1:
    if A[i] == A[i-1]+1:
      total += C[Ai-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(" ")))
point = 0
last_index = -1
for a in A:
    point += B[a - 1]
    if last_index == a - 1:
        point += C[a-2]
    last_index = a

print(point)

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

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
Cnum = 0
cur_a = 100
for a in aa:
    ans += bb[a-1]
    if a == cur_a+1:
        ans += cc[cur_a-1]
        Cnum += 1
    cur_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()))
count=0
for i in range(n-1):
    count+=b[a[i]-1]
    if a[i+1]-1==a[i]:
        count+=c[a[i]-1]
print(count+b[a[-1]-1])

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

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

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

s = 0
for i in range(N):
    s += B[A[i]-1]
    try:
        if A[i]+1 == A[i+1]:
            s += C[A[i]-1]
    except:
        pass

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

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

print(satisf)

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

total_value = 0
last_index = -2

for i in range(n):
  index = a_list[i] - 1
  total_value += b_list[index]
  
  if last_index + 1 == index:
    total_value += c_list[last_index]
  
  last_index = index
  
print(total_value)

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

last = -99
for i in range(0, n):
    now = a[i]

    sum += b[now - 1]

    if last + 1 == now:
        sum += c[last - 1]
    last = now

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

Solution (Python):
import numpy as np

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]
    
A_ = [-100] + A[:-1]
A_ = np.array(A_)
A = np.array(A)

A_diff = A - A_

for j in A[A_diff == 1] -1:
    ans += C[j-1]
print(ans)

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 = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

Solution (Python):
n = int(input())
a = input().split()
b = input().split()
c = input().split()
a = [int(i) for i in a] 
b = [int(i) for i in b] 
c = [int(i) for i in c] 

sut = 0
for i,ind in enumerate(a):
    sut += b[ind-1]
    if i>=1:
        if a[i-1]+1 == a[i]:
            sut += c[a[i]-2]
print(sut)

Solution (Python):


n = int(input())

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

old_a = -1
ans = 0

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

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

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 ii in range(N-1):
    if A[ii]-A[ii+1] ==	-1:
        total += C[A[ii]-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()))
point=sum(b)

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

exit(0)