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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 
#define sq(a) ((a)*(a))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	char str[8];
	while(scanf("%s", str), str[0]!='0'){
		int v;
		sscanf(str+1, "%x", &v);
		int r = v / 0x10000;
		int g = (v % 0x10000) / 0x100;
		int b =  v % 0x100;
		
		const int rs[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
		const int gs[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff};
		const int bs[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff};
		
		int bestid = 0;
		int best = 1<<29;
		rep(i, 8){
			int d = sq(r-rs[i])+sq(g-gs[i])+sq(b-bs[i]);
			if(d < best){
				best = d;
				bestid = i;
			}
		}
		
		const char* name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
		puts(name[bestid]);
	}
	
	return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <string>
#include <tuple>

using namespace std;

class Solver{

};

int main() {
	vector<tuple<string, string>> colors{
		make_tuple("#000000","black"),
		make_tuple("#0000ff","blue"),
		make_tuple("#00ff00","lime"),
		make_tuple("#00ffff","aqua"),
		make_tuple("#ff0000","red"),
		make_tuple("#ff00ff","fuchsia"),
		make_tuple("#ffff00","yellow"),
		make_tuple("#ffffff","white"),
	};


	while (true) {
		string s;
		cin >> s;
		if (s[0] == '0')break;

		int num = -1;
		int dd = 1e9;
		int r = 0;
		int g = 0;
		int b = 0;
		if ('a' <= s[1] && s[1] <= 'f')r += 16 * (s[1] - 'a' + 10);
		else r += 16 * (s[1] - '0');
		if ('a' <= s[2] && s[2] <= 'f')r += (s[2] - 'a' + 10);
		else r += (s[2] - '0');
		if ('a' <= s[3] && s[3] <= 'f')g += 16 * (s[3] - 'a' + 10);
		else g += 16 * (s[3] - '0');
		if ('a' <= s[4] && s[4] <= 'f')g += (s[4] - 'a' + 10);
		else g += (s[4] - '0');
		if ('a' <= s[5] && s[5] <= 'f')b += 16 * (s[5] - 'a' + 10);
		else b += 16 * (s[5] - '0');
		if ('a' <= s[6] && s[6] <= 'f')b += (s[6] - 'a' + 10);
		else b += (s[6] - '0');

		for (int i = 0; i < 8; i++) {
			int rr = 0;
			int gg = 0;
			int bb = 0;
			if (get<0>(colors[i])[1] == 'f')rr = 255;
			if (get<0>(colors[i])[3] == 'f')gg = 255;
			if (get<0>(colors[i])[5] == 'f')bb = 255;

			int tmp_d = (rr - r) * (rr - r)
				+ (gg - g) * (gg - g) + (bb - b) * (bb - b);
			if (tmp_d < dd) {
				num = i;
				dd = tmp_d;
			}
		}

		cout << get<1>(colors[num]) << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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 sixteen[200]={};
    for(int i=0;i<10;i++)sixteen[i]=i;
    for(int i=0;i<6;i++)sixteen['a'-'0'+i]=10+i;
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=sixteen[str[1+2*i]-'0']*16+sixteen[str[2+2*i]-'0'];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=(colornum[i][j]-num[j])*(colornum[i][j]-num[j]);
            ans[i]=sqrt(ans[i]);
        }
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}

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 = sqrt((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);
}

C++: #include <bits/stdc++.h>
using namespace std;

const double INF=10000;

double color[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
};
string colors[8]=
{"black",
"blue",
"lime",
"aqua",
"red",
"fuchsia",
"yellow",
"white"
};

int main(void){
    while(1){
        string str;
        cin >> str;
        if(str=="0")break;
        double c[3]={0,0,0};
        for(int i=0;i<3;i++){
            if(str[i*2+1]>='a' && str[i*2+1]<='f'){
                c[i]+=(str[i*2+1]-'a'+10)*16;
            }else c[i]+=(str[i*2+1]-'0')*16;
            if(str[i*2+2]>='a' && str[i*2+2]<='f'){
                c[i]+=str[i*2+2]-'a'+10;
            }else c[i]+=str[i*2+2]-'0';
        }
        double adk=INF;
        int ans=0;
        for(int i=0;i<8;i++){
            double dk=sqrt(pow(abs(c[0]-color[i][0]),2)+pow(abs(c[1]-color[i][1]),2)+pow(abs(c[2]-color[i][2]),2));
            if(adk>dk){
                ans=i;
                adk=dk;
            }
        }
        cout << colors[ans] << endl;
    }
    return 0;
}

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

const int INF = 1 << 30;

const int color[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} };
const string name[] = {"black", "blue", "lime", "aqua",
		       "red", "fuchsia", "yellow", "white" };

int main()
{
  string RGB;
  while (cin >> RGB) {
    if (RGB == "0")
      break;

    int R = strtol(RGB.substr(1, 2).c_str(), NULL, 16);
    int G = strtol(RGB.substr(3, 2).c_str(), NULL, 16);
    int B = strtol(RGB.substr(5, 2).c_str(), NULL, 16);

    int d = INF, index = 0;
    for (int i = 0; i < 8; ++i) {
      int dd = (R-color[i][0]) * (R-color[i][0])
	+ (G-color[i][1]) * (G-color[i][1])
	+ (B-color[i][2]) * (B-color[i][2]);

      if (d > dd) {
	d = dd;
	index = i;
      }
    }
    cout << name[index] << endl;
  }
  return 0;
}