Problem:
 Score : 200 points    Problem Statement Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1 , Dish 2 , \ldots , Dish N ) once.  The i -th dish (1 \leq i \leq N) he ate was Dish A_i .  When he eats Dish i  (1 \leq i \leq N) , he gains B_i satisfaction points.  Additionally, when he eats Dish i+1 just after eating Dish i  (1 \leq i \leq N - 1) , he gains C_i more satisfaction points.  Find the sum of the satisfaction points he gained.      Constraints  All values in input are integers.  2 \leq N \leq 20  1 \leq A_i \leq N  A_1, A_2, ..., A_N are all different.  1 \leq B_i \leq 50  1 \leq C_i \leq 50         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N  B_1  B_2  ...  B_N  C_1  C_2  ...  C_{N-1}       Output Print the sum of the satisfaction points Takahashi gained, as an integer.        Sample Input 1 3
3 1 2
2 5 4
3 6      Sample Output 1 14  Takahashi gained 14 satisfaction points in total, as follows:   First, he ate Dish 3 and gained 4 satisfaction points.  Next, he ate Dish 1 and gained 2 satisfaction points.  Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.        Sample Input 2 4
2 3 4 1
13 5 8 24
45 9 15      Sample Output 2 74       Sample Input 3 2
1 2
50 50
50      Sample Output 3 150

Solution (Python):
import sys


def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))


n=II()
A=LI()
B=LI()
C=LI()

ans = 0
before = -1

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

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
N=input()
A=[None]+map(int, sys.stdin.readline().split())
B=[None]+map(int, sys.stdin.readline().split())
C=[None]+map(int, sys.stdin.readline().split())

ans=0
prev=None
for a in A:
    if a is None: continue
    ans+=B[a]
    if prev is not None and prev+1==a:
        ans+=C[prev]
    prev=a

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

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

print(sum(satisfactions))

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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



if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
A=[int(_) for _ in input().split()]
B=[int(_) for _ in input().split()]
C=[int(_) for _ in input().split()]
ans=sum(B)
for i in range(n-1):
    if A[i+1]==A[i]+1:
        ans+=C[A[i]-1]

print(ans)

Solution (Python):

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

ret = b[a[0]-1]
for i,j in zip(a,a[1::]):
    ret += b[j-1]
    if j - i == 1:
        ret += c[j-2]
print(ret)

Solution (Python):
n = int(input())
ali = list(map(int,input().split()))
bli = list(map(int,input().split()))
cli = list(map(int,input().split()))
total = 0
for i in range(n):
    total += bli[ali[i]-1]
    if i != n-1:
        if ali[i] == ali[i+1] - 1:
            total += cli[ali[i]-1]
print(total)

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

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

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

s = 0
k = int(A[0])
for i in range(N):
  n = int(A[i])
  s += int(B[n-1])
  if k+1 == n:
    s += int(C[n-2])
  k = n

print(s)

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

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

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

Solution (Python):
num = int(input())
index = list(map(int, input().split()))
point = list(map(int, input().split()))
add = list(map(int, input().split()))


total = 0
for i in range(num):
  total += point[index[i]-1]

for j in range(num-1):
  if index[j+1] == index[j]+ 1:
    total += add[index[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
for i in range(N):
    ans+=B[A[i]-1]
    if i!=N-1:
        if A[i]+1==A[i+1]:
            ans+=C[A[i]-1]
print(ans)

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


if __name__ == '__main__':
    q2()

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

count = 0

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

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

suff = 0

for i in range(n):
    suff += B[A[i]-1]

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

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

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

sum = sum(b)

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

Solution (Python):
import io
import sys
import math

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

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

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

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

print(x)

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

ans = 0

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

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
C = [C[A[i]-1] for i, _ in enumerate(C) if A[i+1]-A[i]==1] 



U = sum(B) + sum(C)

print(U)

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

Solution (Python):

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

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
n=I()
As=LI()
Bs=LI()
Cs=LI()
satis=Bs[As[0]-1]
for i in range(1,n):
    satis+=Bs[As[i]-1]
    if As[i]==As[i-1]+1:
        satis+=Cs[As[i-1]-1]
print(satis)

Solution (Python):
n = int(input())
order = list(map(int, input().split()))
for i in range(n):
    order[i] -= 1
point = list(map(int, input().split()))
bonus = list(map(int, input().split()))

ans = 0
pre = -2 
for i in range(n):
    now = order[i]
    ans += point[now]
    
    if pre == now - 1:
        ans += bonus[pre]
    
    pre = 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 = 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 = [ int (x) for x in input().split() ]
B = [ int (x) for x in input().split() ]
C = [ int (x) for x in input().split() ]

result = sum(B)

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

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

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

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

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

Solution (Python):
str_to_int = lambda value: int(value)

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

answer = 0
previous = -1
for Ai in A:
    delicious = B[Ai - 1]

    has_bonus = Ai - previous is 1
    bonus = C[previous - 1] if has_bonus  else 0

    answer += (delicious + bonus)

    previous = Ai

print(answer)

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

Solution (Python):
*H,=map(int,open(0).read().split());N=H[0];A=H[1:N+1]+[0];B=H[N+1:2*N+1];C=H[-N+1:];a=i=0
while i<N:
    a+=B[i]
    if A[i+1]-A[i]==1:a+=C[A[i]-1]
    i+=1
print(a)

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

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

sum=0


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

j=0
while j < N-1:
  
  if A[j+1]==A[j]+1:
    sum=sum+C[A[j]-1]
    
  j=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()]
res = 0
last = -1
for a in A:
  res += B[a-1]
  if a - last == 1:
    res += C[last-1]
  last = a
print(res)

Solution (Python):
n = int(input())
a = input().split()
b = input().split()
c = input().split()
result = 0
for i in range(n):
    order = int(a[i]) - 1
    result += int(b[order])
    if int(a[i]) - int(a[i-1]) == 1 and i is not 0:
        result += int(c[order-1])
print(result)

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

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

ans = sum(b)
bef = -1
for x in a:
    if bef + 1 == x:
        ans += c[bef - 1]
    bef = x
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):
    if (cnt > 0) and (a[i]==(a[i-1]+1)):
        cnt += c[a[i-1]-1]

    cnt += b[a[i]-1]
    
print(cnt)

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

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
B=nl()
C=nl()
sum=0

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

print(sum)

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
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
  last = A[0]-1
  for i in range(n):
    ans += B[A[i]-1]
    
    if A[i]-1 == last + 1:
      
      
      ans += C[last]
      last = A[i]-1
    else:
      last = A[i]-1
  print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
result = sum(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n-1):
    if a[i] == a[i+1]-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 = 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]-2]
print(ans)

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

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

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

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

ans = 0
for i in range(n):
    
    ans += b_list[a_list[i]-1]
    
    if i == 0:
        continue
    else:
        if a_list[i] == a_list[i-1]+1:
            
            
            ans += c_list[a_list[i-1]-1]

print(ans)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [int(z) for z in input().split()]

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

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
B = iil()
C = iil()

ans = sum(B)

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

print(ans)

Solution (Python):
n = int(input())
cuisine = list(map(int, input().split()))
saticefaction = list(map(int,input().split()))
moreSaticefaction = list(map(int, input().split()))
total = 0
beforeCuisine = -1
for i in cuisine:
  total += saticefaction[i - 1]
  if (i - 1) == beforeCuisine:
    total += moreSaticefaction[beforeCuisine - 1]
  beforeCuisine = i
print(total)

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

for i in range(n):
  point += b[a[i]-1]
  if i <= n-2 and a[i+1] == a[i] + 1:
    point += c[a[i]-1]

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

for i in range(n):
    if i >= 1 and 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()))

ans = 0
for i in range(0,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):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    b=LIST()
    c=LIST()
    ans=0
    for i in range(n):
        if i==0:
            ans+=b[a[i]-1]
        else:
            ans+=b[a[i]-1]
            if a[i-1]==a[i]-1:
                ans+=c[a[i-1]-1]
    print(ans)
if __name__ == '__main__':
    do()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
stack = A[0]
total = 0
for a in A:
  if stack == a-1:
    total += B[a-1]+C[stack-1]
  else:
    total += B[a-1]
  stack = a
print(total)

Solution (Python):
N = int(input())
Main = list(map(int,input().split()))
S = list(map(int,input().split()))
S_2 = list(map(int,input().split()))
ans = sum(S)
p = 0

for i in range(N-1):
    if Main[i+1] == Main[i]+1:
        p = Main[i]-1
        ans = ans + S_2[p]

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):
n = int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
clist.append(0)
ans = 0
for i in range(0,n):
    ans += blist[alist[i] - 1]
    if i != n-1 :
        if alist[i] +1 == alist[i+1]:
            ans += clist[alist[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
i=0
while i<=N-1:
  sum+=B[i]
  i+=1
for i in range(N-1):
  K=A[i]
  if A[i+1]==K+1:
    sum+=C[K-1]
  else:
    sum+=0
print(sum)

Solution (Python):
N = int(input())
A_k = list(map(int, input().split()))
B_k = list(map(int, input().split()))
C_k = list(map(int, input().split()))

amount = 0
mae = -1
for A in A_k:
    amount += B_k[A-1]
    if A == mae + 1:
        amount += C_k[A-2]
    mae = A    

print(amount)

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

ans = sum(b)

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

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

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

at=-1
for ai in a:
    m+=b[ai-1]
    if ai == at+1:
        m+=c[at-1]
    at=ai
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()))

m=0
at=-1
for i,ai in enumerate(a):
    m+=b[ai-1]
    if ai == at+1:
        m+=c[at-1]
    at=ai
print(m)

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

prev = -1
ret = 0

for item in a_list:
    de = b_list[item-1]
    if item == prev+1:
        de += c_list[item-2]
    prev = item
    ret += de

print(ret)

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

total = 0
mae = -1

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N = int(input())
    A = input_nums()
    B = input_nums()
    C = input_nums()
    total = 0
    before = -2
    for a in A:
        total += B[a-1]
        if before + 1 == a - 1:
            total += C[a-2]
        before = (a - 1)
    print(total)

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

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

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

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

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

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

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
B = lr()
C = lr()
temp = 0
answer = 0
for i in range(N):
    answer += B[A[i] - 1]
    if 0 < i and A[i] - A[i-1] == 1:
        if A[i] - 1 <= N-1:
            answer += C[A[i-1] - 1]

print(answer)

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

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

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

sum_c = 0

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

print(sum(b) + sum_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 = 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 sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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 - 1):
        ans += B[A[i] - 1]

        if A[i] + 1 == A[i+1]:
            ans += C[A[i] - 1]

    ans += B[A[-1] -1]

    print(ans)



if __name__ == "__main__":
    main()

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

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

main()

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

subtotal = sum(b)
bonus = 0

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

total = subtotal + bonus
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()))

manzoku = sum(B)

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

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

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

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

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

    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)


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[i]

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())
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
Clist=list(map(int,input().split()))

b_sum=sum(Blist)

for i in range(N-1):
    if Alist[i]+1==Alist[i+1]:
        b_sum+=Clist[Alist[i]-1]

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