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 = map(int, input().split())
*b, = map(int, input().split())
*c, = map(int, input().split())
count = 0
tmp = -1
for i in a:
    count += b[i-1]
    if i - tmp == 1:
        count += c[i-2]
    tmp = i

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

score = 0
tmp =-100
for a in A:
    score+=B[a-1]
    if tmp +1 ==a:
        score+=C[tmp-1]
    tmp = a

print(score)

Submission status: Accepted

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

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

total = 0
last = -1
for aa in a:
    total += b[aa]
    if aa == last+1:
        total += c[last]
    last = aa


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

Submission status: Accepted

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

a = [d-1 for d in a]
#print(a)
manzoku = 0
jotai = a[0]

for val in a:
    manzoku = manzoku + b[val]
    if jotai +1 == val:
        manzoku += c[val-1]
    jotai = val

print(manzoku)

Submission status: Accepted

Solution code:
def intminus(i):
    return int(i) - 1
def main(): 
    
    n = int(input())
    A = list(map(intminus, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

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

    print(cnt)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
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()]

res = 0
for i in range(1, N + 1):
	menu = A[i - 1]
	res += B[menu - 1]

for i in range(2, N + 1):
	if A[i - 1] - A[i - 2] == 1:
		res += C[A[i - 2] - 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()))
pa = 1000
ans=0
for i in range(N):
  ans += B[A[i]-1]
  if pa == A[i]-1-1:
    ans += C[pa]
  pa = 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()))
cnt = 0
for i in range(n):
    cnt += b[a[i] - 1]
    if (a[i]-1 == a[i-1])&(i!=0):
        cnt += c[a[i - 1]-1]
print(cnt)

Submission status: Accepted

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

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

print(level)

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):
  now = A[i]-1
  res += B[now]
  if i > 0:
    prev = A[i-1]-1
    if now == prev+1:
      res += C[prev]

print(res)

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

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

Submission status: Accepted

Solution code:
import math
input = raw_input

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(1, N):
    if A[i] - A[i-1] == 1:
        x += C[A[i-1]-1]
print(x)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split())) # taberu order
b = list(map(int, input().split())) # get
c = list(map(int, input().split())) # renzoku
 
ans = 0
for i in range(n):
  po = a[i]
  ans += b[po-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())
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
before = -1
for i in range(n):
    now = a[i]
    if before + 1 == now:
        ans += c[before-1]
    before = now
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
mae = -10

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

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):
    a = a_list[i]
    b = b_list[a-1]
    if i != N-1:

        if a_list[i+1] == a+1:
            c = c_list[a-1]
            #print(c)
            ans +=c
    prev = a
    ans += b

    #print(prev)
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()))
#[A, B] = list(map(int,input().split()))
#N = 2
#A = [1, 2]
#B = [50,50]
#C = [50]
ans = sum(B) 
for i in range(len(A)-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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


print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# abc140/abc140_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = i2nn()
    B = i2nn()
    C = i2nn()
    m = 0
    for j in range(N - 1):
        i = A[j] - 1
        m += B[i]
        if i + 1 == A[j + 1] - 1:
            m += C[i]
    m += B[A[N - 1] - 1]
    print(m)
    return

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

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

    print(cst)
    return


# Generated by 1.1.5 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
cnt = 0

for n in A:
  if cnt == 0:
    ans += B[n-1]
    cnt += 1
  else:
    ans += B[n-1]
    if A[cnt] - A[cnt-1] == 1:
      ans += C[A[cnt-1]-1]
    cnt += 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,a in enumerate(A):
  if i>=len(A)-1:
    break
  if A[i+1]-a==1:
    ans+=C[a-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[i]
    if i == 0:
        continue
    judge = A[i] - A[i-1]
    if judge == 1:
        count = A[i-1] - 1
        ans += C[count]

print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    N = II()
    A = LMIIS()
    B = LMIIS()
    C = LMIIS()
    sums = 0
    pre = -9999
    for a in A:
        a = a-1
        sums += B[a]
        if a - pre == 1:
            sums += C[pre]
        pre = a
    print(sums)

        



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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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


print(sum(b) + sum(cl))

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()] 
C.append(0)
ans=0
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=map(int,input().split())
B=map(int,input().split())
C=map(int,input().split())
a=list(A)
b=list(B)
c=list(C)
s=0

for i in range(n):
    if i==n-1:
        s=s+b[i]
    elif a[i]+1==a[i+1]:
        s=s+b[i]+c[a[i]-1]
    else:
        s=s+b[i]

print(s)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 0
for i in range(len(A)):
    if i != 0:
        if A[i] == A[i-1]+1:
            ans += B[A[i]-1]
            ans += C[A[i-1]-1]
        else:
            ans += B[A[i]-1]
    else:
        ans +=B[A[i]-1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input());
a = input().split(" ");
b = input().split(" ");
c = input().split(" ");

for i in range(n) :
	a[i] = int(a[i]);
	b[i] = int(b[i]);
a.insert(0,0);
b.insert(0,0);

for i in range(n-1) :
	c[i] = int(c[i]);
c.insert(0,0);

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0 


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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split())) # list()でリスト化、それを変数liに代入。
b = list(map(int, input().split())) # list()でリスト化、それを変数liに代入。
c = list(map(int, input().split())) # list()でリスト化、それを変数liに代入。
m = 0

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

Submission status: Accepted

Solution code:
N=int(input())
l= [list(map(int, input().split())) for i in range(3)]
a=0
for i in range(N-1):
    a+=l[1][l[0][i]-1]
    if l[0][i+1]==l[0][i]+1:
        a+=l[2][l[0][i]-1]
a+=l[1][l[0][N-1]-1]
print(a)

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

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
ans = 0
for i in range(N):
    a = A[i]
    ans += B[A[i]-1]
    if i and A[i-1] == A[i]-1:
        ans += C[A[i-1]-1]
print(ans)

Submission status: Accepted

Solution code:
import copy 
import numpy as np

N = int(input())

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


sum    = 0
temp_A = 0
for i in range(len(A)):

    if temp_A+1==A[i] and i!=0:
        sum = sum + C[temp_A-1]
    sum = sum + B[A[i]-1]
    temp_A = A[i]

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) - 1 for x in input().split()]
total = sum(map(int, input().split()))
c = [int(x) for x in input().split()]
for i, j in zip(a, a[1:]):
    if j - i == 1:
        total += c[i]
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ListA = [int(val) for val in input().split()]
ListB = [int(val) for val in input().split()]
ListC = [int(val) for val in input().split()]
prevA = -1
point = 0
for val in ListA:
	point += ListB[val - 1]
	if (val == prevA + 1):
		point += ListC[prevA - 1]
	prevA = val
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()))

sum_satisfaction = 0

for i in range(n):
    sum_satisfaction += b[a[i]-1]
    if i == 0:
        continue
    elif a[i] == a[i-1] + 1:
        sum_satisfaction += c[a[i-1]-1]

print(sum_satisfaction)

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

count = 0
pre = -10
for i in range(n):
    food = a[i]
    count += b[food - 1]
    if pre + 1 == food:
        count += c[food - 2]

    pre = food

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


sume = 0

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

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

man = 0
pre = -10

for i in a:
    ai = i-1
    man += b[ai]
    #print(b[ai])
    if pre == ai - 1:
        man += c[pre]
        #print(c[pre])
    pre = ai

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 = -1
for num in A:
    sum += B[num-1]
    if num - prev == 1:
        sum += C[prev-1]
    prev = num
print(sum)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    Bs = [int(x) for x in stdin.readline().rstrip().split()]
    Cs = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    tmp = -1
    for A in As:
        result += Bs[A - 1]
        if tmp + 1 == A:
            result += Cs[tmp - 1]
        tmp = A
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import math
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 一括読み
#N, K, *A = map(int, open(0).read().split())


# 整数の入力
n = int(input())

# スペース区切りの入力
#n, x = input().split()

# スペース区切りの整数の入力
#n, m = map(int, input().split())
#n, x = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#a = [int(x) for x in input().split()]
#b = [int(x) for x in input().split()]
#print("a", a, file=sys.stderr)
#p, q, r = map(int, input().split())
#s = [int(x) for x in input().split()]
#t = [int(x) for x in input().split()]

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#b = []
#for x in range(m):
#  b.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def ton(n, k, x):
  s = ""
  while n > 0:
    s = str(n%k) + s
    n //= k
  return s


#print("a", a, file=sys.stderr)
#print("b", b, file=sys.stderr)

def getEnergy():
  for y in b:
    yield y

def doit():
  total = 0
  prev = -2
  for x in a:
    total += b[x-1]
    if prev == x - 1:
      total += c[prev-1]
    prev = x

  return total

def yn():
  if doit():
    return "Yes"
  else:
    return "No"

#print(doit([0] * 4))
#doit(a)
#print(doit())
try:
  #doit()
  print(doit())
  #print(yn())
except Exception as e:
  print("e", e, file=sys.stderr)

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

s = 0

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

    if (A[i-1]+1) == A[i] and not i == 0:
        s = s + C[A[i-1]-1]


print (s)

Submission status: Accepted

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

s = 0

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

happy = dict()
for i in range(N):
    happy[A[i]] = B[i]

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


prev = A[0]
total = B[prev-1]
for a in A[1:]:
  total += B[a-1]
  if a - prev == 1:
    total += C[prev-1]
  prev = a

print(total)

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

satisfied = 0
for i in range(N):
    A = Alist[i]-1
    satisfied += Blist[A]
    if i>=1 and Alist[i] == Alist[i-1]+1:
        satisfied += Clist[Alist[i-1]-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 = 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()))
# print(a, b, c)
for i in range(n):
    a[i] -= 1
ans = 0
last = -2
for i in range(n):
    ans += b[a[i]]
    if last + 1 == a[i]:
        ans += c[last]
    last = a[i]
print(ans)

Submission status: Accepted

Solution code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        A, B, C = [list(map(int, input().split())) for _ in range(3)]

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


# Run main
if __name__ == '__main__':
    AtCoder().main()

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

s = 0
p_a = -1
for now_a in a:
    s += b[now_a-1]
    if now_a - p_a == 1:
        s += c[p_a-1]

    p_a = now_a

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[i]
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:
# -*- coding: utf-8 -*-
import numpy as np
import sys


def main():
    N = int(input())
    A = np.array(input().split(), dtype='int64')
    B = np.array(input().split(), dtype='int64')
    C = np.array(input().split(), dtype='int64')

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

    print(satisfy)








if __name__ =='__main__':
    main()

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

for i in range(N-1):
    target = A_list[i]
    if (A_list[i+1] - target) == 1:
        add += C_list[target - 1]

print(sum(B_list) + add)

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

print(ans)

Submission status: Accepted

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

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

sum=0
for i in B:
    sum+=i

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

print(sum)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = [int(s) - 1 for s in input().split()]
    b = [int(s) for s in input().split()]
    c = [int(s) for s in input().split()]
    ans = b[a[0]]
    for i, v in enumerate(a[1:]):
        ans += b[v]
        if v - a[i] == 1:
            ans += c[v - 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()] 
D = 0
for i in range(N):
	if i <= N-2:
		D += B[A[i]-1]
		if A[i+1]-1 == A[i]:
			D += C[A[i]-1]
	else:
		D += B[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()))

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

print(sum(b)+cs)