Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

constexpr int INF = (1<<30)-1;
int main() {
    int N, M; cin >> N >> M;
    vector<string> D(M);
    for (int i = 0; i < M; i++) {
        string T = " ";
        string R; cin >> R;
        D[i] = T + R;
    }

    vint suml(N+1, 0);
    vint sumr(N+2, 0);

    for (int j = 1; j <= N; j++) {
        suml[j] = suml[j-1];
        for (int i = 0; i < M; i++) {
            if (D[i][j] == 'E') suml[j]++;
        }
    }
    for (int j = N; j > 0; j--) {
        sumr[j] = sumr[j+1];
        for (int i = 0; i < M; i++) {
            if (D[i][j] == 'W') sumr[j]++;
        }
    }
    
    int ans = -1, erl = -1, err = -1;
    int minv = INF;
    for (int i = 0; i <= N; i++) {
        int val = suml[i]+sumr[i+1];
        if (minv > val) {
            minv = suml[i]+sumr[i+1];
            erl = suml[i], err = sumr[i+1];
            ans = i;
        } else if (minv == val && erl > suml[i]) {
            erl = suml[i], err = sumr[i];
            ans = i;
        }
    }
    cout << ans << " " << ans + 1 << endl;
    return (0);
}