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())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

satis = 0
a_ = 0
for i in range(n):
    a = al[i]
    satis += bl[a-1]
    if i != 0:
        if a_ + 1 == a:
            satis += cl[a_-1]
    a_ = a

print(satis)

Submission status: Accepted

Solution code:
#140 b
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i,x in enumerate(a):
    ans+=b[x-1]
    if i!=n-1 and x+1==a[i+1]:
           ans+=c[x-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()))

sum = 0
pre = -1

for A in A_list:
    sum += B_list[A - 1]

    if pre + 1 == A:
        sum += C_list[A - 2]

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

Submission status: Accepted

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

ans = 0
prev_ind = 50
for i in a:
    ans += b[i]
    if prev_ind + 1 == i:
        ans += c[prev_ind]
    prev_ind = i

print(ans)

Submission status: Accepted

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


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    count = 0
    prev_n = -1
    for n in A:
        count += B[n-1]
        if prev_n == n - 1:
            count+= C[prev_n-1]
        prev_n = n
    print(count)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def input_int_list():
    return [int(x) for x in input().split()]

N = int(input())
A = input_int_list()
B = input_int_list()
C = input_int_list()

satisfaction = B[A[0] - 1]
last_dish = A[0]
for a in A[1:]:
    satisfaction += B[a - 1]
    if a == last_dish + 1:
        satisfaction += C[last_dish - 1]

    last_dish = a


print(satisfaction)

Submission status: Accepted

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

total = 0
pre_dish = -1
for i in range(n):
  dish = A[i]
  total += B[dish]
  if dish - pre_dish == 1:
    total += C[dish-1]
  pre_dish = dish
print(total)

Submission status: Accepted

Solution code:
def main1(N, lstA, lstB, lstC):
    bounus = 0
    for i in range(0, len(lstA)-1):
        if (lstA[i] + 1) == lstA[i+1]:
            bounus += lstC[lstA[i]-1]
    print(sum(lstB) + bounus)

N = int(input())
lstA = list(map(int, input().split()))
lstB = list(map(int, input().split()))
lstC = list(map(int, input().split()))
main1(N, lstA, lstB, lstC)

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

sumB = sum(B)
bouns = 0
for i in range(len(A)-1):
    if A[i+1] - A[i] == 1:
       bouns += C[A[i]-1]
print(sumB + bouns)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve(inp):
    N = int(inp.readline().strip())
    A = list(map(int, inp.readline().strip().split(' ')))
    B = list(map(int, inp.readline().strip().split(' ')))
    C = list(map(int, inp.readline().strip().split(' ')))

    r = sum(B)
    for i in range(N - 1):
        if A[i] + 1 == A[i + 1]:
            r += C[A[i] - 1]
    return str(r)


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    # test('')
    main()

Submission status: Accepted

Solution code:
N = int(input())
a_ls = [int(i) for i in input().split()]
b_ls = [int(i) for i in input().split()]
c_ls = [int(i) for i in input().split()]

ans = sum(b_ls)

for i in range(N-1):
    key = a_ls[i]
    if key == a_ls[i+1] - 1:
        ans += c_ls[key-1]

print(ans)

Submission status: Accepted

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

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 = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

manzoku = 0
for i in range(n):
    manzoku += b[a[i]-1]
    if i == 0:
        continue
    elif a[i] - a[i-1] == 1:
        manzoku += c[a[i-1]-1]

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

curr = -2
for i in a:
    total += b[i - 1]
    if i == curr + 1:
        total += c[i - 2]
    curr = i

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split())) #料理の順番
B = list(map(int, input().split())) #料理の満足度
C = list(map(int, input().split())) #追加の満足度

ans = sum(B)

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

Submission status: Accepted

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

prev = -9999
total = 0
for i, a in enumerate(A):
  total += B[i]
  if prev + 1 == a:
    total += C[prev - 1]
  prev = a

print(total)

Submission status: Accepted

Solution code:
n = int(input())
an = [int(i) for i in input().split()]
bn = [int(i) for i in input().split()]
cn_1 = [int(i) for i in input().split()]
score = bn[an[0] - 1]
for i in range(1, n):
    score += bn[an[i] - 1]
    if an[i] - an[i - 1] == 1:
        score += cn_1[an[i - 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()))

# print(N, A_LIST, B_LIST, C_LIST)

result = 0

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

print(result)
# 5+8+9+24+15+13

Submission status: Accepted

Solution code:
#140
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(0,n):
    res += b[a[i]-1]
    if i > 0 and a[i]-1 == a[i-1]:
        res += c[a[i-1]-1]
        
print(res)

Submission status: Accepted

Solution code:
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    B = LIST()
    C = LIST()

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

    for i in range(N):
        benefit += B[A[i]-1]
    print(benefit)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(satisf)

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

Submission status: Accepted

Solution code:
N = int(input())
meal = list(map(int, input().split()))
satis = list(map(int, input().split()))
adds = list(map(int, input().split()))
total = sum(satis)

for i in range(N-1):
    if (meal[i]+1 == meal[i+1]):
        total += adds[meal[i]-1]

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
ais = list(map(int, input().split()))
bis = list(map(int, input().split()))
cis = list(map(int, input().split()))
sat = bis[ais[0]-1]
for i in range(1, n):
  sat += bis[ais[i]-1]
  if ais[i] == ais[i-1] + 1:
    sat += cis[ais[i]-2]
print(sat)

Submission status: Accepted

Solution code:
n = int(input())
aList = list(map(int,input().split()))
bList = list(map(int,input().split()))
cList = list(map(int,input().split()))

manzoku = bList[aList[0]-1] 
for i in range(1,n):
  if aList[i]-1 == aList[i-1]:
    manzoku += bList[aList[i]-1]+cList[aList[i]-1-1]
  else:
    manzoku += bList[aList[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()))
S = 0
prev = -2
for i in range(n):
    now = a[i]
    S += b[now - 1]
    if now - prev == 1:
        S += c[prev - 1]
    prev = now

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

sum = 0
for i in range(n):
    now = a[i] - 1
    pre = a[i-1] - 1
    sum += b[ now ]
    if i > 0 and now - 1 == pre:
        sum += c[ pre ]

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=input().split()
b=input().split()
c=input().split()
to=0

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

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

b_sum = sum(b)

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

print(b_sum + c_sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
# coding: utf-8
# Your code here!

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


point = 0

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

print(point)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

a = [i-1 for i in a]
ans = b[a[0]]

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

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

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

print(m)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

    count = 0
    before = -1

    for i in range(n):
        count += b_list[a_list[i]-1]
        if before + 1 == a_list[i]:
            count += c_list[a_list[i]-2]
        before = a_list[i]

    print(count)

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, j in enumerate(A):
    ans += B[j - 1]
    if i == N - 1:
        break
    elif j + 1 == A[i + 1]:
        ans += C[j - 1]

print(ans)

Submission status: Accepted

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

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

print(sum)

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()))
s = np.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())
lia = list(map(int, input().split()))
lib = list(map(int, input().split()))
lic = list(map(int, input().split()))

sati = 0
j = lia[0]

for i in lia:
  sati += lib[i-1]
  if j == i-1:    
    sati += lic[j-1]    
  j = i
  
print(sati)

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

Submission status: Accepted

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

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

before = n
result = 0
for i in range(n):
    result += list_b[list_a[i] - 1]
    if before + 1 == list_a[i] - 1:
        result += list_c[before]
    before = list_a[i] - 1
print(result)

Submission status: Accepted

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

ans = sum(b)
for i in good_course:
    ans += c[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(len(a)-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]
    else:
        continue

print(ans+sum(b))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
prev = -1

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

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

former_a = -100
res = 0
for a in As:
    a = a - 1
    b = Bs[a]
    res += Bs[a]
    if a - former_a == 1:
        res += Cs[former_a]
    former_a = a

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

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

total_satisfaction = 0

size = len(a_list)

previous_cuisine_number = None

for i in range(size):
    cuisine_number = a_list[i]
    cuisine_number_index = cuisine_number - 1
    satisfaction = b_list[cuisine_number_index]
    total_satisfaction += satisfaction
    if previous_cuisine_number is not None and previous_cuisine_number == cuisine_number - 1:
        total_satisfaction += c_list[previous_cuisine_number - 1]
    previous_cuisine_number = cuisine_number

print(total_satisfaction)

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

# N = int(readline())
# D = [int(d) for d in readline().split()]

import itertools

N = int(readline())
A = [int(x)-1 for x in readline().split()]
B = [int(x) for x in readline().split()]
C = [int(x) for x in readline().split()]

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


print(ans)

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

# N = int(readline())
# D = [int(d) for d in readline().split()]

import itertools

N = int(readline())
A = [int(x)-1 for x in readline().split()]
B = [int(x) for x in readline().split()]
C = [int(x) for x in readline().split()]

ans = 0
ans += sum(B)
temp = 30
for i in A:
    if temp + 1 == i:
        ans += C[i-1]
    temp = i

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(s) for s in input().split(' ')]
B = [int(s2) for s2 in input().split(' ')]
C = [int(s3) for s3 in input().split(' ')]

satis = 0

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

satis += sum(B)

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

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

Submission status: Accepted

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

    res = 0
    bk = 5
    for i in range(n):
        res += b[a[i]-1]
        if a[i] == bk + 1:
            res += c[a[i]-2]
        bk = a[i]

    print(res)

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

M=0
i=0

while i < N:
  M += B[A[i]-1]
  if i>=1:
    if A[i]-A[i-1]==1:
      M +=  C[A[i-1]-1]
  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()))

score = B[0]
tmp = A[0]

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

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

print(S)

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 a in A:
        ans += B[a-1]

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

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

ans = 0

for i in range(len(a)):
  if i == 0:
    ans += b[a[i]-1]
  elif a[i] - a[i-1] == 1:
    ans += b[a[i]-1] + c[a[i-1]-1]
  else:
    ans += b[a[i]-1]

print(ans)

Submission status: Accepted

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

y=0
for i in b:
    y+=i
#print(y)

x=0
for j in range(n-1):
    if a[j]-a[j+1]==-1:
        
        x+=c[(a[j])-1]
#print(x)

print(x+y)

Submission status: Accepted

Solution code:
n = int(input())
a_lst = list(map(int,input().split()))
b_lst = list(map(int,input().split()))
c_lst = list(map(int,input().split()))
ans = 0

for i in range(n):
    ans += b_lst[a_lst[i]-1]
    if  i != 0 and a_lst[i] == a_lst[i-1] + 1:
        ans += c_lst[a_lst[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()))

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

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(" ")))
    result = 0
    meal_num = -5
    for a in A:
        if a == meal_num + 1:
            result += C[a - 2]
        result += B[a - 1]
        meal_num = a
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = sum(B)

for i in range(N-1):
    if A[i]+1 == A[i+1]:
        #print(str(A[i])+ " : " +str(A[i+1]))
        ans += C[A[i]-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
Cs = [int(i) for i in input().split()]

ans = 0
prev = -1
for a in As:
    ans += Bs[a-1]
    if prev + 1 == a:
        ans += Cs[prev-1]
    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()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=B[int(A[0])-1]

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

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