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

s = 0
last_ai = None
for ai in A:
    s += B[ai]
    if last_ai is not None and ai - last_ai == 1:
        s += C[last_ai]
    last_ai = ai

print(s)

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

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

print(manzoku)

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
    
sum_b = sum(list_b)

sum_c = 0
for i in range(0,len(list_a)-1,1):
  if list_a[i+1] == list_a[i] + 1:
    sum_c += list_c[list_a[i]-1]

print( sum_b + sum_c)

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

cnt=0
ch=a[0]
for i in a:
  cnt+=b[i-1]
  if i-ch == 1:
    cnt+=c[i-2]
  ch=i
print(cnt)

Submission status: Accepted

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

point = 0
last_dish = 0

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

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()]
total = 0
prev_a = -2
for a in A_list:
    total += B_list[a-1]
    if a == prev_a + 1:
        total += C_list[prev_a-1]
    prev_a = a
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
pre = -1
for i in A:
  ans += B[i-1]
  if i == pre+1:
  	ans += C[pre-1]
  pre = i
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()))

SaticefactonalPoint = 0

for i in range(N):
    EatingDish = Alist[i]
    SaticefactonalPoint += Blist[EatingDish-1]
    if i >= 1:
        HavingEatenDish = Alist[i-1]
        if HavingEatenDish + 1 == EatingDish:
            SaticefactonalPoint += Clist[HavingEatenDish-1]

print(SaticefactonalPoint)

Submission status: 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 = 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()))

sum = 0

for i, ai in enumerate(a):
    sum += b[ai-1]
    try:
        if a[i] == a[i+1] -1:
            sum += c[ai-1]
    except:
        break
print(sum)

Submission status: Accepted

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

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

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

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

satisfaction = 0
before = None
for i in range(N):
    num = A[i] - 1
    satisfaction += B[num]
    try:
        if A[i+1] - 1 == num + 1:
            satisfaction += C[num]
    except:
        pass
print(satisfaction)

Submission status: Accepted

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

sum = 0
for i in A:
    sum += B[i - 1] 

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(lambda x:int(x)-1, input().split()))
B = list(map(lambda x:int(x), input().split()))
C = list(map(lambda x:int(x), input().split()))

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

ans = 0

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

Submission status: Accepted

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

pre = 2 * N

for i in A :
    ans += B[i-1]
    if (pre == (i-2) ):
        ans += C[i-2]
    pre = i-1

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
Ai=list(map(int,input().split()))
Bi=list(map(int,input().split()))
Ci=list(map(int,input().split()))

sf=0
for i in range(N):
    sf+=Bi[i]
for i in range(N-1):
    if Ai[i]+1==Ai[i+1]:
        sf+=Ci[Ai[i]-1]
print(sf)

Submission status: Accepted

Solution code:
n = int(input())
menu = [int(x) for x in input().split()]
score = [int(x) for x in input().split()]
additional = [int(x) for x in input().split()]

total = 0
for i in range(n):
  total +=score[menu[i]-1]
  if i + 1 < n:
    if menu[i] + 1 ==menu[i+1]:
      total += additional[menu[i] -1 ]
print(total)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

#単入力
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()]


for i in range(1,n):
    if a[i]-a[i-1]==1:
        b.append(c[a[i]-2])
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()))
m = 0
for i in range(N):
    m += B[A[i] - 1]
for t in range(N-1):
    if A[t] + 1 == A[t + 1]:
        m += C[A[t] - 1]
print(m)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

A=[int(i)-1 for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]

manzoku=sum(B)

for i in range(1,n):
    if A[i]==A[i-1]+1:
        manzoku+=C[A[i-1]]

print(manzoku)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A, B, C):
    sat = B[A[0]]
    for i in range(1, N):
        sat += B[A[i]]
        if A[i - 1] + 1 == A[i]:
            sat += C[A[i - 1]]
    return sat


def main():
    N = int(inp())
    A = [int(e) - 1 for e in inp().split()]
    B = [int(e) for e in inp().split()]
    C = [int(e) for e in inp().split()]
    print(solve(N, A, B, C))


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
pre=-100
for i in A:
    ans+=B[i-1]

    if(i-pre==1):
        ans+=C[i-2]

    pre=i

print(ans)

Submission status: Accepted

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

import sys
input = sys.stdin.readline


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

    sum = 0
    before = 1000
    for i in a:
        sum += b[i - 1]

        if (i - before) == 1:
            sum += c[i - 2]

        before = i

    print(sum)


if __name__ == '__main__':
    main()

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

answer = 0
before = -99

for i in range(n):
    idx = li_a[i]
    answer += li_b[idx - 1]
    if idx == before + 1:
        answer += li_c[idx - 2]
    before = idx
print(answer)

Submission status: Accepted

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

ans = 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-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:

def main():
    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, num in enumerate(a):
        ans += b[num-1]
        if i < len(a)-1:
            if num+1 == a[i+1]:
                ans += c[num-1]
    print(ans)


if __name__ == "__main__":
    main()

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=sum(b)
for i in range(1,N,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()))

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

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

prev = -10
result = 0

for i in range(N):
    n = A[i]
    result += B[n-1]
    if n == (prev + 1):
        result += C[n-2]
        
    prev = n

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    ans = 0
    pre_a = -100
    for i, a in enumerate(As):
        ans += Bs[a-1]
        if (a-1)-1 == pre_a:
            ans += Cs[pre_a]
        pre_a = a-1
    print(ans)

if __name__ == "__main__":
    solve()

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

b_sum = sum(b_list)

for i in range(N-1):
    diff = a_list[i+1] - a_list[i]
    if diff == 1:
        b_sum = b_sum + c_list[a_list[i]-1]
    else:
        continue
    
print(b_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()))
i = 1
manzoku = sum(B)
while N>i:
    if A[i]-A[i-1] == 1:
      j = A[i-1]
      manzoku += C[j-1]
    i += 1
print(manzoku)

Submission status: Accepted

Solution code:
# coding: utf-8
from itertools import *
import sys
import time


#################### library ####################


#################### naive ####################


#################### process ####################

def read_input():
	N = int(raw_input())
	A = map(int, raw_input().split())
	B = map(int, raw_input().split())
	C = map(int, raw_input().split())
	return (N, A, B, C)


#################### main ####################

#t0 = time.clock()
N, A, B, C = read_input()
s = sum(B)
for k1, k2 in zip(A, A[1:]):
	if k1 == k2-1:
		s += C[k1-1]
print s

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) - 1 for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
sum = 0
prev = 100
for i in range(n):
    sum += b[a[i]]
    if a[i] - 1 == prev:
        sum += c[prev]
    prev = a[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()))
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:
#Coding:Utf-8

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
last=0
total=0
for i in range(N):
    total+=B[A[i]-1]
    if last==A[i]-1 and last!=0:
        total+=C[last-1]
    last=A[i]

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: 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:
def main():
    N = int(input())
    A = [int(i) - 1 for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    satisfaction_degrees = 0
    for i in range(N):
        satisfaction_degrees += B[A[i]]
        if i != 0:
            if A[i] == A[i-1] + 1:
                satisfaction_degrees += C[A[i] - 1]
    print(satisfaction_degrees)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

ans = sum(Bs)
for n in range(N-1):
    if As[n+1] - As[n] == 1:
        ans += Cs[As[n] - 1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
manzoku = []
for i in range(3):
  manzoku.append(list(map(int,input().split(' '))))
#print(manzoku)  
mae_i = -1  
man = 0
for i in manzoku[0]:
  man += manzoku[1][i-1]
#  print(man,i,manzoku[1][i-1])
  if i == mae_i +1:
#    print(manzoku[2][i-2])
    #print('hit')
    man += manzoku[2][i-2]
  mae_i = i

  
print(man)

Submission status: 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
prev = -1010
for i in A:
    sum += B[i-1]
    if prev == i-1:
        sum += C[i-2]
    prev = 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()))
s = int(0)
for i in range(0,N-1):
    if A[i+1] == A[i]+1:
        s += C[A[i]-1]
print(s+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()))

utility = 0
prev = -1

for i in A:
    utility += B[i-1]
  
    if prev == i-1:
        utility += C[i-2]
        
    prev = i

print(utility)

Submission status: Accepted

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

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

num = int(input())
order = input().split()
order = [int(i) for i in order]
manzoku = input().split()
additional = input().split()

prev = -1
ans = 0
for i in order:
  ans += int(manzoku[i-1])
  if i == prev+1:
    ans += int(additional[i-2])
  prev = 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()]
r = 0
a = 0
for i in range(N):
    r += B[A[i]-1]
    if  A[i]-1 > len(C):
        continue
    elif A[i] == a+1 and A[i] != 1:
        r += C[a-1]
    a = A[i]
print(r)

Submission status: Accepted

Solution code:
num = int(input())
order = input().split()
order = [int(i) for i in order]
manzoku = input().split()
additional = input().split()

prev = -1
ans = 0
for i in order:
  ans += int(manzoku[i-1])
  if i == prev+1:
    ans += int(additional[i-2])
  prev = i
  
print(ans)

Submission status: Accepted

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


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):

    result = 0
    for i, a_i in enumerate(A):
        result += B[a_i - 1]
        if i != 0:
            if a_i == (a_old + 1):
                result += C[a_i - 2]
        else:
            pass
        a_old = a_i

    print(result)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
An = list(map(int, input().split()))
Bn = map(int, input().split())
Cn = list(map(int, input().split()))

s = sum(Bn)
for i, (ani, ani1) in enumerate(zip(An, An[1:])):
	#print(i, ani, ani1)
    if ani + 1 == ani1:
      s += Cn[ani - 1]
print(s)

Submission status: Accepted

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

res = 0
prev_i = -1
for i in a:
  res += b[i-1]
  if prev_i + 1 == i:
    res += c[prev_i-1]
  prev_i = i
    
print(res)

Submission status: Accepted

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

past_a = -1
happiness = 0

for a in A:
    happiness += B[a-1]
    if a == past_a + 1:
        happiness += C[a - 2]
    past_a = a

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

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

print(sum)

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()))
last = -1
num = 0
for A in Alist:
    num += Blist[A-1]
    if A == (last+1):
        num += Clist[last-1]
    last = A

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) - 1 for x in input().split(" ")]
B = [int(x) for x in input().split(" ")]
C = [int(x) for x in input().split(" ")]

satisfiction = 0
before_id = None
for i in range(N):
    satisfiction += B[A[i]]
    if before_id is None: pass
    elif before_id == A[i] - 1:
        satisfiction += C[before_id]
    before_id = A[i]
    
print(satisfiction)

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

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

print(int(res))

Submission status: Accepted

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

for i in range(n):
    total += b[a[i]-1]
    if i-1 >= 0 and a[i]-a[i-1] == 1:
        total += c[a[i-1]-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(N):
    ans += B[A[i]-1]
    if i==0: continue
    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(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

prev_a = -1
ans = 0
for i_a in a:
    ans += b[i_a-1]
    if i_a - prev_a == 1:
        ans += c[prev_a-1]
    prev_a = i_a

print(ans)

Submission status: Accepted

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

sum = 0
for ia, i in enumerate(A):
    sum += B[i - 1]
    if ia > 0:
        if A[ia-1] == i - 1:
            sum += C[i-2]
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
a, b, c = [list(map(int, input().split())) for i in range(3)]
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:
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:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    res = sum(B)

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

    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

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