One way could be this.

In R2 and copy down(you can hide this column).

=COUNTIF($O$2:O2,O2)

Then in U2 and copy down, use this ARRAY formula.

=IFERROR(INDEX($O$2:$O$13,SMALL(IF($R$2:$R$13=1,ROW($O$2:$O$13)-1),ROW(O1))),"")