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):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

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

print(ans)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy








def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
al = inpl()
bl = inpl()
cl = inpl()
ans = 0
pre = -1
for a in al:
    ans += bl[a - 1]
    if(pre == a - 1):
        ans += cl[pre - 1]
    pre = a
print(ans)

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

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

Solution (Python):
n = int(input())
order = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
addition = list(map(int, input().split()))

index = order[0]
ans = 0

for i in order:
    ans += satisfaction[i-1]
    if i-1 == index:
        ans += addition[i-2]
    index = 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, a in enumerate(A):
    ans += B[a-1]
    if i != 0 and a == A[i-1] +1:
        ans += C[a-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=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 = [ i for i in list(map(int,input().split()))]
b = [j for j in list(map(int,input().split()))]
c = [k for k in list(map(int,input().split()))]
c.append(0)
count  = 0
prev = 0
for o in a:
    count += b[o-1]
    if o == prev +1:
        count +=c[o-2]
        prev = o
    else:
        prev = o
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 = sum(b)

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

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

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

point = 0

prev = -2

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

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

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


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

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

print(count)

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    A=list(mi())
    B=list(mi())
    C=list(mi())

    pre = INF
    ans = 0
    for i in range(N):
        a = A[i]
        b = B[a-1]
        ans += b
        if a == pre + 1:
            ans += C[a-2]
        
        pre = a

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

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

cnt=0
first_flg = True
for i in a:
    if not first_flg:
        if i-1 == before_num:
            cnt += c[i-2]
    first_flg = False
    before_num = i
print(sum(b)+cnt)

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(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()))
ans = 0
c = 0
aa = 0
for a in A:
	ans += B[a - 1]
	if a - 1 == aa:
		ans += c
	aa = a
	c = C[a - 1] if a < N else 0
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 = 100

for a in A:
  ans+=B[a-1]
  if a-bef == 1:
    ans+=C[a-2]
  bef = a
  
print(ans)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
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()]

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

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

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

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

s = 0

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

for a in A:
    ans+=B[a-1]+C[a-2]*(a-a_p==1)
    a_p=a
print(ans)

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

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

Solution (Python):
N = int(input())
A_ls = map(int, input().split(' '))
B_ls = list(map(int, input().split(' ')))
C_ls = list(map(int, input().split(' ')))

result = 0
tmp = 0
for A in A_ls:
    if (A - tmp) == 1 and tmp != 0:
        result += B_ls[A-1] + C_ls[A-2]
    else:
        result += B_ls[A-1]
    tmp = 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()))

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

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

Solution (Python):
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))
 
satis = 0
 
for i in range(len(A)):
  satis += B[A[i] - 1]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[A[i - 1] - 1]
 
print(satis)

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

Solution (Python):
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = [0]+list(map(int, input().split()))
    B = [0]+list(map(int, input().split()))
    C = [0]+list(map(int, input().split()))
    ans = 0
    prev = -1
    for i in range(1, N+1):
        dish = A[i]
        point = B[dish]
        ans += point
        if prev+1==dish:
            ans += C[prev]
        prev = dish
    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[A[i]-1] for i in range(N))
for i in range(N-1):
  if A[i+1]-1==A[i]:
    S += C[A[i]-1]
print(S)

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

Solution (Python):


n = int(input())

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

ans = b[a[0]-1]

for i, food in enumerate(a[1:]):
    ans += b[food-1]
    if a[i] == food-1:
        ans += c[food-2]

print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI_()
    B = LI()
    C = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
N = int(input())
AA = input().split()
BB = input().split()
CC = input().split()
total = 0
for i in range(len(AA)-1):
  if int(AA[i+1]) - int(AA[i]) == 1:
    
    total += int(CC[int(AA[i])-1])
    
for i in BB:
  total += int(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()))

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

p = a[0]
t = 0
for i in range(n):
    j = a[i]
    if a[i] == p + 1:
        t = t + b[j-1] + c[j-2]
    else:
        t += b[j-1]
    p = a[i]

print(t)

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

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

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

happy = sum(B)

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

print(happy)

Solution (Python):







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

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

temp = 9999
ans = 0
for i in a:
  ans += b[i-1]
  if i - temp == 1:
    ans += c[i-2]
  temp = 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
con=10000000
for i in a:
    ans+=b[i-1]
    if con+1==i :
        ans+=c[con-1]
    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

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

print(ans)

Solution (Python):
import math

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


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

resolve()

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

main()

Solution (Python):
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)):
    a = A[i]
    ans += B[a-1]
    if i > 0 and A[i-1] == a - 1:
        ans += C[a-2]


print(ans)

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

ans = sum(B)

tmp = A[0]
for a in A[1:]:
    if a == tmp+1:
        ans += C[a-2]
    tmp = a

print(ans)

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

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

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

  
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(lambda x: int(x) - 1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

Solution (Python):
N = int(input().rstrip())
A = list(map(int,input().rstrip().split()))
B = list(map(int,input().rstrip().split()))
C = list(map(int,input().rstrip().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 heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	
	n = int(input())
	a = list(map(int,input().strip().split()))[0:n]
	b = list(map(int,input().strip().split()))[0:n]
	c = list(map(int,input().strip().split()))[0:n-1]
	ans = 0
	for i in range(n):
		ans += b[i]
	for i in range(n-1):
		x = a[i]
		y = a[i+1]
		if(y == x+1):
			ans += c[x-1]
	print(ans)

Solution (Python):
n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

satisfy = 0
for i in range(n):
    satisfy += bn[an[i] - 1]

for i in range(n - 1):
    if an[i] + 1 == an[i + 1]:
        satisfy += cn[an[i] - 1]

print(satisfy)

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

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

Solution (Python):


































































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    N = int(lines[0])
    
    values_a = list(map(int, lines[1].split()))
    values_b = list(map(int, lines[2].split()))
    values_c = list(map(int, lines[3].split()))
    
    
    
    
    
    

    
    current = values_a[0]-1
    result = values_b[current]
    prev = current

    for n in range(1, N):
        current = values_a[n]-1
        result += values_b[current]
        log(f'n=[{n}], current=[{current}], prev=[{prev}]')
        if current == prev+1:
            result += values_c[prev]
        prev = current

    return [result]



def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '3 1 2', '2 5 4', '3 6']
        lines_export = [14]
    if pattern == 2:
        lines_input = ['4', '2 3 4 1', '13 5 8 24', '45 9 15']
        lines_export = [74]
    if pattern == 3:
        lines_input = ['2', '1 2', '50 50', '50']
        lines_export = [150]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(4)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

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

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

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

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

ans=0
mae=float('inf')
for i in range(n):
    if mae+1==a[i]:
        ans+=c[mae-1]
    ans+=b[a[i]-1]
    mae=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
for i, a in enumerate(A):
  res += B[a-1]
  if i != N-1:
    if A[i+1] == a + 1:
      res += C[a-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=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()))
print(sum(b + [c[a[i] - 1] for i in range(n - 1) if a[i + 1] - a[i] == 1]))

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

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

now = 0
next = 0
ans = 0

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

Solution (Python):
_ = input()
a = [int(e) for e in input().split(" ")]
b = [int(e) for e in input().split(" ")]
c = [int(e) for e in input().split(" ")]
res = 0
for i,j in enumerate(a):
  res += b[j-1]
  if i != 0 and j - a[i-1] == 1:
    res += c[j-2]
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()))

A = [a - 1 for a in A]

ans = B[A[0]]
for i in range(1, N):
    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()))
a = list(map(lambda x:x-1, a))
ans = 0
for i in range(n):
  ans += b[a[i]]
  if i > 0 and a[i-1] + 1 == a[i]:
    ans += c[a[i-1]]
print(ans)

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

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

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
b=lnii()
c=lnii()

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

print(ans)

Solution (Python):
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() ]

k = 0
i = -1

for e in a:
    k += b[e - 1]
    if i == e-1:
        k += c[i - 1]

    i = e

print(k)

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
Bs = list(mapint())
Cs = list(mapint())
ans = 0

before = -2
for a in As:
    a -= 1
    ans += Bs[a]
    if a==before+1:
        ans += Cs[before]
    before = a
print(ans)

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

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

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

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

Solution (Python):
a=int(input())
Order = list(map(int, input().split()))
Happiness = list(map(int, input().split()))
Bonus = list(map(int, input().split()))
res = 0
mae = -1
for i in Order:
  res += Happiness[i-1]
  if mae == -1:
    pass
  elif mae == i-1:
    res += Bonus[i-2]
  mae = 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 i in range(N):
  SUM += B[A[i]-1]
  
for i in range(1,N):
  if A[i]-A[i-1]==1:
    SUM += C[A[i-1]-1]

print(SUM)

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

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

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

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