Justin had cupcakes and Carl had croissants. Both gave half of what they had to each other. Justin sold 12 cupcakes and Carl sold 30 croissants. In the end, the ratios of cupcakes to croissants for Justin and Carl were 1 : 7 and 1 : 5 respectively. How many cupcakes did Justin have at first?