range1-> 1 2 3 1 2 3
range2-> a c a a b a

How do I count duplicates within an array formula?

Say I generated an array formula range2= "a"*range1 I would get an array
{1,0,3,1,0,3}

How do I write the formula to search within that array to count the number of entries that appear exactly twice and how high it is. (3 for the example above. Second highest is 1).