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):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


n = inp()
Alist = inpl()
Blist = inpl()
Clist = inpl()

ans = 0

for i in range(len(Alist)-1):
    if Alist[i+1] == Alist[i]+1:
        ans += Clist[Alist[i]-1]
ans += sum(Blist)

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 = 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 and (A[i] ==A[i-1] + 1):
        manzoku += C[A[i-1]-1]
        

print(manzoku)

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

total=0
for i in range(len(A)):
  total += B[i]
  if i >=1:
    if A[i-1]+1==A[i]:
      k=A[i-1]
      total+= C[k-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()))
s = 0
for i in range(n):   
    if i > 0 and a[i] - a[i-1] ==  1:
        s = s + b[a[i]-1] +c[a[i-1]-1]
    else:  
        s = s + b[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 = 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(int(x) for x in input().split())
    B = list(int(x) for x in input().split())
    C = list(int(x) for x in input().split())
    ans = 0
    a1 = N

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

if __name__ == '__main__':
    main()

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

manzoku = sum(b)

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

print(manzoku)

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

manzoku = 0
maenoosara = a[0]

for i in range(n):
  tabeteruosara = a[i]
  manzoku = manzoku + b[tabeteruosara - 1]

  if tabeteruosara - maenoosara == 1:
      manzoku = manzoku + c[tabeteruosara - 2]

  maenoosara = tabeteruosara

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

sat = sum(B)

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

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

Solution (Python):
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]



def A():
    N = I()
    print(pow(N, 3))
    return



def B():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    a_p = -1
    ans = 0
    for a in A:
        if (a - a_p == 1):
            ans += B[a - 1] + C[a - 2]
        else:
            ans += B[a - 1]
        a_p = a
    print(ans)
    return



def C():
    return



def D():
    return



def E():
    return



def F():
    return



def resolve():
    B()
    return



if __name__ == "__main__":
    B()

Solution (Python):
input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
before_num = 1000
satisfuction = 0
for num in A:
    satisfuction += B[num - 1]
    if num == before_num + 1:
        satisfuction += C[before_num - 1]
    before_num = num

print(satisfuction)

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

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

print(sati)

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

s = ls_b[ls_a[0]-1]

for i in range(1, n):
    s += ls_b[ls_a[i]-1]
    if ls_a[i] == ls_a[i-1] + 1:
        s += ls_c[ls_a[i-1]-1]
print(s)

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

ans=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 = list(map(lambda x: int(x) - 1,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
prev = -3
answer = 0
for v in a:
  answer += b[v]
  if prev + 1 == v:
    answer += c[prev]
  prev = v
print(answer)

Solution (Python):
n = int(input())
eat_num = list(map(int,input().split()))
fill_num = list(map(int,input().split()))
add_fill = list(map(int,input().split()))
count = sum(fill_num)
for i in range(len(eat_num) - 1):
    if eat_num[i+1] == eat_num[i] + 1:
        count += add_fill[eat_num[i]-1]
print(count)

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

A = [i for i in map(int, input().split())]
B = [i for i in map(int, input().split())]
C = [i for i in map(int, input().split())]

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

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(N,A,B,C):
    """Test Case
    >>> print_ans(3,"3 1 2","2 5 4","3 6")
    14
    >>> print_ans(4,"2 3 4 1","13 5 8 24","45 9 15")
    74
    >>> print_ans(2,"1 2","50 50","50")
    150
    """
    A_arr = list(map(int,A.split()))
    B_arr = list(map(int,B.split()))
    C_arr = list(map(int,C.split()))
    ans = sum(B_arr)
    for i in range(N - 1):
        if A_arr[i] + 1 == A_arr[i + 1]:
            ans += C_arr[A_arr[i] - 1]
    print(ans)
if __name__ == '__main__':
    N = int(input().rstrip())
    A = input().rstrip()
    B = input().rstrip()
    C = input().rstrip()
    print_ans(N,A,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=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()))
A = [e-1 for e in A]
A = [10000000] + A
ans = 0
for i in range(1,N+1):
    ans += B[A[i]]
    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
tmp = -10

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

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

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

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

res = 0
for i in range(n):
	a = a_s[i] - 1
	res += bs[a]
	if i > 0 and a_s[i] - a_s[i - 1] == 1:
		res += cs[a - 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()))

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

Solution (Python):
dishes = int(input())
seq_dish = list(map(int,input().split()))
sat_dish = list(map(int,input().split()))
add_sat = list(map(int,input().split()))
sat = 0
for i in range(0,len(seq_dish)):
    sat += sat_dish[seq_dish[i]-1]
    if i != 0:
        if (seq_dish[i] - seq_dish[i-1]) == 1:
            sat += add_sat[seq_dish[i-1]-1]
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

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

print(sum)

Solution (Python):
n=int(input())
foods = list(map(int,input().split()))
satisfy = list(map(int,input().split()))
chain = list(map(int,input().split()))
ans = 0

for i in range(0,n):
    ans += satisfy[foods[i]-1]
    if  i<n-1 and foods[i] == foods[i+1]-1:
        ans += chain[foods[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(len(A)):
        ans += B[A[i] - 1]
        if i == len(A) - 1:
                continue
        else:
                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 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 = list(input().split())
A_list_int = [int(s) for s in A_list]

B_list = list(input().split())
B_list_int = [int(s) for s in B_list]

C_list = list(input().split())
C_list_int = [int(s) for s in C_list]

Answer = []

for i in range(0, N):
  Answer.append(B_list_int[A_list_int[i] - 1])
  if i != N and i != 0:
      if A_list_int[i - 1] == A_list_int[i] - 1:
          Answer.append(C_list_int[A_list_int[i] - 2])

print(sum(Answer))

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

print(pnt)

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]==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
past = 0

for i in range(n):
    ryouri = a[i]-1
    ans += b[ryouri]
    if i >= 1:
      if (ryouri) == past+1:
        ans += c[ryouri-1]
    past = ryouri
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
A.append(-1)
for i in range(N):
    sum += B[A[i] - 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()))
sat = sum(B)
for i in range(1, N):
    if A[i]  - A[i - 1] == 1:
        sat += C[A[i - 1] -1]
print(sat)

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

Solution (Python):
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math
import heapq

from scipy.sparse.csgraph import floyd_warshall

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:
        break
    else:
        if A[i] + 1 == A[i+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()]

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

stsf = 0
before = N
for a in A:
    stsf += B[a-1]
    if a == before+1:
        stsf += C[a-2]
    before = a
print(stsf)

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

ans = sum(b)

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

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

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

score = 0
for i in range(N):
  score += Bs[As[i]-1]
  if i >= 1 and As[i]-1==As[i-1]:
    score += Cs[As[i]-1]
print(score)

Solution (Python):
def calBonus():
    s = 0
    for i in range(n - 1):
        if a[i + 1] == a[i] + 1:
            s += c[a[i] - 1]

    return s


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

base = sum(b)
bonus = calBonus()
print(base + bonus)

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)):
  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()))
befor = 0
count = 0

for i in A:
    if befor == 0:
        count += B[i-1]
        befor = i
        continue

    if befor == i - 1:
        count += B[i-1] + C[befor-1]
        befor = i
    else:
        count += B[i-1]
        befor = i

print(count)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
c_list = []
c_sum = 0
total = 0
for i in range(1, len(a)):
    if a[i] - 1 == a[i - 1]:
        c_list.append(a[i-1]-1)
    else:
        continue

for num in c_list:
    c_sum += c[num]

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

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

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

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

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

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

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

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

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

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()))
C = 0
for i in range(N-1):
  if li_a[i] == li_a[i+1] - 1:
    C += li_c[li_a[i]-1]
B = sum(li_b)
print(B+C)

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

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

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

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

x = 0 
p = 0 
j = -2 

for i in range(n):
  p = int(a[i]) - 1
  x += int(b[p])
  if j + 1 == p:
    x += int(c[j])
  j = p

print(x)

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

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

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

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

sum = 0

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

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

ans = 0
before_i = 100
for i in an:
    ans += bn[i-1]
    if (i-before_i) == 1:
        ans += cn[before_i-1]
    before_i = 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 = -1
for i in range(n):
  if a_list[i] == prev + 1:
    ans += b_list[a_list[i] - 1] + c_list[prev - 1]
  else:
    ans += b_list[a_list[i] - 1]
  prev = a_list[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( )]
mansoku=0
A.append(-1)
for i in range(N):
    mansoku += B[A[i]-1]
    if A[i]+1 == A[i+1]:
        mansoku += C[A[i]-1]
print(mansoku)

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

ans = 0

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

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

print(ans)

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

Solution (Python):
import sys

input = sys.stdin.readline

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

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

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

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

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

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

    
print(hap)

Solution (Python):


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

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

Solution (Python):
def main():

    n = int(input())
    a = [i for i in map(int, input().split())]
    b = [i for i in map(int, input().split())]
    c = [i for i in map(int, input().split())]


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


if __name__ == '__main__':
    main()

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

t = [list(map(int,input().split())) for i in range(3)]

ans = 0;


j = 1
while j <= n - 1 :
    if t[0][j - 1] + 1 == t[0][j] :
        ans += t[2][t[0][j - 1] - 1]
    j += 1

print(sum(t[1]) + 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()]

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

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

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

score = 0

for i,a in enumerate(a_list):
    score += b_list[a-1]
    if i != 0:
        if prev + 1 == a:
            score += c_list[prev-1]
    prev = 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()))
x = sum(b)
for i in range(n - 1):
    if a[i] + 1 == a[i+1]:
        x = x + c[a[i]-1]
print(x)

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(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

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

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

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

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

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

print(ans)

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

sut = 0
i = 0

while i < N:
    sut += B[i]
    if i < N-1 and (A[i]+1) == A[i+1]:
        sut += C[(A[i]-1)]
    i += 1

print(sut)

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

x = sum(b)
for A, B in zip(a, a[1:]):
  if B == A + 1:
    x += c[A - 1]

print(x)

Solution (Python):
x = int(input())
y = input().split()
z = input().split()
a = input().split()

point = 0
tmp = 100

for i in y:
  point += int(z[int(i)-1])
  if tmp == (int(i)-2):
    point += int(a[int(i)-2])
  tmp = int(i)-1
print(point)