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<stdio.h>
using namespace std;

int main(){

string st;
int Z[][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}};

while(1){
cin>>st;if(st=="0")break;


int k[3]={};
int n[10]={};
for(int i=1;i<7;i++){
n[i]=st[i]-'0';
if(st[i]=='a')n[i]=10;
if(st[i]=='b')n[i]=11;
if(st[i]=='c')n[i]=12;
if(st[i]=='d')n[i]=13;
if(st[i]=='e')n[i]=14;
if(st[i]=='f')n[i]=15;
}

k[0]=n[1]*16+n[2];
k[1]=n[3]*16+n[4];
k[2]=n[5]*16+n[6];

int N[10]={};int min=90000;int t=0;
for(int i=0;i<8;i++)
{
N[i]=(Z[i][0]-k[0])*(Z[i][0]-k[0])+(Z[i][1]-k[1])*(Z[i][1]-k[1])+(Z[i][2]-k[2])*(Z[i][2]-k[2]);
if(min>N[i]){t=i;min=N[i];}
//cout<<N[i]<<endl;
}
if(t==0)cout<<"black";
if(t==1)cout<<"blue";
if(t==2)cout<<"lime";
if(t==3)cout<<"aqua";
if(t==4)cout<<"red";
if(t==5)cout<<"fuchsia";
if(t==6)cout<<"yellow";
if(t==7)cout<<"white";
cout<<endl;


}
return 0;
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int d(string s,int color[3]){
  int red=0,blue=0,green=0;
  if(!isdigit(s[1]))red+=(s[1]-'a'+10)*16;
  else red+=(s[1]-'0')*16;
  if(!isdigit(s[2]))red+=(s[2]-'a'+10);
  else red+=(s[2]-'0');
  if(!isdigit(s[3]))green+=(s[3]-'a'+10)*16;
  else green+=(s[3]-'0')*16;
  if(!isdigit(s[4]))green+=(s[4]-'a'+10);
  else green+=(s[4]-'0');
  if(!isdigit(s[5]))blue+=(s[5]-'a'+10)*16;
  else blue+=(s[5]-'0')*16;
  if(!isdigit(s[6]))blue+=(s[6]-'a'+10);
  else blue+=(s[6]-'0');
  return pow((red-color[0]),2)+pow((green-color[1]),2)+pow((blue-color[2]),2);
}

int cl[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 main(){
  string str;
  while(1){
    cin>>str;
    if(str=="0")break;
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(str,cl[i])){
	if(i==0)ans="black";
	else if(i==1)ans="blue";
	else if(i==2)ans="lime";
	else if(i==3)ans="aqua";
	else if(i==4)ans="red";
	else if(i==5)ans="fuchsia";
	else if(i==6)ans="yellow";
	else if(i==7)ans="white";
	num=d(str,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int Conv(char c1, char c2){
	return (c1-'0')*0x10 + (c2-'0');
}
double dist(int R, int G, int B, int rR, int rG, int rB){
	return sqrt( pow(R-rR,2.0) + pow(G-rG,2.0) + pow(B-rB,2.0) );
}
string judge(int R, int G, int B ){
	double min_dist = 65536;
	string color;

	double 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 <string>
#include <cmath>
using namespace std;

const int INF = 1 << 28;

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

int main ()
{
    int R[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
    int G[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff};
    int B[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff};
    string color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

    string str;
    while (cin >> str, str != "0") {
        int r = to_hex(str[1]) * 16 + to_hex(str[2]);
        int g = to_hex(str[3]) * 16 + to_hex(str[4]);
        int b = to_hex(str[5]) * 16 + to_hex(str[6]);

        int D = INF;
        string res;
        for (int i = 0; i < 8; i++) {
            int d = ((R[i] - r) * (R[i] - r) + (G[i] - g) * (G[i] - g) + (B[i] - b) * (B[i] - b));
            if (d < D) {
                res = color[i];
                D = d;
            }
        }
        cout << res << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <string>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

using namespace std;

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

int main(){
    char c[10];
    while(cin>>c && c[0]!='0'){
        unsigned md=1<<30;
        int cn;
        unsigned cd=strtoul(c+1,0,16);
        rep(i,8){
            unsigned d=0;
            rep(j,3){
                static const unsigned cc[]={0x0,0xff,0xff00,0xffff,0xff0000,0xff00ff,0xffff00,0xffffff};
                d+=sq((cd>>j*8&0xFF)-(cc[i]>>j*8&0xFF));
            }
            if(d<md){
                md=d;
                cn=i;
            }
        }

        const string cstr[]= {
            "black",
            "blue",
            "lime",
            "aqua",
            "red",
            "fuchsia",
            "yellow",
            "white"
        };
        cout<<cstr[cn]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<double, int> pdi;

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

string color[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };

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

int main() {
	string str;
	while (cin >> str, str != "0") {
		int c[3];
		REP(i, 3) { c[i] = 16 * calc(str[1 + i * 2]) + calc(str[1 + i * 2 + 1]); }
		
		vector<pdi> ans;
		REP(i, 8) {
			double d = 0.0;
			REP(j, 3) d += pow(lis[i][j] - c[j], 2.0);
			d = sqrt(d);
			ans.push_back(pdi(d, i));
		}
		sort(ans.begin(), ans.end());
		cout << color[ans[0].second] << endl;
	}
	return 0;
}