Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Color struct {
	name    string
	R, G, B int64
}

func main() {
	colors := []Color{
		{"black", 0, 0, 0},
		{"blue", 0, 0, 0xff},
		{"lime", 0, 0xff, 0},
		{"aqua", 0, 0xff, 0xff},
		{"red", 0xff, 0, 0},
		{"fuchsia", 0xff, 0, 0xff},
		{"yellow", 0xff, 0xff, 0},
		{"white", 0xff, 0xff, 0xff},
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), "")
		if buf[0] == "0" {
			break
		}
		r, _ := strconv.ParseInt(strings.Join(buf[1:3], ""), 16, 64)
		g, _ := strconv.ParseInt(strings.Join(buf[3:5], ""), 16, 64)
		b, _ := strconv.ParseInt(strings.Join(buf[5:], ""), 16, 64)
		vmin := int64(3*0xff*0xff)
		var ans string
		for _, c := range colors {
			d := (r-c.R)*(r-c.R) + (g-c.G)*(g-c.G) + (b-c.B)*(b-c.B)
			if d < vmin {
				vmin = d
				ans = c.name
			}
		}
		fmt.Println(ans)
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int a[6],c[3],d[8][3];
string s,na[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int main(){
	for(int i=0;i<8;i++){
		d[i][0]=i/4*255;
		d[i][1]=(i/2)%2*255;
		d[i][2]=i%2*255;
	}
	while(cin>>s){
		if(s=="0")return 0;
		for(int i=1;i<7;i++){
			if(isdigit(s[i]))a[i-1]=s[i]-'0';
			else a[i-1]=s[i]-'a'+10;
			if(!(i%2))c[i/2-1]=a[i-1]+a[i-2]*16;
		}
		int df=999999,no;
		for(int i=0;i<8;i++){
			int sum=0;
			for(int j=0;j<3;j++)sum+=(c[j]-d[i][j])*(c[j]-d[i][j]);
			if(sum<df){no=i;df=sum;}
		}
		cout<<na[no]<<endl;
	}
}

C++: #include <stdio.h>

const char *t[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int solve(int r, int g, int b){
    int min = 0; int mind = 200000;
    for(int i = 0; i < 8; i++){
        int r0 = ((i>>2)&1)*0xff, g0 = ((i>>1)&1)*0xff, b0 = ((i>>0)&1)*0xff;
        //pf("%d,%d,%d : %d,%d,%d\n", r,g,b,r0,g0,b0);
        int d = (r-r0)*(r-r0)+(g-g0)*(g-g0)+(b-b0)*(b-b0);
        if(mind > d){
            mind = d, min = i;
        }
    }
    if(min >= 8) throw;
    return min;
}

int main(){
    int n;
    char buf[16];
    while(fgets(buf,sizeof(buf),stdin)){
        if(buf[0] == '0') break;
        sscanf(buf+1,"%x",&n);
        int i = solve((n>>16)&0xff,(n>>8)&0xff,n&0xff);
        printf("%s\n", t[i]);
    }
    return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
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;
}


#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 MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
map<char,int> ma;
void mainmain(){
	rep(i,10){
		ma[(char)(i+'0')]=i;
	}
	char a[]={'a','b','c','d','e','f'};
	rep(i,6){
		ma[a[i]]=i+10;
	}
	string s;
	int r[]={0,0,0,0,1,1,1,1};
	int g[]={0,0,1,1,0,0,1,1};
	int b[]={0,1,0,1,0,1,0,1};
	string ans[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	while(cin>>s,s[0]!='0'){
		int rr=0,gg=0,bb=0;
		rr=ma[s[1]]*16+ma[s[2]];
		gg=ma[s[3]]*16+ma[s[4]];
		bb=ma[s[5]]*16+ma[s[6]];
		int c=-1;
		int d=INF;
		rep(i,8){
			int t=(rr-r[i]*256)*(rr-r[i]*256)+(gg-g[i]*256)*(gg-g[i]*256)+(bb-b[i]*256)*(bb-b[i]*256);
			if(t<d){
				d=t;
				c=i;
			}
		}
		cout<<ans[c]<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include <iostream>
#include <string>	

using namespace std;
struct color
{
	string str;
	int RGB[3];
};

void solve()
{
	color Color[8];
	Color[0].str = "black";
	Color[0].RGB[0] = 0;	Color[0].RGB[1] = 0;	Color[0].RGB[2] = 0;
	Color[1].str = "blue";
	Color[1].RGB[0] = 0;	Color[1].RGB[1] = 0;	Color[1].RGB[2] = 255;
	Color[2].str = "lime";
	Color[2].RGB[0] = 0;	Color[2].RGB[1] = 255;	Color[2].RGB[2] = 0;
	Color[3].str = "aqua";
	Color[3].RGB[0] = 0;	Color[3].RGB[1] = 255;	Color[3].RGB[2] = 255;
	Color[4].str = "red";
	Color[4].RGB[0] = 255;	Color[4].RGB[1] = 0;	Color[4].RGB[2] = 0;
	Color[5].str = "fuchsia";
	Color[5].RGB[0] = 255;	Color[5].RGB[1] = 0;	Color[5].RGB[2] = 255;
	Color[6].str = "yellow";
	Color[6].RGB[0] = 255;	Color[6].RGB[1] = 255;	Color[6].RGB[2] = 0;
	Color[7].str = "white";
	Color[7].RGB[0] = 255;	Color[7].RGB[1] = 255;	Color[7].RGB[2] = 255;

	string str;
	while(cin >> str, str[0] != '0')
	{
		int C[3] = {0};
		for(int i = 0; i < 3; ++i)
		{
			if('a' <= str[2 * i + 1] && str[2 * i + 1] <= 'f')
			{
				C[i] += (str[2 * i + 1] - 'a' + 10) * 16;
			}
			else if('0' <= str[2 * i + 1] && str[2 * i + 1] <= '9')
			{
				C[i] += (str[2 * i + 1] - '0') * 16;
			}
		}
		for(int i = 1; i < 4; ++i)
		{
			if('a' <= str[2 * i] && str[2 * i] <= 'f')
			{
				C[i - 1] += str[2 * i] - 'a' + 10;
			}
			else if('0' <= str[2 * i] && str[2 * i] <= '9')
			{
				C[i - 1] += str[2 * i] - '0';
			}
		}
		int index = 0;
		int dist = 0;
		int min = 999999999;
		for(int i = 0; i < 8; ++i)
		{
			dist = (C[0] - Color[i].RGB[0]) * (C[0] - Color[i].RGB[0])
				 + (C[1] - Color[i].RGB[1]) * (C[1] - Color[i].RGB[1])
				 + (C[2] - Color[i].RGB[2]) * (C[2] - Color[i].RGB[2]);
			if(dist < min)
			{
				min = dist;
				index = i;
			}
		}
		cout << Color[index].str << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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


int tmp[2] = {16,1};
string s[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int hoge[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}};

int to_ten(string s){
  int ans=0;
  for(int i=0; i<2; i++){
    if(s[i] == 'a') ans += 10*tmp[i];
    else if(s[i] == 'b') ans += 11*tmp[i];
    else if(s[i] == 'c') ans += 12*tmp[i];
    else if(s[i] == 'd') ans += 13*tmp[i];
    else if(s[i] == 'e') ans += 14*tmp[i];
    else if(s[i] == 'f') ans += 15*tmp[i];
    else ans += stoi(s.substr(i,1))*tmp[i];
  }
  return ans;
}

double d(string r,string g,string b,int i){
  double ans = 0;
  ans += (to_ten(r) - hoge[i][0]) * (to_ten(r) - hoge[i][0]);
  ans += (to_ten(g) - hoge[i][1]) * (to_ten(g) - hoge[i][1]);
  ans += (to_ten(b) - hoge[i][2]) * (to_ten(b) - hoge[i][2]);
  return ans;
}

int main(){


  while(1){
    string in; cin >> in;
    if(in == "0") break;
    string r = in.substr(1,2);
    string g = in.substr(3,2);
    string b = in.substr(5,2);

    double min = (int)1e+308;
    int index=100;
    for(int i=0; i<8; i++){
      if(d(r,g,b,i) < min ){
	index = i;
	min = d(r,g,b,i);
      }
      //   cout  << d(r,g,b,i) << " ";
    }
    cout << s[index] << "\n";
  }


}