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:
# 2019/09/07

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
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:
# coding: utf-8
# Your code here!
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

tmp=99
ans=0

for i in range(n):
    ans+=B[A[i]-1]
    if tmp+1==A[i]:
        ans+=C[tmp-1]
    tmp=A[i]
    
print(ans)

Submission status: Accepted

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

ans = 0

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

pre = -1
for i in range(n):
    if a[i] == pre+1:
        ans += c[pre-1]
    pre = 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:
# import sys
# input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
# print(a)
# print(b)
# print(c)
count = sum(b)
for i in range(1,n):
    if (a[i]-1)==a[i-1]:
        count += c[a[i-1]-1]
print(count)

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 = 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())
indexes = [int(i) for i in input().split(" ")]
manzokuB = [int(i) for i in input().split(" ")]
manzokuC = [int(i) for i in input().split(" ")]
ans = 0
beforeIndex = -1
for index in indexes:
    ans += manzokuB[index - 1]
    if index == (beforeIndex + 1):
        ans += manzokuC[beforeIndex - 1]
    beforeIndex = index

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

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

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

Submission status: Accepted

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

print(output)

Submission status: Accepted

Solution code:
N = int(input())

A = [int(n) for n in input().rstrip().split(' ')]
B = [int(n) for n in input().rstrip().split(' ')]
C = [int(n) for n in input().rstrip().split(' ')]

next_a = 0

sum_cnt = 0

for i in range(len(A)):
  now = A[i] -1
  sum_cnt += B[now]
  
  if i < len(A)-1:
    next = A[i+1] -1
    if now + 1 == next:
      sum_cnt += C[now]

print(sum_cnt)

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()))
ans=0
for i in range(N-1):
    ans+=lb[la[i]-1]
    #print("ans",ans)
    if la[i]+1==la[i+1]:
        ans+=lc[la[i]-1]
        #print("ans1",ans)
ans+=lb[la[N-1]-1]
print(ans)

Submission status: Accepted

Solution code:
def main():

    N = int(input())
    A = []
    B = []
    C = []

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

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

    return tot



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

satisfaction = b[a[0]-1]

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

print(satisfaction)

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

print(ans)

Submission status: Accepted

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

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

    if i == N - 1:
        break

    if A[i + 1] - A[i] == 1:
        output += C[tmp]

print(output)

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

print(ans)

Submission status: Accepted

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

s = 0
for i,d in enumerate(a):    
    if i >= 1:
        if a[i-1] + 1 == a[i]:
            s += c[d-2]
        s += b[d-1]
    else:
        s += b[d-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()))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
bef = -1
for n in A:
    ans += B[n-1]
    if n-1==bef:
        ans += C[bef-1]
    bef = n

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

print(d+s)

Submission status: Accepted

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

ans = sum(b)


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

print(ans)

Submission status: Accepted

Solution code:
def get_list(str):
    str_list = str.split(" ")
    result_list = []
    for str in str_list:
        result_list.append(int(str))
    return result_list

n = input()
a_str = input()
b_str = input()
c_str = input()
a_list = get_list(a_str)
b_list = get_list(b_str)
c_list = get_list(c_str)

pre_index = -100
result = 0
for i in range(len(a_list)):
    index = a_list[i] - 1
    result += b_list[index]
    if pre_index+1 == index:
        result += c_list[pre_index]
    pre_index = index

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

satisfy = 0

before = -2
for i in range(n):
    satisfy += B[A[i]-1]
    if A[i]-2 == before:
        satisfy += C[A[i]-2]
    before = A[i]-1
print(satisfy)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = B[A[0] - 1]
tmp = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

A_list = list(int(Ai)-1 for Ai in input().split(' '))
B_list = list(int(Bi) for Bi in input().split(' '))
C_list = list(int(Ci) for Ci in input().split(' '))

num = 0
previous=-10

for i, Ai in enumerate(A_list):
  num += B_list[Ai]
  if previous == Ai-1:
    num += C_list[previous]
  
  previous=Ai
  
print(num)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
n = int(input())
lst_a = input().split()
lst_b = input().split()
lst_c = input().split()
for i in range(n):
    lst_a[i]=int(lst_a[i])
    lst_b[i]=int(lst_b[i])
for i in range(n-1):
    lst_c[i]=int(lst_c[i])

ans = sum(lst_b)
for i in range(n-1):
    if lst_a[i]+1==lst_a[i+1]:
        ans+=lst_c[lst_a[i]-1]

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())

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

ans = 0
for i in range(n):
    ans += bn[an[i]-1]
    if i != 0:
        if an[i-1]+1 == an[i]:
            ans += cn[an[i-1]-1]

print(ans)

Submission status: Accepted

Solution code:
s = input().split()
N=int(s[0])
s = input().split()
a=s
s = input().split()
b=s
s = input().split()
sum=int(b[int(a[0])-1])
for i in range(1,N):
        if int(a[i])-int(a[i-1])==1:
                sum = sum+int(b[int(a[i])-1])+int(s[int(a[i-1])-1])
        else:
                sum += int(b[int(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()))

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

ans = 0
before = 0
for num in range(1,n+1):
    ans += b[a[num]]
    if a[num] == before + 1:
        ans += c[a[num]-1]
    before = a[num]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sum = 0

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

print(sum)

Submission status: Accepted

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

score = sum(B)
for ix in range(1, N):
    if (A[ix-1] + 1 == A[ix]):
        # print(A[ix-1], ":", A[ix]," +=", C[A[ix-1]-1])
        score += C[A[ix-1]-1]

print(score)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list = [-1] + a_list
b_list = list(map(int, input().split()))
b_list = [-1] + b_list
c_list = list(map(int, input().split()))
c_list = [1] + c_list
m = 0
for i in range(1, n+1):
  m += b_list[a_list[i]]
  if i >= 2:
    if a_list[i-1] + 1 == a_list[i]:
      m += c_list[a_list[i-1]]
print(m)

Submission status: Accepted

Solution code:
n = int(input())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
c_l = list(map(int,input().split()))
sum = 0
past = a_l[0]
for i in a_l:
        sum += b_l[i-1]
        if i == past + 1:
                sum += c_l[past-1]
        past = i
print(sum)

Submission status: Accepted

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

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

Submission status: 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 n in range(N):
  ans += B[A[n]-1]
  #print('{}: {}'.format(n,B[A[n]-1]))
  if n+1 < N and A[n]+1 == A[n+1]:
    ans += C[A[n]-1]
    #print('C {}: {}'.format(n,C[A[n]-1]))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
AX = list(map(int, input().split()))
BX = list(map(int, input().split()))
CX = list(map(int, input().split()))

from pprint import pprint

sum_manzokudo = 0
before_ryori = -1
for i in range(0, N):
    # N番目に食べたもの
    ryori = AX[i]
    # 満足度
    manzokudo = BX[ryori-1]
    # 追加満足度
    add_manzokudo = CX[before_ryori-1] if ryori-1 == before_ryori else 0
    
    sum_manzokudo += (manzokudo + add_manzokudo)
    before_ryori = ryori

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

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

ans += sum(b)

print(ans)

Submission status: Accepted

Solution code:
import sys

N=int(sys.stdin.readline().rstrip())
AList=list(map(int,sys.stdin.readline().split()))
BList=list(map(int,sys.stdin.readline().split()))
CList=list(map(int,sys.stdin.readline().split()))

beforeBuffet=-1
sutisfier=0
for i in range(N):
  buffet=AList[i]
  sutisfier+=BList[buffet-1]
  if buffet-beforeBuffet==1:
    sutisfier+=CList[buffet-2]
  beforeBuffet=buffet
print(sutisfier)

Submission status: Accepted

Solution code:
# ABC140b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

manzoku = 0

manzoku += b[a[0] - 1]

#print('eat:' + str(a[0]))
# print(manzoku)
for i in range(1, n):
    #print('eat:' + str(a[i]))
    manzoku += b[a[i]-1]
    if a[i] - a[i - 1] == 1:
        # print('hi:'+str(c[a[i-1]-1]))
        manzoku += c[a[i-1]-1]
    # print(manzoku)

print(manzoku)

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

manzoku=0
for i in range(n):
  manzoku+=bl[al[i]-1]
  #print(manzoku)

for i in range(n-1):
  if al[i+1]-al[i]==1:
    #print(i)
    manzoku+=cl[al[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()))
Ans = 0

for i in range(N):
  Ans = Ans + B[i]

for j in range(N-1):
  if A[j] == A[j + 1] - 1:
    gain = A[j]
    Ans = Ans + C[gain - 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 = 0
for i in range(N-1):
    ans += b[a[i]-1]
    if a[i]+1 == a[i+1]:
        if a[i]-1 != N-1 :
            ans += c[a[i]-1]
ans += b[a[N-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()))

happiness = sum(B);
last = -1
for i in range(n-1):
    if A[i+1] - A[i] == 1:
        happiness += C[A[i]-1]

print(happiness)

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

if __name__ == "__main__":
    f_b()

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

A_1 = A_list[0]-1
ans = B_list[A_1]
for i in range(1, N):
    A = A_list[i]-1
    ans += B_list[A]
    if A_1 < N-1:
        if A == A_1+1:
            ans += C_list[A_1]
    A_1 = A
print(ans)

Submission status: Accepted

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

prev = -100
total = 0
for i in a:
    total += b[i - 1]
    if prev == i - 1:
        total += c[i - 2]
    prev = i
print(total)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = list(map(lambda num: int(num) - 1, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

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

    print(res)



resolve()

Submission status: Accepted

Solution code:
import math
import copy

n = int(input())
# k, x = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
# table = [list(input()) for n in range(h)]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
# s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

kotae = 0

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

print(kotae)

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

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

Submission status: Accepted

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

Submission status: 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)
#print(res)
for i in range(n-1):
    if A[i+1] == A[i] + 1:
        #print(A[i+1], A[i])
        #print(C[i])
        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):
    res += B[A[i] - 1]
    if i <= N - 2 and 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 = 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()))

satis=0
As=False
for i,a in enumerate(A):
  satis+=B[a-1]
  if As:
	  if a==(As+1):
	    satis+=C[a-2]
  As=a
  
print(satis)

Submission status: Accepted

Solution code:
N = int(input())

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

score = sum(B)

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

print(score)

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


# print(n, a, b, c)

ans = 0
last_index = -1
for ai in a:
    ans += b[ai-1]
    if ai - last_index == 1:
        ans += c[ai-2]
    last_index = ai

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
dish = -1

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

food_array = []
for i in range(3):
    food_array.append(list(map(int, input().split())))
#print(food_array)

A = food_array[0]
B = food_array[1]
C = food_array[2]

index = -1
count = 0
for i in A:
    count += B[i - 1]
    #print(index, i)
    if index + 1 == i:
        count += C[index - 1]
    index = i
print(count)

Submission status: Accepted

Solution code:
n=int(input())

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

ans=0
bef=-1
for i in range(n):
  ans+=b[a[i]-1]
  if bef==a[i]-1:
    ans+=c[a[i]-2]
  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()))
temp=21
ans=0
for i in range(N):
  a=A[i]
  b=B[a-1]
  ans+=b
  if temp==a-1:
    c=C[a-2]
    ans+=c
    temp=a
  else:
    temp=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()))
count = 0
_a = 100
for a in A:
    count += B[a-1]
    if a - _a == 1:
        count += C[_a-1]
    _a = a
print(str(count))

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

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

manzoku = sum(b)

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

ans = 0

buf = 99
for i in a :
    i = i - 1
    ans += b[i]
    if buf != 99 and i == buf + 1 :
        ans += c[buf]
    buf = i

print(ans)

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

sum = 0
prev = -1
for i in an:
    sum += bn[i-1]
    if prev + 1 == i:
        sum += cn[i-1-1]
    prev = i


print(sum)

Submission status: Accepted

Solution code:
n=int(input())
alist=[int(i) for i in input().split()]
blist=[int(i) for i in input().split()]
clist=[int(i) for i in input().split()]
before=-1
ans=0
for i in alist:
	ans=ans+blist[i-1]
	if before!=-1 and i==before+1:
		ans=ans+clist[before-1]
	if i==n:
		before=-1
	else:
		before=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-1):
    ans += b[a[i]-1]
    if a[i+1] == a[i] + 1:
        ans += c[a[i]-1]

ans += b[a[n-1]-1]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    bl = [int(i) for i in input().split()]
    cl = [int(i) for i in input().split()]

    ans, last = 0, -1
    for i in range(n):
        if i == 0:
            ans += bl[al[i] - 1]
            last = al[i]
            continue
        ans += bl[al[i] - 1]
        if last == al[i] - 1:
            ans += cl[last - 1]
        last = al[i]
    print(ans)


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

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

ret = sum(b)

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


print(ret)