solve problem 39