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

ans = 0

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



U = sum(B) + sum(C)

print(U)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
n=I()
As=LI()
Bs=LI()
Cs=LI()
satis=Bs[As[0]-1]
for i in range(1,n):
    satis+=Bs[As[i]-1]
    if As[i]==As[i-1]+1:
        satis+=Cs[As[i-1]-1]
print(satis)

Submission status: Accepted

Solution code:
n = int(input())
order = list(map(int, input().split()))
for i in range(n):
    order[i] -= 1
point = list(map(int, input().split()))
bonus = list(map(int, input().split()))

ans = 0
pre = -2 
for i in range(n):
    now = order[i]
    ans += point[now]
    
    if pre == now - 1:
        ans += bonus[pre]
    
    pre = 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(n-1):
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i]-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

A = [ int (x) for x in input().split() ]
B = [ int (x) for x in input().split() ]
C = [ int (x) for x in input().split() ]

result = sum(B)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
str_to_int = lambda value: int(value)

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

answer = 0
previous = -1
for Ai in A:
    delicious = B[Ai - 1]

    has_bonus = Ai - previous is 1
    bonus = C[previous - 1] if has_bonus  else 0

    answer += (delicious + bonus)

    previous = Ai

print(answer)

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

Submission status: Accepted

Solution code:
*H,=map(int,open(0).read().split());N=H[0];A=H[1:N+1]+[0];B=H[N+1:2*N+1];C=H[-N+1:];a=i=0
while i<N:
    a+=B[i]
    if A[i+1]-A[i]==1:a+=C[A[i]-1]
    i+=1
print(a)

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
#print(A,B,C)

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

j=0
while j < N-1:
  #print(A[j+1],A[j])
  if A[j+1]==A[j]+1:
    sum=sum+C[A[j]-1]
    #print(j,j+1,C[A[j]-1])
  j=j+1
    
print(sum)

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

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
b = input().split()
c = input().split()
result = 0
for i in range(n):
    order = int(a[i]) - 1
    result += int(b[order])
    if int(a[i]) - int(a[i-1]) == 1 and i is not 0:
        result += int(c[order-1])
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = sum(b)
bef = -1
for x in a:
    if bef + 1 == x:
        ans += c[bef - 1]
    bef = x
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()))
cnt = 0
for i in range(N):
    if (cnt > 0) and (a[i]==(a[i-1]+1)):
        cnt += c[a[i-1]-1]

    cnt += b[a[i]-1]
    
print(cnt)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
B=nl()
C=nl()
sum=0

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

print(sum)

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  ans = 0
  last = A[0]-1
  for i in range(n):
    ans += B[A[i]-1]
    #print(i,last,ans)
    if A[i]-1 == last + 1:
      #print(i,last)
      #print('come?')
      ans += C[last]
      last = A[i]-1
    else:
      last = A[i]-1
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

ans = 0
for i in range(n):
    
    ans += b_list[a_list[i]-1]
    #print(b_list[a_list[i]-1])
    if i == 0:
        continue
    else:
        if a_list[i] == a_list[i-1]+1:
            #print(a_list[i-1]-1)
            #print(c_list[a_list[i-1]-1])
            ans += c_list[a_list[i-1]-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [int(z) for z in input().split()]

total = 0
pre = 999
for i in range(N):
    total += b[a[i]-1]
    if a[i] == pre+1:
        total += c[pre-1]
    pre = a[i]
print(total)

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

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
B = iil()
C = iil()

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())
cuisine = list(map(int, input().split()))
saticefaction = list(map(int,input().split()))
moreSaticefaction = list(map(int, input().split()))
total = 0
beforeCuisine = -1
for i in cuisine:
  total += saticefaction[i - 1]
  if (i - 1) == beforeCuisine:
    total += moreSaticefaction[beforeCuisine - 1]
  beforeCuisine = i
print(total)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    b=LIST()
    c=LIST()
    ans=0
    for i in range(n):
        if i==0:
            ans+=b[a[i]-1]
        else:
            ans+=b[a[i]-1]
            if a[i-1]==a[i]-1:
                ans+=c[a[i-1]-1]
    print(ans)
if __name__ == '__main__':
    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()))
stack = A[0]
total = 0
for a in A:
  if stack == a-1:
    total += B[a-1]+C[stack-1]
  else:
    total += B[a-1]
  stack = a
print(total)

Submission status: Accepted

Solution code:
N = int(input())
Main = list(map(int,input().split()))
S = list(map(int,input().split()))
S_2 = list(map(int,input().split()))
ans = sum(S)
p = 0

for i in range(N-1):
    if Main[i+1] == Main[i]+1:
        p = Main[i]-1
        ans = ans + S_2[p]

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

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()))
clist.append(0)
ans = 0
for i in range(0,n):
    ans += blist[alist[i] - 1]
    if i != n-1 :
        if alist[i] +1 == alist[i+1]:
            ans += clist[alist[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
i=0
while i<=N-1:
  sum+=B[i]
  i+=1
for i in range(N-1):
  K=A[i]
  if A[i+1]==K+1:
    sum+=C[K-1]
  else:
    sum+=0
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
A_k = list(map(int, input().split()))
B_k = list(map(int, input().split()))
C_k = list(map(int, input().split()))

amount = 0
mae = -1
for A in A_k:
    amount += B_k[A-1]
    if A == mae + 1:
        amount += C_k[A-2]
    mae = A    

print(amount)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = sum(b)

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

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

Submission status: Accepted

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

m=0
# 0で初期化すると最初が1の時にだめ
at=-1
for ai in a:
    m+=b[ai-1]
    if ai == at+1:
        m+=c[at-1]
    at=ai
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()))

m=0
at=-1
for i,ai in enumerate(a):
    m+=b[ai-1]
    if ai == at+1:
        m+=c[at-1]
    at=ai
print(m)

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

prev = -1
ret = 0

for item in a_list:
    de = b_list[item-1]
    if item == prev+1:
        de += c_list[item-2]
    prev = item
    ret += de

print(ret)

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

total = 0
mae = -1

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N = int(input())
    A = input_nums()
    B = input_nums()
    C = input_nums()
    total = 0
    before = -2
    for a in A:
        total += B[a-1]
        if before + 1 == a - 1:
            total += C[a-2]
        before = (a - 1)
    print(total)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
   
s=0
bb=sum(b)
for i in range(n-1):
       if a[i]+1==a[i+1]:
               s+=c[a[i]-1]
s+=bb
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()))
count=0
for i in range(n):
  count+=b[i]
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:
n = int(input())
a, b, c = ([int(i) for i in input().split()] for j in range(3))
pre = a[0]
ans = b[a[0]-1]
for i in range(1, n):
    ans += b[a[i]-1]
    if a[i] == pre+1:
        ans += c[pre-1]
    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()))
M = 0
for i in range(N):
  M += B[A[i] - 1]
  if i < N - 1 and 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()]

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)

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

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
B = lr()
C = lr()
temp = 0
answer = 0
for i in range(N):
    answer += B[A[i] - 1]
    if 0 < i and A[i] - A[i-1] == 1:
        if A[i] - 1 <= N-1:
            answer += C[A[i-1] - 1]

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

sum_c = 0

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

print(sum(b) + sum_c)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

        if A[i] + 1 == A[i+1]:
            ans += C[A[i] - 1]

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    
    ans = sum(b)
    for i in range(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()))

subtotal = sum(b)
bonus = 0

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

total = subtotal + bonus
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()))

manzoku = sum(B)

for x in range(N - 1):
  if A[x] + 1 == A[x + 1]:
    manzoku += C[A[x] - 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()))
D = []
for i in range(N-1):
  if A[i+1] - A[i] == 1:
    D.append(C[A[i]-1])
for j in range(N):
  D.append(B[j])
print(sum(D))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
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()))
cnt = b[a[0] - 1]
for i in range(1, n):
    cnt += b[a[i] - 1]
    if a[i] == a[i - 1] + 1:
        cnt += c[a[i - 1] - 1]
print(cnt)

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    # index begins with 1
    A = [int(x)-1 for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]

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

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

# %%
# from atcoder_test import doTest
# doTest("abc140","b",main)

Submission status: Accepted

Solution code:

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += b[i]

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())
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
Clist=list(map(int,input().split()))

b_sum=sum(Blist)

for i in range(N-1):
    if Alist[i]+1==Alist[i+1]:
        b_sum+=Clist[Alist[i]-1]

print(b_sum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
Ci = list(map(int,input().split())) + [0]

manzoku = 0
im1 = Ai[0]
for i,A in enumerate(Ai):
  manzoku = manzoku + Bi[A-1]
  if A - im1 == 1: manzoku = manzoku + Ci[im1-1]
  im1 = A
print(manzoku)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

if __name__ == '__main__':
    n=int(input())
    a_list=[int(x)-1 for x in input().split()]
    b_list=[int(x) for x in input().split()]
    c_list=[int(x) for x in input().split()]
    score=sum(b_list)
    pre_a=-100
    for a in a_list:
        if(a-pre_a==1):
            score+=c_list[pre_a]
        pre_a=a
    print(score)

Submission status: Accepted

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

ans=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=0
for index, value in enumerate(A):
    ans+=B[value-1]
    if index >= 1:
        if A[index-1] == A[index] - 1:
            ans+=C[value-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()))

s = 0

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

Submission status: Accepted

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

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):
    t = a[i]
    sum += b[t-1]
    if i!=0:
         if a[i]==a[i-1]+1:
             sum += c[a[i-1]-1]
print(sum)

Submission status: Accepted

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

print(sum(b)+ex)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Buffet
https://atcoder.jp/contests/abc140/tasks/abc140_b

"""
import sys


def solve(N, A, B, C):
    ans = 0
    prev = -100
    for a in A[1:]:
        ans += B[a]
        if a == prev + 1:
            ans += C[a-1]
        prev = a
    return ans


def main(args):
    N = int(input())
    A = [-1] + [int(a) for a in input().split()]
    B = [-1] + [int(b) for b in input().split()]
    C = [-1] + [int(c) for c in input().split()]
    ans = solve(N, A, B, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=0
now=-2
for a in A:
    ans+=B[a-1]
    if a==now+1:
        ans+=C[now-1]
    now=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()))
total = 0

for k,i in enumerate(a):
  total += b[i-1]
  if k == n - 1:
    continue
  elif a[k]+1 == a[k+1]:
    total += c[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 = b[a[0]-1]
for i in range(1, n):
    ans += b[a[i]-1]
    if a[i-1] + 1 == a[i]:
        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 = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

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

print(res)

Submission status: Accepted

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

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

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


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

Submission status: Accepted

Solution code:
n = int(input())
orders = list(map(int, input().split()))
suf = list(map(int, input().split()))
ser = list(map(int, input().split()))
ans = 0
flug = -1
for i in orders:
  ans += suf[i-1]
  if flug+1 == i:
    ans += ser[i-2]
  flug = 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]
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)