stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


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

using namespace std;

char in[303000];

int W[303000];

int main()

{

	int n,i,Min=500000,cou=0;

	scanf("%d",&n);

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

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

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

            cou++;

        }

        W[i]=cou;

	}

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

        if(n-1-i-W[n-1]+W[i]+W[i-1]<Min){

            Min=n-1-i-W[n-1]+W[i]+W[i-1];

        }

    }

    printf("%d",Min);

    return 0;

}
// Slower C++ solution:
#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;

}


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

#include <string.h>

#include <math.h>

#include <stdlib.h>

#include <map>

#include <set>

#include <iostream>

#include <string>

#include <algorithm>

#include <vector>

#include <queue>





using namespace std;



typedef long long LL;







int main()

{

    int n;

    string s1;

    while (cin >>n)

    {

        cin >>s1;

        int right_e =0;

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

        {

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

                right_e++;

        }

        int right_w = n -right_e;

        int left_e = 0;

        int left_w =0;

        int ans =0x3f3f3f3f;

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

        {

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

                right_e--;

            else

                right_w--;

            if (i != 0)

            {

                if (s1[i-1] == 'E')

                    left_e++;

                else

                    left_w++;

            }

            ans = min(ans,left_w + right_e);

        }

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



    }









#ifdef VSCode

    system("pause");

#endif

    return 0;

}
// Slower C++ solution:
#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;

}


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

using namespace std;

#define MAXN 100100

#define eps 1e-9

#define For(i,a,b) for(int i=a;i<=b;i++) 

#define Fore(i,a,b) for(int i=a;i>=b;i--) 

#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

#define mkp make_pair

#define pb push_back

#define cr clear()

#define met(a,b) memset(a,b,sizeof(a))

#define iossy ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define fre freopen

#define pi acos(-1.0)

#define inf 1e9+9

#define Vector Point

#define fir first

#define sec second

#define fxx(a) cout<<fixed<<setprecision(a)

#define flu cout.flush()

typedef pair<int,int> pii;

const int Mod=1000000007;

typedef unsigned long long ull;

typedef long long ll;

const int base=227;

const int base1=123;

const int maxn=2005;

char s[3000006];

int suml[300005],sumr[300005];

int n;

void solve(){

	cin>>n;

	cin>>s+1;

	int l=strlen(s+1);suml[0]=0;sumr[l+1]=0;

	For(i,1,l) {

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

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

	}

	Fore(i,l,1) {

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

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

	}

	int ans=suml[1]+sumr[2];;

	For(i,1,l) {

		ans=min(suml[i-1]+sumr[i+1],ans);

	}cout<<ans<<endl;

}

int main(){

	iossy;

	int t=1;

	For(i,1,t) solve();

	return 0;

}
// Slower C++ solution:
#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;

}


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

using namespace std;



const int N = 3e5 + 10;



int pre[N], suf[N];

char s[N];



int main(){

	int n, ans;

	scanf("%d",&n);

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

	pre[0] = 0;

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

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

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

	} 

	suf[n + 1] = 0;

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

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

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

	}

	ans = n;

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

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

	return 0;

}
// Slower C++ solution:
#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;

}


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



#define ll long long



#define rep(i, a, b) for (int i = a; i < b; i++)

#define For(i, a, b) for (int i = a; i <= b; i++)



using namespace std;



const int mod = 1000000000 + 7;

const int MAXN = 300000 + 5;



char s[MAXN];

int countE[MAXN], countW[MAXN];

int n;



int main() {

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

    int ans = INT32_MAX;

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

        countW[i + 1] += countW[i];

        countE[i + 1] += countE[i];

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

            countW[i + 1]++;

        else

            countE[i + 1]++;

    }

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

        ans = min(ans, countW[i - 1] + countE[n] - countE[i]);

    }

    printf("%d", ans);

};
// Slower C++ solution:
#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;

}


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



using namespace std;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    string s;

    int n, ans = 2e9;

    cin >> n >> s;

    int preW[n], preE[n];



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

    preE[0] = (s[0] == 'E');



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

        preW[i] = (s[i] == 'W');

        preE[i] = (s[i] == 'E');



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

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

    }



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

        ans = min(ans, (i ? preW[i - 1] : 0) + (preE[n - 1] - preE[i]));



    cout << ans << '\n';



    return 0;

}
// Slower C++ solution:
#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;

}


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

#define mem(a,v) memset(a,v,sizeof a)

#define ll long long

#define max(a,b) (a>b?a:b)

#define min(a,b) (a<b?a:b)

#define max3(x,y,z) max(x,max(y,z))

#define min3(x,y,z) min(x,min(y,z))

#define f first

#define s second

#define fr(i,n) for(int j=i;j<n;j++)

#define rev(a) reverse(a.begin(),a.end())

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

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

#define lb(a,v) lower_bound(all(a),v)

#define ub(a,v) upper_bound(all(a),v)

#define ins(v) insert(v)

#define pb(v) push_back(v)

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

#define MOD 1000000007

#define sf1(a) scanf("%d",&a)

#define sf2(a,b) scanf("%d %d",&a,&b)

#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)

#define sf4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)

using namespace std;

const int N=1e6+5;

int main() {

	int n;

	sf1(n);

	char s[N];

	scanf("%s",s);

	

	int w[n+1]={},e[n+1]={};

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

	{

		if(s[i]=='W') //ely 2bel

			w[i]++;

		else

			e[i]++;

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

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

	}

	int mn=1e9+5,ss=0;

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

	{

		ss=0;

		if(s[i]=='W'&&i-1>=0) //ely 3leh 

		{

			ss+=(e[n]-e[i]);

			ss+=(w[i]);

		}

		else if(s[i]=='W'&&i==0)

			ss+=(e[n]-e[i]);

		else if(s[i]=='E'&&i-1>=0)

		{

			ss+=(e[n]-e[i]);

			ss+=(w[i]);

		}

		else if(s[i]=='E'&&i==0)

			ss+=(e[n]-e[i]);

		//cout<<ss<<endl;

		mn=min(mn,ss);

	}

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

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.2921869221819013x):
/*

        Author: Prokash

                CSE48, JU



*/



#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

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

int ara[2005];

int main()

{

    FAST;

    int n,cnt=0;

    string str;

    cin>>n>>str;

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

    {

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

        {

            cnt++;

        }

    }

    int mn=cnt;

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

    {

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

        {

            cnt++;

        }

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

        {

            cnt--;

        }

        mn=min(cnt,mn);

    }

    cout<<mn<<endl;

    return 0;

}
// Slower C++ solution:
#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;

}


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

using namespace std;

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

#define  ll  long long

#define  pi  pair<int,int>

#define  pb  push_back

#define  F   first

#define  S   second

const int N=3e5+3;

string s;

int a[N];

int main()

{

    ft

    int t,i,j,n,m,x,l=0,r=0,mn=INT_MAX;

    cin>>n>>s;

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

    {

        a[i]+=l;

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

        {

            l++;

        }

    }

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

    {

        a[i]+=r;

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

        {

            r++;

        }

        mn=min(mn,a[i]);

    }

    cout<<mn<<"\n";

    return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.3023143202828895x):
#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';



	char S[300000];

	fread_unlocked(S, 1, N, stdin);



	int A[300010];

	A[0] = 0;

	rep(i, N) {

		A[i + 1] = A[i];

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

	}



	int kotae = 1e9;

	rep(i, N) {

		kotae = min(kotae, A[i] + N - i - 1 - A[N] + A[i + 1]);

	}

	co(kotae);



	Would you please return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.3290860478951045x):
#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 A[300010];

	A[0] = 0;

	rep(i, N) {

		A[i + 1] = A[i];

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

	}



	int kotae = 1e9;

	rep(i, N) {

		kotae = min(kotae, A[i] + N - i - 1 - A[N] + A[i + 1]);

	}

	co(kotae);



	Would you please return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.4320455932355993x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.3779927011391924x):
#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';



	char S[300001];

	fread_unlocked(S, 1, N, stdin);



	int kotae = 1e9;

	int A = 0;

	rep(i, N) kotae = min(kotae, A - i + (A += S[i] == 'W'));



	co(kotae + N - 1 - A);



	Would you please return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.244307111670695x):
#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;

}
// 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.241183249308497x):
#include <cstdio>

#include <algorithm>

using namespace std;

int n,coun[300005][2],minn=300005;

char s[300005];

int main()

{

	scanf("%d",&n);

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

	{

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

		coun[i][0]=coun[i-1][0];

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

			coun[i][0]++;

	}

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

	{

		coun[i-1][1]=coun[i][1];

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

			coun[i-1][1]++;

		minn=min(minn,coun[i][0]+coun[i][1]);

	}

	minn=min(minn,coun[0][1]);

	printf("%d",minn);

	return 0;

}
// 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.241256462932674x):
#include <cstdio>

#include <algorithm>

using namespace std;

int n,coun[300005][2],minn=300005;

char s[300005];

int main()

{

	scanf("%d",&n);

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

	{

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

		coun[i][0]=coun[i-1][0];

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

			coun[i][0]++;

	}

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

	{

		coun[i-1][1]=coun[i][1];

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

			coun[i-1][1]++;

		minn=min(minn,coun[i][0]+coun[i][1]);

	}

	minn=min(minn,coun[0][1]);

	printf("%d",minn);

	return 0;

}
// 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.1750859894015955x):
#include <cstdio>

#include <algorithm>

using namespace std;

int n,coun[300005][2],minn=300005;

char s[300005];

int main()

{

	scanf("%d",&n);

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

	{

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

		coun[i][0]=coun[i-1][0];

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

			coun[i][0]++;

	}

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

	{

		coun[i-1][1]=coun[i][1];

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

			coun[i-1][1]++;

		minn=min(minn,coun[i][0]+coun[i][1]);

	}

	minn=min(minn,coun[0][1]);

	printf("%d",minn);

	return 0;

}