Gary, Mary, and Rory have the same number of candies. If Gary gives Mary half of all his candies, then Mary gives Rory half of all the candies she has at the moment, and then Rory gives Gary half of all the candies he (Rory) has at the moment, Gary would have 12 more candies than he had originally. How many candies do Gary, Mary, and Rory have altogether