solve problem 9, finally