poj problem 1504