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 pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

enum{
  t = 0,f ,r ,b ,l ,d ,
};
class Dice{
  public:
    array<int,6> D;
    Dice(){
      D = {1,2,3,4,5,6};
    }
    Dice(array<int,6> d){
      D = d;
    }
    void Spin(int dir){
      if(dir == l){//
        swap(D[t],D[r]);
        swap(D[r],D[d]);
        swap(D[d],D[l]);
      }
      else if(dir == r){
        swap(D[t],D[l]);
        swap(D[l],D[d]);
        swap(D[d],D[r]);
      }
      else if(dir == f){
        swap(D[t],D[b]);
        swap(D[b],D[d]);
        swap(D[d],D[f]);
      }
      else if(dir == b){
        swap(D[t],D[f]);
        swap(D[f],D[d]);
        swap(D[d],D[b]);
      }
      else if(dir == d){//leftspin
        swap(D[f],D[r]);
        swap(D[r],D[b]);
        swap(D[b],D[l]);
      }
      else if(dir == t){
        swap(D[f],D[l]);
        swap(D[l],D[b]);
        swap(D[b],D[r]);
      }
    }
    void MatchDice(int T,int F){
      rep(i,4){
        Spin(r);
        if(D[t] == T)break;
      }
      if(D[t] != T){
        rep(i,4){
          Spin(f);
          if(D[t] == T)break;
        }
      }
      rep(i,4){
        Spin(t);
        if(D[f] == F) break;
      }
    }
    int& operator[](const int i){
      return D[i];
    }
    bool operator==(Dice& di2){
      rep(i,4){
        di2.Spin(r);
        rep(j,4){
          di2.Spin(t);
          rep(k,4){
            di2.Spin(r);
            if(D == di2.D){
              return true;
            }
          }
        }
      }
      return false;
    }
    friend ostream& operator<<(ostream& os,const Dice& di){
      os << "t f r l b d\n" ;
      rep(i,6){
        if(i) os << ' ';
        os << di.D[i] ;
      }
      return os;
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  map<string,int> m;
  m["Cyan"] = 0,m["Yellow"] =1,m["Red"]=2,m["Magenta"] = 3, m["Green"] = 4, m["Blue"] = 5;
  ll n;
  while(cin >> n && n){
    vector<Dice> di(n);
    string s,s1,s2,s3,s4,s5;
    vector<Dice> st;
    rep(i,n){
      cin >> s >> s1 >> s2 >> s3 >> s4 >> s5;
      di[i][t] = m[s];
      di[i][f] = m[s1];
      di[i][r] = m[s2];
      di[i][l] = m[s3];
      di[i][b] = m[s4];
      di[i][d] = m[s5];
      if(st.size() == 0){
        st.push_back(di[i]);
      }
      else{
        rep(j,st.size()){
          if(st[j] == di[i]){
            break;
          }
          if(j == st.size()-1){
            st.push_back(di[i]);
          }
        }
      }
    }
    cout << n - st.size()<<endl;
  }
  return 0;
}

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

int cheak(int n,string c[][6]){
    int cou=0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            for (int a=0; a<4; a++) {
                if(c[i][0]==c[j][0]){
                    for (int b=0; b<4; b++) {
                        if(c[i][1]==c[j][1]&&c[i][2]==c[j][2]&&c[i][3]==c[j][3]&&c[i][4]==c[j][4]){
                            cou++;
                            break;
                        }
                        swap(c[i][1], c[i][3]);
                        swap(c[i][1], c[i][4]);
                        swap(c[i][1], c[i][2]);
                    }
                    break;
                }
                swap(c[i][0],c[i][3]);
                swap(c[i][0],c[i][5]);
                swap(c[i][0],c[i][2]);
            }
        }
    }
    return cou;
}

int main(){
    int n;
    string cube[30][6];
    while (1) {
        cin>>n;
        if(n==0)break;
        for (int i=0; i<n; i++) {
            for (int j=0; j<6; j++) {
                cin>>cube[i][j];
            }
        }
        cout<<cheak(n, cube)<<endl;
    }
    return 0;
}

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 = 0, S = 1, U = 2;
	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, 4){
			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);
	}
}