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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
SS ss;
#define debug ss
#endif

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

vstring h(vstring s,int n){
	if(n==0)return s;
	vstring ss;
	ss.PB(s[0]);
	ss.PB(s[3]);
	ss.PB(s[1]);
	ss.PB(s[4]);
	ss.PB(s[2]);
	ss.PB(s[5]);
	return h(ss,n-1);
}

vstring g(vstring s,int n){
	int pos[6][6]={
		{0,1,2,3,4,5},
		{1,5,2,3,0,4},
		{2,1,5,0,4,3},
		{3,1,0,5,4,2},
		{4,0,2,3,5,1},
		{5,4,2,3,1,0},
	};
	vstring res;
	rep(i,6)res.PB(s[pos[n][i]]);
	return res;
}

int main() {
	IL{
		int n;
		cin>>n;
		if(n==0)break;
		vector<vstring> dice;
		vstring rotdice[40][24];
		rep(i,n){
			string s;
			vstring v;
			rep(i,6){
				cin>>s;
				v.PB(s);
			}
			dice.PB(v);
		}
		rep(k,n){
			rep(i,6){
				vstring v=g(dice[k],i);
				rep(j,4){
					rotdice[k][i*4+j]=h(v,j);
				}
			}
		}
		int ng[40]={};
		rep(i,n)repn(j,i+1,n-1){
			rep(k,24){
				if(rotdice[j][k]==dice[i])ng[j]=1;
			}
		}
		int res=0;
		rep(i,n)res+=ng[i];
		cout<<res<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
string s[33][6];
int check(int a,int b){
  if(s[a][0]==s[b][0]&&s[a][1]==s[b][1]&&s[a][2]==s[b][2]&&s[a][3]==s[b][3]&&s[a][4]==s[b][4]&&s[a][5]==s[b][5])return 1;
    return 0;
}
void r1(int a){
  string p=s[a][0];
  swap(s[a][0],s[a][2]);swap(s[a][2],s[a][5]);
  swap(s[a][5],s[a][3]);s[a][3]=p;
}
void r2(int a){
  string p=s[a][0];
  swap(s[a][0],s[a][1]);swap(s[a][1],s[a][5]);
  swap(s[a][5],s[a][4]);s[a][4]=p;
}
void r3(int a){
  string p=s[a][1];
  swap(s[a][1],s[a][2]);swap(s[a][2],s[a][4]);
  swap(s[a][4],s[a][3]);s[a][3]=p;
}
int c7(int a,int b){
  int p=0;
  for(int i=0;i<4;i++){
    r1(a);
    for(int j=0;j<4;j++){
      r2(a);
      for(int k=0;k<4;k++){
        r3(a);
        if(check(a,b))p++;
      }
    }
  }
  return p;
}
int main(){
  int n;
  while(cin>>n,n){
    int sum=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<6;j++)
        cin>>s[i][j];
    for(int i=0;i<n;i++){
      int p=0;
      for(int j=i+1;j<n;j++){
        if(c7(i,j))p++;
      }
      if(p)sum++;
    }
    cout<<sum<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <string.h>
#include <string>
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 table[6];

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;
		memset(&table[0], 0, sizeof(int)*6);
		for(int t=0; t<T; t++)
		{
			for(int i=0; i<t; i++)
			{
				if(match(dices[t], dices[i]))
				{
					if(!table[t] || !table[i])
					{
						table[t] = 1;
						table[i] = 1;
						match_count++;
					}
				}
			}
		}

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

C++: #include<iostream>
#include<string>
using namespace std;
struct kyu_bu{
  string kyu[7];
  bool h;
};
kyu_bu p[30];
int main(){
  int n,start,cou,index;
  int roop[7]={0,2,3,4,5,6,1};
  while(cin >> n){
    if(n==0) break;
    int count = 0;
    for(int i=0;i<n;i++){
      for(int j=1;j<=6;j++) cin >> p[i].kyu[j];
      p[i].h = true;
    }
    for(int i=0;i<n;i++){
      if(!p[i].h) continue;
      for(int j=i+1;j<n;j++){
	if(!p[j].h) continue;
	bool ok = true;;
	for(int g=1;g<=3;g++){
	  if(!ok) break;
	  for(int k=1;k<=6;k++){
	    if(p[i].kyu[g]==p[j].kyu[k]){
	      if(p[i].kyu[6-g+1]!=p[j].kyu[6-k+1]) ok = false;
	    }
	  }
	}
	if(ok) count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}