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 <stdio.h>
#include <string.h>

int main()
{
	int i0, i1, i2, i3, n, m, d[30][6], s[30], sw;
	char c[8];
	char color[6][8] = {"Cyan", "Yellow", "Red", "Magenta", "Green", "Blue"};

	scanf("%d", &n);
	while (n > 0) {
					// ??????????????\???
		for (i0 = 0; i0 < n; i0++) {
			for (i1 = 0; i1 < 6; i1++) {
				scanf("%s", c);
				for (i2 = 0; i2 < 6; i2++) {
					if (strcmp(c, color[i2]) == 0) {
						d[i0][i1] = i2;
						break;
					}
				}
			}
		}
					// ????????????????????????
		m = 0;
		for (i0 = 0; i0 < n; i0++)
			s[i0] = 1;
		for (i0 = 0; i0 < n; i0++) {
			if (s[i0] > 0) {
				m++;
				s[i0] = 0;
				for (i1 = i0+1; i1 < n; i1++) {
					sw = 0;
					for (i2 = 0; i2 < 3 && sw == 0; i2++) {
						for (i3 = 0; i3 < 6 && sw == 0; i3++) {
							if (d[i0][i2] == d[i1][i3]) {
								if (d[i0][5-i2] != d[i1][5-i3])
									sw = 1;
							}
						}
					}
					if (sw == 0)
						s[i1] = 0;
				}
			}
		}
					// ??????
		printf("%d\n", n-m);
					// ?¬?????????????
		scanf("%d", &n);
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
struct kyu_bu{
  string kyu[7];
  bool h;
};
kyu_bu p[30];
void North(int i){
  string mem;
  mem = p[i].kyu[1];
  p[i].kyu[1] = p[i].kyu[2];
  p[i].kyu[2] = p[i].kyu[6];
  p[i].kyu[6] = p[i].kyu[5];
  p[i].kyu[5] = mem;
}
void East(int i){
  string mem;
  mem = p[i].kyu[1];
  p[i].kyu[1] = p[i].kyu[4];
  p[i].kyu[4] = p[i].kyu[6];
  p[i].kyu[6] = p[i].kyu[3];
  p[i].kyu[3] = mem;
}
void Right(int i){
  string mem;
  mem = p[i].kyu[2];
  p[i].kyu[2] = p[i].kyu[3];
  p[i].kyu[3] = p[i].kyu[5];
  p[i].kyu[5] = p[i].kyu[4];
  p[i].kyu[4] = mem;
}
int main(){
  int n;
  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++){
      p[i].h = true;
      for(int j=1;j<=6;j++) cin >> p[i].kyu[j];
    }
    for(int i=0;i<n-1;i++){
      if(!p[i].h) continue;
      for(int j=0;j<=12;j++){
	if(j>=1&&j<=4) North(i);
	else if(j>=5&&j<=8) East(i);
	else if(j>=9&&j<=12)Right(i);
	if(j==0||j%4!=0){
	  for(int k=i+1;k<n;k++){
	    if(!p[k].h) continue;
	    for(int g=1;g<=6;g++){
	      if(p[i].kyu[1]==p[k].kyu[g]){
		int strat = roop[g];
		int cou = 1;
		int index = 2;
		while(cou!=6){
		  if(p[i].kyu[index]!=p[k].kyu[strat]) break;
		  cou++;
		  index++;
		  strat = roop[strat];   
		}
		if(cou==6){
		  count++;
		  p[k].h = false;
		}
		break;
	      }
	    }
	  }
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main() {
	int a, b[101][101],kotaneet=0,ruio=0;
	char str[101];
	while (1) {
		cin >> a;
		if (a == 0)return 0;
		ruio = a;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= 6; j++) {
				scanf("%s", str);
				if (strstr(str, "Red") != NULL) {
					b[i][j] = 1;
				}
				if (strstr(str, "Yellow") != NULL) {
					b[i][j] = 2;
				}
				if (strstr(str, "Blue") != NULL) {
					b[i][j] = 3;
				}
				if (strstr(str, "Magenta") != NULL) {
					b[i][j] = 4;
				}
				if (strstr(str, "Green") != NULL) {
					b[i][j] = 5;
				}
				if (strstr(str, "Cyan") != NULL) {
					b[i][j] = 6;
				}
			}
		}
		kotaneet = 0;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= a; j++) {
				if (j != i && b[j][1] != -1) {
					//cout << "tatuya0" << endl;
					if (b[i][1] + b[i][6] == b[j][1] + b[j][6]) {
						//cout << "tatuya1" << endl;
						if (b[i][3] + b[i][4] == b[j][3] + b[j][4]) {
							//cout << "tatuya2" << endl;
							if (b[i][2] + b[i][5] == b[j][2] + b[j][5]) {
								//cout << "tatuya3" << endl;
								kotaneet++;
								b[i][1] = -1;
								ruio--;
								break;
							}
						}
					}
				}
			}
		}
		cout << a-ruio << endl;
	}
}

C++: #include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
enum{TOP=0,FRONT,RIGHT,LEFT,BACK,BOTTOM}; 
#define rotate_swap(x,a,b,c,d) swap(x.m[a],x.m[b]);swap(x.m[b],x.m[c]);swap(x.m[c],x.m[d]);


class Dice{
public:
  int m[6];
  bool operator<(const Dice &a)const{
    rep(i,6)if (m[i] != a.m[i])return m[i] < a.m[i];
    return false;
  }
};
 
void rotate_r(Dice &x){
  rotate_swap(x,TOP,LEFT,BOTTOM,RIGHT);
}
 
void rotate_l(Dice &x){
 rotate_swap(x,TOP,RIGHT,BOTTOM,LEFT);
}
 
void rotate_f(Dice &x){
 rotate_swap(x,TOP,BACK,BOTTOM,FRONT);
}
 
void rotate_b(Dice &x){
 rotate_swap(x,TOP,FRONT,BOTTOM,BACK);
}
 
void rotate_cw(Dice &x){
  rotate_swap(x,BACK,LEFT,FRONT,RIGHT);
}
 
void rotate_ccw(Dice &x){
  rotate_swap(x,BACK,RIGHT,FRONT,LEFT);
}
 
Dice data[24];

void generate_all(Dice &x){
  rep(i,6){
   rep(j,4){
     data[i*4+j]=x;
     rotate_cw(x);
   }
   if (i%2 == 0)rotate_r(x);
   else rotate_f(x);
 }
}

main(){
  string hoge[6]={"Red","Yellow","Blue","Magenta","Green","Cyan"};
  int n;
  while(cin>>n && n){
    set<Dice> S;
    rep(i,n){
      int a[6];
      rep(j,6){
	string tmp;
	cin>>tmp;
	rep(k,6)if (hoge[k] == tmp)a[j]=k;
      }
      Dice d={a[0],a[1],a[2],a[3],a[4],a[5]};
      generate_all(d);
      bool isok=true;
      rep(j,24){
	if (S.find(data[j]) != S.end()){
	  isok=false;
	}
      }
      if (isok)S.insert(d);
    }
    cout << n-S.size() << endl;
  }
  return false;
}