Go: package main

import (
	"fmt"
	"math"
	"strconv"
)

// ColorCode is a string like #rrggbb
type ColorCode string

// ColorName is a name of color
type ColorName string

// Color has colorname and colorcode
type Color struct {
	name ColorName
	code ColorCode
}

// ColorTable has default colors
type ColorTable struct {
	colors []Color
}

var (
	colorTable = ColorTable{
		[]Color{
			Color{"black", "#000000"},
			Color{"blue", "#0000ff"},
			Color{"lime", "#00ff00"},
			Color{"aqua", "#00ffff"},
			Color{"red", "#ff0000"},
			Color{"fuchsia", "#ff00ff"},
			Color{"yellow", "#ffff00"},
			Color{"white", "#ffffff"},
		},
	}
)

func main() {
	var code ColorCode
	fmt.Scanf("%s", &code)
	for {
		if code == "0" {
			break
		}
		name := colorTable.getNearestColor(code)
		fmt.Println(name)
		fmt.Scanf("%s", &code)
	}
}

func (colorstr ColorCode) parseColorValue() (float64, float64, float64) {
	rr, gg, bb := colorstr[1:3], colorstr[3:5], colorstr[5:7]
	rri, err1 := strconv.ParseUint(string(rr), 16, 8)
	ggi, err2 := strconv.ParseUint(string(gg), 16, 8)
	bbi, err3 := strconv.ParseUint(string(bb), 16, 8)
	if err1 != nil || err2 != nil || err3 != nil {
		err := fmt.Errorf(
			"Failed to read color strings, color code:%s, err: %v %v %v",
			colorstr, err1, err2, err3)
		panic(err)
	}
	return float64(rri), float64(ggi), float64(bbi)
}

func (table *ColorTable) getNearestColor(targetcode ColorCode) ColorName {
	var nearestColor ColorName
	var nearestValue = 1e5
	for _, v := range table.colors {
		trr, tgg, tbb := targetcode.parseColorValue()
		prr, pgg, pbb := v.code.parseColorValue()
		// diff := math.Sqrt(
		// 	math.Pow(prr-trr, 2) + math.Pow(pgg-tgg, 2) + math.Pow(pbb-tbb, 2))
		diff := math.Pow(prr-trr, 2) +
			math.Pow(pgg-tgg, 2) +
			math.Pow(pbb-tbb, 2)
		if nearestValue > diff {
			nearestValue = diff
			nearestColor = v.name
		}
	}
	return nearestColor
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[8],d,f,g,h,i,j;
	char z[8];
	while(1){
		scanf("%s",z);
		if(z[0]=='0') break;
		j=0;
		for(i=1;i<7;i+=2){
			if(z[i]=='8'||z[i]=='9'||z[i]=='a'||z[i]=='b'||z[i]=='c'||z[i]=='d'||z[i]=='e'||z[i]=='f'){
				s[j]=1;
			}
			else s[j]=0;
			j++;
		}
		if(s[0]==1){
			if(s[1]==1){
				if(s[2]==1) printf("white\n");
				else printf("yellow\n");
			}
			else{
				if(s[2]==1) printf("fuchsia\n");
				else printf("red\n");
			}
		}
		else{
			if(s[1]==1){
				if(s[2]==1) printf("aqua\n");
				else printf("lime\n");
			}
			else{
				if(s[2]==1) printf("blue\n");
				else printf("black\n");
			}
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
  char c[10];
  int r,g,b,id;
  string str[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  while(scanf("%s",c),c[0]!='0'){
    r = g = b = 0;
    if('0'<=c[1] && c[1]<='9') r += (c[1]-'0')*16;
    else r += (c[1]-'a'+10)*16;
    if('0'<=c[2] && c[2]<='9') r += (c[2]-'0');
    else r += (c[2]-'a'+10);
    if('0'<=c[3] && c[3]<='9') g += (c[3]-'0')*16;
    else g += (c[3]-'a'+10)*16;
    if('0'<=c[4] && c[4]<='9') g += (c[4]-'0');
    else g += (c[4]-'a'+10);
    if('0'<=c[5] && c[5]<='9') b += (c[5]-'0')*16;
    else b += (c[5]-'a'+10)*16;
    if('0'<=c[6] && c[6]<='9') b += (c[6]-'0');
    else b += (c[6]-'a'+10);
    id = 0;
    if(r >=123) id += 4;
    if(g >=123) id += 2;
    if(b >=123) id += 1;
    cout << str[id] << endl;
  }
  return(0);
}

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

int main()
{
	string s, t[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };

	cin >> s;

	while (s != "0") {
		int r, g, b, i = 0;

		r = stoi(s.substr(1, 2), nullptr, 16);
		g = stoi(s.substr(3, 2), nullptr, 16);
		b = stoi(s.substr(5, 2), nullptr, 16);

		if (r > 127)
			i += 4;
		if (g > 127)
			i += 2;
		if (b > 127)
			i += 1;

		cout << t[i] << endl;
		
		cin >> s;
	}

	return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
map<char,int> ma;
void mainmain(){
	rep(i,10){
		ma[(char)i+'0']=i;
	}
	char a[]={'a','b','c','d','e','f'};
	rep(i,6){
		ma[a[i]]=i+10;
	}
	string s;
	int r[]={0,0,0,0,1,1,1,1};
	int g[]={0,0,1,1,0,0,1,1};
	int b[]={0,1,0,1,0,1,0,1};
	string ans[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	while(cin>>s,s[0]!='0'){
		int rr=0,gg=0,bb=0;
		rr=ma[s[1]]*16+ma[s[2]];
		gg=ma[s[3]]*16+ma[s[4]];
		bb=ma[s[5]]*16+ma[s[6]];
		int c=-1;
		int d=INF;
		rep(i,8){
			int t=(rr-r[i]*255)*(rr-r[i]*255)+(gg-g[i]*255)*(gg-g[i]*255)+(bb-b[i]*255)*(bb-b[i]*255);
			if(t<d){
				d=t;
				c=i;
			}
		}
		cout<<ans[c]<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int black[3] = {0};
    int blue[] = { 0,0,255 };
    int lime[] = {0,255,0};
    int aqua[] = {0,255,255};
    int red[] = {255,0,0};
    int fuchsia[] = {255,0,255};
    int yellow[] = {255,255,0};
    int white[] = {255,255,255};
    while(true){
	string s;
	cin >> s;
	if(s == "0") break;
	int rgb[3];
	rgb[0] = stoi(s.substr(1,2),nullptr,16);
	rgb[1] = stoi(s.substr(3,2),nullptr,16);
	rgb[2] = stoi(s.substr(5,2),nullptr,16);
	string ans;
	int m = 10000000;
	int sum = 0;
	REP(j,3) sum += (rgb[j]-black[j])*(rgb[j]-black[j]);
	if(m > sum){
	    m = sum;
	    ans = "black";
	}
	sum = 0;
	REP(j,3) sum += (rgb[j]-blue[j])*(rgb[j]-blue[j]);
	if(m > sum){
	    m = sum;
	    ans = "blue";
	}
	sum = 0;
	REP(j,3) sum += (rgb[j]-lime[j])*(rgb[j]-lime[j]);
	if(m > sum){
	    m = sum;
	    ans = "lime";
	}
	sum = 0;
	REP(j,3) sum += (rgb[j]-aqua[j])*(rgb[j]-aqua[j]);
	if(m > sum){
	    m = sum;
	    ans = "aqua";
	}
	sum = 0;
	REP(j,3) sum += (rgb[j]-red[j])*(rgb[j]-red[j]);
	if(m > sum){
	    m = sum;
	    ans = "red";
	}
	sum = 0;
	REP(j,3) sum += (rgb[j]-fuchsia[j])*(rgb[j]-fuchsia[j]);
	if(m > sum){
	m = sum;
	ans = "fuchsia";
	}
	sum = 0;
	REP(j,3) sum += (rgb[j]-yellow[j])*(rgb[j]-yellow[j]);
	if(m > sum){
	    m = sum;
	    ans = "yellow";
	}
	sum = 0;
	REP(j,3) sum += (rgb[j]-white[j])*(rgb[j]-white[j]);
	if(m > sum){
	    m = sum;
	    ans = "white";
	}
	cout << ans << endl;
    }
    return 0;
}