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<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//n??????
//Radix r("0123456789abcdef");
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208
class Radix {
private:
	const char* s;
	int a[128];
public:
	Radix(const char* s = "0123456789ABCDEF") : s(s) {
		for (int i = 0; s[i]; i++) a[(int)s[i]] = i;
	}
	//10?????´??° ??? n???????????????
	string format(long long x, int n) {
		if (!x) return "0";
		char t[64] = {};
		int i;
		for (i = 62; x; i--) {
			t[i] = s[x % n];
			x /= n;
		}
		return string(t + i + 1);
	}
	//m??????????????? ??? n???????????????
	string format(const string &t, int m, int n) {
		return format(format(t, m), n);
	}
	//m??????????????? ??? 10?????´??°
	long long format(const string &t, int m) {
		long long sm = a[(int)t[0]];
		for (int i = 1; i < (int)t.length(); i++)
			sm = sm * m + a[(int)t[i]];
		return sm;
	}
};


signed main() {
	string color[] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int R[] = { 0,0,0,0,0xff,0xff,0xff,0xff };
	int G[] = { 0,0,0xff,0xff,0,0,0xff,0xff };
	int B[] = { 0,0xff,0,0xff,0,0xff,0,0xff };
	Radix r("0123456789abcdef");
	for (string s; cin >> s&&s != "0";) {
		int RR, GG, BB;
		RR = r.format(s.substr(1, 2), 16);
		GG = r.format(s.substr(3, 2), 16);
		BB = r.format(s.substr(5, 2), 16);
		int min = INF, ans;
		rep(i, 0, 8) {
			int d = (RR - R[i])*(RR - R[i]) + (GG - G[i])*(GG - G[i]) + (BB - B[i])*(BB - B[i]);
			if (min > d) {
				min = d;
				ans = i;
			}
		}
		cout << color[ans] << endl;
	}
	return 0;
}

C++: // 2011/02/19 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

		if(col[1]>='0'&&col[1]<='7')
			if(col[3]>='0'&&col[3]<='7')
				if(col[5]>='0'&&col[5]<='7')
					cout << "black" << endl;
				else
					cout << "blue" << endl;
			else
				if(col[5]>='0'&&col[5]<='7')
					cout << "lime" << endl;
				else
					cout << "aqua" << endl;
		else
			if(col[3]>='0'&&col[3]<='7')
				if(col[5]>='0'&&col[5]<='7')
					cout << "red" << endl;
				else
					cout << "fuchsia" << endl;
			else
				if(col[5]>='0'&&col[5]<='7')
					cout << "yellow" << endl;
				else
					cout << "white" << endl;
	}

	return 0;
}

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

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
int stoi(char c){
  if('0' <= c && c <= '9')
    return c - '0';
  return c - 'a' + 10;
}

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

int main(void){
  string s;
  string ans[8] = {
    "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 num[8];
  int cnt = 0;
  rep(i,8)num[i] = i * 255;     
  while(cin>>s){
    if(s == "0")break;
    int in[3];
    in[0] = stoi(s[1]) * 16 + stoi(s[2]);
    in[1] = stoi(s[3]) * 16 + stoi(s[4]);
    in[2] = stoi(s[5]) * 16 + stoi(s[6]);
    //rep(i,3)cout<<in[i]<<endl;
    int index = 0;
    unsigned long long diff = 100000000;
    rep(i,8){

      int box[3];
      rep(j,3){
	box[j] = (i>>(2-j))%2*255;
      }
      
     
      unsigned long long int calc = 0;
      rep(j,3)calc += pow(in[j] - box[j]);
     	
      if(calc < diff){
	diff = calc;
	index = i;
      }
    }
    cout<<ans[index]<<endl;
  }
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int hen(char a) {
  if((int)a - 48 >= 0 && (int)a - 48 < 10) return (int)a - 48;
  if(a == 'a') return 10;
  else if(a == 'b') return 11;
  else if(a == 'c') return 12;
  else if(a == 'd') return 13;
  else if(a == 'e') return 14;
  else return 15;
}

int main() {
  string s;
  while(cin >> s) {
    if(s == "0") return 0;
    int r = hen(s[1]) * 16 + hen(s[2]);
    int g = hen(s[3]) * 16 + hen(s[4]);
    int b = hen(s[5]) * 16 + hen(s[6]);

    int ans = INT_MAX;
    string mans;
    if(r * r + g * g + b * b < ans) ans = r * r + g * g + b * b, mans = "black";
    if(r * r + g * g + (b - 255) * (b - 255) < ans) ans = r * r + g * g + (b - 255) * (b - 255), mans = "blue";
    if(r * r + (g - 255) * (g - 255) + b * b < ans) ans = r * r + (g - 255) * (g - 255) + b * b, mans = "lime";
    if(r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans) ans = r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255), mans = "aqua";
    if((r - 255) * (r - 255) + g * g + b * b < ans) ans = (r - 255) * (r - 255) + g * g + b * b, mans = "red";
    if((r - 255) * (r - 255) + g * g + (b - 255) * (b - 255) < ans) ans = (r - 255) * (r - 255) + g * g + (b - 255) * (b - 255), mans = "fuchsia";
    if((r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b < ans) ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b, mans = "yellow";
    if((r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans) ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255), mans = "white";

    cout << mans << endl;
  }
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[8],d,f,g,h,i,j;
	char z[8];
	while(1){
		scanf("%s",z);
		if(z[0]=='0') break;
		j=0;
		for(i=1;i<7;i+=2){
			if(z[i]=='8'||z[i]=='9'||z[i]=='a'||z[i]=='b'||z[i]=='c'||z[i]=='d'||z[i]=='e'||z[i]=='f'){
				s[j]=1;
			}
			else s[j]=0;
			j++;
		}
		if(s[0]==1){
			if(s[1]==1){
				if(s[2]==1) printf("white\n");
				else printf("yellow\n");
			}
			else{
				if(s[2]==1) printf("fuchsia\n");
				else printf("red\n");
			}
		}
		else{
			if(s[1]==1){
				if(s[2]==1) printf("aqua\n");
				else printf("lime\n");
			}
			else{
				if(s[2]==1) printf("blue\n");
				else printf("black\n");
			}
		}
	}
	return 0;
}