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<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;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

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

int toi(string s){
    int ret = 0;
    rep(i, s.size()){
        string t = s.substr(i, 1);
        if('0' <= t[0] && t[0] <= '9') ret += stoi(t);
        else ret += t[0]-'a'+10;
        if(i != s.size()-1) ret *= 16;
    }
    return ret;
}

vector<int> rgb(string s){
    vi ret;
    rep(i, 3){
        string t = s.substr(i*2, 2);
        ret.pb(toi(t));
    }
    return ret;
}

int main(){
    string  s;
    while(cin >> s, s!="0"){
        s = s.substr(1);
        vi c = rgb(s);
        double m = inf;
        int ans = 0;
        rep(i, 8){
            vi d = rgb(strength[i]);
            double ret = sqrt(pow(c[0]-d[0], 2)+pow(c[1]-d[1], 2)+pow(c[2]-d[2], 2));
            if(m > ret){ans = i; m = ret;}
        }
        cout << color[ans] << endl;
    }
}

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

int hext(string a){
	int c,d;
	if(a[0]>='0'&&a[0]<='9')c=a[0]-'0';
	else c=a[0]-'a'+10;
	
	if(a[1]>='0'&&a[1]<='9')d=a[1]-'0';
	else d=a[1]-'a'+10;
	
	return c*16+d;
	}

int main(){
	string s;
	while(cin>>s&&s!="0"){
		int r,g,b;
		r=hext(s.substr(1,2));
		g=hext(s.substr(3,2));
		b=hext(s.substr(5,2));
		
		string ans;
		int d=1e9;
		if(d>((r*r)+(g*g)+(b*b)))ans="black",d=((r*r)+(g*g)+(b*b));
		if(d>((r*r)+(g*g)+((b-255)*(b-255))))ans="blue",d=((r*r)+(g*g)+((b-255)*(b-255)));
		if(d>((r*r)+((g-255)*(g-255))+(b*b)))ans="lime",d=((r*r)+((g-255)*(g-255))+(b*b));
		if(d>((r*r)+((g-255)*(g-255))+((b-255)*(b-255))))ans="aqua",d=((r*r)+((g-255)*(g-255))+((b-255)*(b-255)));
		if(d>((r-255)*(r-255))+(g*g)+(b*b))ans="red",d=((r-255)*(r-255))+(g*g)+(b*b);
		if(d>((r-255)*(r-255))+(g*g)+((b-255)*(b-255)))ans="fuchsia",d=((r-255)*(r-255))+(g*g)+((b-255)*(b-255));
		if(d>((r-255)*(r-255))+((g-255)*(g-255))+(b*b))ans="yellow",d=((r-255)*(r-255))+((g-255)*(g-255))+(b*b);
		if(d>((r-255)*(r-255))+((g-255)*(g-255))+(b-255)*(b-255))ans="white";
		
		cout<<ans<<endl;
		
		}
		return 0;
	}