Solutions to SPOJ problems in Python