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>
#include<cmath>
using namespace std;
#define N 8
string table[N] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
struct Color{ string R, G, B;};

Color colors[N];

int convert(string hex){
    int p = 1, sum = 0;
    for ( int i = hex.size()-1; i >= 0; i--, p *= 16 ){
	sum += p*((isdigit(hex[i]))?(hex[i]-'0'):(hex[i]-'a'+10));
    }
    return sum;
}

double getDistance(Color c1, Color c2){
    int dr = convert(c1.R) - convert(c2.R);
    int dg = convert(c1.G) - convert(c2.G);
    int db = convert(c1.B) - convert(c2.B);
    return sqrt(dr*dr + dg*dg + db*db);
}

main(){
    for ( int i = 0; i < N; i++ ) colors[i].R = colors[i].G = colors[i].B = "00";
    colors[1].B = "ff";
    colors[2].G = "ff";
    colors[3].B = "ff";
    colors[3].G = "ff";
    colors[4].R = "ff";
    colors[5].R = "ff";
    colors[5].B = "ff";
    colors[6].R = "ff";
    colors[6].G = "ff";
    colors[7].R = "ff";
    colors[7].G = "ff";
    colors[7].B = "ff";
    string hex;
    while( cin >> hex && hex != "0"){
	string ans = "";
	double sub = (1<<30);
	Color target;
	target.R = hex.substr(1, 2);
	target.G = hex.substr(3, 2);
	target.B = hex.substr(5, 2);
	for ( int i = 0; i < N; i++ ){
	    double d = getDistance(colors[i], target);
	    if ( d < sub ){
		sub = d;
		ans = table[i];
	    }
	}
	cout << ans << endl;
    }
}

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";
  }


}

C++: #include<iostream>
#include<cmath>
#include<string>
#define sq(a) ((a)*(a))
using namespace std;

int Conv(char c1, char c2){
	return (c1-'0')*0x10 + (c2-'0');
}
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;
		string s;
		cin>>s;
		if(s.compare("0")==0)break;
		R = Conv(s[1],s[2]); G = Conv(s[3],s[4]); B = Conv(s[5],s[6]);
		cout << judge(R,G,B) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cmath>

using namespace std;

int colorCalc(char c1, char c2)
{
	int color = 0;
	if('a' <= c1 && c1 <= 'f')
	{
		color += (c1 - 'a' + 10) * 16;
	}
	else
	{
		color += (c1 - '0') * 16;
	}
	if('a' <= c2 && c2 <= 'f')
	{
		color += c2 - 'a' + 10;
	}
	else
	{
		color += c2 - '0';
	}
	return(color);
}
void solve()
{
	int colors[9][4] = {{{0},   {0},   {0}}, 
						{{0},   {0},   {255}}, 
						{{0},   {255}, {0}}, 
						{{0},   {255}, {255}}, 
						{{255}, {0},   {0}}, 
						{{255}, {0},   {255}}, 
						{{255}, {255}, {0}}, 
						{{255}, {255}, {255}}};
	string name[9] = {"black", 
					  "blue", 
					  "lime", 
					  "aqua", 
					  "red", 
					  "fuchsia", 
					  "yellow", 
					  "white"};
	string str;
	while(cin >> str, str != "0")
	{
		int r = colorCalc(str[1], str[2]);
		int g = colorCalc(str[3], str[4]);
		int b = colorCalc(str[5], str[6]);
		int min = 999999999;
		int label = 0;
		for(int i = 0; i < 8; ++i)
		{
			int sum = sqrt((double)(r - colors[i][0]) * (r - colors[i][0]) + (g - colors[i][1]) * (g - colors[i][1]) + (b - colors[i][2]) * (b - colors[i][2]));
			if(sum < min)
			{
				min = sum;
				label = i;
			}
		}
		cout << name[label] << endl;
	}
}

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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  string color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
  string s;
  while(cin >> s, s!="0") {
    int rgb[3];
    REP(i,3)
      sscanf(s.substr(i*2+1,2).c_str(), "%x", rgb+i);
    
    int mi = INF;
    int ans;
    REP(i,8) {
      int hoge = 0;
      REP(j,3) {
        if (i>>j & 1)
          hoge += pow(255 - rgb[j], 2);
        else
          hoge += pow(rgb[j], 2);
      }
      if (hoge < mi) {
        mi = hoge;
        ans = i;
      }
    }
    cout << color[ans] << endl;
  }
}