#include<stdio.h>
#include<algorithm>
#define N 6
using namespace std;
int c[N][N];
int solve(int a,int b){
if(a==N){
int ret=1;
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
for(int k=0;k<N;k++)
for(int l=0;l<N;l++)
if(c[c[i][j]][c[k][l]]!=c[i][l])return 0;
return 1;
}
if(b==N)return solve(a+1,0);
if(a==b)return solve(a,b+1);
int ret=0;
for(int i=0;i<N;i++){
bool ok=true;
for(int j=0;j<N;j++){
if(!ok)break;
for(int k=0;k<N;k++){
if(~c[j][k]&&~c[i][c[j][k]]&&~c[a][k]&&c[a][k]!=c[i][c[j][k]]){ok=false;break;}
if(~c[j][k]&&~c[c[j][k]][i]&&~c[j][b]&&c[j][b]!=c[c[j][k]][i]){ok=false;break;}
if(~c[a][j]&&~c[k][b]&&~c[c[a][j]][c[k][b]]&&i!=c[c[a][j]][c[k][b]]){ok=false;break;}
}
}
if(ok){
c[a][b]=i;
ret+=solve(a,b+1);
c[a][b]=-1;
}
}
return ret;
}
int main(){
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
c[i][j]=-1;
for(int i=0;i<N;i++)c[i][i]=i;
printf("%d\n",solve(0,0));
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8YWxnb3JpdGhtPgojZGVmaW5lIE4gNgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IGNbTl1bTl07CmludCBzb2x2ZShpbnQgYSxpbnQgYil7CglpZihhPT1OKXsKCQlpbnQgcmV0PTE7CgkJZm9yKGludCBpPTA7aTxOO2krKykKCQkJZm9yKGludCBqPTA7ajxOO2orKykKCQkJCWZvcihpbnQgaz0wO2s8TjtrKyspCgkJCQkJZm9yKGludCBsPTA7bDxOO2wrKykKCQkJCQkJaWYoY1tjW2ldW2pdXVtjW2tdW2xdXSE9Y1tpXVtsXSlyZXR1cm4gMDsKCQlyZXR1cm4gMTsKCX0KCWlmKGI9PU4pcmV0dXJuIHNvbHZlKGErMSwwKTsKCWlmKGE9P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