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<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#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<algorithm>
#include<stdio.h>
using namespace std;
int main(){
    int c1[100],c2[100],c3[100],c4[100],c5[100],c6[100],i,j,n,k[100],count=0;
    for(j=0;j<100;j++){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>c1[i]>>c2[i]>>c3[i]>>c4[i]>>c5[i]>>c6[i];
        if(c1[i]==0&&c2[i]==0){
            break;
        }
        k[i]=c1[i]>>c2[i]>>c3[i]>>c4[i]>>c5[i]>>c6[i];
    }
        if(k[i]==k[i]){
            count++;
        }
        cout<<count<<endl;
        count=0;
    }
    return 0;
}

C++: #include <cstdio>
#include <string>

using namespace std;

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

string board[30][6];

bool same(int a, int b)
{
	for (int i = 0; i < 6; i++){
		for (int j = 0; j < 6; j++){
			if (board[a][i] != board[b][j]) continue;
			for (int dx = 0; dx < 4; dx++){
				bool same = true;
				for (int k = 0; k < 4; k++){
					if (board[a][rot[i][(k + dx) % 4]] != board[b][rot[j][k]])
						same = false;
				}
				if (same) return (true);
			}
		}
	}
	return (false);
}

int main()
{
	int n;
	while (scanf("%d", &n) && n){
		int ct = 0;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < 6; j++){
				char tmp[64];
				scanf("%s", tmp);
				board[i][j] = tmp;
			}
			bool ok = true;
			for (int j = 0; j < i; j++) if (same(i, j)) ok = false;
			ct += ok;
		}
		
		printf("%d\n", n - ct);
	}	
}

C++: #include<stdio.h>
#include<set>
#include<string>
using namespace std;
set<string> memo;

void flatRound(string& xai)
{
	char t=xai[2];
	xai[2]=xai[1];
	xai[1]=xai[3];
	xai[3]=xai[4];
	xai[4]=t;
	memo.insert(xai);
}

void northRound(string& xai)
{
	char t=xai[0];
	xai[0]=xai[1];
	xai[1]=xai[5];
	xai[5]=xai[4];
	xai[4]=t;
}

void eastRound(string& xai)
{
	char t=xai[0];
	xai[0]=xai[3];
	xai[3]=xai[5];
	xai[5]=xai[2];
	xai[2]=t;
}

void allRoundIn(string xai)
{
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<4;j++)
		{
			flatRound(xai);
		}
		eastRound(xai);
	}
	northRound(xai);
	for(int i=0;i<4;i++)
	{
		flatRound(xai);
	}
	northRound(xai);
	northRound(xai);
	for(int i=0;i<4;i++)
	{
		flatRound(xai);
	}
}

void setData(int n)
{
	char text[8];
	string xai = "000000";
	int redundancy=0;
	memo.clear();
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<6;j++)
		{
			scanf("%s",text);
			xai[j]=text[0];
		}
		if(memo.find(xai)==memo.end())
		{
			allRoundIn(xai);
		}
		else
		{
			redundancy++;
		}
	}
	printf("%d\n",redundancy);
}

int main()
{
	int n;
	while(1)
	{
		scanf("%d",&n);
		if(n==0) break;
		setData(n);
	}
}

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

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	dice(int top,int front,int right,int left,int back,int bottom) {
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	int& operator[] (FACE f) { return id[f]; }
	const int& operator[] (FACE f) const { return id[f]; }
	bool operator==(const dice &b) const {
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
	void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
	void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
	void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
	void all_rolls(set<long long> &s){
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				s.insert(((long long)id[TOP]<<40) | ((long long)id[FRONT]<<32) | (id[RIGHT]<<24) | (id[LEFT]<<16) | (id[BACK]<<8) | (id[BOTTOM]<<0));
	}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int main(){
	string str;
	int d[6];
	int n,i,j,r;
	for(;cin>>n,n;){
		set<long long>s;
		for(r=i=0;i<n;i++){
			for(j=0;j<6;j++)cin>>str,d[j]=str[0];
			long long x=((long long)d[0]<<40) | ((long long)d[1]<<32) | (d[2]<<24) | (d[3]<<16) | (d[4]<<8) | (d[5]<<0);
			if(s.find(x)!=s.end())r++;
			else{
				dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
				di.all_rolls(s);
			}
		}
		cout<<r<<endl;
	}
}