Code jam problem: https://codingcompetitions.withgoogle.com/codejam/round/0000000000876ff1/0000000000a4672b