Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

pair<int,int> dfs1(const vector<vector<int>>&edges, const vector<int>&scores, int pre,int now,int  num) {
	num+=scores[now];
	pair<int,int>ans(make_pair(num,now));
	for (auto e : edges[now]) {
		if (pre != now) {

			auto p=dfs1(edges, scores, now,e, num);
			ans=max(ans,p);
		}
	}
	return ans;
}

int solve(const vector<vector<int>>&edges,const vector<int>&scores) {
	auto p1(dfs1(edges,scores,-1,0,0));
	auto p2(dfs1(edges,scores,-1,p1.second,0));
	return p2.first;
}

int main(){
	int N,M;cin>>N>>M;
	vector<int>ws(N);
	vector<int>sum_ws(N+1);
	for (int i = 0; i < M; ++i) {
		string st;cin>>st;
		for (int j = 0; j < N; ++j) {
			if(st[j]=='W')ws[j]++;
		}
	}
	for (int i = 0; i < N; ++i) {
		sum_ws[i+1]=sum_ws[i]+ws[i];
	}

	pair<int,int>ans(1e9,-1);
	for (int i = 0; i <= N; ++i) {
		int er_cnt=(M*i-sum_ws[i])+(sum_ws[N]-sum_ws[i]);
		pair<int,int>p(er_cnt,i);
		if(p<ans)ans=p;
	}
	cout<<ans.second<<" "<<ans.second+1<<endl;
	return 0;
}