solution to POJ