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()))) #料理iの満足度
c = list(map(int,(input().split()))) 

result = 0
mae = 1111
for i in a:
    #print("result",result)
    result += b[i-1]
    #print("mae,b[i-1]",mae,i)
    if mae == i -1:
        #print("if",result)
        result += c[i-2]
    mae = i

print(result)

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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())

inputs = []

for i in range(3):
    inp = [int(x) for x in input().split(' ')]
    inputs.append(inp)

def solve(n, inputs):
    a = inputs[0]
    b = inputs[1]
    c = inputs[2]

    satisfaction = 0
    last = -1
    dish = -1
    for d in range(n):
        dish = a[d]        
        if dish == last + 1:
            satisfaction += c[dish-2]
        last = a[d]        
        satisfaction += b[dish-1]

    print(satisfaction)

solve(n, inputs)

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(len(A)):
#    print (f"i={i},A[i]-1={A[i]-1},B={B[A[i]-1]}")
    score += B[A[i]-1]

    if i != len(A)-1:
        if A[i+1] == A[i] + 1:
#            print (f"c,C[A[i]-1]={C[A[i]-1]}")
            score += C[A[i]-1]
#    print (f"score={score}")
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()))
pre = -10
ans = 0
for a in A:
    ans += B[a-1]
    if a == pre + 1:
        ans += C[pre-1]
    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()))
pnt = 0
cnt = -2
for i in a:
  if i == cnt+1:
    pnt += c[cnt-1]
  pnt += b[i-1]
  cnt = i
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()))

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

print(e)

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

Submission status: Accepted

Solution code:
n = int(input())
a_s = list(map(int, input().split(' ')))
b_s = list(map(int, input().split(' ')))
c_s = list(map(int, input().split(' ')))

sat = 0
for a_i in range(0, n):
    i = a_s[a_i] - 1
    b = b_s[i]
    sat += b
    if a_i < n-1 and a_s[a_i] +1 == a_s[a_i+1]:
        if i >= 0:
            sat += c_s[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()))

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

Submission status: Accepted

Solution code:
import numpy as np
input()
A = np.array(input().split(), np.int16) - 1
B = np.array(input().split(), np.int16)
C = np.array(input().split(), np.int16)
print(B.sum() + C[A[:-1][A[1:] - A[:-1] == 1]].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(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()))

count = 0
count_list = []
result = 0

for i in range(len(A)):
  if i != 0 and i < len(A):
    if A[i-1] == A[i]-1:
      count_list.append(A[i-1])
  result += B[A[i]-1]

for i in count_list:
  result += C[i-1]

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

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

for i in range(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()))

tmp = n
ans = 0
for i in A:
    ans += B[i - 1]
    if tmp + 1 == i - 1:
        ans += C[tmp]
    #print('ans :', end = ' ')
    #print(ans)
    tmp = i - 1
    #print('tmp :', end = ' ')
    #print(tmp)
print(ans)

Submission status: Accepted

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

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

	pre_ai = ai

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
a_arr = list(map(int, input().split()))
b_arr = list(map(int, input().split()))
c_arr = list(map(int, input().split()))

ans = b_arr[a_arr[0]-1]
for i in range(1,N):
    if a_arr[i] == a_arr[i-1]+1:
        ans += c_arr[a_arr[i]-2]+b_arr[a_arr[i]-1]
    else:
        ans += b_arr[a_arr[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
tmp = -1
for a_i in a:
    if a_i == tmp + 1:
        ans = ans + b[a_i-1] +c[tmp-1]
    else:
        ans += b[a_i-1]
    tmp = a_i
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
b=[0]*n
c=[0]*n
a[:]=map(int,input().split())
b[:]=map(int,input().split())
c[1:]=map(int,input().split())
r=0
l=n
for ii in range(n):
  r+=b[a[ii]-1]
  if l+1==a[ii]-1:
    r+=c[a[ii]-1]
  l=a[ii]-1
print(r)

Submission status: Accepted

Solution code:
N = int(input())
As = [A-1 for A in map(int, input().split())]
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

ans = 0
APrev = -100
for i in range(N):
    A = As[i]
    ans += Bs[A]
    if APrev == A-1:
        ans += Cs[APrev]
    APrev = A

print(ans)

Submission status: Accepted

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

foods = {}
for i, b in zip(range(1, N + 1), B):
    if i != N:
        foods[i] = {
            "point": b,
            "bonus": C[i - 1],
            "bonus_food": i + 1
        }
    else:
        foods[i] = {
            "point": b,
            "bonus": 0,
            "bonus_food": -1
        }

point = 0
before = {
    "point": 0,
    "bonus": 0,
    "bonus_food": 0
}
for a in A:
    point += foods[a]["point"]

    if before["bonus_food"] == a:
        point += before["bonus"]

    before = foods[a]

print(point)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:16:28 2020

@author: Kanaru Sato
"""

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+1] == a[i]+1:
        sat += c[a[i]-1]

print(sat)

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

mae=0
MAN=0
i=0
while i<N:
    MAN+=BList[(AList[i])-1]
    if (mae+1)==AList[i] and i!=0:
        MAN+=CList[mae-1]
    
    
    mae=AList[i]
    
    
    i+=1

print(MAN)

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()]
a.append(0)

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

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1
sum = b[a[0]]
for i in range(1,n):
    if a[i-1] + 1 == a[i]:
        sum += b[a[i]]+c[a[i]-1]
    else:
         sum += b[a[i]]

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 range(n-1):
  if a[i]+1 == a[i+1]:
    ans += b[a[i]-1]+c[a[i]-1]
  else:
    ans += b[a[i]-1]
ans += b[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)
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):
    ans += b[a[i]-1]
    if 1<=i and a[i]-a[i-1] == 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 = 0
ate = a[0]
ans += b[ate-1]
for i in range(1,n):
    eat = a[i]
    ans += b[eat-1]
    if ate + 1 == eat:
        ans += c[ate-1]
    ate = eat
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, a in enumerate(A):
    ans += B[a-1]
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:
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:(input())

"""========main code==============="""
t=ii()
a=ll()
b=ll()
c=ll()
ans=0
for i in range(t):
    ans+=b[a[i]-1]
    if(i<t-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()))

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

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

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()))
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 = input().split()
b = input().split()
c = input().split()
sum = 0
number = -2

for i in a:
  k = int(i)-1
  sum += int(b[k])
  if number + 1 == k:
    sum += int(c[k-1])
  number = k
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 range(N-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]
        
print(ans + sum(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()))
cnt=0
for i in range(N-1):
  cnt += B[A[i]-1] #A[i]を食べることで得られる満足
  if A[i]+1==A[i+1]: #うれしい
    cnt += C[A[i]-1]
cnt += B[A[N-1]-1] #最後の分

print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def solve(A, B, C):
    n = len(A)
    ans = sum(B)
    for i in range(n):
        if i < n - 1 and A[i] + 1 == A[i+1]:
            ans += C[A[i]-1]
    return ans

def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    print(solve(A, B, C))

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
A = inputIL()
B = inputIL()
C = inputIL()

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

count = 0

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

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

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

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

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

print(res)

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()))
ans = sum(b_list)
for i in range(n-1):
    if a_list[i+1]-a_list[i] == 1:
        ans += c_list[a_list[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()))
happy=0
old_a=n
for i in range(n):
    new_a=a[i]
    happy+=b[(new_a-1)]
    if new_a==old_a+1:
        happy+=c[new_a-2]
    old_a=new_a
print(happy)

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

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()))
d = {}
e = {}
cnt = 0
for i in range(1, n+1):
    d[i] = B[i-1]
for i in range(1, n):
    e[i] = C[i-1]
for i in range(n):
    cnt += d[A[i]]
    if i != 0:
        if A[i] == 1:
            continue 
        else:
            if A[i] == A[i-1] + 1:
                cnt += C[A[i]-2]
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()))
cnt = sum(b)
for i in range(n):
  if i<=n-2 and (a[i+1] - a[i] == 1):
    cnt += c[a[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()))
a = [i-1 for i in a]
ans = b[a[0]]
for i in range(1, n):
    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()))
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 and ( A[i-1] + 1 ) == A[i]:
        cnt += C[A[i-1]-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 and 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()))
ans = sum(list(map(int,input().split())))
c = list(map(int,input().split()))
for i in range(1,n):
    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()))
add = 0
a1 = a[:-1]
for i, m in enumerate(a1):
    if m+1 == a[i+1]:
        add += c[m-1]
print(sum(b)+add)

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

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    prev = -100
    s = 0
    for a in A:
        s += B[a-1]
        if a - prev == 1:
            s += C[prev-1]
        prev = a

    print(s)


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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = LI()
B = LI()
C = LI()

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

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):
    ans += b[a[i]-1]
    if a[i+1]-a[i] == 1:
        ans += c[a[i]-1]
        
ans += b[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 = 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:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

tmp = A[1:]

tmp = np.append(tmp, -1)

add = A[np.where((tmp-A)==1)]

ans = B.sum() + C[add-1].sum()
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()))
d=sum(b)
m=[]
for i in range(N-1):
  if a[i+1]-a[i]==1:
    m.append(c[a[i]-1])
e=sum(m)
print(d+e)

Submission status: Accepted

Solution code:
from sys import argv

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
c = c + [0] * (len(b) - len(c))
ans = 0
debug = "a" in argv
for index, x in enumerate(a):
    ans += b[x - 1]
    if a[index - 1] + 1 == a[index] and index != 0:
        if debug:
            print(x, index, a[index - 1], a[index])
            print(c[x - 2], c[x - 1])
        ans += c[x - 2]
print(ans)

Submission status: Accepted

Solution code:
# B - Buffet

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

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

for target in A:
  ans += B[target-1]
  if(pre == -1):
    pre = target
    continue
  if(pre + 1 == target):
    ans += C[pre - 1]
  pre = target
print(ans)

Submission status: Accepted

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

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

print(sf)

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

ans = sum(b[ai] for ai in a) + sum(c[ai] for ai, aii in zip(a, a[1:]) if ai + 1 == aii)
print(ans)

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

for i in range(n-1):
    a1 = a_lst[i]
    a2 = a_lst[i+1]
    b = b_lst[a1-1]
    good += b
    if a1+1==a2:
        c = c_lst[a1-1]
        good += c

a = a_lst[-1]
b = b_lst[a-1]
good += b
print(good)

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.readline().split()))

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

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

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

manzoku=0


for i in range(N):
    ryori = A[i]

    manzoku+=B[ryori-1]

    if i!=0:
        if ryori-1 == ryori_pre:
            manzoku+=C[ryori_pre-1]

    ryori_pre = A[i]


print(manzoku)

Submission status: Accepted

Solution code:
n = 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 = []
B = []
C = []
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
C = list(map(int, input().split(' ')))
satis = 0
for i in range(N - 1):
  satis += B[A[i] - 1]
  if A[i] + 1 == A[i + 1]:
    satis += C[A[i] - 1]
satis += B[A[N - 1] - 1]
print(satis)