Solution by Sergio Iglesias.
