Spoj problem solutions in python