Time Limit: 3000 MS    Memory Limit: 65536 K 


The president of the Ural State University is going to make an 80 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 1 to N; 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.


For each case the first line of the input contains a number N. ( 1 <= N <= 6000 ). Each of the subsequent N lines contains the conviviality rating of the corresponding employee. Conviviality rating is an integer number in a range from ĘC128 to 127. After that the supervisor relation tree goes. Each line of the tree specification has the form which means that the K-th employee is an immediate supervisor of L-th employee. Input is ended with the line 0 0


For each case the output should contain the maximal total rating of the guests.

Sample Input

7 1 1 1 1 1 1 1 1 3 2 3 6 4 7 4 4 5 3 5 0 0

Sample Output



Ural State University Internal Contest October'2000 Students Session