50107. Height and Weight

I'm a slow walker, but I never walk backwards.

Write a program to sort students according to their BMI.

Task Description

You are given $N$ students’ names, heights and weights and you need to sort them. We will sort them according to the BMI first, which is defined as the weight (in kilogram) divided by the square of the height (in meter). If two students have the same BMI, then we compare the weight, if they are still the same then we compare the height. If they are still the same we compare the names (in dictionary order). It is guaranteed that no two students have the same name. Note that you need to use floating-point to compute BMI.

Subtask

  • 10 points: There are only 2 students.
  • 30 points: There are only 5000 students.
  • 60 points: The number of students is so large that you have to use qsort().

Input Format

There is one number $N$ in the first line indicating the number of students. The next $N$ lines are students’ names, heights(centimeter) and weights(kilogram). Each line contains one string and two integers. The string is student’s name. The first number is student’s height. The second number is student’s weight.

  • $0 \lt N \lt 100001$
  • $\text{length of name} \lt 64$

Output Format

Print sorted data in different line. The output format for each student is name height weight.

Sample Input 1

1
2
3
2
Tom 160 80
John 175 70

Sample Output 1

1
2
John 175 70
Tom 160 80

Sample Input 2

1
2
3
4
5
6
5
Tom 160 80
John 175 70
Tony 200 125
Andy 160 80
Morris 175 65

Sample Output 2

1
2
3
4
5
Morris 175 65
John 175 70
Andy 160 80
Tom 160 80
Tony 200 125

Discussion