Language: C++

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T,typename U, typename H=hash<T> >
using gmap = cc_hash_table<T, U, H>;

//INSERT ABOVE HERE
const int MAX = 404;
int cs[4][MAX];

using A = array<int, 8>;
A rotH(A x){
  A y;
  y[0]=x[1];
  y[1]=x[2];
  y[2]=x[3];
  y[3]=x[0];

  y[7]=x[6];
  y[6]=x[5];
  y[5]=x[4];
  y[4]=x[7];
  return y;
}

A rotN(A x){
  A y;
  y[0]=x[3];
  y[3]=x[4];
  y[4]=x[7];
  y[7]=x[0];

  y[1]=x[2];
  y[2]=x[5];
  y[5]=x[6];
  y[6]=x[1];
  return y;
}

using ll = long long;
ll make_hash(ll a,ll b,ll c,ll d){
  return (a<<30)|(b<<20)|(c<<10)|d;
}

using P = pair<ll, ll>;
P make_hash(A x){
  return P(make_hash(x[0],x[1],x[2],x[3]),
           make_hash(x[4],x[5],x[6],x[7]));
}

gmap<ll, int> cnt,idx;
ll hs[4][MAX]={};

void inc(ll v){
  int k=idx[v];
  cnt[hs[0][k]]++;
  cnt[hs[1][k]]++;
  cnt[hs[2][k]]++;
  cnt[hs[3][k]]++;
}

void dec(ll v){
  int k=idx[v];
  cnt[hs[0][k]]--;
  cnt[hs[1][k]]--;
  cnt[hs[2][k]]--;
  cnt[hs[3][k]]--;
}

__int128_t check(A x){
  ll a=make_hash(x[0],x[1],x[2],x[3]);
  ll b=make_hash(x[4],x[5],x[6],x[7]);

  ll c=make_hash(x[3],x[2],x[5],x[4]);
  ll d=make_hash(x[2],x[1],x[6],x[5]);
  ll e=make_hash(x[1],x[0],x[7],x[6]);
  ll f=make_hash(x[0],x[3],x[4],x[7]);

  if(!cnt.count(a)) return 0;
  if(!cnt.count(b)) return 0;
  if(!cnt.count(c)) return 0;
  if(!cnt.count(d)) return 0;
  if(!cnt.count(e)) return 0;
  if(!cnt.count(f)) return 0;

  __int128_t res=1;
  res*=cnt[a];dec(a);
  res*=cnt[b];dec(b);
  res*=cnt[c];dec(c);
  res*=cnt[d];dec(d);
  res*=cnt[e];dec(e);
  res*=cnt[f];dec(f);

  inc(a);
  inc(b);
  inc(c);
  inc(d);
  inc(e);
  inc(f);

  return res;
}

signed main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>cs[0][i]>>cs[1][i]>>cs[2][i]>>cs[3][i];
    for(int z=0;z<4;z++){
      hs[z][i]=make_hash(cs[(z+0)%4][i],
                         cs[(z+1)%4][i],
                         cs[(z+2)%4][i],
                         cs[(z+3)%4][i]);
      cnt[hs[z][i]]++;
      idx[hs[z][i]]=i;
    }
  }

  ll ans=0;
  set<P> used;

  vector<A> vs;
  {
    A w;
    set<A> rs;
    for(int i=0;i<8;i++) w[i]=i;
    for(int p=0;p<4;p++){
      for(int q=0;q<4;q++){
        for(int r=0;r<4;r++){
          rs.emplace(w);
          w=rotH(w);
        }
        w=rotN(w);
      }
      w=rotH(w);
    }
    vs=vector<A>(rs.begin(),rs.end());
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      for(int z=0;z<4;z++){
        A x;
        for(int k=0;k<4;k++){
          x[k+0]=cs[(k+z)%4][i];
          x[k+4]=cs[k][j];
        }

        int way=0;
        A w(x);
        for(auto v:vs){
          A y;
          for(int k=0;k<8;k++) y[k]=x[v[k]];
          if(x==y) way++;
          chmin(w,y);
        }

        if(used.count(make_hash(w))) continue;
        used.emplace(make_hash(w));

        ans+=check(x)/way;
      }
    }
  }

  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function '__int128 check(A)':
a.cc:85:11: error: 'gmap<long long int, int>' {aka 'class __gnu_pbds::cc_hash_table<long long int, int, std::hash<long long int>, std::equal_to<long long int>, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>, false, std::allocator<char> >'} has no member named 'count'
   85 |   if(!cnt.count(a)) return 0;
      |           ^~~~~
a.cc:86:11: error: 'gmap<long long int, int>' {aka 'class __gnu_pbds::cc_hash_table<long long int, int, std::hash<long long int>, std::equal_to<long long int>, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>, false, std::allocator<char> >'} has no member named 'count'
   86 |   if(!cnt.count(b)) return 0;
      |           ^~~~~
a.cc:87:11: error: 'gmap<long long int, int>' {aka 'class __gnu_pbds::cc_hash_table<long long int, int, std::hash<long long int>, std::equal_to<long long int>, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>, false, std::allocator<char> >'} has no member named 'count'
   87 |   if(!cnt.count(c)) return 0;
      |           ^~~~~
a.cc:88:11: error: 'gmap<long long int, int>' {aka 'class __gnu_pbds::cc_hash_table<long long int, int, std::hash<long long int>, std::equal_to<long long int>, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>, false, std::allocator<char> >'} has no member named 'count'
   88 |   if(!cnt.count(d)) return 0;
      |           ^~~~~
a.cc:89:11: error: 'gmap<long long int, int>' {aka 'class __gnu_pbds::cc_hash_table<long long int, int, std::hash<long long int>, std::equal_to<long long int>, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>, false, std::allocator<char> >'} has no member named 'count'
   89 |   if(!cnt.count(e)) return 0;
      |           ^~~~~
a.cc:90:11: error: 'gmap<long long int, int>' {aka 'class __gnu_pbds::cc_hash_table<long long int, int, std::hash<long long int>, std::equal_to<long long int>, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>, false, std::allocator<char> >'} has no member named 'count'
   90 |   if(!cnt.count(f)) return 0;
      |           ^~~~~