Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<string> s(m);
    for(int i = 0; i < m; i++) cin >> s[i];
    int p, d = INF;
    vector<int> E(n + 1, 0), W(n + 1, 0);
    for(int i = 0; i < m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            E[j] += (s[i][j - 1] == 'E');
        }
        for(int j = n; j >= 1; j--)
        {
            W[j - 1] += (s[i][j - 1] == 'W');
        }
    }
    for(int j = 1; j <= n; j++) E[j] += E[j - 1];
    for(int j = n; j >= 1; j--) W[j - 1] += W[j];
    int num = INF, ans = -1;
    for(int i = 0; i <= n; i++)
    {
        if(E[i] + W[i] < num)
        {
            num = E[i] + W[i];
            ans = i;
        }
    }
    cout << ans << " " << ans + 1 << endl;
    return 0;
}