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: Wrong Answer

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

Submission status: Wrong Answer

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) + sum(C) - C[0])

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
lia = list(map(int, sys.stdin.readline().split()))
lib = list(map(int, sys.stdin.readline().split()))
lic = list(map(int, sys.stdin.readline().split()))
s = sum(lib)
li = []
i = 0
while i < n-1:
  if lia[i+1] - lia[i] == 1:
    li.append(i)
for i in li:
  s += lic[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
num = 0
for i in A:
    ans += B[i-1]
    if num != 0 and i - num == 1:
        ans += C[i-2]
    num = 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()))
food = 0
manzoku = 0
bonus = 0
before = 10*3
ans = 0
for i in range(n):
    food = a[i]
    manzoku = b[food-1]
    if food == before+1:
        bonus = c[food-2]
        ans += manzoku + bonus
    else:
        ans += manzoku
    before = food
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()))

sum1 = sum(B)

cn = 0
SUM = 0

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




print(sum1 + 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()))
su = 0
n1 = len(a)
for i in a:
    su += b[i-1]

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

print(su)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
jun = [int(s) for s in input().split()]
r = [int(s) for s in input().split()]
m = [int(s) for s in input().split()]

point = 0
for i in range(n):
    point += r[jun[i]-1]
    if jun[i]-1 == jun[i-1] and i > 0:
        point += m[jun[i-1]-1]
print(point)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

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

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

ans+=B[A[N-1]-1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = tuple(map(int, input().split()))
assert len(A) == N
assert len(B) == N
assert len(C) == N - 1

score = sum([B[a-1] for a in A])
for A1,A2 in zip(A, A[1:]):
  if A2 == A1 + 1:
    score += C[A1-1]
print(score)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#from decimal import Decimal
#mod = 1000000007
#mod = 998244353
N = int(input())
#N, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
#flag = True
ans = 0
b = -2
for k in range(N):
  if A[k] == b+1:
    ans += C[b-1]
  ans+=B[A[k]-1] 
  
  b = A[k]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list((int(x) for x in input().split()))
B = list((int(x) for x in input().split()))
C = list((int(x) for x in 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:
kind = int(input())

table_1 = input().split(' ')
table_2 = input().split(' ')
table_3 = input().split(' ')
total = 0
for i in range(kind):
    total += int(table_2[i])
    
for j in range(kind-1):
    if int(table_1[j]) == int(table_1[j + 1]) - 1:
        total += int(table_3[int(table_1[j]) - 1])
print(total)

Submission status: Accepted

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

ans = 0
x = -1

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

sumB = sum(B)

cnt = []

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

sumC = 0
for i in cnt:
    sumC += C[i]

print(sumB+sumC)

Submission status: Accepted

Solution code:
N = int(input())
Alst = list(map(int, input().split()))
Blst = list(map(int, input().split()))
Clst = list(map(int, input().split()))

ans = sum(Blst)

for i in range(N-1):
    if Alst[i] + 1 == Alst[i+1]:
        ans += Clst[Alst[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):
    num = a[i] - 1
    ans += b[num]

    if i == 0:
        continue
    elif a[i - 1] + 1 == a[i]:
        ans += c[num - 1]

print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
A = LI()
B = LI()
C = LI()
ans = 0
before = -1
for i in range(n):
    taberuNo = A[i]-1
    ans += B[taberuNo]
    if taberuNo -1 == before and i != 0:
        ans += C[before]
    before = taberuNo
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()))

addans=0

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

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

X=0
for i in range(1,N+1):
    X+=B[i]

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Manzoku = sum(liB)

for i in range(N):
    if i < N - 1:
        if liA[i+1] - liA[i] == 1:
            Manzoku += liC[liA[i] - 1]

print((Manzoku))

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

Submission status: Accepted

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

an = list(map(int,input().split()))
bn = list(map(int,input().split()))
cn = list(map(int,input().split()))
sat = sum(bn)

for x in range(n-1):
    if an[x+1] == an[x] + 1:
        sat += cn[an[x]-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()))
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
cnt = 100
for i in range(N):
  if cnt + 1 == A[i]:
    ans += C[cnt-1]
  cnt = A[i]
  ans += B[A[i]-1]
  
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
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]


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

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

for i in range(len(A_List)):
    ans += B_List[A_List[i] - 1]
    if (i != 0) & (A_List[i] - A_List[i-1] == 1):
        ans += C_List[A_List[i-1]-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
list_a = [int(i) for i in input().split()]
list_b = [int(j) for j in input().split()]
list_c = [int(k) for k in input().split()]
satisfied = 0
for i in range(0, len(list_a)):
    satisfied += list_b[list_a[i] - 1]
    if i > 0 and list_a[i] == list_a[i - 1] + 1:
        satisfied += list_c[list_a[i - 1] - 1]
print(satisfied)

Submission status: Accepted

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

ans=0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

count = 0
for j in A:
    count += B[j-1]

#print(count)

for z in range(N-1):
    if A[z+1]- A[z] == 1:
        zz = A[z]
        count += C[zz-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()))


b=sum(B)

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


print(b)

Submission status: Accepted

Solution code:
N = int(input())
lsA = list(map(int,input().split()))
lsB = [0]+list(map(int,input().split()))
lsC = [0]+list(map(int,input().split()))
sumB = sum(lsB)
for i in range(N-1):
    if lsA[i]+1 == lsA[i+1]:
        sumB += lsC[lsA[i]]
print(sumB)

Submission status: Accepted

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

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

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

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

print(s)

Submission status: Accepted

Solution code:
N=int(input())
d=[[int(s) for s in input().split()] for i in range(3)]
ans=0
for i in range(N):
    ans+=d[1][d[0][i]-1]
    if i<=N-2 and d[0][i+1]-d[0][i]==1:
        ans+=d[2][d[0][i]-1]
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = 0
    prev = N + 100

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    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)


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()))
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]-2]
print(s)

Submission status: Accepted

Solution code:
def L():
	return list(map(int, input().split()))

N = int(input())
A = L()
B = L()
C = L()
O = 0

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

print(O)

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=sum(B)
for i in range(n-1):
  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()))

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

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()))
    total_score = sum(b)

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

    print(total_score)


if __name__ == '__main__':
    main()

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()))
    point = sum(b)

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


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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    c_lst = list(map(int, input().split()))
    ans = 0

    for a in a_lst:
        ans += b_lst[a - 1]

    for i in range(n - 1):
        if a_lst[i] + 1 == a_lst[i + 1]:
            ans += c_lst[a_lst[i] - 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()))
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]-2]
print(ans)

Submission status: Accepted

Solution code:
# 問題：https://atcoder.jp/contests/abc140/tasks/abc140_a

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

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

print(res)

Submission status: Accepted

Solution code:
N = int(input())
A,B,C = [list(map(int, input().split())) for _ in range(3)]

ans = 0

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

print(sum(B) + ans)

Submission status: Accepted

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

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

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

ans = b[a[0] - 1]

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

a_list=[int(i) for i in input().split()]
b_list=[int(i) for i in input().split()]
c_list=[int(i) for i in input().split()]

satisfaction=0

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

for i in range(n):
  ans += b[i]
for j in range(n-1):
  if a[j] == a[j+1] -1:
    ans += c[(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()))
ANS = sum(B)
for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    ANS += C[A[i]-1]
print(ANS)

Submission status: Accepted

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

Submission status: Accepted

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