My solution to Google Code Jam