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++ (GCC 5.4.1) (judge verdict: Accepted)

//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 101
#define INF (int)1e9
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
 
int mp[inf][inf],sum[inf][inf],f[inf][inf][inf];
int n,m;
 
int getsum(int l1,int l2,int r1,int r2){
    return sum[r1][r2]-sum[l1-1][r2]-sum[r1][l2-1]+sum[l1-1][l2-1];
}
 
int main(){
    rd(n) rd(m)
    char ch;
    int ex,ey;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            ch=getchar();
            while (ch!='o' && ch!='.' && ch!='E'){
                ch=getchar();
            }
            if (ch=='o'){
                mp[i][j]=1;
            }
            else if (ch=='E'){
                ex=i,ey=j;
            }
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            sum[i][j]=mp[i][j]+sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
        }
    }
    int ans=0;
    for (int i=0;ex-i>=1;i++){
        for (int j=0;ex+j<=n;j++){
            int l1=max(ex-i,j+1),r1=min(ex+j,n-i);
            if (l1>r1){
                continue;
            }
            for (int k=0;ey-k>=1;k++){
                for (int l=0;ey+l<=m;l++){
                    int l2=max(ey-k,1+l),r2=min(ey+l,m-k);
                    if (l2>r2){
                        continue;
                    }
                    ans=max(ans,f[j][k][l]);
                    if (i+j<n-ex){
                        f[j+1][k][l]=max(f[j+1][k][l],f[j][k][l]+getsum(ex+j+1,l2,ex+j+1,r2));
                    }
                    if (k+l<ey-1){
                        f[j][k+1][l]=max(f[j][k+1][l],f[j][k][l]+getsum(l1,ey-k-1,r1,ey-k-1));
                    }
                    if (k+l<m-ey){
                        f[j][k][l+1]=max(f[j][k][l+1],f[j][k][l]+getsum(l1,ey+l+1,r1,ey+l+1));
                    }
                    if (i+j<ex-1){
                        f[j][k][l]=max(f[j][k][l],f[j][k][l]+getsum(ex-i-1,l2,ex-i-1,r2));
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}