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>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
const int N = 6;
struct T{string f[N];}c,d,e;

bool operator<(const T&l,const T&r)
{
	for(int i=0;i<N;++i)
	{
		if(l.f[i]<r.f[i]) return true;
		else if(l.f[i]>r.f[i]) return false;
	}
	return false;
}
void r(T&r,int a[4])
{
	string t = r.f[a[0]];
	for(int i=1;i<4;++i) r.f[a[i-1]] = r.f[a[i]];
	r.f[a[3]]=t;
}
int main()
{
	int n,i,j,k,a[N][4]={
		{1,2,4,3},
		{0,2,5,3},
		{0,1,5,4},
		{0,1,5,4},
		{0,2,5,3},
		{1,2,4,3},
	};
	while(cin>>n,n)
	{
		set<T>s;
		for(i=0;i<n;++i)
		{
			for(j=0;j<N;++j)cin>>c.f[j];
			
			d=c;
			for(j=0;j<4;++j)
			{
				r(d, a[0]);
				for(k=0;k<4;++k)
				{
					r(d,a[1]);
					s.insert(d);
				}
			}
			for(j=0;j<4;++j)
			{
				r(d,a[2]);
				for(k=0;k<4;++k)
				{
					r(d,a[1]);
					s.insert(d);
				}
			}
			;
		}
		printf("%d\n",n-s.size()/24);
	}
	return 0;
}

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

int colorToInt(std::string s){
	const	char cs[] = {'C', 'Y', 'R', 'M', 'G', 'B'};
	for(int i=0;i<6;i++){
		if(s[0] == cs[i]){
			return i;
		}
	}
}

int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> cube_v;
		int cyan_pos;

		for(int i=0;i<n;i++){
			int cs[6];
			for(int j=0;j<6;j++){
				std::string c;
				std::cin >> c;
				cs[j] = colorToInt(c);
			}

			std::swap(cs[3], cs[5]);
			for(int j=0;j<6;j++){
				if(cs[j] == 0){
					cyan_pos = j;
				}
			}

			int cube = cs[(cyan_pos+3)%6] << 6,
				vs[] = {(cs[(cyan_pos+1)%6] << 3) + cs[(cyan_pos+4)%6],
					(cs[(cyan_pos+2)%6] << 3) + cs[(cyan_pos+5)%6]};

			for(int j=0;j<2;j++){
				if(std::find(cube_v.begin(), cube_v.end(), cube+vs[j]) == cube_v.end()){
					cube_v.push_back(cube+vs[j]);
				}
			}
		}

		std::cout << (n-cube_v.size()/2) << std::endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

static const int trans[][6] = 	{
									{ 0, 1, 2, 3, 4, 5 },	// no rotation 
									{ 2, 1, 5, 0, 4, 3 },	// left rotation
									{ 3, 1, 0, 5, 4, 2 }, 	// right rotation
									{ 1, 5, 2, 3, 0, 4 },	// top rotation
									{ 4, 0, 2, 3, 5, 1 },	// bottom rotation
									{ 0, 2, 4, 1, 3, 5 }	// front and buttom fixed right 90 ratate 
								};
set <vector <char> > comb;

bool is_same (vector <char> s, int i, vector <char> & t )
{
	bool found = false;
	rep (j, 6 ){
		t[j] = s[trans[i][j]];
	} // end rep
	if (comb.count (t ) ){
		found = true;
	} // end if

	return found;
}

int main()
{
	const string color[6] = { "Red", "Cyan", "Yellow", "Blue", "Magenta", "Green" };
	map<string, char> C;
	rep (i, 6 )
		C[color[i]] = color[i][0];


	int n;
	while (cin >> n && n ){
		comb.clear();
		vector <vector <char> > c(n, vector <char> (6 ) );
		rep (i, n ){
			rep (j, 6 ){
				string in;
				cin >> in;
				c[i][j] = C[in];
			} // end rep
		} // end rep
		for (int i = 0; i < n; i++ ){
			bool found = false;
			vector <char> t(6, 0 );
			rep (j, 5 ){
				if (is_same (c[i], j, t ) ){
					found = true;  
					break;
				} // end if
				vector <char> s = t;
				vector <char> r(6, 0 );
				rep (k, 3 )
				if (is_same (s, 5, r ) ){
					found = true;
					break;
				}else{
					s = r;
				} // end if
				vector <char> tt = t;			
				if (is_same (t, j, tt ) ){
					found = true; 
					break;
				} // end if
				s = tt;
				rep (k, 3 )
				if (is_same (s, 5, r ) ){
					found = true;
					break;
				}else{
					s = r;
				} // end if
			} // end rep
			if (!found ){
				comb.insert (c[i] );
			} // end if			
		} // end for
		int res = comb.size();
		cout << n - res << endl;
	} // end loop

		
	return 0;
}

C++: #define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
  int n;
  int ans=0;
  int box[30][6];
  bool b[30][30];
  int samenum;
  while(cin>> n,n){
    ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
    	b[i][j]=false;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<6;j++){
	string s;
	cin>> s;
	if(s=="Red") box[i][j]=0;
	else if(s=="Yellow") box[i][j]=1;
	else if(s=="Blue") box[i][j]=2;
	else if(s=="Magenta") box[i][j]=3;
	else if(s=="Green") box[i][j]=4;
	else if(s=="Cyan") box[i][j]=5;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j) continue;
	if(b[i][j]==true) continue;
	b[i][j]=b[j][i]=true;
	for(int k=0;k<6;k++){
	  if(box[i][0]==box[j][k]){
	    samenum=k; break;
	  }
	}
	if(box[j][samenum]-box[i][0]==0){
	  if(box[i][5]==box[j][5]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==1){
	  if(box[i][5]==box[j][4]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==2){
	  if(box[i][5]==box[j][3]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==3){
	  if(box[i][5]==box[j][2]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==4){
	  if(box[i][5]==box[j][1]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==5){
	  if(box[i][5]==box[j][0]){
	    ans++;
	  }
	}
      }
    }
    cout<< ans<< endl;
  }
}

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

int main(){
  int n;
  string cube[30][6];
  bool use[30];

  for(;;){
    cin >> n;
    if(!n)break;
    for(int i=0;i<n;i++){
      use[i] = false;
      for(int j=0;j<6;j++)cin >> cube[i][j];
    }

    for(int i=0;i<n;i++){
      if(!use[i]){
	for(int j=i+1;j<n;j++){
	  string tmp[6] = cube[j];
	  bool f;
	  for(int k=0;k<6;k++){
	    swap(tmp[0],tmp[1]);
	    swap(tmp[1],tmp[5]);
	    swap(tmp[5],tmp[4]);
	    for(int l=0;l<4;l++){
	      if(l){
		if(j%2){
		  swap(tmp[1],tmp[2]);
		  swap(tmp[2],tmp[4]);
		  swap(tmp[4],tmp[3]);
		}else{
		  swap(tmp[3],tmp[4]);
		  swap(tmp[4],tmp[2]);
		  swap(tmp[2],tmp[1]);
		}
	      }

	      f = true;
	      for(int z=0;z<6;z++)
		if(cube[i][z] != tmp[z])f = false;
	      if(f)break;
	    }
	    if(f)break;
	  }
	  if(f)use[j] = true;
	}
      }
    }
    int ans = 0;
    for(int i=0;i<n;i++)if(use[i])ans++;
    cout << ans << endl;
  }
}