Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include <iostream>
#include <string>
 
using namespace std;
 
#define M 100
#define REP(i, n) for(int i=0; i<n; ++i)
 
std::string d[M];
 
#define N 10000
int eastern[N];
int western[N];
 
typedef long long ll;
ll sum_eastern[N+1] = {};
ll sum_western[N+1] = {};
 
ll sum[N+1] = {};
 
int main(){
  int n,m;
  cin >> n >> m;
  REP(i, m) cin >> d[i];
  
  REP(i_n, n) REP(i_m, m) (d[i_m][i_n] == 'E' ? eastern[i_n] : western[i_n]) += 1;
  
  for(int i = 0; i < n; ++i) sum_eastern[i+1] = sum_eastern[i] + eastern[i];
  for(int i = n-1; i >= 0; --i) sum_western[i] = sum_western[i+1] + western[i];
 
  REP(i, n+1) sum[i] = sum_eastern[i] + sum_western[i];
 
  ll current_i = -1;
  ll current_cost = 10000000;
 
  REP(i, n+1) if(current_cost > sum[i]){
    current_i = i;
    current_cost = sum[i];
  }
 
  cout << current_i << " " << current_i + 1 << endl;
 
  return 0;
}