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>
using namespace std;

typedef vector<string> Dice;

void rotate_front(Dice& dice)
{
	string t = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = t;
}

void rotate_right(Dice& dice)
{
	string t = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = t;
}

void rotate_clock(Dice& dice)
{
	string t = dice[1];
	dice[1] = dice[2];
	dice[2] = dice[4];
	dice[4] = dice[3];
	dice[3] = t;
}

void rotate(Dice& dice, string top)
{
	for(int i=0; i<4; i++)
	{
		if(dice[0] == top) return;
		rotate_front(dice);
	}

	for(int i=0; i<4; i++)
	{
		if(dice[0] == top) return;
		rotate_right(dice);
	}
}

bool match(Dice d1, Dice d2)
{
	if(d1[5] != d2[5]) return false;

	for(int i=0; i<4; i++)
	{
		bool is_match = true;
		for(int j=1; j<5; j++)
		{
			if(d1[j] != d2[j])
			{
				is_match = false;
				break;
			} 
		}
		if(is_match) return true;
		
		rotate_clock(d2);
	}

	return false;
}

int main()
{
	int T;
	string color;
	vector<Dice> dices;

	while(cin >> T, T)
	{
		dices = vector<Dice>(T);
		for(int t=0; t<T; t++)
		{
			for(int i=0; i<6; i++)
			{
				cin >> color;
				dices[t].push_back(color);
			}
			if(t != 0) rotate(dices[t], dices[0][0]);
		}

		int match_count = 0;
		for(int t=0; t<T; t++)
		{
			for(int i=0; i<t; i++)
			{
				if(match(dices[t], dices[i])) match_count++;
			}
		}

		printf("%d\n", match_count);
	}
}

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

int data[30][6];

bool judge(int);

main(){
  string in;
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    int count=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<6;j++){
	cin >> in;
	if(in=="Red") data[i][j]=1;
	if(in=="Yellow") data[i][j]=2;
	if(in=="Blue") data[i][j]=3;
	if(in=="Magenta") data[i][j]=4;
	if(in=="Green") data[i][j]=5;
	if(in=="Cyan") data[i][j]=6;
      }
      if(judge(i)) count++;
    }
    int ans=n-count;
    if(ans<0) ans=0;
    cout << ans << endl;
  }
  return 0;
}

bool judge(int n){
  if(n==0) return true;
  int tmp[6];
  for(int i=0;i<6;i++){
    tmp[i]=data[n][i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
	if(tmp[0]==data[i][0] && tmp[1]==data[i][1] && tmp[2]==data[i][2] && tmp[3]==data[i][3] && tmp[4]==data[i][4] && tmp[5]==data[i][5]) return false;
	int tt[6];
	for(int l=0;l<6;l++){
	  tt[l]=tmp[l];
	}
	tt[0]=tmp[1];
	tt[1]=tmp[5];
	tt[2]=tmp[2];
	tt[3]=tmp[3];
	tt[4]=tmp[0];
	tt[5]=tmp[4];
	for(int l=0;l<6;l++){
	  tmp[l]=tt[l];
	}
      }
      int t[6];
      for(int k=0;k<6;k++){
	t[k]=tmp[k];
      }
      t[0]=tmp[3];
      t[1]=tmp[1];
      t[2]=tmp[0];
      t[3]=tmp[5];
      t[4]=tmp[4];
      t[5]=tmp[2];
      for(int k=0;k<6;k++){
	tmp[k]=t[k];
      }
    }
  }
  return true;
}

C++: #include<bits/stdc++.h>
#include<set>
using namespace std;
#define pb push_back
int N;
int co(int i,int j,int k){
	if(i>j)swap(i,j);
	if(i>k)swap(i,k);
	if(j>k)swap(j,k);
	return i*36+j*6+k;
}
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		int X[6];
		set<vector<int> >S;
		for(int i=0;i<N;i++){
			for(int j=0;j<6;j++){
				string SS;
				cin >> SS;
				if(SS=="Cyan")X[j]=0;
				if(SS=="Yellow")X[j]=1;
				if(SS=="Red")X[j]=2;
				if(SS=="Magenta")X[j]=3;
				if(SS=="Green")X[j]=4;
				if(SS=="Blue")X[j]=5;
			}
			vector<int>XX;
			XX.pb(co(X[0],X[1],X[2]));
			XX.pb(co(X[1],X[2],X[5]));
			XX.pb(co(X[0],X[1],X[3]));
			XX.pb(co(X[1],X[3],X[5]));
			XX.pb(co(X[0],X[4],X[2]));
			XX.pb(co(X[4],X[2],X[5]));
			XX.pb(co(X[0],X[4],X[3]));
			XX.pb(co(X[4],X[3],X[5]));
			sort(XX.begin(),XX.end());
			S.insert(XX);
		}
		printf("%d\n",N-(int)S.size());
	}
}

C++: #include<stdio.h>

#define rep(i,n) for(int i=0;i<n;i++)

int main(void){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0){
			break;
		}
		int sonzai[6][6][6][6][6][6];
		rep(a,6){
			rep(b,6){
				rep(c,6){
					rep(d,6){
						rep(e,6){
							rep(f,6){
								sonzai[a][b][c][d][e][f]=0;
							}
						}
					}
				}
			}
		}
		
		int now[6];
		for(int q=0;q<n;q++){
			for(int i=0;i<6;i++){
				char str[10];
				scanf("%s",str);
				switch(str[0]){
					case 'C':now[i]=0;break;
					case 'Y':now[i]=1;break;
					case 'R':now[i]=2;break;
					case 'M':now[i]=3;break;
					case 'G':now[i]=4;break;
					case 'B':now[i]=5;break;
				}
			}
			int temp;
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					
					sonzai[now[0]][now[1]][now[2]][now[3]][now[4]][now[5]]=1;
					
					temp=now[2];
					now[2]=now[4];
					now[4]=now[3];
					now[3]=now[1];
					now[1]=temp;
				}
				temp=now[0];
				now[0]=now[2];
				now[2]=now[5];
				now[5]=now[3];
				now[3]=temp;
			}
		}
		int cont=0;
		rep(a,6){
			rep(b,6){
				rep(c,6){
					rep(d,6){
						rep(e,6){
							rep(f,6){
								cont+=sonzai[a][b][c][d][e][f];
							}
						}
					}
				}
			}
		}
		printf("%d\n",n-cont/16);
	}
	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]<t[i][c[i][l]]) 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]<t[j][c[j][l]]) 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;
  }
}