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 <stdio.h>

const char *t[] = {"black","blue","lime","aqua","redff","fuchsia","yellow","white"};

int solve(int r, int g, int b){
    int min = 0; int mind = 200000;
    for(int i = 0; i < 8; i++){
        int r0 = ((i>>2)&1)*0xff, g0 = ((i>>1)&1)*0xff, b0 = ((i>>0)&1)*0xff;
        //pf("%d,%d,%d : %d,%d,%d\n", r,g,b,r0,g0,b0);
        int d = (r-r0)*(r-r0)+(g-g0)*(g-g0)+(b-b0)*(b-b0);
        if(mind > d){
            mind = d, min = i;
        }
    }
    if(min >= 8) throw;
    return min;
}

int main(){
    int n;
    char buf[16];
    while(fgets(buf,sizeof(buf),stdin)){
        if(buf[0] == '0') break;
        sscanf(buf+1,"%x",&n);
        int i = solve((n>>16)&0xff,(n>>8)&0xff,n&0xff);
        printf("%s\n", t[i]);
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

struct COLOR{
	string name;
	string R;
	string G;
	string B;
};

int hex2dec(string str){
	const char hex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
	return 16 * (int)lower_bound(hex,hex+16,str[0]) + (int)lower_bound(hex,hex+16,str[1]);
}

int main(){

	struct COLOR color[] = {
		"black","00","00","00",
		"blue","00","00","ff",
		"lime","00","ff","00",
		"aqua","00","ff","ff",
		"red","ff","00","00",
		"fuchsia","ff","00","ff",
		"yellow","ff","ff","00",
		"white","ff","ff","ff",
	};

	string str;
	while(cin >> str){
		if(str.size() == 1 && str[0] == '0') break;
		int r = hex2dec(str.substr(1,2));
		int g = hex2dec(str.substr(3,2));
		int b = hex2dec(str.substr(5,2));

		int dk = 10000000;
		int idx=0;
		for(int i=0;i<sizeof(color)/sizeof(struct COLOR); i++){
			int tmp;
			if(dk > (tmp=((r - hex2dec(color[i].R)) * (r - hex2dec(color[i].R))
				+ (g - hex2dec(color[i].G)) * (g - hex2dec(color[i].G))
				+ (b - hex2dec(color[i].B)) * (b - hex2dec(color[i].B))))){
					dk = tmp;
					idx=i;
			}
		}

		printf("%s\n",color[idx].name.c_str());
	}

}

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

int main()
{
  vector< vector<int> > table( 8, vector<int>(3) );
  vector<string> name(8);
  vector<int> color(3);
  char c;
  int i, near, dist, t;
  table[0][0] = 0; table[0][1] = 0; table[0][2] = 0;
  table[1][0] = 0; table[1][1] = 0; table[1][2] = 255;
  table[2][0] = 0; table[2][1] = 255; table[2][2] = 0;
  table[3][0] = 0; table[3][1] = 255; table[3][2] = 255;
  table[4][0] = 255; table[4][1] = 0; table[4][2] = 0;
  table[5][0] = 255; table[5][1] = 0; table[5][2] = 255;
  table[6][0] = 255; table[6][1] = 255; table[6][2] = 0;
  table[7][0] = 255; table[7][1] = 255; table[7][2] = 255;
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";

  while (cin>>c, c!='0') {
    color.clear();
    for (i = 0; i < 3; i++) {
      cin>>c;
      if ('a' <= c) color[i] = c-'a'+10;
      else color[i] = c-'0';
      color[i] *= 16;
      cin>>c;
      if ('a' <= c) color[i] += c-'a'+10;
      else color[i] += c-'0';
    }
    dist = INT_MAX;
    near = 0;
    for (i = 0; i < 8; i++) {
      t = (table[i][0]-color[0])*(table[i][0]-color[0]) + (table[i][1]-color[1])*(table[i][1]-color[1]) + (table[i][2]-color[2])*(table[i][2]-color[2]);
      if (t < dist) {
	near = i;
	dist = t;
      }
    }
    cout<<name[near]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
using namespace std;

const char *name[] = {
	"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white",
};

int main(){
	int r, g, b;
	while(scanf(" #%2x%2x%2x", &r, &g, &b) == 3){
		puts(name[(r > 127) * 4 + (g > 127) * 2 + (b > 127)]);
	}
}

C++: // 0176
#include <iostream>
#include <string>
#define  N   255
using namespace std;

int c_table[8][3] = {{0,0,0}, {0,0,N}, {0,N,0}, {0,N,N}, {N,0,0}, {N,0,N}, {N,N,0}, {N,N,N}};

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

int dk(int co1[3], int co2[3]){
	int d = 0;

	for(int i=0;i<3;i++)
		d += (co1[i]-co2[i])*(co1[i]-co2[i]);

	return d;
}

int main(){
	while(1){
		string str;
		cin>>str;

		if(str == "0")
			break;

		int rgb[3], d=3*N*N, color=0;
		for(int i=0;i<3;i++)
			rgb[i] = 16*conv_16(str[2*i+1]) + conv_16(str[2*i+2]);
	
		
		for(int i=0;i<8;i++)
			if(d > dk(c_table[i], rgb)){
				d = dk(c_table[i], rgb);
				color = i;
			}

		if(color == 0)
			cout<<"black"<<endl;
		else if(color == 1)
			cout<<"blue"<<endl;
		else if(color == 2)
			cout<<"lime"<<endl;
		else if(color == 3)
			cout<<"aqua"<<endl;
		else if(color == 4)
			cout<<"red"<<endl;
		else if(color == 5)
			cout<<"fuchsia"<<endl;
		else if(color == 6)
			cout<<"yellow"<<endl;
		else if(color == 7)
			cout<<"white"<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct COL{
  int n;
  string name;
};

const int c[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}};

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

bool cmp(COL lhs, COL rhs)
{
  return (lhs.n < rhs.n);
}

signed main()
{
  //ios::sync_with_stdio(false);
  char sr[2], sg[2], sb[2];
  char sh;
    
  while (scanf("%1s", &sh), sh != '0'){
    COL col[8];
    scanf("%2s%2s%2s", sr, sg, sb);
    int r = strtol(sr, NULL, 16),
        g = strtol(sg, NULL, 16),
        b = strtol(sb, NULL, 16);

    REP(i, 8){
      col[i].n = (c[i][0] - r) * (c[i][0] - r) + (c[i][1] - g) * (c[i][1] - g) + (c[i][2] - b) * (c[i][2] - b);
      col[i].name = s[i];
    }

    sort(col, col + 8, cmp);
    print(col[0].name);
  }

  return (0);
}