100 atcoder#ABC140B. [ABC140B] Buffet

[ABC140B] Buffet

Score : 200200 points

Problem Statement

Takahashi went to an all-you-can-eat buffet with NN kinds of dishes and ate all of them (Dish 11, Dish 22, \ldots, Dish NN) once.

The ii-th dish (1iN)(1 \leq i \leq N) he ate was Dish AiA_i.

When he eats Dish ii (1iN)(1 \leq i \leq N), he gains BiB_i satisfaction points.

Additionally, when he eats Dish i+1i+1 just after eating Dish ii (1iN1)(1 \leq i \leq N - 1), he gains CiC_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

  • All values in input are integers.
  • 2N202 \leq N \leq 20
  • 1AiN1 \leq A_i \leq N
  • A1,A2,...,ANA_1, A_2, ..., A_N are all different.
  • 1Bi501 \leq B_i \leq 50
  • 1Ci501 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 ...... ANA_N

B1B_1 B2B_2 ...... BNB_N

C1C_1 C2C_2 ...... CN1C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

3
3 1 2
2 5 4
3 6
14

Takahashi gained 1414 satisfaction points in total, as follows:

  • First, he ate Dish 33 and gained 44 satisfaction points.
  • Next, he ate Dish 11 and gained 22 satisfaction points.
  • Lastly, he ate Dish 22 and gained 5+3=85 + 3 = 8 satisfaction points.
4
2 3 4 1
13 5 8 24
45 9 15
74
2
1 2
50 50
50
150