At this point, we already know that students love to sleep. Patrik is a record holder in this category. He wakes up only when he needs to eat or if he wishes to play FIFA 20. Therefore, his dreams usually revolve around football. In his last dream, he found himself in the role of a football manager of his favourite team – GNK Dinamo Zagreb.
His job is to select
- All players must have surnames of distinct lengths.
- Surname of a player must appear as a continuous subsequence of surnames of all players whose surnames are longer.
To make his job easier, Patrik divided the potential players into
Input
The first line contains two integers
Each of the next
Output
In the only line, you should output the answer from the task description.
Scoring
Subtask | Score | Constraints |
---|---|---|
No additional constraints. |
Sample Input 1
3 2
a b
ab bd
abc abd
Sample Output 1
5
Explanation of Sample Output 1
Patrik can choose the following teams:
Sample Input 2
3 3
a b c
aa ab ac
aaa aab aca
Sample Output 2
6
Sample Input 3
3 1
a
bc
def
Sample Output 3
0
Comments