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):
class Solution:
    def solve(self, N: int, A, B, C) -> int:

        answer = 0
        previous = -2

        for a in A:
            answer += B[a-1]

            if previous + 1 == a and a > 1:
                answer += C[a-2]

            previous = a

        return answer


if __name__ == '__main__':

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

    
    solution = Solution()
    print(solution.solve(N, A, B, C))

Solution (Python):
kind=int(input())
food=list(map(int,input().split()))
manzoku=list(map(int,input().split()))
manzokuAfter=list(map(int,input().split()))

total=0
for i in range(0,kind):
  total += manzoku[food[i]-1]
  if i!=0 and food[i-1]+1==food[i]:
    total+=manzokuAfter[food[i-1]-1]

print(total)

Solution (Python):


import numpy as np

def main():
    n = int(input())
    a = np.array(list(map(int, input().split())))
    b = np.array(list(map(int, input().split())))
    c = np.array(list(map(int, input().split())))
    res = np.sum(b)
    idx = a[:-1][np.diff(a) == 1]
    res += np.sum(c[idx - 1])
    print(res)

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

total = 0
temp = float("inf")
for i in range(n):
  if a[i] == temp + 1:
    total += c[a[i - 1] - 1]
  temp = a[i]
  total += b[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()))

s = b[a[0] - 1]

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

print(co)

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

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

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

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

print(hap)

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

s = 0
t = 99
for i in a:
  if t+1 == i:
    s += c[t-1]
  s += b[i-1]
  t = 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()))
count=sum(B)
for i in range(N-1):
    if A[i]+1==A[i+1]:
        count=count+C[A[i]-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()))
satisfy = sum(B)

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

print(satisfy)

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

v = 0


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

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

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

print(ans)

Solution (Python):

import sys



def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans=sum(B)
    for i in range(N-1):
        if A[i+1]==A[i]+1: ans+=C[A[i]-1]
    print(ans)
    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 = sum(B)
for i, j in zip(A, A[1:]):
    if j == i+1:
        ans += C[i-1]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
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 = 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=0
for i in range(n):
    a_i=a[i]
    b_i=b[i]
    ans+=b_i
    if i<n-1:
        if a[i+1]-a_i==1:
            ans+=c[a_i-1]
print(ans)

Solution (Python):
from sys import stdin
n = int(input())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
c = list(map(int, stdin.readline().split()))
ans = sum(b)
for i in range (n-1):
    if a[i]+1 == a[i+1]:
        t = a[i]-1
        ans +=c[t]
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 = sum(B)
for i in range(0,N-1):
    if A[i]+1 == A[i+1]:
        s = s+C[A[i]-1]
print (s)

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

x = sum(B)
for a,b in zip(A,A[1:]):
    if b == a+1:
        x += C[a-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()))

add = 0

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

total = sum(b) + add

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

Solution (Python):



def main():
  n = int(input())
  As = list(map(int, input().strip().split()))
  Bs = list(map(int, input().strip().split()))
  Cs = list(map(int, input().strip().split()))
  score = 0
  for i in range(len(As)):
    score += Bs[As[i]-1]
    if i > 0 and As[i-1] != n and As[i-1] + 1 == As[i]:
      score += Cs[As[i-1]-1]
  print(score)

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):
  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):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	ans = 0
	A = LI()
	B = LI()
	C = LI()
	pre = -1
	for a in A:
		if(pre+1 ==a):
			ans += B[a-1]+C[a-2]
		else:
			ans += B[a-1]
		pre = a

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

for i in range(len(a)):
    if i == 0:
        scr = b[a[i] - 1]
    else:
        scr += b[a[i] - 1]
        if a[i] == a[i-1] + 1:
            scr += c[a[i-1] - 1]

print(scr)

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

ans=B[A[0]-1]
buf=A[0]

for a in A[1:]:
    ans+=B[a-1]
    if a-buf==1:
        ans+=C[buf-1]
    buf=a

print(ans)

Solution (Python):
import sys

n = int(sys.stdin.readline().rstrip())
a = [None] + [int(x) for x in sys.stdin.readline().split()]
b = [None] + [int(x) for x in sys.stdin.readline().split()]
c = [None] + [int(x) for x in sys.stdin.readline().split()]

def main():
    res = 0
    for i in range(1, n+1):
        j = a[i]
        res += b[j]
        if a[i-1] == j - 1:
            res += c[j-1]
    
    return res
    
if __name__ == '__main__':
    ans = main()
    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
b_n=-2
for i in range(n):
  num=a[i]-1
  ans+=b[num]
  if num==b_n+1:
    ans+=c[b_n]
  b_n=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

A.append(0)

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

print(sum)

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

Solution (Python):


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

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

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

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

s = b[a[0] - 1]

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

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

print(s)

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

satisfy = 0
prev = 10000

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

print(satisfy)

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

ans = 0
prev = 100000
for a in A:
    if prev + 1 == a:
        ans += B[a] + C[a - 1]
    else:
        ans += B[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()))
man=0
cnt=0
while cnt<N:
    man+=b[a[cnt]-1]
    if cnt<N-1:
        
        if a[cnt+1]-a[cnt]==1:
            man+=c[a[cnt]-1]
    cnt+=1
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()))
ans = 0
for i in range(len(a)):
    ans += b[a[i]-1]
    if a[i]-a[i-1] == 1 and i > 0:
        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
for i in range(len(a)):
    ans += b[a[i]-1]
    if a[i]-a[i-1] == 1 and i > 0:
        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()))
total=0
for i in range(N):
    total+=B[i]

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

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

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()]
e = 0
last = -1
for ax in a:
    e += b[ax - 1]
    if ax == last + 1:
        e += c[last - 1]
    last = ax
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()))
m=0
for i in a:
    m+=b[i-1]
for i in range(n-1):
    if a[i]+1==a[i+1]:
        m+=c[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()))
s = sum(b)
for i in range(n-1):
    if a[i+1]-a[i] == 1:
        s+=c[a[i]-1]
print(s)

Solution (Python):
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))

ans=0
dish=al[0]
ans+=bl[dish-1]
bef_dish=dish
for i in range(1,n):
    dish=al[i]
    ans+=bl[dish-1]
    if dish== bef_dish+1:
        ans+=cl[bef_dish-1]
    bef_dish=dish
print(ans)

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

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


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

score=b[a[0]-1]

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

prev = -2
ans = 0
for a in A:
    if a == prev+1:
        ans += C[prev-1]
    ans += B[a-1]
    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()))
total = 0

for j in range(N):
  total = total + B[j]

for i in range(N):
  if i > 0 and A[i] == A[i-1] + 1:
    total = 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 = ans + B[A[i] - 1]
  if i > 0 and A[i] == A[i-1] + 1:
    ans = ans + C[A[i-1] - 1]
print(str(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, j in zip(a[1:], a[:-1]):
    if i - j == 1:
        ans += c[i-2]
        
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = LIST()

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

print(sum(B) + su)

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

Solution (Python):
import sys

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

for i in range(number):
    answer += b[a[i]-1]
    
    if i != 0:
        if a[i-1] == a[i]-1:
            answer += c[a[i-1]-1]

print(answer)

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

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

for i in range(N):
    glad+=B[i]

print(glad)

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

sem_result = sum(b_list)
for i in range(n-1):
    if a_list[i+1] - a_list[i] == 1:
        sem_result += c_list[a_list[i] - 1]

print(sem_result)

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

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

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

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

print(point)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
score = list(map(int,input().split()))
add = list(map(int,input().split()))
sum = sum(score)

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

Solution (Python):
n = int(input())
a, b, c = [list(map(int, input().split()))for i in range(3)]

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

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)

Solution (Python):
import sys

[N] = [int(x) for x in sys.stdin.readline().split(" ")]

As = [int(x) - 1 for x in sys.stdin.readline().split(" ")]
Bs = [int(x) for x in sys.stdin.readline().split(" ")]
Cs = [int(x) for x in sys.stdin.readline().split(" ")]

prev = -999
result = 0
for i in range(N):
    a = As[i]
    result += Bs[a]
    if a == prev+1:
        result += Cs[prev]
    prev = a

print(result)

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

d = {}
for i in A:
    d[i] = B[i-1]

before = -1
ans = 0
for i in A:
    ans+=d[i]
    if i-before==1:
        ans += C[i-2]
    before = i

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
U1 = list(map(int,input().split()))
U2 = list(map(int,input().split()))
Ut = 0
for j in A:
    Ut += U1[j-1]
i = 0
while i < N-1:
    x = A[i:i+1]+A[i+1:i+2]
    if (x[1] - x[0]) == 1:
        Ut += U2[x[0]-1]
    i += 1
print(Ut)

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

Solution (Python):
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += bl[al[i]-1]
    if 1 <= i and al[i] == al[i-1]+1:
        ans += cl[al[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()))

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

print(Satisfaction)

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

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

Solution (Python):
n = int(input())
a_array, b_array, c_array = [list(map(int, input().split())) for _ in range(3)]
c_array.append(0)

sum = 0

for m in a_array:
    sum += b_array[m-1]

for i in range(n-1):
    if (a_array[i] + 1 == a_array[i+1]):
        sum += c_array[a_array[i]-1]

print(sum)

Solution (Python):
N = int(input())
A, B, C = [input().split() for i in range(3)]
A = [int(num) for num in A]
B = [int(num) for num in B]
C = [int(num) for num in C]
A.insert(0,0)
B.insert(0,0)
C.insert(0,0)
p = 0
for i in range(1,N+1):
  p += B[A[i]]
  if A[i-1] == A[i] - 1:
    p += C[A[i-1]]
print(p)

Solution (Python):
N=int(input())
A,B,C=[list(map(int,input().split())) for _ in range(3)]
C.append(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):
ans=0
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.append(0)
for i in A:
    ans+=B[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()))
s,f=0,-1
for x in a:
  s+=b[x-1]
  if x-f==1:
    s+=c[f-1]
  f=x
print(s)

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

ans = 0
p = -99999
for ind, i in enumerate(a):
  ans += b[i]
  if ind != 0:
    if i-1 == p:
      ans += c[i-1]
  p = 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):
	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 sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    r=sum(B)
    for i in range(N-1):
        if A[i+1]-A[i]==1:
            r+=C[A[i]-1]
    return r


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

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

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 num in b:
    s += num

for i in range(len(a)-1):
    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 = 0
before = -9

for i in a:
  ans += b[i - 1]
  if before + 1 == i:
    ans += c[before - 1]
  before = 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
o = a[0]
for i in a:
	s += b[i-1]
	if i-o == 1:
		s += c[o-1]
	o = 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()))
x = 0
for i in range(n):
    x += b[a[i]-1]
    if i!=0 and a[i-1]==a[i]-1:
        x += c[a[i]-2]
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()))
b_dic = {}
for i in range(1, N + 1):
  b_dic[i] = B[i - 1]
c_dic = {}
for i in range(1, N):
  c_dic[i] = C[i - 1]
count=0
br = -1
for a in A:
  count += b_dic[a]
  if br == a - 1:
    count += c_dic[br]
  br = a
print(count)

Solution (Python):
_ = input()
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = tuple(map(int, input().split()))
AA = tuple(zip(A, A[1:]))
CC = {(i,i+1):c for i, c in enumerate(C, 1)}
print(sum(B) + sum(CC.get(aa, 0) for aa in AA))

Solution (Python):
N = input()
A = [int(t)-1 for t in raw_input().split()]
B = map(int, raw_input().split())
C = map(int, raw_input().split())

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

result=0

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

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

c_count=0

ans=0

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

print(ans)

Solution (Python):
N = int(input().rstrip())
Idxs = [int(x) for x in input().rstrip().split()]
Bs = [int(x) for x in input().rstrip().split()]
Cs = [int(x) for x in input().rstrip().split()]

ret = 0
prev = -100
for idx in Idxs:
    ret += Bs[idx-1]
    if idx-1 == prev:
        ret += Cs[prev-1]
    prev = idx
print(ret)

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

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

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

print(answer)