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


import sys

class BBuffet:
    def solve(self):
        n = int(input())
        a = [int(_) - 1 for _ in input().split()]
        b = [int(_) for _ in input().split()]
        c = [int(_) for _ in input().split()]
        ans = 0
        last = -2
        for i in range(n):
            ans += b[a[i]]
            if a[i] - 1 < n - 1 and a[i] - 1 == last:
                ans += c[a[i] - 1]
            last = a[i]
            

        print(ans)

solver = BBuffet()
input = sys.stdin.readline

solver.solve()

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

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

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

sum = 0

prev = -1

for now in a:
    sum += b[now-1]

    if(now == prev + 1):
        sum += c[prev-1]

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z=list(map(int,input().split()))

res=0

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

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

Solution (Python):

"""
Created on Sat Sep  7 21:01:43 2019

@author: doppe
"""

N = int(input())

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

score = 0
before = -99
for i in range(0, len(A)):
    score += B[A[i] - 1]
    if (before == A[i] - 1):
        score += C[A[i] - 2]
    before = A[i]
print(score)

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

c.append(0)

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



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

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

        num = A[i]
        sum += B[num-1]
        save = num


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

a_prev = N+1

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

print(ans)

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

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

    sum = 0

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

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

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


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

sat = 0
prev = 0

for i, a in enumerate(A):
    sat += B[a - 1]

    if i > 0:
        if (a - 1 - prev) == 1:
            sat += C[prev]

    prev = a - 1

print(sat)

Solution (Python):
n = int(input())
zyunban = list(map(int, input().split()))
val = list(map(int, input().split()))
kougo = list(map(int, input().split()))

total = sum(val)
for i in range(n-1):
    if zyunban[i+1] == zyunban[i] + 1:
        total += kougo[zyunban[i] -1]
print(total)

Solution (Python):
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

al = list(map(lambda x: x - 1, al))

s = 0
a_prev = -100
for a in al:
    s += bl[a]
    if a_prev != (n - 1) and a - a_prev == 1:
        s += cl[a_prev]
    a_prev = a


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

Solution (Python):
import numpy as np

N=int(input())
A=np.array(input().split(),dtype=np.int32)-1
B=np.array(input().split(),dtype=np.int32)
C=np.array(input().split(),dtype=np.int32)

s=0
for i in range(len(A)):
    key=A[i]
    s+=B[key]
    if(i+1<=len(A)-1):
        if(key+1==A[i+1]):
            s+=C[key]

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

current_eat = -2
manzoku = 0
for n in range(N):
    eat_index  = A[n] - 1
    manzoku += B[eat_index]
    if(current_eat  +1 == eat_index):
        manzoku += C[current_eat]
    current_eat = eat_index
print(manzoku)

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy




def main():
    n = int(input())
    aa = list(map(int,input().split()))
    bb = list(map(int,input().split()))
    cc = list(map(int,input().split()))
    ba = aa[0]-1
    ans = bb[ba]
    for a in aa[1::]:
        if ba+1 == a-1:
            ans += cc[ba]
        ba = a-1
        ans += bb[ba]
    print(ans)


if __name__ == '__main__':
    main()

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

nA = [ 0 for i in range(N)]
nB = [ 0 for i in range(N)]
nC = [ 0 for i in range(N-1)]

Tmp = []
Tmp = input().rstrip().split(' ')
for i in range(N):
  nA[i] = int(Tmp[i])

Tmp = []
Tmp = input().rstrip().split(' ')
for i in range(N):
  nB[i] = int(Tmp[i])

Tmp = []
Tmp = input().rstrip().split(' ')
for i in range(N-1):
  nC[i] = int(Tmp[i])
  
Ans = 0

nTmpOld = N + 2
for i in range(N):
  nTmp = nA[i] - 1
  
  Ans += nB[nTmp]
  
  if i > 0 and nTmp == nTmpOld + 1:
    Ans += nC[nTmp-1]
  
  nTmpOld = nTmp

print(Ans)

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

Solution (Python):
n=int(input())
lista = [int(i) for i in input().split()]
listb = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

ans = 0
bef = -1000
for i in range(n):
    bango = lista[i]
    ans+=listb[bango-1]
    
    if bango-bef == 1:
        ans+=listc[bango-2]
        
    bef = bango
    
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]
ans = ans + sum(B)

print(ans)

Solution (Python):
n  = int(input())
xs = [0]
ys = [0]
zs = [0]
p  = None
c  = 0

xs.extend([int(x) for x in input().split()])
ys.extend([int(x) for x in input().split()])
zs.extend([int(x) for x in input().split()])

for i in range(1, n + 1):
	a  = xs[i]
	c += ys[a]
	if a - 1 == p:
		c += zs[p]
	p = a
	
print(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
for i in range(n):
    ans += b[a[i]-1]
    if i >= 1 and a[i] - j == 1:
        ans += c[j-1]
    j = a[i]
print(ans)

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

_sum = sum(B)
prev_a = N+1

for a in A:
    if prev_a+1 == a:
        _sum += C[prev_a-1]
    prev_a = a

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()))
sum = sum(b)
a_new = [0] * (n-1)
for i in range(1, n):
    a_new[i-1] = a[i]- a[i-1]
for i, val in enumerate(a_new):
    if val == 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()))
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):
def resolve():
    n = int(input())
    aaa = list(map(int, input().split()))
    bbb = list(map(int, input().split()))
    ccc = list(map(int, input().split()))
    ans = bbb[aaa[0]-1]
    for i in range(n-1):
        if aaa[i+1] == aaa[i] + 1:
            ans += ccc[aaa[i]-1]
        ans += bbb[aaa[i+1]-1]
    print(ans)
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
x = -1
for i in range(N):
    sum += B[A[i] - 1]
    if x == A[i] - 1:
        sum += C[x-1]
    x = A[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()))
ans = sum(B)
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        AAA = A[i]
        ans += C[AAA-1]

print(ans)

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

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

Solution (Python):
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
p = 0
for i in list_B:
    p += i
for i in range(N-1):
    if list_A[i+1] - list_A[i] == 1:
        p += list_C[list_A[i] - 1]
print(p)

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
past = -10
for i in range(n):
    ans += B[A[i] - 1]
    if past == A[i] - 1 - 1:
        ans += C[A[i] - 1 - 1]
    past = 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
tmp = 10000
for a_ in a:
    ans += b[a_ - 1]
    if tmp + 1 == a_:
        ans += c[a_ - 2]
    tmp = 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
check = -1

for i in range(N):
    eat = A[i] - 1
    count += B[eat]
    if 1 <= i <= (N-1):
        if check == eat - 1:
            count += C[check]
    check = eat

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

print(ans)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]

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

Solution (Python):
def main():
    b = int(input())
    l_A = [int(i) for i in input().split()]
    l_B = [int(i) for i in input().split()]
    l_C = [int(i) for i in input().split()]

    last = -100
    ans = 0
    for A in l_A:
        ans += l_B[A-1]
        if A - last - 1 == 1:
            ans += l_C[A - 2]
        last = 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

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

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]:
        cnt += c[a[i]-1]
        
print(cnt)

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

satis = 0
for j in range(n):
    ate = A[j] - 1
    satis += B[ate]
    if j > 0 and A[j] == A[j - 1] + 1:
        satis += C[A[j - 1] - 1]
print(satis)

Solution (Python):
def p_b():
    N = int(input())
    A = list(map(int, input().split()))
    A = [i - 1 for i in A]
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = 0

    bf = -100
    for i in A:
        ans += B[i]
        if bf == i - 1:
            ans += C[i - 1]
        bf = i

    print(ans)


if __name__ == '__main__':
    p_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(len(A) -1):
  if A[i + 1] == A[i] + 1:
    ans += C[A[i]-1]
print(ans)

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
for i in range(N-1):
    ans += B_l[A_l[i]-1]
    if(A_l[i]+1 == A_l[i+1]):
        ans += C_l[A_l[i]-1]
ans += B_l[A_l[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 = 0
for i in range(len(A)):
  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()))
point0 = sum(B)
for (i,j) in zip(A[:-1],A[1:]):
    if i == j - 1:
        point0 += C[i-1]
print(point0)

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

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

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):
N = int(raw_input())
A = raw_input().split()
B = raw_input().split()
C = raw_input().split()


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

print satis

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

A = [int(x) - 1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = 0
flag = False
temp = A[0]

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
cnt = 0
pre = -1
for i in range(N):
  idx = A[i]
  cnt += B[idx-1]
  if pre==idx-1:
    cnt += C[pre-1]
  pre = idx
  
print(cnt)

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

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

prev = n
total = 0
for i in range(n):
	cur = A[i]
	total += B[cur-1]
	if cur == prev + 1:
		total += C[prev-1]
	prev = cur 
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(len(a)):
    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 = sum(b)

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

print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
C.append(0)
ans = B[A[0]-1]
pre = A[0]-1
for i in range(1,N):
    ans += B[A[i]-1]
    if A[i]-1 - pre == 1:
        ans += C[pre]
    pre = A[i]-1
print(ans)

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

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

Solution (Python):
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()]
satisfaction = sum(b)
for dish, next_dish in zip(a, a[1:]):
    if next_dish == dish+1:
        satisfaction += c[dish-1] 
print(satisfaction)

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A = [a-1 for a in A]
    manzoku = 0
    for i in range(N):
        manzoku += B[A[i]]
        if i < N-1 and A[i+1] == A[i] + 1:
            manzoku += C[A[i]]
    print(manzoku)
    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):
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()]

m = 0
ba = -1
for ai in a:
    m = m + b[ai-1]
    if ba + 1 == ai:
        m = m + c[ba-1]
    ba = ai
print(m)

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

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

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

ans = 0

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

print(ans)

Solution (Python):
N = int(input())
A = 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 = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
point = 0
temp = -1
for a in a_list:
    point += b_list[a-1]
    if a - temp == 1:
        point += c_list[a-1-1]
    temp = 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()))

s = 0
prev = -1

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

print(s)

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

n2 = [int(i) for i in input().split()]
n3 = [int(i) for i in input().split()]
n4 = [int(i) for i in input().split()]

r1 = 0

for i1 in range(n1):
    r1 += n3[n2[i1] - 1]
    if i1 <= n1 - 2:
        if n2[i1] + 1 == n2[i1 + 1]:
            r1 += n4[n2[i1] - 1]

print(r1)

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

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

print(count)

Solution (Python):
import sys; from collections import deque ; readline = sys.stdin.readline

N = int(readline())
A = list(map(lambda x:int(x)-1, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))

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

a += sum(B)

print(a)

Solution (Python):
def solve():
  import sys
  import math

  sys.setrecursionlimit(10**7)
  readline=sys.stdin.readline

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

  print(ans)


if __name__ == '__main__':
  solve()

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

Solution (Python):
N = int(input())
a_list = [int(i) for i in input().split(' ')]
b_list = [int(i) for i in input().split(' ')]
c_list = [int(i) for i in input().split(' ')]

manzoku = 0
last_order = -1
for order in a_list:
    manzoku += b_list[order - 1]
    if order == last_order + 1:
        manzoku += c_list[last_order - 1]
    last_order = order

print(manzoku)

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

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

print(ans)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


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

a.insert(0, -1)
b.insert(0, -1)
c.insert(0, -1)





f = 0
for i in range(1,n+1):
    taste_a = a[i]

    f += b[taste_a]

    
    if a[i]-a[i-1] == 1:

        f += c[taste_a-1]

print(f)

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 = None

for i in range(n):

    idx = a[i] - 1

    ans += b[idx]

    if i > 0 and idx == prev + 1:
        ans += c[prev]
    prev = idx


print(ans)

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


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

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

print(ans)

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

base = sum(b_list)

bouns = 0
pre = -10
for index, a in enumerate(a_list):
    if index > 0:
        if a - pre == 1:
            bouns += c_list[pre - 1]
    pre = a

print(base + bouns)

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
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[A[i]-2]
  tmp = 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()))
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(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

res = 0
for ai in range(len(A)):
    if ai == 0:
        res += B[A[ai] -1]
    else:
        res += B[A[ai] -1]
        if A[ai-1] +1 == A[ai]:
            res += C[A[ai-1]-1]
print(res)

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

ans = 0
pre = None
for ai in a:
    ans += b[ai - 1]
    if pre is not None and pre + 1 == ai:
        ans += c[ai - 2]
    pre = ai

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

Solution (Python):
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)




def main():
    n = int(input())
    order = list(map(int, input().split()))
    points = list(map(int, input().split()))
    bonus = list(map(int, input().split()))
    last_one = -10
    ans = 0

    for x in order:
        if last_one + 1 == x - 1:
            ans += bonus[last_one]

        last_one = x - 1
        ans += points[x-1]

    print(ans)


if __name__ == '__main__':
    main()

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