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.