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 numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))






testA = A + [0]
testB = [0] + A







print(sum(B) + sum(np.array(C)[np.array(A)[((np.array(testA) - np.array(testB)) == 1)[1:]]-1]))

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

point = 0
for j in range(n):
    if j >= 1:
        if c_l[0][j] == c_l[0][j-1] + 1:
            point += c_l[1][c_l[0][j]-1]
            point += c_l[2][c_l[0][j]-2]
        else:
            point += c_l[1][c_l[0][j]-1]
    elif j == 0:
        point += c_l[1][c_l[0][j]-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()))

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

arr = []
for i in range(len(a)):
    arr.append(b[a[i]-1])
    if i > 0:
        if a[i] == a[i-1] + 1:
            arr.append(c[a[i-1]-1])
    
print(sum(arr))

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 :
        if A[i] + 1 == A[i + 1]:
            M += C[A[i] - 1]

print(M)

Solution (Python):
n = int(input())
alist =list(map(int,input().split()))
blist =list(map(int,input().split()))
clist =list(map(int,input().split()))
cscore =0
for i in range(n-1):
   if alist[i+1]==alist[i]+1:
      cscore =cscore+clist[alist[i]-1]
print(sum(blist)+cscore)

Solution (Python):
n = int(input())
ryouri = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
tuika = list(map(int, input().split()))

base = 0
for i in range(n):
  base += manzoku[i]

for i in range(n-1):
  if ryouri[i+1]-ryouri[i] == 1:
    base += tuika[ryouri[i]-1]

print(base)

Solution (Python):

n = int(input())
alist =list(map(int,input().split()))
blist =list(map(int,input().split()))
clist =list(map(int,input().split()))
cscore =0
for i in range(n-1):
   if alist[i+1]==alist[i]+1:
      cscore =cscore+clist[alist[i]-1]
print(sum(blist)+cscore)

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):
    j = a[i]-1
    ans += c[j]

print(ans)

Solution (Python):

import sys

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


count = 0

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

Solution (Python):
n = int(input().rstrip())
eat = [ int(ch) for ch in input().rstrip().split(' ') ]
bs = [ int(ch) for ch in input().rstrip().split(' ') ]
cs = [ int(ch) for ch in input().rstrip().split(' ') ]

pre = -1
sum = 0
for k in eat:
  sum += bs[k - 1]
  
  if k - pre == 1:
    sum += cs[pre - 1]
  pre = k
  
print(sum)

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()]
cnt = 0

x = a[0]
cnt += b[a[0]-1]

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

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

total = 0
for i in range(n):
    total += b[a[i] - 1]

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

Solution (Python):
n=int(input())
lista = [int(i) for i in input().split()]
listb = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

ans1=sum(listb)
ans2=0
for i in range(n-1):
    if lista[i+1]==lista[i]+1:
        ans2=ans2+listc[lista[i]-1]
ans=ans1+ans2
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()))

mae = -1
point = 0

for i, a in enumerate(As):
    if mae + 1 == a:
        point += Cs[(a - 1)-1]
    point += Bs[a-1]
    mae = a

    
print(point)

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

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

As = []
As = list(map(int,input().split()))
Bs = []
Bs = list(map(int,input().split()))
Cs = []
Cs = list(map(int,input().split()))

value = 0
before = As[0]
for i,a in enumerate(As):
	value += Bs[a-1]
	if before+1 == a-1:
		value += Cs[before]
	before = a-1
	
print(value)

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

    b4 = a[i]
print(ans)

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

manzoku = 0
before_A = 0
for A in A_list:
    manzoku += B_list[A-1]
    if before_A == 0:
        before_A = A
    elif A == before_A + 1:
        manzoku += C_list[before_A-1]
        before_A = A
    else:
        before_A = A
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()))

s = 0

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

s+=b[a[n-1]-1]

print(s)

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

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

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

count=0

for b in B:
  count+=b

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_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
C_list = list(map(int,input().split()))
ans = sum(B_list)

for i in range(1,N):
    
    if A_list[i] == A_list[i-1]+1 :
        ans += C_list[A_list[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()))

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 = 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 - 1):
    if A_list[i + 1] - A_list[i] == 1:
        answer += C_list[A_list[i] - 1]

answer += sum(B_list)

print(answer)

Solution (Python):
N = int(input())
route = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
plus_s = list(map(int, input().split()))

ans = 0
route_cnt = None
for i in range(N):
    a = route[i]
    ans += satisfaction[a - 1]
    if route_cnt is None:
        route_cnt = a
        continue
    if a - route_cnt == 1:
        ans += plus_s[route[i] - 2]
    route_cnt = a
print(ans)

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

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

    total += B[x]
    if x == oldx +1:
            total += C[x-1]

    oldx = x

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


d = [0 for k in range(n)]
d[0]=b[a[0]-1]

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

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

Solution (Python):
N = int(input())
tmp = [list(map(int, input().split())) for _ in range(3)]
A = tmp[0]
B = tmp[1]
C = tmp[2]
A = list(map(lambda x:x-1,A))
result = B[A[0]]
for i in range(1,N):
  result += B[A[i]]
  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()))

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

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(N):
    A[i] -=1

sum = B[A[0]]

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

print(sum)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=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()))

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


a = sum(B2)
for i in range(N-1):
    if int(A[i])+1 == int(A[i+1]):
        b = int(A[i])-1
        a += int(C[b])
print(a)

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


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

Solution (Python):


import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
        lines.append(input())
        lines.append(input())

    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = int(lines[0])

    a = [int(e) for e in lines[1].split(" ")]
    b = [int(e) for e in lines[2].split(" ")]
    c = [int(e) for e in lines[3].split(" ")]

    return (n, a, b, c)


def solve(n, a, b, c):

    total = 0
    previous_dish_num = -1
    for i in range(n):
        dish_num = a[i]
        total = total + b[dish_num-1]
        if previous_dish_num + 1 == dish_num:
            total = total + c[previous_dish_num-1]
        previous_dish_num = dish_num

    return total


def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % 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()))




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


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


n = int(input())

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

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

c = map(int, input().split())
clist = list(c)
sum = 0
zenkai = 0
for ryouri in alist:
    sum += blist[ryouri-1]
    if zenkai == 0:
        zenkai = ryouri
    else:
        if zenkai+1 == ryouri:
            sum += clist[zenkai-1]
        zenkai = ryouri

print("{}".format(sum))

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

print(ans)

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

Solution (Python):
import numpy as np

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

s = np.sum(b)
for i in range(n):
  a[i] = a[i] -1

t = a[0]
for i in range(1, len(a)):
  if (t+1) == a[i]:
    s = s + c[a[i]-1]
  t = a[i]
print(s)

Solution (Python):
N = int(input())
eat = list(map(int, input().split())) 
sat = list(map(int, input().split())) 
ad_sat = list(map(int, input().split())) 


sum_sat = sat[eat[0]-1]
for i in range(1,N):
  sum_sat += sat[eat[i]-1]
  
  
  if eat[i] == 1 + eat[i-1]:
    sum_sat += ad_sat[eat[i-1]-1]
    

print(sum_sat)

Solution (Python):
def main():

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

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

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

Solution (Python):
n = int(input())
d = 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):
    if(i<(n-1) and d[i]==(d[i+1]-1)):
        ans+=c[d[i]-1]
print(ans)

Solution (Python):
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''

gi = lambda : list(map(int,input().split()))
n, = gi()
a, b, c = gi(), gi(), gi()
ans = sum(b)
for k in range(1, n):
	if a[k] - a[k - 1] == 1:
		ans += c[a[k] - 2]
print(ans)

Solution (Python):
N = int(input())
Cook = list(map(int, input().split()))
Manzoku = list(map(int, input().split()))
addManzoku = list(map(int, input().split()))

result_sum = 0
past_c = 55

for i, c in enumerate(Cook):
    result_sum += Manzoku[c-1]

    if c - past_c == 1:
        result_sum += addManzoku[c-2]
    past_c = c

print(result_sum)

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = list(np.array(A) - 1)
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum_ = 0
diff = list(np.array(A[1:]) - np.array(A[:-1]))
diff.insert(0, -1)
for i in range(N):
  sum_ += B[A[i]]
  
  if diff[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()))
ans = 0
prev = -10
for i in A:
    ans += B[i-1]
    if i-prev==1:
        ans += C[prev-1]
    prev = 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() ]

SUM = sum(B)

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

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

Solution (Python):
N = int(input())
a = [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_menu = -1
for i in range(len(a)):
    res += b[a[i] - 1]
    if 0 < i and 1 < a[i] and a[i] - a[i-1] == 1:
        bonus = c[a[i-1] - 1]
        res += bonus
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=sum(B)

for j in range(N):
  if j+1!=N:
    if A[j]+1==A[j+1]:
      total+=C[A[j]-1]
      
print(total)

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

ans=0
for i in range(len(A)):
    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())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))

score = 0
i1 = 0
i2 = -100
for i in range(n):
  i1 = aaa[i]
  if i1 == i2 + 1:
    score += ccc[i2 - 1]
  score += bbb[i1 - 1]
  i2 = aaa[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()))

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

Solution (Python):
N = int(input())
Junban_L = list(map(int, input().split()))
point_L = list(map(int, input().split()))
katen_point_L = list(map(int, input().split()))

ans=0
prenum = None
for num in Junban_L:
    ans = ans + point_L[num-1]
    if prenum == num-1:
        ans = ans + katen_point_L[prenum-1]
    prenum = num

print(ans)

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

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


sum = 0
previous = -10
for a in A:
    sum += B[a - 1]

    if a == previous + 1:
        sum += C[a - 2]
    previous = a
print(sum)

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()))
 
b_sum = sum(list_b)
 
satis = 0
for i in range(n-1):
  if list_a[i+1] == list_a[i] + 1:
    satis += list_c[list_a[i]-1]
 
result = b_sum + satis

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()))
s = 0
for i in range(len(a)):
  s += b[a[i]-1]
  if i == (len(a)-1): break
  elif (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()))

m=0

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

Solution (Python):


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

satis_level = sum(B)

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

print(satis_level)

Solution (Python):
N = int(input())
eatingOrder = list(map(int, input().split()))
points = list(map(int, input().split()))
bonusPoints = list(map(int, input().split()))

sutisfactionPoint = 0
beforeFood = -1
for food in eatingOrder:
    sutisfactionPoint += points[food-1]

    if beforeFood+1 == food:
        sutisfactionPoint += bonusPoints[beforeFood-1]
    
    beforeFood = food
print(sutisfactionPoint)

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
for idx, a in enumerate(A):
    score += B[a-1]
    if idx >= 1 and a == A[idx-1] + 1:
        score += C[A[idx-1]-1]

print(score)

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

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

a_new = list(map(lambda x: x - 1, a))
s = 0

for i in range(0, n):
    s += b[a_new[i]]
    if i != 0 and a_new[i] == a_new[i-1] + 1:
        s += c[a_new[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=sum(B)
prev=A[0]
for i in range(1,n):
    if A[i]==prev+1:
        ans+=C[prev-1]
    prev=A[i]
print(ans)

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

Solution (Python):
food_number = int(input())
food_history = list(map(int, input().split()))
point_b = list(map(int, input().split()))
point_c = list(map(int, input().split()))
total_point = 0
for x in range(food_number):
  total_point += point_b[food_history[x] - 1]
  if(x >= 1 and food_history[x] - 1 == food_history[x - 1]):
    total_point += point_c[food_history[x - 1] - 1]
print("{}".format(total_point))

Solution (Python):
N = int(input())
A_LIST = input().split(" ")
B_LIST = input().split(" ")
C_LIST = input().split(" ")

n = 0
start = 1 
S = 0
for i in A_LIST:
    i = int(i)
    if start == 1:
        start = 0
    else:
        if i == n + 1:
            S += int(C_LIST[i - 2])
        else:
            n = i
    
    S += int(B_LIST[i - 1])
    n = i
    
print(S)

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

list_A = input().split()
list_B = input().split()
list_C = input().split()



mysum = 0
mypast = int(list_A[0])
for i in list_A:
    mysum += int(list_B[int(i)-1])
    if int(i)-mypast == 1:
        mysum += int(list_C[mypast-1])
        

    mypast = int(i)
    
    
    


print(mysum)

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

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

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

before = -100
result = sum(b)

for i in a:
  if(i == before+1):
    result += c[before-1]
  before = i
  
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()))
ma = 0
a.append(0)

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

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

ans = sum(Bs)

for i in range(len(As) - 1):
    if As[i] + 1 == As[i+1]:
        ans += Cs[As[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()))
satisfy=0
b_i=0
for i in A:
    if i-b_i==1 and b_i!=0:
        satisfy=satisfy+B[i-1]+C[i-2]
    else:
        satisfy+=B[i-1]
    b_i=i
print(satisfy)

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

Solution (Python):
from itertools import accumulate
import sys

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


if __name__ == '__main__':
    main()

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

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

satisfaction = 0
prev = a[0]

for i in a:
  satisfaction +=  b[i-1]

  if i-prev == 1:
    satisfaction += c[i-2]
  prev = i


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

sum_b = sum(B)
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()))
a.append(0)
ans = 0

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

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

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

Solution (Python):
import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())
def main():
  n = ni()
  a = list(na())
  b = list(na())
  c = list(na())

  ans = 0
  pre = 0
  for i, aa in enumerate(a):
    aa -= 1
    if i >= 1 and i <= n-1 and pre+1 == aa:
      ans += c[aa-1]
    ans += b[aa]
    pre = aa
  print(ans)
main()

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

x = 0
iii=-2

i=0

for i in range(n):

    ii = int(a[i])
    x += int(b[ii-1])

    if ii == iii+1 :
        x += int(c[iii-1])
        
    iii = ii
    
print(x)

Solution (Python):
n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
c = tuple(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 = [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
before = 0
for a in A:
    m += B[a-1]
    if before != 0:
        if before+1 == a:
            m += C[before-1]
    before = a
    
    

print(m)

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

Solution (Python):
N = int(input())
AList = [int(i) for i in input().split()]
BList = [int(i) for i in input().split()]
CList = [int(i) for i in input().split()]
Kasan = 0
for k in range(N-1):
    if AList[k]+1 == AList[k+1]:
        Kasan += CList[AList[k]-1]
print(sum(BList) + Kasan)

Solution (Python):

import sys


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

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

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