Problem

Source: Estonia IMO TST 2017 p7

Tags: combinatorics, square table, table



Let $n$ be a positive integer. In how many ways can an $n \times n$ table be filled with integers from $0$ to $5$ such that a) the sum of each row is divisible by $2$ and the sum of each column is divisible by $3$ b) the sum of each row is divisible by $2$, the sum of each column is divisible by $3$ and the sum of each of the two diagonals is divisible by $6$?