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

point = []

for i in range(len(A)):
    ryori = A[i]
    point.append(B[ryori - 1])
    if i > 0:
        if ryori - A[i - 1] == 1:
            point.append(C[ryori - 2])

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

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:
# 2019-11-18 00:38:19(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n = int(sys.stdin.readline().rstrip())
    
    eating_order = [int(x) for x in sys.stdin.readline().split()]
    base_point = sum([int(x) for x in sys.stdin.readline().split()])
    bonus_points = [0] + [int(x) for x in sys.stdin.readline().split()]

    total = base_point
    for i in range(n-1):
        if eating_order[i+1] == eating_order[i] + 1:
            total += bonus_points[eating_order[i]]

    print(total)

if __name__ == "__main__":
    main()

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()))
l=[0]*(n+1)
count=0
for i,a2 in enumerate(a,1):
    l[a2]=i
l=l[1:]
for j in range(n-1):
    if l[j]+1==l[j+1]:
        count+=c[j]
print(sum(b)+count)

Submission status: Accepted

Solution code:
N = int(input())
An = list(map(int,input().split(' ')))
Bn = list(map(int,input().split(' ')))
Cn = list(map(int,input().split(' ')))

sum_count = 0
previous_number = -100
for a in An:
    sum_count += Bn[a-1]
    if previous_number + 1 == a:
        sum_count += Cn[previous_number-1]
    previous_number = a
print(sum_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(' ')))
tmp = 60
ans = 0
for i in A:
    ans = ans + B[i-1]
    if i-1 == tmp:
        ans = ans + C[i-2]
    tmp = 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()))
sum = 0
for i in range(N):
    n = A[i]-1
    sum += B[n]
    if (A[i] == A[i-1]+1)and(0 < i):
        j = A[i-1] - 1
        sum += C[j]
print(sum)

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(C) #Cはn-1こなことに注意

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

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

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()
B = inpl()
C = inpl()

A = [(i, A[i]) for i in range(N)]
A.sort()

ans = sum(B)
for a, na in zip(A, A[1:]):
    if a[1] + 1 == na[1]:
        ans += C[a[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 = sum(b)
count = 100
for i in a:
  if i - 1 == count:
    ans += c[i - 2]
  count = i
print(ans)

Submission status: Accepted

Solution code:
#140
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(len(a)-1):
    if a[i]+1 == a[i+1]:
        s += c[a[i]-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()))
a=0
for co,i in enumerate(A):
    if co==0 :
        a+=B[i-1]
    if co>=1 :
        if A[co-1]+1==A[co]:
            a+=B[i-1]
            a+=C[A[co-1]-1]
        else:
            a+=B[i-1]
print(a)

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
*c, = map(int, input().split())
ans = 0
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)

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
old =100
sum_val =0
for x in A:
    B_index = x-1
    sum +=B[x-1]
    if B_index ==old+1:
        sum +=C[old]
    old = B_index
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()))
score = 0

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

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

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

manzoku=0

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

Submission status: Accepted

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

for a_idx, i in enumerate(a):
  res += b[i]
  if a_idx >= 1 and (a[a_idx - 1] + 1 == i):
    res += c[i-1]

print(res)

Submission status: Accepted

Solution code:
n = int(input())
alis = list(map(int,input().split()))
blis = list(map(int,input().split()))
clis = list(map(int,input().split()))

sum = 0
for i in range(n):
    sum += blis[alis[i]-1]
    if i != 0:
        if alis[i] == alis[i-1] +1:
            sum += clis[alis[i-1]-1]
print(sum)

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()))
point = sum(Blist)
for i in range(0, N - 1):
    if Alist[i + 1] == Alist[i] + 1:
        point += Clist[Alist[i] - 1]

print(point)

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

Submission status: Accepted

Solution code:
N = int(input())
AS = list(map(int, input().split()))
BS = list(map(int, input().split()))
CS = list(map(int, input().split()))

total = 0
last = None
for x in AS:
    total += BS[x - 1]
    if x - 1 == last:
        total += CS[x - 2]
    last = x
print(total)

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

delisious = 0

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

print(delisious)

Submission status: Accepted

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

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] - 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(" ")) )#追加満足度


#満足度を足し合わせていく
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)

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

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)

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

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

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

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)

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

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)

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

sat = sum(B)

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

print(sat)

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

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

Submission status: Accepted

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


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


# B
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


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    B()
    return


# Solve
if __name__ == "__main__":
    B()

Submission status: Accepted

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

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

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

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

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)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split())) #食べた料理（n種類）
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)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

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

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 != 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 = 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))

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

print(pnt)

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<n-1:
        if a[i]==a[i+1]-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
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)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

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 <= N-2:
    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 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)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):#料理=A[i]
    if(A[i]+1==A[i+1]):
        sat += C[A[i]-1]
        #print(i,C[A[i]])
print(sat)

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