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

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()


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

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

    print(ans)


if __name__ == '__main__':
    solve()

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

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

print(score)

Solution (Python):
import sys
import decimal 

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    keep = n
    sum = 0
    for i in a:
        sum += b[i-1]
        if i == keep + 1:
            sum += c[i-2]
        keep = i
    print(sum)

    
    
main()

Solution (Python):

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

print(ans)

Solution (Python):
def main():
    n=int(input())
    a=map(int,input().split())
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))
    m = 0
    prev = -100
    for i in (x-1 for x in a):
        m += b[i]
        if prev + 1 == i:
            m += c[prev]
        prev = i
    return m

if __name__ == "__main__":
    print(main())

Solution (Python):
def main():
    n=int(input())
    a=map(int,input().split())
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))
    m = 0
    prev = -100
    for i in (x-1 for x in a):
        m += b[i]
        if prev + 1 == i:
            m += c[prev]
        prev = i
    return m

if __name__ == "__main__":
    print(main())

Solution (Python):
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])-1])

print(ans)

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

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

Solution (Python):
N,  *_ABC,  = map(int, open(0).read().split())

A = _ABC[:N]
B = _ABC[N: 2*N]
C = _ABC[2*N:]

ans = 0

for i, a in enumerate(A):
    ans += B[a-1]

    if i != len(A)-1 and A[i+1] == a + 1:
        ans += C[a-1]

print(ans)

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

Solution (Python):

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

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

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

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

print( sum(b)+score )

Solution (Python):
n = int(input())

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

total = 0
p = -1

for i in a:
    total += b[i-1]
    
    if p + 1 == i:
        total += c[i-2]
        
    p = i
    
print(total)

Solution (Python):

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

Solution (Python):
import collections
n = int(raw_input())
ais = map(int, raw_input().split(' '))
bis = map(int, raw_input().split(' '))
cis = map(int, raw_input().split(' '))


c = 0
q = collections.deque([])
for a in ais:
	c += bis[a - 1]
	if q:
		p = q.popleft()
		if p + 1== a - 1:
			c += cis[p]
	q.append(a - 1)

print c

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    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 > 0 and a[i] == a[i - 1] + 1:
            ans += c[a[i - 1] - 1]

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

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

A = [0] + A
B = [0] + B
C = [0] + C

ans = 0
for i, a in enumerate(A[1:-1]):
    i = i+1 


    ans += B[a]
    if A[i+1] - A[i] == 1:

        ans += C[a]
ans += B[A[-1]]
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
n = int(input())
readline = sys.stdin.readline
A = [int(i)-1 for i in readline().split()]
B = [int(i) for i in readline().split()]
C = [int(i) for i in readline().split()]

ans = 0
a_prev = -100
for a in A:
    ans += B[a]
    if a == a_prev+1:
        ans += C[a-1]
    a_prev = a
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
count = 0
bonus = 0
for i in a:
    count += b[i-1]
    if i == bonus:
        count += c[i-2]
    bonus = i+1
print(count)

Solution (Python):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()
B = rl()
C = rl()

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

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

ans=0
bk=-1
for a in A:
    if a-1==bk:
        ans+=C[bk]
    ans+=B[a]
    bk=a
print(ans)

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

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

for x in range(len(A)):
    if x != len(A) - 1:
        if A[x] + 1 == A[x + 1]:
            count += C[A[x]-1]
print(count)

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

ans = 0
a.append(0)

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

print(ans)

Solution (Python):


N = int(input())
A = [int(a)-1 for a in input().split()]
B = [int(a) for a in input().split()]
C = [int(a) for a in input().split()]
m =0
l = N + 10
for a in A:
    m+=B[a]
    if l+1 == a:
        m+=C[l]
    l=a
print(m)

Solution (Python):
n = int(input())

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

ans = 0
tmp = -1

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[0]+list(map(int,input().split()))
count=0
for i in range(N):
    a=A[i]-1
    count+=B[a]
    if  i!=0 and A[i-1]+1==A[i]:
        count+=C[a]
print(count)

Solution (Python):
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 = 0
ans = sum(B)

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

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

Solution (Python):
pre=-1
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=[0]+list(map(int,input().split()))
ans=0
prec=0
for  a,b in zip(al,bl):
    ans+=b
    if pre+1==a:ans+=cl[pre]
    pre=a
print(ans)

Solution (Python):
n=int(input())
a=[int(_) for _ in input().split()]
b=[int(_) for _ in input().split()]
c=[int(_) for _ in input().split()]
r=0
for i in range(1,len(a)):
    if a[i]-a[i-1] == 1:
        r+=c[a[i-1]-1]
print(sum(b)+r)

Solution (Python):

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    _ = int(readline())
    As = list(map(int, readline().split()))
    Bs = list(map(int, readline().split()))
    Cs = list(map(int, readline().split()))

    ans = 0
    for a, a_next in zip(As, As[1:]):
        ans += Bs[a-1]
        if a_next - a == 1:
            ans += Cs[a-1]
    ans += Bs[As[-1]-1]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A, B, C = [list(map(int, input().split())) for i in range(3)]

S = 0

for i in range(N):
    S += B[i]
    try:
        if A[i+1] == A[i]+1:
            S += C[A[i]-1]
    except IndexError as e:
        continue

print(S)

Solution (Python):
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-1):
    if a[i]==a[i+1]-1:
        d=a[i]
        
        count+= c[d-1]


print(sum(b)+ count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
back = 0
for i in range(0, n):
  count += b[a[i]-1]
  if back+1 == a[i] and back != 0:
    count += c[a[i]-2]
  back = a[i]
print(count)

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

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

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

ans = 0
memo = -100
for i in range(N):
  dish = A[i]
  base = B[dish - 1]
  ans += base
  if dish - memo == 1:
    ans += C[dish - 2]
  memo = dish
  
    
print(ans)

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

buffer = 0
sati = 0

for i in A:
  sati += B[i - 1]
  if buffer == 0:
    buffer = i
    continue
  elif buffer == i - 1:
    sati += C[buffer -1]
  buffer = i
print(sati)

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

Solution (Python):
N = int(input())
A = tuple(map(int, input().split(' ')))
B = tuple(map(int, input().split(' ')))
C = tuple(map(int, input().split(' ')))

s = sum(B)
s += sum([C[a1 - 1] for a1, a2 in zip(A, A[1:]) if a2 - a1 == 1])

print(s)

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

print(takashi)

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

Solution (Python):
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue



ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = il()
    B = il()
    C = il()

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


if __name__ == '__main__':
    main()

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)





n=n0()
a=[0]
a.extend(n1())

b=[0]
b.extend(n1())
c=[0]
c.extend(n1())

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

Solution (Python):
def buffet(n, ali, bli, cli):

    ans = 0
    count = 10**5

    for i in range(n):
        ans += bli[ali[i]-1]

        if ali[i] == count+1:
            ans += cli[count-1]
        count = ali[i]
    return ans

def main():
    n = int(input())
    ali = list(map(int, input().split()))
    bli = list(map(int, input().split()))
    cli = list(map(int, input().split()))
    print(buffet(n, ali, bli, cli))

if __name__ == '__main__':
    main()

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

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

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

result = 0
mae = 1111
for i in a:
    
    result += b[i-1]
    
    if mae == i -1:
        
        result += c[i-2]
    mae = i

print(result)

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

cnt = 0
prev_food = -10
for a in A:
    cnt += B[a]
    if prev_food == a-1:
        cnt += C[a-1]
    prev_food = a
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
prev = -1
ans = 0

for i,dish in enumerate(A):
    if prev+1 == dish:
        ans += C[prev-1]
    prev = A[i]
    ans += B[i-1]

print(ans)

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

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

Solution (Python):
n = int(input())

inputs = []

for i in range(3):
    inp = [int(x) for x in input().split(' ')]
    inputs.append(inp)

def solve(n, inputs):
    a = inputs[0]
    b = inputs[1]
    c = inputs[2]

    satisfaction = 0
    last = -1
    dish = -1
    for d in range(n):
        dish = a[d]        
        if dish == last + 1:
            satisfaction += c[dish-2]
        last = a[d]        
        satisfaction += b[dish-1]

    print(satisfaction)

solve(n, inputs)

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

score = 0
for i in range(len(A)):

    score += B[A[i]-1]

    if i != len(A)-1:
        if A[i+1] == A[i] + 1:

            score += C[A[i]-1]

print (score)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pre = -10
ans = 0
for a in A:
    ans += B[a-1]
    if a == pre + 1:
        ans += C[pre-1]
    pre = a

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
pnt = 0
cnt = -2
for i in a:
  if i == cnt+1:
    pnt += c[cnt-1]
  pnt += b[i-1]
  cnt = i
print(pnt)

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

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

print(e)

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

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

sat = 0
for a_i in range(0, n):
    i = a_s[a_i] - 1
    b = b_s[i]
    sat += b
    if a_i < n-1 and a_s[a_i] +1 == a_s[a_i+1]:
        if i >= 0:
            sat += c_s[i]
print(sat)

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

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

Solution (Python):
import numpy as np
input()
A = np.array(input().split(), np.int16) - 1
B = np.array(input().split(), np.int16)
C = np.array(input().split(), np.int16)
print(B.sum() + C[A[:-1][A[1:] - A[:-1] == 1]].sum())

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

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

count = 0
count_list = []
result = 0

for i in range(len(A)):
  if i != 0 and i < len(A):
    if A[i-1] == A[i]-1:
      count_list.append(A[i-1])
  result += B[A[i]-1]

for i in count_list:
  result += C[i-1]

print(result)

Solution (Python):
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-1):
    if a[i+1] == a[i]+1:
        cnt+=c[a[i]-1]

print(sum(b)+cnt)

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

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

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

tmp = n
ans = 0
for i in A:
    ans += B[i - 1]
    if tmp + 1 == i - 1:
        ans += C[tmp]
    
    
    tmp = i - 1
    
    
print(ans)

Solution (Python):
n = int(input().rstrip())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
c = list(map(int, input().rstrip().split()))

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

	pre_ai = ai

print(sum)

Solution (Python):
N = int(input())
a_arr = list(map(int, input().split()))
b_arr = list(map(int, input().split()))
c_arr = list(map(int, input().split()))

ans = b_arr[a_arr[0]-1]
for i in range(1,N):
    if a_arr[i] == a_arr[i-1]+1:
        ans += c_arr[a_arr[i]-2]+b_arr[a_arr[i]-1]
    else:
        ans += b_arr[a_arr[i]-1]

print(ans)

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

ans = 0
tmp = -1
for a_i in a:
    if a_i == tmp + 1:
        ans = ans + b[a_i-1] +c[tmp-1]
    else:
        ans += b[a_i-1]
    tmp = a_i
print(ans)

Solution (Python):
n=int(input())
a=[0]*n
b=[0]*n
c=[0]*n
a[:]=map(int,input().split())
b[:]=map(int,input().split())
c[1:]=map(int,input().split())
r=0
l=n
for ii in range(n):
  r+=b[a[ii]-1]
  if l+1==a[ii]-1:
    r+=c[a[ii]-1]
  l=a[ii]-1
print(r)

Solution (Python):
N = int(input())
As = [A-1 for A in map(int, input().split())]
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

ans = 0
APrev = -100
for i in range(N):
    A = As[i]
    ans += Bs[A]
    if APrev == A-1:
        ans += Cs[APrev]
    APrev = A

print(ans)

Solution (Python):

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

foods = {}
for i, b in zip(range(1, N + 1), B):
    if i != N:
        foods[i] = {
            "point": b,
            "bonus": C[i - 1],
            "bonus_food": i + 1
        }
    else:
        foods[i] = {
            "point": b,
            "bonus": 0,
            "bonus_food": -1
        }

point = 0
before = {
    "point": 0,
    "bonus": 0,
    "bonus_food": 0
}
for a in A:
    point += foods[a]["point"]

    if before["bonus_food"] == a:
        point += before["bonus"]

    before = foods[a]

print(point)

Solution (Python):

"""
Created on Fri May 15 00:16:28 2020

@author: Kanaru Sato
"""

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)

Solution (Python):
N=int(input())
AList = list(map(int, input().split()))
BList = list(map(int, input().split()))
CList = list(map(int, input().split()))

mae=0
MAN=0
i=0
while i<N:
    MAN+=BList[(AList[i])-1]
    if (mae+1)==AList[i] and i!=0:
        MAN+=CList[mae-1]
    
    
    mae=AList[i]
    
    
    i+=1

print(MAN)

Solution (Python):

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()]
a.append(0)

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

Solution (Python):
import itertools
import math
import fractions
import functools
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):
    a[i] -= 1
sum = b[a[0]]
for i in range(1,n):
    if a[i-1] + 1 == a[i]:
        sum += b[a[i]]+c[a[i]-1]
    else:
         sum += b[a[i]]

print(sum)

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

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

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

print(ans)

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

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

Solution (Python):
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:(input())

"""========main code==============="""
t=ii()
a=ll()
b=ll()
c=ll()
ans=0
for i in range(t):
    ans+=b[a[i]-1]
    if(i<t-1):
        if(a[i]+1==a[i+1]):
            ans+=c[a[i]-1]
print(ans)

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

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

Solution (Python):
n=int(input())
A=[int(_) for _ in input().split()]
B=[int(_) for _ in input().split()]
C=[int(_) for _ in 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)

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

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

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

Solution (Python):
n = int(input())
a = input().split()
b = input().split()
c = input().split()
sum = 0
number = -2

for i in a:
  k = int(i)-1
  sum += int(b[k])
  if number + 1 == k:
    sum += int(c[k-1])
  number = k
print(sum)

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

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

print(cnt)

Solution (Python):
import sys
import math
import bisect

def solve(A, B, C):
    n = len(A)
    ans = sum(B)
    for i in range(n):
        if i < n - 1 and A[i] + 1 == A[i+1]:
            ans += C[A[i]-1]
    return ans

def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    print(solve(A, B, C))

if __name__ == "__main__":
    main()

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