Problem:


理想の体型

肥満度を表す指数としてBMI（Body Mass Index）があります。BMIの値は以下の式で計算します。

BMI = 体重(kg) / (身長(m))2

BMIの値が標準値に近いほど「理想の体型」と考えられます。そこで、BMIの標準値を 22 とした場合、対象者の情報を入力とし、最も「理想の体型」に近い人の情報を出力するプログラムを作成してください。

対象者の数を n とすると、各対象者には重複のないように1 以上 n 以下の整数値の受付番号 p が振られています。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。各データセットは以下の形式で与えられます。

n
p1 h1 w1
p2 h2 w2
:
pn hn wn

１行目に対象者の人数 n (n ≤ 1000)、続く n 行に i 人目の対象者の受付番号 pi (1 ≤ pi ≤ n)、センチメートル単位の身長 hi (1 ≤ hi ≤ 200)、キログラム単位の体重 wi (1 ≤ wi ≤ 200) が与えられます。入力は全て整数で与えられます。

Output

データセットごとに「理想の体型」に最も近い人の受付番号（整数）を１行に出力します。最も「理想の体型」に近い人が二人以上いる場合は、受付番号の小さい方を出力することとします。

Sample Input

6
1 165 66
2 178 60
3 180 72
4 160 65
5 185 62
6 182 62
3
3 160 65
2 180 70
1 170 75
0

Output for the Sample Input

3
2



Sample input:
6
1 165 66
2 178 60
3 180 72
4 160 65
5 185 62
6 182 62
3
3 160 65
2 180 70
1 170 75
0


Sample output:
3
2

Submission status: Wrong Answer

Solution code:
while 1:
	n=input()
	if n==0:break
	mn,d=1,22
	for _ in range(n):
		i,h,w=map(int,raw_input().split())
		bmi=w/((h/100.0)**2)
		if abs(22-bmi)==d:
			mn=min(mn,i)
		elif abs(22-bmi)<d:
			d=abs(22-bmi)
			mn=i
	print mn

Submission status: Accepted

Solution code:
import math
while 1:
  n = input()
  if n==0: break
  x = []
  for _ in [0]*n:
    i,h,w = map(int, raw_input().split())
    x.append([i,abs(w/math.pow((h/100.0),2)-22)])
  x = sorted(x, key = lambda a: (a[1], a[0]))
  print x[0][0]

Submission status: Accepted

Solution code:
while 1:
  n = input()
  if n==0: break
  a = 1e9
  b = 1e9
  for _ in [0]*n:
    i,h,w = map(int, raw_input().split())
    tmp = abs(w/(h/100.0)**2-22)
    if a>=tmp: a,b = tmp,i
  print b

Submission status: Accepted

Solution code:
while 1:
  n = input()
  if n==0: break
  a = b = 1e9
  for _ in [0]*n:
    i,h,w = map(int, raw_input().split())
    tmp = abs(w/(h/100.0)**2-22)
    if a>=tmp: a,b = tmp,i
  print b

Submission status: Accepted

Solution code:
while True:
    n = input()
    if n == 0: break
    pb = None
    ans = 0
    for i in range(n):
        i, h, w = map(int, raw_input().split())
        bmi = w/((float(h)/100)**2)
        a = abs(22-bmi)
        if pb is None:
            pb = a
            ans = i
        elif pb is not None and a < pb:
            pb = a
            ans = i
    else:
        print ans

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    ans = minv = 1<<10
    for _ in range(n):
        p, h, w = map(int, input().split())
        BMI = w / ((h*0.01)**2)
        tmp = 22 - BMI if 22 > BMI else BMI - 22
        if tmp < minv:
            ans, minv = p, tmp
    print(ans)

Submission status: Accepted

Solution code:
while 1:
 n=input()
 if n<1:break
 print sorted([map(int,i().split())for i in[raw_input]*n],key=lambda(p,h,w):(abs(0.0022-w/h**2.),p))[0][0]

Submission status: Accepted

Solution code:
# Aizu Problem 00159: The Best Body
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n = int(input())
    if n == 0:
        break
    best = 999999999999999999
    near = float('Inf')
    for _ in range(n):
        no, h, w = [int(__) for __ in input().split()]
        h /= 100
        bmi = w / h**2
        diff = abs(bmi - 22)
        if abs(diff - near) < 1e-8:
            near = abs(bmi - 22)
            best = min(best, no)
        elif diff < near:
            near = diff
            best = no
    print(best)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0159

"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple
bmi = namedtuple('bmi', ['d', 'p'])

def calc_BMI(h, w):
    return w / ((h / 100)**2)


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break

        scores = []
        for _ in range(n):
            p, h, w = map(int, input().split())
            scores.append(bmi(abs(calc_BMI(h, w) - 22), p))

        scores.sort()
        print(scores[0].p)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
def BMI(height, weight):
    return weight / (height / 100) ** 2


STANDARD_VALUE = 22

while True:

    input_count = int(input())

    if input_count == 0:
        break

    input_data = [map(int, input().split(" ")) for _ in range(input_count)]
    data = [(number, BMI(height, weight)) for number, height, weight in input_data]
    data = [(number, abs(bmi - STANDARD_VALUE)) for number, bmi in data]
    data.sort(key=lambda item: (item[1], item[0]))
    print(data[0][0])

Submission status: Accepted

Solution code:
# AOJ 0159 The Best Body
# Python3 2018.6.18 bal4u

GOAL = 22.0
EPS = 1e-5

while True:
	n = int(input())
	if n == 0: break
	id, vmin = 0, 1000000000.0;
	for i in range(n):
		p, h, w = list(map(int, input().split()))
		bmi = w/(h/100)**2
		diff = abs(bmi-GOAL)
		if abs(diff-vmin) < EPS:	# diff == vmin
			if p < id: id = p
		elif diff < vmin:
			id, vmin = p, diff
	print(id)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break

  pairs = []
  for _ in range(n):
    p, h, w = map(int, input().split())
    bmi = w / (h / 100) ** 2
    pairs.append((p, bmi))
  pairs.sort()
  print(min(pairs, key=lambda x:abs(x[1] - 22))[0])

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    d={}
    for i in range(n):
        num,h,w=map(int,raw_input().split())
        d[num]=w/pow(h/100.0,2)
    diff=100
    best=0
    for i in d.values():
        if abs(i-22)<diff:
            diff=abs(i-22)
            best=i
    print sorted([i for i,j in d.items() if j==best])[0]

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    print int(min((map(float,raw_input().split()) for _ in xrange(n)),
              key = lambda (i,h,w):abs(22.0-w/(h/100)**2))[0])

Submission status: Accepted

Solution code:
def bmi(a):
	return int(a[0]), abs(22-int(a[2])/((int(a[1])/100.0)**2))
	
while 1:
	n=input()
	if n==0:break
	data=[bmi(raw_input().split()) for i in range(n)]
	print sorted(sorted(data),key=lambda x:x[1])[0][0]

Submission status: Accepted

Solution code:
def bmi(a):
	return a[0], abs(22-a[2]/((a[1]/100.0)**2))
	
while 1:
	n=input()
	if n==0:break
	d=[bmi(map(int,raw_input().split())) for i in range(n)]
	print sorted(sorted(d),key=lambda x:x[1])[0][0]

Submission status: Accepted

Solution code:
def bmi(a):
	a=map(int,a.split())
	return a[0], abs(22-a[2]/((a[1]/100.0)**2))
	
while 1:
	n=input()
	if n==0:break
	print sorted(sorted([bmi(raw_input()) for i in range(n)]),key=lambda x:x[1])[0][0]

Submission status: Accepted

Solution code:
def bmi(a):
	return a[0], abs(22-a[2]/((a[1]/100.0)**2))
	
while 1:
	n=input()
	if n==0:break
	print sorted(sorted([bmi(map(int,raw_input().split())) for i in range(n)]),key=lambda x:x[1])[0][0]

Submission status: Accepted

Solution code:
while True:
  N = input()
  if not N:
    break
  a, b = -1, 100000000
  for j in range(N):
    i, h, w = map(int, raw_input().split())
    h /= 100.00
    bmi = w / (h * h)
    if abs(bmi - 22) < b:
      b = abs(bmi - 22)
      a = i
  print(a)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


#最大公約数
def gcd(x,y):
    x = abs(x)
    y = abs(y)

    if x < y:
        x,y = y,x

    if y == 0:
        return x
    else:
        return gcd(y,x%y)


class Info:
    def __init__(self,arg_numerator,arg_denominator):
        self.numerator = arg_numerator
        self.denominator = arg_denominator

while True:
    N = int(input())
    if N == 0:
        break

    ans = -1
    info = Info(1000,1)

    for i in range(N):
        ID,height,weight = map(int,input().split())
        height *= height
        weight *= 10000
        common = gcd(height,weight)
        height //= common
        weight //= common
        numerator = abs(22*height-weight)
        denominator = height

        if numerator*info.denominator < info.numerator*denominator:
            ans = ID
            info.numerator = numerator
            info.denominator = denominator

    print("%d"%(ans))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    
    L =[]
    for _ in range(n):
        id, h, w = [int(x) for x in input().split()]
        bmi = abs(w * 10000 / h**2 -22.0)
        L.append([bmi,id])
    L.sort()
    print(L[0][1])

Submission status: Accepted

Solution code:
while True:
  def BMI(h,w):
    X=w/(h/100)**2
    return X
  n =int(input())
  if n==0:
    break
  tbl=[[0 for j in range(2)] for i in range(n)]
  for i in range(n):
    p,h,w=list(map(int, input().split()))
  #  print(BMI(h,w))
    id=abs(22-BMI(h,w))
    tbl[i][0]=p
    tbl[i][1]=id
  #print(tbl)
  id_min=10**9
  ans=0
  for i in range(n):
    if tbl[i][1]<id_min:
      ans=tbl[i][0]
      id_min=tbl[i][1]
  print(ans)

Submission status: Accepted

Solution code:
# from sys import exit
while(True):
    N = int(input())
    if N == 0:
        break
    L = []
    for i in range(N):
        p, h, w = [int(n) for n in input().split()]
        L.append((p, abs(22- w/((h/100)**2))))
        # print(abs(22- w/((h/100)**2)))
    L = sorted(L, key=lambda x: x[1])
    print(L[0][0])

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break

    best = 10**9
    for _ in range(n):
        p, h, w = map(int, input().split())

        bmi = w / (h / 100)**2
        diff = abs(bmi - 22)

        if diff < best:
            ans = p
            best = diff
        elif diff == best:
            if ans > p:
                ans = p

    print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    
    pairs = []
    for _ in range(n):
        p, h, w = map(int, input().split())
        bmi = w / (h / 100) ** 2
        pairs.append((p, bmi))
    pairs.sort()
    print(min(pairs, key=lambda x: abs(x[1]-22))[0])

Submission status: Accepted

Solution code:
while True:

    n = int(input())
    if n == 0:
        break

    ans = 0
    min_bmi = 100000.0
    for l in range(n):
        p,hh,ww = [int(i) for i in input().split()]
        h = float(hh)
        w = float(ww)
        h = h * 0.01

        bmi = abs(w / (h*h) - 22.0)

        if bmi < min_bmi:
            min_bmi = bmi
            ans = p

    print(ans)