Solution (source code)

= Solution

The relations
$$
M^2=I,\qquad R^n=I,\qquad MRM=R^{-1}
$$
imply $RM=MR^{-1}$. Moving every occurrence of $M$ to the left and reducing exponents therefore puts every word into one of the normal forms
$$
R^j\quad\text{or}\quad MR^j,
\qquad 0\leq j<n.
$$
Explicitly, with $\theta=2\pi/n$,
$$
R^j=
\begin{pmatrix}
\cos(j\theta)&-\sin(j\theta)\\
\sin(j\theta)&\cos(j\theta)
\end{pmatrix},
$$
and
$$
MR^j=
\begin{pmatrix}
\cos(j\theta)&-\sin(j\theta)\\
-\sin(j\theta)&-\cos(j\theta)
\end{pmatrix}.
$$
The $n$ rotations are distinct. The $n$ reflected matrices are also distinct, and no reflected matrix equals a rotation because their determinants are $-1$ and $1$, respectively. Hence there are exactly
$$
\boxed{2n}
$$
matrices, forming the <dihedral group>.