Problem:
Score : 1400 points

Problem Statement

We have a grid with H rows and W columns.
The state of the cell at the i-th (1≤i≤H) row and j-th (1≤j≤W) column is represented by a letter a_{ij}, as follows:

. : This cell is empty.

o : This cell contains a robot.

E : This cell contains the exit. E occurs exactly once in the whole grid.

Snuke is trying to salvage as many robots as possible, by performing the following operation some number of times:

Select one of the following directions: up, down, left, right. All remaining robots will move one cell in the selected direction, except when a robot would step outside the grid, in which case the robot will explode and immediately disappear from the grid. If a robot moves to the cell that contains the exit, the robot will be salvaged and immediately removed from the grid.

Find the maximum number of robots that can be salvaged.

Constraints

2≤H,W≤100

a_{ij} is ., o or E.

E occurs exactly once in the whole grid.

Input

The input is given from Standard Input in the following format:

H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}

Output

Print the maximum number of robots that can be salvaged.

Sample Input 1

3 3
o.o
.Eo
ooo

Sample Output 1

3

For example, select left, up, right.

Sample Input 2

2 2
E.
..

Sample Output 2

0

Sample Input 3

3 4
o...
o...
oooE

Sample Output 3

5

Select right, right, right, down, down.

Sample Input 4

5 11
ooo.ooo.ooo
o.o.o...o..
ooo.oE..o..
o.o.o.o.o..
o.o.ooo.ooo

Sample Output 4

12

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 101;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m,sx,sy;

char st[maxn][maxn];

short line[maxn][maxn],row[maxn][maxn];

short dp[maxn][maxn][maxn];

void Work(){
	memset(dp,-1,sizeof(dp));dp[0][0][0]=0;
	REP(l,0,m-sy)
		REP(i,0,sx-1)
			REP(j,0,n-sx)
				REP(k,0,sy-1)if(dp[i][j][k]!=-1){
					int U=max(sx-i,j+1),D=min(sx+j,n-i),L=max(sy-k,l+1),R=min(sy+l,m-k);
					if(sx-i-1>=j+1)dp[i+1][j][k]=max((int)dp[i+1][j][k],dp[i][j][k]+line[sx-i-1][R]-line[sx-i-1][L-1]);
					if(sx+j+1<=n-i)dp[i][j+1][k]=max((int)dp[i][j+1][k],dp[i][j][k]+line[sx+j+1][R]-line[sx+j+1][L-1]);
					if(sy-k-1>=l+1)dp[i][j][k+1]=max((int)dp[i][j][k+1],dp[i][j][k]+row[D][sy-k-1]-row[U-1][sy-k-1]);
					if(sy+l+1<=m-k)dp[i][j][k]=max((int)dp[i][j][k],dp[i][j][k]+row[D][sy+l+1]-row[U-1][sy+l+1]);
				}
	int ans=0;
	REP(i,0,n)REP(j,0,n)REP(k,0,m)ans=max(ans,(int)dp[i][j][k]);
	iout(ans);
}

void Init(){
	read(n,m);
	REP(i,1,n)scanf("%s",st[i]+1);
	REP(i,1,n)REP(j,1,m){
		if(st[i][j]=='E')sx=i,sy=j;
		line[i][j]=line[i][j-1]+(st[i][j]=='o');
		row[i][j]=row[i-1][j]+(st[i][j]=='o');
	}
}

int main(){
	Init();
	Work();
	return 0;
}