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

manzoku = 0
im1 = Ai[0]
for i,A in enumerate(Ai):
  manzoku = manzoku + Bi[A-1]
  if A - im1 == 1: manzoku = manzoku + Ci[im1-1]
  im1 = A
print(manzoku)

Solution (Python):



if __name__ == '__main__':
    n=int(input())
    a_list=[int(x)-1 for x in input().split()]
    b_list=[int(x) for x in input().split()]
    c_list=[int(x) for x in input().split()]
    score=sum(b_list)
    pre_a=-100
    for a in a_list:
        if(a-pre_a==1):
            score+=c_list[pre_a]
        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()))

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

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

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

s = 0

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

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 = 0
    prevdish = -1
    for i in range(n):
        dish = a[i]
        ans += b[dish-1]
        if prevdish == dish-1:
            ans += c[dish-2]
        prevdish = dish
    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 =0
for i in range(n):
    t = a[i]
    sum += b[t-1]
    if i!=0:
         if a[i]==a[i-1]+1:
             sum += c[a[i-1]-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()))

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

print(sum(b)+ex)

Solution (Python):

"""
B - Buffet
https://atcoder.jp/contests/abc140/tasks/abc140_b

"""
import sys


def solve(N, A, B, C):
    ans = 0
    prev = -100
    for a in A[1:]:
        ans += B[a]
        if a == prev + 1:
            ans += C[a-1]
        prev = a
    return ans


def main(args):
    N = int(input())
    A = [-1] + [int(a) for a in input().split()]
    B = [-1] + [int(b) for b in input().split()]
    C = [-1] + [int(c) for c in input().split()]
    ans = solve(N, A, B, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=0
now=-2
for a in A:
    ans+=B[a-1]
    if a==now+1:
        ans+=C[now-1]
    now=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 k,i in enumerate(a):
  total += b[i-1]
  if k == n - 1:
    continue
  elif a[k]+1 == a[k+1]:
    total += c[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 = 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()))
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())
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 = sum(B)
for i in range(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()))

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

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


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

Solution (Python):
n = int(input())
orders = list(map(int, input().split()))
suf = list(map(int, input().split()))
ser = list(map(int, input().split()))
ans = 0
flug = -1
for i in orders:
  ans += suf[i-1]
  if flug+1 == i:
    ans += ser[i-2]
  flug = i
print(ans)

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

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

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

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

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

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

print(ans)

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

ans = 0

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

b = 0
for k in range(N-1):
    if A[k]+1 == A[k+1]:
        b = b+C[(A[k]-1)]

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

Solution (Python):


n = int(input())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b_l[a_l[i]-1]
    if i != 0 and a_l[i] == a_l[i-1]+1:
        ans += c_l[a_l[i]-2]
print(ans)

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

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

Solution (Python):
N = int(input())
ls_A = list(map(int,input().split()))
ls_B = list(map(int,input().split()))
ls_C = list(map(int,input().split()))


manzoku = sum(ls_B)  


for i in range(N-1):
    if ls_A[i+1] == ls_A[i]+1:
        manzoku += ls_C[ls_A[i]-1]

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

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

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

total_value = sum(b)

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

print(total_value)

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

Solution (Python):
n,*a = map(int,open(0).read().split())
print(sum(a[n:n*2]) + sum(a[i-n] for i, j in zip(a, a[1:n]) if j == i + 1))

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

ans = 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 = [0]*n

t = list(map(int, input().split()))
for i in range(n-1):
  c[i] = t[i]
  

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

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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

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

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

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

Solution (Python):
N=int(input())
A=[int(x)for x in input().split()]
B=[int(x)for x in input().split()]
C=[int(x)for x in input().split()]
ans=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())

arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))
arrC = list(map(int,input().split()))

arrC = [0] + arrC

ans = 0
for i,dishnum in enumerate(arrA):
    if i == 0:
        ans += arrB[dishnum-1]
    else:
        ans += arrB[dishnum-1]
        if arrA[i] == arrA[i-1]+1:
            ans += arrC[dishnum-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()))
sum1 = 0
for i in range(N):
    sum1 += B[A[i]-1]
    if(i < N-1):
        if(A[i]+1 == A[i+1]):
            sum1 += C[A[i]-1]
print(sum1)

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

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

print(answer+sum(B))

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

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

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

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

Solution (Python):
def solve():
    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(N-1):
        if A[i+1] - A[i] == 1:
            s += C[A[i]-1]

    return s

print(solve())

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

print(ans)

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

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

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

ans = 0

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

print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ap = 0
ad = 0
for i in a:
    ap += b[i - 1]
    
for j in range(1, len(a)):
    
    if a[j] - a[j - 1] == 1:
            ad += c[a[j - 1] - 1]

print(ap + ad)

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

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

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

    satisfaction = 0

    for i in range(n):
        satisfaction += B[A[i] - 1]
        if 0 < i < n and A[i] == A[i-1] + 1:
            satisfaction += C[A[i]-2]
    
    print(satisfaction)

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

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

result = 0
was = -5
for a in A:
    result += B[a]
    if was == a-1:
        result += C[a-1]
    was = a

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

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

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

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

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

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
ans = b_list[a_list[0]-1]
for i in range(1, N):
    ans += b_list[a_list[i]-1]
    if a_list[i-1]+1 == a_list[i]:
        ans += c_list[a_list[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()]

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())
List1 = [int(i) for i in input().split(" ")]
List2 = [int(j) for j in input().split(" ")]
List3 = [int(k) for k in input().split(" ")]

baf = 0
last_m = 21

for i in range(N):
    p = List1[i]
    baf += List2[p-1]
    if last_m == p-1:
        baf += List3[last_m-1]
    last_m = p
print(baf)

Solution (Python):
N = int(input())
total = 0
number = input().split(" ")
point = input().split(" ")
C = input().split(" ")
for i in point:
    total += int(i)
for j in range(N-1):
    if int(number[j]) == int(number[int(j)+1])-1:
        x = int(number[j])-1
        total += int(C[x])
    else:
        pass
    
print(total)

Solution (Python):
n = input()
line1 = input()
line2 = input()
line3 = input()
a_list = line1.split(" ")
a_list = [int(a) for a in a_list]
b_list = line2.split(" ")
b_list = [int(b) for b in b_list]
c_list = line3.split(" ")
c_list = [int(c) for c in c_list]

manzoku = 0

for i in range(int(n)):
    if i == 0:
        manzoku = manzoku + b_list[a_list[i]-1]
    else:
        manzoku = manzoku + b_list[a_list[i]-1]
        if a_list[i]-1 == a_list[i-1]:
            manzoku = manzoku + c_list[a_list[i-1]-1]
print(manzoku)

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

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

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

print(sumc + sum(B))

Solution (Python):
n = int(input())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))
listC = list(map(int, input().split()))

cnt = 0
temp = ""
for x in listA: 
    cnt += listB[x-1]
  
    if temp == x-1:
        cnt += listC[temp-1]   
        
   
    temp = x

print(cnt)

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

cnt=b[a[0]-1]
idx=a[0]-1

for i in range(1, len(a)):
    cnt += b[a[i]-1]
    
    if idx == a[i] - 2:
        cnt += c[idx]
        
    idx = a[i]-1
    
print(cnt)

Solution (Python):


n = int(input().rstrip())

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

prev = -2
ans = 0
for i in range(n):
    dish = a_list[i] - 1
    ans += b_list[dish]
    if dish - prev == 1:
        ans += c_list[prev]
    prev = dish

print(ans)

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

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

print(sat)

Solution (Python):
import sys
import math

N=int(input())
li0= [int(x) for x in input().split()]
li1= [int(x) for x in input().split()]
li2= [int(x) for x in input().split()]
i=total=0
total=sum(li1)

for i in range(N-1):
  if li0[i]==(li0[i+1]-1):
    total+=int(li2[li0[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()))
satisfy=0
for i in range(N-1):
    if A[i+1]==A[i]+1:
        satisfy+=C[A[i]-1]
    satisfy+=B[i]
satisfy+=B[N-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()))
before = None
ans = 0
for ai in a[::-1]:
    i = ai-1
    ans += b[i]
    if i+1 == before:
        ans += c[i]
    before = i
print(ans)

Solution (Python):
n = int(input())
s = [list(map(int,input().split())) for i in range(3)]

a=s[0]
b=s[1]
c=s[2]


score = 0
for i in range(len(a)):
    score+=b[a[i]-1]
    
    if i == len(a)-1:
        pass
    else:
        if a[i]+1 == a[i+1]:
            score+=c[a[i]-1]
            
print(score)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
a, b, c = [[int(x) for x in stdin.readline().rstrip().split()]
           for _ in range(3)]
total = 0
for i in range(len(a)):
    total += b[a[i]-1]
    if (i != len(a) - 1) and (a[i + 1] - a[i] == 1):
        total += c[a[i] - 1]

print(total)

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

poin = B[A[0]-1]

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

Solution (Python):
def resolve():
    N = int(input())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    C_list = list(map(int, input().split()))

    point = 0

    i_minus = None

    for i in A_list:
        point += B_list[i-1]
        if i_minus is not None:
            if (i - i_minus) == 1:
                point += C_list[i_minus-1]
        i_minus = i

    print(point)

if __name__ == "__main__":
    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 = 0

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

Solution (Python):
n = int(input())
satisfy = 0
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]:
        satisfy += c[a[i]-1]
satisfy += sum(b)
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()))

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

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

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

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

print(ans)

Solution (Python):


n = int(input().rstrip())

dish_list = [int(i) for i in input().rstrip().split(" ")]
manzoku = [int(i) for i in input().rstrip().split(" ")]
bonus = [int(i) for i in input().rstrip().split(" ")]

prev = -10
ans = sum(manzoku)
for i in range(n):
    dish = dish_list[i]
    if dish - prev == 1:
        ans += bonus[prev - 1]
    prev = dish
print(ans)

Solution (Python):





import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    b = list(map(int,ipti().split()))
    c = list(map(int,ipti().split()))

    ans = sum(b)
    prev = a[0]

    for i in range(n):
        if a[i] - prev == 1:
            ans += c[prev-1]
        prev = a[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()))
scr = 0
ai_1 = float('Inf')
for ai in a:
    scr += b[ai-1]
    if ai_1 + 1 == ai:
        scr += c[ai_1-1]
    ai_1 = ai
print(scr)

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

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

ans=0
for i in range(1,len(a)):
  if a[i]==prev+1:
    ans+=c[prev-1]
  prev=a[i]
print(s1+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
pre=N
for a in A:
  s+=B[a-1]
  if pre == a-2:
    s+=C[pre]
  pre=a-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()))

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

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

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

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