solve problem 40