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 <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct COL{
  double n;
  string name;
};

const int c[8][3] = {{0, 0, 0}, {0, 0, 0xff}, {0, 0xff, 0}, {0, 0xff, 0xff}, {0xff, 0, 0}, {0xff, 0, 0xff}, {0xff, 0xff, 0}, {0xff, 0xff, 0xff}};

const string s[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

bool cmp(COL lhs, COL rhs)
{
  return (lhs.n < rhs.n);
}

signed main()
{
  //ios::sync_with_stdio(false);
  char sr[2], sg[2], sb[2];
  char sh;
    
  while (scanf("%1s", &sh), sh != '0'){
    COL col[8];
    scanf("%2s%2s%2s", sr, sg, sb);
    int r = strtol(sr, NULL, 16),
        g = strtol(sg, NULL, 16),
        b = strtol(sb, NULL, 16);

    REP(i, 8){
      col[i].n = sqrt((c[i][0] - r) * (c[i][0] - r) + (c[i][1] - g) * (c[i][1] - g) + (c[i][2] - b) * (c[i][2] - b));
      col[i].name = s[i];
    }

    sort(col, col + 8, cmp);
    print(col[0].name);
  }

  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,255},
  {  0,255,  0},
  {  0,255,255},
  {255,  0,  0},
  {255,  0,255},
  {255,255,  0},
  {255,255,255}
};
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 <cstdlib>
using namespace std;

const int MAX_C = 8;

int main() {
	pair< int, string > colors[MAX_C] = {
		make_pair< int, string >(0x000000, "black"),
		make_pair< int, string >(0x0000ff, "blue"),
		make_pair< int, string >(0x00ff00, "lime"),
		make_pair< int, string >(0x00ffff, "aqua"),
		make_pair< int, string >(0xff0000, "red"),
		make_pair< int, string >(0xff00ff, "fuchsia"),
		make_pair< int, string >(0xffff00, "yellow"),
		make_pair< int, string >(0xffffff, "white")
	};
	string color, cname;
	int r, g, b, _r, _g, _b, min, dist;
	
	while(cin >> color, color != "0"){
		r = strtol(color.substr(1, 2).c_str(), NULL, 16);
		g = strtol(color.substr(3, 2).c_str(), NULL, 16);
		b = strtol(color.substr(5, 2).c_str(), NULL, 16);
		
		min = ~(1 << 31);
		cname;
		
		for(int i = 0; i < MAX_C; ++i){
			_r = (colors[i].first & 0xff0000) >> 16;
			_g = (colors[i].first & 0x00ff00) >> 8;
			_b = (colors[i].first & 0x0000ff);
			
			dist = (r - _r) * (r - _r) + (g - _g) * (g - _g) + (b - _b) * (b - _b);
			
			if(dist < min){
				min = dist;
				cname = colors[i].second;
			}
		}
		cout << cname << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>

using namespace std;

string str;
const string color[8] = {"black","blue","lime","aqua","red","fuchsia",
			 "yellow","white"};
const string strong[8] = {"#000000","#0000ff","#00ff00","#00ffff","#ff0000",
			  "#ff00ff","#ffff00","#ffffff"};

int change(char ch){
  if('0' <= ch && ch <= '9'){
    return ch - '0';
  }
  return 10 + (ch - 'a');
}

int d(string str1,string str2){
  int R1 = change(str1[1])*16 + change(str1[2]);
  int G1 = change(str1[3])*16 + change(str1[4]);
  int B1 = change(str1[5])*16 + change(str1[6]);

  int R2 = change(str2[1])*16 + change(str2[2]);
  int G2 = change(str2[3])*16 + change(str2[4]);
  int B2 = change(str2[5])*16 + change(str2[6]);

  int res = pow(R1-R2,2.0) + pow(G1-G2,2.0) + pow(B1-B2,2.0);

  return res;
}

#define INF (1<<29)

int main(){
  while(cin >> str , str != "0"){
    int min_ = INF,ans;
    for(int i = 0 ; i < 8 ; i++){
      int dist = d(str,strong[i]);
      if(dist < min_){
	min_ = dist;
	ans = i;
      }
    }
    cout << color[ans] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <string>
using namespace std;
double square(int SQ){
	double KAGA;
	KAGA=SQ*SQ;
	return KAGA;
}
int main(){
	string s,kaga="0123456789abcdef";
	string color[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	int RK[8]={0,0,0,0,255,255,255,255};
	int GK[8]={0,0,255,255,0,0,255,255};
	int BK[8]={0,255,0,255,0,255,0,255};
	int C[3];
	double tmp;
	double MIN;
	string ans;
	while(cin>>s,s!="0"){
		for(int i=2,j=0;j<3;i+=2,j++){
			C[j]=0;
			for(int k=0;k<20;k++){
				if(s[i]==kaga[k]){
					C[j]+=k;
					k+=30;
				}
			}
			for(int k=0;k<20;k++){
				if(s[i-1]==kaga[k]){
					C[j]+=k*16;
					k+=30;
				}
			}
		}
		
		ans="?";
		MIN=10000000;
		
		for(int i=0;i<8;i++){
			tmp=sqrt(square(C[0]-RK[i])+square(C[1]-GK[i])+square(C[2]-BK[i]));
			if(MIN>tmp){
				MIN=tmp;
				ans=color[i];
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		string st; cin >> st;
		map<int, string>mp;
		mp[0] = "black";
		mp[1] = "blue";
		mp[2] = "lime";
		mp[3] = "aqua";
		mp[4] = "red";
		mp[5] = "fuchsia";
		mp[6] = "yellow";
		mp[7] = "white";
		if (st == "0")break;
		else {
			int red = stoi(st.substr(1, 2), nullptr, 16);
			int gre = stoi(st.substr(3, 2), nullptr, 16);
			int blu = stoi(st.substr(5, 2), nullptr, 16);
			int num = (red > 127) * 4 + (gre > 127) * 2 + (blu > 127);
			cout << mp[num] << endl;
		}
	}
	return 0;
}