A generalization of Lie's “counting” theorem for second-order ordinary differential equations