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

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

Solution (Python):




 
from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul,itemgetter
from bisect import* 
from heapq import* 
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)

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

            
if __name__ == '__main__':
    main()

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

A = []
B = []
C = []

for z in a:
  A.append(int(z))

for x in b:
  B.append(int(x))
  
for y in c:
  C.append(int(y))

manzokudo = 0

for j in range(len(A)):
  manzokudo += B[A[j] - 1]
  try:
    if (A[j] - 1 == A[j-1]) and (j-1 > -1): 
      manzokudo += C[A[j] - 1 - 1]
  except:
    pass
  
print(manzokudo)

Solution (Python):
n = int(input())
a = [list(map(int,input().split())) for l in range(3)]
mnpk = 0
fl = 0
for i in range(n):
  b = a[0][i] - 1
  mnpk = mnpk + a[1][b]
  if fl == 1:
    if a[0][i-1] == b:
      mnpk = mnpk + a[2][b-1]
  else:
    fl = 1
 
print(mnpk)

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

pre_index = 99

sum_point = 0
for index in a_list:
    sum_point += b_list[index - 1]
    
    if (index - pre_index == 1):
        sum_point += c_list[pre_index - 1]
    
    pre_index = index

print(sum_point)

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

res = sum(b_list)

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

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

for count in range(n):
    satisfaction_point += b_list[a_list[count] - 1]
    
    if count < n - 1:
        if a_list[count] + 1 == a_list[count + 1]:
            satisfaction_point += c_list[a_list[count] - 1]

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

print(ans + 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()))

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

Solution (Python):
N = int(input())
A = [int(item) for item in input().split()]
B = [int(item) for item in input().split()]
C = [int(item) for item 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):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )



import random


def main():
    n = int(input())
    t_order = list(map(int, input().split()))
    happiness = list(map(int, input().split()))
    additional_hpns = list(map(int, input().split()))
    for i in range(len(happiness)):
        t_order[i]=t_order[i]-1
        
    sum=0
    for i in range(n):
        sum+=happiness[i]
        
        if i!=0:
            if t_order[i] == t_order[i-1] + 1:
                sum+=additional_hpns[t_order[i-1]]
                
    print(sum)
    
    return

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





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

for i in a:
    if i - a[a.index(i)-1] == 1 and a.index(i)-1 >= 0:
        ans=ans+b[i-1]+c[i-2]
    else:
        ans+=b[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(" ")))
score = 0

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

s = 0
for i in range(len(A)):
    s += B[i - 1]
    if i < len(A) - 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 = 0
pre_a = 0
for i, a in enumerate(A):
    sat += B[a-1]
    if i > 0 and pre_a == a -1:
        sat += C[pre_a-1]
    pre_a = a
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()))

i = 0
point = 0
while i < len(A):
    point += B[A[i]-1]
    if i != 0 and A[i-1] + 1 == A[i]:
        point += C[A[i-1]-1]
    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 = 0
tmp_old = A[0] - 1
for i in range(N):
    ans += B[A[i] - 1]
    tmp = A[i] - 1
    if tmp == tmp_old + 1:
        ans += C[tmp_old]
    tmp_old = tmp
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 = b[a[0]-1]
p = a[0]-1
for i in a[1:]:
    index = i-1
    sum += b[index]
    if p != n-1 and index == p+1:
        sum += c[p]
    p = 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()))

total = 0
before = -1
for i in a:
    if before + 1 == i: total = b[i - 1] + c[i - 2] + total
    else: total = b[i - 1] + total
    before = i

print(total)

Solution (Python):
def main():
  n = int(input())
  a_s = list(map(int, input().split(' ')))
  b_s = list(map(int, input().split(' ')))
  c_s = list(map(int, input().split(' ')))
  ans = 0
  for i in range(n):
    ans += (b_s[a_s[i]-1] + c_s[a_s[i]-1]) if (i != n-1 and a_s[i+1]) == (a_s[i] + 1) else b_s[a_s[i]-1]
  print(ans)


if __name__ == '__main__':
  main()

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

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

Solution (Python):
n = input()

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))



before_num = 0
sum = 0
for a in a_list:
    sum += b_list[a-1]
    if before_num > 0 and (before_num == (a-1)):
        sum += c_list[before_num-1]
    before_num = a

print(sum)

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

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

ans = 0
check = []
for i in a:    
    ans += b[i-1]
    check.append(i)
    if check[check.index(i)-1] + 1 == check[check.index(i)]:
        ans += c[i-2]
    
print(ans)

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

ans=0
prev=-1
for _a in a:
    ans+=b[_a-1]
    if prev+1 == _a:
        ans+=c[_a-2]
    prev=_a

print(ans)

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

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

Solution (Python):
import math

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

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

ans = satis
print(ans)

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

s = 0
last_ai = None
for ai in A:
    s += B[ai]
    if last_ai is not None and ai - last_ai == 1:
        s += C[last_ai]
    last_ai = ai

print(s)

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

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

print(manzoku)

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()))
    
sum_b = sum(list_b)

sum_c = 0
for i in range(0,len(list_a)-1,1):
  if list_a[i+1] == list_a[i] + 1:
    sum_c += list_c[list_a[i]-1]

print( sum_b + sum_c)

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

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

Solution (Python):
n = int(input())
a = [int(number) for number in input().split(' ')]
b = [int(number) for number in input().split(' ')]
c = [int(number) for number in input().split(' ')]

point = 0
last_dish = 0

for i in range(len(a)):
  dish = a[i]
  point += b[dish-1]
  if 0 < i and (dish - last_dish) == 1:
    point += c[last_dish-1]
  last_dish = dish

print(point)

Solution (Python):
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]
C_list = [int(i) for i in input().split()]
total = 0
prev_a = -2
for a in A_list:
    total += B_list[a-1]
    if a == prev_a + 1:
        total += C_list[prev_a-1]
    prev_a = a
print(total)

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

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

SaticefactonalPoint = 0

for i in range(N):
    EatingDish = Alist[i]
    SaticefactonalPoint += Blist[EatingDish-1]
    if i >= 1:
        HavingEatenDish = Alist[i-1]
        if HavingEatenDish + 1 == EatingDish:
            SaticefactonalPoint += Clist[HavingEatenDish-1]

print(SaticefactonalPoint)

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

sum = 0

for i, ai in enumerate(a):
    sum += b[ai-1]
    try:
        if a[i] == a[i+1] -1:
            sum += c[ai-1]
    except:
        break
print(sum)

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

sum = 0
for i in range(n-1):
    sum+=b_list[a_list[i] - 1]
    if a_list[i+1] - a_list[i] == 1:
        sum+=c_list[a_list[i] - 1]
sum+=b_list[a_list[-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()))

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

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
before = None
for i in range(N):
    num = A[i] - 1
    satisfaction += B[num]
    try:
        if A[i+1] - 1 == num + 1:
            satisfaction += C[num]
    except:
        pass
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 = 0
for i in A:
    sum += B[i - 1] 

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

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

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

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

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

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

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

ans = 0

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

    else:
        ans = ans + B[A[i]-1]
        if A[i]-A[i-1] == 1:
            ans = ans + C[A[i]-2]


print(ans)

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

Solution (Python):

N = int(input())

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

ans = 0

pre = 2 * N

for i in A :
    ans += B[i-1]
    if (pre == (i-2) ):
        ans += C[i-2]
    pre = i-1

print(ans)

Solution (Python):
N=int(input())
Ai=list(map(int,input().split()))
Bi=list(map(int,input().split()))
Ci=list(map(int,input().split()))

sf=0
for i in range(N):
    sf+=Bi[i]
for i in range(N-1):
    if Ai[i]+1==Ai[i+1]:
        sf+=Ci[Ai[i]-1]
print(sf)

Solution (Python):
n = int(input())
menu = [int(x) for x in input().split()]
score = [int(x) for x in input().split()]
additional = [int(x) for x in input().split()]

total = 0
for i in range(n):
  total +=score[menu[i]-1]
  if i + 1 < n:
    if menu[i] + 1 ==menu[i+1]:
      total += additional[menu[i] -1 ]
print(total)

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


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


for i in range(1,n):
    if a[i]-a[i-1]==1:
        b.append(c[a[i]-2])
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()))
m = 0
for i in range(N):
    m += B[A[i] - 1]
for t in range(N-1):
    if A[t] + 1 == A[t + 1]:
        m += C[A[t] - 1]
print(m)

Solution (Python):
import sys
sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

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

Solution (Python):
N = int(input())
A_s = list(map(int, input().split()))
B_s = list(map(int, input().split()))
C_s = list(map(int, input().split()))
pa = -1
answer = 0
for a in A_s:
    if pa+1 == a:
        answer += C_s[pa-1]
    answer += B_s[a-1]
    pa = a
print(answer)

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

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

manzoku=sum(B)

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

print(manzoku)

Solution (Python):


import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A, B, C):
    sat = B[A[0]]
    for i in range(1, N):
        sat += B[A[i]]
        if A[i - 1] + 1 == A[i]:
            sat += C[A[i - 1]]
    return sat


def main():
    N = int(inp())
    A = [int(e) - 1 for e in inp().split()]
    B = [int(e) for e in inp().split()]
    C = [int(e) for e in inp().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()))

ans=0
pre=-100
for i in A:
    ans+=B[i-1]

    if(i-pre==1):
        ans+=C[i-2]

    pre=i

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

    sum = 0
    before = 1000
    for i in a:
        sum += b[i - 1]

        if (i - before) == 1:
            sum += c[i - 2]

        before = i

    print(sum)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))

answer = 0
before = -99

for i in range(n):
    idx = li_a[i]
    answer += li_b[idx - 1]
    if idx == before + 1:
        answer += li_c[idx - 2]
    before = idx
print(answer)

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

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

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

    ans = 0
    for i, num in enumerate(a):
        ans += b[num-1]
        if i < len(a)-1:
            if num+1 == a[i+1]:
                ans += c[num-1]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


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

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

print(ans)

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

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

print(ans)

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

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

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

prev = -10
result = 0

for i in range(N):
    n = A[i]
    result += B[n-1]
    if n == (prev + 1):
        result += C[n-2]
        
    prev = n

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

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

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

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

Solution (Python):


def solve():
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    ans = 0
    pre_a = -100
    for i, a in enumerate(As):
        ans += Bs[a-1]
        if (a-1)-1 == pre_a:
            ans += Cs[pre_a]
        pre_a = a-1
    print(ans)

if __name__ == "__main__":
    solve()

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

b_sum = sum(b_list)

for i in range(N-1):
    diff = a_list[i+1] - a_list[i]
    if diff == 1:
        b_sum = b_sum + c_list[a_list[i]-1]
    else:
        continue
    
print(b_sum)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
i = 1
manzoku = sum(B)
while N>i:
    if A[i]-A[i-1] == 1:
      j = A[i-1]
      manzoku += C[j-1]
    i += 1
print(manzoku)

Solution (Python):

from itertools import *
import sys
import time










def read_input():
	N = int(raw_input())
	A = map(int, raw_input().split())
	B = map(int, raw_input().split())
	C = map(int, raw_input().split())
	return (N, A, B, C)





N, A, B, C = read_input()
s = sum(B)
for k1, k2 in zip(A, A[1:]):
	if k1 == k2-1:
		s += C[k1-1]
print s

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

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

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

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

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

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

if __name__ == "__main__":
    main()

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

ans = sum(Bs)
for n in range(N-1):
    if As[n+1] - As[n] == 1:
        ans += Cs[As[n] - 1]
print(ans)

Solution (Python):
n = int(input())
manzoku = []
for i in range(3):
  manzoku.append(list(map(int,input().split(' '))))

mae_i = -1  
man = 0
for i in manzoku[0]:
  man += manzoku[1][i-1]

  if i == mae_i +1:

    
    man += manzoku[2][i-2]
  mae_i = i

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

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

utility = 0
prev = -1

for i in A:
    utility += B[i-1]
  
    if prev == i-1:
        utility += C[i-2]
        
    prev = i

print(utility)

Solution (Python):















num = int(input())
order = input().split()
order = [int(i) for i in order]
manzoku = input().split()
additional = input().split()

prev = -1
ans = 0
for i in order:
  ans += int(manzoku[i-1])
  if i == prev+1:
    ans += int(additional[i-2])
  prev = i
  
print(ans)