lp6m’s blog

いろいろかきます

test

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int r,c;
string data[500][500];

bool istentaisho(int lui,int luj,int h,int w){
	bool rst = true;
	REP(i,h){
		REP(j,w){
			//cout << i+lui << j+luj << h-i+lui-1 << w-j+luj-1 << endl;
			if(data[i+lui][j+luj]!=data[h-i+lui-1][w-j+luj-1]){
				//damedesu
				rst = false;
				j = w+1; h = i+1;
			}
		}
		//hanbundeenough
		//if(i>h/2-1) i = h+1;
	}
	return rst;
}
int main(){
	cin >> r >> c;
	REP(i,r){
		string tmp;
		cin >> tmp;
		REP(j,tmp.size()) data[i][j] = tmp[j];
	}
	ll int ans = 0;
	REP(i,r){
		REP(j,c){
			FOR(hh,2,r+1){
				FOR(ww,2,c+1){
					if(i+hh<=r||j+ww<=c){
						if(istentaisho(i,j,hh,ww)) ans++;
					}
				}
			}

		}
	}
	cout << ans << endl;
	return 0;
}