#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mem(a) memset(a,0,sizeof(a))

typedef long long ll;
typedef pair<int,int> pii;

const int mn=4005;

int n;
int a[mn];

//BIT
int t[mn+100];
void add(int i,int x){while(i<=n*2)t[i]+=x,i+=i&-i;}
int sum(int i){int s=0;while(i)s+=t[i],i-=i&-i;return s;}

int d[mn>>1][mn>>1];
int pos[2][mn];//0 white

int main() {
	cin>>n;
	for(int i=1;i<=2*n;i++){
		char u;int v;
		cin>>u>>v;
		if (u=='B'){
			v+=n;
			pos[1][v-n]=i;
		}
		else pos[0][v]=i;
		a[i]=v;
	}
	//DP
	memset(d,4, sizeof(d));
	d[0][0]=0;
	for(int i=0;i<=n;i++){//white
		fill_n(t,4100,0);
		int temp=0;
		for(int k=1;k<=i;k++) temp+=pos[0][k]-sum(pos[0][k])-1,add(pos[0][k],1);
		d[i][0]=temp;
		for(int j=1;j<=n;j++){//black
			if (!i&&!j) continue;
			d[i][j]=min(d[i][j],d[i][j-1]+pos[1][j]-sum(pos[1][j])-1);
			add(pos[1][j],1);
			if (i<n) d[i+1][j]=min(d[i+1][j],d[i][j]+pos[0][i+1]-sum(pos[0][i+1])-1);
		}
	}
	cout<<d[n][n]<<endl;
	return 0;
}