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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		string str;
		vector<vector<string> > vvs;
		for(int i = 0; i < n; i++){
			vector<string> vs;
			for(int j = 0; j < 6; j++){
				cin>>str;
				vs.push_back(str);
			}
			vvs.push_back(vs);
		}
		bool f=false;
		set<map<string,set<string> > > smsss;
		// ツ重ツ閉。ツつキツづゥツ姪堋づーツ探ツつキ
		for(int i = 0; i < n; i++){
//			for(int j = i+1; j < n; j++){
			vector<string> &v1=vvs[i];
			//				vector<string> &v2=vvs[j];
			
			map<string,set<string> > msss;
			
			for(int k = 0; k < 6; k++){
				if(k==0){
					msss[v1[k]].insert(v1[1]);
					msss[v1[k]].insert(v1[2]);
					msss[v1[k]].insert(v1[3]);
					msss[v1[k]].insert(v1[4]);
				}
				else if(k==1){
					msss[v1[k]].insert(v1[0]);
					msss[v1[k]].insert(v1[2]);
					msss[v1[k]].insert(v1[3]);
					msss[v1[k]].insert(v1[5]);
				}
				else if(k==2){
					msss[v1[k]].insert(v1[0]);
					msss[v1[k]].insert(v1[5]);
					msss[v1[k]].insert(v1[1]);
					msss[v1[k]].insert(v1[4]);
				}
				else if(k==3){
					msss[v1[k]].insert(v1[0]);
					msss[v1[k]].insert(v1[5]);
					msss[v1[k]].insert(v1[1]);
					msss[v1[k]].insert(v1[4]);
				}
				else if(k==4){
					msss[v1[k]].insert(v1[0]);
					msss[v1[k]].insert(v1[5]);
					msss[v1[k]].insert(v1[3]);
					msss[v1[k]].insert(v1[2]);
				}
				else if(k==5){
					msss[v1[k]].insert(v1[1]);
					msss[v1[k]].insert(v1[4]);
					msss[v1[k]].insert(v1[3]);
					msss[v1[k]].insert(v1[2]);
				}
			}
			smsss.insert(msss);
		}
		cout<<n-smsss.size()<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<functional>

using namespace std;

#define OUT cout <<
#define IN cin >>
#define E << endl;
#define FOR(i,a,b) for(int i = a;i < b;i++)

int n;

void input(){
	IN n;
}

class Dice{
	private:
		string temp;
	public:
		string c[6];
		Dice(){}
		void roll(int axis){
			if(axis == 1){
				temp = c[1];
				c[1] = c[2];
				c[2] = c[6];
				c[6] = c[5];
				c[5] = temp;
			}
			else{
				temp = c[2];
				c[2] = c[4];
				c[4] = c[5];
				c[5] = c[3];
				c[3] = temp;
			}
		}
		void getd(string& c1, string& c2, string& c3, string& c4, string& c5, string& c6){
			c1 = c[0];
			c2 = c[1];
			c3 = c[2];
			c4 = c[3];
			c5 = c[4];
			c6 = c[5];
		}

		void input(){
			FOR(i,0,6){
				IN c[i];
			}
		}

};

int main(){
	while(true){
		input();
		if(n == 0)break;
		int count = 0;
		bool match[n];
		FOR(i, 0, n){
			match[i] = false;
		}
		string str1[6];
		string str2[6];	

		vector<Dice> dice;
	
		dice.resize(n);
		FOR(i, 0, n){
			dice[i].input();
		}
			

		FOR(i, 0, n - 1){
			FOR(j, i + 1, n){
				bool flag2 = false;
				FOR(x, 0, 4){
					FOR(y, 0, 4){
						dice[i].getd(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
						dice[j].getd(str2[0],str2[1],str2[2], str2[3],str2[4],str2[5]);
						
						bool flag1 = true;
						FOR(d, 0, 6){					
							if(str1[d] != str2[d]){
								flag1 == false;
							}
						}
						if(flag1){
							if(match[i] == false){							
								flag2 = true;
							}
							match[j] = true;
						}
						flag1 = true;
					
						dice[i].roll(y);
					}
					dice[i].roll(x);
				}
				//OUT i << " " << j << " " << flag2 E
				if(flag2){
					count++;
					//OUT "count++ " << i << " " << j  E
				}
			}
		}	

		OUT count E

	}
}

C++: #include <stdio.h>
#include <set>

using namespace std;

set<unsigned int> hashList;

int make_face(char input)
{
	int ret;
	
	switch (input){
	  case 'R': ret = 0; break;
	  case 'G': ret = 1; break;
	  case 'B': ret = 2; break;
	  case 'C': ret = 3; break;
	  case 'M': ret = 4; break;
	  case 'Y': ret = 5; break;
	}
	
	return (ret);
}

unsigned int make_hash(int cube[])
{
	int ret;
	
	ret = 0;
	for (int i = 0; i < 6; i++){
		ret = ret * 6 + cube[i];
	}
	
	return (ret);
}

int rote_x(int cube[])
{
	int temp;
	
	temp = cube[1];
	cube[1] = cube[3];
	cube[3] = cube[4];
	cube[4] = cube[2];
	cube[2] = temp;
	
	return (0);
}

int rote_y(int cube[])
{
	int temp;
	
	temp = cube[0];
	cube[0] = cube[3];
	cube[3] = cube[5];
	cube[5] = cube[2];
	cube[2] = temp;
	
	return (0);
}

int rote_z(int cube[])
{
	int temp;
	
	temp = cube[0];
	cube[0] = cube[4];
	cube[4] = cube[5];
	cube[5] = cube[1];
	cube[1] = temp;
	
	return (0);
}

int main(void)
{
	int cube[6];
	int ans;
	int n;
	
	while (1){
		hashList.clear();
		
		scanf("%d", &n);
		
		if (n == 0){
			 break;
		}
		
		ans = 0;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < 6; j++){
				char str[20];
				
				scanf("%s", str);
				cube[j] = make_face(str[0]);
			}
			if (hashList.find(make_hash(cube)) != hashList.end()){
				ans++;
				continue;
			}
			for (int i = 0; i < 4; i++){
				for (int j = 0; j < 4; j++){
					for (int k = 0; k < 4; k++){
						hashList.insert(make_hash(cube));
						rote_x(cube);
					}
					rote_y(cube);
				}
				rote_z(cube);
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}