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<algorithm>
#include<vector>
#include<string>
using namespace std;
int x[6][6] = { { 0,3,5,2,4,0 },{ 4,0,1,6,0,3 },{ 2,6,0,0,1,5 },{ 5,1,0,0,6,2 },{ 3,0,6,1,0,4 },{ 0,4,2,5,3,0 } };
vector<int>z[1000]; int Ty[1000], cnt;
bool solve(vector<int>p1, vector<int>p2) {
	int b[7] = { 0,0,0,0,0,0,0 }, maxn = 0, a[6] = { 0,0,0,0,0,0 };
	for (int i = 0; i < 6; i++) { b[p1[i]]++; b[p2[i]]++; }
	for (int i = 0; i < 7; i++)maxn = max(maxn, b[i]);
	if (maxn >= 6)return true;
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 6; j++) {
			if (p1[j] == p2[i]) a[i] = j;
		}
	}
	if (x[a[0]][a[1]] == a[2] + 1) return true;
	return false;
}
int main() {
	while (true) {
		int n; cin >> n; if (n == 0)break;
		for (int i = 0; i < 1000; i++)z[i].clear();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 6; j++) {
				string S; cin >> S;
				if (S[0] == 'C')z[i].push_back(1);
				if (S[0] == 'M')z[i].push_back(2);
				if (S[0] == 'Y')z[i].push_back(3);
				if (S[0] == 'R')z[i].push_back(4);
				if (S[0] == 'B')z[i].push_back(5);
				if (S[0] == 'G')z[i].push_back(6);
			}
		}
		cnt = 1; for (int i = 0; i < 1000; i++)Ty[i] = -1; Ty[0] = 1;
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < i; j++) {
				if (solve(z[i], z[j]) == true)Ty[i] = Ty[j];
			}
			if (Ty[i] == -1) { cnt++; Ty[i] = cnt; }
		}
		cout << n - cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int n;
  vector<string> col;
  col.push_back("Red");
  col.push_back("Yellow");
  col.push_back("Blue");
  col.push_back("Magenta");
  col.push_back("Green");
  col.push_back("Cyan");
  while(cin>>n,n){
    int c[30][6] = {0};
    int check[30] = {0};
    int t[30][6];
    REP(i,n)
      REP(j,6){
        string tmp;
        cin >> tmp;
        REP(k,6){
          if(col[k] == tmp){
            c[i][j] = k;
            break;
          }
        }
      }
    int count = 0;
    REP(i,n)
      REP(j,6)
        t[i][c[i][j]] = c[i][5-j];
    REP(i,n){
      if(check[i] == 0){
        int check1=0;
        REP(l,3){
          if(c[i][l]>2) check1++;
        }
        FOR(j,i+1,n){
          int check2 = 0;
          int check3 = 0;
          bool f = true;
          REP(k,6){
            if(t[i][k] != t[j][k]) f=false;
          }
          REP(l,3){
            if(c[j][l]>2) check2++;
          }
          REP(l,3){
            if(c[i][l] != c[j][l] && c[i][l] != t[j][c[j][l]]) check3++;
          }
          if(check3>0) check3--;
          if((check1+check2+check3)%2!=0) f=false;
          if(f){
            check[j] = 1;
            count++;
          }
        }
      }
    }
    cout<<count<<endl;
  }
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[31][7],d[31],f[31],g,h,i,j,k,l,o,x;
	char z[31][7][10];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			for(j=0;j<6;j++){
				scanf("%s",z[i][j]);
				if(z[i][j][0]=='R') s[i][j]=0;
				if(z[i][j][0]=='Y') s[i][j]=1;
				if(z[i][j][0]=='B') s[i][j]=2;
				if(z[i][j][0]=='M') s[i][j]=3;
				if(z[i][j][0]=='G') s[i][j]=4;
				if(z[i][j][0]=='C') s[i][j]=5;
			}
		}
		for(i=0;i<a;i++) f[i]=0;
		g=0;
		for(i=0;i<a-1;i++){
			if(f[i]==0){
				for(j=i+1;j<a;j++){
					for(k=0;k<5;k++){
						h=s[j][0];
						s[j][0]=s[j][1];
						s[j][1]=s[j][5];
						s[j][5]=s[j][4];
						s[j][4]=h;
						for(l=0;l<5;l++){
							x=0;
							h=s[j][1];
							s[j][1]=s[j][2];
							s[j][2]=s[j][4];
							s[j][4]=s[j][3];
							s[j][3]=h;
							for(o=0;o<6;o++){
								if(s[i][o]!=s[j][o]) break;
								else x++;
							}
							if(x==6){
								f[j]=1;
								g++;
							/*	for(o=0;o<6;o++) printf("%d %d\n",s[i][o],s[j][o]);
								printf("%d\n",j);*/
								break;
							}
						}
						if(f[j]==1) break;
					}
				}
			}
		}
		printf("%d\n",g);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
struct BOX {
  string top;
  string back, left, right, head;
  string buttom;
  bool operator==(const BOX& b) const {
    return(top    == b.top   &&
           back   == b.back  &&
           left   == b.left  &&
           right  == b.right &&
           head   == b.head  &&
           buttom == b.buttom);
  }
};
 
void Roll(BOX& B)
{
  string temp = B.head;
  B.head = B.right;
  B.right = B.back;
  B.back = B.left;
  B.left = temp;
}
 
void RoLL(BOX& B) {
  string temp = B.head;
  B.head = B.top;
  B.top = B.back;
  B.back = B.buttom;
  B.buttom = temp;
}
 
bool Myon(BOX& a, BOX& b)
{
  for(int k = 0; k < 4; k++) {
    Roll(a);
    for(int l = 0; l < 4; l++) {
      RoLL(a);
      if(a == b) return(true);
    }
  }
  return(false);
}
 
int main()
{
  int n;
  vector< BOX > boxes;
  while(cin >> n, n) {
    boxes.resize(n);
    for(int i = 0; i < n; i++) {
      BOX &b = boxes[i];
      cin >> b.top >> b.head >> b.right >> b.left >> b.back >> b.buttom;
    }
    int ret = 0;
    for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
        if(Myon(boxes[i], boxes[j])) {
           ++ret;
           break;
        }
      }
    }
    cout << ret << endl;
  }
}