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

total=sum(B)

for j in range(N):
  if j+1!=N:
    if A[j]+1==A[j+1]:
      total+=C[A[j-1]]
      
print(total)

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

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

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()))
ans = sum(B_list)

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

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)

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

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

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

outNum = 0
outNum += sum(B_list)
a_prev = 0

for index, a in enumerate(A_list):
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        outNum += C_list[index]
    a_prev = a
    
print(out)

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

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

out = 0
out += sum(B_list)
#print("out", out)

a_prev = 0

for index, a in enumerate(A_list):
#    print(index, a, a_prev)
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        out += C_list[index]
    a_prev = a
    
print(out)

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

if(len(a) >2):
  result = sum(b) + sum(c) - c[a[-1]-1]
  print(result)
else:
  result = sum(b) + c[0]
  print(result)

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

out = 0
out += sum(B_list)
print("out", out)

a_prev = 0

for index, a in enumerate(A_list):
    print(index, a, a_prev)
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        out += C_list[index]
    a_prev = a
    
print(out)

Submission status: Runtime Error

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

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

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

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

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

print(point)

Submission status: Runtime Error

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

sb=sum(B)
dC=np.diff(A)
sC=C[np.where(dC==1)[0]].sum()

print(sb+sC)

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

manzokudo = 0
for B in Blist:
    manzokudo += B
    
for i in range(len(Alist) - 1):
    if Alist[i]+1 == Alist[i+1]:
        manzokudo += Clist[i+1]

print(manzokudo)

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

x = 1
manzoku = 0

mae = a[0]

manzoku += b[a[x]]
while(n):
  manzoku += b[a[x]]
  if a[x] - 1 == mae:
    manzoku += c[a[x] - 1]
  x += 1
  if x == n:
    break

print(manzoku)

Submission status: Runtime Error

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

sb=sum(B)
dC=np.diff(A)
sC=C[np.where(dC==1)[0]].sum()

print(sb+sC)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define HSORT(V,n) sort(V,V+n)
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n-1];
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n-1) cin >> c[i];
    int man = b[a[0] - 1];
    REP(i,n-1){
        man += b[a[i+1] - 1];
        if (a[i+1] == a[i] + 1){
            man += c[a[i]-1];
        }
    }
    PRINT(man);
}

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

Submission status: Runtime Error

Solution code:
n = int(input())
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] 

sut = 0
for i,ind in enumerate(a):
    sut += b[ind-1]
    if i>=1:
        if a[i-1]+1 == a[i]:
            sut += c[i]
print(sut)

Submission status: Runtime Error

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

satisfy = sum(B)

for i in range(len(A)-1):
  if A[i+1]-A[i] is 1:
    satisfy += C[A[i]]

print(satisfy)

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

Submission status: Runtime Error

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

sb=sum(B)
dC=np.diff(A)
sC=C[np.where(dC==1)[0]].sum()

print(sb+sC)

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

ful = sum(B)

for i in range(N-1):
  if (A[i+1]-A[i]) == 1:
    ful += C[A[i]]

print(ful)

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

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

Submission status: Runtime Error

Solution code:
ans = 0
for i, a in enumerate(A):
    ans += B[a-1]
    if a - A[i-1] == 1 and i-1 > 0:
        ans += C[i-2]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split())) # taberu order
b = list(map(int, input().split())) # get
c = list(map(int, input().split())) # renzoku

ans = 0
for i in range(n):
  po = a[i]
  ans += b[po]

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

Submission status: Runtime Error

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

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)

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ful = sum(B)

for i in range(N-1):
  if (A[i+1]-A[i]) == 1:
    ful += C[A[i]]

print(ful)

Submission status: Runtime Error

Solution code:
def solve():
  import sys
  import math

  sys.setrecursionlimit(10**7)
  readline=sys.stdin.readline

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

  print(ans)


if __name__ == '__main__':
  solve()

Submission status: Runtime Error

Solution code:
N = int(input())

A = []
for i in range(N):
    A.append(list(map(int,input().split())))
B = []
for i in range(N):
    B.append(list(map(int,input().split())))
C = []
for i in range(N-1):
    C.append(list(map(int,input().split())))

ans = 0
before = 9999
for i in range(N):
    ans += B[A[i]-1]
    if A[i]==before + 1:
        ans += c[i-1]

print(ans)

Submission status: Runtime Error

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

ans = 0

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

Submission status: Runtime Error

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

print(ans)