Problem list
Log in
#coci00557 · COCI 2019/2020 Contest 6

Trener

Platinum V 1.0 s 256 MB

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 $N$ players that will defend the blue colors in the next season, but the board has some peculiar requests. They are:

  • 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 in $N$ buckets such that players in $i$-th bucket have exactly $i$ letters in their surname. In each of these buckets there are exactly $K$ players. Patrik wants to know in how many distinct ways (modulo $10^{9} + 7$) can he choose the players for his squad while also conforming to the given requests.

Input

The first line contains two integers $N$ ($1 \le N \le 50$) and $K$ ($1 \le K \le 1,500$). Each of the next $N$ lines contains $K$ not necessarily distinct surnames of players. The surnames of players in $i$-th of those lines consist of exactly $i$ lowercase letters from the English alphabet.

Output

In the only line you should output the answer from the task description. Bodovanje Subtask Score Constraints 1 22 $N = 5$ and $K = 10$ 2 33 $N = 50$ and $K = 100$ 3 55 No additional constraints.

Example 1

Input
3 2
a b
ab bd
abc abd
Output
5

Example 2

Input
3 3
a b c
aa ab ac
aaa aab aca
Output
6

Example 3

Input
3 1
a
bc
def
Output
0

Clarification of the first example: Patrik can choose the following teams: (a, ab, abc), (a, ab, abd), (b, ab, abc), (b, ab, abd) and (b, bd, abd).

Source
COCI 2019/2020 Contest 6
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code