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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

b = 0
for k in range(N-1):
    if A[k]+1 == A[k+1]:
        b = b+C[(A[k]-1)]

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

Submission status: Accepted

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

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
for i in range(n):
    ans += b_l[a_l[i]-1]
    if i != 0 and a_l[i] == a_l[i-1]+1:
        ans += c_l[a_l[i]-2]
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()))

bef = -2
sum = 0
for i in A:
	sum += B[i]
	if(bef + 1 == i):
		sum += C[i - 1]
	bef = i

print(sum)

Submission status: Accepted

Solution code:
#a,b = map(int,input().split())
#A = 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 = 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())
ls_A = list(map(int,input().split()))
ls_B = list(map(int,input().split()))
ls_C = list(map(int,input().split()))

#追加点なしで考える
manzoku = sum(ls_B)  #全種類食べる

#追加点
for i in range(N-1):
    if ls_A[i+1] == ls_A[i]+1:
        manzoku += ls_C[ls_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
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()))

total_value = sum(b)

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

print(total_value)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*a = map(int,open(0).read().split())
print(sum(a[n:n*2]) + sum(a[i-n] for i, j in zip(a, a[1:n]) if j == 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()))

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 = [0]*n

t = list(map(int, input().split()))
for i in range(n-1):
  c[i] = t[i]
  

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

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
A = list(map(lambda s: int(s) - 1, 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]
    if i > 0 and A[i - 1] == a - 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()))

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

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

result = 0
g = -10
for i in a:
    result += b[i-1]
    if g+1 == i:
        result += c[i-2]
    g = i
print(result)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(x)for x in input().split()]
B=[int(x)for x in input().split()]
C=[int(x)for x in input().split()]
ans=sum(B)
for i in range(len(A)-1):
    if A[i]+1==A[i+1]:
        ans+=C[A[i]-1]
print(ans)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 配列入力の受け取り
arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))
arrC = list(map(int,input().split()))

arrC = [0] + arrC

ans = 0
for i,dishnum in enumerate(arrA):
    if i == 0:
        ans += arrB[dishnum-1]
    else:
        ans += arrB[dishnum-1]
        if arrA[i] == arrA[i-1]+1:
            ans += arrC[dishnum-1]

print(ans)
# print("{:.10f}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(answer+sum(B))

Submission status: Accepted

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

Submission status: Accepted

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

sum=0
t=-999
for a1 in a:
    i=a1-1
    sum+=b[i]
    if t==i-1:
        sum+=c[i-1]
    t=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()))

su = 0
chokuzen = -5
for i in range(N):
  su += B[A[i] - 1]
  if A[i] == chokuzen + 1:
    su += C[A[i] - 2]
  chokuzen = A[i]
print(su)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
c=[int(x) for x in input().split()]
ans=b[a[0]-1]
for i in range(1,n):
    #print("ans: ", ans)
    #print("a[i]: ",a[i])
    ans+=b[a[i]-1]
    if a[i-1]+1 == a[i]:
        #print("a[i]: ",a[i])
        ans+=c[a[i]-2]
        #print("c: ",c[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()))
    
    s = sum(B)
    for i in range(N-1):
        if A[i+1] - A[i] == 1:
            s += C[A[i]-1]

    return s

print(solve())

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ap + ad)

Submission status: Accepted

Solution code:
f=lambda:list(map(int,input().split()))
n,a,b,c=f()[0],f(),f(),f()
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:
f=lambda:list(map(int,input().split()))
n=int(input())
a,b,c=f(),f(),f()
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:
f=lambda:list(map(int,input().split()))
n=int(input())
a,b,c=f(),f(),f()
s=sum(b)
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:
# ABC140 B

def main():
    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 0 < i < n and A[i] == A[i-1] + 1:
            satisfaction += C[A[i]-2]
    
    print(satisfaction)

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

Submission status: Accepted

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

result = 0
was = -5
for a in A:
    result += B[a]
    if was == a-1:
        result += C[a-1]
    was = a

print(result)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
least = -1
for ai in a:
    ans += b[ai - 1]
    if ai - 1 == least:
        ans += c[least - 1]
    least = ai
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
i = -2
for a in A:
    ans += B[a-1]
    if a == i + 1:
        ans += C[i-1]
    i = 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 a:
  ans+=b[i-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:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
List1 = [int(i) for i in input().split(" ")]
List2 = [int(j) for j in input().split(" ")]
List3 = [int(k) for k in input().split(" ")]

baf = 0
last_m = 21

for i in range(N):
    p = List1[i]
    baf += List2[p-1]
    if last_m == p-1:
        baf += List3[last_m-1]
    last_m = p
print(baf)

Submission status: Accepted

Solution code:
N = int(input())
total = 0
number = input().split(" ")
point = input().split(" ")
C = input().split(" ")
for i in point:
    total += int(i)
for j in range(N-1):
    if int(number[j]) == int(number[int(j)+1])-1:
        x = int(number[j])-1
        total += int(C[x])
    else:
        pass
    
print(total)

Submission status: Accepted

Solution code:
n = input()
line1 = input()
line2 = input()
line3 = input()
a_list = line1.split(" ")
a_list = [int(a) for a in a_list]
b_list = line2.split(" ")
b_list = [int(b) for b in b_list]
c_list = line3.split(" ")
c_list = [int(c) for c in c_list]

manzoku = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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-1):
    if A[i+1] - A[i] == 1:
        score += C[A[i] - 1]
print(score + 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()))
sumc = 0

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

print(sumc + sum(B))

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

cnt = 0
temp = ""
for x in listA: 
    cnt += listB[x-1]
  
    if temp == x-1:
        cnt += listC[temp-1]   
        
   
    temp = x

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=b[a[0]-1]
idx=a[0]-1

for i in range(1, len(a)):
    cnt += b[a[i]-1]
    
    if idx == a[i] - 2:
        cnt += c[idx]
        
    idx = a[i]-1
    
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input().rstrip())

a_list = list(map(int, input().rstrip().split(" ")))
b_list = list(map(int, input().rstrip().split(" ")))
c_list = list(map(int, input().rstrip().split(" ")))

prev = -2
ans = 0
for i in range(n):
    dish = a_list[i] - 1
    ans += b_list[dish]
    if dish - prev == 1:
        ans += c_list[prev]
    prev = dish

print(ans)

Submission status: Accepted

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

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

print(sat)

Submission status: Accepted

Solution code:
import sys
import math
#a,b= map(int,input().split())
N=int(input())
li0= [int(x) for x in input().split()]
li1= [int(x) for x in input().split()]
li2= [int(x) for x in input().split()]
i=total=0
total=sum(li1)

for i in range(N-1):
  if li0[i]==(li0[i+1]-1):
    total+=int(li2[li0[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()))
satisfy=0
for i in range(N-1):
    if A[i+1]==A[i]+1:
        satisfy+=C[A[i]-1]
    satisfy+=B[i]
satisfy+=B[N-1]
print(satisfy)

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

Submission status: Accepted

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

score = 0
for i in range(len(a)):
    score+=b[a[i]-1]
    # print(b[a[i]-1])
    if i == len(a)-1:
        pass
    else:
        if a[i]+1 == a[i+1]:
            score+=c[a[i]-1]
            # print("c:"+str(c[a[i]-1]))
print(score)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
a, b, c = [[int(x) for x in stdin.readline().rstrip().split()]
           for _ in range(3)]
total = 0
for i in range(len(a)):
    total += b[a[i]-1]
    if (i != len(a) - 1) and (a[i + 1] - a[i] == 1):
        total += c[a[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()))

poin = B[A[0]-1]

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    C_list = list(map(int, input().split()))

    point = 0

    i_minus = None

    for i in A_list:
        point += B_list[i-1]
        if i_minus is not None:
            if (i - i_minus) == 1:
                point += C_list[i_minus-1]
        i_minus = i

    print(point)

if __name__ == "__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(len(a)):
    sum += b[a[i] - 1]
    #print("i:{0} sum{1}".format(i, sum))#
    if(i != len(a) - 1 and a[i] + 1 == a[i + 1]):
        sum += c[a[i] - 1]
        #print("i:{0} sum{1}".format(i, sum))#

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# B
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
past = -2
for index in a:
    ans += b[index-1]
    if past == index-1:
        ans += c[index-2]
    past = index
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input().rstrip())

dish_list = [int(i) for i in input().rstrip().split(" ")]
manzoku = [int(i) for i in input().rstrip().split(" ")]
bonus = [int(i) for i in input().rstrip().split(" ")]

prev = -10
ans = sum(manzoku)
for i in range(n):
    dish = dish_list[i]
    if dish - prev == 1:
        ans += bonus[prev - 1]
    prev = dish
print(ans)

Submission status: Accepted

Solution code:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

    ans = sum(b)
    prev = a[0]

    for i in range(n):
        if a[i] - prev == 1:
            ans += c[prev-1]
        prev = a[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()))
scr = 0
ai_1 = float('Inf')
for ai in a:
    scr += b[ai-1]
    if ai_1 + 1 == ai:
        scr += c[ai_1-1]
    ai_1 = ai
print(scr)

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
pre = -1
for i in range(n):
    count += b[a[i]-1]
    if a[i] == pre+1:
        count += c[pre-1]
    pre = a[i]
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()))
prev=a[0]
s1=sum(b)
#ans=s1
ans=0
for i in range(1,len(a)):
  if a[i]==prev+1:
    ans+=c[prev-1]
  prev=a[i]
print(s1+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
pre=N
for a in A:
  s+=B[a-1]
  if pre == a-2:
    s+=C[pre]
  pre=a-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()))

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

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 and A[i]-1==A[i-1]):
        res+=C[A[i]-2]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Solution:
    def solve(self, N: int, A, B, C) -> int:

        answer = 0
        previous = -2

        for a in A:
            answer += B[a-1]

            if previous + 1 == a and a > 1:
                answer += C[a-2]

            previous = a

        return answer


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    print(solution.solve(N, A, B, C))

Submission status: Accepted

Solution code:
kind=int(input())
food=list(map(int,input().split()))
manzoku=list(map(int,input().split()))
manzokuAfter=list(map(int,input().split()))

total=0
for i in range(0,kind):
  total += manzoku[food[i]-1]
  if i!=0 and food[i-1]+1==food[i]:
    total+=manzokuAfter[food[i-1]-1]

print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import numpy as np

def main():
    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())))
    res = np.sum(b)
    idx = a[:-1][np.diff(a) == 1]
    res += np.sum(c[idx - 1])
    print(res)

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

total = 0
temp = float("inf")
for i in range(n):
  if a[i] == temp + 1:
    total += c[a[i - 1] - 1]
  temp = a[i]
  total += b[a[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()))

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

print(co)

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
y = 0

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

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

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

print(hap)

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)