she was a rescue cat from a overcrowded house
This may be one of the reasons Mary isn't litter-trained. Did she come from a hoarder's house? (Where the people had lots of uncared for, unneutered, cats). If so, they probably didn't take the time to teach her, or her mother cat didn't have a litter tray, or the space, to teach her kittens not to soil the nest.
This means that you're starting at the very beginning of her toilet training. You'd be better off having advice from Purrs peeps who are experienced with kittens and have watched the mother cat train them.
But mainly, you need to gently communicate that carpets are not for soiling. DON'T HIT HER OR FRIGHTEN HER. Try to do this with gentle encouragement to use the tray. Praise her in a soft voice when she does use it.
There are some cat-safe nasty-smelling sprays which you can buy. But
check that these are safe for CATS. Things safe for babies and dogs aren't always safe for cats. Apply this to the areas you don't want her to use as a toilet. Other Purrs members may be able to give you the name of a product.
Be careful what you use to clean those areas where she makes mistakes. The best thing to use is biological washing powder. This will get rid of the smell and help to avoid her re-using that place.
Good luck.