#include <iostream>
using namespace std;
int board[4][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{-1, 0, -1}
};
int dir[8][2] = {
{-2, -1}, {-2, 1},
{-1, -2}, {-1, 2},
{1, -2}, {1, 2},
{2, -1}, {2, 1}
};
int sum = 0;
void dfs(int now, int row, int col, int length){
if(length == 7)
{
sum++;
return;
}
for(int i = 0; i <8; i++){
int nr = dir[i][0] + row;
int nc = dir[i][1] + col;
if(nr < 0 || nr >=4 || nc < 0 || nc >= 3) continue;
if(board[nr][nc] == -1) continue;
dfs(now * 10 + board[nr][nc], nr, nc, length + 1);
}
}
int main(){
for(int i = 0; i < 4; i++)
for(int j = 0; j < 3; j++) if(board[i][j] != -1 && board[i][j] != 1 && board[i][j] != 0)
dfs(board[i][j], i, j, 1);
cout << sum << endl;
}
using namespace std;
int board[4][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{-1, 0, -1}
};
int dir[8][2] = {
{-2, -1}, {-2, 1},
{-1, -2}, {-1, 2},
{1, -2}, {1, 2},
{2, -1}, {2, 1}
};
int sum = 0;
void dfs(int now, int row, int col, int length){
if(length == 7)
{
sum++;
return;
}
for(int i = 0; i <8; i++){
int nr = dir[i][0] + row;
int nc = dir[i][1] + col;
if(nr < 0 || nr >=4 || nc < 0 || nc >= 3) continue;
if(board[nr][nc] == -1) continue;
dfs(now * 10 + board[nr][nc], nr, nc, length + 1);
}
}
int main(){
for(int i = 0; i < 4; i++)
for(int j = 0; j < 3; j++) if(board[i][j] != -1 && board[i][j] != 1 && board[i][j] != 0)
dfs(board[i][j], i, j, 1);
cout << sum << endl;
}