The standard two pair formula is ${13\choose2}{11\choose1}{4\choose2}{4\choose2}{4\choose1}$ but this assumes that in the poker hand AABBC the rank of AA, BB and C cannot be the same (to avoid for conflicts with 4oak and full house).
I am trying to derive a formula which counts two pair combinations where the rank of AA can be equal to BB or the rank of AA/BB can be equal to C. For Example I'd like to count the poker hand 22223 as a two pair (two pairs of 2s) or the hand 22333 (a pair of 2s and a pair of 3s).
I had the idea to use the combinations w/ repetitions function for ${13\choose2}$ which I think properly accounts for the rank of AA to be equal to BB, but I'm pretty sure the final result of 144144 is still wrong because subtracting the number of 4oak/full house combinations doesn't result in 123552.
Thank you for your time reading this and any potential help.