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<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
  int n;
  int ans;
  int res=0;
  int box[30][6];
  bool b[30][30];
  int samenum;
  int samenum2;
  while(cin>> n,n){
    ans=0;
    //for(int i=0;i<n;i++){
    //for(int j=0;j<n;j++){
    //	b[i][j]=false;
    //}
    //}
    for(int i=0;i<n;i++){
      for(int j=0;j<6;j++){
	string s;
	cin>> s;
	if(s=="Red") box[i][j]=0;
	else if(s=="Yellow") box[i][j]=1;
	else if(s=="Blue") box[i][j]=2;
	else if(s=="Magenta") box[i][j]=3;
	else if(s=="Green") box[i][j]=4;
	else if(s=="Cyan") box[i][j]=5;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j) continue;
	//if(b[i][j]==true) continue;
	//b[i][j]=b[j][i]=true;
	ans=0;
	for(int k=0;k<6;k++){
	  if(box[i][0]==box[j][k]){
	    samenum=k; 
	  }
	}
	if(box[j][samenum]-box[i][0]==0){
	  if(box[i][5]==box[j][5]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==1){
	  if(box[i][5]==box[j][4]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==2){
	  if(box[i][5]==box[j][3]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==3){
	  if(box[i][5]==box[j][2]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==4){
	  if(box[i][5]==box[j][1]){
	    ans++;
	  }
	}
	else if(box[j][samenum]-box[i][0]==5){
	  if(box[i][5]==box[j][0]){
	    ans++;
	  }
	}



	for(int k=0;k<6;k++){
	  if(box[i][1]==box[j][k]){
	    samenum=k; 
	  }
	}
	if(box[j][samenum]-box[i][1]==0){
	  if(box[i][4]==box[j][4]){
	    if(ans)res++;
	  }
	}
	else if(box[j][samenum]-box[i][1]==-1){
	  if(box[i][4]==box[j][5]){
	    if(ans)res++;
	  }
	}
	else if(box[j][samenum]-box[i][1]==1){
	  if(box[i][4]==box[j][3]){
	    if(ans)res++;
	  }
	}
	else if(box[j][samenum]-box[i][1]==2){
	  if(box[i][4]==box[j][2]){
	    if(ans)res++;
	  }
	}
	else if(box[j][samenum]-box[i][1]==3){
	  if(box[i][4]==box[j][1]){
	    if(ans)res++;
	  }
	}
	else if(box[j][samenum]-box[i][1]==4){
	  if(box[i][4]==box[j][0]){
	    if(ans)res++;
	  }
	}
      }
    }


    cout<< res/2<< endl;
  }
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<set>
using namespace std;
string face[6];
int n;
int main(){
  while(cin >> n, n){
    set<string> ans;
    for(int j = 0;j < n;j++){
      cin >> face[0] >> face[1] >> face[2] >> face[3] >> face[4] >> face[5];
      string p;
      for(int i = 0;i < 4;i++){
	if(face[0] == "Blue")break;
	swap(face[0], face[1]);
	swap(face[1], face[5]);
	swap(face[5], face[3]);
      }
      for(int i = 0;i < 4;i++){
	if(face[0] == "Blue")break;
	swap(face[0], face[2]);
	swap(face[2], face[5]);
	swap(face[5], face[4]);
      }
      for(int i = 1;i < 5;i++){
	if(i == 1)p = face[i];
	p = min(p, face[i]);
      }
      while(face[1] != p){
	swap(face[1], face[4]);
	swap(face[3], face[4]);
	swap(face[2], face[3]);
      }
      string res ="";
      for(int i = 0;i < 6;i++){
	res += face[i][0];
      }
      ans.insert(res);
    }
    cout << n - ans.size() << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int N;
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		int X[6];
		set<int>S;
		for(int i=0;i<N;i++){
			for(int j=0;j<6;j++){
				string SS;
				cin >> SS;
				if(SS=="Cyan")X[j]=0;
				if(SS=="Yellow")X[j]=1;
				if(SS=="Red")X[j]=2;
				if(SS=="Magenta")X[j]=3;
				if(SS=="Green")X[j]=4;
				if(SS=="Blue")X[j]=5;
			}
			if(X[0]==0){
				int minc=7,minci;
				for(int i=1;i<5;i++){
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==1){
					sum=X[1]+X[2]*6+X[4]*36+X[3]*216;
				}
				if(minci==2){
					sum=X[2]+X[4]*6+X[3]*36+X[1]*216;
				}
				if(minci==3){
					sum=X[4]+X[3]*6+X[1]*36+X[2]*216;
				}
				if(minci==4){
					sum=X[3]+X[1]*6+X[2]*36+X[4]*216;
				}
				//printf("%d\n",sum);
				S.insert(sum);
			}
			if(X[5]==0){
				int minc=7,minci;
				for(int i=1;i<5;i++){
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==1){
					sum=X[1]+X[3]*6+X[4]*36+X[2]*216;
				}
				if(minci==2){
					sum=X[3]+X[4]*6+X[2]*36+X[1]*216;
				}
				if(minci==3){
					sum=X[4]+X[2]*6+X[1]*36+X[3]*216;
				}
				if(minci==4){
					sum=X[2]+X[1]*6+X[3]*36+X[4]*216;
				}
				//printf("%d\n",sum);
				S.insert(sum);
			}
			if(X[1]==0){
				int minc=7,minci;
				for(int i=0;i<6;i++){
					if(i==1||i==4)continue;
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==0){
					sum=X[0]+X[2]*6+X[5]*36+X[3]*216;
				}
				if(minci==2){
					sum=X[2]+X[5]*6+X[3]*36+X[0]*216;
				}
				if(minci==5){
					sum=X[5]+X[3]*6+X[0]*36+X[2]*216;
				}
				if(minci==3){
					sum=X[3]+X[0]*6+X[2]*36+X[5]*216;
				}
				//printf("%d\n",sum);
				S.insert(sum);
			}
			if(X[4]==0){
				int minc=7,minci;
				for(int i=0;i<6;i++){
					if(i==1||i==4)continue;
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==0){
					sum=X[0]+X[3]*6+X[5]*36+X[2]*216;
				}
				if(minci==2){
					sum=X[3]+X[5]*6+X[2]*36+X[0]*216;
				}
				if(minci==5){
					sum=X[5]+X[2]*6+X[0]*36+X[3]*216;
				}
				if(minci==3){
					sum=X[2]+X[0]*6+X[3]*36+X[5]*216;
				}
				//printf("%d\n",sum);
				S.insert(sum);
			}
			if(X[2]==0){
				int minc=7,minci;
				for(int i=0;i<6;i++){
					if(i==2||i==3)continue;
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==4){
					sum=X[4]+X[0]*6+X[1]*36+X[5]*216;
				}
				if(minci==0){
					sum=X[0]+X[1]*6+X[5]*36+X[4]*216;
				}
				if(minci==1){
					sum=X[1]+X[5]*6+X[4]*36+X[0]*216;
				}
				if(minci==5){
					sum=X[5]+X[4]*6+X[0]*36+X[1]*216;
				}
				//printf("%d\n",sum);
				S.insert(sum);
			}
			if(X[3]==0){
				int minc=7,minci;
				for(int i=0;i<6;i++){
					if(i==2||i==3)continue;
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==4){
					sum=X[4]+X[5]*6+X[1]*36+X[0]*216;
				}
				if(minci==0){
					sum=X[5]+X[1]*6+X[0]*36+X[4]*216;
				}
				if(minci==1){
					sum=X[1]+X[0]*6+X[4]*36+X[5]*216;
				}
				if(minci==5){
					sum=X[0]+X[4]*6+X[5]*36+X[1]*216;
				}
				//printf("%d\n",sum);
				S.insert(sum);
			}
		
		}
		printf("%d\n",N-(int)S.size());
	}
}