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<algorithm>
#include<iostream>
#include<string>
#include<set>
using namespace std;
string a, b, c, d, e, f;
int n;
int main(){
  while(cin >> n, n){
    set<int> num;
    for(int i = 0;i < n;i++){
      cin >> a >> b >> c >> d >> e >> f;
      int p = (int)(b[0] + e[0]) * (int)(c[0] + d[0]) * (int)(a[0] + f[0]);
      if(((a<f) + (b<d) + (c<f)) % 3)p *= -1;
      num.insert(p);
    }
    cout << n - num.size() << endl;
  }
  return 0;
}

C++: 
// Trouble in Shinagawa's Artifacts
//  URL: http://rose.u-aizu.ac.jp/onlinejudge/ProblemSet/description.jsp?id=0198&lang=jp

#include <cstdio>
#include <cstring>
#include <vector>
#include <set>

// Ö
std::vector <int> rotate_x( std::vector <int> box );
std::vector <int> rotate_y( std::vector <int> box );
std::vector <int> rotate_z( std::vector <int> box );


// xÉñ]³¹éÖ
std::vector <int> rotate_x( std::vector <int> box )
{
	// xñ]
	// c1, c2, c3, c4, c5, c6 : default
	// c5, c1, c3, c4, c6, c2

	int tmp = box[0];
	box[0] = box[4];
	box[4] = box[5];
	box[5] = box[1];
	box[1] = tmp;

	return box;

}


// yÉñ]³¹éÖ
std::vector <int> rotate_v( std::vector <int> box )
{
	// yñ]
	// c1, c2, c3, c4, c5, c6 : default
	// c1, c4, c2, c5, c3, c6

	int tmp = box[1];
	box[1] = box[3];
	box[3] = box[4];
	box[4] = box[2];
	box[2] = tmp;

	return box;

}

// zÉñ]³¹éÖ
std::vector <int> rotate_z( std::vector <int> box )
{
	// zñ]
	// c1, c2, c3, c4, c5, c6 : default
	// c3, c2, c6, c1, c5, c4
	
	int tmp	= box[0];
	box[0]	= box[2];
	box[2]	= box[5];
	box[5]	= box[3];
	box[3]	= tmp;

	return box;

}

// Gg[|Cg
int main()
{

	// Ï
	int n;
	int answer;
	char color[32];
	std::vector <int> box( 6, 0 );
	std::set < std::vector <int> > table;

	/*
	// debug
	std::vector <int> test( 6, 0 );
	for( int i = 0; i < 6; ++i )
	{
		test[i] = i + 1;
	}

	for( int j = 0; j < 4; ++j )
	{
		if( j > 0 )
		{
			test = rotate_h( test );
		}
		printf( "¡\n" );
		for( int l = 0; l < 6; ++l )
		{
			printf( "%d: %d\n", l, test[l] );
		}
		puts( "//==================================================" );
		
		// c
		for( int k = 0; k < 4; ++k )
		{
			test = rotate_v( test );
			printf( "c\n" );
			for( int l = 0; l < 6; ++l )
			{
				printf( "%d: %d\n", l, test[l] );
			}
			puts( "//==================================================" );
		}
	}
	// debug
	*/

	while( 1 )
	{
		// ú»
		answer = 0;
		table.clear();
		for( int i = 0; i < 6; ++i )
		{
			box[i] = 0;
		}

		// üÍ
		std::fflush( stdin );
		std::scanf( "%d", &n );

		// üÍÌIíèF[ÐÆÂ
		if( n == 0 ) break;

		// nÌ¾¯ÇÝÞ
		for( int i = 0; i < n; ++i )
		{
			std::fflush( stdin );

			// FîñðüÍ
			for( int j = 0; j < 6; ++j )
			{
				std::scanf( "%s", color );

				// µ¢â·¢æ¤É¶ñ¨®ÉÏ·
				// F: Red, Yellow, Blue, Magenta, Green, Cyan
				if( std::strcmp( "Red", color ) == 0 )
					box[j] = 1;
				else if( std::strcmp( "Yellow", color ) == 0 )
					box[j] = 2;
				else if( std::strcmp( "Blue", color ) == 0 )
					box[j] = 3;
				else if( std::strcmp( "Magenta", color ) == 0 )
					box[j] = 4;
				else if( std::strcmp( "Grdeen", color ) == 0 )
					box[j] = 5;
				else if( std::strcmp( "Cyan", color ) == 0 )
					box[j] = 6;
			}

			// insertÌOÉ¯¶àÌªÈ¢©T·
			// ¯¶àÌª Á½çJEg
			if( table.find( box ) != table.end() )
			{
				++answer;
				continue;
			}

			// insertµÄ¨­
			// ¡¨cx3ð4ñ

			// x
			for( int j = 0; j < 4; ++j )
			{
				box = rotate_x( box );
				table.insert( box );
			}

			// y
			for( int j = 0; j < 4; ++j )
			{
				box = rotate_y( box );
				table.insert( box );
			}

			// z
			for( int j = 0; j < 4; ++j )
			{
				box = rotate_z( box );
				table.insert( box );
			}

		}

		// oÍ
		std::printf( "%d\n", answer );

	}

} // main()

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

using namespace std;


class Dice{
private:
	int yoko;
	int tate;
	int round;

public:
	string face[3][4];

	string getFace(int i,int j)const{
		return face[i][j];
	}

	Dice(vector<string> &v){
		init();
		face[1][1]=v[0];
		face[2][1]=v[1];
		face[1][2]=v[2];
		face[1][0]=v[3];
		face[0][1]=v[4];
		face[1][3]=v[5];
	}

	void init(){
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 4; j++){
				face[i][j]="";
			}
		}
		yoko=0;
		tate=0;
		round=0;
	}

	void rotate(){
		if(round<4){
			string tmp = face[2][1];
			face[2][1]=face[1][2];
			face[1][2]=face[0][1];
			face[0][1]=face[1][0];
			face[1][0]=tmp;
			round++;
		}
		if(round>=4){
			round=0;
			// àÇÁÄ«½çA¡ÌXbgðñ]³¹é
			if(yoko<4){
				string tmp = face[1][3];
				for(int i = 2; i >= 0; i--){
					face[1][i+1]=face[1][i];
				}
				face[1][0]=tmp;
				yoko++;
			}
			// àÇÁÄ«½çAcÌXbgðñ]³¹é
			if(yoko>=4){
				if(tate<4){
					tate++;
					string tmp = face[1][3];
					face[1][3]=face[0][1];
					for(int i = 0; i < 2; i++){
						face[i][1]=face[i+1][1];
					}
					face[2][1]=tmp;
				}
				if(tate>=4){
					round=0;
					tate=0;
					yoko=0;
				}
			}
		}
	};
};

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<Dice> ds;
		for(int i = 0; i < n; i++){
			vector<string> v;
			for(int j = 0; j < 6; j++){
				string str;
				cin>>str;
				v.push_back(str);
			}
			ds.push_back(Dice(v));
		}

		vector<Dice> used;
		used.push_back(ds[0]);
		for(int i = 1; i < n; i++){
			bool t=false;
			// ÇêðÝé©
			bool f=false;
			for(int j = 0; j < used.size(); j++){
				// ÇÌûü©
				for(int k = 0; k < 24; k++){
					// ½ÄÆæ±
					for(int l = 0; l < 3; l++){
						for(int m = 0; m < 4; m++){
							if(used[j].face[l][m]!=ds[i].face[l][m]){
								t=true;
								break;
							}
						}
						if(t)
							break;
					}
					if(!t){
						f=true;
					}
					used[j].rotate();
					t=false;
				}
				if(f)
					break;
				// àµÇÌûüÅàêvµÈ©Á½çAXgÉÁ¦é
				//for(int l = 0; l < 3; l++){
				//	for(int k = 0; k < 4; k++){
				//		cout<<used[j].face[l][k]<<" ";
				//	}
				//	cout<<endl;
				//}
				//cout<<endl;
			}
			if(!f){
				used.push_back(ds[i]);
			}
		}
		cout<<n-used.size()<<endl;
	}

	return 0;
}