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_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
c_l = list(map(int,input().split()))

score=0
for i in range(n):
  score+=b_l[a_l[i]-1]
  if(i>0):
    if(a_l[i]-a_l[i-1]==1):
      score+=c_l[a_l[i-1]-1]  
   
print(score)

Solution (Python):


from collections import Counter,deque


from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
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
before=-1
for i in range(n):
    ans+=b[a[i]-1]
    if a[i]-1==before:
        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-1):
    if A[i]+1==A[i+1]:
        ans+=C[A[i]-1]
        
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()))
b_sum=sum(b)
c_sum=0

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

print(b_sum + c_sum)

Solution (Python):


import sys
import copy

sys.setrecursionlimit(1000000)







N = int(input())

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

ans = sum(B)

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

print(ans)

Solution (Python):
import numpy as np 

listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

sum=np.sum(listA[2])
for i in range(len(listA[1])-1):
  if listA[1][i+1]-listA[1][i]==1:
    b=listA[1][i]-1
    sum+=listA[3][b]
    
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()]

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

Solution (Python):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

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

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

    print(ans)


sol()

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

Solution (Python):

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


if __name__ == "__main__":
    main()

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

satify = 0

for i in range(len(a)):
    if i == 0 or a[i-1] == n or a[i]-1 != a[i-1]:
        satify += b[a[i]-1]
    else:
        satify += b[a[i]-1] + c[a[i-1]-1]
        
print(satify)

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

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

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

Solution (Python):
n = int(input())
a_list = [int(s) for s in input().split()]
b_list = [int(s) for s in input().split()]
c_list = [int(s) for s in input().split()]

manzokudo = 0
prev_a = 0

for jun in a_list:
    manzokudo = manzokudo + b_list[jun-1]
    if jun > 1:
        if jun == prev_a + 1:
            manzokudo = manzokudo + c_list[prev_a-1]
    prev_a = jun
        
print(manzokudo)

Solution (Python):
s=input()
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=list(map(int,input().split()))
a=len(t)
b=len(u)
d=0
for i in range(b):
  d=d+u[i]
for j in range(a-1):
  if t[j]+1==t[j+1]:
    e=t[j]-1
    d=d+v[e]
print(d)

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

list_A = list(map(int,input().split()))
list_B = list(map(int,input().split()))
list_C = list(map(int,input().split()))

b_val = 0

for i in range(N):
    aaa = list_A[i]
    b_val += list_B[aaa-1]
    if i ==0:
        continue
    elif aaa == list_A[i-1]+1:
        b_val += list_C[list_A[i-1]-1]
print(b_val)

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):
    score += B[A[i]-1]
    if i != 0 and A[i] == A[i-1] + 1:
        score += C[A[i-1]-1]

print(score)

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

print(res)

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

Solution (Python):
N = int(input())
Ai = list(map(int,input().rstrip().split(" ")))
Bi = list(map(int,input().rstrip().split(" ")))
Ci = list(map(int,input().rstrip().split(" ")))
previous = -100
satisfied = 0
for current in Ai:
  satisfied += Bi[current - 1]
  if current == previous + 1:
    satisfied += Ci[previous - 1]
  previous = current
print(satisfied)

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

ans = sum(b)
for x, y in zip(a[:-1], a[1:]):
    if x + 1 == y:
        ans += c[x-1]
print(ans)

Solution (Python):
N=int(input())
ans=0;last=-1;same=[]
for A in list(map(int,input().split())):
    if A==last+1:
        same.append(last)
    last=A
for B in list(map(int,input().split())):
    ans+=B
i=1
for C in list(map(int,input().split())):
    if i in same:
        ans+=C
    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()))
m = 0
for i, a in enumerate(A):
    m += B[a-1]
    if i > 0:
        if A[i-1] + 1 == A[i]:
            m += C[a-2]
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(N):
  sum += b[a[i]-1]
  if(i != 0):
    if(a[i] - a[i-1] == 1):
      sum += int(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()]
sum1=0
for i in range(n):
	sum1+=b[a[i]-1]
	if(i!=n-1):
		if(a[i+1]-a[i]==1):
			sum1+=c[a[i]-1]
print(sum1)

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


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

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

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(v) for v in input().split(' ')]
B = [int(v) for v in input().split(' ')]
C = [int(v) for v in input().split(' ')]

point = 0
prev_dish = -1
for i in range(0, N):
    dish = A[i]
    point += B[dish - 1]

    if prev_dish + 1 == dish:
        point += C[prev_dish - 1]
    prev_dish = dish

print(point)

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

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

print(answer)

Solution (Python):
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += Blist[i]
for i in range(N-1):
    if Alist[i]+1 == Alist[i+1]:
        
        ans += Clist[Alist[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()))

cplus = 0

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

print(sum(B) + cplus)

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

print(s)

Solution (Python):
nums = list(map(int, input().split()))
orders = list(map(int, input().split()))
su1 = list(map(int, input().split()))
su2 = list(map(int, input().split()))

total = 0
lastmeal = 0
for i, num in enumerate(orders):
    if i==0:
        total += su1[num-1]
    else:
        if 1 == num - lastmeal and lastmeal != len(su2)+1:
            total += su1[num-1] + su2[lastmeal-1]
        else:
            total += su1[num-1]
    lastmeal = num
print (total)

Solution (Python):
N = int(input())
a = input().split(' ')
b = input().split(' ')
c = input().split(' ')

total_point = 0
before_eat = -2

for i in range(N):
  now_eat = int(a[i]) - 1
  point = int(b[now_eat])
  if now_eat == before_eat + 1:
    additional_point = int(c[before_eat])
  else:
    additional_point = 0
  total_point = total_point + point + additional_point
  before_eat = now_eat
  
print(total_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
mae = -1
for i in range(n):
    a = A[i]
    ans += B[a-1]
    if a - 1 == mae:
        ans += C[mae-1]
    mae = 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
ans = sum(b)

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

print(str(ans))

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

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

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

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

previous_dish = -100
satisfaction_level = 0

for index in range(n):
    satisfaction_level += b[a[index] - 1]
    if previous_dish + 1 == a[index]:
        satisfaction_level += c[previous_dish - 1]

    previous_dish = a[index]

print(satisfaction_level)

Solution (Python):
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    al = list(map(int, input().split()))
    for i in range(n):
        al[i] -= 1
    bl = list(map(int, input().split()))
    cl = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        ans += bl[al[i]]
        if i > 0:
            if al[i-1] + 1 == al[i]:
                ans += cl[al[i-1]]

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
cList = list(map(int, input().split()))
ans = sum(bList)
before = -2
for i in range(0, n):
    a = aList[i] - 1
    if before + 1 == a:
        ans = ans + cList[before]
    before = a

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

Cplus=0
for n in range (N-1):
  if Alist[n+1] == Alist[n]+1:
    Cplus += Clist[Alist[n]-1]

print(sum(Blist)+Cplus)

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

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

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

Solution (Python):
def _input():
    n = int(input())
    a = input().split()
    foods = convrt_to_int(a)
    b = input().split()
    satisfaction = convrt_to_int(b)
    c = input().split()
    add = convrt_to_int(c)
    return foods, satisfaction, add

def convrt_to_int(array):
    int_array = []
    for i in array:
        int_array.append(int(i))
    return int_array

def calc(foods, satisfaction, add):
    counter = 0
    total = satisfaction[foods[0] - 1]
    for i in foods:
        if counter == 0:
            counter += 1
            continue
        if i == foods[counter - 1] + 1:
            option = optional(i - 1,add)
            total += satisfaction[i - 1]
            total += option
        else:
            total += satisfaction[i - 1]
        counter += 1
    return total

def optional(index, add):
    return add[index - 1]


if __name__ == "__main__":
    foods, satisfaction, add = _input()
    print(calc(foods, satisfaction, add))

Solution (Python):
num = int(input())
A_i = [ int(x) for x in input().split()]
B_i = [ int(x) for x in input().split()]
C_i = [ int(x) for x in input().split()]
 
prev = 50
result = 0
for a in A_i:
  result += B_i[a-1]
  if a-1 == prev:
    result += C_i[prev-1]
  prev = a
  
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()))

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

print(S)

Solution (Python):
def intminus(a):
    return int(a) - 1


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


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

print(ans)

Solution (Python):
total_dish = int(input())
dish_order = list(map(int, input().split()))
satis_B = list(map(int, input().split()))
satis_C = list(map(int, input().split()))

ans = 0
for i in range(total_dish):
  ans = ans + satis_B[dish_order[i]-1]
  if dish_order[i] - dish_order[i-1] == 1 and i != 0:
    ans = ans + satis_C[dish_order[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()))
before = N
result = 0
for i in range(N):
  result += B[A[i] - 1]
  if before + 1 == A[i] - 1:
    result += C[before]
  before = A[i] - 1
print(result)

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

Solution (Python):
N=int(input())
A,B,C=[list(map(int,input().split())) for _ in range(3)]
A=[x-1 for x in A]
ans=sum(B)
p=A[0]

for i in A[1::]:
    if i==p+1:
        ans+=C[p]
    p=i
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()))
count = 0
for i in range(n):
    index=a_list[i]
    count += b_list[index - 1]

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

print(ans)

Solution (Python):
def find(A,B,C):
    A=[x-1 for x in A]
    ans=B[A[len(A)-1]]
    for i in range(len(A)-1):
        now=A[i]
        next_one=A[i+1]
        if next_one==now+1:
            ans+=C[now]
        ans+=B[A[i]]
    return ans

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

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

Solution (Python):

n = int(input())

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

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

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

m = n-1
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 = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

sat = 0

prev_dish = -1
for i, dish in enumerate(A[1:]):
  sat += B[dish]
  if prev_dish == dish-1:
    sat += C[prev_dish]
  prev_dish = dish
  

print(sat)

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

ans = sum(B)

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

print('{}'.format(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):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

C.append(0)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
manzoku = 0
prev = 0
 
for a in A:
  manzoku += B[a-1]
  if prev+1 == a and prev != 0:
    manzoku += C[prev-1]
  prev = a
print(manzoku)

Solution (Python):
import sys
sys.setrecursionlimit(int(1e6))

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 a in A:
    i = a - 1
    ans += B[i]
    if (prev + 1) == a:
        ans += C[i-1]
    prev = a

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    a = sum([B[i - 1] for i in A])
    c = sum([C[i - 1] for i, j in zip(A[:-1], A[1:]) if i == j - 1])
    print(a + c)


if __name__ == "__main__":
    main()

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

ans = 0
pre = -2
for a in A:
    ans += B[a]
    if pre == a - 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()))
mem = set()
s=0
last =-5
for v in a:
    s+=b[v-1]
    if last+1 ==v and last<n:
        s+=c[last-1]
    last=v
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
prev = -1
for i in range(N):
    idx = A[i] - 1
    if (A[i] == prev + 1):
        ans += C[idx - 1]
    ans += B[idx]
    prev = A[i]
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()]

point = 0
i = 0

while  i < n :
    point += B[A[i] - 1]
    if i > 0 and A[i-1] == A[i] - 1 :
        point += C[A[i-1]-1]
    i += 1

print(point)

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

Solution (Python):
numberN = int(input())
seqAi = list(map(int,input().split()))
benefitBi = list(map(int,input().split()))
increaseCi = list(map(int,input().split()))






totalBenefit = 0
for k,seq in enumerate(seqAi):

    totalBenefit += benefitBi[seq -1]

    if k == 0:
        continue

    if seq == ( seqAi[k -1] +1 ):
        totalBenefit += increaseCi[seq -2]

print(totalBenefit)

Solution (Python):
N=int(input())
A=[int(_) for _ in input().split()]
B=[int(_) for _ in input().split()]
C=[int(_) for _ in input().split()]
ans=0
a=10000000
for i in A:
  ans+=B[i-1]
  if i==a+1:
    ans+=C[a-1]
  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):
    k = A[i]
    ans += B[k-1]
    if i < N-1:
        if A[i+1] == k+1 and k != N:
            ans += C[k-1]
        else:
            pass
    else:
        pass
print(ans)

Solution (Python):
from sys import stdin

n = int(input())
a = [ int(x) for x in stdin.readline().rstrip().split()]
b = [ int(x) for x in stdin.readline().rstrip().split()]
c = [ int(x) for x in stdin.readline().rstrip().split()]
cnt = 0

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

print(cnt)

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

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

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

print(result)

Solution (Python):
import numpy as np
n=int(input())
a=np.array([int(x) for x in input().split()])
b=np.array([int(x) for x in input().split()])
c=np.array([int(x) for x in input().split()])

tf = np.array([a[i+1] - a[i] == 1 for i in range(n-1)])

print(sum(b) + sum([c[j-1] for j in a[tf]]))

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]

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

print(ans)

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

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

A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
result = 0
prev = 0

for i in range(N):
    pointer = int(A[i])
    result += int(B[pointer-1])
    if i != 0 and pointer - prev == 1:
        result += int(C[prev-1])
    prev = pointer

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

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

result = 0
j = 0
isFirst = True
for i in a:
  m = int(i) - 1
  result += int(b[m])
  if (not (isFirst)) and (j + 1 == m):
      result += int(c[j])
  j = m
  isFirst = False
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()))
sum = 0
for i in range(N):
  sum += int(b[a[i]-1])
  if(i != 0):
    if(a[i] - a[i-1] == 1):
      sum += int(c[a[i-1]-1])
print(sum)

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

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

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

satis = sum(B) 

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

		satis += C[j]

print(satis)

Solution (Python):
n = int(input())
ans = 0
pre = -5
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

for i in range(n):
  ans += b_list[a_list[i] - 1]

  if pre == a_list[i] - 1:
    ans += c_list[a_list[i] - 2]
  pre = a_list[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()))

point = 0
memory = -10
for cnt in range(n):
    point += b[a[cnt] - 1]
    if memory + 1 == a[cnt] - 1:
        point += c[a[cnt] - 2]
    memory = a[cnt] - 1

print(point)