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

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

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

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

for i in range(N-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()))
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(sum(b)+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=B[0]
for i in range(1,N):
  ans+=B[i]
  if A[i]==A[i-1]+1:
    ans+=C[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()))
takashi=0
for m,i in enumerate(a):
    takashi+=b[i-1]
    if 0<m<n:
        if abs(a[m]-a[m-1])==1:
            takashi+=c[a[m-1]-1]
print(takashi)

Submission status: Runtime Error

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

i = 0
a = a_s[i]
b = b_s[a]

before_a = a
sas = b
for i in range(1, n):
  a = a_s[i]
  b = b_s[a]
  sas += b
  if before_a + 1 == a:
    sas += c_s[i-1]
  before_a = a
print(sas)

Submission status: Runtime Error

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

i = 0
a = a_s[i]
b = b_s[a]

before_a = a
sas = b
for i in range(1, n):
  a = a_s[i]
  b = b_s[a]
  sas += b
  if before_a + 1 = a:
    sas += c_s[i-1]
  before_a = 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()))

lis=[]
for i in range(0,n-1):
  if a[i]==a[i+1]-1:
    lis.append(a[i])
plus=0
for j in range(0,len(lis)):
  plus+=c[a[j]-1]
print(sum(b)+plus)

Submission status: Runtime Error

Solution code:
n = int(input())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
ans = 0
for i in range(n):
  ans += li_b[li[i]]
  if i-1 >= 0:
      if li_a[i] == li_a[i-1]:
        ans += li_c[i-1]
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()))
list=[]
for i in range(n):
  if lista[i]==lista[i-1]+1:
    list.append(lista[i])
vonus=0
for x in list:
  vonus+=listc[x-1]
print(sum(listb)+vonus)

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()))
list=[]
for i in range(n):
  if lista[i+1]==lista[i]+1:
    list.append(lista[i])
vonus=0
for x in list:
  vonus+=listc[x-1]
print(sum(listb)+vonus)

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

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

Submission status: Runtime Error

Solution code:
n=int(input())
def lima():
    return list(map(int,input().split()))

a=lima()
b=lima()
c=lima()

sum=0
for i in range(n-1):
    sum+=b[a[i]-1]+c[a[i]-1]*(a[i]+1==a[i+1])

print(sum)

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

Submission status: Runtime Error

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

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

    cnt += b[a[i]-1]
    
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [int(z) for z in input().split()]

total = 0
pre = 0
for i in range(N):
    total += b[a[i]-1]
    if a[i] == pre+1:
        total += c[a[i]]
    pre = a[i]
print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [int(z) for z in input().split()]

total = 0
pre = 0
for i in a:
    total += b[i-1]
    if i-1 == pre:
        total += c[pre]
    pre = i
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(" ")))
ans = B[A[0] - 1]
for i in range(1, N):
  ans += B[A[i] - 1]
  if A[i - 1] + 1 == A[i]:
    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()))
c.append(0)
for i in range(n-1):
  if a[i]!=a[i+1]-1:
    c[a[i]]=0
print(sum(b)+sum(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()))
for i in range(n-1):
  if a[i]!=a[i+1]-1:
    c[a[i]]=0
print(sum(b)+sum(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()))

m=0
# 0で初期化すると最初が1の時にだめ
at0
for i,ai in enumerate(a):
    m+=b[ai-1]
    if ai == at+1:
        m+=c[at-1]
    at=ai
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())
   
s=0
bb=sum(b)
for i in range(n-1):
       if a[i]+1==a[i+1]:
               s+=c[a[i]-1]
s+=bb
print(s)

Submission status: Runtime Error

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

s=sum(b)

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

Submission status: Runtime Error

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

s=sum(b)

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

Submission status: Runtime Error

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

s=sum(b)

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

print(ap + ad)

Submission status: Runtime Error

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

sumc = 0
ans = 0
for count in range(1,22):
    sumc = A * count 
    if sumc-count + 1 >= B:
        ans = count 
        break
print(ans)

Submission status: Runtime Error

Solution code:
4
2 3 4 1
13 5 8 24
45 9 15

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

print(co

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

Submission status: Runtime Error

Solution code:
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in range(3)]
x=sum(b)
for i in range(n-1):
    if a[i]+1==a[i+1]:
        b+=c[a[i]-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()))
ans=0
for i in range(N-1):
  ans = ans + B[A[i]]
  if i > 0 and A[i] == A[i-1] + 1:
    ans = ans + C[A[i-1]]
print(str(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
for i in range(N):
  ans = ans + B[A[i]]
  if i > 0 and A[i] == A[i-1] + 1:
    ans = ans + C[A[i-1]]
print(str(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
for i in range(N):
  ans = ans + B[A[i]]
  if i > 0 and A[i] == A[i-1] + 1:
    ans = ans + C[A[i-1]]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a  = [int(i)-1 for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
#ここまで入力
manzoku = 0
for i in range(n):
    if a[i] ==n:
        manzoku += b[a[i]]
    elif i == n-1:
        manzoku += b[a[i]]
    else:
        manzoku += (b[a[i]]+c[a[i]])
print(manzoku)

Submission status: Runtime Error

Solution code:
n = int(input())
a_array = list(map(int(), input().split()))
b_array = list(map(int(), input().split()))
c_array = list(map(int(), input().split()))

c_array.append(0)

sum = 0

for m in a_array:
    sum += b_array[m-1]

for i in range(n-1):
    if (a_array[i] + 1 == a_array[i+1]):
        sum += c_array[a_array[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()))

m = max(a)

print(sum(b) + c[m - 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()))
s=0
for i in range(1,N+1):
  s+=B[A[i-1]]
  if i>=2 and A[i-1]==A[i-2]+1:
    s+=C[i-2]
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()))
s=0
for i in range(N):
  if i>=1 and A[i]==A[i-1}+1:
    s=s+B[A[i]-1]+C[i-1]
  else:
    s=s+B[A[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()))
s=0
for i in range(0,N):
  s+=B[A[i]-1]
  if i>=1 and A[i]==A[i-1}+1:
    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()))
s=0
for i in range(N):
  s+=B[A[i]-1]
  if i>=1 and A[i]==A[i-1}+1:
    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()))
s=0
for i in range(N):
  s+=B[A[i]-1]
  if i>=1 and A[i]==A[i-1}+1:
    s+=C[i]
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()))
b_dic = {}
for i in range(1, N + 1):
  b_dic[i] = B[i - 1]
c_dic = {}
for i in range(1, N):
  c_dic[i] = C[i - 1]
count=0
br = -1
for a in A:
  count += B[a]
  if br == a - 1:
    count += C[br]
  br = a
print(count)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=map(int,input().split())
B=map(int(input().split())
C=map(int,input().split())
A.split()
B.split()
C.split()
for i in range(N):
  s=sum(B[i]):
  if A[i+1]==A[i]+1:
    s=s+C[i]
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()))
happiness = 0
memory = 100
for i in range(N):
  happiness += B[A[i]]
  if memory + 1 == A[i]:
    happiness += C[A[i]-1]
  memory = A[i]
print(happiness)

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int, input().split())
B = list(int, input().split())
C = list(int, input().split())
happiness = 0
memory = 100
for i in range(N):
  happiness += B[A[i]]
  if memory + 1 == A[i]:
    happiness += C[A[i]]
  memory = A[i]
print(happiness)

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()))
d=0

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

b_sum = sum(b)

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

print(b_sum + c_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(" ")))

b_sum = sum(b)

c_sum = 0
for i in range(n-1):
    if a[i] != n and a[i] + 1 == a[i+1]:
        c_sum += c[ai-1]

print(b_sum + c_sum)

Submission status: Runtime Error

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

b_sum = sum(b)

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

print(b_sum + c_sum)

Submission status: Runtime Error

Solution code:
n = input()

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

satisfaction = 0
for i in a:
  satisfaction += b[ i ]
  if i > 0:
    if a[ i ] == a[ i - 1 ] + 1:
    satisfaction += c[ i ]
print( satisfaction )

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())
plug = 1
cnt = 0
while plug < B:
  plug += A - 1
  cnt += 1
print(cnt)

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(len(A)):
  sum+=B[i]
  try
    if A[i]+1==A[i+1]:
      sum+=C[i]
  except:
    pass
print(sum)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
using namespace std;
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b,a % b);
}
int combination(int n, int k){
    int spaceOptimize[k+1];
    memset(spaceOptimize, 0, sizeof(spaceOptimize));
    spaceOptimize[0] = 1;
    for(int i=1;i<=n; i++){
        for(int j= min(i,k);j>0;j--){
            spaceOptimize[j] = spaceOptimize[j] + spaceOptimize[j-1];
        }
    }
    return spaceOptimize[k];
}
int count_permutation(int arr[], int n){
    int a[n];
    for(int i=0;i<n;i++){
        a[i] = i+1;
    }
    int count = 0;
    do {
        count++;
        if (equal(a, a + n, arr)){
            return count;
        }
    } while (next_permutation(a, a + n));
    return 0;
}

signed main(){
#ifndef ONLINE_JUDGE
   // freopen("input.txt","r", stdin);
#endif
    fastIO

    int n;
    cin >> n;
    int a[n],b[n],c[n-1];
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    for(int i=0;i<n-1;i++){
        cin >> c[i];
    }
    set<int> allReady;
    int ans = b[a[0]];
    allReady.insert(a[0]);
    for(int i=1;i<n;i++){
        ans += b[a[i]];
//        cout << "1 - ans = " <<ans << endl;
        if(allReady.find(a[i]-1) != allReady.end()){
//            cout << "in if\n";
            ans += c[a[i-1]];
        }
//        cout << "2 - ans = " <<ans << endl;
        allReady.insert(a[i]);
    }
    cout << ans;

    return 0;
}

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

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

count = 0
for i in range(N):
	# print('B:',B[A[i]-1])
	# 追加の満足度が入らない場合は除く
	if i == 0:
		count += B[A[i]-1]
	else:
		count += B[A[i]-1]
		if abs(A[i]-A[i-1]) == 1:
			# print('C:',C[A[i-1]-1])
			count += C[A[i-1]-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
last = -1
for i in a:
  last = a
  ans += b[a-1]
  if a = last + 1:
    ans += c[a-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()))

count = 0

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

for i in range(0, N - 1):
    count += C[i]

if N > 2:
    count -= C[A[N - 1] - 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()))
cnt = 0
for i in range(3):
    cnt += B[A[i]-1]
    if i < N-1:
        if A[i]+1==A[i+1]:
            cnt += C[A[i]-1]
print(cnt)

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

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

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

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

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.append(100)
B.append(100)
ans=0
for i in range(1,N+1):
	ans+=B[A[i-1]-1]
	if A[i-1]==A[i]-1:
		ans+=C[A[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()))
A.append()
B.append()
ans=0
for i in range(1,N+1):
	ans+=B[A[i-1]-1]
	if A[i-1]==A[i]-1:
		ans+=C[A[i-2]]
print(ans)

Submission status: Runtime Error

Solution code:
C = list(map(int, input().split()))
A.append("")
B.append("")
ans=0
for i in range(1,N+1):
	ans+=B[A[i-1]-1]
	if A[i-1]==A[i]-1:
		ans+=C[A[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()))
ans=0
for i in range(N):
	ans+=B[A[i]]
	if A[i]==A[i-1]+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()))
 
happy = 0
 
for i in range(N):
  happy += B[A[i]]
  if A[i]+1 == A[i+1]:
    happy += C[i]
 
print(happy)

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

print(happy)

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

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

print(sum(b)+tmp)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
A=input()
B=input()
C=input()

As=list(map(int,A.split(' ')))
Bs=list(map(int,B.split(' ')))
Cs=list(map(int,C.split(' ')))
total=0
for i in range(0,n):
    if As[i]-As[i-1]==1 and i!=0:
        total=total+Cs[As[i]-1]
    else:
        total=total+Bs[As[i]-1]
print(total)

Submission status: Runtime Error

Solution code:
n=input()
A=input()
B=input()
C=input()

As=map(int,A.split(' '))
Bs=map(int,B.split(' '))
Cs=map(int,C.split(' '))
total=0
for i in range(0,n):
    if As[i]-As[i-1]==1 and i!=0:
        total=total+Cs[As[i]]
    else:
        total=total+Bs[As[i]]
print(total)

Submission status: Runtime Error

Solution code:
n=input()
A=input()
B=input()
C=input()

As=map(int,A.split(' '))
Bs=map(int,B.split(' '))
Cs=map(int,C.split(' '))
total=0
for i in range(0,n):
    if As[i]-As[i-1]==1 and i!=0:
        total=total+Cs[A[i]]
    else:
        total=total+Bs[A[i]]
print(total)

Submission status: Runtime Error

Solution code:
n=input()
A=input()
B=input()
C=input()

As=map(int,A.split(' '))
Bs=map(int,B.split(' '))
Cs=map(int,C.split(' '))
total=0
for i in range(0,n):
    if A[i]-A[i-1]==1 and i!=0:
        total=total+Cs[A[i]]
    else:
        total=total+Bs[A[i]]
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()))
res = sum(b)
for i in range(len(a) - 1):
  if a[i+1] == a[i] + 1:
    res += c[a[i]]
print(res)

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

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

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

a = int(input().split())
b = int(input().split())
c = int(input().split())

for i in range(n):
  if i > 0:
    sat += b[a[i]]
    if a[i-1]+1 == a[i]:
      sat += c[a[i-1]]
  else:
    sat += b[a[i]]

print(sat)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
result= 0
for i in range (n):
  result += b[i]
c = input().split()
c = [int(i) for i in c]
for i in range (n):
  if a[i] - a[i-1] == 1:
    result += c[i-2]
  else:
    break
print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
result= 0
for i in range(n):
  i = a[i]
for i in range (n):
  result += b[i]
c = input().split()
c = [int(i) for i in c]
for i in range (n):
  if a[i] - a[i-1] == 1:
    result += c[i-2]
  else:
    break
print(result)

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
     item=int(intput())
     a.append(item)
b=[]
for i in range(n):
     item=int(intput())
     b.append(item)
c=[]
for i in range(n):
     item=int(intput())
     c.append(item)
sum=0
for i in range(n):
    if i>0:
        if a[i]-1==a[i-1]:
           sum+=b[a[i]-1]+c[a[i-1]-1]
        else :
           sum+=b[a[i]-1]
        
    else:
       sum+=b[a[i]-1]
print(sum)

Submission status: Runtime Error

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

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
pred_i=np.inf
for i in A:
    if pred_i+1 ==i:
        score=score+C[i-2]+B[i-1]
    else:
        score+=B[i-1]
    pred_i=i
print(score)

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

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

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

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

print(res)

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

bonus=0
for x in range(0,n):
  if A[x] == A[x+1] +1:
    bonus += C[x]

ans = sum(B) + bonus
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()))

count = 0

for i in range(n):

    if i == 0:
        count += b[a[i]-1]

    else:
        count += b[a[i]-1]

        if a[i] - a[i-1] == 1:
            count += c[a[i-1]-1]

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
foods = list(map(int,input().split()))
satis_1 = list(map(int,input().split()))
satis_2 = list(map(int,input().split()))
ttl = 0

for i in range(n):
  food = foods[i]
  ttl += satis_1[food-1]
  if(i > 0 and i<n-1):
    ttl += satis_2[food-1]
print(ttl)