  We perform a Hamiltonian analysis of a large class of scalar-tensor
Lagrangians which depend quadratically on the second derivatives of a scalar
field. By resorting to a convenient choice of dynamical variables, we show that
the Hamiltonian can be written in a very simple form, where the Hamiltonian and
the momentum constraints are easily identified. In the case of degenerate
Lagrangians, which include the Horndeski and beyond Horndeski quartic
Lagrangians, our analysis confirms that the dimension of the physical phase
space is reduced by the primary and secondary constraints due to the
degeneracy, thus leading to the elimination of the dangerous Ostrogradski
ghost. We also present the Hamiltonian formulation for nondegenerate theories
and find that they contain four degrees of freedom, as expected. We finally
discuss the status of the unitary gauge from the Hamiltonian perspective.
