Solution by Alexander Karelas
