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

using namespace std;

#define ll long long

int n, m; ll paths, mod = 1e9+7, memo[1002][1002];

char c[1002][1002];

ll fix_mod(ll x){

	return (mod + x % mod) % mod;

}

ll solve(int i, int j){

    if(c[i][j] == '#' || i >= n || j >= m) return 0;

    if(i == n-1 && j == m-1) return 1;

    if(memo[i][j] != -1) return memo[i][j];

    paths = fix_mod(solve(i, j+1) + solve(i+1, j));

    return memo[i][j] = paths;

}

int main()

{



    cin>> n>> m;

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

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

            cin>> c[i][j];

        }

    }

    memset(memo, -1, sizeof memo);

    cout<< solve(0, 0);

    return 0;

}


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

#define ll long long

#define MOD int(1e9+7)

using namespace std;



ll x,m,k,y,z,sum,dp[1005][1005];

char ar[1005][1005];



int main() {

	scanf("%lld%lld",&x,&y);

	dp[x][y+1] = 1;

	for (int a = 1; a <= x; a++) for (int b = 1; b <= y; b++) cin >> ar[a][b];

	while (x != 0 && y != 0) {

		for (int a = x; a >= 1; a--) if (ar[a][y] != '#') dp[a][y] = (dp[a][y+1]+dp[a+1][y])%MOD; else dp[a][y] = 0;

		for (int a = y; a >= 1; a--) if (ar[x][a] != '#') dp[x][a] = (dp[x][a+1]+dp[x+1][a])%MOD; else dp[x][a] = 0;

		x--; y--;

	}

	cout << dp[1][1]%MOD << "\n";

	return 0;

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

#define ll long long

using namespace std;

#define mod 1000000007

ll h,w;

char ar[1001][1001];

ll dp[1001][1001];



ll path(ll i,ll j){

    if(i==h-1&&j==w-1) return 1;

    if(dp[i][j]!=-1) return dp[i][j];

    ll x=0,y=0;

    if(i+1<h&&ar[i+1][j]!='#') x=path(i+1,j);

    if(j+1<w&&ar[i][j+1]!='#') y=path(i,j+1);

    return dp[i][j]=(x+y)%mod;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //freopen("input.txt", "r", stdin);

    //freopen("output.txt", "w", stdout);



    cin>>h>>w;

    for(ll i=0;i<h;i++){

        for(ll j=0;j<w;j++){

            cin>>ar[i][j];

        }

    }

    memset(dp,-1,sizeof(dp));

    cout<<path(0,0)<<endl;

    return 0;

}


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

#define ll long long

#define MOD int(1e9+7)

using namespace std;



ll x,m,k,y,z,sum,dp[1005][1005];

char ar[1005][1005];



int main() {

	scanf("%lld%lld",&x,&y);

	dp[x][y+1] = 1;

	for (int a = 1; a <= x; a++) for (int b = 1; b <= y; b++) cin >> ar[a][b];

	while (x != 0 && y != 0) {

		for (int a = x; a >= 1; a--) if (ar[a][y] != '#') dp[a][y] = (dp[a][y+1]+dp[a+1][y])%MOD; else dp[a][y] = 0;

		for (int a = y; a >= 1; a--) if (ar[x][a] != '#') dp[x][a] = (dp[x][a+1]+dp[x+1][a])%MOD; else dp[x][a] = 0;

		x--; y--;

	}

	cout << dp[1][1]%MOD << "\n";

	return 0;

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

using namespace std;

#define ll long long

int n, m; ll paths, mod = 1e9+7, memo[1002][1002];

char c[1002][1002];

ll fix_mod(ll x){

	return (mod + x % mod) % mod;

}

ll solve(int i, int j){

    if(c[i][j] == '#' || i >= n || j >= m) return 0;

    if(i == n-1 && j == m-1) return 1;

    if(memo[i][j] != -1) return memo[i][j];

    paths = fix_mod(solve(i, j+1) + solve(i+1, j));

    return memo[i][j] = paths;

}

int main()

{



    cin>> n>> m;

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

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

            cin>> c[i][j];

        }

    }

    memset(memo, -1, sizeof memo);

    cout<< solve(0, 0);

    return 0;

}


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

THE WHITE WOLF

NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/



#include<bits/stdc++.h>

using namespace std;



#define io ios_base::sync_with_stdio(false)

#define ll long long

#define ull unsigned long long

#define vi vector<int>

#define vll vector<long long>

#define pb push_back

#define mod  1000000007

#define pii pair<int, int>

#define PI 2*acos(0.0)

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



int dp[1005][1005];



int main()

{

    io;

    int r, c;

    cin>>r>>c;

    char inp[r+1][c+1];

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

        for(int j = 1;j <= c; j++)

            cin>>inp[i][j];



    dp[1][1] = 1;

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

    {

        for(int j=1; j<= c;j++)

        {

            if(i == 1 && j == 1)

                continue;

            if(inp[i][j] == '#')

                dp[i][j] = 0;

            else

                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;

        }

    }

    cout<<dp[r][c];

    return 0;

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

#define ll long long

using namespace std;

#define mod 1000000007

ll h,w;

char ar[1001][1001];

ll dp[1001][1001];



ll path(ll i,ll j){

    if(i==h-1&&j==w-1) return 1;

    if(dp[i][j]!=-1) return dp[i][j];

    ll x=0,y=0;

    if(i+1<h&&ar[i+1][j]!='#') x=path(i+1,j);

    if(j+1<w&&ar[i][j+1]!='#') y=path(i,j+1);

    return dp[i][j]=(x+y)%mod;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //freopen("input.txt", "r", stdin);

    //freopen("output.txt", "w", stdout);



    cin>>h>>w;

    for(ll i=0;i<h;i++){

        for(ll j=0;j<w;j++){

            cin>>ar[i][j];

        }

    }

    memset(dp,-1,sizeof(dp));

    cout<<path(0,0)<<endl;

    return 0;

}


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

THE WHITE WOLF

NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/



#include<bits/stdc++.h>

using namespace std;



#define io ios_base::sync_with_stdio(false)

#define ll long long

#define ull unsigned long long

#define vi vector<int>

#define vll vector<long long>

#define pb push_back

#define mod  1000000007

#define pii pair<int, int>

#define PI 2*acos(0.0)

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



int dp[1005][1005];



int main()

{

    io;

    int r, c;

    cin>>r>>c;

    char inp[r+1][c+1];

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

        for(int j = 1;j <= c; j++)

            cin>>inp[i][j];



    dp[1][1] = 1;

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

    {

        for(int j=1; j<= c;j++)

        {

            if(i == 1 && j == 1)

                continue;

            if(inp[i][j] == '#')

                dp[i][j] = 0;

            else

                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;

        }

    }

    cout<<dp[r][c];

    return 0;

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

using namespace std;

#define ll long long

int n, m; ll paths, mod = 1e9+7, memo[1002][1002];

char c[1002][1002];

ll fix_mod(ll x){

	return (mod + x % mod) % mod;

}

ll solve(int i, int j){

    if(c[i][j] == '#' || i >= n || j >= m) return 0;

    if(i == n-1 && j == m-1) return 1;

    if(memo[i][j] != -1) return memo[i][j];

    paths = fix_mod(solve(i, j+1) + solve(i+1, j));

    return memo[i][j] = paths;

}

int main()

{



    cin>> n>> m;

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

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

            cin>> c[i][j];

        }

    }

    memset(memo, -1, sizeof memo);

    cout<< solve(0, 0);

    return 0;

}


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

#define PI acos(-1)

#define falcon ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;

typedef long long ll ;

using namespace std ;



char grid[1001][1001] ;

int paths[1001][1001] ;



int main()

{

    falcon ;



    int n , m ;

    cin >> n >> m ;

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

    {

        for(int j = 0 ; j < m ; j++)

        {

            cin >> grid[i][j] ;

            paths[i][j] = 0 ;

        }

    }

    paths[0][0] = 1 ;

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

    {

        for(int j = 0 ; j < m ; j++)

        {

            if(grid[i][j] == '#') continue ;

            if(i > 0) paths[i][j] = paths[i][j] + paths[i - 1][j] ;

            if(j > 0) paths[i][j] = paths[i][j] + paths[i][j - 1] ;

            paths[i][j] = paths[i][j] % 1000000007 ;

        }

    }

    cout << paths[n - 1][m - 1] << "\n" ;

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

#define ll long long

using namespace std;

#define mod 1000000007

ll h,w;

char ar[1001][1001];

ll dp[1001][1001];



ll path(ll i,ll j){

    if(i==h-1&&j==w-1) return 1;

    if(dp[i][j]!=-1) return dp[i][j];

    ll x=0,y=0;

    if(i+1<h&&ar[i+1][j]!='#') x=path(i+1,j);

    if(j+1<w&&ar[i][j+1]!='#') y=path(i,j+1);

    return dp[i][j]=(x+y)%mod;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //freopen("input.txt", "r", stdin);

    //freopen("output.txt", "w", stdout);



    cin>>h>>w;

    for(ll i=0;i<h;i++){

        for(ll j=0;j<w;j++){

            cin>>ar[i][j];

        }

    }

    memset(dp,-1,sizeof(dp));

    cout<<path(0,0)<<endl;

    return 0;

}


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

#define PI acos(-1)

#define falcon ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;

typedef long long ll ;

using namespace std ;



char grid[1001][1001] ;

int paths[1001][1001] ;



int main()

{

    falcon ;



    int n , m ;

    cin >> n >> m ;

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

    {

        for(int j = 0 ; j < m ; j++)

        {

            cin >> grid[i][j] ;

            paths[i][j] = 0 ;

        }

    }

    paths[0][0] = 1 ;

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

    {

        for(int j = 0 ; j < m ; j++)

        {

            if(grid[i][j] == '#') continue ;

            if(i > 0) paths[i][j] = paths[i][j] + paths[i - 1][j] ;

            if(j > 0) paths[i][j] = paths[i][j] + paths[i][j - 1] ;

            paths[i][j] = paths[i][j] % 1000000007 ;

        }

    }

    cout << paths[n - 1][m - 1] << "\n" ;

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

using namespace std;

typedef long long ll;

const int N = 1e5+10;

int n;

struct node{

	int id,val;

}a[N],b[N];

bool cmp(const node &a,const node &b)

{

	return a.val<b.val;

}

bool cmp2(const node &a,const node &b)

{

	return a.id<b.id;

}

map<int,int>mp;

int main()

{

	cin>>n;

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

	{

		cin>>a[i].val;

		a[i].id=i;

	}

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

	{

		cin>>b[i].val;

		b[i].id=i;

	}

	sort(a+1,a+n+1,cmp);

	sort(b+1,b+n+1,cmp);

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

	{

		if(b[i].val<a[i].val)

		{

			cout<<"No\n";

			return 0;

		}

	}

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

	{

		if(b[i].val>=a[i+1].val)

		{

			cout<<"Yes\n";

			return 0;

		}

	}

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

	b[i].val=min(b[i].val,a[i].val);

	sort(a+1,a+n+1,cmp2);

	sort(b+1,b+n+1,cmp2);

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

	mp[b[i].val]=i;

	int cnt=0;

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

	{

		if(a[i].val==b[i].val)

		continue;

		int pos=mp[a[i].val];

		cnt++;

		swap(mp[b[i].val],mp[a[i].val]);

		swap(b[i].val,b[pos].val);

	}

	if(cnt>n-2)

	cout<<"No\n";

	else

	cout<<"Yes\n";

}

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

#include <algorithm>

#include <cstring>

#include <cctype>

using namespace std;



namespace zyt

{

	template<typename T>

	inline bool read(T &x)

	{

		char c;

		bool f = false;

		x = 0;

		do

			c = getchar();

		while (c != EOF && c != '-' && !isdigit(c));

		if (c == EOF)

			return false;

		if (c == '-')

			f = true, c = getchar();

		do

			x = x * 10 + c - '0', c = getchar();

		while (isdigit(c));

		if (f)

			x = -x;

		return true;

	}

	template<typename T>

	inline void write(T x)

	{

		static char buf[20];

		char *pos = buf;

		if (x < 0)

			putchar('-'), x = -x;

		do

			*pos++ = x % 10 + '0';

		while (x /= 10);

		while (pos > buf)

			putchar(*--pos);

	}

	const int N = 1e5 + 10;

	int n, a[N], b[N], fa[N], ida[N], idb[N];

	int f(const int x)

	{

		return x == fa[x] ? x : fa[x] = f(fa[x]);

	}

	bool cmpa(const int i, const int j)

	{

		return a[i] < a[j];

	}

	bool cmpb(const int i, const int j)

	{

		return b[i] < b[j];

	}

	int work()

	{

		read(n);

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

			read(a[i]), ida[i] = i;

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

			read(b[i]), idb[i] = i;

		sort(ida + 1, ida + n + 1, cmpa);

		sort(idb + 1, idb + n + 1, cmpb);

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

		{

			fa[i] = i;

			if (a[ida[i]] > b[idb[i]])

			{

				puts("No");

				return 0;

			}

		}

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

			if (i && a[ida[i]] <= b[idb[i - 1]])

			{

				puts("Yes");

				return 0;

			}

		int cnt = 0;

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

		{

			int x = f(ida[i]), y = f(idb[i]);

			if (x == y)

				++cnt;

			else

				fa[x] = y;

		}

		if (cnt > 1)

			puts("Yes");

		else

			puts("No");

		return 0;

	}

}

int main()

{

	return zyt::work();

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

#define ll long long

using namespace std;

#define maxn 100010

#define mod 1000000007

struct cv{

    int x,y;

}a[maxn];

int b[maxn];

int cnt;

set<int>s[maxn];

int dp[maxn],du[maxn];

bool cmp(cv p,cv q){

    if(p.x!=q.x) return p.x<q.x;

    return p.y<q.y;

}

int main(){

    int n;

    scanf("%d",&n);

    for(int i=0;i<n;i++) scanf("%d",&a[i].x);

    for(int i=0;i<n;i++) scanf("%d",&a[i].y),b[i]=a[i].y;

    sort(a,a+n,cmp);

    sort(b,b+n);

    cnt=0;

    int flag=0;

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

        if(a[i].x>b[i]){

            printf("No\n");

            return 0;

        }

        if(i<n-1&&a[i+1].x<b[i]) flag=1;

        if(i!=0){

            if(b[i]==b[i-1]) flag=1;

        }

        if(i!=0&&a[i].x!=a[i-1].x){

            cnt++;

            s[cnt].insert(a[i].y);

        }

        else{

            s[cnt].insert(a[i].y);

            if(i!=0) flag=1;

        }

    }

    cnt=0;

    if(flag){

        printf("Yes\n");

        return 0;

    }

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

        dp[lower_bound(b,b+n,a[i].y)-b]=i;

    }

    cnt=0;

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

        if(du[i]) continue;

        cnt++;

        du[i]=1;

        int x=dp[i];

        while(du[x]==0){

            du[x]=1;

            x=dp[x];

        }

    }

    if(cnt>=2) printf("Yes\n");

    else printf("No\n");

    return 0;

}

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

using namespace std;



namespace TYC

{

	typedef long long ll;

	typedef pair<int, int> pii;

	const int N = 1e5 + 5;



	int n, A[N], B[N], P[N];

	map<int, int> idA, idB;



	inline int read()

	{

		int x = 0, f = 0, ch = getchar();

		while (!isdigit(ch))

			f |= (ch == '-'), ch = getchar();

		while (isdigit(ch))

			x = x * 10 + ch - '0', ch = getchar();

		return f ? -x : x;

	}



	inline void End(const int t)

	{

		puts(t ? "Yes" : "No");

		exit(0);

	}



	void work()

	{

		n = read();

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

			A[i] = read(), idA[A[i]] = i;

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

			B[i] = read(), idB[B[i]] = i;

		sort(A + 1, A + 1 + n);

		sort(B + 1, B + 1 + n);

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

			if (A[i] > B[i])

				End(0);

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

			if (A[i] == A[i + 1] || B[i] == B[i + 1])

				End(1);

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

			if (i < n && A[i + 1] <= B[i])

				End(1);

			else

				P[idA[A[i]]] = idB[B[i]];

		int c = 1, u = P[1];

		while (u != 1)

			c++, u = P[u];

		End(c != n);

	}

}



int main()

{

	TYC::work();

	return 0;

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

#include <string>

#include <algorithm>

using namespace std;

string s;

const int Kmax=1e7;

int sum[Kmax];

int R[Kmax];

 

int main()

{

    int n;

    cin>>n;

    cin>>s;

    int Max=0;

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

         sum[j]=sum[j-1];

         if(s[j-1]=='E'){

            sum[j]++;

			

         }

         }

        for(int k=n;k>0;k--){

        R[k-1]=R[k];

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

        R[k-1]++;

        }

         sum[k-1]=sum[k-1]+R[k-1];

		

         Max=max(Max,sum[k-1]);

        }

        cout<<n-1-Max<<endl;

    return 0;

}

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

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

}

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

}
// 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[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;





}






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

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

}

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

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

}

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

}
// 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: 6.9263765661443255x):
#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;

}