Problem:
 Score : 200 points    Problem Statement Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1 , Dish 2 , \ldots , Dish N ) once.  The i -th dish (1 \leq i \leq N) he ate was Dish A_i .  When he eats Dish i  (1 \leq i \leq N) , he gains B_i satisfaction points.  Additionally, when he eats Dish i+1 just after eating Dish i  (1 \leq i \leq N - 1) , he gains C_i more satisfaction points.  Find the sum of the satisfaction points he gained.      Constraints  All values in input are integers.  2 \leq N \leq 20  1 \leq A_i \leq N  A_1, A_2, ..., A_N are all different.  1 \leq B_i \leq 50  1 \leq C_i \leq 50         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N  B_1  B_2  ...  B_N  C_1  C_2  ...  C_{N-1}       Output Print the sum of the satisfaction points Takahashi gained, as an integer.        Sample Input 1 3
3 1 2
2 5 4
3 6      Sample Output 1 14  Takahashi gained 14 satisfaction points in total, as follows:   First, he ate Dish 3 and gained 4 satisfaction points.  Next, he ate Dish 1 and gained 2 satisfaction points.  Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.        Sample Input 2 4
2 3 4 1
13 5 8 24
45 9 15      Sample Output 2 74       Sample Input 3 2
1 2
50 50
50      Sample Output 3 150

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

m = 0

mae = -1
for a in A:
  m += B[a - 1]
  if a - mae == 1:
    m += C[mae - 1]
  mae = a

print(m)

Solution (Python):
n = int(input())
a = input().split()
b = input().split()
c = input().split()
count = 0
k = -100
for x in a:
  num = int(x)
  count += int(b[num-1])
  if k+1 == num:
    count += int(c[num-2])
  k = num
print(count)

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 


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, len(a)):
    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())
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):
    ans+=b[i]
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()))
M=list(map(int,input().split()))
L=list(map(int,input().split())) ; ans=0
for i in range(n):
    ans+=M[A[i]-1]
    if i!=n-1:
        if A[i]+1==A[i+1]:
            ans+=L[A[i]-1]
print(ans)

Solution (Python):
import sys
n = int(sys.stdin.readline())
lia = list(map(int, sys.stdin.readline().split()))
lib = list(map(int, sys.stdin.readline().split()))
lic = list(map(int, sys.stdin.readline().split()))
s = sum(lib)
li = []
i = 0
while i < n-1:
  if lia[i+1] - lia[i] == 1:
    li.append(lia[i]-1)
  i += 1
for i in li:
  s += lic[i]
print(s)

Solution (Python):

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

s = 0

sb = sum(B)

sc = 0

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

s = sb + sc

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()))
s = 0
sb = sum(B)
sc = 0
for i in range(N-1):
  if A[i+1] == A[i] + 1:
    sc += C[A[i]-1]
s = sb + sc
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)
x=-1
for i in a:
    if x+1==i:
        ans+=c[x-1]
    x = 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 = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

d = dict(zip(A, B))
ans = d[A[0]]

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

print(ans)

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

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

manzoku = 0
i_b = 100
for i in a:
    manzoku+=b[i-1]
    if i-1 == i_b:
        manzoku+=c[i-2]
    i_b = i

        
print(manzoku)

Solution (Python):

n = int(input())

get_line = lambda: [int(x) for x in input().split()]

A = get_line()

b = sum(map(int, input().split()))

C = get_line()

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

print(b)

Solution (Python):
N = int(input())
eat_list = list(map(int, input().split()))
manzok_list = list(map(int, input().split()))
add_manzok_list = list(map(int, input().split()))

manzok = 0

for i in range(N):
 manzok += manzok_list[eat_list[i]-1]
 if(i > 0 and (eat_list[i] - eat_list[i-1]) == 1):
   manzok += add_manzok_list[eat_list[i-1]-1]

print(manzok)

Solution (Python):


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

sm = sum(b)
cnt = 0

for i in range(1, N):
    if a[i-1]+1 == a[i]:
        aidx = a[i]-1
        cnt += c[aidx-1]
print(sm+cnt)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def main():
    N, *ABC = map(int, read().split())
    A = ABC[:N]
    B = ABC[N:2*N]
    C = ABC[2*N:]
    ans = sum(B)
    for i in range(N-1):
        if A[i] == A[i+1] - 1:
            ans += C[A[i]-1]
    print(ans)
    return

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
totalSatis = 0
lastItem = 0
for i in As:
    totalSatis += Bs[i-1]
    if lastItem == i-1 and lastItem != 0:
        totalSatis += Cs[lastItem-1]
    lastItem = i
print(totalSatis)

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

print(sum(b)+m)

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

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

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

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

for i in range(len(A)-1):
    if A[i]+1==A[i+1]:
        l.append(C[A[i]-1])

total=sum(B)+sum(l)
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()))
total_b = sum(b)
t_c=0
for i in range(1,n):
    if a[i-1]+1==a[i]:
        t_c+=c[a[i-1]-1]

print(total_b+t_c)

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

Solution (Python):
import sys
from io import StringIO
import unittest

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

    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)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
3 1 2
2 5 4
3 6"""
        output = """14"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
2 3 4 1
13 5 8 24
45 9 15"""
        output = """74"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2
1 2
50 50
50"""
        output = """150"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

Solution (Python):

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())) )
B = np.array(list(map(int, input().split())) )
C = np.array(list(map(int, input().split())) )


manzoku =sum(B)
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 = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
c_list = [int(x) for x in input().split()]

ans = 0
a_old = a_list[0] - 1
for i in range(n):
    a = a_list[i] - 1
    ans += b_list[a]
    if a - a_old == 1:
        ans += c_list[a_old]
    a_old = 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
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=sum(B)
cnt=0
for i in range(1,N):
  if A[i-1]+1==A[i]:
    s=A[i]-1
    cnt=C[s-1]+cnt

print(sum+cnt)

Solution (Python):

N = int(input())
A = [int(s) - 1 for s in input().split()]
B, C = [[int(s) for s in input().split()] for _ in range(2)]

s = B[A[0]]

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

print(s)

Solution (Python):

import sys
import numpy as np


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    prev = -1
    ans = 0
    for i in range(N):
        ans += B[A[i]-1]
        if A[i]==prev+1:
            ans+=C[prev-1]
        prev=A[i]
    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    B = [int(next(tokens)) for _ in range(N)]  
    C = [int(next(tokens)) for _ in range(N - 1)]  
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Solution (Python):
import os

def main():
	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_num = sum(b_list)

	for i,v in enumerate(a_list):
		count = v
		if i == (len(a_list)-1):
			break
		if (count+1) == a_list[i+1]:
			result_num += c_list[count-1]
	print(result_num)		

	
if __name__ == "__main__":
	main()

Solution (Python):
n = input()
line1 = input()
line2 = input()
line3 = input()

a_list = line1.split(" ")
a_list = [int(a) for a in a_list]
b_list = line2.split(" ")
b_list = [int(b) for b in b_list]
c_list = line3.split(" ")
c_list = [int(c) for c in c_list]

temp = a_list[0]
ans = 0
for a in a_list:
    if a == temp + 1:
        ans = ans + b_list[a-1] + c_list[temp-1]
    else:
        ans = ans + b_list[a-1]
    temp = 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
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()))

ans = 0

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

count=0
for i in range(0,len(A)-1):
  if A[i]+1==A[i+1]:
    count=count+C[A[i]-1]
    
print(sum(B)+count)

Solution (Python):
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))
score = bb[aa[0]-1]
for i in range(1,n):
    score += bb[aa[i]-1]
    if aa[i] == aa[i-1] +1:
        score += cc[aa[i-1]-1]
print(score)

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

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

Solution (Python):
import itertools
import math
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):
    ind = a[i] - 1
    ind_next = a[i+1] - 1
    if ind + 1 == ind_next:
        ans += c[ind]
print(ans)
"""
for i in range(len(a)):
    
    sum+=int(b[int(a[i])-1])

    if a[i]==int(a[i-1])+1:
        sum+=int(c[int(a[i])-1])
        
print(sum)

"""

Solution (Python):
N=int(input())
A=[int(x) for x in input().rstrip().split()]
B=[int(x) for x in input().rstrip().split()]
C=[int(x) for x in input().rstrip().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 = input()

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

sum = 0
befcuis = 0
cuis = 0

for x in A:
    sum += B[x-1]
    cuis=x
    if  befcuis == cuis- 1:
        if befcuis -1 >=0:
            sum+=C[befcuis-1]
    
    befcuis = cuis
    
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
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):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


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

total = 0
tmp_num = -1

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

    if tmp_num + 1 == num:
        total += C[tmp_num-1]
    tmp_num = num

print(total)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

sf=0

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

  if i!=0:
    if a[i]==(a[i-1]+1):
      sf+=c[a[i-1]-1]

print(sf)

Solution (Python):
def main():
    N = int(input())
    Ai = [int(a) for a in input().split()]
    Bi = [int(a) for a in input().split()]
    Ci = [int(a) for a in input().split()]
    s = 0
    for i in range(N):
        menu = Ai[i] - 1
        s += Bi[menu - 1]
        if i > 0 :
            if Ai[i] - Ai[i-1] == 1:
                s += Ci[Ai[i-1]-1]
    print(s)
main()

Solution (Python):
N = int(input())
A = [_ for _ in map(int,input().split())]
B = [_ for _ in map(int,input().split())]
C = [_ for _ in map(int,input().split())]
Happy = 0
temp = -10**9
for i in range(N):
  Happy += B[A[i]-1]
  if A[i]-1 == (temp+1):
    Happy += C[temp]
  temp = A[i] - 1
print(Happy)

Solution (Python):
L = [int(input()), list(map(int, input().split(' '))), list(map(int, input().split(' '))), list(map(int, input().split(' ')))]
print(sum([L[2][L[1][i]-1]+L[3][L[1][i]-2] if i>0 and L[1][i]-L[1][i-1]==1 else L[2][L[1][i]-1] for i in range(L[0])]))

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

Solution (Python):
N = int(input())
dish = list(map(int,input().split()))
sat =  list(map(int,input().split()))
cons = list(map(int,input().split()))
add = 0
past = -2
for i in range(len(dish)):
	curr = dish[i]
	if curr==past+1 and curr-2>=0:
		add+= (sat[curr-1]+cons[curr-2])
	else:
		add += sat[curr-1]
	past = curr
print(add)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


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)
  
  
if __name__ == '__main__':
  main()

Solution (Python):
def main():
    n = int(input())
    a_l = list(map(int, input().split()))
    b_l = list(map(int, input().split()))
    c_l = list(map(int, input().split()))
    res = 0
    pre = 0
    for a in a_l:
        res += b_l[a-1]
        if (a - pre == 1) and (a != 1):
            res += c_l[a-2]
        pre = a
    print(res)

if __name__ == "__main__":
    main()

Solution (Python):


import sys


















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi_0()
    b = lmi()
    c = lmi()
    ans = b[a[0]]
    for i in range(1, n):
        ans += b[a[i]]
        if a[i-1] + 1 == a[i]:
            ans += c[a[i-1]]
    print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
total = sum(b)
for i in range(1,n):
    if a[i] == a[i-1] + 1:
        total += c[a[i]-2]
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=sum(B)

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

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

for i, n in enumerate(A):
    count += B[n-1]
    if i != len(A) - 1 and A[i+1] == n + 1:
        count += C[n - 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
before = -1
for i in range(n):
	ans += b[a[i]-1]
	if a[i] == before+1:
		ans += c[before-1]
	before = a[i]

print(ans)

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

sm = 0

for x in a:
    if x != a[0]:
        if x == num + 1:
            sm += c[num-1]
    sm += b[x-1]

    num = x

print(sm)

Solution (Python):
"""
B-Buffet
"""

import sys
input = sys.stdin.readline
from itertools import *
from collections import *

INF = float('inf')


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

    total = 0
    pre_a = - INF
    for a in A:
        a -= 1
        total += B[a]

        if pre_a + 1 == a:
            total += C[pre_a]
        pre_a = a

    print(total)


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[i]

for j in range(N):
    if j >= 1:
        if A[j] == A[j - 1] + 1:
            tmp = A[j] - 2
            ans += C[tmp]

print(ans)

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

print(ful)

Solution (Python):
n=int(input())
def lima():
    return list(map(int,input().split()))

a=lima()
b=lima()
c=lima()

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

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

for i in range(N):
    t=A[i]
    s+=B[t-1]
    if i==0:
        pass
    elif A[i]==A[i-1]+1:
        s+=C[t-2]
print(s)

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

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

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

score=sum(B)
for a,b in zip(A,A[1:]):
    if b==a+1:
        score+=C[a-1]

print(score)

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

satisfiction = 0

for i in range(len(a)):
    tmpb = b[a[i] - 1]
    satisfiction += b[a[i] - 1]
    if i <= len(a) - 2 and (a[i + 1] - a[i] == 1):
        satisfiction += c[a[i]-1]
        
print(satisfiction)

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

x = 0
for i in range(n):
    x += bb[aa[i] - 1]
    if i > 0 and aa[i - 1] == aa[i] - 1:
        x += cc[aa[i - 1] - 1]
print(x)

Solution (Python):
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
s = 0
p = 0
for i in range(n):
  indx = al[i] - 1
  s += bl[indx]
  if i > 0 and al[i] - prev == 1:
    s += cl[indx - 1]
  prev = al[i]
print(s)

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

print(bb+cnt)

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

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

sum = 0

prev = -1

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

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

print(S)

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

answer = 0
for index, food in enumerate(a):
    if index == 0:
        answer += b[food - 1]
    elif a[index - 1] + 1 == food:
        answer += b[food - 1]
        answer += c[a[index - 1] - 1]
    else:
        answer += b[food - 1]

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

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

print(manzoku)