Solution to POJ 2656