Palindromic Paths (Bronze)#11169

Palindromic Paths (Bronze)

1 second
128 megabytes
Hard

Farmer John's farm is in the shape of an n \times n grid of fields, with each field labeled by a letter of the alphabet. For example:

\begin{array}{cccc} A & B & C & D \\ B & X & Z & X \\ C & D & X & B \\ W & C & B & A \end{array}

Each day, Bessie the cow walks from the upper-left field to the lower-right field. At each step, she moves either one field to the right or one field downward. Bessie keeps track of the string formed by the letters of the fields she visits along her path.

Bessie becomes very disoriented, however, if this string is a palindrome (that is, if it reads the same forward and backward), because she gets confused about the direction in which she was traveling.

Please help Bessie determine the number of distinct palindromes she can form along her walks. Different paths that produce the same palindrome count only once. For example, in the grid above, several different paths produce the palindrome ABXZXBA, but there are only distinct palindromes Bessie can form:

ABCDCBA,~ABCWCBA,~ABXZXBA,~and~ABXDXBA

Input

The first line contains an integer n~(2 \le n \le 18). The next lines contain the rows of the grid. Each row consists of characters from to .

Output

Print the number of distinct palindromes Bessie can form.

Examples

Example 1

Loading
Loading