Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<vector<vector<char> >,int> P;
const long long int MOD = 1000000007;
const int INF = 1000000000;

int w, h;
int ww[10000], ee[10000];
int sw[10000], se[10000];

int main(){
    cin >> w >> h;
    rep(i,h){
        rep(j,w){
            char hoge;
            cin >> hoge;
            if(hoge == 'W') ww[j]++;
            else ee[j]++;
        }
    }
    rep(j,w){
        if(j == 0){
            sw[j] = ww[j];
            continue;
        }
        sw[j] = sw[j-1]+ww[j];
    }
    for(int j = w-1; j >= 0; j--){
        if(j == w-1){
            se[j] = ee[j];
            continue;
        }
        se[j] = se[j+1]+ee[j];
    }
    int ans = h*w-se[0];
    int pos = 0;
    rep(i,w-1){
        int cnt = (i+1)*h-sw[i]+(w-i-1)*h-se[i+1];
        if(ans > cnt){
            ans = cnt;
            pos = i+1;
        }
    }
    if(ans > h*w-sw[w-1]){
        pos = w;
    }
    cout << pos << " " << pos+1 << endl;
}