Anda di halaman 1dari 1

The weather is pleasant at NSIT and Swaroop is returning home after taking classes

of recursion at TDS.Unfortunately there is strike in Delhi.So he has decided to


stay at guest house in the college itself.
Let's assume that NSIT has the shape of a rectangle consisting of 'a' rows and 'b'
columns. We enumerate the rows of the rectangle from top to bottom with numbers
from 1 to a and the columns — from left to right with numbers from 1 to b.Let's
denote the cell at the intersection of the r-th row and the c-th column as (r, c).
Initially Swaroop stands in cell (1, 1), and in the end he wants to be in cell (a, 
b). Since Swaroop is in a hurry to reach guest house, he can go from cell (r, c),
only to either cell (r + 1, c) or (r, c + 1). He can't leave NSIT.

Some cells of NSIT are similar to each other, and some look very different. Swaroop
enjoys taking photographs and at every step he takes a photograph of the cell where
he is currently present. The path through the NSIT is considered to be convenient
if photographs taken on his way, can be viewed in both forward and in reverse
order, showing the same sequence of photos. More formally, the line formed by the
cells in order of visiting should be a palindrome.

Count the number of convenient paths from cell (1, 1) to cell (a, b). Since this
number can be very large, determine the remainder after dividing it by 10^9 + 7.

Input Format :

The first line contains two integers a, b (1 ≤ a, b ≤ 500) — the height and width
of NSIT.

Each of the following n lines contains b lowercase English letters identifying the
types of cells of the forest. Identical cells are represented by identical letters,
different cells are represented by different letters.

Constraints:

1<=a,b<=500

Output Format:

Print a single integer — the number of convenient paths modulo 10^9 + 7.

Sample Input:
3 4
aaab
baaa
abba

Sample Output:
4
0

Anda mungkin juga menyukai