Problem:


Score : 200 points

Problem Statement

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.

The i-th dish (1 \leq i \leq N) he ate was Dish A_i.

When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.

Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

All values in input are integers.

2 \leq N \leq 20

1 \leq A_i \leq N

A_1, A_2, ..., A_N are all different.

1 \leq B_i \leq 50

1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

Sample Input 1

3
3 1 2
2 5 4
3 6

Sample Output 1

14

Takahashi gained 14 satisfaction points in total, as follows:

First, he ate Dish 3 and gained 4 satisfaction points.

Next, he ate Dish 1 and gained 2 satisfaction points.

Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.

Sample Input 2

4
2 3 4 1
13 5 8 24
45 9 15

Sample Output 2

74

Sample Input 3

2
1 2
50 50
50

Sample Output 3

150



Sample input:
3
3 1 2
2 5 4
3 6


Sample output:
14

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

s = np.sum(b)
for i in range(n):
  a[i] = a[i] -1

t = a[0]
for i in range(1, len(a)):
  if (t+1) == a[i]:
    s = s + c[a[i]-1]
  t = a[i]
print(s)

Submission status: Accepted

Solution code:
N = int(input())
eat = list(map(int, input().split())) #料理の番号
sat = list(map(int, input().split())) #i番目の料理の満足度
ad_sat = list(map(int, input().split())) #追加の満足度

#print(N, eat, sat, ad_sat)
sum_sat = sat[eat[0]-1]
for i in range(1,N):
  sum_sat += sat[eat[i]-1]
  #print(eat[i]-1)
  #print(sum_sat)
  if eat[i] == 1 + eat[i-1]:
    sum_sat += ad_sat[eat[i-1]-1]
    #print("add")

print(sum_sat)

Submission status: Accepted

Solution code:
def main():

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
d = 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):
    if(i<(n-1) and d[i]==(d[i+1]-1)):
        ans+=c[d[i]-1]
print(ans)

Submission status: Accepted

Solution code:
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, = gi()
a, b, c = gi(), gi(), gi()
ans = sum(b)
for k in range(1, n):
	if a[k] - a[k - 1] == 1:
		ans += c[a[k] - 2]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Cook = list(map(int, input().split()))
Manzoku = list(map(int, input().split()))
addManzoku = list(map(int, input().split()))

result_sum = 0
past_c = 55

for i, c in enumerate(Cook):
    result_sum += Manzoku[c-1]

    if c - past_c == 1:
        result_sum += addManzoku[c-2]
    past_c = c

print(result_sum)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = list(np.array(A) - 1)
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum_ = 0
diff = list(np.array(A[1:]) - np.array(A[:-1]))
diff.insert(0, -1)
for i in range(N):
  sum_ += B[A[i]]
  
  if diff[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()))
ans = 0
prev = -10
for i in A:
    ans += B[i-1]
    if i-prev==1:
        ans += C[prev-1]
    prev = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

A = [int(i) for i in input().split() ]

B = [int(i) for i in input().split() ]

C = [int(i) for i in input().split() ]

SUM = sum(B)

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

print(SUM)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#N=input()
#N,M=map(int,input().split())
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 j in range(N):
  if j+1!=N:
    if A[j]+1==A[j+1]:
      total+=C[A[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(len(A)):
    ans+=B[A[i]-1]
    if i>0:
        if A[i]==A[i-1]+1:
            ans+=C[A[i-1]-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))

score = 0
i1 = 0
i2 = -100
for i in range(n):
  i1 = aaa[i]
  if i1 == i2 + 1:
    score += ccc[i2 - 1]
  score += bbb[i1 - 1]
  i2 = aaa[i]

print(score)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
Junban_L = list(map(int, input().split()))
point_L = list(map(int, input().split()))
katen_point_L = list(map(int, input().split()))

ans=0
prenum = None
for num in Junban_L:
    ans = ans + point_L[num-1]
    if prenum == num-1:
        ans = ans + katen_point_L[prenum-1]
    prenum = num

print(ans)

Submission status: Accepted

Solution code:
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()]


sum = 0
previous = -10
for a in A:
    sum += B[a - 1]

    if a == previous + 1:
        sum += C[a - 2]
    previous = a
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
 
b_sum = sum(list_b)
 
satis = 0
for i in range(n-1):
  if list_a[i+1] == list_a[i] + 1:
    satis += list_c[list_a[i]-1]
 
result = b_sum + satis

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

m=0

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

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

satis_level = sum(B)

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

print(satis_level)

Submission status: Accepted

Solution code:
N = int(input())
eatingOrder = list(map(int, input().split()))
points = list(map(int, input().split()))
bonusPoints = list(map(int, input().split()))

sutisfactionPoint = 0
beforeFood = -1
for food in eatingOrder:
    sutisfactionPoint += points[food-1]

    if beforeFood+1 == food:
        sutisfactionPoint += bonusPoints[beforeFood-1]
    
    beforeFood = food
print(sutisfactionPoint)

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 idx, a in enumerate(A):
    score += B[a-1]
    if idx >= 1 and a == A[idx-1] + 1:
        score += C[A[idx-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()))

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:
#coding:utf-8
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a_new = list(map(lambda x: x - 1, a))
s = 0

for i in range(0, n):
    s += b[a_new[i]]
    if i != 0 and a_new[i] == a_new[i-1] + 1:
        s += c[a_new[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)
prev=A[0]
for i in range(1,n):
    if A[i]==prev+1:
        ans+=C[prev-1]
    prev=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()))
count = B[A[0]-1]
j = 0
for i in range(1,N):
    manzoku = B[A[i]-1]
    if A[i-1] == A[i]-1:
        # print("C",C[A[i-1]-1])
        manzoku += C[A[i-1]-1]
    count += manzoku
print(count)

Submission status: Accepted

Solution code:
food_number = int(input())
food_history = list(map(int, input().split()))
point_b = list(map(int, input().split()))
point_c = list(map(int, input().split()))
total_point = 0
for x in range(food_number):
  total_point += point_b[food_history[x] - 1]
  if(x >= 1 and food_history[x] - 1 == food_history[x - 1]):
    total_point += point_c[food_history[x - 1] - 1]
print("{}".format(total_point))

Submission status: Accepted

Solution code:
N = int(input())
A_LIST = input().split(" ")
B_LIST = input().split(" ")
C_LIST = input().split(" ")

n = 0
start = 1 #最初のみ例外処理
S = 0
for i in A_LIST:
    i = int(i)
    if start == 1:
        start = 0
    else:
        if i == n + 1:
            S += int(C_LIST[i - 2])
        else:
            n = i
    
    S += int(B_LIST[i - 1])
    n = i
    
print(S)

Submission status: Accepted

Solution code:
N = int(input())

list_A = input().split()
list_B = input().split()
list_C = input().split()

#print(list_A)

mysum = 0
mypast = int(list_A[0])
for i in list_A:
    mysum += int(list_B[int(i)-1])
    if int(i)-mypast == 1:
        mysum += int(list_C[mypast-1])
        #print('C', list_C[mypast-1])

    mypast = int(i)
    #print(list_B[int(i)-1],mysum)
    
    


print(mysum)

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

ans = 0
for i in range(len(A)):
    j = A[i]
    ans += B[int(j-1)]
    if i == 0:
        pass
    else:
        if A[i]-A[i-1] == 1:
            ans += C[int(j-2)]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

before = -100
result = sum(b)

for i in a:
  if(i == before+1):
    result += c[before-1]
  before = i
  
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()))
ma = 0
a.append(0)

for i in range(len(a)-1):
    ma += b[a[i]-1]

    if a[i+1]-a[i] == 1:
        ma += c[a[i]-1]
        

print(ma)

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]
    else:
        ans+=0
print(ans)

Submission status: Accepted

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

ans = sum(Bs)

for i in range(len(As) - 1):
    if As[i] + 1 == As[i+1]:
        ans += Cs[As[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()))
satisfy=0
b_i=0
for i in A:
    if i-b_i==1 and b_i!=0:
        satisfy=satisfy+B[i-1]+C[i-2]
    else:
        satisfy+=B[i-1]
    b_i=i
print(satisfy)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    r = 0
    for i in range(N):
        r += B[A[i] - 1]
        if i < N - 1 and A[i+1] - A[i] == 1:
            r += C[A[i] - 1]
    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

satisfaction = 0
prev = a[0]

for i in a:
  satisfaction +=  b[i-1]

  if i-prev == 1:
    satisfaction += c[i-2]
  prev = i


print(satisfaction)

Submission status: Accepted

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

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

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)
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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
e=[0]*n
c = [int(i) for i in input().split()]
s=0
for i in range(n):
  s+=b[a[i]-1]
  if(i>0 and a[i]==a[i-1]+1):s+=c[a[i]-2]
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
be = 22
cu = 0

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())
def main():
  n = ni()
  a = list(na())
  b = list(na())
  c = list(na())

  ans = 0
  pre = 0
  for i, aa in enumerate(a):
    aa -= 1
    if i >= 1 and i <= n-1 and pre+1 == aa:
      ans += c[aa-1]
    ans += b[aa]
    pre = aa
  print(ans)
main()

Submission status: Accepted

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

x = 0
iii=-2

i=0

for i in range(n):

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

    if ii == iii+1 :
        x += int(c[iii-1])
        
    iii = ii
    
print(x)

Submission status: Accepted

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

m = 0
before = 0
for a in A:
    m += B[a-1]
    if before != 0:
        if before+1 == a:
            m += C[before-1]
    before = a
    #print(m)
    #print(before)

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

Submission status: Accepted

Solution code:
N = int(input())
AList = [int(i) for i in input().split()]
BList = [int(i) for i in input().split()]
CList = [int(i) for i in input().split()]
Kasan = 0
for k in range(N-1):
    if AList[k]+1 == AList[k+1]:
        Kasan += CList[AList[k]-1]
print(sum(BList) + Kasan)

Submission status: Accepted

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


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):

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

    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))
cn = list(map(int,input().split()))
st = sum(bn)
for i in range(0, n-1):
    if an[i] == an[i+1] - 1:
        st += cn[an[i]-1]
print(st)

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

Submission status: Accepted

Solution code:
N = int(input())
dishs = list(map(int, input().split()))
points = list(map(int, input().split()))
add_points = list(map(int, input().split()))

res = 0
for i in range(0,len(dishs)-1):
    res += points[dishs[i]-1]
    if dishs[i]+1 == dishs[i+1]:
        res += add_points[dishs[i]-1]
res += points[dishs[len(dishs)-1]-1]
print(res)

Submission status: Accepted

Solution code:
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):
  if i != n-1 and a[i] == a[i+1] - 1:
        ans += c[a[i]-1]
print(ans + sum(b))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

sum_bn = sum(bn)
sum_cn = 0

for i in range(N-1):
    if an[i] + 1 == an[i+1]:
        sum_cn += cn[an[i]-1]

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

v = 0

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

print(v)

Submission status: Accepted

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

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

result = 0
for i in range(N):
    result += B[A[i]-1]
    if i>=1:
        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()))
ans = 0
for index, i in enumerate(a):
  ans += b[i-1]
  if(index > 0 and a[index] - a[index - 1] == 1):
    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()))
d=0
for i in range(n-1):
    if a[i+1]-a[i]==1:
        d+=c[a[i]-1]
print(sum(b)+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()]
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 -*-
import numpy as np


def main():
    n = int(input())
    a = np.array(input().split(), dtype='int')
    b = np.array(input().split(), dtype='int')
    c = np.array(input().split(), dtype='int')

    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)


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()))
total = 0
former = -2
for i in range(n):
  total += B[A[i]-1]
  if i != 0:
    if A[i] == A[i-1]+1:
      total += C[A[i-1]-1]
print(total)

Submission status: Accepted

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

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 = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

out = 0
out += sum(B_list)
a_prev = 0

for index, a in enumerate(A_list):
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        out += C_list[a-2]
    a_prev = a
    
print(out)

Submission status: Accepted

Solution code:
n = int(input())
dish = list(map(int, input().split()))
koyo = list(map(int, input().split()))
tsuika = list(map(int, input().split()))

ans = 0
bdish = -1

for i in dish:
  ans += koyo[i-1]
  if bdish+1 == i:
    ans += tsuika[bdish-1]
  bdish = 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()))
a.append(10000)
cnt=0
for i in range (n):
    cnt+=b[a[i]-1]
    if a[i]+1==a[i+1]:
        cnt+=c[a[i]-1]
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
arrs = [list(map(int,input().split())) for i in range(3)]

score = 0

for i in range(n):
    score += arrs[1][arrs[0][i]-1]
    if i != 0 :
        if arrs[0][i-1]+1 == arrs[0][i]:
            score += arrs[2][arrs[0][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()))
sum = 0
before = 99999
for i in range(n):
    sum += b[a[i]-1]
    if before == a[i] - 1:
        sum += c[a[i-1]-1]
    before = a[i]
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
#N,A,B = map(int,input().split())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
C_list = list(map(int,input().split()))
#X1_list = [int(input()) for i in range(N)]
#X2_list = [list(map(int,input().split())) for i in range(N)]

result= B_list[A_list[0] - 1]
for i in range(1,N):
    #print(result)
    result += B_list[A_list[i] -1]
    if A_list[i] -1 == A_list[i-1] :
        result += C_list[A_list[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()))
score = 0

for i in range(N):
  if i > 0:
    if A[i-1]+1 == A[i]:
  	  score = score + (B[A[i]-1] + C[A[i]-2])
    else:
      score += B[A[i]-1]
      #print("plus : {}".format(B[A[i]-1]))
  else:
    score += B[A[i]-1]
    #print("plus : {}".format(B[A[i]-1]))
  #print(score)
  
print(score)

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

ans=0
for i in range(N):
	ans+=listB[i]
	if i==N-1:
		break
	if listA[i]+1==listA[i+1]:
		ans+=listC[listA[i]-1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dish = list(map(lambda x: int(x), input().split()))
utility = list(map(lambda x: int(x), input().split()))
bonus = list(map(lambda x: int(x), input().split()))

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

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))
    CS = list(map(int, input().split()))

    ans = 0
    prev = -2
    for a in AS:
        plus = BS[a-1]
        if 1 < a and prev == a-1-1:
            plus += CS[a-2]
        ans += plus
        prev = a-1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

# solve
ans = 0
prev = 0
for i in range(N):
    now = A[i] - 1
    ans += B[now]
    if i != 0 and prev == now - 1:
        ans += C[prev]
    prev = now

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

satis = 0
idAprev = 0
for idA in A:  
  satis += B[idA - 1]
  if idAprev != 0 and (idA - idAprev) == 1:
    satis += C[idAprev - 1]
    
  idAprev = idA

print(satis)

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 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()))
l = []
cnt = 0
i = 0
for a in A:
  l.append((a,B[a-1]))
  i += 1
j = A[0]
for i in range(len(l)):
  cnt += l[i][1]
  a = l[i][0]-1
  if l[i][0] == j+1:
    cnt += C[a-1]
  j = l[i][0]
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()))
D = []
Sum = sum(B)
for i in range(n-1):
	if A[i+1] == A[i] + 1:
		p = A[i] - 1
		D.append(C[p])
Add = sum(D)
print(Sum+Add)

Submission status: Accepted

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

cnt = 0
pre = -1
for a in As:
  cnt += Bs[a-1]
  if pre == a - 1:
    cnt += Cs[pre-1]
  pre = a
  
print(cnt)

Submission status: Accepted

Solution code:
R = lambda:list(map(int,input().split()))
input()
a, b, c = R(), R(), R()
print(sum(b) + sum(c[i - 1] for i, j in zip(a, a[1:]) if j == i + 1))

Submission status: Accepted

Solution code:
n=int(input())
order=list(map(int,input().rstrip().split()))
num=sum(list(map(int,input().rstrip().split())))
opt=list(map(int,input().rstrip().split()))
for i in range(n-1):
  if order[i]==order[i+1]-1:
    num+=opt[order[i]-1]
print(num)

Submission status: Accepted

Solution code:
# 2019/09/07
# AtCoder Beginner Contest 140 - B

# Input
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.append(-999)

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

ans = sum
# Output
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()] + [-1]
b = [0] + [int(x) for x in input().split()]
c = [0] + [int(x) for x in input().split()]

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