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

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

print(ans + ans2)

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

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

sumB = sum(B)

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

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

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

total = 0


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

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

mnzkC = 0
for j in range(N - 1):
    if A[j + 1] - A[j] == 1:
        mnzkC += C[A[j] - 1]
    
print(mnzkB + mnzkC)

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

s = sum(b)
f = -1


for index,i in enumerate(a):


    if i == f + 1:

        s += c[f-1]
    f = i

print(s)

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

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

a_sub = input().split(" ")
a = [int(n0) for n0 in a_sub]


b_sub = input().split(" ")
b = [int(n0) for n0 in b_sub]


c_sub = input().split(" ")
c = [int(n0) for n0 in c_sub]


score = 0
for xi in range(N-1):
    score = score + b[xi]
    if a[xi+1]==a[xi]+1:
        score = score + c[a[xi]-1]
        
score = score + b[N-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()))
addition = 0
price=0
for i in range(0, N-1):
    if a[i]+1 == a[i+1]:
        addition+=c[a[i]-1]
    else:
        
        addition+=0

print(sum(b) + addition)

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


print(ans)

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

bsum=0
for i in b: 
    bsum += i

csum=0
for i in range(0,n-1):
    if a[i]+1 == a[i+1]:
        csum += c[a[i]-1]
        
        
print(bsum+csum)

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


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

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

score = 0
order = -1

for i in range(n):
  score += b[i]
  _order = a[i]

  if order + 1 == _order:
    score += c[order - 1]
    
  order = _order

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

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

Solution (Python):
import sys
import math
from fractions import gcd





def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n =  int(sys.stdin.readline())
a =  list(map(int, sys.stdin.readline().split()))
b =  list(map(int, sys.stdin.readline().split()))
c =  list(map(int, sys.stdin.readline().split()))

ans=0
a0=a[0]-1





ans+=b[a0]

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

Solution (Python):
cnt = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
lc = list(map(int, input().split()))

total  =0
for i in range(cnt):
  total += lb[la[i] - 1]
  if i != 0 and (la[i-1] +1) == la[i]:
    total += lc[la[i] - 2]

print(total)

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

A = input().split()
B = input().split()
C = input().split()

ans = 0
tmp = -1
if 2<=N and N<=20:
    if 1<=len(A) and len(A)<=N:
        for a in A:
            
            if int(a) == tmp+1:
                
                ans += int(C[tmp-1])
            
            
            b = int(B[int(a)-1])
            if not(1<=b and b<= 50):
                exit()
            else:
                
                ans += b

            tmp = int(a)
        print(ans)

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

for i in range(1, N):
    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()))


p = 0

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

  
  if i == N-1:
    continue
    
  if A[i+1] == A[i] + 1:
    p += C[A[i]-1]

  
print(p)

Solution (Python):
N = int(input())
ORDER = list(map(int,input().split()))
SUTISFUCTION = list(map(int,input().split()))
ADDITTIONAL_SUTISFUCTION = list(map(int,input().split()))

s, prev = 0, 50
for i in ORDER:
    s = s + SUTISFUCTION[i - 1]
    if prev == i - 1:
        s = s + ADDITTIONAL_SUTISFUCTION[prev - 1]
    prev = i
    
print(s)

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

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

satisfy = sum(B)

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

print(satisfy)

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

answer = 0
A.append(0)

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

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

m += B[A[N-1]-1]
print(m)

Solution (Python):


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

ans = 0


for i,v in enumerate(a):
    ans += b[v]
    if i != n-1:
        if a[i]+1 == a[i+1] :
            ans += c[v]

print(ans)

Solution (Python):
def main():
    N = int(input())
    take_dish = list(map(int,input().split()))
    dish_point = list(map(int,input().split()))
    bonus_dish_point = list(map(int,input().split()))
    result = 0

    for index,dish in enumerate(take_dish):
        result += dish_point[dish-1]
        if(index!=0 and (take_dish[index-1]+1 == dish)):
            result += bonus_dish_point[take_dish[index-1]-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()))

ans=0
memo=1000
for i in a:
    ans += b[i-1]
    if (i - memo) == 1:
        ans+=c[memo-1]
    memo=i
print(ans)

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

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

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

bFood = 21
sut = 0

for i in range(N):
    food = A[i]
    sut = B[food - 1] + sut
    
    if food is bFood + 1: 
        sut = C[food - 2] + sut

    bFood = food

print(sut)

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

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

    
    if i > 0:
        if A[i] == A[i-1] + 1:

            r += C[A[i-1] - 1]

print(r)

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

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

Solution (Python):
_ = input()
n = list(map(int, input().split()))
s = sum(map(int, input().split()))
p = list(map(int, input().split()))
a = []
for i, (c, d) in enumerate(zip(n[1:], n[:-1])):
  if (c-d) == 1:
    a.append(d-1)

print(s + sum([p[i] for i in a]))

Solution (Python):

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

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

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

print(manzoku)

Solution (Python):
def B_Buffet():
    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 (0 < i) and (A[i] == A[i-1] +1):
            ans += C[A[i-1]-1]
    print(ans)
    
if __name__ == "__main__":
    B_Buffet()

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[A[i]-1]
  if i != 0:
    if (A[i-1] + 1) == A[i]:
      satisfaction += C[A[i-1]-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()))
alpha =0
kiso_score = sum(B)
for i in range(N-1):
    ind = A[i+1] - A[i]
    if ind ==1:
        alpha += C[A[i]-1]
print(kiso_score+alpha)

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

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

result = 0
old = -5
for i in range(N):
    result = result + B[A[i]-1]

    if (A[i]-2 == old):
        result = result + C[old]

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

man = 0

for i in range(N):
    
    
    
    
    
    

    man += B[A[i]-1]
    if i-1 >= 0 and A[i-1]+1 == A[i]:
        man += C[A[i-1]-1]





print(man)

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

d = 0
for i in b:
  d += i

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

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 x in B:
    s += x
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):
  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(lambda x: int(x), input().split()))
b = list(map(lambda x: int(x), input().split()))
c = list(map(lambda x: int(x), input().split()))

point = 0
temp = n + 1

for i, num in enumerate(a):
    point += b[num - 1]
    if num == temp + 1:
        point += c[num - 2]
    temp = num

print(point)

Solution (Python):


def ans() :

    
    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]

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

    print(ans)


if __name__ == '__main__':
    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(N):
    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()))
cnt = 0

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

point = sum(B)

for i in range(1, len(A)):
    if A[i] - A[i-1] == 1:
        point += C[A[i-1]-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()))
point = sum(B)
for i, AA in enumerate(A[0:N-1]):
    if AA + 1 == A[i+1]:
        point = point + C[AA-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()))
sat = 0
for i in range(n):
  j = a[i]-1
  sat += b[j]
  if 0<i<=n-1 and a[i]-a[i-1]==1:
    sat += c[j-1]
print(sat)

Solution (Python):

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

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

print(sati)

Solution (Python):
N = int(input())
AA = input()
BB = input()
CC = input()

A = [int(i) for i in AA.split()]
B = [int(i) for i in BB.split()]
C = [int(i) for i in CC.split()]

score = 0
prev = "None"
for i in range(N):

    a = A[i]

    score += B[a-1]


    if prev != "None" and prev == a - 1:
        score += C[prev - 1]
    prev = a
    
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()))
x=0
for i in range (N-1):
  if A[i]+1 == A[i+1]:
    x= x+B[i]+C[A[i]-1]
  else:
    x= x+B[i]
print(x+B[N-1])

Solution (Python):
n = int(input())
order = list(map(lambda x : int(x)-1, input().split()))
sats = list(map(int, input().split()))
bonus = list(map(int, input().split()))

bef = 21
ans = 0
for i in order:
  ans += sats[i]
  if i == bef + 1:
    ans += bonus[i - 1]
  bef = i

print(ans)

Solution (Python):
while True:
    try:
        n = int(input())
        ans = 0
        lsta = list(map(int, input().split()))
        lstb = list(map(int, input().split()))
        lstc = list(map(int, input().split()))
        last = lsta[0]
        for i in range(n):
            ans += lstb[lsta[i]-1]
            if last + 1 == lsta[i]:
                ans += lstc[last-1]
            last = lsta[i]
        print(ans)
    except:
        break

Solution (Python):
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

manzokudo = 0
for B in Blist:
    manzokudo += B
    
for i in range(0, N-1):
    if Alist[i]+1 == Alist[i+1]:
        manzokudo += Clist[Alist[i]-1]

print(manzokudo)

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

ABC[2].append(0)

flg = -100
cnt = 0
for n in range(N):
    cnt += ABC[1][n]
    if flg == ABC[0][n] - 1:
      cnt += ABC[2][flg - 1]
    flg = ABC[0][n]
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
temp = []
for i in range(1, N):
    if A[i]-1 == A[i-1]:
        if not A[i]-2 < 0:
            ans += C[A[i]-2]
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()))

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

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

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

    print(res)

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

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

ALL = 0

for j,k in enumerate(A):
    len_A = len(A)
    ALL += B[k-1]
    if j + 1 == len_A:
        pass
    else:
        if A[j+1] - k == 1:
            ALL += C[k-1]
print(ALL)

Solution (Python):
a = int(input())
List_a=list(map(int,input().split()))
List_b=list(map(int,input().split()))
List_c=list(map(int,input().split()))
B = 0
count = 0
key = 0
for i in List_a:
  B += List_b[i-1]
  if count > 0 and key+1 ==i:
    B += List_c[i-2]
  key = i
  count += 1
 
print(B)

Solution (Python):
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
adds = list(map(int, input().split()))

pre = 100
total = 0
for dish in dishes:
  if dish == pre + 1:
    total += points[dish-1] + adds[pre-1]
    pre = dish
  else:
    total += points[dish-1]
    pre = dish

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

result = 0
for i, x in enumerate(A):
    result += B[x-1]
    if i == N-1:
        break
    if x+1 == A[i+1]:
        result += C[x-1]
        
print(result)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
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())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))

ans = sum(list_b)

for i in range(N-1):
    if(list_a[i+1] == list_a[i]+1 ):
        ans = ans + list_c[list_a[i]-1]

print(ans)

Solution (Python):
import numpy as np
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())))

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

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

print(sum(B)+plus)

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

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

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

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

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

a = [ i-1 for i in a]

ans = 0
pre = -2
for x in a:
    ans += b[x]

    if x == (pre + 1):
       ans += c[pre]

    pre = x

print(ans)

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

bonus = 0
for i, no in enumerate(A):
    
    if i == len(A) - 1:
        break
    elif no + 1 == A[i + 1]:
        bonus += C[no - 1]

print(sums + bonus)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
old_a = -1
ans = 0

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

a.insert(0,0)
b.insert(0,0)
c.insert(0,0)
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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

man = 0
k = 0
for i in a:
  man += b[i-1]
  if i == k:
    man += c[i-2]
  k = i + 1

print(man)

Solution (Python):
n=int(input())
a_box=list(map(int,input().split()))
b_box=list(map(int,input().split()))
c_box=list(map(int,input().split()))

count=0
number=-10
for i in a_box:
    i=i-1
    count +=b_box[i]
    if number+1==i:
        count +=c_box[number]
    number=i

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)
con=[]

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    con.append(A[i]-1)



for i in con:
  satisfy += C[i]
  

print(satisfy)

Solution (Python):
n = int(input())
a = list(map(lambda x : int(x) -1 ,input().split()))
b = list(map(int,input().split()))
c = [0]
c.extend(list(map(int,input().split())))
prev = 20
ans = 0
for i in range(n):
    if a[i] -1 == prev:
        ans += b[a[i]] + c[a[i]]
    else:
        ans += b[a[i]]
    prev = a[i]
print(ans)

Solution (Python):
N=int(input())
A=[int(n) for n in input().split()]
B=[int(n) for n in input().split()]
C=[int(n) for n in input().split()]
ans = 0
pre = -1
for i in A:
    ans += B[i-1]
    if pre == i-1:
        ans += C[i-2]
    pre = i
print(ans)

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

point = 0
point = sum(B)

for i in range(len(A)-1):
    if 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()))

res = 0
buf = -2
for i in A:
	res += B[i-1]
	if buf == i-2:
		res += C[i-2]
	buf = i-1

print(res)

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

history = list()
sat = 0
for i in range(N):
  a = A[i]
  b = B[a - 1]
  sat += b
  
  if len(history) == 0:
    pass
  elif history[-1] == a - 1:
    sat += C[a-2]
  history.append(a)
    
print(sat)

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

def main(a_list, b_list, c_list):
    before_element = 999
    result = 0
    for element in a_list:
        result += b_list[element-1]
        if element == before_element + 1:
            result += c_list[before_element-1]
        before_element = element
    return result

print(main(a_list, b_list, c_list))

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

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

print(sum(B) + additional)

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]
    if(i>0):
        if(a[i]==(a[i-1]+1)):
                sum += c[a[i-1]-1]

print(sum)

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

s = [input().split() for i in range(3)]

count =  0

num = s[0]
point = s[1]
bonus = s[2]


for p in range(int(len((num)))):
    count += int(point[int(num[p])-1])
    

for q in range(int(len(num))-1):
    if int(num[q+1]) - int(num[q]) == 1:
        count += int(bonus[int(num[q])-1])
       
    else:
        pass
print(count)

Solution (Python):
N = int(input())
foods = [int(i) for i in input().split()]
eff = sum([int(i) for i in input().split()])
plus = [int(i) for i in input().split()]
tmp = 0
for i, f in enumerate(foods):
  if i == 0:
    tmp = f
  elif f - tmp == 1:
    eff += plus[f-2]
    tmp = f
  else:
    tmp = f
print(eff)

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

Solution (Python):

def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        ans += B[A[i]-1]
        if i != 0 and A[i-1]+1 == A[i]:
            ans += C[A[i]-2]
    print(ans)

if __name__ == '__main__':
    main()

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

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

manzoku=0

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

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

print(num)