A solution to POJ 2148