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:
import os

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()))
	result_num = sum(b_list)

	for i,v in enumerate(a_list):
		count = v
		if i == (len(a_list)-1):
			break
		if (count+1) == a_list[i+1]:
			result_num += c_list[count-1]
	print(result_num)		

	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n = input()
line1 = input()
line2 = input()
line3 = input()

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

temp = a_list[0]
ans = 0
for a in a_list:
    if a == temp + 1:
        ans = ans + b_list[a-1] + c_list[temp-1]
    else:
        ans = ans + b_list[a-1]
    temp = 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(n):
    ans += b[a[i]-1]
    if i > 0 and a[i] == a[i-1] + 1:
        ans += c[a[i-1]-1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))
score = bb[aa[0]-1]
for i in range(1,n):
    score += bb[aa[i]-1]
    if aa[i] == aa[i-1] +1:
        score += cc[aa[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()))

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:
import itertools
import math
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):
    ind = a[i] - 1
    ind_next = a[i+1] - 1
    if ind + 1 == ind_next:
        ans += c[ind]
print(ans)
"""
for i in range(len(a)):
    #print(type(a[i]))
    sum+=int(b[int(a[i])-1])

    if a[i]==int(a[i-1])+1:
        sum+=int(c[int(a[i])-1])
        
print(sum)

"""

Submission status: Accepted

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

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

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

sum = 0
befcuis = 0
cuis = 0

for x in A:
    sum += B[x-1]
    cuis=x
    if  befcuis == cuis- 1:
        if befcuis -1 >=0:
            sum+=C[befcuis-1]
    
    befcuis = cuis
    
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


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

total = 0
tmp_num = -1

for i in range(N):
    num = A[i]
    total += B[num-1]

    if tmp_num + 1 == num:
        total += C[tmp_num-1]
    tmp_num = num

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = LIST()
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 >= 1 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()))

sf=0

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

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

print(sf)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    Ai = [int(a) for a in input().split()]
    Bi = [int(a) for a in input().split()]
    Ci = [int(a) for a in input().split()]
    s = 0
    for i in range(N):
        menu = Ai[i] - 1
        s += Bi[menu - 1]
        if i > 0 :
            if Ai[i] - Ai[i-1] == 1:
                s += Ci[Ai[i-1]-1]
    print(s)
main()

Submission status: Accepted

Solution code:
N = int(input())
A = [_ for _ in map(int,input().split())]
B = [_ for _ in map(int,input().split())]
C = [_ for _ in map(int,input().split())]
Happy = 0
temp = -10**9
for i in range(N):
  Happy += B[A[i]-1]
  if A[i]-1 == (temp+1):
    Happy += C[temp]
  temp = A[i] - 1
print(Happy)

Submission status: Accepted

Solution code:
L = [int(input()), list(map(int, input().split(' '))), list(map(int, input().split(' '))), list(map(int, input().split(' ')))]
print(sum([L[2][L[1][i]-1]+L[3][L[1][i]-2] if i>0 and L[1][i]-L[1][i-1]==1 else L[2][L[1][i]-1] for i in range(L[0])]))

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

Submission status: Accepted

Solution code:
N = int(input())
dish = list(map(int,input().split()))
sat =  list(map(int,input().split()))
cons = list(map(int,input().split()))
add = 0
past = -2
for i in range(len(dish)):
	curr = dish[i]
	if curr==past+1 and curr-2>=0:
		add+= (sat[curr-1]+cons[curr-2])
	else:
		add += sat[curr-1]
	past = curr
print(add)

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_l = list(map(int, input().split()))
    b_l = list(map(int, input().split()))
    c_l = list(map(int, input().split()))
    res = 0
    pre = 0
    for a in a_l:
        res += b_l[a-1]
        if (a - pre == 1) and (a != 1):
            res += c_l[a-2]
        pre = a
    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi_0()
    b = lmi()
    c = lmi()
    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)

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()))
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(str(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()))
total = sum(b)
for i in range(1,n):
    if a[i] == a[i-1] + 1:
        total += c[a[i]-2]
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=sum(B)

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

for i, n in enumerate(A):
    count += B[n-1]
    if i != len(A) - 1 and A[i+1] == n + 1:
        count += C[n - 1]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sm = 0

for x in a:
    if x != a[0]:
        if x == num + 1:
            sm += c[num-1]
    sm += b[x-1]

    num = x

print(sm)

Submission status: Accepted

Solution code:
"""
B-Buffet
"""

import sys
input = sys.stdin.readline
from itertools import *
from collections import *

INF = float('inf')


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

    total = 0
    pre_a = - INF
    for a in A:
        a -= 1
        total += B[a]

        if pre_a + 1 == a:
            total += C[pre_a]
        pre_a = a

    print(total)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(N):
    ans += B[i]

for j in range(N):
    if j >= 1:
        if A[j] == A[j - 1] + 1:
            tmp = A[j] - 2
            ans += C[tmp]

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

print(ful)

Submission status: Accepted

Solution code:
n=int(input())
def lima():
    return list(map(int,input().split()))

a=lima()
b=lima()
c=lima()

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

for i in range(N):
    t=A[i]
    s+=B[t-1]
    if i==0:
        pass
    elif A[i]==A[i-1]+1:
        s+=C[t-2]
print(s)

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

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

score = sum(b)
for i,j in zip(a,a[1:]):
    if j == i+1:
        score += c[i-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()))

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

print(score)

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

satisfiction = 0

for i in range(len(a)):
    tmpb = b[a[i] - 1]
    satisfiction += b[a[i] - 1]
    if i <= len(a) - 2 and (a[i + 1] - a[i] == 1):
        satisfiction += c[a[i]-1]
        # c.remove(c[0])
print(satisfiction)

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

Submission status: Accepted

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

x = 0
for i in range(n):
    x += bb[aa[i] - 1]
    if i > 0 and aa[i - 1] == aa[i] - 1:
        x += cc[aa[i - 1] - 1]
print(x)

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()))
s = 0
p = 0
for i in range(n):
  indx = al[i] - 1
  s += bl[indx]
  if i > 0 and al[i] - prev == 1:
    s += cl[indx - 1]
  prev = al[i]
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()))
x = sum(b)
for i in range(0,n-1):
    if a[i+1]-a[i]==1:
        x+=c[a[i]-1]
print(x)

Submission status: Accepted

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

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

sum = 0

prev = -1

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

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

answer = 0
for index, food in enumerate(a):
    if index == 0:
        answer += b[food - 1]
    elif a[index - 1] + 1 == food:
        answer += b[food - 1]
        answer += c[a[index - 1] - 1]
    else:
        answer += b[food - 1]

print(answer)

Submission status: Accepted

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

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

print(manzoku)

Submission status: Accepted

Solution code:
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))


n=II()
A=LI()
B=LI()
C=LI()

ans = 0
before = -1

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

total = B[A[0] - 1]

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

Submission status: Accepted

Solution code:
import sys
N=input()
A=[None]+map(int, sys.stdin.readline().split())
B=[None]+map(int, sys.stdin.readline().split())
C=[None]+map(int, sys.stdin.readline().split())

ans=0
prev=None
for a in A:
    if a is None: continue
    ans+=B[a]
    if prev is not None and prev+1==a:
        ans+=C[prev]
    prev=a

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
tmp = a[0] + 1
satisfactions = []
for i in a:
    satisfaction = b[i-1]
    if i == tmp:
        satisfaction = satisfaction + c[i-2]
    satisfactions.append(satisfaction)
    tmp = i + 1

print(sum(satisfactions))

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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



if __name__ == '__main__':
    main()

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

ret = b[a[0]-1]
for i,j in zip(a,a[1::]):
    ret += b[j-1]
    if j - i == 1:
        ret += c[j-2]
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
ali = list(map(int,input().split()))
bli = list(map(int,input().split()))
cli = list(map(int,input().split()))
total = 0
for i in range(n):
    total += bli[ali[i]-1]
    if i != n-1:
        if ali[i] == ali[i+1] - 1:
            total += cli[ali[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()))
ans = 0

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

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

ans = 0
for i in range(n-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())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split())) # len: n-1
point = 0
for i in range(n):
    index = a[i] -1
    point += b[index] # 基礎ポイント
    if i>=1 and a[i] == a[i-1]+1:
        point += c[a[i-1]-1]
print(point)

Submission status: Accepted

Solution code:
num = int(input())
index = list(map(int, input().split()))
point = list(map(int, input().split()))
add = list(map(int, input().split()))


total = 0
for i in range(num):
  total += point[index[i]-1]

for j in range(num-1):
  if index[j+1] == index[j]+ 1:
    total += add[index[j]-1]

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def q2():
    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
    pre_i = N
    for i in range(N):
        ans += B[A[i]-1]
        if A[i] == pre_i + 1:
            ans += C[A[i]-2]
        pre_i = A[i]
    print(ans)


if __name__ == '__main__':
    q2()

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

count = 0

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

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

suff = 0

for i in range(n):
    suff += B[A[i]-1]

for j in range(n-1):
    if A[j+1] == A[j]+1:
        suff += C[A[j]-1]
        
print(suff)

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

Submission status: Accepted

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

sum = sum(b)

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

Submission status: Accepted

Solution code:
import io
import sys
import math

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

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

Submission status: Accepted

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

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

print(x)