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 <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>
using namespace std;
int henkan(int i){
	if('0'<=i && i<='9') return i-'0';
	else return i-'a'+10;
}
int main(){
	while(true){
		string s;
		cin >> s;
		if(s=="0") break;
		int r,g,b;
		r=henkan(s[1])*16+henkan(s[2]);
		g=henkan(s[3])*16+henkan(s[4]);
		b=henkan(s[5])*16+henkan(s[6]);
		bool rr=true,gg=true,bb=true;
		if(r<128) rr=false;
		if(g<128) gg=false;
		if(b<128) bb=false;
		if(rr && gg && bb) cout << "white";
		if(rr && gg && !bb) cout << "yellow";
		if(rr && !gg && bb) cout << "fuchsia";
		if(rr && !gg && !bb) cout << "red";
		if(!rr && gg && bb) cout << "aqua";
		if(!rr && gg && !bb) cout << "lime";
		if(!rr && !gg && bb) cout << "blue";
		if(!rr && !gg && !bb) cout << "black";
		cout << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int color[8][3],i,j,k,rgb[3],min,c,d,r,g,b;
	color[0][0]=0; color[0][1]=0; color[0][2]=0;
	color[1][0]=0; color[1][1]=0; color[1][2]=255;
	color[2][0]=0; color[2][1]=255; color[2][2]=0;
	color[3][0]=0; color[3][1]=255; color[3][2]=255;
	color[4][0]=255; color[4][1]=0; color[4][2]=0;
	color[5][0]=255; color[5][1]=0; color[5][2]=255;
	color[6][0]=255; color[6][1]=255; color[6][2]=0;
	color[7][0]=255; color[7][1]=255; color[7][2]=255;
	char a[]="0123456789abcdef",s[8];
	while(1){
		for(i=0;i<3;i++)rgb[i]=0;
		cin>>s;
		if(s[0]=='0') break;
		i=0;
		for(j=1;j<6;j+=2){
			for(k=0;k<16;k++){
				if(s[j]==a[k]){
					rgb[i]=rgb[i]+k*16;
					break;
				}
			}
			for(k=0;k<17;k++){
				if(s[j+1]==a[k]){
					rgb[i]=rgb[i]+k;
					break;
				}
			}
			i++;
		}
		min=1000000;
		for(i=0;i<8;i++){
			r=color[i][0]-rgb[0];
			g=color[i][1]-rgb[1];
			b=color[i][2]-rgb[2];
			d=r*r+g*g+b*b;
			if(min>d){
				min=d;
				c=i;
			}
		}
		if(c==0) cout<<"black"<<endl;
		if(c==1) cout<<"blue"<<endl;
		if(c==2) cout<<"lime"<<endl;
		if(c==3) cout<<"aqua"<<endl;
		if(c==4) cout<<"red"<<endl;
		if(c==5) cout<<"fuchsia"<<endl;
		if(c==6) cout<<"yellow"<<endl;
		if(c==7) cout<<"white"<<endl;
//		printf("%d %d %d\n",rgb[0],rgb[1],rgb[2]);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int d(string s,int color[3]){
  int red=0,blue=0,green=0;
  if(!isdigit(s[1]))red+=(s[1]-'a'+10)*16;
  else red+=(s[1]-'0')*16;
  if(!isdigit(s[2]))red+=(s[2]-'a'+10);
  else red+=(s[2]-'0');
  if(!isdigit(s[3]))green+=(s[3]-'a'+10)*16;
  else green+=(s[3]-'0')*16;
  if(!isdigit(s[4]))green+=(s[4]-'a'+10);
  else green+=(s[4]-'0');
  if(!isdigit(s[5]))blue+=(s[5]-'a'+10)*16;
  else blue+=(s[5]-'0')*16;
  if(!isdigit(s[6]))blue+=(s[6]-'a'+10);
  else blue+=(s[6]-'0');
  return pow((red-color[0]),2)+pow((green-color[1]),2)+pow((blue-color[2]),2);
}

int cl[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 main(){
  string str;
  while(1){
    cin>>str;
    if(str=="0")break;
    int num=INF;
    string ans="";
    rep(i,8){
      if(num>d(str,cl[i])){
	if(i==0)ans="black";
	else if(i==1)ans="blue";
	else if(i==2)ans="lime";
	else if(i==3)ans="aqua";
	else if(i==4)ans="red";
	else if(i==5)ans="fuchsia";
	else if(i==6)ans="yellow";
	else if(i==7)ans="white";
	num=d(str,cl[i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

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

int calc_d(int r, int g, int b, int i){
  return (r - R[i]) * (r - R[i]) + (g - G[i]) * (g - G[i]) + (b - B[i]) * (b - B[i]);
}

int main(){

  REP(i,8){
    if(i % 2 == 1){
      B[i] = 255;
    }
    if(i % 4 >= 2){
      G[i] = 255;
    }
    if(i >= 4){
      R[i] = 255;
    }
  }

  while(true){
    string s;
    cin >> s;

    if(s == "0") break;

    int r, g, b;
    r = stoi(s.substr(1,2), nullptr, 16);
    g = stoi(s.substr(3,2), nullptr, 16);
    b = stoi(s.substr(5,2), nullptr, 16);

    int ans = 0;
    int d = INF;
    REP(i,8){
      int tmp = calc_d(r, g, b, i);
      if(tmp < d){
        d = tmp;
        ans = i;
      }
    }
    cout << color[ans] << endl;
  }
  return 0;
}