The president of Central European University is going to make an th Anniversary party. The university has a hierarchical structure of employees; that is, the supervisor relation forms a tree rooted at the president. Employees are numbered by integer numbers in a range from to . The personnel office has ranked each employee with a conviviality rating. In order to make the party fun for all attendees, the president does not want both an employee and his or her immediate supervisor to attend.
Your task is to make up a guest list with the maximal conviviality rating of the guests.
The first line of the input contains a number (1 \le N \le 6000). Each of the subsequent lines contains the conviviality rating of the corresponding employee. Conviviality rating is an integer number in a range from to . After that the supervisor relation tree goes. Each line of the tree specification has the form
which means that the -th employee is an immediate supervisor of -th employee. Input is ended with the line (this line should not be processed):
The output should contain the maximal total rating of the guests.
Example 1