Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

#define MAX 10010

int n,m;
vector<string> c;
int sum[MAX][2];

void pre(char v,int dir,int sp,int type) {
  for(int cur=sp;0<=cur&&cur<n;cur+=dir) {
    int prev = cur - dir;
    if( 0 <= prev && prev < n ) sum[cur][type] = sum[prev][type];
    rep(j,m) if( c[j][cur] == v ) ++sum[cur][type];
  }
}

void compute() {
  pre('E',+1,0,0);
  pre('W',-1,n-1,1);
  int L = -1, R = 0;
  int mini = sum[0][1];
  rep(i,n-1) {
    if( mini > sum[i][0] + sum[i+1][1] ) {
      mini = sum[i][0] + sum[i+1][1];
      L = i, R = i + 1;
    }
  }
  if( mini > sum[n-1][0] ) {
    mini = sum[n-1][0];
    L = n-1, R = n;
  }
  cout << L+1 << " " << R+1 << endl;
}

int main() {
  cin >> n >> m;
  c.resize(m);
  rep(i,m) cin >> c[i];
  compute();
  return 0;
}