A bakery sells muffins and cookies. Each muffin costs $2 and each cookie costs $1. On a certain day, the bakery earned a total of $50 from selling muffins and cookies. If the number of cookies sold is twice the number of muffins sold, how many muffins were sold?