Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<string> D(m);
  for(int i = 0; i < m; ++i) cin >> D[i];
  vector<int> E(n+2,0), W(n+2,0);
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      if(D[j][i] == 'E') ++E[i+1];
      if(D[j][n-1-i] == 'W') ++W[n-i];
    }
    if(i < n){
      E[i+2] += E[i+1];
      W[n-1-i] += W[n-i];
    }
  }
  /*
  for(int i = 0; i < n+2; ++i) cout << E[i] << " ";
  cout << endl;
  for(int i = 0; i < n+2; ++i) cout << W[i] << " ";
  cout << endl;
  */
  int ans = 1000000000, l = -1, r = -1;
  for(int i = 1; i < n+2; ++i){
    if(E[i-1]+W[i] < ans){
      l = i-1;
      r = i;
      ans = E[i-1]+W[i];
    }
  }
  cout << l << " " << r << endl;
  return 0;
}