Good string pairs - MarisaOJ: Marisa Online Judge

Good string pairs

Time limit: 1000 ms
Memory limit: 256 MB
A pair of strings is considered good if they have at least one common letter. For example, the pair abc and adc is good because they share the letters a and c. Conversely, the pair bc and def is not good because they have no common letters. Given $n$ strings, count the number of good string pairs. ### Input - The first line contains an integer $n$. - The next $n$ lines each contain a string. ### Output - Print the number of good string pairs. ### Constraints - $1 \le n \le 10^5$. - The strings consist of the first 15 letters of the alphabet and have a length of at most 10 characters. ### Example Input: ``` 4 abc def afg ed ``` Output: ``` 3 ```