Problem:
立方体の作品
芸術家品川は
n
点の作品を出展するように依頼されました。そこで、立方体の 6 面をペンキで色付けしたものを作品として出展することにしました。作品は、Red、Yellow、Blue、Magenta、Green、Cyan の 6 色全てが使われていて、各面は 1 色で塗りつぶされています。品川は形が同じ立方体の作品でも色の配置の仕方を変え、異なる作品として
n
点作成しました。
彼の友人であるあなたは、友人のよしみで作品を出展前に閲覧させてもらいましたが、そこであることに気が付きました。それらの作品の中に異なる色付けをされているように見えても、実は同じ色の組み合わせをした立方体が存在していたのです。このままでは、
n
点の作品を出展することできなくなってしまいます。
作成した作品の数と各作品の色の情報を入力とし、出展するためにあと何点必要かを出力するプログラムを作成してください。
立方体の各面の色は c1 から c6 までの記号で表され、 以下のような配置となっています。また、c1 から c6 のそれぞれは Red、Yellow、Blue、Magenta、Green、Cyan のいずれか 1 色となります。
Input
複数のデータセットの並びが入力として与えられます。 入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
n
cube
1
cube
2
:
cube
n
１行目に作品の数
n
(1 ≤
n
≤ 30)、続く
n
行に
i
番目の作品の情報が与えられます。各作品の情報は次の形式で与えられます。
c1 c2 c3 c4 c5 c6
作品の色の配置 c
i
が空白区切りで与えられます。
データセットの数は 100 を超えません。
Output
データセットごとに、出展するのにあと何点の作品が必要かを１行に出力します。
Sample Input
3
Cyan Yellow Red Magenta Green Blue
Cyan Yellow Red Magenta Green Blue
Red Yellow Magenta Blue Green Cyan
4
Red Magenta Blue Green Yellow Cyan
Red Yellow Magenta Blue Green Cyan
Magenta Green Red Cyan Yellow Blue
Cyan Green Yellow Blue Magenta Red
0
Output for the Sample Input
1
1

Submitted solutions:

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

// D[i][j] : (2,3,4,5面) 方向に倒した時 + 1面を軸に (時計/反時計) 周りにした時、
// 次の j 面は今の D[i][j] 面になる
int D[6][6] = {{4, 0, 2, 3, 5, 1}, {3, 1, 0, 5, 4, 2}, {2, 1, 5, 0, 4, 3},
               {1, 5, 2, 3, 0, 4}, {0, 2, 4, 1, 3, 5}, {0, 3, 1, 4, 2, 5}};
template <typename T> array<T, 6> get_next_dice(array<T, 6> dice, int dir) {
    array<T, 6> ndice;
    for (int i = 0; i < 6; i++) {
        ndice[i] = dice[D[dir][i]];
    }
    return ndice;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    while (cin >> n, n) {
        using Dice = array<string, 6>;
        set<Dice> st;
        int res = 0;
        for (int i = 0; i < n; i++) {
            bool f = false;
            vector<Dice> v(6);
            for (int j = 0; j < 6; j++) {
                cin >> v[0][j];
            }
            for (int j = 1; j < 4; j++) {
                v[j] = get_next_dice(v[j - 1], 0);
            }
            v[4] = get_next_dice(v[0], 1);
            v[5] = get_next_dice(v[0], 2);
            for (int j = 0; j < 6; j++) {
                auto d = v[j];
                for (int k = 0; k < 4; k++) {
                    if (st.find(d) != st.end()) f = true;
                    st.insert(d);
                    d = get_next_dice(d, 4);
                }
            }

            if (f) res += 1;
        }
        cout << res << "\n";
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3504
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    while(cin >> n, n){
        set<vector<string>> S;
        int ans = 0;
        for(int i = 0; i < n; i++){
            vector<string> a(6);
            for(auto &&s:a)cin >> s;
            if(S.count(a)){
                ans++;
                continue;
            }
            for(int l = 0; l < 4; l++){
                for(int j = 0; j < 4; j++){
                    for(int k = 0; k < 4; k++){
                        S.insert(a);
                        swap(a[5], a[2]);
                        swap(a[2], a[0]);
                        swap(a[0], a[3]);
                    }
                    swap(a[4], a[2]);
                    swap(a[2], a[1]);
                    swap(a[1], a[3]);
                }
                swap(a[5], a[2]);
                swap(a[2], a[0]);
                swap(a[0], a[3]);
            }
        }
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3592
final_rank: 17

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 1000000007 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;

  BIT(int n){
    N = n;
    node.resize(N+10);
  }

  /* a: 1-indexed */
  void update(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] = max(node[i],x);
  }

  /* [1, a] */
  T query(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res = max(res,node[x]);
    return res;
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};
struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;
    int n;
    // construct
    RollingHash(const string &S) {
        n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
 
    inline pair<long long, long long> c_shift(int l) {
      auto h1 = get(0, l);
      auto h2 = get(l, n);
      return {(h1.first + h2.first * power1[l]) % mod1, (h1.second + h2.second * power2[l]) % mod2};
    }
 
    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};
struct Dice {
    const int UP = 0;
    const int FRONT = 1;
    const int RIGHT = 2;
    const int LEFT = 3;
    const int BACK = 4;
    const int DOWN = 5;

    vector<string> d;

    Dice(vector<string> v, int N = 6){
        d.resize(N);
        for(int i=0; i<N; i++){
            d[i] = v[i];
        }
    }

    void rotate(char s){
        vector<string> tmp = d;
        if(s == 'S'){
            d[0] = tmp[4];
            d[1] = tmp[0];
            d[5] = tmp[1];
            d[4] = tmp[5];
        }

        if(s == 'E'){
            d[0] = tmp[3];
            d[2] = tmp[0];
            d[5] = tmp[2];
            d[3] = tmp[5];
        }

        if(s == 'W'){
            d[0] = tmp[2];
            d[3] = tmp[0];
            d[5] = tmp[3];
            d[2] = tmp[5];
        }

        if(s == 'N'){
            d[0] = tmp[1];
            d[1] = tmp[5];
            d[5] = tmp[4];
            d[4] = tmp[0];
        }
    }

    void spin(){
        vector<string> tmp = d;
        d[1] = tmp[2];
        d[2] = tmp[4];
        d[4] = tmp[3];
        d[3] = tmp[1];
    }
    

    string operator[](const int &k)
    {
        return d[k];
    }

    bool issame(Dice d2){
        bool res = true;

        for(int i=0; i<6; i++){
            if(d[i] != d2[i]) res = false;
        }

        return res;
    }
};
int main() {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  
  int n; 
  while(cin >> n, n) {
    int ans = 0;
    vector<Dice> ds;
    REP(i,n) {
      vector<string> s(6);
      REP(j,6) cin >> s[j];
      Dice d(s);
      ds.push_back(Dice(s));
    }
    UnionFind uf(n);
    REP(i,n) {
      bool ok = true;
      REP(j,n) {
        if(i == j) continue;
        Dice d1 = ds[i];
        Dice d2 = ds[j];
        REP(k,4) {
          d2.spin();
          REP(l,4){
            d2.rotate('N');
            REP(m,4) {
              d2.rotate('W');
              if(d1.issame(d2)) uf.merge(i, j);
            }
          }
        }
      }
    }
    set<int> roots;
    REP(i,n) {
      roots.insert(uf.root(i));
    }
    for(auto e: roots) {
      ans += uf.size(e) -1;
    }
    cout << ans << '\n';
  }
  return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 3396
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = 1e9;
template <typename T>
void input_arr(vector<T>& A, long long N) {
    for (long long i = 0; i < N; i++) {
        cin >> A[i];
    }
}
struct Dice {
    vector<string>S;
    Dice() {S.resize(6, "");}
    void read() {
        for (long long i = 0; i < 6; i++) {
            cin >> S[i];
        }
    }
    string &operator [] (long long i) {
        return S[i];
    }
};
void rotate(string &A, string &B, string &C, string &D) {
    string S = A;
    A=B;B=C;C=D;D=S;
}
bool same(Dice &A, Dice &B) {
    vector<vector<long long>>C = {
        {0,3,5,2},
        {0,2,5,3},
        {0,1,5,4},
        {0,4,5,1},
        {1,2,4,3},
        {1,3,4,2}
    };
    vector<long long>D = {5, 4, 3, 2, 1, 0};
    for (long long i = 0; i < 6; i++) {
        for (long long j = 0; j < 4; j++) {
            //compare
            bool check = true;
            for (long long k = 0; k < 6; k++) {
                if (A[k] != B[k]) check = false;
            }
            if (check) return true;
            rotate(B[C[5][0]],B[C[5][1]],B[C[5][2]],B[C[5][3]]);
        }
        if (i % 2 == 0) {
            rotate(B[C[3][0]],B[C[3][1]],B[C[3][2]],B[C[3][3]]);
        }
        else rotate(B[C[1][0]],B[C[1][1]],B[C[1][2]],B[C[1][3]]);
    }
    return false;
}
int main() {
    long long N; cin >> N;
    while (N != 0) {
        vector<Dice>S(N);
        for (long long i = 0; i < N; i++) {
            S[i].read();
        }
        for (long long i = 0; i < N; i++) {
            for (long long j = i + 1; j < N; j++) {
                if (same(S[i], S[j])) {
                    for (long long k = 0; k < 6; k++) {
                        S[i][k] = "-1";
                    }
                    break;
                }
            }
        }
        long long ans = 0;
        for (long long i = 0; i < N; i++) {
            ans += (S[i][0] == "-1");
        }
        cout << ans << endl;
        cin >> N;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 13

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).endf()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).endf(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).endf())
#define SORT(c) sort((c).begin(), (c).endf())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-4, PI = acos(-1);
//ここから編集    
typedef string::const_iterator State;
struct Dice {
    const int UP = 0;
    const int FRONT = 1;
    const int RIGHT = 2;
    const int LEFT = 3;
    const int BACK = 4;
    const int DOWN = 5;

    vector<int> d;

    Dice(vector<int> v, int N = 6){
        d.resize(N);
        for(int i=0; i<N; i++){
            d[i] = v[i];
        }
    }

    void rotate(char s){
        vector<int> tmp = d;
        if(s == 'S'){
            d[0] = tmp[4];
            d[1] = tmp[0];
            d[5] = tmp[1];
            d[4] = tmp[5];
        }

        if(s == 'E'){
            d[0] = tmp[3];
            d[2] = tmp[0];
            d[5] = tmp[2];
            d[3] = tmp[5];
        }

        if(s == 'W'){
            d[0] = tmp[2];
            d[3] = tmp[0];
            d[5] = tmp[3];
            d[2] = tmp[5];
        }

        if(s == 'N'){
            d[0] = tmp[1];
            d[1] = tmp[5];
            d[5] = tmp[4];
            d[4] = tmp[0];
        }
    }

    void spin(){
        vector<int> tmp = d;
        d[1] = tmp[2];
        d[2] = tmp[4];
        d[4] = tmp[3];
        d[3] = tmp[1];
    }
    

    int operator[](const int &k)
    {
        return d[k];
    }

    bool issame(Dice &d2){
        bool res = true;

        for(int i=0; i<6; i++){
            if(d[i] != d2[i]) res = false;
        }

        return res;
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n; 
    while(cin >> n,n){

        set<vector<int>> st;
        vector<vector<string>> v(n);
        map<string, int> mp;
        int cnt = 0;
        REP(i,n){
            REP(j,6){
                string t; cin >> t;
                if(!mp.count(t)) mp[t] = cnt++;
                v[i].push_back(t);
            }
        }
        int ans = 0;
        vector<bool> checked(n, false);
        REP(i,n){
            if(checked[i]) continue;

            REP(t,n){            
                if(i == t || checked[t]) continue;
                vector<int> tt;
                REP(j,6) tt.push_back(mp[v[i][j]]);
                Dice d1(tt, 6);
                vector<int> ttt;
                REP(j,6) ttt.push_back(mp[v[t][j]]);
                Dice d2(ttt, 6);
                bool ok = false;
                REP(j,4){
                    d1.spin();
                    REP(k,4){
                        d1.rotate('N');
                        REP(l,4){
                            d1.rotate('W');
                            if(d2.issame(d1)) ok = true;
                        }
                    }
                }
                if(ok){
                    ans++;
                    checked[t] = true;
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3184
final_rank: 11

code_snippet: #include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

vector<string> CubeInfo[30];
string StrTmp[6];
int N;
bool SameFlag[30];
//top front right left back bottom
int RotateBase[24][6] = {
	{ 0,1,2,3,4,5 },{},{},{},
	{ 1,5,2,3,0,4 },{},{},{},
	{ 2,1,5,0,4,3 },{},{},{},
	{ 3,1,0,5,4,2 },{},{},{},
	{ 4,0,2,3,5,1 },{},{},{},
	{ 5,4,2,3,1,0 },{},{},{},
};


void fullRotateBase() {
	int tmp[6], num;

	for (int i = 0; i < 21; i += 4) {
		for (int j = 0; j < 6; ++j) {
			tmp[j] = RotateBase[i][j];
		}
		for (int k = 1; k < 4; ++k) {
			num = tmp[1];
			tmp[1] = tmp[3];
			tmp[3] = tmp[4];
			tmp[4] = tmp[2];
			tmp[2] = num;
			for (int j = 0; j < 6; ++j) {
				RotateBase[i + k][j] = tmp[j];
			}
		}
	}
	/*for (int i = 0; i < 24; ++i) {
		for (int j = 0; j < 6; ++j) {
			cout << RotateBase[i][j] + 1 << " ";
		}
		cout << endl;
	}
	cout << endl;*/
}

bool judgeSame(int i, int j) {
	string tmp[6];
	bool flag;

	for (int id = 0; id < 24; ++id) {
		for (int k = 0; k < 6; ++k) {
			tmp[k] = CubeInfo[j][RotateBase[id][k]];
		}
		for (int k = 0; k < 6; ++k) {
			if (CubeInfo[i][k] != tmp[k]) {
				flag = false;
				break;
			}
			flag = true;
		}
		if (flag) {
			return true;
		}
	}
	return false;
}

int solve() {
	int cnt;

	cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (SameFlag[i]) {
			continue;
		}
		for (int j = i + 1; j < N; ++j) {
			if (judgeSame(i, j)) {
				SameFlag[j] = true;
				++cnt;
			}
		}
	}
	return cnt;
}

int main() {
	string str;

	fullRotateBase();
	while (cin >> N, N) {
		memset(SameFlag, false, sizeof(SameFlag));
		for (int i = 0; i < N; ++i) {
			CubeInfo[i].clear();
			for (int j = 0; j < 6; ++j) {
				cin >> str;
				CubeInfo[i].push_back(str);
			}
		}
		cout << solve() << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3016
final_rank: 5

code_snippet: #include<iostream>
using namespace std;
struct A{
	string s[6];
	void input(){
		for(int i=0;i<6;i++)cin>>s[i];
	}
	bool operator==(const A&a){
		for(int _=0;_<8;_++)
		{
			for(int __=0;__<4;__++)
			{
				bool flag=true;
				for(int i=0;i<6;i++)flag&=s[i]==a.s[i];
				if(flag)return true;
				string tmp=s[1];
				s[1]=s[2];
				s[2]=s[4];
				s[4]=s[3];
				s[3]=tmp;
			}
			if(_<4)
			{
				string tmp=s[0];
				s[0]=s[1];
				s[1]=s[5];
				s[5]=s[4];
				s[4]=tmp;
			}
			else
			{
				string tmp=s[0];
				s[0]=s[2];
				s[2]=s[5];
				s[5]=s[3];
				s[3]=tmp;
			}
		}
		return false;
	}
};
int N;
A a[30];
bool used[30];
main()
{
	while(cin>>N,N)
	{
		int ans=0;
		for(int i=0;i<N;i++)
		{
			a[i].input();
			used[i]=true;
			for(int j=0;j<i;j++)
			{
				if(used[j]&&a[j]==a[i])
				{
					used[i]=false;
					ans++;
					break;
				}
			}
		}
		cout<<ans<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3160
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

struct cube {

    vector<string> c;

    cube(): c(6) {}

    static bool is_same(cube a, cube b) {

        {
            bool r = true;
            for (int l = 0; l < 6; l++) {
                if (a.c[l] != b.c[l]) {
                    r = false;
                    break;
                }
            }
            if (r) return true;
        }
        
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    string temp = b.c[3];
                    b.c[3] = b.c[5];
                    b.c[5] = b.c[2];
                    b.c[2] = b.c[0];
                    b.c[0] = temp;
                    bool r = true;
                    for (int l = 0; l < 6; l++) {
                        if (a.c[l] != b.c[l]) {
                            r = false;
                            break;
                        }
                    }
                    if (r) return true;
                }
                string temp = b.c[4];
                b.c[4] = b.c[5];
                b.c[5] = b.c[1];
                b.c[1] = b.c[0];
                b.c[0] = temp;
            }
            string temp = b.c[3];
            b.c[3] = b.c[4];
            b.c[4] = b.c[2];
            b.c[2] = b.c[1];
            b.c[1] = temp;
        }

        return false;

    }


};

int main() {

    ll n;
    while (cin >> n, n) {

        vector<cube> cb(n);
        for (ll i = 0; i < n; i++) {
            for (ll j = 0; j < 6; j++) {
                cin >> cb[i].c[j];
            }
        }

        ll ans = 0;
        for (ll i = 0; i < n; i++) {
            bool is_kaburi = false;
            for (ll j = 0; j < i; j++) {
                if (cube::is_same(cb[i], cb[j])) {
                    is_kaburi = true;
                    break;
                }
            }
            if (is_kaburi) {
                ans++;
            }
        }

        cout << ans << endl;

    }

}
accuracy: 1
time_ms: 20
memory_kb: 3156
final_rank: 10

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

//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second

//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << p.first << " " << p.second;return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if (it != v.begin())os << " ";os << *it;
  }return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}

//typedef
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;




class UnionFind{
public:
	vector<int> ran, par;
	void init(int n){
		for(int i = 0;i < n;i++){
			par.push_back(i);
			ran.push_back(0);
		}
	}
	
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y){
		x = find(par[x]);
		y = find(par[y]);
		if(x == y)return;
		if(ran[x] < ran[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(par[x] == par[y])ran[x]++;
		}
	}
	
	bool same(int x, int y){
		return find(par[x]) == find(par[y]);
	}
};

template <typename T>class Box;
template <typename T>ostream& operator<<(ostream &, const Box<T> &);
template<typename T>class Box{
public:
	T top;
  T back, left, right, head;
  T bottom;
	T a[6];
	void init(T TOP, T BACK, T LEFT, T RIGHT, T HEAD, T BOTTOM){
		top = TOP;back = BACK;left = LEFT;
		right = RIGHT;head = HEAD;bottom = BOTTOM;
		a[0] = top;a[1] = back;a[2] = left;
		a[3] = right;a[4] = head;a[5] = bottom;
	}
	friend ostream &operator<<<T>(ostream &os, const Box &B);
	bool operator==(const Box& b) const {
		return(top    == b.top   &&
					 back   == b.back  &&
					 left   == b.left  &&
					 right  == b.right &&
					 head   == b.head  &&
					 bottom == b.bottom);
	}
	void rotate(T &d1, T &d2, T &d3, T &d4){
		T tmp = d1;
		d1 = d2;d2 = d3;d3 = d4;
		d4 = tmp;
	}
	void rotate_forward(){rotate(top, head, bottom, back);}
	void rotate_right(){rotate(top, left, bottom, right);}
	void rotate_spin(){rotate(head, right, back, left);}
	friend ostream & operator<< <>(ostream &, const Box<T> & B);
};
template <typename T>
ostream & operator<<(ostream & os, const Box<T> & B){
	os <<  "  " 				<< B.back   << endl;
	os << B.left << " " << B.bottom << " " << B.right << " " << B.top << endl;
	os <<  "  " 				<< B.head   << endl;
	return os;
}

bool same(Box<string> a, Box<string> b){
	rep(i,4){
		a.rotate_forward();
		rep(j,4){
			a.rotate_right();
			rep(k,4){
				a.rotate_spin();
				if(a == b)return true;
			}
		}
	}
	return false;
}

signed main(){
	while(1){
		int n;
		scanf("%lld", &n);
		if(n == 0)break;
		Box<string> B[n];
		UnionFind uf;uf.init(n);
		rep(i,n){
			string str[6];
			rep(j,6)cin >> str[j];
			B[i].init(str[5], str[4], str[3], str[2], str[1], str[0]);
		}
		int ans = 0;
		rep(i,n)rep(j,n){
			if(same(B[i], B[j]))uf.unite(i, j);
		}
		rep(i,n)ans += (uf.find(i) == i);
		printf("%lld\n", n-ans);
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3180
final_rank: 12

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

int pad[3][6] = { { 3, 1, 0, 5, 4, 2 }, { 1, 5, 2, 3, 0, 4 }, { 0, 2, 4, 1, 3, 5 } };
void rotate ( int op, string &S )
{
    string temp;
    for ( int i = 0; i < 6; i++ ) {
        temp.push_back ( S[pad[op][i]] );
    }
    S = temp;
}

bool search ( string S, string T )
{
    for ( int i = 0; i < 4; i++ ) {
        for ( int j = 0; j < 4; j++ ) {
            for ( int k = 0; k < 4; k++ ) {
                if ( S == T ) {
                    return ( false );
                }
                rotate ( 2, S );
            }
            rotate ( 1, S );
        }
        rotate ( 0, S );
    }
    return ( true );
}

int main()
{
    int N;
    int rotate_pos[35];

    while ( cin >> N, N ) {
        vector < string > data(N);
        int ans = 0;
        bool flag[35];

        fill_n(flag, 35, true);
        for ( int i = 0; i < N; i++ ) {
            string S;
            for ( int j = 0; j < 6; j++ ) {
                cin >> S;
                data[i] += S[0];
            }
            for ( int j = 0; j < i; j++ ) {
                flag[i] &= search ( data[i], data[j] );
            }
        }
        for ( int i = 0; i < N; i++ ) {
            if ( !flag[i] ) {
                ans++;
            }
        }
        cout << ans << endl;
    }

    return ( 0 );
}
accuracy: 1
time_ms: 140
memory_kb: 3008
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define MAX 100
class Cube {
public:
	string f[6];
	Cube() {
	}
	void roll_z() {
		roll(1, 2, 4, 3);
	}
	void roll_y() {
		roll(0, 2, 5, 3);
	}
	void roll_x() {
		roll(0, 1, 5, 4);
	}
	void roll(int i, int j, int k, int l) {
		string t = f[i];
		f[i] = f[j];
		f[j] = f[k];
		f[k] = f[l];
		f[l] = t;
	}
};
Cube C[MAX];
int n;
bool eq(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++)
		if (c1.f[i] != c2.f[i])
			return false;
	return true;
}

bool equal(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 4; j++) {
			if (eq(c1, c2))
				return true;
			c1.roll_z();
		}
		if (i % 2 == 0)
			c1.roll_y();
		else
			c1.roll_x();
	}
	return false;
}
main() {
	while( cin >> n && n ) {
		for(int i = 0;i<n;i++) for(int j = 0;j<6;j++) cin >> C[i].f[j];
		int cnt = 0;
		for(int i = 0;i<n;i++) {
			bool hasSame = false;
			for(int j=i+1; j<=n-1;j++) if (equal(C[i],C[j])) {hasSame =
				true;break;}
			if ( !hasSame ) cnt++;
		}
		cout << n - cnt << endl;
	}
}
accuracy: 1
time_ms: 20
memory_kb: 3092
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
string s[33][6];
int check(int a,int b){
  if(s[a][0]==s[b][0]&&s[a][1]==s[b][1]&&s[a][2]==s[b][2]&&s[a][3]==s[b][3]&&s[a][4]==s[b][4]&&s[a][5]==s[b][5])return 1;
    return 0;
}
void r1(int a){
  string p=s[a][0];
  swap(s[a][0],s[a][2]);swap(s[a][2],s[a][5]);
  swap(s[a][5],s[a][3]);s[a][3]=p;
}
void r2(int a){
  string p=s[a][0];
  swap(s[a][0],s[a][1]);swap(s[a][1],s[a][5]);
  swap(s[a][5],s[a][4]);s[a][4]=p;
}
void r3(int a){
  string p=s[a][1];
  swap(s[a][1],s[a][2]);swap(s[a][2],s[a][4]);
  swap(s[a][4],s[a][3]);s[a][3]=p;
}
int c7(int a,int b){
  int p=0;
  for(int i=0;i<4;i++){
    r1(a);
    for(int j=0;j<4;j++){
      r2(a);
      for(int k=0;k<4;k++){
        r3(a);
        if(check(a,b))p++;
      }
    }
  }
  return p;
}
int main(){
  int n;
  while(cin>>n,n){
    int sum=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<6;j++)
        cin>>s[i][j];
    for(int i=0;i<n;i++){
      int p=0;
      for(int j=i+1;j<n;j++){
        if(c7(i,j))p++;
      }
      if(p)sum++;
    }
    cout<<sum<<endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 3136
final_rank: 9

code_snippet: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

map<string,int> dict;

//saikoro
 
typedef vector<int> Dice;
enum {TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM};
#define rotate_swap(x, a, b, c, d) swap(x[a], x[b]); swap(x[b], x[c]); swap(x[c], x[d]);
 
void rotate_r(Dice& dice) {rotate_swap(dice, TOP, LEFT, BOTTOM, RIGHT);}
void rotate_l(Dice& dice) {rotate_swap(dice, TOP, RIGHT, BOTTOM, LEFT);}
void rotate_f(Dice& dice) {rotate_swap(dice, TOP, BACK, BOTTOM, FRONT);}
void rotate_b(Dice& dice) {rotate_swap(dice, TOP, FRONT, BOTTOM, BACK);}
void rotate_w(Dice& dice) {rotate_swap(dice, BACK, LEFT, FRONT, RIGHT);}
void rotate_c(Dice& dice) {rotate_swap(dice, BACK, RIGHT, FRONT, LEFT);}
 
vector<Dice> generate_all(Dice dice) {
 	vector<Dice> res;
  	for (int i = 0; i < 6; ++i) {
    	for (int j = 0; j < 4; ++j){
    		res.emplace_back(dice), rotate_w(dice);
    	}
	    if (i % 2) rotate_f(dice);
	    else rotate_r(dice);
	}
	return res;
}


void mainmain(){
	dict["Red"] = 0;
	dict["Yellow"] = 1;
	dict["Blue"] = 2;
	dict["Magenta"] = 3;
	dict["Green"] = 4;
	dict["Cyan"] = 5;
	int n;
	while(cin>>n,n){
		vector<Dice> v(n);
		rep(i,n){
			v[i] = Dice(6);
			rep(j,6){
				string s;
				cin>>s;
				v[i][j] = dict[s];
			}
		}
		int cnt = 0;
		rep(i,n){
			bool ok = true;
			rep(j,i){
				vector<Dice> tmp = generate_all(v[j]);
				rep(k, tmp.size()){
					if(tmp[k] == v[i]) ok = false;
				}
			}
			if(ok){
				cnt++;
			}
		}
		cout << n - cnt << endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 7

code_snippet: #include<iostream>
#include<string>
using namespace std;
int Dice[6][6] = { { 1,5,2,3,0,4 },{ 4,0,2,3,5,1 },{ 3,1,0,5,4,2 },{ 2,1,5,0,4,3 },{ 0,2,4,1,3,5 },{ 0,3,1,4,2,5 } }, power[6] = { 1,3,9,27,81,243 };
struct Saikoro { int x[6]; }; Saikoro T[30]; int n, vis[30]; char F[7] = "CYRMGB"; bool G[30][30];
bool bfs(int p, int q) {
	for (int i = 0; i < 729; i++) {
		int bit[6]; for (int j = 0; j < 6; j++) { bit[j] = (i / power[j]) % 3; }
		Saikoro U = T[p];
		for (int j = 0; j < 6; j++) {
			for (int k = 0; k <= bit[j]; k++) {
				Saikoro V = U; for (int l = 0; l < 6; l++)V.x[l] = U.x[Dice[j][l]]; U = V;
			}
		}
		bool OK = true; for (int j = 0; j < 6; j++) { if (T[q].x[j] != U.x[j])OK = false; }
		if (OK == true)return true;
	}
	return false;
}
int main() {
	while (true) {
		for (int i = 0; i < 30; i++) { for (int j = 0; j < 30; j++)G[i][j] = false; vis[i] = 0; }
		cin >> n; if (n == 0)break; for (int i = 0; i < n; i++) { for (int j = 0; j < 6; j++) { string S; cin >> S; for (int k = 0; k < 6; k++) { if (S[0] == F[k])T[i].x[j] = k; } } }
		for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { G[i][j] = bfs(i, j); G[j][i] = G[i][j]; } }
		int cnt = 0; for (int i = 0; i < n; i++) { if (vis[i] != 0)continue; cnt++; vis[i] = cnt; for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (vis[k] != cnt)continue; for (int l = 0; l < n; l++) { if (G[k][l] == true)vis[l] = cnt; } } } }
		cout << n - cnt << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 890
memory_kb: 2976
final_rank: 20

code_snippet: #ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

#include <vector>

// ------ Class ------ //
class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

#endif

#include <set>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<int> x, y; int t;
bool same(vector<int> a, vector<int> b) {
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				for (int l = 0; l < 4; l++) {
					string s;
					for (int m = 0; m < i; m++) s += 'N';
					for (int m = 0; m < j; m++) s += 'E';
					for (int m = 0; m < k; m++) s += 'S';
					for (int m = 0; m < l; m++) s += 'W';
					for (int i = 0; i < s.size(); i++) {
						t = a[0];
						switch (s[i]) {
						case 'N':
							a[0] = a[1];
							a[1] = a[5];
							a[5] = a[4];
							a[4] = t;
							break;
						case 'E':
							a[0] = a[3];
							a[3] = a[5];
							a[5] = a[2];
							a[2] = t;
							break;
						case 'S':
							a[0] = a[4];
							a[4] = a[5];
							a[5] = a[1];
							a[1] = t;
							break;
						case 'W':
							a[0] = a[2];
							a[2] = a[5];
							a[5] = a[3];
							a[3] = t;
							break;
						}
					}
					if (a == b) return true;
				}
			}
		}
	}
	return false;
}
int n; string s;
int main() {
	while (cin >> n, n) {
		vector<vector<int> > v(n, vector<int>(6));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 6; j++) {
				cin >> s;
				v[i][j] = s[0];
			}
		}
		UnionFind uf(n);
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (same(v[i], v[j])) uf.unite(i, j);
			}
		}
		set<int> s_;
		for (int i = 0; i < n; i++) s_.insert(uf.root(i));
		cout << n - s_.size() << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 530
memory_kb: 3180
final_rank: 19

code_snippet: #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,f[30],i,j,k,x,cnt,l,flg;
	char pat1[7],pat2[7];
	char a[30][6],buf[10],wk;
	while(1)	{
		scanf(" %d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	{
			for(j=0;j<6;j++)	{
				scanf("%s",buf);
				a[i][j]=buf[0];
			}
		}
//		for(i=0;i<n;i++)	{
//			for(j=0;j<6;j++)	printf("%c",a[i][j]);
//			printf("\n");
//		}
		pat1[6]='\0';	pat2[6]='\0';
		for(i=0;i<n;i++)	f[i]=0;
		for(i=0;i<n-1;i++)	{
			for(j=i+1;j<n;j++)	{
				for(k=0;k<6;k++)	{
					pat1[k]=a[i][k];
					pat2[k]=a[j][k];
				}
				flg=0;
				for(k=0;k<4;k++)	{
					wk=pat1[0];
					pat1[0]=pat1[2];
					pat1[2]=pat1[5];
					pat1[5]=pat1[3];
					pat1[3]=wk;
					for(l=0;l<4;l++)	{
						wk=pat1[1];
						pat1[1]=pat1[3];
						pat1[3]=pat1[4];
						pat1[4]=pat1[2];
						pat1[2]=wk;
						if(strcmp(pat1,pat2)==0)	{
							flg=1;
						}
					}
				}
				for(k=0;k<4;k++)	{
					wk=pat1[0];
					pat1[0]=pat1[1];
					pat1[1]=pat1[5];
					pat1[5]=pat1[4];
					pat1[4]=wk;
					for(l=0;l<4;l++)	{
						wk=pat1[1];
						pat1[1]=pat1[3];
						pat1[3]=pat1[4];
						pat1[4]=pat1[2];
						pat1[2]=wk;
						if(strcmp(pat1,pat2)==0)	{
							flg=1;	
						}
					}
				}
				if(flg==1)	{
					f[j]=1;
				}
			}
		}
		cnt=0;
		for(i=0;i<n;i++)	cnt+=f[i];
		printf("%d\n",cnt);
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1040
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
int N;
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		int X[30][6];
		for(int i=0;i<N;i++){
			for(int j=0;j<6;j++){
				string SS;
				cin >> SS;
				if(SS=="Cyan")X[i][j]=0;
				if(SS=="Yellow")X[i][j]=1;
				if(SS=="Red")X[i][j]=2;
				if(SS=="Magenta")X[i][j]=3;
				if(SS=="Green")X[i][j]=4;
				if(SS=="Blue")X[i][j]=5;
			}
		}
		int cou=0;
		for(int i=0;i<N;i++){
			bool F=true;
			for(int j=i+1;j<N;j++){
				//equal->false
				for(int k=0;k<6;k++){
					for(int l=0;l<4;l++){
						bool FF=false;
						for(int m=0;m<6;m++){
							//if(i==0&&j==1)printf("%d ",X[i][m]);
							if(X[i][m]!=X[j][m])FF=true;
						}
						//if(i==0&&j==1)printf("\n");
						if(!FF)F=false;
						int t=X[i][1];
						X[i][1]=X[i][2];
						X[i][2]=X[i][4];
						X[i][4]=X[i][3];
						X[i][3]=t;
					}
					if(k==0){
						int t=X[i][0];
						X[i][0]=X[i][1];
						X[i][1]=X[i][5];
						X[i][5]=X[i][4];
						X[i][4]=t;
					}
					if(k==1){
						int t=X[i][0];
						X[i][0]=X[i][2];
						X[i][2]=X[i][5];
						X[i][5]=X[i][3];
						X[i][3]=t;
					}
					if(k==2){
						int t=X[i][2];
						X[i][2]=X[i][3];
						X[i][3]=t;
						t=X[i][5];
						X[i][5]=X[i][0];
						X[i][0]=t;
					}
					if(k==3){
						int t=X[i][0];
						X[i][0]=X[i][3];
						X[i][3]=X[i][5];
						X[i][5]=X[i][2];
						X[i][2]=t;
					}
					if(k==4){
						int t=X[i][0];
						X[i][0]=X[i][1];
						X[i][1]=X[i][5];
						X[i][5]=X[i][4];
						X[i][4]=t;
					}
					
				}
			}
			if(F)cou++;
		}
		printf("%d\n",N-cou);
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1256
final_rank: 2

code_snippet: #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){
			switch(axis){
			case 0:
				temp = c[0];
				c[0] = c[1];
				c[1] = c[5];
				c[5] = c[4];
				c[4] = temp;
				break;
			case 1:
				temp = c[1];
				c[1] = c[3];
				c[3] = c[4];
				c[4] = c[2];
				c[2] = temp;
				break;
			case 2:
				temp = c[0];
				c[0] = c[2];
				c[2] = c[5];
				c[5] = c[3];
				c[3] = temp;
				break;
			default:
				OUT "switch error!!!!!!\n" E
				break;
			}
		}
		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 + 1, n){
				bool flag2 = false;
				FOR(z, 0, 4){
				FOR(x, 0, 4){
					FOR(y, 0, 4){
						dice[i].getd(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
						dice[j].getd(str2[0],str2[1],str2[2],str2[3],str2[4],str2[5]);
						
						//printf("\n%s %s %s %s %s %s \n",str1[0].c_str(),str1[1].c_str(),str1[2].c_str(),str1[3].c_str(),str1[4].c_str(),str1[5].c_str());
						//printf("%s %s %s %s %s %s \n\n",str2[0].c_str(),str2[1].c_str(),str2[2].c_str(),str2[3].c_str(),str2[4].c_str(),str2[5].c_str());

						bool flag1 = true;
						FOR(d, 0, 6){					
							if(str1[d] != str2[d]){
								flag1 = false;
							}
						}

						if(flag1){
							if(match[i] == false){							
								flag2 = true;
								//printf("%s %s %s %s %s %s \n",str1[0].c_str(),str1[1].c_str(),str1[2].c_str(),str1[3].c_str(),str1[4].c_str(),str1[5].c_str());
								//printf("%s %s %s %s %s %s \n",str2[0].c_str(),str2[1].c_str(),str2[2].c_str(),str2[3].c_str(),str2[4].c_str(),str2[5].c_str());
							}
							match[j] = true;
						}
						flag1 = true;
					
						dice[i].roll(1);
					}
					dice[i].roll(0);
				}
				dice[i].roll(2);
				}
				//OUT i << " " << j << " " << flag2 E
				if(flag2){
					count++;
					//OUT "count++ " << i << " " << j  E
				}
			}
		}	

		OUT count E

	}
}
accuracy: 1
time_ms: 80
memory_kb: 3156
final_rank: 14

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

struct Dice{
	string me[6];
	
	void Init(string a[6]){
		for (int i = 0; i < 6; i++){
			me[i] = a[i];
		}
	}

	bool check(Dice d2){
		for (int i = 0; i < 6; i++){
			if (d2.me[i] != me[i])return false;
		}
		return true;
	}

	void print(){
		for (int i = 0; i < 6; i++){
			cout << me[i] << " ";
		}
		cout << endl;
	}
};

int n;
string a[6];
Dice d[110];
bool F[100];

int main(){
	while (cin >> n&&n){
		fill(F, F + 100, 1);
		REP(i, n){
			REP(j, 6)cin >> a[j];
			d[i].Init(a);
		}
		bool f = 0;
		REP(k, n){
			if (F[k]){
				FOR(l, k + 1, n){
					REP(i, 4){
						REP(j, 4){
							if (d[k].check(d[l]))F[l] = 0;
							swap(d[k].me[1], d[k].me[2]);
							swap(d[k].me[2], d[k].me[4]);
							swap(d[k].me[4], d[k].me[3]);
						}
						REP(j, 4){
							if (d[k].check(d[l]))F[l] = 0;
							swap(d[k].me[0], d[k].me[1]);
							swap(d[k].me[1], d[k].me[5]);
							swap(d[k].me[5], d[k].me[4]);
						}
						swap(d[k].me[0], d[k].me[2]);
						swap(d[k].me[2], d[k].me[5]);
						swap(d[k].me[5], d[k].me[3]);
					}
				}
			}
		}
		int co = 0;
		REP(i, n)if (F[i])co++;
		cout << n - co << endl;
	}
}
accuracy: 1
time_ms: 30
memory_kb: 1228
final_rank: 4

code_snippet: #include <iostream>
#include <string>
#include <vector>

using namespace std;

class DICE {
public:
	string top;
	string bottom;
	string left;
	string right;
	string front;
	string back;
	void TF();
	void TB();
	void TL();
	void TR();
	void TurnL();
	void TurnR();
	bool HANTEI(DICE d2);
	bool CHECK(DICE d2);
};

void DICE::TF() {
	string kari = front;
	front = top;
	top = back;
	back = bottom;
	bottom = kari;
}

void DICE::TB() {
	TF();
	TF();
	TF();
}

void DICE::TL() {
	string kari = left;
	left = top;
	top = right;
	right = bottom;
	bottom = kari;
}

void DICE::TR() {
	TL();
	TL();
	TL();
}

void DICE::TurnL() {
	string kari = left;
	left = back;
	back = right;
	right = front;
	front = kari;
}

void DICE::TurnR() {
	TurnL();
	TurnL();
	TurnL();
}

bool DICE::HANTEI(DICE d2) {
	if ((top==d2.top)&&(bottom==d2.bottom)&&(left==d2.left)&&(right==d2.right)&&(front==d2.front)&&(back==d2.back)) {
		return true;
	}
	return false;
}

bool DICE::CHECK(DICE d2) {
	DICE d3 = d2;
	for (int i = 0; i < 4; i++) {
		d3.TurnL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TF();
	d3.TF();
	for (int i = 0; i < 4; i++) {
		d3.TurnL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TF();
	for (int i = 0; i < 4; i++) {
		d3.TL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TB();
	for (int i = 0; i < 4; i++) {
		d3.TL();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TL();
	for (int i = 0; i < 4; i++) {
		d3.TF();
		if (HANTEI(d3)) {
			return true;
		}
	}
	d3 = d2;
	d3.TR();
	for (int i = 0; i < 4; i++) {
		d3.TF();
		if (HANTEI(d3)) {
			return true;
		}
	}
	return false;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<DICE> dd;
		for (int i = 0; i < n; i++) {
			DICE d;
			cin >> d.top >> d.front >> d.right >> d.left >> d.back >> d.bottom;
			bool h = true;
			for (int j = 0; j < dd.size(); j++) {
				if (dd[j].CHECK(d)) {
					h = false;
					break;
				}
			}
			if (h) {
				dd.push_back(d);
			}
		}
		int sz = dd.size();
		cout << n-sz << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1240
final_rank: 3