<s>[INST] how many $3\times 3$ matrices with entries from $\{0,1,2\}$. 
How many $3 × 3$ matrices $M$ with entries from $\left\{0, 1, 2\right\}$ are there for which taken from 
the sum of the main diagonal of $M^TM$ is $5$.

Attempt: Let $M = \begin{pmatrix}
a & b & c\\ 
d & e & f\\ 
g & h & i
\end{pmatrix}$. where  $a,b,c,d,e,f,g,h,i\in \{0,1,2\}$
$$M^{T}M= \begin{pmatrix}
a & d & g\\ 
b & e & h\\ 
c & f & i
\end{pmatrix}\begin{pmatrix}
a & b & c\\ 
d & e & f\\ 
g & h & i
\end{pmatrix} $$.
sum of diagonal entries $$a^2+b^2+c^2+d^2+e^2+f^2+g^2+h^2+i^2 = 5$$
How can I form different cases?
 [/INST] The numbers $a^2$ etc. are either $0$, $1$or $4$. To get them adding to $5$ you need five $1$s, or a $4$ and a $1$ and all the rest $0$s.
</s>