Problem: Mitya has a rooted tree with vertices indexed from to , where the root has index . Each vertex initially had an integer number written on it. For every vertex Mitya has computed : the sum of all values written on the vertices on the path from vertex to the root, as well as — the depth of vertex , which denotes the number of vertices on the path from vertex to the root. Clearly, and .
Then Mitya erased all numbers , and by accident he also erased all values for vertices with even depth (vertices with even ). Your task is to restore the values for every vertex, or determine that Mitya made a mistake. In case there are multiple ways to restore the values, you're required to find one which minimizes the total sum of values for all vertices in the tree.
Input Format: The first line contains one integer — the number of vertices in the tree (). The following line contains integers , , ... , where stands for the parent of vertex with index in the tree (). The last line contains integer values , , ..., (), where erased values are replaced by .
Output Format: Output one integer — the minimum total sum of all values in the original tree, or if such tree does not exist.