Solution (source code)

= Solution

Here $A^{3n+1}=A$, so its <inverse matrix> is
$$
\boxed{(A^{3n+1})^{-1}=A^2.}
$$