  In this paper, we prove Dahmen and Beukers' conjecture that the number of
integral Lam\'{e} equations with index $n$ modulo scalar equivalence with the
monodromy group dihedral $D_{N}$ of order $2N$ is given by
\[L_{n}(N)=\frac{1}{2}\left( \frac{n(n+1)\Psi(N)}{24}-\left( a_{n}%
\phi(N)+b_{n}\phi(\tfrac{N}{2}) \right) \right) +\frac{2}%
{3}\varepsilon_{n}(N).\] Our main tool is the new pre-modular form
$Z_{r,s}^{(n)}(\tau)$ of weight $n(n+1)/2$ introduced by Lin and Wang
\cite{LW2} and the associated modular form
$M_{n,N}(\tau):=\prod_{(r,s)}Z_{r,s}^{(n)}(\tau)$ of weight
$\Psi(N)n(n+1)/{2}$, where the product runs over all $N$-torsion points $(r,s)$
of exact order $N$. We show that this conjecture is equivalent to the precise
formula of the vanishing order of $M_{n,N}(\tau)$ at infinity:
\[v_{\infty}(M_{n,N}(\tau))=a_{n}\phi(N)+b_{n}\phi( N/2).\] This formula is
extremely hard to prove because the explicit expression of
$Z_{r,s}^{(n)}(\tau)$ is not known for general $n$. Here we succeed to prove it
by using certain Painlev\'{e} VI equations. Our result also indicates that this
conjecture is intimately connected with the problem of counting pole numbers of
algebraic solutions of certain Painlev\'{e} VI equations. The main results of
this paper has been announced in \cite{Lin-CDM}.
