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

manpuku = 0

for i in range(n):
    manpuku += b[a[i]-1]
    try:
        if i == 0:
            pass
        else:
            if (a[i] - a[i-1]) == 1:
                manpuku += c[a[i-1]-1]
    except:
        pass

print(manpuku)

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

Dishes  = list(map(int, input().split(" ")))
Scores  = list(map(int, input().split(" ")))
Bonuses = list(map(int, input().split(" ")))





TotalScore = sum(Scores)
for i in range(N-1):
    if Dishes[i] + 1 == Dishes[i+1]:
        BonusIdx = Dishes[i] - 1
        TotalScore = TotalScore + Bonuses[BonusIdx]
print(TotalScore)

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

former = -10
satisfy = 0
for i in a:
    satisfy += b[i-1]
    if i == former + 1:
        satisfy += c[i-2]
    former = i
print(satisfy)

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

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

print(ans)

Solution (Python):
if __name__ == "__main__":
    input_data =[]
    for x in range(4):
        input_data.append(input())
    dim = int(input_data[0])
    A = [int(x) for x in input_data[1].split()]
    B = [int(x) for x in input_data[2].split()]
    C = [int(x) for x in input_data[3].split()]

    goukei = 0
    pre = -10
    for x in range(dim):
        goukei += B[A[x]-1]
        if A[x] - pre == 1:
            goukei += C[pre - 1]
        
        pre = A[x]

    print(goukei)

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

man = sum(B)

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

print(man)

Solution (Python):
class ABC140B:

    def __init__(self):
        self.nNum = int(input())
        self.aList = list(map(int, input().split()))
        self.bList = list(map(int, input().split()))
        self.cList = list(map(int, input().split()))

    def solve(self):
        prev = -2
        point = 0
        for aNum in self.aList:
            aNum -= 1
            point += self.bList[aNum]
            if prev + 1 == aNum:
                point += self.cList[prev]
            prev = aNum

        print(point)


if __name__ == '__main__':
    ABC140B().solve()

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)

i = 0
while i < n - 1:
	if a[i] + 1 == a[i + 1]:
		s += c[a[i] - 1]
	i += 1

print(s)

Solution (Python):
n = int(input())
o = list(map(int, input().split()))
m = list(map(int, input().split()))
a = list(map(int, input().split()))

b = -2
ans = 0
for i, name in enumerate(o):
    if name == b + 1:
        ans += a[name - 2]
    ans += m[name-1]
    b = name

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

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

ans = 0
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())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.append(0)

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

Solution (Python):
n=int(input())
eat=list(map(int,input().split()))
point=list(map(int,input().split()))
extra=list(map(int,input().split()))

total=sum(point)
for i in range(n-1):
  if eat[i+1]==eat[i]+1:
    total+=extra[(eat[i]-1)]

print(total)

Solution (Python):
H=int(input())
S = [list(map(int, input().split())) for i in range(3)]
ans=sum(S[1])
for i in range(H-1):
  if (S[0][i+1]-S[0][i])==1:
    ans+=S[2][S[0][i]-1]
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def solve(A, B, C):
    prev_a = -1
    result = 0
    for a in A:
        result += B[a - 1]
        if a - prev_a == 1:
            result += C[prev_a - 1]
        prev_a = a

    return result


if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    answer = solve(A, B, C)
    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()))

cnt = 0
j=-1

for i in A:
    cnt += B[i-1]
    if i==j+1:cnt+=C[j-1]
    j=i

print(cnt)

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

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

    print(happiness+B[A[-1]-1])

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()))+[0]

prev = N
cnt = 0
for a, b in zip(As,Bs):
    
    cnt += b
    if prev + 1 == a:
        cnt += Cs[a-2]
        
    prev = a
print(cnt)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
c = list(map(int, stdin.readline().rstrip().split()))

res = 0
predish = -999
for dish in a:
    res += b[dish - 1]
    if dish - predish == 1:
        res += c[predish - 1]
    predish = dish

print(res)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
c = list(map(int, stdin.readline().rstrip().split()))

res = 0
predish = -999
for dish in a:
    res += b[dish - 1]
    if dish - predish == 1:
        res += c[predish - 1]
    predish = dish

print(res)

Solution (Python):
def solve_b(n, a_list, b_list, c_list):

    res = sum(b_list)

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

    return res


def main():

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

    print(solve_b(n, a_list, b_list, c_list))


if __name__ == "__main__":
    main()

Solution (Python):

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

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

print(manzoku)

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

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

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

s = 0
b_ia = 0
for ia in a:
  
  s += b[ia-1]
  if b_ia != 0 and (b_ia + 1) == ia:
    s += c[b_ia-1]
  b_ia = ia
print(s)

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


if __name__ == "__main__":
    main()

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

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

ans = 0
for i in range(N):
  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())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
M=0
for i in range(N):
    A[i]-=1
for i in range(N-1):
    if A[i]+1==A[i+1]:
        M+=B[A[i]]+C[A[i]]
    else:
        M+=B[A[i]]
print(M+B[A[N-1]])

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

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

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

s = 0
prev_a = -1
for a in A:
    s += B[a - 1]
    if a == prev_a + 1:
        s += C[prev_a - 1]
    prev_a = a

print(s)

Solution (Python):
if (__name__ == '__main__'):
    n = int(input())
    
    a = [0]
    b = [0]
    c = [0]

    aa = input().strip().split()
    for i in range(n):
        a.append(int(aa[i]))
    bb = input().strip().split()
    for i in range(n):
        b.append(int(bb[i]))
    cc = input().strip().split()
    for i in range(n-1):
        c.append(int(cc[i]))

    sum = b[a[1]]
    lastmenu = a[1]

    for i in range(2, n+1):
        sum = sum + b[a[i]]
        if (a[i] == lastmenu+1):
            sum = sum + c[lastmenu]
        lastmenu = a[i]

    print(sum)

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

sum_full = 0
prev_dish = -1
for dish in A:
	sum_full += B[dish-1]
	if dish == prev_dish + 1:
		sum_full += C[prev_dish-1]
	prev_dish = dish

print(sum_full)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



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

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

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

print(manzoku)

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):
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n = INT()
A = LIST()
B = LIST()
C = LIST()
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())

jun=list(map(int,input().split()))
sat=list(map(int,input().split()))
add=list(map(int,input().split()))

ans=sum(sat)
for i in range(n-1):
    if jun[i+1]==jun[i]+1:
        ans+=add[jun[i]-1]


print(ans)

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

s = sum(bn)
a0 = n+1
for ai in an:
  if ai == a0 + 1:
    s += cn[a0-1]
  a0 = ai
print(s)

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

ans = sum(B)
C_index = [str(i)+str(i+1) for i in range(1,N)]
A_index = [A[i]+A[i+1] for i in range(0,N-1)]
C_dict = dict(zip(C_index,C))
for i in A_index:
    if i in C_index:
        ans += C_dict[i]
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(' ')))
              





ans = 0 
prev_a = 0
for a in A_LIST:
  
  
  ans += B_LIST[a-1]
  if prev_a + 1  == a and a != 1:

    ans += C_LIST[a - 2]

  
  prev_a = a
print(ans)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
A = LI()
B = LI()
C = LI()

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

print(ans)

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

ans = sum(Bi)

for i in range(N-1):
  if Ai[i] + 1 == Ai[i+1]:
    ans += Ci[Ai[i]-1]

print(ans)

Solution (Python):
import sys
from collections import deque
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N = int(input())
A = [int(v) - 1 for v in input().split()]
B = [int(v) for v in input().split()]
C = [int(v) for v in input().split()]

ans = 0
for v in A:
    ans += B[v]

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

print(ans)

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

Solution (Python):
if __name__ == "__main__":
 
    n = int(input())
    a_list = input().split()
    b_list = input().split()
    c_list = input().split()
    
    points = 0
    for i, a in enumerate(a_list):
        points += int(b_list[int(a) - 1])
        if i >= 1 and int(a_list[i]) == int(a_list[i - 1]) + 1:
            points += int(c_list[int(a_list[i - 1]) - 1])
    
    print('{0}'.format(points))

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(A)):
  ans += B[A[i]-1]
  if i <= (N-1)-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
ex_A = 0

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

print(ans)

Solution (Python):
from collections import Counter
mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


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

    print(ans)

main()

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

answer = 0
tyokkin = -1

for dish in A:
  manzoku = B[dish-1]
  if dish - tyokkin == 1:
    manzoku += C[dish-2]
  answer += manzoku
  tyokkin = dish
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
num = None
for i in range(n):
    ans += b[a[i] - 1]
    if num == a[i] - 2:
        ans += c[a[i] - 2]
    num = a[i] - 1
print(ans)

Solution (Python):
n=int(input())
turn=list(map(int,input().split()))
happy=list(map(int,input().split()))
combo=list(map(int,input().split()))
total=0
pre_t=-2
for t in turn:
    total+=happy[t-1]
    if pre_t+1==t:
        total+=combo[pre_t-1]
    pre_t=t
print(total)

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

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

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

sum_counter = 0

for i in range(N):
    num = a[i] - 1
    sum_counter += b[num]

    if i < N-1 and a[i+1] - 1 == a[i]: 
        sum_counter += c[num]

print(sum_counter)

Solution (Python):
N = int(input())
A = [int(e) - 1 for e in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
before = N
result = 0
for i in range(N):
  result += B[A[i]]
  if before + 1 == A[i]:
    result += C[before]
  before = 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()))
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):
a = int(input())
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
cr = list(map(int,input().split(" ")))
count = sum(br)
for i in range(a-1):
    if ar[i+1] - ar[i] == 1:
        count += cr[ar[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
prev = -1
for i in A:
    ans += B[i-1]
    if prev == i-1:
        ans += C[i-2]
    prev = 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()))

score = sum(B)
for a, b in zip(A, A[1:]):
  if a == b-1:
    score += C[a-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()))

pre = 0
score = 0
for i in A:
  score += B[i-1]  
  if pre == (i-1) and i != 1:
    score += C[pre-1]
  pre = i
    
print(score)

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

tot = 0
while len(A) > 1:
    a = A.pop()
    tot += B[a - 1]
    if a - 1 == A[-1]:
        tot += C[a - 1 - 1]
tot += B[A.pop() - 1]
print(tot)

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

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

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

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

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

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

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

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

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

sum = B[A[0]-1]
x = A[0]

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

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

Solution (Python):
n = int(input())
lsta = [0] + list(map(int,input().split()))
lstb = [0] + list(map(int,input().split()))
lstc = [0] + list(map(int,input().split()))
ans = 0
kept = -10
for i in range(1,n+1):
    ans += lstb[lsta[i]]
    if lsta[i] == kept + 1:
        ans += lstc[kept]
    kept = lsta[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
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 = 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 slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    c = list(map(int, input().rstrip('\n').split()))
    t = sum(b)
    for i in range(1, n):
        if a[i] == a[i-1] + 1:
            t += c[a[i-1] - 1]
    print(t)


if __name__ == '__main__':
    slove()

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

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

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

Solution (Python):

def main():
    N, *ABC = map(int, open(0).read().split())
    A, B, C = ABC[:N], ABC[N : N * 2], ABC[N * 2 :]
    ans = sum(B)
    for i, j in zip(A, A[1:]):
        if i + 1 == j:
            ans += C[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()))
satisfaction = 0
for i in range(N):
    satisfaction += B[i]
    if i > 0 and A[i-1] + 1 == A[i]:
        satisfaction += C[A[i-1] - 1]
print(satisfaction)

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

for i in range(0,N):

    ans = ans + B[A[i]-1]
    if i!= 0 and A[i] == A[i-1] + 1:
        ans = ans + C[A[i-1]-1]

print(ans)

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


A.append(100)
C.append(0)

total = 0

total = sum(B)

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

print(total)

Solution (Python):
n = int(input())
list_A  = list(map(int, input().split()))
list_B  = list(map(int, input().split()))
list_C  = list(map(int, input().split()))

list_A_01 = []
for i in range(len(list_A) - 1):
    if list_A[i] == list_A[i + 1] - 1:
        list_A_01.append(list_A[i])

    if list_A[i] != list_A[i + 1] - 1:
        list_A_01.append(0)

result = 0

for i, score in enumerate(list_A_01):
    if score != 0:
        result = result + list_C[score-1]

print(sum(list_B) + 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()]

p=n+1
ans =0

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

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

Solution (Python):


n=int(raw_input())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
c=map(int,raw_input().split())
res=sum(b)
for i in xrange(n-1):
 if a[i+1]==a[i]+1:
  res+=c[a[i]-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
for i in range(n-1):
    s+=b[a[i]-1]
    if a[i+1]==a[i]+1:
        s+=c[a[i]-1]
s+=b[a[n-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()))


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

Solution (Python):
n=int(input())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
cl=[int(i) for i in input().split()]
cnt=sum(bl)
for i in range(n-1):
	if al[i]+1==al[i+1]:
		cnt+=cl[al[i]-1]
print(cnt)

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

ans = 0
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):
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pre_a = -1
ans = 0

for a in A:
    ans += B[a-1]
    if a == pre_a + 1:
        ans += C[pre_a-1]
    pre_a = a

print(ans)

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

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