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 rep(i,n) for(int i = 0 ; i < n ; i++) 
 
class Cube {
private:
    string tmp;
public:
    string d[6];
  
    void rollN() {
	tmp = d[0];
	d[0] = d[1];
	d[1] = d[5];
	d[5] = d[4];
	d[4] = tmp;
    }
  
    void rollW() {
	tmp = d[0];
	d[0] = d[2];
	d[2] = d[5];
	d[5] = d[3];
	d[3] = tmp;
    }
 
    void rotation() {
	tmp = d[1];
	d[1] = d[3];
	d[3] = d[4];
	d[4] = d[2];
	d[2] = tmp;
    }
 
    bool judge(Cube &C) {
	rep(i,6){
	    if(d[i] != C.d[i]){
		return false;
	    }
	}
	return true;
    }
 
    bool equals(Cube &C) {
	rep(i,3){
	    rollN();
	    if(d[0] == C.d[0]){
		break;
	    }
	    rollW();
	    if(d[0] == C.d[0]){
		break;
	    }
	}
	rep(i,4){
	    if(judge(C)){
		return true;
	    }
	    rotation();
	}
	return false;
    }
};
  
int main()
{
    int N;
 
    while (cin >> N, N) {
	Cube cube[N];
	rep (i, N) {
	    rep (j, 6) {
		cin >> cube[i].d[j];
	    }
	}   
	int ans = 0;
	bool used[N];
	memset(used, false, sizeof(used));
	rep (i, N-1) {
	    for (int j = i+1; j < N; j++) {
		if (cube[i].equals(cube[j]) && !used[j]) {
		    used[j] = true;
		    ans++;
		}
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define REP(i, s, e) for ( int i = s; i <= e; i++ )
using namespace std;
#define MAX 100

class Cube{
    public:
    string f[6];
    Cube(){}
    void roll_z(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
	string t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
};

Cube C[MAX];
int n;

bool eq( Cube c1, Cube c2 ){
    rep(i, 6) if ( c1.f[i] != c2.f[i] ) return false;
    return true;
}

bool equal( Cube c1, Cube c2 ){
    rep(i, 6){
	rep(j, 4){
	    if ( eq(c1, c2) ) return true;
	    c1.roll_z();
	}
	if ( i % 2 == 0 ) c1.roll_y();
	else c1.roll_x();
    }
    return false;
}

main(){
    while( cin >> n && n ){
	rep(i, n) rep(j, 6) cin >> C[i].f[j];
	int cnt = 0;
	REP(i,0,n-1) {
	    bool hasSame = false;
	    REP(j, i+1, n-1){
		if ( equal(C[i], C[j] ) ) hasSame = true;
	    }
	    if ( !hasSame ) cnt++;
	}
	cout << n - cnt << endl;
    }
}

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/2<< endl;
  }
}

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

struct Dice
{
	int c[6];	//??????????????????

	Dice() {}

	//c0:???, c1:??????, c2:???, c3:?\\, c4:???, c5:???
	Dice(int c0, int c1, int c2, int c3, int c4, int c5)
	{
		c[0] = c0; c[1] = c1; c[2] = c2; c[3] = c3; c[4] = c4; c[5] = c5;
	}

	void temae()
	{
		int temp = c[0];
		c[0] = c[3]; c[3] = c[5]; c[5] = c[1];
		c[1] = temp;
	}

	void oku()
	{
		int temp = c[0];
		c[0] = c[1]; c[1] = c[5]; c[5] = c[3];
		c[3] = temp;
	}

	//y????????¢??????
	void y_migi()
	{
		int temp = c[1];
		c[1] = c[4]; c[4] = c[3]; c[3] = c[2];
		c[2] = temp;
	}

	//y????????¢??????
	void y_hidari()
	{
		int temp = c[1];
		c[1] = c[2]; c[2] = c[3]; c[3] = c[4];
		c[4] = temp;
	}

	//z????????¢??????
	void z_migi()
	{
		int temp = c[0];
		c[0] = c[4]; c[4] = c[5]; c[5] = c[2];
		c[2] = temp;
	}

	//z????????¢??????
	void z_hidari()
	{
		int temp = c[0];
		c[0] = c[2]; c[2] = c[5]; c[5] = c[4];
		c[4] = temp;
	}

	//1???????????\?????????????????¢??????2????¨????????????´????????????????\\??????????????°3????\\????????????????????????
	void format()
	{
		if (c[0] == 1) {
			;
		} else if (c[1] == 1) {
			oku();
		} else if (c[2] == 1) {
			z_hidari();
		} else if (c[3] == 1) {
			temae();
		} else if (c[4] == 1) {
			z_migi();
		} else if (c[5] == 1) {
			oku();
			oku();
		}

		if (c[1] == 2)
		{
			y_migi();
			y_migi();
		} else if (c[2] == 2) {
			y_migi();
		} else if (c[4] == 2) {
			y_hidari();
		} else if (c[3] == 2) {
			return;
		} else {
			if (c[1] == 3)
			{
				y_migi();
				y_migi();
			} else if (c[2] == 3) {
				y_migi();
			} else if (c[4] == 3) {
				y_hidari();
			}
		}
	}

	bool operator == (const Dice &d) const {
		Dice td1 = Dice(c[0], c[1], c[2], c[3], c[4], c[5]);
		Dice td2 = d;

		td1.format();
		td2.format();

		rep(i,6)
		{
			if (td1.c[i] != td2.c[i]) return false;
		}
		return true;
	}
};

int n;
map<string, int> c2n;
string color[6];
int cc[6];
Dice d[30];
bool used[30];

signed main()
{
	c2n["Red"] = 1;
	c2n["Yellow"] = 2;
	c2n["Blue"] = 3;
	c2n["Magenta"] = 4;
	c2n["Green"] = 5;
	c2n["Cyan"] = 6;

	while (true)
	{
		cin >> n;
		if (n == 0) break;

		rep(j,n)
		{
			rep(i,6) cin >> color[i];
			cc[0] = c2n[color[0]];
			cc[1] = c2n[color[1]];
			cc[2] = c2n[color[2]];
			cc[3] = c2n[color[4]];
			cc[4] = c2n[color[3]];
			cc[5] = c2n[color[5]];
			d[j] = Dice(cc[0], cc[1], cc[2], cc[3], cc[4], cc[5]);
		}

		rep(i,n) used[i] = false;

		int ans = 0;
		for (int i=0; i<n; i++)
		{
			for (int j=i+1; j<n; j++)
			{
				if (d[i] == d[j] && used[j] == false)
				{
					ans++;
					used[j] = true;
				}
			}
		}

		cout << ans << endl;
	}
}