Count the operations
The penguins found the plane in the jungle and were almost able to repair it. It remains only to fix the engine.
To do this, they need to understand the dashboard. It is a hanging tree rooted at the 0 vertex, with an integer written at each vertex. Since the penguins do not want to work themselves, they have hired monkeys and will pay them bananas. At each stage of the repair work, the penguins can choose any vertex, and then, for one banana, the monkey agrees to change the values in all vertices on the path from the tree root to the vertex chosen by the penguins: either add 1 to the values of all these vertices, or subtract from the values all these vertices 1.
The plane will start only when zeros are written in all vertices. The penguins want to start the engine for the minimum amount of bananas, so they need your help.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5
) - the number of nodes in the tree.
The following n - 1 lines contain one integer each p[i]
- the number of the vertex that is the ancestor of i (0 ≤ p[i]
< n, 1 ≤ i < n). It is guaranteed that you are given a hanging tree rooted at vertex 0.
The last line contains n numbers, initial values in the vertices (|a[i]
| ≤ 10^5
).
Output
Print a single number, the minimum number of bananas needed to start the plane.