#include #define ff first #define ss second #define pb push_back #define ll long long using namespace std; ll n,ppow[200000],m; const ll p=31; const ll mod = 1e9 + 9; int main() { ios::sync_with_stdio(0); cin.tie(0); freopen("rolling_table.in","r",stdin); freopen("rolling_table.out","w",stdout); cin >> n >> m; ll lista[n+10][m+10]; ll dp[6][n+10][m+10]; for(ll i=1;i<=n;i++){ string s; cin >> s; for(ll j=0;j=1;i--){ ll temphash=0; for(ll j=1;j<=m;j++){ temphash+=lista[i][j]*ppow[j-1]; temphash%=mod; dp[2][i][j]=dp[2][i+1][j]*ppow[j]+temphash; dp[2][i][j]%=mod; //cout << dp[2][i][j] << ' '; } //cout << endl; } ///goredesno for(ll i=1;i<=n;i++){ ll temphash=0; for(ll j=m;j>=1;j--){ temphash=temphash*ppow[1]+lista[i][j]; temphash%=mod; dp[1][i][j]=dp[1][i-1][j]+ppow[(i-1)*(m-j+1)]*temphash; dp[1][i][j]%=mod; //cout << dp[1][i][j] << ' '; } //cout << endl; } ///doledesno for(ll i=n;i>=1;i--){ ll temphash=0; for(ll j=m;j>=1;j--){ temphash=temphash*ppow[1]+lista[i][j]; temphash%=mod; dp[3][i][j]=dp[3][i+1][j]*ppow[m-j+1]+temphash; dp[3][i][j]%=mod; //cout << dp[3][i][j] << ' '; } //cout << endl; } ll res=0; for(ll i=1;i<=n;i++){ for(ll j=1;j<=m;j++){ if(dp[0][n-i][m-j] == dp[3][i+1][j+1] && dp[1][i][j+1]==dp[2][n-i+1][m-j] && dp[0][i][j]==dp[3][n-i+1][m-j+1] && dp[2][i+1][j]==dp[1][n-i][m-j+1]) res++; } } cout << res; return 0; }