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 <vector>
#include <algorithm>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		int num,ans_num;
		double h,w,ans;
		
		rep(i,n)
		{
			cin >> num >> h >> w;
			
			h /= 100;
			double bmi = w / (h*h);

			if(i == 0)
			{
				ans_num = num;
				ans = fabs(22 - bmi);
			}
			else
			{
				if(fabs(22 - bmi) == ans)
				{
					ans_num = min(ans_num,num);
				}

				if(fabs(22 - bmi) < ans)
				{
					ans_num = num;
					ans = fabs(22 - bmi);
				}
			}
		}

		cout << ans_num << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <utility>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pdi pair<double, int>
const double EPS = 1e-10;
int main(){
	int n, h, w;
	pdi a;
	while(cin >> n, n) {
		vector<pdi> v;
		rep(i,n) {
			cin >> a.second;
			cin >> h >> w;
			a.first = abs(w / ((h/100.0) * (h/100.0)) - 22);
			v.push_back(a);
		}
		sort(v.begin(), v.end());
		rep(i,v.size()) 
		cout << v[i].first << " " << v[i].second << endl;

		cout << v[0].second << endl;
		int i = 1;
		while(v[i+1].first - v[i].first < EPS) {
			cout << v[i].second << endl;
			i++;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int N,I,H,W,R,i;
float B,t;
int main()
{
	for(;scanf("%d",&N),N;)
	{
		R=1000000000;B=99999;
		for(i=0;i<N;i++)
		{
			scanf("%d%d%d",&I,&H,&W);
			t=(float)W*100/(H*H);
			//printf("%f\n",t);
			if(abs(0.22-B)==abs(0.22-t))R=min(R,I);
			if(abs(0.22-B)>abs(0.22-t))
			{
				R=I;
				B=t;
			}
		}
		printf("%d\n",R);
	}
}

C++: #include <iostream>
#include <set>
#include <math.h>
#include <vector>
using namespace std;

int main(){
	int n;
	int Id;
	double cm,kg;
	while(cin >> n && n){
		double mi   = 1000000.0;
		int miId = -1;
		for(int i=0;i<n;i++){
			cin >> Id >> cm >> kg;
			if(fabs(22.0 - kg/(cm/100)/(cm/100))<mi){
				mi = fabs(22.0 - kg/(cm/100)/(cm/100));
				miId = Id;
			}
		}
		cout << miId << endl;
			
	}
}

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<double,int> > v;
		for(int i = 0; i < n; i++) {
			pair<double,int> tmp;
			int id, h, w;
			cin >> id >> h >> w;
			tmp.first = fabs(22 - w / ((h / 100.0) * (h / 100.0)));
			tmp.second = id;
			v.push_back(tmp);
		}

		sort(v.begin(), v.end());
		cout << v[0].second << endl;
	}
}

C++: #include<iostream>
#include<cmath>
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 >= abs(10000.00*w / (h*h) - 22.00)) {
				maxn = abs(10000.00*w / (h*h) - 22.00);
				maxid = b;
			}
		}
		cout << maxid << endl;
	}
}

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

double BMI(double h, double w) {return w/(h*h);}

int main() {
  int n;
  while(cin >> n && n) {
    vector<vector<int> > v;
    while(n--) {
      vector<int> p(3);
      cin >> p[0] >> p[1] >> p[2];
      v.push_back(p);
    }

    sort(v.begin(), v.end());
    int bestID = v[0][0];
    double bestValue = abs(22.0-BMI(v[0][1]/100.0,v[0][2]));
    for(int i = 1; i < v.size(); ++i) {
      double newValue = abs(22.0-BMI(v[i][1]/100.0,v[i][2]));
      if(newValue < bestValue) {
	bestID = v[i][0];
	bestValue = newValue;
      }
    }
    cout << bestID << endl;
  }
  return 0;
}

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

using namespace std;

const double BMI = 22.0;

int main()
{
	int n, no;
	double bmi;
	while(cin >> n, n)
	{
		no = 1000001; bmi = 100.0;
		while(n--)
		{
			int nn;
			double w, h;
			cin >> nn >> h >> w;
			double tmp = abs(BMI - ((w*10000.0) / 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;
}

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

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		long double opt_bmi = 2000001.0;
		int opt_p = n+1;
		for (int i=0; i<n; i++) {
			int p, h, w;
			std::cin >> p >> h >> w;
			long double bmi = (long double)w * 10000.0 / (h*h);
			if ( std::abs(opt_bmi - 22.0) > std::abs(bmi - 22.0) ) {
				opt_bmi = bmi;
				opt_p = p;
			} else if ( std::abs(opt_bmi - 22.0) == std::abs(bmi - 22.0) ) {
				if (opt_p > p) opt_p = p;
			}
		}
		std::cout << opt_p << std::endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

const double INF = 1e40;
const double EPS = 1e-8;

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) break;
    int ans = -1;
    double dif = INF;
    rep (i, n) {
      int k;
      double h, w;
      cin >> k >> h >> w;
      h /= 100;
      if (dif > abs(22 - w / h / h)) {
	ans = k;
	dif = abs(22 - w / h / h);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	double a,b;
	int n;
	while(cin >> n && n){
		pair<double,int> e = make_pair(1e9,1e9);
		for(int i = 0 ; i < n ; i++){
			int a;
			double b;
			double c;
			cin >> a >> b >> c;
			b /= 100;
			double f = fabs(22-c/b/b);
			if( e > make_pair(f,a) ){
				e = make_pair(f,a);
			}
		}
		cout << e.second << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
int n;
pair<double,int>p[1000];
main()
{
    while(cin>>n,n)
    {
        for(int i=0;i<n;i++)
        {
            double h,w;
            cin>>p[i].second>>h>>w;
            h/=100;
            p[i].first=abs(22-w/h/h);
        }
        sort(p,p+n);
        cout<<p[0].second<<endl;
    }
}