Problem: Example

Input

2 1
WE


Output

1 2

Solution (in CPP):

Solution:
#include<iostream>
using namespace std;

int main()
{
    int n, m;

    cin >> n >> m;

    char a[m][n];
    int s[m];

    for( int i = 0; i < m; i++ )
        s[i] = 0;

    for( int i = 0; i < m; i++ )
    {
        for( int j = 0; j < n; j++ )
        {
            cin >> a[i][j];
            if( a[i][j] == 'W' )
                s[i]++;
        }
    }

    int x = 0, error = 0;
    for( int i = 0; i < m; i++ )
        error += s[i];
    
    int w[m], e[m];
    for( int i = 0; i < m; i++ )
    {
        w[i] = 0;
        e[i] = 0;
    }

    for( int j = 0; j < n; j++ )
    {

        int sum = 0;
        for( int i = 0; i < m; i++ )
        {
            if( a[i][j] == 'W' )
                w[i]++;
            else
                e[i]++;

            sum += e[i] + s[i] - w[i];
        }

        if( sum < error )
        {
            error = sum;
            x = j + 1;
        }
    }

    cout << x << " " << x + 1 << endl;

    return 0;
}