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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

double bmi(double h, double w)
{
	return w / h / h;
}

int main()
{
    for(int n; cin >> n && n;)
	{
		double index, fit = 1 << 20;
		rep(i, n)
		{
			double in, h, w;
			cin >> in >> h >> w;
			
			int p = abs(22.0 - bmi(h / 100, w));
			if(p < fit)
			{
				index = in;
				fit = p;
			}
			else if(p == fit && in < index)
			{
				index = in;
			}
		}
		
		cout << index << endl;
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    double h,g;
    int n,NO;
    while(cin>>n,n){
        double s=10000;
        int sNO;
        while(n--){
            cin>>NO>>h>>g;
            h/=100;
            double bmi=22-g/(h*h*1.0);
            if(bmi<0)bmi*=-1;
            if(s>bmi){
                s=bmi;
                sNO=NO;
            }
            else if(s==bmi&&sNO>NO)sNO=NO;
        }
        cout<<sNO<<endl;
    }
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	while(true){
		ll N=in();
		if(!N) break;

		vector<pair<ll,double>> P(N);
		REP(i,N){
			P[i].first=in();
			ll H=in(),W=in();
			P[i].second = abs(22-10000.0*W/(H*H));
		}
		sort(ALL(P),[](pair<ll,double>& l,pair<ll,double>& r){return l.second==r.second ? l.first<r.first : l.second<r.second;});
		out(P[0].first);
	}
	
	return 0;
}

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

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) return 0;
        int res;
        double diff = 1000000;
        for (int i = 0; i < n; i++) {
            int p;
            double h, w;
            cin >> p >> h >> w;
            double bmi = w / (h / 100.0) / (h / 100.0);
            if (fabs(22.0 - bmi) < diff) {
                diff = fabs(22.0 - bmi); 
                res = p;
            }
        }
        cout << res << endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	double best=10000.0;
	int ans;
	int i,h,w;
	for(int u=0;u<n;u++){
		cin>>i>>h>>w;
		double r=w*10000/(h+0.0)/(h+0.0);
		r-=22;
		if(r<0)
			r=-r;
		if(best>r||(best==r&&ans>i)){
			best=r;
			ans=i;
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

const int BMI = 22;

int main()
{
	int n;
	int no, bmi;
	while(cin >> n, n)
	{
		no = 1000001; bmi = 100;
		while(n--)
		{
			int nn, w, h;
			cin >> nn >> h >> w;
			w *= 10000;
			int tmp = abs(BMI - (w / h / h));
			if(bmi > tmp) {
				bmi = tmp;
				no = nn;
			}else if(bmi == tmp) {
				if(no > nn) {
					no = nn;
					bmi = tmp;
				}
			}
		}
		cout << no << endl;
	}
	return 0;
}