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 <algorithm>

using namespace std;

double abs(double a){
    if(a>0)return a;
    else return -a;
}
double bmi(double height,double weight){
    return 10000 * weight / (height*height);
}

int solve(int n){
    int bw=0,bh=0,bi=100000000;
    double bbmi = -1;
    for(int i=0;i<n;i++){
        int ind,w,h;
        cin >> ind >> h >> w;
        double te = bmi(h,w);
        if(bh*bh*w == h*h*bw && bi > ind){
            bi = ind;bbmi = te;bw=w;bh=h;
        }else if(abs(bbmi-22) > abs(te-22)){
            bi = ind;bbmi = te;bw=w;bh=h;
        }
    }
    return bi;
}

int main(){
    int n;
    while(cin >> n && n != 0){
        cout << solve(n) << endl;
    }
}

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		double bmi,best=1e9;
		int ibest=1000000000;
		for(int j=0;j<n;j++){
			int i,h,w;
			scanf("%d%d%d",&i,&h,&w);
			bmi=w/((h/100.0)*(h/100.0));
			if(abs(22-bmi)+1e-9<abs(22-best))
				best=bmi,ibest=i;
			else if(abs(abs(22-bmi)-abs(22-best))<1e-9)
				ibest=min(ibest,i);
		}
		printf("%d\n",ibest);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;

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

        int ans = n+1;
        double dif = 1<<19;
        rep(i, n) {
            int p;
            double h, w;
            cin >> p >> h >> w;
            double bmi = 10000*w/h/h;
            if (dif >= abs(bmi-22)) {
                if (dif == abs(bmi-22)) ans = min(ans, p);
                else ans = p;
                dif = abs(bmi-22);
            }
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int n;
	while(cin >> n, n){
		double ok = 100000.0;
		int ans = 0;
		rep(i,n){
			int num;
			double diff, kg, m;
			cin >> num >> m >> kg;
			m /= 100.0;
			m *= m;
			diff = 22.0-(kg/m);
			if(ok > fabs(diff)){
				ok = fabs(diff);
				ans = num;
			}
		}
		FIN(ans);
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

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

C++: #include <bits/stdc++.h>
using namespace std;

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool is_inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

const double BEST = 22.0;

signed main()
{
  ios::sync_with_stdio(false);
  int n;
  
  for (; cin >> n, n;){
    // Fi->number Se->bmi_diff
    vector<pair<int, double> > body(n);

    REP(i, n){
      double h, w;
      cin >> body[i].Fi >> h >> w;
      h /= 100;
      body[i].Se = fabs(BEST - w / (h * h));
    }

    pair<int, double> ans(body[0].Fi, body[0].Se);
    RREP(i, n - 1){
      if (body[i].Se <= ans.Se){
        if (body[i].Se == ans.Se){
          if (body[i].Fi < ans.Fi){
            ans = body[i];
          }
        } else {
          ans = body[i];
        }
      }
    }

    print(ans.Fi);
  }
  return (0);
}

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

int n;

int main() {
  while (cin >> n, n) {
    int id;
    double diff = double(1<<30);
    for (int i = 0; i < n; ++i) {
      int _id, h, w;
      cin >> _id >> h >> w;
      double height = h / 100.0;
      double bmi = w / height / height;
      if (diff > abs(22.0 - bmi)) {
        id = _id;
        diff = abs(22.0 - bmi);
      }
    }
    cout << id << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<math.h>
int main()
{
	int n,bestIndex,i;
	while(scanf("%d",&n),n)
	{
		double bestBMI=999,h,w,b;
		while(n--)
		{
			scanf("%d%lf%lf",&i,&h,&w);
			b=fabs(w/h/h*10000-22);
			if(bestBMI > b)
				bestBMI = b, bestIndex=i;
		}
		printf("%d\n",bestIndex);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n!=0) {
		double a = -100;
		double r=22, r1 = 10000;
		for (int i = 0; i < n; i++) {
			double id, cm, kg;
			cin >> id >> cm >> kg;
			cm /= 100;
			double bmi;
			bmi = (kg / (cm*cm));
			double 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;
	}
}