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>
using namespace std;
string S, x[2][2][2] = { {{"black","blue"}, {"lime","aqua"}}, { {"red","fuchsia"}, {"yellow","white"} } };
char T[9] = "89abcdef";
int a, b, c;
int main() {
	while (true) {
		a = 0; b = 0; c = 0;
		cin >> S;
		if (S == "0") { break; }
		for (int i = 0; i < 8; i++){
			if (T[i] == S[1]) {
				a = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[3]) {
				b = 1;
			}
		}
		for (int i = 0; i < 8; i++) {
			if (T[i] == S[5]) {
				c = 1;
			}
		}
		cout << x[a][b][c] << endl;
	}
}

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

const int INF = 1 << 28;

int main ()
{
    int R[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
    int G[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff};
    int B[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff};
    string color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

    string str;
    while (cin >> str, str != "0") {
        int r = (str[1] - '0') * 16 + (str[2] - '0');
        int g = (str[3] - '0') * 16 + (str[4] - '0');
        int b = (str[5] - '0') * 16 + (str[6] - '0');

        double D = INF;
        string res;
        for (int i = 0; i < 8; i++) {
            double d = sqrt((R[i] - r) * (R[i] - r) + (G[i] - g) * (G[i] - g) + (B[i] - b) * (B[i] - b));
            if (d < D) {
                res = color[i];
                D = d;
            }
        }
        cout << res << endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
string str;
string ta[8] = {"black","blue","lime","aqua",
		"red","fuchsia","yellow","white"};

string tb[8] = {"#000000","#0000ff","#00ff00","#00ffff",
                "#ff0000","#ff00ff","#ffff00","#ffffff"};
int tab[8];
int mini,miniNo;

/*
string d(int in){
  if(in==0)return "0";  if(in==8)return "8";
  if(in==1)return "1";  if(in==9)return "9";
  if(in==2)return "2";  if(in==15)return "f";
  if(in==3)return "3";  if(in==14)return "e";
  if(in==4)return "4";  if(in==13)return "d";
  if(in==5)return "5";  if(in==12)return "c";
  if(in==6)return "6";  if(in==11)return "b";
  if(in==7)return "7";  if(in==1.)return "a";
}
*/
int c(char ch){
  if('a'<=ch&&ch<='f')return 10+(ch-'a');
  return ch-'0';
}

int b(string x,string y){
  int X = c(x[0])*16 + c(x[1]);
  int Y = c(y[0])*16 + c(y[1]);
  int Z = X - Y;
  //string z= d(Z/16)+d(Z%16);
  return Z*Z;
}
string compute(){
  
}
int main(){
  while(1){
    mini=99999;
    cin>>str;
    if(str=="0")break;
    for(int i=0;i<8;i++){
      tab[i] =b( tb[i].substr(1,2) , str.substr(1,2) );
      tab[i]+=b( tb[i].substr(3,2) , str.substr(3,2) );
      tab[i]+=b( tb[i].substr(5,2) , str.substr(5,2) );
      if(mini>tab[i]){
	mini=tab[i];
	miniNo=i;
      }
    }
    cout<<ta[miniNo]<<endl;
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

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

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

int main() {
	string str;
	while(cin>>str,str!="0"){
		int r,g,b;
		r=x(str[1])*16+x(str[2]);
		g=x(str[3])*16+x(str[4]);
		b=x(str[5])*16+x(str[6]);
//cout<<r<<" "<<g<<" "<<b<<endl;
		int i;
		string res="";
		int re=1000000000;
		for(i=0;i<8;i++){
			if(re>(r-(i&4?255:0))*(r-(i&4?255:0))+(g-(i&2?255:0))*(g-(i&2?255:0))+(b-(i&1?255:0))*(b-(i&1?255:0))){
				res=color[i];
				re=(r-(i&4?255:0))*(r-(i&4?255:0))+(g-(i&2?255:0))*(g-(i&2?255:0))+(b-(i&1?255:0))*(b-(i&1?255:0));
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cctype>
#define sq(a) ((a)*(a))
using namespace std;
int dist(int R, int G, int B, int rR, int rG, int rB){
	return sq(R-rR) + sq(G-rG) + sq(B-rB);
}
string judge(int R, int G, int B ){
	int min_dist = 1<<30;
	string color;

	int r;
	
	r = dist( R, G, B, 0, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "black";
	}
	r = dist( R, G, B, 0, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "blue";
	}
	r = dist( R, G, B, 0, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "lime";
	}
	r = dist( R, G, B, 0, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "aqua";
	}
	r = dist( R, G, B, 0xFF, 0, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "red";
	}
	r = dist( R, G, B, 0xFF, 0, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "fuchsia";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0 );
	if( min_dist > r ){
		min_dist = r;
		color = "yellow";
	}
	r = dist( R, G, B, 0xFF, 0xFF, 0xFF );
	if( min_dist > r ){
		min_dist = r;
		color = "white";
	}
	return color;
}

int main(){
	while( true ){
		int R;
		int G;
		int B;
		char c;
		string s;
		scanf("%c", &c);
		if( c=='0')break;
		scanf("%2x%2x%2x", &R, &G, &B);
		getline(cin,s);
		cout << judge(R,G,B) << endl;
	}
	return 0;
}