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<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;
}

C++: (function(input) {
  var lines = input.split("\n");
  var colors = [
    ['black', 0x00, 0x00, 0x00],
    ['blue', 0x00, 0x00, 0xff],
    ['lime', 0x00, 0xff, 0x00],
    ['aqua', 0x00, 0xff, 0xff],
    ['red', 0xff, 0x00, 0x00],
    ['fuchsia', 0xff, 0x00, 0xff],
    ['yellow', 0xff, 0xff, 0x00],
    ['white', 0xff, 0xff, 0xff],
  ];
  for (var i = 0; i < lines.length; ++i) {
    if (lines[i][0] === '#') {
      var best_color;
      var min_d = 3 * 256 * 256 + 1;
      var r = parseInt(lines[i].substr(1, 2), 16);
      var g = parseInt(lines[i].substr(3, 2), 16);
      var b = parseInt(lines[i].substr(5, 2), 16);
      for (var j = 0; j < colors.length; ++j) {
        var d = Math.pow(r - colors[j][1], 2) + Math.pow(g - colors[j][2], 2) + Math.pow(b - colors[j][3], 2);
        if (d < min_d) {
          min_d = d;
          best_color = colors[j][0];
        }
      }
      console.log(best_color);
    }
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8').trim());