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 ; _ < 10 ; _++)
	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<cmath>
using namespace std;
int main() {
	long long a[10], c = 1, d, e = 0;
	int b = 0;
	while (c <= 1000000000) {
		a[b] = c;
		b++;
		c *= 8;
	}
	while (cin >> d&&d != 0) {
		e = 0;
		int f = 0;
		for (int i = b-1; i >= 0; i--) {
			f = 0;
			if (a[i] <= d) {
				while (a[i] <= d) {
					f++;
					d -= a[i];
				}
				if (f <= 3)
					e += (pow(10, i)*f);
				else if (f == 5)
					e += (pow(10, i)*(f + 2));
				else if (f < 6)
					e += (pow(10, i)*(f + 1));
				else if(f>=6)
					e += (pow(10, i)*(f + 2));
			}
		}
		cout << e << endl;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	string c[8] = { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
	int d[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} };
	while (cin>>a&&a!="0")
	{
		int t[3];
		for (int i = 1; i < a.length(); i += 2) {
			int b = 0;
			for (int j = 0; j <= 1; j++) {
				if ((int)a[i + j] >= '0' && (int)a[i +j] <= '9')
					b += (pow(16, (j+1)%2)*(int)(a[i +j] - '0'));
				else 
					b += (pow(16, (j+1)%2)*(10 + (int)a[i + j] - 'a'));
			}
			t[(i - 1) / 2] = b;
		}
		double e = 100000;
		string f = "";
		for (int i = 7; i >= 0; i--) {
			double g = sqrt(pow((t[0] - d[i][0]), 2) + pow((t[1] - d[i][1]), 2) + pow((t[2] - d[i][2]), 2));
			if (g <= e) {
				e = g;
				f = c[i];
			}
		}
		cout << f << endl;
	}
}

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

using namespace std;

class RGBc{
public:
	int R,G,B;
	string name;

	RGBc();
	RGBc(int R_,int G_,int B_){
		R=R_;
		G=G_;
		B=B_;
	}

	bool operator<(const RGBc &rgb)const{
		return rgb.R>this->R;
	}
};

int main(){
	
	//map<RGB,string>table;
	vector<RGBc> vrgb;
	RGBc tmp(0,0,0);

	tmp.name="black";
	tmp.R=0;
	tmp.G=0;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="blue";
	tmp.R=0;
	tmp.G=0;
	tmp.B=255;
	vrgb.push_back(tmp);

	tmp.name="lime";
	tmp.R=0;
	tmp.G=255;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="aqua";
	tmp.R=0;
	tmp.G=255;
	tmp.B=255;
	vrgb.push_back(tmp);

	tmp.name="red";
	tmp.R=255;
	tmp.G=0;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="fuchsia";
	tmp.R=255;
	tmp.G=0;
	tmp.B=255;
	vrgb.push_back(tmp);

	tmp.name="yellow";
	tmp.R=255;
	tmp.G=255;
	tmp.B=0;
	vrgb.push_back(tmp);

	tmp.name="white";
	tmp.R=255;
	tmp.G=255;
	tmp.B=255;
	vrgb.push_back(tmp);

	//table["black"].R=0;
	//table["black"].G=0;
	//table["black"].B=0;

	//table["blue"]=RGB(0,0,255);
	//table["lime"]=RGB(0,255,0);
	//table["aqua"]=RGB(0,255,255);
	//table["red"]=RGB(255,0,0);
	//table["fuchsia"]=RGB(255,0,255);
	//table["yellow"]=RGB(255,255,0);
	//table["white"]=RGB(255,255,255);

	string str;
	while(cin>>str&&str!="0"){
		vector<int> v;
		for(int i = 1; i < str.size(); i+=2){
			int num=0;
			if(str[i]>='a'&&str[i]<='f'){
				num+=str[i]-'a'+10;
				num*=16;
			}
			else{
				num+=str[i]-'0';
				num*=16;
			}
			if(str[i+1]>='a'&&str[i+1]<='f'){
				num+=str[i+1]-'a'+10;
			}
			else{
				num+=str[i+1]-'0';
			}
			v.push_back(num);
		}

		int R=v[0];
		int G=v[1];
		int B=v[2];

		int minDk=10000000;
		string color;
		for(int i = 0; i < vrgb.size(); i++){
			int dk=(R-vrgb[i].R)*(R-vrgb[i].R)+(G-vrgb[i].G)*(G-vrgb[i].G)+(B-vrgb[i].B)*(B-vrgb[i].B);
			if(minDk>dk){
				minDk=dk;
				color=vrgb[i].name;
			}
		}
		cout<<color<<endl;
	}

	return 0;
}