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<stdio.h>
int main(void)
{
	int n;
	int i,h,w;
	int j;
	double best;
	double bmi,sa;
	int a;
	
	scanf("%d",&n);
	best=22.0;
	while(n!=0){
		sa=99999.0;
		for(j=0;j<n;j++){
			scanf("%d %d %d",&i,&h,&w);
			bmi=(double)w/(((double)h/100)*((double)h/100));
			if(best<bmi){
				bmi=bmi-best;
			}
			else {
				bmi=best-bmi;
			}
//			printf("%lf\n",bmi);
			if(sa>bmi){
				a=i;
				sa=bmi;
			}
			else if(sa==bmi && a>i){
				a=i;
			}	
		}
		printf("%d\n",a);
		scanf("%d",&n);

	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <cfloat>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

int main() {
  int n, id, w, h, ans_id;
  double bmi, err, min_err;
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    min_err = DBL_MAX;
    for (int i=0; i<n; i++) {
      scanf("%d %d %d", &id, &h, &w);
      bmi = (double)w * 10000. / (h * h);
      err = fabs(bmi - 22.);
      if (err < min_err) {
        min_err = err;
        ans_id = id;
      } else if (err == min_err && id < ans_id) {
        ans_id = id;
      }
    }
    printf("%d\n", ans_id);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n;
	pair< int,double > b;
	b= pair<int,double>(0,10000000.0);
	cin >> n;
	if(n == 0) break;
	REP(i,n){
	    double j,h,w;
	    cin >> j >> h >> w;
	    h /= 100;
	    double bmi = w / (h*h);
	    bmi = abs(bmi - 22.0);
	    if(b.second > bmi){
		b.first = (int)j;
		b.second = bmi;
	    }
	}
	cout << b.first << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int n; cin >> n&&n;) {
		int ans = 0;
		double min = INF;
		rep(i, 0, n) {
			double l, h, w; cin >> l >> h >> w;
			h /= 100;
			if (min > abs(w / (h*h) - 22)) {
				ans = l;
				min = abs(w / (h*h) - 22);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n;
	int i,h,w;
	int j;
	double best;
	double bmi;
	int a,sa;
	
	scanf("%d",&n);
	best=22.0;
	while(n!=0){
		sa=99999;
		for(j=0;j<n;j++){
			scanf("%d %d %d",&i,&h,&w);
			bmi=(double)w/(h*h)*10000;
			printf("%lf\n",bmi);
			if(best<bmi){
				bmi=bmi-best;
			}
			else {
				bmi=best-bmi;
			}
			if(sa>bmi){
				a=i;
				sa=bmi;
			}
		}
		printf("%d\n",a);
		scanf("%d",&n);

	}
	return 0;
}

C++: // 2011/03/01 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		double b22_min = 2000000.0;
		int    num_min = 0;
		for(int i=0; i<n; i++){
			int num, h, w;
			cin >> num >> h >> w;

			double bmi = (double)(w*10000)/(double)(h*h);
			double b22 = bmi-22.0;
			if(b22<0.0)
				b22 = -b22;

			if(b22<b22_min||(b22==b22_min&&num<num_min)){
				b22_min = b22;
				num_min = num;
			}
		}

		cout << num_min << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cmath>
#define INF 1000000000

using namespace std;

int main(void){

  int n;
  double i,h,w,ans,bmi;

  while(cin >> n,n){
    ans=INF,bmi=INF;

    for(int j=0;j<n;j++){
      cin >> i >> h >> w;
      if(abs(22-bmi)>abs(22-w/(h*h/10000))||
	 (abs(22-bmi)==abs(22-w/(h*h)/10000) && i<ans)){
	ans=i,bmi=w/(h*h/10000);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

  while(1){

    int n;

    cin >> n;

    if(n == 0) break;

    int min = 1000;
    int minnum;
    double bmi[n];

    for(int i = 0; i < n; i++){
      int num;
      double tall, wei;

      cin >> num >> tall >> wei;

      bmi[i] = wei / (tall / 100) / (tall / 100);

      bmi[i] -=22;

      if(bmi[i] < 0) bmi[i] *= -1;
 
      if(min > bmi[i]){
	minnum = num;
	min = bmi[i];
      }
    }

    cout << minnum << endl;
  }


  return 0;

}

C++: #include <iostream>
#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 pint pair<int, int>
int main(){
    int n, h, w;
    pint a;
    while(cin >> n, n) {
        vector<pint> v;
        rep(i,n) {
            cin >> a.second;
            cin >> h >> w;
            a.first = abs(h * h * 22 - w * 10000);
            v.push_back(a);
        }
        sort(v.begin(), v.end());
        cout << v[0].second << endl;
    }
    return 0;
}

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

int main(){
	int n;
	while(scanf("%d", &n),n){
		int ans = -1; double dif = 1000000.0;
		for(int i = 0; i < n; i++){
			int x, h, w; scanf("%d%d%d",&x,&h,&w);
			if(dif > abs(22.0-(double)w*100.0*100.0/(double)h/(double)h)){
				dif = abs(22.0-(double)w*100.0*100.0/(double)h/(double)h);
				ans = x;
			} else if(dif==abs(22.0-(double)w*100.0*100.0/(double)h/(double)h)&&ans > h){
				ans = x;
			}
		}
		printf("%d\n", ans);
	}
}