You are given a tree with vertices labeled from to rooted at . The root is not considered a leaf even if it has just one descendant. Each vertex has an associated cost and a state, the state may be active or inactive. Initially all nodes are considered active.
In one operation you may pick a leaf and switch the state from active to inactive or inactive to active for all vertices along the path from the leaf to the root. Print the maximum achievable sum of active vertices if you are allowed to make this operation as many times as you wish on any leaf.
Input
The first line will contain the integer (). The following lines will contain two values and , and each pair ( and ) represents an edge in the tree. The last line will contain integers representing the cost of each vertex starting with ().
Output
Only one integer will be printed, the maximum achievable sum.
Notes
For tests worth 10 points, .
For tests worth 10 extra points, .
Example
stdin
5
1 2
1 3
2 4
2 5
1 2 4 -4 -5
stdout
7
Explanation
In the sample we may pick vertex to apply the operation first, so the vertices on the path will be flipped from activated to deactivated.
We must also pick vertex to flip , so in the end and will keep being activated but and are deactivated. Lastly only vertices , and are active so their sum is .