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):
if __name__ == '__main__':
    N = int(input())    
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

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

Solution (Python):
def main():
    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 = B[A[0]]
    for n in range(1, N):
        ans += B[A[n]]
        if A[n] - A[n-1] == 1:
            ans += C[A[n-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(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(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 = 0
prev = -5

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

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
a = readl()
b = readl()
c = readl()

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

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

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    result = 0
    i_before = -100
    for i in A:
        j = i - 1
        result += B[j]
        if j == i_before + 1:
            result += C[j - 1]
        i_before = j
    print(result)



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    B = [int(next(tokens)) for _ in range(N)]  
    C = [int(next(tokens)) for _ in range(N - 1)]  
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Solution (Python):
import math
import queue

mod = 1e9+7

def swap(a,b):
    return (b,a)

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

def divisors(a):
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

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

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

Solution (Python):
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = []
b = []
c = []

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

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

satisfied = 0

prev = -10
for i in range(N):
	a = a_list[i]
	satisfied += b_list[a - 1]
	if prev + 1 == a:
		satisfied += c_list[prev - 1]
	prev = a

print(satisfied)

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

Solution (Python):


import sys



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


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


print(ans)

Solution (Python):
n = int(input())
dishes = [int(x) - 1 for x in input().split()]
scores = [int(x) for x in input().split()]
plusscores = [int(x) for x in input().split()]

result = 0
prev_d = -100
for d in dishes:
  result += scores[d]
  if prev_d + 1 == d:
    result += plusscores[prev_d]
  prev_d = d

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()))
pre = 100
ans = 0

for i in a:
    ans += b[i-1]
    if i == pre + 1:
        ans += c[i-2]
    pre = i
print(ans)

Solution (Python):
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left

class Solution:
    def main(self):
        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()))

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

if __name__ == '__main__':
    Solution().main()

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

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

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


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

ans=0
before=-1

for i in a:
	ans+=b[i-1]
	if before+1==i:
		ans+=c[i-2]
	before=i
print(ans)

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

previous = -1
satisfaction = 0

for a in A[1:]:
    satisfaction += B[a]
    if previous == a-1:
        satisfaction += C[a-1]
    previous = a

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

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

cnt = 0
pre = -10
for i in range(N):
    a = A[i] - 1
    cnt += B[a]
    if pre+1 == a:
        cnt += C[pre]
    pre = a
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()))
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=[0]+list(map(int,input().split()))
C=[0]+list(map(int,input().split()))
s=B[A[0]]
for i in range(1,n):
  s+=B[A[i]]
  if A[i]==A[i-1]+1:
    s+=C[A[i]-1]
print(s)

Solution (Python):
N = int(input())
Ryori = [[int(i) for i in input().split()] for j in range(3)]

ans = 0
before_eat = -1
for i in range(N):
    a = Ryori[0][i] - 1
    b = Ryori[1][a]
    c = Ryori[2][before_eat] if before_eat != -1 and a == before_eat + 1 else 0
    before_eat = a
    ans += b + c
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_i = 100
for p in range(n):
  i = a[p]
  ans += b[i-1]
  if i >= 2 and pre_i+1 == i:
    ans += c[pre_i-1]
  pre_i = i
print(ans)

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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
a_lst = [int(x) for x in stdin.readline().rstrip().split()]
b_lst = [int(x) for x in stdin.readline().rstrip().split()]
c_lst = [int(x) for x in stdin.readline().rstrip().split()]
val = 0
prev = -100

for a in a_lst:
  val += b_lst[a-1]
  if prev + 1 == a:
    val += c_lst[a-2]
  prev = a
 
print(val)

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 = [int(x)-1 for x in input().split()]
B_list = [int(x) for x in input().split()]
C_list = [int(x) for x in input().split()]
ans = 0
prevA = -100
for A in A_list:
    ans += B_list[A]
    if (A == prevA+1):
        ans += C_list[prevA]
    prevA = 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
pre = -1
for i in range(n):
    ans += b[a[i] - 1]
    if pre == a[i] - 1:
        ans += c[pre - 1]
    pre = a[i]
print(ans)

Solution (Python):
n=int(input())
jun=list(map(int,input().split()))
lis=list(map(int,input().split()))
add=list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=lis[i]
for i in range(n-1):
    if jun[i]+1==jun[i+1]:
        ans+=add[jun[i]-1]

print(ans)

Solution (Python):
import sys, math

def main():
    N = int( sys.stdin.readline())
    *A, = map(int, sys.stdin.readline().split())
    *B, = map(int, sys.stdin.readline().split())
    *C, = map(int, sys.stdin.readline().split())

    ans = 0
    last = -100
    for a in A:
        ans += B[a-1]
        if a == last + 1:
            ans += C[last -1]
        last = a

    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = inpl()
B = inpl()
C = inpl()
prev = -1
ans = sum(B)
for i in range(N):
    if A[i] == prev + 1:
        ans += C[prev-1]
    prev = 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(lambda x:int(x)-1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

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()))
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,B,C=([int(x) for x in input().split()] for _ in range(3))
A=[x-1 for x in A]
print(sum(B) + sum(C[A[i]] for i in range(N-1) if A[i]+1 == A[i+1]))

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

ans = 0
pre = 100
for i in Alist:
    ans += Blist[i-1]

    if i - pre == 1:
        ans += Clist[pre-1]

    pre = i

print(ans)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
aaa = na()
bbb = na()
ccc = na()
ans = 0
pr = -100
for i in range(n):
    a = aaa[i] - 1
    ans += bbb[a]
    if a == pr + 1:
        ans += ccc[pr]
    pr = 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 = sum(B)
tmp = A[0]
for i in range(1, N):
    if tmp + 1== A[i]:
        ans += C[tmp - 1]
    tmp = A[i]

print (ans)

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

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

print(sum(B)+a)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
before = -10
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 = [int(x) for x in input().split(' ')]
B = [int(x) for x in input().split(' ')]
C = [int(x) for x in 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):
import numpy as np

N = int(input())  
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)

ans = np.sum(B)

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

Solution (Python):
n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))

ans = sum(bbb)
for a1, a2 in zip(aaa, aaa[1:]):
    if a1 == a2 - 1:
        ans += ccc[a1 - 1]
print(ans)

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

p = 0

for i in range(N):
    b_index = a_list[i] - 1
    p += b_list[b_index]
    if i != 0:
        if a_list[i] - 1 == a_list[i-1]:
            c_index = a_list[i] - 2
            p += c_list[c_index]
print(p)

Solution (Python):
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    B = InputToInt()
    C = InputToInt()

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

Solution (Python):
n = int(input())
a = [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
tmp = -10
for i in a:
	ans+=b[i-1]
	if tmp+1 == i-1:
		ans+=c[i-2]
	tmp = i-1

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

cnt = 0
temp = -1

for x in a_list:
    cnt += b_list[x-1]
    if temp == x -1:
        cnt += c_list[temp-1]
    temp = x
    
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
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()))
m = B[A[0]-1]
for i, j in zip(A, A[1:]):
    m += B[j-1]
    m += C[i-1] if j-i==1 else 0
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()))
res=sum(B)
for i in range(1, N):
  if A[i]==A[i-1]+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()))

prev_a = 0
satisfaction = sum(B)
for a in A:
    if prev_a + 1 == a and prev_a > 0:
        satisfaction += C[prev_a-1]
    prev_a = a

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

ct=0
at=-100
for a in A:
    ct+=B[a-1]
    if a==at+1:
        ct+=C[a-2]
    at=a

print(ct)

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

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()]
ans = 0
pre = None
for a in A:
    ans += B[a-1]
    if pre == a-1:
        ans += C[a-2]
    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()))
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
input=sys.stdin.readline

def main():
    _ = 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 tmp + 1 == a:
            ans += C[a-2]
        tmp = a

    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    s = 0
    before = 0
    for ai in a:
        s += b[ai - 1]
        if ai == before + 1 and before > 0:
            s += c[before - 1]
        before = ai
    print(s)


if __name__ == "__main__":
    resolve()

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

print(ans)

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

ans = sum(b)
diff = np.diff(a)
mask = diff == 1
mask2 = a[mask]-1
ans += np.sum(c[mask2])
print(ans)

Solution (Python):
def resolve():
    n=int(input())
    A=list(map(lambda x:int(x)-1,input().split()))
    ans=sum(map(int,input().split()))
    C=list(map(int,input().split()))

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

    print(ans)
resolve()

Solution (Python):
import math
N = input()
As =  list(map(int,input().split(" ")))
Bs =  list(map(int,input().split(" ")))
Cs =  list(map(int,input().split(" ")))

ans = 0
for i,a in enumerate(As):

    ans += Bs[a-1]

    if i != 0:
        if a - 1 == As[i-1]:
            ans +=Cs[a - 2]



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

print(ans)

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

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

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

total = 0
prev = None
for A in As:
  total = total + Bs[A-1]
  if prev and prev + 1 == A:
    total = total + Cs[prev-1]
  prev = 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()))

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

Solution (Python):
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] + list(map(int, input().split()))
    C = [0] + list(map(int, input().split()))
    last = -1
    ans = 0
    for i in A:
        ans += B[i]
        if last + 1 == i:
            ans += C[last]
        last = i
    print(ans)
solve()

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

ans = 0
before_A = -1
for A in A_list:
    ans += B_list[A - 1]
    if A - before_A == 1:
        ans += C_list[before_A - 1]
    before_A = 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, Ai in enumerate(A):
    Bi = B[Ai - 1]
    ans += Bi
    if i == 0: continue
    
    if A[i - 1] + 1 == Ai:
        ans += C[A[i - 1] - 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()))

    lastIdx = -1
    sc = 0

    for a in A:
        sc += B[a-1]
        if a == lastIdx + 1:
            sc += C[lastIdx-1]

        lastIdx = a

    print(sc)


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

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

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

result = 0
pre = -2

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

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

res = 0
cur = A[0]
for a in range(N-1):
    if A[a+1] == cur + 1:
        res += C[A[a+1]-2]
    cur = A[a+1]
res += sum(B)
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
last_eat = -1
for a in A:
    ans += B[a - 1]
    if a == last_eat + 1:
        ans += C[last_eat - 1]
    last_eat = 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
check=1000
for i in range(n):
    j=a[i]
    ans+=b[j-1]
    if check+1 == j:
        ans+=c[check-1]
    
    check=j
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 = -10
for ai in a:
    ans += b[ai-1]
    if tmp+1 == ai:
        ans += c[tmp-1]
    tmp = ai
    
print(ans)

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

Solution (Python):
import sys
def input():
	return sys.stdin.readline().strip()


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

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

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

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

preva=-1
ans=0

for a in alist:
    idx=a-1
    ans+=blist[idx]
    if a==preva+1:
        ans+=clist[preva-1]
    preva=a

print(ans)

Solution (Python):
import sys
import collections
sys.setrecursionlimit(4100000)

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(1,len(a)):
    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()))

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

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

ans = sum(b)

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

print(ans)