Time limit
2s
Memory limit
128 MB
A DNA string consists of the nucleotides A, C, G, and T. Some DNA strings can be converted into a protein, which is a nonempty sequence of amino acids. The conversion works as follows.
ACCTGTACG produces the codons ACC, TGT, and ACG in that order, while ACCTGTAC produces only ACC and TGT, ignoring the final AC.ACC maps to thr, TGT maps to cys, and ACG maps to thr, then ACCTGTACG is converted into thr cys thr.A deletion removes one or more nucleotides from a DNA string. The remaining nucleotides keep their relative order. For example, after a deletion, ACTG could become ACG or CG, among other strings.
Given a DNA string and a codon conversion table, compute how many distinct proteins can be obtained after applying zero or more deletions.
The first line contains the DNA string. Its length is at most 2,500.
The second line contains M, the number of codons in the codon conversion table. M is at most 50.
Each of the next M lines contains one table entry: a codon followed by an amino acid. A codon is a length-3 string made only of A, C, G, and T. An amino acid is a nonempty string of length at most 20 consisting of uppercase or lowercase English letters. No codon appears more than once in the table.
Print one line containing the number of distinct obtainable proteins modulo 1,000,000,007.