Code Jam 2014 problem 5