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<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 &&b[i][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;
								b[i][1] = -1;
								ruio--;
								break;
							}
						}
					}
				}
			}
		}
		cout << a-ruio << endl;
	}
}

C++: #include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
    int i,j,n,k[100],count=0;
    char c1[100],c2[100],c3[100],c4[100],c5[100],c6[100];
    for(j=0;j<100;j++){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>c1>>c2>>c3>>c4>>c5>>c6;
        k[i]=c1[i]>>c2[i]>>c3[i]>>c4[i]>>c5[i]>>c6[i];
    }
        if(k[i]==k[i]){
            count++;
        }
        if(n==0){
            break;
        }
        cout<<count<<endl;
        count=0;
}
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
using namespace std;

vector<string> rotate(vector<string> src,int t[]){
	vector<string> tmp(6);
	for(int i = 0 ; i < 6 ; i++){
		tmp[t[i]] = src[i];
	}
	return tmp;
}


vector<string> le(vector<string> src){
	//int s[] = {0,1,2,3,4,5};
	int t[] = {0,2,4,1,3,5};
	return rotate(src,t);
}
vector<string> no(vector<string> src){
	//int s[] = {0,1,2,3,4,5};
	int t[] = {1,5,2,3,0,4};
	return rotate(src,t);
}

vector<string> we(vector<string> src){
	//int s[] = {0,1,2,3,4,5};
	int t[] = {3,1,0,5,4,2};
	return rotate(src,t);
}
int main(){
	int n;
	while(cin >> n && n){
		set< vector<string> > c;
		int k = 0;
		for(int i = 0 ; i < n ; i++){
			vector<string> s;
			for(int j = 0 ; j < 6 ; j++){
				string t;cin >> t;
				s.push_back(t);
			}
			if( c.count(s) ) k++;
			for(int x = 0 ; x < 4 ; x++){
				for(int y = 0 ; y < 4 ; y++){
					for(int z = 0 ; z < 4 ; z++){
						c.insert(s);
						s = we(s);
					}
					s=le(s);
				}
				s=no(s);
			}
		}
		cout << k << endl;
	}
}

C++: #include <iostream>
#include <map>
#include <string>
#include <set>
using namespace std;
class Dice {
public:
  int c[6];
  bool operator <(const Dice &d) const {
    for(int i = 0; i < 6; i++) {
      if(c[i] != d.c[i]) return c[i] < d.c[i];
    }
    return false;
  }

  void sort() {
    for(int i = 0; i < 6; i++) {
      if(c[i] == 0) {
	switch(i) {
	case 0: break;
	case 1: rotateY(-1); break;
	case 2: rotateX(-1); break;
	case 3: rotateX(1); break;
	case 4: rotateY(1); break;
	case 5: rotateX(2); break;
	}
	break;
      }
    }
    int minc = 9999;
    int pos;
    for(int i = 1; i <= 4; i++) {
      if(c[i] < minc) {
	minc = c[i];
	pos = i;
      }
    }
    switch(pos) {
    case 1: break;
    case 2: rotateZ(-1); break;
    case 3: rotateZ(1); break;
    case 4: rotateZ(2); break;
    }
  }

  void rotateX(int dx) {
    int d = 1;
    if(dx < 0) {
      d *= -1;
      dx *= -1;
    }
    for(int i = 0; i < dx; i++) {
      int tmp;
      if(d > 0) {
	tmp = c[0];
	c[0] = c[3];
	c[3] = c[5];
	c[5] = c[2];
	c[2] = tmp;
      } else {
	tmp = c[0];
	c[0] = c[2];
	c[2] = c[5];
	c[5] = c[3];
	c[3] = tmp;
      }
    }
  }
  void rotateY(int dy) {
    int d = 1;
    if(dy < 0) {
      d *= -1;
      dy *= -1;
    }
    for(int i = 0; i < dy; i++) {
      int tmp;
      if(d > 0) {
	tmp = c[0];
	c[0] = c[4];
	c[4] = c[1];
	c[1] = tmp;
      } else {
	tmp = c[0];
	c[0] = c[1];
	c[1] = c[4];
	c[4] = tmp;
      }
    }
  }
  void rotateZ(int dz) {
    int d = 1;
    if(dz < 0) {
      d *= -1;
      dz *= -1;
    }
    for(int i = 0; i < dz; i++) {
      int tmp;
      if(d > 0) {
	tmp = c[1];
	c[1] = c[3];
	c[3] = c[4];
	c[4] = c[2];
	c[2] = tmp;
      } else {
	tmp = c[1];
	c[1] = c[2];
	c[2] = c[4];
	c[4] = c[3];
	c[3] = tmp;
      }
    }
  }
};



int main() {
  map<string, int> color;
  color["Red"] = 0;
  color["Yellow"] = 1;
  color["Blue"] = 2;
  color["Magenta"] = 3;
  color["Green"] = 4;
  color["Cyan"] = 5;

  while(1) {
    int n;
    set<Dice> s;
    Dice dice;
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < 6; j++) {
	string str;
	cin >> str;
	dice.c[j] = color[str];
      }
      dice.sort();
      s.insert(dice);
    }
    cout << n - s.size() << endl;
  }
  return 0;
}