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<vector>
#include<cmath>
using namespace std;

class Col
{
public:
  int R,G,B;
  Col():R(0),G(0),B(0){}
  Col(int R,int G,int B):R(R),G(G),B(B){}
};

int _16to10(string s)
{
  int a[2];
  for(int i=0;i<2;i++)
    {
      if(s[i] == 'a')
	a[i] = 10;
      else if(s[i] == 'b')
	a[i] = 11;
      else if(s[i] == 'c')
	a[i] = 12;
      else if(s[i] == 'd')
	a[i] = 13;
      else if(s[i] == 'e')
	a[i] = 14;
      else if(s[i] == 'f')
	a[i] = 15;
      else 
	a[i] = s[i] - '0';
    }
  return a[1]+a[0]*16;
}

int main()
{
  string s;
  vector<Col> vec;
  vector<string> name;
  vec.resize(8),name.resize(8);
  int ff = _16to10("ff");
  vec[0] = Col(0,0,0);
  vec[1] = Col(0,0,ff);
  vec[2] = Col(0,ff,0);
  vec[3] = Col(0,ff,ff);
  vec[4] = Col(ff,0,0);
  vec[5] = Col(ff,0,ff);
  vec[6] = Col(ff,ff,0);
  vec[7] = Col(ff,ff,ff);
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";
  while(true)
    {
      cin >> s;
      cerr << s << endl;
      if(s == "0")
	break;
      int R,G,B;
      R = _16to10(s.substr(1,2));
      G = _16to10(s.substr(3,2));
      B = _16to10(s.substr(5,2));

      int men = (1<<28),pos = -1;
      for(int i=0;i<8;i++)
	{
	  int d =  sqrt(pow(R-vec[i].R,2)+pow(B-vec[i].B,2)+pow(G-vec[i].G,2));
	  if(men > d)
	    {
	      men = d;
	      pos = i;
	    }
	}
      cout << name[pos] << endl;

    }
  return 0;
}

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

struct set{
  string val;
  double rgb[3];
};

set temp[8];

string name[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
void make_temp(){
  for(int i=0;i<8;i++){
    temp[i].val = name[i];
    temp[i].rgb[0] = (i >> 2 & 1 ? 255 : 0);
    temp[i].rgb[1] = (i >> 1 & 1 ? 255 : 0);
    temp[i].rgb[2] = (i & 1 ? 255 : 0);
  }
}

int main(){
  make_temp();

  while(true){
    double num[3];
    double ans = (2 << 10);
    string s,spt[3];
    cin >> s;
    if(s == "0") break;

    s.erase(0,1);
    for(int i=0;i<3;i++){
      for(int j=0;j<2;j++){
	spt[i] += s[0]; s.erase(0,1);
      }

      int a;
      sscanf(spt[i].c_str(),"%x",&a);
      num[i] = a;
    }
    
    string a;
    for(int i=0;i<8;i++){
      double d = sqrt(pow(num[0] - temp[i].rgb[0],2) + pow(num[1] - temp[i].rgb[1],2) + pow(num[2] - temp[i].rgb[2],2));

      if(ans > d){
	a = temp[i].val; ans = d;
      }
    }
    cout << a << endl;
  }

}

C++: // Tazoe

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

int main()
{
	while(true){
		string S;
		cin >> S;

		if(S=="0")
			break;

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

	return 0;
}

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) {
    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 = "brack";
    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 = "yello";
    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 <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<vector<int>> rgb = {
  {0, 0, 0},
  {0, 0, 255},
  {0, 255, 0},
  {0, 255, 255},
  {255, 0, 0},
  {255, 0, 255},
  {255, 255, 0},
  {255, 255, 255}
};
vector<string> name = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  auto f = [&](string s) { return (isdigit(s[0]) ? s[0] - '0' : s[0] - 'a' + 10) * 16 + (isdigit(s[1]) ? s[1] - '0' : s[1] - 'a' + 10); };
  string s;
  while (cin >> s, s != "0") {
    int r = f(s.substr(1, 2)), g = f(s.substr(3, 2)), b = f(s.substr(5, 2));
    double d_min = 1e9;
    string ans = "";
    for (int i = 0; i < 8; i++) {
      double d = sqrt(pow(r - rgb[i][0], 2.0) + pow(g - rgb[i][1], 2.0) + pow(b - rgb[i][2], 2.0));
      if (d < d_min) {
        d_min = d;
        ans = name[i];
      }
    }
    cout << ans << endl;
  }

  return 0;
}