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

s = 0
prev = -2
for i in range(n):
  s += b_s[a_s[i]]
  if a_s[i] - prev == 1 and prev < n-1:
    s += c_s[prev]
  prev = a_s[i]

print(s)

Submission status: Accepted

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

score = 0

for n in range(N):
    b_index = A[n]-1
    score = score + B[b_index]

    if n -1 != -1:
        if A[n-1]+1 == A[n]:

            score += C[A[n]-2]

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

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

Submission status: Accepted

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

manzoku=0;

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    if i >= 1 and A[i] == A[i - 1] + 1:
        res += C[A[i - 1] - 1]

print(res)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

ans =sum(b)

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

print(sum(b) + 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()))

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

print(sum(b) + tmp)

Submission status: Accepted

Solution code:
def solve(n, a, b, c):
    res = 0
    for i in range(n):
        if (i + 1 < n) and (a[i+1] == a[i] + 1):
            res += c[a[i]-1]
        res += b[a[i]-1]
    return res

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

Submission status: Accepted

Solution code:
n = int(input())

ordered_menus = [int(i) for i in input().split()]
menu_values = [int(i) for i in input().split()]
additional_happiness = [int(i) for i in input().split()]

res = 0

res += sum(menu_values)

for i in range(n-1):
    if ordered_menus[i+1] - ordered_menus[i] == 1:
        res += additional_happiness[ordered_menus[i] - 1]

print(res)

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
line1 = input().split(" ")
line2 = input().split(" ")
line3 = input().split(" ")

line22 = {}
for i in range(N):
    line22[i + 1] = int(line2[i])

total = 0
memory = - 1
for number in line1:
    num = int(number)
    total += line22[num]
    if num == memory + 1:
        total += int(line3[memory - 1])
    memory = num

print(total)

Submission status: Accepted

Solution code:
#140b
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))

#print("0 :",list_A[0],"…",list_B[list_A[0]-1])
ans = list_B[list_A[0]-1]

for i in range(1,N,1):
    #print(i,":",list_A[i],"…",list_B[list_A[i]-1])
    ans += list_B[list_A[i]-1]
    
    if list_A[i-1]+1 == list_A[i]:
        ans += list_C[list_A[i]-2]
        
print(ans)

Submission status: Accepted

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


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

    print(ans)


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 = 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sat_sum = 0

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

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

for cnt in range(len(A)):
  if A[cnt] - before == 1:
    manzoku += C[before-1]
  before = A[cnt]

print(manzoku)

Submission status: Accepted

Solution code:
N = int(input())
grid = []
A = list(map(int, input().strip().split()))
Ai = [n-1 for n in A]
B = list(map(int, input().strip().split()))
C = list(map(int, input().strip().split()))
ans = 0
for i in range(N):
  ans += B[Ai[i]]
  if((i > 0) and (Ai[i] == Ai[i-1]+1)):
  	ans += C[Ai[i-1]]
print(ans)

Submission status: Accepted

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

point = 0

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

print point

Submission status: Accepted

Solution code:
N=int(input())
l_A=[int(e) for e in input().split(' ')]
l_B=[int(e) for e in input().split(' ')]
l_C=[int(e) for e in input().split(' ')]

result=sum(l_B)
for i,A in enumerate(l_A):
    if i == 0:
        A_pre=A
        continue
    if A == A_pre+1:
        result += l_C[A_pre-1]
    A_pre=A
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 range(n):
  ai = a[i] -1
  pre_ai = -10
  if i != 0:
    pre_ai = a[i-1] -1
    
  ans += b[ai]
  if ai - pre_ai == 1:
    ans += c[pre_ai]
    
print (ans)

Submission status: Accepted

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

full = 0
pre = 0
for i in range(N):
    a = A[i]
    b = B[a-1]
    if pre+1 == a and pre != 0:
        c = C[pre-1]
    else:
        c = 0

    full += b + c
    pre = a

print(full)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ret = 0
    for i in range(N):
        ret += B[A[i] - 1]
        if i > 0 and A[i] == A[i - 1] + 1:
            ret += C[A[i] - 2]
    print(ret)
    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 = [int(i) for i in input().split()]
bn = [int(i) for i in input().split()]
cn = [int(i) for i in input().split()]
ans = sum(bn)
for i in range(1,n):
  if an[i] == an[i-1] + 1:
    ans += cn[an[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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
ans = 0

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

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

print(ans)

Submission status: Accepted

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

ans=0
for i in range(N):
  ans+=B[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()))

tmp = -10
res = 0
for i in range(N):
  res += B[A[i]-1]
  
  if A[i] == tmp + 1:
    res += C[tmp-1]
    
  tmp = A[i]
  
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 = 0
j = 100
for i in A:
  sum += B[i-1]
  if i == j+1:
    sum += C[j-1]
    
  j = i

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
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()))

line = -20
satisfy = 0
for i in A:
    satisfy += B[i - 1]
    if line + 1 == i:
        satisfy += C[i - 2]
    line = i

print(satisfy)

Submission status: Accepted

Solution code:
N = int(input())
A, B, C = [int(i) for i in input().split()], [int(i) for i in input().split()], [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(raw_input())

x = lambda: map(int, raw_input().strip().split())

A = x()
B = x()
C = x()

points = 0
for i in xrange(n):
  points += B[A[i]-1]
  if i > 0 and A[i] == A[i-1] + 1:
    points += C[A[i]-2]

print points

Submission status: Accepted

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

for i in range (0,N-1):
  if A[i] + 1 == A[i+1]:
    s = 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()))
res = 0
for i in range(0,n):
    res += b[a[i]-1]
    if i != 0 and a[i-1]==a[i]-1:
        res += c[a[i-1]-1]

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

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

    before = A[i]

print(m)

Submission status: Accepted

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

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

print(r)

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

for i in range(n):
  num += b[a[i]-1]
  if i >= 1 and a[i]-a[i-1] == 1:
    num += c[a[i]-2]
    
print(num)

Submission status: Accepted

Solution code:
n = int(input())
ind = list(map(int, input().split()))
val = list(map(int, input().split()))
val1 = list(map(int, input().split()))
res = sum(val)
if ind[1] == ind[0] + 1:
    res += val1[ind[0]-1]
for i in range(1, len(ind)-1):
    if ind[i+1] == ind[i] + 1:
        res += val1[ind[i]-1]
print(res)

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(3)]

count_num=0
for i in l[0]:
    count_num += l[1][i-1]
for j in range(n-1):
    if (l[0][j])+1 == l[0][j+1]:
        count_num += l[2][(l[0][j])-1]
    
print(count_num)

Submission status: Accepted

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

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

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

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

bcount =0
ccount=0

for x in alist:    
    bcount+=blist[x-1]


for x in range (len(alist)-1):
    if alist[x+1]-alist[x]==1:
        temp = alist[x]-1
        ccount+=clist[temp]
        
print (bcount+ccount)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A_array = list(map(int, input().split()))
B_array = list(map(int, input().split()))
C_array = list(map(int, input().split()))
D_array = []
tmp = A_array[0]
for i in range(1,len(A_array)):
    if tmp + 1 == A_array[i]:
        D_array.append(C_array[tmp-1])
    tmp = A_array[i]

print(sum(B_array)+sum(D_array))

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

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 = [a-1 for a in A]
cnt = 0
tmp = -1000000
for a in A:
    cnt += B[a]
    if a-tmp==1:
        cnt+=C[a-1]
    tmp=a
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

sob = [int(x) for x in input().split()]
pts = [int(p) for p in input().split()]
exex = [int(h) for h in input().split()]

maxi = 0
ex = 0
maxi = sum(pts)
for i in range(n):
	if i != 0:
		if sob[i] - sob[i-1] == 1:
			maxi += exex[sob[i-1]-1]
print(maxi)

Submission status: Accepted

Solution code:
N=int(input())

A_str_list = input().split(' ')
A = [int(x) for x in A_str_list]
B_str_list = input().split(' ')
B = [int(x) for x in B_str_list]
C_str_list = input().split(' ')
C = [int(x) for x in C_str_list]

satis = 0
prev_eat = -2
for ii in range(N):
    satis += B[A[ii]-1]
    if prev_eat + 1 == A[ii]-1 and 0 < ii:
        satis += C[prev_eat]
        #print(C[A[ii]-1])
    prev_eat = A[ii]-1
print(satis)

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

bonus = 0

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



from functools import reduce

print(reduce(lambda x,y: x+y,B) + bonus)

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

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

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    ans = sum(B)
    before = -inf
    for a in A:
        if before + 1 == a:
            ans += C[before-1]
        before = a
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()

anums = getList()
bnums = getList()
cnums = getList()

anums = [-100] + anums

ans = 0
for i, j in zip(anums, anums[1:]):
    ans += bnums[j-1]
    if j == i + 1:
        ans += cnums[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>0 and a[i-1]+1==a[i]:
        ans+=c[a[i-1]-1]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
A = list(map(int,(input().split())))
B = list(map(int,(input().split())))
C = list(map(int,(input().split())))
S = 0
before = 100

for i in range(n):
    S += B[A[i]-1]
    if A[i]-1 == before + 1:
        S += C[before]
    before = 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 += 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 = 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 = list(map(int,input().split()))
B_list = list(map(int,input().split()))
C_list = list(map(int,input().split()))

satisfaction = 0

for i in range(N):
    satisfaction += B_list[A_list[i] - 1]
    if (i != N-1 and A_list[i + 1] == A_list[i] + 1):
        satisfaction += C_list[A_list[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()))

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 solve(string):
    n, *abc = map(int, string.split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    ans = [b[a0 - 1] + c[a0 - 1] if a0 + 1 == a1 else b[a0 - 1] for a0, a1 in zip(a, a[1:])]
    return str(sum(ans) + b[a[-1] - 1])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))

Submission status: Accepted

Solution code:
N = int(input())
cook_list = list(map(int,input().split()))
satisfy_list = list(map(int,input().split()))
plus_satisfy_list = list(map(int,input().split()))

sum_point = 0
prev_num = 0

for now_num in cook_list:
  sum_point += satisfy_list[now_num - 1]
  if (now_num - prev_num) == 1 and (now_num > 1):
    sum_point += plus_satisfy_list[prev_num - 1]
  prev_num = now_num
  
print(sum_point)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import pandas as pd
# import numpy as np

# d = pd.read_csv("useful.csv", usecols = ["Q133", "Q134", "Q146"])

# #l = d["Q133"]
# l = d["Q146"]
# bad = []
# good = [] 
# for i in range(1, 56):
# 	if int(l[i][0]) >= 4:
# 		good.append(i)
# 	else:
# 		bad.append(i)
# print(bad, good)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_arr = list(map(lambda n: int(n), input().split()))
B_arr = list(map(lambda n: int(n), input().split()))
C_arr = list(map(lambda n: int(n), input().split()))
sum = 0

for i, a in enumerate(A_arr):
    if (i != 0) and (A_arr[i-1]+1 == a):
        sum += B_arr[a-1] + C_arr[A_arr[i-1]-1]
    else:
        sum += B_arr[a-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):
  ans+=B[A[i]-1]
  if (1<=i) and A[i-1]==A[i]-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()))
cnt=0
before=50
for i in A:
    cnt+=B[i-1]
    if before+1==i:cnt+=C[i-2]
    before=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

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

Submission status: Accepted

Solution code:
N = int(input())
Ai = [int(i) for i in input().split(" ")]
Bi = [int(i) for i in input().split(" ")]
Ci = [int(i) for i in input().split(" ")]

res = 0
pre_i = None
for i in Ai:
  res += Bi[i-1]
  if pre_i and i == pre_i+1:
    res += Ci[i-2]
  pre_i = i

print(res)

Submission status: Accepted

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

for i in range(1, len(a)):
    #print("i", i)
    if (a[i] - a[i-1]) == 1:
        #print("b", b[a[i-1]-1])
        r += b[a[i-1]-1]
        #print("c", c[a[i-1]-1])
        r += c[a[i-1]-1]
    else:
        r += b[a[i-1]-1]
       # print("b", b[a[i-1]-1])
    if i == (len(a)-1):
        r += b[a[i]-1]
print(r)

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

manzoku = 0
before = -10
for i in A:
    i = i-1
    manzoku += B[i]
    if before+1 == i:
        manzoku +=C[i-1]
    before = i
print(manzoku)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split());print(sum(a[n:n+n])+sum(a[i-n]for i,j in zip(a,a[1:n])if j==i+1))

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

Submission status: Accepted

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

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

print(result)