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;
#define rep(i,n) for(int i=0;i<n;i++)
#define TOP 0 
#define BOTTOM 1
#define FRONT 2
#define BACK 3
#define RIGHT 4
#define LEFT 5

vector< vector<string> > check;

void z(vector<string> &dice){
	string to[6];
	to[BACK] = dice[TOP];
	to[BOTTOM] = dice[BACK];
	to[FRONT] = dice[BOTTOM];
	to[TOP] = dice[FRONT];

	to[LEFT] = dice[LEFT];
	to[RIGHT] = dice[RIGHT];

	rep(i,6)dice[i] = to[i];

}

void x(vector<string> &dice){
	string to[6];
	to[FRONT] = dice[LEFT];
	to[LEFT] = dice[BACK];
	to[BACK] = dice[RIGHT];
	to[RIGHT] = dice[FRONT];
	
	to[BOTTOM] = dice[BOTTOM];
	to[TOP] = dice[TOP];
	
	rep(i,6)dice[i] = to[i];
}

void y(vector<string> &dice){
	string to[6];
	to[TOP] = dice[LEFT];
	to[LEFT] = dice[BOTTOM];
	to[BOTTOM] = dice[RIGHT];
	to[RIGHT] = dice[TOP];
	
	to[FRONT] = dice[FRONT];
	to[BACK] = dice[BACK];
	
	rep(i,6)dice[i] = to[i];
}

bool isunique(vector<string> data){

	rep(l1,4)rep(l2,4)rep(l3,4){
	
		vector<string> t(6);
		
		rep(j,6)t[j] = data[j];

		rep(j,l1)x(t);
		rep(j,l2)y(t);
		rep(j,l3)z(t);
		
		rep(i,check.size()){
			bool flag = true;
			rep(j,6)if(t[j] != check[i][j])flag = false;
			if(flag)return false;
		}

	}
	return true;
}

int main(){
	int n;
	string c[6];
	while(cin >> n, n){
		check.clear();
		rep(i,n){
			rep(j,6)cin >> c[j];
			string d[6] =  {c[0],c[5],c[1],c[4],c[2],c[3]};
			vector<string> dice(6);
			rep(j,6)dice[j] = d[j];
			
			if( isunique(dice) ){
				check.push_back(dice);
			}
		}
		cout << n-check.size() << endl;
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

struct cube {
	vector<string>v;
	int E = 2, S = 1, U = 0;
	void rotate(char C) {
		int a = E, b = S;
		switch (C) {
		case'E':E = U; U = 5 - a; break;
		case'S':S = U; U = 5 - b; break;
		case'L':E = S; S = 5 - a; break;
		}
	}
	bool operator==(cube b) {
		rep(i, 2){
			rep(j, 4) {
				rep(k, 4) {
					if (v[E] == b.v[b.E] && v[5 - E] == b.v[5 - b.E] && v[S] == b.v[b.S] && v[5 - S] == b.v[5 - b.S] && v[U] == b.v[b.U] && v[5 - U] == b.v[5 - b.U])return true;
					rotate('S');
				}
				rotate('E');
			}
			rotate('L');
		}
		return false;
	}
};
cube s[30];
bool used[30];
int main() {
	int n;
	while (cin >> n, n) {
		rep(i, n) {
			s[i].v = vector<string>(6);
			rep(j, 6)cin >> s[i].v[j];
		}
		vector<int>v[30];
		rep(i, n)for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) {
				v[i].push_back(j);
			}
		}
		int cnt = 0;
		memset(used, 0, sizeof(used));
		rep(i, n) {
			if (used[i])continue;
			cnt++;
			for (int j : v[i])used[j] = true;
		}
		printf("%d\n", n - cnt);
	}
}

C++: #include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<functional>

using namespace std;

#define OUT cout <<
#define IN cin >>
#define E << endl;
#define FOR(i,a,b) for(int i = a;i < b;i++)

int n;

void input(){
	IN n;
}

class Dice{
	private:
		string temp;
	public:
		string c[6];
		Dice(){}
		void roll(int axis){
			switch(axis){
			case 0:
				temp = c[0];
				c[0] = c[1];
				c[1] = c[5];
				c[5] = c[4];
				c[4] = temp;
				break;
			case 1:
				temp = c[1];
				c[1] = c[3];
				c[3] = c[4];
				c[4] = c[2];
				c[2] = temp;
				break;
			case 2:
				temp = c[0];
				c[0] = c[2];
				c[2] = c[5];
				c[5] = c[3];
				c[3] = temp;
				break;
			default:
				OUT "switch error!!!!!!\n" E
				break;
			}
		}
		void getd(string& c1, string& c2, string& c3, string& c4, string& c5, string& c6){
			c1 = c[0];
			c2 = c[1];
			c3 = c[2];
			c4 = c[3];
			c5 = c[4];
			c6 = c[5];
		}

		void input(){
			FOR(i,0,6){
				IN c[i];
			}
		}

};

int main(){
	while(true){
		input();
		if(n == 0)break;
		int count = 0;
		bool match[n];
		FOR(i, 0, n){
			match[i] = false;
		}
		string str1[6];
		string str2[6];	

		vector<Dice> dice;
	
		dice.resize(n);
		FOR(i, 0, n){
			dice[i].input();
		}
			

		FOR(i, 0, n - 1){
			FOR(j, i + 1, n){
				bool flag2 = false;
				FOR(z, 0, 4){
				FOR(x, 0, 4){
					FOR(y, 0, 4){
						dice[i].getd(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
						dice[j].getd(str2[0],str2[1],str2[2],str2[3],str2[4],str2[5]);
						
						//printf("\n%s %s %s %s %s %s \n",str1[0].c_str(),str1[1].c_str(),str1[2].c_str(),str1[3].c_str(),str1[4].c_str(),str1[5].c_str());
						//printf("%s %s %s %s %s %s \n\n",str2[0].c_str(),str2[1].c_str(),str2[2].c_str(),str2[3].c_str(),str2[4].c_str(),str2[5].c_str());

						bool flag1 = true;
						FOR(d, 0, 6){					
							if(str1[d] != str2[d]){
								flag1 = false;
							}
						}

						if(flag1){
							if(match[i] == false){							
								flag2 = true;
								//printf("%s %s %s %s %s %s \n",str1[0].c_str(),str1[1].c_str(),str1[2].c_str(),str1[3].c_str(),str1[4].c_str(),str1[5].c_str());
								//printf("%s %s %s %s %s %s \n",str2[0].c_str(),str2[1].c_str(),str2[2].c_str(),str2[3].c_str(),str2[4].c_str(),str2[5].c_str());
							}
							match[j] = true;
						}
						flag1 = true;
					
						dice[i].roll(1);
					}
					dice[i].roll(0);
				}
				dice[i].roll(2);
				}
				//OUT i << " " << j << " " << flag2 E
				if(flag2){
					count++;
					//OUT "count++ " << i << " " << j  E
				}
			}
		}	

		OUT count E

	}
}

C++: #include<stdio.h>
int main(void){
	int i,j,k,n;
	char color[9];
	while(scanf("%d",&n),n>0){
		int uesita[6]={0},yokomen[6]={0},del=0;
		for(i=0,k=-1;i<=n;i++,k++){
			if(i<n){
				for(j=0;j<6;j++){
					scanf("%s",&color);
					if(j==0 ||j==5)uesita[i]+=color[0];
					else yokomen[i]+=color[0];
				}
			}
			if(k>=0){
				if(k==0 || k==5)if(uesita[k]==uesita[k+1])del++;
				else if(yokomen[k]==yokomen[k+1])del++;
			}
		}
		printf("%d\n",del);
	}
	return 0;
}

C++: main(){char* l="RYBMGC";int i,j,n,a,c[6],f,s,t[4],r[][4]={{1,2,4,3},{5,2,0,3},{0,1,5,4},{0,4,5,1},{0,2,5,3},{2,1,3,4}};while(scanf("%d",&n),n){a=0;int u[9999]={0};while(n--){char b[16];for(i=0;i<6;++i){scanf("%s",b);for(j=0;l[j]!=*b;++j);c[i]=j;if(j==0)f=i;}for(i=0;i<4;++i)t[i]=c[r[f][i]];for(i=0;i<3;++i){s=0;for(j=0;j<4;++j)s=s*10+t[(i+j)%4];if(u[s]){++a;break;}else u[s]=1;}}printf("%d\n",a);}exit(0);}