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>
#include<iostream>
using namespace std;
int main(){

int N;
while(1){
	cin>>N;if(N==0)break;
	int i,I=0;
	double w,h;
	double min=0;

	cin>>i>>h>>w;
	h=h/100;
	if(w/h/h<=22)min=22-w/h/h;
	else min=w/h/h-22;
	I=i;
	for(int ii=1;ii<N;ii++)
	{
		cin>>i>>h>>w;
		h=h/100;
		if(min>22-w/h/h&&w/h/h<=22){min=22-w/h/h;I=i;}
		else if(min>w/h/h-22&&w/h/h>22){min=w/h/h-22;I=i;}
	
	}
	cout<<I<<endl;
}
return 0;
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		double b_min = 2000000.0;
		int m_min = 0;
		for(int i=0; i<n; i++){
			int m, h, w;
			cin >> m >> h >> w;

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

			if(b<b_min||(b==b_min&&m<m_min)){
				b_min = b;
				m_min = m;
			}
		}

		cout << m_min << endl;
	}

	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const double EPS = 1e-8;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		int id = -1;
		double diff;
		rep(i, n){
			int i, h, w;
			scanf("%d%d%d", &i, &h, &w);
			double H = h / 100.0;
			double d = fabs(22.0 - w / H / H);
			
			if(id == -1){
				diff = d;
				id = i;
			}
			else if(fabs(diff - d) < EPS)
				id = min(id, i);
			else if(diff > d){
				diff = d;
				id = i;
			}
		}
		
		printf("%d\n", id);
	}
	
	return 0;
}

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

int main()
{
  int n;
  while( cin >> n, n ) {
    double id, h, w;
    double close_id = (1 << 30), close_bmi = (1 << 30);
    double basic = 22.0;

    while( n-- ) {
      cin >> id >> h >> w;

      double bmi = w / ((h/100) * (h/100));
      if( fabs(basic - bmi) == fabs(basic - close_bmi) ) {
	close_id = min(close_id, id);
      }
      else if( fabs(basic - bmi) < fabs(basic - close_bmi) ) {
	close_id = id;
	close_bmi = bmi;
      }

    }

    cout << close_id << endl;
  }

}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

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

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<pair<double,int> > data;
    REP(i,n){
      int num;
      double h,w;
      cin>>num>>h>>w;
      data.push_back(pair<double, int>(w*10000/(h*h), num));
    }
    sort(data.begin(), data.end());
    vector<pair<double,int> >::iterator itl, itu;
    itl = lower_bound(data.begin(), data.end(), pair<double,int>(22,0));
    itu = itl-1;
    if(abs(22-(*itl).first)>abs(22-(*itu).first)){
      cout<<(*itu).second<<endl;
    }else{
      cout<<(*itl).second<<endl;
    }
  }

  return 0;
}

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

int main(void){
    int n,num,h,w;
    
    while(1){
        double best = 22;
        int tmp,bn;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++){
            cin >> num >> h >> w;
            
            double nh = (double)h / 100;
            double BMI = (double)w / (nh*nh);
            if(!i){
                tmp = abs(BMI-best);
                bn = num;
                continue;
            }
            
            if(tmp > abs(BMI-best)){
                tmp = abs(BMI-best);
                bn = num;
            }
        }
        cout << bn << endl;
    }

    return 0;
}

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;
  }
  if(r==best){
	  if(set>c){
		  set=c;
		  best=r;
	  }
  }
 }
 cout<<set<<endl;
 }
 return 0;   
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int output;
        double diff = 100;
        for (int i = 0; i < n; i++) {
            int num;
            double h, w;
            cin >> num >> h >> w;
            double bmi = w / pow(h / 100, 2);
            if (fabs(bmi - 22) < diff) {
                diff = fabs(bmi - 22);
                output = num;
            }
        }
        cout << output << endl;
    }
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        double best=1000000,num;
        for(int i=0;i<n;i++){
            int x;
            double y,z;
            cin>>x>>y>>z;
            y/=100;
            if(fabs(z/(y*y)-22)<best)best = fabs(z/(y*y)-22),num = x;
        }
        cout<<num<<endl;
    }
}