A solution to POJ 3367