Efficient Methods For Congruency-Constrained Optimization