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
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N = inputI()
A = inputIL()
B = inputIL()
C = inputIL()

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

count = 0

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

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

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

list=[]
for i in range(n-1):
  if a[i]+1==a[i+1]:
    list.append(a[i]-1)
vonus=0
for ll in list:
  vonus+=c[ll]
print(sum(b)+vonus)

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

res = 0

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

print(res)

Solution (Python):
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
ans = sum(b_list)
for i in range(n-1):
    if a_list[i+1]-a_list[i] == 1:
        ans += c_list[a_list[i]-1]
print(ans)

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
d = {}
e = {}
cnt = 0
for i in range(1, n+1):
    d[i] = B[i-1]
for i in range(1, n):
    e[i] = C[i-1]
for i in range(n):
    cnt += d[A[i]]
    if i != 0:
        if A[i] == 1:
            continue 
        else:
            if A[i] == A[i-1] + 1:
                cnt += C[A[i]-2]
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()))
cnt = sum(b)
for i in range(n):
  if i<=n-2 and (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()))
a = [i-1 for i in a]
ans = b[a[0]]
for i in range(1, n):
    ans += b[a[i]]
    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()))
cnt = 0

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

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

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
sum = 0
for a in A:
    sum += B[a-1]
    if prev+1 == a-1:
        sum += C[prev]
    prev = a-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()))
SUM = 0
before = -1
for i in A:
    SUM += B[i-1]
    if before + 1 == i:
        SUM += C[before-1]
    before = i
print(SUM)

Solution (Python):
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    prev = -100
    s = 0
    for a in A:
        s += B[a-1]
        if a - prev == 1:
            s += C[prev-1]
        prev = a

    print(s)


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

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = LI()
B = LI()
C = LI()

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

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
back = 0
for i in range(0, n):
  count += b[a[i]-1]
  if back+1 == a[i] and back != 0:
    count += c[a[i]-2]
  back = a[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()))

ans = 0 

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

tmp = A[1:]

tmp = np.append(tmp, -1)

add = A[np.where((tmp-A)==1)]

ans = B.sum() + C[add-1].sum()
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=sum(b)
m=[]
for i in range(N-1):
  if a[i+1]-a[i]==1:
    m.append(c[a[i]-1])
e=sum(m)
print(d+e)

Solution (Python):
from sys import argv

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
c = c + [0] * (len(b) - len(c))
ans = 0
debug = "a" in argv
for index, x in enumerate(a):
    ans += b[x - 1]
    if a[index - 1] + 1 == a[index] and index != 0:
        if debug:
            print(x, index, a[index - 1], a[index])
            print(c[x - 2], c[x - 1])
        ans += c[x - 2]
print(ans)

Solution (Python):


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

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

print(ans)

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

ans = sum(b)

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

for target in A:
  ans += B[target-1]
  if(pre == -1):
    pre = target
    continue
  if(pre + 1 == target):
    ans += C[pre - 1]
  pre = target
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
pre = -1

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

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

print(sf)

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

Solution (Python):
n = int(input())
a_lst = list(map(int,input().split()))
b_lst = list(map(int,input().split()))
c_lst = list(map(int,input().split()))
good = 0

for i in range(n-1):
    a1 = a_lst[i]
    a2 = a_lst[i+1]
    b = b_lst[a1-1]
    good += b
    if a1+1==a2:
        c = c_lst[a1-1]
        good += c

a = a_lst[-1]
b = b_lst[a-1]
good += b
print(good)

Solution (Python):
import sys
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()
C = LI()

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

print(res)

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

sum=0
for i in range(n):
    sum+=b[i]

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

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

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

manzoku=0


for i in range(N):
    ryori = A[i]

    manzoku+=B[ryori-1]

    if i!=0:
        if ryori-1 == ryori_pre:
            manzoku+=C[ryori_pre-1]

    ryori_pre = A[i]


print(manzoku)

Solution (Python):
n = 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 = []
B = []
C = []
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 - 1):
  satis += B[A[i] - 1]
  if A[i] + 1 == A[i + 1]:
    satis += C[A[i] - 1]
satis += B[A[N - 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()))

def solve(A,B,C):
    ans = sum(B)
    for i in range(N-1):
        if A[i+1]==A[i]+1:
            ans += C[A[i]-1]
    return ans
print(solve(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()))
ans=sum(B)
for i in range(1,N):
    if A[i-1]+1==A[i]:
        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
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()))
r=0
k=-9
for i,j in enumerate(a):
    r+=b[j-1]
    if j-1==k+1:
        r+=c[j-2]
    k=j-1
print(r)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    lc=list(map(int,input().split()))
    manzoku=sum(lb)
    for j in range(n-1):
        if la[j+1]-la[j]==1:
            manzoku+=lc[la[j]-1]
    print(manzoku)

resolve()

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

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 != n-1 and a[i+1] == a[i] + 1:
    ans += c[a[i]-1]

print(ans)

Solution (Python):
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    ans = sum(B)
    k = -1
    for i in A:
        if i == k + 1:
            ans += C[k-1]
        k = i
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

print(ans)

Solution (Python):
import math
n = int(input())
food_list = list(map(int, input().split()))
satis_list = list(map(int, input().split()))
moreS_list = list = list(map(int, input().split()))

total = sum(satis_list)

for i in range(n-1):
    if food_list[i] + 1 == food_list[i+1]:
        total += moreS_list[food_list[i]-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
pre = -1
for a in A:
  ans += B[a-1]
  if a - 1 == pre:
    ans += C[a-2]
  pre = 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[i]
for i in range (1,n):
  if A[i] == (A[i-1] + 1):
    ans += C[A[i-1]-1]
print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B=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:
        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()))

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

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
s += sum(B)

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

print(s)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 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()))

s = b[a[0]-1]

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

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

print(ans)

Solution (Python):
N = int(input())
count = 0
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
for i in range(N-1):
  count = count + B[A[i]-1]
  if A[i+1] == A[i] + 1:
    count = count + C[A[i]-1]
                      
count = count + B[A[N-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 = 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()))
j = -1
res = 0
for  i in a:
    if i - 1 == j:
        res += c[j-1]
    j = i
print(res+sum(b))

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

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

Solution (Python):
n=int(input())
as_=list(map(int,input().split()))
bs=list(map(int,input().split()))
cs=list(map(int,input().split()))
p=sum(bs)+sum([cs[a-1] for a,a_ in zip(as_,as_[1:]) if a+1==a_])
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()))

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

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

lis=[]
for i in range(0,n-1):
  if a[i]==a[i+1]-1:
    lis.append(a[i])
plus=0
for j in range(0,len(lis)):
  plus+=c[lis[j]-1]
print(sum(b)+plus)

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

ans = 0
for i in range(len(a_list)):
    ans += b_list[a_list[i] - 1]
    if i > 0 and a_list[i] == a_list[i - 1] + 1:
        ans += c_list[a_list[i - 1] - 1]


print(ans)

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

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

print(ans)

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

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

ans=sum(B)

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

print(ans)

Solution (Python):


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    
    Bs = []
    for i in range(1, N):
        if A[i] - A[i-1] == 1:
            Bs.append(C[A[i -1] - 1])

    print(sum(B) + sum(Bs))

main()

Solution (Python):
a=int(input())
b=input().split()
c=input().split()
count=0
for i in c :
  count+=int(i)

d=input().split()
list1=[]

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

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

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

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = LI1()
    B = LI()
    C = LI()

    
    
    
    pre = -4
    ans = 0
    for a in A:
        score = B[a]
        if a - pre == 1:
            score += C[pre]
        ans += score
        pre = a
    print(ans)


if __name__ == '__main__':
    solve()

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

Solution (Python):
n = int(input())
aaa = list(map(int, input().split()))
li_a = []
for i in aaa:
  i -= 1
  li_a.append(i)
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
ans = 0
for i in range(n):
  ans += li_b[li_a[i]]
  if i-1 >= 0:
      if li_a[i] == li_a[i-1]+1:
        ans += li_c[li_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
total += sum(b)
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        total += c[a[i]-1]
print(total)

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


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

print(cnt)

Solution (Python):
import os, sys, re, math

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

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

Solution (Python):
N = int(input())
A = [int(s) for s in input().split(' ')]
B = [int(s) for s in input().split(' ')]
C = [int(s) for s in input().split(' ')]
ret = 0
prev = -1
for i in range(N):
    ii = A[i] - 1
    ret += B[ii]
    if prev > -1:
        if prev + 1 == ii:
            ret += C[prev]
    prev = ii
print(ret)

Solution (Python):
n = int(input())
aaa = list(map(int, input().split(' ')))
bbb = list(map(int, input().split(' ')))
ccc = list(map(int, input().split(' ')))
ans = 0
old = -999
for i in aaa:
    ans += bbb[i-1]
    if i == old + 1 and old-1 < len(ccc):
        ans += ccc[old-1]
    old = i
print(ans)

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

Solution (Python):
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime



def input1():
	return int(input())


def input2():
	return map(int,input().split())


def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets


def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	
	return fact(x+y)/fact(x)/fact(y)


def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			




N=input1()
A=input_array()
B=input_array()
C=input_array()
result=0
before=0
for i in range(N):
	result+=B[A[i]-1]
	if (before+1==A[i]) and before!=0:
		result+=C[A[i]-2]
	before=A[i]

print(result)

Solution (Python):
n=int(input())
lista=list(map(int,input().split()))
listb=list(map(int,input().split()))
listc=list(map(int,input().split()))
list=[]
for i in range(2,n+1):
  if lista[i-1]==lista[i-2]+1:
    list.append(lista[i-2])
vonus=0
for x in list:
  vonus+=listc[x-1]
print(sum(listb)+vonus)

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):
  cnt += B[A[i]-1]


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