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: Runtime Error

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

print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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]]
  if i < n-1 and a[i+1] == a[i]+1:
    s += c[i]

print(s)

Submission status: Runtime Error

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

bj=0
newlist=0
for j in List[0]:
  newlist += List[1][j-1]
  if j-bj==1: 
    newlist += List[2][j-2]
  bj=j

print(newlist)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
Row=int(input())

List=[]
try:
  for i in range(Row):
    List.append(list(map(int,input().split())))
except EOFError:
    pass
  
bj=0
newlist=0
for j in List[0]:
  newlist += List[1][j-1]
  if j-bj==1: 
    newlist += List[2][j-2]
  bj=j

print(newlist)

Submission status: Runtime Error

Solution code:
Row=int(input())

List=[]
try:
  for i in range(Row):
    List.append(list(map(int,input().split())))
except EOFError:
    pass
  
bj=0
newlist=0
blist=0
for j in List[0]:
  newlist += List[1][j-1]
  if bj is not None and j-bj==1: 
    newlist += List[2][j-2]
  bj=j

print(newlist)

Submission status: Runtime Error

Solution code:
num = int(input())
A_i = [ int(x) for x in input().split()]
B_i = [ int(x) for x in input().split()]
C_i = [ int(x) for x in input().split()]

prev = 0
for a in a_i:
  result += B_i[a]
  if prev > 0 and a-1 == prev:
    result += C_i[prev]
  
print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
x = input().split()
y = input().split()
z = input().split()
x_i = [int(s_x) for s_x in x]
y_i = [int(s_y) for s_y in y]
z_i = [int(s_z) for s_z in z]
m = 0
i_bef = 0
for i in x_i:
    if i < len(z_i) or i ==x_i[0]:
        m = m + y_i[i-1]
    else:
        m = m + y_i[i-1] + z_i[i_bef-1]
    i_bef = i
print(m)

Submission status: Runtime Error

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 = 0
for i in range(m):
    if a[i+1] == a[i]+1:
        sumc += c[i]
#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: Runtime Error

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

box = []


for i in range(1, N):
    if A[i] == A[i-1] + 1:
        box.append(B[A[i-1]] + C[i-2] if i >=2 else c[0])
        
    else:
        box.append(B[A[i]-1])


print(sum(box) + B[A[0]-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
orders = [ int(_) for _ in input().split()]
Bn = [ int(_) for _ in input().split()]
Cn = [ int(_) for _ in input().split()]

utility = 0
for i in range(orders):
  utility += Bn[orders[i]-1]
  if i!=0 and orders[i-1] +1 == orders[i]:
    utility += Cn[i-1]

print(utility)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().rstrip().split()]
B = [int(i) for i in input().rstrip().split()]
if N >2:
    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: Runtime Error

Solution code:
a=input()
n=input()
n=int(n)

a = list(int(i) for i in input().split()) 
b = list(int(i) for i in input().split()) 
c =  list(int(i) for i in input().split()) 
d=abs(2-n)

buf = b[a[0]-1]
for i in range(1,n-1):
  buf = b[a[i]-1] +  buf +c[a[i]-d]


buf =b[a[n-1]-1] +  buf
  
print(buf)

Submission status: Runtime Error

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) + sum(B)
else:
        manzoku += sum(C) - C[A[0]-1] +sum(B)

print(manzoku)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(num):
	if i == 0:
		sum += b[a[i]-1]
	else:
		sum += b[a[i]-1]
		if (a[i]-1) == a[i-1]:
			sum += c[a[i-1]]

print(sum)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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(len(A)-1):
    if A[i] + 1 == A[i+1]:
        if N % 2 == 1 or N == 2:
            ans += C[i-1]
        else:
            ans += C[i+1]

print(ans)

Submission status: Runtime Error

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

print(sum)

Submission status: Runtime Error

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

for i in range(n-1):
  sum = sum + l[1][i]
  if l[0][i+1] - l[0][i] == 1:
    sum = sum + l[2][l[0][i]]
sum = sum + l[1][n-1]
print(sum)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

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

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

print(a)

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())
add_s = 0
for order in range(N-1):
  cur_f = A[order]
  nxt_f = A[order+1]
  add_s += C[order] if nxt_f == cur_f + 1 else 0
  
print(sum(B) + add_s)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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)
while n<N:
    manzoku += B[n]
    n += 1

if A[0] == hantei:
        manzoku += sum(C)
else:
        manzoku += sum(C) - C[A[0]-1]

print(manzoku)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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)
while n<N:
    manzoku += B[n]
    n += 1

if A[0] == hantei:
        manzoku += sum(C)
else:
        manzoku += sum(C) - C[A[0]]

print(manzoku)

Submission status: Runtime Error

Solution code:
n = int(input())

a = []
for i in range(n):
  a.append(int(input()))

b = []
for i in range(n):
  b.append(int(input()))

c = []
for i in range(n - 1):
  c.append(int(input()))

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: Runtime Error

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

s = 0
prev = 0
for f in A:
  if prev != 0:
    s += B[f-1]
    s += C[prev-1]
  else:
    s += B[f-1]
  prev = f
print(s)

Submission status: Runtime Error

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

a=0

for i in List[0]:
  a+=List[1][i-1]

for i in range(len(List[0])-1):
  if List[1][i]-List[1][i+1] == 1:
    a+=List[2][i-1]

print(a)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [0] * N
B = [0] * N
C = [0] * N
for i in range(N):
    A[i], B[i], C[i] = map(int, input().split())

j=int(0)
manzoku=int(0)
while j<N:
    manzoku += B[j]
    j += 1
    if A[0]=1:
        manzoku += sum(C)
    else:
        manzoku += sum(C) - C[A[0]]

print(manzoku)

Submission status: Runtime Error

Solution code:
# a.py
# N = int(input()) #ここで標準入力
# # print (type(N),N) 

# print(N*N*N)
#### ##################
# b.py
man=0
N = int(input()) #ここで標準入力
A = [input().split() for i in range(3)]
# print(A)
# B全部たす
for i in range(N):
   man=man+int(A[1][i])
#例外処理
for i in range(N-1):
   if(A[0][i]<=A[0][i+1]):
      # print(man)
      cn=int(A[0][i])
      man=man+int(A[2][cn-1])
      # print (cn)

print(man)

Submission status: Runtime Error

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

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

    addb += b[i]
print(addc+addb)

Submission status: Runtime Error

Solution code:
# a.py
# N = int(input()) #ここで標準入力
# # print (type(N),N) 

# print(N*N*N)
#### ##################
# b.py
man=0

N = int(input()) #ここで標準入力
A = [input().split() for i in range(3)]

# print(A)
# B全部たす
for i in range(N):
   man=man+int(A[1][i])
#例外処理
for i in range(N-1):
   if(A[0][i]<A[0][i+1]):
      # print(man)
      cn=int(A[0][i])
      man=man+int(A[2][cn-1])
      # print (cn)


print(man)

Submission status: Runtime Error

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

count=0

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

Submission status: Runtime Error

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):
      #print(i)
      ans += b[a[i]-1]
      #print("ans",ans)
  #print("aaa",a[i])
      if i != 0:
        hantei = a[i-1] + 1
        if a[i] == hantei:
            ans += c[i]
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
B =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
C =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

ans=0

x=-1
for a in A:
	
	if a==x+1:
		ans+=C[a]
	else:
		ans+=B[a]
	x=a

print(ans)

Submission status: Runtime Error

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

s = 0
last = -2
for j in range(N):
    s += B[A[j]-1]
    if A[j] == last+1:
      s += C[last-1]
    last = A[j]
    
print(s)a

Submission status: Runtime Error

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())) 
plus_ans=int()
for i in range(0,n):
    if a_list[i-1]==a_list[i]-1:
        if i!=0:
            plus_ans+=c_list[i]
ans=sum(b_list)+plus_ans
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

    addb += b[i]
print(addc+addb)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(n):
  sum = sum + l[1][i]
  if l[0][i+1] - l[0][i] == 1:
    sum = sum + l[2][i]
sum = sum + l[1][n]
print(sum)

Submission status: Runtime Error

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

N = raw_input()
ans = 0

a = []
b = []
c = []
for i in range(N):
    a.append(map(int, raw_input().split()))
for i in range(N):
    b.append(map(int, raw_input().split()))
for i in range(N):
    c.append(map(int, raw_input().split()))
    
for i in range(N-1)
	if a[N] - a[N+1] == 1
  		ans += c[N]
ans += sum(b)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
num = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
result = 0

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

print(result)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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]]].sum()
#print(sb, sC)
print(sb+sC)

Submission status: Runtime Error

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: Runtime Error

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

for i in range(n):
  sum += l[1][i]
  if l[0][i+1] == l[0][i]+1:
    sum += l[2][i]

print(sum)

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
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: Runtime Error

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

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

sum = 0
tmp = 0
cc = 0

for m in range(n):
    i = a[m]
    print(f"i = {i}")
    print(f"tmp = {tmp}")
    if tmp == i-1:
        cc = c[i-2]
        print(f"cc = {cc}")
    else:
        cc = 0
    sum += b[i-1]
    sum += cc
    tmp = i

print(sum)

Submission status: Runtime Error

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

N = raw_input()
ans = 0
Al = map(int, raw_input().split())
Bl = map(int, raw_input().split())
Cl = map(int, raw_input().split())

for i in range(N)
	if Al[N] - Al[N+1] == 1
  		ans += Cl[N]
ans += sum(Bl)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
i=0
manzoku=0
while i<N:
    manzoku += B[i]
    i += 1
if A[0]=1:
    manzoku += sum(C)
else:
    manzoku += sum(C) - C[A[0]]

print(manzoku)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
i=0
manzoku=0
j=0
while i<N:
    manzoku += B[i]
    i += 1
if A[0]=1:
    manzoku += sum(C)
else:
    manzoku += sum(C) - C[A[0]]

print('manzoku')

Submission status: Runtime Error

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,)
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: Runtime Error

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

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

Submission status: Runtime Error

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 - 1]
    temp = num

print(point)

Submission status: Runtime Error

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: Runtime Error

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

for i in range(n):
  sum += l[1][i]
  if l[0][i+1] == l[0][i]+1:
    sum += l[2][i]

print(sum)

Submission status: Runtime Error

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]]
  elif a[i]==a[i-1]+1:
    s=s+b[a[i]-1]+c[a[i]-2]
  else:
    s=s+b[a[i]]
print(s)

Submission status: Runtime Error

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

for i in range(n):
  sum += l[1][i]
  if l[0][i] == l[0][i+1]:
    sum += l[2][i]

print(sum)

Submission status: Runtime Error

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

for i in range(n)
	if a[i] == a[i+1]:
        addc += c[i]
    else:
        addb += b[i]
print(addc+addb)

Submission status: Runtime Error

Solution code:
N=int(input())
listA = list(map(int,input().split()))
listB = list(map(int,input().split()))
listC = list(map(int,input().split()))

listD = [ListA,ListB,ListC]
sorted(listD)
print(sum(listD[1])+sum(list[2]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
c=0
n=int(input())
A_list=input().split()
B_list=input().split()
C_list=input().split()
for i in range(0,n):
  c+=B_list[A_list[i]-1]
  if i==n:
    break
  if A_list[i]==(A_list[i+1]-1):
    c+=C_list[A_list[i+1]-1]
print(c)

Submission status: Runtime Error

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

for i in range(n)
	if a[i] == a[i+1]:
      addc += c[i]
    else:
      addb += b[i]
print(addc+addb)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a;
  vector<int> num_a;
  vector<int> num_b;  
  vector<int> num_c;
  int sum=0;
  cin>>a;
  for(int i=0;i<a;i++){
    int tmp;
    cin>>tmp;
    num_a.push_back(tmp);
  }
  for(int i=0;i<a;i++){
    int tmp;
    cin>>tmp;
    num_b.push_back(tmp);
  }
  for(int i=0;i<a-1;i++){
    int tmp;
    cin>>tmp;
    num_c.push_back(tmp);
  }

  for(int i=0;i<a-1;i++){
    if(num_a[i]+1==num_a[i+1]){
      sum = sum+ num_c[num_a[i]-1];
    }
  }
  sum =sum+ accumulate(num_b.begin(), num_b.end(), 0); 
  cout<<sum<<endl; 
}

Submission status: Runtime Error

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
C = 0
count = 0
key = 0
for i in List_a:
  B += List_b[i-1]
  if count > 0 and key+1 ==i:
    C += List_c[i-2]
  key = i
  count += 1
 print(B+C)

Submission status: Runtime Error

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 = _orderprint(score)

Submission status: Runtime Error

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)):
  if A[x] + 1 == A[x+1]:
    y.append(x)
 
 
for k in range(len(y)):
  t = t + C[k]
print(t)

Submission status: Runtime Error

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
count = n + 1

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

print(point)

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
N=int(input())
listA = list(map(int,input().split()))
listB = list(map(int,input().split()))
listC = list(map(int,input().split()))

listD = [ListA,ListB]
sorted(listD)
print(sum(listD[1]))

Submission status: Runtime Error

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 ramnge(len(A)):
  if A[x] + 1 == A[x+1]:
    y.append(x)
 
 
for k in range(len(y)):
  t = t + C[k]
print(t)

Submission status: Runtime Error

Solution code:
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]:
      d += c[i-1]
  
print(d)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
ソースコード 拡げる

Copy
Copy
N = int(input())
A = list(int,input().split())
B = list(int,input().split())
C = list(int,input().split())
 
t = 0
for i in B:
  t = t + i
  
y = []
for x in ramnge(len(A)):
  if A[x] + 1 == A[x+1]:
    y.append(x)
 

for k in range(len(y)):
  t = t + C[k]
print(t)

Submission status: Runtime Error

Solution code:
n = int(input())
d = 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<(n-1) and d[i]==(d[i+1]-1)):
        ans+=c[i-2]
print(ans)

Submission status: Runtime Error

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
prev = 0

for a in A:
  manzoku += B[a-1]
  if prev != 0 && != N:
    manzoku += C[prev-1]
  prev = a
print(manzoku)