Stefan Iliev's task without sorting