Problem 36 solution