The classification of Lagrangian and Legendrian singularities