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: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
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:
        ans+=c[a[i]-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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,(a,b) in enumerate(zip(A,A[1:])):
    if b-a == 1:
        ans += C[a-1]
print(ans)

Submission status: Accepted

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

print(ans + sum(b))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B = [0]+B
C = list(map(int,input().split()))
C = [0]+C

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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l1=LI()
  l2=LI()
  l3=LI()

  ans=0
  b=-1
  for i,x in enumerate(l1):
    ans+=l2[x-1]
    if x==b+1:
      ans+=l3[b-1]
    b=x
  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
prev = -float('inf')
res = 0
for e in a:
    e -= 1
    res += b[e]
    if prev == e - 1:
        res += c[prev]
    prev = e
print(res)

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    A = list( map( int, input().split()))
    B = list( map( int, input().split()))
    C = list( map( int, input().split()))
    now = A[0]
    ans = sum(B)
    for i in range(1, N):
        if now + 1 == A[i]:
            ans += C[now-1]
        now = A[i]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n  = int(input())

a = list(map(lambda x: int(x)-1, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
a_list = _li()
b_list = _li()
c_list = _li()

ans = sum(b_list)
for i in range(N-1):
    if a_list[i] + 1 == a_list[i+1]:
        ans += c_list[a_list[i] - 1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
c_lst = list(map(int, input().split()))

res = sum(b_lst)
for i in range(n-1):
    if a_lst[i] + 1 == a_lst[i+1]:
        res += c_lst[a_lst[i]-1]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = inp()
a = inpl()
b = inpl()
c = inpl()
res = 0
for i in range(n):
    res += b[a[i]-1]
    if i > 0 and a[i] == a[i-1] + 1:
        res += c[a[i-1]-1]
print(res)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()

    a = li()
    b = li()
    c = li()

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

    print(ans)


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
c = [int(i) for i in readline().split()]

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

print(ans)

Submission status: Accepted

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

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    lb = rli()
    lc = rli()
    ans = sum(lb)
    for i in range(n-1):
        if la[i+1] == la[i]+1:
            ans += lc[la[i]-1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
prev = -1
score = 0
for i in range(N):
    if prev+1 == A[i]:
        score+=C[prev-1]
    score+=B[A[i]-1]
    prev = A[i]

print(score)

Submission status: Accepted

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] == a[i-1] +1:
        ans += c[a[i-1]-1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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
pre_i = None
for i in A:
    i -= 1
    ans += B[i]
    if pre_i == i - 1:
        ans += C[pre_i]
    pre_i = i

print(ans)

Submission status: Accepted

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

def main():
    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]
    pre = a[0] - 1
    for i in range(1, N):
        ans += b[a[i] - 1]
        if pre + 1 == a[i] - 1:
            ans += c[pre]
        pre = a[i] - 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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 a_i in a:
    ans += b[a_i - 1]
    if last == a_i - 1:
        ans += c[a_i - 2]
    last = a_i

print(ans)

Submission status: Accepted

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
AA = inpl()
BB = inpl()
CC = inpl()

ans = sum(BB)
for i in range(N-1):
    if AA[i+1] == AA[i]+1:
        ans += CC[AA[i]-1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

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

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

print ans

Submission status: Accepted

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

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-1]==A[i]-1:
        ANS+=C[A[i-1]-1]

print(ANS)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in A:
    ans += B[i - 1]

for i, j in zip(A, A[1:]):
    if i + 1 == j:
        ans += C[i - 1]

print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
b = na()
c = na()

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    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:
            ans += c[a[i - 1] - 1]
    
    print(ans)
    
    return 0

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)
from collections import *
from bisect import *
mod = 10**9+7

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

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
l = list(map(int,input().split()))
ans = sum(li)
for i in range(n-1):
    if lis[i] +1 == lis[i+1]:
        ans += l[lis[i]-1]
print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
res = 0
for i in a:
    res += b[i - 1]
for i, j in zip(a, a[1:]):
    if j == i + 1:
        res += c[i - 1]
print(res)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    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()))

addans=0

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
b = sum(map(int, input().split()))
c = map(int, input().split())
s = 0
for i in range(n-1):
  if a[i+1] - a[i] == 1:
    s += c[a[i] - 1]
print(b + 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()]
res = 0
for j in range(N - 1):
  if (abs(A[j] - A[j + 1]) == 1):
    res += C[A[j]]
    res += B[A[j]]
  else:
    res += B[A[j]]
    
print(res)

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) fot i in range(N)]
B = [int(input()) for i in range(N)]
C = [int(input()) for i in range(N-1)]
res = 0
for j in range(N - 1):
  if (abs(A[i] - A[i + 1]) == 1):
    res += C[A[i]]
    res += B[A[i]]
  else:
    res += B[A[i]]
    
print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) fot i in range(N)]
B = [int(input()) for i in range(N)]
C = [int(input()) for i in range(N)]
res = 0
for j in range(N - 1):
  if (abs(A[i] - A[i + 1]) == 1):
    res += C[A[i]]
    res += B[A[i]]
  else:
    res += B[A[i]]
    
print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) fot i in range(N)]
B = [int(input()) for i in range(N)]
C = [int(input()) for i in range(N)]
res = 0
for j in range(N - 1):
  if (abs(A[i] - A[i + 1]) == 1):
    res += C[i]
    res += B[i]
  else:
    res += B[i]
    
print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) fot i in range(N)]
B = [int(input()) for i in range(N)]
C = [int(input()) for i in range(N)]
res = 0
for j in range(N - 1):
  if (abs(A[i] - A[i + 1]) == 1):
    res += C[i]
  else:
    res += B[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()))
s=0
for i in range(N):
  s+=B[A[i]-1]
  if i!=0 and A[i-1]+1==A[i]:
    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()))
d=sum(B)
for i in range(n-1):
  if A[i+1]-A[i]==1:
    d+=B[A[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()))
res = 0
for i in range(N - 1):
    res += B[i]
    if A[i] + 1 == A[i + 1]:
		res += C[A[i] - 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()))
p=O
for i in range(n):
  p+=b[a[i]-1]
  if i>=1 and a[i]-a[i-1]==1:
    p+=c[a[i-1]-1]
print(p)

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

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

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

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

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

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(int(input()))
b=list(int(input()))
c=list(int(input()))
p=0
for i in range(n):
  p+=b[a[i]]
  if　a[i]-a[i-1]==1:
    p+=c[i]
print(p)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))

satis = 0

for i in range(len(A)):
  satis += B[A[i]]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[i-1]

print(satis)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int,input().split())
B = map(int,input().split())
C = map(int,input().split())
D = A[0]
count=0
for i in A:
  if D != int(i) + 1:
    count += B[i-1]
  else:
    count += B[i-1]
    count += C[i-2]
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())
D = A[0]
count=0
for i in A:
  if D != i + 1:
    count += B[i-1]
  else:
    count += B[i-1]
    count += C[i-2]
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()))

bef=a[0]-1
man=b[0]

for i in a[1:]:
  if i-1=bef+1:
    man+=c[bef]
  man+=b[i-1]
  bef=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()))

bef=a[0]
man=b[0]

for i in a[1:]:
  if i==bef+1:
    man+=c[bef]
  man+=b[i]
  bef=i
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()))

bef=a[0]
man=b[0]

for i in a[1:]:
  if i=bef+1:
    man+=c[bef]
  man+=b[i]
  bef=i
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()))


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

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

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

ans = 0

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [-1].extend(list(map(int, input().split()))) # たべた料理
B = [-1].extend(list(map(int, input().split()))) # 料理の満足度
C = [-1].extend(list(map(int, input().split()))) # i -> i+1ボーナス

manzoku = 0

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

print(manzoku)

Submission status: Runtime Error

Solution code:
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
bonuses = list(map(int, input().split()))

score = 0
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i == prev + 1: score += bonuses[i-1]
  prev = i

print(score)

Submission status: Runtime Error

Solution code:
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
bonuses = list(map(int, input().split()))

score = 0
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i == prev + 1: score += bonuses[i-1]
  prev = i

Submission status: Runtime Error

Solution code:
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
bonuses = list(map(int, input().split()))

score = 
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i == prev + 1: score += bonuses[i-1]
  prev = i

Submission status: Runtime Error

Solution code:
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
bonuses = list(map(int, input().split()))

score = 
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i = prev + 1: score += bonuses[i-1]
  prev = i

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

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:
2
1 2
50 50
50

Submission status: Runtime Error

Solution code:
t = 0
lis = list()
for i in A:
    lis.append(B[i-1])
    #print(i,t)
    if i == t + 1:
        lis.append(C[i-2])
    t = i

print(sum(lis))

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

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

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

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

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