Close #7. Solve POJ 1006