Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"math"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const IDEAL = 22

type Person struct {
	Id int
	Weight float64
	Height float64
	BMI float64
}

type LessFunc func(p1, p2 *Person) bool
type multiSorter struct {
	People []Person
	less []LessFunc
}
func (ms *multiSorter) Sort(people []Person) {
	ms.People = people
	sort.Sort(ms)
}
func OrderBy(less ...LessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}
func (ms *multiSorter) Len() int {
	return len(ms.People)
}
func (ms *multiSorter) Swap(i, j int) {
	ms.People[i], ms.People[j] = ms.People[j], ms.People[i]
}
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.People[i], &ms.People[j]
	var k int
	for k = 0; k < len(ms.less); k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	id := func(p1, p2 *Person) bool {
		return p1.Id < p2.Id
	}
	bmi := func(p1, p2 *Person) bool {
		return math.Abs(p1.BMI-22) < math.Abs(p2.BMI-22)
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		People := make([]Person, 0)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			tmpid, _ := strconv.Atoi(buf[0])
			tmpheight, _ := strconv.ParseFloat(buf[1], 64)
			tmpweight, _ := strconv.ParseFloat(buf[2], 64)
			People = append(People,
			 		Person{tmpid,
			 		tmpheight/100,
			 		tmpweight,
			 		tmpweight/(tmpheight/100*tmpheight/100)})
		}
		OrderBy(bmi, id).Sort(People)
		// bestID := People[0].Id
		bestBMI := People[0].BMI
		for _, p := range People {
			if p.BMI == bestBMI {
				fmt.Println(p.Id)
			}
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int ans = 100000000;
		double BMI = 100000000;
		
		for(int loop = 0; loop < n; loop++){
			double p, h, w;
			cin >> p >> h >> w;
			h /= 100;
			//cout << w / h / h << endl;
			if(abs(22 - w / h / h) < abs(22 - BMI)){
				ans = p;
				BMI = w / h / h;
			}else if(abs(22 - w / h / h) == abs(22 - BMI)){
				if(p < ans){
					ans = p;
				}
			}
		}
		
		cout << ans << endl;
		
	}
	return 0;
}

C++: #include<iostream>
#include<map>
using namespace std;

int main()
{
	int n, i, a;
	double b, c;
	map<double, int> m;
	map<double, int>::iterator it;
	while (cin>>n, n) {
		m.clear();
		for (i = 0; i < n; i++) {
			cin>>a>>b>>c;
			c = 22.0 - (10000.0*c/b/b);
			if (c<0) c *= -1;
			if (m.count(c)) {
				if (m[c] > a) m[c] = a;
			}
			else m[c] = a;
		}
		cout<<(*m.begin()).second<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;

int main(void){
	int n;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int an;
		double bmi=1000000;
		for(int i=0;i<n;i++){
			int num;
			double h,w,b;
			cin >> num >> h >> w;
			h=(double)h/100;
			b=w/pow(h,2);
			if(abs(b-22)<bmi){
				an=num;
				bmi=abs(b-22);
			}
		}
		printf("%d\n",an);
	}
    return 0;
}

C++: #include<cmath>
using namespace std;
int main(){
	int n,mi,id;
	while(cin>>n,n){
		double mx=1000000,h,w;
		for(int i=0;i<n;i++){
			cin>>id>>h>>w; h/=100;
			if(abs(mx-22)>abs(1.*w/h/h-22))mx=1.*w/h/h,mi=id;
		}
		cout<<mi<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) ((abs(a-b)<EPS))
const int INF=100000000;

int main(){

	int n;
	while(cin>>n&&n!=0){
		double reasonableBMI=INF;
		int bnum;
		for(int i = 0; i < n; i++){
			int n,w;
			double h;
			cin>>n>>h>>w;
			h/=100;
			double bmi=(double)w/(h*h);

			if(( abs(bmi-22)<abs(reasonableBMI-22))||(EQ(reasonableBMI,INF)) ){
				reasonableBMI=bmi;
				bnum=n;
			}
			else if(EQ(reasonableBMI,bmi)){
				if(bnum>n)
					bnum=n;
			}
		}
		cout<<bnum<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;

int main(void){
    int n,num,h,w;
    
    while(1){
        double best = 22,tmp;
        int bn;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++){
            cin >> num >> h >> w;
            
            double nh = (double)h / 100;
            double BMI = (double)w / (nh*nh);
            if(!i){
                tmp = fabs(BMI-best);
                bn = num;
                continue;
            }
            
            if(tmp > fabs(BMI-best)){
                tmp = fabs(BMI-best);
                bn = num;
            }
        }
        cout << bn << endl;
    }

    return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	while(cin>>n,n){
		int c;
		double h,w;
		vector<pair<double,int> >data;
		data.clear();
		for(int i =0;i <n;i++){
			cin>>c>>h>>w;
			double bmi =(w/((h/100)*(h/100)));
			bmi =fabs(22.0-bmi);
			//cout <<bmi<<endl;
			data.push_back(mp(bmi,-c));
		}
		sort(data.begin(),data.end());
		//cout <<data[0].first<<endl;
		cout <<-data[0].second<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n!=0) {
		double a = -100;
		long float r=22, r1 = 10000;
		for (int i = 0; i < n; i++) {
			long float id, cm, kg;
			cin >> id >> cm >> kg;
			cm /= 100;
			long float bmi;
			bmi = (kg / (cm*cm));
			long float r2 = r - bmi;
			if (r2 < 0) r2 = 0 - r2;
			if (r1 > r2) {
				r1 = r2;
				a = id;
			}
			else if (r1 == r2&&a<id) {
				a = id;
			}
		}
		cout << a << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int solve() {
  int N; cin >> N;
  if(N == 0) return 1;

  double ideal = 22.0;
  double mi = 1e9; int id = -1;
  for(int i=0; i<N; i++) {
    int p; double h, w; cin >> p >> h >> w;
    h /= 100.0;
    double bmi = w / (h * h);

    double sub = fabs(ideal - bmi);
    if(sub < mi) {
      mi = sub;
      id = p;
    }
  }
  cout << id << endl;
  return 0;
}

int main() {
  while(!solve());
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int m1=1e9,m2=1e9;
    rep(i,n){
      int a;
      double b,c;
      cin>>a>>b>>c;
      b/=100.0;
      if(m2>abs(22-c/b/b)){
	m1=min(m1,a);
	m2=abs(22-c/b/b);
      }
    }
    cout<<m1<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int h, w, maxid, n, b; double maxn = 1000000000.00;
int main() {
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		maxn = 1000000000.00;
		for (int i = 0; i < n; i++){
			cin >> b >> h >> w;
			if (maxn >= 10000.00*w / (h*h) - 22.00) {
				maxn = 10000.00*w / (h*h) - 22.00;
				maxid = b;
			}
		}
		cout << maxid << endl;
	}
}