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:
# coding: utf-8


def solve():
    N = int(input())
    al = list(map(lambda x:int(x)-1, input().split()))
    bl = list(map(int, input().split()))
    cl = list(map(int, input().split()))
    ans = 0
    
    for i in range(N):
        if i != N - 1:
            if al[i] + 1 == al[i+1]:
                ans += cl[al[i]]
        ans += bl[al[i]]
    
    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()))
C = list(map(int, input().split()))

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

score = 0
prev = -1
for ai in a:
    score += b[ai - 1]
    if prev + 1 == ai:
        score += c[prev - 1]

    prev = ai

print(score)

Submission status: Accepted

Solution code:
# 入力を受け取る
N = int(input().strip())
A = input().strip().split()
A = [None] + [int(a) for a in A] # 整数に変換
B = input().strip().split()
B = [None] + [int(b) for b in B] # 整数に変換
C = input().strip().split()
C = [None] + [int(c) for c in C] # 整数に変換

satisfaction = 0
for i in range(1, N+1): # i = 0, 1, ..., N-1
    satisfaction += B[A[i]]
    if i >= 2 and A[i] == A[i - 1] + 1 :
        satisfaction += C[A[i - 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()))
co=0
for i in range(len(B)):
    co+=B[i]
for j in range(len(C)):
    if A[j+1]==A[j]+1:
        co+=C[A[j]-1]
print(co)

Submission status: Accepted

Solution code:

if __name__ == '__main__':

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

	gokei = 0
	for i in range(1,len(A)):
		if A[i] - A[i-1] == 1:
			gokei += C[A[i-1]-1]

	gokei += sum(B)
	print(gokei)

Submission status: Accepted

Solution code:
# ABC140 B - Buffet

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

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

print(pt)

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

ans = sum(b_list)

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=sum(map(int,input().split()))
c=list(map(int,input().split()))
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()]
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 = 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 = 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] - 2]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

ans = 0
bef = N+1
for now in A:
    now -= 1
    ans += B[now]
    if bef + 1 == now:
        ans += C[bef]
    bef = now
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:
# coding: utf-8
# Your code here!
N = int(input())
A = list(map(int,input().split()))
B = [0] + list(map(int,input().split()))
C = [0] + list(map(int,input().split()))
#print(A,B,C)
manzoku = 0
for i in range(N):
    manzoku += B[A[i]]
    if i > 0 and A[i] == A[i-1]+1:
        manzoku += C[A[i-1]]
    
print(manzoku)

Submission status: Accepted

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

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

Submission status: Accepted

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

result = 0

for x in range(len(A) - 1):
	result += B[x]
	if A[x]+1 == A[x+1]:
		result += C[A[x]-1]
result += B[len(A)-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()))

cnt = 0
before = -100
for i in range(n):
    cnt += b[a[i] - 1]

    if before + 1 == a[i]:
        cnt += c[before-1]

    before = a[i]
print(cnt)

Submission status: Accepted

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

for i in range(n):
      if i ==(n-1):
         break
      if (a[i]+1) == a[i+1]: #a[i]は項数
         b[a[i]-1] += c[a[i]-1]
print(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 = 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] - 2]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    a = f.read_int_list()
    b = f.read_int_list()
    c = f.read_int_list()

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


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

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

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

Submission status: Accepted

Solution code:
n = int(input())
aarr = list(map(int, input().split()))
barr = list(map(int, input().split()))
carr = list(map(int, input().split()))
sarr = []

for i in range(n):
    sarr.append(barr[aarr[i] - 1])

    if (i != n - 1) and (aarr[i] + 1 == aarr[i + 1]):
        sarr[len(sarr) - 1] += carr[aarr[i] - 1]

print(sum(sarr))

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 = -999
for i in a:
  i -= 1
  ans += b[i]
  if i == prev + 1:
    ans += c[prev]
  prev = i

print(ans)

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

s = 0

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

print(s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    print(n**3)
    return

#B
def B():
    n = II()
    a = LI()
    b = LI()
    c = LI()
    ans = 0
    for i in range(n):
        ans += b[a[i] - 1] + (c[a[i] - 1] if i != n - 1 and a[i] + 1 == a[i + 1] else 0)
    print(ans)
    return

#C
def C():
    n = II()
    b = LI()
    ans = b[0]
    for i in range(n-1):
        if b[i] >= b[i + 1]:
            ans += b[i + 1]
        else:
            ans += b[i]
    print(ans)
    return

#D
def D():
    n, k = LI()
    s = S()
    a = []
    for i in range(n):
        if i == n - 1:
            a.append(s[i])
        elif s[i] != s[i + 1]:
            a.append(s[i])
    print(min(n - 1, n - len(a) + 2 * k))
    return

#E
def E():
    return

#F
def F():
    return


#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

manzoku_do = 0
i = 0

manzoku_do = 0
i = 0

manzoku_do += int(b[int(a[i]) - 1])
i += 1

while i < n:
  manzoku_do += int(b[int(a[i]) - 1])
  
  if int(a[i - 1]) -1  == int(a[i])-1 - 1:
    manzoku_do += int(c[int(a[i -1]) -1 ])
  i += 1
    
    
print(manzoku_do)

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:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 26 12:13:54 2019

@author: hiros
"""

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


"""
c_dish = A[0]-1 #料理１ならc_dish = 0と定義
ans = B[c_dish] 
f_dish = c_dish #前に食べた料理番号

for i in range(1,N):
    c_dish = A[i]-1
    ans += B[c_dish]
    if (c_dish == f_dish + 1): #ボーナスポイント
        ans += C[f_dish]
    #print(ans, c_dish,f_dish)

    f_dish = c_dish
    #print(ans, c_dish,f_dish)

print(ans)

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


satis = 0

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

sat=sum(B)
#print(sat)

for i in range(0,n-1):
    if int(A[i])+1 == int(A[i+1]):
        name=int(A[i])
        #print('料理の名前は')
        #print(name)
      
        sat = sat + int(C[name-1])
        #print(sat)
    else:
      #print('none')
      continue

print(sat)

Submission status: Accepted

Solution code:
N=int(input())
listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
listC=list(map(int,input().split()))
sumB=int(sum(listB))
for i in range(1,N):
    if listA[i] == listA[i-1]+1:
        sumB=sumB+int(listC[listA[i-1]-1])
print(sumB)

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

Submission status: Accepted

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

s = sum(bb)
for i in range(N-1):
  if aa[i+1] - aa[i] == 1:
    s += cc[aa[i]-1]
print(s)

Submission status: Accepted

Solution code:
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

satisfaction = sum(B)

before_i = float("Inf")
for i in range(N - 1):
    if A[i] + 1 == A[i+1]:
        satisfaction += C[A[i] - 1]
        
print(satisfaction)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

satisfy = sum(B)
for i, a in enumerate(A):
    if i == 0:
        continue
    if a - A[i-1] == 1:
        satisfy += C[A[i-1] - 1]
print(satisfy)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
li_a =list(map(int, input().split()))
li_b =list(map(int, input().split()))
li_c =list(map(int, input().split()))

before = -99
points = 0
for i in li_a:
      points += li_b[i - 1]
      if before + 1 == i:
            points += li_c[i - 2]
      before = i
print(points)

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

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

min_sum = sum(B)
additionals = []

for i in range(1, len(A)):
    if A[i]-A[i-1] == 1:
        j = A[i-1]-1
        additionals.append(C[j])

sum_additionals = sum(additionals)

sum = min_sum + sum_additionals

print(sum)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    lst_A = list(map(int, input().split()))
    lst_B = list(map(int, input().split()))
    lst_C = list(map(int, input().split()))

    ret = sum(lst_B)
    for i in range(N - 1):
        a1 = lst_A[i]
        a2 = lst_A[i + 1]
        diff = a2 -a1

        if diff == 1:
            ret += lst_C[a1 - 1]
    
    return ret


if __name__ == "__main__":
    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()))
for i in range(N-1):
  if A[i]+1 == A[i+1]:
    B.append(C[A[i]-1])
print(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 = 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(lambda s: int(s) - 1, 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]]
for i in range(n - 1):
    if a[i] + 1 == a[i+1]:
        ans += c[a[i]]
print(ans)

Submission status: Accepted

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n=int(input())
    *a,=map(int,input().split())
    *b,=map(int,input().split())
    *c,=map(int,input().split())
    t=sum(b)
    for i in range(len(a)-1):
        if a[i]+1==a[i+1]:
            t+=c[a[i]-1]
    print(t)

            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = input()
a = input().split(" ")
b = input().split(" ")
c = input().split(" ")

A = []
B = []
C = []

for z in a:
  A.append(int(z))

for x in b:
  B.append(int(x))
  
for y in c:
  C.append(int(y))

manzokudo = 0

for j in range(len(A)):
  manzokudo += B[A[j] - 1]
  try:
    if (A[j] - 1 == A[j-1]) and (j-1 > -1): 
      manzokudo += C[A[j] - 1 - 1]
  except:
    pass
  
print(manzokudo)

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int,input().split())) for l in range(3)]
mnpk = 0
fl = 0
for i in range(n):
  b = a[0][i] - 1
  mnpk = mnpk + a[1][b]
  if fl == 1:
    if a[0][i-1] == b:
      mnpk = mnpk + a[2][b-1]
  else:
    fl = 1
 
print(mnpk)

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

pre_index = 99

sum_point = 0
for index in a_list:
    sum_point += b_list[index - 1]
    
    if (index - pre_index == 1):
        sum_point += c_list[pre_index - 1]
    
    pre_index = index

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

res = sum(b_list)

for i in range(n-1):
    if a_list[i+1]-a_list[i]==1:
        res += c_list[a_list[i]-1]
print(res)

Submission status: Accepted

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

for count in range(n):
    satisfaction_point += b_list[a_list[count] - 1]
    # c_listは他の入力より１つ要素が少ない
    if count < n - 1:
        if a_list[count] + 1 == a_list[count + 1]:
            satisfaction_point += c_list[a_list[count] - 1]

print(satisfaction_point)

Submission status: Accepted

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

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

print(ans + sum(b))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    n = int(input())
    t_order = list(map(int, input().split()))
    happiness = list(map(int, input().split()))
    additional_hpns = list(map(int, input().split()))
    for i in range(len(happiness)):
        t_order[i]=t_order[i]-1
        
    sum=0
    for i in range(n):
        sum+=happiness[i]
        
        if i!=0:
            if t_order[i] == t_order[i-1] + 1:
                sum+=additional_hpns[t_order[i-1]]
                
    print(sum)
    
    return

if __name__ == '__main__':
    main()

# 料理i: 0 ~ n-1 が存在する
# 高橋くんはi番目に料理a_iを食べた
# 料理iから得られる満足はb_i
# 
# 1 2 3
# 2 5 4
# 3 6

# 3 1 2
# 4 2 5 
#    3

Submission status: Accepted

Solution code:
#a,b=map(int,input().split())
#p_3,p_4=map(int,input().split())
n=int(input())
#S=input()
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
total=sum(b)
for i in range(n-1):
    if a[i]+1==a[i+1]:
        total+=c[a[i]-1]
print(total)

Submission status: Accepted

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

for i in a:
    if i - a[a.index(i)-1] == 1 and a.index(i)-1 >= 0:
        ans=ans+b[i-1]+c[i-2]
    else:
        ans+=b[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(" ")))
score = 0

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

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

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

Submission status: Accepted

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

i = 0
point = 0
while i < len(A):
    point += B[A[i]-1]
    if i != 0 and A[i-1] + 1 == A[i]:
        point += C[A[i-1]-1]
    i += 1
print(point)

Submission status: Accepted

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

sum = b[a[0]-1]
p = a[0]-1
for i in a[1:]:
    index = i-1
    sum += b[index]
    if p != n-1 and index == p+1:
        sum += c[p]
    p = index

print(sum)

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  a_s = list(map(int, input().split(' ')))
  b_s = list(map(int, input().split(' ')))
  c_s = list(map(int, input().split(' ')))
  ans = 0
  for i in range(n):
    ans += (b_s[a_s[i]-1] + c_s[a_s[i]-1]) if (i != n-1 and a_s[i+1]) == (a_s[i] + 1) else b_s[a_s[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()))

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

Submission status: Accepted

Solution code:
n = input()

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



before_num = 0
sum = 0
for a in a_list:
    sum += b_list[a-1]
    if before_num > 0 and (before_num == (a-1)):
        sum += c_list[before_num-1]
    before_num = 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()))

ans = 0
check = []
for i in a:    
    ans += b[i-1]
    check.append(i)
    if check[check.index(i)-1] + 1 == check[check.index(i)]:
        ans += c[i-2]
    
print(ans)

Submission status: Accepted

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

ans=0
prev=-1
for _a in a:
    ans+=b[_a-1]
    if prev+1 == _a:
        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()))
i = 1
ans = sum(b)
while i <= n-1:
    if a[i]  == a[i-1] + 1:
        ans = ans + c[a[i-1]-1]
    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
bef = 999
for idx, val in enumerate(A):
    ans += B[val - 1]
    if val == bef + 1:
        ans += C[val - 2]
    bef = val
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

ans = satis
print(ans)