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 <stdio.h>
#include <string.h>

int main()
{
	int i0, i1, i2, i3, n, m, d[30][6], s[30], sw;
	char c[8];
	char color[6][8] = {"Cyan", "Yellow", "Red", "Magenta", "Green", "Blue"};

	scanf("%d", &n);
	while (n > 0) {
		for (i0 = 0; i0 < n; i0++) {
			for (i1 = 0; i1 < 6; i1++) {
				scanf("%s", c);
				for (i2 = 0; i2 < 6; i2++) {
					if (strcmp(c, color[i2]) == 0) {
						d[i0][i1] = i2;
						break;
					}
				}
			}
		}
		m = 0;
		for (i0 = 0; i0 < n; i0++)
			s[i0] = 1;
		for (i0 = 0; i0 < n; i0++) {
			if (s[i0] > 0) {
				m++;
				s[i0] = 0;
				for (i1 = i0+1; i1 < n; i1++) {
					sw = 0;
					for (i2 = 0; i2 < 3 && sw == 0; i2++) {
						for (i3 = 0; i3 < 6 && sw == 0; i3++) {
							if (d[i0][i2] == d[i1][i3]) {
								if (d[i0][5-i2] != d[i1][5-i3])
									sw = 1;
							}
						}
					}
					if (sw == 0)
						s[i1] = 0;
				}
			}
		}
		printf("%d\n", n-m);
		scanf("%d", &n);
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<vector<int>> d;
        int ans=0;
        map<string,int> mp;
        mp["Red"]=0;
        mp["Yellow"]=1;
        mp["Blue"]=2;
        mp["Magenta"]=3;
        mp["Green"]=4;
        mp["Cyan"]=5;
        const int sa[6][4]={
                {4,2,1,3},
                {0,2,5,3},
                {4,5,1,0},
                {4,0,1,5},
                {5,2,0,3},
                {4,3,1,2}
        };
        for (int i = 0; i < n; ++i) {
            vector<string> s(6);
            int id;
            for (int j = 0; j < 6; ++j) {
                cin>>s[j];
                if(s[j]=="Red")id=j;
            }
            vector<int> tv;
            for (int j = 0; j < 4; ++j) {
                tv.emplace_back(mp[s[sa[id][j]]]);
            }
            for(auto item:d){
                for (int j = 0; j < 4; ++j) {
                    bool f=true;
                    for (int k = 0; k < 4; ++k) {
                        if(tv[k]!=item[(j+k)%4]){
                            f=false;
                            break;
                        }
                    }
                    if(f){
                        ++ans;
                        goto failed;
                    }
                }
            }
            d.emplace_back(tv);
            failed:;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

//??????????????§??\??????????????¨??????
const int TOP=0,BOTTOM=1,FRONT=2,BACK=3,LEFT=4,RIGHT=5;

template<class T>
class dice{
public:
    dice(){
        for(int i=0;i<6;i++)id[i]=i;
    }

    T& operator[](int f){return var[id[f]];}
    const T& operator[](int f)const{return var[id[f]];}

    //???????????????????????´????????????
    bool operator==(const dice<T>&b)const{
        const dice<T>&a=*this;
        for(int i=0;i<6;i++)if(a[i]!=b[i])return false;
        return true;
    }

    //????¨??????¢??????
    void roll_x(){roll(TOP,BACK,BOTTOM,FRONT);}
    void roll_y(){roll(TOP,LEFT,BOTTOM,RIGHT);}
    void roll_z(){roll(FRONT,RIGHT,BACK,LEFT);}

    //?????¢??????????????\???24???????????¶????????????
    vector<dice<T> >all_rolls(){
        vector<dice<T> >ret;
        for(int k=0;k<6;(k&1?roll_y():roll_x()),k++){
            for(int i=0;i<4;roll_z(),i++){
                ret.push_back(*this);
            }
        }
        return ret;
    }

    bool equivalent_to(const dice<T>& di){
        vector<dice<T> >vec=all_rolls();
        for(int i=0;i<vec.size();i++){
            if(vec[i]==di)return true;
        }
        return false;
    }
private:
    void roll(int a,int b,int c,int d){
        int tmp=id[a];
        id[a]=id[b];id[b]=id[c];
        id[c]=id[d];id[d]=tmp;
    }

    T var[6];
    int id[6];
};

int main(){
    int N;
    while(cin>>N,N){
        vector<dice<string> >vec;

        int cnt=0;
        while(N--){
            dice<string>d;
            cin>>d[TOP];
            cin>>d[FRONT];
            cin>>d[RIGHT];
            cin>>d[LEFT];
            cin>>d[BACK];
            cin>>d[BOTTOM];

            bool ok=true;
            for(int i=0;i<vec.size();i++)
                if(vec[i].equivalent_to(d))ok=false;
            if(ok)vec.push_back(d);
            else cnt++;
        }

        cout<<cnt<<endl;
    }

    return 0;
}

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;
						}
						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;
						}
						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 (tatuo > 0)break;
					}
					if (tatuo > 0) break;
				}
				if (tatuo > 0) {
					tatuo = 0;
					break;
				}
			}
		}
		cout << a-ruio << endl;
	}
}