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;)
	{
		int index = 0;
		double fit = 1 << 30;
		
		rep(i, n)
		{
			int in;
			double h, w;
			cin >> in >> h >> w;
			
			int p = abs(22.0 - bmi(h / 100.0, w));
			if(p < fit)
			{
				index = in;
				fit = p;
			}
			else if(p == fit && in < index)
			{
				index = in;
			}
		}
		
		cout << index << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
double bmi(double h, double w){
	return w/((h/100)*(h/100));
}

int main(){
	int n, p;
	double h, w;
	const double c = 22;
	while(true){
		cin >> n;
		if(n == 0)
			return 0; 
		int num;
		double diff;
		for(int i = 0; i < n; i++){
			cin >> p >> h >> w;
			if(i == 0){
				num = p;
				diff = abs(bmi(h,w) - c);
			}else{
				double k = abs(bmi(h,w) - c);
				if(diff > k){
					diff = k;
					num = p;
				}else if(diff == k){
					if(num > p)
						num = p;
				}
			}
		}
		cout << num << endl;
	}

}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-8;

int main(){

	int i,n;
	double h,w;
	
	while(~scanf("%d",&n)){
		if(n==0) break;
		double diff = 1000000;
		int res=10000000;

		for(int j=0;j<n;j++){
			scanf("%d %lf %lf",&i,&h,&w);
			if(diff > abs(22.0-(w / ((h/100.0)*(h/100.0))))){
				diff = abs(22.0-(w / ((h/100.0)*(h/100.0))));
				res = i;
			}
			else if(diff == abs(22.0-(w / ((h/100.0)*(h/100.0))))){
				res = min(res,i);
			}
		}
		printf("%d\n",res);
	}
}

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


int main(){
	int n;
	while(cin>>n&&n){
		double a=1e10;
		int ans=0;
		for(int i=0;i<n;i++){
			int id,h,w;
			cin>>id>>h>>w;
			double bmi=w/(h*h*1e-4);
			if(fabs(bmi-22)<a){
				a=fabs(bmi-22);
				ans=id;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int N; cin >> N, N;) {
		vector<pair<double, int> > v;
		for(int i = 0; i < N; i++) {
			int num, h, w;
			cin >> num >> h >> w;
			v.push_back(mp(fabs(22.0 - w / (h * h / 10000.0)), num));
		}

#if 0
		cerr << "debug" << endl;

		for(int i = 0, end = v.size(); i != end; ++i)
			cerr << v[i].first << endl;
#endif

		sort(v.begin(), v.end());

		cout << v.at(0).second << endl;
	}

	return 0;
}

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

int main() {
int n,num;
double ta,omo,bmi;
while(cin>>n){
	if(n==0){
		break;
	}
	double max=100000,sa;
	int best=1000000;
for(int k=0;k<n;k++){
	cin>>num>>ta>>omo;
	bmi=omo*10000/(ta*ta);
	if(bmi-22<0){
		sa=22-bmi;
	}
	else{
		sa=bmi-22;
	}
	if(sa<=max&& num<best){
		best=num;
		max=sa;
	}
}
cout<<best<<endl;
}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int bmi(double h, double w){
	return w/((h/100)*(h/100));
}

int main(){
	int n, p;
	double h, w;
	const double c = 22;
	while(true){
		cin >> n;
		if(n == 0)
			return 0; 
		int num;
		double diff;
		for(int i = 0; i < n; i++){
			cin >> p >> h >> w;
			if(i == 0){
				num = p;
				diff = abs(bmi(h,w) - c);
			}else{
				double k = abs(bmi(h,w) - c);
				if(diff > k){
					diff = k;
					num = p;
				}else if(diff == k){
					if(num > p)
						num = p;
				}
			}
		}
		cout << num << endl;
	}

}

C++: #include <iostream>
#include <cmath>
using namespace std;
 
  int id;
  double h;
  double w;
 
int main(){
  int n;
  double bmi;
 
  while( cin >> n,n){
  int ans = 0;
  double s = 1000;
    for(int i = 0 ; i < n ; i++){
      cin >> id >> h >> w;
      h /= 100;
      bmi = w/(h * h);
      if(s > fabs(22 - bmi)  ){
    s = fabs(22 - bmi);
    ans = id;
      }
    }
    cout << ans << endl;
}
  return 0;
}

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