Solution to second problem.