#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=4010;
int bigger_num[2][maxn][maxn],a[maxn],pos[2][maxn];
bool c[maxn];
int dp[maxn][maxn];
int main(){
	int n;
	scanf("%d",&n);
	char ch[5];
	for(int i=1;i<=n+n;i++){
		scanf("%s%d",ch,a+i);
		c[i]=(ch[0]=='B');
		pos[c[i]][a[i]]=i;
	}
	for(int i=0;i<2;i++){
		for(int j=1;j<=n+n;j++){
			int cnt=0;
			for(int k=n;k>=0;k--){
				bigger_num[i][j][k]=cnt;
				if(pos[i][k]<=j) cnt++;
			}
		}
	}
	memset(dp,0x3f,sizeof dp);
	dp[0][0]=0;
	for(int i=1;i<=n+n;i++){
		for(int j=0;j<=n;j++){
			if(j+1<=n){
				int diff_col=bigger_num[1][pos[0][j+1]][i-1-j];
				dp[i][j+1]=min(dp[i][j+1],dp[i-1][j]+diff_col+bigger_num[0][pos[0][j+1]][j+1]);
			}
			if(i-j<=n){
				int diff_col=bigger_num[0][pos[1][i-j]][j];
				dp[i][j]=min(dp[i][j],dp[i-1][j]+diff_col+bigger_num[1][pos[1][i-j]][i-j]);
			}
		}
	}
	printf("%d\n",dp[n+n][n]);
	return 0;
}