For each of the new areas, the royal cartographer has provided a simple map with the
towns and major roads: Any two towns are connected by exactly one route (a
sequence of roads from one town to another). To each road, the royal treasurer has
assigned a number that indicates the profit he expects from collecting
fees at that road. This number may be negative, which means that the cost of
installing deputies is higher than the income.
Your task is to determine a selection of roads that maximizes the total profit (the sum of the earnings of all selected roads). It is not required that every town is at the end of a selected road, but the selection has to be connected: It must be possible to go from any selected road to any other selected road by using only selected roads (this makes transporting the collected fees safer).
Input
The input consists of a sequence of simple maps.
Each map starts with a line containing the number of roads
, where
.
Each of the following
lines holds a road description that consists of three integer
numbers
,
and
, where
and
.
They indicate the towns
and
at the ends of the road and the profit
of selecting this road.
Towns are identified by unique numbers and roads may be passed in both directions.
The sequence of maps is followed by a line containing a 0
.
Output
For each map, output a line containing the maximum profit achievable by
choosing a selection of roads as described above.
Sample Input
Sample Output