#include<bits/stdc++.h>
using namespace std;
int a[12] = {0,0,0,0,0,0,0,1,1,1,1,1};
int ans,mmap[3][4],flag;
set<string> state;
void dfs(int y,int x){
if(mmap[y][x] == 0) return;
mmap[y][x] = 0;
int newy = y+1;
if(newy>=0&&newy<=2){
dfs(newy,x);
}
int newx = x+1;
if(newx>=0&&newx<=3){
dfs(y,newx);
}
newy = y-1;
if(newy>=0&&newy<=2){
dfs(newy,x);
}
newx = x-1;
if(newx>=0&&newx<=3){
dfs(y,newx);
}
flag = 1;
}
bool check(){
int i,j;
for(i=0;i<3;i++){
for(j=0;j<4;j++){
mmap[i][j] = a[i*4+j];
}
}
int cnt = 0;
for(i=0;i<3;i++){
for(j=0;j<4;j++){
if(mmap[i][j] == 1){
dfs(i,j);
cnt++;
}
}
}
return cnt==1;
}
int main(){
do{
if(check()){
ans++;
}
}while(next_permutation(a,a+12));
printf("%d",ans);
return 0;
}