cho.sh
Notes
Loading...

Bowl Stacking

Time limit

1s

Memory limit

128 MB

Problem

Each bowl is a frustum with height h, bottom radius r, and top radius R. Its top is open, its side is a straight line, and its thickness is ignored. Given N bowls, choose an order for stacking them on the same central axis so that the total height is as small as possible. Find the minimum possible height.

Input

The first line contains the number of bowls n. Each of the next n lines contains three integers h, r, and R describing one bowl. h is the height, r is the bottom radius, and R is the top radius.

Output

Print the minimum possible height on the first line. Output the integer obtained by discarding the fractional part of the actual minimum height.

Constraints

  • 2 ≤ n ≤ 9
  • 0 < h, r, R < 1000
  • r < R