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

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().split()]
c=[int(x) for x in input().rstrip().split()]

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

res = 0
for i, a in enumerate(A):
  res += B[a-1]
  if i != N-1:
    if A[i+1] == a + 1:
      res += C[a-1]

print(res)

Submission status: Accepted

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

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

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

now = 0
next = 0
ans = 0

for i in range(N):#ループ１ 0 ~ 2
    now = a[i]
    ans = ans + b[a[i]-1]
    
    if(i  < N-1):

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_ = input()
a = [int(e) for e in input().split(" ")]
b = [int(e) for e in input().split(" ")]
c = [int(e) for e in input().split(" ")]
res = 0
for i,j in enumerate(a):
  res += b[j-1]
  if i != 0 and j - a[i-1] == 1:
    res += c[j-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()))

A = [a - 1 for a in A]

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)

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 = list(map(lambda x:x-1, a))
ans = 0
for i in range(n):
  ans += b[a[i]]
  if i > 0 and a[i-1] + 1 == a[i]:
    ans += c[a[i-1]]
print(ans)

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

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
b=lnii()
c=lnii()

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 = [ int(x) for x in input().split() ]
b = [ int(x) for x in input().split() ]
c = [ int(x) for x in input().split() ]

k = 0
i = -1

for e in a:
    k += b[e - 1]
    if i == e-1:
        k += c[i - 1]

    i = e

print(k)

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
Bs = list(mapint())
Cs = list(mapint())
ans = 0

before = -2
for a in As:
    a -= 1
    ans += Bs[a]
    if a==before+1:
        ans += Cs[before]
    before = a
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())
Order = list(map(int, input().split()))
Happiness = list(map(int, input().split()))
Bonus = list(map(int, input().split()))
res = 0
mae = -1
for i in Order:
  res += Happiness[i-1]
  if mae == -1:
    pass
  elif mae == i-1:
    res += Bonus[i-2]
  mae = i
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()))

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

print(SUM)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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()))
acc = 0
for j in range(N - 1):
    i = aaa[j] - 1
    acc += bbb[i]
    if aaa[j] + 1 == aaa[j + 1]:
        acc += ccc[i]
else:
    acc += bbb[aaa[-1] - 1]
print(acc)

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
j = 25
for i in a:
    x += b[i-1]
    if i - j == 1:
        x += c[j-1]
    j = i
print(x)

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

for i in range(len(a)):
  content += b[a[i]-1]
  if i>=1:
    if a[i] == a[i-1] +1:
      content += c[a[i-1]-1]
print(content)

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

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

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

    print(m)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    input = sys.stdin.readline
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

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

    sat = 0
    prev = None
    for i in range(N):
        A = As[i]
        sat += Bs[A-1]
        if prev is not None and prev + 1 == A:
            sat += Cs[prev - 1]
        prev = A

    print(sat)





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main() -> None:
    N = int(input())
    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 = sum(B[a] for a in A)
    for a1, a2 in zip(A, A[1:]):
        if a1 + 1 == a2:
            ans += C[a1]
    print(ans)


if __name__ == '__main__':
    main()

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

con = 0

for i in range(n-1):
    if la[i+1]==la[i]+1:
        con += lc[la[i]-1]

print(sum(lb)+con)

Submission status: Accepted

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

cnt=0
before=0

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

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
array_a = list(map(int,input().split()))
array_b = list(map(int,input().split()))
array_c = list(map(int,input().split()))

if not ( 2 <= N <= 20 ):sys.exit()
if not ( 1 <= min(array_a) and max(array_a) <= N ): sys.exit()
if not ( 1 <= min(array_b) and max(array_b) <= 50 ): sys.exit()
if not ( 1 <= min(array_c) and max(array_c) <= 50 ): sys.exit()

confortable = 0
before = -1
for I in range(len(array_a)):
    pos = array_a[I]
    confortable += array_b[pos-1]
    if before + 1 == array_a[I]:
        confortable += array_c[before-1]
    before = array_a[I]
print(confortable)

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(len(a)):
  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:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
C = list(map(int,readline().split()))

ans = sum(B)
for i in range(N-1):
    for j in range(1,N):
        if A[i] == j and A[i+1] == j+1:
            ans += C[j-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)
memo = 20
for i in A:
    if memo+1 == i:
        total += C[i-2]
    memo = 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()))
sat = b[a[0]-1]
for i in range(1,len(a)):
    sat += b[a[i]-1]
    
    if a[i] - a[i-1] == 1:
        sat += c[a[i-1]-1]
        
print(sat)

Submission status: Accepted

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

sum = sum(b_list)

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

bef=a[0]-1
man=b[bef]

for i in a[1:]:
  ind=i-1
  if ind==bef+1:
    man+=c[bef]
  man+=b[ind]
  bef=ind
print(man)

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-2:
    if a[i] == a[i+1] - 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) % n] == 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()))
x = 0

for i in range(n):
    if a[i] != n:
        x += b[a[i] - 1]
        if i != n -1:
            if a[i + 1] == a[i] + 1:
                x += c[a[i] - 1]
        
    else:
        x += b[a[i] - 1]


print(x)

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 = B[A[0]-1]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

m=0
y=-1
for x in A:
    m+=B[x-1]
    if x==y+1:
        m+=C[y-1]
    y=x
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0

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

for j in range(1,N):
    if A[j]==A[j-1]+1:
        ans+=C[A[j]-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 = sum(b)

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

print(ans)

Submission status: Accepted

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

ans = 0
last = A[0]
ans += B[last]
#print(ans)
for a in A[1:]:
  if last + 1 == a:
    ans += C[last]
  ans += B[a]
  last = a
  #print(ans,a,B[a],C[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, a in enumerate(A[1:]):
    bef_a = A[i]
    ans += B[a - 1]
    if a - bef_a == 1:
        ans += C[bef_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()))

sat = 0

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

print(sat)

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

if '__main__' == __name__:
    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()))

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 = [0] + list(map(int, input().split()))
b_list = [0] + list(map(int, input().split()))
c_list = [0] + list(map(int, input().split()))

sum = 0

for i in range(1, n+1):
    sum += b_list[a_list[i]]
    if i >= 2:
        if a_list[i] == a_list[i-1] + 1:
            sum += c_list[a_list[i-1]]
    #print(sum)


print(sum)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [i-1 for i in map(int, input().split())]
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    ans = 0
    for idx, a in enumerate(A):
        ans += B[a]
        if idx != 0 and A[idx-1] + 1 == A[idx]:
            ans += C[A[idx-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()))

sat = 0
ai_prev = None
for ai in a:
    sat += b[ai - 1]
    if ai_prev == ai - 1:
        sat += c[ai_prev - 1]
    ai_prev = ai
print(sat)

Submission status: Accepted

Solution code:
n = int(input())
an = [int(num) for num in input().split()]
bn = [int(num) for num in input().split()]
cn = [int(num) for num in input().split()]

sum = 0
for a in an:
  sum += bn[a-1]

add = []
for i in range(n-1):
  if an[i]+1 == an[i+1] :
    add.append(an[i])

for j in add:
  sum += cn[j-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()))
ful=0
for i in range(n):
  tempa=A[i]-1
  ful+=B[tempa]
  if A[i]-A[i-1]==1 and i>0:
    tempb=A[i-1]-1
    ful+=C[tempb]
print(ful)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
# mapはcallable, iterator
# input().split()でリストを作成する
a = [int(i) for i in input().split()]
iSSequence = [False] * (len(a) - 1)

# a[i]のあとにa[i+1]を食べたならフラグを立てる
for i in range(len(a) - 1):
    if(a[i] + 1 == a[i + 1]):
        iSSequence[a[i] - 1] = True

sum = 0
# bは必ずすべて足される
for b in input().split():
    sum += int(b)

index = 0
for c in input().split():
    if(iSSequence[index]):
        sum += int(c)
    index += 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 = sum(b)
for i in range(len(c)):
    try:
        if a[a.index(i+1)+1] == i+2:
            ans += c[i]
    except IndexError:
        pass
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):
  s+=b[a[i]-1]
  if a[i-1]==a[i]-1:
    s+=c[a[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()))
ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i == n - 1:
        break
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i] - 1]

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin,stdout

if __name__=="__main__":

    n=int(stdin.readline());

    a=[int(x) for x in stdin.readline().split()]
    b=[int(x) for x in stdin.readline().split()]
    c=[int(x) for x in stdin.readline().split()]

    sm=sum(b)

    for i in range(1,n):
        if a[i]-1==a[i-1]:
            sm+=c[a[i-1]-1]
    stdout.write(str(sm)+"\n")

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


 
b_sum = sum(b) 


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

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(0,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()))+[0]
ans=0
bn,ba=0,0
for i in a:
    ans+=b[i-1]
    if bn+1==i:
        ans+=ba
    bn=i
    ba=c[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()))
r = 0
p = N
for a in A:
  r += B[a - 1]
  if p == a - 1:
    r += C[p - 1]
  p = a
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 = 0
# Bの足し算
ans += sum(b)

# Cの足し算
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()))
t = 0
t += b[a[0]-1]
for i in range(1,n):
    t += b[a[i]-1]
    if a[i] - a[i-1] == 1:
        t += c[a[i-1]-1]
print(t)

Submission status: Accepted

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

import io
import sys
import math

def solve(n, a_lst,b_lst,c_lst):
    # implement process
    pre_a = -float('inf')
    satisfaction = 0
    for a in a_lst:
        a -= 1
        satisfaction += b_lst[a]
        if pre_a +1 == a:
            satisfaction += c_lst[a-1]
        pre_a = a
    
    return satisfaction
    
def main():
    # input
    n = int(input())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    c_lst = list(map(int, input().split()))

    # process
    ans = str( solve(n, a_lst,b_lst,c_lst ) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
2
1 2
50 50
50
"""
_EXPECTED = """\
150
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

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 = 0
for i in A:
    ans += B[i - 1]

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

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

ans = 0
for i in A:
    ans += B[i - 1]

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())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
cc=list(map(int,input().split()))

ans=0
for i in range(n):
  ans+=bb[aa[i]-1]
  if i>0 and (aa[i]-1)==aa[i-1]:
    ans+=cc[aa[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()))
satisfaction = 0
last_dish = 10000

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

print(satisfaction)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.buffer.readline
from math import*

n=int(input())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))
crr=list(map(int,input().split()))

ans=0
for i in range(n):
	if i!=0 and arr[i]==arr[i-1]+1:
			ans+=brr[arr[i]-1]+crr[arr[i-1]-1]
	else:
		ans+=brr[arr[i]-1]
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)


# map(int, sys.stdin.read().split())


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    be = 100
    ans = 0
    for i in A:
        ans += B[i - 1]
        if be == i - 1:
            ans += C[i - 2]
        be = i

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

Submission status: Accepted

Solution code:
N = int(input())
buffet = [int(i) for i in input().split()]
satisfaction_level_B = [int(i) for i in input().split()]
satisfaction_level_C = [int(i) for i in input().split()]
result = 0

for i in range(N):
    result += satisfaction_level_B[buffet[i] - 1]
    if i > 0:
        if buffet[i] - buffet[i - 1] == 1:
            result += satisfaction_level_C[buffet[i - 1] - 1]
print(result)

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

i=0
man=0
oldA=1
for A in a:
  #print(A)
  B = b[int(A)-1]
  #print(B)
  man = man + int(B)
  if i>0:
    if oldA+1==A:
      C = int(c[oldA-1])
      man = man + C
      #print(C)
  i=i+1
  oldA=A
print(man)

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

Submission status: Accepted

Solution code:
N = int(input())
A_int_list = list(map(int, input().split()))
B_int_list = list(map(int, input().split()))
C_int_list = list(map(int, input().split()))

ans = 0

for i in range(N):
    ans += B_int_list[A_int_list[i] - 1]
    if i != N - 1 and A_int_list[i] + 1 == A_int_list[i + 1]:
        ans += C_int_list[A_int_list[i] - 1]

print(ans)