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<map>
using namespace std;
int main() {
	map <char, int>b;
	b.insert(map<char, int>::value_type('0', 0));
	b.insert(map<char, int>::value_type('1', 1));
	b.insert(map<char, int>::value_type('2', 2));
	b.insert(map<char, int>::value_type('3', 3));
	b.insert(map<char, int>::value_type('4', 4));
	b.insert(map<char, int>::value_type('5', 5));
	b.insert(map<char, int>::value_type('6', 6));
	b.insert(map<char, int>::value_type('7', 7));
	b.insert(map<char, int>::value_type('8', 8));
	b.insert(map<char, int>::value_type('9', 9));
	b.insert(map<char, int>::value_type('a', 10));
	b.insert(map<char, int>::value_type('b', 11));
	b.insert(map<char, int>::value_type('c', 12));
	b.insert(map<char, int>::value_type('d', 13));
	b.insert(map<char, int>::value_type('e', 14));
	b.insert(map<char, int>::value_type('f', 15));
	string d[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int e[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} };
	string a;
	while (cin >> a&&a != "0") {
		int sa = 10000, t[3];
		string iro;
		for (int i = 1; i < 7; i += 2) {
			char f = a[i], g = a[i + 1];
			t[(i - 1) / 2] = b[f]*16 + b[g];
		}
		for (int i = 7; i >= 0; i--) {
			int h = sqrt(pow((e[i][0] - t[0]), 2) + pow((e[i][1] - t[1]), 2) + pow((e[i][2] - t[2]), 2));
			if (h <= sa) {
				sa = h;
				iro = d[i];
			}
		}
		cout << iro << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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 sixteen[200]={};
    for(int i=0;i<10;i++)sixteen[i]=i;
    for(int i=0;i<6;i++)sixteen['a'-'0'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=sixteen[str[1+2*i]-'0']*16+sixteen[str[2+2*i]-'0'];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=pow(colornum[i][j]-num[j],2);
            ans[i]=sqrt(ans[i]);
        }
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}

C++: #include<iostream>
#include<cstdlib>
#include<cstdio>
#define w 15*16+15
using namespace std;
int fld[8][3]={0,0,0,0,0,w,0,w,
	0,0,w,w,w,0,0
	,w,0,w,w,w,0,w,w,w};
char* col[]={"black",
	"blue","lime","aqua",
	"red","fuchsia",
	"yellow","white"};
int main(){
	int temp,t,x,y,z,a[8],ren;
	char s[10];
	while(cin>>s,s[0]!='0'){
		temp=100000000;
		for(int i=1;i<8;i++){
			if(s[i]>'9')
			a[i-1]=9+s[i]-'a';
			else a[i-1]=s[i]-'0';
		}
		for(int i=0;i<8;i++){
			x=a[0]*16+a[1]-fld[i][0];
			y=a[2]*16+a[3]-fld[i][1];
			z=a[4]*16+a[5]-fld[i][2];
			ren=x*x+y*y+z*z;
			if(ren<temp){
				t=i;
				temp=ren;
			}
		}cout<<col[t]<<endl;
	}
	return 0;
}

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

using namespace std;

const double INF=10000;

double color[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
};
string colors[8]=
{"black",
"blue",
"lime",
"aqua",
"red",
"fuchsia",
"yellow",
"white"
};

int main(void){
	while(1){
		string str;
		cin >> str;
		if(str=="0")break;
		double c[3]={0,0,0};
		for(int i=0;i<3;i++){
			if(str[i*2+1]>='a' && str[i*2+1]<='f'){
				c[i]+=(str[i*2+1]-'a'+10)*16;
			}else c[i]+=(str[i*2+1]-'0')*16;
			if(str[i*2+2]>='a' && str[i*2+2]<='f'){
				c[i]+=str[i*2+2]-'a'+10;
			}else c[i]+=str[i*2+2]-'0';
		}
		double adk=INF;
		int ans=0;
		for(int i=0;i<8;i++){
			double dk=sqrt(pow(abs(c[0]-color[i][0]),2)+pow(abs(c[1]-color[i][1]),2)+pow(abs(c[2]-color[i][2]),2));
			if(adk>dk){
				ans=i;
				adk=dk;
			}
		}
		cout << colors[ans] << endl;
	}
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

string s;

string colortable[] = { "black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white" };
double numtable[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 }
};

double changenum(string s){
	double res = 0;
	REP(i, 2){
		double num;
		if (s[i] >= '0'&&s[i] <= '9') num = s[i] - '0';
		else if (s[i] == 'a')num = 10;
		else if (s[i] == 'b')num = 11;
		else if (s[i] == 'c')num = 12;
		else if (s[i] == 'd')num = 13;
		else if (s[i] == 'e')num = 14;
		else if (s[i] == 'f')num = 15;
		
		if (i == 0)res += num * 16;
		else res += num;
	}
	return res;
}

void solve(){

}

int main(){
	while (cin >> s&&s != "0"){
		int ans;
		double dk = INF, rk = changenum(s.substr(1, 2)),
			gk = changenum(s.substr(3, 2)), bk = changenum(s.substr(5, 2));
		REP(i, 8){
			double num = sqrt(pow(numtable[i][0] - rk, 2)
				+ pow(numtable[i][1] - gk, 2)
				+ pow(numtable[i][2] - bk, 2));
			if (num - dk < EPS){
				dk = num;
				ans = i;
			}
		}
		cout << colortable[ans] << endl;
	}
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int to_int(string s){
	int k=1,res=0;
	for(int i=s.size()-1;i>=0;i--){
		if('0'<=s[i]&&s[i]<='9'){
			res+=k*(s[i]-'0');
		}else{
			res+=k*(s[i]-'a'+10);
		}
		k*=16;
	}
	return res;
}

int main(){
	string ans[2][2][2];
	ans[0][0][0]="black";
	ans[0][0][1]="blue";
	ans[0][1][0]="lime";
	ans[0][1][1]="aqua";
	ans[1][0][0]="red";
	ans[1][0][1]="fuchsia";
	ans[1][1][0]="yellow";
	ans[1][1][1]="white";
	string s;
	while(cin>>s&&s[0]!='0'){
		int a,b,c,dat[3];
		for(int i=1;i<6;i+=2){
			string tmp;int ans[3];
			tmp.assign(s,i,2);
			int d=to_int(tmp);
			if(d<=(to_int("ff")-d))dat[i/2]=0;
			else dat[i/2]=1;
		}
		cout<<ans[dat[0]][dat[1]][dat[2]]<<endl;
	}
}