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

Submission status: Accepted

Solution code:
N = int(input())
buffet = [int(i) for i in input().split()]
satisfaction_level_B = [int(i) for i in input().split()]
satisfaction_level_C = [int(i) for i in input().split()]
count = []
result = 0

for i in buffet:
    count.append(i)
    result += satisfaction_level_B[i - 1]
    if len(count) >= 2:
        if count[-1] - count[-2] == 1:
            result += satisfaction_level_C[i - 2]
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()))
print(sum(B)+sum(C[A[n]-1] for n in range(N-1) if A[n]+1==A[n+1]))

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 n in range(1,N):
  if A[n]!=1+A[n-1]:
    ans+=B[A[n]-1]
  else:
    ans+=B[A[n]-1]+C[A[n]-2]

print(ans)

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
a = intl()
b = intl()
c = intl()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())
print(sum(b)+sum(c[a[i]-1]for i in range(n-1) if a[i]+1==a[i+1]))

Submission status: Accepted

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

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

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

s = 0
for i in range(n):
    s += b[i]

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
before = -100
for i in a:
    i -= 1
    if i == before + 1:
        ans += c[before]
    before = i
    ans += b[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 = 0
for i in range(n):
    num = a[i]
    res += b[num - 1]
for i in range(n-1):
    if a[i] +1== a[i+1] :
        num = a[i]
        res += c[num-1]
print(res)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] + list(map(int , input().split()))
    c = [0] + list(map(int , input().split()))
    ans = 0
    for i in range(n):
        ans += b[a[i]]
        if i > 0 and a[i-1] == a[i] - 1:
            ans += c[a[i-1]]
    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 >0 and A[i] - A[i-1] ==1:
    ans += C[A[i]-2]
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
Total = sum(B)
for T in range(0,N-1):
    if A[T+1]-A[T]==1:
        Total += C[A[T]-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()))
fill = 0
cnt = 0
for f in range(n):
    fill = fill + b[a[f] - 1]
    if(f != 0 and a[f] == a[f-1] + 1):
        fill = fill + c[a[f-1]-1]
        cnt = cnt + 1
    else:
        cnt = cnt + 1
print(fill)

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]
    #print(b[a[i]-1])
    
    if( i > 0):
        if( a[i-1]+1 == a[i] ):
            manzoku += c[a[i-1]-1]
            #print('+'+str(c[a[i-1]-1]))
#print('')
print(manzoku)

Submission status: Accepted

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

ans = 0
before = None
for i in a_l:
    ans += b_l[i-1]
    if before == i-1:
        ans += c_l[before-1]
    before = 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()))
stf = 0

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

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):
    if(A[i-1]+1==A[i]):
        ans+=B[A[i]-1]+C[A[i-1]-1]
    else:
        ans+=B[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
for i in range(N):
  total += B[A[i]-1]
  if i != 0 and A[i]-A[i-1] == 1:
    total += C[A[i-1]-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
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()))
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())
    alis = list(map(int, input().split()))
    blis = list(map(int, input().split()))
    clis = list(map(int, input().split()))
    ans = 0
    tmp = ""
    for a in alis:
        ans += blis[a-1]
        if tmp == a-1:
            ans += clis[a-2]
        tmp = a
    print(ans)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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


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=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]
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=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=ans+c[a[i]-1]
print(sum(b)+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)
lt=[]
for i in range(len(la)-1):
  if la[i]+1==la[i+1]:
    lt.append(la[i])

for j in lt:
  ans+=lc[j-1]

print(ans)

Submission status: Accepted

Solution code:
num = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
z = list(map(int,input().split()))
val = 0
 
for i in range(num):
    val += y[x[i]-1]
    if 1<=i and x[i]-x[i-1] == 1:
        val += z[x[i]-2]
 
print(val)

Submission status: Accepted

Solution code:
N = int(input())
A = [-1]
A.extend(list(map(int, input().split()))) # たべた料理
B = [-1]
B.extend(list(map(int, input().split()))) # 料理の満足度
C = [-1]
C.extend(list(map(int, input().split()))) # i -> i+1ボーナス

manzoku = 0

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

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

Submission status: Accepted

Solution code:
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
bonuses = list(map(int, input().split()))

score = 0
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i == prev + 1: score += bonuses[i-2]
  prev = i

print(score)

Submission status: Accepted

Solution code:
# 140 B

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(len(a)):
    sum += b[a[i] - 1]
    try:
        if i != 0 and a[i] == a[i-1] + 1:
           sum += c[a[i-1] - 1]
    except IndexError:
        continue

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())+1
inp1 = list(map(int, input().split()))
inp2 = list(map(int, input().split()))
inp3 = list(map(int, input().split()))
c, val = 0, 1
for i in range(n-1):
    c = (inp2[inp1[i] - val])+c
    if i > 0 and inp1[i] == inp1[i-val] + val:
        c = (inp3[inp1[i-val] - val])+c
print(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()))
Sum=sum(b)
for i in range (0,len(a)-1):
  if a[i]+1==a[i+1]:
    number=a[i]
    Sum+=c[number-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()))

memory=-1
add=0
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=[list(mi()) for _ in range(3)]
ans=0
for i in range(a-1):
  ans+=l[1][l[0][i]-1]
  if l[0][i]+1==l[0][i+1]:
    ans+=l[2][l[0][i]-1]
print(ans+l[1][l[0][a-1]-1])

Submission status: Accepted

Solution code:
a=int(input())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
o=list(map(int,input().split()))
result1=0

for i in range(0,a-1):
    if n[i]+1==n[i+1]:
        result1+=o[n[i]-1]

for i in range(a):
    result1+=m[n[i]-1]
print(result1)

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

minus_index = -1
happy = 0

for i in range(n):
    index = a[i] - 1
    happy += b[index]
    if(a[i] == minus_index + 1):
        happy += c[minus_index-1]
    minus_index = a[i]

print(happy)

Submission status: Accepted

Solution code:
# B - Buffet
def main():
    _ = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    cnt = 0
    flg = a[0]

    for i in a:
        if flg == i - 1:
            cnt += c[flg-1]
        cnt += b[i-1]
        flg = i
    print(cnt)

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

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

Submission status: Accepted

Solution code:

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

ans = sum(B)
for i, a in enumerate(A):
    if i >= len(A) - 1:
        break
    if a + 1 == A[i+1]:
        ans = ans + C[a-1]
print(ans)

Submission status: Accepted

Solution code:
input()
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
pts = 0
prev = 0
for i in range(len(A)):
    try:
        pts += B[A[i] - 1]
    except:
        pass
    try:
        if prev+1 == A[i]:
            pts += C[A[i-1]-1]
    except:
        pass
    prev = A[i]
print(pts)

Submission status: Accepted

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

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>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=input()
a_=a__=[int(i) for i in a.split()]
b=input()
b_=b__=[int(i) for i in b.split()]
c=input()
c_=c__=[int(i) for i in c.split()]
sat=0
first=a_[0]-1
sat=sat+b_[first]
for x in a_:
    if x>N:
        a_.remove(x)
for x in b_:
    if x<1 or x>50:
        b__=b_.remove(x)
for x in c_:
    if x<1 or x>50:
        c__=c_.remove(x)
a__=list(dict.fromkeys(a_))
if len(a__) ==len(a_) and len(c__)==len(c_) and len(b__)==len(b_) and 2<=N<=50:
    for x in range(1,N):
        if a_[x]==1+a_[x-1]:
            sat=sat+b_[(a_[x])-1]+c_[(a_[x])-2]
        else:
            sat=sat+b_[(a_[x])-1]
    if sat!=0:
        print(sat)

Submission status: Accepted

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

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
l3 = list(map(int,input().split()))
m=0
m+=l2[l1[0]-1]
for i in range(1,n):
    if l1[i] == l1[i-1]+1:
        m+=l2[l1[i]-1]+l3[l1[i]-2]
    else:
        m+=l2[l1[i]-1]
print(m)

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

ans = 0
ans += b[a[0]-1] 
for i in range(1,n):
    ans += b[a[i]-1]
    if a[i-1]+1 ==  a[i]:
        ans += c[a[i]-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()))
A.insert(0,"X")
B.insert(0,"X")
C.insert(0,"X")
stf_c = 0
j = 100
for i in range(1,N+1):
	if A[i] == j+1:
		stf_c += (B[A[i]]+C[j])
		j = A[i]
	else:
		stf_c += B[A[i]]
		j = A[i]
print(stf_c)

Submission status: Accepted

Solution code:
n = int(input())
a = [-1] + list(map(int, input().split()))
b = [-1] + list(map(int, input().split()))
c = [-1] + list(map(int, input().split()))

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

print(ans)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    p = -1
    ans = 0
    for i, d in enumerate(a):
        if d == p+1:
            ans += b[d-1] + c[p-1]
        else:
            ans += b[d-1]
        p = d
    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()))

score = 0
for i in range(0, n):
   menu = a[i]
   score += b[menu-1]
   if i != 0 and a[i] - a[i-1] == 1:
      beforeMenu = a[i-1]
      score += c[beforeMenu-1]

print(score)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=0
for i in range(n):
    s+=b[i]
    if i<=n-2 and 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()))
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()))
tmp=-5
res=0
for i in range(n):
  res += b[a[i]-1]
  if tmp==a[i]-2:
    res += c[a[i]-2]
  tmp=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()))
ans=0
j=0
for i in a:
	ans+=b[i-1]
	if i==j+1 and i!=1:
		ans+=c[j-1]
	j=i
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<N-1 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
prev = -1
for i in A:
    ans += B[i-1]
    if prev == i-1:
        ans += C[i-2]
    prev=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()))
p=-1
ans=0
for i in range(n):
    ans+=b[a[i]-1]
    if p+1==a[i]:
        ans+=c[a[i]-2]
    p=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()))

prev_food = A[0] - 1
ans = 0
for i in range(N):
    curr_food = A[i] - 1
    ans += B[curr_food]
    if curr_food - 1 == prev_food:
        ans += C[prev_food]
    prev_food = curr_food
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()))
sat = sum(b)
for i in range(n - 1):
    if a[i + 1] - a[i] == 1:
        sat = 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()))
ans = sum(B)
for i in range(N-1):
  if A[i]+1 == A[i+1]:
    D = A[i]
    ans += C[D-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()))
x=sum(b)
for i in range(len(a)-1):
  if a[i+1]-a[i]==1:
    d=a[i]
    x+=c[d-1]
print(x)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

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

ans = sum(B)

if N == 2 and A[0] == 1: ## only 2 items, and order 1 to 2
  ans = ans +C[0]
  print(ans)
  sys.exit()

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

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

print(total)

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

SFB = sum(LB)
SFC = 0

for i in range(1, N):
    j = i - 1
    if LA[i] == (LA[j] + 1):
        A = LA[i] - 2
        SFC += LC[A]

print(SFB + SFC)

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

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

sum = 0
hantei = 0


for i in range(len(a)):


    if i == 0:
        sum = sum + b[a[i]-1]
        hantei = a[i]
    else:
        if a[i] == hantei + 1:
            sum = sum + b[a[i]-1] + c[a[i]-2]
            hantei = a[i]
        else:
            sum = sum + b[a[i]-1]
            hantei = a[i]
    
print(sum)

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    *A, = (int(x) - 1 for x in input().split())
    B = map(int, input().split())
    *C, = map(int, input().split())

    ans = sum(B)
    for a, b in zip(A, A[1:]):
        if b - a == 1:
            ans += C[a]
    print(ans)


if __name__ == '__main__':
    main()

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

total = 0
for a in A_list:
    total += B_list[a-1]

for i in range(N-1):
    if A_list[i] + 1 == A_list[i + 1]:
        total += C_list[A_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()))
sb=sum(b)

for i in range(len(a)-1):
  
  if a[i]+1==a[i+1]:
    sb+=c[a[i]-1]
    
print(sb)

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[N-1]-1]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))

sum=0
bef=-2

for a in alist:
    sum += blist[a-1]
    if bef + 1 == a:
        sum += clist[bef-1]
    bef = a

print(sum)

Submission status: Accepted

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

    sum = 0

    before = A[0]

    for ryouri in A:
        if before + 1 == ryouri:
            sum += B[ryouri - 1] + C[before - 1]
        else:
            sum += B[ryouri - 1]

        before = ryouri

    print(sum)


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

prev_dish = -1
satisfaction = 0
for dish in A:
    satisfaction += B[dish-1]
    if dish - prev_dish == 1:
        satisfaction += C[prev_dish-1]
    
    prev_dish = dish

print(satisfaction)

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 = 0
before = 10**10

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

print(point)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
total=0
for i in range(N):
  total+=B[A[i]-1]
  if i!=0:
    if A[i]==A[i-1]+1:
      total+=C[A[i-1]-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
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:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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