There are N cities in a country, numbered 1 through N. They are connected with N−1 undirected roads in such a way that one can move from one city to any other city through these roads. Each city contains a box filled with coins. The ith city contains a box with Ai coins, and it requires Bi consecutive seconds to open the box.
Alice is initially in city 1. While standing in city i(1≤i≤N), Alice can either:
Find the maximum number of coins Alice can collect in K seconds.
Alice can visit a city any number of times but can collect the coins only once from a city.
Input format
The third line contains N integers B1,B2,…,BN, denoting the number of seconds to open the boxes.
Output format
For each query, print the maximum number of coins Alice can collect in K seconds.
Constraints
1≤N,K≤3001≤Ai≤1051≤Bi≤3001≤Xi,Yi≤NXi≠Yi
During the first second, Alice moves to city 3. During the 2nd second, Alice collects 2 coins from city 3. During the third second, he moves to city 4 and collects 3 coins during the fourth and fifth second. So Alice collected total 2+3=5 coins.