Solution to third problem.