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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int foo(int a,int b,int c){
    int t=a*a+b*b+c*c;
    return t;
}
void mainmain(){
    vector<string> v;
    v.PB("black");
    v.PB("blue");
    v.PB("lime");
    v.PB("aqua");
    v.PB("red");
    v.PB("fuchsia");
    v.PB("yellow");
    v.PB("white");
    string s;
    while(cin>>s){
        if(s.size()==1) return;
        vint w(3,0);
        rep(i,3){
            string tmp=s.substr(1+i*2,2);
            if(isdigit(tmp[0])) w[i]=16*(tmp[0]-'0');
            else{
                w[i]=16*(tmp[0]-'a'+10);
            }
            if(isdigit(tmp[1])) w[i]+=(tmp[1]-'0');
            else{
                w[i]+=(tmp[1]-'a'+10);
            }
        }
        // cout<<w[0]<<" "<<w[1]<<" "<<w[2]<<endl;
        vector<pii> vv(8);
        rep(i,8){
            vint tmp(3);
            rep(j,3){
                if((1<<j)&i) tmp[j]=255;
                else tmp[j]=0;
            }
            vv[i].S=i;
            vv[i].F=foo(w[0]-tmp[0],w[1]-tmp[1],w[2]-tmp[2]);
        }
        sort(ALL(vv));
        cout<<v[vv[0].S]<<endl;
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
      cout<<fixed<<setprecision(20);
    mainmain();
}

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

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

int conv(char a, char b) {
  return conv(a)*16 + conv(b);
}

int main() {
  string str;
  int c[3], d, m, ans;
  int cc[8][3] = {{0, 0, 0}, {0, 0, 0xff}, {0, 0xff, 0}, {0, 0xff, 0xff},
                  {0xff, 0, 0}, {0xff, 0, 0xff}, {0xff, 0xff, 0}, {0xff, 0xff, 0xff}};
  const char *label[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

  while (1) {
    cin >> str;
    if (str == "0") break;
    for (int i=0; i<3; i++) {
      c[i] = conv(str.at(2*i+1), str.at(2*i+2));
    }
    m = INT_MAX;
    ans = -1;
    for (int i=0; i<8; i++) {
      d = 0;
      for (int j=0; j<3; j++) {
        d += (c[j]-cc[i][j])*(c[j]-cc[i][j]);
      }
      if (m > d) {
        m = d;
        ans = i;
      }
    }
    cout << label[ans] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long i,j,k;
string s,c[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
while(cin>>s){
if(s=="0")break;
k=0;
i=s[1]-48;if(s[1]>64)i-=39;
j=s[2]-48;if(s[2]>64)j-=39;
if(i*16+j>=128)k+=4;
i=s[3]-48;if(s[3]>64)i-=39;
j=s[4]-48;if(s[4]>64)j-=39;
if(i*16+j>=128)k+=2;
i=s[5]-48;if(s[5]>64)i-=39;
j=s[6]-48;if(s[6]>64)j-=39;
if(i*16+j>=128)k++;
cout<<c[k]<<endl;
}
return 0;
}

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

class Col
{
public:
  int R,G,B;
  Col():R(0),G(0),B(0){}
  Col(int R,int G,int B):R(R),G(G),B(B){}
};

int _16to10(string s)
{
  int a[2];
  for(int i=0;i<2;i++)
    {
      if(s[i] == 'a')
	a[i] = 10;
      else if(s[i] == 'b')
	a[i] = 11;
      else if(s[i] == 'c')
	a[i] = 12;
      else if(s[i] == 'd')
	a[i] = 13;
      else if(s[i] == 'e')
	a[i] = 14;
      else if(s[i] == 'f')
	a[i] = 15;
      else 
	a[i] = s[i] - '0';
    }
  return a[1]+a[0]*16;
}

int main()
{
  string s;
  vector<Col> vec;
  vector<string> name;
  vec.resize(8),name.resize(8);
  int ff = _16to10("ff");
  vec[0] = Col(0,0,0);
  vec[1] = Col(0,0,ff);
  vec[2] = Col(0,ff,0);
  vec[3] = Col(0,ff,ff);
  vec[4] = Col(ff,0,0);
  vec[5] = Col(ff,0,ff);
  vec[6] = Col(ff,ff,0);
  vec[7] = Col(ff,ff,ff);
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";
  while(true)
    {
      cin >> s;
      if(s == "0")
	break;
      int R,G,B;
      R = _16to10(s.substr(1,2));
      G = _16to10(s.substr(3,2));
      B = _16to10(s.substr(5,2));

      int men = (1<<28),pos = -1;
      for(int i=0;i<8;i++)
	{
	  int d =  sqrt(pow(R-vec[i].R,2)+pow(B-vec[i].B,2)+pow(G-vec[i].G,2));
	  if(men > d)
	    {
	      men = d;
	      pos = i;
	    }
	}
      cout << name[pos] << endl;

    }
  return 0;
}