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 <cctype>

using namespace std;

int pow(int x, int n) {
  int ans = 1;
  for(int i = 0; i < n; i++) {
    ans *= x;
  }
  return ans;
}

int charToInt(char c) {
  return (int)c - (int)'0';
}

int _16to10(char c) {
  int ans = charToInt(c);
  if(ans >= 0 && ans <= 9) return ans;
  else return (int)tolower(c) - (int)'a' + 10;
}

int _16to10(string str) {
  int ans = 0;
  for(int i = 0; i < str.length(); i++) {
    ans += _16to10(str[i])*pow(16, str.length()-i-1);
  }
  return ans;
}

int d2(string a, string b) {
  int ans = 0;
  for(int i = 0; i < 3; i++) {
    int p = i*2;
    ans += pow(_16to10(a.substr(p,2))-_16to10(b.substr(p,2)), 2);
  }
  return ans;
}

int main() {
  string colors[8][2] = {{"black", "000000"},
			 {"blue", "0000ff"},
			 {"lime", "00ff00"},
			 {"aqua", "00ffff"},
			 {"red", "ff0000"},
			 {"fuchsia", "ff00ff"},
			 {"yellow", "ffff00"},
			 {"white", "ffffff"}};
  while(1) {
    string str;
    cin >> str;
    if(str == "0") break;

    int min = 999999;
    int k;
    for(int i = 0; i < 8; i++) {
      int temp = d2(str.substr(1, 6), colors[i][1]);
      if(temp < min) {
	min = temp;
	k = i;
      }
    }
    cout << colors[k][0] << endl;
  }
  return 0;
}

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

int R,G,B;
void solve() {
  string color[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
  int icolor[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 nearest=0,dist,mindist=1000000;
  for(int i=0;i<8;i++) {
    dist = sqrt( (R-icolor[i][0])*(R-icolor[i][0]) + (G-icolor[i][1])*(G-icolor[i][1]) + (B-icolor[i][2])*(B-icolor[i][2]));
    if(dist < mindist) {
      mindist = dist;
      nearest = i;
    }
  }
  cout << color[nearest] << endl;
}

int main() {
  string str;
  while(getline(cin,str)) {
    if(str == "0") break;
    R = strtol(str.substr(1,2).c_str(),NULL,16);
    G = strtol(str.substr(3,2).c_str(),NULL,16);
    B = strtol(str.substr(5,2).c_str(),NULL,16);
    solve();
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

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

int change(string t){
    int res = 0;
    rep(i, 0, 2){
        if('0' <= t[i] && t[i] <= '9'){
            res += (t[i] - '0')*16*(1 - i);
        }else{
            res += ((t[i] - 'a') + 10)*16*(1 - i);
        }
    }
    return res;
}

signed main() {
    string s;
    while(cin >> s){
        if(s == "0") break;
        int r, g, b;
        r = change(s.substr(1, 2));
        g = change(s.substr(3, 2));
        b = change(s.substr(5, 2));
        int MIN = 1e9, p = -1;
        rep(i, 0, 2){
            rep(j, 0, 2){
                rep(k, 0, 2){
                    int d = (r - i*16*16)*(r - i*16*16) + (g - j*16*16)*(g - j*16*16) + (b - k*16*16)*(b - k*16*16);
                    //o(d);
                    if(d < MIN){
                        MIN = d;
                        p = i*4 + j*2 + k;
                    }
                }
            }
        }
        cout << str[p] << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

/*
	ツつ「ツづつつゥツカツδ可ーツコツーツドツδ可イツブツδ可δ環づつつュツづォツつ、
 */
struct Color
{
	int r, g, b;
	
	Color() : r(0), g(0), b(0) { }
	Color(int r, int g, int b) : r(r), g(g), b(b)
	{	}
	Color(string str)
	{
		r = strtol(str.substr(1, 2).c_str(), NULL, 16);
		g = strtol(str.substr(3, 2).c_str(), NULL, 16);
		b = strtol(str.substr(5, 2).c_str(), NULL, 16);
	}
};

Color operator - (const Color& left, const Color& right)
{	return Color(left.r - right.r, left.g - right.g, left.b - right.b);	}

template<class T> T SQR(T x){ return x * x; }

double abs(Color color)
{	return sqrt(SQR(color.r) + SQR(color.g) + SQR(color.b));	}

int main()
{
    string name[] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	Color colors[8];
	
	rep(i, 8) colors[i] = Color(bool(i & 1 << 2) * 0xff, bool(i & 1 << 1) * 0xff, bool(i & 1) * 0xff);
	
	for(string line; cin >> line && line != "0";)
	{
		int index = 0;
		double fit = 1 << 30;
		
		rep(i, 8) if(abs(colors[i] - Color(line)) < fit)
		{
			index = i;
			fit = abs(colors[i] - Color(line));
		}
		
		cout << name[index] << endl;
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int m[8][3] = {
  {0,0,0}, {0,0,0xff}, {0,0xff,0}, {0,0xff,0xff},
  {0xff,0,0}, {0xff,0,0xff}, {0xff,0xff,0}, {0xff,0xff,0xff},
};
string s[8] = {
  "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white",
};
int conv(string s)
{
  int n=0,i;
  for(i=0;i<2;i++){
    n *= 16;
    if('0' <= s[i] && s[i] <= '9') n += s[i] - '0';
    else n += s[i] - 'a' + 10;
  }
  return n;
}
int main()
{
  string i;
  for(;;){
    cin >> i;
    if(i=="0") break;
    int r,g,b;
    r = conv(i.substr(1,2));
    g = conv(i.substr(3,2));
    b = conv(i.substr(5,2));
    int d,e=0x1fffffff,j,k;
    for(j=0;j<8;j++){
      d = (r-m[j][0])*(r-m[j][0])+(g-m[j][1])*(g-m[j][1])+(b-m[j][2])*(b-m[j][2]);
      if(e>d) {
	e = d;
	k = j;
      }
    }
    cout << s[k] << endl;
  }
  return 0;
}