Governing sand
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 64 M,其他语言128 M
64bit IO Format: %lld

题目描述

The Wow village is often hit by wind and sand,the sandstorm seriously hindered the economic development of the Wow village.
There is a forest in front of the Wowo village, this forest can prevent the invasion of wind and sand. But there is a rule that the number of tallest trees in the forest should be more than half of all trees, so that it can prevent the invasion of wind and sand. Cutting down a tree need to cost a certain amount of money. Different kinds of trees cost different amounts of money. Wow village is also poor.
There are n kinds of trees. The number of i-th kind of trees is P_i, the height of i-th kind of trees is H_i, the cost of cutting down one i-th kind of trees is C_i.

(Note: "cutting down a tree" means removing the tree from the forest, you can not cut the tree into another height.)

输入描述:

The problem is multiple inputs (no more than 30 groups).
For each test case.
The first line contines one positive integers ,the kinds of trees.
Then followed n lines with each line three integers -the height of each tree, -the cost of cutting down each tree, and -the number of the tree.

输出描述:

For each test case, you should output the minimum cost.
示例1

输入

复制
2
5 1 1
1 10 1
2
5 1 2
3 2 3

输出

复制
1
2