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++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

string s;

string colortable[] = { "black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white" };
double numtable[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 }
};

double changenum(string s){
	double res = 0;
	REP(i, 2){
		double num;
		if (s[i] >= '0'&&s[i] <= '9') num = s[i] - '0';
		else if (s[i] == 'a')num = 10;
		else if (s[i] == 'b')num = 11;
		else if (s[i] == 'c')num = 12;
		else if (s[i] == 'd')num = 13;
		else if (s[i] == 'e')num = 14;
		else if (s[i] == 'f')num = 15;
		
		if (i == 0)res += num * 16;
		else res += num;
	}
	return res;
}

void solve(){

}

int main(){
	while (cin >> s&&s != "0"){
		int ans;
		double dk = INF, rk = changenum(s.substr(1, 2)),
			gk = changenum(s.substr(3, 2)), bk = changenum(s.substr(5, 2));
		REP(i, 8){
			double num = sqrt(pow(numtable[i][0] - rk, 2)
				+ pow(numtable[i][1] - gk, 2)
				+ pow(numtable[i][2] - bk, 2));
			if (num - dk < EPS){
				dk = num;
				ans = i;
			}
		}
		cout << colortable[ans] << endl;
	}
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int to_int(string s){
	int k=1,res=0;
	for(int i=s.size()-1;i>=0;i--){
		if('0'<=s[i]&&s[i]<='9'){
			res+=k*(s[i]-'0');
		}else{
			res+=k*(s[i]-'a'+10);
		}
		k*=16;
	}
	return res;
}

int main(){
	string ans[2][2][2];
	ans[0][0][0]="black";
	ans[0][0][1]="blue";
	ans[0][1][0]="lime";
	ans[0][1][1]="aqua";
	ans[1][0][0]="red";
	ans[1][0][1]="fuchsia";
	ans[1][1][0]="yellow";
	ans[1][1][1]="white";
	string s;
	while(cin>>s&&s[0]!='0'){
		int a,b,c,dat[3];
		for(int i=1;i<6;i+=2){
			string tmp;int ans[3];
			tmp.assign(s,i,2);
			int d=to_int(tmp);
			if(d<=(to_int("ff")-d))dat[i/2]=0;
			else dat[i/2]=1;
		}
		cout<<ans[dat[0]][dat[1]][dat[2]]<<endl;
	}
}

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

struct Color {
    string name; int r, g, b;
};
vector<Color> colors = {
    (Color){"black", 0, 0, 0},
    (Color){"blue", 0, 0, 255},
    (Color){"lime", 0, 255, 0},
    (Color){"aqua", 0, 255, 255},
    (Color){"red", 255, 0, 0},
    (Color){"fuchsia", 255, 0, 255},
    (Color){"yellow", 255, 255, 0},
    (Color){"white", 255, 255, 255}
};

int dec(char c) {
    if (isdigit(c)) return c - '0';
    return c - 'a' + 10;
}

int sq(int x) {
    return x * x;
}

int main() {
    string s;
    while (cin >> s, s != "0") {
        int r = dec(s[1]) * 16 + dec(s[2]);
        int g = dec(s[3]) * 16 + dec(s[4]);
        int b = dec(s[5]) * 16 + dec(s[6]);
        int mn = INT_MAX, k = -1;
        for (int i=0; i<(int)colors.size(); ++i) {
            int t = sq(r-colors[i].r) + sq(g-colors[i].g) + sq(b-colors[i].b);
            if (t < mn) {
                mn = t;
                k = i;
            }
        }
        cout << colors[k].name << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int henkan(int i){
	if('0'<=i && i<='9') return i-'0';
	else return i-'a'+10;
}
int main(){
	while(true){
		string s;
		cin >> s;
		if(s=="0") break;
		int r,g,b;
		r=henkan(s[1])*16+henkan(s[2]);
		g=henkan(s[3])*16+henkan(s[4]);
		b=henkan(s[5])*16+henkan(s[6]);
		bool rr=true,gg=true,bb=true;
		if(r<128) rr=false;
		if(g<128) gg=false;
		if(b<128) bb=false;
		if(rr && gg && bb) cout << "white";
		if(rr && gg && !bb) cout << "yellow";
		if(rr && !gg && bb) cout << "fuchsia";
		if(rr && !gg && !bb) cout << "red";
		if(!rr && gg && bb) cout << "aqua";
		if(!rr && gg && !bb) cout << "lime";
		if(!rr && !gg && bb) cout << "blue";
		if(!rr && !gg && !bb) cout << "black";
		cout << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int color[8][3],i,j,k,rgb[3],min,c,d,r,g,b;
	color[0][0]=0; color[0][1]=0; color[0][2]=0;
	color[1][0]=0; color[1][1]=0; color[1][2]=255;
	color[2][0]=0; color[2][1]=255; color[2][2]=0;
	color[3][0]=0; color[3][1]=255; color[3][2]=255;
	color[4][0]=255; color[4][1]=0; color[4][2]=0;
	color[5][0]=255; color[5][1]=0; color[5][2]=255;
	color[6][0]=255; color[6][1]=255; color[6][2]=0;
	color[7][0]=255; color[7][1]=255; color[7][2]=255;
	char a[]="0123456789abcdef",s[8];
	while(1){
		for(i=0;i<3;i++)rgb[i]=0;
		cin>>s;
		if(s[0]=='0') break;
		i=0;
		for(j=1;j<6;j+=2){
			for(k=0;k<16;k++){
				if(s[j]==a[k]){
					rgb[i]=rgb[i]+k*16;
					break;
				}
			}
			for(k=0;k<17;k++){
				if(s[j+1]==a[k]){
					rgb[i]=rgb[i]+k;
					break;
				}
			}
			i++;
		}
		min=1000000;
		for(i=0;i<8;i++){
			r=color[i][0]-rgb[0];
			g=color[i][1]-rgb[1];
			b=color[i][2]-rgb[2];
			d=r*r+g*g+b*b;
			if(min>d){
				min=d;
				c=i;
			}
		}
		if(c==0) cout<<"black"<<endl;
		if(c==1) cout<<"blue"<<endl;
		if(c==2) cout<<"lime"<<endl;
		if(c==3) cout<<"aqua"<<endl;
		if(c==4) cout<<"red"<<endl;
		if(c==5) cout<<"fuchsia"<<endl;
		if(c==6) cout<<"yellow"<<endl;
		if(c==7) cout<<"white"<<endl;
//		printf("%d %d %d\n",rgb[0],rgb[1],rgb[2]);
	}
	return 0;
}