Anton the Guard
Anton is a security guard responsible for objects numbered from to . There are also roads, where the -th road connects objects and and has a length of . It is possible to reach any object from object .
At the beginning, Anton is located at object .
Let's define the priority of each object as the minimum number of roads that need to be traveled from this object to object . For example, for object this number will be ; for all objects directly connected to , it will be , and so on.
Anton needs to visit all objects. He needs to first visit all objects that have a priority of , then those that have a priority of , and so on. If there are several objects with the same priority, Anton can choose the order in which to visit them. Note that he can only visit any object with priority after he has visited all objects with priority .
Find the minimum distance that he will have to travel.
Input
The first line contains an integer ().
The second line contains integers which indicate that there is a road from object to object ().
The third line contains integers which are the lengths of roads between objects and ().
It is guaranteed that it is possible to reach all other objects from object .
Output
Output a single integer — the answer to the problem.
Examples
Scoring
( points): ;
( points): ;
( points): no more than objects have the same priority;
( points): no more than objects have the same priority;
( points): ;
( points): ;
( points): without additional restrictions.