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<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(k&1){
		  swap(tmp[3],tmp[4]);
		  swap(tmp[4],tmp[2]);
		  swap(tmp[2],tmp[1]);
		}else{
		  swap(tmp[1],tmp[2]);
		  swap(tmp[2],tmp[4]);
		  swap(tmp[4],tmp[3]);
		}
	      }
	      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;
  }
}

C++: /*
 * src.cpp
 *
 *  Created on: 2016/07/27
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=30;

struct dice{
	char c[7];
	void move(int f){
		if (f==1){
			swap(c[1],c[3]);
			swap(c[3],c[4]);
			swap(c[3],c[6]);
		}else if (f==2){
			swap(c[1],c[2]);
			swap(c[2],c[5]);
			swap(c[2],c[6]);
		}else{
			swap(c[2],c[3]);
			swap(c[3],c[4]);
			swap(c[3],c[5]);
		}
	}
	bool operator == (dice &a){
		if (c[1]!=a.c[1]){
			REP(i,4){
				a.move(1);
				if (c[1]==a.c[1]) break;
			}
			if (c[1]!=a.c[1]){
				REP(i,4){
					a.move(2);
					if (c[1]==a.c[1]) break;
				}
			}
		}
		if (c[6]!=a.c[6]) return false;
		REP(i,4){
			a.move(3);
			if (c[2]==a.c[2]) break;
		}
		FOR(i,1,7){
			if (c[i]!=a.c[i]){
				return false;
			}
		}
		return true;
	}
};

int N;
dice d[MAX_N];

int main(){
	do{
		cin>>N;
		if (N){
			cin.ignore();
			string s;
			REP(i,N){
				REP(j,6){
					cin>>s;
					d[i].c[j+1]=s[0];
				}
			}
			int ans=0;
			REP(i,N){
				REP(j,i){
					if (d[i]==d[j]){
						ans++;
						break;
					}
				}
			}
			cout<<ans<<endl;
		}
	}while (N);
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
  char c1[30][10],c2[30][10],c3[30][10],c4[30][10],c5[30][10],c6[30][10];
  int n;
  while(1){
    int flag=0;
    int count=0;
    int ans=0;
    cin>>n;
    if(n==0) break;
    
    for(int i=0;i<n;i++){
      scanf("%s %s %s %s %s %s",c1[i],c2[i],c3[i],c4[i],c5[i],c6[i]);
    }
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	if(strcmp(c6[i],c6[j])==0){
	  count++;
	}
      }
    }
    printf("%d\n",count);
  }
}

C++: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;

const int N=30;
vector<int>rot_l(vector<int>&v) {
	int k=v[1];
	v[1]=v[2];
	v[2]=v[4];
	v[4]=v[3];
	v[3]=k;
	return v;
}
vector<int>rot_u(vector<int>&v) {
	int k=v[1];
	v[1]=v[0];
	v[0]=v[4];
	v[4]=v[5];
	v[5]=k;
	return v;
}
vector<int>zero_top(vector<int>v) {
	{
		int x = find(v.begin(), v.end(), 0) - v.begin();
		if (x == 0) {

		}
		else if (x == 1) {
			rot_u(v);
			rot_u(v);
			rot_u(v);
		}
		else if (x == 5) {
			rot_u(v);
			rot_u(v);
			
		}
		else if (x == 4) {
			rot_u(v);
		}
		else if (x == 2) {
			rot_l(v); 
			rot_u(v);
			rot_u(v);
			rot_u(v);
		}
		else if (x == 3) {
			rot_l(v);
			rot_u(v);
		}
	}
	assert(v[0]==0);
	return v;
}
bool same(vector<int>l, vector<int>r) {
	l=zero_top(l);
	r=zero_top(r);
	for (int i = 0; i < 4; ++i) {
		if(l==r)return true;
		rot_l(l);
	}
	return false;
}

int main() {
	while (true) {
		int N; cin >> N;if(!N)break;
		vector<vector<int>>cubes;
		for (int i = 0; i < N; ++i) {
			string color_st = "MRYBGC";
			vector<int>v;
			for (int j = 0; j < 6; ++j) {
				string st; cin >> st;
				int k = color_st.find(st[0]);
				v.push_back(k);
			}
			bool ok=true;
			for (auto cube : cubes) {
				if(same(cube,v))ok=false;
			}
			if (ok) {
				cubes.emplace_back(v);
			}
		}
		cout<<N-cubes.size()<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
string color[6] =  {"Cyan", "Yellow", "Red", "Magenta", "Green", "Blue"};
int* south(int c[6]) {
	int buf = c[0];
	c[0] = c[1];
	c[1] = c[5];
	c[5] = c[4];
	c[4] = buf;
	return c;
}
int* east(int c[6]) {
	int buf = c[0];
	c[0] = c[2];
	c[2] = c[5];
	c[5] = c[3];
	c[3] = buf;
	return c;
}
int* round(int c[6]) {
	int buf = c[1];
	c[1] = c[2];
	c[2] = c[4];
	c[4] = c[3];
	c[3] = buf;
	return c;
}
bool same(int d1[6], int d2[6]) {
	bool f = 1;
	rep(i,4) {
		d1 = south(d1);
		rep(j,4) {	
			d1 = round(d1);
			f = 1;
			rep(k,6) {
				if(d1[k] != d2[k]) {
					f = 0;
					break;
				}
			}	
			if(f) return true;
		}
	}
	rep(i,4) {
		d1 = east(d1);
		rep(j,4) {
			d1 = round(d1);
			f = 1;
			rep(k,6) {
				if(d1[k] != d2[k]) {
					f = 0;
					break;
				}
			}
			if(f) return true;
		}
	}
	return false;
}
int main(){
	int n, d[30][6] = {};
	string s;
	while(cin >> n, n) {
		rep(i,n) {
			rep(j,6) {
				cin >> s;
				rep(k,6) {
					if(color[k] == s) d[i][j] = k;
				}
			}
		}
		int a[30] = {};
		rep(i,n) {
			rep2(j,i+1,n) {
				if(same(d[i],d[j])) {
					a[i]++, a[j]++;
				}
			}
		}
		int ret = 0;
		rep(i,30) {
			if(a[i]) ret++;
		}
		if(ret) ret--;
		cout << ret << endl;
	}
	return 0;
}