My attempt from Code Jam 2010