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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

enum { U, F, R, L, B, D };
struct dice {
    int face[6];
    dice(const dice& d){ rep(i, 6) this->face[i] = d.face[i]; }
    dice(){
        // デフォルトでは各面は 1..6 だがそうである必要はない
        face[F] = 1;
        face[R] = 2;
        face[U] = 3;
        face[B] = 6;
        face[L] = 5;
        face[D] = 4;
    }

    int find_face(int f){
        rep(i, 6) if (face[i] == f) return i;
        return -1;
    }

    void turn(int dir){
        switch (dir){
        case R:
            rotate(U, R, D, L); break;
        case B:
            rotate(U, B, D, F); break;
        case L:
            rotate(U, L, D, R); break;
        case F:
            rotate(U, F, D, B); break;
        case U:  // 上から見て反時計回り
            rotate(F, R, B, L); break;
        case D: // 下から見て反時計回り
            rotate(F, L, B, R); break;
        default: throw "";
        }
    }
    int& operator[](int n){ return face[n]; }

    vector<dice> all() {
        vector<dice> res(24);
        rep(k, 6){
            rep(i, 4){ res.push_back(*this); turn(R); }
            (k & 1 ? turn(U) : turn(F));
        }
        return res;
    }

    void rotate(int a, int b, int c, int d){
        int t = face[d];
        face[d] = face[c];
        face[c] = face[b];
        face[b] = face[a];
        face[a] = t;
    }

    bool operator==(const dice& d_) const {
        dice d = d_;
        vector<dice> ds = d.all();
        rep(i, ds.size()){
            bool res = true;
            rep(j, 6){
                if (ds[i][j] != this->face[j]) {
                    res = false;
                    break;
                }
            }
            if (res) return true;
        }
        return false;
    }
};

int main(){
    int n;
    while (cin >> n && n){
        vector<dice> made;
        rep(i, n){
            dice d;
            rep(j, 6){
                string s; cin >> s;
                d[j] = s.front();
            }
            made.push_back(d);
        }
        int c = 0;
        rep(i, made.size()){
            rep(j, i){
                if (made[j] == made[i]){
                    c++;
                }
            }
        }
        cout << c << endl;
    }
}

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;
    rep(i,N-1){
      for(int j = i+1 ; j < N ; j++){
        if(cube[i].equals(cube[j])){
          ans++;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,q;
  int i;
  con 
  int s[n];
  for(i=0;i<n;i++) printf("%d",&s[i]);
  printf("%d",&q);
  int t[q];
  for(i=0;i<q;i++) printf("%d",&t[i]);
  int count=0;
  int h[10000000];
  for(i=0;i<n;i++) h[s[i]] = 1;
  for(i=0;i<q;i++){
    if(h[t[q]]==1){
      count++;
      h[t[q]] = 0;
    }
  }
  scanf("%d\n",count);
  return 0;
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

struct dice
{
	string o;
	vs a;
	dice(string _a)
	{
		o = _a;
		init();
	}
	string & operator[](int n) { return a[n]; }

	void init()
	{
		string s;
		int d[6][10] = { { -1 },{ 1,-1 },{ 0,0,0,1,-1 },{ 0,1,-1 },{ 0,0,1,-1 },{ 1,1,-1 } };
		FOR(i, 6)
		{
			s = o;
			FOR(j, 10)
			{
				if (d[i][j] == -1)break;
				if (d[i][j] == 1)sn(s);
				else se(s);
			}
			FOR(j, 4)
			{
				a.push_back(s);
				se(s);
			}
		}
	}

	void sn(string &s)
	{
		swap(s[1], s[5]);
		swap(s[2], s[1]);
		swap(s[6], s[2]);
	}
	void se(string &s)
	{
		swap(s[2], s[3]);
		swap(s[4], s[2]);
		swap(s[5], s[4]);
	}
};

int main()
{
	int n;
	while (cin >> n, n)
	{
		vector<dice> a;
		FOR(i, n)
		{
			string o=" ";
			FOR(j, 6)
			{
				string s; cin >> s;
				o += s[0];
			}
			dice d(o);
			bool ok = true;
			FOR(j, a.size())
			{
				FOR(k, a[j].a.size())
				{
					if (o == a[j][k])ok = false;
				}
			}
			if (ok)a.push_back(d);
		}
		cout << n - a.size() << endl;
	}
}