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>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

 
const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

struct Dice
{
    vi d;
    static const int top = 0, frt = 1, rit = 2, lft = 3, bck = 4, btm = 5;
    Dice(){
        rep(i, 6) d.pb(i + 1);
    }
    Dice(vi d):d(d){}
    Dice(int _d[]){
        rep(i, 6) d.pb(_d[i]);
    }
    void spin(int f1, int f2, int f3, int f4){
        int tmp = d[f1];
        d[f1] = d[f2];
        d[f2] = d[f3];
        d[f3] = d[f4];
        d[f4] = tmp;
    }
    void spinN(){
        spin(top, frt, btm, bck);
    }
    void spinS(){
        spin(top, bck, btm, frt);
    }
    void spinE(){
        spin(top, lft, btm, rit);
    }
    void spinW(){
        spin(top, rit, btm, lft);
    }
    void spinCW(){
        spin(frt, rit, bck, lft);
    }
    void spinCCW(){
        spin(frt, lft, bck, rit);
    }
 
    void spin(char c){  
        if(c == 'N') spinN();
        else if(c == 'S') spinS();
        else if(c == 'E') spinE();
        else if(c == 'W') spinW();  
    }
    void spin(string s){
        for(char c : s){
            spin(c);
        }
    }
    void spin(int t, int f){
        rep(i, 4){
            if(d[top] == t) break;
            spinN();
        }
        rep(i, 4){
            if(d[top] == t) break;
            spinE();
        }
        rep(i, 4){
            if(d[frt] == f) break;
            spinCW();
        }
    }
    void spinTop(int f){
        if(f == frt) spinN();
        else if(f == btm) rep(i, 2) spinN();
        else if(f == bck) spinS();
        else if(f == lft) spinE();
        else if(f == rit) spinW();
    }
 
    void spinSmall(){
        Dice tmp(d);
        rep(i, 6){
            if(tmp[top] < d[i]) continue;
            Dice d2(d);
            d2.spinTop(i);
            rep(j, 4){
                if(d2 < tmp) tmp.d = d2.d;
                d2.spinCW();
            }
        }
        d = tmp.d;
    }
 
    int operator[] (int n) const{
        return d[n];
    }
    bool operator == (const Dice& dice) const{
        rep(i, 6){
            if(d[i] != dice[i]) return false;
        }
        return true;
    }
    bool operator < (const Dice& dice) const{
        rep(i, 6) {
            if(d[i] != dice[i]) return d[i] < dice[i];
        }
        return false;
    }
};


int main(){
	map<string, int> mp;
	mp["Cyan"]		= 0;
	mp["Yellow"]	= 1;
	mp["Red"]		= 2;
	mp["Magenta"]	= 3;
	mp["Green"]		= 4;
	mp["Blue"]		= 5;

	while(1){
		int n = in.nextInt();
		if(n == 0) break;

		vector<Dice> d;
		int t[6];
		rep(i, n) {
			rep(j, 6) t[j] = mp[in.next()];
			d.pb(t);
			d.back().spinSmall();
		}

		sort(all(d));

		int ans = 0;
		rep(i, d.size() - 1) if(d[i] == d[i+1]) ans++;
		
		printf("%d\n", ans);
		// rep(i, n){
		// 	rep(j, 6) printf(" %d", d[i][j]);
		// 	printf("\n");
		// }
	}
}

C++: #include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main() {
	int a, b[101][101] = { 0 }, ruio = 0;
	char str[101];
	while (1) {
		cin >> a;
		if (a == 0)return 0;
		ruio = a;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= 6; j++) {
				scanf("%s", str);
				if (strstr(str, "Red") != NULL) {
					b[i][j] = 1;
				}
				if (strstr(str, "Yellow") != NULL) {
					b[i][j] = 2;
				}
				if (strstr(str, "Blue") != NULL) {
					b[i][j] = 3;
				}
				if (strstr(str, "Magenta") != NULL) {
					b[i][j] = 4;
				}
				if (strstr(str, "Green") != NULL) {
					b[i][j] = 5;
				}
				if (strstr(str, "Cyan") != NULL) {
					b[i][j] = 6;
				}
			}
		}
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= 6; j++) {
				cout << b[i][j] << ",";
			}
			cout << endl;
		}

		int tatuo = 0;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= a; j++) {
				if (j != i && b[j][1] != -1 &&b[i][1]!=-1) {
					if (b[i][1] + b[i][6] == b[j][1] + b[j][6]) {
						if (b[i][3] + b[i][4] == b[j][3] + b[j][4]) {
							if (b[i][2] + b[i][5] == b[j][2] + b[j][5]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							if (tatuo > 0)break;
						}
						else if (b[i][3] + b[i][4] == b[j][2] + b[j][5]) {
							if (b[i][2] + b[i][5] == b[j][3] + b[j][4]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
						}
						if (tatuo > 0)break;
					}
					else if (b[i][1] + b[i][6] == b[j][3] + b[j][4]) {
						if (b[i][3] + b[i][4] == b[j][2] + b[j][5]) {
							if (b[i][2] + b[i][5] == b[j][1] + b[j][6]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							if (tatuo > 0)break;
						}
						else if (b[i][3] + b[i][4] == b[j][1] + b[j][6]) {
							if (b[i][2] + b[i][5] == b[j][2] + b[j][5]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
						}
						if (tatuo > 0)break;
					}
					else if (b[i][1] + b[i][6] == b[j][2] + b[j][5]) {
						if (b[i][3] + b[i][4] == b[j][1] + b[j][6]) {
							if (b[i][2] + b[i][5] == b[j][3] + b[j][4]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							if (tatuo > 0)break;
						}
						if (b[i][3] + b[i][4] == b[j][3] + b[j][4]) {
							if (b[i][2] + b[i][5] == b[j][1] + b[j][6]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							if (tatuo > 0)break;
						}
						if (tatuo > 0)break;
					}
					if (tatuo > 0) break;
				}
				if (tatuo > 0) {
					tatuo = 0;
					break;
				}
			}
		}
		cout << a-ruio << endl;
	}
}