AtCoder Beginner Contest 140 - Buffet

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-----
3
3 1 2
2 5 4
3 6

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


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


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


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


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


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


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


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


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


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


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):
	if i == 0:
		ans = b[a[0] - 1]
		y = a[0]
	else:
		x = a[i]
		if x - y == 1:
			ans = ans + b[x - 1] + c[y - 1]
		else:
			ans = ans + b[x - 1]
		y = x
print(ans)


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] - 2]
print(ans)


input()
(A, B, C) = [list(map(int, input().split())) for i in range(3)]
print(sum(B) + sum((C[A[i] - 1] for i in range(len(C)) if A[i] == A[i + 1] - 1)))


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


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
score = sum(B)
for (a, b) in zip(A, A[1:]):
	if b == a + 1:
		score += C[a - 1]
print(score)


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


kind = int(input())
table_1 = input().split(' ')
table_2 = input().split(' ')
table_3 = input().split(' ')
total = 0
for i in range(kind):
	total += int(table_2[i])
for j in range(kind - 1):
	if int(table_1[j]) == int(table_1[j + 1]) - 1:
		total += int(table_3[int(table_1[j]) - 1])
print(total)


N = int(input())
lsA = list(map(int, input().split()))
lsB = [0] + list(map(int, input().split()))
lsC = [0] + list(map(int, input().split()))
sumB = sum(lsB)
for i in range(N - 1):
	if lsA[i] + 1 == lsA[i + 1]:
		sumB += lsC[lsA[i]]
print(sumB)


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


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


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


H = int(input())
S = [list(map(int, input().split())) for i in range(3)]
ans = sum(S[1])
for i in range(H - 1):
	if S[0][i + 1] - S[0][i] == 1:
		ans += S[2][S[0][i] - 1]
print(ans)


n = int(input())
list_a = [int(i) for i in input().split()]
list_b = [int(j) for j in input().split()]
list_c = [int(k) for k in input().split()]
satisfied = 0
for i in range(0, len(list_a)):
	satisfied += list_b[list_a[i] - 1]
	if i > 0 and list_a[i] == list_a[i - 1] + 1:
		satisfied += list_c[list_a[i - 1] - 1]
print(satisfied)


n = int(input())
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
c_list = [int(i) for i in input().split()]
satisfaction = 0
for i in range(n):
	satisfaction += b_list[a_list[i] - 1]
	if i < n - 1:
		if a_list[i + 1] == a_list[i] + 1:
			satisfaction += c_list[a_list[i] - 1]
print(satisfaction)


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


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


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

def __starting_point():
	main()
__starting_point()


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
x = -1
for i in A:
	ans += B[i - 1]
	if x + 1 == i:
		ans += C[x - 1]
	x = i
print(ans)


(n, *a) = map(int, open(0).read().split())
print(sum(a[n:n + n]) + sum((a[i - n] for (i, j) in zip(a, a[1:n]) if j == i + 1)))


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
s = 0
pre = N
for a in A:
	s += B[a - 1]
	if pre == a - 2:
		s += C[pre]
	pre = a - 1
print(s)


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


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


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


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)


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


n = int(input())
ans = 0
a = [*map(int, input().split())]
b = {i + 1: j for (i, j) in enumerate(map(int, input().split()))}
c = {i + 1: j for (i, j) in enumerate(map(int, input().split()))}
ans += b[a[0]]
for i in range(1, n):
	if a[i] - a[i - 1] == 1:
		ans += c[a[i - 1]]
	ans += b[a[i]]
print(ans)


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


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)


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


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


n = int(input())
al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]
cl = [int(i) for i in input().split()]
cnt = sum(bl)
for i in range(n - 1):
	if al[i] + 1 == al[i + 1]:
		cnt += cl[al[i] - 1]
print(cnt)


N = int(input())
(a, b, c) = [list(map(int, input().split(' '))) for i in range(3)]
tot = sum(b)
for i in range(1, len(a)):
	if a[i] - a[i - 1] == 1:
		tot += c[a[i - 1] - 1]
print(tot)


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


def L():
	return list(map(int, input().split()))
N = int(input())
A = L()
B = L()
C = L()
O = 0
for i in range(N):
	ai = A[i] - 1
	O += B[ai]
	if i > 0 and A[i] == A[i - 1] + 1:
		O += C[ai - 1]
print(O)


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


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ct = 0
at = -100
for a in A:
	ct += B[a - 1]
	if a == at + 1:
		ct += C[a - 2]
	at = a
print(ct)


def mapt(fn, *args):
	return tuple(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

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


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


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


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


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


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


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


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


n = int(input())
a = input().split()
b = input().split()
c = input().split()
sum = 0
number = -2
for i in a:
	k = int(i) - 1
	sum += int(b[k])
	if number + 1 == k:
		sum += int(c[k - 1])
	number = k
print(sum)


n = int(input())
(a, b, c) = [list(map(int, input().split())) for _ in range(3)]
x = 0
for (i, _) in enumerate(a):
	if i == len(a) - 1:
		break
	elif a[i] + 1 == a[i + 1]:
		x += c[a[i] - 1]
print(sum(b) + x)


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


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


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 - 1):
	res += B[i]
	if A[i] + 1 == A[i + 1]:
		res += C[A[i] - 1]
print(res + B[-1])


n = int(input())
a = list(map(int, input().split()))
g = sum(map(int, input().split()))
c = list(map(int, input().split()))
for (i, j) in zip(a, a[1:]):
	if j - i == 1:
		g += c[i - 1]
print(g)


N = int(input())
l = [list(map(int, input().split())) for i in range(3)]
a = 0
for i in range(N - 1):
	a += l[1][l[0][i] - 1]
	if l[0][i + 1] == l[0][i] + 1:
		a += l[2][l[0][i] - 1]
a += l[1][l[0][N - 1] - 1]
print(a)


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


input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
m = 0
y = -1
for x in A:
	m += B[x - 1]
	if x == y + 1:
		m += C[y - 1]
	y = x
print(m)


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


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
j = 99
ans = 0
for i in a:
	ans += b[i - 1]
	if i == j + 1:
		ans += c[i - 2]
	j = i
print(ans)


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 x in range(len(a) - 1):
	if a[x + 1] - a[x] == 1:
		s += c[a[x] - 1]
print(s)


from typing import List

def answer(n: int, a: List[int], b: List[int], c: List[int]) -> int:
	satisfaction = sum(b)
	for i in range(1, n):
		previous = a[i - 1]
		if a[i] == previous + 1:
			satisfaction += c[previous - 1]
	return satisfaction

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

def __starting_point():
	main()
__starting_point()


n = int(input())
as_ = list(map(int, input().split()))
bs = list(map(int, input().split()))
cs = list(map(int, input().split()))
p = sum(bs) + sum([cs[a - 1] for (a, a_) in zip(as_, as_[1:]) if a + 1 == a_])
print(p)


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


N = int(input())
(A, B, C) = ([int(x) for x in input().split()] for _ in range(3))
A = [x - 1 for x in A]
print(sum(B) + sum((C[A[i]] for i in range(N - 1) if A[i] + 1 == A[i + 1])))


n = int(input())
T = list(map(int, input().split()))
S = list(map(int, input().split()))
C = list(map(int, input().split()))
SUM = sum(S)
for i in range(n - 1):
	if T[i + 1] == T[i] + 1:
		SUM += C[T[i] - 1]
print(SUM)


N = int(input())
Alst = list(map(int, input().split()))
Blst = list(map(int, input().split()))
Clst = list(map(int, input().split()))
ans = sum(Blst)
for i in range(N - 1):
	if Alst[i] + 1 == Alst[i + 1]:
		ans += Clst[Alst[i] - 1]
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
food = 0
manzoku = 0
bonus = 0
before = 10 * 3
ans = 0
for i in range(n):
	food = a[i]
	manzoku = b[food - 1]
	if food == before + 1:
		bonus = c[food - 2]
		ans += manzoku + bonus
	else:
		ans += manzoku
	before = food
print(ans)


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


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


n = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
lc = list(map(int, input().split()))
ans = sum(lb)
for i in range(n - 1):
	if la[i] + 1 == la[i + 1]:
		ans += lc[la[i] - 1]
print(ans)


N = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
ans = sum(l2)
for i in range(N - 1):
	if l1[i + 1] == l1[i] + 1:
		ans += l3[l1[i] - 1]
print(ans)


N = int(input())
d = [[int(s) for s in input().split()] for i in range(3)]
ans = 0
for i in range(N):
	ans += d[1][d[0][i] - 1]
	if i <= N - 2 and d[0][i + 1] - d[0][i] == 1:
		ans += d[2][d[0][i] - 1]
print(ans)


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


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = sum(B)
old = -2
for a in A:
	if a == old + 1:
		ans += C[old - 1]
	old = a
print(ans)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sumB = sum(B)
cnt = []
for i in range(n - 1):
	if A[i] + 1 == A[i + 1]:
		cnt.append(A[i] - 1)
sumC = 0
for i in cnt:
	sumC += C[i]
print(sumB + sumC)


n = int(input())
ans = 0
l = [list(map(int, input().split())) for i in range(3)]
for i in range(1, n + 1):
	ans += l[1][l[0][i - 1] - 1]
	if i != n and l[0][i] == l[0][i - 1] + 1:
		ans += l[2][l[0][i - 1] - 1]
print(ans)


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


n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
k = list(map(int, input().split()))
s = sum(d)
for i in range(n - 1):
	if l[i] + 1 == l[i + 1]:
		s += k[l[i] - 1]
print(s)


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):
	now = A[i]
	next = A[i + 1]
	ans += B[now - 1]
	if next == now + 1:
		ans += C[now - 1]
ans += B[A[N - 1] - 1]
print(ans)


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)


li = lambda : list(map(int, input().split()))
N = int(input())
A = li()
B = li()
C = li()
res = sum(B)
res += sum([C[A[i] - 1] for i in range(len(A) - 1) if not A[i + 1] - A[i] - 1])
print(res)


N = int(input())
liA = list(map(int, input().split()))
liB = list(map(int, input().split()))
liC = list(map(int, input().split()))
Manzoku = sum(liB)
for i in range(N):
	if i < N - 1:
		if liA[i + 1] - liA[i] == 1:
			Manzoku += liC[liA[i] - 1]
print(Manzoku)


R = lambda : list(map(int, input().split()))
input()
(a, b, c) = (R(), R(), R())
print(sum(b) + sum((c[i - 1] for (i, j) in zip(a, a[1:]) if j == i + 1)))


n = int(input())
(A, B, C) = [list(map(int, input().split())) for _ in 'ABC']
print(sum(B) + sum((C[A[i] - 1] for i in range(len(C)) if A[i + 1] - A[i] == 1)))


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


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


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


n = int(input())
L = [int(i) for i in input().split()]
c = sum((int(i) for i in input().split()))
C = [int(i) for i in input().split()]
for i in range(len(L) - 1):
	if L[i] + 1 == L[i + 1]:
		c += C[L[i] - 1]
print(c)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ct = 0
h = 25
for i in range(n):
	ct += B[i]
	if h + 1 == A[i]:
		ct += C[h - 1]
		h = A[i]
	else:
		h = A[i]
print(ct)


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(len(A_List)):
	ans += B_List[A_List[i] - 1]
	if (i != 0) & (A_List[i] - A_List[i - 1] == 1):
		ans += C_List[A_List[i - 1] - 1]
print(ans)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split())) + [0]
ans = 0
a_p = N + 1
for a in A:
	ans += B[a - 1] + C[a - 2] * (a - a_p == 1)
	a_p = a
print(ans)


n = int(input())

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


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


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


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):
	if A[i + 1] == A[i] + 1:
		S += B[A[i] - 1] + C[A[i] - 1]
	else:
		S += B[A[i] - 1]
S += B[A[N - 1] - 1]
print(S)


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


n = int(input())
abc = []
for i in range(3):
	abc += [[int(i) for i in input().split()]]
ps = sum(abc[1])
for i in range(n - 1):
	if abc[0][i] + 1 == abc[0][i + 1]:
		ps += abc[2][abc[0][i] - 1]
print(ps)


n = int(input())
(a, b, c) = [list(map(int, input().split())) for _ in range(3)]
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 - 1] - 1]
print(ret)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
(s, f) = (0, -1)
for x in a:
	s += b[x - 1]
	if x - f == 1:
		s += c[f - 1]
	f = x
print(s)


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)


n = int(input())
a = input().split()
b = input().split()
c = input().split()
ans = 0
for x in range(len(b)):
	ans += int(b[x])
	if x + 1 < len(b):
		if int(a[x]) + 1 == int(a[x + 1]):
			ans += int(c[int(a[x]) - 1])
print(ans)


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


N = int(input())
dishes = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
additional = list(map(int, input().split()))
res = 0
for i in range(N - 1):
	res += satisfaction[i]
	if dishes[i] + 1 == dishes[i + 1]:
		res += additional[dishes[i] - 1]
print(res + satisfaction[-1])


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


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


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


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


def linp():
	return list(map(int, input().split()))
n = int(input())
a = linp()
b = linp()
c = linp()
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)


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


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
p = -1
r = 0
for a in A:
	r = r + B[a - 1] if a != p + 1 else r + B[a - 1] + C[a - 2]
	p = a
print(r)


n = int(input())
(a, b, c) = [list(map(int, input().split())) for _ in range(3)]
ans = sum(b)
for (x, y) in zip(a[:-1], a[1:]):
	if x + 1 == y:
		ans += c[x - 1]
print(ans)


(n, *l) = map(int, open(0).read().split())
a = l[:n]
b = l[n:2 * n]
c = l[2 * n:]
bef = a[0]
ans = b[bef - 1]
for i in a[1:]:
	ans += b[i - 1]
	if i == bef + 1:
		ans += c[i - 2]
	bef = i
print(ans)


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


n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))
sat = sum(bn)
for x in range(n - 1):
	if an[x + 1] == an[x] + 1:
		sat += cn[an[x] - 1]
print(sat)


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


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

def main():
	score = 0
	for i in range(N):
		score += B[A[i] - 1]
		if A[i] == A[i - 1] + 1 and i >= 1:
			score += C[A[i - 1] - 1]
	return score
print(main())