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

Solution (Python):


n = int(input())
eat = list(map(int, input().split()))
data = list(map(int, input().split()))
plus = list(map(int, input().split()))


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

base = sum(B)
bonus = 0
for i, num in enumerate(A):
  if i + 1 >= len(A):
    break
  if A[i+1] == num + 1:
    bonus += C[num - 1]

print(base + bonus)

Solution (Python):


n = int(input())
ryorijun=[int(i) for i in input().split(' ')]
manzoku1=[int(j) for j in input().split(' ')]
manzoku2=[int(k) for k in input().split(' ')]

goukei=0
preorder = 0
for i in ryorijun:
    goukei += manzoku1[i-1]
    if preorder > 0 and (i-1) == preorder:
        goukei += manzoku2[i-2]
    preorder = i
print(goukei)

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

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

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

Solution (Python):
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(input())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

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

m = 0

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

  if num != n and i != n - 1:
    if num + 1 == int(a[i + 1]):
      m += c[num - 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()))

m = 0

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

  if num != n and i != n - 1:
    if num + 1 == int(a[i + 1]):
      m += c[num - 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()))
satisfy = 0
for i in range(len(a)):
    satisfy += b[a[i]-1]
    if i==0:
        continue
    if a[i]-a[i-1] == 1:
        satisfy += c[a[i-1]-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 = 0
for q in range(n):
    s += b[a[q] - 1]
    if q != 0:
        if a[q - 1] == a[q] - 1:
            s += c[a[q - 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()))
manzoku = 0

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

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

ans = sum(B)

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

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

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

Solution (Python):
n = int(input())
a_s = list(map(lambda x: int(x)-1, input().split()))
b_s = list(map(int, input().split()))
c_s = list(map(int, input().split()))

s = 0
prev = -2
for i in range(n):
  s += b_s[a_s[i]]
  if a_s[i] - prev == 1 and prev < n-1:
    s += c_s[prev]
  prev = a_s[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()]

score = 0

for n in range(N):
    b_index = A[n]-1
    score = score + B[b_index]

    if n -1 != -1:
        if A[n-1]+1 == A[n]:

            score += C[A[n]-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()))

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

manzoku=0;

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

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

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

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

    if i >= 1 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()))

score = 0
prev = -100
for i in A:
    score += B[i-1]
    if i == prev+1:
        score += C[prev-1]
    prev = i
print(score)

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

ans =sum(b)

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

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

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

ans = sum(b)

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

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

print(sum(b) + sumc)

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

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

print(sum(b) + tmp)

Solution (Python):
def solve(n, a, b, c):
    res = 0
    for i in range(n):
        if (i + 1 < n) and (a[i+1] == a[i] + 1):
            res += c[a[i]-1]
        res += b[a[i]-1]
    return res

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

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

ordered_menus = [int(i) for i in input().split()]
menu_values = [int(i) for i in input().split()]
additional_happiness = [int(i) for i in input().split()]

res = 0

res += sum(menu_values)

for i in range(n-1):
    if ordered_menus[i+1] - ordered_menus[i] == 1:
        res += additional_happiness[ordered_menus[i] - 1]

print(res)

Solution (Python):


N = int(input())
line1 = input().split(" ")
line2 = input().split(" ")
line3 = input().split(" ")

line22 = {}
for i in range(N):
    line22[i + 1] = int(line2[i])

total = 0
memory = - 1
for number in line1:
    num = int(number)
    total += line22[num]
    if num == memory + 1:
        total += int(line3[memory - 1])
    memory = num

print(total)

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 = list_B[list_A[0]-1]

for i in range(1,N,1):
    
    ans += list_B[list_A[i]-1]
    
    if list_A[i-1]+1 == list_A[i]:
        ans += list_C[list_A[i]-2]
        
print(ans)

Solution (Python):



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

    ans = sum(b)

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

print(ans)

Solution (Python):

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

sat_sum = 0

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

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
before = -1
manzoku = sum(B)

for cnt in range(len(A)):
  if A[cnt] - before == 1:
    manzoku += C[before-1]
  before = A[cnt]

print(manzoku)

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

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

point = 0

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

print point

Solution (Python):
N=int(input())
l_A=[int(e) for e in input().split(' ')]
l_B=[int(e) for e in input().split(' ')]
l_C=[int(e) for e in input().split(' ')]

result=sum(l_B)
for i,A in enumerate(l_A):
    if i == 0:
        A_pre=A
        continue
    if A == A_pre+1:
        result += l_C[A_pre-1]
    A_pre=A
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 = 0
for i in range(n):
  ai = a[i] -1
  pre_ai = -10
  if i != 0:
    pre_ai = a[i-1] -1
    
  ans += b[ai]
  if ai - pre_ai == 1:
    ans += c[pre_ai]
    
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())) 

full = 0
pre = 0
for i in range(N):
    a = A[i]
    b = B[a-1]
    if pre+1 == a and pre != 0:
        c = C[pre-1]
    else:
        c = 0

    full += b + c
    pre = a

print(full)

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ret = 0
    for i in range(N):
        ret += B[A[i] - 1]
        if i > 0 and A[i] == A[i - 1] + 1:
            ret += C[A[i] - 2]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    B = [ int(next(tokens)) for _ in range(N) ]  
    C = [ int(next(tokens)) for _ in range(N-1) ]  
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
an = [int(i) for i in input().split()]
bn = [int(i) for i in input().split()]
cn = [int(i) for i in input().split()]
ans = sum(bn)
for i in range(1,n):
  if an[i] == an[i-1] + 1:
    ans += cn[an[i-1]-1]
print(ans)

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

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

ans = 0

now = -2
for i in range(len(A)):
    ans += B[A[i]-1]
    if now+1 == A[i]-1:
        ans += C[A[i]-2]
    now = A[i]-1

print(ans)

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

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

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

for i in range(n):
    ans += b_list[i]

print(ans)

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

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

print(ans)

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

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

print(sum)

Solution (Python):
n=int(input())
s=0
a=[int(x) for x in input().split(' ')]
b=[int(y) for y in input().split(' ')]
c=[int(z) for z in input().split(' ')]
s+=b[a[0]-1]
for i in range(1,n):
    s+=b[a[i]-1]
    if a[i]==a[i-1]+1:
        s+=c[a[i-1]-1]
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  = 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 = input()
list1 = list(map(int,a.split()))
b = input()
list2 = list(map(int,b.split()))
c = input()
list3 = list(map(int,c.split()))
point = 0
for i in range(n):
    point += list2[list1[i]-1]
    if i < n-1:
        if list1[i] == list1[i+1] -1:
            point += list3[list1[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()))
ans = 0
for i in range(N):
  ans += B[A[i]-1]
  if i != N-1 and A[i]+1 == A[i+1]:
    ans += C[A[i]-1]
print(ans)

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

line = -20
satisfy = 0
for i in A:
    satisfy += B[i - 1]
    if line + 1 == i:
        satisfy += C[i - 2]
    line = i

print(satisfy)

Solution (Python):
N = int(input())
A, B, C = [int(i) for i in input().split()], [int(i) for i in input().split()], [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(raw_input())

x = lambda: map(int, raw_input().strip().split())

A = x()
B = x()
C = x()

points = 0
for i in xrange(n):
  points += B[A[i]-1]
  if i > 0 and A[i] == A[i-1] + 1:
    points += C[A[i]-2]

print points

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 (0,N-1):
  if A[i] + 1 == A[i+1]:
    s = s + C[A[i]-1]

print(s)

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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

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

    before = A[i]

print(m)

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

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

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

Solution (Python):
n = int(input())
ind = list(map(int, input().split()))
val = list(map(int, input().split()))
val1 = list(map(int, input().split()))
res = sum(val)
if ind[1] == ind[0] + 1:
    res += val1[ind[0]-1]
for i in range(1, len(ind)-1):
    if ind[i+1] == ind[i] + 1:
        res += val1[ind[i]-1]
print(res)

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

count_num=0
for i in l[0]:
    count_num += l[1][i-1]
for j in range(n-1):
    if (l[0][j])+1 == l[0][j+1]:
        count_num += l[2][(l[0][j])-1]
    
print(count_num)

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

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

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

bcount =0
ccount=0

for x in alist:    
    bcount+=blist[x-1]


for x in range (len(alist)-1):
    if alist[x+1]-alist[x]==1:
        temp = alist[x]-1
        ccount+=clist[temp]
        
print (bcount+ccount)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A_array = list(map(int, input().split()))
B_array = list(map(int, input().split()))
C_array = list(map(int, input().split()))
D_array = []
tmp = A_array[0]
for i in range(1,len(A_array)):
    if tmp + 1 == A_array[i]:
        D_array.append(C_array[tmp-1])
    tmp = A_array[i]

print(sum(B_array)+sum(D_array))

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

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

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

A = [a-1 for a in A]
cnt = 0
tmp = -1000000
for a in A:
    cnt += B[a]
    if a-tmp==1:
        cnt+=C[a-1]
    tmp=a
print(cnt)

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

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

sob = [int(x) for x in input().split()]
pts = [int(p) for p in input().split()]
exex = [int(h) for h in input().split()]

maxi = 0
ex = 0
maxi = sum(pts)
for i in range(n):
	if i != 0:
		if sob[i] - sob[i-1] == 1:
			maxi += exex[sob[i-1]-1]
print(maxi)

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

A_str_list = input().split(' ')
A = [int(x) for x in A_str_list]
B_str_list = input().split(' ')
B = [int(x) for x in B_str_list]
C_str_list = input().split(' ')
C = [int(x) for x in C_str_list]

satis = 0
prev_eat = -2
for ii in range(N):
    satis += B[A[ii]-1]
    if prev_eat + 1 == A[ii]-1 and 0 < ii:
        satis += C[prev_eat]
        
    prev_eat = A[ii]-1
print(satis)

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

bonus = 0

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



from functools import reduce

print(reduce(lambda x,y: x+y,B) + bonus)

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

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

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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    ans = sum(B)
    before = -inf
    for a in A:
        if before + 1 == a:
            ans += C[before-1]
        before = a
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()

anums = getList()
bnums = getList()
cnums = getList()

anums = [-100] + anums

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

Solution (Python):

n = int(input())
A = list(map(int,(input().split())))
B = list(map(int,(input().split())))
C = list(map(int,(input().split())))
S = 0
before = 100

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

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

satisfaction = 0

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

ans = sum(b)

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

print(ans)

Solution (Python):
def solve(string):
    n, *abc = map(int, string.split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    ans = [b[a0 - 1] + c[a0 - 1] if a0 + 1 == a1 else b[a0 - 1] for a0, a1 in zip(a, a[1:])]
    return str(sum(ans) + b[a[-1] - 1])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))

Solution (Python):
N = int(input())
cook_list = list(map(int,input().split()))
satisfy_list = list(map(int,input().split()))
plus_satisfy_list = list(map(int,input().split()))

sum_point = 0
prev_num = 0

for now_num in cook_list:
  sum_point += satisfy_list[now_num - 1]
  if (now_num - prev_num) == 1 and (now_num > 1):
    sum_point += plus_satisfy_list[prev_num - 1]
  prev_num = now_num
  
print(sum_point)

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

Solution (Python):
















import sys
input = sys.stdin.readline

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
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]-2]
print(ans)

Solution (Python):
N = int(input())
A_arr = list(map(lambda n: int(n), input().split()))
B_arr = list(map(lambda n: int(n), input().split()))
C_arr = list(map(lambda n: int(n), input().split()))
sum = 0

for i, a in enumerate(A_arr):
    if (i != 0) and (A_arr[i-1]+1 == a):
        sum += B_arr[a-1] + C_arr[A_arr[i-1]-1]
    else:
        sum += B_arr[a-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):
  ans+=B[A[i]-1]
  if (1<=i) and A[i-1]==A[i]-1:
    ans+=C[A[i]-2]
    
print(ans)

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

for _ in range(N-1):
    if A[_]+1==A[_+1]:
        _ans+=C[A[_]-1]
print(sum(B)+_ans)

Solution (Python):
N = int(input())
Ai = [int(i) for i in input().split(" ")]
Bi = [int(i) for i in input().split(" ")]
Ci = [int(i) for i in input().split(" ")]

res = 0
pre_i = None
for i in Ai:
  res += Bi[i-1]
  if pre_i and i == pre_i+1:
    res += Ci[i-2]
  pre_i = i

print(res)

Solution (Python):
n = 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(1, len(a)):
    
    if (a[i] - a[i-1]) == 1:
        
        r += b[a[i-1]-1]
        
        r += c[a[i-1]-1]
    else:
        r += b[a[i-1]-1]
       
    if i == (len(a)-1):
        r += b[a[i]-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()))

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

print(ans)