A solution to POJ 1984