well this isnt’ a complete answer, but this will get you partially, there, cut all the data from columnb and append it to the end of column A so that all your data is in a single column.
then sort the data so same values will be in corresponding rows.
in column c1, put a “1”
in column C2 put =if (A2=A1;=c1+1;1)
(I might have the syntax wrong, but bascially you are keeping a running count of the number of times a number repeats.)
copy C2 to all the other column c cells for each value in in column A.
at his point, you now have a column that has the max count for each value in columnA as a max value in column C
now if you copy the VALUES of column A and C to D and F, and reverse sort Dand F on column D, the first occurance of any value in column d will have number of occurances of that value in its column c.
make a column G that is only the occurances of the first line:
hard code G1,
starting on G2 =if(g1=G2;"";F2) for all the remaining cells in column G