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

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

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

a = list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
c = [0]+list(map(int,input().split()))

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

print(suf)

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

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

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

sums = 0
old_i = -11 
for i in range(N):
    now_i = A[i] -1
    sums += B[now_i]
    if old_i+1 == now_i:
        sums += C[now_i-1]
    
    old_i = now_i

print(sums)

Solution (Python):
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))
aa = [a-1 for a in aa]

sat = 0
before = -2
for a in aa:
    sat += bb[a]
    if a == before + 1:
        sat += cc[before]
    before = a  
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):
    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 = 0
before = -2
for i in range(N):
    ans += B[A[i]-1]
    if A[i] - 1 == before:
        ans += C[before-1]
    before = A[i]
print(ans)

Solution (Python):
N = int(input())
dishes = list(map(int, input().split()))
cost = [0] + list(map(int, input().split()))
bonus = [0] + list(map(int, input().split()))
before = 0
sum_c = 0
for dish in dishes:
  sum_c += cost[dish]
  if before == dish - 1:
    sum_c += bonus[before]
  before = dish
print(sum_c)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
sum_=sum(B)
for i in range(N-1):
    if A[i]+1==A[i+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 = 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
import math
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N =  int(sys.stdin.readline())
A =  list(map(int, sys.stdin.readline().split()))
B =  list(map(int, sys.stdin.readline().split()))
C =  list(map(int, sys.stdin.readline().split()))

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

print(ans)

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

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

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(3)]

    ans = 0
    pre = -1
    for i in range(num):
        ans += data[1][data[0][i] - 1]
        if data[0][i] == pre + 1:
            ans += data[2][pre - 1]
        pre = data[0][i]
    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):




N = int(input())
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))

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

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

score = sum(b)
for i, j in zip(a[:-1], a[1:]):
    if j == i + 1:
        score += c[i-1]
print(score)

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

ans = 0
ex = -1
for i in range(N):
    ans += B[A[i]-1]
    if i != 0 and ex + 1 == A[i]:
        ans += C[ex-1]
    ex = 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()))
j=99
ans=0
for i in a:
    ans+=b[i-1]
    if i==j+1:ans+=c[i-2]
    j=i
print(ans)

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

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    res = 0
    prev = None
    for a in A:
        res += B[a-1]
        if prev == a-1:
            res += C[a-2]
        prev = a
    print(res)
    return



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):
def solve(a, b, c):
	ret = 0

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

		if i != 0:
			if a[i] == a[i-1] + 1:
				ret += c[a[i-1]-1]

	return ret

def main():
	n = int(input())

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

	print (solve(a,b,c))

if __name__ == "__main__":
	main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    a = LI_()
    b = LI()
    c = LI()
    r = 0
    for i in range(n):
        r += b[a[i]]
        if i < n-1:
            if a[i] + 1 == a[i+1]:
                r += c[a[i]]

    return r


print(main())

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):
    ind = A[i]-1
    res += B[ind]
    if i > 0:
        prevind = A[i-1]-1
        if prevind + 1 == ind:
            res += C[prevind] 
print(res)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True


def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    a_list = LI()
    b_list = LI()
    c_list = LI()

    base = 0
    add = 0
    past = -10
    for i in range(N):
        a = a_list[i]
        base += b_list[a-1]
        if a == past + 1:
            add += c_list[past-1]
        past = a
    print(add+base)
solve()

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 = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

temp = -1
score = 0

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

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

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

print(a)

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

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

Solution (Python):
n=int(input())
s,p=0,-2
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 a:
    s+=b[i-1]
    if p-i==-1:s+=c[i-2]
    p=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()))

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

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans = 0
    pre = -INF
    for a in A:
        ans += B[a-1]
        if pre == a-1:
            ans += C[pre-1]

        pre = a
    
    print(ans)

    return


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):
from sys import exit, stderr, stdin
input = stdin.readline


def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


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

if __name__ == "__main__":
    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(N):
    a = A[i]
    ans += B[a - 1]
    if i > 0 and a == A[i-1] + 1:
        ans += C[A[i-1]-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()))

mzoku=0
before=999

for al in alist:
    mzoku+=blist[al-1]
    if before==al-1:
        mzoku+=clist[before-1]
    before=al

print(mzoku)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    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()]

    p = -1
    s = 0
    for i in a:
        s += b[i - 1]
        if p == (i - 1):
            s += c[i - 2]
        p = i

    print(s)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



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

print(ans)

Solution (Python):
def main():
    _ = 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, i1 in zip(A, A[1:]):
        if i1 == i + 1:
            ret += C[i - 1]
    print(ret)


main()

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

ans=0
for i in range(len(B)):
    ans+=B[i]

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

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans=0
    pre=-1
    for i,(a,b) in enumerate(zip(aa,bb)):
        ans+=b
        if a==pre+1:
            ans+=c[a-2]
        pre=a
    print(ans)

main()

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

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

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

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 sys
input = sys.stdin.readline
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()))

ans = 0
tmp = -2
for i in range(N):
    if A[i]-1 == tmp + 1:
        ans += B[A[i]-1] + C[A[i]-2]
    else:
        ans += B[A[i]-1]
    tmp = 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())
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):
    ind = a[i] - 1
    ind_next = a[i+1] - 1
    if ind + 1 == ind_next:
        ans += c[ind]
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 = -100
for i in range(n):
    now = A[i] - 1
    ans += B[now]
    if (now - prev) == 1:
        ans += C[prev]
    
    prev = now

print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, C):
    ans = 0
    pa = -2
    for a in A:
        ans += B[a-1]
        if pa == a-1:
            ans += C[a-2]
        pa = a
    return ans


def main():
    N = read_int()
    A = read_int_n()
    B = read_int_n()
    C = read_int_n()
    print(slv(N, A, B, C))


if __name__ == '__main__':
    main()

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

ans = 0
for i in range(N):
    k = As[i]
    ans += Bs[k-1]
    if i < N-1 and As[i+1] == k+1:
        ans += Cs[k-1]

print(ans)

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

ans = 0
pre_order = -10
for aa in a:
    ind = aa - 1
    ans += b[ind]
    if ind - pre_order == 1:
        ans += c[pre_order]
    pre_order = ind
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 += 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
pre = -1
for a in A:
  ans += B[a-1]
  if a==pre+1:
    ans += C[pre-1]
  pre = a
  
print(ans)

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

ans = sum(B)
p = -1
for i,a in enumerate(A):
    if p+1==a:ans += C[p-1]
    p = a
print(ans)

Solution (Python):
n = int(input())
A = [int(el) for el in input().split(' ')]
B = [int(el) for el in input().split(' ')]
C = [int(el) for el in input().split(' ')]

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

print(ans)

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

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

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

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

Solution (Python):
import sys
input=sys.stdin.readline
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=100
ans=0
for x in a_list:
    if x==pre+1:
        ans+=c_list[x-2]
    ans+=b_list[x-1]
    pre=x
print(ans)

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

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = LI()
c = LI()
ans = 0
tmp = a[0]-1
ans += b[a[0]-1]
for i in range(1,n):
    ans += b[a[i]-1]
    if tmp + 1 == a[i]-1:
        ans += c[tmp]
    tmp = 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
before = 30
for i in range(N):
    ate = A[i]-1
    ans += B[ate]
    if before+1==ate:
        ans += C[ate-1]
    before = ate
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[i]
    if i != N-1 and A[i+1]-A[i]==1:
        ans += C[A[i]-1]

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()))
r = sum(Bs)
for i in range(1, N):
  if As[i] == As[i-1]+1:
    r += Cs[As[i-1]-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()))
res = 0
for i in range(N):
  res += B[A[i] - 1]
  if i != 0:
    if A[i - 1] + 1 == A[i]:
      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()))

s = 0
pa = -100
for a in A:
    s += B[a-1]
    if a == pa + 1:
        s += C[pa-1]
    pa = a
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()))
s=0
buf=-2
for i in range(n):
    x=a[i]-1
    s+=b[x]
    if x==buf+1:
        s+=c[buf]
    buf=x
print(s)

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

print(ans)

Solution (Python):

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


ans = B[0]
for i in range(1,N):
    ans += B[i]
    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
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 = 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):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    ans = sum(B)
    prev = -1
    for a in A:
        if a == prev + 1:
            ans += C[a - 2]
        prev = 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()))

res = 0
pre = -10
for a in A:
    a -= 1
    res += B[a]
    if pre == a - 1:
        res += C[pre]
    pre = a

print(res)