Your town has N junctions numbered 1 to N. These junctions are connected by exactly N−1 bidirectional roads in such a way that there is a unique simple path between each pair of junctions.
M oil tankers are transported through the town. Each of these tankers had oil leaking from them. It is known that the amount of oil that is leaking increases by one per road as the tanker moves ahead on its path. In other words, if K liters of oil spills on the road between the ith and (i+1)th junction on its path, then up to K+1 litres of oil can spill on the road between the (i+1)th and (i+2)th junction on its path.
For each j such that 1≤j≤M, you know Sj, Dj, and Lj that denote the source, destination, and the amount of oil in the jth tanker. Also, you know that exactly one liter of oil is spilled on the first road on the path of each of the tankers.
It is obvious that the amount of oil spilled from an oil tanker can't exceed the amount of oil it was carrying.
You are currently at junction 1. You select a junction X and travel from junction 1 to junction X. Now, you collect all the spilled oil on the roads that you travel along the way. If you choose X optimally, then what is the maximum amount of oil that you can collect?
Input format
Output format
In the only line of the output, print a single integer denoting the answer to the problem.
The first tanker will follow the path 4→2→1→3 and spill 1, 2 and 3 litres of oil on the roads in the path.
The second tanker will follow the path 5→2→1→3→6 and spill 1, 2, 3 and 3 litres of oil on the roads in the path (because the tanker has only 9 litres of oil).
The optimal X for this example is 6. You can travel from 1→6 and collect 9 litres of oil.