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]) {
            cnt++;
            d.erase(d.begin()+i); update = true; goto NEXT;
          }
        }
      }
    NEXT:;
    }
    cout << N-cnt << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<functional>

using namespace std;

#define OUT cout <<
#define IN cin >>
#define E << endl;
#define FOR(i,a,b) for(int i = a;i < b;i++)

int n;

void input(){
	IN n;
}

class Dice{
	private:
		string temp;
	public:
		string c[6];
		Dice(){}
		void roll(int axis){
			if(axis == 1){
				temp = c[1];
				c[1] = c[2];
				c[2] = c[6];
				c[6] = c[5];
				c[5] = temp;
			}
			else{
				temp = c[2];
				c[2] = c[4];
				c[4] = c[5];
				c[5] = c[3];
				c[3] = temp;
			}
		}
		void getd(string& c1, string& c2, string& c3, string& c4, string& c5, string& c6){
			c1 = c[0];
			c2 = c[1];
			c3 = c[2];
			c4 = c[3];
			c5 = c[4];
			c6 = c[5];
		}

		void input(){
			FOR(i,0,6){
				IN c[i];
			}
		}

};

int main(){
	while(true){
		input();
		if(n == 0)break;
		int count = 0;
		bool match[n];
		FOR(i, 0, n){
			match[i] = false;
		}
		string str1[6];
		string str2[6];	

		vector<Dice> dice;
	
		dice.resize(n);
		FOR(i, 0, n){
			dice[i].input();
		}
			

		FOR(i, 0, n - 1){
			FOR(j, i, n - 1){
				bool flag2 = false;
				FOR(x, 0, 4){
					FOR(y, 0, 4){
						dice[j].getd(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
						dice[j + 1].getd(str2[0],str2[1],str2[2], str2[3],str2[4],str2[5]);
						
						bool flag1 = true;
						FOR(d, 0, 6){					
							if(str1[d] != str2[d]){
								flag1 == false;
							}
						}
						if(flag1){
							if(match[j] == false){							
								flag2 = true;
							}
							match[j + 1] = true;
						}
						flag1 = true;
					
						dice[j].roll(y);
					}
					dice[j].roll(x);
				}
				if(flag2){
					count++;
					//OUT "count++ " << i << " " << j  E
				}
			}
		}	

		OUT count E

	}
}