Welcome to ZOJ
 Contests Information Problems Runs Statistics Ranklist Clarification
123 - ZOJ Monthly, January 2013 - I
Destroy

Time Limit: 2 Seconds      Memory Limit: 65536 KB

DJT country and CG country are always on wars.
This time DJT's King built a new information system over the whole country. He wants to know the message from the frontier immediately. There are numerous cities in DJT. In every city, there is one server of this system, and information is sending to the center continuously along a special data road. However, the data road is so expensive that there is one and only one road from one city to another city. Besides, the place of the center is a secret.

CG, of course, won't let DJT be happy for too long. CG is now planning to destroy DJT's new system. Due to some great undercover agents, CG has controlled some information about DJT's new system. The information CG has got:

1. The center of DJT's new system would settle down in a city that for all other cities, the maximum distance should be the least.(you can make sure that only one city has the possibility to be the center)
2. If no frontier city could send message back to the center, the system can be regard as destroyed. (a frontier city is a city that has only one road connecting to it)
3. The length of each road.
4. The power we need to destroy each road. (if we have a weapon of power max, we can destroy all the roads which it need the power less or equal to max)

Now, CG gives you a task: calculate the minimum power to destroy the system.

#### Input

There are multiple cases. For each case, one integer n (0 <= n <= 10000) indicating the number of cities in DJY country, cities are numbered from 1 to n, the next n-1 lines, one line contains four numbers describing one road, the two cities connected by the road, the length, and the power needed to destroy. The lengths are less than or equal to 10000. The powers are less than or equal to 100000000. All integers are nonnegative.

#### Output

For each case, output one number indicating the least power we need.

```9
1 4 1 3
2 3 1 7
2 5 1 2
4 5 1 5
5 6 1 4
5 8 1 4
6 9 1 4
7 8 1 6
```

#### Sample Output

```4
```

Author: HE, Ningxu
Submit    Status