QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#15049. Baby's Problem

Statistics

Wang Baobao has a child named Wang Baobao. Wang Baobao has been clever since childhood and likes to look down on his father. One day, he came up with a problem and brought it to Wang Baobao to solve. Naturally, Wang Baobao could not solve it, so he came to ask you for help.

The problem is as follows: Given $N$ strings $S[1] \sim S[N]$, each of length $K$. $S[1][1], S[1][2], S[1][3], \dots, S[1][K]$ $S[2][1], S[2][2], S[2][3], \dots, S[2][K]$ ... $S[N][1], S[N][2], S[N][3], \dots, S[N][K]$

You need to choose a position $W[i]$ from each string, and then output a string according to the following order: Step 1: Output the $W[i]$-th character of each string in increasing order of the initial $W[i]$ (if $W[i]$ are the same, then in increasing order of $i$). Step 2: Repeat Step 1 $K$ times.

For example: $S[1] = \text{abcde}$ $S[2] = \text{fghij}$ $S[3] = \text{zzzzz}$ $W[1] = 2, W[2] = 0, W[3] = 0$ Then, the output string is: $\text{fzcgzdhzeizajzb}$

Now, our problem is: given $N$, $K$, and these $N$ strings, how many ways are there to choose $W[i]$ such that the final output string is equal to $T$?

Input

The first line contains $N$ and $K$, as described in the problem. The second line contains a string $T$, representing the target string. It is guaranteed that the length of $T$ is equal to $N \times K$. The next $N$ lines each contain a string of length $K$, representing $S[1] \sim S[N]$.

Output

A single integer representing the answer.

Examples

Input 1

3 3
abaabaaba
aaa
aaa
bbb

Output 1

8

Note

There are a total of eight cases: $W[1]=0, W[2]=1, W[3]=0$ $W[1]=0, W[2]=2, W[3]=0$ $W[1]=1, W[2]=0, W[3]=0$ $W[1]=2, W[2]=0, W[3]=0$ $W[1]=0, W[2]=2, W[3]=1$ $W[1]=2, W[2]=0, W[3]=1$ $W[1]=1, W[2]=2, W[3]=1$ $W[1]=2, W[2]=1, W[3]=1$

Constraints

Case $N$ $K$ Ans
1 $\le 5$ $\le 15$ \
2
3 $10$ $\le 2000000$
4
5
6
7 $\le 15$ $\le 20000000$
8
9 \
10

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.