Improve first Python solution