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:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
k = A[-1]
if k == N:
    print(sum(B)+sum(C))
else:
    print(sum(B)+sum(C)-C[k-1])

Submission status: Wrong Answer

Solution code:
N = input()
array_A = list(map(int, input().split()))
array_B = list(map(int, input().split()))
array_C = list(map(int, input().split()))

print(sum(array_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()]

del a[n:]
del b[n:]
del c[(n - 1):]


answer = 0

for x in range(n):
  if x >= 1:
    if a[x-1] < len(c) + 1:
      answer += c[a[x - 1] - 1]
  answer += b[a[x] - 1]

print(answer)

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()))
n=int(0)
manzoku=int(0)
hantei = int(1)
if A[0] == hantei:
        manzoku += sum(C)
        while n<N:
            manzoku += B[n]
            n += 1
else:
        manzoku += sum(C) - C[A[0]-2]
        while n<N:
            manzoku += B[n]
            n += 1

print(manzoku)

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 = n-1
sumc = sum(c)
tmp = a[m]
if m > 1:
    if tmp <= m:
        sumc -= c[tmp-1]
if m == 1:
    if tmp == 1:
        sumc = 0
ans = sum(b)
ans += sumc

print(ans)

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

del a[n:]
del b[n:]
del c[(n-1):]

answer = 0

for x in range(n):
  answer += b[a[x] - 1]
  if x >= 1:
    if a[x-1] < len(c) + 1:
      answer += c[a[x - 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()))
f = False
x = 0
for i in range(N):
  bx = B[A[i]-1]
  if f:
    x += bx + C[A[i-1]-1]
    f = False
    if i+1 < len(A) and A[i] + 1 in A:
      f = True
  else:
    if i+1 < len(A) and A[i] + 1 in A:
      f = True
      x += bx
    else:
      x += bx
print(x)

Submission status: Wrong Answer

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

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()))
        
i = A[-1]
if i < N:
  C.pop(i-1)

print(sum(B) + sum(C))

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 = n-1
sumc = sum(c)
tmp = a[m]
if m > 1:
    if tmp <= m:
        sumc -= c[tmp-1]
ans = sum(b)
ans += sumc

print(ans)

Submission status: Wrong Answer

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[tf]))

Submission status: Wrong Answer

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

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()))
mem = set()
s=0
for v in a:
    s+=b[v-1]
    mem.add(v)
    if v-1 in mem:
        s+=c[v-2]
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()))

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

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 = 0
b = 0
for a in A:
  cnt += B[a-1]
  if a == b+1:
    cnt += C[a-2]
  b = a
print(cnt)

Submission status: Wrong Answer

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 = -1
for a_i in a:
    if a_i == i + 1:
        total += c[i]
    total += b[a_i]
    i = a_i
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()))
happy =0
for i in range(len(a)):
  happy =happy + b[int(a[i])-1]
  if i >1:
    if a[i]==m+1:
      happy=happy+c[int(a[i])-2]
  m=a[i]
  
print(happy)

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


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

satis = sum(B) 

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

print(satis)

Submission status: Wrong Answer

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][i]
sum = sum + l[1][n-1]
print(sum)

Submission status: Wrong Answer

Solution code:
def buffet(n_dish, A, B, C):
    """
    :type n_dish: int
    :type A: List[int]
    :type B: List[int]
    :type C: List[int]
    """
    s_point = 0
    for s in B:
        s_point += s

    for i in range(len(A)-2):
        currentDish = A[i]
        nextDish = A[i+1]
        if A[i+1] - A[i] == 1:
            s_point += C[i-1]

    return s_point

Submission status: Wrong Answer

Solution code:
def buffest(N, list_A, list_B, list_C):
    total_points = 0
    for idx in range(N):
        tmp_dish = list_A[idx]-1
        tmp_score = list_B[tmp_dish]
        total_points += tmp_score
        if idx >= 1 and tmp_dish > 0 and tmp_dish == list_A[idx-1]:
            extra_score = list_C[tmp_dish-1]
            total_points += extra_score
    return total_points

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(int(1e6))

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 a in A:
    i = a - 1
    ans += B[i]
    if (prev + 1) == a and (a < N):
        ans += C[i-1]
    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()))
s=sum(b)
s+=sum(c)
if(a[-1]!=n):
    s-=c[a[-1]-1]
print(s)

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

answer = 0

for x in range(n):
  answer += b[a[x] - 1]
  if x >= 1:
    if a[x-1] < len(c) + 1:
      answer += c[a[x - 1] - 1]

print(answer)

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

answer = 0

for x in range(len(a)):
  answer += b[a[x] - 1]
  if x >= 1:
    if a[x-1] < len(c) + 1:
      answer += c[a[x - 1] - 1]

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []
work = 0
total = 0
i = 0
test = 0
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: 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.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 and (i)<(n-1):
#       s+=c[j]
#       j+=1
#         # print(c[j],a[i],a[i-1])
#   except:
#     pass
# print(s)
ss=sum(b)+sum(c)
print(ss)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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(" ")]
last_one=A_list[-1]-1
ret=0
if last_one==N-1:
    ret = sum(B_list) + sum(C_list)
else:
    ret=sum(B_list)+sum(C_list)-C_list[last_one]
    
print(ret)

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


print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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.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 and (i)<(n-1):
      s+=c[j]
      j+=1
        # print(c[j],a[i],a[i-1])
  except:
    pass
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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:
        m += int(c[pre_a])
    pre_a = _a
    
print(m)

Submission status: Wrong Answer

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][i]
  else:
    ans += list[1][i]
    if list[0][i] == list[0][i-1]+1:
      ans += list[2][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

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

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

P=0
P+=B[A[0]-1]
for i in range(N-1):
    if A[i]!=N and A[i+1]!=1:
        u=B[A[i+1]-1]
        q=C[A[i+1]-2]
        o=u+q
        P+=o
    elif A[i]!=N and A[i+1]==1:
        u=B[A[i+1]-1]
        P+u
    else:
        u=B[A[i+1]-1]
        P+=u
    
print(int(P))

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 = []
aa = 0
while aa <= n-1:
 try:
   k = a[aa]
   #print(b[k-1])
   res.append(b[k-1])
   f = 0
   f = a[aa + 1]- a[aa]
   if f > 0:
    #print(c[f-1])
    res.append(c[f-1])
   aa = aa + 1 
 except:
    print(sum(res))
    break
#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()))
c.sort()
s = 0
j=0
for i in range(n):
  s+=b[a[i]-1]
  # print(a[i])
  try:
    if (a[i]-a[i-1])==1 and (i-1)>=0:
      s+=c[j]
      j+=1
        # print(c[j],a[i],a[i-1])
  except:
    pass
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.sort()
s = 0
j=0
for i in range(n):
  s+=b[a[i]-1]
  # print(a[i])
  try:
    if (a[i]-a[i-1])==1 and (i-1)>=0:
      s+=c[j]
      j+=1
        # print(c[j],a[i],a[i-1])
  except:
    pass
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()))
sum = 0
for i in range(0,N-1):
    sum += B[A[i]-1]
    if A[i] == A[i+1] - 1:
        sum += C[i]
sum += B[A[N-1]-1]
print(sum)

Submission status: Wrong Answer

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

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

print(point)

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 = n-1
sumc = sum(c)
sumc -= max(c)
if m == 1:
    sumc += max(c)
ans = sum(b)
ans += sumc

print(ans)

Submission status: Wrong Answer

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()))
sum = 0
before_target = 0
for i in range(n):
    target = a_list[i]
    if before_target+1 == target :
        sum += b_list[target - 1] + c_list[target - 2]
    else:
        sum += b_list[target - 1]
    before_target = target

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()))
P=0
P+=B[A[0]-1]
for i in range(N-1):
    if A[i]!=N:
        u=B[A[i+1]-1]
        q=C[A[i+1]-2]
        o=u+q
        P+=o
    else:
        u=B[A[i+1]-1]
        P+=u
    
print(int(P))

Submission status: Wrong Answer

Solution code:
N =	 int(input())
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))
L3 = list(map(int,input().split()))

if L1[-1]!=N:
  
  L1.remove(N)
  LL1 = L1[-1]
  L3.pop(LL1-1)

  
SL2 = sum(L2)
SL3 = sum(L3)
print(SL2 + SL3)

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.sort()
s = 0
j=0
for i in range(n):
  s+=b[a[i]-1]
  # print(a[i])
  try:
    if (a[i]-a[i-1])==1 and i>0:
      if j<len(c):
        s+=c[j]
        j+=1
        # print(c[j],a[i],a[i-1])
  except:
    pass
print(s)

Submission status: Wrong Answer

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

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

print(stf)

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

manzoku = 0
for b in B:
  manzoku += b
for c in C:
  manzoku += c
print(manzoku)

Submission status: Wrong Answer

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

b_val = 0

for i in range(N):
    aaa = list_A[i]
    b_val += list_B[aaa-1]
    if i ==0:
        continue
    elif aaa == list_A[i-1]+1:
        b_val += list_C[i-1]
print(b_val)

Submission status: Wrong Answer

Solution code:
n = input()
sated= 0
eat = list(map(int, input().split(' ')))#A
sat = list(map(int, input().split(' ')))#B
aft = list(map(int, input().split(' ')))#C

for i in range(int(n)):
    sated += sat[eat[i]-1]
    if eat[i] == eat[i-1]-1 and i != 0:
        sated += aft[eat[i]-1]
print(sated)

Submission status: Wrong Answer

Solution code:
num = int(input())

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

ans = 0
now = 0

for i, j in enumerate(a):
    ans += b[j-1]
    if now != max(a) and i != 0:
        ans += c[now-1]
    now = j
print(ans)

Submission status: Wrong Answer

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

b_val = 0

for i in range(N):
    aaa = list_A[i]
    b_val += list_B[aaa-1]
    if i ==0:
        continue
    elif aaa == list_A[i-1]+1:
        b_val += list_C[i-1]
        print(b_val)
print(b_val)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
AAA = list(map(int, input().split()))
BBB = list(map(int, input().split()))
CCC = list(map(int, input().split()))

n_satisfy = 0
for i, A in enumerate(AAA):
    B = BBB[A - 1]
    if i == 0:
        n_satisfy += B
    elif AAA[i - 1] + 1 != A:
        n_satisfy += B
    else:
        n_satisfy += B + CCC[A - 1 - 1]
    print(n_satisfy)

print(n_satisfy)

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

Submission status: Wrong Answer

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

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

print(ans)

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

answer = 0

for x in range(len(a)):
  if x >= 1:
    if a[x-1] < len(c) + 1:
      answer += c[a[x - 1] - 1]
  answer += b[a[x] - 1]

print(answer)

Submission status: Wrong Answer

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

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

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: 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 N == 2:
    if A[1] == 2:
        print(sum(B)+sum(C))
    else:
        print(sum(B))
else:
    k = A[-1]
    if k == N:
        print(sum(B)+sum(C))
    else:
        print(sum(B)+sum(C)-C[k-1])

Submission status: Wrong Answer

Solution code:
N =	 int(input())
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))
L3 = list(map(int,input().split()))

L1.remove(N)

LL1 = L1[-1]
L3.pop(LL1-1)

SL2 = sum(L2)
SL3 = sum(L3)


print(SL2 + SL3)

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

P=0
P+=B[A[0]-1]
for i in range(N-1):
    if A[i]!=N:
        u=B[A[i+1]-1]
        q=C[A[i+1]-2]
        o=u+q
        P+=o
    else:
        u=B[A[i+1]-1]
        P+=u
    
print(P)

Submission status: Wrong Answer

Solution code:
N = int(input())
lstA = list(map(int,input().split()))
lstB = list(map(int,input().split()))
lstC = list(map(int,input().split()))

minusC = 0
if (lstA[0] != 1):
    minusC = lstC[lstA[N-1]-1]

print (sum(lstB) + (sum(lstC) - minusC ))

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 N == 2:
    if A[1] == 2:
        print(sum(B)+sum(C))
    else:
        print(sum(B))
else:
    k = A[-1]
    if k == A[N-1]:
        print(sum(B)+sum(C))
    else:
        print(sum(B)+sum(C)-C[k-1])

Submission status: Wrong Answer

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 tmp == i-1:
        cc = c[i-2]
    else:
        cc = 0
    sum += b[i-1]
    sum += cc
    tmp = i

print(sum)

Submission status: Wrong Answer

Solution code:
N =	 int(input())
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))
L3 = list(map(int,input().split()))

L1.remove(N)

ML1 = max(L1)
print(ML1)
L3.pop(ML1-1)

SL2 = sum(L2)
SL3 = sum(L3)


print(SL2 + SL3)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(j) for j in input().split()]
b = [int(j) for j in input().split()]
c = [int(j) for j in input().split()]
ans = 0
prev = 0
for i in a:
    ans+=b[i-1]+prev
    try:
        prev = c[i-1]
    except:
        prev = 0
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)

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

Submission status: Wrong Answer

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

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

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: 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
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)
#for i in range(n):

Submission status: Wrong Answer

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

result = 0
j = 0
for i in a:
  m = int(i) - 1
  result += int(b[m])
  if not (m == 0) and (j + 1 == m):
      result += int(c[j])
  j = m
print(result)

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()))
 
A.insert(0,0)
B.insert(0,0)
C.insert(0,0)
manzoku = 0
prev = 0
 
for a in A:
  manzoku += B[a]
  if prev != 0 and prev != N:
    manzoku += C[prev]
  prev = a
print(manzoku)

Submission status: Wrong Answer

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

Solution code:
n = int(input())

list = []

if n == 1:
    for i in range(2):
        str = input()
        strList = str.split()
        miniList = []
        for x in strList:
            miniList.append(int(x))
        list.append(miniList)
    list.append([])
else:
    for i in range(3):
        str = input()
        strList = str.split()
        miniList = []
        for x in strList:
            miniList.append(int(x))
        list.append(miniList)

list[2].append(0)

end = 1
sum = 0
for i in list[0]:
    i -= 1
    sum += list[1][i]
    if end == n:
        break
    else:
        sum += list[2][i]
    end += 1

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

addc = []
kaisu = -10
for i in range(n-1):
    if a[i+1] == a[i]+1:
        addc.append(c[i-1])
ans = sum(b)+sum(addc)
print(str(ans))

Submission status: Wrong Answer

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(b[x])+1==int(b[x+1]):
      ans+=int(c[x])
print(ans)

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

prev = 0
s = sum(b)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=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[np.where(dC==1)[0]-1].sum()

print(sb+sC)

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 N == 2:
    if A[1] == 2:
        print(sum(B)+sum(C))
    else:
        print(sum(B))
elif N == 1:
    print(sum(B))
else:
    try:
        k = A[-1]
        print(sum(B)+sum(C)-C[k-1])
    except(IndexError):
        print(sum(B)+sum(C))

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
d = -1.5

for i in a:
  m += b[i-1]  
#  print(m)
  if d == b[i-2] and i > 1:
    m += c[i-2]
#    print(m)

  d = b[i-1]
#  print(d)
  
print(m)

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

prev = 0
s = sum(b)

for i in range(n-1):
    if a[i+1] == a[i] + 1:
        # print("match")
        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()))
        
i = A[N-1]
if i < N:
  C.pop(i-1)

print(sum(B) + sum(C))

Submission status: Wrong Answer

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

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

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

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

Solution code:
a = int(input())
List_a=list(map(int,input().split()))
List_b=list(map(int,input().split()))
List_c=list(map(int,input().split()))
B = 0
count = 0
key = 0
for i in List_a:
  B += List_b[i-1]
  if count > 0 and key+1 ==i:
    B += List_c[i-2]
  key = i
  count += 1
  print(B)