Problem:


Score : 200 points

Problem Statement

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.

The i-th dish (1 \leq i \leq N) he ate was Dish A_i.

When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.

Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

All values in input are integers.

2 \leq N \leq 20

1 \leq A_i \leq N

A_1, A_2, ..., A_N are all different.

1 \leq B_i \leq 50

1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

Sample Input 1

3
3 1 2
2 5 4
3 6

Sample Output 1

14

Takahashi gained 14 satisfaction points in total, as follows:

First, he ate Dish 3 and gained 4 satisfaction points.

Next, he ate Dish 1 and gained 2 satisfaction points.

Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.

Sample Input 2

4
2 3 4 1
13 5 8 24
45 9 15

Sample Output 2

74

Sample Input 3

2
1 2
50 50
50

Sample Output 3

150



Sample input:
3
3 1 2
2 5 4
3 6


Sample output:
14

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(int, input().split())) # N番目に食べた料理
B = list(map(int, input().split())) # N番目に食べた料理の満足度
C = list(map(int, input().split())) # N番目の直後にN+1番目を食べた時の追加の満足度

point = sum(B)

for i in range(1, len(A)):
    if A[i] - A[i-1] == 1:
        point += C[A[i-1]-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()))
point = sum(B)
for i, AA in enumerate(A[0:N-1]):
    if AA + 1 == A[i+1]:
        point = point + C[AA-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()))
sat = 0
for i in range(n):
  j = a[i]-1
  sat += b[j]
  if 0<i<=n-1 and a[i]-a[i-1]==1:
    sat += c[j-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
b = -1
for a in A:
        ans += B[a - 1]
        if b + 1 == a:
                ans += C[a -2]
        b = 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()))

sati = 0
for i in range(N):
    if i != 0:
        if a[i] == a[i-1] + 1:
            sati += c[a[i-1]-1]
    sati += b[a[i]-1]

print(sati)

Submission status: Accepted

Solution code:
N = int(input())
AA = input()
BB = input()
CC = input()

A = [int(i) for i in AA.split()]
B = [int(i) for i in BB.split()]
C = [int(i) for i in CC.split()]

score = 0
prev = "None"
for i in range(N):
#    print(i)
    a = A[i]
#    print(a)
    score += B[a-1]
#    print(B[a-1])

    if prev != "None" and prev == a - 1:
        score += C[prev - 1]
    prev = a
    
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()))
x=0
for i in range (N-1):
  if A[i]+1 == A[i+1]:
    x= x+B[i]+C[A[i]-1]
  else:
    x= x+B[i]
print(x+B[N-1])

Submission status: Accepted

Solution code:
n = int(input())
order = list(map(lambda x : int(x)-1, input().split()))
sats = list(map(int, input().split()))
bonus = list(map(int, input().split()))

bef = 21
ans = 0
for i in order:
  ans += sats[i]
  if i == bef + 1:
    ans += bonus[i - 1]
  bef = i

print(ans)

Submission status: Accepted

Solution code:
while True:
    try:
        n = int(input())
        ans = 0
        lsta = list(map(int, input().split()))
        lstb = list(map(int, input().split()))
        lstc = list(map(int, input().split()))
        last = lsta[0]
        for i in range(n):
            ans += lstb[lsta[i]-1]
            if last + 1 == lsta[i]:
                ans += lstc[last-1]
            last = lsta[i]
        print(ans)
    except:
        break

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

manzokudo = 0
for B in Blist:
    manzokudo += B
    
for i in range(0, N-1):
    if Alist[i]+1 == Alist[i+1]:
        manzokudo += Clist[Alist[i]-1]

print(manzokudo)

Submission status: Accepted

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

ABC[2].append(0)

flg = -100
cnt = 0
for n in range(N):
    cnt += ABC[1][n]
    if flg == ABC[0][n] - 1:
      cnt += ABC[2][flg - 1]
    flg = ABC[0][n]
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
temp = []
for i in range(1, N):
    if A[i]-1 == A[i-1]:
        if not A[i]-2 < 0:
            ans += C[A[i]-2]
ans += sum(B)        
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()))

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    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):
        if i > 0:
            if A[i] - A[i-1] == 1:
                res += C[A[i-1]-1]
        res += B[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()))

ALL = 0

for j,k in enumerate(A):
    len_A = len(A)
    ALL += B[k-1]
    if j + 1 == len_A:
        pass
    else:
        if A[j+1] - k == 1:
            ALL += C[k-1]
print(ALL)

Submission status: Accepted

Solution code:
a = int(input())
List_a=list(map(int,input().split()))
List_b=list(map(int,input().split()))
List_c=list(map(int,input().split()))
B = 0
count = 0
key = 0
for i in List_a:
  B += List_b[i-1]
  if count > 0 and key+1 ==i:
    B += List_c[i-2]
  key = i
  count += 1
 
print(B)

Submission status: Accepted

Solution code:
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
adds = list(map(int, input().split()))

pre = 100
total = 0
for dish in dishes:
  if dish == pre + 1:
    total += points[dish-1] + adds[pre-1]
    pre = dish
  else:
    total += points[dish-1]
    pre = dish

print(total)

Submission status: Accepted

Solution code:
N = int(input())

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

result = 0
for i, x in enumerate(A):
    result += B[x-1]
    if i == N-1:
        break
    if x+1 == A[i+1]:
        result += C[x-1]
        
print(result)

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())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))

ans = sum(list_b)

for i in range(N-1):
    if(list_a[i+1] == list_a[i]+1 ):
        ans = ans + list_c[list_a[i]-1]

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int, input().split())))
B=np.array(list(map(int, input().split())))
C=np.array(list(map(int, input().split())))

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

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

print(sum(B)+plus)

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 = ans + B[i]

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

Submission status: Accepted

Solution code:
N = int(input())

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

a = [ i-1 for i in a]

ans = 0
pre = -2
for x in a:
    ans += b[x]

    if x == (pre + 1):
       ans += c[pre]

    pre = x

print(ans)

Submission status: Accepted

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

bonus = 0
for i, no in enumerate(A):
    
    if i == len(A) - 1:
        break
    elif no + 1 == A[i + 1]:
        bonus += C[no - 1]

print(sums + 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()))
res=0
for i in range(len(A)):
    res += B[A[i]-1]
    if i > 0 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()))
old_a = -1
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
#B

n = int(input())

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

a.insert(0,0)
b.insert(0,0)
c.insert(0,0)
ans = sum(b)

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

Submission status: Accepted

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

man = 0
k = 0
for i in a:
  man += b[i-1]
  if i == k:
    man += c[i-2]
  k = i + 1

print(man)

Submission status: Accepted

Solution code:
n=int(input())
a_box=list(map(int,input().split()))
b_box=list(map(int,input().split()))
c_box=list(map(int,input().split()))

count=0
number=-10
for i in a_box:
    i=i-1
    count +=b_box[i]
    if number+1==i:
        count +=c_box[number]
    number=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()))
#print(N,A,B,C)

satisfy = sum(B)
con=[]

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    con.append(A[i]-1)

#print(con)

for i in con:
  satisfy += C[i]
  #print(i, C[i])

print(satisfy)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(lambda x : int(x) -1 ,input().split()))
b = list(map(int,input().split()))
c = [0]
c.extend(list(map(int,input().split())))
prev = 20
ans = 0
for i in range(n):
    if a[i] -1 == prev:
        ans += b[a[i]] + c[a[i]]
    else:
        ans += b[a[i]]
    prev = a[i]
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()]
ans = 0
pre = -1
for i in A:
    ans += B[i-1]
    if pre == i-1:
        ans += C[i-2]
    pre = i
print(ans)

Submission status: Accepted

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

point = 0
point = sum(B)

for i in range(len(A)-1):
    if A[i+1] - A[i] == 1:
        point += C[A[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()))

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

history = list()
sat = 0
for i in range(N):
  a = A[i]
  b = B[a - 1]
  sat += b
  #print(len(history) == 0)
  if len(history) == 0:
    pass
  elif history[-1] == a - 1:
    sat += C[a-2]
  history.append(a)
    
print(sat)

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

def main(a_list, b_list, c_list):
    before_element = 999
    result = 0
    for element in a_list:
        result += b_list[element-1]
        if element == before_element + 1:
            result += c_list[before_element-1]
        before_element = element
    return result

print(main(a_list, b_list, c_list))

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

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

print(sum(B) + additional)

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

print(sum)

Submission status: Accepted

Solution code:
a = int(input())

s = [input().split() for i in range(3)]

count =  0

num = s[0]
point = s[1]
bonus = s[2]


for p in range(int(len((num)))):
    count += int(point[int(num[p])-1])
    #print(count)

for q in range(int(len(num))-1):
    if int(num[q+1]) - int(num[q]) == 1:
        count += int(bonus[int(num[q])-1])
       # print(count)
    else:
        pass
print(count)

Submission status: Accepted

Solution code:
N = int(input())
foods = [int(i) for i in input().split()]
eff = sum([int(i) for i in input().split()])
plus = [int(i) for i in input().split()]
tmp = 0
for i, f in enumerate(foods):
  if i == 0:
    tmp = f
  elif f - tmp == 1:
    eff += plus[f-2]
    tmp = f
  else:
    tmp = f
print(eff)

Submission status: Accepted

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

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

Submission status: Accepted

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

manzoku=0

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

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

print(num)

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

#print(A)
#print(B)
#print(C)
#print(sum(B))

testA = A + [0]
testB = [0] + A
#print(testA)
#print(testB)
#print((np.array(testA) - np.array(testB)))
#print(list(((np.array(testA) - np.array(testB)) == 1))[1:])
#print(np.array(A)[((np.array(testA) - np.array(testB)) == 1)[1:]])
#print(np.array(C)[np.array(A)[((np.array(testA) - np.array(testB)) == 1)[1:]]-1])

print(sum(B) + sum(np.array(C)[np.array(A)[((np.array(testA) - np.array(testB)) == 1)[1:]]-1]))

Submission status: Accepted

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

point = 0
for j in range(n):
    if j >= 1:
        if c_l[0][j] == c_l[0][j-1] + 1:
            point += c_l[1][c_l[0][j]-1]
            point += c_l[2][c_l[0][j]-2]
        else:
            point += c_l[1][c_l[0][j]-1]
    elif j == 0:
        point += c_l[1][c_l[0][j]-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 == 0:
        continue
    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()))

arr = []
for i in range(len(a)):
    arr.append(b[a[i]-1])
    if i > 0:
        if a[i] == a[i-1] + 1:
            arr.append(c[a[i-1]-1])
    
print(sum(arr))

Submission status: Accepted

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

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

print(M)

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()))
cscore =0
for i in range(n-1):
   if alist[i+1]==alist[i]+1:
      cscore =cscore+clist[alist[i]-1]
print(sum(blist)+cscore)

Submission status: Accepted

Solution code:
n = int(input())
ryouri = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
tuika = list(map(int, input().split()))

base = 0
for i in range(n):
  base += manzoku[i]

for i in range(n-1):
  if ryouri[i+1]-ryouri[i] == 1:
    base += tuika[ryouri[i]-1]

print(base)

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()))
cscore =0
for i in range(n-1):
   if alist[i+1]==alist[i]+1:
      cscore =cscore+clist[alist[i]-1]
print(sum(blist)+cscore)

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):
    j = a[i]-1
    ans += c[j]

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

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


count = 0

for i in xrange(n):
    #print i,a[i], b[a[i]-1]  
    count += b[a[i]-1]
    if i > 0 and a[i] == a[i-1] + 1:
        count += c[a[i-1]-1]
        #print c[a[i-1]-1]
print count

Submission status: Accepted

Solution code:
n = int(input().rstrip())
eat = [ int(ch) for ch in input().rstrip().split(' ') ]
bs = [ int(ch) for ch in input().rstrip().split(' ') ]
cs = [ int(ch) for ch in input().rstrip().split(' ') ]

pre = -1
sum = 0
for k in eat:
  sum += bs[k - 1]
  #print(pre, k)
  if k - pre == 1:
    sum += cs[pre - 1]
  pre = k
  
print(sum)

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

x = a[0]
cnt += b[a[0]-1]

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

Submission status: Accepted

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

total = 0
for i in range(n):
    total += b[a[i] - 1]

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())
lista = [int(i) for i in input().split()]
listb = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

ans1=sum(listb)
ans2=0
for i in range(n-1):
    if lista[i+1]==lista[i]+1:
        ans2=ans2+listc[lista[i]-1]
ans=ans1+ans2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())


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

mae = -1
point = 0

for i, a in enumerate(As):
    if mae + 1 == a:
        point += Cs[(a - 1)-1]
    point += Bs[a-1]
    mae = a

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

    b4 = a[i]
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()))

manzoku = 0
before_A = 0
for A in A_list:
    manzoku += B_list[A-1]
    if before_A == 0:
        before_A = A
    elif A == before_A + 1:
        manzoku += C_list[before_A-1]
        before_A = A
    else:
        before_A = A
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()))

s = 0

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

s+=b[a[n-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()))
ans = 0

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

count=0

for b in B:
  count+=b

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

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
C_list = list(map(int,input().split()))
ans = sum(B_list)

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

answer = 0

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

answer += sum(B_list)

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
route = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
plus_s = list(map(int, input().split()))

ans = 0
route_cnt = None
for i in range(N):
    a = route[i]
    ans += satisfaction[a - 1]
    if route_cnt is None:
        route_cnt = a
        continue
    if a - route_cnt == 1:
        ans += plus_s[route[i] - 2]
    route_cnt = 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()))
total = 0
oldx = 100

for i in range(N):
    x=A[i]-1
#    print(B[x], x, oldx)
    total += B[x]
    if x == oldx +1:
            total += C[x-1]
#            print(C[x-1], "pass")
    oldx = x
#    print(x, oldx)
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()))

#満足度D
d = [0 for k in range(n)]
d[0]=b[a[0]-1]

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
tmp = [list(map(int, input().split())) for _ in range(3)]
A = tmp[0]
B = tmp[1]
C = tmp[2]
A = list(map(lambda x:x-1,A))
result = B[A[0]]
for i in range(1,N):
  result += B[A[i]]
  if (A[i]-1)==A[i-1]:
    result += C[A[i-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()))

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

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

sum = B[A[0]]

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

print(sum)

Submission status: Accepted

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

score = 0 
order = -1
for i in range(n):
  score += b[i]
  _order = a[i]
  if order+1 == _order:
    score += c[order - 1]
  order = _order
  

print(score)

Submission status: Accepted

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


a = sum(B2)
for i in range(N-1):
    if int(A[i])+1 == int(A[i+1]):
        b = int(A[i])-1
        a += int(C[b])
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
        lines.append(input())
        lines.append(input())

    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = int(lines[0])

    a = [int(e) for e in lines[1].split(" ")]
    b = [int(e) for e in lines[2].split(" ")]
    c = [int(e) for e in lines[3].split(" ")]

    return (n, a, b, c)


def solve(n, a, b, c):

    total = 0
    previous_dish_num = -1
    for i in range(n):
        dish_num = a[i]
        total = total + b[dish_num-1]
        if previous_dish_num + 1 == dish_num:
            total = total + c[previous_dish_num-1]
        previous_dish_num = dish_num

    return total


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)

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()))
#print(n)
#print(a)
#print(b)
#print(c)
total=0
pre=0
for i in range(n):
  total+=b[i]
  if pre+1==a[i] and pre!=0:
    total+=c[pre-1]
  pre=a[i]
print(total)

Submission status: Accepted

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


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

    if i != n - 1:
        if a[i+1] - a[i] == 1:
            ans += c[a[i] - 1]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
# スペース区切りの整数の入力
a = map(int, input().split())
alist = list(a)

b = map(int, input().split())
blist = list(b)

c = map(int, input().split())
clist = list(c)
sum = 0
zenkai = 0
for ryouri in alist:
    sum += blist[ryouri-1]
    if zenkai == 0:
        zenkai = ryouri
    else:
        if zenkai+1 == ryouri:
            sum += clist[zenkai-1]
        zenkai = ryouri

print("{}".format(sum))

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

print(ans)