Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
		"reflect"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	// 上面の色を固定してから、左右方向に回転して一致するものがあるかを調べる
	round := [][]int{
		{1,2,3,4,5,6}, {1,3,5,2,4,6}, {1,4,2,5,3,6}, {1,5,4,3,2,6}, // c1を上面に固定して回転
		{2,6,3,4,1,5}, {2,3,1,6,4,5}, {2,1,4,3,6,5}, {2,4,6,1,3,5}, // c2を上面に固定して回転
		{3,1,2,5,6,4}, {3,2,6,1,5,4}, {3,5,1,6,2,4}, {3,6,5,2,1,4}, // c3を上面に固定して回転
		{4,1,5,2,6,3}, {4,2,1,6,5,3}, {4,5,6,1,2,3}, {4,6,2,5,1,3}, // c4を上面に固定して回転
		{5,1,3,4,6,2}, {5,3,6,1,4,2}, {5,4,1,6,3,2}, {5,6,4,3,1,2}, // c5を上面に固定して回転
		{6,2,4,3,5,1}, {6,3,2,5,4,1}, {6,5,3,4,2,1}, {6,4,5,2,3,1}, // c6を上面に固定して回転

	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		cubes := make([][]string, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			cubes[i] = strings.Split(scanner.Text(), " ")
		}
		check := func(a, b int) bool {
			tmp := make([]string, 6)
			for i := 0; i < 24; i++ {
				for j := 0; j < 6; j++ {
					tmp[j] = cubes[b][round[i][j]-1]
				}
				if reflect.DeepEqual(tmp, cubes[a]) {
					return true
				}
			}
			return false
		}
		tbl := make([]int, n)
		// 全ての組み合わせを調べる
		for i := 0; i < n; i++ {
			if tbl[i] == 1 {
				continue
			}
			for j := i+1; j < n; j++ {
				if check(i, j) {
					tbl[j] = 1
				}
			}
		}
		fmt.Println(sum(tbl))
	}
}

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

C++: #include <iostream>

using namespace std;

enum Color {
    Red, Yellow, Blue,
    Magenta, Green, Cyan
};

struct Dice {
    Color dice[6];
};

bool Rotate(const Dice &a, Dice &b, int d)
{
    if (d == 1) {
        swap(b.dice[0], b.dice[4]);
        swap(b.dice[0], b.dice[1]);
    }
    else if (d == 2) {
        swap(b.dice[0], b.dice[3]);
        swap(b.dice[0], b.dice[2]);
        swap(b.dice[2], b.dice[5]);
    }
    else if (d == 3) {
        swap(b.dice[0], b.dice[2]);
        swap(b.dice[0], b.dice[5]);
        swap(b.dice[0], b.dice[3]);
    }
    else if (d == 4) {
        swap(b.dice[0], b.dice[1]);
        swap(b.dice[0], b.dice[4]);
    }
    else if (d == 5) {
        swap(b.dice[0], b.dice[5]);
        swap(b.dice[2], b.dice[3]);
    }

    if (a.dice[5] != b.dice[5])
        return false;

    for (int i = 0; i < 3; ++i) {
        bool flag = true;
        for (int j = 0; j < 6; ++j)
            if (a.dice[j] != b.dice[j]) {
                flag = false;
                break;
            }
        if (flag)
            return true;

        for (int j = 1; j <= 3; ++j)
            swap(b.dice[j], b.dice[j + 1]);
    }

    return false;
}

bool isSame(const Dice &a, Dice &b)
{
    for (int i = 0; i < 6; ++i)
        if (a.dice[0] == b.dice[i]) {
            if (Rotate(a, b, i))
                return true;
        }

    return false;
}

int main()
{
    int n;

    while (cin >> n, n) {
        Dice obj[n];
        string inp;

        for (int i = 0; i < n; ++i)
            for (int j = 0; j < 6; ++j) {
                cin >> inp;

                if (inp == "Red")
                    obj[i].dice[j] = Red;
                else if (inp == "Yellow")
                    obj[i].dice[j] = Yellow;
                else if (inp == "Blue")
                    obj[i].dice[j] = Blue;
                else if (inp == "Magenta")
                    obj[i].dice[j] = Magenta;
                else if (inp == "Green")
                    obj[i].dice[j] = Green;
                else if (inp == "Cyan")
                    obj[i].dice[j] = Cyan;
            }

        int same = 0;
        for (int i = 0; i < n; ++i)
            for (int j = i + 1; j < n; ++j)
                if (isSame(obj[i], obj[j]))
                    ++same;

        cout << same << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
string color[6] =  {"Cyan", "Yellow", "Red", "Magenta", "Green", "Blue"};
int* south(int c[6]) {
	int buf = c[0];
	c[0] = c[1];
	c[1] = c[5];
	c[5] = c[4];
	c[4] = buf;
	return c;
}
int* east(int c[6]) {
	int buf = c[0];
	c[0] = c[2];
	c[2] = c[5];
	c[5] = c[3];
	c[3] = buf;
	return c;
}
int* round(int c[6]) {
	int buf = c[1];
	c[1] = c[2];
	c[2] = c[4];
	c[4] = c[3];
	c[3] = buf;
	return c;
}
bool check(int d1[6], int d2[6]) {
	rep(i,6) {
		if(i%2)d1 = south(d1);
		else d1 = east(d1);
		rep(j,4) {
			d1 = round(d1);
			bool f = 1;
			rep(k,6) {
				if(d1[k] != d2[k]) {
					f = 0;
					break;
				}
			}	
			if(f) return true;
		}
	}
	return false;
}
int main(){
	int n, d[30][6] = {};
	string s;
	while(cin >> n, n) {
		rep(i,n) {
			rep(j,6) {
				cin >> s;
				rep(k,6) {
					if(color[k] == s) d[i][j] = k;
				}
			}
		}
		int a[30];
		bool used[30] = {};
		rep(i,n) a[i] = i;
		rep(i,n) {
			rep2(j,i+1,n) {
				if(check(d[i],d[j])) {
					a[j] = i;
				}
			}
		}
		rep(i,n) used[a[i]] = true;
		int ret = 0;
		rep(i,n) {
			if(!used[i]) ret++;
		}
		cout << ret << endl;
	}
	return 0;
}