* Port solution to PHP.
* Minor edit.
* Port solution to Python.