Problem 9 solution