stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int E[300003] ,W [300003] ;

char tmp [300003] ;

int n;

int main ()

{

    ios::sync_with_stdio (false) ;

    while (cin>> n)

    {

        int lw ,le ;

        lw=le=0;

        int ans =n;

        fill (E,E+n,0) ;

        fill (W,W+n,0) ;

        cin>>tmp ;

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

        {



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



            W[i]=lw;

        }

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

        {

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

            E[i]=le;

        }

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

        {

            if (i==0) ans =min (ans, E[i+1]) ;

            else if (i==n-1) ans =min (ans, W[i-1] ) ;

            else

            ans = min (ans, E[i+1] +W[i-1] ) ;

        }

        cout<<ans<<endl ;



    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;

char a[300005];

int s[300005];

int t[300005];

int main()

{

	int n;

	scanf("%d",&n);

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

	{

		scanf(" %c",&a[i]);

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

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

	}

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

	{

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

		else t[i]=t[i+1];

	}

	int minn=2e9;

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

	{

		if(s[i]+t[i]<minn) minn=s[i]+t[i];

	}

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

//	{

//		printf("%d ",s[i]);

//	}

//	printf("\n");

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

//	{

//		printf("%d ",t[i]);

//	}

//	printf("\n");

	printf("%d",minn);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <math.h>

#include <queue>

#include <deque>

#include <vector>

#define maxc 100010

#define inf 0x3f3f3f3f

#define ll long long

using namespace std;

int main()

{

    int n;

    char a[300005];

    cin>>n;

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

        cin>>a[i];

    int sum=0;

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

    {

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

            sum++;

    }

    int k=sum;

    int sum1=sum;

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

    {



        if(a[i]=='E'&&a[i+1]=='E')

        {

            sum1=sum1-1;

        }

        if(a[i]=='W'&&a[i+1]=='W')

        {

            sum1=sum1+1;

        }

        k=min(sum1,k);

    }

cout<<k<<endl;

return 0;





}






// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;

char a[300005];

int s[300005];

int t[300005];

int main()

{

	int n;

	scanf("%d",&n);

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

	{

		scanf(" %c",&a[i]);

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

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

	}

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

	{

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

		else t[i]=t[i+1];

	}

	int minn=2e9;

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

	{

		if(s[i]+t[i]<minn) minn=s[i]+t[i];

	}

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

//	{

//		printf("%d ",s[i]);

//	}

//	printf("\n");

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

//	{

//		printf("%d ",t[i]);

//	}

//	printf("\n");

	printf("%d",minn);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int maxn=300005;



int n,q[maxn],t,ans=1<<30;

char s[maxn];



int main(){

    scanf("%d",&n),scanf("%s",s+1);

    for(int i=1;i<=n;i++) q[i]=q[i-1]+(s[i]=='E');

    t=q[n];

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

    cout<<ans<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;

char a[300005];

int s[300005];

int t[300005];

int main()

{

	int n;

	scanf("%d",&n);

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

	{

		scanf(" %c",&a[i]);

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

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

	}

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

	{

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

		else t[i]=t[i+1];

	}

	int minn=2e9;

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

	{

		if(s[i]+t[i]<minn) minn=s[i]+t[i];

	}

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

//	{

//		printf("%d ",s[i]);

//	}

//	printf("\n");

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

//	{

//		printf("%d ",t[i]);

//	}

//	printf("\n");

	printf("%d",minn);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<vector>

#include<string>

#include<queue>

#include<stack>

#include<set>

#include<cmath>

#include<iomanip>

using namespace std;



int INF = 1e9 + 7;



typedef long long ll;

typedef pair<int, int> P;



vector<int> e(300010), w(300010);



int main() {

	int n;

	string s;

	cin >> n >> s;

	int east = 0, west = 0;

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

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

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

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

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

	}

	int ans = INF;

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

		ans = min(ans, e[i - 1] + w[n - i]);

	}

	cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<int, int> P;

typedef tuple<int, int, int> T;



int MOD=1e9+7;

ll INF=1e18;



int dx[]={1, -1, 0, 0};

int dy[]={0, 0, 1, -1};



int main(){

    int n; cin>>n;

    string s; cin>>s;

    vector<int> esum(n), wsum(n);

    if(s[0]=='W') wsum[0]=1;

    else wsum[0]=0;

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

    else esum[n-1]=0;

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

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

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

    }



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

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

        else esum[i]=esum[i+1];

    }



    int ans=1e9;

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

        if(i==0) ans=min(ans, esum[1]);

        else if(i==n-1) ans=min(ans, wsum[n-2]);

        else ans=min(ans, wsum[i-1]+esum[i+1]);

    }

    cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstring>

#define M 300005

using namespace std;

int main()

{

    int n;

    char A[M];

    int B[M];

    while(scanf("%d",&n)!=EOF)

    {

        memset(A,'\0',sizeof(A));

        scanf("%s",A);



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

        {

            B[i] = cnt;

            if(A[i] == 'W') cnt++;

        }

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

        {

            B[i] = B[i] + cnt;

            if(A[i] == 'E') cnt++;

        }

        sort(B,B+n);

        printf("%d\n",B[0]);

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

int N,f[300001];

char s[300001];

int min(int i,int j){

	return (i<j?i:j);

}

int ans;

int main(){

	scanf("%d %s",&N,s);

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

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

	}

	ans=f[0];

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

		int a=f[i-1];

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

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

		f[i]=a;

		ans=min(f[i],ans);

	}

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define Would

#define you

#define please



int main() {

	//おまじない

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N;

	string S;

	cin >> N >> S;



	int SE[300002] = {};

	int SW[300002] = {};



	rep1(i, N) {

		if (S[i - 1] == 'E') SE[i]++;

		else SW[i]++;

		SE[i + 1] = SE[i];

		SW[i + 1] = SW[i];

	}





	int minimum = 300000;

	rep(i, N) {

		int rouryoku = SW[i] + SE[N] - SE[i + 1];

		minimum = min(minimum, rouryoku);

	}



	cout << minimum << "\n";



	Would you please return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N;

	char C;

	while (!isdigit(C = getchar_unlocked()));

	N = C - '0';

	while (isdigit(C = getchar_unlocked())) N = N * 10 + C - '0';



	int kotae = 1e9;

	int A = 0;

	rep(i, N) {

		if (getchar_unlocked() == 'W') kotae = min(kotae, A - i + ++A);

		else kotae = min(kotae, A + A - i);

	}



	co(kotae + N - 1 - A);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main(){

  int n;

  string s;

  int west[400000] = {};

  int east[400000] = {};

  cin >> n >> s;

  east[0] = west[n-1] = 0;

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

    east[i] = (s[i-1] == 'W' ? east[i-1] + 1 : east[i-1]);

    west[n-i-1] = (s[n-i] == 'E' ? west[n-i] + 1 : west[n-i]);

  }

  int ans = n;

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

    ans = min(ans, east[i] + west[i]);

  }

  cout << ans << endl;

  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main(){

    int n;

    cin >> n;

    string s;

    cin >> s;

    int w[n], e[n];

    w[0] = e[n-1] = 0;

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

        w[i] = (s[i-1] == 'W' ? w[i-1] + 1 : w[i-1]);

        e[n-i-1] = (s[n-i] == 'E' ? e[n-i] + 1 : e[n-i]);

    }

    int ans = 1e9;

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

        ans = min(ans, w[i] + e[i]);

    }

    cout << ans << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;



}

// Optimized solution to the same problem (faster):
#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);

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

    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);

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem: