Solve problem 40