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

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

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

ans = 0

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

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

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

Solution (Python):
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
prev = -10
s = 0

for i in range(n):
    s += l2[l1[i]-1]
    if prev == l1[i] - 2 and prev >= 0:
        s += l3[prev]
    prev = l1[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()))

score=sum(b)

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

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

pts = 0

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

print(pts)

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 numpy as np


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


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

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
As=LI()
Bs=LI()
Cs=LI()

res = 0
lst = -1
for i in As:
    res += Bs[i-1]
    if i  == lst + 1: res += Cs[lst-1]
    lst = i
print(res)

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

ret = 0
cursor = -10
for a in A:
  ret += B[a]
  if cursor == a - 1:
  	ret += C[cursor]
  cursor = a
  
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()))
cnt = 0
for i in range(N):
    cnt += B[A[i]-1]
    if i < N-1:
        if A[i]+1==A[i+1]:
            cnt += C[A[i]-1]
print(cnt)

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

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

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

total=0
pre = -10
for i in range(len(A)):
    total += B[A[i]-1]
    if pre+1 == A[i]:
        total += C[A[i]-2]
    pre=A[i]

        
print(total)

Solution (Python):
A = int(input())
B = list(map(int,input().split(" ")))
C = list(map(int,input().split(" ")))
D = list(map(int,input().split(" ")))
count = 0
before = -2
full_percent = 0
for i in range(A):
    full_percent += C[B[count] - 1]
    if before + 1 == B[count]:
        full_percent += D[before - 1]
    before = B[count]
    count += 1
print(str(full_percent))

Solution (Python):


N = int(input())

Al = list(map(int, input().split()))
Bl = list(map(int, input().split()))
Cl = list(map(int, input().split()))


ans = 0
prev = -1
for foodIndex in Al:
    ans += Bl[foodIndex-1]
    if foodIndex == prev + 1:
        ans += Cl[foodIndex-2]
    prev = foodIndex

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

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans = sum(B)
    for i in range(N-1):
        if A[i+1] == A[i]+1:
            ans += C[A[i]-1]

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

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

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

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

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

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

print(sum)

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

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

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()))
sati = 0

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
an = 0
bf = 0
for i in a:
    an += b[i - 1]
    if bf != 0 and i == bf + 1:
        an += c[i - 2]
    else:
        pass
    bf = i
print(an)

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

count = B[A[0]-1]

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

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

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

h = 0

h += sum(b)

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

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

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

print(sum(b))

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

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

print(life)

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

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

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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]
c = [int(x) for x in stdin.readline().rstrip().split()]

score = 0
ex = 0
for i in a:
    score += b[i-1]
    if ex != 0 and i == ex+1:
        score += c[ex-1]
    ex = i

print(score)

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()))
total = 0
total += sum(li_B)
for i in range(N-1):
    if li_A[i+1] - li_A[i] == 1:
        total += li_C[li_A[i]-1]
print(total)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    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)
resolve()

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(0, n):
    ans += Bs[As[i]-1]
    if i>=1:
        if As[i] - As[i-1] == 1:
            ans+=Cs[As[i-1]-1]
print(ans)

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

satisfaction = sum(B)

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

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

def main():
    n = int(input())
    a, b, c = [tuple(map(int, input().split())) for i in range(3)]
    ans = 0
    pre = -2

    for i in a:
        ans += b[i-1]
        if pre + 1 == i:
            ans += c[pre-1]
        pre = i
    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-1):
    if (A[i] + 1 == A[i+1]):
        ans += C[A[i]-1]
ans += sum(B)

print(ans)

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

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

Solution (Python):
n=int(input())
list1=list(map(int,input().split()))
list2=list(map(int,input().split()))
list3=list(map(int,input().split()))
ans=sum(list2)
for i in range(len(list1)-1):
    if list1[i]+1==list1[i+1]:
        ans+=list3[list1[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()))
point = 0
for i in range(n):
    r = A[i]
    point += B[r-1]
    
for i in range(n-1):
  if A[i]+1 == A[i+1]:
    point += C[A[i] - 1]
    
print(point)

Solution (Python):
N, *L,  = [list(map(int, s.split())) for s in open(0)]
order = L[0]
A = L[1]
B = L[2]

s = 0
last = 0
for i in range(len(order)):
    s += A[order[i] - 1]
    if order[i] - order[last] == 1:
        s += B[order[last] - 1]
    last = i
print(s)

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

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

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

result=0
buf=A[0]

for i in A:
    if(i-buf==1):
        result+=B[i-1]+C[i-2]
    else:
        result+=B[i-1]
    buf=i

print(result)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))
    c = list(map(int, readline().split()))
    le = -10 ** 10
    t = 0
    for av in a:
        t += b[av-1]
        if av - le == 1:
            t += c[le-1]
        le = av
    print(t)


if __name__ == '__main__':
    solve()

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

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

cnt = 0
before = -1
for i in a:
  cnt += b[i]
  if before == i-1 and i != 0:
    cnt += c[before]
  before = i
print(cnt)

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

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = sum(B)

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

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

    
if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
A=input()
B=input()
C=input()

As=list(map(int,A.split(' ')))
Bs=list(map(int,B.split(' ')))
Cs=list(map(int,C.split(' ')))
total=0
for i in range(0,n):
    if As[i]-As[i-1]==1 and i!=0:
        total=total+Cs[As[i]-2]
    total=total+Bs[As[i]-1]
print(total)

Solution (Python):
n = int(input())
a = map(int, input().split())
bs = list(map(int, input().split()))
cs = list(map(int, input().split()))

ans = 0

prev = -1
for i in a:
    ans += bs[i-1]
    if i == prev+1:
        ans += cs[i-2]
    prev = i

print(ans)

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

def main():
    n = int(input())
    a, b, c = [tuple(map(int, input().split())) for i in range(3)]
    ans = 0
    a_bef = -2

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

if __name__ == '__main__':
    main()

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

def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))
    c = tuple(map(int, input().split()))
    ans = 0
    a_bef = -2

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


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: x - 1, A))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisfy = 0

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

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

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

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

total = 0; pre_num = -1
for i in A:
    total = total + B[i-1]
    if pre_num+1 == i:
        total = total + C[pre_num-1]
    pre_num = 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
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()))
res = sum(b)
for i in range(len(a) - 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()))
d = A[0]
e = B[A[0] - 1]
for a in A[1:]:
    e += B[a - 1]
    if a == d + 1:
        e += C[d - 1]
    d = a
print(e)

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

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

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

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

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

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

sum = sum(b)

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

Solution (Python):
point = 0
point2 =None
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()]
for x in range(0,int(N)):
    point =  point + B[x]
    if point2 == A[x]-1:
        point = point + C[point2-1]
    point2 = A[x]
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()))

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

print(sum(b) + bonus)

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

sum=sum(B)

for i in range(N):
    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 = 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=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()))
satisfaction = 0
for i in range(n):
    b_number = a[i]
    satisfaction += b[b_number - 1]
    if i == 0:
        j = i
    else:
        if a[i] == a[j] + 1:
            c_number = a[j]
            satisfaction += c[c_number - 1]
        j = i
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()))
satisfaction = 0
for i in range(n):
    
    
    b_number = a[i]
    
    
    satisfaction += b[b_number - 1]
    if i == 0:
        j = i
    else:
        if a[i] == a[j] + 1:
            c_number = a[j]
            satisfaction += c[c_number - 1]
        j = i
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()))

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

print(sum)

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    sum = B[A[0]-1]
    for i in range(1, len(A)):
        sum += B[A[i]-1]
        if A[i] - A[i-1] == 1:
            sum += C[A[i-1]-1]
    print(sum)
    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):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

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

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[i]

for j in range(1,N):
    if a[j-1]+1==a[j]:
        result+=c[a[j-1]-1]

print(result)

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

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

Solution (Python):
n = int(input())
aa = list(map(int,input().split())) 
a = list(x - 1 for x in aa) 
b = list(map(int,input().split())) 
c = list(map(int,input().split())) 

ans = 0
for i in range(n):
    ans += b[a[i]] 

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

Solution (Python):
N = int(input())
A, B, C = [[int(i) for i in input().split()] for j in range(3)]
score = 0
for i in range(len(A)):
    score += B[A[i] - 1]
    if i > 0 and A[i] - A[i-1] == 1:
        score += C[A[i-1] - 1]
print(score)

Solution (Python):
n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
ci = list(map(int, input().split()))





ans = 0
for i in range(n):
    t = ai[i]
    ans = ans+bi[t-1]
    if i >= 1 and ai[i-1]+1 == t:
        ans = ans + ci[ai[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 = 0

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