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 "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)


string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int red[]={0,0,0,0,255,255,255,255};
int green[]={0,0,255,255,0,0,255,255};
int blue[]={0,255,0,255,0,255,0,255};

string s;
int r,g,b;

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

int main(){
    while(cin>>s&&s!="0"){
        r=trance(s[1])*16+trance(s[2]);
        g=trance(s[3])*16+trance(s[4]);
        b=trance(s[5])*16+trance(s[6]);
        string ret;
        double num=INF<double>();
        REP(i,8){
            double num2=sqrt((r-red[i])*(r-red[i])+(g-green[i])*(g-green[i])+(b-blue[i])*(b-blue[i]));
            if(num>=num2){
                num=num2;
                ret=color[i];
            }
        }
        cout<<ret<<endl;
    }
}

C++: #include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main(){
	string str;
	string ans[10];
	ans[0]="black";ans[1]="blue";ans[2]="lime";ans[3]="aqua";ans[4]="red";
	ans[5]="fuchsia";ans[6]="yellow";ans[7]="white";
	while(true){
		cin >> str;
		if(str[0] == '0')break;
		int r[]={0,0,0,0,255,255,255,255};
		int g[]={0,0,255,255,0,0,255,255};
		int b[]={0,255,0,255,0,255,0,255};
		char ch[]={"0123456789abcdef"};
		int best = -1;
		int x=10000000;
		int R=0,G=0,B=0;
		
		for(int i = 0; i < 16; i++){
			if(str[1] == ch[i])R += i*16;
			if(str[2] == ch[i])R += i;
		}
		for(int i = 0; i < 16; i++){
			if(str[3] == ch[i])G += i*16;
			if(str[4] == ch[i])G += i;
		}
		for(int i = 0; i < 16; i++){
			if(str[5] == ch[i])B += i*16;
			if(str[6] == ch[i])B += i;
		}
		//cout << R << ":"<< G <<":"<< B << endl;
		for(int i = 0; i < 8; i++){
			int k = (R-r[i])*(R-r[i])+(G-g[i])*(G-g[i])+(B-b[i])*(B-b[i]);
			if(k < x){
				best = i;
				x = k;
			}
		}
		cout << ans[best] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>
#include<set>


using namespace std;

int a[10][4]={{0,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(){


	
	while(1){
	string p;
	cin>>p;if(p=="0")return 0;

	int Y[15]={};
	for(int i=1;i<p.size();i++){
		if(p[i]>='0'&&p[i]<='9')Y[i]=p[i]-'0';
		else {Y[i]=10;Y[i]+=p[i]-'a';
		}
	}
	int X[5]={};
	for(int i=0;i<3;i++){
		X[i]+=16*Y[2*i+1];
		X[i]+=Y[2*i+2];
	}
	double ans=0,Bst=9999999;
	int k=0;
	double c0=X[0],c1=X[1],c2=X[2];
	for(int i=0;i<8;i++){
		double A=a[i][0]-c0,B=a[i][1]-c1,C=a[i][2]-c2;
		
		ans=sqrt(A*A+B*B+C*C);

		if(ans<Bst){Bst=ans;k=i;}
	}
	if(k==7)cout<<"white"<<endl;
	else if(k==6)cout<<"yellow"<<endl;
	else if(k==5)cout<<"fuchsia"<<endl;
	else if(k==4)cout<<"red"<<endl;
	else if(k==3)cout<<"aqua"<<endl;
	else if(k==2)cout<<"lime"<<endl;
	else if(k==1)cout<<"blue"<<endl;
	else if(k==0)cout<<"black"<<endl;

	}
	}

C++: #include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<cmath>
using namespace std;
typedef long long int lli;
unordered_map<char, int> h;

lli calc(char a, char b){
  return h[a]*16 + h[b];
}

lli calc(string s){
  lli res = 0;
  for (lli i = 0; i < 3; i++) {
    res *= (16*16);
    res += calc(s[2*i + 1], s[2*i + 2]);
  }
  return res;
}

int main(){
  string s;
  h['0'] = 0;
  h['1'] = 1;
  h['2'] = 2;
  h['3'] = 3;
  h['4'] = 4;
  h['5'] = 5;
  h['6'] = 6;
  h['7'] = 7;
  h['8'] = 8;
  h['9'] = 9;
  h['a'] = 10;
  h['b'] = 11;
  h['c'] = 12;
  h['d'] = 13;
  h['e'] = 14;
  h['f'] = 15;
  vector<lli> val(8);
  string color[] = {"#000000",
                    "#0000ff",
                    "#00ff00",
                    "#00ffff",
                    "#ff0000",
                    "#ff00ff",
                    "#ffff00",
                    "#ffffff"};
  string name[] = {"black",
                   "blue",
                   "lime",
                   "aqua",
                   "red",
                   "fuchsia",
                   "yellow",
                   "white"};
  for (int i = 0; i < 8; i++) {
    val[i] = calc(color[i]);
  }
  while(std::cin >> s, s != "0"){
    lli diff = 1e18, ans = -1;
    for (int i = 0; i < 8; i++) {
      lli hoge = 0;
      for (int j = 0; j < 3; j++) {
        int tmp = 0;
        tmp = calc(s[2*j + 1], s[2*j + 2]) -
          calc(color[i][2*j + 1], color[i][2*j + 2]);
        tmp *= tmp;
        hoge += tmp;
      }
      if(diff > hoge){
        diff = hoge;
        ans = i;
      }
    }
    std::cout << name[ans] << std::endl;
  }
  return 0;
}