Latin squares count

Write codeHard30 min

Your task

Count the number of n x n Latin squares: grids filled with values 1..n such that every row and every column contains each value exactly once. Return the count. 1 <= n <= 4 (the count grows extremely fast).

Examples

count_latin_squares(n: int) -> int
Example 1
Inputcount_latin_squares(3)
Output12