stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

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

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

    //ans1[0]=1;

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

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

            ans1[i]++;

        }

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

    }

    //ans2[N-1]=1;

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

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

            ans2[i]++;

        }

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

    }

    int maxx=0,t;

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

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

        maxx=max(t,maxx);

    }

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

    return 0;

}


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

using namespace std ;



#define inf 0x3f3f3f3f

#define INF 1000111000111000111LL

#define mod 1000000007

#define pi acos(-1.0)

#define eps 1e-8

#define endl '\n'

#define mp make_pair

#define mt make_tuple

#define pb push_back

#define fi first

#define se second

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

using lli = long long int ;

using pii = pair<int, int> ;

using vi = vector<int> ;

using vb = vector<bool> ;

using vvi = vector<vector<int>> ;

using vlli = vector<long long int> ;

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



int main()

  {

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

    int n, ans=inf ;

    string s ;

    cin>> n >> s ;

    s='#'+s ;

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

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

      {

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

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

      }

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

    cout<< ans ;

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

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



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

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



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

        {

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

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

                    l[i]++;

            }

        }



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

        {

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

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

                    r[i]++;

            }

        }





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

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

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

         }



         cout<<n-maxx<<endl;









        return 0;

    }


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

using namespace std;

char s[700000];

int a[700000];

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;

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

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

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

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

    //ans1[0]=1;

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

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

            ans1[i]++;

        }

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

    }

    //ans2[N-1]=1;

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

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

            ans2[i]++;

        }

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

    }

    int maxx=0,t;

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

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

        maxx=max(t,maxx);

    }

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

    return 0;

}


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

using namespace std;

char s[700000];

int a[700000];

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;

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

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



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

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



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

        {

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

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

                    l[i]++;

            }

        }



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

        {

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

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

                    r[i]++;

            }

        }





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

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

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

         }



         cout<<n-maxx<<endl;









        return 0;

    }


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

#define taskname "VirtualACM"

using namespace std;



const int maxn = 3e5 + 10;

int cL[maxn], cR[maxn], n;

string s;



main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);   cout.tie(nullptr);

    if (ifstream("test.inp"))

    {

        freopen("test.inp", "r", stdin);

        #ifdef CHECKING

            freopen(taskname".out", "w", stdout);

        #else

            freopen("test.out", "w", stdout);

        #endif // CHECKING

    }

    else if (ifstream(taskname".inp"))

    {

        freopen(taskname".inp", "r", stdin);

        freopen(taskname".out", "w", stdout);

    }



    cin >> n >> s;

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

    {

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

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

    }

    int ans = n;

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

        ans = min(ans, cL[i - 1] + cR[n] - cR[i]);

    cout << ans;

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

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

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

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

    //ans1[0]=1;

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

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

            ans1[i]++;

        }

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

    }

    //ans2[N-1]=1;

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

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

            ans2[i]++;

        }

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

    }

    int maxx=0,t;

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

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

        maxx=max(t,maxx);

    }

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

    return 0;

}


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

#define taskname "VirtualACM"

using namespace std;



const int maxn = 3e5 + 10;

int cL[maxn], cR[maxn], n;

string s;



main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);   cout.tie(nullptr);

    if (ifstream("test.inp"))

    {

        freopen("test.inp", "r", stdin);

        #ifdef CHECKING

            freopen(taskname".out", "w", stdout);

        #else

            freopen("test.out", "w", stdout);

        #endif // CHECKING

    }

    else if (ifstream(taskname".inp"))

    {

        freopen(taskname".inp", "r", stdin);

        freopen(taskname".out", "w", stdout);

    }



    cin >> n >> s;

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

    {

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

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

    }

    int ans = n;

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

        ans = min(ans, cL[i - 1] + cR[n] - cR[i]);

    cout << ans;

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

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



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

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



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

        {

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

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

                    l[i]++;

            }

        }



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

        {

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

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

                    r[i]++;

            }

        }





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

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

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

         }



         cout<<n-maxx<<endl;









        return 0;

    }


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

*   @author Mustafa Khaled.

**/

#pragma GCC optimize("O3")

#include<bits/stdc++.h>

using namespace std ;

typedef long long ll;



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



string to_string(string s){return '"' + s + '"';}string to_string(const char* s){return to_string((string) s);}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v){bool first = true;string res = "{";for (const auto &x : v){if (!first){res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void debug_out(){cerr << endl;}template <typename Head, typename... Tail>void debug_out(Head H, Tail... T){cerr << " " << to_string(H);debug_out(T...);}/*input*/inline void in(const char *t) {}template <typename Head, typename... Tail>inline void in(const char *t,Head &H, Tail&... T){scanf(t,&H);in(t,T...);}

#define D(...)    in(  "%d",__VA_ARGS__);

#define LLD(...)  in("%lld",__VA_ARGS__);



#ifndef ONLINE_JUDGE

    #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#else

    #define dbg(...) {}

#endif

/// start driven program

const int OO = 0x3f3f3f3f, N=3e5+7  , MOD= 1000000007;



int beforW[N];

int afterE[N];

char s[N];

int main(){

    int n ; D(n); scanf(" %s",s);

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

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

            beforW[i+1]=1;

        }

    }

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

        beforW[i+1]+=beforW[i];

    }





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

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

            afterE[i+1]=1;

        }

    }

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

        afterE[i+1]+=afterE[i+2];

    }

    int mn =OO , x=0;



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

        x=(beforW[i+1]-(s[i]=='W')) + (afterE[i+1]-(s[i]=='E') );

        dbg(i , x);

        mn = min(mn ,x);

    }



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



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

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

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

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

    //ans1[0]=1;

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

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

            ans1[i]++;

        }

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

    }

    //ans2[N-1]=1;

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

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

            ans2[i]++;

        }

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

    }

    int maxx=0,t;

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

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

        maxx=max(t,maxx);

    }

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

    return 0;

}


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

*   @author Mustafa Khaled.

**/

#pragma GCC optimize("O3")

#include<bits/stdc++.h>

using namespace std ;

typedef long long ll;



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



string to_string(string s){return '"' + s + '"';}string to_string(const char* s){return to_string((string) s);}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v){bool first = true;string res = "{";for (const auto &x : v){if (!first){res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void debug_out(){cerr << endl;}template <typename Head, typename... Tail>void debug_out(Head H, Tail... T){cerr << " " << to_string(H);debug_out(T...);}/*input*/inline void in(const char *t) {}template <typename Head, typename... Tail>inline void in(const char *t,Head &H, Tail&... T){scanf(t,&H);in(t,T...);}

#define D(...)    in(  "%d",__VA_ARGS__);

#define LLD(...)  in("%lld",__VA_ARGS__);



#ifndef ONLINE_JUDGE

    #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#else

    #define dbg(...) {}

#endif

/// start driven program

const int OO = 0x3f3f3f3f, N=3e5+7  , MOD= 1000000007;



int beforW[N];

int afterE[N];

char s[N];

int main(){

    int n ; D(n); scanf(" %s",s);

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

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

            beforW[i+1]=1;

        }

    }

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

        beforW[i+1]+=beforW[i];

    }





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

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

            afterE[i+1]=1;

        }

    }

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

        afterE[i+1]+=afterE[i+2];

    }

    int mn =OO , x=0;



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

        x=(beforW[i+1]-(s[i]=='W')) + (afterE[i+1]-(s[i]=='E') );

        dbg(i , x);

        mn = min(mn ,x);

    }



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



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

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



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

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



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

        {

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

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

                    l[i]++;

            }

        }



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

        {

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

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

                    r[i]++;

            }

        }





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

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

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

         }



         cout<<n-maxx<<endl;









        return 0;

    }


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


#include <bits/stdc++.h>



using namespace std;

const int N= 3e5+7;

int vis[N], East [N], West[N];





class NBAFinals

{

public :

    int  dubsAgain (vector < int > scores,string team)

    {

        int arr[2]= {0,0};

        int ans;

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

        {

            if(team[i]=='W'||team[i]=='?')

            {

                arr[0]+=(scores[i]==0?4:scores[i]);

            }

            else

                arr[1]+=(scores[i]==0?1:scores[i]);

        }



        return ans=arr[0]>arr[1];

    }

};

int main()

{



    int n ;

    string s ;

    cin>>n>>s;

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

    {

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

        {



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

            East[i]=East[i-1];

        }

        else

        {

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

            West[i]=West[i-1];



        }

    }

    int mn =INT_MAX;

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

    {

        int e =East[i]-East[0];

        int w =West[n]-West[i-1];

        cerr<<e<<" "<<w<<" "<<endl;



        if(mn>e+w)

            mn=e+w;



    }

    cout<<mn-1<<endl;







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

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

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

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

    //ans1[0]=1;

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

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

            ans1[i]++;

        }

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

    }

    //ans2[N-1]=1;

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

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

            ans2[i]++;

        }

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

    }

    int maxx=0,t;

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

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

        maxx=max(t,maxx);

    }

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

    return 0;

}


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


#include <bits/stdc++.h>



using namespace std;

const int N= 3e5+7;

int vis[N], East [N], West[N];





class NBAFinals

{

public :

    int  dubsAgain (vector < int > scores,string team)

    {

        int arr[2]= {0,0};

        int ans;

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

        {

            if(team[i]=='W'||team[i]=='?')

            {

                arr[0]+=(scores[i]==0?4:scores[i]);

            }

            else

                arr[1]+=(scores[i]==0?1:scores[i]);

        }



        return ans=arr[0]>arr[1];

    }

};

int main()

{



    int n ;

    string s ;

    cin>>n>>s;

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

    {

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

        {



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

            East[i]=East[i-1];

        }

        else

        {

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

            West[i]=West[i-1];



        }

    }

    int mn =INT_MAX;

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

    {

        int e =East[i]-East[0];

        int w =West[n]-West[i-1];

        cerr<<e<<" "<<w<<" "<<endl;



        if(mn>e+w)

            mn=e+w;



    }

    cout<<mn-1<<endl;







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

    #include <iostream>

    #include <cstring>

    #include <cstdio>

    #include <string>



    using namespace std;



    const int maxn=1e6+10;



    int n;

    int l[maxn],r[maxn];

    char str[maxn];

    int maxx=0;



    int main()

    {

        scanf("%d",&n);

        scanf("%s",str);



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

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



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

        {

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

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

                    l[i]++;

            }

        }



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

        {

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

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

                    r[i]++;

            }

        }





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

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

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

         }



         cout<<n-maxx<<endl;









        return 0;

    }


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace __gnu_pbds;  

using namespace std;



typedef long long ll;



typedef tree<

pair <int, int>,

null_type,

less<pair <int, int>>,

rb_tree_tag,

tree_order_statistics_node_update>

os;



double getTime() {

  return clock() / (double) CLOCKS_PER_SEC;

}



void read() {};



template<typename T, typename... Args>

void read(T& a, Args&... args) {

  cin >> a;

  read(args...);

}



void print() {};



template <typename T, typename... Args>

void print(T a, Args... args) {

  cout << a << " \n"[sizeof...(args) == 0];

  print(args...);

}



int main() {

  int n; cin >> n;

  string s; cin >> s;

  int W = count(s.begin(), s.end(), 'W');

  int E = count(s.begin(), s.end(), 'E');

  int w = 0, e = 0;

  int ans = E;

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

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

    else e++;

    ans = min(ans, E - e + w);

  }

  print(ans);

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

#include <cstring>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;

char s[300010];

int ans1[300010],ans2[300010];

int main()

{

    int N;

    scanf("%d",&N);

    scanf("%s",s);

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

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

    //ans1[0]=1;

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

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

            ans1[i]++;

        }

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

    }

    //ans2[N-1]=1;

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

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

            ans2[i]++;

        }

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

    }

    int maxx=0,t;

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

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

        maxx=max(t,maxx);

    }

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

    return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace __gnu_pbds;  

using namespace std;



typedef long long ll;



typedef tree<

pair <int, int>,

null_type,

less<pair <int, int>>,

rb_tree_tag,

tree_order_statistics_node_update>

os;



double getTime() {

  return clock() / (double) CLOCKS_PER_SEC;

}



void read() {};



template<typename T, typename... Args>

void read(T& a, Args&... args) {

  cin >> a;

  read(args...);

}



void print() {};



template <typename T, typename... Args>

void print(T a, Args... args) {

  cout << a << " \n"[sizeof...(args) == 0];

  print(args...);

}



int main() {

  int n; cin >> n;

  string s; cin >> s;

  int W = count(s.begin(), s.end(), 'W');

  int E = count(s.begin(), s.end(), 'E');

  int w = 0, e = 0;

  int ans = E;

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

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

    else e++;

    ans = min(ans, E - e + w);

  }

  print(ans);

}