A speed-optimized solution for 1081.