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

manzoku = 0

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

Solution (Python):
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
bonuses = list(map(int, input().split()))

score = 0
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i == prev + 1: score += bonuses[i-2]
  prev = 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()))
sum = 0

for i in range(len(a)):
    sum += b[a[i] - 1]
    try:
        if i != 0 and a[i] == a[i-1] + 1:
           sum += c[a[i-1] - 1]
    except IndexError:
        continue

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

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

print(ans)

Solution (Python):
n = int(input())+1
inp1 = list(map(int, input().split()))
inp2 = list(map(int, input().split()))
inp3 = list(map(int, input().split()))
c, val = 0, 1
for i in range(n-1):
    c = (inp2[inp1[i] - val])+c
    if i > 0 and inp1[i] == inp1[i-val] + val:
        c = (inp3[inp1[i-val] - val])+c
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()))
Sum=sum(b)
for i in range (0,len(a)-1):
  if a[i]+1==a[i+1]:
    number=a[i]
    Sum+=c[number-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()))

memory=-1
add=0
ans=0

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

print(ans)

Solution (Python):
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=[list(mi()) for _ in range(3)]
ans=0
for i in range(a-1):
  ans+=l[1][l[0][i]-1]
  if l[0][i]+1==l[0][i+1]:
    ans+=l[2][l[0][i]-1]
print(ans+l[1][l[0][a-1]-1])

Solution (Python):
a=int(input())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
o=list(map(int,input().split()))
result1=0

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

for i in range(a):
    result1+=m[n[i]-1]
print(result1)

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

minus_index = -1
happy = 0

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

print(happy)

Solution (Python):

def main():
    _ = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    cnt = 0
    flg = a[0]

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

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

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

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

ans = sum(B)
for i, a in enumerate(A):
    if i >= len(A) - 1:
        break
    if a + 1 == A[i+1]:
        ans = ans + C[a-1]
print(ans)

Solution (Python):
input()
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
pts = 0
prev = 0
for i in range(len(A)):
    try:
        pts += B[A[i] - 1]
    except:
        pass
    try:
        if prev+1 == A[i]:
            pts += C[A[i-1]-1]
    except:
        pass
    prev = A[i]
print(pts)

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

if __name__ == '__main__':
    main()

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

Solution (Python):
N=int(input())
a=input()
a_=a__=[int(i) for i in a.split()]
b=input()
b_=b__=[int(i) for i in b.split()]
c=input()
c_=c__=[int(i) for i in c.split()]
sat=0
first=a_[0]-1
sat=sat+b_[first]
for x in a_:
    if x>N:
        a_.remove(x)
for x in b_:
    if x<1 or x>50:
        b__=b_.remove(x)
for x in c_:
    if x<1 or x>50:
        c__=c_.remove(x)
a__=list(dict.fromkeys(a_))
if len(a__) ==len(a_) and len(c__)==len(c_) and len(b__)==len(b_) and 2<=N<=50:
    for x in range(1,N):
        if a_[x]==1+a_[x-1]:
            sat=sat+b_[(a_[x])-1]+c_[(a_[x])-2]
        else:
            sat=sat+b_[(a_[x])-1]
    if sat!=0:
        print(sat)

Solution (Python):



import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline




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

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

print(ans)

Solution (Python):
n=int(input())
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
l3 = list(map(int,input().split()))
m=0
m+=l2[l1[0]-1]
for i in range(1,n):
    if l1[i] == l1[i-1]+1:
        m+=l2[l1[i]-1]+l3[l1[i]-2]
    else:
        m+=l2[l1[i]-1]
print(m)

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
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 = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
ans += b[a[0]-1] 
for i in range(1,n):
    ans += b[a[i]-1]
    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()))
A.insert(0,"X")
B.insert(0,"X")
C.insert(0,"X")
stf_c = 0
j = 100
for i in range(1,N+1):
	if A[i] == j+1:
		stf_c += (B[A[i]]+C[j])
		j = A[i]
	else:
		stf_c += B[A[i]]
		j = A[i]
print(stf_c)

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

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

print(ans)

Solution (Python):
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    p = -1
    ans = 0
    for i, d in enumerate(a):
        if d == p+1:
            ans += b[d-1] + c[p-1]
        else:
            ans += b[d-1]
        p = d
    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()))

score = 0
for i in range(0, n):
   menu = a[i]
   score += b[menu-1]
   if i != 0 and a[i] - a[i-1] == 1:
      beforeMenu = a[i-1]
      score += c[beforeMenu-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()))
K = 0 
for i in range(N):
  if i == 0:
    K += B[A[i] - 1]
  else:
    K += B[A[i] - 1]
    if A[i] == A[i - 1] + 1:
      K += C[A[i - 1] - 1]
print(K)

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
tmp=-5
res=0
for i in range(n):
  res += b[a[i]-1]
  if tmp==a[i]-2:
    res += c[a[i]-2]
  tmp=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()))
ans=0
j=0
for i in a:
	ans+=b[i-1]
	if i==j+1 and i!=1:
		ans+=c[j-1]
	j=i
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<N-1 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
prev = -1
for i in A:
    ans += B[i-1]
    if prev == i-1:
        ans += C[i-2]
    prev=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()))
p=-1
ans=0
for i in range(n):
    ans+=b[a[i]-1]
    if p+1==a[i]:
        ans+=c[a[i]-2]
    p=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()))

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

print(sat)

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

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

ans = 0
rout = []
for i in range(n):
    ans += b[a[i]-1]
    rout.append(a[i]-1)

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

Solution (Python):
import sys

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

ans = sum(B)

if N == 2 and A[0] == 1: 
  ans = ans +C[0]
  print(ans)
  sys.exit()

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

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

print(total)

Solution (Python):
N = int(input())
LA = list(map(int, input().split()))
LB = list(map(int, input().split()))
LC = list(map(int, input().split()))

SFB = sum(LB)
SFC = 0

for i in range(1, N):
    j = i - 1
    if LA[i] == (LA[j] + 1):
        A = LA[i] - 2
        SFC += LC[A]

print(SFB + SFC)

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

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

sum = 0
hantei = 0


for i in range(len(a)):


    if i == 0:
        sum = sum + b[a[i]-1]
        hantei = a[i]
    else:
        if a[i] == hantei + 1:
            sum = sum + b[a[i]-1] + c[a[i]-2]
            hantei = a[i]
        else:
            sum = sum + b[a[i]-1]
            hantei = a[i]
    
print(sum)

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

    *A, = (int(x) - 1 for x in input().split())
    B = map(int, input().split())
    *C, = map(int, input().split())

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

total = 0
for a in A_list:
    total += B_list[a-1]

for i in range(N-1):
    if A_list[i] + 1 == A_list[i + 1]:
        total += C_list[A_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()))
sb=sum(b)

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

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[N-1]-1]
print(ans)

Solution (Python):
n=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))

sum=0
bef=-2

for a in alist:
    sum += blist[a-1]
    if bef + 1 == a:
        sum += clist[bef-1]
    bef = a

print(sum)

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

    sum = 0

    before = A[0]

    for ryouri in A:
        if before + 1 == ryouri:
            sum += B[ryouri - 1] + C[before - 1]
        else:
            sum += B[ryouri - 1]

        before = ryouri

    print(sum)


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

prev_dish = -1
satisfaction = 0
for dish in A:
    satisfaction += B[dish-1]
    if dish - prev_dish == 1:
        satisfaction += C[prev_dish-1]
    
    prev_dish = dish

print(satisfaction)

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

point = 0
before = 10**10

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

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

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

ans = 0
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):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
b=lmp()
c=lmp()
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]-2]
print(ans)

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

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

Solution (Python):

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if i < n-1 and a[i+1]-1 == a[i]:
        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-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):
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
b = readints()
c = readints()
ans = 0
for i in range(n):
    ans += b[a[i]-1]

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

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

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

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

  ans = 0
  prev = -2
  for x in a:
    x -= 1
    ans += b[x]
    if prev + 1 == x:
      ans += c[prev]
    prev = x
  print(ans)
  return

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

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


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()))
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]
    if i == 0:continue
    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)
pre_idx = -1
pre_val = -1
for idx, val in enumerate(a):
    if pre_idx == -1:
        pre_idx = idx
        pre_val = val
    else:              
        if pre_val == val  - 1:
            ans = ans + c[pre_val - 1]
            pre_idx = idx
            pre_val = val
        else:
            pre_idx = idx
            pre_val = val   
        
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()))
ab = 21
m = 0
for i in a:
    m += b[i-1]
    if i == ab + 1:
        m += c[i-2]
    ab = i
print(m)

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

for i in range(len(a)):
  num = a[i]-1
  sum += b[num]
  if i >= 1 and a[i]-a[i-1] == 1:
    tmp = a[i]-2
    sum += c[tmp]
else:
  print(sum)

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

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

Solution (Python):
n = int(input())
A, B, C = [[int(x) for x in input().split()] for _ in range(3)]

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

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

print(ans)

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

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

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

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

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
U=list(map(int,input().split()))

goukei=0

before=1000
for i in range(N):
    goukei+=T[S[i]-1]
    if before+1==S[i]:
        goukei+=U[S[i]-2]
    
    before=S[i]
    
print(goukei)

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

def actual(n, A, B, C):
    bonus_point = 0

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

    return sum(B) + bonus_point

print(actual(n, A, B, C))

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

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


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

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
a = list(map(lambda x: x - 1, a))
b = LI()
c = LI()

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

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

t = 1000000000
lis = list()
for i in A:
    lis.append(B[i-1])
    
    if i == t + 1:
        lis.append(C[i-2])
    t = i

print(sum(lis))

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

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

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

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

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

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

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

Solution (Python):
def resolve():
    N = int(input())
    eat = list(map(int, input().split()))
    heal = list(map(int, input().split()))
    plus = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        if eat[i+1] - eat[i] == 1:
           ans += plus[eat[i]-1]
    print(sum(heal) + 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()))
sts = 0
for i in range(n):
    sts += B[A[i] - 1]
    if 0 < i and A[i] - A[i-1] == 1:
        sts += C[A[i] - 2]
print(sts)

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

Solution (Python):
def linp():return list(map(int,input().split()))
n=int(input())
a=linp()
b=linp()
c=linp()
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()))

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