#include <bits/stdc++.h>
using namespace std;
char c[4009];
int p[4009],n,p1,p2,dp[4009][4009],w[2][4009][4009],cnt;
int main()
{
	cin>>n;
	for (int i=1;i<=2*n;i++) cin>>c[i]>>p[i];
	for (int i=1;i<=2*n;i++)
	{
		for (int j=i+1;j<=2*n;j++)
		{
			if (c[i]==c[j] && p[i]>p[j]) cnt++;
		}
	}
	p1=n;
	p2=n;
	for (int i=1;i<=2*n;i++)
	{
		int W=0,B=0;
		for (int j=1;j<=2*n;j++)
		{
			if (p[j]>=i)
			{
				if (c[j]=='W') W++;
				if (c[j]=='B') B++;
			}
			if (c[j]=='W') w[0][p[j]][i]=B;
			else w[1][p[j]][i]=W;
		}
	}
	for (int i=0;i<=2*n;i++)
	{
		for (int j=0;j<=2*n;j++) dp[i][j]=(1<<30);
	}
	dp[0][0]=0;
	for (int i=0;i<=p1;i++)
	{
		for (int j=0;j<=p2;j++)
		{
			if (i<p1) dp[i+1][j]=min(dp[i+1][j],dp[i][j]+w[0][i+1][j+1]);
			if (j<p2) dp[i][j+1]=min(dp[i][j+1],dp[i][j]+w[1][j+1][i+1]);
		}
	}
	cout<<cnt+dp[p1][p2]<<endl;
	return 0;
}