John was in charge of buying milk for a class of 32 students. Milk is sold in half-gallon cartons and gallon cartons at the market. The half gallon costs 1.46 and the gallon costs 2.39. John bought all 21 cartons of milk the store had and paid 41.82. How many cartons of each size did he buy?