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

Solution (Python):
num = int(input())
order = input().split()
order = [int(i) for i in order]
manzoku = input().split()
additional = input().split()

prev = -1
ans = 0
for i in order:
  ans += int(manzoku[i-1])
  if i == prev+1:
    ans += int(additional[i-2])
  prev = i
  
print(ans)

Solution (Python):

import sys


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

    result = 0
    for i, a_i in enumerate(A):
        result += B[a_i - 1]
        if i != 0:
            if a_i == (a_old + 1):
                result += C[a_i - 2]
        else:
            pass
        a_old = a_i

    print(result)

    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())
An = list(map(int, input().split()))
Bn = map(int, input().split())
Cn = list(map(int, input().split()))

s = sum(Bn)
for i, (ani, ani1) in enumerate(zip(An, An[1:])):
	
    if ani + 1 == ani1:
      s += Cn[ani - 1]
print(s)

Solution (Python):
n = int(input())
a = [int(elem) for elem in input().split()]
b = [int(elem) for elem in input().split()]
c = [int(elem) for elem in input().split()]

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

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

past_a = -1
happiness = 0

for a in A:
    happiness += B[a-1]
    if a == past_a + 1:
        happiness += C[a - 2]
    past_a = a

print(happiness)

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

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

print(sum)

Solution (Python):
N = int(input())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
last = -1
num = 0
for A in Alist:
    num += Blist[A-1]
    if A == (last+1):
        num += Clist[last-1]
    last = A

print(num)

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
last_i = -2
for index in range(N):
  i = A[index]
  score += B[i - 1]
  if i == last_i + 1:
    score += C[last_i - 1]
  last_i = i
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()))
ans=0
for i in range(n):
  ans+=b[a[i]-1]
  if a[max(i-1,0)]==a[i]-1:
    ans+=c[a[i]-2]
print(ans)

Solution (Python):
N = int(input())
A = [int(x) - 1 for x in input().split(" ")]
B = [int(x) for x in input().split(" ")]
C = [int(x) for x in input().split(" ")]

satisfiction = 0
before_id = None
for i in range(N):
    satisfiction += B[A[i]]
    if before_id is None: pass
    elif before_id == A[i] - 1:
        satisfiction += C[before_id]
    before_id = A[i]
    
print(satisfiction)

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

print(int(res))

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

Solution (Python):
n = int(input())
a = list(int(i) for i in input().split())
b = list(int(i) for i in input().split())
c = list(int(i) for i in input().split())
total = 0

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

prev_a = -1
ans = 0
for i_a in a:
    ans += b[i_a-1]
    if i_a - prev_a == 1:
        ans += c[prev_a-1]
    prev_a = i_a

print(ans)

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

sum = 0
for ia, i in enumerate(A):
    sum += B[i - 1]
    if ia > 0:
        if A[ia-1] == i - 1:
            sum += C[i-2]
print(sum)

Solution (Python):
n = int(input())
a, b, c = [list(map(int, input().split())) for i in range(3)]
ans = sum(b)
for i in range(1, n):
    if 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 = B[A[0] - 1]

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

Solution (Python):

import sys


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

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

    print(res)

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

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    a_input = list(map(int, input().split()))
    b_input = list(map(int, input().split()))
    c_input = list(map(int, input().split()))

    score = 0
    pre_a = -1
    for i in range(n):
        score += b_input[a_input[i] - 1]
        if pre_a == a_input[i] - 1:
            score += c_input[pre_a - 1]
        pre_a = a_input[i]
    print(score)

Solution (Python):
def read():
    return [int(e) for e in input().split(" ")]

N = int(input())
Data = [read() for _ in range(3)]
m = 0
b = -2

for e_A in Data[0]:
    m += Data[1][e_A - 1]
    if(e_A == b + 1):
        m += Data[2][b - 1]
    b = e_A

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

def main():
    n=int(input())
    a=[int(x)-1 for x in input().split()]
    b=[int(x) for x in input().split()]
    c=[int(x) for x in input().split()]

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

    print(s)




if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=[int(x)-1 for x in input().split()]
b=[int(x) for x in input().split()]
c=[int(x) for x in input().split()]

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

print(s)

Solution (Python):
t=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()]
s=[]
for i in range(t):
    if i==0:
        s.append(b[a[i]-1])
    else:
        if a[i]-a[i-1]==1:
            su=b[a[i]-1]+c[a[i]-2]
            s.append(su)
        else:
            s.append(b[a[i]-1])
print(sum(s))

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    c = list(map(int, input().rstrip('\n').split()))
    t = sum(b)
    for i in range(n):
        if i != 0 and a[i] - 1 == a[i-1]:
            t += c[a[i-1]-1]
    print(t)


if __name__ == '__main__':
    slove()

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

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

Solution (Python):
N = int(input())
AryA = list(map(int, input().split()))
AryB = list(map(int, input().split()))
AryC = list(map(int, input().split()))

sum = 0
tmpBox = N+1

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

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    B = LIST()
    C = LIST()
    sumv = 0
    for i in range(N):
        sumv += B[A[i]-1]
        if i > 0:
            if A[i] - A[i-1] == 1:
                sumv += C[A[i-1]-1]
    print(sumv)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import numpy as np
 
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
r = np.sum(B)
for i in range(N-1):
  if A[i] + 1 == A[i + 1]:
    r += C[A[i]-1]

print(r)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
i=0
ans=0
while i!=n:

    ans+=b[a[i]-1]
    if i!=0:
        if (a[i]-a[i-1])==1:
            ans+=c[a[i-1]-1]

    i+=1

print(ans)

Solution (Python):
li = lambda: list(map(int, input().split()))
N = int(input())
A = li()
B = li()
C = li()
res = sum(B)
res += sum([C[A[i]-1] for i in range(len(A)-1) if not (A[i+1]-A[i]-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()))

res = sum(B)
for i, (p, n) in enumerate(zip(A[:N-1], A[1:])):
    if n - p == 1:
        res += C[A[i]-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()))

result = 0
for i, a_i in enumerate(a):
    result += b[a_i - 1]
    if i != 0:
        if a_i == (a_old + 1):
            result += c[a_i - 2]
    else:
        pass
    a_old = a_i
print(result)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split(" ")]
b = [int(j) for j in input().split(" ")]
c = [int(i) for i in input().split(" ")]
gain = 0 
for i in range(n):
	if(i==0):
		gain += b[a[i]-1]
	else:
		gain += b[a[i]-1]
		if(a[i]==a[i-1]+1):
			gain += c[a[i-1]-1]
print(gain)

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

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int,ins()))
def lin(): return list(input())
def iin(): return map(int,ins())

n = ii()
a = iil()
b = iil()
c = iil()
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):
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

prev_a = None
ret = 0
for a_ in a:
    ret += b[a_ - 1]
    if prev_a is not None and a_ - prev_a == 1:
        ret += c[prev_a - 1]
    prev_a = a_

print(ret)

Solution (Python):
N = int(input()) 
s = [input().split() for i in range(3)]

A = [int(i) for i in s[0]]
B = [int(i) for i in s[1]]
C = [int(i) for i in s[2]]

sum1 = sum(B)

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


print(sum1)

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

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

sum1 = sum(B)

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

print(sum1)

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

Solution (Python):
input()
A, B, C = [list(map(int, input().split())) for i in range(3)]
print(sum(B)+sum(C[A[i]-1] for i in range(len(C)) if A[i] == A[i+1]-1))

Solution (Python):
N = int(input())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
fill = 0
for i in range(N):
  fill += B[A[i]-1]
  if i > 0:
    if A[i] == A[i-1]+1:
      fill += C[A[i-1]-1]
print(fill)

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

j = 99
m = 0
for i in range(len(a)) :
    m += b[a[i]-1]
    if a[i]-1 == j+1 :
        m += c[j]
    j = a[i]-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()))
C=0
for i in range(n-1):
    if a[i]+1==a[i+1]:
        C+=c[a[i]-1]
print(sum(b)+C)

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

sum = 0
bf = -1

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

    if i == bf + 1:
        sum += C[i-2]

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

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

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

res = 0

for i in range(n):
    b_index = a[i]
    b_index -= 1
    b_value = b[b_index]
    res += b_value

    if i < n-1:
        b_index_next = a[i+1]
        b_index_next -= 1
        b_value_next = b[b_index_next]
        if b_index_next - b_index == 1:
            c_value = c[b_index]
            res += c_value

print(res)

Solution (Python):
n = int(input())
a_list = [int(e) for e in input().split()]
b_list = [int(e) for e in input().split()]
c_list = [int(e) for e in input().split()]

satisfuction = 0
for i, a in enumerate(a_list):
  satisfuction += b_list[a-1]
  if (i >= 1) & (a - a_list[i-1] == 1):
    satisfuction += c_list[a_list[i-1]-1]
print(satisfuction)

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

C=[0]+C
S=sum(B)

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

last = -1

sum = sum(b) 

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

Solution (Python):
n = input()
a = input()
b = input()
c = input()
n = int(n)
a = a.split()
a = [int(x) for x in a]
b = b.split()
b = [int(x) for x in b]
c = c.split()
c = [int(x) for x in c]
extrapoint = 0

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

output= sum(b) + extrapoint

print(output)

Solution (Python):
from operator import itemgetter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
l=[]
for i in range(n):
  l.append([i,a[i],b[i]])
l.sort(key=itemgetter(1))
cost = 0
for i in range(n):
  val = l[i][1]
  ix = l[i][0]; previx = -2
  if(i!=0):
    previx = l[i-1][0]
  cost+=(l[i][2])
  if(previx+1==ix):
    cost+=(c[i-1])
print(cost)

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

cnt = sum(B)

for i in range(len(A)-1):
  if A[i+1] - A[i] == 1:
    cnt += C[A[i+1]-2]

print(cnt)

Solution (Python):
N = input()
array_A = list(map(int, input().split()))
array_B = list(map(int, input().split()))
array_C = list(map(int, input().split()))

bonus_position = []
for i in range(len(array_A)-1):
  if array_A[i] + 1 == array_A[i+1]:
    bonus_position += [i]

bonus_dish = []
for i in bonus_position:
    bonus_dish += [array_A[i]]

bonus_point = 0
for i in bonus_dish:
    bonus_point += array_C[i-1]

score = sum(array_B) + bonus_point
print(score)

Solution (Python):
n = int(input())
dat_a = map(int, input().split())
dat_b = map(int, input().split())
dat_c = map(int, input().split())
dat_a = list(dat_a)
dat_b = list(dat_b)
dat_c = list(dat_c)
last = -100
res = 0
for i in range(n):
    a = dat_a[i] - 1
    res += dat_b[a]
    if last == (a - 1):
        res += dat_c[last]
    last = a
print(res)

Solution (Python):
import numpy as np
N = input()
N = int(N)
A = np.hstack([int(a) for a in input().split()])
B = np.hstack([int(a) for a in input().split()])
C = np.hstack([int(a) for a in input().split()])

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

score += B[A[N-1]-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()))

total = 0
pos = 0
while pos< N:
	posB = A[pos] -1
	total = total + B[posB]
	if A[pos] - A[pos - 1] == 1 and pos > 0:
		posC = A[pos] - 2
		total = total + C[posC]
	pos += 1
print(total)

Solution (Python):
num = int(input())
order = [int(s) for s in input().split()]
utility = [int(s) for s in input().split()]
add = [int(s) for s in input().split()]
point = 0
for i in range(num - 1):
  if order[i] + 1 == order[i + 1]:
    point += add[order[i] - 1]
    
print(sum(utility) + point)

Solution (Python):
N = int(input())
temp = input().split()
A = []
for i in range(N):
  A.append(int(temp[i]))
temp = input().split()
B = []
for i in range(N):
  B.append(int(temp[i]))
temp = input().split()
C = []
for i in range(N-1):
  C.append(int(temp[i]))

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

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

A.append(-1)
manzoku = 0
for i in range(N):
    num_dish = A[i] - 1
    manzoku += B[num_dish]
    if A[i+1] == A[i] + 1:
        manzoku += C[num_dish]

print(manzoku)

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

Solution (Python):
from sys import stdin
from math import factorial
n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
c = list(map(int,stdin.readline().rstrip().split()))
point = 0
for i in range(n-1):
    point += b[a[i]-1]
    if a[i] + 1 == a[i+1]:
        point += c[a[i]-1]
point += b[a[n-1]-1]
print(point)

Solution (Python):



import sys

N = int(sys.stdin.readline())

a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
c = list(map(int, sys.stdin.readline().rstrip().split()))




manzoku = 0
prev = -1

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


print(manzoku)

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()))
max=sum(b)

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

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

sat = sum(B)
for a, n_a in zip(A, A[1:]):
  if n_a - a == 1:
    sat += C[a]

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

Solution (Python):
import sys
import math

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

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def pro(k, l, n):
    if l < n:
        if k == 0:
            return(n - l)
        return (n - l + 2)
    if l == n:
        if k == 0:
            return 0
        elif k == 1:
            return 1
        return 3
    else:
        l -= n - 1
        if l == k:
            return 1
        elif l > k:
            return 0
        if l < k - 1:
            return 2
        else:
            return 3
            

def rt(k, l , n):
    if k < n:
        if l == 0:
            return (k * 2 + n)
        return (n + k * 2 - 1)
    elif k == n:
        if l == 1:
            return (k * 3 - 2)
        elif l == 0:
            return (k * 3)
        return (k * 3 - 3)
    else:
        k -= n - 1
        if k == l:
            return (n * 3 - 2)
        elif k > l:
            return (n * 3)
        if k < l - 1:
            return ((n - 1) * 3 - 1)
        else:
            return ((n - 1) * 3)



def main():
    n = iinput()
    a = rlinput()
    res = sum(rlinput())
    c = rlinput()
    for i in range(n - 1):
        if a[i] - a[i + 1] == -1:
            res += c[a[i] - 1]
    print(res)
            
        
    
    
    
    
    


main()

Solution (Python):
n = int(input())
Dishes = [int(i) for i in input().split()]
Sat = [int(i) for i in input().split()]
AddSat = [int(i) for i in input().split()]
FinishSat = 0
for i in range(n):
    FinishSat += Sat[i]
    if i > 0:
        if Dishes[i - 1] + 1 == Dishes[i]:
            FinishSat += AddSat[Dishes[i - 1] - 1]
print(FinishSat)

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

basepoint=sum(B)
additional=0
for i in range(N-1):
    if A[i+1]==A[i]+1:
        additional += C[A[i]-1]
ans=basepoint+additional
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())) 
summ = 0 
for i in range(n-1): 
    if a[i] + 1 == a[i + 1]: 
        summ += c[a[i]-1] 
        summ += b[a[i]-1] 
    else: 
        summ += b[a[i]-1] 
print(summ + b[a[n-1]-1])

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

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

point = sum(B)
prev_a = -1
for a in A:
    if a - prev_a == 1:
        point += C[a-2]
    prev_a = a
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()))

ans = sum(B)

now = A[0]
for i in range(1, len(A)):
    if now+1 == A[i]:
        ans += C[now-1]
    now = A[i]

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

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;
for i in range(len(a)):
    total += b[a[i] - 1]
    if n - 1 == i: 
        continue
    elif 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()))

y = -2
ans = 0

for x in a:
    if x == y + 1:
        ans += c[y-1]
    ans += b[x-1]
    y = x

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

  if a[i] == (prev + 1):
    ans += c[prev-1]

  prev = a[i]
  
print(ans)

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

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

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())
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
l_c = list(map(int, input().split()))

s = 0
for i in range(n - 1):
    s += l_b[l_a[i] - 1]
    if l_a[i] + 1 == l_a[i + 1]:
        s += l_c[l_a[i] - 1]
s += l_b[l_a[-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()))

ans = 0

for a in 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):
n = int(input())
a = input().split()
a = [int(s) for s in a]
b = input().split()
b = [int(s) for s in b]
c = input().split()
c = [int(s) for s in c]
hapiness = 0
for i in range(len(a)):
        hapiness += b[a[i]-1]
        if i:
                if a[i-1] + 1 == a[i]: hapiness += c[a[i-1]-1]
print(hapiness)

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

sum1 = sum(b)
tmpsum = 0
for i in range(len(c)):
  if(a[i+1] == a[i]+1):
    tmpsum += c[a[i]-1]

print(sum1+tmpsum)