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 <cctype>
#include <utility>
#include <cfloat>
#include <algorithm>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

using P = pair<double, int>;

int main() {
	for (int n; (n = in());) {
		P m {DBL_MAX, 0};
		while (n--) {
			int p {in()}, h {in()};
			m = min(m, {abs(22 - in() * 10000. / h / h), p});
		}
		outl(m.second);
	}
}

C++: #include<iostream>
#include<string>
#include<map>
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 <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;)
	{
		int index = 0;
		double fit = 0;
		
		rep(i, n)
		{
			int in;
			double h, w;
			cin >> in >> h >> w;
			
			double p = abs(22.0 - bmi(h / 100.0, w));
			if(!i || p < fit)
			{
				index = in;
				fit = p;
			}
			else if(p == fit && in < index)
			{
				index = in;
			}
		}
		
		cout << index << endl;
	}
}

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

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

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector< pair<double, int> > diff;
        for (int a = 0; a < n; a++) {
            int i, h, w;
            cin >> i >> h >> w;
            diff.push_back(pair<double, int>(abs(bmi((double)w, (double)h)-22.0), i));
        }
        cout << min_element(diff.begin(), diff.end())->second << endl;
    }
    return 0;
}

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

double abs( double n )
{
  return ( n < 0 ? -n : n );
}

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

    double min_diff = 10000000;
    int min_num;
    for (int i=0; i<n; i++)
    {
      int num;
      double height, weight;
      cin >> num >> height >> weight;
      double bmi = weight / ( height*height*0.0001);
      double bmi_diff = abs(22.0 - bmi);
      if ( bmi_diff < min_diff )
      {
        min_diff = bmi_diff;
        min_num = num;
      }
      else if ( bmi_diff == min_diff )
      {
        if ( num < min_num )
        {
          min_diff = bmi_diff;
        }
      }
    }
    cout << min_num << endl;
  }
}