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

def solve(A,B,C):
    ans = sum(B)
    for i in range(N-1):
        if A[i+1]==A[i]+1:
            ans += C[A[i]-1]
    return ans
print(solve(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(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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
r=0
k=-9
for i,j in enumerate(a):
    r+=b[j-1]
    if j-1==k+1:
        r+=c[j-2]
    k=j-1
print(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()))
ans = 0
for i in range(n-1):
    if A[i]==A[i+1]-1:
        ans += C[A[i]-1]
ans += sum(B)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    lc=list(map(int,input().split()))
    manzoku=sum(lb)
    for j in range(n-1):
        if la[j+1]-la[j]==1:
            manzoku+=lc[la[j]-1]
    print(manzoku)

resolve()

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    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)
    k = -1
    for i in A:
        if i == k + 1:
            ans += C[k-1]
        k = i
    print(ans)


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 <= n-2 and 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-2 and a[i]+1 == a[i+1]:
        ans += c[a[i]-1]

print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
food_list = list(map(int, input().split()))
satis_list = list(map(int, input().split()))
moreS_list = list = list(map(int, input().split()))

total = sum(satis_list)

for i in range(n-1):
    if food_list[i] + 1 == food_list[i+1]:
        total += moreS_list[food_list[i]-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()))
ans = 0
pre = -1
for a in A:
  ans += B[a-1]
  if a - 1 == pre:
    ans += C[a-2]
  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())) 
ans = 0
for i in range (n):
  ans += B[i]
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()))
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:
n = int(input())

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

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

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

for i in range(1, len(A)):
  if 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 = 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()))

s = b[a[0]-1]

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
count = 0
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
for i in range(N-1):
  count = count + B[A[i]-1]
  if A[i+1] == A[i] + 1:
    count = count + C[A[i]-1]
                      
count = count + B[A[N-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 = 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()))
j = -1
res = 0
for  i in a:
    if i - 1 == j:
        res += c[j-1]
    j = i
print(res+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()))

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())
as_=list(map(int,input().split()))
bs=list(map(int,input().split()))
cs=list(map(int,input().split()))
p=sum(bs)+sum([cs[a-1] for a,a_ in zip(as_,as_[1:]) if a+1==a_])
print(p)

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

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

lis=[]
for i in range(0,n-1):
  if a[i]==a[i+1]-1:
    lis.append(a[i])
plus=0
for j in range(0,len(lis)):
  plus+=c[lis[j]-1]
print(sum(b)+plus)

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

ans = 0
for i in range(len(a_list)):
    ans += b_list[a_list[i] - 1]
    if i > 0 and a_list[i] == a_list[i - 1] + 1:
        ans += c_list[a_list[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()))
cnt = 0
for i in range(1,n):
    if a[i] == a[i - 1] + 1:
        cnt += c[a[i - 1] - 1]
cnt += sum(b)
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 = sum(B)

for i in range(1, n):
    if A[i - 1] + 1 == A[i]:
        ans += C[A[i - 1] - 1]
    else:
        pass

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

def main():
    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()]
    
    Bs = []
    for i in range(1, N):
        if A[i] - A[i-1] == 1:
            Bs.append(C[A[i -1] - 1])

    print(sum(B) + sum(Bs))

main()

Submission status: Accepted

Solution code:
a=int(input())
b=input().split()
c=input().split()
count=0
for i in c :
  count+=int(i)

d=input().split()
list1=[]

for i in range(len(b)-1) :
  if int(b[i+1])-int(b[i])==1 :
    
    count+=int(d[int(b[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()))
ans=0
k=-2
for i in a:
    ans+=b[i-1]
    if i==k+1:
        ans+=c[k-1]
    k=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()))
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:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = LI1()
    B = LI()
    C = LI()

    # print(A)
    # print(B)
    # print(C)
    pre = -4
    ans = 0
    for a in A:
        score = B[a]
        if a - pre == 1:
            score += C[pre]
        ans += score
        pre = a
    print(ans)


if __name__ == '__main__':
    solve()

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

Submission status: Accepted

Solution code:
n = int(input())
aaa = list(map(int, input().split()))
li_a = []
for i in aaa:
  i -= 1
  li_a.append(i)
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
ans = 0
for i in range(n):
  ans += li_b[li_a[i]]
  if i-1 >= 0:
      if li_a[i] == li_a[i-1]+1:
        ans += li_c[li_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 = 0
total += sum(b)
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        total += c[a[i]-1]
print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
A = [int(s)-1 for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]


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

print(cnt)

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]

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

print(s)

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()]
satis = 0
pre = -9
for i in a:
	satis += b[i - 1]
	if i - 1 == pre:
		satis += c[i - 2]
	pre = i
print (satis)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(s) for s in input().split(' ')]
B = [int(s) for s in input().split(' ')]
C = [int(s) for s in input().split(' ')]
ret = 0
prev = -1
for i in range(N):
    ii = A[i] - 1
    ret += B[ii]
    if prev > -1:
        if prev + 1 == ii:
            ret += C[prev]
    prev = ii
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
aaa = list(map(int, input().split(' ')))
bbb = list(map(int, input().split(' ')))
ccc = list(map(int, input().split(' ')))
ans = 0
old = -999
for i in aaa:
    ans += bbb[i-1]
    if i == old + 1 and old-1 < len(ccc):
        ans += ccc[old-1]
    old = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			




N=input1()
A=input_array()
B=input_array()
C=input_array()
result=0
before=0
for i in range(N):
	result+=B[A[i]-1]
	if (before+1==A[i]) and before!=0:
		result+=C[A[i]-2]
	before=A[i]

print(result)

Submission status: Accepted

Solution code:
n=int(input())
lista=list(map(int,input().split()))
listb=list(map(int,input().split()))
listc=list(map(int,input().split()))
list=[]
for i in range(2,n+1):
  if lista[i-1]==lista[i-2]+1:
    list.append(lista[i-2])
vonus=0
for x in list:
  vonus+=listc[x-1]
print(sum(listb)+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()))
cnt = 0

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


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

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

m = 0

mae = -1
for a in A:
  m += B[a - 1]
  if a - mae == 1:
    m += C[mae - 1]
  mae = a

print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
b = input().split()
c = input().split()
count = 0
k = -100
for x in a:
  num = int(x)
  count += int(b[num-1])
  if k+1 == num:
    count += int(c[num-2])
  k = num
print(count)

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

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, len(a)):
    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())
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[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()))
M=list(map(int,input().split()))
L=list(map(int,input().split())) ; ans=0
for i in range(n):
    ans+=M[A[i]-1]
    if i!=n-1:
        if A[i]+1==A[i+1]:
            ans+=L[A[i]-1]
print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
lia = list(map(int, sys.stdin.readline().split()))
lib = list(map(int, sys.stdin.readline().split()))
lic = list(map(int, sys.stdin.readline().split()))
s = sum(lib)
li = []
i = 0
while i < n-1:
  if lia[i+1] - lia[i] == 1:
    li.append(lia[i]-1)
  i += 1
for i in li:
  s += lic[i]
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()))
#すべての合計をsとする
s = 0
#とりあえずBで与えられた満足度は確実に得られる
sb = sum(B)
#Cで追加で与えられるかもしれない満足度をscとする
sc = 0
#食べた料理番号が連続している場合追加の満足度が増加する(問題の条件から)
for i in range(N-1):
  if A[i+1] == A[i] + 1:
    sc += C[A[i]-1]
#すべての合計=Bで与えられる満足度+Cの追加分の満足度
s = sb + sc
#結果
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()))
s = 0
sb = sum(B)
sc = 0
for i in range(N-1):
  if A[i+1] == A[i] + 1:
    sc += C[A[i]-1]
s = sb + sc
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)
x=-1
for i in a:
    if x+1==i:
        ans+=c[x-1]
    x = 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 = 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()))

d = dict(zip(A, B))
ans = d[A[0]]

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

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
i_b = 100
for i in a:
    manzoku+=b[i-1]
    if i-1 == i_b:
        manzoku+=c[i-2]
    i_b = i

        
print(manzoku)

Submission status: Accepted

Solution code:

n = int(input())

get_line = lambda: [int(x) for x in input().split()]

A = get_line()

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

C = get_line()

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

print(b)

Submission status: Accepted

Solution code:
N = int(input())
eat_list = list(map(int, input().split()))
manzok_list = list(map(int, input().split()))
add_manzok_list = list(map(int, input().split()))

manzok = 0

for i in range(N):
 manzok += manzok_list[eat_list[i]-1]
 if(i > 0 and (eat_list[i] - eat_list[i-1]) == 1):
   manzok += add_manzok_list[eat_list[i-1]-1]

print(manzok)

Submission status: Accepted

Solution code:
# AtCoder

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

sm = sum(b)
cnt = 0

for i in range(1, N):
    if a[i-1]+1 == a[i]:
        aidx = a[i]-1
        cnt += c[aidx-1]
print(sm+cnt)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def main():
    N, *ABC = map(int, read().split())
    A = ABC[:N]
    B = ABC[N:2*N]
    C = ABC[2*N:]
    ans = sum(B)
    for i in range(N-1):
        if A[i] == A[i+1] - 1:
            ans += C[A[i]-1]
    print(ans)
    return

if __name__ == '__main__':
    main()

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()))
totalSatis = 0
lastItem = 0
for i in As:
    totalSatis += Bs[i-1]
    if lastItem == i-1 and lastItem != 0:
        totalSatis += Cs[lastItem-1]
    lastItem = i
print(totalSatis)

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

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

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

print(sum(b)+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 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()))
A.append(-1)
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ret = 0
for i in range(N):
  ret += B[A[i]-1] + C[A[i]-1] if A[i+1] == A[i]+1 else B[A[i]-1]
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = sum(list(map(int, input().split())))
c = list(map(int, input().split()))
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 = [int(i) for i in input().split(" ")]
B = [int(i) for i in input().split(" ")]
C = [int(i) for i in input().split(" ")]

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

Submission status: Accepted

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

for i in range(len(A)-1):
    if A[i]+1==A[i+1]:
        l.append(C[A[i]-1])

total=sum(B)+sum(l)
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()))
total_b = sum(b)
t_c=0
for i in range(1,n):
    if a[i-1]+1==a[i]:
        t_c+=c[a[i-1]-1]

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

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

    ans = 0

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

        if i < n - 1 and a[i + 1] - a[i] == 1:
            ans += c[a[i] - 1]

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
3 1 2
2 5 4
3 6"""
        output = """14"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
2 3 4 1
13 5 8 24
45 9 15"""
        output = """74"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2
1 2
50 50
50"""
        output = """150"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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]
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:
# 初期入力
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())) )

#
manzoku =sum(B)
for i in range(N-1):
    if A[i+1] -A[i] ==1: # Ai Ai+1と続くとCiが加算
        manzoku +=C[A[i]-1] #iは０～N-1
        
print(manzoku)

Submission status: Accepted

Solution code:
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
a_old = a_list[0] - 1
for i in range(n):
    a = a_list[i] - 1
    ans += b_list[a]
    if a - a_old == 1:
        ans += c_list[a_old]
    a_old = 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):
    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()))


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

print(sum+cnt)

Submission status: Accepted

Solution code:
# ABC 140: B – Buffet
N = int(input())
A = [int(s) - 1 for s in input().split()]
B, C = [[int(s) for s in input().split()] for _ in range(2)]

s = B[A[0]]

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

print(s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    prev = -1
    ans = 0
    for i in range(N):
        ans += B[A[i]-1]
        if A[i]==prev+1:
            ans+=C[prev-1]
        prev=A[i]
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()