Two barrels, Y and Z, contain water. Y contains more water than Z. Nigel pours from Y into Z as much water as Z already contains. Then, he pours from Z into Y as much water as Y already contains. Finally, Nigel pours from Y into Z as much water as Z already contains. Both barrels now contain 64 gallons of water. How many gallons of water were in each barrel at the beginning?
Hint: It helps to work backwards to solve this problem.