Hide

Problem C
Company Naming

/problems/companynaming/file/statement/en/img-0001.jpg
Source: PixaBay

You are being asked to find a new name for a company. Management wants the new name to sound similar to a list of name ideas (which represent names of their more established competitors in the space), but for trademark reasons, they must be varied so that none of their parts are identical to the original ideas.

Specifically, you are given a list of unique candidate words. Two of these candidate words can form a valid company name if, after swapping their first letters, both newly formed words are not present in the original list. Each valid ordered pair contributes exactly one name.

Input

The input consists of two lines: The first line contains an integer $n$ ($2 \le n \le 50\, 000$) – the number of candidate words. The second line contains exactly $n$ space-separated strings $s$ consisting of between $1$ and $10$ lowercase English letters. All strings are unique.

Output

Output a single integer – the number of distinct valid company names.

Sample Input 1 Sample Output 1
4
coffee donuts time toffee
6
Sample Input 2 Sample Output 2
2
lack rack
0

Please log in to submit a solution to this problem

Log in