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>
using namespace std;

int dir[5010];

void remove(){
	int cnt = 0;
	for(int i = 0 ; i < 5010 ; i++){
		if( dir[i] == 31 ) dir[i] = 0,cnt++;
	}
	for(int k = 0 ; k < cnt ; k++)
	for(int i = 5009 ; i > 0 ; i--){
		if( dir[i] && !dir[i-1] ){
			swap(dir[i],dir[i-1]);
		}
	}
}

void tate(int x,int l){
	for(int i = 1 ; i <= l ; i++) dir[5010-i] |= (1<<x);
	
	for(int _ = 0 ; _ < l ; _++)
	for(int i = 5010-l+_ ; i > 0 ; i--){
		if( (dir[i] >> x & 1) && (dir[i-1] >> x & 1) == 0 ){
			dir[i] -= (1<<x);
			dir[i-1] += (1<<x);
		}else{
			break;
		}
	}
	remove();
}

void yoko(int x,int l){
	int mask = ((1<<l)-1) << x;
	dir[5009] = mask;
	for(int i = 5009 ; i > 0 ; i--){
		if( dir[i] && !(dir[i-1] & mask) ){
			dir[i] -= mask;
			dir[i-1] += mask;
		}else{
			break;
		}
	}
	remove();
}
int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i <= 5009 ; i++)
			dir[i] = 0;
		
		for(int i = 0 ; i < n ; i++){
			int d,l,x;
			cin >> d >> l >> x;
			x--;
			if(d==1){
				yoko(x,l);
			}else{
				tate(x,l);
			}
			int f = 0;
			if( i == 10 ) continue;
			for(	int j = 5009 ; j >= 0 ; j--){
				if(f||dir[j]){
					//cout << j << " " << (dir[j]&1) << (dir[j]&2) << (dir[j]&4) << (dir[j]&8) << (dir[j]&16) << endl; ;
					f=true;
				}
			}
		//	cout << endl;
		}
		int ans = 0;
		for(int i = 0 ; i < 5010 ; i++)
			ans += __builtin_popcount(dir[i]);
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


int cal[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 t[8]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int c[3];

double d(int i){
	double ret=0.0;
	for(int j=0; j<3; j++){
		ret+=(cal[i][j]-c[j])*(cal[i][j]-c[j]);
	}
	return sqrt(ret);
}

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

int main(){
	string s;
	int ans;
	while(cin>>s){
		if(s=="0")break;
		for(int i=0; i<3; i++){
			c[i]=change(s[i*2+1])*16+change(s[i*2+2]);
		}
		//cout<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
		ans=0;
		for(int i=1; i<8; i++){
			if(d(ans)>d(i))ans=i;
		}
		cout<<t[ans]<<endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

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

int change(string t){
    int res = 0;
    rep(i, 0, 2){
        if('0' <= t[i] && t[i] <= '9'){
            res += (t[i] - '0')*16*(1 - i);
        }else{
            res += ((t[i] - 'a') + 10)*16*(1 - i);
        }
    }
    return res;
}

signed main() {
    string s;
    while(cin >> s){
        if(s == "0") break;
        int r, g, b;
        r = change(s.substr(1, 2));
        g = change(s.substr(3, 2));
        b = change(s.substr(5, 2));
        int MIN = 1e9, p = -1;
        rep(i, 0, 2){
            rep(j, 0, 2){
                rep(k, 0, 2){
                    int d = (r - i*240)*(r - i*240) + (g - j*240)*(g - j*240) + (b - k*240)*(b - k*240);
                    if(d < MIN){
                        MIN = d;
                        p = i*4 + j*2 + k;
                    }
                }
            }
        }
        cout << str[p] << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int code[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 name[8] = {"black",
                  "blue",
                  "lime",
                  "aqua",
                  "red",
                  "fuchsia",
                  "yellow",
                  "white"
};

int convert(string s){
    int d;
    sscanf(s.c_str(), "%x", &d);
    return d;
}

int main(){
    string line;
    while(cin >> line && line[0] != '0'){
        int r = convert(line.substr(1, 2));
        int g = convert(line.substr(3, 2));
        int b = convert(line.substr(5, 2));
        int ans_dist = 1e9;
        string ans = "--";
        rep(i,8){
            auto c = code[i];
            int d = 0;
            d += (r-c[0]) * (r-c[0]);
            d += (g-c[1]) * (g-c[1]);
            d += (b-c[2]) * (b-c[2]);
            if(d < ans_dist){
                ans_dist = d;
                ans = name[i];
            }
        }
        cout << ans << endl;
    }
}

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

map<char,int> f;

void foo(){
	for(int i=0 ; i<16 ; ++i ){
		if( i < 10 )
			f[(char)(i+'0')] = i;
		else
			f[(char)(i-10+'a')] = i;
	}
}

int to_i(char c1,char c2){
	return f[c1]*16+f[c2];
}

vector<int> solve(string s){
	int R = to_i( s[1] , s[2] );
	int G = to_i( s[3] , s[4] );
	int B = to_i( s[5] , s[6] );
	vector<int> color;
	color.push_back( R );
	color.push_back( G );
	color.push_back( B );
	return color;
}

int main(){
	const int t[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}
	};
	const string colorName[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	foo();

	string s;
	while( cin >> s , s != "0" ){
		vector<int> color = solve( s );
		int Rk = color[0];
		int Gk = color[1];
		int Bk = color[2];
		int ans = 0;
		int dk = 255*3+1;
		//cout << "R:" << Rk << " G:" << Gk << " B:" << Bk << endl;
		
		for(int i=0 ; i<8 ; ++i ){
			int R = t[i][0];
			int G = t[i][1];
			int B = t[i][2];
			dk = min( abs(Rk-R)+abs(Gk-G)+abs(Bk-B) , dk );
		}

		for(int i=0 ; i<8 ; ++i ){
			int R = t[i][0];
			int G = t[i][1];
			int B = t[i][2];
			if( abs(Rk-R)+abs(Gk-G)+abs(Bk-B) == dk ){
				ans = i;
				break;
			}
		}
		cout << colorName[ ans ] << endl;
	}
}