stablegradients/pie-gem5-pairs huggingface dataset:
// 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.4109205870617867x):
/// However long the night,

///     The dawn will break

/// ICPC next year



#include<bits/stdc++.h>

using namespace std ;

const int N = 3e5+5 ;



int n ,l[N] ,r[N] ;

string str ;

int main(){

    cin >> n >> str ;

    int cur = 0 ;

    for(int i=0;i<str.size();++i){

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

        l[i+1] = cur ;

    }

    cur = 0 ;

    for(int i=str.size()-1;i>=0;--i){

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

        r[i+1] = cur ;

    }

    int ans = 1e9 ;

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

        ans = min(ans ,l[i-1]+r[i+1]);

    }

    cout << ans ;

    return 0;

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

using namespace std;



int main () {

  int N;

  string S;

  cin >> N >> S;

  int w[300010] = {0};

  int e[300010] = {0};

  if(S[0] == 'W'){

    w[0] = 1;

  }

  else {

    e[0] = 1;

  }

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

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

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

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

    }

    else {

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

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

    }

  }

  int ans = e[N-1] - e[0];

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

    int count = w[i-1] + e[N-1] - e[i];

    if (count < ans) ans = min(ans, count);

  }

  cout << ans << endl;

}


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

using namespace std;

using ll = long long;

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

#define repe(i, begin, n) for (int i = begin; i <= n; i++)

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

#define repre(i, begin, end) for (int i = begin; i >= end; i--)



template <class T>

inline bool chmax(T& a, T b) {

  if (a < b) {

    a = b;

    return 1;

  }

  return 0;

}



template <class T>

inline bool chmin(T& a, T b) {

  if (a > b) {

    a = b;

    return 1;

  }

  return 0;

}



const int inf = 1000000007;

const int MOD = 1000000007;

const long long INF = 1000000000000000007;



// -------------------------------------------------------

int N;

string S;

int Easts[301010];



int main() {

  cin >> N >> S;

  rep(i, 0, N) {

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

      Easts[i + 1] = Easts[i] + 1;

    } else {

      Easts[i + 1] = Easts[i];

    }

  }



  int ans = inf;

  repe(i, 1, N) {

    int cost = 0;

    cost += (i - 1) - Easts[i - 1];

    cost += Easts[N] - Easts[i];

    chmin(ans, cost);

  }

  cout << ans << endl;

}
// 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.1202381500040608x):
#include<bits/stdc++.h> //Ithea Myse Valgulious

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=3e5;

typedef int fuko[yuzu|10];

char c[yuzu|10];

fuko sum1,sum2;

int main(){

int n=read(),ans=0x3f3f3f3f;

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

for (int i=1;i<=n;++i) sum1[i]=sum1[i-1]+(c[i]=='W');

for (int i=n;i;--i) sum2[i]=sum2[i+1]+(c[i]=='E');

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

write(ans);

}
// Slower C++ solution:


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int maxn=300005;



int n,a[maxn],t,ans=0x3fffffff;

char s[maxn];



int main(){

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

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

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

    t=a[n];

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

        ans=min(ans,(i-1-a[i-1])+(t-a[i]));

    cout<<ans<<endl;

    return 0;

}


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

#include<cstring>

#include<cmath>

#include<algorithm>

#include<queue>

#include<stack>

#include<vector>

#include<set>

#include<map>

using namespace std;

int n,w,e,minn=300005,ans,add[300005];

char s[300005],ch;

int main(){

	scanf("%d",&n);

	scanf("%s",s);

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

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

			add[i]+=w;

			w++;

		}else{

			add[i]+=w;

		}

	}

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

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

			add[i]+=e;

			e++;

		}else{

		    add[i]+=e;

		}

	}

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

	    minn=min(minn,add[i]);

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

	}

	printf("%d",minn);

	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: 5.7627635129114205x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<queue>

#include<stack>

#include<vector>

#include<set>

#include<map>

using namespace std;

int n,w,e,minn=300005,ans,add[300005];

char s[300005],ch;

int main(){

	scanf("%d",&n);

	scanf("%s",s);

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

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

			add[i]+=w;

			w++;

		}else{

			add[i]+=w;

		}

	}

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

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

			add[i]+=e;

			e++;

		}else{

		    add[i]+=e;

		}

	}

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

	    minn=min(minn,add[i]);

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

	}

	printf("%d",minn);

	return 0;

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

   cin>>n;

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

        cin>>a[i];

    int sum1=0;

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

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

            sum1++;

    int sum=sum1;

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

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

            sum1--;

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

            sum1++;

        if(sum>sum1)

            sum=sum1;

    }

   cout<<sum<<endl;

   return 0;

}


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

#include<cstring>

#include<cmath>

#include<algorithm>

#include<queue>

#include<stack>

#include<vector>

#include<set>

#include<map>

using namespace std;

int n,w,e,minn=300005,ans,add[300005];

char s[300005],ch;

int main(){

	scanf("%d",&n);

	scanf("%s",s);

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

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

			add[i]+=w;

			w++;

		}else{

			add[i]+=w;

		}

	}

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

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

			add[i]+=e;

			e++;

		}else{

		    add[i]+=e;

		}

	}

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

	    minn=min(minn,add[i]);

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

	}

	printf("%d",minn);

	return 0;

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

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=3e5;

typedef int fuko[yuzu|10];

char c[yuzu|10];

fuko sum1,sum2;

int main(){

int n=read(),ans=0x3f3f3f3f;

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

for (int i=1;i<=n;++i) sum1[i]=sum1[i-1]+(c[i]=='W');

for (int i=n;i;--i) sum2[i]=sum2[i+1]+(c[i]=='E');

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

write(ans);

}

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

#include<cstring>

#include<cmath>

#include<algorithm>

#include<queue>

#include<stack>

#include<vector>

#include<set>

#include<map>

using namespace std;

int n,w,e,minn=300005,ans,add[300005];

char s[300005],ch;

int main(){

	scanf("%d",&n);

	scanf("%s",s);

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

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

			add[i]+=w;

			w++;

		}else{

			add[i]+=w;

		}

	}

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

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

			add[i]+=e;

			e++;

		}else{

		    add[i]+=e;

		}

	}

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

	    minn=min(minn,add[i]);

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

	}

	printf("%d",minn);

	return 0;

}
// Slower C++ solution:


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int maxn=300005;



int n,a[maxn],t,ans=0x3fffffff;

char s[maxn];



int main(){

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

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

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

    t=a[n];

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

        ans=min(ans,(i-1-a[i-1])+(t-a[i]));

    cout<<ans<<endl;

    return 0;

}


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

#include<algorithm>

using namespace std;

int N,ans=2e9,zj,w,e,W[300005],E[300005];

char S[300005];

int main()

{

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

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

	{

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

		w++;

		else

		e++;

		W[i+1]=w;

		E[i+1]=e;

	}

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

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

	printf("%d",ans);

	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: 5.7719879143469575x):
#include<cstdio>

#include<algorithm>

using namespace std;

int N,ans=2e9,zj,w,e,W[300005],E[300005];

char S[300005];

int main()

{

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

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

	{

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

		w++;

		else

		e++;

		W[i+1]=w;

		E[i+1]=e;

	}

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

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

	printf("%d",ans);

	return 0;

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

   cin>>n;

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

        cin>>a[i];

    int sum1=0;

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

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

            sum1++;

    int sum=sum1;

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

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

            sum1--;

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

            sum1++;

        if(sum>sum1)

            sum=sum1;

    }

   cout<<sum<<endl;

   return 0;

}


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

#include<algorithm>

using namespace std;

int N,ans=2e9,zj,w,e,W[300005],E[300005];

char S[300005];

int main()

{

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

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

	{

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

		w++;

		else

		e++;

		W[i+1]=w;

		E[i+1]=e;

	}

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

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

	printf("%d",ans);

	return 0;

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

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=3e5;

typedef int fuko[yuzu|10];

char c[yuzu|10];

fuko sum1,sum2;

int main(){

int n=read(),ans=0x3f3f3f3f;

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

for (int i=1;i<=n;++i) sum1[i]=sum1[i-1]+(c[i]=='W');

for (int i=n;i;--i) sum2[i]=sum2[i+1]+(c[i]=='E');

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

write(ans);

}

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

#include<algorithm>

using namespace std;

int N,ans=2e9,zj,w,e,W[300005],E[300005];

char S[300005];

int main()

{

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

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

	{

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

		w++;

		else

		e++;

		W[i+1]=w;

		E[i+1]=e;

	}

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

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

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int maxn=300005;



int n,a[maxn],t,ans=0x3fffffff;

char s[maxn];



int main(){

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

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

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

    t=a[n];

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

        ans=min(ans,(i-1-a[i-1])+(t-a[i]));

    cout<<ans<<endl;

    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

int n,cnt,sE[300002],sW[300002],ans=3*1e6+2;

char c;

int main(){

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

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

		scanf("%c",&c);

		if(c=='E'){

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

			sW[i]=sW[i-1];	

		}else {

			sE[i]=sE[i-1];

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

		}

	}

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

//		printf("%d %d\n",sW[i],sE[i]);

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

		cnt=sW[i-1]+sE[n]-sE[i];

		ans=min(ans,cnt);

	}

	printf("%d",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: 5.760323229255343x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,cnt,sE[300002],sW[300002],ans=3*1e6+2;

char c;

int main(){

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

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

		scanf("%c",&c);

		if(c=='E'){

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

			sW[i]=sW[i-1];	

		}else {

			sE[i]=sE[i-1];

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

		}

	}

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

//		printf("%d %d\n",sW[i],sE[i]);

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

		cnt=sW[i-1]+sE[n]-sE[i];

		ans=min(ans,cnt);

	}

	printf("%d",ans);

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

   cin>>n;

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

        cin>>a[i];

    int sum1=0;

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

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

            sum1++;

    int sum=sum1;

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

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

            sum1--;

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

            sum1++;

        if(sum>sum1)

            sum=sum1;

    }

   cout<<sum<<endl;

   return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

int n,cnt,sE[300002],sW[300002],ans=3*1e6+2;

char c;

int main(){

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

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

		scanf("%c",&c);

		if(c=='E'){

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

			sW[i]=sW[i-1];	

		}else {

			sE[i]=sE[i-1];

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

		}

	}

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

//		printf("%d %d\n",sW[i],sE[i]);

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

		cnt=sW[i-1]+sE[n]-sE[i];

		ans=min(ans,cnt);

	}

	printf("%d",ans);

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

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=3e5;

typedef int fuko[yuzu|10];

char c[yuzu|10];

fuko sum1,sum2;

int main(){

int n=read(),ans=0x3f3f3f3f;

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

for (int i=1;i<=n;++i) sum1[i]=sum1[i-1]+(c[i]=='W');

for (int i=n;i;--i) sum2[i]=sum2[i+1]+(c[i]=='E');

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

write(ans);

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int n,cnt,sE[300002],sW[300002],ans=3*1e6+2;

char c;

int main(){

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

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

		scanf("%c",&c);

		if(c=='E'){

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

			sW[i]=sW[i-1];	

		}else {

			sE[i]=sE[i-1];

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

		}

	}

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

//		printf("%d %d\n",sW[i],sE[i]);

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

		cnt=sW[i-1]+sE[n]-sE[i];

		ans=min(ans,cnt);

	}

	printf("%d",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.116971112000811x):
#include<bits/stdc++.h>

using namespace std;

int n,s1[300010][2],s2[300010][2],ans=2e9;

char c[300010];

int main(){

	scanf("%d",&n);

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

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

		s1[i][0]=s1[i-1][0]+(c[i]=='W'?1:0);

		s2[i][0]=s2[i-1][0]+(c[i]=='E'?1:0);

	}

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

		s1[i][1]=s1[i+1][1]+(c[i]=='W'?1:0);

		s2[i][1]=s2[i+1][1]+(c[i]=='E'?1:0);

	}

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

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

			ans=min(ans,s1[i-1][0]+s2[i+1][1]);

		else

			ans=min(ans,s1[i-1][0]+s2[i+1][1]);

	}

	printf("%d",ans);

}