#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
ll read(){
	char ch=getchar();ll x=0;int op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 2005
int n,ans,a[N],b[N],f[N][N],w1[N][N],w2[N][N];char ch[5];
int main(){
	n=read();
	rep (i,1,2*n){
		scanf("%s",ch);int x=read();
		if (ch[0]=='B') a[x]=i;else b[x]=i;
	}
	rep (i,1,n) rep (j,1,i-1) ans+=(a[i]<a[j])+(b[i]<b[j]);
	rep (i,1,n) rep (j,1,n) w1[i][j]=w1[i][j-1]+(b[j]>a[i]);
	rep (i,1,n) rep (j,1,n) w2[i][j]=w2[i][j-1]+(a[j]>b[i]);
	memset(f,0x3f,sizeof(f));
	rep (i,0,n) f[0][i]=f[i][0]=0;
	rep (i,1,n) rep (j,1,n) f[i][j]=min(f[i-1][j]+w1[i][j],f[i][j-1]+w2[j][i]);
	cout<<ans+f[n][n]<<'\n';
	return 0;
}