Solution for Spartez "Common ancestor" task.