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 <map>
#include <iostream>
#include <cmath>
using namespace std;

string near(int R, int G, int B);

double dist(int R1, int G1, int B1, int R2, int G2, int B2);

int main(void){
  map<char,int> d;
  for(int i=0;i<10;i++){
    d[i+'0']=i;
  }
  for(int i=0;i<6;i++){
    d[i+'a']=i+10;
  }
  string s;
  int R,G,B;
  while(1){
    cin>>s;
    if(s=="0")break;
    R=d[s[1]]*16+d[s[2]];
    G=d[s[3]]*16+d[s[4]];
    B=d[s[5]]*16+d[s[6]];
    cout<<near(R,G,B)<<endl;
  }
  return 0;
}

string near(int R, int G, int B){
  double distance=10000;
  string color="hoge";
  if(dist(R,G,B,0,0,0)<distance){
    color="black";
    distance=dist(R,G,B,0,0,0);
  }
  if(dist(R,G,B,0,0,255)<distance){
    color="blue";
    distance=dist(R,G,B,0,0,255);
  }
  if(dist(R,G,B,0,255,0)<distance){
    color="lime";
    distance=dist(R,G,B,0,255,0);
  }
  if(dist(R,G,B,0,255,255)<distance){
    color="aqua";
    distance=dist(R,G,B,0,255,255);
  }
  if(dist(R,G,B,255,0,0)<distance){
    color="red";
    distance=dist(R,G,B,255,0,0);
  }
  if(dist(R,G,B,255,0,255)<distance){
    color="fuchsia";
    distance=dist(R,G,B,255,0,255);
  }
  if(dist(R,G,B,255,255,0)<distance){
    color="yellow";
    distance=dist(R,G,B,255,255,0);
  }
  if(dist(R,G,B,255,255,255)<distance){
    color="white";
    distance=dist(R,G,B,255,255,255);
  }
  return color;
}

double dist(int R1, int G1, int B1, int R2, int G2, int B2){
  return sqrt((R1-R2)*(R1-R2)+(G1-G2)*(G1-G2)+(B1-B2)*(B1-B2));
}

C++: #include<bits//stdc++.h>
using namespace std;
string s, x[2][2][2] = { {{"black","blue"}, {"lime","aqua"}}, { {"red","fuchsia"}, {"yellow","white"} } },T = "89abcdef";
int main() {
	while (1) {
		int a = 0, b = 0, c = 0;cin >> s;
		if (s == "0") { break; }
		for (int i = 0; i < 8; i++) if (T[i] == s[1]) a++;
		for (int i = 0; i < 8; i++) if (T[i] == s[3]) b++;
		for (int i = 0; i < 8; i++) if (T[i] == s[5]) c++;
		cout << x[a][b][c] << endl;
	}
}

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

using namespace std;

int h(string s){
	int ret = 0;
	int src = 1;
	for(int i=s.length()-1;i>=0;i--){
		ret += (s[i]>'9'?s[i]-'a'+10:s[i]-'0')*src;
		src *= 16;
	}
	return ret;
}

double f(string a,string b){	
	string tr,tg,tb;
	string tr2,tg2,tb2;
	tr = a.substr(1,2);
	tg = a.substr(3,2);
	tb = a.substr(5,2);
	tr2 = b.substr(1,2);
	tg2 = b.substr(3,2);
	tb2 = b.substr(5,2);
	return sqrt(
		(h(tr)-h(tr2))*(h(tr)-h(tr2)) +
		(h(tg)-h(tg2))*(h(tg)-h(tg2)) +
		(h(tb)-h(tb2))*(h(tb)-h(tb2))
	);
}
int main(){
	double MIN;
	string ret;
	
	string rgb;
	while(cin >> rgb && rgb[0] != '0'){
		MIN = (1<<21);
		if(MIN >     f(rgb,"#000000")){
			MIN = f(rgb,"#000000");
			ret = "black";
		}
		if(MIN >     f(rgb,"#0000ff")){
			MIN = f(rgb,"#0000ff");
			ret = "blue";
		}
		if(MIN >     f(rgb,"#00ff00")){
			MIN = f(rgb,"#00ff00");
			ret = "lime";
		}
		if(MIN >     f(rgb,"#00ffff")){
			MIN = f(rgb,"#00ffff");
			ret = "aqua";
		}
		if(MIN >     f(rgb,"#ff0000")){
			MIN = f(rgb,"#ff0000");
			ret = "red";
		}
		if(MIN >     f(rgb,"#ff00ff")){
			MIN = f(rgb,"#ff00ff");
			ret = "fuchsia";
		}
		if(MIN >     f(rgb,"#ffff00")){
			MIN = f(rgb,"#ffff00");
			ret = "yellow";
		}
		if(MIN >     f(rgb,"#ffffff")){
			MIN = f(rgb,"#ffffff");
			ret = "white";
		}
		cout << ret << endl;

	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

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

int rs[] = {
	0, 0, 0, 0, 255, 255, 255, 255
};

int gs[] = {
	0, 0, 255, 255, 0, 0, 255, 255
};

int bs[] = {
	0, 255, 0, 255, 0, 255, 0, 255,
};

int get_num(char c1, char c2){
	int res = 0;
	if(isdigit(c1)) res += c1 - '0';
	else res += c1 - 'a' + 10;
	res *= 16;
	if(isdigit(c2)) res += c2 - '0';
	else res += c2 - 'a' + 10;
	return res;
}

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

int get_d(int id, int r, int g, int b){
	return pow(rs[id] - r) + pow(gs[id] - g) + pow(bs[id] - b);
}

int main(){
	string s;
	int r, g, b;
	while(cin >> s && s != "0"){
		int best;
		int p = INF;
		r = get_num(s[1], s[2]);
		g = get_num(s[3], s[4]);
		b = get_num(s[5], s[6]);
		rep(i, 8){
			int c = get_d(i, r, g, b);
			if(c < p){
				best = i;
				p = c;
			}
		}
		cout << cs[best] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
using namespace std;
int Overten(char a){
  if(a-'0'<10)return a-'0';
  if(a=='A')return 10;
  if(a=='B')return 11;
  if(a=='C')return 12;
  if(a=='D')return 13;
  if(a=='E')return 14;
  if(a=='F')return 15;
}
int changeDtoI(char a,char b){
  return Overten(a)*16+Overten(b);
}
int main(void){
  string color;
  while(cin>>color,color.size()>3){
    int R = changeDtoI(color[1],color[2])<128?0:1;
    int G = changeDtoI(color[3],color[4])<128?0:1;
    int B = changeDtoI(color[4],color[5])<128?0:1;
    //cout<<R << " " << G << " " << B <<endl;
    if(R * G * B)cout<<"white"<<endl;
    else if(R * G)cout<<"yellow"<<endl;
    else if(R * B)cout<<"fuchsia"<<endl;
    else if(G * B)cout<<"aqua"<<endl;
    else if(R)cout<<"red"<<endl;
    else if(G)cout<<"green"<<endl;
    else if(B)cout<<"blue"<<endl;
    else cout<<"black"<<endl;
  }
}