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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = input().split() #食べた順番
b = input().split() #満足度
c = input().split() #追加満足度

x = 0 #合計満足度
p = 0 #今回食べている料理の番号
j = -2 #一個前に食べた料理の番号

for i in range(n):
  p = int(a[i]) - 1
  x += int(b[p])
  if j + 1 == p:
    x += int(c[j])
  j = p

print(x)

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

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

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

print(ans)

Submission status: Accepted

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

sum = 0

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

print(sum)

Submission status: Accepted

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

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

ans = 0
before_i = 100
for i in an:
    ans += bn[i-1]
    if (i-before_i) == 1:
        ans += cn[before_i-1]
    before_i = 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()))

ans = 0
prev = -1
for i in range(n):
  if a_list[i] == prev + 1:
    ans += b_list[a_list[i] - 1] + c_list[prev - 1]
  else:
    ans += b_list[a_list[i] - 1]
  prev = a_list[i]
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( )]
mansoku=0
A.append(-1)
for i in range(N):
    mansoku += B[A[i]-1]
    if A[i]+1 == A[i+1]:
        mansoku += C[A[i]-1]
print(mansoku)

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

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

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

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:
import sys

input = sys.stdin.readline

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
A=map(int,input().split())
B=map(int,input().split());B=list(B)
C=map(int,input().split());C=list(C)
ans=0; temp=30

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

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

    
print(hap)

Submission status: Accepted

Solution code:
# -*- coding:utf8 -*-

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:
def main():
# input
    n = int(input())
    a = [i for i in map(int, input().split())]
    b = [i for i in map(int, input().split())]
    c = [i for i in map(int, input().split())]

# loop
    ans = 0
    temp = -1
    for i in a:
        ans += b[i-1]
        if temp+1 == i:
            ans += c[temp-1]
        temp = i
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

t = [list(map(int,input().split())) for i in range(3)]

ans = 0;

# for j + 1 in range(n) :
j = 1
while j <= n - 1 :
    if t[0][j - 1] + 1 == t[0][j] :
        ans += t[2][t[0][j - 1] - 1]
    j += 1

print(sum(t[1]) + 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()]

score=sum(B)
before = -1
for a in A:
    #print(a, before, score)
    if before+1 == a:
        score+=C[a-2]
    before = a

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

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

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 i,a in enumerate(a_list):
    score += b_list[a-1]
    if i != 0:
        if prev + 1 == a:
            score += c_list[prev-1]
    prev = a

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

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(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

sut = 0
i = 0

while i < N:
    sut += B[i]
    if i < N-1 and (A[i]+1) == A[i+1]:
        sut += C[(A[i]-1)]
    i += 1

print(sut)

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
aj = -10 ** 12
for a in A:
    ans += B[a - 1]
    if a - aj == 1:
        ans += cj
    aj = a
    cj = C[a - 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()]

x = sum(b)
for A, B in zip(a, a[1:]):
  if B == A + 1:
    x += c[A - 1]

print(x)

Submission status: Accepted

Solution code:
x = int(input())
y = input().split()
z = input().split()
a = input().split()

point = 0
tmp = 100

for i in y:
  point += int(z[int(i)-1])
  if tmp == (int(i)-2):
    point += int(a[int(i)-2])
  tmp = int(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()))

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

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

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

print(answer)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
m = 0
mae = -1
for i in A:
    m += int(B[int(i)-1])
    if int(i) - mae  == 1:
        m += int(C[int(i)-2])
    mae = int(i)
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()))


s=0

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

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

s=s+extra

print(s)

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()]
total = sum(b)
last_dish = a[0]
for d in a[1:]:
  if d-last_dish == 1:
    total += c[last_dish-1]
  last_dish = d
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=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 = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
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())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

ans = 0
prev = 40

for i in range(n):
    ans += bl[al[i]-1]
    if al[i] - prev == 1:
        ans += cl[prev-1]

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


last_meal = -100

res = 0

for meal in A_list:
        res += B_list[meal - 1]
        if meal == last_meal + 1:
                res+= C_list[meal-2]
        last_meal = meal


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


def solve():
    point = 0

    point += sum(B)

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

    return point


print(solve())

Submission status: Accepted

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

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

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

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 18,Oct,2019
"""

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

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


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

score = 0
pre = n
for i in range(n):
    score += b[a[i]-1]
    if pre == a[i]-1:
        score += c[pre-1]
    pre = a[i]
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(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()))
S = sum(B)
for i in range(N-1):
    if A[i+1]==A[i]+1:
        j = A[i]-1
        S +=C[j]
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 x,y in zip(a,a[1:]):
  if y == x+1:
    ans += c[x-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
prev_a = -1
for i in range(len(a)):
    ans+=b[a[i]-1]
    if prev_a+1 == a[i]:
        ans+=c[prev_a-1]
    prev_a=a[i]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))

ret = sum(lst_B)
for idx, n in enumerate(lst_A[:-1]):
    if n == lst_A[idx + 1] - 1:
        ret += lst_C[n - 1]
print(ret)

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

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

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

satisfied = 0

for i, a in enumerate(A_list):
  point = B_list[a-1]
  satisfied += point
  
  if i != 0:
    previous = A_list[i-1]
    
    if previous == a-1:
      satisfied += C_list[previous-1]

print(satisfied)

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
clist = list(map(int,input().split()))
score = blist[alist[0]-1]
for i in range(1,n):
    if alist[i] - alist[i-1] == 1:
        score += blist[alist[i]-1] + clist[alist[i] - 1 -1]
    else:
        score += blist[alist[i]-1]

print(score)

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

#output
sum1 = sum(B)
sum2 = 0 
for i in range(N-1):
    if A[i] + 1 == A[i+1]:
        sum2 += C[(A[i]-1)]
print(sum1 + sum2)

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

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

Submission status: Accepted

Solution code:
n= int(input())
la=list(map(int, input().split()))
lb=list(map(int, input().split()))
lc=list(map(int, input().split()))
result=0
for i in range(n-1):
	if la[i]-la[i+1]==-1:
		result+=lc[la[i]-1]
print(sum(lb)+result)

Submission status: Accepted

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

point = 0
prev = 0
for index, dish in enumerate(dishes):
	if index==0:
		point += b[dish-1]
	else:
		if prev+1 == dish:
			point += (b[dish-1]+c[prev-1])
		else:
		 	point += b[dish-1]
	prev = dish

print(point)

Submission status: Accepted

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

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


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

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

print(suti)

Submission status: Accepted

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

print(b)

Submission status: Accepted

Solution code:
a = [input().split() for l in range(4)]
N=int(a[0][0])
A=a[1]
B=a[2]
C=a[3]
manzoku=0
for i in range(N):
    manzoku=manzoku+int(B[int(A[i])-1])
    if i>0 and int(A[i])==int(A[i-1])+1:
        manzoku=manzoku+int(C[int(A[i-1])-1])

print(manzoku)

Submission status: Accepted

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

res=0
back=-1

for a in A:
	res=res+B[a-1]					#listは０スタート
	if a-1==back:					#A内の今考えている変数が前のと同じなら
		res=res+C[back-1]			#listは０スタート
	back=a
    
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()))
for i in range(N-1):
  if A[i] == A[i+1]-1:
    B.append(C[A[i]-1])
    
print(sum(B))

Submission status: Accepted

Solution code:
n = int(input())
dish = [int(i) for i in input().split()]
satisfy = [int(i) for i in input().split()]
bonus = [int(i) for i in input().split()]

ans = 0
pre = -1
for d in dish:
  ans += satisfy[d-1]
  if d == pre + 1:
    ans += bonus[d-2]
  pre = d

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
total=sum([int(i) for i in input().split()])
add=[int(i) for i in input().split()]

for i in range(n-1):
    if A[i+1]==A[i]+1:
        total+=add[A[i]-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
for i in range(0,n):
    ans += b[a[i]-1]
    if i != 0 and a[i-1]+1 == a[i]:
        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())) 
total = 0
preDish = -10
for a in A:
  total += B[a-1]
  if preDish == a - 1 and preDish <= len(C):
    total += C[preDish - 1]
  preDish = a

print(total)

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

def it():
    for x,y in zip(A,A[1:]):
        if x+1 == y:
            yield C[x]
    for x in A:
        yield B[x]
print(sum(it()))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(sum)

Submission status: Accepted

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

satis = 0 #満足度
temp_menu = -1 #１つ前に食べた料理を保存する

for menu in A: #menu:食べた食品
    satis += B[menu-1]
    #今回食べたものが、前回食べたmenuの次ならば追加満足度
    if menu == temp_menu+1 :
        satis += C[temp_menu-1]
    
    temp_menu = menu

print(satis)