#P7552. [COCI 2020/2021 #6] Anagramistica

[COCI 2020/2021 #6] Anagramistica

Description

Biljana likes making word puzzles.

If one word can be obtained from another word by rearranging its letters, then the two words are called “similar”.

Now, she has nn words. She wants to select some words such that there are exactly kk pairs of “similar” words among them. Please help her compute the number of feasible ways, modulo 109+710^9 + 7.

Input Format

The first line contains two integers nn and kk.

The next nn lines each contain a string, representing a word.

Output Format

Output one integer on a single line, representing the number of feasible ways, modulo 109+710^9 + 7.

3 1
ovo
ono
voo
2
5 2
trava
vatra
vrata
leo
ole
3
6 3
mali
lima
imal
je
sve
ej
6

Hint

Explanation for Sample 1

The selections that contain exactly one pair of “similar” words are ovo, ono, voo and ovo, voo.


Constraints

This problem uses bundled testdata.

Subtask Score Constraints
11 1010 1n151 \le n \le 15
22 3030 0k30 \le k \le 3
33 7070 No additional constraints.

For 100%100\% of the testdata, 1n2×1031 \le n \le 2 \times 10^3, 0k2×1030 \le k \le 2 \times 10^3, the length of each word is at most 1010, and it contains only lowercase letters.


Notes

The score settings of this problem follow the original COCI problem, with full score 110110.

This problem is translated from COCI2020-2021 CONTEST #6 T3 Anagramistica

Translated by ChatGPT 5