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 numpy as np
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]
score=0
pred_i=np.inf
for i in A:
    if pred_i+1 ==i:
        score=score+C[i-2]+B[i-1]
    else:
        score+=B[i-1]
    pred_i=i
print(score)

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

Satis = 0

for i in range(N):

    Satis += B[A[i] - 1]

    if 0 < i:
        if A[i - 1] + 1 == A[i]:
            Satis += C[A[i - 1] - 1]

print(Satis)

Solution (Python):
n = input()
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
ans = 0
for i in range(n):
    ans = 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()))

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

print(manzoku+add_manzoku)

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


value = 0

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

print(value)

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:
    x+=C[A[i]-1]
print(x)

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

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

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

Solution (Python):

from itertools import combinations
 
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = 0
nowrow = 0

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

print(total)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()
B = MAP()
C = MAP()

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

print(man)

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-1):
    if A[i+1] == A[i] +1:
        sum += C[A[i]-1]

for i in range(N):
    sum += B[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()))
before = 10000
total=0
for aa in a:
    total+=b[aa-1]
    if before+1==aa:
        total+=c[before-1]
    before=aa
print(total)

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

print(ans)

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

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

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

Solution (Python):
N = int(input())
An = list(map(int, input().split()))
An = [-1] + An
Bn = list(map(int, input().split()))
Bn = [-1] + Bn
Cn = list(map(int, input().split()))
Cn = [-1] + Cn

count = 0
for i in range(1, N + 1):
    count += Bn[An[i]]
    if i > 1 and An[i] == An[i - 1] + 1:
        count += Cn[An[i - 1]]

print(count)

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

sum = 0

for i in range(N):
    sum += b_list[a_list[i]-1]
    if (i>=1 and a_list[i]-a_list[i-1] == 1):
        sum += c_list[a_list[i]-2]

print(sum)

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

ans = 0
count_i = 0
b_con = 0

for i in a_list:
    count_i += 1 
    ans += b_list[i-1]
    if b_con+1 == i and i != 1:
        ans += c_list[i-2]
    b_con = 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
tmp = -1
for i in range(N):
    for j in range(N):
        if A[i] == j+1:
            ans += B[j]
            if A[i] == tmp+1:
                ans += C[tmp-1]
            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()))

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

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

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

print(res)

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

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

print(res)

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

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

Solution (Python):
N=int(input())
order=list(map(int,input().split()))
sat=list(map(int,input().split()))
a=list(map(int,input().split()))

total=sum(sat)

for i in range(N-1):
  if order[i]==order[i+1]-1:
    total += a[order[i]-1]

print(total)

Solution (Python):
import sys
input = sys.stdin.readline

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

ans = 0
for i in range(len(a)-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()))







cnt = 0


temp = ""


for x in A:
    
    
    cnt += B[x-1]
    
    
    if temp == x - 1:
        cnt += C[temp-1]
        
    
    temp = x

print(cnt)

Solution (Python):
N = int(input())
A = list(input().split())
B = list(input().split())
C = list(input().split())
S = 0
for j in range(0,N):
  a = int(A[j])
  b = int(B[a-1])
  S = S + b

for i in range(0,N-1):
  a = int(A[i])+1
  b = int(A[i+1])
  if a == b:
    S = S + int(C[a-2])


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

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

print(ans)

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

res = 0

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

    if i < n - 1 and a[i] + 1 == a[i + 1]:
        res += c[x]

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

count = 0

for i in range(n):

    if i == 0:
        count += b[a[i]-1]

    else:
        count += b[a[i]-1]

        if a[i] - a[i-1] == 1:
            count += c[a[i-1]-1]

print(count)

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

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

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

for a in A:
    total += B[a-1]
    if previous+1 == a:
        total += C[previous-1]
    previous = a
print(total)

Solution (Python):
n=int(input())
A,B,C=[list(map(int,input().split())) for _ in range(3)]
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())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
c=sum(B)
for i in range(n-1):
    if A[i+1]-A[i]==1:c += C[A[i]-1]
print(c)

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

prev = -99
ans = 0
for i in A:
    ans += B[i]
    if prev == i-1:
        ans += C[i-1]
    prev = i
print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(input().split()).astype(int)
B = np.array(input().split()).astype(int)
C = np.array(input().split()).astype(int)
r = sum(B)
r += C[A[np.append(np.diff(A)==1, False)]-1].sum()
print(r)

Solution (Python):

import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

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



t = -10
ans = 0

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

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

prevIdx = -99
ret = 0
for a in A:
    a -= 1
    ret += B[a]
    if a == prevIdx + 1:
        ret += C[a - 1]
    prevIdx = a
print(ret)

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

Solution (Python):

N = int(input())
A = input().split()
B = input().split()
C = input().split()


result = 0
for i in range(N):


  result = result + int(B[int(A[i])-1])  
  
  if (i != 0):
    if (int(A[i]) - int(A[i-1]) == 1):
      
      result = result + int(C[int(A[i-1])-1])
print(result)

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

bonus=0

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

print(sum(B)+bonus)

Solution (Python):
n = int(input())
ryori_list = list(map(int, input().split()))
manzoku_list = list(map(int, input().split()))
tuika_list = list(map(int, input().split()))

point = 0
before_r = 100
for r in ryori_list:
    point += manzoku_list[r-1]
    if r == before_r + 1:
        point += tuika_list[before_r-1]
    before_r = r
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()))
ret = 0
bef = -1
for i in a:
  ret += b[i-1]
  if bef == i - 1:
    ret += c[bef - 1]
  bef = i
print(ret)

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

a_pre = -1
ans = 0
for ai in a:
    ans += b[ai - 1]
    if ai == a_pre + 1:
        ans += c[a_pre - 1]
    a_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
pre_idx=-100
for a in A:
  idx = a-1
  
  ans += B[idx] + ( C[pre_idx] if idx == pre_idx+1 else 0)
  pre_idx = idx
  
  
print(ans)

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

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

s = 0
pre_food = A[0]
for food in A:
    s += B[food-1]
    if food - pre_food == 1 : s += C[food-2]
    pre_food = food

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()))
R = 0

for n in range(N):
    R += B[A[n]-1]
    if n >= 1 and A[n] - A[n-1] == 1:
        R += C[A[n-1]-1]

print(R)

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

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

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

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()]
buf = 0

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

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

print(buf)

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

a.append(23)
c.append(0)
count = 0

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

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(len(a)):
    aa=a[i]
    ans+=b[aa-1]
    if i<n-1:
        if a[i+1]==a[i]+1:
            ans+=c[aa-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]-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(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
pre = -100
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):
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,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())

s=0
bef=float('inf')
for i in range(n):
      s+=b[a[i]-1]
      if bef+1==a[i]:
            s+=c[a[i]-2]
      bef=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=0
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
ans+=sum(b)
print(ans)

Solution (Python):

n = int(input())
a, b = [[int(s) for s in input().split()] for _ in range(2)]
c = [int(s) for s in input().split()]

points = 0

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

print(points)

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

score = 0
item = float('inf')
for a in A:
    score += B[a-1]
    if item+1 == a:
        score += C[a-2]
    item = a
print(score)

Solution (Python):
num = int(input())
bangou = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
addit = list(map(int ,input().split()))
a = 0
for i, youso in enumerate(bangou):
    a += manzoku[youso-1]
    if i == 0:
        pass
    else:
        if bangou[i-1] == youso - 1:
            a += addit[bangou[i-1]-1]
print(a)

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


def solve(N, A, B, C):

    ans = 0
    pre = -1000
    for i in range(N):
        a = A[i] - 1
        ans += B[a]

        if pre + 1 == a:
            ans += C[pre]

        pre = a

    return ans


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

    print(solve(N, A, B, C))


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

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

point = []

for i in range(len(A)):
    ryori = A[i]
    point.append(B[ryori - 1])
    if i > 0:
        if ryori - A[i - 1] == 1:
            point.append(C[ryori - 2])

print(sum(point))

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

import sys














def main():
    n = int(sys.stdin.readline().rstrip())
    
    eating_order = [int(x) for x in sys.stdin.readline().split()]
    base_point = sum([int(x) for x in sys.stdin.readline().split()])
    bonus_points = [0] + [int(x) for x in sys.stdin.readline().split()]

    total = base_point
    for i in range(n-1):
        if eating_order[i+1] == eating_order[i] + 1:
            total += bonus_points[eating_order[i]]

    print(total)

if __name__ == "__main__":
    main()

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

Solution (Python):
N = int(input())
An = list(map(int,input().split(' ')))
Bn = list(map(int,input().split(' ')))
Cn = list(map(int,input().split(' ')))

sum_count = 0
previous_number = -100
for a in An:
    sum_count += Bn[a-1]
    if previous_number + 1 == a:
        sum_count += Cn[previous_number-1]
    previous_number = a
print(sum_count)

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

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


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

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

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

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

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()]
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):
def inpl():
    return list(map(int, input().split()))


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

A = [(i, A[i]) for i in range(N)]
A.sort()

ans = sum(B)
for a, na in zip(A, A[1:]):
    if a[1] + 1 == na[1]:
        ans += C[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 = sum(b)
count = 100
for i in a:
  if i - 1 == count:
    ans += c[i - 2]
  count = 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()))

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

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

Solution (Python):
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
*c, = 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] == a[i-1] + 1:
        ans += c[a[i-1]-1]
print(ans)

Solution (Python):
N = int(input())
A =list(map(int,input().split()))
B =list(map(int,input().split()))
C =list(map(int,input().split()))
sum=0
old =100
sum_val =0
for x in A:
    B_index = x-1
    sum +=B[x-1]
    if B_index ==old+1:
        sum +=C[old]
    old = B_index
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()))
score = 0

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

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

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

manzoku=0

for i in range(n):
  ai = a_list[i]
  if i==0:
    manzoku += b_list[ai-1]
  elif ai == a_list[i-1]+1:
    manzoku += b_list[ai-1] + c_list[ai-2]
  else:
    manzoku += b_list[ai-1]
print(manzoku)

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

for a_idx, i in enumerate(a):
  res += b[i]
  if a_idx >= 1 and (a[a_idx - 1] + 1 == i):
    res += c[i-1]

print(res)

Solution (Python):
n = int(input())
alis = list(map(int,input().split()))
blis = list(map(int,input().split()))
clis = list(map(int,input().split()))

sum = 0
for i in range(n):
    sum += blis[alis[i]-1]
    if i != 0:
        if alis[i] == alis[i-1] +1:
            sum += clis[alis[i-1]-1]
print(sum)

Solution (Python):
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))
point = sum(Blist)
for i in range(0, N - 1):
    if Alist[i + 1] == Alist[i] + 1:
        point += Clist[Alist[i] - 1]

print(point)

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

Solution (Python):
N = int(input())
AS = list(map(int, input().split()))
BS = list(map(int, input().split()))
CS = list(map(int, input().split()))

total = 0
last = None
for x in AS:
    total += BS[x - 1]
    if x - 1 == last:
        total += CS[x - 2]
    last = x
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()))

delisious = 0

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

print(delisious)