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



using namespace std;

string s;

int Min=999999;//a==W,,b=E

int num[1000005];

int main()

{

    int n;

    int tmp;

    cin>>n>>s;

    tmp=0;

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

        num[i]=tmp;

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

    }

    tmp=0;

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

        num[i]+=tmp;

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

    }

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

        Min=min(Min,num[i]);

    cout<<Min<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.29351121443635x):
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>

#include <cctype>

#include <ctime>

#include <set>

#include <algorithm>



namespace LegitStream

{

char bufdatum[BUFSIZ];

char *buf = bufdatum, *endbuf = bufdatum;



inline bool eof(void)

{

    if (endbuf == buf)

    {

        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);

        return endbuf == buf;

    }

    else

        return false;

}



inline int nextch(void)

{

    return eof() ? EOF : *buf++;

}



void legit(void) {}



template<typename Car, typename ...Cdr>

void legit(Car &var, Cdr &...Rest)

{

    int peek;

    while (!isdigit(peek = nextch())

#ifdef LEGIT_NEGI

        && peek != '-'

#endif  // LEGIT_NEGI

        )

        ;

#ifdef LEGIT_NEGI

    bool negi;

    if (peek == '-')

        negi = true;

    else

        negi = false;

#endif  // LEGIT_NEGI

    var = 0;

    do

        var = (((var << 2) + var) << 1) + (peek ^ '0');

    while (isdigit(peek = nextch()));

#ifdef LEGIT_NEGI

    if (negi)

        var = -var;

#endif  // LEGIT_NEGI

    legit(Rest...);

}

}

using LegitStream::nextch;

using LegitStream::eof;

using LegitStream::legit;



void solve(void);



int main(void)

{

#ifdef redirect

    freopen("check/data.in", "r", stdin);

    freopen("check/prog.out", "w", stdout);

    freopen("check/log.out", "w", stderr);

#endif  // redirect

#ifdef chrono

    auto begtm = clock();

#endif  // chrono

    solve();

#ifdef chrono

    auto endtm = clock();

    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);

#endif  // chrono

    return 0;

}



enum class Direction

{

    Left,

    Right,

};



const size_t MaxN = size_t(3e5 + 7);



size_t n;

Direction queue[MaxN];

size_t tol[MaxN], tor[MaxN];



void solve(void)

{

    legit(n);

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

        queue[i] = nextch() == 'W' ? Direction::Left : Direction::Right;

    tor[0] = (queue[0] == Direction::Right);

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

        tor[i] = tor[i - 1] + (queue[i] == Direction::Right);

    tol[n - 1] = (queue[n - 1] == Direction::Left);

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

        tol[i] = tol[i + 1] + (queue[i] == Direction::Left);



    size_t ans = 19260817;

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

        ans = std::min(ans, n - 1 - tor[i - 1] - tol[i + 1]);

    ans = std::min(ans, n - 1 - tol[1]);

    ans = std::min(ans, n - 1 - tor[n - 2]);

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

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

using namespace std;



int n;

string str;



int main(){

	cin >> n;

	cin >> str;



	int cc=0;



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

		if(str[i]=='E')	cc++;

	}



	int mx=cc;



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

		if(str[i]=='E')	cc--;

		else	cc++;



		mx=min(mx,cc);

	}



	cout << mx << endl;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.293585159025233x):
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>

#include <cctype>

#include <ctime>

#include <set>

#include <algorithm>



namespace LegitStream

{

char bufdatum[BUFSIZ];

char *buf = bufdatum, *endbuf = bufdatum;



inline bool eof(void)

{

    if (endbuf == buf)

    {

        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);

        return endbuf == buf;

    }

    else

        return false;

}



inline int nextch(void)

{

    return eof() ? EOF : *buf++;

}



void legit(void) {}



template<typename Car, typename ...Cdr>

void legit(Car &var, Cdr &...Rest)

{

    int peek;

    while (!isdigit(peek = nextch())

#ifdef LEGIT_NEGI

        && peek != '-'

#endif  // LEGIT_NEGI

        )

        ;

#ifdef LEGIT_NEGI

    bool negi;

    if (peek == '-')

        negi = true;

    else

        negi = false;

#endif  // LEGIT_NEGI

    var = 0;

    do

        var = (((var << 2) + var) << 1) + (peek ^ '0');

    while (isdigit(peek = nextch()));

#ifdef LEGIT_NEGI

    if (negi)

        var = -var;

#endif  // LEGIT_NEGI

    legit(Rest...);

}

}

using LegitStream::nextch;

using LegitStream::eof;

using LegitStream::legit;



void solve(void);



int main(void)

{

#ifdef redirect

    freopen("check/data.in", "r", stdin);

    freopen("check/prog.out", "w", stdout);

    freopen("check/log.out", "w", stderr);

#endif  // redirect

#ifdef chrono

    auto begtm = clock();

#endif  // chrono

    solve();

#ifdef chrono

    auto endtm = clock();

    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);

#endif  // chrono

    return 0;

}



enum class Direction

{

    Left,

    Right,

};



const size_t MaxN = size_t(3e5 + 7);



size_t n;

Direction queue[MaxN];

size_t tol[MaxN], tor[MaxN];



void solve(void)

{

    legit(n);

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

        queue[i] = nextch() == 'W' ? Direction::Left : Direction::Right;

    tor[0] = (queue[0] == Direction::Right);

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

        tor[i] = tor[i - 1] + (queue[i] == Direction::Right);

    tol[n - 1] = (queue[n - 1] == Direction::Left);

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

        tol[i] = tol[i + 1] + (queue[i] == Direction::Left);



    size_t ans = 19260817;

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

        ans = std::min(ans, n - 1 - tor[i - 1] - tol[i + 1]);

    ans = std::min(ans, n - 1 - tol[1]);

    ans = std::min(ans, n - 1 - tor[n - 2]);

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

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



using namespace std;



int n;

char str[300100];

int main() {

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



	int sum=0,ans=0;

	for(int i=0;i<n;i++) if(str[i]=='E') sum++;

	ans=sum;

	

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

		if(str[i]=='E') sum--;

		ans=min(ans,sum);

		if(str[i]=='W') sum++;

	}

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

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.22675403959289x):
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>

#include <cctype>

#include <ctime>

#include <set>

#include <algorithm>



namespace LegitStream

{

char bufdatum[BUFSIZ];

char *buf = bufdatum, *endbuf = bufdatum;



inline bool eof(void)

{

    if (endbuf == buf)

    {

        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);

        return endbuf == buf;

    }

    else

        return false;

}



inline int nextch(void)

{

    return eof() ? EOF : *buf++;

}



void legit(void) {}



template<typename Car, typename ...Cdr>

void legit(Car &var, Cdr &...Rest)

{

    int peek;

    while (!isdigit(peek = nextch())

#ifdef LEGIT_NEGI

        && peek != '-'

#endif  // LEGIT_NEGI

        )

        ;

#ifdef LEGIT_NEGI

    bool negi;

    if (peek == '-')

        negi = true;

    else

        negi = false;

#endif  // LEGIT_NEGI

    var = 0;

    do

        var = (((var << 2) + var) << 1) + (peek ^ '0');

    while (isdigit(peek = nextch()));

#ifdef LEGIT_NEGI

    if (negi)

        var = -var;

#endif  // LEGIT_NEGI

    legit(Rest...);

}

}

using LegitStream::nextch;

using LegitStream::eof;

using LegitStream::legit;



void solve(void);



int main(void)

{

#ifdef redirect

    freopen("check/data.in", "r", stdin);

    freopen("check/prog.out", "w", stdout);

    freopen("check/log.out", "w", stderr);

#endif  // redirect

#ifdef chrono

    auto begtm = clock();

#endif  // chrono

    solve();

#ifdef chrono

    auto endtm = clock();

    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);

#endif  // chrono

    return 0;

}



enum class Direction

{

    Left,

    Right,

};



const size_t MaxN = size_t(3e5 + 7);



size_t n;

Direction queue[MaxN];

size_t tol[MaxN], tor[MaxN];



void solve(void)

{

    legit(n);

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

        queue[i] = nextch() == 'W' ? Direction::Left : Direction::Right;

    tor[0] = (queue[0] == Direction::Right);

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

        tor[i] = tor[i - 1] + (queue[i] == Direction::Right);

    tol[n - 1] = (queue[n - 1] == Direction::Left);

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

        tol[i] = tol[i + 1] + (queue[i] == Direction::Left);



    size_t ans = 19260817;

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

        ans = std::min(ans, n - 1 - tor[i - 1] - tol[i + 1]);

    ans = std::min(ans, n - 1 - tol[1]);

    ans = std::min(ans, n - 1 - tor[n - 2]);

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

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



using namespace std;



const int N = 3e5+5;



typedef long long ll;



char s[N];



int a[N];



int flag[N];



int main()



{



    int n;



    string s;



    cin>>n>>s;



    int l=0,r=0;



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



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



    }



    int ans=n-r-1;



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



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



        if(s[i]=='W') r--;



        ans=min(ans,n-l-r-1);



    }



    cout<<ans<<endl;



}

// Faster C++ solution for the same problem (measured speedup: 5.3348595496478755x):
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>

#include <cctype>

#include <ctime>

#include <set>

#include <algorithm>



namespace LegitStream

{

char bufdatum[BUFSIZ];

char *buf = bufdatum, *endbuf = bufdatum;



inline bool eof(void)

{

    if (endbuf == buf)

    {

        endbuf = (buf = bufdatum) + fread(bufdatum, 1, BUFSIZ, stdin);

        return endbuf == buf;

    }

    else

        return false;

}



inline int nextch(void)

{

    return eof() ? EOF : *buf++;

}



void legit(void) {}



template<typename Car, typename ...Cdr>

void legit(Car &var, Cdr &...Rest)

{

    int peek;

    while (!isdigit(peek = nextch())

#ifdef LEGIT_NEGI

        && peek != '-'

#endif  // LEGIT_NEGI

        )

        ;

#ifdef LEGIT_NEGI

    bool negi;

    if (peek == '-')

        negi = true;

    else

        negi = false;

#endif  // LEGIT_NEGI

    var = 0;

    do

        var = (((var << 2) + var) << 1) + (peek ^ '0');

    while (isdigit(peek = nextch()));

#ifdef LEGIT_NEGI

    if (negi)

        var = -var;

#endif  // LEGIT_NEGI

    legit(Rest...);

}

}

using LegitStream::nextch;

using LegitStream::eof;

using LegitStream::legit;



void solve(void);



int main(void)

{

#ifdef redirect

    freopen("check/data.in", "r", stdin);

    freopen("check/prog.out", "w", stdout);

    freopen("check/log.out", "w", stderr);

#endif  // redirect

#ifdef chrono

    auto begtm = clock();

#endif  // chrono

    solve();

#ifdef chrono

    auto endtm = clock();

    printf("%f\n", static_cast<float>(endtm - begtm) / CLOCKS_PER_SEC);

#endif  // chrono

    return 0;

}



enum class Direction

{

    Left,

    Right,

};



const size_t MaxN = size_t(3e5 + 7);



size_t n;

Direction queue[MaxN];

size_t tol[MaxN], tor[MaxN];



void solve(void)

{

    legit(n);

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

        queue[i] = nextch() == 'W' ? Direction::Left : Direction::Right;

    tor[0] = (queue[0] == Direction::Right);

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

        tor[i] = tor[i - 1] + (queue[i] == Direction::Right);

    tol[n - 1] = (queue[n - 1] == Direction::Left);

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

        tol[i] = tol[i + 1] + (queue[i] == Direction::Left);



    size_t ans = 19260817;

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

        ans = std::min(ans, n - 1 - tor[i - 1] - tol[i + 1]);

    ans = std::min(ans, n - 1 - tol[1]);

    ans = std::min(ans, n - 1 - tor[n - 2]);

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

}
// Slower C++ solution:
/*

    Name: Attention

*/

#include "stdio.h"

bool debug=false;

int main()

{

    bool isstarteast=false,isbuffeast,iscureast;//west = false east = true

    int numamong[300010]={};

    int N,numberofdiffer=0;

    char buffer;

    scanf("%d",&N);

    scanf(" %c",&buffer);

    if(buffer=='E') isstarteast=true;

    else{

        numamong[1]=1;

        numberofdiffer++;

        iscureast=false;

    }

    //numberofdiffer is divisible by 2 when it is currently east

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

    {

        scanf(" %c",&buffer);

        if(buffer=='E') isbuffeast=true;

        else            isbuffeast=false;

        if(numberofdiffer==0)

        {

            if(!isbuffeast)

            {

                numamong[1]=1;

                numberofdiffer++;

                iscureast=false;

            }

            continue;

        }

        if(isbuffeast==iscureast)

        {

            numamong[numberofdiffer]++;

            continue;

            printf("hi");

        }

        numberofdiffer++;

        numamong[numberofdiffer]=1;

        iscureast=!iscureast;

    }

    if(numberofdiffer%2) numberofdiffer--;

    if(debug)

    {

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

        {

            if(i%2==0)  printf("E ");

            else        printf("W ");

            printf("%d\n",numamong[i]);

        }

    }

    int mins,caseallW=0;

    for(int i=2;i<=numberofdiffer;i+=2)

    {

        caseallW+=numamong[i];

    }

    mins=caseallW;

    int curcase=caseallW;

    for(int i=1;i<numberofdiffer;i+=2)

    {

        curcase+=numamong[i];

        curcase-=numamong[i+1];

        if(debug)

            printf("curcase of %d = %d\n",i,curcase);

        if(mins>curcase)

        {

            mins=curcase;

        }

    }

    printf("%d",mins);

}




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

using namespace std;

const int M = 1e6;

char s[M];

int a[M];

int main()

{

	int n, j;

	cin >> n;

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

	int left, right = 0;

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

	{

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

			a[i] = 1;

		else

			a[i] = 0;

		right += a[i];

	}

	left = 0;

	right = right - a[1];

	int min = 1e7, cnt;

	

	//   i == 1

	cnt = (n - 1) - right;

	if (cnt < min)

	{

		min = cnt;

		j = 1;

	}

	//    2 <= i <= n - 1

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

	{

		left += a[i - 1];

		right -= a[i];

		cnt = (n - i) - right + left;

		if (cnt < min)

		{

			min = cnt;

			j = i;

//			printf("r = %d, l = %d\n", right, left);

		}

	}

	// i == n

	left += a[n - 1];

	cnt = left;

	if (cnt < min)

	{

		min = cnt;

		j = n;

	}

		

	cout << min << endl;

	

	return 0;

}
// Slower C++ solution:
/*

    Name: Attention

*/

#include "stdio.h"

bool debug=false;

int main()

{

    bool isstarteast=false,isbuffeast,iscureast;//west = false east = true

    int numamong[300010]={};

    int N,numberofdiffer=0;

    char buffer;

    scanf("%d",&N);

    scanf(" %c",&buffer);

    if(buffer=='E') isstarteast=true;

    else{

        numamong[1]=1;

        numberofdiffer++;

        iscureast=false;

    }

    //numberofdiffer is divisible by 2 when it is currently east

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

    {

        scanf(" %c",&buffer);

        if(buffer=='E') isbuffeast=true;

        else            isbuffeast=false;

        if(numberofdiffer==0)

        {

            if(!isbuffeast)

            {

                numamong[1]=1;

                numberofdiffer++;

                iscureast=false;

            }

            continue;

        }

        if(isbuffeast==iscureast)

        {

            numamong[numberofdiffer]++;

            continue;

            printf("hi");

        }

        numberofdiffer++;

        numamong[numberofdiffer]=1;

        iscureast=!iscureast;

    }

    if(numberofdiffer%2) numberofdiffer--;

    if(debug)

    {

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

        {

            if(i%2==0)  printf("E ");

            else        printf("W ");

            printf("%d\n",numamong[i]);

        }

    }

    int mins,caseallW=0;

    for(int i=2;i<=numberofdiffer;i+=2)

    {

        caseallW+=numamong[i];

    }

    mins=caseallW;

    int curcase=caseallW;

    for(int i=1;i<numberofdiffer;i+=2)

    {

        curcase+=numamong[i];

        curcase-=numamong[i+1];

        if(debug)

            printf("curcase of %d = %d\n",i,curcase);

        if(mins>curcase)

        {

            mins=curcase;

        }

    }

    printf("%d",mins);

}




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



using namespace std ;



int main()

{

	ios_base::sync_with_stdio(0) ;

	cin.tie(0) ;

	int n ;

	cin>>n ;

	string s ;

	cin>>s ;

	int pref[n], suff[n] ;

	pref[0] = (s[0] == 'W') ;

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

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

	suff[n-1] = (s[n-1] == 'E') ;

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

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

	int ans = 1e9 ;

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

	{

		if(i == 0)

			ans = min(ans, suff[i+1]) ;

		else if(i == n-1)

			ans = min(ans , pref[i-1]) ;

		else

			ans = min(ans, pref[i-1] + suff[i+1]) ;

	}

	return cout<<ans<<"\n" , 0 ;

}
// Slower C++ solution:
/*

    Name: Attention

*/

#include "stdio.h"

bool debug=false;

int main()

{

    bool isstarteast=false,isbuffeast,iscureast;//west = false east = true

    int numamong[300010]={};

    int N,numberofdiffer=0;

    char buffer;

    scanf("%d",&N);

    scanf(" %c",&buffer);

    if(buffer=='E') isstarteast=true;

    else{

        numamong[1]=1;

        numberofdiffer++;

        iscureast=false;

    }

    //numberofdiffer is divisible by 2 when it is currently east

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

    {

        scanf(" %c",&buffer);

        if(buffer=='E') isbuffeast=true;

        else            isbuffeast=false;

        if(numberofdiffer==0)

        {

            if(!isbuffeast)

            {

                numamong[1]=1;

                numberofdiffer++;

                iscureast=false;

            }

            continue;

        }

        if(isbuffeast==iscureast)

        {

            numamong[numberofdiffer]++;

            continue;

            printf("hi");

        }

        numberofdiffer++;

        numamong[numberofdiffer]=1;

        iscureast=!iscureast;

    }

    if(numberofdiffer%2) numberofdiffer--;

    if(debug)

    {

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

        {

            if(i%2==0)  printf("E ");

            else        printf("W ");

            printf("%d\n",numamong[i]);

        }

    }

    int mins,caseallW=0;

    for(int i=2;i<=numberofdiffer;i+=2)

    {

        caseallW+=numamong[i];

    }

    mins=caseallW;

    int curcase=caseallW;

    for(int i=1;i<numberofdiffer;i+=2)

    {

        curcase+=numamong[i];

        curcase-=numamong[i+1];

        if(debug)

            printf("curcase of %d = %d\n",i,curcase);

        if(mins>curcase)

        {

            mins=curcase;

        }

    }

    printf("%d",mins);

}




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

using namespace std;



int n;

const int N=3e5 +5;

int E[N], W[N];

char a[N];



int main(){



    scanf("%d", &n);

    scanf(" %s", a);



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

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

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

    }



    int mn=n;

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

        int num=W[i]+(E[n]-E[i+1]);

        mn=min(mn, num);

    }



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



    return 0;

}
// Slower C++ solution:
/*

    Name: Attention

*/

#include "stdio.h"

bool debug=false;

int main()

{

    bool isstarteast=false,isbuffeast,iscureast;//west = false east = true

    int numamong[300010]={};

    int N,numberofdiffer=0;

    char buffer;

    scanf("%d",&N);

    scanf(" %c",&buffer);

    if(buffer=='E') isstarteast=true;

    else{

        numamong[1]=1;

        numberofdiffer++;

        iscureast=false;

    }

    //numberofdiffer is divisible by 2 when it is currently east

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

    {

        scanf(" %c",&buffer);

        if(buffer=='E') isbuffeast=true;

        else            isbuffeast=false;

        if(numberofdiffer==0)

        {

            if(!isbuffeast)

            {

                numamong[1]=1;

                numberofdiffer++;

                iscureast=false;

            }

            continue;

        }

        if(isbuffeast==iscureast)

        {

            numamong[numberofdiffer]++;

            continue;

            printf("hi");

        }

        numberofdiffer++;

        numamong[numberofdiffer]=1;

        iscureast=!iscureast;

    }

    if(numberofdiffer%2) numberofdiffer--;

    if(debug)

    {

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

        {

            if(i%2==0)  printf("E ");

            else        printf("W ");

            printf("%d\n",numamong[i]);

        }

    }

    int mins,caseallW=0;

    for(int i=2;i<=numberofdiffer;i+=2)

    {

        caseallW+=numamong[i];

    }

    mins=caseallW;

    int curcase=caseallW;

    for(int i=1;i<numberofdiffer;i+=2)

    {

        curcase+=numamong[i];

        curcase-=numamong[i+1];

        if(debug)

            printf("curcase of %d = %d\n",i,curcase);

        if(mins>curcase)

        {

            mins=curcase;

        }

    }

    printf("%d",mins);

}




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

using namespace std;

class BinaryCalculator



{

     public:

    int minimumSteps(int a, int b)

     {

       int steps=0;

       while(a>b){

       a-=2;

       steps++;

       }

       while(b>a){

       a+=3;

       steps++;

       }

        while(a>b){

       a-=2;

       steps++;

       }

       while(b>a){

       a+=3;

       steps++;

       }

        while(a>b){

       a-=2;

       steps++;

       }

       while(b>a){

       a+=3;

       steps++;

       }

       return steps;

     }

};

const int N = 3e5+5;

int w[N];

int e[N];

int main()

{

 

    string s;

    int n;

    cin>>n;

    cin>>s;

    

    int mn=1e9;

    for(int i =0;i<s.length();i++)

    {

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

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

    }

    for(int i =1;i<s.length();i++)

    {

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

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

    // cout<<e[i]<<" "<<w[i]<<endl;

    }

    for(int i =0;i<s.length();i++)

    {

        int ws = w[i];

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

        ws--;

        int es = e[s.length()-1]- e[i];

        mn = min(mn,es+ws);

    }

    cout<<mn;

}