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

total = 0
for i in range(0, N-1):
    idx = a[i]
    total += b[idx-1]
    if a[i+1] == idx+1:
      total += c[idx-1]
      
total += b[a[-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()))
manzoku=0
dish_b=100
for i in range(n):
    dish=a[i]
    manzoku+=b[dish-1]
    if dish==dish_b+1:
        manzoku+=c[dish_b-1]
    dish_b=dish
print(manzoku)

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

out = 0
before = n

for i in range(n):
  out += B[A[i]]
  if A[i] == before+1:
    out += C[A[i]-1]
  before = A[i]
print(out)

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

Submission status: Accepted

Solution code:
# @author 

import sys

class BBuffet:
    def solve(self):
        n = int(input())
        a = [int(_) - 1 for _ in input().split()]
        b = [int(_) for _ in input().split()]
        c = [int(_) for _ in input().split()]
        ans = 0
        last = -2
        for i in range(n):
            ans += b[a[i]]
            if a[i] - 1 < n - 1 and a[i] - 1 == last:
                ans += c[a[i] - 1]
            last = a[i]
            # print(ans)

        print(ans)

solver = BBuffet()
input = sys.stdin.readline

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

Submission status: Accepted

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

sum = 0

prev = -1

for now in a:
    sum += b[now-1]

    if(now == prev + 1):
        sum += c[prev-1]

    prev = now

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z=list(map(int,input().split()))

res=0

for i in range(n):
	res+=y[x[i]-1]
	if i>0 and x[i]==x[i-1]+1:
		res+=z[x[i]-2]

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  7 21:01:43 2019

@author: doppe
"""

N = int(input())

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

score = 0
before = -99
for i in range(0, len(A)):
    score += B[A[i] - 1]
    if (before == A[i] - 1):
        score += C[A[i] - 2]
    before = A[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()))

c.append(0)

ans = 0
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:
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

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

        num = A[i]
        sum += B[num-1]
        save = num


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

a_prev = N+1

ans = 0
for a in A:
    ans += B[a - 1]
    if (a - a_prev) == 1:
        ans += C[a_prev - 1]
    a_prev = 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()))
answer=0
m=-50
for i in range(n):
  t=a[i]
  answer+=b[t-1]
  if t-1==m:
    answer+=c[m-1]
  m=t
print(answer)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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()]

    sum = 0

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


    print(sum)

Submission status: Accepted

Solution code:
N = int(input())

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

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

sat = 0
prev = 0

for i, a in enumerate(A):
    sat += B[a - 1]

    if i > 0:
        if (a - 1 - prev) == 1:
            sat += C[prev]

    prev = a - 1

print(sat)

Submission status: Accepted

Solution code:
n = int(input())
zyunban = list(map(int, input().split()))
val = list(map(int, input().split()))
kougo = list(map(int, input().split()))

total = sum(val)
for i in range(n-1):
    if zyunban[i+1] == zyunban[i] + 1:
        total += kougo[zyunban[i] -1]
print(total)

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

al = list(map(lambda x: x - 1, al))

s = 0
a_prev = -100
for a in al:
    s += bl[a]
    if a_prev != (n - 1) and a - a_prev == 1:
        s += cl[a_prev]
    a_prev = a


print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
A=np.array(input().split(),dtype=np.int32)-1
B=np.array(input().split(),dtype=np.int32)
C=np.array(input().split(),dtype=np.int32)

s=0
for i in range(len(A)):
    key=A[i]
    s+=B[key]
    if(i+1<=len(A)-1):
        if(key+1==A[i+1]):
            s+=C[key]

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

current_eat = -2
manzoku = 0
for n in range(N):
    eat_index  = A[n] - 1
    manzoku += B[eat_index]
    if(current_eat  +1 == eat_index):
        manzoku += C[current_eat]
    current_eat = eat_index
print(manzoku)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    aa = list(map(int,input().split()))
    bb = list(map(int,input().split()))
    cc = list(map(int,input().split()))
    ba = aa[0]-1
    ans = bb[ba]
    for a in aa[1::]:
        if ba+1 == a-1:
            ans += cc[ba]
        ba = a-1
        ans += bb[ba]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

nA = [ 0 for i in range(N)]
nB = [ 0 for i in range(N)]
nC = [ 0 for i in range(N-1)]

Tmp = []
Tmp = input().rstrip().split(' ')
for i in range(N):
  nA[i] = int(Tmp[i])

Tmp = []
Tmp = input().rstrip().split(' ')
for i in range(N):
  nB[i] = int(Tmp[i])

Tmp = []
Tmp = input().rstrip().split(' ')
for i in range(N-1):
  nC[i] = int(Tmp[i])
  
Ans = 0

nTmpOld = N + 2
for i in range(N):
  nTmp = nA[i] - 1
  
  Ans += nB[nTmp]
  
  if i > 0 and nTmp == nTmpOld + 1:
    Ans += nC[nTmp-1]
  
  nTmpOld = nTmp

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

Submission status: Accepted

Solution code:
n=int(input())
lista = [int(i) for i in input().split()]
listb = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

ans = 0
bef = -1000
for i in range(n):
    bango = lista[i]
    ans+=listb[bango-1]
    
    if bango-bef == 1:
        ans+=listc[bango-2]
        
    bef = bango
    
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]
ans = ans + sum(B)

print(ans)

Submission status: Accepted

Solution code:
n  = int(input())
xs = [0]
ys = [0]
zs = [0]
p  = None
c  = 0

xs.extend([int(x) for x in input().split()])
ys.extend([int(x) for x in input().split()])
zs.extend([int(x) for x in input().split()])

for i in range(1, n + 1):
	a  = xs[i]
	c += ys[a]
	if a - 1 == p:
		c += zs[p]
	p = a
	
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()))
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if i >= 1 and a[i] - j == 1:
        ans += c[j-1]
    j = 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()))

_sum = sum(B)
prev_a = N+1

for a in A:
    if prev_a+1 == a:
        _sum += C[prev_a-1]
    prev_a = a

print(_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
ans=0
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 resolve():
    n = int(input())
    aaa = list(map(int, input().split()))
    bbb = list(map(int, input().split()))
    ccc = list(map(int, input().split()))
    ans = bbb[aaa[0]-1]
    for i in range(n-1):
        if aaa[i+1] == aaa[i] + 1:
            ans += ccc[aaa[i]-1]
        ans += bbb[aaa[i+1]-1]
    print(ans)
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
x = -1
for i in range(N):
    sum += B[A[i] - 1]
    if x == A[i] - 1:
        sum += C[x-1]
    x = 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 = sum(B)
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        AAA = A[i]
        ans += C[AAA-1]

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
p = 0
for i in list_B:
    p += i
for i in range(N-1):
    if list_A[i+1] - list_A[i] == 1:
        p += list_C[list_A[i] - 1]
print(p)

Submission status: Accepted

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

ans = 0
past = -10
for i in range(n):
    ans += B[A[i] - 1]
    if past == A[i] - 1 - 1:
        ans += C[A[i] - 1 - 1]
    past = 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
tmp = 10000
for a_ in a:
    ans += b[a_ - 1]
    if tmp + 1 == a_:
        ans += c[a_ - 2]
    tmp = 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()))
count = 0
check = -1

for i in range(N):
    eat = A[i] - 1
    count += B[eat]
    if 1 <= i <= (N-1):
        if check == eat - 1:
            count += C[check]
    check = eat

print(count)

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]

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

Submission status: Accepted

Solution code:
def main():
    b = int(input())
    l_A = [int(i) for i in input().split()]
    l_B = [int(i) for i in input().split()]
    l_C = [int(i) for i in input().split()]

    last = -100
    ans = 0
    for A in l_A:
        ans += l_B[A-1]
        if A - last - 1 == 1:
            ans += l_C[A - 2]
        last = A-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 < n-1 and 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()))

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

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

Submission status: Accepted

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

satis = 0
for j in range(n):
    ate = A[j] - 1
    satis += B[ate]
    if j > 0 and A[j] == A[j - 1] + 1:
        satis += C[A[j - 1] - 1]
print(satis)

Submission status: Accepted

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

    ans = 0

    bf = -100
    for i in A:
        ans += B[i]
        if bf == i - 1:
            ans += C[i - 1]
        bf = i

    print(ans)


if __name__ == '__main__':
    p_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(len(A) -1):
  if A[i + 1] == A[i] + 1:
    ans += C[A[i]-1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_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-1):
    ans += B_l[A_l[i]-1]
    if(A_l[i]+1 == A_l[i+1]):
        ans += C_l[A_l[i]-1]
ans += B_l[A_l[N-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(len(A)):
  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()))
point0 = sum(B)
for (i,j) in zip(A[:-1],A[1:]):
    if i == j - 1:
        point0 += C[i-1]
print(point0)

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 = -1

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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 >= 1 and a[i - 1] + 1 == a[i]:
        total += c[a[i - 1] - 1]
print(total)

Submission status: Accepted

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


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

print satis

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
flag = False
temp = A[0]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

prev_a = -1
sut = 0
for i in range(N):
    a = A[i]
    sut += B[a-1]
    #print("a", a, prev_a, a-prev_a)
    if (a - prev_a) == 1:
        #print("sut")
        sut += C[a-2]
        #print("C", C[i-2])
    prev_a = a
    #print(i, sut)
print(sut)

Submission status: Accepted

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

prev = n
total = 0
for i in range(n):
	cur = A[i]
	total += B[cur-1]
	if cur == prev + 1:
		total += C[prev-1]
	prev = cur 
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(len(a)):
    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())) 

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input() # N
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
satisfaction = sum(b)
for dish, next_dish in zip(a, a[1:]):
    if next_dish == dish+1:
        satisfaction += c[dish-1] # because 0-indexed
print(satisfaction)

Submission status: Accepted

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


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A = [a-1 for a in A]
    manzoku = 0
    for i in range(N):
        manzoku += B[A[i]]
        if i < N-1 and A[i+1] == A[i] + 1:
            manzoku += C[A[i]]
    print(manzoku)
    return


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

if __name__ == '__main__':
    main()

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

m = 0
ba = -1
for ai in a:
    m = m + b[ai-1]
    if ba + 1 == ai:
        m = m + c[ba-1]
    ba = ai
print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
point = 0
temp = -1
for a in a_list:
    point += b_list[a-1]
    if a - temp == 1:
        point += c_list[a-1-1]
    temp = 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()))

s = 0
prev = -1

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

print(s)

Submission status: Accepted

Solution code:
n1 = int(input())

n2 = [int(i) for i in input().split()]
n3 = [int(i) for i in input().split()]
n4 = [int(i) for i in input().split()]

r1 = 0

for i1 in range(n1):
    r1 += n3[n2[i1] - 1]
    if i1 <= n1 - 2:
        if n2[i1] + 1 == n2[i1 + 1]:
            r1 += n4[n2[i1] - 1]

print(r1)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
import sys; from collections import deque ; readline = sys.stdin.readline

N = int(readline())
A = list(map(lambda x:int(x)-1, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))

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

a += sum(B)

print(a)

Submission status: Accepted

Solution code:
def solve():
  import sys
  import math

  sys.setrecursionlimit(10**7)
  readline=sys.stdin.readline

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


if __name__ == '__main__':
  solve()

Submission status: Accepted

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

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

manzoku = 0
last_order = -1
for order in a_list:
    manzoku += b_list[order - 1]
    if order == last_order + 1:
        manzoku += c_list[last_order - 1]
    last_order = order

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

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

print(ans)