import sys input = sys.stdin.readline mod=10**9+7 H,W=map(int,input().split()) MAP=[input().strip() for i in range(H)] #H,W=200,200 #MAP=["a"*W for i in range(H)] if MAP[0][0]!=MAP[-1][-1]: print(0) exit() def cc(x,y,z,w): return x*8000000+y*40000+z*200+w def re(r): w=r%200 r//=200 z=r%200 r//=200 y=r%200 x=r//200 return x,y,z,w DP=dict() DP[cc(0,0,H-1,W-1)]=1 for i in range((H+W-2)//2): NDP=dict() for r in DP: x,y,z,w=re(r) if 0<=x<H and 0<=z<H and 0<=y+1<W and 0<=w-1<W and MAP[x][y+1]==MAP[z][w-1]: if cc(x,y+1,z,w-1) in NDP: NDP[cc(x,y+1,z,w-1)]+=DP[cc(x,y,z,w)] NDP[cc(x,y+1,z,w-1)]%=mod else: NDP[cc(x,y+1,z,w-1)]=DP[cc(x,y,z,w)] if 0<=x<H and 0<=z-1<H and 0<=y+1<W and 0<=w<W and MAP[x][y+1]==MAP[z-1][w]: if cc(x,y+1,z-1,w) in NDP: NDP[cc(x,y+1,z-1,w)]+=DP[cc(x,y,z,w)] NDP[cc(x,y+1,z-1,w)]%=mod else: NDP[cc(x,y+1,z-1,w)]=DP[cc(x,y,z,w)] if 0<=x+1<H and 0<=z<H and 0<=y<W and 0<=w-1<W and MAP[x+1][y]==MAP[z][w-1]: if cc(x+1,y,z,w-1) in NDP: NDP[cc(x+1,y,z,w-1)]+=DP[cc(x,y,z,w)] NDP[cc(x+1,y,z,w-1)]%=mod else: NDP[cc(x+1,y,z,w-1)]=DP[cc(x,y,z,w)] if 0<=x+1<H and 0<=z-1<H and 0<=y<W and 0<=w<W and MAP[x+1][y]==MAP[z-1][w]: if cc(x+1,y,z-1,w) in NDP: NDP[cc(x+1,y,z-1,w)]+=DP[cc(x,y,z,w)] NDP[cc(x+1,y,z-1,w)]%=mod else: NDP[cc(x+1,y,z-1,w)]=DP[cc(x,y,z,w)] DP=NDP if (H+W)%2==0: ANS=0 for r in DP: x,y,z,w=re(r) if x==z and y==w: ANS+=DP[cc(x,y,z,w)] ANS%=mod print(ANS) else: ANS=0 for r in DP: x,y,z,w=re(r) if x==z and y+1==w: ANS+=DP[cc(x,y,z,w)] ANS%=mod if x+1==z and y==w: ANS+=DP[cc(x,y,z,w)] ANS%=mod print(ANS)