Spoj solutions in Python