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:
if __name__ == '__main__':
    n = int(input())
    a_input = list(map(int, input().split()))
    b_input = list(map(int, input().split()))
    c_input = list(map(int, input().split()))

    score = 0
    pre_a = -1
    for i in range(n):
        score += b_input[a_input[i] - 1]
        if pre_a == a_input[i] - 1:
            score += c_input[pre_a - 1]
        pre_a = a_input[i]
    print(score)

Submission status: Accepted

Solution code:
def read():
    return [int(e) for e in input().split(" ")]

N = int(input())
Data = [read() for _ in range(3)]
m = 0
b = -2

for e_A in Data[0]:
    m += Data[1][e_A - 1]
    if(e_A == b + 1):
        m += Data[2][b - 1]
    b = e_A

print(m)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 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:
import numpy as np

def main():
    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()]

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

    print(s)




if __name__ == '__main__':
    main()

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

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

print(s)

Submission status: Accepted

Solution code:
t=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()]
s=[]
for i in range(t):
    if i==0:
        s.append(b[a[i]-1])
    else:
        if a[i]-a[i-1]==1:
            su=b[a[i]-1]+c[a[i]-2]
            s.append(su)
        else:
            s.append(b[a[i]-1])
print(sum(s))

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    c = list(map(int, input().rstrip('\n').split()))
    t = sum(b)
    for i in range(n):
        if i != 0 and a[i] - 1 == a[i-1]:
            t += c[a[i-1]-1]
    print(t)


if __name__ == '__main__':
    slove()

Submission status: 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 < N-1 and A[i+1] == A[i]+1:
        manzoku += C[A[i]-1]
print(manzoku)

Submission status: Accepted

Solution code:
N = int(input())
AryA = list(map(int, input().split()))
AryB = list(map(int, input().split()))
AryC = list(map(int, input().split()))

sum = 0
tmpBox = N+1

for item in AryA:
	sum += AryB[item-1]
	if (item == tmpBox + 1):
		sum += AryC[tmpBox-1]
	tmpBox = item
print(sum)

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    B = LIST()
    C = LIST()
    sumv = 0
    for i in range(N):
        sumv += B[A[i]-1]
        if i > 0:
            if A[i] - A[i-1] == 1:
                sumv += C[A[i-1]-1]
    print(sumv)

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
 
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
r = np.sum(B)
for i in range(N-1):
  if A[i] + 1 == A[i + 1]:
    r += C[A[i]-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()))
i=0
ans=0
while i!=n:

    ans+=b[a[i]-1]
    if i!=0:
        if (a[i]-a[i-1])==1:
            ans+=c[a[i-1]-1]

    i+=1

print(ans)

Submission status: Accepted

Solution code:
li = lambda: list(map(int, input().split()))
N = int(input())
A = li()
B = li()
C = li()
res = sum(B)
res += sum([C[A[i]-1] for i in range(len(A)-1) if not (A[i+1]-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()))

res = sum(B)
for i, (p, n) in enumerate(zip(A[:N-1], A[1:])):
    if n - p == 1:
        res += C[A[i]-1]
print(res)

Submission status: Accepted

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

result = 0
for i, a_i in enumerate(a):
    result += b[a_i - 1]
    if i != 0:
        if a_i == (a_old + 1):
            result += c[a_i - 2]
    else:
        pass
    a_old = a_i
print(result)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
b = [int(j) for j in input().split(" ")]
c = [int(i) for i in input().split(" ")]
gain = 0 
for i in range(n):
	if(i==0):
		gain += b[a[i]-1]
	else:
		gain += b[a[i]-1]
		if(a[i]==a[i-1]+1):
			gain += c[a[i-1]-1]
print(gain)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int,ins()))
def lin(): return list(input())
def iin(): return map(int,ins())

n = ii()
a = iil()
b = iil()
c = iil()
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())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

prev_a = None
ret = 0
for a_ in a:
    ret += b[a_ - 1]
    if prev_a is not None and a_ - prev_a == 1:
        ret += c[prev_a - 1]
    prev_a = a_

print(ret)

Submission status: Accepted

Solution code:
N = int(input()) 
s = [input().split() for i in range(3)]

A = [int(i) for i in s[0]]
B = [int(i) for i in s[1]]
C = [int(i) for i in s[2]]

sum1 = sum(B)

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

sum1 = sum(B)

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(len(C)) if A[i] == A[i+1]-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = sum(map(int, input().split()))
C = list(map(int, input().split()))
ans += sum(C[A[i]-1] if A[i]==A[i+1]-1 else 0 for i in range(N-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 = 99
m = 0
for i in range(len(a)) :
    m += b[a[i]-1]
    if a[i]-1 == j+1 :
        m += c[j]
    j = a[i]-1
print(m)

Submission status: Accepted

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

for i in range(N):
  ans += B[A[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()))

sum = 0
bf = -1

for i in A:
    sum += B[i-1]

    if i == bf + 1:
        sum += C[i-2]

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

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

print(satis)

Submission status: 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):
    b_index = a[i]
    b_index -= 1
    b_value = b[b_index]
    res += b_value

    if i < n-1:
        b_index_next = a[i+1]
        b_index_next -= 1
        b_value_next = b[b_index_next]
        if b_index_next - b_index == 1:
            c_value = c[b_index]
            res += c_value

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(e) for e in input().split()]
b_list = [int(e) for e in input().split()]
c_list = [int(e) for e in input().split()]

satisfuction = 0
for i, a in enumerate(a_list):
  satisfuction += b_list[a-1]
  if (i >= 1) & (a - a_list[i-1] == 1):
    satisfuction += c_list[a_list[i-1]-1]
print(satisfuction)

Submission status: Accepted

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

C=[0]+C
S=sum(B)

for m in range(N-1):
  if A[m+1]-A[m]==1:
    S=S+C[A[m]]
  
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()))

last = -1

sum = sum(b) 

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

Submission status: Accepted

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

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

output= sum(b) + extrapoint

print(output)

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
l=[]
for i in range(n):
  l.append([i,a[i],b[i]])
l.sort(key=itemgetter(1))
cost = 0
for i in range(n):
  val = l[i][1]
  ix = l[i][0]; previx = -2
  if(i!=0):
    previx = l[i-1][0]
  cost+=(l[i][2])
  if(previx+1==ix):
    cost+=(c[i-1])
print(cost)

Submission status: Accepted

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

cnt = sum(B)

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

print(cnt)

Submission status: Accepted

Solution code:
N = input()
array_A = list(map(int, input().split()))
array_B = list(map(int, input().split()))
array_C = list(map(int, input().split()))

bonus_position = []
for i in range(len(array_A)-1):
  if array_A[i] + 1 == array_A[i+1]:
    bonus_position += [i]

bonus_dish = []
for i in bonus_position:
    bonus_dish += [array_A[i]]

bonus_point = 0
for i in bonus_dish:
    bonus_point += array_C[i-1]

score = sum(array_B) + bonus_point
print(score)

Submission status: Accepted

Solution code:
n = int(input())
dat_a = map(int, input().split())
dat_b = map(int, input().split())
dat_c = map(int, input().split())
dat_a = list(dat_a)
dat_b = list(dat_b)
dat_c = list(dat_c)
last = -100
res = 0
for i in range(n):
    a = dat_a[i] - 1
    res += dat_b[a]
    if last == (a - 1):
        res += dat_c[last]
    last = a
print(res)

Submission status: Accepted

Solution code:
import numpy as np
N = input()
N = int(N)
A = np.hstack([int(a) for a in input().split()])
B = np.hstack([int(a) for a in input().split()])
C = np.hstack([int(a) for a in input().split()])

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

score += B[A[N-1]-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()))

total = 0
pos = 0
while pos< N:
	posB = A[pos] -1
	total = total + B[posB]
	if A[pos] - A[pos - 1] == 1 and pos > 0:
		posC = A[pos] - 2
		total = total + C[posC]
	pos += 1
print(total)

Submission status: Accepted

Solution code:
num = int(input())
order = [int(s) for s in input().split()]
utility = [int(s) for s in input().split()]
add = [int(s) for s in input().split()]
point = 0
for i in range(num - 1):
  if order[i] + 1 == order[i + 1]:
    point += add[order[i] - 1]
    
print(sum(utility) + point)

Submission status: Accepted

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

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

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

A.append(-1)
manzoku = 0
for i in range(N):
    num_dish = A[i] - 1
    manzoku += B[num_dish]
    if A[i+1] == A[i] + 1:
        manzoku += C[num_dish]

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 = 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()))
 
sat = sum(B)
pre_a = A[0]
for a in A[1:]:
  if a == pre_a + 1:
    sat += C[pre_a-1]
  pre_a = a
  
print(sat)

Submission status: Accepted

Solution code:
from sys import stdin
from math import factorial
n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
c = list(map(int,stdin.readline().rstrip().split()))
point = 0
for i in range(n-1):
    point += b[a[i]-1]
    if a[i] + 1 == a[i+1]:
        point += c[a[i]-1]
point += b[a[n-1]-1]
print(point)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())

a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
c = list(map(int, sys.stdin.readline().rstrip().split()))

# print(N)
# print(a)

manzoku = 0
prev = -1

for i in a:
  manzoku += b[i-1]
  if i == prev + 1:
    manzoku += c[prev-1]
  prev = i


print(manzoku)

Submission status: Accepted

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

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()))
max=sum(b)

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

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

sat = sum(B)
for a, n_a in zip(A, A[1:]):
  if n_a - a == 1:
    sat += C[a]

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

Submission status: Accepted

Solution code:
import sys
import math

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def pro(k, l, n):
    if l < n:
        if k == 0:
            return(n - l)
        return (n - l + 2)
    if l == n:
        if k == 0:
            return 0
        elif k == 1:
            return 1
        return 3
    else:
        l -= n - 1
        if l == k:
            return 1
        elif l > k:
            return 0
        if l < k - 1:
            return 2
        else:
            return 3
            

def rt(k, l , n):
    if k < n:
        if l == 0:
            return (k * 2 + n)
        return (n + k * 2 - 1)
    elif k == n:
        if l == 1:
            return (k * 3 - 2)
        elif l == 0:
            return (k * 3)
        return (k * 3 - 3)
    else:
        k -= n - 1
        if k == l:
            return (n * 3 - 2)
        elif k > l:
            return (n * 3)
        if k < l - 1:
            return ((n - 1) * 3 - 1)
        else:
            return ((n - 1) * 3)



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


main()

Submission status: Accepted

Solution code:
n = int(input())
Dishes = [int(i) for i in input().split()]
Sat = [int(i) for i in input().split()]
AddSat = [int(i) for i in input().split()]
FinishSat = 0
for i in range(n):
    FinishSat += Sat[i]
    if i > 0:
        if Dishes[i - 1] + 1 == Dishes[i]:
            FinishSat += AddSat[Dishes[i - 1] - 1]
print(FinishSat)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input()) #waiting_for_pudging
a = list(map(int, input().split())) #waiting_for_pudging
b = list(map(int, input().split())) #waiting_for_pudging
c = list(map(int, input().split())) #waiting_for_pudging
summ = 0 #waiting_for_pudging
for i in range(n-1): #pudging
    if a[i] + 1 == a[i + 1]: #pudging
        summ += c[a[i]-1] #pudging
        summ += b[a[i]-1] #pudging
    else: #pudging
        summ += b[a[i]-1] #pudging
print(summ + b[a[n-1]-1]) #pudging
#accepted

Submission status: 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)
 
now = A[0]
for i in range(1, len(A)):
    if now+1 == A[i]:
        ans += C[now-1]
    now = A[i]
 
print(ans)

Submission status: Accepted

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

point = sum(B)
prev_a = -1
for a in A:
    if a - prev_a == 1:
        point += C[a-2]
    prev_a = a
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()))

ans = sum(B)

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

Submission status: 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(len(a)):
    total += b[a[i] - 1]
    if n - 1 == i: 
        continue
    elif 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()))

y = -2
ans = 0

for x in a:
    if x == y + 1:
        ans += c[y-1]
    ans += b[x-1]
    y = x

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

  if a[i] == (prev + 1):
    ans += c[prev-1]

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

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

Submission status: Accepted

Solution code:
n = int(input())
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
l_c = list(map(int, input().split()))

s = 0
for i in range(n - 1):
    s += l_b[l_a[i] - 1]
    if l_a[i] + 1 == l_a[i + 1]:
        s += l_c[l_a[i] - 1]
s += l_b[l_a[-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 = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
a = [int(s) for s in a]
b = input().split()
b = [int(s) for s in b]
c = input().split()
c = [int(s) for s in c]
hapiness = 0
for i in range(len(a)):
        hapiness += b[a[i]-1]
        if i:
                if a[i-1] + 1 == a[i]: hapiness += c[a[i-1]-1]
print(hapiness)

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

print(sum1+tmpsum)

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

Submission status: Accepted

Solution code:
# coding: utf-8
# input
n = int(input())
eat = list(map(int, input().split()))
data = list(map(int, input().split()))
plus = list(map(int, input().split()))

# processing
ans = 0
for i in range(len(eat)):
    ans += data[eat[i] - 1]
    if i <= n - 2:
        if eat[i + 1] == eat[i] + 1:
            ans += plus[eat[i] - 1]

# output
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[a[i]-1]
    if 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()))

base = sum(B)
bonus = 0
for i, num in enumerate(A):
  if i + 1 >= len(A):
    break
  if A[i+1] == num + 1:
    bonus += C[num - 1]

print(base + bonus)

Submission status: Accepted

Solution code:
# Coding:UTF-8

n = int(input())
ryorijun=[int(i) for i in input().split(' ')]
manzoku1=[int(j) for j in input().split(' ')]
manzoku2=[int(k) for k in input().split(' ')]

goukei=0
preorder = 0
for i in ryorijun:
    goukei += manzoku1[i-1]
    if preorder > 0 and (i-1) == preorder:
        goukei += manzoku2[i-2]
    preorder = i
print(goukei)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(input())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

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

m = 0

for i in range(n):
  num = int(a[i])
  m += b[num - 1]
#  print(i, m)  #erase later
  if num != n and i != n - 1:
    if num + 1 == int(a[i + 1]):
      m += c[num - 1]
#      print('C point', m)  #erase later
print(m)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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(len(a)):
    satisfy += b[a[i]-1]
    if i==0:
        continue
    if a[i]-a[i-1] == 1:
        satisfy += c[a[i-1]-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()))
s = 0
for q in range(n):
    s += b[a[q] - 1]
    if q != 0:
        if a[q - 1] == a[q] - 1:
            s += c[a[q - 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()))
manzoku = 0

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

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