Problem 012 solution.