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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    int a    = INF;
    double b = INF;
    vector<pair<int, pair<double, double>>> v(n);
    rep(i, n) cin >> v[i].fi >> v[i].se.fi >> v[i].se.se;
    sort(all(v));
    rep(i, v.size()) {
      double h = v[i].se.fi, w = v[i].se.se;
      double diff = abs(w * 10000.0 / h / h - 22.0);
      if (cmin(b, diff)) a = v[i].fi;
    }
    cout << a << endl;
  }
}

C++: #include<iostream>
#include<utility>
#include<cmath>

typedef std::pair<double, int> P;

const int INF = 1 << 30;

int n;

int main()
{
	while( std::cin >> n, n )
	{
		P ans( INF, INF );
		
		while( n-- )
		{
			int i; 
			double h, w;
			std::cin >> i >> h >> w;
			h /= 100.0;
			ans = std::min( ans, P( fabs( w / ( h * h ) - 22.0 ), i ) );
		}

		std::cout << ans.second << std::endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

const int BMI = 22;

int main()
{
	int n;
	int no, bmi;
	while(cin >> n, n)
	{
		no = 1000001; bmi = 100;
		while(n--)
		{
			int nn, w, h;
			cin >> nn >> h >> w;
			w *= 10000;
			int tmp = BMI - (w / h / h);
			if(tmp < 0) tmp = -tmp;
			if(bmi > tmp) {
				bmi = tmp;
				no = nn;
			}else if(bmi == tmp) {
				if(no > nn) {
					no = nn;
					bmi = tmp;
				}
			}
		}
		cout << no << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#define INF 1<<28
using namespace std;

int main(){

  int n;
  int a,b,c;

  while(cin >> n, n){

    int ans1 = INF;
    int  ans2 = INF;
    double p = INF,q = INF;

    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      double k = (double)b/100;
      double d = c/(k*k);

      if(p > abs(22-d)){
	p = abs(22-d);
	ans1 = a;
      }

      else if(p == abs(22-d) && ans1 > a) ans1 = a;

    }
    cout << ans1 << endl;

  }
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[1000],x,i;
	double h[1000],w[1000],y;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++) {
			scanf("%d %lf %lf",&p[i],&h[i],&w[i]);
			h[i]=h[i]/100;
			h[i]=w[i]/(h[i]*h[i]);
		
//			if(h[i]<0)  h[i]=h[i]*-1;
			
			h[i]=h[i]-22;
//			if(h[i]<0)  h[i]=h[i]*-1;
//			printf("p=%d h=%d\n",p[i],h[i]);
		}
		x=p[0]; y=h[0];
		for(i=1;i<n;i++){
			if(y>h[i]){
				x=p[i];  y=h[i];
			}
		}
		printf("%d\n",x);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>

using namespace std;

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

        double diff = 999999999.9;
        int least = -1;
        for( int i=0; i<n; ++i ) {
            int i, h, w;

            cin >> i >> h >> w;

            double const bmi = static_cast<double>( w ) / pow( static_cast<double>( h ) / 100.0, 2 );

            double const d = abs( 22.0 - bmi );
            if ( d < diff ) {
                diff = d;
                least = i;
            }
        }

        cout << least << endl;
    }
}

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

int main(){
    int n;
    while(cin >> n, n){ 
        int ans = -1;
        double mi = DBL_MAX;

        int p;
        double h, w;
        for(int i = 0; i < n; i++){
            cin >> p >> h >> w;
            h /= 100;
            double diff = fabs(22.0 - w/h/h);
            if(diff < mi){
                mi = diff;
                ans = p;
            }
        }

        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<utility>
#include<cstdlib>

typedef std::pair<double, int> P;

const int INF = 1 << 30;

int n;

int main()
{
	while( std::cin >> n, n )
	{
		P ans( INF, INF );
		
		while( n-- )
		{
			int i; 
			double h, w;
			std::cin >> i >> h >> w;
			h /= 100.0;
			ans = std::min( ans, P( fabs( w / ( h * h ) - 22.0 ), i ) );
		}

		std::cout << ans.second << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <deque>
using namespace std;
int main()
{
	deque<int> m;
	deque<double> d, h, w;
	int n, i, t[3];
	double u;
	while (cin >> n && n)
	{
		u = 0;
		m.clear();
		h.clear();
		w.clear();
		d.clear();
		for (i = 0; i < n; i++)
		{
			cin >> t[0] >> t[1] >> t[2];
			m.push_back(t[0]);
			h.push_back((double)t[1]/100);
			w.push_back((double)t[2]);
			d.push_back(22.0 - w[i]/(h[i]*h[i]));
			if (i == 0) u = abs(d[0]);
			if (abs(d[i]) < u) u = abs(d[i]);
		}
		for (i = 0; i < n; i++)
		{
			if (u == abs(d[i]))
				cout << m[i] << endl;
		}
	}
}