google code jam14 magic problem