Ice cream parlour - sorting problem