Under construction

Still being built. Things may change

Scar Prepares an Attack

Time limit2sMemory limit1024 MB

Summary
Count the ways to pick a nonempty subsequence of each hyena's genotype so that each chosen birth genotype is stronger than the next, modulo 1e9+7.
Level

Hard8 of 10

Topics
Dynamic programming, String, Bit manipulation, Sorting
Solved
No attempts yet

Problem

Scar is preparing an army of hyenas for an attack. nn hyenas came to the selection. Scar wants to pick the most capable ones, those born with a natural talent.

Each hyena has a genotype, which is a sequence of genes. Genes are denoted by lowercase Latin letters.

Each hyena's genotype at birth was some nonempty subsequence of its current genotype. During its life, an arbitrary number of arbitrary genes were inserted at various places in the genotype, and it took its current form.

We say genotype aa is stronger than genotype bb if there is an index ii such that aj=bja_j = b_j for all j<ij < i and aia_i comes earlier in the alphabet than bib_i. If ai=bia_i = b_i for all ii, the genotype with fewer genes is stronger.

Scar wonders what the birth genotypes could have been. It is known that the birth genotype of the ii-th hyena was stronger than the birth genotype of the (i+1)(i+1)-th hyena. Count the number of possible sets of birth genotypes that satisfy all these conditions, modulo 1 000 000 0071\,000\,000\,007.

Input

The first line contains nn (1≤n≤101 \le n \le 10), the number of hyenas. Each of the next nn lines contains the current genotype sis_i of the ii-th hyena. Each string has length at most 13.

Output

Print the number of sets of birth genotypes that satisfy all conditions, modulo 1 000 000 0071\,000\,000\,007.

Examples3

  1. Example 1

    Input
    2
    aaa
    aa
    
    Expected output
    1
    
  2. Example 2

    Input
    2
    ab 
    abc
    
    Expected output
    13
    
  3. Example 3

    Input
    3
    qwerty
    qwerty
    ytrewq
    
    Expected output
    87506