Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define f first
#define s second
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%I64d",&x)
#define CLR(x)  memset(x,0,sizeof(x))
#define RESET(x,a) memset(x,a,sizeof(x))
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]

const int N=405;
int a[N][4]; //tile
ll val[N];   //hash of tile
int p[4];
int sym[4];
ll g[4];
ll ans[16];
int n;

inline ll h(int p[4],int k)
{
    ll res=0LL;
    for(int i=k;i<4;i++)
        res = res<<10LL | (ll)p[i];
    for(int i=0;i<k;i++)
        res = res<<10LL | (ll)p[i];
    return res;
}

ll normalise(int p[4])
{
    return min(h(p,0),min(h(p,1),min(h(p,2),h(p,3))));
}

ll way(int x, int y, int r)
{
    int i,j,k,b[4];
    for(i=0;i<4;i++)
        b[i]=a[y][ (i+r)%4 ];
    ll e,f,c,d;
    sym[0]=sym[1]=sym[2]=sym[3]=1;
    p[0]=b[1];   p[1]=b[0];
    p[2]=a[x][1];   p[3]=a[x][0];
    e=h(p,0); f=h(p,1); c=h(p,2); d=h(p,3);
    if(e==f)sym[0]=4;
    else if(e==c)sym[0]=2;
    g[0]=min(e,min(f,min(c,d)));

    p[0]=b[0];   p[1]=b[3];
    p[2]=a[x][2];   p[3]=a[x][1];
    e=h(p,0); f=h(p,1); c=h(p,2); d=h(p,3);
    if(e==f)sym[1]=4;
    else if(e==c)sym[1]=2;
    g[1]=min(e,min(f,min(c,d)));

    p[0]=b[2];   p[1]=b[1];
    p[2]=a[x][0];   p[3]=a[x][3];
    e=h(p,0); f=h(p,1); c=h(p,2); d=h(p,3);
    if(e==f)sym[2]=4;
    else if(e==c)sym[2]=2;
    g[2]=min(e,min(f,min(c,d)));

    p[0]=b[3];   p[1]=b[2];
    p[2]=a[x][3];   p[3]=a[x][2];
    e=h(p,0); f=h(p,1); c=h(p,2); d=h(p,3);
    if(e==f)sym[3]=4;
    else if(e==c)sym[3]=2;
    g[3]=min(e,min(f,min(c,d)));

    CLR(ans);
    ans[0]=1;
    for(i=x+1;i<n;i++)
    {
        if(i==y)continue;
        F(14,0); F(14,1); F(14,2); F(14,3);
        F(13,0); F(13,1); F(13,2); F(13,3);
        F(12,0); F(12,1); F(12,2); F(12,3);
        F(11,0); F(11,1); F(11,2); F(11,3);
        F(10,0); F(10,1); F(10,2); F(10,3);
        F(9,0); F(9,1); F(9,2); F(9,3);
        F(8,0); F(8,1); F(8,2); F(8,3);
        F(7,0); F(7,1); F(7,2); F(7,3);
        F(6,0); F(6,1); F(6,2); F(6,3);
        F(5,0); F(5,1); F(5,2); F(5,3);
        F(4,0); F(4,1); F(4,2); F(4,3);
        F(3,0); F(3,1); F(3,2); F(3,3);
        F(2,0); F(2,1); F(2,2); F(2,3);
        F(1,0); F(1,1); F(1,2); F(1,3);
        F(0,0); F(0,1); F(0,2); F(0,3);
//        for(j=14;j>=0;j--)
//        {
//            for(k=0;k<4;k++)
//            {
//                if(j&(1<<k))continue;
//                if(val[i]==g[k])
//                    ans[j|(1<<k)] += sym[k]*ans[j];
//            }
//        }
    }
    return ans[15];
}

int main()
{
    int i,j,k;
    si(n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<4;j++)
            si(a[i][j]);
        val[i] = normalise(a[i]);
    }
    ll ans=0LL;
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
            for(k=0;k<4;k++)
                ans+=way(i,j,k);
    printf("%lld\n",ans);
    return 0;
}


Compiler output:
a.cc: In function 'long long int way(int, int, int)':
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:81:9: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |         ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:81:9: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |         ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:81:9: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |         ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:81:18: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                  ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:81:18: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                  ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:81:18: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                  ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:81:27: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                           ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:81:27: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                           ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:81:27: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                           ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:81:36: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                                    ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:81:36: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                                    ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:81:36: note: in expansion of macro 'F'
   81 |         F(14,0); F(14,1); F(14,2); F(14,3);
      |                                    ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:82:9: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |         ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:82:9: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |         ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:82:9: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |         ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:82:18: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                  ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:82:18: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                  ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:82:18: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                  ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:82:27: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                           ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:82:27: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                           ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:82:27: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                           ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:82:36: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                                    ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:82:36: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                                    ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:82:36: note: in expansion of macro 'F'
   82 |         F(13,0); F(13,1); F(13,2); F(13,3);
      |                                    ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:83:9: note: in expansion of macro 'F'
   83 |         F(12,0); F(12,1); F(12,2); F(12,3);
      |         ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:83:9: note: in expansion of macro 'F'
   83 |         F(12,0); F(12,1); F(12,2); F(12,3);
      |         ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                                  ^~
a.cc:83:9: note: in expansion of macro 'F'
   83 |         F(12,0); F(12,1); F(12,2); F(12,3);
      |         ^
a.cc:15:43: error: invalid types 'long long int[int]' for array subscript
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                           ^
a.cc:83:18: note: in expansion of macro 'F'
   83 |         F(12,0); F(12,1); F(12,2); F(12,3);
      |                  ^
a.cc:15:52: error: 'dp' was not declared in this scope; did you mean 'd'?
   15 | #define F(j,k) if ( !((j>>k)&1) && b[i]==c[k][0] ) dp[j|(1<<k)]+=rc[k]*dp[j]
      |                                                    ^~
a.cc:83:18: note: in expansion of macro 'F'
   83 |         F(12,0); F(12,1); F(12,2); F(12,3);
      |                  ^
a.cc:15:66: error: 'rc' was not declared in this scope; did you mean 'c'?
   15 | #define F(j,k) if ( !((j>>k)&1)