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<string>
#include<vector>

using namespace std;

struct DATA{
  string s1, s2, s3, s4, s5, s6;
};

void Swap(string&, string&, string&, string&);
DATA MakeData(string, string, string, string, string, string);
int SearchTheSame(DATA, DATA);

int main(){
  int i, j, n, x;
  string s1, s2, s3, s4, s5, s6;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> s1 >> s2 >> s3 >> s4 >> s5 >> s6;

      if(s2 == "Red"){
	Swap(s1, s2, s6, s5);
      }else if(s3 == "Red"){
	Swap(s1, s3, s6, s4);
      }else if(s4 == "Red"){
	Swap(s1, s4, s6, s3);
      }else if(s5 == "Red"){
	Swap(s1, s5, s6, s2);
      }else if(s6 == "Red"){
	Swap(s1, s2, s6, s5);
	Swap(s1, s2, s6, s5);
      }

      _data = MakeData(s1, s2, s3, s4, s5, s6);

      for(j=0, x=0; j<data.size(); ++j){
	if(SearchTheSame(data[j], _data) == 1){
	  x = 1;
	  break;
	}
      }
      if(x == 0) data.push_back(_data);
    }

    cout << n-data.size() << endl;
    data.clear();
  }
  return 0;
}

void Swap(string& a, string& b, string& c, string& d){
  string e;
  e = a;
  a = b;
  b = c;
  c = d;
  d = e;
}

DATA MakeData(string s1, string s2, string s3, string s4, string s5, string s6){
  DATA data;
  data.s1 = s1;
  data.s2 = s2;
  data.s3 = s3;
  data.s4 = s4;
  data.s5 = s5;
  data.s6 = s6;
  return data;
}

int SearchTheSame(DATA data1, DATA data2){
  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  Swap(data2.s2, data2.s3, data2.s5, data2.s4);

  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  Swap(data2.s2, data2.s3, data2.s5, data2.s4);

  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  Swap(data2.s2, data2.s3, data2.s5, data2.s4);

  if(data1.s1 == data2.s1 && data1.s2 == data2.s2 && data1.s3 == data2.s3 && 
     data1.s4 == data2.s4 && data1.s5 == data2.s5 && data1.s6 == data2.s6)
    return 1;

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
string s[50][6];
int d[12][6]={
  {0,1,2,3,4,5},
  {0,2,3,4,1,5},
  {0,3,4,1,2,5},
  {0,4,1,2,3,5},
  
  {0,1,2,3,4,5},
  {3,1,0,5,4,2},
  {5,1,3,2,4,0},
  {2,1,5,0,4,3},
  
  {0,1,2,3,4,5},
  {1,4,2,3,5,0},
  {4,5,2,3,0,1},
  {5,0,2,3,1,4}
};
int main(){
  int n;
  while(cin>>n&&n){
    int ans=0;
    lol(i,n){
      lol(j,6)cin>>s[i][j];
      bool same=false;
      lol(j,i){
	lol(r,12){
	  bool ok=true,pk=true;;
	  lol(k,6){
	    if(s[i][k]!=s[j][d[r][k]])ok=false;
	    if(s[i][k]!=s[j][6-d[r][k]])pk=false;
	  }
	  if(ok)same=true;
	  if(pk)same=true;
	}
      }
      if(same)ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main() {
	int a, b[101][101],kotaneet=0;
	char str[101];
	while (1) {
		cin >> a;
		if (a == 0)return 0;
		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;
							}
						}
					}
				}
			}
		}
		cout << kotaneet << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool func(string s1[7], string s2[7])
{
	bool f = true, fs[7];
	string s3[7];
	fill(fs, fs+7, true);
	
	for(int i = 1; i <= 3 && f; i++){
		for(int j = 1; j <= 6 && f; j++){
			if(s1[i] == s2[j]){
				if(!fs[j]){
					f = false;
				} else {
					fs[j] = fs[7-j] = false;
					s3[i] = s2[j];
					s3[7-i] = s2[7-j];
				}
				break;
			}
		}
	}
	
	for(int i = 1; i <= 6 && f; i++){
		if(s1[i] != s3[i]){
			f = false;
		}
	}
	
	return !f;
}

int main()
{
	int n, c;
	string s[31][7];
	bool f[31];
	
	while(cin>>n&&n){
		for(int i = 0; i < n; i++){
			for(int j = 1; j <= 6; j++){
				cin >> s[i][j];
			}
		}
		c = 0;
		fill(f, f+31, true);
		
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n && f[j]; j++){
				f[j] = func(s[i], s[j]);
			}
		}
		
		for(int i = 0; i < n; i++){
			if(f[i]){
				c++;
			}
		}
		
		cout << (n-c) << endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;

#define rep(i,n) for(int i = 0 ; i < n ; i++) 

class Cube{
private:
  string tmp;
public:
  string d[6];
 
  void rollN(){
    tmp = d[0];
    d[0] = d[1];
    d[1] = d[5];
    d[5] = d[4];
    d[4] = tmp;
  }
 
  void rollW(){
    tmp = d[0];
    d[0] = d[2];
    d[2] = d[5];
    d[5] = d[3];
    d[3] = tmp;
  }

  void rotation(){
    tmp = d[1];
    d[1] = d[3];
    d[3] = d[4];
    d[4] = d[2];
    d[2] = tmp;
  }

  bool judge(Cube &C){
    rep(i,6){
      if(d[i] != C.d[i]){
        return false;
      }
    }
    return true;
  }

  bool equals(Cube &C){
    rep(i,3){
      rollN();
      if(d[0] == C.d[0]){
        break;
      }
      rollW();
      if(d[0] == C.d[0]){
        break;
      }
    }
    rep(i,4){
      if(judge(C)){
        return true;
      }
      rotation();
    }
    return false;
  }
};
 
int main(){
  int N;

  while(cin >> N, N){
    Cube cube[N];
    rep(i,N){
      rep(j,6){
        cin >> cube[i].d[j];
      }
    }   

    int ans = 0;
    bool used[N];
    memset(used, false, sizeof(used));
    rep(i,N-1){
      for(int j = i+1 ; j < N ; j++){
        if(cube[i].equals(cube[j]) && !used[j]){
          used[j] = true;
          ans++;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}