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

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

value = 0
tmp = A[0]
for i in A[1:]:
    if (tmp+1 == i):
        value += C[tmp-1]
    tmp = i
    

value += sum(B)
print(value)

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

def solve():
    m = A.pop(0)
    ans = B[m-1]
    for i, a in enumerate(A):
        ans += B[a-1]
        if a == m + 1:
            ans += C[m-1]
        m = a
    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
li_a = list(map(int,input().split()))
li_b = list(map(int,input().split()))
li_c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i==0:
    ans += li_b[li_a[0]-1]
    continue
  else:
    ans += li_b[li_a[i]-1]
    if li_a[i-1] + 1 == li_a[i]:
      ans += li_c[li_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()))
prev = -1
ans = 0
for i in range(n):
  manzoku = B[A[i]-1]
  if prev+1 == A[i]:
    manzoku += C[prev-1]
  prev = A[i]
  ans += manzoku
print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
total = B[A[0] - 1]
for i in range(1, N):
    total += B[A[i] - 1]
    if A[i-1] + 1 == A[i]:
        total += C[A[i-1] - 1]
print(total)

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


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

print(ans)

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

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

print(total)

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

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

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

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

ans = 0
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):
def calc(n, a, b, c):
    r = 0

    pre_x = -2
    for x in a:
        r += b[x-1]
        if pre_x + 1 == x:
            r += c[x-2]
        pre_x = x

    return r


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

r = calc(n, a, b, c)
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()))

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

print(rslt)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
last = -1
sum = 0
for ai in a:
    sum += b[ai-1]
    if ai - last == 1:
        sum += c[ai-2]
    last = ai
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):
def main():
    N = int(input())
    A = [int(number) for number in input().split()]
    B = [int(number) for number in input().split()]
    C = [int(number) for number in input().split()]

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

if __name__ == '__main__':
    main()

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

satisfaction = 0
previous_food = -1

for food in foods:
    satisfaction += B[food-1]
    if food == previous_food+1:
        satisfaction += C[previous_food-1]
    previous_food = food

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()))
a = [i-1 for i in a]
ans = 0
ans += b[a[0]]
prev = a[0]
for i in range(1,n):
    ans+= b[a[i]]
    if prev == a[i]-1:
        ans += c[prev]
    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()))
SUM=B[A[0]-1]
for i in range(1,len(A)):
    if A[i]==A[i-1]+1:
        SUM+=B[A[i]-1]+C[A[i-1]-1]
    else:
        SUM+=B[A[i]-1]
print(SUM)

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

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

def main():
    N = int(input())
    A = [int(a)-1 for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]

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

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    ABC = [list(map(int, input().split())) for _ in range(3)]
    A = ABC[0]
    B = ABC[1]
    C = ABC[2]

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

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

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

print(res)

Solution (Python):

import sys



import numpy as np



"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def make_divisors(n):
    
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            
            return i
            
            


def n_to_10(X, n):
    if int(X / n):
        return n_to_10(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = int(input())
    a = ip.IL()
    b = ip.IL()
    c = ip.IL()
    memo = a[0]
    ans = 0
    for i in range(1, n):
        if memo + 1 == a[i]:
            ans += c[memo-1]
        memo = a[i]
        
    print(sum(b) + 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()]
S=0
for x in range(0,N):
    S=S+B[A[x]-1]
    if x!=N-1:
        if A[x]==A[x+1]-1:
            S=S+C[A[x]-1]
print(S)

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

result = sum(B)

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

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

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

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

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

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

manz = 0

for i, _ in enumerate(A):
    manz += B[A[i]-1]
    if i >= 1 and A[i] == A[i-1]+1:
        manz += C[A[i]-2]
        
print(manz)

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

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

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

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

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

ans = 0
pred = -1
for a in A:
    ans += B[a-1]
    if (a-1) == pred:
        ans += C[pred-1]
    pred = a
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()]
score=0
pre=0
pre_a=-100
for i,a in enumerate(A):
    score+=B[a-1]
    if pre_a+1==a:
        score+=C[pre_a-1]
    pre=i
    pre_a=a
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()))
value = 0

A = [i-1 for i in A]

for ind,i in enumerate(A):
  value += B[i]
  if ind != N-1:
    if A[ind+1] == i+1:
      value += C[i]
    
print(value)

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

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

print(M)

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

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,j in zip(a,a[1:]):
    ans += b[i-1]
    if j == i + 1:
        ans += c[i-1]
print(ans + b[a[-1]-1])

Solution (Python):
N = int(input())
A = [int(_) - 1 for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
ans = sum(B)
for i in range(N - 1):
    if A[i] + 1 == A[i + 1]:
        ans += C[A[i]]
print(ans)

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

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

Solution (Python):

n = int(input())

an = list(map(lambda x :int(x)-1, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))


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


    if before + 1 == an[i]:

        ans += cn[ before ]

    before = an[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()))

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

print(bonus+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 = -2
for a in A:
    ans += B[a - 1]
    if a == prev + 1:
        ans += C[prev - 1]
    prev = a

print(ans)

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



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

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
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
A = LI()
B = LI()
C = LI()

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())
order = list(map(int,input().split()))
satisfaction = list(map(int,input().split()))
add_satisfaction = list(map(int,input().split()))

total_satisfaction = 0
pre_num = -10

for i in order:
    total_satisfaction += satisfaction[i-1]
    if pre_num + 1 == i:
        total_satisfaction += add_satisfaction[pre_num-1]
    pre_num = i

print(total_satisfaction)

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

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

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

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

order = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
add = list(map(int, input().split()))


ans = 0
before = order[0]

for i in range(n):
    if order[i] == before+1:
        ans += manzoku[order[i]-1] + add[before-1]
    else:
        ans += manzoku[order[i]-1]

    before = order[i]

print(ans)

Solution (Python):
def MAP(): return list(map(int,input().split()))

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

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

print(ans)

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

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

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

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

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

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

print(ans)

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

Solution (Python):
n = int(input())
ai = [int(i) for i in input().split()]
bi = [int(i) for i in input().split()]
ci = [int(i) for i in input().split()]

result = sum(bi)
prei = -1
for i in ai:
    if (prei+1) == i:
        result += ci[prei-1]
    prei = 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()))

score = 0
prev_d = -1

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

    if (prev_d >= 0) and (d - prev_d == 1):
        score = score + C[d-1]

    prev_d  = d

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


def main(n, a, b, c):
    total = sum(b)

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

    return total


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    print(main(n, a, b, c))

Solution (Python):



n=int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

point = 0
before = -2
for a in al:
    if a - before == 1:
        point += cl[before - 1]
    before = a
    point += bl[a - 1]
print(point)

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

result = 0

for i in range(N):
    result += B[A[i]-1]
    if i == 0:
        pass
    elif A[i] - 1 == A[i-1]:
        result += C[A[i-1]-1]

print(result)

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

ans=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())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))

answer=0
old_ryori=-100
for i in range(N):
  new_ryori=alist[i]-1
  answer+=blist[new_ryori]
  if old_ryori+1==new_ryori:
    answer+=clist[new_ryori-1]
  old_ryori=new_ryori
    
print(answer)

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

sat = 0
prev_ryouri = -10

for i in range(n):
  ryouri = A[i] - 1
  sat += B[ryouri]
  if prev_ryouri+1 == ryouri:
    sat += C[prev_ryouri]
    
  prev_ryouri = ryouri


print(sat)

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


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

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

print(total)

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

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

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 = [i-1 for i in a]

ans = 0
tmp = -99
for i in a:
  if i == tmp+1:
    ans += c[tmp]
  ans += b[i]
  tmp = 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
pre = -10
for aa in a:
    ans += b[aa-1]
    if aa-1 == pre + 1:
        ans += c[pre]
    pre = aa-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()))

ans = 0
before_A = -1
for A in Alist:
    ans += Blist[A-1]
    if before_A+1 == A:
        ans += Clist[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()))
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 = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

pre = -100
c = 0
for a in A:
  i = a - 1
  c += B[i]
  if pre == a - 1:
    c += C[i - 1]
  pre = a
print(c)

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
temp=30
for item in a:
  result+=b[item-1]
  if item==temp+1:
    result+=c[temp-1]
  
  temp=item
  
print(result)

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

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

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

ans = sum(B)

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

print(ans)

Solution (Python):
num = 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(num):
    count += b[a[i]-1]
    
    if i > 0 and a[i-1] + 1 == a[i]:
        count += c[a[i]-2]

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

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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


if __name__ == '__main__':
    main()

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

ans=0

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

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

print(sum(l))

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

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

print(point)

Solution (Python):
n = int(input())
meals = list(map(int, input().split()))
suts = list(map(int, input().split()))
add_suts = list(map(int, input().split()))

total = 0
pre = None
for meal in meals:
    total += suts[meal-1]
    if pre is not None and pre + 1 == meal:
        total += add_suts[pre-1]
    pre = meal
print(total)

Solution (Python):
N = int(input())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))
CList = list(map(int,input().split()))

manzoku = 0
prev = -1
for a in AList:
    manzoku += BList[a-1]
    if prev + 1 == a:
        manzoku += CList[prev-1]
    prev = a
print(manzoku)

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input().strip())
alist = list(map(int,input().strip().split()))
blist = list(map(int,input().strip().split()))
clist = list(map(int,input().strip().split()))

sat = 0
prenum = 10000
for i in range(N):
	num = alist[i]-1
	sat = sat+blist[num]
	if num==prenum+1:
		sat = sat+clist[prenum]

	prenum = num


print(sat)