Solution by Florian Wirth