LEMMA: Learning from Errors for MatheMatical Advancement in LLMs