#include <bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,w[N],b[N],x;
int f[N][N],cw[N][N],cb[N][N];
int main()
{
	memset(cw,0,sizeof(cw));
	memset(cb,0,sizeof(cb));
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++){
		char op[2];scanf("%s%d",op,&x);
		if(op[0]=='W')w[x]=i;else b[x]=i;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++)if(w[i]<w[j])cw[i][0]++;
		for(int j=1;j<=n;j++){
			cw[i][j]=cw[i][j-1];
			if(w[i]<b[j])cw[i][j]++;	
		}
	}	
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++)if(b[i]<b[j])cb[0][i]++;
		for(int j=1;j<=n;j++){
			cb[j][i]=cb[j-1][i];
			if(b[i]<w[j])cb[j][i]++;
		}
	}
	int c1=0,c2=0;
	for(int i=1;i<=n;i++){
		c1+=cw[i][0],c2+=cb[0][i];
		f[i][0]=c1,f[0][i]=c2;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=min(f[i-1][j]+cw[i][j],f[i][j-1]+cb[i][j]);	
	cout<<f[n][n]<<'\n';
	return 0;
}