Codeforces Round 339 (Div. 1)
E
Puzzle Lover
Codeforces
3200
原题
← D→
翻译中…

Oleg Petrov loves crossword puzzles and every Thursday he buys his favorite magazine with crosswords and other word puzzles. In the last magazine Oleg found a curious puzzle, and the magazine promised a valuable prize for it's solution. We give a formal description of the problem below.

翻译中…

The puzzle field consists of two rows, each row contains $*n*$ cells. Each cell contains exactly one small English letter. You also are given a word $*w*$, which consists of $*k*$ small English letters. A solution of the puzzle is a sequence of field cells $*c*_{1}$, $...$, $*c*_{*k*}$, such that:

翻译中…
  • For all $*i*$ from $1$ to $*k*$ the letter written in the cell $*c*_{*i*}$ matches the letter $*w*_{*i*}$;
  • All the cells in the sequence are pairwise distinct;
  • For all $*i*$ from $1$ to $*k* - 1$ cells $*c*_{*i*}$ and $*c*_{*i* + 1}$ have a common side.
翻译中…

Oleg Petrov quickly found a solution for the puzzle. Now he wonders, how many distinct solutions are there for this puzzle. Oleg Petrov doesn't like too large numbers, so calculate the answer modulo $10^{9} + 7$.

翻译中…

Two solutions $*c*_{*i*}$ and $*c*'_{*i*}$ are considered distinct if the sequences of cells do not match in at least one position, that is there is such $*j*$ in range from $1$ to $*k*$, such that $*c*_{*j*} ≠ *c*'_{*j*}$.

翻译中…

Input

翻译中…

The first two lines contain the state of the field for the puzzle. Each of these non-empty lines contains exactly $*n*$ small English letters.

翻译中…

The next line is left empty.

翻译中…

The next line is non-empty and contains word $*w*$, consisting of small English letters.

翻译中…

The length of each line doesn't exceed $2 000$.

翻译中…

Output

翻译中…

Print a single integer — the number of distinct solutions for the puzzle modulo $10^{9} + 7$.

翻译中…

样例

Input #1
code
edoc

code
Output #1
4
InputCopy OutputCopy
Input #2
aaa
aaa

aa
Output #2
14
InputCopy OutputCopy
题目信息
题号
613E
时间限制
2 s
内存限制
256 MB
标签
动态规划
哈希
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。