In the beginning of the third chapter of Hilchot Teshuva (listen to audio for precise citation), the Rambam (Rabbi Moshe Maimonides, Spain-Egypt, 1135-1204) describes the famous notion of the "account" that each person has of Misvot and sins. A person whose Misvot exceed his sins is deemed a Sadik (righteous person), whereas one whose sins outweigh his Misvot has the status of a Rasha (wicked person), Heaven forbid. One whose sins and Misvot are equivalent is considered a Benoni ("middle" person). On Rosh Hashanah, the Rambam writes, every person's merits are weighed against his sins, and if his merits outweigh his sins he is sentenced to life; if his sins exceed his merits, then he is sentenced to death, Heaven forbid. If he is perfectly balanced between merits and sins, then his sentence is suspended until Yom Kippur.
The Rambam adds that this categorization applies to nations, as well: a nation whose merits outweigh their sins is deemed a righteous nation and is sentenced for life, while a nation whose sins exceed its good deeds is considered wicked and sentenced to destruction. Moreover, the Rambam writes, the entirety of mankind is also subject to this judgment. If the world's sins exceed its merits, then it is sentenced to destruction, Heaven forbid.
The Rambam emphasizes in this context that this judgment does not operate according to a strictly quantitative system. Meaning, it is possible for a particularly grievous sin to be deemed equivalent to several Misvot, and, conversely, for a great Misva to equal numerous misdeeds. Only the Almighty Himself can accurately determine the specific "weight" of any given sin or Misva, and thus nobody but God can determine a person's status as a Sadik or a Rasha.
In the third passage of this chapter, the Rambam writes that Misvot can be erased from a person's record if he experiences regret over having performed them. Just as sincere remorse can erase the record of one's sins, so do feelings of regret after performing a Misva have the effect of eliminating one's merit for that Misva. Thus, for example, if a person discovers an expensive parking ticket upon returning to his car after praying in the synagogue, and in response he declares that it would have been preferable not to have come to the synagogue, he receives no "credit" for that Misva. Once he regrets performing the Misva, it is no longer "credited" to his "account."
Some Rabbis have suggested that this notion underlies the otherwise perplexing passage in the evening prayer service, "Ve'haser Satan Mi'lefanenu U'me'aharenu" – literally, "Eliminate the Satan from before us and after us." We beseech God to protect us not only from the "Satan" - meaning, evil inclination – that seeks to prevent us from performing Misvot, but also from the "Satan" that is behind us that tries to cause us to regret our performance of Misvot after the act. Since such regret eliminates the merit from our record, we must ensure to look upon our Misvot with gratification and joy, and never feel regretful for having fulfilled a Misva.