This page is still under construction.

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

Concert Attendance Schedules

Time limit0.3sMemory limit128 MB

Summary
Count the ways to pick increasing day positions matching a target band sequence, where each pick must wait h_b+1 days after that band's previous pick.
Level

Hard8 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Problem

John listens to 26 bands, labeled A through Z. He checked the schedule for the coming season and found that exactly one concert is held on each of the next nn days. He wants to attend exactly kk of those concerts in a fixed order, and he may attend concerts of the same band more than once.

Some bands charge more than others, so after attending a concert by band bb John rests at home for at least hbh_b days before he attends another concert. If he attends a concert of band bb on day dd, the next concert he attends is on day d+hb+1d + h_b + 1 or later.

Count the schedules that let John attend the concerts in the order he wants. The count can be very large, so print it modulo 109+710^9 + 7.

Input

The first line contains kk and nn, separated by a space (1≤k≤3001 \le k \le 300, 1≤n≤1051 \le n \le 10^5).

The second line contains the 26 values hAh_A through hZh_Z, separated by spaces (0≤hb≤1050 \le h_b \le 10^5).

The third line contains a string of length kk listing the bands whose concerts John wants to attend, in order. For example, AFJAZ means A first, then F, then J, then A, then Z.

The fourth line contains a string of length nn written the same way, giving the band that performs on each of the next nn days.

Both strings consist of uppercase letters only.

Output

Print the number of schedules that let John attend the concerts in the order he wants, modulo 109+710^9 + 7, on one line.

Examples5

  1. Example 1

    Input
    2 10
    1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    AB
    ABBBBABBBB
    
    Expected output
    10
    
  2. Example 2

    Input
    1 5
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    A
    AABAA
    
    Expected output
    4
    
  3. Example 3

    Input
    2 3
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    AB
    BBA
    
    Expected output
    0
    
  4. Example 4

    Input
    2 6
    4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    AB
    ABBBBB
    
    Expected output
    1
    
  5. Example 5

    Input
    3 6
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    AAA
    AAAAAA
    
    Expected output
    20