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<map>
#include<math.h>

using namespace std;

map<int, int> MR;
map<int, int> MG;
map<int, int> MB;

void make(){
  MR[0] = 0;
  MG[0] = 0;
  MB[0] = 0;
  MR[1] = 0;
  MG[1] = 0;
  MB[1] = 225;
  MR[2] = 0;
  MG[2] = 255;
  MB[2] = 0;
  MR[3] = 0;
  MG[3] = 255;
  MB[3] = 255;
  MR[4] = 255;
  MG[4] = 0;
  MB[4] = 0;
  MR[5] = 255;
  MG[5] = 0;
  MB[5] = 255;
  MR[6] = 255;
  MG[6] = 255;
  MB[6] = 0;
  MR[7] = 255;
  MG[7] = 255;
  MB[7] = 255;
}

int main(){

  make();

  char in[2];
  int status = 0;

  while(cin >> in[0]){
    if(in[0] == '0') break;

    int r, g, b;

    for(int i = 0; i < 3; i++){
      
      cin >> in[0] >> in[1];

      for(int j = 0; j <= 1; j++){
	if(in[j] == 'a') in[j] == ':';
	if(in[j] == 'b') in[j] == ';';
	if(in[j] == 'c') in[j] == '<';
	if(in[j] == 'd') in[j] == '=';
	if(in[j] == 'e') in[j] == '>';
	if(in[j] == 'f') in[j] == '?';
      }

      if(i == 0) r = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 1) g = (in[0] - 48) * 16 + (in[1] - 48);
      if(i == 2) b = (in[0] - 48) * 16 + (in[1] - 48);
    }

    double d;
    int min, then;

    for(int j = 0; j < 8; j++){
      d = sqrt((MR[j] - r)*(MR[j] - r)+(MG[j] - g)*(MG[j] - g)+(MB[j] - b)*(MB[j] - b));

      // cout << d << endl;
      if(j == 0 || min > d){
	min = d;
	then = j;
      }
    }

    if(then == 0) cout << "black" <<endl;
    if(then == 1) cout << "blue" <<endl;
    if(then == 2) cout << "lime" <<endl;
    if(then == 3) cout << "aqua" <<endl;
    if(then == 4) cout << "red" <<endl;
    if(then == 5) cout << "fuchsia" <<endl;
    if(then == 6) cout << "yellow" <<endl;
    if(then == 7) cout << "white" <<endl;

  }
  return 0;
}

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 <cmath>

using namespace std;

struct COLOR {
	int R;
	int G;
	int B;
};

int main() {
	string b;

	string co = "0123456789abcdef";


	COLOR samp[] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0}, 
					{255, 0, 255},{255,255,0},{255,255,255}};

	double d;
	string name[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	while (1) {
		cin >> b;
		if (b[0] != '#') {
			break;
		}
		int color[3] = {0};
		int count = 0; 
		double MIN = 100000.0;
		int mc;
		for (int i = 1; i < 7; i++) {
			if (i % 2 != 0) {
				for (int j = 0; j < co.size(); j++) {
					if (b[i] == co[j]) {
						color[count] += j*16;
						break;
					}
				}
			} else {
				for (int j = 0; j < co.size(); j++) {
					if (b[i] == co[j]) {
						color[count] += j;
						break;
					}
				}
				count++;
			}
		}
		for (int i = 0; i < 8; i++) {
			d = sqrt((double)pow(samp[i].R-color[0],2)+(double)pow(samp[i].G-color[1],2)+(double)pow(samp[i].B-color[2],2));
			if (d < MIN) {
				MIN = d;
				mc = i;
			}
		}
		cout << name[mc] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    string color[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
    int colornum[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}};
    int sixteen[200]={};
    for(int i=0;i<10;i++)sixteen[i]=i;
    for(int i=0;i<6;i++){
            sixteen['a'-'0'+i]=10+i;
            sixteen['A'-'0'+i]=10+i;
    }
    string str;
    while(cin>>str&&str!="0"){
        int num[3];
        for(int i=0;i<3;i++)num[i]=sixteen[str[1+2*i]-'0']*16+sixteen[str[2+2*i]-'0'];
        int ans[8]={};
        for(int i=0;i<8;i++){
            for(int j=0;j<3;j++)ans[i]+=pow(colornum[i][j]-num[j],2);
            ans[i]=sqrt(ans[i]);
        }
        int co=0;
        for(int i=1;i<8;i++)if(ans[co]>ans[i])co=i;
        cout<<color[co]<<endl;
    }
}