Confusing Usernames

Time limit: 0.2s Memory limit: 16MB Input: Output:

Task

William spends most of his time administering the Italian portal for the IOI training. During his last sleepless night debugging the system, he figured out that several of the usernames used in the website are very similar. This causes a lot of confusion, especially when inspecting users' rankings.

He is then considering to add a new rule to the website: you are not allowed to select a username whose set of letters is a subset of the set of letters of another username. For example, you cannot register the username bob00 if n0ob is already present. In order to evaluate the impact of such a design choice, he now wants to measure how much this rule is violated by the current list of usernames.

More precisely, given a list of NN usernames UiU_i consisting of characters a - z and 0 - 9, he wants to count the number of username pairs (i,j)(i,j) such that letters(Ui)letters(Uj)\textrm{letters}(U_i) \subseteq \textrm{letters}(U_j).

Input data

The first line contains the only integer NN. The subsequent NN lines contain the usernames UiU_i.

Output data

You need to write a single line with an integer: the number of pairs violating the rule.

Constraints and clarifications

  • 1N100001 \le N \le 10\,000.
  • Each username UiU_i is a string of length at most 6060 consisting of characters a - z and 0 - 9.
# Points Constraints
1 5 Examples.
2 35 N100N \le 100 and there are no two usernames with the same set of letters.
3 25 N1000N \le 1000.
4 25 Usernames UiU_i consists only of characters a - b.
5 10 No additional limitations.

Example 1

stdin

3
carole
rollercar
4ndr31

stdout

2

Explanation

In the first sample case, carole and rollercar share the same set of letters, while 4ndr31 is unrelated. Thus the invalid pairs are (1,2)(1,2) and (2,1)(2,1).

Example 2

stdin

4
robin
tyrionboss
bornin2000
toy

stdout

3

Explanation

In the second sample case the invalid pairs are (1,2)(1,2), (1,3)(1,3), (4,2)(4,2).

Log in or sign up to be able to send submissions!