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 <string>
using namespace std;

const int MAX_C = 8;

int main() {
	pair< int, string > colors[MAX_C] = {
		make_pair< int, string >(0x000000, "black"),
		make_pair< int, string >(0x0000ff, "blue"),
		make_pair< int, string >(0x00ff00, "lime"),
		make_pair< int, string >(0x00ffff, "aqua"),
		make_pair< int, string >(0xff0000, "red"),
		make_pair< int, string >(0xff00ff, "fuchsia"),
		make_pair< int, string >(0xffff00, "yellow"),
		make_pair< int, string >(0xffffff, "white")
	};
	string color, cname;
	int r, g, b, _r, _g, _b, min, dist;
	
	while(cin >> color, color != "0"){
		r = stoi(color.substr(1, 2), nullptr, 16);
		g = stoi(color.substr(3, 2), nullptr, 16);
		b = stoi(color.substr(5, 2), nullptr, 16);
		
		min = ~(1 << 31);
		cname;
		
		for(int i = 0; i < MAX_C; ++i){
			_r = (colors[i].first & 0xff0000) >> 16;
			_g = (colors[i].first & 0x00ff00) >> 8;
			_b = (colors[i].first & 0x0000ff);
			
			dist = (r - _r) * (r - _r) + (g - _g) * (g - _g) + (b - _b) * (b - _b);
			
			if(dist < min){
				min = dist;
				cname = colors[i].second;
			}
		}
		cout << cname << endl;
	}
	return 0;
}

C++: // 2011/08/21 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string clr;
		cin >> clr;
		if(clr=="0")		// ツ閉カツ篠堋療ア
			break;

		if(clr[1]>='0'&&clr[1]<='7')
			if(clr[3]>='0'&&clr[3]<='7')
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "black" << endl;
				else
					cout << "blue" << endl;
			else
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "lime" << endl;
				else
					cout << "aqua" << endl;
		else
			if(clr[3]>='0'&&clr[3]<='7')
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "red" << endl;
				else
					cout << "fuchsia" << endl;
			else
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "yellow" << endl;
				else
					cout << "white" << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
int hextodec(char h){
  int res;
  if(h >= '0' && h <= '9')
    res = h - '0';
  else
    res = h - 'a' + 10;
  return res;
}

int main(){
  int color[8][3] = {{0, 0, 0}, {0, 0, 256}, {0, 256, 0},
                     {0, 256, 256}, {256, 0, 0}, {256, 0, 256},
                     {256, 256, 0}, {256, 256, 256}};
  std::string name[8] = {"black", "blue", "lime",
                         "aqua", "red", "fuchsia",
                         "yellow", "white"};

  std::string c;
  while(std::cin >> c, c.compare("0")){
    int r = hextodec(c[1]) * 16 + hextodec(c[2]),
        g = hextodec(c[3]) * 16 + hextodec(c[4]),
        b = hextodec(c[5]) * 16 + hextodec(c[6]);
    int min_v = 1000000, min_c;
    for(int i=7;i>=0;i--){
      if(color[i][0] == r && color[i][1] == g && color[i][2] == b){
        min_c = i; break;
      }
      int t = pow(r-color[i][0], 2) + pow(g-color[i][1], 2) +
              pow(b-color[i][2], 2);
      if(min_v > t)min_v = t, min_c = i;
    }
    std::cout << name[min_c] << std::endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <sstream>
#include <climits>
//#include <fstream>

using namespace std;

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

int main()
{
	const string color[] = {
"black",//	 00	 00	 00
"blue",//	 00	 00	 ff
"lime",//	 00	 ff	 00
"aqua",//	 00	 ff	 ff
"red",//	 ff	 00	 00
"fuchsia",// ff	 00	 ff
"yellow",//	 ff	 ff	 00
"white"//	 ff	 ff	 ff
};
	const int code[][3] = {
/* black */	 {0x00, 0x00, 0x00 },
/* blue */	 {0x00, 0x00,	0xff },
/* lime */	 {0x00, 0xff,	0x00 },
/* aqua */	 {0x00, 0xff,	0xff },
/* red	*/	 {0xff, 0x00,	0x00 },
/* fuchsia */  {0xff, 0x00,	0xff },
/* yellow */	 {0xff, 0xff,	0x00 },
/* white */	 {0xff, 0xff,	0xff }
};

//	cut here before submit 
//	freopen ("testcase.whatcolor", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){
		int len = str.length();

		if (len == 1 && str[0] == '0'){
			break;
		} // end if

		vector <int> C (3, 0 ); // Red, Green, Blue order
		int i,j;

		for (i = 0; i < 3; ++i){
			C[i] = hex2dec(str[2*i+1])*16 + hex2dec(str[2*i+2]);
		} // end for

		int minV = INT_MAX;
		int res = -1;
		for (i = 0; i	< sizeof (color)/sizeof(color[0] ); ++i){
			int dd = 0;
			for (j = 0; j < 3; ++j){
				dd += (code[i][j] - C[j])*(code[i][j] - C[j]);
			} // end for
			
			if (minV > dd ){
				minV = dd;
				res = i;
			} // end if
		} // end for
		
		cout << color[res] << endl;

	} // end loop
		
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int main(void){
  int col;
  char c;
  while(cin>>c>>hex>>col){
    if(c=='0') break;
    int data[3];
    REP(i,3){
      data[i] = col%256;
      col/=256;
    }
    bool judge[3];
    REP(i,3){
      if(255-data[2-i]<data[2-i]){
        judge[i] = false;
      }else{
        judge[i] = true;
      }
    }
    if(judge[0]){
      if(judge[1]){
        if(judge[2]){
          cout<<"black"<<endl;
        }else{
          cout<<"blue"<<endl;
        }
      }else{
        if(judge[2]){
          cout<<"lime"<<endl;
        }else{
          cout<<"aqua"<<endl;
        }
      }
    }else{
      if(judge[1]){
        if(judge[2]){
          cout<<"red"<<endl;
        }else{
          cout<<"fuchsia"<<endl;
        }
      }else{
        if(judge[2]){
          cout<<"yellow"<<endl;
        }else{
          cout<<"white"<<endl;
        }
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int in[256]={0};
int han[3][8]={
  {0,0,0,0,256,256,256,256},
  {0,0,256,256,0,0,256,256},
  {0,256,0,256,0,256,0,256}
};
string ss[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string s;
  loop(i,'0','9'+1)in[i]=i-'0';
  loop(i,'a','g')in[i]=i-'a'+10;
  while(cin>>s,s.size()!=1||s[0]!='0'){
    int a[3]={0};
    rep(i,3){
      a[i]=in[s[2*i+1]]*16+in[s[2*i+2]];
    }
    long long int mi=1000000000;
    int ms;
    rep(i,8){
      long long int sum=0;
      rep(j,3)sum+=(han[j][i]-a[j])*(han[j][i]-a[j]);
      if(mi>sum){
	ms=i;
	mi=sum;
      }
    }
    cout<<ss[ms]<<endl;
  }

}