#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int dp[2100][2100],a[2100],b[2100],c1[2100][2100],c2[2100][2100];
int main(){
	  int n,m,i,j,k,x;
	  char ch;
	  scanf("%d",&n);
	  for(i=1;i<=2*n;i++){
	  	 cin>>ch;scanf("%d",&x);
	  	 if(ch=='B'){
	  	 	a[x]=i;
	  	 }else {
	  	 	b[x]=i;
	  	 }
	  }
	  for(i=1;i<=n;i++){
	  	 for(j=1;j<i;j++)
	  	    if(a[i]<a[j])c1[i][0]++;
	  	 for(j=1;j<=n;j++){
	  	 	c1[i][j]=c1[i][j-1];
	  	 	if(b[j]>a[i])c1[i][j]++;
	  	 }
	  }
	  for(i=1;i<=n;i++){
	  	 for(j=1;j<i;j++)
	  	    if(b[i]<b[j])c2[0][i]++;
	  	 for(j=1;j<=n;j++){
	  	 	c2[j][i]=c2[j-1][i];
	  	 	if(a[j]>b[i])c2[j][i]++;
	  	 }
	  }
	  int wh1=0,wh2=0;
	  for(i=1;i<=n;i++){
	  	 wh1+=c1[i][0];
	  	 wh2+=c2[0][i];
	  	 dp[i][0]=wh1;
	  	 dp[0][i]=wh2;
	  }
	  for(i=1;i<=n;i++)
	     for(j=1;j<=n;j++)
	        dp[i][j]=min(dp[i-1][j]+c1[i][j],dp[i][j-1]+c2[i][j]);
	  cout<<dp[n][n]<<endl;
	  return 0;
}