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

score = sum(B)

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

print(score)

Submission status: Accepted

Solution code:
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]
C_list = [int(i) for i in input().split()]

satisfying = 0
prev_dish = A_list[0]
for i in range(N) :
    current_dish = A_list[i]
    satisfying += B_list[current_dish-1]
    # print("get", B_list[current_dish-1])

    if (prev_dish + 1 == current_dish) :
        satisfying += C_list[current_dish-2]
        # print("additional get",C_list[current_dish-2])

    prev_dish = current_dish

print(satisfying)

Submission status: Accepted

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

s = 0
a.append(0)

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

print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li_())
b = list(li())
c = list(li())

ans = 0
bef = -10

for i, ai in enumerate(a):
    ans += b[ai]
    if bef == (ai - 1):
        ans += c[ai - 1]

    bef = ai

print(ans)

Submission status: Accepted

Solution code:
a=input()
b=list(map(int,input().split()))
i=list(map(int,input().split()))
j=list(map(int,input().split()))
k=0
for c in b:
    k+=i[c-1]
    d=b.index(c)
    if not d==0 and b[d-1]==c-1:
        k+=j[c-2]
        
print(k)

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(len(C)):
  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()))

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:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 10 01:44:47 2019

"""

point = 0
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(0,N):
    point = point + B[i]
    if(i >= 1):
        if(A[i]-A[i-1] == 1):
            point = 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()))

before = -1
result = 0

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

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

pre = -1
for i in a:
  sat += b[i-1]
  #print(b[i-1])
  if pre + 1 == i:
    sat += c[pre-1]
    #print("c", c[pre-1])
  pre = i
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
for i in range(N):
  ans += B[A[i]-1]
for j in range(N-1):
  if A[j] + 1 == A[j+1]:
    ans += C[A[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())
Ai = input().split()
Bi = input().split()
Ci = input().split()
tA = 0
ret = 0
for A in Ai:
    ret += int(Bi[int(A) - 1])
    if(tA != 0 and tA + 1 == int(A)):
        ret += int(Ci[int(A) - 2])
    tA = int(A)
print(ret)

Submission status: Accepted

Solution code:
#Buffet

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

num = int(input())
dish = [int(item)-1 for item in input().split()]
satis = [int(item) for item in input().split()]
additional = [int(item) for item in input().split()]

sum = 0
prev = num + 10

for item in dish:
    sum += satis[item]
    if item == prev +1:
        sum += additional[prev]
    prev = item
    
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-1):
  val=A[i]
  sat=B[val-1]
  if A[i+1]-A[i]==1:
    ans+=(sat+C[val-1])
  else:
    ans+=sat
ans+=B[A[-1]-1]
print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    B = string_to_int(inputs[1])
    C = string_to_int(inputs[2])
    s = 0
    prev_i = -1
    for i in A:
        i -= 1
        s += B[i]
        if prev_i != -1 and i == prev_i + 1:
            s += C[prev_i]
        prev_i = i

    return s


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(3))
    print(ret)

Submission status: Accepted

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


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

print(happy_sum)

Submission status: Accepted

Solution code:
# B - Buffet
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += Blist[Alist[i] - 1]
    if i > 0 and Alist[i] - Alist[i - 1] == 1:
        ans += Clist[Alist[i - 1] - 1]
    
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
B = [int(_) for _ in stdin.readline().rstrip().split()]
C = [int(_) for _ in stdin.readline().rstrip().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()))
manzoku = 0

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

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


print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=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:
#!/usr/bin/env python3
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
pre=-1
ans=0
for A in a:
    ans+=b[A-1]
    if pre==A-1:
        ans+=c[A-2]
    pre = A
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()))

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
line = list(map(int,input().split()))
p = list(map(int,input().split()))
r = list(map(int,input().split()))
ans = 0
count = -30
for i in line:
    if count == i-1:
        ans += r[i-2]
    count = i
    ans += p[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()))
#
s = 0
next_i = 0
opt = 0
for i in range(0,n):
    s = s + b[a[i]-1]
    if a[i] == next_i:
        s = s + opt
    next_i = a[i]+1
    if next_i <= n:
        opt = c[a[i]-1]
    else:
        opt = 0

print(s)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
 
s = sum(b)
for i in range(len(a)-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()))

s = sum(b)
for i in range(len(a)-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()))
ans = 0
for i in range(len(A)):
    ans += B[A[i] - 1]
    if i == len(A) - 1:
        break
    else:
        if A[i + 1] == A[i] + 1:
            ans += C[A[i] - 1]
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = 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()))
t=0
k=-1
for i in A:
  t+=B[i-1]
  if k+1==i:
    t+=C[k-1]
  k=i
print(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()))
score=0
for i in range(n):
  if i==0:
    score+=b[a[i]-1]
    #print("first ",a[i],b[a[i]-1])
  else:
    if a[i]-a[i-1]==1:
      score+=b[a[i]-1]+c[a[i-1]-1]
      #print("order ",a[i],b[a[i]-1]+c[a[i-1]-1])
    else:
      score+=b[a[i]-1]
      #print("ordinaly ",a[i],b[a[i]-1])
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()))

value = 0
last = None
for a in A:
    idx = a - 1
    value += B[idx]
    if last is not None and last + 1 == idx:
        value += C[last]
    last = idx
print(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()))

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

print(ans)

Submission status: Accepted

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

tmp = -1
for b in A:
    total += B[b - 1]
    if (b - tmp == 1):
        total += C[tmp - 1]
    tmp = b

print(total)

Submission status: Accepted

Solution code:
menu_num = int(input())
order = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
additional = list(map(int, input().split()))

score = int()
before_order = int()
for x in range(menu_num):
    score += manzoku[order[x]-1]
    try:
        if order[x]+1 == order[x+1]:
            score += additional[order[x]-1]
    except:
        pass

print(score)

Submission status: Accepted

Solution code:
# 整数Nの入力
N = int(input())
# 料理番号の数列Aの入力
A = list(map(int, input().split()))
# 満足度の数列Bの入力
B = list(map(int, input().split()))
# 満足度の数列Cの入力
C = list(map(int, input().split()))
# 満足度の合計
Sum = 0

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
abc = []
for i in range(3):
  abc += [[int(i) for i in input().split()]]
ps = sum(abc[1])
for i in range(n-1):
  if abc[0][i]+1 == abc[0][i+1]:
    ps += abc[2][abc[0][i]-1]
print(ps)

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

previous = -1
score = 0

for i in range(N):
    score += B[A[i]-1]
    if i >= 1 and A[i] == previous + 1:
        score += C[previous-1]
    previous = A[i]

print(score)

Submission status: Accepted

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

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


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

satisfy = 0
satisfy += Bs[As[0]-1]

for now, prev in zip(As[1:], As[:-1]):
  satisfy += Bs[now-1]
  if now == prev + 1:
    satisfy += Cs[prev-1]

print(satisfy)

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

Submission status: Accepted

Solution code:
'''
 Author: fuad Ashraful Mehmet
 University of Asia Pacific
 created :09 Sep 2019 7.33 PM
 Category :   from At Coder

 Problem:https:  
'''

 
 

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)
#fuck python if you can its just owsam

Submission status: Accepted

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

MOD = 10 ** 9 + 7

N = int(input())
AN = list(map(int, input().split()))
BN = list(map(int, input().split()))
CN = list(map(int, input().split()))

ans = sum(BN)
for i in range(N - 1):
    if AN[i + 1] == AN[i] + 1:
        ans += CN[AN[i] - 1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_lis = list(map(int,input().split()))
b_lis = list(map(int,input().split()))
c_lis = list(map(int,input().split()))
 
s = 0
 
for i in range(n-1):
  if a_lis[i+1] - a_lis[i] == 1:
    s += c_lis[a_lis[i]-1]
print(sum(b_lis)+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 
#ループカウンタ
counter =0

for i in range(0,N):
    #まずはその料理の満足度を足す
    ans += B[A[i]-1]
    #食べた料理が連番だった場合Cの値がプラスされる
    if((counter >=1) and (A[i]-A[i-1]==1)):
        #処理(C[A[i-1]-1]を足す処理）
        ans += C[A[i-1]-1]
    counter +=1

print(ans)

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()))
s = sum(bb[a-1] for a in aa)
for i in range(n-1):
    if aa[i]+1 == aa[i+1]:
        s += cc[aa[i]-1] 
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = input().split(" ")
b = input().split(" ")
c = input().split(" ")
d = int(b[int(a[0])-1])

for i in range(n-1):
    if int(a[i]) + 1 == int(a[i + 1]):
        d += int(b[int(a[i+1])-1]) + int(c[int(a[i])-1])
    else:
        d += int(b[int(a[i+1])-1])
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]
cl = [int(i) for i in input().split()]

for i in range(len(al)-len(cl)):
    cl.append(0)


v = sum(bl)
memo = -2
for i in al:
    if i == memo +1:
        v += cl[memo-1]
    memo = i
    
print(v)

Submission status: Accepted

Solution code:
import math
N = int(input())

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

point = 0
for i in range(N):

	point += (B[A[i] - 1])

	if i < N - 1 and A[i + 1] - A[i] == 1:
		point+=C[A[i] - 1]

print('%d' % point)

Submission status: Accepted

Solution code:
N=int(input())
order = list(map(int, input().split()))
sati1 = list(map(int, input().split()))
sati2 = list(map(int, input().split()))

score=sati1[order[0]-1]
for i in range(1,N):
    score+=sati1[order[i]-1]
    if order[i]-order[i-1]==1:
        score+=sati2[order[i-1]-1]

print(score)

Submission status: Accepted

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

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

print(ans+sum(B))

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline())
A = list((int(wd) for wd in stdin.readline().split()))
B = list((int(wd) for wd in stdin.readline().split()))
C = list((int(wd) for wd in stdin.readline().split()))

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

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

i = 0
while n>i:
    if i != 0:
        point += b[a[i]-1]
        if a[i]-a[i-1] == 1:
            point += c[a[i-1]-1]
    else:
        point = b[a[i]-1]
    
    i += 1
print(point)

Submission status: Accepted

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

out = 0
last = None
for i in A:
  i -= 1
  out += B[i]
  if last == i - 1:
    out += C[last]
  last = i
print(out)

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

copy = A[0]
for a in A:
  satisfaction += B[a-1]

  if a-copy == 1:
    satisfaction += C[a-2]
  
  copy = a

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

Submission status: Accepted

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

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

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

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):
    ans += b_list[a_list[i]-1]
    if i > 0 and (a_list[i-1] == a_list[i] - 1):
        ans += c_list[a_list[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()))

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
prev_eat = None
ans = 0
for i in range(N):
    dish_idx = A[i]
    ans += B[dish_idx-1]
    if prev_eat is not None and prev_eat + 1 == dish_idx:
        ans += C[prev_eat-1]
    prev_eat = dish_idx
print(ans)

Submission status: Accepted

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

ans = 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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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 = 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 = 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(len(A)):
    sat += B[A[i] - 1]

    if i > 0 and A[i-1] + 1 == A[i]:
        sat += C[A[i-1] - 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()))
total=0
an0=-1
for an in a:
    total+=b[an-1]
    if an-1==an0:
        total+=c[an0-1]
    an0=an

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(lambda x:int(x) - 1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
happy = 0
lastDish = -2
for i in A:
    happy += B[i]
    if i - 1 == lastDish:
        happy += C[i - 1]
    lastDish = i
print(happy)

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

Submission status: Accepted

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

ans=0
for i in range(N):
    ans+=B_list[i]
    if i<N-1:
        if A_list[i+1]-A_list[i]==1:
            ans+=C_list[int(A_list[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
m=-1
for i in a:
  if(i-m==1):
    score+=c[i-2]
  score+=b[i-1]
  m=i
print(score)