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

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(input())
a = [ int(x) for x in stdin.readline().rstrip().split()]
b = [ int(x) for x in stdin.readline().rstrip().split()]
c = [ int(x) for x in stdin.readline().rstrip().split()]
cnt = 0

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

print(cnt)

Submission status: Accepted

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

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

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

print(result)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=np.array([int(x) for x in input().split()])
b=np.array([int(x) for x in input().split()])
c=np.array([int(x) for x in input().split()])

tf = np.array([a[i+1] - a[i] == 1 for i in range(n-1)])

print(sum(b) + sum([c[j-1] for j in a[tf]]))

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

Submission status: Accepted

Solution code:
N = int(input())

A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
result = 0
prev = 0

for i in range(N):
    pointer = int(A[i])
    result += int(B[pointer-1])
    if i != 0 and pointer - prev == 1:
        result += int(C[prev-1])
    prev = pointer

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

Submission status: Accepted

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

result = 0
j = 0
isFirst = True
for i in a:
  m = int(i) - 1
  result += int(b[m])
  if (not (isFirst)) and (j + 1 == m):
      result += int(c[j])
  j = m
  isFirst = False
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(N):
  sum += int(b[a[i]-1])
  if(i != 0):
    if(a[i] - a[i-1] == 1):
      sum += int(c[a[i-1]-1])
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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


A.append(0)
C.append(C[0])

satis = sum(B) 

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

		satis += C[j]

print(satis)

Submission status: Accepted

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

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

  if pre == a_list[i] - 1:
    ans += c_list[a_list[i] - 2]
  pre = a_list[i]


print(ans)

Submission status: Accepted

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

point = 0
memory = -10
for cnt in range(n):
    point += b[a[cnt] - 1]
    if memory + 1 == a[cnt] - 1:
        point += c[a[cnt] - 2]
    memory = a[cnt] - 1

print(point)

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

Submission status: Accepted

Solution code:
n = int(input())
list = [list(map(int,input().split())) for _ in range(3)]  
ans = 0
for i in range(n):
  if i == 0:
    ans += list[1][list[0][i]-1]
  else:
    ans += list[1][list[0][i]-1]
    if list[0][i] == list[0][i-1]+1:
      ans += list[2][list[0][i-1]-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()))
#print(N, type(N))
#print(list_A, type(list_A))
#print(list_B, type(list_B))
#print(list_C, type(list_C))

sum = 0
for i in range(N):
#    print('i=', i)
    sum += list_B[list_A[i]-1]
#    print('list_A=', list_A[i], 'list_B=', list_B[list_A[i]-1])
    if ((list_A[i] - list_A[i-1]) == 1) and (i != 0):
        sum += list_C[list_A[i-1]-1]
#        print('list_C=', list_C[list_A[i-1]-1])
#    print('sum=', sum)
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):
    r=a[i]-1
    if i > 0 and r == prev+1:
        ans+=b[r]+c[r-1]
    else :
        ans+=b[r]
    prev=r

print(ans)

Submission status: Accepted

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

ans = 0

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

result = sum(b)

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

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

Submission status: Accepted

Solution code:
N = int(input())
lineA = input().split()
lineB = input().split()
lineC = input().split()
A = [0] * N
B = [0] * N
C = [0] * (N-1)
for i in range(N):
    if i<N-1:
        A[i] = int(lineA[i])
        B[i] = int(lineB[i])
        C[i] = int(lineC[i])
    else:
        A[i] = int(lineA[i])
        B[i] = int(lineB[i])

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 = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
add_s = 0
for idx in range(N-1):
  cur_f = A[idx]
  nxt_f = A[idx+1]
  add_s += C[cur_f-1] if nxt_f == cur_f + 1 else 0

print(sum(B) + add_s)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n-1):
  sum = sum + l[1][i]
  if l[0][i+1] - l[0][i] == 1:
    sum = sum + l[2][l[0][i]-1]
sum = sum + l[1][n-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(' ')))
a = 0
a += sum(B)
for i in range(N-1):
  if A[i+1]-A[i] == 1:
    a += C[A[i]-1]
print(a)

Submission status: Accepted

Solution code:
n = input()
s1= input()
s2= input()
s3= input()
ss1 = list(map(lambda x:int(x), s1.split()))
ss2 = list(map(lambda x:int(x), s2.split()))
ss3 = list(map(lambda x:int(x), s3.split()))

sum = 0
p = 21
for i in range(len(ss1)):
    sum += ss2[ss1[i]-1] + (ss3[p-1] if (p == (ss1[i]-1)) else 0)
    p = ss1[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()))
c1=b[a[0]-1]

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

Submission status: Accepted

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



def main():
    num = input()
    sseq = input().split()
    iseq = map(int, sseq)
    ssat = input().split()
    svns = input().split()
    
    ans =0
    for i, s in enumerate(iseq):
        ans = ans + int(ssat[s-1])
        if (i < (int(num)-1)):
            if(int(sseq[i+1]) - int(sseq[i]) ==1):
                ans = ans + int(svns[s-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()))
# c.sort()
s = 0
j=0
for i in range(n):
  s+=b[a[i]-1]
  # print(a[i])
  try:
    if (a[i+1]-a[i])==1:
      s+=c[a[i]-1]
      j+=1
        # print(c[j],a[i],a[i-1])
  except:
    pass
print(s)

Submission status: Accepted

Solution code:
N = int(input())
order = list(map(int, input().split()))
total = sum(list(map(int, input().split())))  #合計点
point_added = list(map(int, input().split()))

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
A_list=[int(thing) for thing in input().split(" ")]
B_list=[int(thing) for thing in input().split(" ")]
C_list=[int(thing) for thing in input().split(" ")]
ret=0
P_B=0
for d in range(len(A_list)):
    tottano=A_list[d]-1
    if d!=0 and tottano!=N:
        if tottano==sakki+1:
            ret=ret+C_list[sakki]
    ret=ret+B_list[tottano]
    sakki=tottano
print(ret)

Submission status: Accepted

Solution code:
_ = input()
orders = [int(i) for i in input().split(" ")]
score = [int(i) for i in input().split(" ")]
c_score = [int(i) for i in input().split(" ")]

result = 0
before_dish_no = 0
for n in orders:
  result += score[n-1] + c_score[n-2] if (n is not 1) and (before_dish_no+1 == n) else score[n-1]
  before_dish_no = n

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
menu=list(map(int,input().split()))
man=list(map(int,input().split()))
ak=sum(man)
tuika=list(map(int,input().split()))
s=menu[0]
for i in menu[1:]:
  if i==s+1:
    ak+=tuika[s-1]
  s=i
print(ak)

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):
    now = a[i]
    if i > 0:
        if now == before + 1:
          score += (b[a[i]-1] + c[before-1])
          before = now
          continue
    score += b[now-1]
    before = now
print(score)

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

total = 0
i = -10
for a_i in a:
    if a_i == i + 1:
        total += c[i]
    total += b[a_i]
    i = a_i
print(total)

Submission status: Accepted

Solution code:
List=[list(map(int,input().split())) for i in range(4)]

a=sum(List[2])
b=int(len(List[1]))

for i in range(b-1):
  if List[1][i+1]-List[1][i] == 1:
    a+=List[3][List[1][i]-1]

print(a)

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

s = b[a[0]-1]

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

last_value = -1
satisfied_points = 0

for i, v in enumerate(A):
  s = B[v - 1]
  satisfied_points += s
  if (last_value == (v - 1)):
    ss = C[last_value - 1]
    satisfied_points += ss
  last_value = v
  
print(satisfied_points)

Submission status: Accepted

Solution code:


def main():


   N = int(input())
   buffeList = list(map(int,input().split()))
   gainList =  list(map(int,input().split()))
   addionList =  list(map(int,input().split()))
   ans = 0
   
   for i in range(N):
      wEat = gainList[buffeList[i]-1]
      ans += wEat
      if buffeList[i]-buffeList[i-1] == 1 and i>=1 :
         ans += addionList[buffeList[i-1]-1]
   print(ans)








if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = na()
c = na()

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
food = list(map(int,input().split()))
val = list(map(int,input().split()))
bonas = list(map(int,input().split()))

ans = 0

for i in range(N):
  ans += val[food[i]-1]
  
for i in range(N-1):
  if food[i]+1==food[i+1]:
    ans += bonas[food[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()))

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ans = 0

prev = None
for i in a:
    ans += b[i]
    if prev is not None and prev == i - 1:
        ans += c[i - 1]
    prev = i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = []
b = []
c = []
work = 0
total = 0
i = 0
test = 100
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
while(i < n):
  work = a[i]
  total = total + b[work - 1]
  if(test == a[i] - 1):
    total = total + c[test - 1]
  test = a[i]
  i = i + 1
print(total)

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
precur = -1
for i in range(0, n):
    cur = al[i] - 1
    ans += bl[cur]
    if precur != -1 and precur + 1 == cur:
        ans += cl[precur]
    precur = cur
print(ans)

Submission status: Accepted

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


d=a[1][n-1]
for i in range(n-1):
	d=d+a[1][i]

	if a[0][i+1]==a[0][i]+1:
		d=d+a[2][a[0][i]-1]

print(d)

Submission status: Accepted

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

ans = 0
prev = 0

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

  if (i != 0 and prev == a[i] - 1):
    ans += c[prev - 1]
  prev = a[i]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
SAT = 0

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

    if cnt > 0 and A[cnt] == A[cnt - 1] + 1:
        SAT += C[i - 2]

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

i = 0
Num = 0
Ans = 0
while N > i:
  Num = A[i]-1
  Ans = Ans + B[Num]
  if i != 0 and Num != 0 and A[i] == A[i-1] + 1:
    Ans = Ans + C[Num-1]
  i += 1
print(Ans)

Submission status: Accepted

Solution code:
while True:
    try:
        N = int(input())
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
        C = list(map(int, input().split()))
        A.insert(0, 0)
        B.insert(0, 0)
        C.insert(0, 0)
        
        res = B[A[1]]
        for i in range(2, len(A)):
            res += B[A[i]]
            if A[i-1]+1 == A[i]:
                res += C[A[i-1]]
        print(res)
    except:
        break

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 = input()
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
total = 0


for i in range(int(N)):
    #print(i)
    #print(B[int(A[i])-1])
    total = total + int(B[int(A[i])-1])
    if i > 0 and i < int(N) and int(A[i-1]) == int(A[i])-1:
        #print(C[int(A[i-1])-1])
        #print(int(A[i-1]))
        total = total + int(C[int(A[i-1])-1])

print(total)

Submission status: Accepted

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

s=0
for k in range(len(A)-1):
    if(A[k+1]-A[k]==1):
       s+=C[A[k]-1]
print(sum(B)+s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
kind = int(input())
A = input().split()
B = input().split()
C = input().split()
stf = 0
temp = 0

for n in map(int, A):
    stf += int(B[n - 1])
    if n - temp == 1 and temp != 0:
        stf += int(C[n - 2])
    else:
        pass
    temp = n

print(stf)

Submission status: Accepted

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


content_plus = 0

for i in range(n):
    if i == 0:
        pass
    else:
        if data[0][i-1]+1 == data[0][i]:
            content_plus = content_plus + data[2][data[0][i-1]-1]


def sum(list):
    lsum = 0
    for i in range(len(list)):
        lsum = lsum+list[i]
    return lsum

print(sum(data[1])+content_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):
    ans += B[i]

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

result = 0
for a, i in zip(A, range(len(A))):
    result += B[a-1]
    if i > 0 and (a - A[i-1]) == 1:
        result += C[A[i-1]-1]
print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans,x=0,n
for i in a:
	ans+=b[i-1]
	if x==i-1:
		ans+=c[x-1]
	x=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()))
cnt=0
for i,v in enumerate(a):
	cnt += b[v-1]
	if i == 0:continue
	if v-1 == a[i-1]:
		#print(c[v-1])
		cnt += c[v-2]
print(cnt)

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 < 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:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
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 _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)

N = _I()
A = LI()
B = LI()
C = LI()
A = [i-1 for i in A]

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

Submission status: Accepted

Solution code:
N = int(input())

A = []
B = []
C = []

A = input().split()
A = [int(n) for n in A]

B = input().split()
B = [int(n) for n in B]

C = input().split()
C = [int(n) for n in C]

sati = 0

A.append(-100)

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

#print(N)
#print(A)
#print(B)
#print(C)
print(sati)

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

res = 0
prev = -10

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

print(res)

Submission status: Accepted

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

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


print(ans)

Submission status: Accepted

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

cnt = 0
ss = -10

for i in a :
    i -= 1
    cnt += b[i]
    if (i - ss == 1) :
        cnt += c[ss]
        
    ss = i



print(cnt)

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

M = 0
pre_a = -1

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

print(M)

Submission status: Accepted

Solution code:
_ = input().strip()
a = input().strip().split(" ")
b = input().strip().split(" ")
c = input().strip().split(" ")

m = 0
pre_a = -1
for _a in a:
    
    _a = int(_a)
    _a -= 1
    m += int(b[_a])
    
    if ((pre_a+1 == _a) & (_a > 0)):
        m += int(c[pre_a])
    pre_a = _a
    
print(m)

Submission status: Accepted

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

    satisfaction, pre_a = 0, -1
    for i in range(N):
        a = A[i] - 1
        satisfaction += B[a]
        if pre_a != -1 and pre_a + 1 == a:
            satisfaction += C[pre_a]

        pre_a = a

    print(satisfaction)


if __name__ == '__main__':
    b()

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

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

Submission status: Accepted

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

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

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

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

print(result)