It also timed out:( 241056 2005-09-09 20:11:19 ZZZ time limit exceeded - 7064 PYTH Btw, have a look at this nicest problem: http://spoj.sphere.pl/problems/COINS/ My py solution takes #64 place among its best solutions: http://spoj.sphere.pl/ranks/COINS/start=60