Line#7384

Line

1 segundo
122,174 megabytes
Muy fácil (≈850)

Orysia has arranged n^2 letters on a grid sheet in the shape of an n \times n square. She wants to cross out some letters with a single line, starting from the top-left letter and moving either to the right or downward, ending at the bottom-right letter. This means she will cross out exactly 2n - 1 letters. Additionally, Orysia wants the letters along the line to spell a specific magical word.

Your task is to write a program that, given the grid of letters and the magical word, calculates how many different ways Orysia can cross out the magical word. The result should be given modulo the prime number .

Entrada

The first line contains a natural number (2 \le n \le 1000), which is the length of the side of the square grid of letters. The following lines each contain lowercase Latin letters (which may repeat), representing the grid. There are no spaces between the letters. After the grid, a magical word is provided, consisting of 2n - 1 lowercase Latin letters (which may also repeat).

Salida

Output a single number: the remainder when the number of ways Orysia can cross out the magical word is divided by .

Ejemplos

There are exactly ways to cross out the word "logos":

prb7384_

Ejemplo 1

Loading
Loading