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 <string>
using namespace std;

int cheak(int n,string c[][6]){
    int cou=0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            for (int a=0; a<4; a++) {
                if(c[i][0]==c[j][0]){
                    for (int b=0; b<4; b++) {
                        if(c[i][1]==c[j][1]&&c[i][2]==c[j][2]&&c[i][3]==c[j][3]&&c[i][4]==c[j][4]){
                            cou++;
                            swap(c[j], c[n-1]);
                            --n;
                            --j;
                            break;
                        }
                        swap(c[i][1], c[i][3]);
                        swap(c[i][1], c[i][4]);
                        swap(c[i][1], c[i][2]);
                    }
                    break;
                }
                swap(c[i][0],c[i][3]);
                swap(c[i][0],c[i][5]);
                swap(c[i][0],c[i][2]);
            }
        }
    }
    return cou;
}

int main(){
    int n;
    string cube[30][6];
    while (1) {
        cin>>n;
        if(n==0)break;
        for (int i=0; i<n; i++) {
            for (int j=0; j<6; j++) {
                cin>>cube[i][j];
            }
        }
        cout<<cheak(n, cube)<<endl;
    }
    return 0;
}

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

using namespace std;

class DICE {
public:
	string top;
	string bottom;
	string left;
	string right;
	string front;
	string back;
	void TF();
	void TB();
	void TL();
	void TR();
	void TurnL();
	void TurnR();
	bool HANTEI(DICE d2);
	bool CHECK(DICE d2);
};

void DICE::TF() {
	string kari = front;
	front = top;
	top = back;
	back = bottom;
	bottom = kari;
}

void DICE::TB() {
	TF();
	TF();
	TF();
}

void DICE::TL() {
	string kari = left;
	left = top;
	top = right;
	right = bottom;
	bottom = kari;
}

void DICE::TR() {
	TL();
	TL();
	TL();
}

void DICE::TurnL() {
	string kari = left;
	left = back;
	back = right;
	right = front;
	front = kari;
}

void DICE::TurnR() {
	TurnL();
	TurnL();
	TurnL();
}

bool DICE::HANTEI(DICE d2) {
	if ((top==d2.top)&&(bottom==d2.bottom)&&(left==d2.left)&&(right==d2.right)&&(front==d2.front)&&(back==d2.back)) {
		return true;
	}
	return false;
}

bool DICE::CHECK(DICE d2) {
	DICE d3 = d2;
	for (int i = 0; i < 4; i++) {
		d3.TurnL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TF();
	d3.TF();
	for (int i = 0; i < 4; i++) {
		d3.TurnL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TF();
	for (int i = 0; i < 4; i++) {
		d3.TL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TB();
	for (int i = 0; i < 4; i++) {
		d3.TL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TL();
	for (int i = 0; i < 4; i++) {
		d3.TF();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TR();
	for (int i = 0; i < 4; i++) {
		d3.TF();
		if (HANTEI(d3)) {
			return true;
		}
	}
	return false;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<DICE> dd;
		for (int i = 0; i < n; i++) {
			DICE d;
			cin >> d.top >> d.front >> d.right >> d.left >> d.back >> d.bottom;
			bool h = true;
			for (int j = 0; j < dd.size(); j++) {
				if (dd[j].CHECK(d)) {
					h = false;
					break;
				}
			}
			if (h) {
				dd.push_back(d);
			}
		}
		int sz = dd.size();
		cout << n-sz << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
using namespace std;

int same[][4] = {
	{1, 2, 4, 3},
	{5, 2, 0, 3},
	{1, 5, 4, 0},
	{1, 0, 4, 5},
	{0, 2, 5, 3},
	{1, 3, 4, 2},
};

int s2i(string s) {
	if(s == "Red")
		return 0;
	if(s == "Yellow")
		return 1;
	if(s == "Blue")
		return 2;
	if(s == "Magenta")
		return 3;
	if(s == "Green")
		return 4;
	if(s == "Cyan")
		return 5;
	return -1;
}

bool eq(vector<int> a, vector<int> b) {
	int indx0, indx1;
	for(int i = 0; i < 6; i++) {
		if(a[i] == 0)
			indx0 = i;
		if(b[i] == 0)
			indx1 = i;
	}

	for(int i = 0; i < 4; i++) {
		bool flg = true;
		for(int j = 0; j < 4; j++) {
			flg &= a[same[indx0][j]] == b[same[indx1][(j + i) % 4]];
		}
		if(flg)
			return true;
	}

	return false;
}

int main() {
	int n;
	while(cin >> n, n) {
		vector<vector<int> > v;
		for(int i = 0; i < n; i++) {
			vector<int> tmp;
			for(int j = 0; j < 6; j++) {
				string s;
				cin >> s;
				tmp.push_back(s2i(s));
			}
			bool flg = true;
			for(int j = 0; j < v.size(); j++) {
				if(eq(v[j], tmp)) {
					flg = false;
				}
			}
			if(flg)
				v.push_back(tmp);
		}

		cout << n - v.size() << endl;
	}
}

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

vector<string>V;
int find(string s){
	for(int i=0;i<V.size();i++)if(V[i]==s)return 1;
	return 0;
}

int d[3][6]={
	{3,0,1,2,4,5},
	{4,1,5,3,2,0},
	{0,4,2,5,3,1}
};
string rot(string s,int n){
	string S=s;
	for(int i=0;i<6;i++)S[i]=s[d[n][i]];
	return S;
}
int step[12]={0,1,0,1,0,1,0,1,2,0,2,0};
int STEP[12]={4,1,4,1,4,1,4,1,1,4,2,4};

string cng(string s){
	string S=s;
	S[0]=s[3];
	S[1]=s[0];
	S[2]=s[2];
	S[3]=s[5];
	S[4]=s[4];
	S[5]=s[1];
	return S;
}

int main(){
	
	for(int n;cin>>n,n;){
		V.clear();
		for(int i=0;i<n;i++){
			string s="",t;
			for(int j=0;j<6;j++){
				cin>>t;
				s+=t[0];
			}
			s=cng(s);
			int f=1;
			for(int j=0;j<12;j++){
				for(int k=0;k<STEP[j];k++){
					s=rot(s,step[j]);
					if(find(s))f=0;
				}
			}
			if(f)V.push_back(s);
		}
		cout<<n-V.size()<<endl;
	}
	
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define MAX 100
class Cube {
public:
	string f[6];
	Cube() {
	}
	void roll_z() {
		roll(1, 2, 4, 3);
	}
	void roll_y() {
		roll(0, 2, 5, 3);
	}
	void roll_x() {
		roll(0, 1, 5, 4);
	}
	void roll(int i, int j, int k, int l) {
		string t = f[i];
		f[i] = f[j];
		f[j] = f[k];
		f[k] = f[l];
		f[l] = t;
	}
};
Cube C[MAX];
int n;
bool eq(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++)
		if (c1.f[i] != c2.f[i])
			return false;
	return true;
}

bool equal(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 4; j++) {
			if (eq(c1, c2))
				return true;
			c1.roll_z();
		}
		if (i % 2 == 0)
			c1.roll_y();
		else
			c1.roll_x();
	}
	return false;
}
main() {
	while( cin >> n && n ) {
		for(int i = 0;i<n;i++) for(int j = 0;j<6;j++) cin >> C[i].f[j];
		int cnt = 0;
		for(int i = 0;i<n;i++) {
			bool hasSame = false;
			for(int j=i+1; j<=n-1;j++) if (equal(C[i],C[j])) {hasSame =
				true;break;}
			if ( !hasSame ) cnt++;
		}
		cout << n - cnt << endl;
	}
}