Solves problem 18