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<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int a[8][3]={
  {  0,  0,  0},
  {  0,  0,256},
  {  0,256,  0},
  {  0,256,256},
  {256,  0,  0},
  {256,  0,256},
  {256,256,  0},
  {256,256,256}
};
string out[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string in;
  map<char,int>c;
  rep(i,10)c[i+'0']=i;
  loop(i,'a','f'+1)c[i]=i-'a'+10;
  while(cin>>in,in!="0"){
    int min=1e9;
    int mini=1e9;
    int b[3]={c[in[1]]*16+c[in[2]],c[in[3]]*16+c[in[4]],c[in[5]]*16+c[in[6]]};
    //cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<endl;
    rep(i,8){
      double sum=0;
      rep(j,3)sum+=pow(b[j]-a[i][j],2);
      if(min>sum){min=sum;mini=i;}
    }
    cout<<out[mini]<<endl;
  }
}

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

struct Color {
    string name; int r, g, b;
};
vector<Color> colors = {
    (Color){"black", 0, 0, 0},
    (Color){"blue", 0, 0, 255},
    (Color){"lime", 0, 255, 0},
    (Color){"aqua", 0, 255, 255},
    (Color){"red", 255, 0, 0},
    (Color){"fuchsia", 255, 0, 255},
    (Color){"yellow", 255, 255, 0},
    (Color){"white", 255, 255, 255}
};

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

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

int main() {
    string s;
    while (cin >> s, s != "0") {
        int r = dec(s[1]) * 16 + dec(s[2]);
        int g = dec(s[3]) * 16 + dec(s[4]);
        int b = dec(s[5]) * 16 + dec(s[6]);
        int mn = INT_MAX, k = -1;
        for (int i=0; i<(int)colors.size(); ++i) {
            int t = sq(r-colors[i].r) + sq(g-colors[i].g) + sq(b-colors[i].b);
            if (t < mn) {
                mn = t;
                k = i;
            }
        }
        cout << colors[k].name << 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", "while"};
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<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int a[8][3]={
  {  0,  0,  0},
  {  0,  0,256},
  {  0,256,  0},
  {  0,256,256},
  {256,  0,  0},
  {256,  0,256},
  {256,256,  0},
  {256,256,256}
};
string out[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string in;
  while(cin>>in,in!="0"){
    int min=1e9;
    int mini=1e9;
    loop(i,1,7)in[i]-='0';
    int b[3]={in[1]*16+in[2],in[3]*16+in[4],in[5]*16+in[6]};
    rep(i,8){
      double sum=0;
      rep(j,3)sum+=pow(b[j]-a[i][j],2);
      if(min>sum){min=sum;mini=i;}
    }
    cout<<out[mini]<<endl;
  }
}

C++: # define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int main()
{
	string a;
	int FF = 16 * 16 - 1;
	int f[][3] = { { FF,FF,FF },{ FF,FF,0 },{ FF,0,FF },{ FF,0,0 },{ 0,FF,FF },{ 0,FF,0 },{ 0,0,FF },{ 0,0,0 } };
	string ans[] = { "white","yellow","fuchsia","red","aqua","lime","blue","black" };
	while (cin >> a&&a != "0")
	{
		int g[3] = { strtol(a.substr(1,2).c_str(),NULL,16),strtol(a.substr(3,2).c_str(),NULL,16),strtol(a.substr(5,2).c_str(),NULL,16) };
		int d = INT_MAX, id = 0;
		FOR(i, 8)
		{
			double D = 0;
			FOR(j, 3)
			{
				D += pow(f[i][j] - g[j], 2);
			}
			if (D <= d)
			{
				d = D;
				id = i;
			}
		}
		cout << ans[id] << endl;

	}
}