SPOJ problems' solutions in Python