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<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;     
  //rep(i,8)cout<<ans[i] << " "<<num[i]<<endl;
  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){
      //cout<<i<<(i>>2)%2<<" "<<(i>>1)%2<<" "<<(i%2)<<endl;
   

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

       //*/
    }
    cout<<ans[index]<<endl;
  }
}

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

using namespace std;

class color{
public:
	int r,g,b;
	string name;
	color(int x,int y,int z){r=x;g=y;b=z;}
	color(string s,int x, int y, int z){name = s; r=x; g=y; b=z;}

	double dist(const color arg){
		return sqrt(pow(abs(r - arg.r),2) +
				pow(abs(g - arg.g),2) +
				pow(abs(b - arg.b),2));
	}
};

int c2d(char c){
	if('a' <= c && c <= 'f'){
		return c - 'a' + 10;
	}else{
		return c - '0';
	}
}

int main(void){
	string str;
	vector<color> co;
	co.push_back(color("black",0,0,0));
	co.push_back(color("blue",0,0,255));
	co.push_back(color("lime",0,255,0));
	co.push_back(color("aqua",0,255,255));
	co.push_back(color("red",255,0,0));
	co.push_back(color("fuchsia",255,0,255));
	co.push_back(color("yellow",255,255,0));
	co.push_back(color("white",255,255,255));
	while(cin >> str){
		if(str[0] == '0') break;
		int c[3] = {0,0,0};
		char tmp;
		double dist = 1 << 30;
		int index;
		for(int i=0;i<3;i++){
			c[i] += c2d(str[i*2+1]) * 16;
			c[i] += c2d(str[i*2+2]);
		}
		color arg = color(c[0],c[1],c[2]);

		for(int i=0;i<8;i++){
			double tdist = co[i].dist(arg);
			if(dist > tdist){
				dist = tdist;
				index = i;
			}
		}
		cout << co[index].name << endl;
	}
}

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

int main() {
    vector<string> v{"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    string s;
    while(cin >> s, s != "0") cout << v[4*(s[1]>'7')+2*(s[3]>'7')+1*(s[5]>'7')] << "\n";
    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 in[256]={0};
int han[3][8]={
  {0,0,0,0,256,256,256,256},
  {0,0,256,256,0,0,256,256},
  {0,256,0,256,0,256,0,256}
};
string ss[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int main(){
  string s;
  loop(i,'0','9'+1)in[i]=i-'0';
  loop(i,'a','g')in[i]=i-'a'+10;
  while(cin>>s,s.size()!=1||s[0]!='0'){
    int a[3]={0};
    rep(i,3){
      a[i]=in[s[2*i+1]]*16+in[s[2*i+2]];
    }
    double mi=100000;
    int ms;
    rep(i,8){
      int sum=0;
      rep(j,3)sum+=(han[j][i]-a[j])*(han[j][i]-a[j]);
      if(mi>sum){
	ms=i;
	mi=sum;
      }
    }
    cout<<ss[ms]<<endl;
  }

}

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

int main() {
  const string c[] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
  const int t[][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} };
  string s;
  while (cin >> s, s != "0") {
    int r = stoi(s.substr(1, 2), nullptr, 16);
    int g = stoi(s.substr(3, 2), nullptr, 16);
    int b = stoi(s.substr(5, 2), nullptr, 16);
    double mind = 500.0;
    int idx = -1;
    for (int i = 0; i < 8; i++) {
      double d = sqrt(pow(t[i][0] - r, 2) + pow(t[i][1] - g, 2) + pow(t[i][2] - b, 2));
      if (d < mind) {
        mind = d;
        idx = i;
      }
    }
    cout << c[idx] << "\n";
  }
}

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];
		FOR(i, 3)g[i] = strtol(a.substr(i * 2 + 1,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;

	}
}