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 sys
stdin = sys.stdin
mod = 10**9 + 7

import numpy as np

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = na()
b = na()
c = na()
ans = sum(b)
d = np.array(a[:-1]) - np.array(a[1:])
for di, num in enumerate(d):
        if num == -1:
                ans += c[a[di]-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(" ")))

r = 0
j = -1
for i in A:
  r += B[i-1]
  #print(B[i-1])
  if i - j == 1:
    r += C[i-2]
    #print(C[i-2])
  j = i
  
print(r)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
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 = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

for a in range(N):
    A[a] -= 1


cnt = 0
cnt += B[int(A[0])]

pa = A[0]

for a in A[1:N+1]:
    cnt += B[int(a)]

    if (a-1) == pa:
        cnt += C[int(a-1)]
    pa = a

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

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

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:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
A = LI()
B = LI()
C = LI() + [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:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

lst =[]
count = sum(b)

for i in range(n - 1):
  if a[i + 1] == a[i] + 1:
    lst.append(a[i] - 1)
  
for i in lst:
  count += c[i]
  
print(count)

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

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

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 = s + C[A[i]-1]
print(s)

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_a = list(map(int, sys.stdin.readline().split()))
list_b = list(map(int, sys.stdin.readline().split()))
list_c = list(map(int, sys.stdin.readline().split()))

# print(list_a)
# print(list_b)
# print(list_c)

sum_b = 0

for i in range(N):
    sum_b += list_b[i]
    if(i < N-1 and (list_a[i]+1) == list_a[i+1]):
        sum_b += list_c[list_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()))

dish = []       
for i in range(N):
 dish.append([A[i],B[A[i]-1]])

ans = 0
for i in range(N):
  ans += dish[i][1]
  if(i != N-1):
    if(dish[i][0]+1 == dish[i+1][0]):
      index_ = dish[i][0]-1
      ans += C[index_]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

#ソート
b2 =[0 for i in range(n)]

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

out = b2[0]
pre = a[0]

for i in range(1,n):
    out += b2[i]
    #print("-",pre,a[i],a[i]-pre)
    if a[i]-pre == 1:
        out += c[a[i]-2]
    pre = a[i]
        
print(out)

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

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

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

score = 0
before = N

for i in range(N):

    x = A[i] - 1
    score += B[x]

    if before + 1 == x:
        score += C[before]

    before = x

print(score)

Submission status: Accepted

Solution code:
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
s=lb[la[0]-1]
for i in range(1,n):
  s+=lb[la[i]-1]
  if la[i]-la[i-1]==1:
    s+=lc[la[i-1]-1]
print(s)

Submission status: Accepted

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

print(tmp)

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

print(sum)

Submission status: Accepted

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

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

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

print(manzoku)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

n=int(input())
a=[]
for i in range(3):
    aa=list(map(int,input().split()))
    a.append(aa)
ans=0
num=-1
num2=-1
for j in a[0]:
    ans+=a[1][j-1]
    num2=j
    if num2-num==1:
        ans+=a[2][j-2]
    num=j
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
c = [int(_) for _ in input().split()]
ans = 0
prev = -1
for i in range(n):
    curr = a[i]
    ans += b[a[i] - 1]
    if curr - prev == 1:
        ans += c[prev-1]
    prev = curr
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[i]

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


N = int(input())

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

for n in range(N):
    A[n] -= 1    

def main(): 
    res = B[A[0]]
    past = A[0]
    for n in range(1,N):
        res += B[A[n]]
        if A[n] == past+1:
            res+=C[A[n]-1]
        past = A[n]
        #print(res)
    print(res)
                
                
                
            
            
                

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

before = -1
sum_happy = 0

for a in A:
    sum_happy += B[a - 1]
    if a == before+1:
        sum_happy += C[a - 2]
    before = a

        
print(sum_happy)

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

print(sum)

Submission status: Accepted

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

ans=0
prev=None
for i in range(N):
	a=A[i]
	ans+=B[a-1]
	if prev is None:
		pass
	elif prev+1==a:
		ans+=C[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()))

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


score=0
#食べた番号
num=0
old_num=0

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

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

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

print(sum(B)+CN)

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) - 1 for a in 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]]
  if i != N-1 and A[i] + 1 == A[i+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()))
satis = B[A[0]-1]
for i in range(1,N):
    satis+=B[A[i]-1]
    if A[i-1]+1 == A[i]:
        satis += C[A[i-1]-1]
print(satis)

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

result = 0

for i in range(n):
    result += blist[alist[i]-1]
    if i != n-1:
        if alist[i+1] == (alist[i] +1):
            result += clist[alist[i]-1]

print(result)

Submission status: Accepted

Solution code:
'use strict'
N = int(input())
A = [x-1 for x in (list(map(int, input().split())))]
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisfy_level = B[A[0]]

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

print(satisfy_level)

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

manzoku = sum(B_list)

before = A_list[0]
for i in range(1, N):
  if A_list[i] == before + 1:
    manzoku += C_list[before-1]
  before = A_list[i]

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

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

print(d)

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):
    ai = A[i] - 1
    ans += B[ai]
    if i > 0 and ai == A[i - 1] - 1 + 1:
        ans += C[A[i - 1] - 1]
    # print(ans)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split())) + [10000]
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+1] - a[i] == 1:
    ans += c[a[i]-1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sum = 0
bonus = 10**9
for i in range(N):
    sum += B[A[i]-1]
    if A[i] == bonus:
        sum += C[A[i]-2]
    bonus = 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()))
 
befo = -100
sat = 0
for i in range(N):
    index = A[i] - 1
    sat += B[index]
    if befo + 1 == index:
        sat += C[befo]
    befo = index
 
print(sat)

Submission status: Accepted

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

import sys

n=int(sys.stdin.readline())
a= [ int(x)-1 for x in sys.stdin.readline().split() ]
tot= 0
for x in sys.stdin.readline().split(): tot+=int(x)
c= [ int(x) for x in sys.stdin.readline().split() ]
#
for i in range(1,n):
    if a[i-1]+1==a[i]: tot+= c[a[i-1]]
print( tot )

Submission status: Accepted

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

satisfaction = 0
dinner1 = A[0]
satisfaction += B[dinner1]

for a in A[1:]:
  dinner2 = a
  satisfaction += B[dinner2]
  if dinner1 + 1 == dinner2:
    satisfaction += C[dinner1]
  dinner1 = dinner2

print(satisfaction)

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

Submission status: Accepted

Solution code:
num = int(input())

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

prev = a[0]-1
ans = b[a[0]-1]

for i in a[1:]:
  _i = i-1
  ans += b[_i]
  if prev + 1 == _i:
    ans += c[prev]
  prev = _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
prev_idx = -10
for a in A:

    ans += B[a-1]
    if prev_idx + 1 == a-1:
        ans += C[a-2]
    prev_idx = a-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 = -1
for a_i in a:
    count += b[a_i-1]
    if pre == a_i - 1:
        count += c[pre-1]
    pre = a_i

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()))
p = 0
r = 100

for i in a:
  p += b[i-1]
  if i == r+1:
    p += c[i-2]
  r = i

print(p)

Submission status: Accepted

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

print(n)

Submission status: Accepted

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

for i in range(n):
    ans = ans + b[i]

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
als = list(map(int, input().split()))
bls = list(map(int, input().split()))
cls = list(map(int, input().split()))

numls = []
for i in range(n-1):
  dif = als[i+1] - als[i]
  if dif == 1:
    numls.append(als[i])
#print(numls)

subtotal = 0
for j in numls:
  subtotal = subtotal + cls[j-1]
  
print(sum(bls)+subtotal)

Submission status: Accepted

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

satis = int(0)
before_value = int(100)

for value in a:
  satis += b[value-1]
  if before_value == (value-1):
    satis += c[value-2]
  before_value = value

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

sum=0
prev=-1000

for a in A:
    sum+=B[a-1]
    if a-prev==1:
        sum+=C[a-2]
    prev=a
    
print(sum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

        if i == n - 1:
            break
        if a[i+1] - a[i] == 1:
            result += c[meal]

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)


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

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

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

Submission status: Accepted

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

for i, a in enumerate(A[:-1]):
    if A[i+1] == a+1: ans+=C[a-1]

print(ans)

Submission status: Accepted

Solution code:
n = input()
n = int(n)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
memo = -1
ans = 0
count = -1
for ai in a:
    ans += b[ai - 1]
    if ai - 1 == memo:
        ans += c[ai - 2]
    memo = ai
    count += 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()))
d = 0

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

print(b_sum + d)

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

count = sum(B)

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

print(count)

Submission status: Accepted

Solution code:
def A():
    print(int(input())**3)

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

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

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


result = sum(B)
before = -2

for a in A:
    if before+1 == a:
        result = result + C[a-2]
    before = a

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

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