Improve HDU 2078 solution