A solution to POJ 2242