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

Submission status: Runtime Error

Solution code:
num = int(input())
order = input().split()
manzoku = input().split()
additional = input().split()

prev = 0
ans = 0
for i in range(num):
  ans += manzoku[i]
  if i = prev+1:
    ans += additional[i]
  prev += 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 in range(n-1):
    if a[i+1] - a[i] == 1:
        add = a[i-1]
        ans += c[add]
    else:
        pass
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
B = []
C = []
for i in range(1,N+1):
  A += [int(input())]
for i in range(1,N+1):
  B += [int(input())]
for i in range(1,N+1):
  C += [int(input())]
d = 0:
for i in range(1,N):
 if A[i] == A[i-1]+1:
    d += C[i-1]
for i in range(1,N+1):
    d += B[i-1]
print(d)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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()]
r = 0
a = 0
for i in range(N):
    r += B[A[i]-1]
    if  i-1 > len(C)-1 or [A[i-1]-1] >len(C)-1:
        continue
    elif A[i] == a+1 :
        r += C[A[i-1]-1]
    a = A[i]
print(r)

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

Submission status: Runtime Error

Solution code:
N = int(input())

AryA = list(map(int, input().split()))

AryB = list(map(int, input().split()))

AryC = list(map(int, input().split()))

sum = 0
tmpBox = N+1

for item in AryA:
	sum += AryB[item]
	if (item == tmpBox + 1):
		sum += AryC[tmpBox]

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

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

r = np.sum(B)
for i in range(N-1):
  if A[i] + 1 == A[i + 1]:
    r += C[A[i]]

print(r)

Submission status: Runtime Error

Solution code:
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    ArrayList<Integer> as = new ArrayList<>();
    ArrayList<Integer> bs = new ArrayList<>();
    ArrayList<Integer> cs = new ArrayList<>();

    for (int i = 0; i < n; i++) {
      as.add(sc.nextInt());
    }
    for (int i = 0; i < n; i++) {
      bs.add(sc.nextInt());
    }
    for (int i = 0; i < n -1 ; i++) {
      cs.add(sc.nextInt());
    }

    int ans = 0;
    int prev = -1;
    for (int a : as) {
      ans += bs.get(a -1);
      if (a - prev == 1) {
        ans += cs.get(a - 2);
      }
      prev = a;
    }
    System.out.println(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 = sum(c) + sum(b) - c[a[n-1]-1]

print(sum)

Submission status: Runtime Error

Solution code:
num = int(input())
order = [int(s) for s in input().split()]
utility = [int(s) for s in input().split()]
add = [int(s) for s in input().split()]
point = 0
for i in range(num - 1):
  if order[i] + 1 == order[i + 1]:
    point += add[order[i]]
    
print(sum(utility) + 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()))

total = 0
pos = 0
while pos < N:
	posB = A[pos] -1
	total = total + B[posB]
	if A[pos + 1] - A[pos] == 1:
		posC = A[pos + 1] - 2
		total = total + C[posC]
	pos += 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())]

total = 0
pos = 0
while pos < N:
  total += B[A[pos] - 1]
  if A[pos + 1] - A[pos] == 1:
    total += C[A[pos + 1] - 2]
  pos += 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())]

total = 0
pos = 0
while pos < N:
  total = total + B[A[pos] - 1]
  if A[pos + 1] - A[pos] == 1:
    total = total + C[A[pos + 1] - 2]
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())]

total = 0
pos = 0
while pos < len(A):
	total = total + B[A[pos] - 1]
	if A[pos + 1] - A[pos] = 1:
		total = total + C[A[pos+1] - 2]
	pos += 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()))

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

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

sat = sum(B)
pre_a = A[0]
for a in A[1:]:
  if a == pre_a + 1:
    sat += C[pre_a]
  pre_a = a
  
print(sat)

Submission status: Runtime Error

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

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

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

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

base = sum(B)
bonus = 0
for i, num in enumerate(A):
  if i+1 >= len(A):
    break
  if A[i+1] == A[i] + 1:
    bonus += C[i+1]

print(base + bonus)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    in_arr(int, a, n);
    in_arr(int, b, n);
    in_arr(int, c, n - 1);
    int previ = -2;
    int ans = 0;
    repi(i, a) {
        int j = *i - 1;
        ans += b[j];
        if(previ + 1 == j) {
            ans += c[j - 1];
        }
        previ = j;
    }
    cout << ans << endl;
    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):
  num = int(a[i])
  m += b[num - 1]
  
  if num != n and != n - 1:
    if int(a[i]) == int(a[i + 1]):
      m += c[num - 1]
    
print(m)
print(a[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):
  num = int(a[i])
  m += b[num - 1]
  
  if num != n:
    if int(a[i]) == int(a[i + 1]):
      m += c[num - 1]
    
print(m)
print(a[0])

Submission status: Runtime Error

Solution code:
n = int(imput())
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):
  num = a[i]
  m += b[num]
  
  if a[i + 1] == num + 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()))

manzoku=0;

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

manzoku=0;

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

manzoku=0;

for i in range(len(A)):
	a=A[i]
	manzoku+=B[a-1]
	if i+1<n and A[i+1]-A[i]==1 :
		manzoku+=C[a-1]
	i+=1
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()))

manzoku=0;
i=0; #A[i]を参照する
while i<len(A):
	a=A[i]
	manzoku+=B[a]
	if i+1<n and A[i+1]-A[i]==1 :
		manzoku+=C[a]
	i+=1
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()))

manzoku=0
i=0 #A[i]を参照する
while i<len(A):
	a=A[i]
	manzoku+=a
	if A[i+1]-A[i]==1 :
		manzoku+=C[a]
	i+=1
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()))

manzoku=0
i=0 #A[i]を参照する
while i<len(A):
	a=A[i]
	manzoku+=a
	if A[i+1]-A[i]==1 :
		manzoku+=C[a]
	i+=1
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 = sum(b)
for i in range(1, n):
  if a[i] == a[i - 1] + 1 and i != n:
    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
for i in range(n):
  ai = a[i]
  pre_ai = 0
  if i != 0:
    pre_ai = a[i-1]
    
  ans += b[ai]
  if ai - pre_ai = 1:
    ans += c[pre_ai]
    
print (ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A =[input() for i in range(n)]
B =[input() for i in range(n)]

print(N,A,B)

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())

x = lambda: map(int, raw_input().strip().split())

A = x()
B = x()
C = x()

points = 0
for i in xrange(n):
  points += B[A[i]-1]
  if i > 0 and A[i] == A[i-1] + 1:
    points += C[A[i]-1]

print points

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = int(input().split())
B = int(input().split())
C = int(input().split())
S = 0
before = 100

for i in range(n):
    S += B[A[i]]
    if A[i] == before + 1:
        S += C[before]
    before = A[i]

print(S)

Submission status: Runtime Error

Solution code:
N = int(input())
Ai = [int(i) for i in input().split(" ")]
Bi = [int(i) for i in input().split(" ")]
Ci = [int(i) for i in input().split(" ")]

res = 0
pre_i = None
for i in Ai:
  res += Bi[i-1]
  if i == pre_i+1:
    res += Ci[i-1]
  pre_i = i

  print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
Ai = [int(i) for i in input().split(" ")]
Bi = [int(i) for i in input().split(" ")]
Ci = [int(i) for i in input().split(" ")]

res = 0
res += Ai[N+1]
res += Bi[N+1]
res += Ci[N+2]

print(res)

Submission status: Runtime Error

Solution code:
n = int(input())

order = list(map(int, input().split()))
menu = {}
tmp = list(map(int, input().split()))
for i in range(n):
    menu[i] = tmp[i]
# print(menu)
add = {}
tmp = list(map(int, input().split()))
for i in range(n-1):
    add[i] = tmp[i]

result = 0

for i in range(len(order)):
    # print(order[i]-1, menu[order[i]-1])
    result += menu[order[i]-1]
    if i < len(order)-1:
        if order[i+1] - order[i] == 1:
            # print(add[i-1])
            result += add[i-1]

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

ans = 0
for i in range(N):
  ans += B[A[i]]
  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()))
max=0

for i in range(N):
    max=max+b[a[i]]+c[a[i-1]]
print(max)

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)
max=0

for i in range(1,N+1):
    max=max+b[a[i]]+c[a[i-1]]
print(max)

Submission status: Runtime Error

Solution code:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

void solve(long long N, std::vector<long long> A, std::vector<long long> B,std::vector<long long> C) {
  int ans = 0;
  REP(i, N){
    ans += B[A[i]-1];
    // debug(B[A[i]-1])
    if(i>0){
      if(A[i]-A[i-1]==1){
        ans+=C[A[i-1]-1];
        // debug(C[A[i-1]-1)
      }
    }
  }
  cout<<ans<<endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &B[i]);
  }
  std::vector<long long> C(N - 1);
  for (int i = 0; i < N - 1; i++) {
    scanf("%lld", &C[i]);
  }
  solve(N, std::move(A), std::move(B), std::move(C));
  return 0;
}

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

for i in a:
  sat += b[i]
  pre = i
  if pre + 1 == i:
    sat += c[pre]

print(sat)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = sum(list(map(int, input().split())))
c = list(map(int, input().split()))
for i in range(n-1):
  if a[i+1]-a[i]==1:
    b+=c[a[i]-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()))
total = sum(b)
for i in range(n):
  if a[i+1]-a[i]==1:
    total+=c[i]
print(total)

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

s = 0

for i in a:
  s =+ b[i]
  if b[i] == b[i+1] -1:
    s =+ c[i]

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

ans = 0
for i in range(n):
  if i >= 1 and a[i - 1] + 1 == a[i]:
    ans += c[i - 1]
  ans += b[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()))
s=sum(b)
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_lis = list(map(int,input().split()))
b_lis = list(map(int,input().split()))
c_lis = list(map(int,input().split()))

s = 0

for i in range(n):
  if a_lis[i+1] - a_lis[i] == 1:
    s += c_lis[a_lis[i]]
print(sum(b_lis)+s)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input().split() for l in range(N)]
B = [input().split() for l in range(N)]
C = [input().split() for l in range(N-1)]
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input().split() for l in range(N)]
B = [input().split() for l in range(N)]
C = [input().split() for l in range(N-1)]
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input().split() for l in range(N)]
B = [input().split() for l in range(N)]
C = [input().split() for l in range(N-1)]
ans = 0

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

former = -10
satisfy = 0
for i in a:
    satisfy += b[i-1]
    if i == former + 1:
        satisfy += c[i-2]
    former = i
print(satisfy)

Submission status: Runtime Error

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

former = -10
satisfy = 0
for i in a:
    satisfy += b[i-1]
    if i == former + 1:
        satisfy += c[i-2]
    former = i
print(satisfy)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

former = -10
satisfy = 0
for i in a:
    satisfy += b[i-1]
    if i == former + 1:
        satisfy += c[i-1]
    former = i
print(satisfy)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N - 1);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  for (int i = 0; i < N - 1; ++i) {
    cin >> C[i];
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += B[A[i] - 1];
    if (i < N - 1 and (A[i] + 1 == A[i + 1])) {
      ans += C[A[i] - 1];
    }
  }
  cout << ans << endl;
  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()))

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

Submission status: Runtime Error

Solution code:
if (__name__ == '__main__'):
    a = [0]
    b = [0]
    c = [0]

    aa = input().strip().split()
    for i in range(n):
        a.append(int(aa[i]))
    bb = input().strip().split()
    for i in range(n):
        b.append(int(bb[i]))
    cc = input().strip().split()
    for i in range(n-1):
        c.append(int(cc[i]))

    sum = b[a[1]]
    lastmenu = a[1]

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

    print(sum)

Submission status: Runtime Error

Solution code:

if (__name__ == '__main__'):
    n = int(input())
    a = [0]
    b = [0]
    c = [0]
    aa = input().strip().split()
    for i in range(n):
        a.append(int(aa[i]))
    aa = input().strip().split()
        for i in range(n):
            a.append(int(aa[i]))
    bb = input().strip().split()
        for i in range(n):
            b.append(int(bb[i]))
    c = input().strip().split()
        for i in range(n-1):
            c.append(int(cc[i]))

    sum = b[a[1]]
    lastmenu = a[1]

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

    print(sum)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n = INT()
A = LIST()
B = LIST()
C = LIST()
ans = 0
for i in range(n):
  if A[i]+1 == A[i+1]:
    ans += C[i]
print(ans + sum(B))

Submission status: Runtime Error

Solution code:
N=int(input())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
Ci = list(map(int,input().split()))

ans ~ sum(Bi)

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

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

# 定義してないリストを参照するとエラーがでるからダミー置いといた。
A.append(100)
C.append(0)

total = 0

total = sum(B)

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

print(total)

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

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

print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
a,b,c=[map(list,map(int,input().split())) for _ in range(3)] 
x=0
for i,_ in enumerate(a):
  if(i==len(a)-1):
    break
  elif(a[i]+1==a[i+1]):
    x+=c[a[i]-1]
print(sum(b)+x)