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



Sample input:
3
3 1 2
2 5 4
3 6


Sample output:
14

Submission status: Accepted

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

p=n+1
ans =0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#abc140b

n=int(raw_input())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
c=map(int,raw_input().split())
res=sum(b)
for i in xrange(n-1):
 if a[i+1]==a[i]+1:
  res+=c[a[i]-1]
print res

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pre_a = -1
ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

score=0
for i in range(n):
  score+=b_l[a_l[i]-1]
  if(i>0):
    if(a_l[i]-a_l[i-1]==1):
      score+=c_l[a_l[i-1]-1]  
   
print(score)

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
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=-1
for i in range(n):
    ans+=b[a[i]-1]
    if a[i]-1==before:
        ans+=c[before-1]
    before=a[i]
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
b_sum=sum(b)
c_sum=0

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

print(b_sum + c_sum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline
# from collections import defaultdict
# import bisect

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

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 = sum(B)

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

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np 

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

sum=np.sum(listA[2])
for i in range(len(listA[1])-1):
  if listA[1][i+1]-listA[1][i]==1:
    b=listA[1][i]-1
    sum+=listA[3][b]
    
print(sum)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 (sum(B) + ans)

Submission status: Accepted

Solution code:
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    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 - 1] + 1 == A[i]:
            ans += C[A[i - 1] - 1]

    print(ans)


sol()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))


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

Submission status: Accepted

Solution code:
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()] 

satify = 0

for i in range(len(a)):
    if i == 0 or a[i-1] == n or a[i]-1 != a[i-1]:
        satify += b[a[i]-1]
    else:
        satify += b[a[i]-1] + c[a[i-1]-1]
        
print(satify)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(s) for s in input().split()]
b_list = [int(s) for s in input().split()]
c_list = [int(s) for s in input().split()]

manzokudo = 0
prev_a = 0

for jun in a_list:
    manzokudo = manzokudo + b_list[jun-1]
    if jun > 1:
        if jun == prev_a + 1:
            manzokudo = manzokudo + c_list[prev_a-1]
    prev_a = jun
        
print(manzokudo)

Submission status: Accepted

Solution code:
s=input()
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=list(map(int,input().split()))
a=len(t)
b=len(u)
d=0
for i in range(b):
  d=d+u[i]
for j in range(a-1):
  if t[j]+1==t[j+1]:
    e=t[j]-1
    d=d+v[e]
print(d)

Submission status: Accepted

Solution code:
N = int(input())

list_A = list(map(int,input().split()))
list_B = list(map(int,input().split()))
list_C = list(map(int,input().split()))

b_val = 0

for i in range(N):
    aaa = list_A[i]
    b_val += list_B[aaa-1]
    if i ==0:
        continue
    elif aaa == list_A[i-1]+1:
        b_val += list_C[list_A[i-1]-1]
print(b_val)

Submission status: Accepted

Solution code:
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):
    score += B[A[i]-1]
    if i != 0 and A[i] == A[i-1] + 1:
        score += C[A[i-1]-1]

print(score)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

print(res)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Ai = list(map(int,input().rstrip().split(" ")))
Bi = list(map(int,input().rstrip().split(" ")))
Ci = list(map(int,input().rstrip().split(" ")))
previous = -100
satisfied = 0
for current in Ai:
  satisfied += Bi[current - 1]
  if current == previous + 1:
    satisfied += Ci[previous - 1]
  previous = current
print(satisfied)

Submission status: Accepted

Solution code:
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in range(3)] 
x=0
for i,_ in enumerate(a):
  if(i==len(a)-1):
    break
  elif(a[i]+1==a[i+1]):
    x+=c[a[i]-1]
print(sum(b)+x)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
a, b, c = [list(map(int, input().split())) for _ in range(3)]

ans = sum(b)
for x, y in zip(a[:-1], a[1:]):
    if x + 1 == y:
        ans += c[x-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
m = 0
for i, a in enumerate(A):
    m += B[a-1]
    if i > 0:
        if A[i-1] + 1 == A[i]:
            m += C[a-2]
print(m)

Submission status: Accepted

Solution code:
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):
    if(a[i] - a[i-1] == 1):
      sum += int(c[a[i-1]-1])
print(sum)

Submission status: Accepted

Solution code:
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()]
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)

Submission status: Accepted

Solution code:
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()]

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(v) for v in input().split(' ')]
B = [int(v) for v in input().split(' ')]
C = [int(v) for v in input().split(' ')]

point = 0
prev_dish = -1
for i in range(0, N):
    dish = A[i]
    point += B[dish - 1]

    if prev_dish + 1 == dish:
        point += C[prev_dish - 1]
    prev_dish = dish

print(point)

Submission status: Accepted

Solution code:
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()]

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

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += Blist[i]
for i in range(N-1):
    if Alist[i]+1 == Alist[i+1]:
        # AlistとBlist,Clistの対応する並び方をあわせる　わかりづらい
        ans += Clist[Alist[i]-1]

print(ans)

Submission status: Accepted

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

cplus = 0

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

print(sum(B) + cplus)

Submission status: Accepted

Solution code:
n=int(input())

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

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

print(s)

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
orders = list(map(int, input().split()))
su1 = list(map(int, input().split()))
su2 = list(map(int, input().split()))

total = 0
lastmeal = 0
for i, num in enumerate(orders):
    if i==0:
        total += su1[num-1]
    else:
        if 1 == num - lastmeal and lastmeal != len(su2)+1:
            total += su1[num-1] + su2[lastmeal-1]
        else:
            total += su1[num-1]
    lastmeal = num
print (total)

Submission status: Accepted

Solution code:
N = int(input())
a = input().split(' ')
b = input().split(' ')
c = input().split(' ')

total_point = 0
before_eat = -2

for i in range(N):
  now_eat = int(a[i]) - 1
  point = int(b[now_eat])
  if now_eat == before_eat + 1:
    additional_point = int(c[before_eat])
  else:
    additional_point = 0
  total_point = total_point + point + additional_point
  before_eat = now_eat
  
print(total_point)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

ans = 0
ans = sum(b)

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

print(str(ans))

Submission status: Accepted

Solution code:
N=int(input())
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
Clist=list(map(int,input().split()))
 
Cplus=0
for n in range (0,N-1):
  if Alist[n+1] == Alist[n]+1:
    Cplus += Clist[Alist[n]-1]
 
print(sum(Blist)+Cplus)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
c_lst = list(map(int, input().split()))

ans = 0
for i in range(n):
  a = a_lst[i]
  ans += b_lst[a-1]
  if i<n-1 and a_lst[i+1] == a+1:
    ans += c_lst[a-1]
print(ans)

Submission status: Accepted

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

previous_dish = -100
satisfaction_level = 0

for index in range(n):
    satisfaction_level += b[a[index] - 1]
    if previous_dish + 1 == a[index]:
        satisfaction_level += c[previous_dish - 1]

    previous_dish = a[index]

print(satisfaction_level)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    al = list(map(int, input().split()))
    for i in range(n):
        al[i] -= 1
    bl = list(map(int, input().split()))
    cl = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        ans += bl[al[i]]
        if i > 0:
            if al[i-1] + 1 == al[i]:
                ans += cl[al[i-1]]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
cList = list(map(int, input().split()))
ans = sum(bList)
before = -2
for i in range(0, n):
    a = aList[i] - 1
    if before + 1 == a:
        ans = ans + cList[before]
    before = a

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
Clist=list(map(int,input().split()))

Cplus=0
for n in range (N-1):
  if Alist[n+1] == Alist[n]+1:
    Cplus += Clist[Alist[n]-1]

print(sum(Blist)+Cplus)

Submission status: Accepted

Solution code:
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 0 < i  and a[i] == a[i-1]+1:
    s += c[a[i-1]-1]

print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
score = 0
last = -1
for i in A:
    score += B[i-1]
    if(last+1 == i):
        score += C[last-1]
    last = i
print(score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def _input():
    n = int(input())
    a = input().split()
    foods = convrt_to_int(a)
    b = input().split()
    satisfaction = convrt_to_int(b)
    c = input().split()
    add = convrt_to_int(c)
    return foods, satisfaction, add

def convrt_to_int(array):
    int_array = []
    for i in array:
        int_array.append(int(i))
    return int_array

def calc(foods, satisfaction, add):
    counter = 0
    total = satisfaction[foods[0] - 1]
    for i in foods:
        if counter == 0:
            counter += 1
            continue
        if i == foods[counter - 1] + 1:
            option = optional(i - 1,add)
            total += satisfaction[i - 1]
            total += option
        else:
            total += satisfaction[i - 1]
        counter += 1
    return total

def optional(index, add):
    return add[index - 1]


if __name__ == "__main__":
    foods, satisfaction, add = _input()
    print(calc(foods, satisfaction, add))

Submission status: Accepted

Solution code:
num = int(input())
A_i = [ int(x) for x in input().split()]
B_i = [ int(x) for x in input().split()]
C_i = [ int(x) for x in input().split()]
 
prev = 50
result = 0
for a in A_i:
  result += B_i[a-1]
  if a-1 == prev:
    result += C_i[prev-1]
  prev = a
  
print(result)

Submission status: Accepted

Solution code:
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):
	j = A[i]-1
	S += B[j]
	if i < N-1 and A[i+1] == A[i]+1:
		S += C[j]

print(S)

Submission status: Accepted

Solution code:
def intminus(a):
    return int(a) - 1


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


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

print(ans)

Submission status: Accepted

Solution code:
total_dish = int(input())
dish_order = list(map(int, input().split()))
satis_B = list(map(int, input().split()))
satis_C = list(map(int, input().split()))

ans = 0
for i in range(total_dish):
  ans = ans + satis_B[dish_order[i]-1]
  if dish_order[i] - dish_order[i-1] == 1 and i != 0:
    ans = ans + satis_C[dish_order[i-1]-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A,B,C=[list(map(int,input().split())) for _ in range(3)]
A=[x-1 for x in A]
ans=sum(B)
p=A[0]

for i in A[1::]:
    if i==p+1:
        ans+=C[p]
    p=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
def find(A,B,C):
    A=[x-1 for x in A]
    ans=B[A[len(A)-1]]
    for i in range(len(A)-1):
        now=A[i]
        next_one=A[i+1]
        if next_one==now+1:
            ans+=C[now]
        ans+=B[A[i]]
    return ans

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

print(find(A,B,C))

Submission status: Accepted

Solution code:
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+=c[a[i]-1]
print(x)

Submission status: Accepted

Solution code:

n = int(input())

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

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

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

m = n-1
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)

Submission status: Accepted

Solution code:
n = int(input())

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

sat = 0

prev_dish = -1
for i, dish in enumerate(A[1:]):
  sat += B[dish]
  if prev_dish == dish-1:
    sat += C[prev_dish]
  prev_dish = dish
  

print(sat)

Submission status: Accepted

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

ans = sum(B)

for i in range(1, N):
    if A[i - 1] == A[i] - 1:
        if len(C) - 1 >= A[i] - 2: 
          ans += C[A[i] - 2]
          # print('{}:{}'.format(i, C[i - 2]))

print('{}'.format(ans))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

C.append(0)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
manzoku = 0
prev = 0
 
for a in A:
  manzoku += B[a-1]
  if prev+1 == a and prev != 0:
    manzoku += C[prev-1]
  prev = a
print(manzoku)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(int(1e6))

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

ans = 0
prev = -1
for a in A:
    i = a - 1
    ans += B[i]
    if (prev + 1) == a:
        ans += C[i-1]
    prev = a

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    a = sum([B[i - 1] for i in A])
    c = sum([C[i - 1] for i, j in zip(A[:-1], A[1:]) if i == j - 1])
    print(a + c)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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
pre = -2
for a in A:
    ans += B[a]
    if pre == a - 1:
        ans += C[pre]
    pre = a

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
mem = set()
s=0
last =-5
for v in a:
    s+=b[v-1]
    if last+1 ==v and last<n:
        s+=c[last-1]
    last=v
print(s)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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()]

point = 0
i = 0

while  i < n :
    point += B[A[i] - 1]
    if i > 0 and A[i-1] == A[i] - 1 :
        point += C[A[i-1]-1]
    i += 1

print(point)

Submission status: Accepted

Solution code:
N = input()
Ai = input()
A = Ai.split(" ")
Bi= input()
B = Bi.split(" ")
Ci = input()
C = Ci.split(" ")
C.append(0)
A.append(0)
B.append(0)
ans = 0
for i in range(int(N)):
  if (int(A[i]) + 1) == int(A[i + 1]):
    ans = ans + int(B[int(A[i]) - 1]) + int(C[int(A[i]) - 1])
  else:
    ans = ans + int(B[int(A[i]) - 1])
print(ans)

Submission status: Accepted

Solution code:
numberN = int(input())
seqAi = list(map(int,input().split()))
benefitBi = list(map(int,input().split()))
increaseCi = list(map(int,input().split()))

# print(numberN)
# print(seqAi)
# print(benefitBi)
# print(increaseCi)

totalBenefit = 0
for k,seq in enumerate(seqAi):

    totalBenefit += benefitBi[seq -1]

    if k == 0:
        continue

    if seq == ( seqAi[k -1] +1 ):
        totalBenefit += increaseCi[seq -2]

print(totalBenefit)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(_) for _ in input().split()]
B=[int(_) for _ in input().split()]
C=[int(_) for _ in input().split()]
ans=0
a=10000000
for i in A:
  ans+=B[i-1]
  if i==a+1:
    ans+=C[a-1]
  a=i  
  
print(ans)