Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	Info(){
		num_E = num_W = 0;
	}
	int num_E,num_W;
};


int main(){

	int N,M,total_W = 0,total_E = 0;
	scanf("%d %d",&N,&M);

	Info info[N+1];
	char buf[N+1];

	for(int loop = 0; loop < M; loop++){
		scanf("%s",buf);
		for(int i = 0; i < N; i++){
			if(buf[i] == 'W'){
				info[i+1].num_W++;
				total_W++;
			}else{
				info[i+1].num_E++;
				total_E++;
			}
		}
	}

	if(total_W == 0){
		printf("0 1\n");
		return 0;
	}else if(total_E == 0){
		printf("%d %d\n",N,N+1);
		return 0;
	}

	int calc_E = 0,calc_W = 0,left = 0,div_min = total_W,tmp_div;

	for(int i = 1; i <= N; i++){
		calc_E += info[i].num_E;
		calc_W += info[i].num_W;
		tmp_div = calc_E + total_W - calc_W;
		if(div_min > tmp_div){
			div_min = tmp_div;
			left = i;
		}
	}

	printf("%d %d\n",left,left+1);

	return 0;
}