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

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

print(ans)

Solution (Python):
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

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

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

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

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

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

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

if __name__ == '__main__':
    main()

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

N = int(input())
A = [int(i)-1 for i in 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]]
    
    
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 = -2
ans = 0
for i in a:
    if j == i-1:
        ans += c[i-2]
    j = i
ans += sum(b)
print(ans)

Solution (Python):
n,*l=map(int,open(0).read().split())
a=l[:n];b=l[n:2*n];c=l[2*n:]
bef=a[0]
ans=b[bef-1]
for i in a[1:]:
	ans+=b[i-1]
	if i==bef+1:
		ans+=c[i-2]
	bef=i
print(ans)

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

ans = sum(B)

for i 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(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

answer = 0

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

print(answer)

Solution (Python):
n = int(input())
meshi = [0] * 100
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 != 0 and a[i-1] + 1 == a[i]):
        ans += c[a[i-1]-1]


print(ans)

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

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

Solution (Python):
def solve():
    a, b, c = read()
    result = think(a, b, c)
    write(result)


def read():
    n = read_int(1)[0]
    a = read_int(n)
    b = read_int(n)
    c = read_int(n - 1)
    return a, b, c


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, c):
    satisfaction = 0
    prev = -1
    for e in a:
        satisfaction += b[e - 1]
        if prev == e - 1:
            satisfaction += c[prev - 1]
        prev = e
    return satisfaction


def write(result):
    print(result)


if __name__ == '__main__':
    
    
    
    
    solve()

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

Solution (Python):
n=int(input())
an=list(map(int,input().split()[:n]))
bn=list(map(int,input().split()[:n]))
cn=list(map(int,input().split()[:n-1]))

ret=sum(bn)

for i in range(n-1):
    if an[i] +1 ==an[i+1]:
        ret+=cn[an[i]-1]

print(ret)

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

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

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

c = [0] + list(map(int, input().split()))

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

    tmp = 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
prev = -10
for e in a:
  ans += b[e-1]
  if e==prev+1:
    ans += c[prev-1]
  prev = e
print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
ans = 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):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = sum(b)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    A = LI()
    B = LI()
    C = LI()


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

    print(manzoku)


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

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

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
ans = 0

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

print(ans)

Solution (Python):
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
A=get_array()
B=get_array()
C=get_array()
score=0
for i in range(n):
  score+=B[A[i]-1]
  if i!=0:
    if A[i]==A[i-1]+1:
      score+=C[A[i-1]-1]
print(score)

Solution (Python):

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
fm = 2 * N 
result = 0
for i in range(N):
    nm = As[i]
    result += Bs[As[i]-1]
    if nm -fm == 1:
        result += Cs[fm-1]
    fm = nm
print(result)

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()))
    Ap = N + 100
    Score = 0
    for Ai in A:
        Score += B[Ai-1]
        if Ai == Ap + 1:
            Score += C[Ap-1]
        Ap = Ai
    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()))

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

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

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
tmp = AL[0]-1
for i in AL:
    i = i-1
    ans += BL[i]
    if tmp == i-1:
        ans += CL[tmp]
    tmp = 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()))

for i in range(len(A)):
    A[i] -= 1

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

print(manzoku)

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()))
A += [0]

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

print(s + sum(B))

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

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

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[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
pre = 21
for a in A:
    total += B[a - 1]
    if pre + 1 == a:
        total += C[pre - 1]
    pre = a
print(total)

Solution (Python):
n=int(input())
a=[int(j)-1 for j in input().split()]
b=[int(j) for j in input().split()]
c=[int(j) for j in input().split()]
ans=sum(b)
for i in range(1,n):
    if a[i-1]+1==a[i]:
        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()]
ans=chk=0
for i in range(n):
    ans+=b[a[i]-1]
    if i!=0 and a[i-1]+1==a[i]:
        ans+=c[a[i-1]-1]
print(ans)

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

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

print(ans)

Solution (Python):

import sys


def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
A = ILI()
B = ILI()
C = ILI()
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

for i, eat in enumerate(a):
    point += b[eat - 1]
    if i == n - 1:
        print(point)
        exit()
    if a[i + 1] == eat + 1:
        point += c[eat - 1]

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

print(foodSum)

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

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

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

total = sum(Bs)

for i in range(N-1):
    if As[i+1] - As[i] == 1:
        
        total += Cs[As[i]-1]
print(total)

Solution (Python):
N = int(input())
L = []
for i in range(3):
    L.append([int(x) for x in input().split()])
    
ans = 0
A_b = -2
for i in range(N):
    A = L[0][i]
    if A_b + 1 == A:
        ans += L[2][A-2]
    ans += L[1][A-1]
    A_b = A
    
print(ans)

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

    result = 0
    pre = -1
    for a in a_s:
        result += b_s[a-1]
        if a == (pre+1):
            result += c_s[pre-1]
        pre = a
    print(result)



if __name__ == '__main__':
    main()

Solution (Python):

ip = lambda : map(int, input().split())

N = int(input())
A = list(ip())
B = list(ip())
C = list(ip())
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]
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(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 = 0
pre = -100
for i in A:
    i = i-1
    ans += B[i]
    if pre+1 == i:
        ans += C[pre]
    pre = i
print(ans)

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

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

for i in range(N-1):
    ans += B[A[i]-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 = 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=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):
  eat=a[i]
  ans+=b[a[i]-1]
  if a[i]-a[i-1]==1:
    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]"):
    pos = -100
    sm = 0 
    for i in range(N):
        sm += B[i]
        if i < N-1:
            if A[i] + 1 == A[i+1]:
                sm += C[A[i]-1]
    print(sm)
    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()))
sum=0
for i in range(n):
  sum += b[a[i]-1]

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

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

p = 0
for i in al:
    p += bl[i-1]

count = 0
tmp = -1
for i in al:
    if tmp == i-1:
        p += cl[tmp-1]
    tmp = i
print(p)

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

confetto = B[A[0] - 1]
old = A[0]

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

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=[int(i)-1 for i in input().split()]
b_list=[int(i) for i in input().split()]
c_list=[int(i) for i in input().split()]

bef=-1
ans=0
for a in a_list:
    ans+=b_list[a]
    if bef>=0 and a<n and bef==a-1:
        ans+=c_list[bef]
    bef=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()))

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

print(ans)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    a_list = list(map(int,input().split()))
    b_list = list(map(int,input().split()))
    c_list = list(map(int,input().split()))

    answer = 0
    for i in range(n):
        a = a_list[i]
        answer += b_list[a-1]
        if i < n-1:
            next_a = a_list[i+1]
            if next_a - a == 1:
                answer += c_list[a-1]
    print(answer)

Solution (Python):


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    before = -1
    satisfied = 0

    for num in A:
        satisfied += B[num-1]
        if (before != -1) and ((before + 1) == num):
            satisfied += C[num-2]
        before = num
    print(satisfied)

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

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.insert(0,0)
C = list(map(int,input().split()))
C.insert(0,0)
cnt = 0
for i in range(N-1):
    cnt += B[A[i]]
    if A[i+1] == A[i]+1:
        cnt += C[A[i]]
cnt += B[A[N-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()))
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()))
output = 0
prev = -1
for i in a:
    output += b[i - 1]
    if prev + 1 == i:
        output += c[prev - 1]
    prev = i
print(output)

Solution (Python):
N = int(input())
vA = list(map(int, input().split()))
vB = list(map(int, input().split()))
vC = list(map(int, input().split()))

res = 0

p = -100
for a in vA:
    ate = a - 1
    b = vB[ate]
    c = vC[p] if p+1==ate else 0
    res += b + c
    p = ate

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

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

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

ans = 0
prev = 99
for i in a:
    ans += b[i-1]
    if prev == i-1:
        ans += c[prev-1]
    prev = i

print(ans)

Solution (Python):
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]
    ans = 0
    latter = 60
    for i in range(n):
        now = a[i]-1
        ans += b[now]
        if latter+1 == now:
            ans += c[now-1]
        latter = now
    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 = 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 = [ int(x)-1 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]]
for i in range(1,N):
  ans += B[A[i]]
  if A[i] == A[i-1]+1:
    ans += C[A[i-1]]

print(ans)

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

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

S = sum(B)

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

total = B[A[0]-1]


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

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

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

satisfy = 0

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

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
mae = -1

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

t = [0]
for i in range(n-1):
    t.append(a[i]+1)

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

Solution (Python):



def solve(N, A, B, C):
    last = -1
    ans = 0
    for a in A:
        ans += B[a-1]
        if a == last+1:
            ans += C[last-1]
        last = a
    return ans


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = solve(N, A, B, C)

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

print(result)

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

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

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

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

Solution (Python):
def calc(N, A, B, C):
    score = sum(B)
    for i in range(N - 1):
        if (A[i] + 1 == A[i + 1]):
            score += C[A[i] - 1]
    return score


N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
print(calc(N, A, B, C))

Solution (Python):
n=int(input())
ass=list(map(int,input().split()))
bs=list(map(int,input().split()))
cs=list(map(int, input().split()))
ans=sum(bs)

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

print(ans)

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

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

    print(m)

if __name__ == "__main__":
    main()