Code Jam contest python implementation