Close #5. Solve POJ 1004