Problem 005 solution.