Akash had recently bought a puzzle book. Each page in the book has a word puzzle in which a grid of letters from the English Alphabet (uppercase or lowercase) or digits between 0-9 are given. Akash has to figure out the number of occurrences of a particular word in the given grid. The grid is always a square, and the word can be present in any direction in the grid i.e. left to right, right to left, top to bottom, bottom to top, and the diagonals. Palindromic words (words which are read the same as the original word in the opposite direction too) if present in the grid will be counted twice.

Write a program to help Akash. Read the input from STDIN and print the output to STDOUT. Do not write arbitrary strings anywhere in the program, as these contribute to the standard output and test cases will fail.

Input Format:
The first line of input has N, which is the number of rows/columns in the grid.
The next N lines each contain N-characters (alphabets or digits).
The last line contains the word whose number of occurrences has to be found out.

Output Format:
The output has the number of occurrences of the given word in the grid.

Constraint:
N >= 3.

Sample Input 1:

bash
Copy code
3
ctt
cat
cct
cat
Sample Output 1:

Copy code
4
Explanation 1:
Size of the grid, N = 3. The grid along with occurrences of the word given in input is marked in the figure given below.

Comments (1)