Solves problem 4.