Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> E(N + 1, 0), W(N + 1, 0);
    for (int q = 0; q < M; ++q) {
        string S;
        cin >> S;
        int cnt = 0;
        for (int i = 1; i <= N; ++i) {
            if (S[i - 1] == 'E') ++cnt;
            E[i] += cnt;
        }

        reverse(S.begin(), S.end());
        cnt = 0;
        for (int i = 1; i <= N; ++i) {
            if (S[i - 1] == 'W') ++cnt;
            W[i] += cnt;
        }
    }

    int ans = 0, mincost = W[N];  // 左からans個がW
    for (int i = 1; i <= N; ++i) {
        int cost = E[i] + W[N - i];
        if (cost < mincost) {
            ans = i;
            mincost = cost;
        }
    }

    cout << ans << " " << ans + 1 << endl;
    return 0;
}