Little E likes to create Maximum Weight Independent Set problems. Next, he has thought of $n$ Maximum Weight Independent Set problems. Little E has $n$ AIs, numbered $1 \sim n$. Initially, the $i$-th AI contains $d_i$ Maximum Weight Independent Set problems that Little E has prepared in advance. Some AIs can communicate with each other. For all $2 \le i \le n$, the $i$-th AI can communicate with the $c_i$-th AI. Here $c_i < i$, and the same $c_i$ appears at most 2 times. Therefore, these AIs form the shape of a binary tree. Furthermore, no other pairs of AIs can communicate with each other. Little E needs to temporarily disconnect the connections between these AIs. He can only disconnect the connections between AIs one by one. Before two AIs that were originally able to communicate have their connection disconnected, they will exchange all the problems stored within them; please see the example for details. Little E wants to minimize the total number of problems involved in exchanges after all connections are broken. He wants you to help him solve this problem, and he says that if you successfully solve this problem, he will help you submit a reference solution code when he creates those Maximum Weight Independent Set problems.
Input
The first line contains a positive integer $n$. The second line contains $n$ integers, where the $i$-th integer represents $d_i$. The third line contains $n - 1$ positive integers, where the $i$-th integer represents $c_{i+1}$.
Output
A single integer representing the answer.
Examples
Input 1
3 2 1 3 1 1
Output 1
7
Note
One optimal strategy is: disconnect the connection between AI 1 and AI 2, which requires exchanging $2 + 1 = 3$ problems; then disconnect the connection between AI 1 and AI 3, which requires exchanging $1 + 3 = 4$ problems. Therefore, the answer is 7.
Subtasks
It is guaranteed that $1 \le c_i < i$, and the same $c_i$ appears at most 2 times. It is guaranteed that $1 \le d_i \le 10^9$.
| Test Case ID | $n \le$ |
|---|---|
| $1 \sim 3$ | 10 |
| $4 \sim 7$ | 100 |
| $8 \sim 11$ | 500 |
| $12 \sim 16$ | 1000 |
| $17 \sim 25$ | 5000 |