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())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
ans = 0
#満足度の計算からいく[
for i in range(1, n + 1):
    if i == n:
        break
    if As[i-1] + 1 == As[i]:
        ans += Cs[As[i-1] - 1]
ans += sum(Bs)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(cnt)

Submission status: Accepted

Solution code:
c=0
n=int(input())
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(0,n):
  c+=B_list[A_list[i]-1]
  if i==n-1:
    break
  if A_list[i]==(A_list[i+1]-1):
    c+=C_list[A_list[i]-1]
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()))

p = 0
prev = -1
for i in A:
    p += B[i-1]
    if i - prev == 1:
        p += C[prev-1]
    prev = 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()))
#print(n,a,b,c,)
p = 0
for i in range (n):
  #print("i=",i)
  #print("ryouri",a[i],"wotabetanode",b[a[i]-1],"mannzokudowoemasita")
  p += b[a[i]-1]
  if i >= 1 and a[i]-1 == a[i-1]:
    #print(a[i]-1,a[i-1])
    ci = a[i-1]
    #print(ci)
    #print("rennbannnanode",c[ci-1],"tsuikasimasu")
    p += c[ci-1]
    #print(p)
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()))
value = 0
for i in range(N):
  value += B[A[i]-1]
  if i > 0 and A[i] == A[i-1]+1:
    value += C[A[i-1]-1]
print(value)

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

Alist.insert(0,0)
Blist.insert(0,0)
Clist.insert(0,0)

ans = 0

for i in range(1,N+1):
    ans = ans + Blist[Alist[i]]
    if i+1 < N+1:
        if Alist[i] +1  == Alist[i+1]:
            ans = ans + Clist[Alist[i]]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

grid = []
for i in range(3):
    array = list(map(int, input().strip().split()))
    grid.append(array)

k = sum(grid[1])
for i in range(n-1):
    if grid[0][i]+1 == grid[0][i+1]:
        k += grid[2][grid[0][i]-1]
        
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()))
value=0
last=100

for dish in A:
  value+=B[dish-1]
  if dish==last+1:
    value+=C[last-1]
  #print(dish,last,value)
  last=dish
  
print(value)

Submission status: Accepted

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

sat = sum(b)

for i in range (0, len(a)-1):
    if a[i]+1 == a[i+1]:
        sat += c[a[i]-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()))

addc = []
for i in range(n-1):
    if a[i+1] == a[i]+1:
        addc.append(c[a[i]-1])
ans = sum(b)+sum(addc)
print(str(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()]
 
t = 0
for i in B:
  t = t + i
  
y = []
for x in range(len(A)-1):
  if A[x] + 1 == A[x+1]:
    y.append(A[x]-1)
  else:
    pass
for k in y:
  t = t + C[k]
print(t)

Submission status: Accepted

Solution code:
n = 0
a = []
b = []
c = []

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

sum = 0
tmp = 0
cc = 0

for m in range(n):
    i = a[m]
    if i-1 <=0:
        cc = 0
    elif tmp == i-1:
        cc = c[i-2]
    else:
        cc = 0
    sum += b[i-1]
    sum += cc
    tmp = i

print(sum)

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()))
result = sum(b_list)
dif_list = []
for i in range(n -1):
  if a_list[i + 1] == a_list[i] + 1:
    dif_list.append(1)
  else:
    dif_list.append(0)
for m in range(len(dif_list)):
   if dif_list[m] == 1:
    result += c_list[a_list[m] -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()))

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

Submission status: Accepted

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

sb=sum(B)
dC=np.diff(A)

sC=C[A[np.where(dC==1)[0]]-1].sum()
#print(sb, sC)
print(sb+sC)

Submission status: Accepted

Solution code:
from itertools import tee


def pairwise(iterable):
    x, y = tee(iterable)
    next(y, None)
    return zip(x, y)


n = int(input())
a = tuple(map(int, input().split(" ")))
b = tuple(map(int, input().split(" ")))
c = tuple(map(int, input().split(" ")))

point = sum(b)
for i, j in pairwise(a):
    if j == i + 1:
        point += c[i - 1]

print(point)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
import time
ts=time.time()
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n=I()
a=LI()
b=LI()
c=LI()
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=input().split()
b=input().split()
c=input().split()
ans=0

for x in range(len(b)):
  ans+=int(b[x])
  if x+1<len(b):
    if int(a[x])+1==int(a[x+1]):
      ans+=int(c[int(a[x])-1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
all = sum(l_b)
for i in range (N-1):
    if l_a[i+1] - l_a[i] == 1:
        all +=l_c[l_a[i]-1]
print(all)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")


satisfaction = 0

for i in range(0, N):
  satisfaction += int(B[int(A[i])-1])
  if i == 0:
    continue
  if int(A[i]) - int(A[i-1]) == 1:
    satisfaction += int(C[int(A[i-1])-1])
    
print(satisfaction)

Submission status: Accepted

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

p = 0
for i in range(N):
    p += B[A[i] - 1]
    # print("ba", B[A[i] - 1])
    if i > 0 and A[i] - 1 == A[i - 1]:
        p += C[A[i - 1] - 1]
        # print("c", C[A[i - 1] - 1])
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()))
an=0
before=0

for i in a:
    an+=b[i-1]

for j in range(n-1):
    if a[j]==(a[j+1]-1):
        an+=c[a[j]-1]

print(an)

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

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

print(su)

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

print(ans)

Submission status: Accepted

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

satisf = 0
former = 20

for a in A:
    satisf += B[a-1]
    if a - 1 == former:
        satisf += C[a-2]
    former = a

print(satisf)

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):
    num = a[i] -1
    point += b[num]
    
    j = i -1
    
    if a[i] == a[j]+1 and a[i] > a[j] and j >=0:
        
        k = a[i] - 1 - 1 
        point += c[k]
    
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()))
cost = 0

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import re

N = sys.stdin.readline() 
A = (sys.stdin.readline()).split()
B = (sys.stdin.readline()).split()
C = (sys.stdin.readline()).split()

j=0
result = 0

for i in A:
  i = int(i)
  result += int(B[i-1])
  
  if j != 0 and j+1 is i:
    result += int(C[j-1])
  j = i
  

print (result)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) - 1 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]]
    if i >= 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
for i in range(n):
    ans = ans + b[i]

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

print(ans + ans2)

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

sumB = sum(B)

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

Submission status: Accepted

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

total = 0


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

print(total)

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

mnzkB = 0
for i in range(N):
    mnzkB += B[i]

mnzkC = 0
for j in range(N - 1):
    if A[j + 1] - A[j] == 1:
        mnzkC += C[A[j] - 1]
    
print(mnzkB + mnzkC)

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

s = sum(b)
f = -1
#print(s)                                                                      

for index,i in enumerate(a):
#    print("index = {} {}".format(index,i))                                    
#    print("f = {}".format(f))                                                 
    if i == f + 1:
#        print("f = {}".format(f))                                             
        s += c[f-1]
    f = i

print(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

a_sub = input().split(" ")
a = [int(n0) for n0 in a_sub]
# print(a)

b_sub = input().split(" ")
b = [int(n0) for n0 in b_sub]
# print(b)

c_sub = input().split(" ")
c = [int(n0) for n0 in c_sub]
# print(c)

score = 0
for xi in range(N-1):
    score = score + b[xi]
    if a[xi+1]==a[xi]+1:
        score = score + c[a[xi]-1]
        # print(xi, c[xi])
score = score + b[N-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()))
addition = 0
price=0
for i in range(0, N-1):
    if a[i]+1 == a[i+1]:
        addition+=c[a[i]-1]
    else:
        
        addition+=0

print(sum(b) + addition)

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


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

bsum=0
for i in b: 
    bsum += i

csum=0
for i in range(0,n-1):
    if a[i]+1 == a[i+1]:
        csum += c[a[i]-1]
        
        
print(bsum+csum)

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()]
#print(a,b,c)

sat = 0
prev = -1
for i in range(n):
  #print("i;",i)
  #print("a;",a[i])
  #print("b;",b[a[i]-1])
  sat += b[a[i]-1]
  if(prev == a[i]-1):
    sat += c[a[i]-2]
    #print('c;',c[a[i]-2])
  prev = a[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()))

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

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n =  int(sys.stdin.readline())
a =  list(map(int, sys.stdin.readline().split()))
b =  list(map(int, sys.stdin.readline().split()))
c =  list(map(int, sys.stdin.readline().split()))

ans=0
a0=a[0]-1

# print(a)
# print(b)
# print(c)

ans+=b[a0]
# print(ans)
for i in range(1,n):
    ai=a[i]
    if a[i] == a[i-1]+1:
        ans+=b[ai-1]+c[ai-2]
    else:
        ans+=b[ai-1]
print(ans)

Submission status: Accepted

Solution code:
cnt = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
lc = list(map(int, input().split()))

total  =0
for i in range(cnt):
  total += lb[la[i] - 1]
  if i != 0 and (la[i-1] +1) == la[i]:
    total += lc[la[i] - 2]

print(total)

Submission status: Accepted

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

A = input().split()
B = input().split()
C = input().split()

ans = 0
tmp = -1
if 2<=N and N<=20:
    if 1<=len(A) and len(A)<=N:
        for a in A:
            
            if int(a) == tmp+1:
                # print(C[tmp-1])
                ans += int(C[tmp-1])
            # print(a)
            
            b = int(B[int(a)-1])
            if not(1<=b and b<= 50):
                exit()
            else:
                # print(b)
                ans += b

            tmp = int(a)
        print(ans)

Submission status: Accepted

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

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


p = 0

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

Submission status: Accepted

Solution code:
N = int(input())
ORDER = list(map(int,input().split()))
SUTISFUCTION = list(map(int,input().split()))
ADDITTIONAL_SUTISFUCTION = list(map(int,input().split()))

s, prev = 0, 50
for i in ORDER:
    s = s + SUTISFUCTION[i - 1]
    if prev == i - 1:
        s = s + ADDITTIONAL_SUTISFUCTION[prev - 1]
    prev = i
    
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
count=-1
acount=0
for i in a:
    ans+=b[i-1]
    if(acount <= len(a)-2):
        if(a[acount+1]==i+1):
            #print('cappned')
            ans+=c[i-1]
    count=i
    acount+=1
print(ans)

Submission status: Accepted

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

satisfy = sum(B)

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

answer = 0
A.append(0)

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

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

m += B[A[N-1]-1]
print(m)

Submission status: Accepted

Solution code:

#b
n = int(input())
a = list (map(int, input().split()))
a = [i-1 for i in a]
b = list (map(int, input().split()))
c = list (map(int, input().split()))

ans = 0

# print(a,b,c)
for i,v in enumerate(a):
    ans += b[v]
    if i != n-1:
        if a[i]+1 == a[i+1] :
            ans += c[v]

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    take_dish = list(map(int,input().split()))
    dish_point = list(map(int,input().split()))
    bonus_dish_point = list(map(int,input().split()))
    result = 0

    for index,dish in enumerate(take_dish):
        result += dish_point[dish-1]
        if(index!=0 and (take_dish[index-1]+1 == dish)):
            result += bonus_dish_point[take_dish[index-1]-1]
    
    print(result)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans=0
memo=1000
for i in a:
    ans += b[i-1]
    if (i - memo) == 1:
        ans+=c[memo-1]
    memo=i
print(ans)

Submission status: Accepted

Solution code:
N = int(input().rstrip())
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):
  #print(A[i],end="A ")
  score += B[A[i]-1]
  #print(score,end="B ")
  if (A[i-1] - A[i]) == -1 and i > 0:
    score += C[A[i]-2]
    #print(score,end="score ")
    
    
print(score)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc140/tasks/abc140_b

N = int(input())
A = list(map(int, input().split()))  # 料理を食べた順番
B = list(map(int, input().split()))  # 料理の基本満足度
C = list(map(int, input().split()))  # 料理の追加満足度

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

print(satisfaction)

Submission status: Accepted

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

bFood = 21
sut = 0

for i in range(N):
    food = A[i]
    sut = B[food - 1] + sut
    
    if food is bFood + 1: 
        sut = C[food - 2] + sut

    bFood = food

print(sut)

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

r = 0
for i in range(n):
    r += B[A[i] - 1]
#    print("B = ",B[A[i] - 1])
    
    if i > 0:
        if A[i] == A[i-1] + 1:
#            print("bonus", C[A[i-1] - 1])
            r += C[A[i-1] - 1]

print(r)
#print(r)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
_ = input()
n = list(map(int, input().split()))
s = sum(map(int, input().split()))
p = list(map(int, input().split()))
a = []
for i, (c, d) in enumerate(zip(n[1:], n[:-1])):
  if (c-d) == 1:
    a.append(d-1)

print(s + sum([p[i] for i in a]))

Submission status: Accepted

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

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

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

print(manzoku)

Submission status: Accepted

Solution code:
def B_Buffet():
    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 (0 < i) and (A[i] == A[i-1] +1):
            ans += C[A[i-1]-1]
    print(ans)
    
if __name__ == "__main__":
    B_Buffet()

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

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

print(satisfaction)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A = [int(a) for a in input().split() ]
B = [int(a) for a in input().split() ]
C = [int(a) for a in input().split() ]

result = 0
old = -5
for i in range(N):#foodA[i]
    result = result + B[A[i]-1]

    if (A[i]-2 == old):
        result = result + C[old]

    old  = A[i]-1
    #print(result)

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

man = 0

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

    man += B[A[i]-1]
    if i-1 >= 0 and A[i-1]+1 == A[i]:
        man += C[A[i-1]-1]

#     print("i {} man {}".format(i,man))
# 
# print("result {}".format(man))

print(man)

Submission status: Accepted

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

d = 0
for i in b:
  d += i

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

point = 0
temp = n + 1

for i, num in enumerate(a):
    point += b[num - 1]
    if num == temp + 1:
        point += c[num - 2]
    temp = num

print(point)

Submission status: Accepted

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

def ans() :

    # 整数の入力
    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 = b[a[0] - 1]

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

    print(ans)


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

Submission status: Accepted

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

for i in range(N):
    cnt += B[A[i]-1]
    if i == 0:
        continue
    elif A[i] == A[i-1]+1:
        cnt += C[A[i]-2]
print(cnt)