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())
tmp = input()
A = [int(x.strip()) for x in tmp.split(' ')]
tmp = input()
B = [int(x.strip()) for x in tmp.split(' ')]
tmp = input()
C = [int(x.strip()) for x in tmp.split(' ')]
tmpsum = sum(B)
for i in range(0, N-1):
    if A[i]+1 == A[i+1]:
        tmpsum += C[A[i]-1]
print(tmpsum)

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

beforeNumber = 0
manzoku = 0
for i in a:
    if beforeNumber != 0 and beforeNumber + 1 == i:
        manzoku = manzoku + b[i-1] + c[beforeNumber-1]
    else:
        manzoku += b[i-1]
    beforeNumber = i
print(manzoku)

Submission status: Accepted

Solution code:
def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    ans=0
    np=-199
    for i in range(N):
        n=A[i]
        ans+=B[n-1]
        if np+1==n:
            ans+=C[np-1]
        np=n
    print(ans)
resolve()

Submission status: Accepted

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

def main(N,A,B,C):
    ans = 0
    olda = float("INF")
    for a in A:
        if a - olda == 1:
            ans += C[olda]
        olda = a
    print(ans+sum(B))
        

if __name__ == '__main__':
    N = int(input())
    A = [int(a)-1 for a in input().split()]
    B = [int(a) for a in input().split()]
    C = [int(a) for a in input().split()]
    main(N,A,B,C)

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

score=0
tmp=-1
for i in A:
    score+=B[i-1]
    if i==tmp+1:
        score+=C[tmp-1]
    tmp=i
print(score)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
lc = list(map(int, input().split()))

ans = 0
e = -1
for a in la:
  ans += lb[a - 1]
  if e == a - 1:
    ans += lc[e - 1]
  e = 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()]
total = 0

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

satisfaction = 0

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

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

manzokudo = sum(B)
i1 = 0
i2 = 0
for idx, i in enumerate(A):
  if idx == 0:
    i1 = i
  else:
    i2 = i1
    i1 = i
    if i1 - i2 == 1:
      manzokudo += C[i2 - 1]
print(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):
    ans += B[A[i]-1]
    if i > 0 :
        if A[i] - A[i-1] == 1 :
            ans += C[A[i]-2]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
ans = 0
prev_i = -1

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
count = 0
for i in range(n):
    A = a[i]-1
    count += b[A]
    try:
        if a[i]+1==a[i+1]:
            count += c[A]
    except:
        continue
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()))

answer = 0
previous_index = n + 1

for number in a:
    answer += b[number - 1]

    if number == previous_index + 1:
        answer += c[previous_index - 1]

    previous_index = number

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

Submission status: Accepted

Solution code:
num = int(input())
list1 = []
result = 0
prev = -2
for i in range(3):
    list1.append(list(map(int, input().split())))

a = list1[0]
b = list1[1]
c = list1[2]

for i in range(num):
    result += b[a[i]-1]
    if prev + 1 == a[i]:
        result += c[a[i-1]-1]
    prev = a[i]

print(result)

Submission status: Accepted

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

res = 0

for i in range(N):
    res += B[A[i] - 1]
    if i >= 1:
        if A[i] - A[i - 1] == 1:
            res += C[A[i] - 2]

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

sum_B = sum(B)
sum_C = 0
for i in range(n-1):
  if A[i] + 1 == A[i+1]:
    sum_C += C[A[i]-1]
    
ans = sum_B + sum_C
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=0
prev=-2
for i in range(N):
    now=A[i]-1
    happiness+=B[now]
    if prev==now-1:
        happiness+=C[now-1]
    prev=now
    
print(happiness)

Submission status: Accepted

Solution code:
n=int(input())
li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))
li3 = list(map(int,input().split()))

sum = 0
last_num = 0
for i in range(n):
  sum += li2[li1[i]-1]
  now = li1[i]
  if last_num != 0:
    if now - last_num == 1:
      sum+=li3[li1[i-1]-1]
  last_num = li1[i]
print(sum)

Submission status: Accepted

Solution code:
while True:
    try:
        N = int(input())
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
        C = list(map(int, input().split()))
        result = 0
        prev = None
        for i in A:
            result += B[i-1]
            if prev is not None and i == prev + 1:
                result += C[prev-1]
            prev = i
        print(result)
    except EOFError:
        break

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

import numpy as np

ans = np.sum(B)

D = np.zeros(N-1)

for i in range(N-1):
  D[i] = A[i+1] - A[i]
  
for i in range(N-1):
  if D[i] == 1:
    x = A[i] - 1
    ans += C[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()))
m=0
for i in range(n-1):
    if a[i+1]-a[i]==1:
        ai=a[i]-1
        m+=c[ai]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
numDishes = int(input())
order = input()
sat1 = input()
sat2 = input()
satisfaction = 0
prev = -20

orderList = []
orderList = order.split(" ")
sat1List = []
sat1List = sat1.split(" ")
sat2List = []
sat2List = sat2.split(" ")

if (len(orderList) == numDishes) and (len(sat1List) == numDishes) and (len(sat2List) == numDishes-1):
    for i in orderList:
        num = int(i)
        if prev + 1 == num:
            satisfaction = satisfaction + int(sat1List[num - 1])
            satisfaction = satisfaction + int(sat2List[prev - 1])
        else:
            satisfaction = satisfaction + int(sat1List[num - 1]) 
        prev = num

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()))  #複数数値入力

Sat = sum(B) # Bの合計

for idx, a in enumerate(A):
  if idx == N-1:
    break
  if ((a+1) == A[idx+1]):
    Sat = Sat+C[a-1]

print(Sat)

Submission status: Accepted

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

ans = 0
count = len(C)
for i, j in enumerate(A):
  ans += B[j - 1]
  if i < count and A[i] + 1 == A[i+1]: 
    ans += C[j - 1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

meals = list(map(int, input().split()))
likes = list(map(int, input().split()))
addLikes = list(map(int, input().split()))

total_like = 0

for i in range(n):
  meal = meals[i]
  like = likes[meal-1]
  if i < n-1 and meal == meals[i+1]-1:
    like += addLikes[meal-1]
  total_like += like
    
print(total_like)

Submission status: Accepted

Solution code:
import sys
#template by uwi 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
ns()
ar = na()
ans = sum(na())
cr = na()
prev = -1
for i in range(len(ar)):
    if prev+1 == ar[i]:
        ans += cr[prev-1]
    prev = ar[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()))

result = 0
for ai, i in enumerate(a):
    result += b[i - 1]
    if ai > 0 and i - a[ai - 1] == 1:
        result += c[a[ai - 1] - 1]
print(result)

Submission status: Accepted

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

A = [int(s) for s in A]
B = [int(s) for s in B]
C = [int(s) for s in C]

manzoku = 0
pre_a = 100

for a in A:
    manzoku += B[a-1]
    if(pre_a == a-1):
        manzoku += C[a-2]
    pre_a = a

print(manzoku)

Submission status: Accepted

Solution code:
num = 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()]

sum = 0
count = 0
for i in range(0,num):
    count = A[i]
    if(i >= 1):
        if(A[i] -1 == A[i-1] ):
            sum = sum + B[count-1]+ C[count-2]
        else:
            sum = sum + B[count-1]
    else:
        sum = sum + B[count-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()))

h = 0
for i in b:
    h += i


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

print(h)

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

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

Submission status: Accepted

Solution code:
N = int(input())
A_array = [int(i) for i in input().split()]
B_array = [int(i) for i in input().split()]
C_array = [int(i) for i in input().split()]

counter = 0
for i, e in enumerate(B_array):
    counter += e

for i in range(N-1):
    menu_i = A_array[i]
    menu_iplus1 = A_array[i+1]
    if menu_iplus1 == menu_i + 1:
        counter += C_array[menu_i-1]

print(counter)

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

print(m)

Submission status: Accepted

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

total = 0
for i, Ai in enumerate(A):
  total += B[Ai]
  if i >= 1:
    if A[i] == A[i-1]+1:
      total += C[Ai-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(" ")))
point = 0
last_index = -1
for a in A:
    point += B[a - 1]
    if last_index == a - 1:
        point += C[a-2]
    last_index = a

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

Submission status: Accepted

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

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()))
count = 0
ins = 100
for i in A:
  count += B[i-1]
  if ins == i-1 and C[i-2]:
    count += C[i-2]
  ins = 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()))

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

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

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

print(satisf)

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

total_value = 0
last_index = -2

for i in range(n):
  index = a_list[i] - 1
  total_value += b_list[index]
  
  if last_index + 1 == index:
    total_value += c_list[last_index]
  
  last_index = index
  
print(total_value)

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

last = -99
for i in range(0, n):
    now = a[i]

    sum += b[now - 1]

    if last + 1 == now:
        sum += c[last - 1]
    last = now

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;
setter = -100;
for i in a:
    ans+=b[i-1]
    if(setter+1 == i):
        ans+= c[setter-1]
    setter = i
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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, a in enumerate(A):    
    ans += B[a-1]
    
A_ = [-100] + A[:-1]
A_ = np.array(A_)
A = np.array(A)

A_diff = A - A_

for j in A[A_diff == 1] -1:
    ans += C[j-1]
print(ans)

Submission status: Accepted

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

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

counter = 0
for i in range(N):
    # print(i)
    num = A[i] - 1
    counter += B[num]
    # print('Add:', B[num])
    if i != 0 and num - 1 == A[i-1] - 1:
        counter += C[num-1]
        # print('Add:', C[num-1])
    # print('')
print(counter)

Submission status: Accepted

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

sut = 0
for i,ind in enumerate(a):
    sut += b[ind-1]
    if i>=1:
        if a[i-1]+1 == a[i]:
            sut += c[a[i]-2]
print(sut)

Submission status: Accepted

Solution code:


n = int(input())

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

old_a = -1
ans = 0

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

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

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

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

print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input()) # Skip first line
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
point=sum(b)
# print("Point",point)
for i in range(n-1):
    if a[i] + 1 == a[i + 1]:
        point = point + c[a[i]-1]
print(point)   

exit(0)

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

t = 0

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

print(sum(b) + t)

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, b, c = [list(map(int, input().split())) for _ in range(3)]

ans = sum(b)
last = -1
for x in a:
    if last+1 == x:
        ans += c[last-1]
    last = 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 = sum(B)
now = 99
for i in A:
  pre = now
  now = i
  if now == (pre+1):
    ans += C[pre-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
a_ = -float('inf')
for a in A:
    a = a - 1
    ans += B[a]
    if a_ == a - 1:
        ans += C[a_]
    a_ = 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())) 
ans1=0
for i in range(1,n):
    if a[i]==a[i-1]+1:
        ans1+=c[a[i-1]-1]
print(sum(b)+ans1)

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
A = list(map(int, inputs[1].split()))
B = list(map(int, inputs[2].split()))
C = list(map(int, inputs[3].split()))

x = 0
pre = -1
for a in A:
  x += B[a-1]
  if pre+1 == a:
  	x += C[pre-1]
  pre = a

print(x)

Submission status: Accepted

Solution code:
import copy

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = sum(b)

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

ful = sum(B)

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

print(ful)

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

sati = 0
for (index, a) in enumerate(A):
    sati += B[a-1]

    if(index+1 < N and A[index]+1 == A[index+1]):
        sati += C[A[index]-1]

print(sati)

Submission status: Accepted

Solution code:
import numpy as np


N = int(input())
A = np.array(input().split(), np.int32)
B = np.array(input().split(), np.int32)
C = np.array(input().split(), np.int32)

A_diff = np.zeros(A.shape)
A_diff[1:] = np.diff(A, n=1)

res = 0

for i, diff_num in zip(A, A_diff):
    res += B[i-1]
    if diff_num == 1:
        res  += C[i-2]

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

temp = -100
ans = 0

for i, value in enumerate(A):
    ans += B[value-1]

    if temp == value-1:
        ans += C[value-2]

    temp = value

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

Submission status: Accepted

Solution code:
#!/usr/bin/python
# coding: UTF-8

from math import *
import os
import sys

#import scipy.optimize
import numpy as np


##################################################################
if __name__ == "__main__":
    Input = [input() for i in range(4)]
    N = int(Input[0])
    A = list(map(int,Input[1].split()))
    B = list(map(int,Input[2].split()))
    C = list(map(int,Input[3].split()))

    raw = sum(B[i-1] for i in A)
    for i in np.arange(1,len(A),1):
        if A[i]-A[i-1] == 1:
            raw = raw + C[A[i-1]-1]
    print(raw)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
ans=0
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=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=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()))
tot = sum(B)
for i in range(n-1):
  if A[i+1] == A[i]+1:
    tot += C[A[i]-1]
print(tot)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
s = 0
prev = 0
for i in range(n):
  s += B[A[i]-1]
  if A[i] != 1 and (A[i]-1 == prev):
    s += C[A[i]-2]
  prev = A[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()))
D = []
for i in range(N-1):
  if A[i+1] - A[i] ==1:
    D.append(C[A[i]-1])

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

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-1]-1]
    
  
  
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

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, a in enumerate(A):
        ans += B[a-1]
        if i > 0 and A[i] - A[i-1] == 1:
            j = A[i-1] - 1
            ans += C[j]
    print(ans)

input = lambda: stdin.readline()[:-1]
main()

Submission status: Accepted

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

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

ans = 0
past = 999

for i in alist:

    if i - past == 1:
        #print(i, ans)
        ans += clist[past-1]
    #print(i, ans)
    ans += blist[i-1]
    past = 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()))

tot = 0

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

print(tot)

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, a, b, c):
    ans = 0
    pre = -1
    for a_i in a:
        # print(a_i)
        ans += b[a_i-1]
        if pre + 1 == a_i:
            ans += c[pre-1]
        pre = a_i

    print(ans)

if __name__ == '__main__':
  n = int(sys.stdin.readline().strip())
  a = list(map(int, sys.stdin.readline().strip().split(" ")))
  b = list(map(int, sys.stdin.readline().strip().split(" ")))
  c = list(map(int, sys.stdin.readline().strip().split(" ")))
  # pprint(a)
  # pprint(b)
  # pprint(c)
  solve(n, a, b, c)