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>

using namespace std;
 
enum { TOP = 0, BOTTOM, FRONT, BACK, LEFT, RIGHT };
enum { WEST = 0, NORTH, EAST, SOUTH };
 
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)
  {
    num[TOP] = t; num[BOTTOM] = 7-t;
    num[FRONT] = f; num[BACK] = 7-f;
     
    switch(num[TOP])
      {
      case 1:
        switch(num[FRONT]) {
        case 3: num[LEFT] = 2; break;
        case 5: num[LEFT] = 3; break;
        case 4: num[LEFT] = 5; break;
        case 2: num[LEFT] = 4; break;
        }
        break;
      case 2:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 3; break;
        case 3: num[LEFT] = 6; break;
        case 4: num[LEFT] = 1; break;
        case 6: num[LEFT] = 4; break;
        }
        break;
      case 3:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 5; break;
        case 2: num[LEFT] = 1; break;
        case 6: num[LEFT] = 2; break;
        case 5: num[LEFT] = 6; break;
        }
        break;
      case 4:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 2; break;
        case 2: num[LEFT] = 6; break;
        case 5: num[LEFT] = 1; break;
        case 6: num[LEFT] = 5; break;
        }
        break;
      case 5:
        switch(num[FRONT]) {
        case 1: num[LEFT] = 4; break;
        case 3: num[LEFT] = 1; break;
        case 4: num[LEFT] = 6; break;
        case 6: num[LEFT] = 3; break;
        }
        break;
      case 6:
        switch(num[FRONT]) {
        case 2: num[LEFT] = 3; break;
        case 3: num[LEFT] = 5; break;
        case 4: num[LEFT] = 2; break;
        case 5: num[LEFT] = 4; break;
        }
        break;
      }
    num[RIGHT] = 7-num[LEFT];
  }

  bool operator == (Dice rhs) const {
    for(int i=0; i<4; i++) {
      for(int j=0; j<4; j++) {
        rhs.roll(NORTH);
        rhs.roll(WEST);
        for(int k=0; k<6; k++) if(num[k]!=rhs.num[k]) continue;
        return true;
      }
    }
    return false;
  }
};

string cols[]={"Red", "Yellow", "Blue", "Magenta", "Green", "Cyan"};
map<string, int> mp;

int main() {
  
  for(int i=0; i<6; i++) mp[cols[i]] = i;
  int N;
  while(cin >> N && N) {
    vector<Dice> d;
    for(int i=0; i<N; i++) {
      string s; int t, f;
      cin >> s; t = mp[s];
      cin >> s; f = mp[s];
      d.push_back(Dice(t, f));
      for(int j=2; j<6; j++) {
        string s; cin >> s;
      }
    }
    
    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] == d[j]) {
            d.erase(d.begin()+i); update = true; goto NEXT;
          }
        }
      }
    NEXT:;
    }
    cout << d.size() << endl;
  }
  
  return 0;
}

C++: #include<iostream>
using namespace std;
int t[6],n,a,flg,cnt,tmp,p[6][6][6][6][6][6];
string moji;
void init(){
  if(a==6){
    p[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]=0;
  }else{
    for(int i=0;i<6;i++){
      t[a]=i;
      a++;
      init();
      a--;
    }
  }
}
int change(){
  if(moji=="Red"){
    return 0;
  }else if(moji=="Yellow"){
    return 1;
  }else if(moji=="Blue"){
    return 2;
  }else if(moji=="Magenta"){
    return 3;
  }else if(moji=="Green"){
    return 4;
  }else{
    return 5;
  }
}
void mov(int z){
  for(int j=0;j<4;j++){
    tmp=t[0]; t[0]=t[2]; t[2]=t[5]; t[5]=t[3]; t[3]=tmp;
    for(int k=0;k<3;k++){
      tmp=t[0]; t[0]=t[4]; t[4]=t[5]; t[5]=t[1]; t[1]=tmp;
      if(t[0]==z){
    //cout<<t[4]<<endl<<t[3]<<t[0]<<t[2]<<t[5]<<endl<<t[1]<<endl;
    return;
      }
    }
  }
}
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    flg=cnt=a=0;
    init();
 
    for(int i=0;i<n;i++){
      for(int j=0;j<6;j++){
	cin>>moji;
	t[j]=change();
      }
      if(p[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]==1){
	cnt++;
      }else{
	for(int j=0;j<6;j++){
	  mov(j);
	  for(int k=0;k<4;k++){
	    tmp=t[1];  t[1]=t[2];  t[2]=t[4];  t[4]=t[3];  t[3]=tmp;
	    p[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]=1;
	  }
	  
	}
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;

bool judge(vector<string>a, vector<string>b){
  int ret = 1;
  rep(i, 3){
    int j;
    for(j = 0; j < 6; j++) if(a[i] == b[j]) break;
    if(a[5-i] != b[5-j]) ret = 0;

  }
  /*  rep(i, 6) cout << a[i] << " "; puts("");
  rep(i, 6) cout << b[i] << " "; puts("");
  cout << ret << endl;*/
  return ret;
}

int main(){
  while(scanf("%d", &n) && n){

    vector<vector<string> >c(n, vector<string>(6));
    rep(i, n) rep(j, 6) cin >> c[i][j];

    vector<int>f(n, 0);
    rep(i, n){
      if(f[i]) continue;
      REP(j, i+1, n) if(judge(c[i], c[j])) f[j] = 1;
    }
    int res = 0;
    rep(i, n) if(f[i]) res++;
    printf("%d\n", res);
  }
  return 0;
}