Valerio is drawing his (rooted) Christmas tree to celebrate his favorite holiday. Being a computer scientist, his tree has nodes, numbered from to , with node being the root. Each other node is connected to its parent by an edge of length .

Task
Valerio now wants to color some of the edges to make his drawing look more similar to the original subject. He also wants to avoid making the drawing too chaotic, therefore each node can have at most incident colored edges. What is the maximum total length of colored edges he can achieve?
Input data
The input file consists of:
- a line containing integer .
- a line containing the integers .
- a line containing the integers .
- a line containing the 64-bit integers .
Output data
The output file must contain a single line consisting of 64-bit integer .
Constraints and clarifications
- .
- for each .
- for each .
- for each .
| # | Score | Constraints |
|---|---|---|
| 1 | 0 | Examples |
| 2 | 12 | , for each |
| 3 | 24 | for each |
| 4 | 33 | |
| 5 | 31 | No additional restrictions |
Example 1
stdin
5
1 1 1 1 1
0 0 1 1
4 2 3 5
stdout
7
Explanation
The tree in the first sample case is depicted below.

The optimal solution consists in coloring the edge between nodes and and the one between nodes and , as shown below, with a total length of .
Example 2
stdin
7
1 2 2 1 1 1 1
0 0 1 1 2 2
8 7 6 6 3 4
stdout
23
Explanation

In the second sample case, the optimal solution consists in coloring the edges , , and , for a total length of .