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 <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;
 
enum { TOP=0, FRONT=1, LEFT=2, RIGHT=3, BACK=4, BOTTOM=5 };
enum { WEST = 0, NORTH=1, EAST=2, SOUTH=3 };
 
class Dice
{
public:
  int num[6];
   
  int getTop()    { return num[TOP];    }
  int getBottom() { return num[BOTTOM]; }
  int getFront()  { return num[FRONT];  }
  int getBack()   { return num[BACK];   }
  int getLeft()   { return num[LEFT];   }
  int getRight()  { return num[RIGHT];  }
   
  void roll(int dir)
  {
    int tmp;
    switch(dir) {
    case EAST:
      tmp = num[RIGHT];
      num[RIGHT] = num[TOP];
      num[TOP] = num[LEFT];
      num[LEFT] = num[BOTTOM];
      num[BOTTOM] = tmp;
      break;
       
    case WEST:
      tmp = num[LEFT];
      num[LEFT] = num[TOP];
      num[TOP] = num[RIGHT];
      num[RIGHT] = num[BOTTOM];
      num[BOTTOM] = tmp;
      break;
       
    case NORTH:
      tmp = num[BOTTOM];
      num[BOTTOM] = num[FRONT];
      num[FRONT] = num[TOP];
      num[TOP] = num[BACK];
      num[BACK] = tmp;
      break;
       
    case SOUTH:
      tmp = num[BOTTOM];
      num[BOTTOM] = num[BACK];
      num[BACK] = num[TOP];
      num[TOP] = num[FRONT];
      num[FRONT] = tmp;
      break;
       
    }
     
  }
   
public:
  
  Dice() {
  }
  
  Dice(int t, int f, int l, int r, int b, int m)
  {
    num[TOP] = t, num[FRONT] = f, num[LEFT] = l, num[RIGHT] = r, num[BACK] = b, num[BOTTOM] = m;
  }
  Dice(vector<int> v)
  {
    num[TOP] = v[0], num[FRONT] = v[1], num[LEFT] = v[2], num[RIGHT] = v[3], num[BACK] = v[4], num[BOTTOM] = v[5];
  }
  
  bool equals (Dice rhs) const {
    for(int i=0; i<4; i++) {
      rhs.roll(NORTH);
      for(int j=0; j<4; j++) {
        rhs.roll(WEST);
        bool ng = false;
        for(int k=0; k<6; k++) {
          if(num[k]!=rhs.num[k]) { ng = true; break; }
        }
        if(ng) continue;
        return true;
      }
    }
    return false;
  }
};

map<string, int> mp;

int main() {
  
  mp["Red"]=0, mp["Yellow"]=1, mp["Blue"]=2, mp["Magenta"]=3, mp["Green"]=4, mp["Cyan"]=5;
  int N;
  while(cin >> N && N) {
    vector<Dice> d;
    for(int i=0; i<N; i++) {
      vector<int> v(6);
      for(int j=0; j<6; j++) {
        string s; cin >> s; v[j] = mp[s];
      }
      swap(v[2], v[3]);
      d.push_back(Dice(v));
    }
    
    int cnt = 0;
    bool update = true;
    while(update) {
      update = false;
      for(int i=0; i<d.size(); i++) {
        for(int j=i+1; j<d.size(); j++) {
          if(d[i].equals(d[j])) {
            d.erase(d.begin()+j);
            update = true; cnt ++;
            goto NEXT;
          }
        }
      }
    NEXT:;
    }
    cout << cnt << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


int main() {
    using P = array<int, 6>;
    vector<P> ps{{0,1,2,3,4,5},{0,2,3,4,1,5},{0,3,4,1,2,5},{0,4,1,2,3,5},{1,0,4,5,2,3},{1,2,0,4,5,3},{1,4,5,2,0,3},{1,5,2,0,4,3},{2,0,1,5,3,4},{2,1,5,3,0,4},{2,3,0,1,5,4},{2,5,3,0,1,4},{3,0,2,5,4,1},{3,2,5,4,0,1},{3,4,0,2,5,1},{3,5,4,0,2,1},{4,0,3,5,1,2},{4,1,0,3,5,2},{4,3,5,1,0,2},{4,5,1,0,3,2},{5,1,4,3,2,0},{5,2,1,4,3,0},{5,3,2,1,4,0},{5,4,3,2,1,0}};
    auto mul = [](P a, P b){
        P res;
        for (int i = 0; i < 6; ++i) res[i] = a[b[i]];
        return res;
    };
    vector<string> v{"Blue","Cyan","Green","Magenta","Red","Yellow"};
    int n;
    while(cin >> n, n){
        vector<P> A(n);
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < 6; ++j) {
                string s;
                cin >> s;
                A[i][j] = lower_bound(v.begin(),v.end(), s)-v.begin();
            }
            swap(A[i][3], A[i][4]);
            int ok = 0;
            for (int j = 0; j < i; ++j) {
                for (int k = 0; k < ps.size(); ++k) {
                    if(A[j] == mul(A[i], ps[k])){
                        ok = 1;
                        j = k = 100;
                    }
                }
            }
            cnt += ok;
        }
        cout << cnt << "\n";
    }
    return 0;
}

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

void roll_x(vector<int> &v) {
  vector<int> res = v;
  
  res[0] = v[4];
  res[1] = v[0];
  res[5] = v[1];
  res[4] = v[5];
  v = res;
}

void roll_y(vector<int> &v) {
  vector<int> res = v;
  res[0] = v[3];
  res[2] = v[0];
  res[5] = v[2];
  res[3] = v[5];
  v = res;
}

void roll_z(vector<int> &v) {
  vector<int> res = v;
  res[1] = v[2];
  res[2] = v[3];
  res[3] = v[4];
  res[4] = v[1];
  v = res;
}

void allpattern(vector<int> v, vector<vector<int> > &out) {
  out.clear();  
  for(int i = 0; i < 6; i++) {
    if( i & 1 ) roll_x(v);
    else roll_y(v);
    for(int j = 0; j < 4; j++) {
      roll_z(v);
      out.push_back(v);
    }
  }
  
}

bool same(vector<int> a, vector<int> b) {
  vector<vector<int> > aa, bb;
  
  allpattern(b, bb);

  for(int i = 0; i < bb.size(); i++) 
    if( bb[i] == a ) return true;
  return false;
}

bool dup(vector< vector<int> > have, vector<int> b) {
  for(int i = 0; i < (int)have.size(); i++) {
    if( same( have[i], b ) ) return true;
  }
  return false;
}

int main() {
  for(int N; cin >> N, N; ) {

    vector<int> dice[N];

    for(int n = 0; n < N; n++) {
      for(int i = 0; i < 6; i++) {
        string s; cin >> s;
        dice[n].push_back( s[0] - 'A' );
      }
    }
    
    vector< vector<int> > uni;
    for(int i = 0; i < N; i++) {
      if( ! dup(uni, dice[i]) ) {
        uni.push_back( dice[i] );
      }
    }

    cout << N - (int)uni.size() << endl;
    
  }
}