This page is still under construction.

Parts of this page are still being built. What you see may change.

Anagramistica

Time limit1sMemory limit512 MB

Summary
Given n distinct words, count subsets that contain exactly k pairs of anagrams, modulo 10^9+7.
Level

Medium7 of 10

Topics
Combinatorics, Dynamic programming, Hash map, Math
Solved
No attempts yet

Problem

Biljana loves making crosswords. Her favourite type is the so called anagram crossword, where each clue is an anagram of the required solution.

She has a set of n words that she thinks would be good candidates for her next puzzle. We say that two words are similar if one can be obtained from the other by rearranging the letters (i.e. they are anagrams). She wants to select a subset of her words, such that there are exactly k pairs of similar words in that subset. Help Biljana determine the number of such subsets.

Input

The first line contains integers n (1 ≤ n ≤ 2000) and k (0 ≤ k ≤ 2000), the number of words and the required number of similar pairs.

Each of the following n lines contains a word consisting of at most 10 lowercase letters. All words will be distinct.

Output

Output the number of described subsets modulo 109 + 7.

Examples3

  1. Example 1

    Input
    3 1
    ovo
    ono
    voo
    
    Expected output
    2
    
  2. Example 2

    Input
    5 2
    trava
    vatra
    vrata
    leo
    ole
    
    Expected output
    3
    
  3. Example 3

    Input
    6 3
    mali
    lima
    imal
    je
    sve
    ej
    
    Expected output
    6