Part 1 solution