poj problem 1007