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 <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <cfloat>
#include <algorithm>
#include <cmath>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

struct C {
	int r, g, b;
};

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

int main() {
	vector<C> t {{0x00, 0x00, 0x00}, {0x00, 0x00, 0xff}, {0x00, 0xff, 0x00}, {0x00, 0xff, 0xff},
		{0xff, 0x00, 0x00}, {0xff, 0x00, 0xff}, {0xff, 0xff, 0x00}, {0xff, 0xff, 0xff}};
	vector<string> S{"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
	for (int r, g, b; scanf("#%2x%2x%2x\n", &r, &g, &b);) {
		double m {DBL_MAX}, i {};
		for (int j: range(t.size())) {
			double s = sqrt(sq(r - t[j].r) + sq(g - t[j].g) + sq(b - t[j].b));
			if (s < m)
				m = s, i = j;
		}
		outl(S[i]);
	}
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define c(a,b,c,d,e,f) (a-d)*(a-d)+(b-e)*(b-e)+(c-f)*(c-f)
using namespace std;
int f(string s){
  int n=0;
  if('a'<=s[0]&&s[0]<='f')
    n+=(s[0]-'a'+10)*16;
  else
    n+=(s[0]-'0')*16;
  if('a'<=s[1]&&s[1]<='f')
    n+=s[1]-'a'+10;
  else
    n+=s[1]-'0';
  return n;
}
int main(){
  int i;
  int r[8]={0,0,0,0,0xff,0xff,0xff,0xff},g[8]={0,0,0xff,0xff,0,0,0xff,0xff},b[8]={0,0xff,0,0xff,0,0xff,0,0xff};
  int d,e;
  string s[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"},t;
  for(;;){
    cin>>t;
    if(t=="0")
      break;
    d=255*255*3;
    for(i=0;i<8;i++){
      if(d>c(f(t.substr(1,2)),f(t.substr(3,2)),f(t.substr(5,2)),r[i],g[i],b[i])){
	e=i;
	d=c(f(t.substr(1,2)),f(t.substr(3,2)),f(t.substr(5,2)),r[i],g[i],b[i]);
      }
    }
    cout<<s[e]<<endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int btoh(string s){
    if(s.size()!=2)cout<<"error"<<endl;
    int ret=0;
    if('0'<=s[1]&&s[1]<='9')ret+=(s[1]-'0');
    else{
        ret+=10+(int)(s[1]-'a');
    }
    if('0'<=s[0]&&s[0]<='9')ret+=(s[0]-'0')*16;
    else{
        ret+=(10+(int)(s[0]-'a'))*16;
    }
    return ret;
}

double solve(string a,string b,string c,string d,string e,string f){
    int x,y,z;
//    cout<<btoh(a)<<" "<<btoh(b)<<" "<<btoh(c)<<" "<<btoh(d)<<" "<<btoh(e)<<" "<<btoh(f)<<endl;
    x=(btoh(a)-btoh(d)) * (btoh(a)-btoh(d));
    y=(btoh(b)-btoh(e)) * (btoh(b)-btoh(e));
    z=(btoh(c)-btoh(f)) * (btoh(c)-btoh(f));
    
    return sqrt(x+y+z);
}

int main(){
//    string color = {"black","blue",}
    string s;
    while(cin>>s){
        if(s=="0")break;
        string a,b,c;
        a=s.substr(1,2);
        b=s.substr(3,2);
        c=s.substr(5,2);
        string ans="";
        double d=INF;
        
        double t=solve(a,b,c,"00","00","00");
        if(t<d){
            d=t;
            ans="black";
        }
        
        t=solve(a,b,c,"00","00","ff");
        if(t<d){
            d=t;
            ans="blue";
        }
        
        t=solve(a,b,c,"00","ff","00");
        if(t<d){
            d=t;
            ans="lime";
        }
        
        t=solve(a,b,c,"00","ff","ff");
        if(t<d){
            d=t;
            ans="aqua";
        }
        
        t=solve(a,b,c,"ff","00","00");
        if(t<d){
            d=t;
            ans="red";
        }
        
        t=solve(a,b,c,"ff","00","ff");
        if(t<d){
            d=t;
            ans="fuchsia";
        }
        
        t=solve(a,b,c,"ff","ff","00");
        if(t<d){
            d=t;
            ans="yellow";
        }
        
        t=solve(a,b,c,"ff","ff","ff");
        if(t<d){
            d=t;
            ans="white";
        }
        cout<<ans<<endl;
    }
}

/*
 black	00	00	00
 blue	00	00	ff
 lime	00	ff	00
 aqua	00	ff	ff
 red	ff	00	00
 fuchsiaff	00	ff
 yellow	ff	ff	00
 white	ff	ff	ff

 */