Ambiguities in the Lagrangian and Hamiltonian formalism: Transformation properties