Problem 2: complete solution.