Problem 9: complete solution.