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<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct color{
    string name;
    int r,g,b;
};

int xx(int a){ return a * a; }

string colorName(struct color c[8], int r, int g, int b){
    int near = 99999;
    string name;
    rep(i,8){
        int dis = sqrt(xx(r - c[i].r) + xx(g - c[i].g) + xx(b - c[i].b));
        if(near > dis){
            near = dis;
            name = c[i].name;
        }
    }
    return name;
}

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

int DecimalNumber(char c16[2]){
    int c10 = 0;
    rep(i,chenge(c16[0])){
        c10 += 16;
    }
    c10+=chenge(c16[1]);
    
    return c10;
}


int main(){
    struct color c[8] = {
        {"black", 0, 0, 0},
        {"blue", 0, 0, 255},
        {"lime", 0, 255, 0},
        {"aqua", 0, 255, 255},
        {"red", 255, 0, 0},
        {"fuchsia", 255, 0, 255},
        {"yellow", 255, 255, 0},
        {"white", 255, 255, 255}
    };

    char r[2],g[2],b[2],gar;
    while(true){
        int R,G,B;
        cin >> gar;
        if(gar == '0') break;
        rep(i,2) cin >> r[i]; 
        rep(i,2) cin >> g[i]; 
        rep(i,2) cin >> b[i]; 

        R =  DecimalNumber(r);
        G =  DecimalNumber(g);
        B =  DecimalNumber(b);
        cout << colorName(c,R,G,B) << endl;
    }

}

C++: #include <iostream>
#include <math.h>
using namespace std;

int main() {
    double s,m;
    char a[8],c[8][8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"},h[17]="0123456789abcdef";
    int d[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}},
        w[6],i,j,e,r,g,b;
    while(cin >> a) {
		if (a[0]=='0') break;
		for (i=0;i<6;i++)  for (j=0;j<16;j++) if (a[i+1]==h[j]) w[i]=j;
		s=99999999; r=w[0]*16+w[1]; g=w[2]*16+w[3]; b=w[4]*16+w[5]; 
		for (i=0;i<8;i++) {
		 m=sqrt((r-d[i][0])*(r-d[i][0])+(g-d[i][1])*(g-d[i][1])+(b-d[i][2])*(b-d[i][2]));
		 if (m<s) { s=m; e=i;};
	 }
	 cout << c[e] << endl;
 }	
 return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define mod 1000000007
typedef long long ll;
using namespace std;
int d[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 ans[8]={
  "black",
  "blue",
  "lime",
  "aqua",
  "red",
  "fuchsia",
  "yellow",
  "white"
};
int F(char z){
  if('0'<=z&&z<='9')return z-'0';
  return 10+z-'a';
}
int main(){
  string s;
  while(cin>>s&&s!="0"){
    int a=F(s[1])*16+F(s[2]);
    int b=F(s[3])*16+F(s[4]);
    int c=F(s[5])*16+F(s[6]);
    int mini=mod,pnt;
    for(int i=0;i<8;i++){
      int dis=(d[i][0]-a)*(d[i][0]-a);
      dis+=(d[i][1]-b)*(d[i][1]-b);
      dis+=(d[i][2]-c)*(d[i][2]-c);
      if(dis<mini)mini=dis,pnt=i;
    }
    cout<<ans[pnt]<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int FF = 255, F  = 16;

string name[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
int R[] = { 0, 0, 0, 0, FF, FF, FF, FF};
int G[] = { 0, 0, FF, FF, 0, 0, FF, FF};
int B[] = { 0, FF, 0, FF, 0, FF, 0, FF};

int num(char t)
{
    if(t >='0' && t <= '9') return t - '0';
    else return t - 'a' + 10;
}
int f(int n) { return n * n;}

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

        int mind = FF * FF * F, d = 0, ans = 0;
        REP(8)
        {
            d = f(R[i] -( num(s[1]) * F + num(s[2]) )) + f(G[i]-(num(s[3])*F + num(s[4]))) + f(B[i] - (num(s[5])*F + num(s[6])));
            if(mind > d) { ans = i; mind = d;}
        }
        cout << name[ans] << endl;
    }
    return 0;
}

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

#define INF (1<<29)

string str;
const string color[8] = {"black","blue","lime","aqua","red","fuchsia",
			 "yellow","white"};
const string strong[8] = {"#000000","#0000ff","#00ff00","#00ffff","#ff0000",
			  "#ff00ff","#ffff00","#ffffff"};
 
int change(char ch)
{
    if ('0' <= ch && ch <= '9') {
	return ch - '0';
    }
    return 10 + (ch - 'a');
}
 
int d(string str1, string str2)
{
    int R1 = change(str1[1])*16 + change(str1[2]);
    int G1 = change(str1[3])*16 + change(str1[4]);
    int B1 = change(str1[5])*16 + change(str1[6]);
 
    int R2 = change(str2[1])*16 + change(str2[2]);
    int G2 = change(str2[3])*16 + change(str2[4]);
    int B2 = change(str2[5])*16 + change(str2[6]);
 
    int res = pow(R1-R2,2.0) + pow(G1-G2,2.0) + pow(B1-B2,2.0);
 
    return res;
}
 
int main()
{
    while (cin >> str, str != "0") {
	int min_ = INF,ans;
	for (int i = 0; i < 8; i++) {
	    int dist = d(str, strong[i]);
	    if (dist < min_) {
		min_ = dist;
		ans = i;
	    }
	}
	cout << color[ans] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cctype>

using namespace std;

string Strength[8] = {"000000","0000ff","00ff00","00ffff",
		      "ff0000","ff00ff","ffff00","ffffff"};

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

int x_t(char c){
  if(islower(c)) return 10 + (c - 'a');
  return c - '0';
}

int change(string s){
  return x_t(s[0])*16 + x_t(s[1]);
}

string solve(string R,string G,string B){
  int pos,Min = (1<<29),d;
  int r = change(R),g = change(G),b = change(B);
  string rr,gg,bb;

  for(int i = 0 ; i < 8 ; i++){
    rr = Strength[i].substr(0,2);
    gg = Strength[i].substr(2,2);
    bb = Strength[i].substr(4,2);
 
    int rk = change(rr) ,gk = change(gg) ,bk = change(bb);    
    d = (r-rk)*(r-rk) + (g-gk)*(g-gk) + (b-bk)*(b-bk);

    if(d < Min){
      Min = d;
      pos = i;
    }
  }

  return Color[pos];
}

int main(){
  string str;

  while(cin >> str ,str != "0"){
    string R,G,B;

    R = str.substr(1,2);
    G = str.substr(3,2);
    B = str.substr(5,2);

    cout << solve(R,G,B) << endl;
  }

  return 0;
}