eolymp
bolt
Try our new interface for solving problems
Problems

Count the operations

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 (1n105) - the number of nodes in the tree.

The following n - 1 lines contain one integer each pi - the number of the vertex that is the ancestor of i (0pi < n, 1i < 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 (|ai| ≤ 105).

Output

Print a single number, the minimum number of bananas needed to start the plane.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3
0
0
2 1 3
Output example #1
6
Source 2020 Cycle of Internet Olympiads for schoolchildren, Fifth team contest, Novemver 28, Problem E