POJ problem 1007