Here a possibility
Assuming data from A1 to B7 with header as shown
D2 to D5 like next
<TABLE style="WIDTH: 48pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=64 border=0 x:str><COLGROUP><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; WIDTH: 48pt; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=64 height=17>A</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>A</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>B</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>B</TD></TR></TBODY></TABLE>
E2 =LARGE((A$2:A$7=D2)*(B$2:B$7),1)
E3 =LARGE((B$2:B$7)*(A$2:A$7=D3),2)
E4 =LARGE((B$2:B$7)*(A$2:A$7=D4),1)
E5 =LARGE((B$2:B$7)*(A$2:A$7=D5),2)
F2 =SMALL(IF((A$2:A$7=D2)*(B$2:B$7)<>0,(A$2:A$7=D2)*(B$2:B$7),""),1)
F3 =SMALL(IF((A$2:A$7=D3)*(B$2:B$7)<>0,(A$2:A$7=D3)*(B$2:B$7),""),2)
F4 =SMALL(IF((A$2:A$7=D4)*(B$2:B$7)<>0,(A$2:A$7=D4)*(B$2:B$7),""),1)
F5 =SMALL(IF((A$2:A$7=D5)*(B$2:B$7)<>0,(A$2:A$7=D5)*(B$2:B$7),""),2)
All formulas to be confirmed with CONTROL + SHIFT + ENTER as area formula
²