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:
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    B = InputToInt()
    C = InputToInt()

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

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

print(ans)

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

cnt = 0
temp = -1

for x in a_list:
    cnt += b_list[x-1]
    if temp == x -1:
        cnt += c_list[temp-1]
    temp = x
    
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()))

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
m = B[A[0]-1]
for i, j in zip(A, A[1:]):
    m += B[j-1]
    m += C[i-1] if j-i==1 else 0
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()))
res=sum(B)
for i in range(1, N):
  if A[i]==A[i-1]+1:
    res+=C[A[i-1]-1]
print(res)

Submission status: Accepted

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

prev_a = 0
satisfaction = sum(B)
for a in A:
    if prev_a + 1 == a and prev_a > 0:
        satisfaction += C[prev_a-1]
    prev_a = a

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

ct=0
at=-100
for a in A:
    ct+=B[a-1]
    if a==at+1:
        ct+=C[a-2]
    at=a

print(ct)

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(sum(b)+ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(s)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ans = 0
pre = None
for a in A:
    ans += B[a-1]
    if pre == a-1:
        ans += C[a-2]
    pre = a
print(ans)

Submission status: Accepted

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

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    ans = 0
    tmp = -1
    for a in A:
        ans += B[a-1]
        if tmp + 1 == a:
            ans += C[a-2]
        tmp = a

    print(ans)
if __name__ == '__main__':
    main()

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()))
    s = 0
    before = 0
    for ai in a:
        s += b[ai - 1]
        if ai == before + 1 and before > 0:
            s += c[before - 1]
        before = ai
    print(s)


if __name__ == "__main__":
    resolve()

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:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split(" ")])
b = [int(i) for i in input().split(" ")]
c = np.array([int(i) for i in input().split(" ")])

ans = sum(b)
diff = np.diff(a)
mask = diff == 1
mask2 = a[mask]-1
ans += np.sum(c[mask2])
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    n=int(input())
    A=list(map(lambda x:int(x)-1,input().split()))
    ans=sum(map(int,input().split()))
    C=list(map(int,input().split()))

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

    print(ans)
resolve()

Submission status: Accepted

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

ans = 0
for i,a in enumerate(As):

    ans += Bs[a-1]

    if i != 0:
        if a - 1 == As[i-1]:
            ans +=Cs[a - 2]



print(ans)

Submission status: Accepted

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

ans = sum(B)

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

print(ans)

Submission status: Accepted

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

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

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

total = 0
prev = None
for A in As:
  total = total + Bs[A-1]
  if prev and prev + 1 == A:
    total = total + Cs[prev-1]
  prev = A

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

count = 0
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 solve():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] + list(map(int, input().split()))
    C = [0] + list(map(int, input().split()))
    last = -1
    ans = 0
    for i in A:
        ans += B[i]
        if last + 1 == i:
            ans += C[last]
        last = i
    print(ans)
solve()

Submission status: Accepted

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

res=b[a[0]-1]
last=a[0]
for i in range(1,n):
	if last+1==a[i]:
		res+=b[a[i]-1]+c[a[i]-2]
	else:
		res+=b[a[i]-1]
	last=a[i]
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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
before_A = -1
for A in A_list:
    ans += B_list[A - 1]
    if A - before_A == 1:
        ans += C_list[before_A - 1]
    before_A = A
print(ans)

Submission status: Accepted

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

ans = 0
for i, Ai in enumerate(A):
    Bi = B[Ai - 1]
    ans += Bi
    if i == 0: continue
    #
    if A[i - 1] + 1 == Ai:
        ans += C[A[i - 1] - 1]

print(ans)

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

    lastIdx = -1
    sc = 0

    for a in A:
        sc += B[a-1]
        if a == lastIdx + 1:
            sc += C[lastIdx-1]

        lastIdx = a

    print(sc)


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

Submission status: Accepted

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

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):
    now = a[i]
    if a[i+1] == now +1:
        ans += c[now-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()))

result = 0
pre = -2

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

res = 0
cur = A[0]
for a in range(N-1):
    if A[a+1] == cur + 1:
        res += C[A[a+1]-2]
    cur = A[a+1]
res += sum(B)
print(res)

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

ans = 0
last_eat = -1
for a in A:
    ans += B[a - 1]
    if a == last_eat + 1:
        ans += C[last_eat - 1]
    last_eat = a

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
ans=0
check=1000
for i in range(n):
    j=a[i]
    ans+=b[j-1]
    if check+1 == j:
        ans+=c[check-1]
    
    check=j
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
tmp = -10
for ai in a:
    ans += b[ai-1]
    if tmp+1 == ai:
        ans += c[tmp-1]
    tmp = ai
    # print(ans)
print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
	return sys.stdin.readline().strip()


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

print(total)

Submission status: Accepted

Solution code:
N=int(input())

A=[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()))

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())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))

preva=-1
ans=0

for a in alist:
    idx=a-1
    ans+=blist[idx]
    if a==preva+1:
        ans+=clist[preva-1]
    preva=a

print(ans)

Submission status: Accepted

Solution code:
import sys
import collections
sys.setrecursionlimit(4100000)

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(1,len(a)):
    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()))

r = sum([b[x-1] for x in a])
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        r += c[a[i]-1]
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:
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])
    B = input([int, N])
    C = input([int, N - 1])

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

    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    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()))

d = 0 # 直前に食べた料理
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())
lsA=[int(s) for s in input().split()]
lsB=[int(s) for s in input().split()]
lsC=[int(s) for s in input().split()]
sum=lsB[lsA[0]-1]
for i in range(1,N):
  a=lsA[i]
  if lsA[i-1]+1==a:
    sum+=lsB[a-1]+lsC[a-2]
  else:
    sum+=lsB[a-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()))
r = sum(b)
for i in range(n - 1):
    if a[i + 1] == a[i] + 1:
        r += c[a[i] - 1]
print(r)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

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

main()

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = [0] + LIST()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
#S = list(input())

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

ans=0
remind_i = N+100

for i in A:
    ans+=B[i-1]
    if i-remind_i==1:
        ans+=C[remind_i-1]
    remind_i = i





print(str(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
*an, = map(int,input().split())
*bn, = map(int,input().split())
*cn, = map(int,input().split())
befi = -1
ans = sum(bn)
for i in an:
  if i - befi == 1:
    ans += cn[befi-1]
  befi = 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()))

result = 0
prev = -1
for i in A:
  result += B[i-1]
  if prev == i-1 and i -2 >= 0:
    result += C[i-2]
  prev = i
  
print(result)

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


lastEatIdx = -999
ans = 0
for eatIdx in A:
    ans += B[eatIdx]
    if eatIdx == lastEatIdx + 1:
        ans += C[lastEatIdx]
    lastEatIdx = eatIdx

print(ans)

Submission status: Accepted

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

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

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

for i, k in enumerate(A):
  res += B[k-1]
  if A[i-1] == k-1 and i != 0:
    res += C[k-2]
    
print(res)

Submission status: Accepted

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

    prevIdx = -1
    value = 0
    for i in A:
        value += B[i]
        if prevIdx != -1 and prevIdx + 1 == i:
            value += C[i-1]
        
        prevIdx = i

    print(value)

if __name__ == '__main__':
    func()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    A = lmi()
    B = lmi()
    C = lmi()
    ans = 0
    for i in range(N - 1):
        if A[i] + 1 == A[i + 1]:
            ans += C[A[i] - 1]
    ans += sum(B)
    print(ans)
    return


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()))
tmp = float("inf")
ans = 0
for i in a:
    ans += b[i - 1]
    if tmp == i - 1:
        ans += c[tmp - 1]
    tmp = i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(a) for a in input().split()] + [10000]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
ans = 0
for i,j in enumerate(A[:len(A)-1]):
    ans += B[i]
    if A[i+1] == j+1:
        ans += C[j-1]
        
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_list , b_list, c_list = [ int(v)-1 for v in input().split() ], [ int(v) for v in input().split() ], [ int(v) for v in input().split() ]
before = None
total = 0
for i in range(n):
    total += b_list[a_list[i]]
    if i > 0 and a_list[i-1] + 1 == a_list[i]:
        total += c_list[a_list[i-1]]
    before = 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()))

manzoku = 0

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

print(manzoku)

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

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

print(output)

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
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls = [int(i) for i in sys.stdin.readline().split()]
cnt = 0
for i in range(n-1):
    if a_ls[i+1] - a_ls[i] == 1:
        cnt += c_ls[a_ls[i]-1]
cnt += sum(b_ls)
print(cnt)

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

count = 0
for n in range(N):
    count += B[A[n] - 1]
    if n != N - 1:
        if A[n + 1] - 1 == A[n]:
            count += C[A[n] - 1]
print(count)

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

res = sum(lb)
for a0, a1 in zip(la, la[1:]):
    if a1 == a0 + 1:
        res += lc[a0 - 1]
print(res)

Submission status: Accepted

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

out=sum(B)

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

print(out)

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):
    A = a[i]-1
    ans += b[A]
    if i > 0:
        if a[i] == a[i-1]+1:
            ans += c[A-1]

print(ans)

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

a_list = [a-1 for a in a_list]

sat = 0
sat += sum(b_list)
# print(sat)
for i in range(len(a_list)-1):
    if a_list[i+1] - a_list[i] == 1:
#         print(i)
#         print(c_list[i])
        sat += c_list[a_list[i]]
        
print(sat)