Problem 6 solution.