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):
k = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
s = 0
a = []
s += B[A[0]-1]
a.append(A[0])
for i in range(1,k):
    if((A[i]-1)==a[-1]):
        s += (B[A[i]-1]+C[A[i]-2])
        a.append(A[i])
    else:
        a.append(A[i])
        s += B[A[i]-1]
print(s)

Solution (Python):
num = 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(num):
	if i == 0:
		sum += b[a[i]-1]
	else:
		sum += b[a[i]-1]
		if (a[i]-1) == a[i-1]:
			sum += c[a[i-1]-1]
 
print(sum)

Solution (Python):
n = int(input())
list = [list(map(int,input().split())) for _ in range(3)]  
ans = 0
for i in range(n):
  if i == 0:
    ans += list[1][list[0][i]-1]
  else:
    ans += list[1][list[0][i]-1]
    if list[0][i] == list[0][i-1]+1:
      ans += list[2][list[0][i-1]-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()))





sum = 0
for i in range(N):

    sum += list_B[list_A[i]-1]

    if ((list_A[i] - list_A[i-1]) == 1) and (i != 0):
        sum += list_C[list_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()))

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

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

result = sum(b)

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

print(result)

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

Solution (Python):
N = int(input())
lineA = input().split()
lineB = input().split()
lineC = input().split()
A = [0] * N
B = [0] * N
C = [0] * (N-1)
for i in range(N):
    if i<N-1:
        A[i] = int(lineA[i])
        B[i] = int(lineB[i])
        C[i] = int(lineC[i])
    else:
        A[i] = int(lineA[i])
        B[i] = int(lineB[i])

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
add_s = 0
for idx in range(N-1):
  cur_f = A[idx]
  nxt_f = A[idx+1]
  add_s += C[cur_f-1] if nxt_f == cur_f + 1 else 0

print(sum(B) + add_s)

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

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

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

Solution (Python):
n = input()
s1= input()
s2= input()
s3= input()
ss1 = list(map(lambda x:int(x), s1.split()))
ss2 = list(map(lambda x:int(x), s2.split()))
ss3 = list(map(lambda x:int(x), s3.split()))

sum = 0
p = 21
for i in range(len(ss1)):
    sum += ss2[ss1[i]-1] + (ss3[p-1] if (p == (ss1[i]-1)) else 0)
    p = ss1[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()))
c1=b[a[0]-1]

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

Solution (Python):





def main():
    num = input()
    sseq = input().split()
    iseq = map(int, sseq)
    ssat = input().split()
    svns = input().split()
    
    ans =0
    for i, s in enumerate(iseq):
        ans = ans + int(ssat[s-1])
        if (i < (int(num)-1)):
            if(int(sseq[i+1]) - int(sseq[i]) ==1):
                ans = ans + int(svns[s-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()))

s = 0
j=0
for i in range(n):
  s+=b[a[i]-1]
  
  try:
    if (a[i+1]-a[i])==1:
      s+=c[a[i]-1]
      j+=1
        
  except:
    pass
print(s)

Solution (Python):
N = int(input())
order = list(map(int, input().split()))
total = sum(list(map(int, input().split())))  
point_added = list(map(int, input().split()))

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




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

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

Solution (Python):
N=int(input())
A_list=[int(thing) for thing in input().split(" ")]
B_list=[int(thing) for thing in input().split(" ")]
C_list=[int(thing) for thing in input().split(" ")]
ret=0
P_B=0
for d in range(len(A_list)):
    tottano=A_list[d]-1
    if d!=0 and tottano!=N:
        if tottano==sakki+1:
            ret=ret+C_list[sakki]
    ret=ret+B_list[tottano]
    sakki=tottano
print(ret)

Solution (Python):
_ = input()
orders = [int(i) for i in input().split(" ")]
score = [int(i) for i in input().split(" ")]
c_score = [int(i) for i in input().split(" ")]

result = 0
before_dish_no = 0
for n in orders:
  result += score[n-1] + c_score[n-2] if (n is not 1) and (before_dish_no+1 == n) else score[n-1]
  before_dish_no = n

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

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

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

Solution (Python):
n=int(input())
menu=list(map(int,input().split()))
man=list(map(int,input().split()))
ak=sum(man)
tuika=list(map(int,input().split()))
s=menu[0]
for i in menu[1:]:
  if i==s+1:
    ak+=tuika[s-1]
  s=i
print(ak)

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):
    now = a[i]
    if i > 0:
        if now == before + 1:
          score += (b[a[i]-1] + c[before-1])
          before = now
          continue
    score += b[now-1]
    before = now
print(score)

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

total = 0
i = -10
for a_i in a:
    if a_i == i + 1:
        total += c[i]
    total += b[a_i]
    i = a_i
print(total)

Solution (Python):
List=[list(map(int,input().split())) for i in range(4)]

a=sum(List[2])
b=int(len(List[1]))

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

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

s = b[a[0]-1]

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

last_value = -1
satisfied_points = 0

for i, v in enumerate(A):
  s = B[v - 1]
  satisfied_points += s
  if (last_value == (v - 1)):
    ss = C[last_value - 1]
    satisfied_points += ss
  last_value = v
  
print(satisfied_points)

Solution (Python):


def main():


   N = int(input())
   buffeList = list(map(int,input().split()))
   gainList =  list(map(int,input().split()))
   addionList =  list(map(int,input().split()))
   ans = 0
   
   for i in range(N):
      wEat = gainList[buffeList[i]-1]
      ans += wEat
      if buffeList[i]-buffeList[i-1] == 1 and i>=1 :
         ans += addionList[buffeList[i-1]-1]
   print(ans)








if __name__== "__main__":
    main()

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = na()
c = na()

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

print(ans)

Solution (Python):
N = int(input())
food = list(map(int,input().split()))
val = list(map(int,input().split()))
bonas = list(map(int,input().split()))

ans = 0

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

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


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

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

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

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

a = [x-1 for x in a]

ans = 0

prev = None
for i in a:
    ans += b[i]
    if prev is not None and prev == i - 1:
        ans += c[i - 1]
    prev = i
print(ans)

Solution (Python):
n = int(input())
a = []
b = []
c = []
work = 0
total = 0
i = 0
test = 100
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
while(i < n):
  work = a[i]
  total = total + b[work - 1]
  if(test == a[i] - 1):
    total = total + c[test - 1]
  test = a[i]
  i = i + 1
print(total)

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

ans = 0
precur = -1
for i in range(0, n):
    cur = al[i] - 1
    ans += bl[cur]
    if precur != -1 and precur + 1 == cur:
        ans += cl[precur]
    precur = cur
print(ans)

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


d=a[1][n-1]
for i in range(n-1):
	d=d+a[1][i]

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

ans = 0
prev = 0

for i in range(len(a)):
  ans += b[a[i] - 1]

  if (i != 0 and prev == a[i] - 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()))
SAT = 0

for cnt, i in enumerate(A):
    SAT += B[i - 1]

    if cnt > 0 and A[cnt] == A[cnt - 1] + 1:
        SAT += C[i - 2]

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

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,a in enumerate(A[:-1]):
    if A[i+1]-a==1:
        manzoku += C[a-1]
manzoku += sum(B)
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()))

i = 0
Num = 0
Ans = 0
while N > i:
  Num = A[i]-1
  Ans = Ans + B[Num]
  if i != 0 and Num != 0 and A[i] == A[i-1] + 1:
    Ans = Ans + C[Num-1]
  i += 1
print(Ans)

Solution (Python):
while True:
    try:
        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)
        
        res = B[A[1]]
        for i in range(2, len(A)):
            res += B[A[i]]
            if A[i-1]+1 == A[i]:
                res += C[A[i-1]]
        print(res)
    except:
        break

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 = input()
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
total = 0


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

print(total)

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

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

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

Solution (Python):
kind = int(input())
A = input().split()
B = input().split()
C = input().split()
stf = 0
temp = 0

for n in map(int, A):
    stf += int(B[n - 1])
    if n - temp == 1 and temp != 0:
        stf += int(C[n - 2])
    else:
        pass
    temp = n

print(stf)

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


content_plus = 0

for i in range(n):
    if i == 0:
        pass
    else:
        if data[0][i-1]+1 == data[0][i]:
            content_plus = content_plus + data[2][data[0][i-1]-1]


def sum(list):
    lsum = 0
    for i in range(len(list)):
        lsum = lsum+list[i]
    return lsum

print(sum(data[1])+content_plus)

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

result = 0
for a, i in zip(A, range(len(A))):
    result += B[a-1]
    if i > 0 and (a - A[i-1]) == 1:
        result += C[A[i-1]-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,x=0,n
for i in a:
	ans+=b[i-1]
	if x==i-1:
		ans+=c[x-1]
	x=i
print(ans)

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

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)

N = _I()
A = LI()
B = LI()
C = LI()
A = [i-1 for i in A]

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

A = input().split()
A = [int(n) for n in A]

B = input().split()
B = [int(n) for n in B]

C = input().split()
C = [int(n) for n in C]

sati = 0

A.append(-100)

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

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






print(sati)

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
prev = -10

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

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

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()))
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 = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
c = [int(x) for x in input().split(' ')]

cnt = 0
ss = -10

for i in a :
    i -= 1
    cnt += b[i]
    if (i - ss == 1) :
        cnt += c[ss]
        
    ss = i



print(cnt)

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

M = 0
pre_a = -1

for a in A:
  M += B[a - 1]
  
  if (a - pre_a) == 1:
    M += C[a - 2]
    
  pre_a = a

print(M)

Solution (Python):
_ = input().strip()
a = input().strip().split(" ")
b = input().strip().split(" ")
c = input().strip().split(" ")

m = 0
pre_a = -1
for _a in a:
    
    _a = int(_a)
    _a -= 1
    m += int(b[_a])
    
    if ((pre_a+1 == _a) & (_a > 0)):
        m += int(c[pre_a])
    pre_a = _a
    
print(m)

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

    satisfaction, pre_a = 0, -1
    for i in range(N):
        a = A[i] - 1
        satisfaction += B[a]
        if pre_a != -1 and pre_a + 1 == a:
            satisfaction += C[pre_a]

        pre_a = a

    print(satisfaction)


if __name__ == '__main__':
    b()

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

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

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

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

total=0
for i in range(N):
  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(lambda x: int(x)-1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

P=0
P+=B[A[0]-1]
for i in range(N-1):
    if A[i]!=N and A[i+1]==A[i]+1:
        u=B[A[i+1]-1]
        q=C[A[i+1]-2]
        o=u+q
        P+=o
    else:
        u=B[A[i+1]-1]
        P+=u
    
print(int(P))

Solution (Python):







man=0
N = int(input()) 
A = [input().split() for i in range(3)]


for i in range(N):
   man=man+int(A[1][i])
   


for i in range(N-1):
   
   if(int(A[0][i+1]) == int(A[0][i])+1):
      
      ryori_i=int(A[0][i])
      man_c=int(A[2][ryori_i-1])
      man=man+man_c
      

print(man)

Solution (Python):

"""
1~Nの料理がある
{Ai}は実際に食べた順番である。
{Bi}はiを食べたときに得られる満足度である。
{Ci}はiを食べた直後にi+1を食べたときに得られる追加の満足度である。
"""

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

manzoku=0

pre_dish = None
for ai in A:
    ai_index = ai-1
    manzoku += B[ai_index]
    if pre_dish == ai-1: 
        pre_dish_index=pre_dish-1
        manzoku += C[pre_dish_index]
        pre_dish = ai
    else:
        pre_dish = ai

print(manzoku)

Solution (Python):
n = int(input())
a_s = [int(v) for v in input().split()]
b_s = [int(v) for v in input().split()]
c_s = [int(v) for v in input().split()]

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

s = sum(B)

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

A.append(100)
C.append(0)

total = 0

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

print(total)

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


s = 0
before = -1

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

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

Solution (Python):
N = int(input())
eat_list = list(map(int,input().split()))
scores = list(map(int,input().split()))
c_list = list(map(int,input().split()))
"""
print(eat_list)
print(scores)
print(c_list)
"""

score = 0
for i_eat,eat in enumerate(eat_list):
    score += scores[eat-1]
    
    if i_eat == 0:
        continue
    elif eat - 1 == eat_list[i_eat-1]:
        score += c_list[eat-2]
        

print(score)

Solution (Python):
n = int(input())
a = [input().split() for l in range(3)]
mnpk = 0
fl = 0
for i in range(n):
  b = int(a[0][i]) - 1
  mnpk = mnpk + int(a[1][b])
  if fl == 1:
    if int(a[0][i-1]) == b:
      mnpk = mnpk + int(a[2][b-1])
  else:
    fl = 1

print(mnpk)

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

point = []
for i in range(len(A)):
    ryori = A[i]
    point.append(B[ryori - 1])
    if i >  0 :
        if ryori - A[i - 1] == 1:
            point.append(C[ryori - 2])
    

print(sum(point))

Solution (Python):
N = int(input())
order = list(map(int, input().split(' ')))
Bs = list(map(int, input().split(' ')))
Cs = list(map(int, input().split(' ')))
old = None
ans = 0
for i in order:
    index = i - 1
    if old != None and old + 1 == index:
        ans += Cs[old]
    ans += Bs[index]
    old = index
        
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()))

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

Solution (Python):
num = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
result = 0
 
for i in range(num):
  result += int(B[int(A[i])-1])
  if i > 0 and (int(A[i]) - int(A[i-1]) == 1):
    result += int(C[int(A[i])-2])
 
print(result)

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()))
sum = 0
before_target = 0
for i in range(n):
    target = a_list[i]
    if i != 0 and before_target+1 == target :
        sum += b_list[target - 1] + c_list[target - 2]
    else:
        sum += b_list[target - 1]
    before_target = target

print(sum)

Solution (Python):
N = [int(s) for s in raw_input().split(" ")][0]
A = [int(s) for s in raw_input().split(" ")]
B = [int(s) for s in raw_input().split(" ")]
C = [int(s) for s in raw_input().split(" ")]

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

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

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



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

  
print(sum(B)+k)

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

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

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)

diff = [a[i+1] - a[i] == 1 for i in range(n-1)]
diff.append(False)

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