Language: C++

#include <cstdio>
#include <set>
using namespace std;

int nextInt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 400;
int col[N][8];
long long hash[N][4];
set<long long> any;
long long dp[16];
int ways[4];

long long calcHash(int a, int b, int c, int d) {
	long long h = 0;
	h = 1000 * h + a;
	h = 1000 * h + b;
	h = 1000 * h + c;
	h = 1000 * h + d;
	return h;
}

int main() {
	int n = nextInt();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			col[i][j] = nextInt();
			col[i][j + 4] = col[i][j];
		}
		for (int rot = 0; rot < 4; rot++) {
			for (int j = 0; j < 4; j++) {
				hash[i][rot] = 1000 * hash[i][rot] + col[i][(rot + j) % 4];
			}
			any.insert(hash[i][rot]);
		}
	}
	long long ans = 0;
	for (int front = 0; front < n; front++) {
		int a = col[front][0];
		int b = col[front][1];
		int c = col[front][2];
		int d = col[front][3];
		for (int back = front + 1; back < n; back++) {
			rotLoop:
			for (int rotBack = 0; rotBack < 4; rotBack++) {
				int f = col[back][(rotBack + 0)];
				int e = col[back][(rotBack + 1)];
				int h = col[back][(rotBack + 2)];
				int g = col[back][(rotBack + 3)];
				long long h1 = calcHash(a, e, f, b);
				long long h2 = calcHash(b, f, g, c);
				long long h3 = calcHash(d, c, g, h);
				long long h4 = calcHash(e, a, d, h);
				vector<long long> hs = {h1, h2, h3, h4};
				bool can = true;
				for (int i = 0; i < 4; i++) {
					if (any.count(s) == 0) {
						can = false;
					}
				}
				if (!can) {
					continue;
				}
				for (int i = 0; i < 16; i++) {
					dp[i] = 0;
				}
				dp[0] = 1;
				for (int i = front + 1; i < n; i++) {
					if (i == back) {
						continue;
					}
					for (int j = 0; j < 4; j++) {
						ways[j] = 0;
					}
					for (int bit = 0; bit < 4; bit++) {
						for (int rot = 0; rot < 4; rot++) {
							if (hash[i][rot] == hs[bit]) {
								++ways[bit];
							}
						}
					}
					for (int mask = 15; mask >= 0; mask--) {
						if (dp[mask] == 0) {
							continue;
						}
						for (int bit = 0; bit < 4; bit++) {
							if ((mask & (1 << bit)) != 0) {
								continue;
							}
							dp[mask | (1 << bit)] += dp[mask] * ways[bit];
						}
					}
				}
				ans += dp[15];
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:33: error: 'vector' was not declared in this scope
   58 |                                 vector<long long> hs = {h1, h2, h3, h4};
      |                                 ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <set>
  +++ |+#include <vector>
    3 | using namespace std;
a.cc:58:40: error: expected primary-expression before 'long'
   58 |                                 vector<long long> hs = {h1, h2, h3, h4};
      |                                        ^~~~
a.cc:61:55: error: 's' was not declared in this scope
   61 |                                         if (any.count(s) == 0) {
      |                                                       ^
a.cc:81:77: error: 'hs' was not declared in this scope; did you mean 'h4'?
   81 |                                                         if (hash[i][rot] == hs[bit]) {
      |                                                                             ^~
      |                                                                             h4