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())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))

answer=0
old_ryori=-100
for i in range(N):
  new_ryori=alist[i]-1
  answer+=blist[new_ryori]
  if old_ryori+1==new_ryori:
    answer+=clist[new_ryori-1]
  old_ryori=new_ryori
    
print(answer)

Submission status: Accepted

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

sat = 0
prev_ryouri = -10

for i in range(n):
  ryouri = A[i] - 1
  sat += B[ryouri]
  if prev_ryouri+1 == ryouri:
    sat += C[prev_ryouri]
    
  prev_ryouri = ryouri


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()))
# print(N, A, B, C)

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

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

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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):
    dinner = A[i] - 1
    ans += B[dinner]
    if i != N-1:
        if dinner + 1 == A[i+1] - 1:
            ans += C[dinner]

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
before_A = -1
for A in Alist:
    ans += Blist[A-1]
    if before_A+1 == A:
        ans += Clist[before_A-1]
    before_A = A

print(ans)

Submission status: Accepted

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

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

pre = -100
c = 0
for a in A:
  i = a - 1
  c += B[i]
  if pre == a - 1:
    c += C[i - 1]
  pre = a
print(c)

Submission status: Accepted

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

#print(a,b,c)

result=0
temp=30
for item in a:
  result+=b[item-1]
  if item==temp+1:
    result+=c[temp-1]
  
  temp=item
  
print(result)

Submission status: Accepted

Solution code:
n = int(input())
As = list(map(int,input().split()))
ans = sum(map(int,input().split()))
c = list(map(int,input().split()))
for i in range(n-1):
  if As[i+1] ==As[i] +1:
    ans += c[As[i]-1]
  else:
    pass
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=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)
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] == A[i + 1] - 1:
        ans += C[A[i] - 1]

print(ans)

Submission status: Accepted

Solution code:
num = int(input())

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

count = 0

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

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

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

print(sum(l))

Submission status: Accepted

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

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

print(point)

Submission status: Accepted

Solution code:
n = int(input())
meals = list(map(int, input().split()))
suts = list(map(int, input().split()))
add_suts = list(map(int, input().split()))

total = 0
pre = None
for meal in meals:
    total += suts[meal-1]
    if pre is not None and pre + 1 == meal:
        total += add_suts[pre-1]
    pre = meal
print(total)

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

manzoku = 0
prev = -1
for a in AList:
    manzoku += BList[a-1]
    if prev + 1 == a:
        manzoku += CList[prev-1]
    prev = a
print(manzoku)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input().strip())
alist = list(map(int,input().strip().split()))
blist = list(map(int,input().strip().split()))
clist = list(map(int,input().strip().split()))

sat = 0
prenum = 10000
for i in range(N):
	num = alist[i]-1
	sat = sat+blist[num]
	if num==prenum+1:
		sat = sat+clist[prenum]

	prenum = num


print(sat)

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

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

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

ans = 0
prv = -2
for i in range(n):
	#print(i, ans)
	ans += bb[aa[i] - 1]
	if aa[i] - 1 == prv + 1:
		ans += cc[prv]
	prv = aa[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] == a[i+1]-1:
        ans += c[a[i]-1]
  
print(ans)

Submission status: Accepted

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

ans = sum(b)
for p, q in zip(a, a[1:]):
    if p+1 == q:
        ans += c[p-1]
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))
    C=list(map(int, input().split()))
    prev_a = -1
    ans = 0
    for a in A:
        ans += B[a-1]
        if prev_a + 1 == a:
            ans += C[prev_a-1]
        prev_a = a
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
"""
N = int(input())
A, B = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(M)]
A = list(map(int,input().split()))
"""

N = int(input())
A = [int(i)-1 for i in 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]]
    #print(i, A[i], C[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()))
j = -2
ans = 0
for i in a:
    if j == i-1:
        ans += c[i-2]
    j = i
ans += sum(b)
print(ans)

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
a=l[:n];b=l[n:2*n];c=l[2*n:]
bef=a[0]
ans=b[bef-1]
for i in a[1:]:
	ans+=b[i-1]
	if i==bef+1:
		ans+=c[i-2]
	bef=i
print(ans)

Submission status: Accepted

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

ans = sum(B)

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

print(ans)

Submission status: Accepted

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

answer = 0

for i in range(len(A)):                                                                                                                                                                                     
    answer += B[A[i]-1]                                                                                                                                                                                     
                                                                                                                                                                                                            
    if i < len(A) - 1:                                                                                                                                                                                      
        if A[i] + 1 == A[i+1]:                                                                                                                                                                              
            answer += C[A[i]-1]                                                                                                                                                                             

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
meshi = [0] * 100
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 != 0 and 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()))

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

Submission status: Accepted

Solution code:
def solve():
    a, b, c = read()
    result = think(a, b, c)
    write(result)


def read():
    n = read_int(1)[0]
    a = read_int(n)
    b = read_int(n)
    c = read_int(n - 1)
    return a, b, c


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, c):
    satisfaction = 0
    prev = -1
    for e in a:
        satisfaction += b[e - 1]
        if prev == e - 1:
            satisfaction += c[prev - 1]
        prev = e
    return satisfaction


def write(result):
    print(result)


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    # import sys
    # sys.setrecursionlimit(10000)
    solve()

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

Submission status: Accepted

Solution code:
n=int(input())
an=list(map(int,input().split()[:n]))
bn=list(map(int,input().split()[:n]))
cn=list(map(int,input().split()[:n-1]))

ret=sum(bn)

for i in range(n-1):
    if an[i] +1 ==an[i+1]:
        ret+=cn[an[i]-1]

print(ret)

Submission status: Accepted

Solution code:
n = int(input())

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

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

c = [0] + list(map(int, input().split()))

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

    tmp = i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
ans = 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)
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(1,len(a)):
  if a[i-1]+1 == a[i]:
    ans += c[a[i]-2]
    
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    A = LI()
    B = LI()
    C = LI()


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

    print(manzoku)


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,A,B,C)

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

Submission status: Accepted

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

ans = sum(B)
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 = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in 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-1]-1]

print(ans)

Submission status: Accepted

Solution code:
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
A=get_array()
B=get_array()
C=get_array()
score=0
for i in range(n):
  score+=B[A[i]-1]
  if i!=0:
    if A[i]==A[i-1]+1:
      score+=C[A[i-1]-1]
print(score)

Submission status: Accepted

Solution code:
#B
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
fm = 2 * N 
result = 0
for i in range(N):
    nm = As[i]
    result += Bs[As[i]-1]
    if nm -fm == 1:
        result += Cs[fm-1]
    fm = nm
print(result)

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()))
    Ap = N + 100
    Score = 0
    for Ai in A:
        Score += B[Ai-1]
        if Ai == Ap + 1:
            Score += C[Ap-1]
        Ap = Ai
    print(Score)



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

total = B[A[0]-1]
for i in range(1,len(A)):
    total += B[A[i]-1]
    if A[i] - A[i-1] == 1:
        total += C[A[i-1]-1]

print(total)

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

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

Submission status: Accepted

Solution code:

n = int(input())
AL = list(map(int,input().split()))
BL = list(map(int,input().split()))
CL = list(map(int,input().split()))
ans = 0
tmp = AL[0]-1
for i in AL:
    i = i-1
    ans += BL[i]
    if tmp == i-1:
        ans += CL[tmp]
    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()))

for i in range(len(A)):
    A[i] -= 1

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

print(manzoku)

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()))
A += [0]

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

print(s + 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()]

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

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

Submission status: Accepted

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

total = 0
pre = 21
for a in A:
    total += B[a - 1]
    if pre + 1 == a:
        total += C[pre - 1]
    pre = a
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

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

Submission status: Accepted

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

for i, eat in enumerate(a):
    point += b[eat - 1]
    if i == n - 1:
        print(point)
        exit()
    if a[i + 1] == eat + 1:
        point += c[eat - 1]

Submission status: Accepted

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

print(foodSum)

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

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

total = sum(Bs)

for i in range(N-1):
    if As[i+1] - As[i] == 1:
        # print(i)
        total += Cs[As[i]-1]
print(total)

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(3):
    L.append([int(x) for x in input().split()])
    
ans = 0
A_b = -2
for i in range(N):
    A = L[0][i]
    if A_b + 1 == A:
        ans += L[2][A-2]
    ans += L[1][A-1]
    A_b = A
    
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    b_s = list(map(int, input().split(' ')))
    c_s = list(map(int, input().split(' ')))

    result = 0
    pre = -1
    for a in a_s:
        result += b_s[a-1]
        if a == (pre+1):
            result += c_s[pre-1]
        pre = a
    print(result)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

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


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    pos = -100
    sm = 0 
    for i in range(N):
        sm += B[i]
        if i < N-1:
            if A[i] + 1 == A[i+1]:
                sm += C[A[i]-1]
    print(sm)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

p = 0
for i in al:
    p += bl[i-1]

count = 0
tmp = -1
for i in al:
    if tmp == i-1:
        p += cl[tmp-1]
    tmp = i
print(p)

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

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

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=[int(i)-1 for i in input().split()]
b_list=[int(i) for i in input().split()]
c_list=[int(i) for i in input().split()]

bef=-1
ans=0
for a in a_list:
    ans+=b_list[a]
    if bef>=0 and a<n and bef==a-1:
        ans+=c_list[bef]
    bef=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()))

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

print(ans)