Artificial intelligent assistant

Permutation question: Pick out 2 items from 4 items which 2 duplicated, is there any formula? If given ABBC, find the permutations if 2 letters are picked. If I calculate manually, they are: AB, AC, BA, BB, BC, CA, CB, 7 permutations. Is there any formula to solve this type of question? (Meaning, picking _r_ number of letters from _n_ number of letters with duplicated letters)

Suppose you had $n$ unique letters ${X_k}$, and letter $X_k$ were present in $r_k$ copies.

Then the number of unique pairs of letters, can be computed as $n (n-1) + \sum_{k} \mathrm{sgn} (r_k-1)$.

The term $n(n-1)$ count the number of pairs where letters are distinct, and remaining sum counts same letter pairs.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 33c2fb3dbffa2849f12a2490f5ac3ba9