Solution for problem 4.