#R1020. [KBC002D] String

[KBC002D] String

Problem Statement

Given two strings, AA and BB, both of length NN, which are composed of uppercase letters, and a string SS of length MM.

A position is considered valid if the substring formed by selecting uppercase letters from AA and BB is equal to SS.

Output the count of valid positions modulo 10071007.

We consider two strings to be different if there exists a position ii such that SiSiS_i \neq S'_i.

Constraints

  • 1N20001 \leq N \leq 2000 and 1M20001 \leq M \leq 2000.
  • The solution is guaranteed to exist.

Input

N MN\ M A1A2ANA_1A_2\cdots A_N B1B2BNB_1B_2\cdots B_N S1S2SMS_1S_2\cdots S_M

  • The first line contains two positive integers NN and MM.
  • The next two lines contain strings AA and BB.
  • The last line contains MM characters representing SS.

Output

The count of valid positions modulo 10071007.

Sample Input 1

4 4
LOVE
EVOL
LOVE

Sample Output 1

4
  • Possibility 1: (1,1)(1,2)(1,3)(1,4)(1,1) \to (1,2) \to (1,3) \to (1,4);
  • Possibility 2: (1,1)(1,2)(2,2)(2,1)(1,1) \to (1,2) \to (2,2) \to (2,1);
  • Possibility 3: (2,4)(2,3)(2,2)(2,1)(2,4) \to (2,3) \to (2,2) \to (2,1);
  • Possibility 4: (2,4)(2,3)(1,3)(1,4)(2,4) \to (2,3) \to (1,3) \to (1,4).

Sample Input 2

1 3
Y
Y
YYY

Sample Output 2

2
  • Possibility 1: (1,1)(1,2)(1,1)(1,1) \to (1,2) \to (1,1);
  • Possibility 2: (1,2)(1,1)(1,2)(1,2) \to (1,1) \to (1,2).