# 9663번 N-Queen
import sys
N = int(sys.stdin.readline())
data = [[0]*N for _ in range(N)]
count = 0
check_col = [0]*N
check_diag = [0]*(2*N-1)
check_diag2 = [0]*(2*N-1)
def check(row, col):
if check_col[col] == 1:
return False
elif check_diag[row+col]==1:
return False
elif check_diag2[row-col + (N-1)] == 1:
return False
else:
return True
def dfs(row):
global count
if row == N:
count += 1
return
for j in range(N):
if check(row, j):
data[row][j] = check_col[j] = check_diag[row+j] = check_diag2[row-j+(N-1)] = 1
dfs(row+1)
data[row][j] = check_col[j] = check_diag[row + j] = check_diag2[row - j + (N - 1)] = 0
dfs(0)
print(count)