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
}

Python: roll = [
(0,1,2,3,4,5),
(3,0,2,5,4,1),
(4,1,0,3,5,2),
(1,5,2,0,4,3),
(2,1,5,3,0,4),
(5,3,2,1,4,0)]

def zero_move_to_left(xi):
    r = roll[xi[0]]
    return [r[i] for i in xi]

def sort_middle_face(xi):
    m = xi[1:-1] 
    min_m = min(m)
    while m[0] != min_m:
        m = m[1:] + m[:1]
    return xi[:1] + m + xi[-1:]

import sys
f = sys.stdin


str2i = {'Blue':0, 'Cyan':1, 'Green':2, 'Magenta':3, 'Red':4, 'Yellow':5}

import collections
while True:
    n = int(f.readline())
    if n == 0:
        break
    c = collections.Counter()
    for i in range(n):
        xi = [str2i[w] for w in f.readline().split()]
        xi = zero_move_to_left(xi)
        xi = sort_middle_face(xi)
        c[tuple(xi)] += 1
    print(n - len(c))

Python: # AOJ 0198 Trouble in Shinagawa's Artifacts
# Python3 2018.6.20 bal4u

r = [ \
	[0,1,2,3,4,5,6], [0,1,3,5,2,4,6], [0,1,4,2,5,3,6], [0,1,5,4,3,2,6], \
	[0,2,6,3,4,1,5], [0,2,3,1,6,4,5], [0,2,1,4,3,6,5], [0,2,4,6,1,3,5], \
	[0,3,1,2,5,6,4], [0,3,2,6,1,5,4], [0,3,5,1,6,2,4], [0,3,6,5,2,1,4], \
	[0,4,1,5,2,6,3], [0,4,2,1,6,5,3], [0,4,5,6,1,2,3], [0,4,6,2,5,1,3], \
	[0,5,1,3,4,6,2], [0,5,3,6,1,4,2], [0,5,4,1,6,3,2], [0,5,6,4,3,1,2], \
	[0,6,2,4,3,5,1], [0,6,3,2,5,4,1], [0,6,5,3,4,2,1], [0,6,4,5,2,3,1]]

def same(x, y):
	t = ['']*7
	for i in range(24):
		for j in range(1, 7): t[j] = a[y][r[i][j]]
		if a[x] == t: return True
	return False

while True:
	n = int(input())
	if n == 0: break
	f = [0]*n
	a = [['' for j in range(7)] for i in range(n)]
	for i in range(n):
		s = list(input().split())
		for j in range(6): a[i][j+1] = s[j]
	for i in range(n):
		if f[i] == 1: continue
		for j in range(i+1, n):
			if same(i, j): f[j] = 1
	print(sum(f))

Python: def to_top_red(cube):
  c1, c2, c3, c4, c5, c6 = cube
  if c2 == "Red":
    c1, c2, c6, c5 = c2, c6, c5, c1
  elif c3 == "Red":
    c1, c4, c6, c3 = c3, c1, c4, c6
  elif c4 == "Red":
    c1, c4, c6, c3 = c4, c6, c3, c1
  elif c5 == "Red":
    c1, c5, c6, c2 = c5, c6, c2, c1
  elif c6 == "Red":
    c1, c2, c6, c5 = c6, c5, c1, c2
  return (c1, c2, c3, c4, c5, c6)

def regist(cube, cube_dic):
  c1, c2, c3, c4, c5, c6 = cube
  cube_dic[(c1, c2, c3, c4, c5, c6)] = True
  cube_dic[(c1, c4, c2, c5, c3, c6)] = True
  cube_dic[(c1, c3, c5, c2, c4, c6)] = True
  cube_dic[(c1, c5, c4, c3, c2, c6)] = True

while True:
  n = int(input())
  if n == 0:
    break

  cube_dic = {}
  ans = 0
  
  for _ in range(n):
    cube = to_top_red(input().split())
    if cube in cube_dic:
      ans += 1
    else:
      regist(cube, cube_dic)
  
  print(ans)

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

using namespace std;

int n;
string str[31][6];

bool roll(int x,int y){
	bool flag2=false;
	for(int i=0;i<4;i++){
		string st=str[y][1];
		str[y][1]=str[y][2];
		str[y][2]=str[y][4];
		str[y][4]=str[y][3];
		str[y][3]=st;
		bool flag=true;
		for(int j=0;j<6;j++){
			if(str[y][j]!=str[x][j])flag=false;
		}
		if(flag)flag2=true;
	}
	return flag2;
}

bool check(int x,int y){
	bool flag=true;
	if(roll(x,y))flag=false;
	swap(str[y][0],str[y][5]);
	swap(str[y][1],str[y][4]);
	if(roll(x,y))flag=false;
	swap(str[y][0],str[y][5]);
	swap(str[y][1],str[y][4]);
	for(int i=0;i<4;i++){
		string st=str[y][0];
		str[y][0]=str[y][2];
		str[y][2]=str[y][5];
		str[y][5]=str[y][3];
		str[y][3]=st;
		if(roll(x,y))flag=false;
	}
	return flag;
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			for(int j=0;j<6;j++){
				cin >> str[i][j];
			}
		}
		int cnt=0;
		for(int i=0;i<n;i++){
			bool flag=true;
			for(int j=0;j<i;j++){
				if(!check(i,j))flag=false;
			}
			if(flag)cnt++;
		}
		printf("%d\n",n-cnt);
	}
	return 0;
}

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

using namespace std;

int n;
string str[31][6];

bool roll(int x,int y){
	bool flag2=false;
	for(int i=0;i<4;i++){
		string st=str[y][1];
		str[y][1]=str[y][2];
		str[y][2]=str[y][4];
		str[y][4]=str[y][3];
		str[y][3]=st;
		bool flag=true;
		for(int j=0;j<6;j++){
			if(str[y][j]!=str[x][j])flag=false;
		}
		if(flag)flag2=true;
	}
	return flag2;
}

bool check(int x,int y){
	bool flag=true;
	if(roll(x,y))flag=false;
	for(int i=0;i<4;i++){
		string st=str[y][0];
		str[y][0]=str[y][2];
		str[y][2]=str[y][5];
		str[y][5]=str[y][3];
		str[y][3]=st;
		if(roll(x,y))flag=false;
	}
	swap(str[y][0],str[y][5]);
	swap(str[y][1],str[y][4]);
	if(roll(x,y))flag=false;
	for(int i=0;i<4;i++){
		string st=str[y][0];
		str[y][0]=str[y][2];
		str[y][2]=str[y][5];
		str[y][5]=str[y][3];
		str[y][3]=st;
		if(roll(x,y))flag=false;
	}
	swap(str[y][0],str[y][5]);
	swap(str[y][1],str[y][4]);
	return flag;
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			for(int j=0;j<6;j++){
				cin >> str[i][j];
			}
		}
		int cnt=0;
		for(int i=0;i<n;i++){
			bool flag=true;
			for(int j=0;j<i;j++){
				if(!check(i,j))flag=false;
			}
			if(flag)cnt++;
		}
		printf("%d\n",n-cnt);
	}
	return 0;
}

C++: #include<iostream>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int colornum(string color){
  //cout<<color<<endl;
  if(color=="Red")return 0;
  if(color=="Yellow")return 1;
  if(color=="Blue")return 2;
  if(color=="Magenta")return 3;
  if(color=="Green")return 4;
  if(color=="Cyan")return 5;
  return 0;
}

int main(){
  int n;
  while(true){
    cin>>n;
    if(!n)break;
    set<int> dice;
    for(int i=0;i<n;i++){
      int d=0;
      int red = 0;
      vector<string> colors(6);
      for(int j=0;j<6;j++){
	cin>>colors[j];
	if (colors[j]=="Red")
	  red = j;
      }
      d = colornum(colors[5-red])*1296;
      int side[4];
      if(red==0)side[0] = 1,side[1]=2;
      if(red==1)side[0] = 0,side[1]=3;
      if(red==2)side[0] = 0,side[1]=1;
      if(red==3)side[0] = 0,side[1]=4;
      if(red==4)side[0] = 0,side[1]=2;
      if(red==5)side[0] = 1,side[1]=3;
      side[2] = 5-side[0];
      side[3] = 5-side[1];
      int dmin = 1296;
      for(int j=0;j<4;j++){
	int dd = 0;
	for(int k=0;k<4;k++){
	  dd *= 6;
	  dd += colornum(colors[side[(j+k)%4]]);
	}
	if(dd<dmin)dmin=dd;
      }
      d += dmin;
      dice.insert(d);
    }
    cout<<(n-dice.size())<<endl;
  }
  return 0;
}