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: Wrong Answer

Solution code:
kind = int(input())

table_1 = input().split(' ')
table_2 = input().split(' ')
table_3 = input().split(' ')
total = 0
for i in range(kind):
    total += int(table_2[i])

for j in range(kind-1):
    if int(table_1[j]) == int(table_1[j + 1]) - 1:
        total += int(table_3[j])
print(total)

Submission status: Wrong Answer

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

addans=0

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

Submission status: Wrong Answer

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

addans=0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

C.append(0)
ans = sum(B) + sum(C) - C[A[N-1] - 1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
for j in A:
    count += B[j-1]

#print(count)

for z in range(N-1):
    if A[z+1]- A[z] == 1:
        zz = A[z]
        count += C[zz-1]

#print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
dishes = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
additional = list(map(int, input().split()))

res = 0

for i in range(N-1):
    res += satisfaction[i]

    if dishes[i] + 1 == dishes[i+1]:
        res += additional[dishes[i] - 1]
    
    print(res)

print(res + satisfaction[-1])

Submission status: Wrong Answer

Solution code:
i = int(input())

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

res = sum(b)

for j in range(1,i):
    res += b[a[j]-1]
    if a[j] - a[j-1] == 1:
        res += c[a[j-1]-1]
print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
d=list(map(int,input().split()))
k=list(map(int,input().split()))
s=sum(l)
for i in range(n-1):
    if(l[i]+1==l[i+1]):
        s+=k[l[i]-1]
print(s)

Submission status: Wrong Answer

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[i-2]
print(ans)

Submission status: Wrong Answer

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

for a in range(len(A)):
    if a == len(A)-1:
        break
    B.append(C[A[a]-1])
    
print(sum(B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))
 
satis = 0
 
for i in range(len(A)):
  satis += B[A[i] - 1]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[i-1]
 
print(satis)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

anker=-1
ans=0
for i in range(1,n+1):
    cuisine=a.index(i)
    if cuisine-anker==1:
        print("おいしい")
        ans += c[i-2]
    anker = cuisine
ans += sum(b)
print(ans)

Submission status: Wrong Answer

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

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

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

print(happy)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = 0

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

  
for i in range(n):
  s += b[i]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = 0

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

con = 0

for i in range(len(la)-1):
    if la[(i+1)%3]==la[i]+1:
        con += lc[la[i]-1]

print(sum(lb)+con)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = [0] + list(map(int, input().split()))
b_list = [0] + list(map(int, input().split()))
c_list = [0] + list(map(int, input().split()))

sum = 0
j = 1

for i in range(1, n+1):
    sum += b_list[a_list[i]]
    if i >= 2:
        if a_list[i] == a_list[i-1] + 1:
            sum += c_list[a_list[i-1]]
            #j += 1
    print(sum)


print(sum)

Submission status: Wrong Answer

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):
    print(i)
    if A[i-1] == A[i]-1 and i != 0:
        print(B[A[i]-1])
        m += B[A[i]-1] + C[A[i-1]-1]
    else:
        m += B[A[i]-1]
    print(m)
print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 A:
    ans += B[i-1]
    if A.index(i) != 0:
        if i - 1 == A[A.index(i) - 1]:
            ans += C.pop(0)
            
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n =  int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
fill = 0
cnt = 0
for f in range(n):
    fill = fill + b[a[f] - 1]
    if(f != 0 and a[f] == a[f-1] + 1):
        fill = fill + c[f-2]
        cnt = cnt + 1
    else:
        cnt = cnt + 1
print(fill)

Submission status: Wrong Answer

Solution code:
n =  int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
fill = 0
cnt = 0
for f in range(n):
    fill = fill + b[a[f] - 1]
    if(f != 0 and a[f] == a[f-1] + 1):
        fill = fill + a[f-2]
        cnt = cnt + 1
    else:
        cnt = cnt + 1
print(fill)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
if a[n-1] == n:
  print(sum(b)+sum(c))
else:
  print(sum(b)+sum(c)-c[a[n-1]-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
if a[n-1] == n:
  print(sum(b)+sum(c))
else:
  print(sum(b)+sum(c)-c[n-2])

Submission status: Wrong Answer

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

score = 0
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i == prev + 1: score += bonuses[i-2]
  print(score)
  prev = i

print(score)

Submission status: Wrong Answer

Solution code:
a=int(input())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
o=list(map(int,input().split()))
result1=0

for i in range(0,a-1):
    if n[i]+1==n[i+1]:
        print(i)
        result1+=o[n[i]-1]

for i in range(a):
    result1+=m[n[i]-1]
print(result1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)+sum(C)

if A[-1] == N:
    print(ans)
else:
    tmp = A[-1] -1
    print(ans-C[tmp])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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)
pre_idx = -1
pre_val = -1
for idx, val in enumerate(a):
    if pre_idx == -1:
        pre_idx = idx
        pre_val = val
    else:              # pre_idx != -1:
        if pre_val == val - 1:
            ans = ans + c[pre_idx - 1]
            pre_idx = idx
            pre_val = val
        else:
            pre_idx = idx
            pre_val = val   
        
print(ans)

Submission status: Wrong Answer

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)
pre_idx = -1
pre_val = -1
for idx, val in enumerate(a):
    if pre_idx == -1:
        pre_idx = idx
        pre_val = val
    else:              # pre_idx != -1:
        if pre_val == val - 1:
            ans = ans + c[pre_idx - 1]
            pre_idx = idx
            pre_val = val
        else:
            pre_idx = idx
            pre_val = val   
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [0] + list(map(int,input().split()))
B = [0] + 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]+1 == A[i]:
    ans += C[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
lis = list()
for i in A:
    lis.append(B[i-1])
    #print(i,t)
    if i == t + 1:
        lis.append(C[i-2])
    t = i

print(sum(lis))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(0,n-1):
    if(i < n-2 and a[i+1] == a[i] + 1 ):
        sum_satisfaction = sum_satisfaction + c[i+1]
    elif(i >= n-2 and a[i+1] == a[i] + 1 ):
        sum_satisfaction = sum_satisfaction + c[i-1]
print(sum_satisfaction)

Submission status: Wrong Answer

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

for i in range(1,n):
    if(i < n-1 and  a[i] == a[i-1] + 1 ):
        sum_satisfaction = sum_satisfaction + c[i]
print(sum_satisfaction)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sts = 0
for i in range(n):
    sts += B[A[i] - 1]
    if 0 < i and A[i] - A[i-1] == 1:
        sts += C[B.index(B[A[i] - 1]) - 1]
print(sts)

Submission status: Wrong Answer

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[i-1]
print(ans+sum(b))

Submission status: Wrong Answer

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):
    eat=a[i]-1
    ans+=b[eat]
    if eat!=n-1 and i!=n-1:
        ans+=c[eat]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
readline = sys.stdin.readline
A = [int(i)-1 for i in readline().split()]
B = [int(i) for i in readline().split()]
C = [int(i) for i in readline().split()]

ans = 0
a_prev = -1
for a in A:
    ans += B[a]
    if a == a_prev+1:
        ans += C[a-1]
    a_prev = a
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def buffet(n, ali, bli, cli):

    ans = 0
    count = 0

    for i in range(n):
        ans += bli[ali[i]-1]

        if ali[i] == count+1:
            ans += cli[count-1]
        count = ali[i]
    return ans

def main():
    n = int(input())
    ali = list(map(int, input().split()))
    bli = list(map(int, input().split()))
    cli = list(map(int, input().split()))
    print(buffet(n, ali, bli, cli))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sat = 0
for a_i in range(0, n):
    print(sat)
    i = a_s[a_i] - 1
    b = b_s[i]
    sat += b
    if a_i < n-1 and a_s[a_i] +1 == a_s[a_i+1]:
        if i >= 0:
            sat += c_s[i]
print(sat)

Submission status: Wrong Answer

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

sat = 0
for i in range(0, n):
    idx = a_s[i] - 1
    b = b_s[idx]
    sat += b
    if i < n-1 and a_s[i] +1 == a_s[i+1]:
        if i > 0:
            sat += c_s[i-1]
print(sat)

Submission status: Wrong Answer

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

sat = 0
for i in range(0, n):
    print(sat)
    idx = a_s[i] - 1
    b = b_s[idx]
    sat += b
    if i < n-1 and a_s[i] +1 == a_s[i+1]:
        if i > 0:
            print('true')
            sat += c_s[i-1]
print(sat)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

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

#############
# Main Code #
#############

N = inputI()
A = inputIL()
B = inputIL()
C = inputIL()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
cnt = sum(b)
for i in range(n):
  if i<=n-2 and (a[i+1] - a[i] == 1):
    cnt += c[i]
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
tem = n

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

Submission status: Wrong Answer

Solution code:
n = int(input())
qq= list(map(int,input().split()))
ww = list(map(int,input().split()))
c = list(map(int,input().split()))
t = 0
for i in range(n):
  if i != 0:
    t = t+ww[qq[i]-1]+c[qq[i]-2]
  else:
    t = t + ww[qq[i]-1]
print(t)

Submission status: Wrong Answer

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(i,s)
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
lista=list(map(int,input().split()))
listb=list(map(int,input().split()))
listc=list(map(int,input().split()))
list=[]
for i in range(n):
  if lista[i]==lista[i-1]+1:
    list.append(lista[i-1])
vonus=0
for x in list:
  vonus+=listc[x-1]
print(sum(listb)+vonus)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())
lia = list(map(int, sys.stdin.readline().split()))
lib = list(map(int, sys.stdin.readline().split()))
lic = list(map(int, sys.stdin.readline().split()))
s = sum(lib)
li = []
i = 0
while i < n-1:
  if lia[i+1] - lia[i] == 1:
    li.append(i)
  i += 1
for i in li:
  s += lic[i-1]
print(s)

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())
lia = list(map(int, sys.stdin.readline().split()))
lib = list(map(int, sys.stdin.readline().split()))
lic = list(map(int, sys.stdin.readline().split()))
s = sum(lib)
li = []
i = 0
while i < n-1:
  if lia[i+1] - lia[i] == 1:
    li.append(i)
  i += 1
for i in li:
  s += lic[i]
print(s)

Submission status: Wrong Answer

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

if A[-1] > len(C):
    ans = sum(B)+sum(C)
else:
    ans = sum(B)+sum(C) - C[A[-1]-1]
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

d = dict(zip(A, B))
ans = d[A[0]]

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

d = dict(zip(A, B))
ans = d[A[0]]

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
eat_list = list(map(int, input().split()))
manzok_list = list(map(int, input().split()))
add_manzok_list = list(map(int, input().split()))

manzok = 0

for i in range(N):
 manzok += manzok_list[eat_list[i]-1]
 if(i > 0 and (eat_list[i] - eat_list[i-1]) == 1):
   print(i)
   manzok += add_manzok_list[eat_list[i-1]-1]

print(manzok)

Submission status: Wrong Answer

Solution code:
N = int(input())
eat_list = list(map(int, input().split()))
manzok_list = list(map(int, input().split()))
add_manzok_list = list(map(int, input().split()))

manzok = 0

for i in range(N):
 manzok += manzok_list[eat_list[i]-1]
if(i > 0 and (eat_list[i] - eat_list[i-1]) == 1):
  manzok += add_manzok_list[eat_list[i-1]-1]

print(manzok)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(sum(b)+m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest

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

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
3 1 2
2 5 4
3 6"""
        output = """14"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
2 3 4 1
13 5 8 24
45 9 15"""
        output = """74"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2
1 2
50 50
50"""
        output = """150"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()
    resolve()