Problem:
Problem A:
Where is the Boundary
An island country JAGAN in a certain planet is very long and narrow, and extends east and
west. This long country is said to consist of two major cultural areas | the eastern and the
western. Regions in the east tend to have the eastern cultural features and regions in the west
tend to have the western cultural features, but, of course, the boundary between the two cultural
areas is not clear, which has been an issue.
You are given an assignment estimating the boundary using a given data set.
More precise specification of the assignment is as follows:
JAGAN is divided into $n$ prefectures forming a line in the east-west direction. Each
prefecture is numbered 1, 2, ..., $n$
from WEST to EAST
.
Each data set consists of $m$ features, which has 'E' (east) or 'W' (west) for each prefecture.
These data indicate that each prefecture has eastern or western features from $m$ different
point of views, for example, food, clothing, and so on.
In the estimation, you have to choose a cultural boundary achieving the minimal errors.
That is, you have to minimize the sum of 'W's in the eastern side and 'E's in the western
side.
In the estimation, you can choose a cultural boundary only from the boundaries between
two prefectures.
Sometimes all prefectures may be estimated to be the eastern or the western cultural area.
In these cases, to simplify, you must virtually consider that the boundary is placed between
prefecture No. 0 and No. 1 or between prefecture No. $n$ and No. $n+1$. When you get multiple
minimums, you must output the most western (least-numbered) result.
Write a program to solve the assignment.
Input
Each input is formatted as follows:
$n$ $m$
$d_{11} ... d_{1n}$
:
:
$d_{m1} ... d_{mn}$
The first line consists of two integers $n$ ($1 \leq n \leq 10,000$), $m$ ($1 \leq m \leq 100$), which indicate
the number of prefectures and the number of features in the assignment. The following m lines
are the given data set in the assignment. Each line contains exactly $n$ characters. The $j$-th
character in the $i$-th line $d_{ij}$ is 'E' (east) or 'W' (west), which indicates $j$-th prefecture has the
eastern or the western feature from the $i$-th point of view.
Output
Print the estimated result in a line. The output consists of two integers sorted in the ascending
order which indicate two prefectures touching the boundary.
Sample Input
2 1
WE
Output for the Sample Input
1 2
Sample Input
3 2
WWE
WEE
Output for the Sample Input
1 2
Both estimates "1 2" and "2 3" achieve 1 error as the minimum. From the restriction that you
must adopt the most western estimate, you must output "1 2".
Sample Input
3 1
WWW
Output for the Sample Input
3 4
In this case, all the prefectures are western. As described in the problem statement, you must
virtually consider that the boundary is placed between third and fourth prefectures.
Sample Input
3 1
WEW
Output for the Sample Input
1 2
You cannot assume that 'E's and 'W's are separated.

Submitted solutions:

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
namespace ranges = std::ranges;
namespace views = std::views;
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
int N, M;
std::string S[100];
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> M;
    for (int i = 0 ; i < M ; i++) {
        std::cin >> S[i];
    }
    std::vector<int> pref(N + 1), suf(N + 1);
    for (int i = 0 ; i < N ; i++) {
        for (int j = 0 ; j < M ; j++) if (S[j][i] == 'E') pref[i + 1]++;
        pref[i + 1] += pref[i];
    }
    for (int i = N - 1 ; i >= 0 ; i--) {
        for (int j = 0 ; j < M ; j++) if (S[j][i] == 'W') suf[i]++;
        suf[i] += suf[i + 1];
    }
    int error = suf[0], ans = 0;
    for (int i = 0 ; i < N ; i++) {
        const int v = pref[i + 1] + suf[i + 1];
        if (error > v) {
            ans = i + 1;
            error = v;
        }
    }
    std::cout << ans << ' ' << ans + 1 << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4736
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N,0);
    rep(i,0,M) {
        string S;
        cin >> S;
        rep(j,0,N) {
            if (S[j] == 'E') A[j]++;
        }
    }
    vector<int> L(N+1,0), R(N+1,0);
    rep(i,0,N) L[i+1] = L[i]+A[i];
    rrep(i,0,N) R[i] = R[i+1]+A[i];
    int MIN = inf, ANS = -1;
    rep(i,0,N+1) {
        if (chmin(MIN,L[i]+(N-i)*M-R[i])) ANS = i;
    }
    cout << ANS << ' ' << ANS+1 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3612
final_rank: 2

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
guess:
prefix sum of E from left and of W from right => summing up
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 10000;
const int MAX_M = 100;
static char G[MAX_M][MAX_N];

static int L[MAX_N]; // prefix sum of 'E' from left
static int R[MAX_N]; // prefix sum of 'W' from left
static int cost[MAX_N+1];

//------------------------------------------------------------------------------
void solve(int M, int N)
{
    for (int i=0; i<N; ++i) { L[i] = 0; R[i] = 0; cost[i] = 0; }
    cost[N] = 0;

    for (int m=0; m<M; ++m)
        for (int i=0; i<N; ++i)
            if (G[m][i] == 'E')
                L[i]++;
    for (int i=1; i<N; ++i) L[i] += L[i-1];

    for (int m=0; m<M; ++m)
        for (int i=0; i<N; ++i)
            if (G[m][i] == 'W')
                R[i]++;
    for (int i=N-2; i>=0; --i) R[i] += R[i+1];

    cost[0] = R[0];
    cost[N] = L[N-1];
    for (int i=1; i<N; ++i) cost[i] = L[i-1] + R[i];

    int index = -1;
    int min_c = INF;
    for (int i=0; i<N+1; ++i)
        if (cost[i] < min_c)
            {
                min_c = cost[i];
                index = i;
            }
    int k = index+1;
    printf("%d %d\n", k-1, k);
}



//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, M, num;
    num = scanf("%d %d ", &N, &M);
    for (int m=0; m<M; ++m) for (int i=0; i<N; ++i) num = scanf("%c ", &G[m][i]);
    solve(M, N);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 30
memory_kb: 4672
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<'\n';}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

//2次元累積和
template< class T > struct CumulativeSum2D{
    vector<vector<T>> data;
    CumulativeSum2D(int H, int W) : data(H + 1, vector<T>(W + 1, 0)) {}
    void add(int y, int x, int z){
        y++, x++;
        if(y>=data.size()||x>=data[0].size())return;
        data[y][x]+=z;
    }
    void build(){
        for(int i=1;i<data.size();i++) {
            for(int j=1;j<data[i].size();j++) {
                data[i][j]+=data[i][j-1]+data[i-1][j]-data[i-1][j-1];
            }
        }
    }
    T query(int sy,int sx,int gy, int gx){
        return (data[gy][gx]-data[sy][gx]-data[gy][sx]+data[sy][sx]);
    }
};

int main(){
    INT(w,h);
    CumulativeSum2D<int> E(h, w), W(h, w);
    vector<string> A(h);
    in(A);
    rep(y,h){
        rep(x,w){
            if(A[y][x] == 'E')E.add(y,x,1);
            else W.add(y,x,1);
        }
    }
    E.build();
    W.build();
    vector<int> ans(2);
    int minv = INF;
    for(int i = 0; i <= w; i++){
        int v = E.query(0,0,h,i) + W.query(0,i,h,w);
        if(v < minv){
            minv = v;
            ans[0] = i;
            ans[1] = i + 1;
        }
    }
    out(ans);
}
accuracy: 1
time_ms: 20
memory_kb: 12452
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}


int main() {
   ll N,M;
   cin>>N>>M;
  vector<string> S(M);
  rep(m,M){cin>>S[m];}
  vll W(N+1,0);
  rep(m,M)rep(i,N)if(S[m][i]=='W')W[i+1]++;
  rep(i,N)W[i+1]+=W[i];
  ll m=1e18;
  ll an=-1;
  rep(i,N+1){
     ll d1=i*M-W[i];
     ll d2=(W[N]-W[i]);
     //cout<<i<<" "<<d1<<" "<<d2<<endl;
     if(m>(d1+d2)){
        an=i;
        m=d1+d2;
     }
  }
  cout<<an<<" "<<an+1<<endl;
  


}
accuracy: 1
time_ms: 10
memory_kb: 4676
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pint;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)

set<vector<string>> used;
vector<string> S;
ll ans = 0;
ll N;
vector<ll> dx = {1, 0, -1, 0};
vector<ll> dy = {0, 1, 0, -1};

bool valid(ll x, ll y){
  return (0 <= x && x <= N-1 && 0 <= y && y <= N-1);
}

void dfs(ll num){
  if(used.find(S)!=used.end()){
    return;
  }
  used.insert(S);
  if(num == 0){
    ans++;
    return;
  }

  vector<pint> next;
  rep(i, N) {
    rep(j, N) {
      if(S[i][j] == '.'){
        bool flag = false;
        rep(k, 4) {
          ll nx = j+dx[k];
          ll ny = i+dy[k];
          if(valid(nx, ny) && S[ny][nx]=='@'){
            flag = true;
          }
        }
        if(flag) {
          next.push_back(pint(j, i));
        }
      }
    }
  }
  for(auto c: next){
    ll x = c.first;
    ll y = c.second;
    S[y][x] = '@';
    dfs(num-1);
    S[y][x] = '.';
  }
}

int main(){
  ll N, M; cin >> N >> M;
  vector<string> V(N);
  rep(i, M) cin >> V[i];
  vector<ll> W(N), E(N);
  rep(i, M) {
    rep(j, N) {
      if(V[i][j] == 'W') W[j]++;
      else E[j]++;
    }
  }
  ll ans = 0;
  vector<ll> sum_W(N+1, 0), sum_E(N+1, 0);
  rep(i, N) sum_W[i+1] = sum_W[i]+W[i], sum_E[i+1] = sum_E[i+1] = sum_E[i]+E[i];
  ll score = -INT_MAX;
  rep(i, N+1) {
    ll tmp = 0;
    tmp += sum_W[i];
    tmp -= sum_E[i];
    tmp -= (sum_W[N]-sum_W[i]);
    tmp += (sum_E[N]-sum_E[i]);
    if(score < tmp) {
      score = tmp;
      ans = i;
    }
  }
  cout << ans << ' ' << ans+1 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 5240
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define inc(i, a, b) for (int i = (a); i <= (b); ++i)
#define dec(i, a, b) for (int i = (a); i >= (b); --i)

int main() {
    ll n, m;
    cin >> n >> m;
    string s[m];
    rep(i, m) cin >> s[i];

    ll a[n + 1] = {}, b[n + 1] = {};
    rep(i, n) {
        rep(j, m) s[j][i] == 'W' ? a[i + 1]++ : b[i + 1]++;
        a[i + 1] += a[i], b[i + 1] += b[i];
    }

    ll mn = 1e18, idx = 0;
    rep(i, n + 1) {
        if (mn > b[i] + a[n] - a[i]) {
            mn = b[i] + a[n] - a[i];
            idx = i;
        }
    }
    cout << idx << " " << idx + 1 << "\n";
}
accuracy: 1
time_ms: 10
memory_kb: 4788
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, m;
    cin >> n >> m;
    vector<string> d(m);
    rep(i, m) cin >> d[i];

    vector<int> L(n + 1, 0), R(n + 1, 0);
    rep(i, n)
    {
        L[i + 1] = L[i];
        rep(j, m) if (d[j][i] == 'E') L[i + 1]++;
    }
    for (int i = n - 1; i >= 0; i--)
    {
        R[i] = R[i + 1];
        rep(j, m) if (d[j][i] == 'W') R[i]++;
    }

    int ans = 1e9, pos = -1;
    rep(i, n + 1) if (L[i] + R[i] < ans)
    {
        ans = L[i] + R[i];
        pos = i;
    }
    cout << pos << " " << pos + 1 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4404
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int H, W;
    cin >> W >> H;
    vector<string> V(H);
    vector<int> cnt(W + 1);
    for (int i = 0; i < H; i++) {
        cin >> V[i];
    }
    for (int j = 0; j < W; j++) {
        cnt[j + 1] = cnt[j];
        for (int i = 0; i < H; i++) {
            cnt[j + 1] += V[i][j] == 'E';
        }
    }
    int ans = 0, cost = H * W - cnt[W];
    for (int i = 0; i <= W; i++) {
        int now = cnt[i] * 2 - cnt[W] + H * (W - i);
        if (now < cost) {
            cost = now;
            ans = i;
        }
    }
    cout << ans << " " << ans + 1 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4344
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;

string d[100];
int sumL[10010], sumR[10010];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> d[i];
    }
    for (int i = 0; i < n; i++) {
        sumL[i + 1] = sumL[i];
        for (int j = 0; j < m; j++) {
            sumL[i + 1] += (d[j][i] == 'E');
        }
    }
    for (int i = n; i >= 1; i--) {
        sumR[i] = sumR[i + 1];
        for (int j = 0; j < m; j++) {
            sumR[i] += (d[j][i - 1] == 'W');
        }
    }
    int mi = 1 << 30;
    int idx = 0;
    for (int i = 0; i <= n; i++) {
        if (mi > sumL[i] + sumR[i + 1]) {
            mi = sumL[i] + sumR[i + 1];
            idx = i;
        }
    }
    cout << idx << " " << idx + 1 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4712
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n, m;
vector<string> s;
vector<int> wcnt, ecnt;

int solve();

int main() {
  cin >> n >> m;
  s.resize(m);
  for (auto &p : s) cin >> p;
  int res = solve();
  cout << res << " " << res + 1 << endl;
  return 0;
}

int solve() {
  wcnt.assign(n + 1, 0);
  ecnt.assign(n + 1, 0);
  for (int j = 0; j < m; ++j)
    for (int i = 0; i < n; ++i) {
      ecnt[i + 1] += s[j][i] == 'E';
      wcnt[i] += s[j][i] == 'W';
    }
  for (int i = 0; i < n; ++i) ecnt[i + 1] += ecnt[i];
  for (int i = n - 1; i >= 0; --i) wcnt[i] += wcnt[i + 1];
  int res = 0;
  for (int i = 0; i <= n; ++i)
    if (ecnt[i] + wcnt[i] < ecnt[res] + wcnt[res]) res = i;
  return res;
}
accuracy: 1
time_ms: 10
memory_kb: 4688
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> w(n+1), e(n+1);
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j) {
            if (s[j] == 'W') {
                w[j+1]++;
            } else {
                e[j+1]++;
            }
        }
    }
    for (int i = 0; i < n; ++i) w[i+1] += w[i], e[i+1] += e[i];

    int mn = INT_MAX;
    int id = 0;
    for (int i = 0; i <= n; ++i) {
        int le = e[i] - e[0];
        int rw = w[n] - w[i];
        if (le + rw < mn) id = i, mn = le + rw;
    }
    cout << id << ' ' << id + 1 << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3536
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define var auto

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> fw(n, 0);
  int wSum, eSum = 0;
  for (int i = 0; i < m; i++){
    string s;
    cin >> s;
    for (int j = 0; j < n; j++){
      if (s[j] == 'W') fw[j]++;
    }
  }
  for (int i = 0; i < n; i++){
    wSum += fw[i];
  }
  int mi = wSum + eSum;
  //cout << mi << endl;
  int mind = -1;
  for (int i = 0; i < n; i++){
    int w = fw[i];
    int e = m - fw[i];
    wSum -= w;
    eSum += e;
    var cur = wSum + eSum;
    //cout << cur << endl;
    if (cur < mi){
      mi = cur;
      mind = i;
    }
  }
  cout << mind + 1 << " " << mind + 2 << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3300
final_rank: 13

code_snippet: #include <iostream>
#include <string>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    string d[102];
    for(int i = 0; i < m; i++) cin >> d[i];
    int s[102][10005];
    for(int i = 0; i < m; i++){
        s[i][0] = 0;
        for(int j = 1; j <= n; j++){
            s[i][j] = s[i][j - 1];
            if(d[i][j - 1] == 'W') s[i][j]++;
        }
    }
    int l = 100000000, ans;
    for(int j = 0; j <= n; j++){
        int c = 0;
        for(int i = 0; i < m; i++) c += (j - s[i][j]) + s[i][n] - s[i][j];
        if(c < l){
            l = c;
            ans = j;
        }
    }
    cout << ans << " " << ans + 1 << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 8552
final_rank: 18

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll H, W;
string S[10500];
ll okW = 0;
ll okE = 0;
ll ans;
ll ansval;
int main() {
  cin >> W >> H;
  for(int h = 0; h < H; h++) {
    cin >> S[h];
    for(int w = 0; w < W; w++) {
      if(S[h][w] == 'E') okE++;
    }
  }
  ansval = okE;
  for(ll w = 0; w < W; w++) {
    for(ll h = 0; h < H; h++) {
      if(S[h][w] == 'E') okE--;
      else okW++;
    }
    if(chmax(ansval, okE + okW)) {
      ans = w + 1;
    }
  }
  cout << ans << " " << ans + 1 << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4924
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000




int main(){
	
	int H,W;
	cin>>W>>H;
	
	vector<string> S(H);
	for(int i=0;i<H;i++){
		cin>>S[i];
	}
	int l=0,r=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S[i][j]=='W')r++;
		}
	}
	
	int ans = l+r;
	int now = 0;
	
	for(int i=0;i<W;i++){
		for(int j=0;j<H;j++){
			if(S[j][i]=='W')r--;
			else l++;
		}
		if(l+r<ans){
			ans = l+r;
			now = i+1;
		}
	}
	
	cout<<now<<' '<<now+1<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4476
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i,n) for (int i=0; i<(n); ++i)
#define RREP(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i,a,n) for (int i=(a); i<(n); ++i)
#define RFOR(i,a,n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    REP (i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) { a = b; return true; }
    return false;
}

const ll MOD = 1e9+7;
const ld EPS = 1e-9;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<typename T>
struct edge {
    int src, to;
    T cost;

    friend ostream &operator<<(ostream &os, const edge &e) {
        return os << "(" << e.src << "->" << e.to << ":" << e.cost << ")";
    }
};

template<typename T>
using Graph = vector<vector<edge<T>>>;

template<int64_t mod>
class modint {
    int64_t x;

public:
    modint(int64_t x = 0) : x(x < 0 ? ((x % mod) + mod) % mod : x % mod) {}

    const modint operator-() const { return x ? mod - x : 0; }

    modint &operator+=(const modint &rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }

    modint &operator-=(const modint &rhs) {
        return *this += -rhs;
    }

    modint &operator*=(const modint &rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }

    modint &operator/=(const modint &rhs) {
        return *this *= rhs.pow(mod - 2);
    }

    friend const modint operator+(modint lhs, const modint &rhs) {
        return lhs += rhs;
    }

    friend const modint operator-(modint lhs, const modint &rhs) {
        return lhs -= rhs;
    }

    friend const modint operator*(modint lhs, const modint &rhs) {
        return lhs *= rhs;
    }

    friend const modint operator/(modint lhs, const modint &rhs) {
        return lhs /= rhs;
    }

    const modint pow(int64_t n) const {
        modint ret = 1, tmp = *this;
        while (n) {
            if (n & 1) ret *= tmp;
            tmp *= tmp;
            n >>= 1;
        }
        return ret;
    }

    friend bool operator==(const modint &lhs, const modint &rhs) {
        return lhs.x == rhs.x;
    }

    friend bool operator!=(const modint &lhs, const modint &rhs) {
        return !(lhs == rhs);
    }

    friend ostream &operator<<(ostream &os, const modint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        int64_t tmp;
        is >> tmp;
        a = tmp;
        return is;
    }
};


using Real = double;
const Real PI = acos(-1);

struct Point3D {
    double x, y, z;

    Point3D() {}

    Point3D(double x, double y, double z) : x(x), y(y), z(z) {}

    Point3D operator+(const Point3D &b) const {
        return Point3D(x + b.x, y + b.y, z + b.z);
    }

    Point3D operator-(const Point3D &b) const {
        return Point3D(x - b.x, y - b.y, z - b.z);
    }

    friend double norm(const Point3D &p) {
        return p.x * p.x + p.y * p.y + p.z * p.z;
    };

    friend double abs(const Point3D &p) { return sqrt(norm(p)); }

    friend ostream &operator<<(ostream &os, Point3D &p) {
        return os << "(" << p.x << "," << p.y << "," << p.z << ")";
    }

    friend istream &operator>>(istream &is, Point3D &p) {
        return is >> p.x >> p.y >> p.z;
    }
};

struct Segment3D {
    Point3D a, b;

    Segment3D() {}

    Segment3D(const Point3D &a, const Point3D &b) : a(a), b(b) {}

    friend ostream &operator<<(ostream &os, Segment3D &l) {
        return os << "[" << l.a << "," << l.b << "]";
    }

    friend istream &operator>>(istream &is, Segment3D &l) {
        return is >> l.a >> l.b;
    }
};

inline bool eq(Real a, Real b) { return abs(b - a) < EPS; }

double dot(const Point3D &a, const Point3D &b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

Point3D cross(const Point3D &a, const Point3D &b) {
    double x = a.y * b.z - a.z * b.y,
            y = a.z * b.x - a.x * b.z,
            z = a.x * b.y - a.y * b.x;
    return Point3D(x, y, z);
}

bool parallel(
        const Point3D &a1, const Point3D &a2,
        const Point3D &b1, const Point3D &b2) {
    return eq(abs(cross(a1 - b1, a2 - b2)), 0.);
}

bool parallel(const Segment3D &l1, const Segment3D &l2) {
    return parallel(l1.a, l1.b, l2.a, l2.b);
}

double distance(const Segment3D &l, const Point3D &p) {
    if (dot(l.b - l.a, p - l.a) < EPS) return abs(p - l.a);
    if (dot(l.a - l.b, p - l.b) < EPS) return abs(p - l.b);
    return abs(cross(l.b - l.a, p - l.a)) / abs(l.b - l.a);
}


int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    int n, m; cin >> n >> m;
    vi ws(n + 1), es(n + 1);
    REP(i, m) {
        string s; cin >> s;
        REP(j, n) {
            if (s[j] == 'W') ++ws[j + 1];
            if (s[j] == 'E') ++es[j + 1];
        }
    }
    REP(i, n) ws[i + 1] += ws[i], es[i + 1] += es[i];

    int ma = es[n], ans = 0;
    REP(i, n) {
        if (chmax(ma, ws[i + 1] + (es[n] - es[i + 1]))) {
            ans = i + 1;
        }
    }
    cout << ans << ' ' << ans + 1 << endl;

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3336
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
int INF = 10000000;
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<char>> d(m, vector<char>(n));
  for (int i = 0; i < m; i++){
    for (int j = 0; j < n; j++){
      cin >> d[i][j];
    }
  }
  vector<int> L(n + 1, 0);
  for (int i = 0; i < n; i++){
    L[i + 1] = L[i];
    for (int j = 0; j < m; j++){
      if (d[j][i] == 'E'){
        L[i + 1]++;
      }
    }
  }
  vector<int> R(n + 1, 0);
  for (int i = n - 1; i >= 0; i--){
    R[i] = R[i + 1];
    for (int j = 0; j < m; j++){
      if (d[j][i] == 'W'){
        R[i]++;
      }
    }
  }
  int ans = INF;
  int pos = -1;
  for (int i = 0; i <= n; i++){
    if (L[i] + R[i] < ans){
      ans = L[i] + R[i];
      pos = i;
    }
  }
  cout << pos << ' ' << pos + 1 << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3948
final_rank: 19

code_snippet: #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);
}
accuracy: 1
time_ms: 30
memory_kb: 4268
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define var auto

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> fw(n, 0);
  int wSum, eSum = 0;
  for (int i = 0; i < m; i++){
    string s;
    cin >> s;
    for (int j = 0; j < n; j++){
      if (s[j] == 'W') fw[j]++;
    }
  }
  for (int i = 0; i < n; i++){
    wSum += fw[i];
  }
  int mi = wSum + eSum;
  //cout << mi << endl;
  int mind = -1;
  for (int i = 0; i < n; i++){
    int w = fw[i];
    int e = m - fw[i];
    wSum -= w;
    eSum += e;
    var cur = wSum + eSum;
    //cout << cur << endl;
    if (cur < mi){
      mi = cur;
      mind = i;
    }
  }
  cout << mind + 1 << " " << mind + 2 << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3216
final_rank: 12