Go: package main

import (
	"fmt"
	"math"
	"strconv"
)

// ColorCode is a string like #rrggbb
type ColorCode string

// ColorName is a name of color
type ColorName string

// Color has colorname and colorcode
type Color struct {
	name ColorName
	code ColorCode
}

// ColorTable has default colors
type ColorTable struct {
	colors []Color
}

var (
	colorTable = ColorTable{
		[]Color{
			Color{"black", "#000000"},
			Color{"blue", "#0000ff"},
			Color{"lime", "#00ff00"},
			Color{"aqua", "#00ffff"},
			Color{"red", "#ff0000"},
			Color{"fuchsia", "#ff00ff"},
			Color{"yellow", "#ffff00"},
			Color{"white", "#ffffff"},
		},
	}
)

func main() {
	var code ColorCode
	fmt.Scanf("%s", &code)
	for {
		if code == "0" {
			break
		}
		name := colorTable.getNearestColor(code)
		fmt.Println(name)
		fmt.Scanf("%s", &code)
	}
}

func (colorstr ColorCode) parseColorValue() (float64, float64, float64) {
	rr, gg, bb := colorstr[1:3], colorstr[3:5], colorstr[5:7]
	rri, err1 := strconv.ParseUint(string(rr), 16, 8)
	ggi, err2 := strconv.ParseUint(string(gg), 16, 8)
	bbi, err3 := strconv.ParseUint(string(bb), 16, 8)
	if err1 != nil || err2 != nil || err3 != nil {
		err := fmt.Errorf(
			"Failed to read color strings, color code:%s, err: %v %v %v",
			colorstr, err1, err2, err3)
		panic(err)
	}
	return float64(rri), float64(ggi), float64(bbi)
}

func (table *ColorTable) getNearestColor(targetcode ColorCode) ColorName {
	var nearestColor ColorName
	var nearestValue = 1e5
	for _, v := range table.colors {
		trr, tgg, tbb := targetcode.parseColorValue()
		prr, pgg, pbb := v.code.parseColorValue()
		// diff := math.Sqrt(
		// 	math.Pow(prr-trr, 2) + math.Pow(pgg-tgg, 2) + math.Pow(pbb-tbb, 2))
		diff := math.Pow(prr-trr, 2) +
			math.Pow(pgg-tgg, 2) +
			math.Pow(pbb-tbb, 2)
		if nearestValue > diff {
			nearestValue = diff
			nearestColor = v.name
		}
	}
	return nearestColor
}

C++: # define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int main()
{
	string a;
	int FF = 16 * 16 - 1;
	int f[][3] = { { FF,FF,FF },{ FF,FF,0 },{ FF,0,FF },{ FF,0,0 },{ 0,FF,FF },{ 0,FF,0 },{ 0,0,FF },{ 0,0,0 } };
	string ans[] = { "white","yellow","fuchsia","red","aqua","lime","blue","black" };
	while (cin >> a&&a != "0")
	{
		int g[3];
		FOR(i, 3)g[i] = strtol(a.substr(i * 2 + 1,2).c_str(),NULL,16);
		int d = INT_MAX, id = 0;
		FOR(i, 8)
		{
			double D = 0;
			FOR(j, 3)
			{
				D += pow(f[i][j] - g[j], 2);
			}
			if (D <= d)
			{
				d = D;
				id = i;
			}
		}
		cout << ans[id] << endl;

	}
}

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

int dir[5010];

void remove(){
	int cnt = 0;
	for(int i = 0 ; i < 5010 ; i++){
		if( dir[i] == 31 ) dir[i] = 0,cnt++;
	}
	for(int k = 0 ; k < cnt ; k++)
	for(int i = 5009 ; i > 0 ; i--){
		if( dir[i] && !dir[i-1] ){
			swap(dir[i],dir[i-1]);
		}
	}
}

void tate(int x,int l){
	for(int i = 1 ; i <= l ; i++) dir[5010-i] |= (1<<x);
	
	for(int _ = 0 ; _ < l ; _++)
	for(int i = 5010-l+_ ; i > 0 ; i--){
		if( (dir[i] >> x & 1) && (dir[i-1] >> x & 1) == 0 ){
			dir[i] -= (1<<x);
			dir[i-1] += (1<<x);
		}else{
			break;
		}
	}
	remove();
}

void yoko(int x,int l){
	int mask = ((1<<l)-1) << x;
	dir[5009] = mask;
	for(int i = 5009 ; i > 0 ; i--){
		if( dir[i] && !(dir[i-1] & mask) ){
			dir[i] -= mask;
			dir[i-1] += mask;
		}else{
			break;
		}
	}
	remove();
}
int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i <= 5009 ; i++)
			dir[i] = 0;
		
		for(int i = 0 ; i < n ; i++){
			int d,l,x;
			cin >> d >> l >> x;
			x--;
			if(d==1){
				yoko(x,l);
			}else{
				tate(x,l);
			}
			int f = 0;
			if( i == 10 ) continue;
			for(	int j = 5009 ; j >= 0 ; j--){
				if(f||dir[j]){
					//cout << j << " " << (dir[j]&1) << (dir[j]&2) << (dir[j]&4) << (dir[j]&8) << (dir[j]&16) << endl; ;
					f=true;
				}
			}
		//	cout << endl;
		}
		int ans = 0;
		for(int i = 0 ; i < 5010 ; i++)
			ans += __builtin_popcount(dir[i]);
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


int cal[8][3]={
	{0,0,0},
	{0,0,255},
	{0,255,0},
	{0,255,255},
	{255,0,0},
	{255,0,255},
	{255,255,0},
	{255,255,255}
};

string t[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int c[3];

double d(int i){
	double ret=0.0;
	for(int j=0; j<3; j++){
		ret+=(cal[i][j]-c[j])*(cal[i][j]-c[j]);
	}
	return sqrt(ret);
}

int change(char c){
	if(c>='0'&&c<='9')return c-'0';
	return 10+c-'a';
}

int main(){
	string s;
	int ans;
	while(cin>>s){
		if(s=="0")break;
		for(int i=0; i<3; i++){
			c[i]=change(s[i*2+1])*16+change(s[i*2+2]);
		}
		//cout<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
		ans=0;
		for(int i=1; i<8; i++){
			if(d(ans)>d(i))ans=i;
		}
		cout<<t[ans]<<endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string str[8]={"black",
                "blue",
                "lime",
                "aqua",
                "red",
                "fuchsia",
                "yellow",
                "white"};

int change(string t){
    int res = 0;
    rep(i, 0, 2){
        if('0' <= t[i] && t[i] <= '9'){
            res += (t[i] - '0')*16*(1 - i);
        }else{
            res += ((t[i] - 'a') + 10)*16*(1 - i);
        }
    }
    return res;
}

signed main() {
    string s;
    while(cin >> s){
        if(s == "0") break;
        int r, g, b;
        r = change(s.substr(1, 2));
        g = change(s.substr(3, 2));
        b = change(s.substr(5, 2));
        int MIN = 1e9, p = -1;
        rep(i, 0, 2){
            rep(j, 0, 2){
                rep(k, 0, 2){
                    int d = (r - i*240)*(r - i*240) + (g - j*240)*(g - j*240) + (b - k*240)*(b - k*240);
                    if(d < MIN){
                        MIN = d;
                        p = i*4 + j*2 + k;
                    }
                }
            }
        }
        cout << str[p] << endl;
    }
}