Go: package main

import (
	"fmt"
	"math"
	"strconv"
)

// ColorCode is a string like #rrggbb
type ColorCode string

// ColorName is a name of color
type ColorName string

// Color has colorname and colorcode
type Color struct {
	name ColorName
	code ColorCode
}

// ColorTable has default colors
type ColorTable struct {
	colors []Color
}

var (
	colorTable = ColorTable{
		[]Color{
			Color{"black", "#000000"},
			Color{"blue", "#0000ff"},
			Color{"lime", "#00ff00"},
			Color{"aqua", "#00ffff"},
			Color{"red", "#ff0000"},
			Color{"fuchsia", "#ff00ff"},
			Color{"yellow", "#ffff00"},
			Color{"white", "#ffffff"},
		},
	}
)

func main() {
	var code ColorCode
	fmt.Scanf("%s", &code)
	for {
		if code == "0" {
			break
		}
		name := colorTable.getNearestColor(code)
		fmt.Println(name)
		fmt.Scanf("%s", &code)
	}
}

func (colorstr ColorCode) parseColorValue() (float64, float64, float64) {
	rr, gg, bb := colorstr[1:3], colorstr[3:5], colorstr[5:7]
	rri, err1 := strconv.ParseUint(string(rr), 16, 8)
	ggi, err2 := strconv.ParseUint(string(gg), 16, 8)
	bbi, err3 := strconv.ParseUint(string(bb), 16, 8)
	if err1 != nil || err2 != nil || err3 != nil {
		err := fmt.Errorf(
			"Failed to read color strings, color code:%s, err: %v %v %v",
			colorstr, err1, err2, err3)
		panic(err)
	}
	return float64(rri), float64(ggi), float64(bbi)
}

func (table *ColorTable) getNearestColor(targetcode ColorCode) ColorName {
	var nearestColor ColorName
	var nearestValue = 1e5
	for _, v := range table.colors {
		trr, tgg, tbb := targetcode.parseColorValue()
		prr, pgg, pbb := v.code.parseColorValue()
		// diff := math.Sqrt(
		// 	math.Pow(prr-trr, 2) + math.Pow(pgg-tgg, 2) + math.Pow(pbb-tbb, 2))
		diff := math.Pow(prr-trr, 2) +
			math.Pow(pgg-tgg, 2) +
			math.Pow(pbb-tbb, 2)
		if nearestValue > diff {
			nearestValue = diff
			nearestColor = v.name
		}
	}
	return nearestColor
}

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

string str;

string t[8][4]={
  {"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"}
};



int c2i(char ch){
  if('0'<=ch&&ch<='9')return ch-'0';
  return 10+ch-'a';
}

int cc2i(char ch,char ch2){
  return c2i(ch)*16+c2i(ch2);
}

int s2i(string str){
  return cc2i(str[0],str[1]);
}

int pow(int x){
  return x*x;
}

int main(){
  int a,mini,mini_no;
  while(cin>>str){
    if(str=="0")break;
    mini=9999999;
    for(int i=0;i<8;i++){
      a=pow( cc2i(str[1],str[2]) - s2i(t[i][1]) ); 
      a+=pow(cc2i(str[3],str[4]) - s2i(t[i][2]) );
      a+=pow(cc2i(str[5],str[6]) - s2i(t[i][3]) ); 
      if(a<mini){
	mini=a;
	mini_no=i;
      }
    }
    cout<<t[mini_no][0]<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<cmath>
typedef struct{
  int R;
  int G;
  int B;
  char name[16];
} color;
int main(void){
  char s[16], r[3], g[3], b[3];
  int rk, gk, bk, n;
  double dk, min;
  color c[8];
  c[0].R = c[0].G = c[0].B = c[1].R = c[1].G = c[2].R = c[2].B = c[3].R = c[4].G = c[4].B = c[5].G = c[6].B = 0;
  c[1].B = c[2].G = c[3].G = c[3].B = c[4].R = c[5].R = c[5].B = c[6].R = c[6].G = c[7].R = c[7].G = c[7].B = 255;
  strcpy(c[0].name, "black"); strcpy(c[1].name, "blue"); strcpy(c[2].name, "lime"); strcpy(c[3].name, "aqua"); strcpy(c[4].name, "red"); strcpy(c[5].name, "fuchsia"); strcpy(c[6].name, "yellow"); strcpy(c[7].name, "white");
  for( ; ; ){
    scanf("%s", s);
    if(s[0] == '0') break;
    r[2] = g[2] = b[2] = '\0';
    r[0] = s[1]; r[1] = s[2]; g[0] = s[3]; g[1] = s[4]; b[0] = s[5]; b[1] = s[6];
    sscanf(r, "%x", &rk); sscanf(g, "%x", &gk); sscanf(b, "%x", &bk);
    for(int i = 0;i < 8; i++){
      dk = sqrt(pow(c[i].R - rk, 2) + pow(c[i].G - gk, 2) + pow(c[i].B - bk, 2));
      if(i == 0) min = dk, n = i;
      else{
	if(dk < min)
	  min = dk, n = i;
      }
    }
    printf("%s\n", c[n].name);
  }
}

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 = (int) 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 <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


string color[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
string col[8]={"000000","0000ff","00ff00","00ffff","ff0000","ff00ff","ffff00","ffffff"};

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

int solve(string s,int n){
    string t=col[n];
    
    string a[3],b[3];
    rep(i,3){
        a[i]=s.substr(i*2,2);
        b[i]=t.substr(i*2,2);
    }
    int x[3];
    rep(i,3){
        
        x[i]=abs(  ( to(a[i][0])*16 + to(a[i][1]) ) -( to(b[i][0])*16 + to(b[i][1]) )  );
    }
    
    return sqrt( pow(x[0],2)+pow(x[1],2)+pow(x[2],2) );
}


int main() {
    string s;
    while(cin>>s){
        if(s=="0")break;
        
        s=s.substr(1,6);
        
        int mini=999999999;
        int num=-1;
        
        
        rep(i,8){
            
            if(mini>solve(s,i)){
                num=i;
                mini=solve(s,i);
            }
        }
        
        
        
        cout<<color[num]<<endl;
    }
    return 0;
}