Code Jam 2014 Qualification, Problem D