stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int maxn=1000000;

int main()

{

    int n,w[maxn],ans,m,tmp;

    char rank[maxn];

    while(~scanf("%d",&n))

    {

        scanf("%s",rank+1);

        fill(w+1,w+n,0);

        for(int i=n;i>=1;i--)

        {

            w[i]=w[i+1];

            if(rank[i]=='W') w[i]++;

        }

        m=w[1];

        ans=maxn;

        for(int i=n;i>=1;i--)

        {

            tmp=((n-i)-w[i+1])+(m-w[i]);

            ans=min(ans,tmp);

        }

        printf("%d\n",ans);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1018487535786607x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<string>

#include<iostream>

#include<algorithm>

using namespace std;



int n;

int numw, nume;

string str;



int main()

{

    cin >> n;

    cin >> str;

    for (int i = 0; i < n; ++i)

        if (str[i] == 'W')

            ++numw;



    int maxs, ans = 0;

    for (int i = 0; i < n; ++i)

    {

        if (str[i] == 'W')

            numw--;

        maxs = numw + nume;

        ans = max(ans, maxs);

        if (str[i] == 'E')

            nume++;

    }

    cout << n - ans - 1 << endl;



	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int maxn=1000000;

int main()

{

    int n,w[maxn],ans,m,tmp;

    char rank[maxn];

    while(~scanf("%d",&n))

    {

        scanf("%s",rank+1);

        fill(w+1,w+n,0);

        for(int i=n;i>=1;i--)

        {

            w[i]=w[i+1];

            if(rank[i]=='W') w[i]++;

        }

        m=w[1];

        ans=maxn;

        for(int i=n;i>=1;i--)

        {

            tmp=((n-i)-w[i+1])+(m-w[i]);

            ans=min(ans,tmp);

        }

        printf("%d\n",ans);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1071260984557632x):
// Author : Mohamed Sameh

#include <bits/stdc++.h>

typedef long long ll ;

#define pb push_back

#define f first

#define s second

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define SZ(a) (int)a.size()

#define Flush fflush(stdout);

using namespace std ;

int main()

{



    int n ;

    string s ;

    cin >> n >> s ;

    int W= 0 ;

    /// W ||  E

    int E = 0 ;

    for (int i =0 ; i < n ;i++)

    {

        if (s[i] == 'E')E++;

    }

    int ans = n+1;

    for (int i =0 ; i < n ;i++)

    {

        if (s[i] == 'E')E--;

        ans = min (ans , W + E );

        if (s[i] == 'W')W++;

    }

    printf ("%d\n" ,ans );



}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;



char s[300005];

int cnt1[300005];

int cnt2[300005];

int main()

{

	int n;

	cin>>n>>s;

	int tem1=0,tem2=0;

	memset(cnt1,0,sizeof(cnt1));

	memset(cnt2,0,sizeof(cnt2));

	for(int i=0,j=n-1;i<n;i++,j--)

	{

		cnt1[i]=tem1;

		cnt2[j]=tem2;

		if(s[i]=='W')	tem1++;

		if(s[j]=='E')	tem2++;

	}

	

	int ans=1e8;

	for(int i=0;i<n;i++)

	{

		if(ans>cnt1[i]+cnt2[i])	ans=cnt1[i]+cnt2[i];

	}

	

	cout<<ans<<endl;

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4205045262888474x):
// Author : Mohamed Sameh

#include <bits/stdc++.h>

typedef long long ll ;

#define pb push_back

#define f first

#define s second

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define SZ(a) (int)a.size()

#define Flush fflush(stdout);

using namespace std ;

int main()

{



    int n ;

    string s ;

    cin >> n >> s ;

    int W= 0 ;

    /// W ||  E

    int E = 0 ;

    for (int i =0 ; i < n ;i++)

    {

        if (s[i] == 'E')E++;

    }

    int ans = n+1;

    for (int i =0 ; i < n ;i++)

    {

        if (s[i] == 'E')E--;

        ans = min (ans , W + E );

        if (s[i] == 'W')W++;

    }

    printf ("%d\n" ,ans );



}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



const int maxn=1000000;

int main()

{

    int n,w[maxn],ans,m,tmp;

    char rank[maxn];

    while(~scanf("%d",&n))

    {

        scanf("%s",rank+1);

        fill(w+1,w+n,0);

        for(int i=n;i>=1;i--)

        {

            w[i]=w[i+1];

            if(rank[i]=='W') w[i]++;

        }

        m=w[1];

        ans=maxn;

        for(int i=n;i>=1;i--)

        {

            tmp=((n-i)-w[i+1])+(m-w[i]);

            ans=min(ans,tmp);

        }

        printf("%d\n",ans);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1076483418241283x):
#include <bits/stdc++.h>

using namespace std ;

#define ll long long

void FastInputOutput(){

    ios_base :: sync_with_stdio( 0 ) ;

    cin.tie( 0 ) ;

    cout.tie( 0 ) ;

}



inline int D(){

    int t ;

    scanf( "%d" , &t ) ;

    return t ;

}

inline ll LLD(){

    ll t ;

    scanf( "%lld" , &t ) ;

    return t ;

}

inline ll power(ll x, ll p, ll m){

    ll res = 1;

    while(p){

        if(p & 1)

            res = ((res % m) * (x % m)) % m;

        x = ((x % m) * (x % m)) % m;

        p >>= 1;

    }

    return res % m;

}

long double ModLog(long double base, long double x) {

    return (logl(x) / logl(base));

}

int gcd (int a, int b) {

    while (b) {

        a %= b;

        swap(a, b);

    }

    return a;

}

int lcm(int a, int b){

    return a / gcd(a, b) * b;

}

const ll P = 1e9 + 9;

const int N = 1e6 + 1;



char a[N];

int cml[N], cmr[N];

int main(){

    int n = D();

    scanf("%s", a);

    for(int i = 1; i <= n; ++i){

        cml[i] = cml[i - 1] + (a[i - 1] == 'W');

    }

    for(int i = n; i > 0; --i){

        cmr[i] = cmr[i + 1] + (a[i - 1] == 'W');

    }

    int ans = INT_MAX;

    for(int i = 1; i <= n; ++i){

        int el = (i - 1) - cml[i - 1];

        int er = (n - i) - cmr[i + 1];

        ans = min(ans, (cml[i - 1]) + er);

        //printf("pos : %d wl = %d  el = %d wr = %d er = %d\n", i, cml[i - 1], el, cmr[i + 1], er);

    }

    printf("%d", ans);

    

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;



char s[300005];

int cnt1[300005];

int cnt2[300005];

int main()

{

	int n;

	cin>>n>>s;

	int tem1=0,tem2=0;

	memset(cnt1,0,sizeof(cnt1));

	memset(cnt2,0,sizeof(cnt2));

	for(int i=0,j=n-1;i<n;i++,j--)

	{

		cnt1[i]=tem1;

		cnt2[j]=tem2;

		if(s[i]=='W')	tem1++;

		if(s[j]=='E')	tem2++;

	}

	

	int ans=1e8;

	for(int i=0;i<n;i++)

	{

		if(ans>cnt1[i]+cnt2[i])	ans=cnt1[i]+cnt2[i];

	}

	

	cout<<ans<<endl;

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4221180153103856x):
#include <bits/stdc++.h>

using namespace std ;

#define ll long long

void FastInputOutput(){

    ios_base :: sync_with_stdio( 0 ) ;

    cin.tie( 0 ) ;

    cout.tie( 0 ) ;

}



inline int D(){

    int t ;

    scanf( "%d" , &t ) ;

    return t ;

}

inline ll LLD(){

    ll t ;

    scanf( "%lld" , &t ) ;

    return t ;

}

inline ll power(ll x, ll p, ll m){

    ll res = 1;

    while(p){

        if(p & 1)

            res = ((res % m) * (x % m)) % m;

        x = ((x % m) * (x % m)) % m;

        p >>= 1;

    }

    return res % m;

}

long double ModLog(long double base, long double x) {

    return (logl(x) / logl(base));

}

int gcd (int a, int b) {

    while (b) {

        a %= b;

        swap(a, b);

    }

    return a;

}

int lcm(int a, int b){

    return a / gcd(a, b) * b;

}

const ll P = 1e9 + 9;

const int N = 1e6 + 1;



char a[N];

int cml[N], cmr[N];

int main(){

    int n = D();

    scanf("%s", a);

    for(int i = 1; i <= n; ++i){

        cml[i] = cml[i - 1] + (a[i - 1] == 'W');

    }

    for(int i = n; i > 0; --i){

        cmr[i] = cmr[i + 1] + (a[i - 1] == 'W');

    }

    int ans = INT_MAX;

    for(int i = 1; i <= n; ++i){

        int el = (i - 1) - cml[i - 1];

        int er = (n - i) - cmr[i + 1];

        ans = min(ans, (cml[i - 1]) + er);

        //printf("pos : %d wl = %d  el = %d wr = %d er = %d\n", i, cml[i - 1], el, cmr[i + 1], er);

    }

    printf("%d", ans);

    

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;



char s[300005];

int cnt1[300005];

int cnt2[300005];

int main()

{

	int n;

	cin>>n>>s;

	int tem1=0,tem2=0;

	memset(cnt1,0,sizeof(cnt1));

	memset(cnt2,0,sizeof(cnt2));

	for(int i=0,j=n-1;i<n;i++,j--)

	{

		cnt1[i]=tem1;

		cnt2[j]=tem2;

		if(s[i]=='W')	tem1++;

		if(s[j]=='E')	tem2++;

	}

	

	int ans=1e8;

	for(int i=0;i<n;i++)

	{

		if(ans>cnt1[i]+cnt2[i])	ans=cnt1[i]+cnt2[i];

	}

	

	cout<<ans<<endl;

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.378503448805413x):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    string s;

    cin >> n >> s;

    int cnt1[n] = {0}, cnt2[n] = {0};

    (s[0] == 'W') ? cnt1[0] = 1 : cnt2[0] = 1;

    for (int i = 1; i < n; i++)

    {

        if (s[i] == 'W')

        {

            cnt1[i] = cnt1[i-1] + 1;

            cnt2[i] = cnt2[i-1];

        }

        else

        {

            cnt2[i] = cnt2[i-1] + 1;

            cnt1[i] = cnt1[i-1];

        }



    }

    int minn = min(cnt2[n-1]-cnt2[0], cnt1[n-1]);

    for (int i = 1; i < n-1; i++)

    {

        if (minn > cnt2[n-1]-cnt2[i] + cnt1[i-1])

            minn = cnt2[n-1]-cnt2[i] + cnt1[i-1];

    }

    cout << minn << endl;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;



char s[300005];

int cnt1[300005];

int cnt2[300005];

int main()

{

	int n;

	cin>>n>>s;

	int tem1=0,tem2=0;

	memset(cnt1,0,sizeof(cnt1));

	memset(cnt2,0,sizeof(cnt2));

	for(int i=0,j=n-1;i<n;i++,j--)

	{

		cnt1[i]=tem1;

		cnt2[j]=tem2;

		if(s[i]=='W')	tem1++;

		if(s[j]=='E')	tem2++;

	}

	

	int ans=1e8;

	for(int i=0;i<n;i++)

	{

		if(ans>cnt1[i]+cnt2[i])	ans=cnt1[i]+cnt2[i];

	}

	

	cout<<ans<<endl;

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.3215836808110537x):
#include <bits/stdc++.h>



void optimize_cp_stdio() {

    std::ios::sync_with_stdio(false);

    std::cout.tie(nullptr);

    std::cin.tie(nullptr);

}



int main() {

    optimize_cp_stdio();

    int n;

    std::string s;

    std::cin >> n >> s;

    std::vector<int> prefix(n), suffix(n);

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

        prefix[i] = s[i] == 'W';

        suffix[i] = s[i] == 'E';

    }

    std::partial_sum(prefix.begin(), prefix.end(), prefix.begin());

    std::partial_sum(suffix.rbegin(), suffix.rend(), suffix.rbegin());

    int ans = INT_MAX;

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

        int cost = (i == 0 ? 0 : prefix[i - 1]) + (i + 1 == n ? 0 : suffix[i + 1]);

        ans = std::min(ans, cost);

    }

    std::cout << ans << "\n";

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;



char s[300005];

int cnt1[300005];

int cnt2[300005];

int main()

{

	int n;

	cin>>n>>s;

	int tem1=0,tem2=0;

	memset(cnt1,0,sizeof(cnt1));

	memset(cnt2,0,sizeof(cnt2));

	for(int i=0,j=n-1;i<n;i++,j--)

	{

		cnt1[i]=tem1;

		cnt2[j]=tem2;

		if(s[i]=='W')	tem1++;

		if(s[j]=='E')	tem2++;

	}

	

	int ans=1e8;

	for(int i=0;i<n;i++)

	{

		if(ans>cnt1[i]+cnt2[i])	ans=cnt1[i]+cnt2[i];

	}

	

	cout<<ans<<endl;

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.3760010304266714x):
#include <bits/stdc++.h>

using namespace std;



#define      ll      long long int



const int N = 300005;

int east[N];

int west[N];



int main( )

{

    int n, i, j, k, l;

    string s;

    cin >> n >> s;

    l = (int) s.size();

    s = "@" + s;

    for (i = 1; i <= n; i++) {

        west[i] += west[i - 1];

        if (s[i] == 'W') {

            west[i]++;

        }

    }

    for (i = n; i >= 1; i--) {

        east[i] += east[i + 1];

        if (s[i] == 'E') {

            east[i]++;

        }

    }

    int mn = 1e9;

    for (i = 1; i <= n; i++) {

        mn = min(mn, west[i - 1] + east[i + 1]);

    }

    cout << mn << '\n';

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;



char s[300005];

int cnt1[300005];

int cnt2[300005];

int main()

{

	int n;

	cin>>n>>s;

	int tem1=0,tem2=0;

	memset(cnt1,0,sizeof(cnt1));

	memset(cnt2,0,sizeof(cnt2));

	for(int i=0,j=n-1;i<n;i++,j--)

	{

		cnt1[i]=tem1;

		cnt2[j]=tem2;

		if(s[i]=='W')	tem1++;

		if(s[j]=='E')	tem2++;

	}

	

	int ans=1e8;

	for(int i=0;i<n;i++)

	{

		if(ans>cnt1[i]+cnt2[i])	ans=cnt1[i]+cnt2[i];

	}

	

	cout<<ans<<endl;

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.359443685521402x):
#include <bits/stdc++.h>

  

using namespace std;

  

template<class T> void ckmin(T &a, T b) { a = min(a, b); }

template<class T> void ckmax(T &a, T b) { a = max(a, b); }

  

#define pb push_back

#define mp make_pair

#define cotu cout

#define itn int

#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define F first

#define S second

#define sz(x) (int)x.size()

#define all(x) (x).begin(), (x).end()

#define rep(i, n) for(int i = 0; i < n; ++i)

#define repr(i,n) for(int i = n - 1; i >= 0; --i)

#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)

#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)

#define Repr(i, a, n) for(int i = (n); i >= (a); --i)

#define setp(x) fixed << setprecision(x)

#define o_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 

#define trav(it, v) for(auto &it : v)



#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 

  

typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;

  

const int inf = int(1e9);

const int mod = inf + 7;

const int N = 1e6 + 555; // TL MB

const double PI = acos(-1.0);

void mul(ll &x, ll y){

	x *= y;

	if(x >= mod) x %= mod;

}

 

void add(ll &x, ll y){

	x += y;

	if(x >= mod) x -= mod;

	if(x < 0) x += mod;

}

ll bp(ll a, ll n){

	ll r = 1;

	while(n){

		if(n & 1) mul(r, a);

		mul(a, a);

		n >>= 1;

	}

 	return r;

}





void solve()

{

	int n; string s;	

	cin >> n >> s;

	int e = 0, w = 0;

	rep(i, n) if(s[i] == 'E') ++e; else ++w;

	int pre = 0;

	int res = inf;

	rep(i, n) {

		if(s[i] == 'E') --e;

		else --w;

		res = min(res, pre + e);

		if(s[i] == 'W') pre++;

 	}

 	cout << res;

}



int main()

{

    Red;

    // freopen("black.in", "r", stdin);

	// freopen("black.out", "w", stdout);

    int T = 1;

    // cin >> T;

    for(int i = 1; i <= T; ++i) {

    	// cout << "Case #" << i << ": ";

    	solve();

  	}

  	return 0;



}
// Slower C++ solution:
//先从左边先行扫描一遍，再从右边扫描一遍，两边加起来直接用总人数相减

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



        memset(l,0,sizeof(l));

        memset(r,0,sizeof(r));



        for(int i=0;i<n;i++)

        {

            l[i]=l[i-1];

            if(str[i]=='E') {

                    l[i]++;

            }

        }



        for(int i=n-1;i>=0;i--)

        {

            r[i]=r[i+1];

            if(str[i]=='W') {

                    r[i]++;

            }

        }





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

            r[i]=r[i]+l[i];

            maxx=max(r[i],maxx);

         }



         cout<<n-maxx<<endl;









        return 0;

    }


// Faster C++ solution for the same problem (measured speedup: 2.730077451871661x):
#include <iostream>

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

    memset(ans1,0,sizeof(ans1));

    memset(ans2,0,sizeof(ans2));

    //ans1[0]=1;

    for(int i=0;i<N;i++){

        if(s[i]=='E'){

            ans1[i]++;

        }

        ans1[i+1]=ans1[i];

    }

    //ans2[N-1]=1;

    for(int i=N-1;i>=0;i--){

        if(s[i]=='W'){

            ans2[i]++;

        }

        ans2[i-1]=ans2[i];

    }

    int maxx=0,t;

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

        t=ans1[j]+ans2[j];

        maxx=max(t,maxx);

    }

    printf("%d\n",N-maxx);

    return 0;

}
// Slower C++ solution:
//先从左边先行扫描一遍，再从右边扫描一遍，两边加起来直接用总人数相减

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



        memset(l,0,sizeof(l));

        memset(r,0,sizeof(r));



        for(int i=0;i<n;i++)

        {

            l[i]=l[i-1];

            if(str[i]=='E') {

                    l[i]++;

            }

        }



        for(int i=n-1;i>=0;i--)

        {

            r[i]=r[i+1];

            if(str[i]=='W') {

                    r[i]++;

            }

        }





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

            r[i]=r[i]+l[i];

            maxx=max(r[i],maxx);

         }



         cout<<n-maxx<<endl;









        return 0;

    }


// Faster C++ solution for the same problem (measured speedup: 48.63835398084879x):
#include<cstdio>

#include<cmath>

#include<algorithm>

using namespace std;

int n,ans=400000;

char a[300010];

int cnt[300010];

int main()

{

	scanf("%d%s",&n,a);

	if (a[0]=='E') cnt[0]=1;

	for (int i=1;i<n;i++)

	{

		if (a[i]=='E') cnt[i]=cnt[i-1]+1;

		else cnt[i]=cnt[i-1];

	}

	for (int i=0;i<n;i++)

	{

		int t;

		if (i!=0) t=cnt[n-1]-cnt[i]+i-cnt[i-1];

		else t=cnt[n-1]-cnt[i];

		if (ans>t) ans=t;

	}

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

    memset(ans1,0,sizeof(ans1));

    memset(ans2,0,sizeof(ans2));

    //ans1[0]=1;

    for(int i=0;i<N;i++){

        if(s[i]=='E'){

            ans1[i]++;

        }

        ans1[i+1]=ans1[i];

    }

    //ans2[N-1]=1;

    for(int i=N-1;i>=0;i--){

        if(s[i]=='W'){

            ans2[i]++;

        }

        ans2[i-1]=ans2[i];

    }

    int maxx=0,t;

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

        t=ans1[j]+ans2[j];

        maxx=max(t,maxx);

    }

    printf("%d\n",N-maxx);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 17.81574143528557x):
#include<cstdio>

#include<cmath>

#include<algorithm>

using namespace std;

int n,ans=400000;

char a[300010];

int cnt[300010];

int main()

{

	scanf("%d%s",&n,a);

	if (a[0]=='E') cnt[0]=1;

	for (int i=1;i<n;i++)

	{

		if (a[i]=='E') cnt[i]=cnt[i-1]+1;

		else cnt[i]=cnt[i-1];

	}

	for (int i=0;i<n;i++)

	{

		int t;

		if (i!=0) t=cnt[n-1]-cnt[i]+i-cnt[i-1];

		else t=cnt[n-1]-cnt[i];

		if (ans>t) ans=t;

	}

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
//先从左边先行扫描一遍，再从右边扫描一遍，两边加起来直接用总人数相减

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



        memset(l,0,sizeof(l));

        memset(r,0,sizeof(r));



        for(int i=0;i<n;i++)

        {

            l[i]=l[i-1];

            if(str[i]=='E') {

                    l[i]++;

            }

        }



        for(int i=n-1;i>=0;i--)

        {

            r[i]=r[i+1];

            if(str[i]=='W') {

                    r[i]++;

            }

        }





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

            r[i]=r[i]+l[i];

            maxx=max(r[i],maxx);

         }



         cout<<n-maxx<<endl;









        return 0;

    }


// Faster C++ solution for the same problem (measured speedup: 9.288616787506315x):
#include <iostream>





using namespace std;



int main() {

    int n,sum1=0,sum2=0,sum=0,k;

    cin>>n;

    char str[n];

    cin>>str;

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

        if(str[i]=='W'){

            sum++;

        }

    }

    k=n;

    

    

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

	    if(str[i]=='W'){sum2++;}

	    

	    if(sum1+n-(i+1)-(sum-sum2)<k){ k=sum1+n-(i+1)-(sum-sum2);

	        k=sum1+n-(i+1)-(sum-sum2);

	    }

	    sum1=sum2;

	    

	}



	cout<<k;

}
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

    memset(ans1,0,sizeof(ans1));

    memset(ans2,0,sizeof(ans2));

    //ans1[0]=1;

    for(int i=0;i<N;i++){

        if(s[i]=='E'){

            ans1[i]++;

        }

        ans1[i+1]=ans1[i];

    }

    //ans2[N-1]=1;

    for(int i=N-1;i>=0;i--){

        if(s[i]=='W'){

            ans2[i]++;

        }

        ans2[i-1]=ans2[i];

    }

    int maxx=0,t;

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

        t=ans1[j]+ans2[j];

        maxx=max(t,maxx);

    }

    printf("%d\n",N-maxx);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.402327205456502x):
#include <iostream>





using namespace std;



int main() {

    int n,sum1=0,sum2=0,sum=0,k;

    cin>>n;

    char str[n];

    cin>>str;

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

        if(str[i]=='W'){

            sum++;

        }

    }

    k=n;

    

    

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

	    if(str[i]=='W'){sum2++;}

	    

	    if(sum1+n-(i+1)-(sum-sum2)<k){ k=sum1+n-(i+1)-(sum-sum2);

	        k=sum1+n-(i+1)-(sum-sum2);

	    }

	    sum1=sum2;

	    

	}



	cout<<k;

}
// Slower C++ solution:
//先从左边先行扫描一遍，再从右边扫描一遍，两边加起来直接用总人数相减

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



        memset(l,0,sizeof(l));

        memset(r,0,sizeof(r));



        for(int i=0;i<n;i++)

        {

            l[i]=l[i-1];

            if(str[i]=='E') {

                    l[i]++;

            }

        }



        for(int i=n-1;i>=0;i--)

        {

            r[i]=r[i+1];

            if(str[i]=='W') {

                    r[i]++;

            }

        }





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

            r[i]=r[i]+l[i];

            maxx=max(r[i],maxx);

         }



         cout<<n-maxx<<endl;









        return 0;

    }


// Faster C++ solution for the same problem (measured speedup: 9.057278673711917x):
#include <bits/stdc++.h>

using namespace std ;



#define inf 0x3f3f3f3f

#define INF 1000111000111000111LL

#define mod 1000000007

#define pi acos(-1.0)

#define eps 1e-8

#define endl '\n'

#define mp make_pair

#define mt make_tuple

#define pb push_back

#define fi first

#define se second

#define all(cc) (cc).begin(),(cc).end()

using lli = long long int ;

using pii = pair<int, int> ;

using vi = vector<int> ;

using vb = vector<bool> ;

using vvi = vector<vector<int>> ;

using vlli = vector<long long int> ;

using vpii = vector<pair<int, int>> ;



int main()

  {

    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;

    int n, ans=inf ;

    string s ;

    cin>> n >> s ;

    s='#'+s ;

    vi cntW(n+1, 0), cntE(n+1, 0) ;

    for(int i=1 ; i<=n ; i++)

      {

        cntW[i]=cntW[i-1]+(s[i]=='W') ;

        cntE[i]=cntE[i-1]+(s[i]=='E') ;

      }

    for(int i=1 ; i<=n ; i++) ans=min(ans, cntW[i-1]+cntE[n]-cntE[i]) ;

    cout<< ans ;

  }