Problem:


Score : 200 points

Problem Statement

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

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

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

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

Find the sum of the satisfaction points he gained.

Constraints

All values in input are integers.

2 \leq N \leq 20

1 \leq A_i \leq N

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

1 \leq B_i \leq 50

1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3
3 1 2
2 5 4
3 6

Sample Output 1

14

Takahashi gained 14 satisfaction points in total, as follows:

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

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

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

Sample Input 2

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

Sample Output 2

74

Sample Input 3

2
1 2
50 50
50

Sample Output 3

150



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


Sample output:
14

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ 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:
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ 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:
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[i]
    if i == n-1:
        continue
    else:
        if A[i]+1 == A[i+1]:
            sum += C[A[i]-1]
print(sum)

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

print(res)

Submission status: Accepted

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


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    last = -999
    satis = 0
    for now in A:
        if now-1 == last:
            satis += C[last-1]
        satis += B[now-1]
        last = now
    print(satis)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

food_cnt = int(input())
food_odr = list(map(int, input().strip().split()))
food_man = list(map(int, input().strip().split()))
food_pls = list(map(int, input().strip().split()))


man_sum = 0
man_sum += food_man[0]
for i in range(1,food_cnt):
    man_sum += food_man[i]
    if (food_odr[i-1] + 1) == food_odr[i]:
        man_sum += food_pls[food_odr[i-1]-1]

print(man_sum)

Submission status: Accepted

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
c = sum(int(i) for i in input().split())
C = [int(i) for i in input().split()]
for i in range(len(L)-1):
  if L[i]+1 == L[i+1]:
    c += C[L[i]-1]
print(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()))

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
B = []
C = []
sat = 0#合計満足度
for x in input().split():
    A.append(int(x))
for x in input().split():
    B.append(int(x))
    sat += int(x)
for x in input().split():
    C.append(int(x))

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

print(sat)

Submission status: Accepted

Solution code:
N = int(input())

satis = 0

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

next = -1

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

print(satis)

Submission status: Accepted

Solution code:
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

n = ip()
a = iprow()
b = iprow()
c = iprow()
s = sum(b)
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())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
m = 0
count = 0
for i in range(N):
    eat_num = As[count]
    if count != 0:
        before = As[count-1]
        if before + 1 == eat_num:
            m = m + Cs[before-1]
    m = m + Bs[eat_num-1]
    count += 1
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()))
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:
#input
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sat = 0
old_i = -2
for a in A:
    i = a - 1
    sat += B[i]
    if old_i + 1 == i:
        sat += C[old_i]
    old_i = i

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

    if last == a[i]-1:
        ans += c[a[i]-2]
        
    last = a[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    point += B[A[i]-1]
    if i>0 and A[i]-1 == A[i-1]:
        point += C[A[i-1]-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
b = -1
for a in A:
    if b+1==a:ans+=C[b-1]
    b = a
    ans+=B[b-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=123
ans=0
for i in range(n):
  ans+=b[a[i]-1]
  if x+1==a[i]:
    ans+=c[x-1]
  x=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()))
pnt = 0
for i in range(len(A)):
  pnt += B[A[i]-1]
  if i>0 and A[i]-A[i-1]==1:
    pnt += C[A[i]-2]
print(pnt)

Submission status: Accepted

Solution code:
N = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

old_index = False
s = 0
for a in al:
  s += bl[a-1]
  if old_index is not False and old_index + 1 == a:
    s += cl[a-2]
  old_index = a
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

before = None
for a in A:
    ans += B[a-1]
    if before is not None:
        if a - before == 1:
            ans += C[a-2]
    before = a

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=input()
A=a.split()
b=input()
B=b.split()
c=input()
C=c.split()
ans=0
for i in range(n):
    ans=ans+int(B[int(A[i])-1])
for j in range(n-1):
    if int(A[j+1])==int(A[j])+1:
        ans=ans+int(C[int(A[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()))
u = sum(b)
for i in range(1,n):
    if a[i] - a[i-1] == 1:
        u = u + c[a[i]-2]
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()))

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

Submission status: Accepted

Solution code:
N = int(raw_input())
A = map(int,raw_input().split())
B = map(int,raw_input().split())
C = map(int,raw_input().split())
ans = 0

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

count = 0
for idx, a in enumerate(A):
	food = a - 1
	count += B[food]
	if(idx < len(A) - 1 and A[idx] + 1 == A[idx+1]):
		count += C[food]
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
cuisine = list(map(int, input().split()))
satis = list(map(int, input().split()))
bonus = list(map(int, input().split()))

sum = 0;

for i in range(N):
    sum += satis[i]
    num = cuisine[i]
    try:
        if(cuisine[i+1]==num+1):
            sum+=bonus[num-1]
    except:
        pass

print(sum)

Submission status: Accepted

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

Answer=sum(B)

for i in range(0,N):
    if i!=(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()))

ans = 0
prv = -1

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

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

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
a = []
b = []
c = []
for i in input().split():
    a.append(int(i)-1)
for i in input().split():
    b.append(int(i))
for i in input().split():
    c.append(int(i))
    
ans = 0
for i in range(len(a)):
    ans += b[a[i]]
    if i < len(a)-1 and 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()))
e=0
d = sum(b)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        e += c[a[i]-1]
    else:
        e += 0
print(e + d)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc140/tasks/abc140_b
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
satisfaction = 0
i0 = -2
for i in a:
    if i - i0 == 1:
        satisfaction += c[i - 2]
    satisfaction += b[i-1]
    i0 = i
print(satisfaction)

Submission status: Accepted

Solution code:
"""
3
3 1 2
2 5 4
3 6

ans 14
"""


def main():
    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()]

    total_eat_point = 0
    for round_num in range(N):
        total_eat_point += B[A[round_num]]
        if round_num == 0:
            continue
        if A[round_num] - 1 == A[round_num-1]:
            total_eat_point += C[A[round_num-1]]

    print(total_eat_point)


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

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


B_sum = sum(B)
ex = 0

for n in range(N-1):
    if A[n] == A[n+1]-1:
        ex += C[A[n]-1]
    else:
        pass
ans = B_sum + ex

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
eat = list(map(int, input().split(" ")))
satisfication = list(map(int, input().split(" ")))
add_satisfication = list(map(int, input().split(" ")))

total = 0
previous_eat = ""
for i in eat:
  total = total + satisfication[i-1]
  if previous_eat == i-1:
    total = total + add_satisfication[previous_eat-1]
  previous_eat = 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()))
D = B[N-1]
for i in range(N-1):
    D += B[i]
    if A[i] + 1 == A[i+1]:
        D += C[A[i]-1]
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()))
suf = 0
for i in range (n):
  suf += b[i]
  if i >= 1 and a[i - 1]  + 1 == a[i]:
    suf += c[a[i - 1] - 1]
print(suf)

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

Submission status: Accepted

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

m = -10
s = 0
for d in A:
    s+=B[d-1]
    if d == m + 1:
        s+=C[m-1]
    m = d
print(s)

Submission status: Accepted

Solution code:
n = int(input())
eat_lst = list(map(int,input().split()))
manzoku_lst = list(map(int,input().split()))
tuika_lst = list(map(int,input().split()))

res = sum(manzoku_lst)
#eat_lstの並びを確認し、iの次にi+1を食べていたらtuika_lstの値を加算

for i in range(n-1):
    if eat_lst[i] + 1 == eat_lst[i+1]:
        res = tuika_lst[eat_lst[i]-1] + res
print(res)

Submission status: Accepted

Solution code:
N=int(input())
A=map(int,input().split())
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ANS=0
BC=-99
for a in A:
  if BC == a - 1:
    ANS += C[a-2]
  BC = a
  ANS += B[a - 1]
  #print(ANS, a-1, B[a-1])
#print('----')
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:
N=int(input())
A=[int(x)-1 for x in input().split()]
B={A[i]:int(x) for i,x in enumerate(input().split())}
C=[int(x) for x in input().split()]
score=B[A[0]]
for i in range(1,N):
    score+=B[A[i]]
    score+=C[A[i-1]] if A[i-1]+1==A[i] else 0
print(score)

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_order = -100
for n in A:
  res += B[n-1]
  if n-1 == last_order+1:
    res += C[n-2]
  last_order = n-1
print(res)

Submission status: Accepted

Solution code:
N = int(input())
A_l = [x-1 for x in list(map(int, input().split()))]
B_l = list(map(int, input().split()))
C_l = list(map(int, input().split()))

ans = 0

for idx in range(len(A_l)):
    ans += B_l[A_l[idx]]
    if idx >= 1:
        if A_l[idx] - A_l[idx-1] == 1:
            ans += C_l[A_l[idx-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

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

sat = 0
for a,b in zip(A,A[1:]):
  if b == a+1:
    sat += C[a-1]
    
print( sum(B) + sat )

Submission status: Accepted

Solution code:
# i番目に食べた料理はAi
# 料理iを食べると満足度Biを得る
# 料理iを食べた直後に料理(i+1)を食べると追加で満足度Ciを得る

N = int(input())
A = list(map(int, input().split()))  # A1~AN
B = list(map(int, input().split()))  # B1~BN
C = list(map(int, input().split()))  # C1~C(N-1)

satisf = sum(B)

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

print(satisf)

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:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    ans = 0
    old = -1
    for i, val in enumerate(A):
        if old != -1 and old+1 == val:
            ans += C[old-1]
        ans += B[val-1]
        old = val
            
    print(ans)
    
if __name__ == "__main__":
	main()

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 = 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=list(map(int,input().split()))
g=sum(map(int,input().split()))
c=list(map(int,input().split()))
for i,j in zip(a,a[1:]):
  if j-i==1:
    g+=c[i-1]
print(g)

Submission status: Accepted

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

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

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(N-1):
    if A[i]+1 == A[i+1]:
        res += C[A[i]-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=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 = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
res = 0
pre = -1
for i in A:
    res += B[i-1]
    if i - pre == 1:
        res += C[pre-1]
    
    pre = 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()))

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

satisfaction=0

for i in range(N):
  satisfaction+=B[A[i]-1]
    
  if  i<=N-2:
      if  A[i]+1==A[i+1]:
          satisfaction+=C[A[i]-1] 
  else:
      pass

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

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

print(manzokudo)

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_s = sum(b)
add_s = sum(c[i1-1] for i1, i2 in zip(a, a[1:]) if i1 + 1 == i2)
print(sum_s + add_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
j = -1
for i in a:
    ans += b[i-1]
    if i == j+1:
        ans += c[j-1]
    j = i
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()))

bonus = []
for i in range(N-1):
    if Ai[i + 1] - Ai[i] == 1:
        bonus.append(Ci[Ai[i]-1])

print(sum(Bi) + sum(bonus))

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

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:
#!/usr/bin/env python3
import sys
import math
import numpy as np
# from functools import lru_cache

args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False

#### input
# a, b, c, d = 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()))
# a = list(map(lambda x: int(x)*(-1), a))  # 各要素を-1倍


# n = int(input())
# t = [int(input()) for i in range(n)]
if em: sys.stdin = open('/dev/tty')

#### functions
# @lru_cache(maxsize=10000)

#### process
# if em: embed()
score = 0
tmp_A = -2
for A in As:
  score = score + Bs[A - 1]
  if A == tmp_A + 1:
    score = score + Cs[tmp_A - 1]
  tmp_A = A

print(score)
## heapsort, O(logN)
# import heapq
# heapq.heapify(A)
# min = heapq.heappop(A)
# heapq.heappush(A, new_element)

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

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

score = 0

for val in b_list :
	score +=val
	
for val in range(n-1):
	if a_list[val+1] - a_list[val] == 1:
		score += c_list[a_list[val]-1]
	else:
		pass

print(score)

Submission status: Accepted

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

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


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

ans = 0
pre = -1

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

def buffet(N,x,y,z):
  a = sum(y)
  for i in range(N-1):
    if x[i+1] - x[i] == 1:
      a = a + z[x[i]-1]
  print(a)

if __name__ == '__main__':
  buffet(N,A,B,C)

Submission status: Accepted

Solution code:
C = [0]
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 = sum(B)

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

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

ans = sum(blist)
for i in range(n-1):
    if alist[i + 1] - alist[i] == 1:
        ans += clist[alist[i]-1]
print(ans)

Submission status: Accepted

Solution code:
def func(N, A_i, B_i, C_i):
    stf = 0
    for i in range(N):
        stf += B_i[i]
        if i >= 1 and (A_i[i] == A_i[i-1] + 1):
            stf += C_i[A_i[i-1]-1]
    return stf

N = int(input())
A_i = list(map(int, input().split(" ")))
B_i = list(map(int, input().split(" ")))
C_i = list(map(int, input().split(" ")))
print(func(N, A_i, B_i, C_i))

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

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

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

sat=0

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