Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
using namespace std;
int w[10002];
int e[10002];
int main()
{
	int n,m;
	string d[100];
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>d[i];
	fill(e,e+10002,0);
	fill(w,w+10002,0);
	//累積和
	for(int i=1;i<n+1;i++)
	{
		w[i]=w[i-1];
		e[i]=e[i-1];
		for(int j=0;j<m;j++)
		{
			if(d[j][i-1]=='E')
				e[i]++;
			if(d[j][i-1]=='W')
				w[i]++;
		}
	}
	w[n+1]=w[n];
	e[n+1]=e[n];
	//境界の探索
	int err=1e8-1;
	int ans=-1;
	for(int i=0;i<n+1;i++)
	{
		//cerr<<w[i]<<" "<<e[i]<<endl;
		if(err>e[i]+w[n+1]-w[i])
		{
			err=e[i]+w[n+1]-w[i];
			ans=i;
		}
	}
	cout<<ans<<" "<<ans+1<<endl;
	return 0;
}