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())
dishes = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
additional = list(map(int, input().split()))

res = 0

for i in range(N-1):
    res += satisfaction[i]

    if dishes[i] + 1 == dishes[i+1]:
        res += additional[dishes[i] - 1]

print(res + satisfaction[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))

def Input():
    return mapt(int, input().split(" "))

def main():
    n = int(input())
    a = Input()
    b = Input()
    c = Input()
    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)
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()))
m = -1
num = sum(b)
for i in a:
    if i == m+1:
        num += c[m-1]
    m = i
print(num)

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, aa in enumerate(a):
  if i==n-1:
    break
  if a[i]+1==a[i+1]:
    ans+=c[a[i]-1]

print(ans)

Submission status: Accepted

Solution code:
# ABC140
# Buffet
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ct = 0
h = 25
for i in range(n):
    ct += B[i]
    if h + 1 == A[i]:
        ct += C[h - 1]
        h = A[i]
    else:
        h = A[i]
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()))

cnt=0

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

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

satisfy = 0

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

print(satisfy)

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:
n=int(input())
l=list(map(int,input().split()))
d=list(map(int,input().split()))
k=list(map(int,input().split()))
s=sum(d)
for i in range(n-1):
    if(l[i]+1==l[i+1]):
        s+=k[l[i]-1]
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
al = inpl()
bl = inpl()
cl = inpl()
ans = 0
pre = -1
for a in al:
    ans += bl[a - 1]
    if(pre == a - 1):
        ans += cl[pre - 1]
    pre = 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
for i in range(N) :
    Ai = A[i]
    ans += B[Ai-1]
    if i != N-1 and A[i]+1 == A[i+1] :
        ans += C[Ai-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
count = b[a[0]-1]
for i in range(1,n):
    if a[i] - a[i-1] == 1:
        count += b[a[i]-1] + c[a[i-1]-1]
    else:
        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()))
sum=0
for i in range(0,N):
    sum=sum+B[i]
    if i<=N-2 and A[i+1]-A[i]==1:
        sum=sum+C[A[i]-1]
    
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
order = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
addition = list(map(int, input().split()))

index = order[0]
ans = 0

for i in order:
    ans += satisfaction[i-1]
    if i-1 == index:
        ans += addition[i-2]
    index = 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, a in enumerate(A):
    ans += B[a-1]
    if i != 0 and a == A[i-1] +1:
        ans += C[a-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=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 = [ i for i in list(map(int,input().split()))]
b = [j for j in list(map(int,input().split()))]
c = [k for k in list(map(int,input().split()))]
c.append(0)
count  = 0
prev = 0
for o in a:
    count += b[o-1]
    if o == prev +1:
        count +=c[o-2]
        prev = o
    else:
        prev = o
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()))
cnt = sum(b)

for i in range(n-1):
    if a[i+1] - a[i] == 1:
        cnt += c[a[i]-1]
        
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
tmp = N
for a in A:
    ans += B[a-1]
    if tmp+1 == a:
        ans += C[a-2]
    tmp = 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()))

point = 0

prev = -2

for i in range(n):
    food = a[i]-1
    point += b[food]
    if food == prev + 1:
        point += c[prev]
    prev = food

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

Submission status: Accepted

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


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

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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    A=list(mi())
    B=list(mi())
    C=list(mi())

    pre = INF
    ans = 0
    for i in range(N):
        a = A[i]
        b = B[a-1]
        ans += b
        if a == pre + 1:
            ans += C[a-2]
        
        pre = a

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

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

Submission status: Accepted

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

cnt=0
first_flg = True
for i in a:
    if not first_flg:
        if i-1 == before_num:
            cnt += c[i-2]
    first_flg = False
    before_num = i
print(sum(b)+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()))
b=sum(b)

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
c = 0
aa = 0
for a in A:
	ans += B[a - 1]
	if a - 1 == aa:
		ans += c
	aa = a
	c = C[a - 1] if a < N else 0
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
bef = 100

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().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 = [0] + list(map(int,input().split()))
b = [0] + list(map(int,input().split()))
c = [0] + list(map(int,input().split()))
ans = 0
tmp = 0
for i in range(1,n+1):
    ans += b[a[i]]
    if tmp==a[i]-1:
        ans += c[tmp]
    tmp = 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 = 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()))
c.append(0)
get=0
for i in range(n):
    get+=b[a[i]-1]
    if a[i-1]+1==a[i] and i>0:
        get+=c[a[i-1]-1]
print(get)

Submission status: Accepted

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

Submission status: Accepted

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

s = 0

for i in range(n):
    s += b[a[i]-1]
    if i > 0 and a[i-1] + 1 == a[i]:
        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()))+[0]
ans=0
a_p=N+1

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

Submission status: Accepted

Solution code:
N = int(input())
A_ls = map(int, input().split(' '))
B_ls = list(map(int, input().split(' ')))
C_ls = list(map(int, input().split(' ')))

result = 0
tmp = 0
for A in A_ls:
    if (A - tmp) == 1 and tmp != 0:
        result += B_ls[A-1] + C_ls[A-2]
    else:
        result += B_ls[A-1]
    tmp = A
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()))

prev = n + 1
s = 0
for i in range(n):
    s += b[a[i] - 1]
    if a[i] - 1 == prev:
        s += c[prev - 1]
    prev = a[i]
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 >= 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(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))
 
satis = 0
 
for i in range(len(A)):
  satis += B[A[i] - 1]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[A[i - 1] - 1]
 
print(satis)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = [0]+list(map(int, input().split()))
    B = [0]+list(map(int, input().split()))
    C = [0]+list(map(int, input().split()))
    ans = 0
    prev = -1
    for i in range(1, N+1):
        dish = A[i]
        point = B[dish]
        ans += point
        if prev+1==dish:
            ans += C[prev]
        prev = dish
    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[A[i]-1] for i in range(N))
for i in range(N-1):
  if A[i+1]-1==A[i]:
    S += C[A[i]-1]
print(S)

Submission status: Accepted

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

for i, food in enumerate(a[1:]):
    ans += b[food-1]
    if a[i] == food-1:
        ans += c[food-2]

print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI_()
    B = LI()
    C = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
AA = input().split()
BB = input().split()
CC = input().split()
total = 0
for i in range(len(AA)-1):
  if int(AA[i+1]) - int(AA[i]) == 1:
    
    total += int(CC[int(AA[i])-1])
    
for i in BB:
  total += int(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()))

anker=-10
ans=0
for i in range(1,n+1):
    cuisine=a.index(i)
    if cuisine-anker==1:
        ans += c[i-2]
    anker = cuisine
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()))
res = 0
for i in range(N):
    res += B[A[i]-1]
    if A[i] - A[i-1] == 1 and i>=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()))

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

p = a[0]
t = 0
for i in range(n):
    j = a[i]
    if a[i] == p + 1:
        t = t + b[j-1] + c[j-2]
    else:
        t += b[j-1]
    p = a[i]

print(t)

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

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

print(man + sum(b))

Submission status: Accepted

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

happy = sum(B)

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

print(happy)

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(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()))

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

temp = 9999
ans = 0
for i in a:
  ans += b[i-1]
  if i - temp == 1:
    ans += c[i-2]
  temp = 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
con=10000000
for i in a:
    ans+=b[i-1]
    if con+1==i :
        ans+=c[con-1]
    con=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 and a[i+1]-a[i] == 1:
        ans += c[a[i]-1]

print(ans)

Submission status: Accepted

Solution code:
import math

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

resolve()

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

main()

Submission status: Accepted

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

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

tmp = A[0]
for a in A[1:]:
    if a == tmp+1:
        ans += C[a-2]
    tmp = a

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = 0

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

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

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

ans = 0
prev = -10
for a in A:
    ans += B[a]
    if a == prev + 1:
        ans += C[prev]
    prev = a
print(ans)

Submission status: Accepted

Solution code:
N = int(input().rstrip())
A = list(map(int,input().rstrip().split()))
B = list(map(int,input().rstrip().split()))
C = list(map(int,input().rstrip().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 heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	# n = map(int,input().split())
	n = int(input())
	a = list(map(int,input().strip().split()))[0:n]
	b = list(map(int,input().strip().split()))[0:n]
	c = list(map(int,input().strip().split()))[0:n-1]
	ans = 0
	for i in range(n):
		ans += b[i]
	for i in range(n-1):
		x = a[i]
		y = a[i+1]
		if(y == x+1):
			ans += c[x-1]
	print(ans)
	# print(n*n*n)
	# m = 1000
	# i = 0
	# while i < n:
	# 	j = i
	# 	while j+1 < n and v[j+1] >= v[j]:
	# 		j += 1
	# 	x = m//v[i]
	# 	m = m%v[i]
	# 	temp = x*v[j]
	# 	m += temp
	# 	i = j+1
	# print(m)

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

satisfy = 0
for i in range(n):
    satisfy += bn[an[i] - 1]

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

print(satisfy)

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

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

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

Submission status: Accepted

Solution code:
# abc140_b.py
# https://atcoder.jp/contests/abc140/tasks/abc140_b

# B - Buffet /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 高橋くんは N種類の料理が食べ放題のビュッフェに行き、全種類の料理 (料理 1, 料理 2, …, 料理 N) を 1度ずつ食べました。
# 高橋くんが i(1≤i≤N) 番目に食べた料理は料理 Aiでした。
# 高橋くんは、料理 i(1≤i≤N) を食べると満足度 Biを得ます。
# また、料理 i(1≤i≤N−1) を食べた直後に料理 i+1 を食べると満足度 Ciを追加で得ます。
# 高橋くんが得た満足度の合計を求めてください。

# 制約
#     入力は全て整数である。
#     2≤N≤20
#     1≤Ai≤N
#     A1,A2,...,AN
#     は全て異なる。
#     1≤Bi≤50
#     1≤Ci≤50

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# A1 A2 ... AN
# B1 B2 ... BN
# C1 C2 ... CN−1

# 出力
# 高橋くんが得た満足度の合計を整数で出力せよ。

# 入力例 1
# 3
# 3 1 2
# 2 5 4
# 3 6

# 出力例 1
# 14

# 以下のように高橋くんは合計 14の満足度を得ました。
#     高橋くんはまず料理 3を食べ、満足度 4を得ました。
#     高橋くんは次に料理 1を食べ、満足度 2を得ました。
#     高橋くんは最後に料理 2を食べ、満足度 5+3=8を得ました。

# 入力例 2
# 4
# 2 3 4 1
# 13 5 8 24
# 45 9 15

# 出力例 2
# 74

# 入力例 3
# 2
# 1 2
# 50 50
# 50

# 出力例 3
# 150


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values_a = list(map(int, lines[1].split()))
    values_b = list(map(int, lines[2].split()))
    values_c = list(map(int, lines[3].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    # 最初の分を計算しておく
    current = values_a[0]-1
    result = values_b[current]
    prev = current

    for n in range(1, N):
        current = values_a[n]-1
        result += values_b[current]
        log(f'n=[{n}], current=[{current}], prev=[{prev}]')
        if current == prev+1:
            result += values_c[prev]
        prev = current

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '3 1 2', '2 5 4', '3 6']
        lines_export = [14]
    if pattern == 2:
        lines_input = ['4', '2 3 4 1', '13 5 8 24', '45 9 15']
        lines_export = [74]
    if pattern == 3:
        lines_input = ['2', '1 2', '50 50', '50']
        lines_export = [150]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(4)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()