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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define c(a,b,c,d,e,f) (a-d)*(a-d)+(b-e)*(b-e)+(c-f)*(c-f)
using namespace std;
int f(string s){
  int n=0;
  if('a'<=s[0]&&s[0]<='f')
    n+=(s[0]-'a'+10)*16;
  else
    n+=(s[0]-'0')*16;
  if('a'<=s[1]&&s[1]<='f')
    n+=s[1]-'a'+10;
  else
    n+=s[1]-'0';
  return n;
}
int main(){
  int i;
  int r[8]={0,0,0,0,0xff,0xff,0xff,0xff},g[8]={0,0,0xff,0xff,0,0,0xff,0xff},b[8]={0,0xff,0,0xff,0,0xff,0,0xff};
  int d,e;
  string s[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"},t;
  for(;;){
    cin>>t;
    if(t=="0")
      break;
    d=255*255*3;
    for(i=0;i<8;i++){
      if(d>c(f(t.substr(1,2)),f(t.substr(3,2)),f(t.substr(5,2)),r[i],g[i],b[i])){
	e=i;
	d=c(f(t.substr(1,2)),f(t.substr(3,2)),f(t.substr(5,2)),r[i],g[i],b[i]);
      }
    }
    cout<<s[e]<<endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"

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(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int btoh(string s){
    if(s.size()!=2)cout<<"error"<<endl;
    int ret=0;
    if('0'<=s[1]&&s[1]<='9')ret+=(s[1]-'0');
    else{
        ret+=10+(int)(s[1]-'a');
    }
    if('0'<=s[0]&&s[0]<='9')ret+=(s[0]-'0')*16;
    else{
        ret+=(10+(int)(s[0]-'a'))*16;
    }
    return ret;
}

double solve(string a,string b,string c,string d,string e,string f){
    int x,y,z;
//    cout<<btoh(a)<<" "<<btoh(b)<<" "<<btoh(c)<<" "<<btoh(d)<<" "<<btoh(e)<<" "<<btoh(f)<<endl;
    x=(btoh(a)-btoh(d)) * (btoh(a)-btoh(d));
    y=(btoh(b)-btoh(e)) * (btoh(b)-btoh(e));
    z=(btoh(c)-btoh(f)) * (btoh(c)-btoh(f));
    
    return sqrt(x+y+z);
}

int main(){
//    string color = {"black","blue",}
    string s;
    while(cin>>s){
        if(s=="0")break;
        string a,b,c;
        a=s.substr(1,2);
        b=s.substr(3,2);
        c=s.substr(5,2);
        string ans="";
        double d=INF;
        
        double t=solve(a,b,c,"00","00","00");
        if(t<d){
            d=t;
            ans="black";
        }
        
        t=solve(a,b,c,"00","00","ff");
        if(t<d){
            d=t;
            ans="blue";
        }
        
        t=solve(a,b,c,"00","ff","00");
        if(t<d){
            d=t;
            ans="lime";
        }
        
        t=solve(a,b,c,"00","ff","ff");
        if(t<d){
            d=t;
            ans="aqua";
        }
        
        t=solve(a,b,c,"ff","00","00");
        if(t<d){
            d=t;
            ans="red";
        }
        
        t=solve(a,b,c,"ff","00","ff");
        if(t<d){
            d=t;
            ans="fuchsia";
        }
        
        t=solve(a,b,c,"ff","ff","00");
        if(t<d){
            d=t;
            ans="yellow";
        }
        
        t=solve(a,b,c,"ff","ff","ff");
        if(t<d){
            d=t;
            ans="white";
        }
        cout<<ans<<endl;
    }
}

/*
 black	00	00	00
 blue	00	00	ff
 lime	00	ff	00
 aqua	00	ff	ff
 red	ff	00	00
 fuchsiaff	00	ff
 yellow	ff	ff	00
 white	ff	ff	ff

 */

C++: #include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

struct Color{
	double r,g,b;
};

double sq( double a ){
	return a * a;
}

int main(int argc, char const* argv[])
{
	const char *color[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	Color colorStrong[] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};

	Color inputColor;
	int rgb;
	double d[8];
	char damy;

	while( cin >> damy && damy != '0' ){
		cin >> hex >> rgb;
		inputColor.r = rgb >> 16;
		inputColor.g = ( rgb >> 8 ) & 0xff;
		inputColor.b = rgb & 0xff;

		for( int i = 0;i < 8;i++ ){
			d[i] = sqrt( sq( inputColor.r - colorStrong[i].r ) + sq( inputColor.g - colorStrong[i].g ) + sq( inputColor.b - colorStrong[i].b ) );
		}

		double* answer = min_element( d, d + 8 );

		for( int i = 0;i < 8;i++ ){
			if( answer == &d[i] ){
				cout << color[i] << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int r,g,b,n[6],p[8],q[8];
	char a[7];
	
	while(1){
		gets(a);
		if(a[0]=='0'){
			return 0;
		}
		for(int i=1;i<7;i++){
			if(a[i]=='0'){
				n[i-1]=0;
			}
			if(a[i]=='1'){
				n[i-1]=1;
			}
			if(a[i]=='2'){
				n[i-1]=2;
			}
			if(a[i]=='3'){
				n[i-1]=3;
			}
			if(a[i]=='4'){
				n[i-1]=4;
			}
			if(a[i]=='5'){
				n[i-1]=5;
			}
			if(a[i]=='6'){
				n[i-1]=6;
			}
			if(a[i]=='7'){
				n[i-1]=7;
			}
			if(a[i]=='8'){
				n[i-1]=8;
			}
			if(a[i]=='9'){
				n[i-1]=9;
			}
			if(a[i]=='a'){
				n[i-1]=10;
			}
			if(a[i]=='b'){
				n[i-1]=11;
			}
			if(a[i]=='c'){
				n[i-1]=12;
			}
			if(a[i]=='d'){
				n[i-1]=13;
			}
			if(a[i]=='e'){
				n[i-1]=14;
			}
			if(a[i]=='f'){
				n[i-1]=15;
			}
		}
		r=n[0]*16+n[1];
		g=n[2]*16+n[3];
		b=n[4]*16+n[5];
		
		p[0]=r*r+g*g+b*b;
		p[1]=r*r+g*g+(255-b)*(255-b);
		p[2]=r*r+(255-g)*(255-g)+b*b;
		p[3]=r*r+(255-g)*(255-g)+(255-b)*(255-b);
		p[4]=(255-r)*(255-r)+g*g+b*b;
		p[5]=(255-r)*(255-r)+g*g+(255-b)*(255-b);
		p[6]=(255-r)*(255-r)+(255-g)*(255-g)+b*b;
		p[7]=(255-r)*(255-r)+(255-g)*(255-g)+(255-b)*(255-b);
		
		for(int i=0;i<8;i++){
			q[i]=i;
		}
		for(int i=1;i<8;i++){
			for(int j=0;j<8-i;j++){
				if(p[j]>p[j+1]){
					r=p[j]; p[j]=p[j+1]; p[j+1]=r;
					b=q[j]; q[j]=q[j+1]; q[j+1]=b;
				}
			}
		}
		
		if(q[0]==0){
			cout << "black\n";
		}
		if(q[0]==1){
			cout << "blue\n";
		}
		if(q[0]==2){
			cout << "lime\n";
		}
		if(q[0]==3){
			cout << "aqua\n";
		}
		if(q[0]==4){
			cout << "red\n";
		}
		if(q[0]==5){
			cout << "fuchsia\n";
		}
		if(q[0]==6){
			cout << "yellow\n";
		}
		if(q[0]==7){
			cout << "white\n";
		}
	}
	
return 0;
}