Solve problem 31