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

print(n)

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

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

print(ans)

Solution (Python):
n = int(input())
als = list(map(int, input().split()))
bls = list(map(int, input().split()))
cls = list(map(int, input().split()))

numls = []
for i in range(n-1):
  dif = als[i+1] - als[i]
  if dif == 1:
    numls.append(als[i])


subtotal = 0
for j in numls:
  subtotal = subtotal + cls[j-1]
  
print(sum(bls)+subtotal)

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

satis = int(0)
before_value = int(100)

for value in a:
  satis += b[value-1]
  if before_value == (value-1):
    satis += c[value-2]
  before_value = value

print(satis)

Solution (Python):
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]-1]
    else:
        pass
print(q)

Solution (Python):


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

sum=0
prev=-1000

for a in A:
    sum+=B[a-1]
    if a-prev==1:
        sum+=C[a-2]
    prev=a
    
print(sum)

Solution (Python):



def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    result = 0
    for i in range(n):
        meal = a[i] - 1
        result += b[meal]

        if i == n - 1:
            break
        if a[i+1] - a[i] == 1:
            result += c[meal]

    print(result)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    A = LIST()
    B = LIST()
    C = LIST()

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

    print(ans)


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

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

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

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

print(ans)

Solution (Python):
n = input()
n = int(n)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
memo = -1
ans = 0
count = -1
for ai in a:
    ans += b[ai - 1]
    if ai - 1 == memo:
        ans += c[ai - 2]
    memo = ai
    count += 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()))
d = 0

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

print(b_sum + d)

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

count = sum(B)

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

print(count)

Solution (Python):
def A():
    print(int(input())**3)

def B():
    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()]

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

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

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


result = sum(B)
before = -2

for a in A:
    if before+1 == a:
        result = result + C[a-2]
    before = a

print(result)

Solution (Python):


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

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

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

print(count)

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

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

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

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

score = 0
tmp =-100
for a in A:
    score+=B[a-1]
    if tmp +1 ==a:
        score+=C[tmp-1]
    tmp = a

print(score)

Solution (Python):
import sys
input = sys.stdin.readline


n = int(input())
a = list(map(int,input().split()))
b = [0] + list(map(int,input().split()))
c = [0] + list(map(int,input().split())) + [0]*50

total = 0
last = -1
for aa in a:
    total += b[aa]
    if aa == last+1:
        total += c[last]
    last = aa


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

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

a = [d-1 for d in a]

manzoku = 0
jotai = a[0]

for val in a:
    manzoku = manzoku + b[val]
    if jotai +1 == val:
        manzoku += c[val-1]
    jotai = val

print(manzoku)

Solution (Python):
def intminus(i):
    return int(i) - 1
def main(): 
    
    n = int(input())
    A = list(map(intminus, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

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

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

Solution (Python):

 
N = int(input())

A = [int(e) for e in input().split()]
B = [int(e) for e in input().split()]
C = [int(e) for e in input().split()]

res = 0
for i in range(1, N + 1):
	menu = A[i - 1]
	res += B[menu - 1]

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

print(res)

Solution (Python):
N=int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pa = 1000
ans=0
for i in range(N):
  ans += B[A[i]-1]
  if pa == A[i]-1-1:
    ans += C[pa]
  pa = 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()))
cnt = 0
for i in range(n):
    cnt += b[a[i] - 1]
    if (a[i]-1 == a[i-1])&(i!=0):
        cnt += c[a[i - 1]-1]
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()))

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

print(level)

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

print(res)

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

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

Solution (Python):
import math
input = raw_input

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

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):
  po = a[i]
  ans += b[po-1]
 
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+=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
before = -1
for i in range(n):
    now = a[i]
    if before + 1 == now:
        ans += c[before-1]
    before = now
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()))
point = 0
mae = -10

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

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

ans = 0
prev = -1
for i in range(N):
    a = a_list[i]
    b = b_list[a-1]
    if i != N-1:

        if a_list[i+1] == a+1:
            c = c_list[a-1]
            
            ans +=c
    prev = a
    ans += b

    
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(len(A)-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 != N-1 and 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()))

total = 0
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):
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]
    if i != 0:
        if A[i]-1 == A[i-1]:
            ans += C[A[i-1]-1]


print(ans)

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

satisfied = 0
for i in range(0, N):
    i_food = A[i]
    satisfied += B[i_food - 1]
    if i > 0:
        i_food_prev = A[i - 1]
        if i_food - i_food_prev == 1:
            satisfied += C[i_food_prev - 1]

print satisfied

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

Solution (Python):


import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = i2nn()
    B = i2nn()
    C = i2nn()
    m = 0
    for j in range(N - 1):
        i = A[j] - 1
        m += B[i]
        if i + 1 == A[j + 1] - 1:
            m += C[i]
    m += B[A[N - 1] - 1]
    print(m)
    return

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

print(ans)

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):

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

    print(cst)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    B = [int(next(tokens)) for _ in range(N)]  
    C = [int(next(tokens)) for _ in range(N - 1)]  
    solve(N, 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())) 

ans = 0
cnt = 0

for n in A:
  if cnt == 0:
    ans += B[n-1]
    cnt += 1
  else:
    ans += B[n-1]
    if A[cnt] - A[cnt-1] == 1:
      ans += C[A[cnt-1]-1]
    cnt += 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,a in enumerate(A):
  if i>=len(A)-1:
    break
  if A[i+1]-a==1:
    ans+=C[a-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[i]
    if i == 0:
        continue
    judge = A[i] - A[i-1]
    if judge == 1:
        count = A[i-1] - 1
        ans += C[count]

print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    N = II()
    A = LMIIS()
    B = LMIIS()
    C = LMIIS()
    sums = 0
    pre = -9999
    for a in A:
        a = a-1
        sums += B[a]
        if a - pre == 1:
            sums += C[pre]
        pre = a
    print(sums)

        



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

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

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 != n-1 and 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):
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()] 

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


print(sum(b) + sum(cl))

Solution (Python):
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()] 
C.append(0)
ans=0
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):
n=int(input())
A=map(int,input().split())
B=map(int,input().split())
C=map(int,input().split())
a=list(A)
b=list(B)
c=list(C)
s=0

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

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

print(ans)

Solution (Python):
n = int(input());
a = input().split(" ");
b = input().split(" ");
c = input().split(" ");

for i in range(n) :
	a[i] = int(a[i]);
	b[i] = int(b[i]);
a.insert(0,0);
b.insert(0,0);

for i in range(n-1) :
	c[i] = int(c[i]);
c.insert(0,0);

ans = b[a[1]]
for i in range(2,n+1) :
 	ans += b[a[i]];
 	if a[i-1] + 1 == a[i] :
 		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 = B[A[0]-1]
for i in range(1, n):
    ans += B[A[i]-1]
    if A[i-1]+1 == A[i]:
        ans += C[A[i]-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()))
total = 0
before = -2
for i in range(N):
  menu = A[i] - 1
  total += B[menu]
  if menu == before+1:
    total += C[before]
  before = menu
print(total)

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 


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

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

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

print(m)

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

Solution (Python):
N=int(input())
l= [list(map(int, input().split())) for i in range(3)]
a=0
for i in range(N-1):
    a+=l[1][l[0][i]-1]
    if l[0][i+1]==l[0][i]+1:
        a+=l[2][l[0][i]-1]
a+=l[1][l[0][N-1]-1]
print(a)

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

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

Solution (Python):
import copy 
import numpy as np

N = int(input())

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


sum    = 0
temp_A = 0
for i in range(len(A)):

    if temp_A+1==A[i] and i!=0:
        sum = sum + C[temp_A-1]
    sum = sum + B[A[i]-1]
    temp_A = A[i]

print(sum)

Solution (Python):
n = int(input())
a = [int(x) - 1 for x in input().split()]
total = sum(map(int, input().split()))
c = [int(x) for x in input().split()]
for i, j in zip(a, a[1:]):
    if j - i == 1:
        total += c[i]
print(total)

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

Solution (Python):
n = int(input())
ListA = [int(val) for val in input().split()]
ListB = [int(val) for val in input().split()]
ListC = [int(val) for val in input().split()]
prevA = -1
point = 0
for val in ListA:
	point += ListB[val - 1]
	if (val == prevA + 1):
		point += ListC[prevA - 1]
	prevA = val
print(point)

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

sum_satisfaction = 0

for i in range(n):
    sum_satisfaction += b[a[i]-1]
    if i == 0:
        continue
    elif a[i] == a[i-1] + 1:
        sum_satisfaction += c[a[i-1]-1]

print(sum_satisfaction)

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
pre = -10
for i in range(n):
    food = a[i]
    count += b[food - 1]
    if pre + 1 == food:
        count += c[food - 2]

    pre = food

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


sume = 0

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

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

man = 0
pre = -10

for i in a:
    ai = i-1
    man += b[ai]
    
    if pre == ai - 1:
        man += c[pre]
        
    pre = ai

print(man)

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

sum = 0
prev = -1
for num in A:
    sum += B[num-1]
    if num - prev == 1:
        sum += C[prev-1]
    prev = num
print(sum)

Solution (Python):
def main():
    n = int(input())
    a=list(map(int,input().split(' ')))
    b=list(map(int,input().split(' ')))
    c=list(map(int,input().split(' ')))
    ans = 0
    tmp = a[0]
    for i in range(n):
        if tmp +1 == a[i]:
            ans += b[a[i]-1]+c[a[i]-2]
        else:
            ans += b[a[i]-1]
        tmp = a[i]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    Bs = [int(x) for x in stdin.readline().rstrip().split()]
    Cs = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    tmp = -1
    for A in As:
        result += Bs[A - 1]
        if tmp + 1 == A:
            result += Cs[tmp - 1]
        tmp = A
    print(result)


if __name__ == "__main__":
    main()

Solution (Python):

import sys;
import string;
sys.setrecursionlimit(20000) 

import copy
import math
import itertools

from functools import lru_cache


PPP = 1000000007






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














import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def ton(n, k, x):
  s = ""
  while n > 0:
    s = str(n%k) + s
    n //= k
  return s





def getEnergy():
  for y in b:
    yield y

def doit():
  total = 0
  prev = -2
  for x in a:
    total += b[x-1]
    if prev == x - 1:
      total += c[prev-1]
    prev = x

  return total

def yn():
  if doit():
    return "Yes"
  else:
    return "No"




try:
  
  print(doit())
  
except Exception as e:
  print("e", e, file=sys.stderr)

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

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

for i in range(N):
   
    s = s + B[(A[i]-1)]

    if (A[i-1]+1) == A[i] and not i == 0:
        s = s + C[A[i-1]-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()))

s = 0

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

happy = dict()
for i in range(N):
    happy[A[i]] = B[i]

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 = [int(a) for a in input().strip().split()]
B = [int(b) for b in input().strip().split()]
C = [int(c) for c in input().strip().split()]


prev = A[0]
total = B[prev-1]
for a in A[1:]:
  total += B[a-1]
  if a - prev == 1:
    total += C[prev-1]
  prev = a

print(total)

Solution (Python):
N = int(input())
Alist = [int(i) for i in input().split()]
Blist = [int(i) for i in input().split()]
Clist = [int(i) for i in input().split()]

satisfied = 0
for i in range(N):
    A = Alist[i]-1
    satisfied += Blist[A]
    if i>=1 and Alist[i] == Alist[i-1]+1:
        satisfied += Clist[Alist[i-1]-1]

print(satisfied)

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

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

Solution (Python):

import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        A, B, C = [list(map(int, input().split())) for _ in range(3)]

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



if __name__ == '__main__':
    AtCoder().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()))

s = 0
p_a = -1
for now_a in a:
    s += b[now_a-1]
    if now_a - p_a == 1:
        s += c[p_a-1]

    p_a = now_a

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

Solution (Python):

import numpy as np
import sys


def main():
    N = int(input())
    A = np.array(input().split(), dtype='int64')
    B = np.array(input().split(), dtype='int64')
    C = np.array(input().split(), dtype='int64')

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

    print(satisfy)








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

Solution (Python):
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
add = 0

for i in range(N-1):
    target = A_list[i]
    if (A_list[i+1] - target) == 1:
        add += C_list[target - 1]

print(sum(B_list) + add)

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

_x = -2
for x in a:
    x -= 1
    ans += b[x]
    if x == (_x) + 1:
        ans += c[_x]
    _x = x

print(ans)